3
set.seed(888)
y<-sample(c(0,1), 100, replace = TRUE)
x1<-rnorm(100,2,3)
x2<-rnorm(100,1,4)
library(rms)
f1<-lrm(y~x1,,x=TRUE,y=TRUE)
f2<-lrm(y~x2,,x=TRUE,y=TRUE)
plot(calibrate(f1))
plot(calibrate(f2),add=TRUE)

with the above code, it is supposed to add both calibrate plots to the same figure. However, It reported errors:

Warning messages:

1: In plot.window(...) : "add" is not graphical parameter
2: In plot.xy(xy, type, ...) : "add" is not graphical parameter
3: In axis(side = side, at = at, labels = labels, ...) : "add"is not graphical parameter
4: In axis(side = side, at = at, labels = labels, ...) : "add"is not graphical parameter
5: In box(...) : "add"is not graphical parameter
6: In title(...) : "add"is not graphical parameter

Or are there any other methods for this purpose? also I want to specify different colors for x1 and x2 curves. I don't know how to specify the argument par.corrected=list(col="blue"). It does not work.

  plot(calibrate(f2),par.corrected=list(col="blue",lwd=2))

 #n=100   Mean absolute error=0.061   Mean squared error=0.00541
 #0.9 Quantile of absolute error=0.109

Warning messages:

1: In plot.window(...) : "par.corrected"is not graphical parameter 2: In plot.xy(xy, type, ...) : "par.corrected"is not graphical parameter 3: In axis(side = side, at = at, labels = labels, ...) :
"par.corrected"is not graphical parameter 4: In axis(side = side, at = at, labels = labels, ...) : "par.corrected"is not graphical parameter 5: In box(...) : "par.corrected"is not graphical parameter 6: In title(...) : "par.corrected"is not graphical parameter

GGamba
  • 13,140
  • 3
  • 38
  • 47
Z. Zhang
  • 637
  • 4
  • 16

2 Answers2

1

The plot.calibrate function in the rms package does not implement add=TRUE, partly because histograms showing risk distributions would collide. By looking at the code you will see that it is not hard to write your own plotting function to make the plots you need.

Frank Harrell
  • 1,954
  • 2
  • 18
  • 36
0

The following allowed me to plot the bias-corrected calibration curve for f2 on top of the original plot for f1. By examining the contents of the object created by calibrate you can see about plotting other components.

set.seed(888)
y<-sample(c(0,1), 100, replace = TRUE)
x1<-rnorm(100,2,3)
x2<-rnorm(100,1,4)
library(rms)
f1<-lrm(y~x1,,x=TRUE,y=TRUE)
f2<-lrm(y~x2,,x=TRUE,y=TRUE)
f1.cal<-calibrate(f1)
f2.cal<-calibrate(f2)
plot(f1.cal)
lines(f2.cal[,"predy"], cal.plot[,"calibrated.corrected"])