Tutorials › Biostatistics › Time-Varying Covariates in Survival Models

Survival Analysis

Time-Varying Covariates in Survival Models

A practical guide to modeling covariates that change during follow-up, including extended Cox models, counting-process and start-stop data, time-dependent treatment exposure, laboratory measurements, interpretation, immortal time bias, landmark analysis, and implementation in R and SAS.

Advanced 18 min read

What You'll Learn

  • Why ordinary baseline Cox regression can be inappropriate when covariates change during follow-up
  • How the extended Cox model incorporates covariate histories
  • How start-stop and counting-process data represent changing covariates
  • How to model treatment initiation, dose changes, biomarkers, and repeated measurements
  • How time-varying covariates differ from time-varying coefficients
  • How to avoid immortal time bias and other common analytical errors

Introduction

Many survival analyses begin with a simple assumption: the covariates used in the model are measured once at baseline and remain fixed throughout follow-up.

That assumption is reasonable for characteristics such as sex, race, treatment assignment at randomization, or baseline disease stage.

But many clinically important variables change during a study.

A patient may:

  • Begin treatment after enrollment
  • Discontinue treatment
  • Change dose
  • Experience disease progression
  • Develop a complication
  • Have laboratory measurements change over time
  • Move from one risk category to another
  • Develop a biomarker-positive state during follow-up

If these changes contain information about subsequent event risk, treating the variable as fixed at baseline can discard important information or, in some settings, introduce serious bias.

Key idea: A time-varying covariate is a predictor whose value is allowed to change during follow-up. The survival model can then use the covariate value that is relevant to the patient's current risk set at each event time.

Why Baseline Covariates Are Sometimes Not Enough

Suppose patients with advanced cancer are followed for overall survival.

Some patients receive a subsequent-line therapy during follow-up, while others do not.

If we simply define:

$$ Z_i= \begin{cases} 1,&\text{patient eventually receives treatment}\\ 0,&\text{patient never receives treatment} \end{cases} $$

and use \(Z_i\) as though it were known from baseline, we have a major problem.

A patient cannot receive the treatment before actually receiving it.

If a patient dies on day 20, for example, that patient cannot have a treatment initiation date on day 50.

Yet classifying patients according to whether they eventually receive treatment can effectively use future information to classify earlier periods of follow-up.

This is a central danger: A covariate must not be assigned a value at time \(t\) using information that becomes available only after time \(t\). Otherwise, the analysis can introduce look-ahead bias or immortal time bias.

The Standard Cox Proportional Hazards Model

The ordinary Cox proportional hazards model is:

$$ h_i(t) = h_0(t) \exp\left( \beta_1X_{i1} +\beta_2X_{i2} +\cdots+ \beta_pX_{ip} \right) $$

where:

  • \(h_i(t)\) is the hazard for patient \(i\) at time \(t\)
  • \(h_0(t)\) is the baseline hazard
  • \(X_{ij}\) are covariates
  • \(\beta_j\) are regression coefficients

In the usual baseline-covariate formulation, the \(X_{ij}\) values are treated as fixed.

For example, if treatment is randomized at baseline, the model might be:

$$ h_i(t) = h_0(t)\exp(\beta_1\text{Treatment}_i+\beta_2\text{Age}_i) $$

But if treatment status changes during follow-up, we need a more general formulation.

The Extended Cox Model

The extended Cox model allows one or more covariates to depend explicitly on time:

$$ h_i(t) = h_0(t) \exp\left[ \beta_1X_{i1}(t) +\beta_2X_{i2}(t) +\cdots+ \beta_pX_{ip}(t) \right] $$

The notation \(X_{ij}(t)\) emphasizes that the covariate value can change as \(t\) changes.

For a single time-varying covariate:

$$ h_i(t) = h_0(t)\exp\{\beta X_i(t)\} $$

The hazard ratio associated with a one-unit increase in the covariate, comparing two individuals with otherwise identical covariate histories at time \(t\), is:

$$ HR=e^\beta $$
Interpretation: The coefficient describes the association between the current covariate value and the hazard at time \(t\), under the specified model. It does not automatically describe the causal effect of changing the covariate.

What Does "Time-Varying" Actually Mean?

There are two concepts that are often confused.

Time-Varying Covariate

The predictor itself changes:

$$ X(t) $$

Examples include current treatment exposure, current biomarker concentration, or current disease status.

Time-Varying Coefficient

