【R】标注ROC曲线上最佳cutoff点

前面小编跟大家分享过

今天我们来聊一下怎么将这个最优的cutoff值对应的点在ROC曲线上面标注出来。废话不多说,直接上代码

############################
#youden方法
############################
library(pROC)
#加载数据
data("aSAH")
#进行分析
roc.out <- roc(aSAH$outcome, aSAH$s100b)
roc.out$auc
#找到最优cutoff点
best=coords(roc.out, "best",best.method = c("youden"), ret=c("threshold","sensitivity", "specificity"))
#绘制ROC曲线
plot(roc.out)
#标注最优cutoff点
points(best[3],best[2],pch="*",col="red",cex=2)
#标注最优cutoff的坐标
text(best[3],best[2]+0.05,paste0("(",round(best[3],2),",",round(best[2],2),")"))


########################
#closest.topleft方法
#######################
library(pROC)
#加载数据
data("aSAH")
#进行分析
roc.out <- roc(aSAH$outcome, aSAH$s100b)
#找到最优cutoff点
opt.coords <- coords(roc.out, "best", best.method = c("closest.topleft"), ret=c("threshold","sensitivity", "specificity"))
#绘制ROC曲线
plot(roc.out)
#标注最优cutoff点
points(opt.coords[3],opt.coords[2],pch="*",col="red",cex=2)
#标注最优cutoff的坐标
text(opt.coords[3],opt.coords[2]+0.05,paste0("(",round(opt.coords[3],2),",",round(opt.coords[2],2),")"))

我们可以得到下面的图


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容