Survival analysis
How Kaplan–Meier curves, log-rank tests and Cox regression analyze the time until an event, such as failure or death, while correctly using subjects not yet observed to have the event.
What it is
Survival analysis is a set of statistical methods for data on the time until an event: death, relapse, machine failure, equipment repair, customer churn or a material cracking. Its defining feature is censoring: for some subjects the event has not happened by the end of observation (or they are lost to follow-up), so their true time is known only to exceed a certain value. Ordinary methods, such as averaging times or regression, either discard these subjects or treat them as if the event had occurred, and both choices bias results. Survival methods use the partial information censored cases carry.
It answers questions such as: What fraction of patients survive 5 years? Does the new treatment lengthen time to relapse? Which factors raise or lower the risk of failure, and by how much? What is the median time to failure? How does risk change over time?
Fundamentals
Basic functions
Let T be the event time. The survival function S(t) = P(T > t) is the probability of surviving beyond t, starting at 1 and falling. The hazard function h(t) = limΔt→0 P(t ≤ T < t + Δt | T ≥ t)/Δt is the instantaneous event rate among those still at risk, and the cumulative hazard H(t) = ∫0t h(u) du satisfies S(t) = exp[−H(t)]. A constant hazard gives the exponential distribution, S(t) = e−λt, with mean 1/λ; the Weibull allows monotone hazards. The median survival time is the t at which S(t) = 0.5, and it is preferred to the mean because follow-up is usually incomplete. Censoring is mostly right-censoring; left-censoring (event before observation began) and interval-censoring (event between two checks) also occur. A key assumption is non-informative censoring: the reason a subject is censored must be unrelated to their risk of the event.
Kaplan–Meier estimator and log-rank test
The Kaplan–Meier (product-limit) estimator is the standard non-parametric estimate of S(t). At each distinct event time ti, with di events and ni subjects at risk just before it:
Ŝ(t) = Πti ≤ t (1 − di/ni)
The curve is a step function that drops at events, while censored subjects leave the risk set without causing a drop (marked by ticks). Confidence bands use Greenwood’s formula for the variance, Var[Ŝ(t)] ≈ Ŝ(t)2 Σ di/[ni(ni − di)], preferably on a log-log scale. Curves of two or more groups are compared with the log-rank test, which compares observed with expected events in each group at every event time under the null hypothesis of identical survival curves (chi-square with g − 1 df); it is most powerful when hazards are proportional. Alternatives like the Wilcoxon (Breslow) or Fleming–Harrington tests weight early or late differences. Always show the numbers at risk below the plot, since the tail of a KM curve rests on few subjects. The KM curve does not adjust for covariates.
Cox proportional hazards regression
To assess several factors at once, the Cox model specifies the hazard for a subject with covariates x as
h(t | x) = h0(t) exp(β1x1 + … + βpxp)
where h0(t) is an unspecified baseline hazard, so no distribution of times is assumed (semi-parametric). The coefficients are estimated by maximizing the partial likelihood, which uses only the order of events. The exponentiated coefficient eβ is the hazard ratio (HR): HR = 0.7 for treatment means a 30% lower instantaneous risk at any time, and HR > 1 means higher risk, with a confidence interval and Wald or likelihood-ratio tests. The central assumption is proportional hazards: the HR does not change over time. It is checked with Schoenfeld residuals (a test and plot against time) and log-log plots of survival curves. If violated, options are stratification on the offending variable, time-varying coefficients or covariates (such as interaction with log t), restricted mean survival time (RMST) comparison, or accelerated failure time models. Ties in event times are handled by the Efron or Breslow approximation, and the rule of thumb is about 10 events per covariate (events, not subjects, set the effective sample size).
Parametric models, competing risks and extensions
- Parametric models (exponential, Weibull, log-normal, log-logistic) fit a specified distribution, giving smooth curves and extrapolation. Accelerated failure time (AFT) models describe how covariates stretch or shrink time, log T = β′x + σε, with a time ratio as effect measure.
- Competing risks: when other events prevent the event of interest (death from another cause), the KM estimate overstates the probability of the event; use the cumulative incidence function and Fine–Gray or cause-specific hazard models.
- Time-varying covariates and recurrent events (Andersen–Gill, PWP, frailty models) allow covariates that change during follow-up and repeated events, and frailty models include random effects for clustered data.
Software: R (survival, survminer, cmprsk, flexsurv), Python (lifelines, scikit-survival), SAS (PROC LIFETEST, PHREG), Stata (stcox) and SPSS.
Typical applications and limits
Applications include clinical trials and cohort studies, device and component reliability, warranty analysis, ecology (time to dispersal), economics (unemployment duration) and customer retention. Limits include the need for adequate follow-up, the non-informative censoring assumption, proportional hazards and the need for clearly defined time zero and event.
Basic operation
- Define time zero and the event. Specify the start of observation, the event and the censoring rules.
- Prepare the data. Record time and an event indicator (1 = event, 0 = censored) per subject, plus covariates.
- Plot Kaplan–Meier curves. Show groups, confidence bands and numbers at risk.
- Compare groups. Run a log-rank test and report median survival with confidence intervals.
- Fit a Cox model. Include relevant covariates, with enough events per variable.
- Check assumptions. Test proportional hazards with Schoenfeld residuals, and examine influential points.
- Consider alternatives. Use stratification, time-varying effects, competing risks or parametric models if needed.
- Collect the output. You obtain survival curves and hazard ratios with intervals; competing risks and model checking are covered in the video.
Good practice
- Define time zero clearly. Ambiguity biases results.
- Do not drop censored cases. Use them in the analysis.
- Show numbers at risk. Tails of curves are uncertain.
- Check proportional hazards. Do not assume it.
- Account for competing risks. KM can mislead when they are common.
- Report fully and handle data carefully. State censoring, follow-up and event counts, and protect the privacy of patient or customer records.
Key terms
- Censoring — incomplete observation of the event time for some subjects.
- Survival function S(t) — the probability of remaining event-free beyond time t.
- Hazard rate — the instantaneous event rate among those still at risk.
- Kaplan–Meier estimator — a non-parametric estimate of the survival curve.
- Hazard ratio — the relative event rate between groups or per unit of a covariate.
- Proportional hazards — the assumption that hazard ratios stay constant over time.
- Competing risk — another event that prevents the event of interest from happening.
Video coming soon
About five minutes on Survival analysis: how it works in detail, how the data is acquired, and how it is analyzed.
More in 3.6 Time Series, Survival and Evidence Synthesis
