Cox regression with a time-dependent covariate (a characteristic changes over time)
In brief
Some characteristics change during observation: a therapy starts, a transplant takes place, a lab value is measured again. Treating such a characteristic as a fixed group "ever switched" creates the immortal time bias. The Cox regression with a time-dependent covariate avoids it: each person carries the value 0 until the switch and the value 1 from the switch on. It is chosen in the question "How long does it take until an event?" under "More options" → "A characteristic changes over time".
The immortal time bias
Anyone who switches later had to survive until then. If such a person is counted in the group of those who switched from the start, that group looks longer-lived only because of this error. Measured in a simulation with a true hazard ratio of 1: the fixed group "ever switched" gives on average HR 0.49 and is significant in every run; the time-dependent covariate gives 0.99 and a significant result in 4% of the runs. In the Stanford heart data (transplant) the fixed group falls to HR 0.27, the time-dependent covariate to 1.04. Therefore the covariate may have only values at each point in time that were already known at that time.
The data: interval form
Statable needs the table in interval form (counting process): one row per person and interval with ID, start, end, event and the value that applied in this interval. The intervals are open on the left and closed on the right: (start, end]. The value applies from the start, the event happens at the end. The event (1) is only in the last row of the person. In the card the ID, the start and the time-dependent covariate are chosen; the time above is the end. Before calculating, Statable checks: start less than end, no overlap, no gap, at most one event per person and only in the last row.
The assistant "Time points per person → intervals"
If the table has only one row per person with end, event and the time of a switch (empty = never), the assistant under Data > Reshape builds the table in interval form: value 0 before the switch, 1 from the switch on, the chosen columns of the person run into every row. It says how many people switched, how many had the switch at the start or after the end of observation (input error? or already the immortal time bias in the raw data) and how many on the day of the event. The new table does not take the case weight along.
Switch on the day of the event
If the switch falls on the day of the event, the rule decides the result. Strict (default): the switch applies only afterwards, the event still belongs to the old value. "Counts already": the switch is moved forward by half of the smallest time gap in the data (0.5 for days, a fraction for years), which is how survival fixes the order too; Statable names the amount. In the Stanford heart data this concerns a single patient and moves the hazard ratio of the transplant from 0.90 (strict) to 0.99 (counts already). Statable always names the rule and the number of people affected.
Reading the result
- The hazard ratio of the time-dependent covariate compares the momentary risk after the switch with that before it, other characteristics being equal. HR = 1 means: no difference. It is not a risk ratio.
- The result describes a relationship with the risk after the switch, not proof of an effect. If the covariate is itself a consequence of the illness (for example a lab value), it already says something about the event (internal covariate).
- Statable handles tied event times by Efron. Statable checks the proportional hazards assumption with cox.zph; with time-dependent covariates the test is only a guide. There is no concordance in this form.
- Rule of thumb: at least 10 events per coefficient, events in both states (before and after the switch) and at least 5 people with a switch; otherwise Statable warns.
Something else: the time-dependent effect
A time-dependent covariate is not the same as a time-dependent effect (tt() in R): there the characteristic stays fixed (for example age), its effect changes with time, so it violates proportionality. Statable does not offer this.
Reporting the result
Cox regression with a time-dependent covariate: LR test χ²(4) = 15.11, p = .004; HR = 0.99, 95% CI [0.53, 1.82], p = .967 (transplant); 103 people in 170 rows, 75 events
For specialists
survival::coxph with Surv(start, stop, event), ties = "efron", Wald test and Wald interval with qnorm(.975); several rows per person are fine for one time-dependent covariate without a robust variance (the intervals do not overlap). The reshaping runs in JavaScript and agrees with survival::tmerge row by row; the model of the survival vignette (Kalbfleisch and Prentice 1980, table 6.1, model 6) is matched to the last printed digit.
library(survival)
m <- coxph(Surv(start, stop, event) ~ transplant + age + surgery + year, data = heart_long, ties = "efron")
summary(m)
Sources
Therneau, T. M. & Grambsch, P. M. (2000). Modeling survival data: extending the Cox model. Springer. Kalbfleisch, J. D. & Prentice, R. L. (1980). The statistical analysis of failure time data. Wiley. Crowley, J. & Hu, M. (1977). Covariance analysis of heart transplant survival data. Journal of the American Statistical Association, 72, 27-36. survival vignette "Using time dependent covariates and time dependent coefficients in the Cox model".