The effect of a covariate changes with time:

$$ \beta(t) $$

For example:

$$ h_i(t) = h_0(t)\exp\{\beta(t)X_i\} $$

This is a way of modeling violation of the proportional hazards assumption.

Concept What Changes? Example
Time-varying covariate \(X(t)\) Current treatment status changes from 0 to 1
Time-varying coefficient \(\beta(t)\) Treatment effect becomes weaker over time
Both \(X(t)\) and \(\beta(t)\) Changing biomarker with a time-dependent effect
Do not confuse these problems. A time-varying covariate addresses a predictor whose value changes. A time-varying coefficient addresses an effect whose magnitude changes over time. The two ideas solve different modeling problems.

A Simple Clinical Example

Suppose 100 patients are followed for time to disease progression.

A biomarker is measured every four weeks.

For patient \(i\), the biomarker history might look like:

Time Biomarker
Baseline 4.2
4 weeks 5.1
8 weeks 6.4
12 weeks 8.0

A baseline-only Cox model uses only the initial value:

$$ X_i=4.2 $$

The time-varying model instead allows the current value to enter the risk model:

$$ X_i(t)= \begin{cases} 4.2,&0\le t<4\\ 5.1,&4\le t<8\\ 6.4,&8\le t<12\\ 8.0,&t\ge12 \end{cases} $$

Thus, the model can associate the current biomarker level with the current hazard.

Step-Function Representation

In many clinical datasets, a time-varying covariate is observed intermittently rather than continuously.

The analysis therefore commonly treats the observed value as remaining constant until a new measurement becomes available.

For example:

$$ X_i(t)=X_{ij} \qquad \text{for } t_{ij}\le t

This is sometimes called a last-observation-carried-forward representation within the risk intervals.

Important distinction: Using the most recently observed covariate value as the current value within a prespecified interval is a modeling convention. It is not the same thing as arbitrarily imputing missing data.

The Counting-Process Data Structure

Time-varying Cox models are often represented using a counting-process or start-stop data structure.

Instead of one row per patient, there may be multiple rows per patient.

Each row represents an interval during which the covariate values are constant.

For example:

Patient Start Stop Treatment Biomarker Event
101 0 30 0 4.2 0
101 30 60 1 5.1 0
101 60 87 1 6.4 1

Patient 101 therefore contributes three risk intervals.

The treatment changes from 0 to 1 at day 30, and the biomarker changes at subsequent measurement times.

The event occurs at day 87.

Why Multiple Rows Are Necessary

Suppose treatment begins on day 30.

The patient contributes:

1
Days 0–30: patient is untreated.
2
Days 30 onward: patient is treated.

A single baseline row cannot represent this change.

The start-stop structure explicitly tells the model when the patient changes from one covariate state to another.

Risk Sets and Time-Varying Covariates

The Cox model compares patients who are at risk at each event time.

With time-varying covariates, the relevant value is the value that applies to each patient at that event time.

Suppose an event occurs at day 50.

Patient A started treatment at day 20, while Patient B started treatment at day 70.

At day 50:

Patient Treatment Start Treatment Status at Day 50
A Day 20 1
B Day 70 0

The model therefore compares A as treated and B as untreated at day 50.

Core principle: The covariate value must be aligned with the patient's risk-set membership at the event time.

Time-Varying Treatment Exposure

Treatment initiation is one of the most common applications.

Suppose a patient enters the study untreated and later begins therapy.

Define:

$$ Z_i(t)= \begin{cases} 0,&t

The Cox model becomes:

$$ h_i(t) = h_0(t) \exp\{\beta Z_i(t)\} $$

If \(e^\beta=0.70\), then at any time \(t\), patients currently receiving treatment have an estimated hazard 30% lower than comparable patients currently not receiving treatment, according to this model.

That interpretation is an association conditional on the model, not automatically a causal treatment effect.

Why "Ever Treated" Is Usually Wrong

Consider this incorrect coding:

treated_ever <- ifelse(patient_ever_received_treatment, 1, 0)

Suppose a patient receives treatment on day 100.

If the patient is classified as treated from day 0, the analysis incorrectly attributes the first 100 days of follow-up to the treated group.

The patient could not have benefited from a treatment that had not yet been administered.

This can produce substantial bias.

Immortal Time Bias

The problem becomes particularly important when exposure status is determined by an event that occurs after baseline.

