# Kaplan–Meier estimator

Short description: Non-parametric statistic used to estimate the survival function
An example of a Kaplan–Meier plot for two conditions associated with patient survival.

The Kaplan–Meier estimator,[1][2] also known as the product limit estimator, is a non-parametric statistic used to estimate the survival function from lifetime data. In medical research, it is often used to measure the fraction of patients living for a certain amount of time after treatment. In other fields, Kaplan–Meier estimators may be used to measure the length of time people remain unemployed after a job loss,[3] the time-to-failure of machine parts, or how long fleshy fruits remain on plants before they are removed by frugivores. The estimator is named after Edward L. Kaplan and Paul Meier, who each submitted similar manuscripts to the Journal of the American Statistical Association.[4] The journal editor, John Tukey, convinced them to combine their work into one paper, which has been cited almost 61,000 times since its publication in 1958.[5][6]

The estimator of the survival function $\displaystyle{ S(t) }$ (the probability that life is longer than $\displaystyle{ t }$) is given by:

$\displaystyle{ \widehat S(t) = \prod\limits_{i:\ t_i\le t} \left(1 - \frac{d_i}{n_i}\right), }$

with $\displaystyle{ t_i }$ a time when at least one event happened, di the number of events (e.g., deaths) that happened at time $\displaystyle{ t_i }$, and $\displaystyle{ n_i }$ the individuals known to have survived (have not yet had an event or been censored) up to time $\displaystyle{ t_i }$.

## Basic concepts

A plot of the Kaplan–Meier estimator is a series of declining horizontal steps which, with a large enough sample size, approaches the true survival function for that population. The value of the survival function between successive distinct sampled observations ("clicks") is assumed to be constant.

An important advantage of the Kaplan–Meier curve is that the method can take into account some types of censored data, particularly right-censoring, which occurs if a patient withdraws from a study, is lost to follow-up, or is alive without event occurrence at last follow-up. On the plot, small vertical tick-marks state individual patients whose survival times have been right-censored. When no truncation or censoring occurs, the Kaplan–Meier curve is the complement of the empirical distribution function.

In medical statistics, a typical application might involve grouping patients into categories, for instance, those with Gene A profile and those with Gene B profile. In the graph, patients with Gene B die much quicker than those with Gene A. After two years, about 80% of the Gene A patients survive, but less than half of patients with Gene B.

To generate a Kaplan–Meier estimator, at least two pieces of data are required for each patient (or each subject): the status at last observation (event occurrence or right-censored), and the time to event (or time to censoring). If the survival functions between two or more groups are to be compared, then a third piece of data is required: the group assignment of each subject.[7]

## Problem definition

Let $\displaystyle{ \tau\ge 0 }$ be a random variable, which we think of as the time until an event of interest takes place. As indicated above, the goal is to estimate the survival function $\displaystyle{ S }$ underlying $\displaystyle{ \tau }$. Recall that this function is defined as

$\displaystyle{ S(t) = \operatorname{Prob}(\tau \gt t ) }$, where $\displaystyle{ t=0,1,\dots }$ is the time.

Let $\displaystyle{ \tau_1,\dots,\tau_n\ge 0 }$ be independent, identically distributed random variables, whose common distribution is that of $\displaystyle{ \tau }$: $\displaystyle{ \tau_j }$ is the random time when some event $\displaystyle{ j }$ happened. The data available for estimating $\displaystyle{ S }$ is not $\displaystyle{ (\tau_j)_{j=1,\dots,n} }$, but the list of pairs $\displaystyle{ (\, ( \tilde \tau_j, c_j )\, )_{j=1,\dots,n} }$ where for $\displaystyle{ j\in [n] := \{1,2,\dots,n\} }$, $\displaystyle{ c_j\ge 0 }$ is a fixed, deterministic integer, the censoring time of event $\displaystyle{ j }$ and $\displaystyle{ \tilde \tau_j = \min(\tau_j,c_j) }$. In particular, the information available about the timing of event $\displaystyle{ j }$ is whether the event happened before the fixed time $\displaystyle{ c_j }$ and if so, then the actual time of the event is also available. The challenge is to estimate $\displaystyle{ S(t) }$ given this data.

## Derivation of the Kaplan–Meier estimator

Here, we show two derivations of the Kaplan–Meier estimator. Both are based on rewriting the survival function in terms of what is sometimes called hazard, or mortality rates. However, before doing this it is worthwhile to consider a naive estimator.

### A naive estimator

To understand the power of the Kaplan–Meier estimator, it is worthwhile to first describe a naive estimator of the survival function.

