Inferensys

Glossary

Time-Varying Covariates

Predictor variables whose values change over the observation period, requiring extended Cox models or landmark analysis to avoid immortal time bias in longitudinal studies.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
LONGITUDINAL PREDICTORS

What is Time-Varying Covariates?

Predictor variables whose values change over the observation period, requiring specialized statistical methods to avoid immortal time bias in survival analysis.

Time-varying covariates are predictor variables in a regression model whose values are not fixed at baseline but change over the follow-up period. Unlike fixed covariates such as sex or birth year, these dynamic predictors—like repeated blood pressure readings, cumulative drug dosage, or disease progression markers—require extended Cox models or landmark analysis to correctly capture their temporal relationship with the event of interest.

Standard survival models that treat time-dependent variables as fixed introduce immortal time bias, a critical flaw where future exposure status is incorrectly assigned to past survival time. Proper handling requires structuring data in a counting process format with (start, stop] intervals, enabling the hazard at time t to depend only on covariate values observed up to that moment, preserving the causal temporal ordering essential for valid inference.

LONGITUDINAL PREDICTORS

Key Characteristics of Time-Varying Covariates

Time-varying covariates are predictor variables whose values change over the observation period, requiring specialized statistical methods to avoid immortal time bias and accurately capture dynamic risk relationships.

01

Definition and Core Mechanism

A time-varying covariate is a predictor whose value is not fixed at baseline but can change during follow-up. Unlike time-fixed covariates (e.g., sex, birth year), these variables capture dynamic patient states such as repeated lab measurements, medication adherence patterns, or disease progression markers. In survival analysis, they require data restructuring into a counting process format where each subject contributes multiple rows corresponding to intervals where covariate values remain constant. The hazard at time t is modeled as a function of the covariate value at that exact moment, not its baseline value.

02

Internal vs. External Covariates

Time-varying covariates are classified into two fundamental types that dictate analytical approach:

  • Internal (Endogenous) Covariates: Generated by the subject themselves and require the subject to be alive to be measured. Examples include CD4 count in HIV patients, tumor size in cancer studies, or blood pressure readings. Their existence is conditional on survival, creating complex dependencies.

  • External (Exogenous) Covariates: Determined independently of the subject's survival status. Examples include air pollution levels, calendar time, or treatment assignment in a crossover trial. These can be further subdivided into fixed, defined, and ancillary external covariates.

03

Immortal Time Bias

Immortal time bias is a critical error that occurs when time-varying exposures are mishandled as fixed baseline variables. Consider a study comparing survival between patients who receive a transplant versus those who do not. Patients must survive long enough to receive the transplant—this waiting period is immortal time. If the transplant variable is coded as a fixed baseline characteristic, the survival time before transplantation is incorrectly attributed to the transplant group, artificially inflating its apparent benefit. Proper handling using time-dependent Cox models or landmark analysis eliminates this bias by classifying person-time before and after the exposure separately.

04

Extended Cox Model Specification

The extended Cox proportional hazards model accommodates time-varying covariates by modifying the hazard function:

h(t|X(t)) = h₀(t) × exp(β₁X₁ + β₂X₂(t))

Where X₂(t) represents a covariate that changes over time. The model assumes that the effect of the covariate is instantaneous and that the proportional hazards assumption holds for the time-varying effect. Implementation requires data in counting process (start, stop] format, where each row represents an interval with constant covariate values. Software implementations in R (survival::coxph) and Python (lifelines) support this structure natively.

05

Landmark Analysis Approach

Landmark analysis is an alternative to time-dependent Cox models that avoids complex data restructuring. The method:

  • Selects a specific landmark time (e.g., 6 months after diagnosis)
  • Excludes patients who experienced the event or were censored before the landmark
  • Uses covariate values measured at the landmark to predict subsequent survival
  • Treats all predictors as fixed from that point forward

This approach is intuitive for clinicians and avoids immortal time bias by conditioning on survival to the landmark. However, it discards information from patients who die early and is sensitive to the choice of landmark time. Dynamic landmarking extends this by updating predictions at multiple landmarks.

06

Joint Modeling Alternative

When time-varying covariates are measured with error or at irregular intervals, joint models for longitudinal and survival data provide a superior framework. These models simultaneously estimate:

  • A longitudinal submodel (e.g., linear mixed effects) describing the trajectory of the time-varying biomarker
  • A survival submodel (e.g., Cox model) linking the true unobserved trajectory to the hazard

This approach accounts for measurement error and handles endogenous covariates naturally. The association is typically parameterized through the current value, current slope, or cumulative effect of the longitudinal process. Software includes R packages JM and joineRML.

TIME-VARYING COVARIATES

Frequently Asked Questions

