MK Huda
MK Huda

Reputation: 687

How to add the optimum threshold to the ROC curve plot in R

I got this example below and wondering how to get the optimal threshold (Youden's index = sensitivity+specificity-1) for each method and plot that value on the ROC curve to know the coordinate obtained from that optimal threshold. How to do that? My real ROC curves consist of 4 roc curves (see the example below) for four different methods and I want to plot the optimum threshold for each method on each corresponding method. For simplicity, I use the example below instead.

library(ROCR)
data(ROCR.simple)
df <- data.frame(ROCR.simple)
pred <- prediction(df$predictions, df$labels)
perf <- performance(pred,"tpr","for")
plot(perf,colorize=FALSE)

This is an example of my ROC curve. enter image description here

Upvotes: 1

Views: 2851

Answers (1)

Calimo
Calimo

Reputation: 7959

You can do that easily with the pROC package (disclaimer: I am the author and maintainer of this package). Setting the print.thres

library(pROC)
my_curve <- roc(df$predictions, df$labels)
plot(my_curve, print.thres=TRUE)

Upvotes: 1

Related Questions