Fix $\displaystyle{ k\in [n]:=\{1,\dots,n\} }$ and let $\displaystyle{ t\gt 0 }$. A basic argument shows that the following proposition holds:

Proposition 1: If the censoring time $\displaystyle{ c_k }$ of event $\displaystyle{ k }$ exceeds $\displaystyle{ t }$ ($\displaystyle{ c_k\ge t }$), then $\displaystyle{ \tilde \tau_k\ge t }$ if and only if $\displaystyle{ \tau_k\ge t }$.

Let $\displaystyle{ k }$ be such that $\displaystyle{ c_k\ge t }$. It follows from the above proposition that

$\displaystyle{ \operatorname{Prob}(\tau_k\ge t) = \operatorname{Prob}(\tilde \tau_k\ge t). }$

Let $\displaystyle{ X_k = \mathbb{I}(\tilde \tau_k\ge t) }$ and consider only those $\displaystyle{ k\in C(t) := \{ 1\le k \le n \,:\, c_k \ge t\} }$, i.e. the events for which the outcome was not censored before time $\displaystyle{ t }$. Let $\displaystyle{ m(t)=|C(t)| }$ be the number of elements in $\displaystyle{ C(t) }$. Note that the set $\displaystyle{ C(t) }$ is not random and so neither is $\displaystyle{ m(t) }$. Furthermore, $\displaystyle{ (X_k)_{k\in C(t)} }$ is a sequence of independent, identically distributed Bernoulli random variables with common parameter $\displaystyle{ S(t-1)=\operatorname{Prob}(\tau\ge t) }$. Assuming that $\displaystyle{ m(t)\gt 0 }$, this suggests to estimate $\displaystyle{ S(t-1) }$ using

$\displaystyle{ \hat S_\text{naive}(t-1) = \frac{1}{m(t)} \sum_{k:c_k\ge t} X_k = \frac{|\{1\le k \le n\,:\, \tilde \tau_k\ge t\}|}{|\{1\le k \le n\,:\, c_k\ge t\}|} = \frac{|\{1\le k \le n\,:\, \tilde \tau_k\ge t\}|}{m(t)}, }$

where the second equality follows because $\displaystyle{ \tilde \tau_k\ge t }$ implies $\displaystyle{ c_k\ge t }$, while the last equality is simply a change of notation.

The quality of this estimate is governed by the size of $\displaystyle{ m(t) }$. This can be problematic when $\displaystyle{ m(t) }$ is small, which happens, by definition, when a lot of the events are censored. A particularly unpleasant property of this estimator, that suggests that perhaps it is not the "best" estimator, is that it ignores all the observations whose censoring time precedes $\displaystyle{ t }$. Intuitively, these observations still contain information about $\displaystyle{ S(t) }$: For example, when for many events with $\displaystyle{ c_k \lt t }$, $\displaystyle{ \tilde \tau_k\lt c_k }$ also holds, we can infer that events often happen early, which implies that $\displaystyle{ \operatorname{Prob}(\tau\le t) }$ is large, which, through $\displaystyle{ S(t) = 1-\operatorname{Prob}(\tau\le t) }$ means that $\displaystyle{ S(t) }$ must be small. However, this information is ignored by this naive estimator. The question is then whether there exists an estimator that makes a better use of all the data. This is what the Kaplan–Meier estimator accomplishes. Note that the naive estimator cannot be improved when censoring does not take place; so whether an improvement is possible critically hinges upon whether censoring is in place.

### The plug-in approach

By elementary calculations,

\displaystyle{ \begin{align} S(t) & = \operatorname{Prob}(\tau \gt t\mid\tau \gt t-1)\operatorname{Prob}(\tau \gt t-1) \\[4pt] & = (1-\operatorname{Prob}(\tau\le t\mid\tau \gt t-1)) \operatorname{Prob}(\tau \gt t-1)\\[4pt] & = (1-\operatorname{Prob}(\tau=t\mid\tau \ge t)) \operatorname{Prob}(\tau \gt t-1) \\[4pt] & = q(t) S(t-1)\,, \end{align} }

where the one but last equality used that $\displaystyle{ \tau }$ is integer valued and for the last line we introduced

$\displaystyle{ q(t) = 1-\operatorname{Prob}(\tau=t\mid\tau\ge t). }$

By a recursive expansion of the equality $\displaystyle{ S(t) = q(t) S(t-1) }$, we get

$\displaystyle{ S(t) = q(t) q(t-1) \cdots q(0). }$

