Kaplan–Meier and Nelson–Aalen Estimation › Formula
Machine Learning from ScratchAll chapters Kaplan–Meier and Nelson–Aalen Estimation › FormulaSection view · Sections in this chapter4 / 10 ↓
Reading tools Definitions, links & notes
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The formulas in this chapter look different at first, one a product and the other a sum. The shared logic is easier to see if we start from the data and ask a single question at each event time: who is still eligible to have the event? The answer is the risk set. Once we can count the risk set and the events that occur inside it, both estimators follow almost immediately.
We begin with the observed data. For subject ,
- is the true event time,
- is the censoring time,
- is the observed follow-up time,
- is the event indicator, equal to if we observed the event and if the observation was censored.
We assume independent draws from the target population, strictly positive event times, and right censoring. For the basic marginal estimators, independence of and is a sufficient censoring assumption, with positive probability of remaining observed throughout the time range we estimate. Random treatment assignment alone does not establish this assumption about follow-up.
Risk sets, tied events, and censoring order
At any time , the risk set is the set of subjects still under observation and event-free just before :
Its size is . This definition is the bookkeeping center of the whole chapter. A subject who has already had the event is no longer eligible to have it again, and a subject who has been censored before cannot contribute information about an event at . Both leave the risk set. A subject who is censored exactly at is a boundary case, and we will handle it by convention below.
If the distinct observed event times are
then at event time we write
for the number at risk and
for the number of events at that time. The ratio is the empirical event fraction among those who were still eligible at . That fraction will become the Nelson-Aalen increment, and its complement will become the Kaplan-Meier factor.
It is also where censoring enters: a censored subject remains in up to and including their censoring time, then leaves. Censoring does not create an event, but it changes who is available for later events.
Tied events occur when . The product-limit estimator handles ties by grouping all events at into one conditional factor. Tied event and censoring times require a convention. We use the standard convention that events are processed before censorings at the same time. A subject censored at is therefore counted in for the event at , and is removed only after that event time. Removing those censorings first would make the denominator smaller, increase the event fraction, and lower the estimated survival under a different convention.
This convention is worth checking in software. The tied-data check below confirms events before censorings for the installed SciPy and statsmodels implementations; consult documentation when exact tie behavior matters. The convention matters most when the risk set is small or when many subjects share the same recorded time.
Kaplan–Meier product-limit estimation
Kaplan-Meier estimates survival by chaining conditional probabilities. At event time , suppose subjects are at risk and events occur. The estimated probability of surviving past , given that a subject was still at risk just before , is
where:
- : the number of events at event time
- : the number of subjects at risk at event time
If no events occur at , then and the factor is ; censoring times do not create factors. If all subjects at risk have an event, the factor is and the estimated survival drops to zero. In between, the factor is the fraction of the current risk set that survives the event time.
Multiplying these conditional factors across all event times up to gives the Kaplan-Meier estimator:
with the empty product defined as for times before the first event. The word product-limit refers to this product of estimated conditional survival probabilities. It is the nonparametric maximum likelihood estimator of the survival function under independent right censoring.
where:
- : the estimated survival probability of surviving past time
- : the -th distinct observed event time
- : the number of events at event time
- : the number of subjects at risk at event time
- : the estimated conditional probability of surviving past given survival to just before
- the product over : multiply the conditional factors for all event times up to and including
We can read the formula as a sequence of updates. Start with . At each event time, multiply the current survival probability by the fraction of the risk set that did not have an event. Censoring changes the next risk set, but it does not directly multiply the curve by anything.
The variance of the Kaplan-Meier estimator is usually estimated with Greenwood’s formula. Greenwood’s cumulative variance factor is
where:
- : Greenwood’s cumulative variance factor for the survival curve up to time , which combines with the squared survival estimate to give the variance of
- : the number of events at event time
- : the number of subjects at risk at event time
- : the number at risk who do not have the event at
Then
where:
- : the estimated variance of the Kaplan-Meier survival estimate at time
- : the Kaplan–Meier survival estimate at time
- : Greenwood’s cumulative variance factor at time
To see where this comes from, take logs:
For a binomial proportion , the delta method gives
where:
- : the estimated event fraction at event time
- : the event probability in the local binomial working model, conditional on membership in the current risk set at
- : the number of subjects at risk at event time
- : the number of events at event time
Plugging in yields . This binomial calculation is a sketch of the local variance contribution. The full large-sample derivation uses counting-process martingales, since earlier events change later risk sets. Summing the contributions and applying the delta method once more to gives the factor . The denominator shows why Greenwood’s formula fails when : at that point the curve hits zero and the variance formula is not finite.
Nelson–Aalen cumulative hazard estimation
For an absolutely continuous event-time distribution, at times with positive survival where the following limit exists, the hazard is the instantaneous event rate among those still at risk:
where:
- : the hazard function, the instantaneous event rate at time among those still at risk
- : the true event time
- : a small time increment
- : the conditional probability of an event in given survival to time
The cumulative hazard is
where:
- : the cumulative hazard up to time
- : the hazard function at time
This integral describes a continuous-time hazard with no initial event mass. For inherently discrete event times, cumulative hazard is instead a sum of conditional hazard jumps and need not equal . The implementation below groups events that share a recorded time; it does not split a tied group into a sequence of separate failures.
Nelson-Aalen estimates by accumulating estimated hazard increments at the observed event times. At , the observed event fraction among those at risk is , so we set
where:
- : the estimated hazard increment at event time
- : the number of events at event time
- : the number of subjects at risk at event time
Adding these increments gives
with , where:
- : the Nelson–Aalen cumulative hazard estimate at time
- : the -th distinct observed event time
- : the number of events at event time
- : the number of subjects at risk at event time
- the sum over : add the hazard increments for all event times up to and including
This is a nondecreasing step function. It jumps at event times; censoring alone creates no jump. The jump size is large when many events occur among few subjects at risk, and small when one event occurs among a large risk set.
A grouped Greenwood-type variance estimate is
This is a binomial plug-in, Greenwood-type estimate. The Aalen counting-process estimate uses instead. The two differ by the factor in each contribution. A smaller reported variance does not by itself establish better uncertainty coverage, especially with few subjects at risk.
where:
- : the estimated variance of the Nelson–Aalen cumulative hazard at time
- : the number of events at event time
- : the number of subjects at risk at event time
A local plug-in argument treats the event count as binomial given the current risk set, with trials and event probability estimated by . This motivates the contribution; it is not an exact finite-sample variance proof for the accumulated estimator. The variance of is approximately
Nelson-Aalen is closely related to Kaplan-Meier, but the relationship is not exact in finite samples. Since
and for small , we have
The approximation is useful on a time range where the event fractions and their accumulated second-order error are small. Large risk sets with few events per time make the individual fractions small. It is not an identity. For , where represents an event fraction ,
so the product-limit estimator lies below the exponential transform of Nelson–Aalen whenever events occur:
The exact product-integral relationship is
not . We should not report as if it were Kaplan–Meier. Their relative difference tends to zero in a small-increment limit where the accumulated second-order error also vanishes. Heavy ties or small risk sets can make the difference noticeable.
The finite-time gap has a simple source: for every event fraction strictly between zero and one, the product-limit factor is smaller than the exponential factor . We can display that inequality directly.
PythonIn [3]Expand
import matplotlib.pyplot as plt
import numpy as np
event_fraction_grid = np.linspace(0.001, 0.999, 499)
factor_product = 1.0 - event_fraction_grid
factor_exp = np.exp(-event_fraction_grid)
factor_gap = factor_exp - factor_productVisualizationOut [4]Expand