Clear answers to common questions about predictor variables that change over time in survival analysis, including how to avoid immortal time bias and choose the right modeling approach.

A time-varying covariate is a predictor variable whose value changes over the observation period for a given subject, in contrast to a time-fixed covariate (like sex or baseline age) which remains constant. Examples include repeated laboratory measurements (e.g., CD4 counts in HIV studies), cumulative drug exposure, or a patient's transplant status that changes mid-study. Standard Cox proportional hazards models assume covariates are fixed at baseline; using a time-varying covariate requires restructuring the dataset into a counting process format where each subject contributes multiple rows corresponding to intervals where the covariate remains constant. This allows the hazard at time t to depend on the covariate value at that exact moment, reflecting the dynamic nature of disease progression and treatment response.

TIME-VARYING COVARIATES

Common Examples in Clinical Research

In longitudinal clinical studies, many patient characteristics change over the observation period. Treating these as static values introduces immortal time bias and distorts hazard ratios. Below are key examples requiring extended Cox models or landmark analysis.

01

Repeated Laboratory Measurements

Serial biomarker values such as CD4+ T-cell counts, serum creatinine, or tumor marker levels are classic time-varying covariates. A patient's risk profile changes with each new lab result. Using only the baseline value ignores disease progression or treatment response. In the extended Cox model, these are formatted in counting process style with (start, stop] intervals, updating the hazard at each measurement time. This allows the model to capture the dynamic relationship between biomarker trajectory and event risk.

02

Cumulative Drug Exposure

In pharmacoepidemiology, cumulative dose or duration of treatment changes continuously. A patient on a 6-month course of a cardiotoxic agent has a different risk at month 1 versus month 6. Treating exposure as a baseline binary variable creates immortal time bias—patients must survive long enough to receive the full course. Time-varying analysis segments follow-up into pre-exposure, during-exposure, and post-exposure intervals, accurately attributing events to the correct exposure window.

03

Disease Progression Status

In oncology trials, disease progression is both a time-varying covariate and a potential endpoint. When analyzing overall survival, progression status acts as an internal time-dependent covariate—it only exists because the patient survived to experience it. Standard Cox regression fails here. Landmark analysis or joint models for longitudinal and survival data are required to avoid conditioning on the future. The covariate is updated at the progression date, splitting the patient's timeline into pre- and post-progression intervals.

04

Treatment Crossover and Switching

In randomized trials where patients in the control arm may cross over to the experimental treatment upon progression, the actual treatment received becomes time-varying. An intent-to-treat analysis preserves randomization but underestimates the treatment effect. Rank-preserving structural failure time models or marginal structural models with inverse probability weighting are used to estimate the causal effect of treatment while accounting for the time-dependent confounding introduced by crossover decisions.

05

Transplant or Surgical Intervention

A solid organ transplant or surgical procedure occurring during follow-up fundamentally alters the hazard. In survival analysis of end-stage disease, receiving a transplant is a time-varying covariate. The challenge is that patients must survive to the transplant date, creating waiting-time bias. The covariate is coded as 0 before the procedure and 1 after, with the timeline split at the surgery date. This allows estimation of the post-transplant hazard ratio relative to the pre-transplant baseline.

06

Adherence and Compliance Metrics

Medication possession ratio (MPR) or proportion of days covered (PDC) are dynamic adherence measures that fluctuate over a study period. A patient with 90% adherence in month 1 may drop to 40% by month 6. Treating adherence as a fixed baseline average misclassifies exposure. Time-varying analysis updates the adherence metric at each refill or assessment window, allowing the model to capture the true relationship between current adherence behavior and clinical outcomes.

COVARIATE CLASSIFICATION

Time-Varying vs. Time-Fixed Covariates

Comparison of predictor variable types in survival analysis based on their temporal behavior and modeling requirements

FeatureTime-Varying CovariatesTime-Fixed CovariatesMixed Covariates

Definition

Predictors whose values change during the observation period

Predictors measured once at baseline and assumed constant

Models incorporating both static and dynamic predictors

Measurement timing

Repeated assessments at multiple time points

Single measurement at study entry

Baseline plus scheduled follow-up assessments

Primary model type

Extended Cox model with counting process format

Standard Cox proportional hazards model

Joint models or landmark analysis

Data structure

Multiple rows per subject (start-stop intervals)

Single row per subject

Combination of wide and long formats

Handles immortal time bias

Examples

Blood pressure, CD4 count, tumor size, medication adherence

Sex, race, baseline age, genetic variants

Baseline age plus longitudinal biomarker trajectories

Proportional hazards assumption

Can be assessed via Schoenfeld residuals per interval

Standard Schoenfeld residual test

Requires careful interval-specific diagnostics

Missing data complexity

High (intermittent missingness, dropout)

Low (single observation)

Moderate to high

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.