Note that here $\displaystyle{ q(0) = 1-\operatorname{Prob}(\tau=0\mid\tau \gt -1) = 1-\operatorname{Prob}(\tau=0) }$.

The Kaplan–Meier estimator can be seen as a "plug-in estimator" where each $\displaystyle{ q(s) }$ is estimated based on the data and the estimator of $\displaystyle{ S(t) }$ is obtained as a product of these estimates.

It remains to specify how $\displaystyle{ q(s)=1-\operatorname{Prob}(\tau=s\mid\tau\ge s) }$ is to be estimated. By Proposition 1, for any $\displaystyle{ k\in [n] }$ such that $\displaystyle{ c_k\ge s }$, $\displaystyle{ \operatorname{Prob}(\tau=s) = \operatorname{Prob}(\tilde \tau_k=s) }$ and $\displaystyle{ \operatorname{Prob}(\tau\ge s) = \operatorname{Prob}(\tilde \tau_k\ge s) }$ both hold. Hence, for any $\displaystyle{ k\in [n] }$ such that $\displaystyle{ c_k\ge s }$,

$\displaystyle{ \operatorname{Prob}(\tau=s|\tau\ge s) = \operatorname{Prob}(\tilde \tau_k=s)/\operatorname{Prob}(\tilde \tau_k\ge s). }$

By a similar reasoning that lead to the construction of the naive estimator above, we arrive at the estimator

$\displaystyle{ \hat q(s) = 1 - \frac{|\{1\le k\le n\,:\, c_k\ge s, \tilde \tau_k=s\}|}{|\{1\le k \le n\,:\, c_k\ge s, \tilde \tau_k\ge s\}|} = 1 - \frac{|\{1\le k\le n\,:\,\tilde \tau_k=s\}|}{|\{1\le k \le n\,:\, \tilde \tau_k\ge s\}|} }$

(think of estimating the numerator and denominator separately in the definition of the "hazard rate" $\displaystyle{ \operatorname{Prob}(\tau=s|\tau\ge s) }$). The Kaplan–Meier estimator is then given by

$\displaystyle{ \hat S(t) = \prod_{s=0}^t \hat q(s). }$

The form of the estimator stated at the beginning of the article can be obtained by some further algebra. For this, write $\displaystyle{ \hat q(s)=1-d(s)/n(s) }$ where, using the actuarial science terminology, $\displaystyle{ d(s)=|\{1\le k\le n\,:\,\tau_k=s\}| }$ is the number of known deaths at time $\displaystyle{ s }$, while $\displaystyle{ n(s)=|\{1\le k \le n\,:\, \tilde \tau_k\ge s\}| }$ is the number of those persons who are alive (and not being censored) at time $\displaystyle{ s-1 }$.

Note that if $\displaystyle{ d(s)=0 }$, $\displaystyle{ \hat q(s)=1 }$. This implies that we can leave out from the product defining $\displaystyle{ \hat S(t) }$ all those terms where $\displaystyle{ d(s)=0 }$. Then, letting $\displaystyle{ 0\le t_1\lt t_2\lt \dots\lt t_m }$ be the times $\displaystyle{ s }$ when $\displaystyle{ d(s)\gt 0 }$, $\displaystyle{ d_i = d(t_i) }$ and $\displaystyle{ n_i = n(t_i) }$, we arrive at the form of the Kaplan–Meier estimator given at the beginning of the article:

$\displaystyle{ \hat S(t) = \prod_{i:t_i\le t} \left(1-\frac{d_i}{n_i}\right). }$

As opposed to the naive estimator, this estimator can be seen to use the available information more effectively: In the special case mentioned beforehand, when there are many early events recorded, the estimator will multiply many terms with a value below one and will thus take into account that the survival probability cannot be large.

### Derivation as a maximum likelihood estimator

Kaplan–Meier estimator can be derived from maximum likelihood estimation of hazard function.[8] More specifically given $\displaystyle{ d_i }$ as the number of events and $\displaystyle{ n_i }$ the total individuals at risk at time $\displaystyle{ t_i }$, discrete hazard rate $\displaystyle{ h_i }$ can be defined as the probability of an individual with an event at time $\displaystyle{ t_i }$. Then survival rate can be defined as:

$\displaystyle{ S(t) = \prod\limits_{i:\ t_i\le t} (1-h_i) }$

and the likelihood function for the hazard function up to time $\displaystyle{ t_i }$ is:

$\displaystyle{ \mathcal{L}(h_{j: j\le i}\mid d_{j: j\le i},n_{j: j\le i}) = \prod_{j=1}^i h_j^{d_j}(1-h_j)^{n_j-d_j} }$

therefore the log likelihood will be:

$\displaystyle{ \log(\mathcal{L}) = \sum_{j=1}^i \left(d_j\log(h_j)+(n_j-d_j)\log(1-h_j)\right) }$

finding the maximum of log likelihood with respect to $\displaystyle{ h_i }$ yields:

$\displaystyle{ \frac{\partial \log(\mathcal{L})}{\partial h_i} = \frac{d_i}{\widehat{h}_i}-\frac{n_i-d_i}{1-\widehat{h}_i} = 0 \Rightarrow \widehat{h}_i=\frac{d_i}{n_i} }$

where hat is used to denote maximum likelihood estimation. Given this result, we can write:

$\displaystyle{ \widehat S(t) = \prod\limits_{i:\ t_i\le t} \left(1 - \widehat{h}_i\right) = \prod\limits_{i:\ t_i\le t} \left(1 - \frac{d_i}{n_i}\right) }$

## Benefits and limitations

The Kaplan–Meier estimator is one of the most frequently used methods of survival analysis. The estimate may be useful to examine recovery rates, the probability of death, and the effectiveness of treatment. It is limited in its ability to estimate survival adjusted for covariates; parametric survival models and the Cox proportional hazards model may be useful to estimate covariate-adjusted survival.

## Statistical considerations

The Kaplan–Meier estimator is a statistic, and several estimators are used to approximate its variance. One of the most common estimators is Greenwood's formula:[9]

$\displaystyle{ \widehat{\operatorname{Var}} \left( \widehat S(t) \right) = \widehat S(t)^2 \sum_{i:\ t_i\le t} \frac{d_i}{n_i(n_i-d_i)}, }$

where $\displaystyle{ d_i }$ is the number of cases and $\displaystyle{ n_i }$ is the total number of observations, for $\displaystyle{ t_i \lt t }$.

For a 'sketch' of the mathematical derivation of the equation above, click on "show" to reveal

Greenwood's formula is derived[10] by noting that probability of getting $\displaystyle{ d_i }$ failures out of $\displaystyle{ n_i }$ cases follows a binomial distribution with failure probability $\displaystyle{ h_i }$. As a result for maximum likelihood hazard rate $\displaystyle{ \widehat{h}_i = d_i/n_i }$ we have $\displaystyle{ E\left(\widehat{h}_i\right) = h_i }$ and $\displaystyle{ \operatorname{Var}\left(\widehat{h}_i\right) = h_i(1-h_i)/n_i }$. To avoid dealing with multiplicative probabilities we compute variance of logarithm of $\displaystyle{ \widehat S(t) }$ and will use the delta method to convert it back to the original variance:

\displaystyle{ \begin{align} \operatorname{Var}\left(\log \widehat{S}(t)\right) &\sim \frac{1}{{\widehat{S}(t)}^2} \operatorname{Var} \left(\widehat{S}(t)\right) \Rightarrow \\ \operatorname{Var}\left( \widehat{S}(t)\right) &\sim {{\widehat{S}(t)}^2}\operatorname{Var}\left(\log\widehat{S}(t) \right) \end{align} }

using martingale central limit theorem, it can be shown that the variance of the sum in the following equation is equal to the sum of variances:[10]

$\displaystyle{ \log\widehat S(t) = \sum\limits_{i:\ t_i\le t} \log\left(1 - \widehat{h}_i\right) }$

as a result we can write:

\displaystyle{ \begin{align} \operatorname{Var}( \widehat{S}(t)) &\sim {{\widehat{S}(t)}^2}\operatorname{Var}\left(\sum_{i:\ t_i\le t} \log\left(1 - \widehat{h}_i\right)\right) \\ &\sim {{\widehat{S}(t)}^2}\sum\limits_{i:\ t_i\le t} \operatorname{Var}\left(\log\left(1 - \widehat{h}_i\right)\right) \end{align} }

using the delta method once more:

\displaystyle{ \begin{align} \operatorname{Var}( \widehat{S}(t)) &\sim {{\widehat{S}(t)}^2}\sum_{i:\ t_i\le t}\left(\frac{\partial \log\left(1 - \widehat{h}_i\right)}{\partial \widehat{h}_i}\right)^2 \operatorname{Var}\left(\widehat{h}_i\right)\\ &={{\widehat{S}(t)}^2}\sum_{i:\ t_i\le t}\left(\frac{1}{1-\widehat{h}_i}\right)^2\frac{\widehat{h}_i \left( 1-\widehat{h}_i \right)}{n_i} \\ &= {{\widehat{S}(t)}^2}\sum_{i:\ t_i\le t} \frac{\widehat{h}_i}{n_i\left(1-\widehat{h}_i\right)} \\ &= {{\widehat{S}(t)}^2}\sum_{i:\ t_i\le t} \frac{d_i}{n_i(n_i-d_i)} \end{align} }

