[R] help on pspline in coxph

Terry Therneau therneau at mayo.edu
Thu Apr 7 15:44:37 CEST 2011


> Hi there,

> I have a question on how to extract the linear term in the penalized 
> spline in coxph. Here is a sample code:

Here is a slightly more general example: 
   fit <- coxph(Surv(time, status) ~ ph.ecog + pspline(age) + sex, lung)
(The lung data set is part of the survival package.)
There are 14 coefficients, of which 2-13 are the for the spline.  

The slope logic is subtle. Luckily I left comments on this in the source
code for pspline, because I remember it taking a long time for me to
figure it out.  
      slope = (X'VX)^{-1} X'V c
A weighted regression on the coefficients where c= spline coefficients =
fit$coef[2:13] in this case, V= fit$var[2:13,2:13], and X is a two
column matrix with column 1=1 (intercept) and column 2 = centers of the
pspline basis functions.  These centers are saved away in the print
function:
	get("cbase", environment(fit$printfun[[1]]))
If there were multiple psline terms in the fit use [[2]], [[3]] etc as
appropriate.  No, you won't find this without reading the source code.

  Note that this is the linear slope from a fit with only a linear term,
i.e., what would have resulted from a fit with "age" instead of
pspline(age).  I thought it quite interesting that this quantity could
be derived at all.  I leave the details as a homework exercise for the
reader.

Terry Therneau



More information about the R-help mailing list