Thie1e / cutpointr

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

Cutpointr confidence interval predictive positive value #32

Closed maltarel closed 3 years ago

maltarel commented 4 years ago

Hi,

I'm using cutpointr with boot_runs to get cutpoints , AUC, specificity and sensitivity with their respective confidence intervals. I also "manually" extracted the PPV and NPV, but I don't know how to get their respective confidence intervals.
Does someone has any idea ?

Thank you !

Thie1e commented 3 years ago

Hi,

I'm assuming you're using the cutpointr version from CRAN? If you'd like to calculate the usual bootstrap confidence intervals for additional metrics like PPV and NPV you can do so with the cutpointr version from Github (yes, we should push this version to CRAN eventually...):

devtools::install_github("thie1e/cutpointr")

The add_metric function from that version adds the additional metrics also to the bootstrap results, so you can use boot_ci on them. I just assumed that we're doing a "cross validation" and set in_bag = FALSE. Set it to TRUE if you're looking for the in-sample variability of the respective metrics. For example:

library(cutpointr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

cp <- cutpointr(suicide, dsi, suicide, boot_runs = 200)
#> Assuming the positive class is yes
#> Assuming the positive class has higher x values
#> Running bootstrap...

cp %>% 
    add_metric(list(ppv, npv)) %>% 
    boot_ci(ppv, in_bag = FALSE, alpha = 0.05)
#> # A tibble: 2 x 2
#>   quantile values
#>      <dbl>  <dbl>
#> 1    0.025  0.176
#> 2    0.975  0.449

cp %>% 
    add_metric(list(ppv, npv)) %>% 
    boot_ci(npv, in_bag = FALSE, alpha = 0.05)
#> # A tibble: 2 x 2
#>   quantile values
#>      <dbl>  <dbl>
#> 1    0.025  0.970
#> 2    0.975  1

Created on 2020-11-13 by the reprex package (v0.3.0)

Does that help?

maltarel commented 3 years ago

Fantastic ! Thank you very much for your help