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\):
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.
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 time | At risk (n) | Events (d) | 1 − d/n | S(t) |
|---|---|---|---|---|
| 0.64 | 30 | 1 | 0.9667 | 0.9667 |
| 1.49 | 29 | 1 | 0.9655 | 0.9333 |
| 2.07 | 27 | 1 | 0.9630 | 0.8988 |
| 6.18 | 24 | 1 | 0.9583 | 0.8613 |
| 8.10 | 23 | 1 | 0.9565 | 0.8239 |
| 8.52 | 22 | 1 | 0.9545 | 0.7864 |
| 8.58 | 21 | 1 | 0.9524 | 0.7490 |
| 9.77 | 20 | 1 | 0.9500 | 0.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:
| Time | 0 | 5 | 10 | 15 | 20 | 25 | 30 |
|---|---|---|---|---|---|---|---|
| Treatment at risk | 31 | 24 | 19 | 14 | 10 | 7 | 5 |
| Control at risk | 29 | 17 | 12 | 8 | 6 | 3 | 1 |
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:
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:
| t | S(t) | 95% CI |
|---|---|---|
| 5 | 0.8988 | (0.7180, 0.9662) |
| 10 | 0.7115 | (0.5039, 0.8445) |
| 15 | 0.6291 | (0.4175, 0.7820) |
| 20 | 0.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:
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:
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.