I have successfully created a plot with multiple ROC curves of different prediction models in the same plot and the numerical value of the AUC and CI is printed nicely on the side.
However it makes no sense for my project to have these printed with three decimals, rather I need the rounded version with two decimals and I have not been able to convince Rstudio to print it this way...
(to clearify, it says AUC: 0.708 (0.661-0.754)
and I need it to be 0.71 (0.66-0.75)).
I tried:
print(ROC_rfhipfx60X1MOmospugholt, digits = max(3, getOption("digits") -3 ), call= TRUE)
which returns the call (seemingly succesfull at first):
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)
>
And instead of creating a new plot it returns (same message gets printed again if I scroll through my plots and return to the one that is not working):
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
The digit
argument to print
controls the number of significant digits. In this case it matches the number of decimals, as we are between 0 and 1. So you can use digits = 2
, like so:
> 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)
For plots I suggest you use the plot
function separately. You should customize the print.auc.pattern
argument, to plot the numbers with two decimals (this time it's not the number of significant digits):
plot(roc_curve, print.auc = TRUE, col = "red", lwd = 4, print.auc.y = 0.3, legacy.axes = TRUE, print.auc.pattern = "%.2f (%.2f-%.2f)")
When you get plot errors from Rstudio, most often creating the plot fresh again will solve the problem.