[R] coxph with smooth survival

Terry Therneau therneau at mayo.edu
Mon Jan 21 15:14:17 CET 2013

For your first question -- read the manual.  ?survfit.coxph will reveal the "censor" 
argument, which controls the inclusion of points where the curve does not drop.

For your second, "smooth" is in the eye of the beholder, literally.  If the reason for a 
smooth curve is to plot it, you need to decide how many x-values you want across the range 
of the plotting window, I find 50 to 100 to be enough.
You also need to decide how many degrees of freedom for the spline.  If you are using the 
interpolates for prediction then you need to think through what the statistical properties 
of the smoothed estimates might be.

Here's an example where the default df of smooth.spline doesn't work so well

testfit <- coxph(Surv(time, status) ~ age + sex , data=lung, subset=(ph.ecog==2))
testcurve <- survfit(testfit, data.frame(age=65, sex=2), censor=FALSE)  # prediction for 
65 yr old female
testspl <- smooth.spline(testcurve$time, testcurve$surv)
xx <- seq(0, 800, length=100)
lines(predict(testspl, xx), col=2)

Terry T.

---  begin included message ----
Hello users,

I would like to obtain a survival curve from a Cox model that is smooth and does not have 
zero differences due to no events for those particular days.
I have:
 > sum((diff(surv))==0)
[1] 18

So you can see 18 days where the survival curve did not drop due to no events.

Is there a way to ask survfit to fit a nice spline for the survival??

Note: I tried survreg and it did not work, but maybe I did not do it properly??

Thank you very much.

Stephen B

--- end inclusion ---

More information about the R-help mailing list