MerQuR+Statistics Glossary

Statistics Glossary → Time-dependent Cox Regression

Time-dependent Cox Regressionanalysis

A Cox regression for situations in which a person's characteristics change during follow-up (e.g. starting treatment later) or a factor's effect changes over time, modelling the risk of the event at each moment from the values at that moment.

Concept

Ordinary Cox regression treats the covariates as measured at the start of follow-up and fixed. Yet many factors change during follow-up: a patient receives a transplant after waiting several months, an athlete joins an injury-prevention programme mid-season, a drug dose is changed. Coding such a factor as fixed from the start creates 'immortal time' bias: those exposed later had to remain event-free until their exposure, so the exposure looks more protective than it is.

The solution is to split each person's follow-up into intervals during which the covariates stay constant (counting-process format): each row holds a (start, stop] interval, the covariate values in that interval and whether the interval ended with an event. At each event time, the model compares the current covariate values of the people at risk; the hazard ratio is read as in ordinary Cox. The same structure is used when a factor's effect changes over time: an interaction of the covariate with a function of time (x·g(t)) is added, relaxing the proportional hazards assumption.

When the same person has several rows, the rows are not independent; especially with recurrent events, within-subject robust standard errors should be used. A time-dependent covariate must be a value known before the event; variables affected by the event itself or carrying information about the future should not be put in the model. The proportional hazards assumption is checked with Schoenfeld residuals.

When to use it

  • When an exposure or treatment starts, stops or changes during follow-up (transplant, starting or stopping treatment, repeatedly measured laboratory values).
  • If a covariate's effect fades or grows over time (the proportional hazards assumption fails), use a time-interaction term; if the event recurs in the same person, use the counting-process format with within-subject robust standard errors.
  • If all covariates are fixed values measured at baseline, ordinary Cox regression is enough; if the covariate's change over follow-up is itself to be modelled, joint longitudinal-survival models can be considered.

An everyday example

A football club studies the time to a muscle injury during one season. Some players join a preventive flexibility programme at the start of the season, others in month 3 or 5. The first 5 months of a player who joined in month 5 must count as time without the programme; otherwise the programme looks more effective than it is, because its participants had already stayed injury-free until they joined. Time-dependent Cox splits each player's follow-up into intervals before and after joining and might estimate that the programme cuts the injury risk at any moment by 40% (HR = 0.60).

Parameters in MerQur

ID, Start, Stop, Event column and Covariates

Concept: In counting-process format each row is one follow-up interval of one person: the ID identifies the person, start and stop give the interval's limits, the event column says whether the interval ended with the event, and the covariates give the values in that interval.

Everyday example: A player who joined the programme in month 5 has two rows: (0, 5] with programme = 0 and no event; (5, 9] with programme = 1 and event = 1 if injured in month 9.

What it does: (start, stop] counting-process data; rows with start = stop are excluded with a warning.

Effect on the result: The whole model changes.

On the validation data: In Bladder, 166 zero-length rows (TStart = TStop) are excluded; Trt -0.45979, Number 0.17164 (SE 0.19996 and 0.04733). uis off_trt 2.27033 (SE 0.18650). heart: 172 rows, 103 persons, 75 events.

→ Time-dependent covariate and counting-process data

Categorical covariates and Categorical coding (Indicator first / Indicator last / Deviation)

Concept: A categorical covariate is expanded into dummy variables. With indicator coding each level is compared with a base level (the first or last); with deviation coding the levels are compared with the average of all levels.

Everyday example: With indicator coding, a player's position (goalkeeper, defender, midfielder, forward) is read 'relative to goalkeepers'. With deviation coding, each position shows how far its injury risk differs from that of an 'average position'.

What it does: Coding of categorical covariates (indicator: baseline level first or last level; deviation: last level -1).

Effect on the result: The baseline level of the dummy variable coefficients changes.

On the validation data: cgd treat + inherit: first level treat_rIFN-g -1.07222 (SE 0.26187), last level treat_placebo +1.07222, deviation treat_placebo 0.53611 (SE 0.13094); inherit 0.1777.

→ Dummy (indicator) variable coding

Penalizer (L2)

Concept: The L2 (ridge) penalty stabilises the model by pulling large coefficients towards zero. It reduces overfitting when there are many or highly correlated covariates and few events; the larger the penalty, the smaller the coefficients.

