如何在pROC中绘制具有置信区间的多条roc曲线?
此代码可以绘制具有置信区间的roc曲线:如何在pROC中绘制具有置信区间的多条roc曲线?,r,roc,proc-r-package,R,Roc,Proc R Package,此代码可以绘制具有置信区间的roc曲线: ciobj <- ci.se(obj, specificities=seq(0, 1, l=25)) dat.ci <- data.frame(x = as.numeric(rownames(ciobj)), lower = ciobj[, 1], upper = ciobj[, 3]) ggroc(obj) + theme_minimal() + geom
ciobj <- ci.se(obj, specificities=seq(0, 1, l=25))
dat.ci <- data.frame(x = as.numeric(rownames(ciobj)),
lower = ciobj[, 1],
upper = ciobj[, 3])
ggroc(obj) + theme_minimal() + geom_abline(slope=1, intercept = 1, linetype = "dashed", alpha=0.7, color = "grey") + coord_equal() +
geom_ribbon(data = dat.ci, aes(x = x, ymin = lower, ymax = upper), fill = "steelblue", alpha= 0.2) + ggtitle(capture.output(obj$ci))
它将返回一个错误:可能有一种更优雅的方法来执行此操作,但以下是对我有效的方法:
library(pROC)
roc.list <- roc(outcome ~ s100b + ndka + wfns, data = aSAH)
ci.list <- lapply(roc.list, ci.se, specificities = seq(0, 1, l = 25))
dat.ci.list <- lapply(ci.list, function(ciobj)
data.frame(x = as.numeric(rownames(ciobj)),
lower = ciobj[, 1],
upper = ciobj[, 3]))
p <- ggroc(roc.list) + theme_minimal() + geom_abline(slope=1, intercept = 1, linetype = "dashed", alpha=0.7, color = "grey") + coord_equal()
for(i in 1:3) {
p <- p + geom_ribbon(
data = dat.ci.list[[i]],
aes(x = x, ymin = lower, ymax = upper),
fill = i + 1,
alpha = 0.2,
inherit.aes = F)
}
p
库(pROC)
谢谢你!那正是我想要的。
ggroc(roc.list) + theme_minimal() + geom_abline(slope=1, intercept = 1, linetype = "dashed", alpha=0.7, color = "grey") + coord_equal() +
geom_ribbon(data = dat.ci, aes(x = x, ymin = lower, ymax = upper), fill = "steelblue", alpha= 0.2) + ggtitle(capture.output(obj$ci))
library(pROC)
roc.list <- roc(outcome ~ s100b + ndka + wfns, data = aSAH)
ci.list <- lapply(roc.list, ci.se, specificities = seq(0, 1, l = 25))
dat.ci.list <- lapply(ci.list, function(ciobj)
data.frame(x = as.numeric(rownames(ciobj)),
lower = ciobj[, 1],
upper = ciobj[, 3]))
p <- ggroc(roc.list) + theme_minimal() + geom_abline(slope=1, intercept = 1, linetype = "dashed", alpha=0.7, color = "grey") + coord_equal()
for(i in 1:3) {
p <- p + geom_ribbon(
data = dat.ci.list[[i]],
aes(x = x, ymin = lower, ymax = upper),
fill = i + 1,
alpha = 0.2,
inherit.aes = F)
}
p