限制在 pROC 中使用 ROC 曲线打印的 AUC 小数位
Limiting decimals of AUC to be printed with with ROC curve in pROC
我已经成功地在同一个图中创建了一个图,其中包含不同预测模型的多个 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)
哪个 return 调用(一开始看起来很成功):
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)
>
而不是创建新图 returns(如果我滚动浏览我的图并 return 滚动到不起作用的图,则会再次打印相同的消息):
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
print
的 digit
参数控制有效数字的数量。在这种情况下,它匹配小数位数,因为我们介于 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 中收到绘图错误时,通常重新创建绘图即可解决问题。
我已经成功地在同一个图中创建了一个图,其中包含不同预测模型的多个 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)
哪个 return 调用(一开始看起来很成功):
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)
>
而不是创建新图 returns(如果我滚动浏览我的图并 return 滚动到不起作用的图,则会再次打印相同的消息):
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
print
的 digit
参数控制有效数字的数量。在这种情况下,它匹配小数位数,因为我们介于 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 中收到绘图错误时,通常重新创建绘图即可解决问题。