[R] Enquiry about 2nd-order interactions survival analysis

Terry Therneau therneau at mayo.edu
Mon Nov 14 13:59:56 CET 2011

David's answers were correct.  You are looking deep into the code when
there is no reason to to so.

1. h(t|(X=x,Z=z)) = exp(Beta0 + XZBeta1) 
Most statisticians will tell you that this is an unwise model.  The
reason is that if you replace X with "X+1" the fit changes, which is
almost never desirable.  What if someone coded your dummy variable as
1/0 instead of 0/1 -- wouldn't you want to get the same fit
  Therefore the default in R for the model
     lm(y ~ x*z)
is to fit  y = b0 + b1 x + b2 z + b3 xz

   You can get exactly the model you specify as lm(y ~ x:z), or as
             temp <- x*z; lm(y ~ temp) 
Statistically, this is almost surely a mistake.

2. The model formulas work across packages.  I used lm() above, but
survreg is no different.  Formula processing is done by the
model.matrix() function, which survreg, lm, glm, ....  all call.  My C
code is all downstream of this, and irrelevant to your question.

Terry T

On Sun, 2011-11-13 at 14:39 +0800, Kenji Ryusuke wrote:
> Dr Terry Therneau,
> Firstly I do apologize upon unsolicited email. I know about Dr Terry
> through R package "survival" and alot of your papers.
> As we know Equation(1) is a normal parametric survival analysis, I'ld
> like to modify it to be a 2nd-order interactions as in Equation(2) :- 
>     h(t|X=x)      = exp(Beta0 + XBeta1)  ------- (1)
> h(t|(X=x,Z=z)) = exp(Beta0 + XZBeta1) ------ (2)
> Where x and z are two covariates: 
> x = dummy variable (1 or 0) 
> z = factors (people name)
> I would like to modify survreg() to be a second-order interactions
> regression while there is no 2nd-order interactions survival
> regression as I searched over www.rseek.org. I tried to read through
> the codes of survreg(), but I am stuck (cannot understand) at
> survreg6.c 
> survreg6.c apply C Language which involves Cholesky decomposition
> multi-matrix (first-order interactions) calculation. 
> 1) chinv2.c 
> 2) cholesky3.c 
> 3) chsolve2.c (only solve the equations of first-order interactions) 
> I do appreciate if Dr Terry willing to enlighten me.
> Thank you. 
> Best, 
> Ryusuke

More information about the R-help mailing list