2016-02-21 34 views
1

我有這樣的ROC曲線:如何在R中填寫ROC圖的AUC?

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

pROCplot.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)) 
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) 
+0

謝謝。這是有用的,但它只是從對角線向上 - 不是整個表面的0.7,還是它?我可能會感到困惑...... – Toni

+2

@Toni你是否接受了這個答案並嘗試了一下自己? (可能是(res,cbind(特性,敏感性)),c(0,0))? – rawr