[R] predict()

Terry Therneau therneau at mayo.edu
Thu Apr 14 14:59:50 CEST 2011


--- begin included message ---
I am experimenting with the function predict() in two versions of R and
the R extension package "survival".

library(survival)

set.seed(123)
testdat=data.frame(otime=rexp(10),event=rep(0:1,each=5),x=rnorm(10))
testfm=as.formula('Surv(otime,event)~x')

testfun=function(dat,fm)
  {
    predict(coxph(fm,data=dat),type='lp',newdata=dat)
  }

-- end inclusion ----

 The question was: this works under survival 2.35-8, but not survival
2.36-5

Answer: The predict and underlying model.frame functions for coxph were
brought into line with lm and other models.  The major advantage is that
I now deal with factors and data dependent predictors like ns()
correctly.
  You've shown a disadvantage of which I was not aware.  Using your
example but replacing coxph() by lm() with otime ~x as the model I get a
similar failure.  I'd like to ask a wider audience of R-devel since it
is bigger than coxph.

Terry Therneau



More information about the R-help mailing list