[R] Problem with predict.coxph

Terry Therneau therneau at mayo.edu
Wed Aug 19 17:53:42 CEST 2009

-- begin included message ---
We occasionally utilize the coxph function in the survival library to
fit multinomial logit models. (The breslow method produces the same
likelihood function as the multinomial logit). We then utilize the
predict function to create summary results for various combinations of
covariates.  For example:


The problem is that under R 2.8.1 and R 2.9.1 the previous line fails
with the following error:

> totalut<-predict(mod1,newdata=newdata,type="lp")
Error in model.frame.default(Terms2, newdata, xlev = object$xlevels) :
  variable lengths differ (found for 'Price')
In addition: Warning message:
'newdata' had 25 rows but variable(s) found have 43350 rows

-----------end inclusion --------------

 The coxph code was updated to use the "standard" R methods for
prediction with factors.  I even added test cases -- but obviously I've
missed something.  I'll look into a fix and get back to you.  
  Can I assume that Price and Product were both factors with the 5
levels 1:5?

	Terry Therneau

More information about the R-help mailing list