我想知道是否有办法在我的 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