Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pROC R package with customized cutoff values?

Can I use some pre-specified cutoff values (thresholds) to plot a ROC curve with the pROC package? For example, can I input control/case values and my own threshold points where to calculate corresponding sensitivities and specificities?

like image 348
Vish Avatar asked Sep 11 '25 04:09

Vish


1 Answers

This is no longer a ROC curve

To address your comments in my other answer (but not answer your question, which can't be answered as I commented above), I can give you a way to do what you seem to want. Please do NOT under any circumstances refer to this as a ROC curve: it is not! Please come up with a descriptive name yourself, depending on the purpose of this exercise (which you never explained).

You can do what you seem to want indirectly with pROC: you compute the ROC on all thresholds, extract the coordinates you want: and use a trapezoid function to finish up.

library(pROC)
data(aSAH)
my.cutoff <- c(0.6, 1, 1.5, 1.8)
roc.obj <- roc(aSAH$outcome, aSAH$s100b)
like.coordinates <- coords(roc.obj, c(-Inf, sort(my.cutoff), Inf), input="threshold", ret=c("specificity", "sensitivity"))

Now you can plot the results as:

plot(like.coordinates$specificity, like.coordinates$sensitivity, xlim=c(1, 0), type="l")

And compute the AUC, for instance with the trapz function in package caTools:

library(caTools)
trapz(like.coordinates$specificity, like.coordinates$sensitivity)

Once again, you did NOT plot a ROC curve and the AUC you computed is NOT that of a ROC curve.

like image 155
Calimo Avatar answered Sep 12 '25 19:09

Calimo