Tutorials › Econometrics (Graduate) › Time-Varying Covariates In Cox Models

Duration and Survival Models · Tutorial 581 of 952

Time-Varying Covariates In Cox Models

Represent covariates as histories over time, form risk sets from start-stop records, and interpret estimates from an extended Cox model.

Advanced 11 min read

What You'll Learn

  • Define counting-process outcomes and at-risk indicators for survival data.
  • Encode changing covariates in start-stop intervals without using future information.
  • Construct event-time risk sets from interval records.
  • Write the partial likelihood for a Cox model with time-varying covariates.
  • Interpret a fitted hazard ratio as a comparison of current covariate values.
  • Identify key assumptions and common errors in extended Cox analyses.

Why Covariate Histories Matter

Some predictors are not fixed at the beginning of follow-up. A patient may start a medication, a worker’s exposure may change, or a firm’s financial status may be updated during observation. A Cox model using only baseline values cannot represent these histories directly. The extended Cox model allows the covariate vector to change over time while retaining a proportional-hazards structure for the covariate effects.

The key is to use the covariate value that is known just before each event time. This determines both the subject’s contribution to the risk set and the hazard weight assigned to that subject. A time-varying covariate is not the same thing as a time-varying coefficient: here the covariate history changes, while the coefficient remains fixed.

Definition: In the extended Cox model, subject \(i\)'s hazard at time \(t\), conditional on the covariate history available just before \(t\), is $$ \lambda_i(t\mid \mathcal{H}_i(t-))=\lambda_0(t)\exp\{\beta^\top X_i(t)\}. $$ Here \(\lambda_0(t)\) is the unspecified baseline hazard, \(X_i(t)\) is the possibly time-varying covariate vector, and \(\beta\) is a vector of constant regression coefficients. The notation \(t-\) emphasizes that the covariate value must be available immediately before \(t\).

The model says that, at a given time, subjects with different current covariate values have hazards whose ratio is \(\exp\{\beta^\top[X_i(t)-X_j(t)]\}\). The baseline hazard may vary freely over time, but the coefficient vector does not. As in an ordinary Cox model, this is a conditional hazard comparison, not by itself a causal effect.

Counting-Process and Start-Stop Representation

Let \(T_i\) be subject \(i\)'s event time, \(C_i\) the censoring time, and \(\tilde T_i=\min(T_i,C_i)\) the observed follow-up time. Let \(\Delta_i=1\) if the event is observed and \(\Delta_i=0\) if the observation is censored. The counting-process representation records whether an event has occurred by each time, while the at-risk indicator records whether the subject is under observation and has not yet had the event.

Definition: With entry time \(L_i\), define $$ N_i(t)=I(\tilde T_i\leq t,\ \Delta_i=1),\qquad Y_i(t)=I(L_i<t\leq \tilde T_i). $$ The process \(N_i(t)\) jumps from 0 to 1 at an observed event and otherwise remains 0. The indicator \(Y_i(t)\) equals 1 when subject \(i\) is at risk immediately before time \(t\). For ordinary follow-up beginning at time 0, use \(L_i=0\).

In a start-stop data set, each row describes one interval \((a_{ij},b_{ij}]\) during which a subject has a specified covariate value. The row’s event indicator is 1 only if the subject’s event occurs at the interval’s stop time; it is 0 otherwise. If a covariate changes, split the record at the change time. A subject may therefore have multiple rows, but contributes to the risk set only once at any particular event time.

The interval convention matters. A subject represented by \((a,b]\) is at risk at an event time \(t\) when \(a<t\leq b\). The covariate assigned to that row must be the value applicable just before \(t\), based on information then available. If an event and a covariate update share a recorded time, the analysis needs a stated convention that determines whether the update was known before the event.

Worked Example: Splitting Follow-Up at Covariate Changes

Consider hypothetical follow-up for three subjects. The covariate \(X\) indicates current exposure (1 = exposed, 0 = unexposed). Subject A changes exposure at time 2 and has an event at time 5. Subject B has an event at time 4 without changing exposure. Subject C remains exposed and is censored at time 5.

SubjectStartStop\(X\)Event at stop?
A0200
A2511
B0401
C0510

At time 4, A is in \((2,5]\), B is in \((0,4]\), and C is in \((0,5]\). Thus all three are at risk just before time 4, with current covariate values \(1,0,1\), respectively; B is the event subject. At time 5, B has already left the risk set. A and C are both at risk immediately before 5, with \(X=1\). A has the event, while C is censored at 5. C is included in the risk set for the event at 5 because censoring at that time does not remove C before the instant immediately preceding it.

The split for A is essential: assigning \(X=1\) to A’s entire follow-up would incorrectly treat A as exposed before time 2. Conversely, using only A’s baseline value would fail to represent the exposure during \((2,5]\).

Risk Sets and the Extended Cox Partial Likelihood

At an observed event time \(t_k\), the risk set consists of all subjects with \(Y_i(t_k)=1\). The relevant covariate for each member is \(X_i(t_k)\), not necessarily their baseline covariate. For distinct event times, the Cox partial likelihood is the product of the event subject’s hazard weight divided by the sum of hazard weights over that event’s risk set.

Definition: For distinct observed event times \(t_1,\ldots,t_D\), with event subject \(i_k\) at \(t_k\), the partial likelihood is $$ L(\beta)=\prod_{k=1}^{D} \frac{\exp\{\beta^\top X_{i_k}(t_k)\}} {\sum_{j:Y_j(t_k)=1}\exp\{\beta^\top X_j(t_k)\}}. $$ The partial-likelihood estimate maximizes this function over \(\beta\). The baseline hazard cancels from the conditional event probabilities. When event times are tied, an appropriate standard tie method is required.

