Comments (3)
To follow-up, say I'd like to manually set one subgroup (female) to black.
I did the following but obviously the resulting plot doesn't make much sense. I also don't know what is exactly "cohens_kappa_oob...25" In addition, I have to set conf_lvl = 0, otherwise, I got this error:
Error in geom_line()
:
! Problem while computing aesthetics.
ℹ Error occurred in the 3rd layer.
Caused by error in FUN()
:
! object 'ymax' not found
`
temp <- opt_cut %>% dplyr::filter(subgroup == 'female') %>%
data.frame()
temp2 <- temp$boot %>%
data.frame() %>%
dplyr::rename(cohens_kappa = "cohens_kappa_oob...25")
plot_cutpointr(opt_cut, xvar = cutpoint,
yvar = cohens_kappa,
conf_lvl = 0,
aspect_ratio = NULL) +
scale_x_continuous(n.breaks=20, minor_breaks = waiver()) +
scale_y_continuous(n.breaks=5, minor_breaks = waiver()) +
geom_line(data = temp2,
mapping = aes(x = optimal_cutpoint, y = cohens_kappa),
color = "black")
`
Any advice is greatly appreciated.
from cutpointr.
Hi Jian,
I think your first approach isn't so bad. You just need a function that generates the color palette. I think there are many options to do that in R. Here, I am using rainbow
. Then you modify the color of the reference class manually.
Can you try this? It's a bit hacky, but I think it should pick the correct subgroup for the manually set color. Can you confirm that?
data(suicide)
# Generate some additional subgroups
testdat <- suicide
testdat$gender <- sample(1:5, size = nrow(testdat), replace = T)
opt_cut <- cutpointr(data=testdat, x=dsi, class=suicide, direction = ">=", pos_class = "yes",
neg_class = "no", subgroup = gender,
method = maximize_metric, metric = youden,
boot_runs = 100) %>%
add_metric(list(cohens_kappa))
# Find the position of the reference class and set its color
ref_class <- "2"
(which_ref <- which(sort(opt_cut$subgroup) == ref_class))
color_vec <- rainbow(nrow(opt_cut))
ref_color <- "black"
color_vec[which_ref] <- ref_color
print(color_vec)
# If you do not want to plot the confidence intervals when having many
# subgroups, set conf_lvl = 0
# Otherwise, also define the fill color to use your color palette
p <- plot_cutpointr(opt_cut, xvar = cutpoint,
yvar = youden,
conf_lvl = 0,
aspect_ratio = NULL) +
geom_line(linewidth = 1) +
scale_x_continuous(n.breaks=20, minor_breaks = waiver()) +
scale_y_continuous(n.breaks=5, minor_breaks = waiver()) +
scale_color_manual(values = color_vec)
print(p)
If you need more control or want to try plotting the data with a manual call to ggplot, you could extract the plotted data with p$data
.
Also, thanks for drawing my attention to the problems with add_metric
(the wrong column names). I think it doesn't lead to errors in the results, but I will have to look into that. The additional metric column is added multiple times and gets unintended names. I guess a dependency changed and I will have to update that function. Thanks again.
from cutpointr.
Thanks very much Christian. This is a perfect solution. I will go ahead to close this issue. One very minor observation with regard the "New names during the run."
`
opt_cut <- cutpointr(data=testdat, x=dsi, class=suicide, direction = ">=", pos_class = "yes", neg_class = "no", subgroup = gender,
-
method = maximize_metric, metric = youden,
-
boot_runs = 100) %>%
-
add_metric(list(cohens_kappa))
`
Running bootstrap...
New names:New names:New names:New names:New names:`
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
- 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.