Dan W
Dan W

Reputation: 121

How do I find actual cutoff values from the ROC curve I generate in R?

I am familiar with how to create a ROC curve with the pROC library in R. My code is in the following form:

glmfit <- glm(Y ~ X1 + X2 +..., family = binomial(), data = df)
roc_in_sample <- roc(df$Y, predict(glmfit, newdata = df, type = "response"))

This will then give me an ROC object, and I can plot my ROC curve of Sensitivity vs. 1-Specificity.

My question is, how do I get the actual cutoff values from this curve? Like let's say I identify a point on the curve where sensitivity and specificity are both 80%. How do I pull the actual cutoff value from this model, the cutoff at which the sensitivity and specificity are 80%?

I'm not looking for guidance as to the BEST choice I could make. I simply want to know how to find the actual cutoff value that I would list in my report. IE, I want to be able to say something like "my model determined that a cutoff of 0.567 probability will give us a sensitivity of 80% and a specificity of 80%" (these are hypothetical values; this is just the sort of thing I need to be able to say). How do I get that in R, either from this pROC function or something else?

Upvotes: 1

Views: 1078

Answers (1)

thothal
thothal

Reputation: 20379

You need to find the threshold slot from your roc object which is the closest to your desired probability and return the repective sensitivity and specificity:

library(pROC)
r <- roc(aSAH$outcome, aSAH$s100b,
           levels=c("Good", "Poor"))
prob <- .8
idx <- which.min((tail(head(r$thresholds, -1L), -1L) - prob) ^ 2)
c(r$specificities[idx], r$sensitivities[idx])

Upvotes: 0

Related Questions