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?
-
From the comments you left in my answer, it looks like what you are asking is NOT a ROC curve. A ROC curve goes over all thresholds. If you limit the thresholds, your curve is not a ROC any more. So please rephrase your question. – Calimo Aug 11 '14 at 06:59
-
Also, it doesn't make any sense to me why the hell you'd like to do, probably beacuse your question is too specific. If you tell us a bit more about the reason behind your choice to do this, a better answer may appear. – Calimo Aug 11 '14 at 07:01
2 Answers
Have a look at ?plot.roc
.
Let's say you have:
my.cutoff <- 0.6
Then you can do:
library(pROC)
data(aSAH)
plot.roc(aSAH$outcome, aSAH$s100b, print.thres = my.cutoff)

- 7,510
- 4
- 39
- 61
-
Thanks a lot for your response. But I want something different than this. I do not know how pROC select thresholds to calculate sensitivities and specificities. However, I want to calculate them at threshold values specified myself. For example, roc(case=mycases, control=mycontrols, ...); in here is there a way to specify my own threshold values? – Vish Jul 18 '14 at 18:12
-
@Vish I used 0.6 but you can specify any cutoff you want in `my.cutoff`, you can also pass a vector of cutoffs. – Calimo Jul 19 '14 at 09:10
-
-
Thanks so much again for your attention. However, I want to use my own thresholds to generate the ROC curve. For example, roc(case=mycases, control=mycontrols, Thresholds = c(0.6, 1, 1.5, 1.8). Then the function produce ROC curve and AUC considering ONLY those specified thresholds. I guess this is not possible with pROC package. Is it? Thanks so much. – Vish Aug 08 '14 at 16:45
-
@Vish You cannot generate a ROC curve with only a few thresholds: it isn't ROC any more. – Calimo Aug 11 '14 at 07:20
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.

- 7,510
- 4
- 39
- 61