The risk-set construction is the same at each event time; what changes from a baseline-only Cox model is the value of \(X_j(t_k)\) used in the numerator and denominator. This depends on correctly recording each subject’s history and interval membership. Treating the changing covariate as fixed at baseline changes the model being fitted.

Worked Example: Computing a Partial-Likelihood Estimate

Suppose a hypothetical study has three subjects, A, B, and C, and two distinct event times. At time 1, A has an event; all three are at risk, with covariate values \(X_A(1)=1\), \(X_B(1)=0\), and \(X_C(1)=0\). After time 1, C’s covariate changes from 0 to 1. At time 2, B has an event and B and C are at risk, with \(X_B(2)=0\) and \(X_C(2)=1\). Assume no other event or censoring occurs before time 2.

For a scalar coefficient \(\beta\), the contribution at time 1 is \(e^\beta/(e^\beta+2)\). At time 2, B’s event weight is 1 and the risk-set weights are 1 for B and \(e^\beta\) for C, so the contribution is \(1/(1+e^\beta)\). Therefore

$$ L(\beta)=\frac{e^\beta}{e^\beta+2}\frac{1}{1+e^\beta}. $$

To maximize it, set \(z=e^\beta>0\) and differentiate the log partial likelihood:

$$ \frac{d\log L}{d\beta} =1-\frac{z}{z+2}-\frac{z}{1+z}=0. $$

Rearranging gives \(2/(z+2)=z/(1+z)\), so \(2(1+z)=z(z+2)\), and hence \(z^2=2\). The maximum occurs at \(z=\sqrt{2}\), giving \(\hat\beta=\log(\sqrt{2})\approx 0.3466\). The estimated hazard ratio for \(X=1\) versus \(X=0\), at the same time and with the same other covariates, is \(e^{\hat\beta}=\sqrt{2}\approx 1.414\). This small hypothetical calculation illustrates the likelihood mechanics; it does not provide a reliable basis for substantive inference.

Assumptions and Interpretation

The model and its estimates require more than correctly formatted rows. The hazard must be adequately represented by the Cox form, including the chosen covariate effects and their functional forms. Conditional on the modeled covariates, each coefficient is constant over time. The covariate history must be measured accurately and available at the appropriate time; in particular, the model cannot use information that becomes known only after an event. Standard inference also relies on suitable censoring assumptions: censoring should not carry unmodeled information about future event risk after conditioning on the information represented in the analysis. When subjects enter after time 0, their entry times must be represented so that they enter risk sets only once they are observed.

For a one-unit increase in a scalar covariate, holding the other covariates fixed at a given time, the hazard ratio is \(e^\beta\). More generally, comparing covariate vectors \(x_1\) and \(x_0\) at the same time gives \(e^{\beta^\top(x_1-x_0)}\). The comparison concerns the instantaneous event rate among subjects who are still at risk, not the ratio of event probabilities over an entire follow-up period.

Worked Example: Interpreting a Fitted Time-Varying Covariate Effect

Suppose a hypothetical extended Cox model estimates the coefficient for current treatment status (1 = currently receiving treatment) as \(\hat\beta=0.35\), with standard error \(SE=0.16\). Assume the model uses a binary treatment indicator updated at treatment initiation, and that the other covariates are held fixed in the comparison.

The estimated hazard ratio for currently treated versus currently untreated is

$$ \exp(\hat\beta)=\exp(0.35)\approx 1.419. $$

Under the fitted model, at a given time and conditional on the other covariates, the hazard among subjects currently receiving treatment is estimated to be about 1.42 times the hazard among otherwise comparable subjects not currently receiving treatment. This is an association conditional on the model, not a causal conclusion.

For illustration, a 95% Wald confidence interval for the coefficient is \(0.35\pm1.96(0.16)\), or approximately \([0.0364,0.6636]\). Exponentiating the endpoints gives a hazard-ratio interval of approximately \([1.037,1.942]\). Under the model and the Wald approximation, this interval is constructed by a procedure with 95% long-run coverage for the hazard ratio. The Wald statistic is \(z=0.35/0.16=2.188\), giving a two-sided p-value of approximately 0.0287. This is evidence against a zero coefficient under the stated model and approximation; it is not the probability that the null hypothesis is true.

Common Pitfall: Using Future Covariate Information

A common error is to label a subject “ever treated” from the beginning of follow-up, even when treatment begins later. The mistaken reasoning is that eventual treatment status is simply another subject characteristic. But before initiation, treatment has not yet occurred; assigning the later value to earlier intervals uses future information and misstates the covariate history. The correction is to split follow-up at initiation and use the untreated value before that time and the treated value afterward. In general, define each interval’s covariate using information available at its event times, and verify that every event subject and risk-set member has the correct row and value.

A time-varying covariate also does not automatically solve confounding or establish causation. It changes how measured covariate histories enter the hazard model. The interpretation remains conditional on the model and the assumptions supporting the analysis.

Key takeaway: Build the risk set at each event time from start-stop intervals, evaluate each subject’s covariates using the history known just before that time, and use those values in the Cox partial likelihood. Accurate timing is central to both estimation and interpretation.

Check Your Understanding

Use these questions to test your understanding of time-varying covariates in Cox models.

  1. What does \(Y_i(t)=1\) mean, and why can a subject censored at an event time still be in that time’s risk set?
  2. A covariate changes at time 3. How should the subject’s start-stop records represent the values before and after time 3?
  3. At an event time, which covariate value belongs in the partial-likelihood denominator for a subject with a changing history?
  4. For a scalar coefficient \(\beta=0.4\), what hazard ratio does the model imply for a one-unit increase in the covariate, holding other covariates fixed?
  5. Why is coding a subject as exposed from baseline when exposure starts later a mistake?
Clinical Biostats