calculate cut-off that max sensitivity vs specific

2019-05-30 10:59发布

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)

标签: r roc auc
1条回答
对你真心纯属浪费
2楼-- · 2019-05-30 11:48

"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)

enter image description here

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.

查看更多
登录 后发表回答