I have an dataset in which a time-varying covariate has a strong effect on subsequent risk.
I would like to "illustrate" this effect by comparing the estimated survival curve for a typical individual who does not experience the intervening event to one who does at a particular time.
In the documentation for the rms package in R, there is an example that appears to be very similar in spirit.
(Though I refer to R software here [and paste the example code], I do not believe this is an R-specific question. It may be conceptual.)
In the example, the estimated survival curve for an individual who does not experience the intervening event at 5 days is compared to the curve for one who does.
However, though the two curves differ, they do not differ starting at day 5. They differ all the way back to day 0.
Time-dependent covariates are a challenging topic, but I would have expected the two curves to coincide until day 5, at which point the second individual's estimated survival would be reduced to reflect the newly acquired risk factor.
Perhaps my goal is misguided and I have misunderstood the approach.
Any explanations, pointers, references, etc. would be most appreciated.
Here is the example copied from
help(cph). It assumes you have loaded the
#Fit a time-dependent covariable representing the instantaneous effect #of an intervening non-fatal event rm(age) set.seed(121) dframe <- data.frame(failure.time=1:10, event=rep(0:1,5), ie.time=c(NA,1.5,2.5,NA,3,4,NA,5,5,5), age=sample(40:80,10,rep=TRUE)) z <- ie.setup(dframe$failure.time, dframe$event, dframe$ie.time) S <- z$S ie.status <- z$ie.status attach(dframe[z$subs,]) # replicates all variables f <- cph(S ~ age + ie.status, x=TRUE, y=TRUE) #Must use x=TRUE,y=TRUE to get survival curves with time-dep. covariables #Get estimated survival curve for a 50-year old who has an intervening #non-fatal event at 5 days new <- data.frame(S=Surv(c(0,5), c(5,999), c(FALSE,FALSE)), age=rep(50,2), ie.status=c(0,1)) g <- survfit(f, new) plot(c(0,g$time), c(1,g$surv[,2]), type='s', xlab='Days', ylab='Survival Prob.') # Not certain about what columns represent in g$surv for survival5 # but appears to be for different ie.status #or: #g <- survest(f, new) #plot(g$time, g$surv, type='s', xlab='Days', ylab='Survival Prob.') #Compare with estimates when there is no intervening event new2 <- data.frame(S=Surv(c(0,5), c(5, 999), c(FALSE,FALSE)), age=rep(50,2), ie.status=c(0,0)) g2 <- survfit(f, new2) lines(c(0,g2$time), c(1,g2$surv[,2]), type='s', lty=2) #or: #g2 <- survest(f, new2) #lines(g2$time, g2$surv, type='s', lty=2) detach("dframe[z$subs, ]") options(datadist=NULL)