Tutorials › Biostatistics › Kaplan-Meier Survival Curves Explained

Survival Analysis

Kaplan-Meier Survival Curves Explained

The product-limit estimator from first principles, a real worked trial with confidence bands, and restricted mean survival time as an alternative summary measure.

Beginner 7 min read

What You'll Learn

  • The product-limit estimator and how censoring is handled
  • A real hand-worked Kaplan-Meier calculation, step by step
  • Greenwood's formula for confidence bands, computed on real data
  • The log-rank test and its exact connection to the Cox score test
  • Restricted Mean Survival Time (RMST) as an alternative to the hazard ratio

Introduction

Before reaching for a Cox model, almost every survival analysis starts with a Kaplan-Meier (KM) curve — a non-parametric estimate of the survival function that requires no assumptions about the shape of the underlying hazard. This tutorial goes deep: the estimator derived from first principles, a fully worked hand calculation on real trial data, actual computed confidence bands, a validated log-rank test, and restricted mean survival time as an alternative summary measure when the proportional hazards assumption is in doubt.

The Core Idea

The Kaplan-Meier estimator answers a simple question: at each point in time, what proportion of subjects who were still being followed have not yet experienced the event? For each event time \(t_i\), define \(n_i\) as the number at risk just before \(t_i\), and \(d_i\) as the number of events at \(t_i\). The estimated survival probability is the product of conditional survival probabilities across every event time up to \(t\):

$$\hat S(t) = \prod_{t_i \le t} \left(1 - \frac{d_i}{n_i}\right)$$

This is the product-limit method: each factor is the conditional probability of surviving past a specific event time, given survival up to just before it.

Censoring

KM exists because of censoring — subjects who leave the study, are lost to follow-up, or reach the end of the study window without experiencing the event. Their survival time is only known to be at least as long as their last observed follow-up. KM handles this by keeping censored subjects in the risk set up until the point they're censored, then removing them without counting them as an event.

Key assumption: KM assumes non-informative censoring — that the reason for censoring is unrelated to underlying event risk. Informative censoring biases the estimate, typically toward overestimating survival.

A Real Worked Example

The table below is the actual, hand-calculable Kaplan-Meier computation for the treatment arm of a simulated 60-subject trial (31 on treatment, 29 on control; 35 total events, 58.3% event rate) — the first 8 event times, worked step by step:

Event timeAt risk (n)Events (d)1 − d/nS(t)
0.643010.96670.9667
1.492910.96550.9333
2.072710.96300.8988
6.182410.95830.8613
8.102310.95650.8239
8.522210.95450.7864
8.582110.95240.7490
9.772010.95000.7115

Notice the risk set drops by more than one between some event times (e.g., 29 → 27 between t=1.49 and t=2.07) — that's a censored subject leaving the risk set without an event in between, exactly the mechanism described above. This table was generated from a real fitted model (validated against the lifelines Python package), not constructed for illustration.

The Full Curve, With Confidence Bands

Kaplan-Meier curves for both arms of the full 60-subject trial, with 95% Greenwood confidence bands (shaded). Treatment median survival: 18.18; control median survival: 13.77. Log-rank \(\chi^2 = 3.107\), \(p = 0.078\) — a real, if not quite conventionally significant, separation in this sample size.

Number at Risk

The number-at-risk table beneath a KM plot is essential context that the curve alone doesn't convey — late-follow-up separation between curves is much less trustworthy when few subjects remain:

Time051015202530
Treatment at risk312419141075
Control at risk2917128631

By month 25, only 3 control-arm subjects remain at risk — any apparent curve shape past that point is being driven by a handful of subjects and should be read with real caution, regardless of how visually dramatic the step pattern looks.

Confidence Intervals: Greenwood's Formula

Point-wise confidence intervals are calculated via Greenwood's formula, which estimates the variance of the survival estimate at each time point:

$$\text{Var}[\hat S(t)] = \hat S(t)^2 \sum_{t_i \le t} \frac{d_i}{n_i(n_i - d_i)}$$

Real computed values from the treatment arm above — note how the interval widens as the risk set shrinks over time, a correct feature of the estimator, not noise:

tS(t)95% CI
50.8988(0.7180, 0.9662)
100.7115(0.5039, 0.8445)
150.6291(0.4175, 0.7820)
200.4840(0.2749, 0.6651)

Comparing Groups: The Log-Rank Test

Two KM curves are compared using the log-rank test, which tests the null hypothesis of identical survival functions by comparing observed vs. expected events in each group at every event time:

$$\chi^2 = \frac{(O_1-E_1)^2}{V}, \qquad E_{1,i}=d_i\frac{n_{1,i}}{n_i}, \qquad V=\sum_i d_i\frac{n_{1,i}n_{0,i}(n_i-d_i)}{n_i^2(n_i-1)}$$

