(1)
假设您有一个带有值和真实标签的数据。这里,5假5真
df <- data.frame(value = c(1,2,3,5,8,4,6,7,9,10),
truth = c(rep(0,5), rep(1,5)))
在阈值 9、9 和 10 检测为真阳性,灵敏度 = 40% 在阈值 6(或 5 和 6 之间的任何值)检测到 (6、7、9、10),灵敏度 = 80%
要查看 ROC 曲线,可以使用 pROC 包
library(pROC)
roc.demo <- roc(truth ~ value, data = df)
par(pty = "s") # make it square
plot(roc.demo) # plot ROC curve

如果您想要百分比,请执行以下操作
roc.demo <- roc(truth ~ value, data = df, percent = T)
并将下面的 0.8 替换为 80。
您可以从 roc 对象中获取阈值
roc.demo$thresholds[roc.demo$sensitivities == 0.8]
你可能会看到它说 4.5 和 5.5
你也可以使用 roc.demo$sensitivities > 0.79 & roc.demo$sensitivities < 0.81
(2)
或者,如果您只想要一个阈值并且不关心特异性,您可以尝试分位数功能
quantile(df$value[df$truth == 1],
probs = c(0.00, 0.10, 0.20, 0.30), type = 1) # percentile giving the closest number
probs=0.20 对应 80% 灵敏度
0% 10% 20% 30%
4 4 4 6
任何介于 4 和 6 之间的阈值都是您要寻找的。您可以根据需要更改概率。
希望它有所帮助。