Krambrink, Amy M
2010-Sep-23 00:15 UTC
[R] extending survival curves past the last event using plot.survfit
Hello, I'm using plot.survfit to plot cumulative incidence of an event. Essentially, my code boils down to: cox <-coxph(Surv(EVINF,STATUS) ~ strata(TREAT) + covariates, data=dat) surv <- survfit(cox) plot(surv,mark.time=F,fun="event") Follow-up time extends to 54 weeks, but the last event occurs at week 30, and no more people are censored in between. Is there a direct way to extend the curves with a horizontal line to the end of follow-up (54 weeks), rather than stopping at the time of the last event (30 weeks)? I've pretty much exhausted my search options and didn't see this in a previous thread, so would really appreciate any help or thoughts! Thanks in advance! Amy [[alternative HTML version deleted]]
David Winsemius
2010-Sep-23 03:53 UTC
[R] extending survival curves past the last event using plot.survfit
On Sep 22, 2010, at 8:15 PM, Krambrink, Amy M wrote:> Hello, > > > > I'm using plot.survfit to plot cumulative incidence of an event. > Essentially, my code boils down to: > > cox <-coxph(Surv(EVINF,STATUS) ~ strata(TREAT) + covariates, data=dat) > > surv <- survfit(cox) > > plot(surv,mark.time=F,fun="event") > > Follow-up time extends to 54 weeks, but the last event occurs at week > 30, and no more people are censored in between. Is there a direct way > to extend the curves with a horizontal line to the end of follow-up > (54 > weeks), rather than stopping at the time of the last event (30 weeks)?Not sure if it's the approved method, but this works: > ?survfit.object > ?survfit # to get a working example since you did not provide one > lsurv2 <- survfit(Surv(time, status) ~ x, aml, type='fleming') > plot(lsurv2, lty=2:3, xmax=300) # drats, no effect of xmax > str(lsurv2) # so see the structure of the survfit object > lsurv2$time[21] <- 300 #add a time value > lsurv2$n.censor[21] <- 1 # mark as censoring time > lsurv2$strata[2] <- 11 # add to count of group 2 > > plot(lsurv2, lty=2:3, xmax=300) # horizontal line to 300 for group 2> > > > I've pretty much exhausted my search options and didn't see this in a > previous thread, so would really appreciate any help or thoughts! > > > > Thanks in advance! > > AmyPLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- David Winsemius, MD West Hartford, CT
Terry Therneau
2010-Sep-23 13:35 UTC
[R] extending survival curves past the last event using plot.survfit
On Sep 22, 2010, at 8:15 PM, Krambrink, Amy M wrote:> Hello, > > > > I'm using plot.survfit to plot cumulative incidence of an event. > Essentially, my code boils down to: > > cox <-coxph(Surv(EVINF,STATUS) ~ strata(TREAT) + covariates, data=dat) > > surv <- survfit(cox) > > plot(surv,mark.time=F,fun="event") > > Follow-up time extends to 54 weeks, but the last event occurs at week > 30, and no more people are censored in between. Is there a direct way > to extend the curves with a horizontal line to the end of follow-up > (54 > weeks), rather than stopping at the time of the last event (30 weeks)?The survfit.coxph function only records the survival curve at the death times, so there is no data in the "surv" object about time 54. (This will change in my next bundle of updates, which are currently under test.) You will need to update the survival curves' output by hand. For now this would be the easiest code for multiple strata, at least that I can think of offhand. plot(surv, mark.time=F, fun='event', xlim=c(0, 54)) for (i in 1:length(surv$strata)) { #number of curves temp <- surv[i] lines(c(max(temp$time), 54), 1- rep(min(temp$surv),2)) } Terry Therneau