AdvancedIndependently reviewed, not yet spot-checked by a human

Kaplan-Meier curves and the log-rank test

Why survival data cannot be summarised by an average survival time, what each step of a KM curve is computing, which questions the log-rank test answers and which it cannot, and how to read the median line.

What problem this method solves

You follow a group of patients and want to know how long it takes for some event to happen. The difficulty is that when the study ends, some people still have not had the event — they may still be alive, may have moved away, may have withdrawn. Their data are not worthless: a patient followed for 400 days without an event tells you plainly that they made it past 400 days.

An observation where only the lower bound is known is called censoring — more precisely, right-censoring. The whole survival analysis toolkit answers one question: how do you estimate the distribution of event times without throwing censored observations away?

Two common ways of handling them are both systematically biased:

  • Counting censored patients as event-free and computing a plain proportion → underestimates risk (the event may have happened after you stopped looking)
  • Deleting censored patients altogether → usually overestimates risk (everyone left is someone who had the event)

What the KM estimator computes

The Kaplan-Meier estimator cuts time at every point where an event occurs and asks one small question at each of them: of the people still being followed at this instant, what fraction got past it?

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

Here did_i is the number of events at time tit_i and nin_i is the number still in the risk set at that time. The whole curve is these conditional survival probabilities multiplied together.

That explains the two things you notice about the curve’s appearance:

  • It is a step function, dropping only when an event occurs. Censoring never makes the curve fall.
  • It becomes less reliable towards the right, because nin_i keeps shrinking and each step is decided by fewer and fewer people. A dramatic drop at the tail is often three or five patients.

Run it yourself

library(survival)
data(cancer, package = "survival")   # lung ships inside the cancer help page

lung$sex_f <- factor(lung$sex, levels = c(1, 2),
                     labels = c("Male", "Female"))

# status: 1 = censored, 2 = dead
fit <- survfit(Surv(time, status) ~ sex_f, data = lung)

summary(fit)$table          # n, events, median survival and its CI per group
survdiff(Surv(time, status) ~ sex_f, data = lung)   # log-rank

plot(fit, col = c("#4d6a8c", "#c44d4d"), lwd = 2,
     conf.int = TRUE, mark.time = TRUE,
     xlab = "Days since enrolment", ylab = "Survival probability")

Verified with R 4.6.0 and survival 3.8.6

Kaplan-Meier survival curves for the NCCTG lung cancer trial split by sex, with 95% confidence bands and censoring marks. Apart from the first few days, the curve for women sits above the curve for men for almost all of follow-up. A numbers-at-risk table below the plot shows one row per sex, both falling over time and reaching very small counts at the right-hand end.
KM curves for survival::lung by sex. The dashed lines in each colour are that group's 95% confidence interval, and the + marks on the curves are censored observations. The horizontal dotted line marks 0.5, where median survival is read off. The numbers-at-risk table below gives the size of each risk set over time; the further right you go, the fewer patients remain and the less stable the curve becomes.Plotting script figures/scripts/B3-02-kaplan-meier.R

The data come from the NCCTG advanced lung cancer trial: 228 patients, of whom 165 had an event and 63 were censored.

GroupnEventsMedian survival (days)95% CI
Male138112270212–310
Female9053426348–550

How to read median survival

Median survival is the time at which the curve first drops to 0.5 — not the mean of everyone’s survival times, and not a median computed by forcing censored patients into the calculation. It is the horizontal dashed line in the figure above.

Two frequent misreadings:

  • “Median survival 270 days” does not mean these patients live about 270 days. The distribution is usually strongly right-skewed, so the mean sits well above the median.
  • When the curve never reaches 0.5, median survival is “not reached” (NR), which does not mean infinite. This is common with short follow-up or a good-prognosis population. NR only licenses the statement “longer than the follow-up period”.

What the log-rank test does and does not answer

The log-rank test compares two curves over their whole length; the null hypothesis is that the two survival functions are identical. Here the result is χ2\chi^2 = 10.33 (df = 1), p = 0.0013.

What it cannot answer is worth remembering better than what it can:

QuestionWhat log-rank cannot give you
By how much?It returns a p-value and no effect size. For an effect size use the HR from a Cox model, or compare survival at a specified time point
Which group is better?The test carries no direction; direction has to be read off the curves
When does the difference appear?It collapses the entire follow-up into a single statistic

