[R] some question about partial prediction in survival

Thomas Lumley tlumley at u.washington.edu
Mon Oct 15 17:09:18 CEST 2007


On Sun, 14 Oct 2007, coldeyes.Rhelp wrote:

> Hi there:
> i got a problem to get the prediction from a model recently.  for
> example if i use a survival analysis to predict the risk. i use the code
> like below: i found the the prediction is not equal to (coef * x + coef
> * sex) , could someone help me with why this happened?

The intercept is not identifiable in a Cox model, and the code takes 
advantage of this to center the variables.  The predicted values are the 
values you expected, minus the mean.

For the example in ?predict.coxph
R> fit<-coxph(Surv(time,status)~x,data=aml)
R> predict(fit)
          1          2          3          4          5          6          7
-0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692
          8          9         10         11         12         13         14
-0.4776692 -0.4776692 -0.4776692 -0.4776692  0.4378634  0.4378634  0.4378634
         15         16         17         18         19         20         21
  0.4378634  0.4378634  0.4378634  0.4378634  0.4378634  0.4378634  0.4378634
         22         23
  0.4378634  0.4378634
R> sum(predict(fit))
[1] 7.21645e-16
R> a<-coef(fit)*(aml$x=="Nonmaintained")
R> a-mean(a)
  [1] -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692
  [7] -0.4776692 -0.4776692 -0.4776692 -0.4776692 -0.4776692  0.4378634
[13]  0.4378634  0.4378634  0.4378634  0.4378634  0.4378634  0.4378634
[19]  0.4378634  0.4378634  0.4378634  0.4378634  0.4378634


>							 and  can someone
> explain to me how this command "predict(f, type="terms")" works? is
> every partial prediction equal to coef*x=predict(f,type="terms")[,1] and
> coef*sex=predict(f,type="terms")[,2]?  it looks like they did not match.
> however
> "predict(f)=predict(f,type="terms")[,1]+predict(f,type="terms")[,2]"

The same thing happens here. Each column of predict(,type="terms") sums to 
zero.  In this case it is the same behaviour as  lm() and glm().

 	-thomas



More information about the R-help mailing list