-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plot_sensitivity_specificity not ploting #8
Comments
I discovered what is missing: is the argument boot_runs
As I extracted this example from the documentation, maybe it needs to be corrected. |
Hi, thanks for the report. I'll look into it tomorrow. It should actually run with and without the |
This was a bug in |
Sure, I tested and it worked beautifully. Thanks for the wonderfull package! |
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:
|
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). |
You can do it manually as below. The problem is IMO that 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 |
Perfect!! |
Something is wrong with the plot_sensitivity_specificity command. When I do this I get an empty ggplot estructure with a vertical line on the number 2.
Is this correct?
Thanx
The text was updated successfully, but these errors were encountered: