[R] coxph with smooth survival

Andrews, Chris chrisaa at med.umich.edu
Fri Jan 18 13:47:35 CET 2013


survreg does work.  Hard to tell what went wrong without any code from you.

As for smoothing a Cox survival function, see example below.  However, just because you can, doesn't mean you should.

Chris


library(survival)
nn <- 10
zz <- rep(0:1, nn)
xx <- rexp(2*nn)
cc <- rexp(2*nn)
tt <- pmin(xx, cc)
dd <- xx <= cc

mod <- coxph(Surv(tt,dd)~zz)
sf <- survfit(mod)

steps.y <- sf[[c("surv")]][c(1,1+which(diff(sf[[c("surv")]])<0))]
steps.x <- sf[[c("time")]][c(1,1+which(diff(sf[[c("surv")]])<0))]

plot(sf, conf.int=FALSE)
lines(steps.x, steps.y, col=2)

smoothfun <- approxfun(steps.x, steps.y)
plot(smoothfun, from=0, to=3, add=TRUE, col=3, n=1000, lty=2)



-----Original Message-----
From: Bond, Stephen [mailto:Stephen.Bond at cibc.com] 
Sent: Thursday, January 17, 2013 9:49 AM
To: r-help at r-project.org
Subject: [R] coxph with smooth survival

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


**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues 



More information about the R-help mailing list