as desired.

In some cases, one may wish to compare different Kaplan–Meier curves. This can be done by the log rank test, and the Cox proportional hazards test.

Other statistics that may be of use with this estimator are pointwise confidence intervals,[11] the Hall-Wellner band[12] and the equal-precision band.[13]

## Software

• Mathematica: the built-in function SurvivalModelFit creates survival models.[14]
• SAS: The Kaplan–Meier estimator is implemented in the proc lifetest procedure.[15]
• R: the Kaplan–Meier estimator is available as part of the survival package.[16][17][18]
• Stata: the command sts returns the Kaplan–Meier estimator.[19][20]
• Python: the lifelines package includes the Kaplan–Meier estimator.[21]
• MATLAB: the ecdf function with the 'function','survivor' arguments can calculate or plot the Kaplan–Meier estimator.[22]
• StatsDirect: The Kaplan–Meier estimator is implemented in the Survival Analysis menu.[23]
• SPSS: The Kaplan–Meier estimator is implemented in the Analyze > Survival > Kaplan-Meier... menu.[24]
• Julia: the Survival.jl package includes the Kaplan–Meier estimator.[25]

## References

1. Kaplan, E. L.; Meier, P. (1958). "Nonparametric estimation from incomplete observations". J. Amer. Statist. Assoc. 53 (282): 457–481. doi:10.2307/2281868.
2. Kaplan, E.L. in a retrospective on the seminal paper in "This week's citation classic". Current Contents 24, 14 (1983). Available from UPenn as PDF.
3. Meyer, Bruce D. (1990). "Unemployment Insurance and Unemployment Spells". Econometrica 58 (4): 757–782. doi:10.2307/2938349.
4. Stalpers, Lukas J A; Kaplan, Edward L (4 May 2018). "Edward L. Kaplan and the Kaplan-Meier Survival Curve". BSHM Bulletin: Journal of the British Society for the History of Mathematics 33 (2): 109–135. doi:10.1080/17498430.2018.1450055.
5. Rich, Jason T.; Neely, J. Gail; Paniello, Randal C.; Voelker, Courtney C. J.; Nussenbaum, Brian; Wang, Eric W. (September 2010). "A practical guide to understanding Kaplan-Meier curves". Otolaryngology–Head and Neck Surgery 143 (3): 331–336. doi:10.1016/j.otohns.2010.05.007. PMID 20723767.
6.
7. Greenwood, Major (1926). A report on the natural duration of cancer. Issue 33 of Reports on public health and medical subjects. HMSO. OCLC 14713088.
8.
9. Fay, Michael P.; Brittain, Erica H.; Proschan, Michael A. (1 September 2013). "Pointwise confidence intervals for a survival distribution with small samples or heavy censoring". Biostatistics 14 (4): 723–736. doi:10.1093/biostatistics/kxt016. PMID 23632624.
10. Hall, W. J.; Wellner, Jon A. (1980). "Confidence bands for a survival curve from censored data". Biometrika 67 (1): 133–143. doi:10.1093/biomet/67.1.133.
11. Nair, Vijayan N. (August 1984). "Confidence Bands for Survival Functions With Censored Data: A Comparative Study". Technometrics 26 (3): 265–275. doi:10.1080/00401706.1984.10487964.
12. The LIFETEST Procedure
13. "survival: Survival Analysis". R Project. April 2019.
14. Willekens, Frans (2014). "The Survival Package". Multistate Analysis of Life Histories with R. Springer. pp. 135–153. doi:10.1007/978-3-319-08383-4_6. ISBN 978-3-319-08383-4.
15. Chen, Ding-Geng; Peace, Karl E. (2014). Clinical Trial Data Analysis Using R. CRC Press. pp. 99–108. ISBN 9781439840214.
16. Cleves, Mario (2008). An Introduction to Survival Analysis Using Stata (Second ed.). College Station: Stata Press. pp. 93–107. ISBN 978-1-59718-041-2.
17. lifelines docs
18. https://www.statsdirect.co.uk/help/Default.htm#survival_analysis/kaplan_meier.htm