如何在R中填写ROC图的AUC?

时间:2016-02-21 17:43:46

标签: r roc

我有这个ROC情节:

library(Epi)
library(pROC)
data(aSAH)
data <- aSAH
plot.roc(data$outcome, data$s100b)

我想为Area under the curve: 0.7314着色。

我试过......

x <- seq(1, 0, by = - .001)
polygon(x, roc(data$outcome, data$s100b), 
        col = rgb(.35,0.31,0.61, alpha = 0.4), 
        border = rgb(.35,0.31,0.61, 0.4),
        lwd=2)

enter image description here ...并收到错误消息:Error in xy.coords(x, y) : 'x' and 'y' lengths differ

如何才能完成任务?

2 个答案:

答案 0 :(得分:2)

来自plot.roc的{​​{1}}功能已构建参数以启用(pROC)和调整(auc.polygonauc.polygon.col等,请参阅{{1 })AUC的显示。在您的情况下,您可以使用:

auc.polygon.border

答案 1 :(得分:1)

尝试

library(Epi)
library(pROC)
data(aSAH)
data <- aSAH
res <- plot.roc(data$outcome, data$s100b)
polygon(with(res, cbind(specificities, sensitivities)), 
        col = rgb(.35,0.31,0.61, alpha = 0.4), 
        border = rgb(.35,0.31,0.61, 0.4),
        lwd=2)