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
I also tried fitting a spline to the resulting survival curve and the result was horrible. maybe spline won't work or knots need special handling. overall, I must have the final point of the smooth survival to be same as the final point of the raw Cox survival and no flat days, the drops should be spread around. Thanks again everybody. Stephen
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
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) plot(testcurve) 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 ---