There is a more fundamental limitation too: the log-rank test has poor power when the curves cross. It is designed to be most sensitive when the hazard ratio is constant across follow-up. If one group does worse early and then overtakes — the shape immunotherapy trials keep producing — the early and late differences cancel each other out, and the p-value can be wildly large even though the two curves are obviously different.

Common misuses

MisuseWhy it is wrong
Using 1 − KM as cumulative incidence when the event has competing risksCompeting events make 1 − KM overestimate cumulative incidence; use the cumulative incidence function (CIF)
A KM figure with no numbers-at-risk tableThe reader cannot tell how many patients the tail rests on
Treating the log-rank p-value as evidence of effect sizeIt contains no effect size; the size of a p-value and the size of a difference are different things
Reporting a single HR when the curves crossProportional hazards has already failed, so that HR has no clear interpretation
Describing median survival as “how long people live on average”Survival times are right-skewed, and the two can be far apart
Splitting KM curves by a variable only knowable after baselineGrouping by “responded to treatment”, for instance, manufactures immortal time bias
Reading p > 0.05 as “the two groups do not differ in survival”It only means this study did not detect a difference — and log-rank power is low to begin with when curves cross

Reproducing every number on this page

/opt/homebrew/bin/Rscript figures/scripts/B3-02-kaplan-meier.R

Read the figure

The answer comes from the same statistical output that produced this page's figures, not from a number typed in beside them.

The number-at-risk row under a KM plot shows a number for the female arm at day 400. Which statement is right?

Show the answer and why

Correct answer: That cell reads 26, counting the women who have neither had the event nor been censored yet

Number at risk counts people who have neither had the event nor been censored - the next stretch of curve rests on those 26. 53 is the female arm's event count across all of follow-up, which is what has accumulated rather than who is left; 31 is the male arm's number at risk at that same day, not a combined total. When the right-hand tail looks reassuringly flat, read this row first: where two or three people remain, one event drops the curve a long way, and that drop is not evidence that the risk rose.

Someone counts the downward steps on a KM curve to recover how many events were observed. What is wrong with that?

Show the answer and why

Correct answer: It undercounts, because events sharing a time collapse into one step; there were 165 events

The curve steps down only when an event occurs, and two events on the same day draw a single step - so counting steps gives the number of distinct event times, not the number of events, and the two agree only when no times are tied. 228 is the enrolment total, and reading it as the event count reads "how many were recruited" as "how many things were observed"; the 63 censored patients appear as tick marks rather than steps, so they are not overcounted.

Output prints the male arm's median survival, its lower confidence bound, and the female arm's median side by side. Which is the male median, and why?

Show the answer and why

Correct answer: 270 days - the time at which the curve first drops below a survival probability of one half

Median survival is defined as the first time the curve falls below one half, which is 270 days for men. 212 is the lower bound of that median's 95% confidence interval: it describes how uncertain the estimate is, so using it as the point estimate is not "conservative" but a different quantity altogether; 426 is the female arm's median, read off the wrong row. Output prints all three side by side, so the wrong column and the wrong row both yield an answer that looks entirely plausible.

Watch next

Kaplan-Meier-Curve [Simply Explained]
ENnumiqo· 10 minTen minutes drawing the KM calculation out step by step. The formula below reads much more easily afterwards.
醫學統計 EP16 存活分析:解讀階梯狀 KM 曲線與風險比率
繁中EDMAN MURMURS· 11 minIn Mandarin, aimed at clinicians. It is about what to read off the figure rather than how to compute it.
如何看懂 K-M 存活曲線:以 FLAURA 研究為例
繁中腫瘤科吳教恩醫師· 9 minWalks through a real oncology trial end to end. Best watched after you have finished this page.
Censoring and Truncation [Survival Analysis 2/8]
ENzedstatistics· 14 minCensoring is the foundation of everything in survival analysis, and this one draws a clean line between it and truncation.

Sources and licences

This page is original writing

Report a content problem

The statistics on this site are written by AI and reviewed by AI; a human only spot-checks. What you can see may be what we cannot.

The more specific, the more fixable — e.g. which sentence disagrees with which textbook or paper.

Needed only if you want a reply; reports without it are still read.

Sent along with your report

These are attached automatically. You can drop any of them.