[R] survplot() for cph(): Design vs rms
David Winsemius
dwinsemius at comcast.net
Fri Aug 26 00:15:11 CEST 2011
On Aug 25, 2011, at 5:11 PM, array chip wrote:
> 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 don't remember what that would have done in Design and you have not
explained what you expected. You should read the rms help page for cph
and walk through the examples where ht euse of the Predict function is
illustrated. The plotting support for Predict objects is excellent.
> I like to use Frank Harrell's new package rms and try to avoid using
> old Design package.
>
> Thanks
>
> John
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list