Suppose researchers classify patients according to whether they eventually receive a treatment.

A patient who eventually receives treatment must survive long enough to receive it.

That period before treatment initiation can therefore be an immortal period for the eventually-treated group: the patient had to remain alive and event-free long enough to become classified as treated.

Immortal time bias: If future exposure information is used to classify earlier survival time, the exposed group can receive artificial survival advantages because patients had to survive long enough to become exposed.

The Correct Time-Varying Solution

Instead of:

$$ \text{Ever treated}=1 $$

from baseline, define treatment according to the actual initiation time.

$$ Z_i(t)=0 \quad\text{before treatment} $$

and:

$$ Z_i(t)=1 \quad\text{after treatment} $$

This preserves the temporal ordering of exposure and outcome.

A Complete Worked Example

Consider a hypothetical Phase III oncology study evaluating time to progression.

Patients are followed from randomization until progression, death, or censoring.

Some patients receive a dose modification during follow-up.

We want to investigate whether the current treatment dose is associated with progression hazard.

Suppose Patient 25 has the following history:

Interval Start Stop Dose Level Event
1 0 28 1 0
2 28 56 2 0
3 56 83 1 1

The patient begins at dose level 1, increases to dose level 2 on day 28, and returns to dose level 1 on day 56.

Progression occurs at day 83.

The patient therefore contributes three intervals.

Model Specification

Let \(D_i(t)\) represent the current dose level.

A simple model is:

$$ h_i(t) = h_0(t)\exp\{\beta D_i(t)\} $$

The hazard ratio for a one-unit increase in dose is:

$$ HR=e^\beta $$

For example, if:

$$ \hat{\beta}=0.25 $$

then:

$$ HR=e^{0.25}\approx1.28 $$

Thus, a one-unit higher current dose level is associated with approximately a 28% higher instantaneous hazard, assuming the model is otherwise correctly specified.

Caution: A time-varying treatment or dose variable can be strongly confounded by disease severity. Patients may receive dose increases because they are deteriorating. Therefore, an observed association between current dose and hazard should not automatically be interpreted causally.

Time-Varying Biomarkers

Another common application is repeated laboratory measurement.

Suppose C-reactive protein is measured at baseline and every four weeks.

A model might use:

$$ h_i(t) = h_0(t) \exp\{\beta\,CRP_i(t)\} $$

If:

$$ e^\beta=1.15 $$

then each one-unit increase in the current CRP value is associated with a 15% higher hazard, conditional on the other variables in the model.

The scale of the biomarker matters enormously.

For a biomarker measured over a wide range, it may be more interpretable to use a clinically meaningful increment.

For example:

$$ HR_{10} = e^{10\beta} $$

would represent the hazard ratio associated with a 10-unit increase.

Categorical Time-Varying Covariates

A time-varying covariate does not have to be continuous.

For example, disease status could be categorized as:

Status Code
No progression 0
Progression 1

The model could then estimate:

$$ h_i(t) = h_0(t)\exp\{\beta Z_i(t)\} $$

with:

$$ HR=e^\beta $$

The interpretation compares the hazard while a patient is in the specified disease state with the reference state.

Multiple Time-Varying Covariates

A model can contain several changing predictors simultaneously.

$$ h_i(t) = h_0(t) \exp\left[ \beta_1X_{i1}(t) + \beta_2X_{i2}(t) + \beta_3X_{i3}(t) \right] $$

For example:

  • Current treatment exposure
  • Current dose
  • Current biomarker
  • Current disease status

can all be represented in the same model.

More variables are not automatically better. Time-varying covariates may be measured frequently, highly correlated with one another, affected by prior treatment, or strongly associated with disease severity. Their inclusion should be driven by the scientific question and prespecified analysis strategy.

Start-Stop Intervals

A common data representation is:

$$ (\text{start},\text{stop},\text{event}) $$

For example:

ID Start Stop Exposure Event
1 0 20 0 0
1 20 45 1 0
1 45 70 1 1
2 0 35 0 0
2 35 90 1 0

Each patient can have multiple rows.

The event indicator is typically 1 only on the final interval containing the event.

Data rule: For a given patient, intervals should correctly partition the period at risk, with covariate changes represented by new interval boundaries. The event indicator should identify the interval in which the event occurs.

R: Using the survival Package

In R, time-varying Cox models can be fit using the coxph() function from the survival package.

library(survival)

fit <- coxph(
  Surv(start, stop, event) ~ treatment,
  data = tv_data
)

summary(fit)

The key difference from a standard Cox model is the survival response:

Surv(start, stop, event)

rather than:

Surv(time, event)

The first form tells R that the data are represented using start-stop intervals.

R Worked Example

Consider:

tv_data <- data.frame(
  id = c(1,1,1,2,2,3,3),
  start = c(0,30,60,0,40,0,50),
  stop = c(30,60,90,40,100,50,120),
  treatment = c(0,1,1,0,1,0,1),
  event = c(0,0,1,0,1,0,1)
)

The Cox model is:

fit <- coxph(
  Surv(start, stop, event) ~ treatment,
  data = tv_data
)

summary(fit)

The treatment coefficient can be exponentiated to obtain the hazard ratio:

exp(coef(fit))

and a confidence interval can be obtained with:

exp(confint(fit))

Adding Baseline Covariates

Time-varying covariates can be combined with ordinary baseline covariates.

fit <- coxph(
  Surv(start, stop, event) ~
    treatment +
    age +
    sex +
    stage,
  data = tv_data
)

Here, treatment varies over time while age, sex, and baseline stage remain fixed.

The model therefore combines:

$$ X_i(t)= \left[ \text{Treatment}_i(t), \text{Age}_i, \text{Sex}_i, \text{Stage}_i \right] $$

Using the tt() Function

R's coxph() function also supports transformations in which the effect of a baseline covariate changes as a function of time.

For example:

fit <- coxph(
  Surv(time, event) ~ age + tt(age),
  data = data,
  tt = function(x, t, ...) x * log(t)
)

This is a different use of "time-dependent" modeling.

The patient's age itself does not change during the study.

Instead, the coefficient associated with age is allowed to have a time-dependent component.

Remember: tt() can be used to model a time-dependent effect. That is conceptually different from converting the dataset into start-stop intervals to represent a covariate whose observed value changes.

SAS: PROC PHREG

SAS PROC PHREG can analyze counting-process data using the start and stop times.

proc phreg data=tv_data;
    model (start, stop)*event(0) =
        treatment
        age
        sex
        stage;
run;

The notation:

(start, stop)*event(0)

defines the interval-censored risk representation used for the counting-process formulation.

SAS Example with a Time-Varying Treatment

proc phreg data=tv_data;
    model (start, stop)*event(0) = treatment age sex stage;
run;

The treatment variable can take different values on different rows for the same patient.

For example:

ID Start Stop Treatment Event
101 0 42 0 0
101 42 90 1 0
101 90 117 0 1

The model therefore uses treatment status appropriate to each interval.

Creating Start-Stop Data

A major practical challenge is constructing the analysis dataset correctly.

Suppose a patient has:

  • Enrollment at day 0
  • Treatment initiation at day 35
  • Biomarker measurement at day 60
  • Treatment discontinuation at day 90
  • Event at day 120

The analysis dataset may need intervals such as:

Start Stop Treatment Biomarker Event
0 35 0 Baseline 0
35 60 1 Baseline 0
60 90 1 Updated 0
90 120 0 Updated 1

Every time a covariate changes, a new interval begins.

The General Data-Construction Algorithm

1
Identify the patient's complete period of observation.
2
Collect all times at which any modeled covariate changes.
3
Add the event or censoring time.
4
Sort all relevant time points.
5
Create one interval between each consecutive time point.
6
Assign each covariate its value for that interval.
7
Set the event indicator to 1 only for the interval containing the event.

Data Quality Checks

Time-varying survival analyses are particularly sensitive to data-structure errors.

At minimum, verify:

  • Intervals are ordered chronologically.
  • There are no unintended overlapping intervals.
  • There are no unexplained gaps in the patient's risk period.
  • The final interval ends at the event or censoring time.
  • Only the event-containing interval has an event indicator of 1.
  • Covariate changes occur at the correct times.
  • No covariate value uses information observed after the interval.
  • Patients are not duplicated accidentally.

A Useful Validation Check in R

tv_data[order(tv_data$id, tv_data$start), ]

For each patient, inspect whether:

$$ start_{j+1}=stop_j $$

when contiguous intervals are expected.

You can also check for multiple events:

aggregate(
  event ~ id,
  data = tv_data,
  sum
)

For ordinary time-to-first-event analysis, the total event count per patient should generally be at most one.

Time-Varying Covariates and Causality

This is one of the most important advanced issues.

A time-varying covariate may itself be affected by prior treatment or evolving disease status.

For example:

1
Treatment affects the biomarker.
2
The biomarker reflects disease severity.
3
Disease severity affects subsequent treatment decisions.
4
Disease severity also affects the event risk.

The time-varying biomarker is therefore both affected by treatment and predictive of future treatment and outcome.

A conventional time-varying Cox regression may estimate an association, but it does not automatically recover a causal treatment effect in the presence of such time-dependent confounding.

Advanced point: When treatment and confounders change over time and prior treatment affects future confounder values, causal methods such as marginal structural models may be required for a causal treatment-effect question.

Time-Dependent Confounding

Suppose disease severity \(L(t)\) changes over time.

Treatment \(A(t)\) is influenced by severity:

$$ L(t)\rightarrow A(t) $$

But treatment also influences future severity:

$$ A(t)\rightarrow L(t+1) $$

and severity influences future event risk:

$$ L(t)\rightarrow T $$

This creates feedback between treatment and the time-varying confounder.

A standard regression adjustment can be problematic because the confounder may simultaneously be:

  • A predictor of future treatment
  • A predictor of the outcome
  • A consequence of previous treatment

Landmark Analysis

A landmark analysis is another approach for handling certain time-dependent exposure questions.

Choose a landmark time \(t_L\).

Only patients alive and event-free at \(t_L\) are included.

Exposure status at the landmark is then used to define groups for subsequent survival.

$$ T^*=T-t_L $$

The analysis then asks a question such as: Among patients alive and event-free at day 90, is survival after day 90 associated with treatment status at day 90?

Landmark analysis is useful when: the scientific question explicitly concerns prognosis conditional on surviving to a clinically meaningful time point. It is not a universal replacement for a time-varying Cox model.

Time-Varying Covariate vs. Landmark Analysis

Feature Time-Varying Cox Landmark Analysis
Uses changing exposure during follow-up Yes Usually summarized at landmark
Patients who fail before landmark Can contribute information Excluded from landmark population
Risk sets change over time Yes Post-landmark risk set
Handles multiple exposure changes Yes Usually less directly
Interpretation Current exposure association Conditional post-landmark prognosis

Time-Varying Covariates and the Proportional Hazards Assumption

It is important to understand that adding a time-varying covariate does not automatically solve proportional hazards violations.

Consider:

$$ h_i(t) = h_0(t)\exp\{\beta X_i(t)\} $$

The coefficient \(\beta\) can still be assumed constant.

If instead the treatment effect itself changes with time, the model may need:

$$ h_i(t) = h_0(t)\exp\{\beta(t)X_i\} $$

or a model containing an interaction between treatment and a function of time.

These are separate modeling decisions.

A Combined Model

In some situations both the covariate and its effect can vary over time:

$$ h_i(t) = h_0(t) \exp\{\beta(t)X_i(t)\} $$

This is considerably more complex and should be motivated by the scientific question and supported by sufficient data.

Time-Dependent Covariates Based on Events

A covariate can change when an intermediate event occurs.

For example, define:

$$ Z_i(t)= I(\text{hospitalization has occurred by time }t) $$

Before hospitalization:

$$ Z_i(t)=0 $$

After hospitalization:

$$ Z_i(t)=1 $$

This allows the analysis to compare the hazard before and after hospitalization.

But again, the interpretation is associational.

Patients who become hospitalized may already be becoming sicker, and hospitalization may therefore be a marker of disease severity rather than a randomized exposure.

Internal vs. External Time-Varying Covariates

A useful conceptual distinction is between external and internal time-varying covariates.

External Covariate

An external covariate evolves independently of the patient's event process, at least conceptually.

Examples might include:

  • Calendar-time environmental exposure
  • Ambient temperature
  • External treatment availability

Internal Covariate

An internal covariate is generated by the patient's own biological or clinical process.

Examples include:

  • Tumor burden
  • Biomarker concentration
  • Current disease status
  • Physiological measurements

Internal covariates require particular care because their evolution can be closely connected to the outcome process.

Last Observation Carried Forward: A Warning

Suppose a biomarker is measured every four weeks.

If the measurement at week 8 is 5.2, the analyst might use 5.2 until the week 12 measurement becomes available.

That can be a reasonable working definition of the current observed biomarker.

However, it should not be confused with a general solution to missing data.

