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.

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, ], 

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?

  • $\begingroup$ Not sure if it is supported. See: stats.stackexchange.com/questions/66623/… $\endgroup$
    – julieth
    Commented Aug 5, 2017 at 15:01
  • $\begingroup$ 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? $\endgroup$
    – AdamO
    Commented Jan 12, 2018 at 15:14
  • $\begingroup$ Is this a methods question or a programming question? $\endgroup$
    – AdamO
    Commented Oct 12, 2023 at 19:05

1 Answer 1


You need to use vfit2 <- cph(Surv(tstart, time, status) ~ trt + prior + karno*strat(tgroup), data=vet2, surv = TRUE, x=TRUE, y=TRUE)

The x and y arguments are lower cases.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.