【问题标题】:Limiting decimals of AUC to be printed with with ROC curve in pROC在 pROC 中使用 ROC 曲线打印的 AUC 的小数限制
【发布时间】:2021-01-10 13:53:59
【问题描述】:

我已经成功地在同一个图中创建了一个包含不同预测模型的多条 ROC 曲线的图,并且 AUC 和 CI 的数值很好地打印在了侧面。

但是,我的项目用三位小数打印这些是没有意义的,而是我需要带有两位小数的四舍五入版本,我无法说服 Rstudio 以这种方式打印它......

(澄清一下,上面写着AUC: 0.708 (0.661-0.754),我需要它是0.71(0.66-0.75))。

我试过了:

print(ROC_rfhipfx60X1MOmospugholt, digits = max(3, getOption("digits") -3 ), call= TRUE)

返回调用(起初似乎成功):

Call:
roc.default(response = hipfx_pugely_and_holt_predictions_20200820$`1MO`,     predictor = hipfx_pugely_and_holt_predictions_20200820$`PUGELY RISK %`,     ci = TRUE, plot = TRUE, print.auc = TRUE, col = "red", lwd = 4,     print.auc.y = 0.3, legacy.axes = TRUE, add = TRUE)

Data: hipfx_pugely_and_holt_predictions_20200820$`PUGELY RISK %` in 121 controls (hipfx_pugely_and_holt_predictions_20200820$`1MO` no) > 1050 cases (hipfx_pugely_and_holt_predictions_20200820$`1MO` yes).
Area under the curve: 0.7078
95% CI: 0.6615-0.7542 (DeLong)
> 

它返回而不是创建一个新图(如果我滚动浏览我的图并返回到不工作的图,则会再次打印相同的消息):

Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file '/var/folders/22/nxnj3khn76q9hz0khppd11_40000gn/T/RtmpXrawRS/rs-graphics-7de8e907-4a56-4944-b16e-aeb4054ee835/2473fad9-4618-46c1-9014-fbcb61050b97.snapshot', probable reason 'No such file or directory'
Graphics error: Plot rendering error
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection

【问题讨论】:

  • 您要打印还是绘制曲线?

标签: r roc auc proc-r-package


【解决方案1】:

printdigit 参数控制有效数字的数量。在这种情况下,它匹配小数位数,因为我们介于 0 和 1 之间。所以您可以使用 digits = 2,如下所示:

> library(pROC)
> data(aSAH)
> roc_curve <- roc(aSAH$outcome, aSAH$ndka)
Setting levels: control = Good, case = Poor
Setting direction: controls < cases
> print(roc_curve, digits = 2)

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$ndka, ci = TRUE)

Data: aSAH$ndka in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Area under the curve: 0.61
95% CI: 0.5-0.72 (DeLong)

对于绘图,我建议您单独使用plot 函数。您应该自定义 print.auc.pattern 参数,以绘制带有两位小数的数字(这次不是有效位数):

plot(roc_curve, print.auc = TRUE, col = "red", lwd = 4, print.auc.y = 0.3, legacy.axes = TRUE, print.auc.pattern = "%.2f (%.2f-%.2f)")

当您从 Rstudio 收到绘图错误时,通常重新创建绘图可以解决问题。

【讨论】:

  • 非常感谢!!终于解决了这个问题,我用 print.auc.pattern = "%.2f (%.2f-%.2f) 插入了一个新图。
  • 我实际上之前尝试过,但是我从其他地方获得了“%#.2f”,但没有成功。所以“2f”表示2个格式化小数,“%”就像“x”,括号是这样的,它甚至适用于括号中的数字?那是我应该如何阅读代码吗?非常感谢您的帮助,真是如释重负!
  • 乐于助人。格式与 sprintf 函数的文档中描述的完全相同:rdocumentation.org/packages/base/versions/3.6.2/topics/sprintf
  • 括号在这里没有具体含义,它们出现在最终输出中,只是您正在格式化3个数字。所以你可以玩得开心,说 print.auc.pattern = "%.10f, and the confidence interval is %.4f-%.1f!!!" 有 10、4 和 1 位小数以及一些额外的文本和感叹号。
猜你喜欢
  • 2012-04-15
  • 1970-01-01
  • 2019-04-11
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 2018-05-29
相关资源
最近更新 更多