1

我想知道是否有办法在我的 ROC 图上进一步注释打印的 AUC?

目前,尚不清楚 AUC 在我的图中属于哪条线(下图)。我想添加更多描述,使文本看起来像:

  • FI 的 AUC:0.506
  • FP 的 AUC:0.468

有没有办法在 pROC::roc() 函数中做到这一点?

在此处输入图像描述

这是一个使用测试数据的可生产示例:

library(pROC)

testdata = structure(list(outcome = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c("0", 
"1"), class = "factor"), fi = c(0.0395, 0.0835, 0.03975, -0.079, 
-0.00825000000000001, NA, NA, -0.0125, -0.04175, -0.09375, -0.02275, 
0.01675, 0.03325, -0.0165, 0.0165, 0.0585, -0.04175, NA, -0.004, 
0.05, 0.0165, -0.0335, -0.01225, -0.025, 0.01225, NA, 0.05425, 
0.08125, 0.07925, NA, NA, -0.00625, 0.05, 0.06875, NA, 0.0645, 
NA, -0.00625000000000001, 0.03125, 0.07275, 0.00625, 0.027, 0.0665, 
0.023, 0.046, -0.1875, -0.2, -0.002, -0.10225, 0.0605), fp = c(-2, 
-1, -1, -1, 0, NA, NA, 0, 0, -1, 1, 0, 0, 1, NA, NA, -1, NA, 
0, NA, NA, NA, NA, NA, 0, NA, NA, 1, NA, NA, NA, 1, 1, -1, NA, 
NA, NA, 0, 0, NA, 1, 0, NA, 0, 1, 1, 2, 0, 0, -1)), class = "data.frame", row.names = c(NA, 
-50L))


par(pty="s") # change the graphical parameter pty to s before calling plot.roc so that the margins are outside the plot
plot(roc(testdata[["outcome"]], testdata[["fi"]]), print.auc=TRUE, col="black", lty=1, lwd=2, legacy.axes = TRUE, print.auc.y=.35, grid=TRUE)
plot(roc(testdata[["outcome"]], testdata[["fp"]]), print.auc=TRUE, col="black", lty=3, lwd=2, legacy.axes = TRUE, print.auc.y=.3, grid=TRUE, add=TRUE)
legend("bottomright",
       legend=c("Frailty Index", "Frailty Phenotype"),
       col=c("black", "black"),
       lty=c(1,3),
       lwd=c(2,2))
myroc = recordPlot() # saves current plot
4

1 回答 1

2

您可以print.auc=FALSE使用以下方法设置然后添加文本text

roc_fi <- roc(testdata[["outcome"]], testdata[["fi"]])
roc_fp <- roc(testdata[["outcome"]], testdata[["fp"]])

plot(roc_fi, print.auc=FALSE, col="black", lty=1, lwd=2, legacy.axes = TRUE, print.auc.y=.35, grid=TRUE)
plot(roc_fp, print.auc=FALSE, col="black", lty=3, lwd=2, legacy.axes = TRUE, print.auc.y=.3, grid=TRUE, add=TRUE)
legend("bottomright",
       legend=c("Frailty Index", "Frailty Phenotype"),
       col=c("black", "black"),
       lty=c(1,3),
       lwd=c(2,2))

text(0.4, 0.4, paste("AUC for FI:", round(roc_fi$auc, 3)))
text(0.4, 0.35, paste("AUC for FP:", round(roc_fp$auc, 3)))
于 2020-05-07T13:37:15.827 回答