Skip to content
Prev 359716 / 398502 Next

Convergence issues when using ns splines (pkg: spline) in Cox model (coxph) even when changing coxph.control

Thanks to David for pointing this out.  The "time dependent covariates" vignette in the 
survival package has a section on time dependent coefficients that talks directly about 
this issue.  In short, the following model is simply wrong:
      coxph(Surv(time, status) ~ trt + prior + karno + I(karno * log(time)), data=veteran)

People try this often as a way to create the time dependent covariate  Karnofsky * log(t), 
which is often put forwards as a way to deal with non-proportional hazards.  To do this 
correctly you have to use the tt() functionality in coxph to move the computation out of 
the model statement:
       coxph(Surv(time, status) ~ trt + prior + karno + tt(karno), data=veteran,
	    tt = function(x, time, ...) x*log(time))


BTW the following SAS code is also wrong:
      proc phreg data=veteran;
          model time * status(0) = trt + prior + karno* time;

SAS does the right thing, however, if you move the computation off the model line.
	  model time * status(0) = trt + karno + zzz;
           zzz = karno * time;

The quote "SAS does it but R fails" comes at me moderately often in this context.  The 
reason is that SAS won't LET you put a phrase like "log(time)" into the model statement, 
so people end up doing the right thing, but by accident.

Terry T.
On 03/30/2016 05:28 PM, G?ran Brostr?m wrote: