Two step-shaped Kaplan–Meier survival curves by treatment group, plotted from the aml dataset in the R survival package.

Two Kaplan–Meier survival curves grouped by treatment; the data are the acute myeloid leukemia (aml) dataset bundled with the R survival package. Figure: Michaelg2015; source: Wikimedia Commons; license: CC BY-SA 4.0.

The Kaplan–Meier curve (product-limit estimate) answers the question: when follow-up has not ended for some subjects and their outcomes are unknown, what proportion survives beyond a given time point? Proposed by Kaplan and Meier in 1958, it makes no assumption about the shape of the survival-time distribution. This entry uses a public dataset to demonstrate, step by step, the calculation, censoring marks, and the log-rank test, and explains common misuses such as ignoring competing risks, confusion over proportional hazards, and over-interpretation of the curve's tail.

The Estimand and the Product-Limit Formula

In survival analysis, "survival" broadly means that the event of interest has not yet occurred; the event may be death or relapse, or it may be equipment failure or conception. The quantity to be estimated is the survival function S(t) = P(T > t), the proportion of the population whose event time T exceeds t. The difficulty is censoring: some people have still not experienced the event when the study ends, others are lost to follow-up partway through, and all we know is that their event time is later than the last observation. In their 1958 paper, Kaplan and Meier referred to the event of interest generically as "death" and to events that prevent observation as "loss", noting that a loss may be accidental or may result from the investigator deliberately ending observation; they generally assumed that the lifetime and the potential loss time are independent of each other, while cautioning that this assumption needs careful scrutiny in practice.

Computing a proportion directly goes wrong: excluding censored subjects throws away the information that "they survived at least until a certain time," so survival is underestimated; treating censored subjects as having survived throughout leads to overestimation. The product-limit estimate cuts the time axis at each event time, estimates the conditional probability of "surviving this segment" for each segment using only those still under observation at that time, and then multiplies the segment probabilities together. Censored subjects remain in the denominator until they are censored and drop out afterward. The original paper proves that, when no distributional form is imposed, this estimate is the distribution that maximizes the sample likelihood; if there is no censoring before time t, it reduces to the ordinary proportion surviving.

S^(t)=∏tj≤t(1−djnj),Var⁡^[S^(t)]=S^(t)2∑tj≤tdjnj (nj−dj)\hat S(t)=\prod_{t_j\le t}\left(1-\frac{d_j}{n_j}\right),\qquad \widehat{\operatorname{Var}}\big[\hat S(t)\big]=\hat S(t)^2\sum_{t_j\le t}\frac{d_j}{n_j\,(n_j-d_j)}

Here tjt_j are the distinct event times, njn_j is the number of people still at risk just before tjt_j (including those who have the event or are censored exactly at tjt_j), and djd_j is the number of events at tjt_j. The right-hand expression is Greenwood's formula; Kaplan and Meier used this name in Section 6 of their original paper.

Data are usually recorded in two columns: time, and status (1 for an event, 0 for censoring). When an event and a censoring are recorded at the same time, by convention the event is taken to come first and the censoring afterward, so the censored subject is still counted in the risk set at that time; both Kaplan and Meier's original paper and Collett's textbook adopt this convention. When plotted, the curve is a step function that drops only at event times; it does not drop at censoring times, which are marked only by a short vertical tick or a "+" on the curve. If the last observation is censored, the curve is undefined beyond that time and cannot be extrapolated; if the last observation is an event, the curve drops to 0.

A Step-by-Step Example with Glioma Data

The example below uses a dataset published by Bland and Altman in their statistics notes in the British Medical Journal (BMJ): the number of weeks from entry to death or censoring for 51 adult patients with recurrent malignant glioma; the original study was a phase II trial by Rostomily et al. in 1994. By tumor type, the patients were divided into anaplastic astrocytoma (group A, 20 patients, 14 deaths, 6 censored) and glioblastoma (group G, 31 patients, 28 deaths, 3 censored). The observation times in group A were 6, 13, 21, 30, 31+, 37, 38, 47+, 49, 50, 63, 79, 80+, 82+, 82+, 86, 98, 149+, 202, 219 weeks ("+" denotes censoring). The table below computes the product-limit estimate for group A row by row; the values were calculated by hand, step by step, from the formula and are given to three decimal places.

Week At risk n Deaths d Censored Conditional survival (n−d)/n Ŝ(t)
6 20 1 0 19/20 0.950
13 19 1 0 18/19 0.900
21 18 1 0 17/18 0.850
30 17 1 0 16/17 0.800
31 16 0 1 — 0.800
37 15 1 0 14/15 0.747
38 14 1 0 13/14 0.693
47 13 0 1 — 0.693
49 12 1 0 11/12 0.636
50 11 1 0 10/11 0.578
63 10 1 0 9/10 0.520
79 9 1 0 8/9 0.462
80 8 0 1 — 0.462
82 7 0 2 — 0.462
86 5 1 0 4/5 0.370
98 4 1 0 3/4 0.277
149 3 0 1 — 0.277
202 2 1 0 1/2 0.139
219 1 1 0 0/1 0

A few details are worth checking. At week 31, 1 person is censored and the curve does not drop, but the denominator at week 37 changes from 16 to 15, so the conditional survival is 14/15 rather than 15/16. At week 63, Ŝ(63) = 0.520, and Greenwood's formula gives a standard error of about 0.117; with a sample of 20, the estimate is quite rough. For comparison: if the two censored subjects at weeks 31 and 47 are excluded, the proportion surviving past week 63 is 9/18 = 0.50; if they are treated as having survived throughout, it is 11/20 = 0.55; the product-limit estimate falls between the two. The median survival time is taken as the time at which Ŝ(t) first falls to 0.5 or below; for group A it is 79 weeks. For group G, the estimate is 0.516 at week 30 and falls to 0.484 at week 33, so the median survival time is 33 weeks.

The Python code below depends only on NumPy, SciPy, and Matplotlib. It implements the product-limit estimate, Greenwood standard errors, and the log-rank test according to the formulas in the previous section, and plots the two groups' curves with censoring ticks. The figures in the text were checked by hand using the same formulas, and the code can be run to verify them one by one.

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import chi2

# Bland & Altman, BMJ 2004: weeks to death (event=1) or censoring (event=0)
astro_time = np.array([6, 13, 21, 30, 31, 37, 38, 47, 49, 50, 63, 79, 80, 82, 82,
                       86, 98, 149, 202, 219])
astro_event = np.array([1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0,
                        1, 1, 0, 1, 1])
glio_time = np.array([10, 10, 12, 13, 14, 15, 16, 17, 18, 20, 24, 24, 25, 28, 30, 33,
                      34, 35, 37, 40, 40, 40, 46, 48, 70, 76, 81, 82, 91, 112, 181])
glio_event = np.array([1] * 16 + [0] + [1] * 4 + [0] + [1, 1, 0] + [1] * 6)


def kaplan_meier(time, event):
    """Product-limit estimate with Greenwood standard errors."""
    s, gw, rows = 1.0, 0.0, []
    for t in np.unique(time[event == 1]):
        n = np.sum(time >= t)  # subjects censored at t stay in the risk set
        d = np.sum((time == t) & (event == 1))
        s *= 1 - d / n
        gw = gw + d / (n * (n - d)) if n > d else np.nan
        rows.append((t, n, d, s, s * np.sqrt(gw)))
    return rows


def logrank(t1, e1, t2, e2):
    times = np.unique(np.concatenate([t1[e1 == 1], t2[e2 == 1]]))
    observed = expected = variance = 0.0
    for t in times:
        n1, n2 = np.sum(t1 >= t), np.sum(t2 >= t)
        d1 = np.sum((t1 == t) & (e1 == 1))
        d = d1 + np.sum((t2 == t) & (e2 == 1))
        n = n1 + n2
        observed += d1
        expected += n1 * d / n
        if n > 1:
            variance += n1 * n2 * d * (n - d) / (n ** 2 * (n - 1))
    stat = (observed - expected) ** 2 / variance
    return observed, expected, variance, stat, chi2.sf(stat, df=1)


def plot_km(ax, time, event, label):
    rows = kaplan_meier(time, event)
    t = np.r_[0, [r[0] for r in rows], time.max()]
    s = np.r_[1.0, [r[3] for r in rows], rows[-1][3]]
    line, = ax.step(t, s, where="post", label=label)
    cens = time[event == 0]
    idx = np.searchsorted(t, cens, side="right") - 1
    ax.plot(cens, s[idx], "|", markersize=10, markeredgewidth=1.5,
            color=line.get_color())


for name, t, e in [("A", astro_time, astro_event), ("G", glio_time, glio_event)]:
    print(f"Group {name}")
    for tj, n, d, s, se in kaplan_meier(t, e):
        print(f"  week {tj:>3}  n={n:>2}  d={d}  S={s:.3f}  SE={se:.3f}")

obs, exp_, var, stat, p = logrank(astro_time, astro_event, glio_time, glio_event)
print(f"Log-rank: O_A={obs:.0f}  E_A={exp_:.2f}  V={var:.2f}  chi2={stat:.2f}  p={p:.4f}")

fig, ax = plt.subplots(figsize=(7, 4.5))
plot_km(ax, astro_time, astro_event, "Anaplastic astrocytoma (n=20)")
plot_km(ax, glio_time, glio_event, "Glioblastoma (n=31)")
ax.set(xlabel="Weeks since entry", ylabel="Estimated survival S(t)", ylim=(0, 1.05))
ax.legend(title="| marks censored times")
fig.tight_layout()
fig.savefig("km_glioma.png", dpi=200)

R users can perform the same calculations with the survival package:

library(survival)

d <- data.frame(
  group  = rep(c("A", "G"), c(20, 31)),
  time   = c(6, 13, 21, 30, 31, 37, 38, 47, 49, 50, 63, 79, 80, 82, 82, 86, 98, 149, 202, 219,
             10, 10, 12, 13, 14, 15, 16, 17, 18, 20, 24, 24, 25, 28, 30, 33, 34, 35, 37,
             40, 40, 40, 46, 48, 70, 76, 81, 82, 91, 112, 181),
  status = c(1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1,
             rep(1, 16), 0, rep(1, 4), 0, 1, 1, 0, rep(1, 6))
)
fit <- survfit(Surv(time, status) ~ group, data = d)
summary(fit)                                     # n.risk, n.event, survival, std.err
survdiff(Surv(time, status) ~ group, data = d)   # log-rank test
plot(fit, mark.time = TRUE, lty = 1:2, xlab = "Weeks", ylab = "Estimated survival")

AI illustration of step-shaped survival curves for two groups of glioma patients, one falling noticeably faster, with short vertical ticks of the same color marking censoring times.

Illustration of step-shaped Kaplan–Meier survival curves for two groups of glioma patients: one curve falls noticeably faster, and short vertical ticks of the same color on the curves indicate censoring. The shapes of the curves and the positions of the steps are for illustration only and do not correspond to the actual values in this example; running the code above with the data published by Bland and Altman (BMJ 2004) plots the real curves for group A (anaplastic astrocytoma, n=20) and group G (glioblastoma, n=31). AI-generated illustration.

The Log-Rank Test and Between-Group Comparison

When comparing two groups' curves, picking a single time point (for example, 1-year survival) yields conclusions that change depending on the time point chosen. In 1966, Mantel proposed a chi-square procedure for comparing two life tables "as a whole," noting that when the intervals are made arbitrarily short it is essentially a rank test that can handle individual right censoring and ties; this is what is now commonly called the log-rank test. The procedure is to construct a 2×2 table at each event time t_j: if the two groups have the same risk, the expected number of events in group A is E_j = n_Aj × d_j / n_j. The observed counts O and expected counts E are summed separately across time points and then standardized by the hypergeometric variance V.

χ2=(OA−EA)2V,V=∑jnAj nGj dj (nj−dj)nj2 (nj−1)\chi^2=\frac{(O_A-E_A)^2}{V},\qquad V=\sum_j\frac{n_{Aj}\,n_{Gj}\,d_j\,(n_j-d_j)}{n_j^2\,(n_j-1)}