Important: If a patient misses the week 12 assessment, automatically carrying the week 8 value forward may impose strong assumptions about the unobserved biomarker trajectory. The statistical handling of genuinely missing measurements should be justified separately.

Measurement Timing Matters

Suppose an event occurs on day 45 and the biomarker is measured on day 60.

The day-60 biomarker cannot be used as the covariate value for the day-45 risk set.

Doing so introduces future information into the model.

A safe temporal ordering is:

1
Covariate is observed.
2
Covariate becomes available for analysis.
3
Patient contributes subsequent risk time using that information.

Lagged Time-Varying Covariates

In some applications, the biologically relevant question concerns the prior measurement rather than the instantaneous current measurement.

For example:

$$ h_i(t) = h_0(t)\exp\{\beta X_i(t-L)\} $$

where \(L\) is a prespecified lag.

For example, a 7-day lag might be used when the scientific hypothesis is that the biomarker measured one week earlier predicts subsequent risk.

Lagging can also help ensure that the covariate clearly precedes the outcome.

Why the Choice of Lag Should Be Prespecified

Trying many lag periods and selecting the one producing the strongest association can inflate false-positive findings and produce unstable results.

A clinically justified lag should ideally be selected before examining the final outcome associations.

Time-Varying Treatment and Clinical Trials

In randomized trials, treatment assignment at baseline is ordinarily fixed.

Therefore, the primary intention-to-treat survival analysis usually uses treatment assignment as a baseline covariate.

A time-varying treatment variable answers a different question.

For example:

  • What is the association between current treatment exposure and risk?
  • What happens after treatment discontinuation?
  • Is cumulative exposure associated with outcome?
  • Is dose intensity associated with risk?

These analyses can be useful as secondary or exploratory analyses but should not automatically replace the prespecified primary analysis.

Clinical-trial principle: Do not redefine a randomized treatment effect as a time-varying observational exposure merely because treatment changes after randomization. Treatment switching, discontinuation, crossover, and adherence require a clearly defined estimand and appropriate causal strategy.

Cumulative Exposure

Sometimes the relevant variable is cumulative exposure rather than current exposure.

Define:

$$ C_i(t) = \int_0^t A_i(u)\,du $$

where \(A_i(u)\) represents treatment exposure.

If treatment is binary, \(C_i(t)\) can represent cumulative time exposed.

For example, a patient treated continuously for 60 days has:

$$ C_i(60)=60 $$

while a patient treated for only 20 days has:

$$ C_i(60)=20 $$

The survival model can then include cumulative exposure as a time-varying covariate.

Current Exposure vs. Cumulative Exposure

Exposure Definition Question
Current treatment What is the hazard while currently exposed?
Time since treatment initiation How does risk change with duration since starting treatment?
Cumulative exposure Is accumulated treatment exposure associated with risk?
Recent exposure Is exposure during a recent window associated with risk?

These are different estimands and should not be treated as interchangeable.

Time Since Exposure Initiation

Another useful time-varying variable is time since treatment initiation.

Define:

$$ S_i(t)= \begin{cases} 0,&t

This can model whether the association between treatment and risk changes according to time since treatment initiation.

For example, the risk immediately after initiation may differ from risk after several months.

Common Mistakes

  1. Classifying patients according to future exposure. "Ever treated" is not the same as treatment status at time \(t\).
  2. Using measurements that occur after the event. Future biomarker values must not be used to predict an earlier event.
  3. Confusing time-varying covariates with non-proportional hazards. Changing \(X(t)\) and changing \(\beta(t)\) are different concepts.
  4. Ignoring immortal time bias. Patients must not receive guaranteed event-free time merely because they are classified according to future exposure.
  5. Ignoring time-dependent confounding. A conventional time-varying Cox model does not automatically provide a causal estimate when confounders are themselves affected by prior treatment.
  6. Constructing overlapping intervals. The risk intervals must accurately represent the patient's follow-up.
  7. Using the wrong covariate timing. The covariate must represent information available at the relevant risk time.
  8. Treating last observation carried forward as a universal missing-data method. A time-varying data structure does not eliminate missing-data problems.
  9. Changing the primary estimand. A post-randomization time-varying exposure analysis may answer a different question from the trial's primary treatment-effect analysis.

Time-Varying Covariate Analysis Workflow

1
Define the scientific question and estimand.
2
Determine which covariates actually change during follow-up.
3
Define exactly when each covariate becomes available.
4
Construct start-stop or counting-process intervals.
5
Validate interval boundaries and event indicators.
6
Fit the extended Cox model.
7
Interpret hazard ratios according to the time-varying covariate definition.
8
Assess proportional hazards assumptions separately.
9
Investigate time-dependent confounding where relevant.
10
Perform sensitivity analyses using alternative clinically justified exposure definitions.

Model Diagnostics

The addition of time-varying covariates does not eliminate the need for model diagnostics.

Consider:

  • Proportional hazards diagnostics
  • Functional form of continuous covariates
  • Influential observations
  • Extreme biomarker values
  • Measurement timing
  • Missingness patterns
  • Number and length of risk intervals
  • Correlation among repeated covariates

Functional Form of a Time-Varying Continuous Covariate

Suppose \(X(t)\) is a continuous biomarker.

The basic model assumes:

$$ \log h_i(t) = \log h_0(t)+\beta X_i(t) $$

This means the log hazard is linear in the current biomarker value.

That may be inappropriate.

A nonlinear relationship could instead be represented with splines:

$$ \log h_i(t) = \log h_0(t) + f\{X_i(t)\} $$

where \(f(\cdot)\) is a flexible function.

In R, spline terms can be implemented using functions such as splines::ns().

library(survival)
library(splines)

fit <- coxph(
  Surv(start, stop, event) ~
    ns(biomarker, df = 3),
  data = tv_data
)

Interactions with Time

If the scientific question is whether a covariate's effect changes over time, an interaction can be used.

For example:

$$ h_i(t) = h_0(t) \exp\{\beta_1X_i+\beta_2X_i g(t)\} $$

where \(g(t)\) might be \(\log(t)\), \(t\), or another prespecified function.

This is modeling a time-varying coefficient, not a time-varying covariate.

Sensitivity Analyses

For important clinical analyses, sensitivity analyses may examine whether conclusions change under reasonable alternative specifications.

Examples include:

  • Different clinically justified lag periods
  • Current versus cumulative exposure
  • Alternative biomarker transformations
  • Alternative landmark times
  • Different rules for handling missing measurements
  • Different definitions of treatment discontinuation

Sensitivity analyses should be scientifically motivated rather than selected solely according to which specification produces the smallest \(p\)-value.

Reporting a Time-Varying Cox Analysis

A statistical report should make the time-varying definition reproducible.

At minimum, report:

  • The exact covariate treated as time-varying
  • How frequently it was measured
  • How measurement times were handled
  • How the covariate value was assigned between measurements
  • How treatment initiation and discontinuation were defined
  • Whether lags were used
  • The start-stop data structure
  • The Cox model specification
  • Handling of missing measurements
  • Whether baseline covariates were also included
  • How proportional hazards assumptions were assessed
  • Whether the analysis was intended to be causal or associational

Example Statistical Analysis Plan Language

A time-varying covariate analysis might be described conceptually as follows:

Example: Treatment exposure will be modeled as a time-varying covariate, with patients classified as unexposed from enrollment until treatment initiation and exposed thereafter. Follow-up will be represented using counting-process intervals, with a new interval created whenever treatment exposure changes. The Cox proportional hazards model will include baseline prognostic covariates prespecified in the statistical analysis plan. Hazard ratios and 95% confidence intervals will be reported.

Time-Varying Covariates in Recurrent-Event Settings

Time-varying covariates can also be used when patients experience multiple events.

However, recurrent-event analysis introduces additional issues concerning within-patient dependence.

Methods such as:

  • Andersen-Gill models
  • Prentice-Williams-Peterson models
  • Frailty models
  • Marginal recurrent-event models

may be appropriate depending on the estimand and event process.

A time-varying covariate answers the question of how predictors change over time; it does not by itself specify how repeated events should be modeled.

Time-Varying Covariates and Competing Risks

Time-varying covariates can also arise in competing-risk settings.

For example, a patient's treatment status or disease severity may change before experiencing one of several competing events.

The appropriate analysis depends on the estimand and whether the goal is:

  • Cause-specific hazard
  • Cumulative incidence
  • Subdistribution hazard
  • A causal treatment effect under competing risks

Simply adding a time-varying covariate to a Cox model does not resolve these competing-risk questions.

A Practical R Template

library(survival)

# Time-varying Cox model
fit <- coxph(
  Surv(start, stop, event) ~
    treatment +
    biomarker +
    age +
    sex +
    stage,
  data = tv_data
)

# Model summary
summary(fit)

# Hazard ratios
exp(coef(fit))

# 95% confidence intervals
exp(confint(fit))

A Practical SAS Template

proc phreg data=tv_data;

    model (start, stop)*event(0) =
        treatment
        biomarker
        age
        sex
        stage;

run;

Checking the Analysis Dataset

Before fitting the model, inspect several patients manually.

tv_data[
  order(tv_data$id, tv_data$start),
  c("id","start","stop","treatment","biomarker","event")
]

A good validation process should include patients who:

  • Never change exposure
  • Change exposure once
  • Change exposure multiple times
  • Have missing measurements
  • Experience the event
  • Are censored

Interpreting the Hazard Ratio Carefully

Suppose the fitted model gives:

$$ \hat{\beta}=-0.357 $$

Then:

$$ HR=e^{-0.357}\approx0.70 $$

The model estimates a 30% lower instantaneous hazard associated with the exposed covariate state compared with the reference state, conditional on the other variables in the model.

The phrase "at a given time" is important.

For a time-varying covariate, the comparison is based on the exposure state relevant to the risk set at that time.

What the Hazard Ratio Does Not Mean

A time-varying hazard ratio does not necessarily mean:

  • The treatment caused the observed difference.
  • Every patient experiences exactly the same proportional change.
  • The cumulative probability of an event changes by the same percentage.
  • The effect is constant over calendar time if the coefficient itself is allowed to vary.
  • The association applies to exposure values that occur in the future.

The exact interpretation depends on how the covariate and model were defined.

The Most Important Concept: Temporal Alignment

The single most important practical rule is:

$$ \boxed{ \text{Information used at time }t \text{ must be available by time }t } $$

If treatment begins at day 30, it cannot be coded as treatment exposure during days 0–30.

If a biomarker is measured at day 60, it cannot be used to predict an event that occurred at day 45.

If a patient must survive to day 90 to become eligible for an exposure category, that fact must be reflected in the risk-set construction.

Bottom line: Time-varying survival analysis is fundamentally about preserving the temporal relationship between covariates, risk sets, and events.

Summary of the Main Concepts

Concept Key Idea
Time-varying covariate The predictor value changes during follow-up
Extended Cox model Allows \(X_i(t)\) to enter the hazard model
Counting-process data Represents follow-up using start-stop intervals
Time-varying coefficient Allows \(\beta(t)\) to change with time
Immortal time bias Occurs when future exposure information incorrectly classifies earlier survival time
Landmark analysis Analyzes post-landmark survival conditional on surviving to a specified time
Time-dependent confounding Occurs when changing confounders are affected by prior treatment and affect future treatment
Lagged covariate Uses a previous covariate value to predict subsequent risk

Final Practical Checklist

1
Ask whether the covariate truly changes.
2
Define exactly when the new value becomes available.
3
Build start-stop intervals around every relevant covariate change.
4
Ensure future information never enters an earlier risk interval.
5
Distinguish time-varying covariates from time-varying coefficients.
6
Check carefully for immortal time bias.
7
Consider time-dependent confounding when treatment changes over time.
8
Validate the analysis dataset before interpreting the model.
9
Report the exact definition and timing of every time-varying covariate.

References

Cox, D.R. (1972). Regression models and life-tables. Journal of the Royal Statistical Society: Series B, 34, 187–220.

Cox, D.R. (1975). Partial likelihood. Biometrika, 62, 269–276.

Andersen, P.K. & Gill, R.D. (1982). Cox's regression model for counting processes: A large sample study. Annals of Statistics, 10, 1100–1120.

Kalbfleisch, J.D. & Prentice, R.L. (2002). The Statistical Analysis of Failure Time Data. 2nd ed. Wiley.

Therneau, T.M. & Grambsch, P.M. (2000). Modeling Survival Data: Extending the Cox Model. Springer.

Hernán, M.A., Brumback, B. & Robins, J.M. (2000). Marginal structural models to estimate the causal effect of zidovudine on the survival of HIV-positive men. Epidemiology, 11, 561–570.

Hernán, M.A. & Robins, J.M. (2020). Causal Inference: What If. Chapman & Hall/CRC.

Suissa, S. (2008). Immortal time bias in pharmaco-epidemiology. American Journal of Epidemiology, 167, 492–499.