Re: [R] help on pspline in coxph

From: Terry Therneau <>
Date: Thu, 07 Apr 2011 08:44:37 -0500

> 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 mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 07 Apr 2011 - 13:47:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 13:50:27 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive