Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 48

Understanding Time-Dependent Covariates

Recommended resources

Hello! Welcome to the next lesson in our journey through survival analysis.

In our last session, we discussed the stratified Cox model, a clever way to handle categorical variables that violate the proportional hazards assumption. We concluded that while stratification is effective for controlling for "nuisance" variables, it's not ideal if your main variable of interest has non-proportional hazards, because it prevents you from estimating that variable's effect.

Today, we'll tackle this challenge head-on by exploring time-dependent covariates (TDCs). This powerful technique allows us to model variables whose values change over the course of a study. By the end of this lesson, you will be able to define what time-dependent covariates are and, more importantly, explain when they are essential for building a valid and unbiased model.

What is a Time-Dependent Covariate?

Up to this point, all the covariates we've considered in our models—like sex, age at diagnosis, or baseline disease stage—have been time-fixed. Their values are measured once at the beginning of the study and are assumed to remain constant throughout the follow-up period.

However, in reality, many important characteristics are dynamic. A patient's health status, treatments, and exposures can change over time. A time-dependent covariate (also called a time-varying covariate, or TVC) is simply a variable whose value is not fixed but can change during follow-up.

This image illustrates several common examples of time-dependent covariates in a medical context, such as blood pressure, medication use, or lab results, which can all change during a patient's follow-up.

At first, this might seem to contradict the "proportional hazards" assumption of the Cox model. If a covariate's value is changing, how can the hazard ratio associated with it be constant? The following reading explains the elegant theoretical solution to this apparent paradox.

Time-varying Covariates in Cox Models | SciencePedia - Bohrium

This article provides a superb explanation of the principles behind modeling time-dependent covariates. It addresses how the Cox model handles them and the practical data structures required.

Please read the section titled "Principles and Mechanisms." Start from the beginning and read down to the paragraph ending "...from one moment to the next." This part explains the concept of "instantaneous proportionality." Then, continue reading the subsection "Slicing Time," which describes the data structure needed for this type of analysis.

Let's summarize the two key ideas from the reading:

  1. Instantaneous Proportionality: The Cox model's proportional hazards assumption holds at any given instant in time. The model's formula is written as:

    The crucial part is —the covariate vector for person is now a function of time . This means the model compares individuals based on their covariate values at the exact moment an event occurs, not just their baseline values.

  2. The start-stop Data Format: To handle this in practice, we restructure the data. Instead of one row per patient, a patient's follow-up is sliced into multiple rows or intervals. A new interval begins whenever a time-dependent covariate changes its value. Within each interval, the covariate is constant. This format, also known as the counting process format, allows the software to know the precise value of all covariates for every person at risk at every event time.

The following short video clip visually explains this practical data restructuring.

Cox with time dependent covariates with EZR

This video on using the EZR software provides a clear, side-by-side illustration of the standard data format versus the start-stop format for time-dependent covariates.

Watch the segment from the beginning of the data format explanation. Focus on understanding the difference between the "single row per person" and the "multiple rows per person" datasets.


When are TDCs Necessary? The Problem of Immortal Time Bias

Now we know what TDCs are. But why are they so important? They are necessary whenever a key exposure or predictor can change during follow-up. Failing to account for this change doesn't just reduce a model's accuracy; it can introduce a severe and misleading form of bias.

The most famous example of this is immortal time bias. This bias occurs when a study group is defined by an event that happens after follow-up begins. To be in that group, a person must survive the period between the start of the study and the event. This period of guaranteed survival is called "immortal time."

Let's make this concrete with the classic Stanford heart transplant study. In this study, patients were enrolled when they were placed on a waitlist for a transplant. Some received a transplant, others did not. A naive analysis might compare the "transplanted" group to the "non-transplanted" group from day one.

The following video brilliantly demonstrates the flaw in this approach.

Cox Proportional Hazard with Time Varying Covariate

This video uses the Stanford heart transplant data to provide one of the clearest explanations of immortal time bias available.

First, watch the section from the description of a typical analysis. This will show you the dangerously wrong conclusion you get by ignoring the timing of the transplant. Next, continue watching from the mathematical comparison. The narrator provides an outstanding numerical example that contrasts the biased (time-fixed) and correct (time-varying) ways to calculate the death rates. Pay close attention to how the follow-up time is allocated in each scenario.

The video's numerical example is the heart of the matter.

  • Incorrect (Biased) Method: All follow-up time for a patient who eventually gets a transplant is counted in the "transplant" group, right from day zero. This includes the "immortal" waiting period before the surgery, during which they could not have died and still received a transplant. This artificially lowers the death rate in the transplant group.
  • Correct (Time-Varying) Method: A patient's follow-up time is split. The time before their transplant is correctly attributed to the "non-transplant" group. Only the time after the transplant is attributed to the "transplant" group. The patient effectively moves from one group to the other at the time of surgery.

This next image provides a perfect visual summary of the problem and its solution.

This diagram illustrates three ways of handling a time-dependent exposure like treatment. (A) **Misclassified immortal time**: The waiting period is incorrectly assigned to the treated group, causing bias. (B) **Excluded immortal time**: The waiting period is ignored, leading to selection bias. (C) **Time-varying analysis**: The waiting period is correctly attributed to the untreated group, and the patient's status changes to treated only at the start of treatment. This is the correct approach.

As you can see, the time-varying analysis (Panel C) is the only method that correctly attributes person-time. This is precisely what we achieve by modeling treatment as a time-dependent covariate.

Immortal time bias is not a niche academic issue. As the video mentions, it has been found in numerous published studies, often leading to wildly optimistic conclusions about the effectiveness of treatments. It is a critical flaw to look for when evaluating any observational study where the exposure of interest can begin after follow-up starts.


Internal vs. External Covariates: An Important Distinction

Finally, it's useful to distinguish between two types of TDCs, because the distinction has important implications for how we interpret our model.

Tools & Techniques - Statistics: Dealing with time-varying covariates ...

This article from EuroIntervention makes a clear and crucial distinction between two types of TDCs and discusses the limitations of the standard Cox model.

Read the section "Types of time-varying covariates," which defines exogenous and endogenous covariates. Then, read the first paragraph of the next section, "Methods for survival analysis," which highlights why this distinction is important.

As the article explains:

  • External (or Exogenous) TDCs: These are variables whose values are not influenced by the individual patient's journey. Examples include things like daily air pollution levels or seasonal changes. Their paths are determined by outside forces.
  • Internal (or Endogenous) TDCs: These are processes generated by the individual, and they require the person to be alive to be measured. Examples include biomarkers (like blood pressure), symptom severity, or the initiation of a new treatment based on the patient's condition.

While the Cox model can handle both types mechanically, interpreting the results for internal covariates requires great care. When an internal covariate (like a worsening lab value) influences a doctor's decision to start a treatment (another internal TDC), you can get a feedback loop known as time-dependent confounding. In this situation, the model coefficient for the treatment measures its association with the outcome conditional on the lab value, which may not be the same as the overall causal effect of the treatment. Untangling this is a complex topic for advanced causal inference, but being aware of this distinction between association and causation is a key step in sophisticated interpretation.


Conclusion

In this lesson, we have moved beyond fixed, baseline characteristics to the dynamic world of time-dependent covariates. This is a crucial step for accurately modeling real-world health processes.

Here are the key takeaways:

  • A time-dependent covariate (TDC) is a variable whose value can change over the course of a study's follow-up period.
  • TDCs are necessary whenever a key predictor is not constant, such as when a treatment is initiated after follow-up begins.
  • Failing to model a time-dependent exposure correctly can lead to immortal time bias, which creates a spurious survival advantage for the exposed group by misattributing a period of guaranteed survival.
  • The correct approach involves a time-varying analysis, where a subject's exposure status changes at the time the event occurs. This is achieved by restructuring the data into a start-stop format.
  • It is important to distinguish between external (e.g., pollution) and internal (e.g., biomarkers, treatments) TDCs, as internal covariates can introduce complex interpretive challenges like time-dependent confounding.

You now understand the critical importance of identifying and correctly conceptualizing time-dependent covariates to avoid major analytical errors. In our next lesson, we will build directly on this foundation and learn how to interpret the output of a Cox model that includes a time-dependent covariate.