Comments (8)
Perfect!!
from cutpointr.
I discovered what is missing: is the argument boot_runs
opt_cut <- cutpointr(suicide, dsi, suicide,boot_runs = 50)
plot_sensitivity_specificity(opt_cut)
As I extracted this example from the documentation, maybe it needs to be corrected.
Thanx!
from cutpointr.
Hi, thanks for the report. I'll look into it tomorrow. It should actually run with and without the boot_runs
argument.
from cutpointr.
This was a bug in plot_sensitivity_specificity
. I pushed a new version of cutpointr
(0.7.4) to Github that should fix the problem. You can install it using devtools::install_github("thie1e/cutpointr")
. (By the way, it also includes the add_metric
function.) Can you give the new version a try?
from cutpointr.
Sure, I tested and it worked beautifully.
I have another suggestion for plot_sensitivity_specificity. It would be nice if we could build an output with diverses outcomes in one graph only. Maybe using facet_wrap from ggplot2.
Thanks for the wonderfull package!
from cutpointr.
Good to hear that it works now and thanks again for the report. The fix will make it to CRAN soon.
Regarding the graphing suggestion: You mean plotting different subgroups on different facets instead of with different shapes / colors? So basically like this:
library(tidyverse)
library(cutpointr)
cp <- cutpointr(suicide, dsi, suicide, gender)
cp %>%
select(subgroup, roc_curve) %>%
unnest %>%
ggplot(aes(x = fpr, y = tpr)) +
geom_step() +
facet_wrap(~ subgroup) +
ggtitle("ROC curve")
from cutpointr.
Hummm, actually, if it is possible, I was trying to find a way of doing the graphic below in facet_wrap style. I think this way it is too polluted.
# librarys
library(tidyverse); library(cutpointr)
# random data
data <- data_frame(test = runif(1000, min=0, max=10),
out1 = c(rep(1,400),rep(0,600)),
out2 = c(rep(1,200),rep(0,800)),
out3 = c(rep(1,100),rep(0,900)),
out4 = c(rep(1,500),rep(0,500))) %>%
sample_n(300) %>%
mutate_at(vars(starts_with("out")),factor)
data
#> # A tibble: 300 x 5
#> test out1 out2 out3 out4
#> <dbl> <fct> <fct> <fct> <fct>
#> 1 1.02 0 0 0 0
#> 2 3.64 0 0 0 0
#> 3 5.27 0 0 0 0
#> 4 4.62 0 0 0 0
#> 5 4.16 0 0 0 0
#> 6 2.88 1 1 0 1
#> 7 4.40 1 1 1 1
#> 8 6.46 0 0 0 0
#> 9 3.82 1 1 0 1
#> 10 4.04 0 0 0 0
#> # ... with 290 more rows
# loop and plots
out <- c("out1","out2","out3","out4")
plot <- out %>%
map(~cutpointr(data = data, x = test, class = pull(data, .), pos_class = 1, neg_class = 0, method = oc_youden_normal, metric = ppv) %>%
plot_sensitivity_specificity +
geom_vline(xintercept = c(1,5, 7.5), col="dodgerblue2") +
xlab(paste("cutpoint for",.))) %>%
set_names(out)
#> Assuming the positive class has lower x values
#> Assuming the positive class has lower x values
#> Assuming the positive class has lower x values
#> Assuming the positive class has higher x values
#> Warning in method(data = dat$data[[1]], x = predictor, class = outcome, :
#> Cutpoint -3.40934500415604 was restricted to range of independent variable
cowplot::plot_grid(plot$out1, plot$out2, plot$out3, plot$out4)
Created on 2018-08-25 by the reprex package (v0.2.0).
from cutpointr.
You can do it manually as below. The problem is IMO that data
is not tidy which makes it harder (gather it first and treat the out columns as subgroups).
Actually, this might also be a good addition to the package. We could just offer the option to make facets instead of different shapes for the subgroups - but this would take some work. I'll open an issue.
library(cutpointr); library(tidyverse)
data <- data_frame(test = runif(1000, min=0, max=10),
out1 = c(rep(1,400),rep(0,600)),
out2 = c(rep(1,200),rep(0,800)),
out3 = c(rep(1,100),rep(0,900)),
out4 = c(rep(1,500),rep(0,500))) %>%
sample_n(300) %>%
mutate_at(vars(starts_with("out")),factor)
#
# This would be the "cutpointr way" of doing it. Gather the data first.
#
cp <- data %>%
gather(key, value, -test) %>%
cutpointr(test, value, key)
#> Assuming the positive class is 1
#> Assuming the positive class has higher x values
plot_sensitivity_specificity(cp)
# Facet wrap:
res_unnested <- cp %>%
select(roc_curve, subgroup, optimal_cutpoint) %>%
unnest(roc_curve) %>%
mutate(Sensitivity = sensitivity(tp = tp, fn = fn),
Specificity = specificity(fp = fp, tn = tn)) %>%
gather(metric, value, Sensitivity, Specificity) %>%
filter(is.finite(x.sorted))
#> Warning: attributes are not identical across measure variables;
#> they will be dropped
ggplot(res_unnested, aes(x = x.sorted, y = value, color = metric)) +
geom_line() +
geom_vline(aes(xintercept = optimal_cutpoint)) +
facet_wrap(~subgroup)
Created on 2018-09-03 by the reprex
package (v0.2.0).
from cutpointr.
Related Issues (20)
- Cutpointr confidence interval predictive positive value HOT 2
- Missing metrics if maximize/minimize_boot_metric HOT 2
- Allow bootstrap stratification for maximize_boot_metric and minimize_boot_metric HOT 1
- Make printing of summary_cutpointr nicer in Rmd documents HOT 1
- 95% confidence intervals instead of getting limits at 5% and 95% in summary of cutpointr HOT 1
- Documentation and cutpointr output suggestion HOT 3
- Confidence Intervals for ROC curves
- Plot a the ROC curve with manual settings HOT 4
- cutpointr() subgroup option how to determine opt_cut$boot list belonging to which subgroup? HOT 2
- Specify a customer cutpoint using oc_manual=avalue ignored? HOT 2
- Can we specify the bootstrap sampling size? HOT 2
- How to access ppv values given a custom cutpoint HOT 2
- How to include more than one predictors? HOT 5
- Calculating confidence intervals in cutpointr HOT 1
- Creating a composite biomarker score using regression coefficients HOT 2
- direction parameter in the cutpointr() HOT 2
- Set manual color for only one line HOT 3
- add_metric adds the metric column multiple times
- An ambiguous region bounded by two cutpoint
- Explain oc_youden Kernel
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cutpointr.