[R] survplot() for cph(): Design vs rms

array chip arrayprofile at yahoo.com
Thu Aug 25 23:11:40 CEST 2011


Hi, in Design package, a plot of survival probability vs. a covariate can be generated by survplot() on a cph object using the folliowing code:

n <- 1000
set.seed(731)
age <- 50 + 12*rnorm(n)
label(age) <- "Age"
sex <- factor(sample(c('male','female'), n, TRUE))
cens <- 15*runif(n)
h <- .02*exp(.04*(age-50)+.8*(sex=='Female'))
dt <- -log(runif(n))/h
label(dt) <- 'Follow-up Time'
e <- ifelse(dt <= cens,1,0)
dt <- pmin(dt, cens)
units(dt) <- "Year"
dd <- datadist(age, sex)
options(datadist='dd')
S <- Surv(dt,e)


library(Design)

f <- cph(S ~ age, surv=TRUE,x=T,y=T)
plot(f,age=NA,time=5)

But the same code won't work if I used rms package:

detach(package:Design)
library(rms)

f <- cph(S ~ age, surv=TRUE,x=T,y=T)

plot(f,age=NA,time=5)
Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ


Is there a way to plot the same graph using rms package. I like to use Frank Harrell's new package rms and try to avoid using old Design package.

Thanks

John



More information about the R-help mailing list