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

How to fill in AUC of a ROC plot in R?

我有这个 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)

...并得到错误信息:Error in xy.coords(x, y) : 'x' and 'y' lengths differ.

如何计算长度?

尝试

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)

pROC 中的 plot.roc 函数已构建参数以启用 (auc.polygon) 和调整 (auc.polygon.colauc.polygon.border 等,请参阅 ?plot.roc) AUC 的显示。在您的情况下,您可以使用:

plot.roc(data$outcome, data$s100b, 
    auc.polygon = TRUE, 
    auc.polygon.col=rgb(.35,0.31,0.61, alpha = 0.4), 
    auc.polygon.border=rgb(.35,0.31,0.61, 0.4))