I need help with setting up my dataset to perform survival analysis with a time-dependent covariate. I read the Therneau et al. paper but I'm still unsure of how to set up the counting process format for my data.

Below is a test dataset similar to what I have.

Data: Liver transplant dataset where some patients are in group 1 (if on immunosuppressive drug A at baseline), others are in group 2 (if on drug B at baseline).

Goal: I want to know how/if the time of first switch from med A to med B impacts graft survival (graft failure is the event of interest). The expectation is that the switch to drug B wouldn't significantly impact graft survival but it's important to show this because drug B would be preferable as it has less side effects, better tolerance profile and is more cost effective than drug A.

GROUP=1, if on drug A; 2 if on drug B, and 3 if they switched from A to B;

CENSOR=1, if event (graft failure) happened, 0 otherwise;

FUTIME = total follow-up time (days) (=CENSDT – transplant date), where CENSDT (not shown here, is either date of event, or date of last follow-up/death)

EVTIME= time of event (days); EVTIME=FUTIME when CENSOR=1, else EVTIME= N/A;

SWITCHDATE (not shown here) =date of first switch from drug A to drug B;

SWITCHTIME=time of first switch from group 1 to group 2 (=SWITCHDATE – transplant date); this will be 0 for those patients who start off on drug B at baseline, and it is FUTIME for those who start off on drug A and never switch (per investigators's request).

ID<-c(“001”, “002”, “003”, “004”, “005”, “006”, “007” ,”008”, “009” ,”010”, “011”, “012”, “013”, “014”, “015”, “016”, “017”, “018”, “019”, “020”, “021”, “022”, “023”, “024”, “025”, “026”, “027”, “028”, “029”, “030”)
censor<-c(0, 0, 0, 0, 1,  1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0,  1, 0, 0, 1, 0, 0)
futime<-c(1229, 1659, 733, 6998, 1005, 4726, 3790, 672, 5224, 4143, 4973, 3626, 4296, 977, 2898, 1382, 1164, 1232, 1599, 1795, 3171, 483, 824, 662, 597, 1269, 4120, 621, 3452, 1842)

evtime<-c(NA, NA, NA, NA, 1005, 4726, NA, 672, NA, NA, NA, 3626, NA, NA, NA, NA, 1164, NA, 1599, NA, NA, 483, 824, NA, 597, NA, NA, 621, NA, NA)

switchtime<-c(333, 343, 509, 1630, 558, 147, 2856, 504, 2648, 149, 500, 3624, 3998, 0, 331, 1187, 1164, 336, 143, 111, 3171, 333, 351, 662, 0, 0, 4120, 0, 3452, 0)
group<-c(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, 2, 2, 1, 2, 1, 2)
  • 1
    $\begingroup$ Are these data subject to left censoring? It seems odd to me that the "group" for switchers in group A takes on a whole new level in group C, if they're on the immunsuppressive drug, I would think their covariate should change to "B" $\endgroup$
    – AdamO
    Commented Feb 24, 2023 at 23:57
  • 1
    $\begingroup$ If a subject is censored, their event time should be set to the last known time they were at risk for the event. $\endgroup$
    – AdamO
    Commented Feb 24, 2023 at 23:58
  • $\begingroup$ AdamO, thank you for your input and yes, you are correct in that their event time is actually futime so my evtime variable is redundant. Sorry about the confusion. $\endgroup$
    – R. Simian
    Commented Mar 2, 2023 at 5:19

1 Answer 1


I think you need to work with an experienced statistician who can discuss the clinical issues and help you avoid survivorship bias and other problems this study poses.

To address your question: in the counting-process data format, each data row represents a time interval during which the covariate values are constant for an individual. You specify the start time and the stop time of each interval, the covariate values in place during the interval, and an indicator of whether the stop time represents an event or not (like your censor values). See the R time dependence vignette.

As @AdamO notes in a comment, you need to specify the last observation time for individuals who never have an event during your study. That seems to be in your futime values; your extra evtime values are redundant.

I don't think that the 3 groups, at least as you have set them up, helps here. A simple way to proceed would be to specify treatment (A or B) as a time-varying covariate. If someone switches from A to B, set the stop time of her first data row and the start time of her second data row to the time of the switch, indicating "no event" in the first data row. Each row has the treatment value corresponding to what was received during that time period. Anyone who never switches treatments would just have a single data row.

That simple model would determine whether the treatment currently in place matters. Even that simple model has a problem with interpretation, however, as you say that some who start on A never switch "per investigators's request." That's probably due to some underlying clinical situation that is also likely to influence time to graft failure.

Also, that simple model doesn't get directly to the issue of the "time of first switch," whether the duration of A before B matters in addition to the treatment currently in place. The problem is that any measure associated with the length of prior exposure to A before switching to B (even your identification of an additional group 3, or a simple indicator that a switch occurred) represents a value for an individual already known to have survived as long as the switch time. That can lead to survivorship bias.

Trying to get a causal interpretation of your observational data that would support something like "always start patients on B" will be very tricky, if that's even possible. You need to work closely with a statistician who can discuss closely with you and your colleagues how far you can push this type of data.

  • $\begingroup$ thank you for your input, it is very illuminating and helps me get a better idea of all the different nuances that need to be considered here. I will request some additional input and advice from a more seasoned co-worker and further clarification from the investigators to understand how to best approach this in order to get valid and interpretable results. $\endgroup$
    – R. Simian
    Commented Mar 2, 2023 at 5:17
  • $\begingroup$ Just one quick clarification that I forgot to mention: it's not that the investigator requested that those who start on "A" never switch. Rather, what I was saying is that, those who start on "A" and never switch, should be right censored at either last follow up or event. $\endgroup$
    – R. Simian
    Commented Mar 2, 2023 at 5:27

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.