calculate cut-off that max sensitivity vs specific

2019-05-30 11:28发布

问题:

I am trying to calculate the cut-off point that max sensitivity vs specifity. I am using the ROCR package and I have managed to plot the graph sensitivity vs specifity. However, I don't know how to calculate what is the cut off point that max sensitivity vs specifity. Ideal I would like to have a label in the graph that shows the cut off and the coordenates at the point. But, any suggestion to solve this question will be greatly appreciated.

pred <- prediction( ROCR.simple$hello, ROCR.simple$labels)
ss <- performance(pred, "sens", "spec")
plot(ss)

回答1:

"Maximize sensitivity vs. specificity" isn't very precise, because you are trading these quantities off at each point along the ROC curve. To make it more precise, I'll assume you are trying to maximize the sum of these two values. Let's look at your example, which uses ROCR.simple:

library(ROCR)
data(ROCR.simple)
pred <- prediction(ROCR.simple$predictions, ROCR.simple$labels)
ss <- performance(pred, "sens", "spec")
plot(ss)

You can identify the cutoff that yields the highest sensitivity plus specificity with:

ss@alpha.values[[1]][which.max(ss@x.values[[1]]+ss@y.values[[1]])]
# [1] 0.5014893
max(ss@x.values[[1]]+ss@y.values[[1]])
# [1] 1.69993

The highest sensitivity plus specificity is achieved in this case when you predict the positive outcome when the predicted probability exceeds 0.501 and predict the negative outcome when the predicted probability does not exceed 0.501. This yield a sensitivity plus specificity value of 1.7.

Naturally, this can be extended to other functions of the sensitivity and specificity by changing the expression inside the which.max call.



标签: r roc auc