Kaplan–Meier Survival Analysis
Many clinical outcomes are not simply present or absent — they occur at a particular point in time. Time to death, time to disease recurrence, time to first hospitalisation: these time-to-event outcomes require a different analytical framework from the methods used for continuous or binary endpoints. The complication is censoring: a patient who is lost to follow-up, or who has not yet experienced the event when the study ends, provides partial information — we know they survived at least until their last contact, but not what happened afterwards. Standard methods that ignore censoring produce biased estimates of survival.
The Kaplan–Meier estimator handles censored observations correctly, producing a step-function estimate of the survival curve — the probability of surviving beyond any given time point — directly from the observed event and censoring times. It requires no assumptions about the underlying distribution of survival times.
The Product-Limit Estimator
Let $t_1 < t_2 < \cdots < t_k$ be the ordered times at which at least one event occurs. At each event time $t_i$, let $d_i$ be the number of events and $n_i$ the number of subjects still at risk (those who have neither experienced the event nor been censored before $t_i$). The Kaplan–Meier estimate of the survival function at time $t$ is:
$$ \hat{S}(t) = \prod_{i:\, t_i \leq t} \frac{n_i - d_i}{n_i} $$The product is taken over all event times up to and including $t$. Between consecutive event times the estimate is constant, producing the characteristic step function: $\hat{S}(t)$ remains flat, then drops vertically at each event. Censored observations contribute to the at-risk count $n_i$ at times before their censoring but are removed from the risk set afterwards — they inform the curve without biasing it.
The formula can be understood as a sequence of conditional probabilities. At each event time, $d_i/n_i$ is the observed proportion who experienced the event among those still at risk; $(n_i - d_i)/n_i$ is the conditional probability of surviving past that moment given survival up to it. Multiplying these conditional probabilities gives the unconditional probability of surviving past time $t$.
Worked example
Ten subjects are followed. Events occur at months 2, 5, 8, 11, and 15; one subject is censored between each consecutive pair of event times.
| Time (months) | At risk ($n$) | Events (d) | ($n$ − d) / $n$ | Ŝ($t$) |
|---|---|---|---|---|
| 2 | 10 | 1 | 9/10 = 0.900 | 0.900 |
| 5 | 8 | 1 | 7/8 = 0.875 | 0.788 |
| 8 | 6 | 1 | 5/6 = 0.833 | 0.656 |
| 11 | 4 | 1 | 3/4 = 0.750 | 0.492 |
| 15 | 2 | 1 | 1/2 = 0.500 | 0.246 |
At each step, the updated estimate multiplies the previous value by the conditional survival probability. The drop from 0.900 to 0.788 between months 2 and 5 is larger than the equal number of events at each step would suggest from the parametric perspective, because one censored observation has reduced the at-risk count from 9 to 8 by month 5.
Censoring
The most common form of censoring in clinical studies is right censoring: the subject's follow-up ends before the event is observed. Three situations produce right-censored observations:
- The study ends and the subject has not yet experienced the event (administrative censoring).
- The subject is lost to follow-up — emigration, withdrawal, death from a competing cause.
- The subject withdraws consent.
In all three cases the censoring time is the last date at which the subject was known to be event-free. Kaplan–Meier assumes that censoring is non-informative: a censored subject's future risk, had they been followed, would be the same as that of subjects who remain under observation. This assumption is violated if, for example, subjects who experience adverse effects are selectively withdrawn — in that case the censored observations are not a random subset of the at-risk population, and the survival estimate will be biased upward.
Censored observations are shown on the survival curve as small vertical tick marks at the time of censoring. In the figure above, the tick marks are visible at various points along both curves; their presence confirms that the follow-up is not complete and reminds the reader that the later portions of the curve are based on fewer subjects.
Confidence Intervals for S(t)
The variance of the Kaplan–Meier estimator at time $t$ is given by Greenwood's formula (Greenwood, 1926):
$$ \widehat{\text{Var}}[\hat{S}(t)] = [\hat{S}(t)]^2 \sum_{i:\, t_i \leq t} \frac{d_i}{n_i(n_i - d_i)} $$A naive symmetric confidence interval $\hat{S}(t) \pm 1.96 \times \sqrt{\widehat{\text{Var}}[\hat{S}(t)]}$ can produce bounds outside $[0, 1]$ and performs poorly near 0 or 1. MedCalc uses the complementary log-log transformation, which maps $\hat{S}(t)$ to an unbounded scale, constructs the interval there, and back-transforms. The resulting 95% CI is guaranteed to lie within $[0, 1]$ and has better coverage properties at extreme survival probabilities (Kalbfleisch & Prentice, 2002).
Median and Mean Survival Time
The median survival time is the smallest time $t$ at which $\hat{S}(t) \leq 0.50$: the time by which half the subjects have experienced the event. It is read directly from the survival curve as the point where it crosses the horizontal line at $S = 0.50$ — shown as a dashed line in the figure. The 95% CI for the median is computed by the method of Brookmeyer & Crowley (1982), which inverts the confidence band for the survival curve rather than relying on the asymptotic normality of the median estimate. If the survival curve does not fall to 0.50 — which can happen when follow-up is short or the event rate is low — the median is undefined and should not be reported.
The mean survival time is estimated as the area under the Kaplan–Meier curve from time zero to the last observed time $t_\text{max}$:
$$ \hat{\mu} = \int_0^{t_{\max}} \hat{S}(t)\, dt $$This estimate is truncated at $t_\text{max}$ and therefore underestimates the true mean whenever the curve has not yet reached zero at the end of follow-up (Klein & Moeschberger, 2003). The restricted mean survival time (RMST) makes the truncation explicit by pre-specifying a time horizon $t^*$ and reporting the expected event-free time up to that point:
$$ \text{RMST}(t^*) = \int_0^{t^*} \hat{S}(t)\, dt $$The RMST is always estimable as long as follow-up extends to $t^*$, avoids the problem of an undefined median, and provides a clinically meaningful summary — the average number of event-free months (or years) up to a specified time horizon. It is particularly useful when survival curves cross, because the median and log-rank test can then be misleading (Royston & Parmar, 2013).
Comparing Survival Curves: The Log-Rank Test
When two or more groups are compared, the log-rank test (Mantel, 1966) tests the null hypothesis that the survival functions are identical across groups. At each event time $t_j$, the number of events expected in group 1 under the null hypothesis — equal event rates — is:
$$ e_{1j} = \frac{n_{1j}}{n_j} \cdot d_j $$where $n_{1j}$ is the number at risk in group 1 at $t_j$, $n_j$ is the total at risk, and $d_j$ is the total number of events at that time. Summing over all event times gives the total observed and expected events in group 1: $O_1 = \sum d_{1j}$ and $E_1 = \sum e_{1j}$. The log-rank statistic is:
$$ \chi^2 = \frac{(O_1 - E_1)^2}{V} $$where $V$ is a variance term derived from the hypergeometric distribution at each event time. For two groups this statistic follows a chi-squared distribution with 1 degree of freedom; for $k$ groups, with $k - 1$ degrees of freedom.
The log-rank test gives equal weight to every event time, which means it is most powerful when the hazard ratio between groups is approximately constant over time — the proportional-hazards assumption. When survival curves cross, early and late differences cancel each other out and the log-rank test has low power; in that situation the RMST difference is a more informative summary.
Hazard Ratio
The log-rank test answers whether survival differs between groups; the hazard ratio quantifies how much. It is estimated as the ratio of observed to expected events in each group:
$$ \widehat{HR} = \frac{O_1 / E_1}{O_2 / E_2} $$A hazard ratio of 0.60 means that at any point in time, subjects in group 1 experience the event at 60% of the rate of subjects in group 2 — a 40% reduction in the instantaneous event rate. The 95% confidence interval and associated $p$-value are calculated according to Altman et al. (2000).
Interpretation caution: The hazard ratio summarises the entire follow-up as a single ratio, implicitly assuming that the ratio is constant over time. When survival curves cross — indicating that one treatment is beneficial early but harmful late, or vice versa — the hazard ratio is an inappropriate summary. Inspect the curves before reporting a hazard ratio.
MedCalc's Kaplan–Meier survival analysis procedure produces the survival curve with pointwise 95% confidence intervals, the survival table with at-risk counts at user-specified time points, the median and mean survival time with confidence intervals, the restricted mean survival time, and — when two or more groups are defined — the log-rank test statistic and hazard ratio with confidence interval.
See the Cox proportional-hazards regression chapter for a multivariate survival model that adjusts for the simultaneous influence of several covariates.