R的ROC曲线置信区间

发布于 2025-02-09 10:22:59 字数 952 浏览 2 评论 0 原文

我创建了用于显示ROC曲线的置信区间的代码,均为logistic和随机森林。但是我想在X轴上具有1-特异性而不是特异性。 代码为

roc.list <- roc(test_df$extry ~ Logistic_Regression+Random_Forest)
ci.list <- lapply(roc.list, ci.se, specificities = seq(0, 1, l = 10))

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,legacy.axes=TRUE) + 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

且输出: ” 有什么想法吗?

I have created the code for displaying a confidence interval for the ROC curve for both Logistic and Random Forest. But I would like to have 1- specificity in the x-axis instead of specificity.
The code is

roc.list <- roc(test_df$extry ~ Logistic_Regression+Random_Forest)
ci.list <- lapply(roc.list, ci.se, specificities = seq(0, 1, l = 10))

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,legacy.axes=TRUE) + 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

And the output: ThE CI is weird.
Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚雾 2025-02-16 10:22:59

我假设您正在使用 ggroc 函数从 proc 软件包中使用。

当您使用 laceacy.axes = true 运行 ggroc 时, ggplot 函数在以下美学中调用:

aes(x = "1-specificity", y = "sensitivity")

@allan cameron 在评论中,您需要指定在x:x::

p <- p + geom_ribbon(
     data = dat.ci.list[[i]],
     aes(x = 1 - x, ymin = lower, ymax = upper),
     fill = i + 1,
     alpha = 0.2,
     inherit.aes = F) 

I assume you are using the ggroc function from the pROC package.

When you run ggroc with legacy.axes=TRUE, the ggplot function is called with the following aesthetics:

aes(x = "1-specificity", y = "sensitivity")

As identified by @Allan Cameron in the comments, you need to specify compatible aesthetics that specify 1-specificity in x:

p <- p + geom_ribbon(
     data = dat.ci.list[[i]],
     aes(x = 1 - x, ymin = lower, ymax = upper),
     fill = i + 1,
     alpha = 0.2,
     inherit.aes = F) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文