Everyday example: With only 30 injuries and a 12-covariate model, some hazard ratios may take extreme values. A small penalty pulls them towards more reasonable levels; with penalty 0 the model is ordinary unpenalised Cox.

What it does: The L2 penalty n·pen·½·Σ(b·sd_x)² (a ridge penalty on the standardized coefficients). 0 = unpenalized.

Effect on the result: Coefficients shrink toward zero; the reported log-likelihood and AIC are penalized (stated with a note on screen).

On the validation data: heart surgery coefficient: -0.63721 for penalty 0; -0.63555 for 0.001; -0.62109 for 0.01; -0.51139 for 0.1. At penalty 0.01 the reported log-likelihood is -290.7287 (the penalized likelihood, with the penalty term 0.1593 subtracted).

→ Regularization (penalty) and the penalty parameter λ/α

Time interaction (x·g(t)) and g(t) function (log t / t)

Concept: Allows a covariate's effect to change over time: alongside x the model includes the term x·g(t), with g(t) = log t or t. The interaction coefficient shows in which direction the effect changes as time passes.

Everyday example: If the flexibility programme's protective effect is strong in the first months and then fades, the 'programme x log(time)' term comes out positive. This shows the programme's hazard ratio moving towards 1 as the season goes on.

What it does: An x·g(t) term is added for the selected covariate; the data are split at the event times (heart from 172 rows to 3 606 rows). If a column that is not in the covariate list is selected, the term is not added and an explicit warning is given.

Effect on the result: A new interaction coefficient is added; the PH test, C-index and residuals are not produced when there is a time interaction.

On the validation data: Rats Group×log(t) -0.22952 (SE 1.82489); Group 0.63966 = -0.59976 - 5.4·(-0.22952). For g(t) = t, Group×t -8e-05. heart transplant×log(t) -0.08512.

→ Time-dependent covariate and counting-process data

Proportional hazards test (Schoenfeld) and PH test time transform

Concept: The test based on Schoenfeld residuals checks whether each covariate's hazard ratio is constant over time. The time transformation (Kaplan-Meier, rank, identity, log t) sets the time scale against which the residuals are judged; a small p means the proportional hazards assumption may fail for that covariate.

Everyday example: If the test is significant for player age, age affects injury risk differently at the start and end of the season. Adding a time interaction for age or stratifying by age group is then considered.

What it does: The Grambsch-Therneau score test; the transform is Kaplan-Meier, rank, time or log t. The test is skipped with the exact ties method and when x·g(t) is present, and a note is written.

Effect on the result: Only the PH test section changes.

On the validation data: heart global χ²: km 3.4731, rank 2.6843, time 4.6879, log 2.1163; Breslow km 3.4695.

→ Proportional hazards assumption

Strata variable (STRATA)

Concept: Stratification gives each stratum its own baseline hazard but treats the covariate effects as common across strata. It is a way to handle a variable that violates the proportional hazards assumption or whose effect is not of interest.

Everyday example: If injury risk evolves differently over time for teams playing on grass and on artificial turf, pitch type is made a stratum. The programme's hazard ratio is estimated jointly for both, but no separate HR is given for pitch type itself.

What it does: A separate baseline hazard for each stratum, common β.

Effect on the result: The coefficients change.

On the validation data: cgd hos.cat: steroids 1.13168; Bladder2 Visit (PWP total time, Breslow): Trt -0.3343 (SE 0.21609). Bladder2 stratified C-index 0.61520.

→ Stratified analysis (stratum variable)

Within-subject robust SE - cluster(id)

Concept: When the same person has several rows or several events, these observations are dependent. Cluster-robust (sandwich) standard errors by person ID account for this dependence; they do not change the coefficients but give their uncertainty more realistically.

Everyday example: If some players are injured two or three times in a season, a few injury-prone players inflate the event count. Within-subject robust SEs widen the confidence interval for the programme's hazard ratio to allow for this proneness.

What it does: The sandwich variance that accounts for the correlation among the rows of the same person.

Effect on the result: SE, p and intervals change; the naive and robust SE are given separately.

On the validation data: cgd robust SE 0.31183 / 0.31804 / 0.46871, naive 0.26187 / 0.23560 / 0.51689; robust Wald 16.8115 (128 clusters). Bladder sandwich SE 0.25801 / 0.06131 / 0.07555.

→ Cluster-robust (clustered) standard errors