Mathematical Properties
The formulas above imply a few structural facts that are useful when reading software output or checking a plot:
- is a right-continuous, nonincreasing step function with values in and .
- is a right-continuous, nondecreasing step function with .
- Both estimators change only at observed event times. A censoring time changes future risk sets but does not create a jump.
- Ties are handled by grouping: the Kaplan–Meier factor is , and the Nelson–Aalen increment is .
- The exponential transform satisfies , with exact equality only when no events have occurred at or before time .
- Greenwood’s variance requires . If , the survival estimate reaches zero and the variance formula is not finite at that point.
Uncertainty, median survival, and tail limitations
The Kaplan-Meier intervals below describe uncertainty at a fixed time; they do not give simultaneous coverage for the whole curve. We use the log-log transformation because its interior limits stay within , whereas a symmetric normal interval can extend outside that range. Its coverage accuracy still depends on censoring, sample support, and distance from the endpoints. Let
For , a pointwise interval is
where:
- : the Kaplan–Meier survival estimate at time
- : the square root of Greenwood’s cumulative variance factor,
- : the standard normal quantile, such as for a 95% interval
- : the significance level (one minus the confidence level)
The log-log transformation is undefined at or . We return missing limits at these boundaries instead of treating a zero-width display as statistical certainty. The known starting value is separate because event times are strictly positive. These are approximate pointwise intervals. Simultaneous coverage over a specified, adequately supported time interval requires a method calibrated for the whole curve, such as a Hall–Wellner band; separate pointwise bootstrap percentiles would still be pointwise.
For in a supported regime with a reliable nondegenerate variance and normal approximation, an approximate pointwise log-transformed interval for is
where:
- : the Nelson–Aalen cumulative hazard estimate at time
- : the standard error from the chosen Greenwood-type variance estimate
- : the standard normal quantile for a interval, such as for a 95% interval
- : the significance level (one minus the confidence level)
The displayed log interval is undefined at . A no-event estimate at a positive follow-up time does not imply zero uncertainty; inference there needs a boundary-specific method. The chosen binomial variance can also vanish after every member of a tied risk set fails. A resulting zero-width interval is not justified merely because the hazard estimate is positive. The known origin is a separate structural value.
The median survival time is the first time the estimated survival curve reaches or falls below one half:
Because the curve is a step function, the median is an observed event time, not an interpolated value between steps. If the curve never reaches or falls below by the last follow-up, the median is not estimable. We should report “median not reached” rather than a fabricated number, together with the last follow-up time and the number still at risk. A confidence interval for the median can be obtained by inverting pointwise survival intervals, as in the Brookmeyer–Crowley approach, or by resampling observed time–event-indicator pairs and recomputing the Kaplan-Meier median. Adequate follow-up around the median is still needed; some resamples or interval endpoints may not reach it. A point estimate alone does not show its sampling uncertainty.
Tail limitations follow directly from the risk-set definition. At late times is small, so each event removes a larger fraction of the remaining survival estimate. The absolute Greenwood standard error need not grow: it also depends on the survival estimate, which is falling. If the largest observed time is censored, the curve remains above zero and we have no direct estimate beyond that time. A flat empirical tail does not establish a cure fraction. Beyond the last observed follow-up, there are no further observations to support its extension. If , the curve drops to zero and Greenwood’s denominator vanishes. Sparse late risk sets limit tail precision. Tied times require the recorded-time convention and time-resolution assumptions to be checked; informative censoring can bias the curve throughout follow-up.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!