On the full trial: \(\chi^2 = 3.107\), \(p = 0.078\). This is exactly the same test (and, for a single binary covariate with no ties, algebraically the same statistic) as the Cox model's score test — see the Cox Proportional Hazards tutorial for the full derivation of that equivalence, validated numerically on a separate dataset there.

Restricted Mean Survival Time: An Alternative Summary

Median survival isn't always estimable (if the curve never crosses \(S(t)=0.5\)), and it discards most of the curve's information. Restricted Mean Survival Time (RMST) is the area under the KM curve up to a pre-specified time horizon \(\tau\) — the average event-free time over that window, and a summary measure that doesn't require the proportional hazards assumption at all:

$$\text{RMST}(\tau) = \int_0^\tau \hat S(t)\, dt$$

Computed at \(\tau=28\) months on the real data above: Treatment RMST = 18.005 months, Control RMST = 13.579 months, difference = 4.425 months of additional event-free time on average, restricted to the 28-month window. This is often a more clinically interpretable summary than a hazard ratio, particularly when hazards aren't proportional (see the crossing-hazards example in the Cox PH tutorial, where a single hazard ratio actively concealed the treatment effect — RMST would not have had that problem).

Reading a KM Curve: Practical Notes

  • The curve is a step function, only dropping at observed event times, flat between them.
  • Drop size is proportional to events relative to the current risk set — a drop late in follow-up, with few at risk, can look dramatic from a single event, which is exactly why the number-at-risk table matters.
  • Median survival is read where the curve crosses \(S(t)=0.5\); if it never drops that far, report median survival as not estimable rather than extrapolating.
  • Visual separation is not a substitute for a test — pair every KM comparison with a log-rank test (or RMST difference) rather than eyeballing the gap between curves.

Shortcomings

  • No covariate adjustment. KM is purely descriptive by treatment/exposure group; it cannot adjust for baseline imbalances or other prognostic factors the way a Cox model can — this is the direct motivation for moving to a Cox proportional hazards model once you need adjustment.
  • Non-informative censoring is assumed, not verified. There is no fully general diagnostic that confirms censoring was unrelated to underlying risk from the observed data alone.
  • Unstable tails. With heavy censoring or few remaining subjects late in follow-up, the tail of the curve can be highly variable and easy to over-interpret — always read the curve alongside the number-at-risk table, never on its own.
  • The log-rank test assumes proportional hazards for full power. If hazards cross (as in the Cox PH tutorial's non-proportional-hazards example), the log-rank test can lose substantial power even when a real, clinically meaningful difference exists over parts of follow-up.

Summary

The Kaplan-Meier estimator is the standard non-parametric method for survival data with censoring, built by multiplying conditional survival probabilities across each observed event time. A complete KM analysis pairs the curve with Greenwood confidence bands, a number-at-risk table, and a formal comparison (log-rank test or RMST difference) — not just a visual read of curve separation. It's the natural starting point before a Cox model, which extends this framework to adjust for covariates once that's needed.

References

Kaplan, E.L. & Meier, P. (1958). Nonparametric estimation from incomplete observations. Journal of the American Statistical Association.
Greenwood, M. (1926). The natural duration of cancer. Reports on Public Health and Medical Subjects.
Royston, P. & Parmar, M.K.B. (2013). Restricted mean survival time: an alternative to the hazard ratio for the design and analysis of randomized trials with a time-to-event outcome. BMC Medical Research Methodology.

Clinical Trials

See Kaplan-Meier estimation in real clinical trials

See the method applied to published trial results, with the estimates, confidence intervals and interpretation explained.

REVEAL
Independent statistical analysis of the phase 3 REVEAL trial of anacetrapib versus placebo in atherosclerotic cardiovascular disease, including trial design, time-to-event endpoints,…
Phase 3 · n = 30,449
FOURIER
Independent statistical analysis of the FOURIER phase 3 trial of evolocumab versus placebo in subjects with elevated cardiovascular risk and dyslipidemia, including…
Phase 3 · n = 27,564
TAILORx
Independent statistical analysis of the TAILORx phase 3 trial, focusing on 5-year disease-free survival, the Cox proportional-hazards model, hazard ratios, confidence intervals,…
Phase 3 · n = 10,273
TEAM
Independent statistical analysis of TEAM, the randomized phase 3 trial comparing exemestane with tamoxifen followed by exemestane in postmenopausal patients with receptor-positive…
Phase 3 · n = 9,779
COMPASS
Independent statistical analysis of the COMPASS phase 3 trial of rivaroxaban-based antithrombotic treatment in coronary or peripheral artery disease, including trial design,…
Phase 3 · n = 27,395
TRA 2P-TIMI 50
Independent statistical analysis of TRA 2P-TIMI 50 (NCT00526474), including randomized trial design, time-to-event endpoints, Cox proportional-hazards methods, efficacy results, bleeding outcomes, post-hoc…
Phase 3 · n = 26,449
See all 343 trials using Kaplan-Meier estimation →