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

微笑、不失礼 提交于 2020-01-03 03:17:08

问题


I have this ROC plot:

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

I want to color the Area under the curve: 0.7314.

I tried variations on...

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)

... and get the error message: Error in xy.coords(x, y) : 'x' and 'y' lengths differ.

How can I make the lengths work out?


回答1:


The plot.roc function from pROC has built parameters to enable (auc.polygon) and tune (auc.polygon.col, auc.polygon.border, etc., see ?plot.roc) the display of the AUC. In your case you could use:

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



回答2:


Try

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)


来源:https://stackoverflow.com/questions/35539581/how-to-fill-in-auc-of-a-roc-plot-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!