Under the null hypothesis, this statistic approximately follows a chi-square distribution with 1 degree of freedom (k − 1 degrees of freedom when comparing k groups). In the BMJ, Bland and Altman use the simpler approximation ∑(O−E)2/E\sum (O-E)^2/E, which extends easily to multiple groups.

Take the glioma data as an example. At the first death, in week 6, 51 people are at risk, 20 of them in group A, so the expected number of deaths in group A is 20 × 1/51 ≈ 0.39; at week 10, 2 people in group G die, when group A has 19 people and the total is 50, so the expected number of deaths in group A is 19 × 2/50 = 0.76. Summing over all event times, hand calculation gives about 22.50 expected deaths in group A and about 19.50 in group G; the BMJ paper reports 22.48 and 19.52, a difference of 0.02. The expected values given step by step in the original paper are rounded to two decimal places, so the discrepancy may come from rounding. Group A had 14 observed deaths, clearly fewer than expected; group G had 28 observed deaths, more than expected. The simplified BMJ formula gives χ² ≈ 6.92 (6.88 in the original); using the hypergeometric variance V ≈ 9.59 gives χ² ≈ 7.53, with 1 degree of freedom, P ≈ 0.006. Both methods give P < 0.01: the difference in survival experience between the two groups is statistically significant, in the direction of more deaths than expected in the glioblastoma group.

The log-rank test answers only "whether the two groups' survival experiences differ"; it does not tell how large the difference is and provides no confidence interval. To estimate the effect size, a Cox proportional hazards model is commonly used to give a hazard ratio. Because the test sums O − E with equal weight across event times, it is most likely to detect a difference when one group's risk is consistently higher than the other's; if the curves cross (for example, a surgery group with higher early risk but later benefit), early and late differences in opposite directions cancel each other out, and the test may not be significant. Bland and Altman therefore recommend always plotting the curves first when analyzing survival data.

Assumptions, Common Misuses, and the Life-Table Method

The Kaplan–Meier estimate and the log-rank test share several assumptions: censoring is unrelated to prognosis, meaning that at any moment those censored have the same survival prospects as those who remain under follow-up; people enrolled early and late have the same survival probabilities; and events occur at the recorded times. The first assumption is hard to test with data. Bland and Altman give the example of a conception study: if some people drop out of follow-up because they have not conceived after a long time, censoring is related to the outcome, and the estimated probability of "not conceiving" will be biased downward. If the groups violate the assumptions to different degrees—for example, if one group has markedly more loss to follow-up—the between-group comparison is affected most. In addition, every subject needs a clearly defined time origin; Kaplan and Meier's original paper lists "observation of the initial event that marks the beginning of the lifetime" as an assumption.

The first kind of misuse is ignoring competing risks. If the outcome of interest is cardiovascular death and patients may die of other causes first, the latter is not a case of "the outcome has not been seen yet"; rather, it makes the event of interest impossible from then on. When competing events are treated as censoring, 1 − KM estimates the cumulative incidence in a hypothetical population in which "competing events do not exist," which is usually higher than in the real population. In a tutorial published in Circulation in 2016, Austin, Lee, and Fine reported that the 5-year incidence of cardiovascular death among patients hospitalized for heart failure was 43.0% when calculated with 1 − KM and 36.8% when calculated with the cumulative incidence function (CIF). When competing risks are present, the cumulative incidence function should be reported; for regression, either a cause-specific hazards model or the Fine–Gray model can be chosen depending on the research question (Putter et al. 2007; Austin et al. 2016).

The second kind of misuse is conflating the proportional hazards assumption with KM. The KM curve is a nonparametric estimate and does not require the proportional hazards assumption; the log-rank test likewise does not require prior knowledge of the shape of the curves or of the survival-time distribution. Proportional hazards is an assumption of the Cox model and of the practice of "summarizing the entire follow-up with a single hazard ratio." Two confusions are common. The first is declaring that "KM is not applicable" upon seeing crossing curves, when in fact crossing curves are still a valid description; it is just that a single hazard ratio and the log-rank test are no longer suitable for summarizing the difference. The second is using the log-rank P value to imply that a constant hazard ratio exists. When the curves cross or the gap between them changes markedly over time, one can report survival rates with confidence intervals at several prespecified time points, or choose a model after checking the proportional hazards assumption.

