Dear Dr. Harrell, Thanks for response so quickly. Here is example code to illustrate the problem.
> n <- 1000 > set.seed(731) > age <- 50 + 12*rnorm(n) > label(age) <- "Age" > sex <- factor(sample(c('Male','Female'), n, + rep=TRUE, prob=c(.6, .4))) > 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" > dat <- data.frame(dt,e,age,sex) > dd <- datadist(dat) > options(datadist='dd') > f1 <- cph( Surv(dt,e) ~ rcs(age,4) + sex, data=dat,x=TRUE, y=TRUE, surv=TRUE) > f2 <- cph( Surv(dt,e)~ age + strat(sex), data=dat, x=TRUE, y=TRUE,surv=TRUE) > Function(f1) # works well function(age = 48.800654,sex = "Male") {0.28612987-0.017321951* age+0.00012586581*pmax(age-29.600456,0)^3-0.00046285671*pmax(age-44.2731 98,0)^3+0.00042111763*pmax(age-53.769262,0)^3-8.4126731e-05*pmax(age-69. 855597,0)^3-0.64448916*(sex=="Male") } <environment: 0x02c2aef4> > Function(f2) Error in Nam[[i]] : subscript out of bounds I am using Windows R ( version 2.6.0 2007-10-03). Best regards, Changhong Yu -----Original Message----- From: Frank E Harrell Jr [mailto:f.harr...@vanderbilt.edu] Sent: Thursday, December 11, 2008 6:58 PM To: Yu, Changhong Cc: r-help@r-project.org Subject: Re: [R] How to generate a prediction equation for a stratified survival model that was fitted by cph() in Design package Yu, Changhong wrote: > Dear all, > > I used cph() function from Frank harrell's Design package to create a > survival model, then used functions 'Function' and 'sascode' to generate > prediction equation based on the saved survival model. But it failed. I > included a stratified variable in the model. If I removed the > stratification, they were working well. Does that mean that function > 'Function' doesn't accept a stratified model? It is supposed to work for that case. Please send trivial example code with data defined in the code that replicates the problem you are seeing, and I'll debug. Frank > > Any thoughts on this will be appreciated. Thanks. > > > Changhong > > =================================== > > P Please consider the environment before printing this e-mail > > Cleveland Clinic is ranked one of the top hospitals > in America by U.S. News & World Report (2008). > Visit us online at http://www.clevelandclinic.org for > a complete listing of our services, staff and > locations. > > > Confidentiality Note: This message is intended for use\...{{dropped:13}} > > ______________________________________________ > R-help@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. > -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S. News & World Report (2008). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} ______________________________________________ R-help@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.