Thie1e / cutpointr

Optimal cutpoints in R: determining and validating optimal cutpoints in binary classification
https://cran.r-project.org/package=cutpointr
84 stars 13 forks source link

cutpointr() subgroup option how to determine opt_cut$boot list belonging to which subgroup? #52

Closed jwang-lilly closed 2 years ago

jwang-lilly commented 2 years ago

Hi Christian,

Thanks much for the nice and fast package to make cupoint related calculations enjoyable!

I have a quick question. When using subgroup option in the cutpointr(), for example subgroup = 'gender', the opt_cut$boot would be a list of two items. How can I tell which item for gender = female and which is for gender = male? I guess it is based on alphabetical order therefore female in opt_cut$boot[[1]] and male in opt_cut$boot[[2]], is this correct?

Thanks a lot.

@Thie1e

Thie1e commented 2 years ago

Hi Jian,

the order is not alphabetical. The elements of opt_cut$boot belong to opt_cut$subgroup. With the example data opt_cut$boot[[1]] is for the female group:

library(cutpointr)
library(tidyverse)
cutpointr(data = suicide, 
          x = dsi, 
          class = suicide, 
          subgroup = gender, 
          boot_runs = 100,
          method = maximize_metric,
          metric = sum_sens_spec,
          use_midpoints = TRUE) %>% 
    select(subgroup, optimal_cutpoint, roc_curve, boot)
#> Assuming the positive class is yes
#> Assuming the positive class has higher x values
#> Running bootstrap...
#> # A tibble: 2 x 4
#>   subgroup optimal_cutpoint roc_curve                 boot               
#>   <chr>               <dbl> <list>                    <list>             
#> 1 female                1.5 <roc_cutpointr [11 x 10]> <tibble [100 x 23]>
#> 2 male                  2.5 <roc_cutpointr [11 x 10]> <tibble [100 x 23]>

Created on 2022-02-26 by the reprex package (v2.0.1)

P.S. Thanks for the kind words! Glad that you like the package.

jwang-lilly commented 2 years ago

Excellent Christian. Thanks so much!