Get the optimal threshold with a sensitivity of at least 75% with pROC in R

I have a dataframe with two columns: score1which numericand truth1which is equal boolean. I want to predict truth1using score1. To do this, I need a simple linear model, and then ask for a good threshold, i.e. A threshold that gives me 75% sensitivity in my ROC curve. Therefore, I:

roc_curve = roc(truth1 ~ score1 , data = my_data)
coords(roc=roc_curve, x = 0.75, input='sensitivity', ret='threshold')

My problem is that the coords return "NA" because the 0.75 sensitivity does not appear in the ROC curve. So, here is my question: how can I get a threshold that gives me a sensitivity of at least 0.75, with maximum specificity?

+5
source share
2

1:

my.coords <- coords(roc=roc_curve, x = "all", transpose = FALSE)
my.coords[my.coords$sensitivity >= .75, ]

2: pROC, AUC 75% 100%:

roc_curve = roc(truth1 ~ score1 , data = my_data, partial.auc = c(1, .75), partial.auc.focus="sensitivity")

pROC :

coords(roc=roc_curve, x = "local maximas", ret='threshold', transpose = FALSE)
+10

Calimo, :

# Specify SENSITIVITY criteria to meet.
Sn.upper <- 1.0
Sn.lower <- 0.5

# Specify SPECIFICITY criteria to meet.
Sp.upper <- 1.0
Sp.lower <- 0.6

# Extract all coordinate values from the ROC curve.
my.coords <- coords(roc=auc, x = "all", transpose = FALSE)

# Identify and print all points on the ROC curve that meet the JOINT sensitivity AND specificity criteria.
my.coords[(my.coords$specificity >= Sp.lower & my.coords$specificity <= Sp.upper & 
            my.coords$sensitivity >= Sn.lower & my.coords$sensitivity <= Sn.upper),]

:

       threshold specificity sensitivity
all.46    10.950   0.5000000   0.7073171
all.47    11.080   0.5138889   0.7073171
all.48    11.345   0.5138889   0.6829268
all.49    11.635   0.5138889   0.6585366
all.50    11.675   0.5138889   0.6341463
all.51    11.700   0.5277778   0.6341463
all.52    11.725   0.5277778   0.6097561
all.53    11.850   0.5416667   0.6097561
all.54    12.095   0.5555556   0.6097561
+1

Source: https://habr.com/ru/post/1611601/


All Articles