# Predicting Cox survival with time-dependent covariates

With the following sample I wish to illustrate the problem I have with estimating the survival of individuals while having time-dependent covariates in R.

I start with the standard veterans database, which I split up at 90 and 180 days (as an illustration). I proceed by creating a CPH model (from RMS) and attempt to get a prediction of the second patient with the standard survest function at 210 days.

library("rms")
vet2 <- survSplit(Surv(time, status) ~ ., data= veteran, cut=c(90, 180),
episode= "tgroup", id="id")
vfit2 <- cph(Surv(tstart, time, status) ~ trt + prior + karno*strat(tgroup), data=vet2,surv = T,X=T,Y=T)
prob = survest(vfit2,newdata=vet2[vet2$id==2,],times=210)$surv


However this results in

   2         3         4
NA        NA 0.8919535


Which obviously is incorrect. First of all the NAs shouldn't be there and the probability of 0.89 is way too high. I believe that 89% probability is the chance of reaching 210 days, GIVEN that you've already reached 180. That seems to make more sense. Given this reasoning, I should then predict the survival at 90, 180 and 210 days and multiply these probabilities for the respective episodes, right?

I did this with: prod(diag(survest(vfit2,newdata=vet2[vet2$id==2,],times=c(90,180,210))$surv)) which results in a probability of 0.293

Is this algorithm/reasoning correct? Can I use this method to calculate survival probabilities with time-varying covariates?

• Not sure if it is supported. See: stats.stackexchange.com/questions/66623/… – julieth Aug 5 '17 at 15:01
• What is the stratum membership for vet2\$id==2? Is the 2:4 name to the output indicative of the stratum membership? Further is it set to missing simply because that observation doesn't belong to those strata, or rather the mutual distribution of covariates, strata, and survival time are inestimable? – AdamO Jan 12 '18 at 15:14

You need to use vfit2 <- cph(Surv(tstart, time, status) ~ trt + prior + karno*strat(tgroup), data=vet2,surv = T,x=T,y=T)
The x and y are lower cases.