Kaplan–Meier Survival Estimator, Explained
After reading this you can build a Kaplan–Meier survival curve by hand, read a life table with confidence intervals, and know when a median survival time is trustworthy and when it is not.
What the estimator does
You track a group of subjects over time and wait for a single event: a machine failure, a relapse, a customer cancellation. Some subjects reach the event during the study. Others do not. A patient may still be alive when the study ends, or a customer may still be active. For those subjects you know only that they survived at least a certain length of time. That partial information is called right censoring, and throwing it away wastes data and biases your estimate.
The Kaplan–Meier estimator, published by Edward Kaplan and Paul Meier in 1958, gives you the survival function S(t): the probability that a subject survives past time t. It uses every subject for as long as that subject is observed, then lets censored subjects quietly leave the risk set without pretending they had the event.
Here is the hook. Suppose 10 subjects start, one has the event at time 5, and one is censored at time 12. At time 20 the curve reflects both facts: the event pushed survival down, and the censored subject stopped contributing to the denominator after time 12 rather than being counted as a survivor or a death. That bookkeeping is the whole trick.
When to use it, and when not
Use Kaplan–Meier when your outcome is a time until a single, well-defined event and some observations are right censored. Typical cases: time to death, time to failure, time to churn, time to first purchase.
Do not use it in these situations:
- No censoring at all. If every subject has the event and you know every time exactly, the survival curve is just
1minus the empirical cumulative distribution. A percentile calculator gives you the same quantiles more directly. - Competing events you care about separately. If a subject can leave through several distinct exits (death from cause A versus cause B), treating one as censoring overstates survival. You need a competing-risks method.
- Left or interval censoring. The product-limit formula assumes you know each event time exactly and each censored subject's minimum survival. If you only know an event fell inside a window, this is the wrong tool.
- Comparing groups formally. The estimator draws curves; it does not test whether two curves differ. That needs a log-rank test.
The formula and the intuition
Sort the distinct event times t_1 \lt t_2 \lt \dots \lt t_k. At each event time t_i let n_i be the number of subjects still at risk (alive and uncensored just before t_i) and let d_i be the number of events at t_i. The estimator is a running product:
Each factor 1 - d_i/n_i is the conditional probability of surviving through time t_i given survival up to that point. Multiply those conditional survivals and you get the unconditional survival to time t. Between event times the curve is flat, so it is a step function that only drops when someone actually has the event.
Censored subjects never appear in any d_i. They only shrink n_i at later times because they are no longer at risk. That is why a censored observation slows the curve's decline: fewer subjects remain, so each later event carries slightly more weight, but the censoring itself does not force a step down.
For the confidence interval, Greenwood's formula estimates the variance of \hat{S}(t):
The interval is \hat{S}(t) \pm z \sqrt{\widehat{\text{Var}}}, with z = 1.96 for 95% confidence, then clipped to [0, 1] because a probability cannot leave that range. The sum grows as more events accumulate and as the risk set shrinks, so intervals widen in the tail of the curve where few subjects remain.
A worked example with the demo data
Ten subjects, seven events, three censored
Load the demo data: times 5, 8, 12, 16, 23, 27, 30, 33, 43, 45 with event flags 1, 1, 0, 1, 1, 0, 1, 1, 0, 1. A 1 means the event happened; a 0 means the subject was censored at that time. The times are already sorted, which makes the table easy to follow.
- Start with n = 10 at risk and \hat{S} = 1.
- Time 5, event: 1 - 1/10 = 0.9, so \hat{S} = 0.9.
- Time 8, event, now 9 at risk: 1 - 1/9 = 0.8889, so \hat{S} = 0.9 \times 0.8889 = 0.8.
- Time 12, censored, 8 at risk: no step. The curve stays at
0.8, but one subject leaves the risk set. - Time 16, event, 7 at risk: 1 - 1/7 = 0.8571, so \hat{S} = 0.8 \times 0.8571 = 0.6857.
- Time 23, event, 6 at risk: 1 - 1/6 = 0.8333, so \hat{S} = 0.5714.
- Time 27, censored, 5 at risk: no step, curve stays at
0.5714. - Time 30, event, 4 at risk: 1 - 1/4 = 0.75, so \hat{S} = 0.4286.
- Time 33, event, 3 at risk: 1 - 1/3 = 0.6667, so \hat{S} = 0.2857.
- Time 43, censored, 2 at risk: no step, curve stays at
0.2857. - Time 45, event, 1 at risk: 1 - 1/1 = 0, so \hat{S} = 0.
| Time | At risk n | Events d | Factor 1 − d/n | S(t) |
|---|---|---|---|---|
| 5 | 10 | 1 | 0.9000 | 0.9000 |
| 8 | 9 | 1 | 0.8889 | 0.8000 |
| 16 | 7 | 1 | 0.8571 | 0.6857 |
| 23 | 6 | 1 | 0.8333 | 0.5714 |
| 30 | 4 | 1 | 0.7500 | 0.4286 |
| 33 | 3 | 1 | 0.6667 | 0.2857 |
| 45 | 1 | 1 | 0.0000 | 0.0000 |
The median survival is the first time \hat{S}(t) drops to 0.5 or below. Here the curve is 0.5714 at time 23 and falls to 0.4286 at time 30, so the estimated median survival is 30.
Reading the results
Three outputs deserve attention.
- The step curve
- Height at any time is the estimated probability of surviving past that time. Long flat stretches mean no events happened, not that nothing is going on: censored subjects can be leaving during a flat stretch.
- The confidence band
- Greenwood intervals are narrow early, when the full sample is at risk, and wide late, when few subjects remain. In the demo, the interval at time 5 is tight around
0.9, but by time 33 with only three at risk it is very wide. Treat the far right of any Kaplan–Meier curve with suspicion. - The median survival
- A single summary number, robust to the shape of the tail. If the curve never reaches
0.5, the median is undefined and the tool reports it as not reached.
Report the number at risk under the time axis, at least at a few grid points. A survival estimate of 0.29 with 30 subjects still at risk is solid; the same 0.29 with one subject at risk, as at time 45 in the demo, is almost noise.
Explore how censoring reshapes the curve
Censoring is the concept that a static picture hides. Move one subject from event to censored and watch the median shift.
Common mistakes
The single most damaging error is coding the event flag backwards. If 1 means censored and 0 means event, every step lands in the wrong place and the curve is meaningless. Confirm that 1 marks the event before you trust anything.
Other pitfalls to watch:
- Reading the tail as fact. When only a few subjects remain, one event moves the curve a lot. The demo drops from
0.2857straight to0at time 45 because a single subject was left. That zero is an artifact of the last observation, not evidence that survival is truly zero. - Comparing curves by eye. Two curves that cross or nearly touch can still differ, or not differ, in ways your eye cannot judge. Use a formal test.
- Informative censoring. The method assumes censored subjects have the same future risk as those still under study. If subjects drop out because they are about to have the event, the estimate is optimistic. No formula fixes this; only a better study design does.
- Treating ties carelessly. When several subjects share a time, an event and a censoring at the same time are handled by counting events first, then removing the censored subject from the next risk set. Mixing that order shifts the curve.
Related tools
Kaplan–Meier describes time-to-event data, but the times themselves are ordinary numbers you may want to profile first. Run them through the descriptive statistics calculator for mean, quartiles and spread, and check for suspicious values with the outlier detector before you decide a very long survival time is real rather than a data-entry error. If you want the raw quantiles of the observed times ignoring censoring, the percentile calculator gives them directly.
Frequently asked questions
Why does my survival curve never reach zero?
Because the last observation was censored, not an event. The product-limit formula only steps down at events, so if the largest time is censored the curve stays flat above zero at the right edge. In that case the mean survival is not estimable and you should quote the median or a fixed-time survival like \hat{S}(30) instead.
What does "median not reached" mean?
It means the curve never dropped to 0.5 during the observation window, usually because more than half the subjects were still event-free at the end. You cannot report a median; report survival at a specific time instead, for example "62% survival at 24 months".
How many subjects do I need?
There is no hard minimum, but the confidence intervals tell the story. With 10 subjects the demo band is already wide past time 30. Precision depends on the number of events, not the number of subjects, so a large sample with few events is still imprecise.
Can I use Kaplan–Meier for churn or machine failure?
Yes. Any time-to-single-event outcome with right censoring fits. For churn, the event is cancellation and active customers at the analysis date are censored. For hardware, the event is failure and units still running are censored.
Does the confidence level change the curve?
No. The estimated survival \hat{S}(t) is fixed by the data. The confidence level only changes the width of the band around it, through the multiplier z (1.96 at 95%, 1.645 at 90%, 2.576 at 99%).