The third kind of misuse is over-interpreting small samples and the step shape of the curve's tail. A single event makes the curve drop by Ŝ(t)/n; the smaller the risk set n, the larger the step. In this example, group A has only 2 people left by week 202, and 1 death drops the estimate from 0.277 to 0.139; conversely, a long plateau in the tail often just means that the few people still under follow-up have not yet had an event, and does not represent "cure" or zero risk. Pocock, Clayton, and Altman (2002) recommend showing the extent of follow-up in the figure (such as the number at risk at each time point), giving standard errors or confidence intervals, truncating the curve when too few people remain under follow-up, and interpreting the curve shape and late differences with caution. The truncation approach proposed by Gebski et al. (2018) is for the investigators to prespecify the maximum acceptable drop that "1 more event" would cause; once this would be exceeded, the curve is not extended any further.

Finally, there is the distinction from the life-table method. The life-table method is also called the actuarial method, and Kaplan and Meier's original paper calls it the actuarial estimate: it likewise multiplies conditional survival probabilities together, but the intervals are usually grouped, so the result depends to some extent on the choice of intervals. Collett's textbook calls the assumption that "censoring occurs uniformly within an interval, with the number at risk taken as n − c/2" the actuarial assumption, and points out that KM is precisely the limit of the life-table estimate as the number of intervals tends to infinity and the interval width tends to zero, which is why it is also called the product-limit estimate. When each person's exact time is known, grouping loses information, and KM should be preferred; when only the numbers of events and censorings in each interval are available, the life-table method is more appropriate.

Kaplan–Meier (product-limit method) Life-table method (actuarial method)
Time partitioning Split at each distinct event time Intervals defined in advance, commonly 5–15
Handling of censoring Censored subjects remain in the risk set until the time of censoring Censoring assumed to occur uniformly within the interval; number at risk taken as n − c/2
Dependence on grouping None Varies with the choice of intervals, similar to a histogram
Suitable data Exact time known for each person Only the numbers of events and censorings in each interval

References

  1. Kaplan EL, Meier P. Nonparametric estimation from incomplete observations. Journal of the American Statistical Association, 1958, 53(282): 457–481. doi:10.1080/01621459.1958.10501452

  2. Mantel N. Evaluation of survival data and two new rank order statistics arising in its consideration. Cancer Chemotherapy Reports, 1966, 50(3): 163–170. PubMed 5910392

  3. Bland JM, Altman DG. Survival probabilities (the Kaplan-Meier method). BMJ, 1998, 317: 1572. doi:10.1136/bmj.317.7172.1572

  4. Bland JM, Altman DG. The logrank test. BMJ, 2004, 328: 1073. doi:10.1136/bmj.328.7447.1073

  5. Pocock SJ, Clayton TC, Altman DG. Survival plots of time-to-event outcomes in clinical trials: good practice and pitfalls. The Lancet, 2002, 359(9318): 1686–1689. doi:10.1016/S0140-6736(02)08594-X

  6. Gebski V, Garès V, Gibbs E, Byth K. Data maturity and follow-up in time-to-event analyses. International Journal of Epidemiology, 2018, 47(3): 850–859. doi:10.1093/ije/dyy013

  7. Putter H, Fiocco M, Geskus RB. Tutorial in biostatistics: competing risks and multi-state models. Statistics in Medicine, 2007, 26(11): 2389–2430. doi:10.1002/sim.2712

  8. Austin PC, Lee DS, Fine JP. Introduction to the analysis of survival data in the presence of competing risks. Circulation, 2016, 133: 601–609. doi:10.1161/CIRCULATIONAHA.115.017719

  9. Collett D. Modelling Survival Data in Medical Research. 4th ed. Boca Raton: CRC Press, 2023. doi:10.1201/9781003282525

  10. Research Methods · Rituals can be imitated; understanding cannot be faked

  11. This information was compiled and published by Scholay One-Stop Academic Platform; in case of any infringement, please let us know and it will be taken down.

  12. This information is also published on EnterScholar, a community for scholars in the age of intelligence