[R] error message trying to plot survival curves from hypothetical covariate profiles

Simon Kiss sjkiss at gmail.com
Tue Jun 14 22:23:05 CEST 2011


Dear colleagues, 
following John Fox' advice in this article (http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf), I'm trying to create a new data frame to examine the differential survival curves from a combination of covariates.
These are derived from a Cox Proportional Hazards model I fit to data about the diffusion of a particular policy across American states over a period of 7 years.

The original dataset looks as follows:
'data.frame':	819 obs. of  10 variables:
 $ state   : Factor w/ 39 levels "Alabama","Arkansas",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ year    : num  2005 2005 2005 2006 2006 ...
 $ enviro  : num  0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 ...
 $ ban     : num  0 0 0 0 0 0 0 0 0 0 ...
 $ partisan: Factor w/ 3 levels "democrat","mixed",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ news    : num  0 0 0 0 0 0 0 0 0 0 ...
 $ start   : num  2005 2005 2005 2006 2006 ...
 $ stop    : num  2006 2006 2006 2007 2007 ...
 $ risk    : num  1 2 3 1 2 3 1 2 3 1 ...
 $ evstatus: num  0 0 0 0 0 0 0 0 0 0 ...

I am modelling the survival time until the adoption of the policy as follows:

mod1<-Surv(newdat$start, newdat$stop, newdat$evstatus)
mymod1<-coxph(mod1 ~ news + enviro + partisan + cluster(state) + strata(evstatus), method=c("efron"), robust=TRUE)

Again, following Fox, I try to construct a data frame with a hypothetical covariate profile:

n<-data.frame(news=rep(c(1,4,8)), evstatus=as.factor(1:3), enviro=mean(newdat$enviro), partisan=c("democrat", "mixed", "republican"))
plot(survfit(mymod1, newdata=n))

Error in scale.default(x2, center = xcenter, scale = FALSE) : 
  length of 'center' must equal the number of columns of 'x'

I've looked and someone encountered a similar error trying to plot predicted values from a stepwise regression. That issue did not appear to be solved.  
On the surface of it it seems that I need to expand the 'n' data frame to have an equal number of columns as the original (newdat), although perusing Fox's data and instructions, that does not appear to be the case there, so I'm a little bit lost.

Any guidance is appreciated 
Yours truly,
Simon J. Kiss
*********************************
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 905 746 7606



More information about the R-help mailing list