I am using the time transform feature of the coxph function in the survival package to model the effect of a time varying covariate.

fit <- coxph(Surv(start, stop, death) ~ disease + tt(disease), data=data, 
       tt=function(x,t,...) x*t, x=TRUE)

My question is, can Cox-Snell residuals be computed from this model to assess goodness of fit, and if so, how? I have tried to compute them like this:

 res <- data$death - fit$residual

But the problem is that the vector fit$residual is much longer than data$death, and I don't understand why. Shouldn't these vectors be the same length? How come there are more residuals than there are observations? I do not have this problem if I specify the time varying effect this way:

fit2 <- coxph(Surv(start, stop, death) ~ disease + disease:stop, data=data, x=TRUE)

Now I can compute Cox-Snell residuals as res <- data$death - fit$residual.


1 Answer 1


Because the tt(disease) means you fit the model with a time-dependent covariate disease*t, R would split one obs into several by the unique event time in the whole dataset to do that, and fit the model by viewing the several observations with adjacent time intervals as several "subjects". Then there would be much more residuals as there are more "subjects".

You may want to try

survsplit(Surv(..)~1, cut=data$stop, episode = "tgroup", id = "id", 

to get the same length "death" to get the cox-snell residuals like the way you described.


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.