1

我已经成功地在同一个图中创建了一个包含不同预测模型的多条 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
4

1 回答 1

1

控制有效位数的digit参数。print在这种情况下,它匹配小数位数,因为我们介于 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 收到绘图错误时,通常重新创建绘图将解决问题。

于 2020-09-24T13:41:32.703 回答