Ties method (Efron / Breslow / Exact)

Concept: Sets how the partial likelihood is computed when several events occur at the same time (ties). The Efron approximation is accurate enough in most cases; the exact method is the most accurate but slow with many ties; Breslow is the simplest approximation.

Everyday example: If injuries are recorded only by week, several players may appear injured in the same week. With few ties the three methods give almost the same hazard ratio; with many, Efron or the exact method is preferred.

What it does: The ties approximation; the exact option is the discrete-time conditional logistic likelihood.

Effect on the result: Coefficients and likelihood change.

On the validation data: cgd treat: Efron -1.07222, Breslow -1.07400, exact -1.07906; LL -330.898 / -331.017 / -326.667.

→ Ties method (Efron, Breslow, exact)

Extra outputs: Residuals and Save residuals to dataset

Concept: Residuals are used to check the model's fit: martingale residuals give the difference between observed and expected numbers of events, deviance residuals a more symmetric form of it, Cox-Snell residuals overall fit, and Xb each row's linear risk score. They can be saved to the data set for further study.

Everyday example: A player with a large negative martingale residual is one the model rated high-risk who was never injured. If such players share something (e.g. they all work with the same physiotherapist), a variable may be missing from the model.

What it does: Martingale, deviance, Cox-Snell and Xb residuals; the save option adds them to the dataset as columns.

Effect on the result: Adds output; saving does not change the text.

On the validation data: For heart, the residuals, including martingale and Xb, are given row by row.

→ Cox model residuals (martingale, deviance, Cox-Snell, dfbeta)

Confidence Level (%90 / %95 / %99 / Other, custom value)

Concept: Sets the level of the confidence interval for the hazard ratios; if the interval excludes 1, the factor changes the risk significantly.

Everyday example: If the programme's hazard ratio is 0.60 with a 95% confidence interval of 0.40-0.90, the programme very probably lowers injury risk; at 99% the interval may widen enough to include 1.

What it does: The level of the HR interval. The heading, comment line and significance mark use the selected level.

Effect on the result: Only the intervals change.

On the validation data: heart surgery HR interval: 95% (0.2574, 1.0860), 90% (0.2890, 0.9674), 99% (0.2053, 1.3617), 80% (0.3303, 0.8465), 99.9% (0.1579, 1.7703).

→ Confidence level and confidence interval

Example on real data

Data: Stanford heart transplant, R survival heart

Variables: ID id, interval start-stop, event event, covariates age, year, surgery and the time-dependent transplant

  • Question: In the Stanford heart transplant program (103 patients, 172 (start, stop] rows, 75 deaths), how do transplant (a covariate that changes from 0 to 1 over time), age, year of acceptance and prior surgery affect the risk of death?
  • Why time-dependent: Patients receive the transplant after a waiting time; coding transplant as fixed at baseline creates "immortal time" bias. The counting-process form splits each patient's time at risk into intervals before and after the transplant.
  • Model test: Likelihood ratio χ²(4) = 15.11, p = 0.0045; Wald χ²(4) = 14.49, score χ²(4) = 15.03. Harrell C = 0.6358.
  • Result: Age increases the risk (HR = 1.0275 [1.0003, 1.0555], p = .048); a later year of acceptance reduces the risk (HR = 0.8639 [0.7524, 0.9918], p = .038). Prior surgery is borderline (HR = 0.529, p = .083); transplant is not significant (HR = 0.990 [0.535, 1.831], p = .974).
  • Limitation: The near-zero transplant effect may arise because the risk is high early after transplant and low later; whether the transplant effect changes over time should be tested separately.
  • APA: In the time-dependent Cox model, age, HR = 1.03, 95% CI [1.00, 1.06], p = .048, and year of acceptance, HR = 0.86, 95% CI [0.75, 0.99], p = .038, are significant; transplant is not significant, p = .974; LR χ²(4, N = 103) = 15.11, p = .004.

Related concepts

Proportional hazards assumptionTies method (Efron, Breslow, exact)Time-dependent covariate and counting-process dataRegularization (penalty) and the penalty parameter λ/αCox model residuals (martingale, deviance, Cox-Snell, dfbeta)CovariateStratified analysis (stratum variable)Ties and zero differences (rank tests)

The numbers in the examples are MerQur's output on independent, publicly available validation data; see the MerQur Technical Note for details.