Module 1 · Survival analysis — functions & estimation

Lectures 1.1–1.3 and the non-parametric estimation lectures. Reading: Lecture Notes Part 1, §1.1–1.4.

← Back to notes index

Lecture 1.1–1.2 — Survival analysis: core functions

Notation

$T$ = random variable denoting the event time.

Symbol Also written Name
$f(t)$   probability density function (pdf)
$F(t)$   cumulative distribution function (CDF)
$S(t)$   survival distribution
$\lambda(t)$ $h(t)$ hazard function
$\Lambda(t)$ $H(t)$ cumulative hazard function

Probability density function — as a limit:

\[f(t) = \lim_{\Delta \to 0} \frac{1}{\Delta}\, P(t \le T < t + \Delta)\]

Functions

Cumulative distribution function — probability the event has happened by time $t$:

\[F(t) = P(T \le t) = \int_0^t f(x)\,dx\]

Survival function — probability of surviving beyond $t$:

\[\begin{aligned} S(t) &= P(T > t) = 1 - P(T \le t) = 1 - F(t) \\[4pt] &= 1 - \int_0^t f(u)\,du \\[4pt] &= \int_t^{\infty} f(u)\,du \end{aligned}\]

The last step uses $\int_0^{\infty} f(u)\,du = 1$: everything not accumulated before $t$ is the mass remaining after it.

Hazard function — instantaneous event rate at $t$, given survival up to $t$:

\[\lambda(t) = \lim_{\Delta \to 0} \frac{1}{\Delta}\, P(t \le T < t + \Delta \mid T \ge t)\]

Same limit as $f(t)$, but conditioned on $T \ge t$ — that conditioning is the whole difference. $f(t)$ is a rate over everyone; $\lambda(t)$ is a rate among those still at risk at time $t$. Neither is a probability.

Cumulative hazard:

\[\Lambda(t) = \int_0^t \lambda(u)\,du\]

Deriving $\lambda(t) = f(t) / S(t)$

Start from the definition of conditional probability:

\[P(A \mid B) = \frac{P(A, B)}{P(B)}\]

The key observation: ${t \le T < t + \Delta}$ already implies ${T \ge t}$, so intersecting with it changes nothing —

\[P(t \le T < t + \Delta,\; T \ge t) = P(t \le T < t + \Delta)\]

Applying both to the hazard:

\[\begin{aligned} \lambda(t) &= \lim_{\Delta \to 0} \frac{1}{\Delta}\, P(t \le T < t + \Delta \mid T \ge t) \\[6pt] &= \lim_{\Delta \to 0} \frac{1}{\Delta}\, \frac{P(t \le T < t + \Delta,\; T \ge t)}{P(T \ge t)} \\[6pt] &= \lim_{\Delta \to 0} \frac{1}{\Delta}\, \frac{P(t \le T < t + \Delta)}{P(T \ge t)} \\[6pt] &= \frac{1}{P(T \ge t)} \lim_{\Delta \to 0} \frac{1}{\Delta}\, P(t \le T < t + \Delta) \\[6pt] &= \frac{1}{P(T \ge t)}\, f(t) \;=\; \frac{f(t)}{S(t)} \end{aligned}\]

$P(T \ge t)$ comes out of the limit because it does not depend on $\Delta$; what remains is exactly the limit definition of $f(t)$. For continuous $T$, $P(T = t) = 0$, so $P(T \ge t) = P(T > t) = S(t)$.

Key results

The two identities to remember:

\[\lambda(t) = \frac{f(t)}{S(t)}\] \[S(t) = e^{-\Lambda(t)}\]

The second follows from the first. The bridge between them is

\[-\frac{d}{dt}\big[\log S(t)\big] = \lambda(t)\]

which unpacks by the chain rule, then substituting $S(t) = 1 - F(t)$:

\[\begin{aligned} -\frac{d}{dt}\big[\log S(t)\big] &= -\frac{1}{S(t)}\, \frac{d}{dt} S(t) \\[6pt] &= -\frac{1}{S(t)}\, \frac{d}{dt}\big[1 - F(t)\big] \\[6pt] &= -\frac{1}{S(t)}\,\big[-f(t)\big] \\[6pt] &= \frac{f(t)}{S(t)} \;=\; \lambda(t) \end{aligned}\]

The two minus signs cancel: $\frac{d}{dt}[1 - F(t)] = -f(t)$, since $F’(t) = f(t)$ and the constant $1$ differentiates away.

Now substitute that into the cumulative hazard and integrate:

\[\begin{aligned} \Lambda(t) &= \int_0^t \lambda(u)\,du = \int_0^t -\frac{d}{du}\big[\log S(u)\big] du \\[6pt] &= -\log S(u)\,\Big|_0^t \\[6pt] &= -\log S(t) + \underbrace{\log S(0)}_{\log 1 \;=\; 0} \\[6pt] &= -\log S(t) \end{aligned}\]

The boundary term vanishes because $S(0) = 1$ — nobody has had the event at time zero — and $\log 1 = 0$. So

\[\Lambda(t) = -\log S(t) \qquad\Longrightarrow\qquad S(t) = e^{-\Lambda(t)}\]

So these are not five independent objects — any one of them determines the rest.

Summary measures

Mean survival, $\mu$:

\[E(T) = \mu = \int_0^{\infty} x\, f(x)\,dx\]

Median survival, $\tau$ — the time at which half the population is still event-free:

\[S(\tau) = 0.5\]

In practice the median is the more commonly reported of the two: it is defined directly off the survival curve, and unlike $\mu$ it does not require the right tail of $f$ to be observed.

Lecture 1.3 — Parametric estimation

Rather than estimating $S(t)$ non-parametrically, assume $T$ follows a known distribution and estimate its parameters.

Exponential distribution

The simplest parametric survival model. One parameter, $\lambda > 0$:

\[f(t) = \lambda e^{-\lambda t}, \qquad t \ge 0\] \[S(t) = \int_t^{\infty} f(u)\,du = e^{-\lambda t}\] \[\lambda(t) = \frac{f(t)}{S(t)} = \frac{\lambda e^{-\lambda t}}{e^{-\lambda t}} = \lambda\] \[\Lambda(t) = \int_0^t \lambda(u)\,du = \int_0^t \lambda\,du = \lambda t\]

The defining property: constant hazard. $\lambda(t) = \lambda$ does not depend on $t$ — the instantaneous risk is the same at every moment, regardless of how long the subject has already survived (the memoryless property). This is what makes the exponential simple, and also what makes it restrictive: real hazards usually rise or fall over time.

If $\lambda$ is large, hazard is high and survival is low.

The general identity $S(t) = e^{-\Lambda(t)}$ checks out here:

\[S(t) = e^{-\Lambda(t)} = e^{-\lambda t} \quad\checkmark\]

Exponential: median and mean

Median survival $\tau$ — solve $S(\tau) = 0.5$:

\[\begin{aligned} S(\tau) &= 0.5 \\[4pt] e^{-\lambda \tau} &= 0.5 \\[4pt] -\lambda \tau &= \log(0.5) \\[4pt] \tau &= \frac{-\log(0.5)}{\lambda} = \frac{\log 2}{\lambda} \end{aligned}\]

Mean survival $\mu$:

\[\mu = \int_0^{\infty} x f(x)\,dx = \int_0^{\infty} x\, \lambda e^{-\lambda x} dx = \frac{1}{\lambda}\]

Evaluated by integration by parts:

\[\int_a^b u\,dv = uv\,\Big|_a^b - \int_a^b v\,du\]

Take $u = \lambda x$ and $dv = e^{-\lambda x} dx$, so $du = \lambda\,dx$ and $v = -\frac{1}{\lambda} e^{-\lambda x}$:

\[\begin{aligned} \int_0^{\infty} x\, \lambda e^{-\lambda x} dx &= \underbrace{\left[ \lambda x \cdot \left(-\tfrac{1}{\lambda} e^{-\lambda x}\right) \right]_0^{\infty}}_{=\; 0} + \int_0^{\infty} e^{-\lambda x} dx \\[6pt] &= 0 + \left[ -\tfrac{1}{\lambda} e^{-\lambda x} \right]_0^{\infty} \\[6pt] &= \frac{1}{\lambda} \end{aligned}\]

The boundary term vanishes at both ends: at $x = 0$ the factor $x$ is zero, and as $x \to \infty$ the decay $e^{-\lambda x}$ beats the linear growth of $x$.

So for the exponential both summaries are simple functions of the single parameter:

\[\mu = \frac{1}{\lambda} \qquad \tau = \frac{\log 2}{\lambda} \qquad\Longrightarrow\qquad \tau = \mu \log 2 \approx 0.693\, \mu\]

The median is always below the mean here — the exponential is right-skewed.

Weibull distribution

Two parameters — a scale parameter $\lambda > 0$ and a shape parameter $k > 0$:

\[f(t) = k\lambda(\lambda t)^{k-1} e^{-(\lambda t)^k}\] \[S(t) = e^{-(\lambda t)^k}\] \[\lambda(t) = k\lambda(\lambda t)^{k-1}\] \[\Lambda(t) = (\lambda t)^k\]

Lecture erratum: at 23:50 the board reads $\Lambda(t) = \lambda t^k$; the corrected form is $\Lambda(t) = (\lambda t)^k$, consistent with $S(t) = e^{-(\lambda t)^k}$.

The shape parameter controls how the hazard moves over time — this is what the exponential could not do:

$k$ Hazard $\lambda(t)$ Interpretation
$0 < k < 1$ decreasing risk falls with time (early failures, e.g. post-surgical)
$k = 1$ constant, $= \lambda$ reduces exactly to the exponential
$k > 1$ increasing risk rises with time (wear-out, ageing)

At $k = 1$: $f(t) = \lambda e^{-\lambda t}$, $S(t) = e^{-\lambda t}$, $\lambda(t) = \lambda$ — the exponential is the special case.

The identities still hold. From $S(t) = e^{-\Lambda(t)}$:

\[\Lambda(t) = -\log S(t) = -\log e^{-(\lambda t)^k} = (\lambda t)^k\]

and differentiating gives back the hazard:

\[\lambda(t) = \frac{d}{dt}\Lambda(t) = \frac{d}{dt}(\lambda t)^k = k\lambda(\lambda t)^{k-1}\]

Gamma distribution

Also two parameters — a scale parameter $\theta$ and a shape parameter $k$:

\[f(t) = \frac{1}{\Gamma(k)\, \theta^k}\, t^{k-1} e^{-t/\theta}\]

where $\Gamma$ is the gamma function:

\[\Gamma(k) = (k-1)!\]

That factorial form holds for positive integer $k$; in general the gamma function is the integral that extends the factorial to all $k > 0$:

\[\Gamma(k) = \int_0^{\infty} x^{k-1} e^{-x}\,dx\]

Special case — setting $k = 1$ and $\theta = 1/\lambda$ recovers the exponential:

\[f(t) = \frac{1}{\Gamma(1)\,(1/\lambda)^1}\, t^{0} e^{-\lambda t} = \lambda e^{-\lambda t}\]

since $\Gamma(1) = 0! = 1$.

Unlike the exponential and Weibull, the gamma has no closed form for $S(t)$ — it requires the incomplete gamma function — which is part of why the Weibull is the more common choice in survival work.

Log-normal distribution

Parameters $\mu \in (-\infty, \infty)$ and $\sigma > 0$.

Definition by transformation — if $N \sim \text{Normal}(\mu, \sigma^2)$, then

\[T = \exp(N) \quad\text{is}\quad \text{Log-normal}(\mu, \sigma^2)\]

That is: $T$ is log-normal exactly when $\log T$ is normal. Since $\exp$ is always positive, $T > 0$ automatically — which is what makes it usable as a survival time.

\[f(t) = \frac{1}{t\sigma\sqrt{2\pi}} \exp\left\{ -\frac{\big(\log(t) - \mu\big)^2}{2\sigma^2} \right\}\] \[\text{mean} = e^{\mu + \sigma^2/2}\]

Careful with $\mu$ here. In this distribution $\mu$ and $\sigma$ are the parameters of the underlying normal $\log T$ — they are not the mean and standard deviation of $T$. That is why the mean of $T$ is $e^{\mu + \sigma^2/2}$ rather than $\mu$. Elsewhere in these notes $\mu$ denotes mean survival $E(T)$; the two uses are unrelated.

The median, by contrast, is just $e^{\mu}$ — since $S(\tau) = 0.5$ corresponds to the median of the normal, which is $\mu$. The mean sits above it by the factor $e^{\sigma^2/2}$, so the log-normal is right-skewed.

Its hazard is non-monotone: it rises to a peak and then falls back toward zero. That distinguishes it from the exponential (flat), and from the Weibull and gamma (both monotone), and suits settings where risk peaks some time after baseline.

The distributions compared

  Parameters $S(t)$ Hazard
Exponential $\lambda$ $e^{-\lambda t}$ constant, $\lambda$
Weibull $\lambda, k$ $e^{-(\lambda t)^k}$ monotone: up if $k>1$, down if $k<1$
Gamma $\theta, k$ no closed form monotone, approaches $1/\theta$
Log-normal $\mu, \sigma$ no closed form non-monotone: rises, then falls

Both the Weibull and the gamma contain the exponential as a special case ($k = 1$), so each is a strict generalization of it. The log-normal does not — it is a different family, and the only one of the four with a non-monotone hazard.

Maximum likelihood estimation

Having picked a parametric family, fit it by choosing the parameter that makes the observed data most likely. For $n$ independent observed times $t_1, \dots, t_n$, the likelihood is the product of the densities:

\[L(\lambda) = \prod_{i=1}^{n} f_\lambda(t_i)\]

and the estimate $\hat{\lambda}$ is whatever maximizes it:

\[\begin{aligned} \hat{\lambda} &= \arg\max_{\lambda} \prod_{i=1}^{n} f_\lambda(t) \\[6pt] &= \arg\max_{\lambda} \prod_{i=1}^{n} \lambda e^{-\lambda t_i} \end{aligned}\]

substituting the exponential density in the second line.

Take logs. A product of $n$ terms is awkward to differentiate, and underflows numerically. Because $\log$ is strictly increasing, it does not move the location of the maximum — $\arg\max$ is unchanged, even though the max value is not:

\[\begin{aligned} \hat{\lambda} &= \arg\max_{\lambda} \log\left( \prod_{i=1}^{n} \lambda e^{-\lambda t_i} \right) \\[6pt] &= \arg\max_{\lambda} \sum_{i=1}^{n} \log\left( \lambda e^{-\lambda t_i} \right) \\[6pt] &= \arg\max_{\lambda} \sum_{i=1}^{n} \log(\lambda) - \lambda t_i \end{aligned}\]

The product became a sum ($\log ab = \log a + \log b$), and each term expanded to something with no exponential left in it — a function that is easy to differentiate.

Solve. Differentiate the log-likelihood and set it to zero:

\[\frac{d}{d\lambda} \sum_{i=1}^{n} \big\{ \log(\lambda) - \lambda t_i \big\}\] \[\sum_{i=1}^{n} \left[ \frac{1}{\lambda} - t_i \right] = 0\]

The sum splits: $\sum_i \frac{1}{\lambda} = \frac{n}{\lambda}$ (the same term $n$ times), leaving

\[\frac{n}{\lambda} - \sum_{i=1}^{n} t_i = 0 \qquad\Longrightarrow\qquad \boxed{\;\hat{\lambda} = \frac{n}{\sum_i t_i}\;}\]

Sanity check. $\sum_i t_i / n$ is the sample mean $\bar{t}$, so

\[\hat{\lambda} = \frac{1}{\bar{t}}\]

which lines up with $\mu = 1/\lambda$ derived earlier: the estimate of the rate is the reciprocal of the observed mean survival time. Long survival times $\Rightarrow$ small $\hat{\lambda}$ $\Rightarrow$ low hazard.

Censoring in the likelihood

In practice not every subject is observed to have the event — some are still event-free when the study ends or they drop out.

Let $T$ be the event time and $C$ the censoring time (when the subject leaves observation). What is actually recorded is whichever comes first:

\[X = \min(T, C)\]

Both $T$ and $C$ are random variables; only their minimum is observed. The indicator $\delta$ records which of the two it was:

\[\delta = \begin{cases} 1 & \text{if } T \le C \quad \text{(event observed)} \\ 0 & \text{if } C < T \quad \text{(censored)} \end{cases}\]

So each subject contributes a pair $(x_i, \delta_i)$:

Observed $\delta_i$ Meaning Contributes
$x_i$ $\delta_i = 1$ event happened at $x_i$ $f_\lambda(x_i)$
$x_i$ $\delta_i = 0$ censored — all we know is $T > x_i$ $S_\lambda(x_i)$

An observed event tells us the density at that exact time. A censored observation tells us only that the subject survived past $x_i$, which is precisely $S(x_i)$ — so the survival function itself carries the information.

Combining both cases into one expression:

\[L(\lambda) = \prod_{i=1}^{n} f_\lambda(x_i)^{\delta_i}\, S_\lambda(x_i)^{(1 - \delta_i)}\]

The exponents act as a switch: when $\delta_i = 1$ the term is $f_\lambda(x_i)^1 S_\lambda(x_i)^0 = f_\lambda(x_i)$, and when $\delta_i = 0$ it is $f_\lambda(x_i)^0 S_\lambda(x_i)^1 = S_\lambda(x_i)$. Anything to the power $0$ is $1$, so the unused factor drops out.

Assume independent censoring. This is the key assumption that makes the likelihood valid: why a subject was censored must carry no information about when they would have had the event. If sicker patients drop out earlier, censoring is informative, and this likelihood is biased.

Censored observations are not discarded — dropping them throws away real information and biases the estimate, since the subjects who survive longest are exactly the ones most likely to be censored.

The censored exponential likelihood

Substituting the exponential $f_\lambda(x) = \lambda e^{-\lambda x}$ and $S_\lambda(x) = e^{-\lambda x}$ into the censored likelihood:

\[\begin{aligned} L(\lambda) &= \prod_{i=1}^{n} f_\lambda(x_i)^{\delta_i}\, S_\lambda(x_i)^{1-\delta_i} \\[6pt] &= \prod_{i=1}^{n} \left( \lambda e^{-\lambda x_i} \right)^{\delta_i} \left( e^{-\lambda x_i} \right)^{1-\delta_i} \\[6pt] &= \prod_{i=1}^{n} \lambda^{\delta_i} e^{-\lambda x_i} \end{aligned}\]

The exponential factors merge regardless of $\delta_i$, since the exponents sum to one:

\[e^{-\lambda x_i \delta_i} \cdot e^{-\lambda x_i (1 - \delta_i)} = e^{-\lambda x_i (\delta_i + 1 - \delta_i)} = e^{-\lambda x_i}\]

Only the $\lambda^{\delta_i}$ factor distinguishes an event from a censored observation. Taking logs:

\[\begin{aligned} \log L(\lambda) &= \sum_{i=1}^{n} \left[ \log\!\left( \lambda^{\delta_i} \right) - \lambda x_i \right] \\[6pt] &= \sum_{i=1}^{n} \left[ \delta_i \log \lambda - \lambda x_i \right] \end{aligned}\]

using $\log(a^b) = b \log a$ in the second line.

Lecture erratum: at 45:00 the board writes $+\lambda X_i$ in the last three lines; the sign is negative, as written above.

Note how this generalizes the uncensored case: if every $\delta_i = 1$ this reduces to $\sum_i [\log\lambda - \lambda x_i]$, exactly the log-likelihood derived before.

Solve. Differentiate the censored log-likelihood and set it to zero:

\[\frac{d \log L(\lambda)}{d\lambda} = \sum_{i=1}^{n} \left[ \frac{\delta_i}{\lambda} - x_i \right] = 0\]

Rearranging:

\[\sum_{i=1}^{n} x_i = \frac{\sum_{i=1}^{n} \delta_i}{\lambda} \qquad\Longrightarrow\qquad \boxed{\;\hat{\lambda} = \frac{\sum_{i=1}^{n} \delta_i}{\sum_{i=1}^{n} x_i}\;}\]

Reading it. $\sum_i \delta_i$ counts the observed events — call it $d$ — while $\sum_i x_i$ is the total time everyone was under observation. So

\[\hat{\lambda} = \frac{\text{number of events}}{\text{total observed time}}\]

an events-per-person-time rate. Censored subjects contribute their time to the denominator but not to the numerator: they add exposure without adding an event, which is exactly the right accounting.

This also recovers the uncensored result. With no censoring every $\delta_i = 1$, so $\sum_i \delta_i = n$ and $\hat{\lambda} = n / \sum_i x_i$ — matching the earlier $\hat{\lambda} = n / \sum_i t_i$.

Non-parametric estimation

Drop the assumption that $T$ follows any particular distribution and estimate $S(t)$ straight from the data.

The empirical survival estimator

Each of the $n$ observations carries weight $1/n$. The estimator is one minus the empirical CDF:

\[\hat{S}(t) = 1 - \underbrace{\frac{1}{n} \sum_{i=1}^{n} I(x_i \le t)}_{\text{empirical CDF} \;=\; \hat{F}(t)}\]

$I(\cdot)$ is the indicator function — $1$ when the condition holds, $0$ otherwise — so the sum simply counts how many observed times are $\le t$. Dividing by $n$ turns that count into a proportion, which estimates $F(t) = P(T \le t)$ directly. No parameters, no assumed shape: $\hat{S}$ is a step function that drops by $1/n$ at each observed time.

Worked example

ID $x_i$ (days) $\delta_i$
1 32 1
2 5 0
3 200 1
4 250 0
5 181 0
6 95 1

With $n = 6$, sort the times: $5, 32, 95, 181, 200, 250$. At each one, count how many observations are $\le t$ and subtract that fraction from 1:

$t$ $\sum_i I(x_i \le t)$ $\hat{S}(t) = P(T > t)$, empirical  
$0$ $0$ $1$ $1$
$5$ $1$ $1 - \frac{1}{6} \cdot 1 = \frac{5}{6}$ $0.83$
$32$ $2$ $1 - \frac{1}{6} \cdot 2 = 1 - \frac{2}{6} = \frac{4}{6}$ $0.667$
$95$ $3$ $\frac{3}{6} = \frac{1}{2}$ $0.5$
$181$ $4$ $\frac{2}{6}$ $0.33$
$200$ $5$ $\frac{1}{6}$ $0.1667$
$250$ $6$ $0$ $0$

Between listed times $\hat{S}$ is flat — it is a step function, dropping by $1/6$ only at an observed time and holding its value until the next one.

Approaches to censored observations

Notice what the estimator above does not use: $\delta_i$ never appears in the formula. That leaves the question of what to do with the censored subjects — IDs 2, 4 and 5, who were only ever last seen event-free.

Approach 1 — treat every observation as an event. This is the table above, taken at face value. It is wrong in a predictable direction: a censoring time is recorded as though it were a death, so $\hat{S}$ steps down at times when nobody actually had the event. Survival is underestimated.

Approach 2 — delete the censored rows. Keep only $\delta_i = 1$:

ID $x_i$ (days) $\delta_i$
1 32 1
3 200 1
6 95 1

Now $n = 3$, with times $32, 95, 200$:

$t$ $\hat{S}(t)$  
$0$ $1$ $1$
$32$ $2/3$ $0.667$
$95$ $1/3$ $0.333$
$200$ $0$ $0$

This is also wrong, and in the opposite way at the tail: it throws away half the sample, and $\hat{S}(200) = 0$ claims nobody survives past 200 days — while ID 4 was alive and event-free at 250. The subjects most likely to be censored are the long survivors, so discarding them biases the estimate too.

Approach 3 — Kaplan–Meier. Neither extreme is right: a censored subject genuinely contributes information up to $x_i$ and none after it. Kaplan–Meier keeps them in the at-risk set until they are censored, then removes them without recording an event.

Kaplan–Meier: setup

Two ingredients. First, the multiplication rule, rearranged from the definition of conditional probability:

\[P(A \mid B) = \frac{P(A, B)}{P(B)} \qquad\Longrightarrow\qquad P(A, B) = P(A \mid B)\, P(B)\]

and the independent special case:

\[\text{if } A \perp B, \qquad P(A, B) = P(A)\, P(B)\]

The first form is the one that matters here — it lets a joint probability be built up as a chain of conditional ones, which is exactly how $S(t)$ will be decomposed.

Second, order the event times. Let

\[t_{(1)} < t_{(2)} < t_{(3)} < \cdots < t_{(K)}\]

be the $K$ unique event times — only times where an event actually occurred, so censoring times are not among them, and ties collapse to a single entry. $t_{(K)}$ is the final event time.

These cut the timeline into $K + 1$ mutually exclusive intervals:

\[[0, t_{(1)}) \;\cup\; [t_{(1)}, t_{(2)}) \;\cup\; \cdots \;\cup\; [t_{(K)}, \infty)\]

Each interval is half-open, so every moment $t \ge 0$ falls in exactly one — the partition is complete and non-overlapping. Within an interval nothing happens, so $S(t)$ is flat there; all the action is at the boundaries.

Putting the two together: surviving to time $t$ means surviving each interval up to $t$ in turn, and by the multiplication rule that joint probability factors into a product of conditional survival probabilities — one per interval.

Decomposing $S(t)$ into a product

Take the survival probability at the $j$-th event time. Because $T > t_{(j)}$ already implies $T > t_{(j-1)}$, and that implies $T > t_{(j-2)}$, and so on — the events are nested — adding all the earlier conditions changes nothing:

\[P(T > t_{(j)}) = P\big(T > t_{(j)},\; T > t_{(j-1)},\; \dots,\; T > t_{(1)}\big)\]

Now peel off the earliest condition with the multiplication rule $P(A,B) = P(A \mid B)P(B)$:

\[= P\big(T > t_{(j)},\; T > t_{(j-1)},\; \dots,\; T > t_{(2)} \;\big|\; T > t_{(1)}\big)\; P\big(T > t_{(1)}\big)\]

Repeating this — peeling off one condition at a time — collapses the whole thing into a product of one-step conditional survival probabilities:

\[P(T > t_{(j)}) = \prod_{k=1}^{j} P\big(T > t_{(k)} \;\big|\; T > t_{(k-1)}\big)\]

with the convention $t_{(0)} = 0$, so the first factor is just $P(T > t_{(1)} \mid T > 0) = P(T > t_{(1)})$.

Finally, rewrite each factor as a complement — surviving the interval is one minus having the event in it:

\[S\big(t_{(j)}\big) = \prod_{k=1}^{j} \Big\{ 1 - P\big(T \le t_{(k)} \;\big|\; T > t_{(k-1)}\big) \Big\}\]

Why this form is the point. Each factor asks a question answerable from the data at that moment: of those still at risk just before $t_{(k)}$, what fraction had the event? A subject censored earlier is simply absent from that at-risk set — they are not counted as an event, and they are not deleted from the intervals they did survive. That is exactly the accounting Approaches 1 and 2 got wrong.

The risk set

\[R_k = \text{risk set} = \text{the set of individuals who are at risk of the event at time } t_{(k)}\]

To be at risk at $t_{(k)}$ a subject must still be under observation and still event-free going into that time — that is, their recorded time has not yet passed:

\[R_k = \{\, i : x_i \ge t_{(k)} \,\}\]

For each $R_k$, two counts:

\[\begin{aligned} n_k &= \text{\# of individuals at risk at time } t_{(k)} \quad (= |R_k|) \\[4pt] d_k &= \text{\# of events at time } t_{(k)} \end{aligned}\]

These are the denominator and numerator each conditional factor needs: of the $n_k$ people at risk at $t_{(k)}$, the $d_k$ who had the event. Note $d_k \ge 1$ by construction — the $t_{(k)}$ are the times where an event actually occurred — and $d_k > 1$ when several subjects have the event at the same recorded time.

The risk set is what makes censoring work correctly. A subject censored at $x_i$ belongs to $R_k$ for every $t_{(k)} \le x_i$ and to none after — so they count toward the denominator for exactly the intervals they were genuinely observed through, and then quietly leave. They are never counted as an event, and never erased from the earlier intervals they contributed to.

$R_k$ shrinks monotonically as $k$ increases: subjects leave when they have the event or are censored, and none ever return.

The Kaplan–Meier estimator

Estimate each conditional event probability by the sample proportion — of the $n_k$ subjects at risk at $t_{(k)}$, the $d_k$ who had the event. But note carefully what that ratio actually conditions on: membership in the risk set is defined by the observed time $X$, not the event time $T$:

\[\frac{d_k}{n_k} = P\big(T \le t_{(k)} \;\big|\; X > t_{(k-1)}\big)\]

Since $X = \min(T, C)$, the condition $X > t_{(k-1)}$ means both $T > t_{(k-1)}$ and $C > t_{(k-1)}$ — still event-free and still under observation:

\[= P\big(T \le t_{(k)} \;\big|\; T > t_{(k-1)},\; C > t_{(k-1)}\big)\]

This is where independent censoring does its work. If $T \perp C$, then knowing $C > t_{(k-1)}$ says nothing about $T$, so that condition drops out:

\[\overset{T \perp C}{=} P\big(T \le t_{(k)} \;\big|\; T > t_{(k-1)}\big)\]

which is exactly the factor the decomposition called for. Substituting into the product gives the Kaplan–Meier (or product-limit) estimator:

\[\boxed{\;\hat{S}_{KM}(t) = \prod_{k \,:\, t_{(k)} \le t} \left[\, 1 - \frac{d_k}{n_k} \,\right]\;}\]

The product runs over every event time at or before $t$. Each factor $1 - d_k/n_k$ is the estimated probability of surviving through that event time given you reached it, and $\hat{S}$ multiplies them together.

Compare with the naive estimator, which subtracted $1/n$ with a fixed $n$ throughout. Here the denominator $n_k$ is recomputed at every step against who is actually still at risk — that is the entire fix. Censored subjects shrink $n_k$ for later steps without ever contributing to any $d_k$.

Note what the derivation above rests on: without $T \perp C$ the observed ratio $d_k/n_k$ does not estimate the conditional event probability at all, and Kaplan–Meier is biased. Independent censoring is not a technicality — it is the assumption that makes the estimator mean what it claims to mean.

Kaplan–Meier: worked example

Same six subjects. Only the $\delta_i = 1$ rows give event times — IDs 1, 3 and 6:

\[32 < 95 < 200\]

so $K = 3$, and the timeline splits into $K + 1 = 4$ intervals:

\[[0, 32) \;\cup\; [32, 95) \;\cup\; [95, 200) \;\cup\; [200, \infty)\]

At each event time, count the risk set $n_k = #{i : x_i \ge t_{(k)}}$ and the events $d_k$:

$t$ $n_k$ $d_k$ $1 - \dfrac{d_k}{n_k}$ $\hat{S}_{KM}(t)$
$0$ $6$ $0$ $1 - 0/6 = 1$ $1$
$32$ $5$ $1$ $1 - 1/5 = 4/5$ $1 \cdot \frac{4}{5} = 0.8$
$95$ $4$ $1$ $1 - 1/4 = 3/4$ $1 \cdot \frac{4}{5} \cdot \frac{3}{4} = 0.6$
$200$ $2$ $1$ $1 - 1/2 = 1/2$ $1 \cdot \frac{4}{5} \cdot \frac{3}{4} \cdot \frac{1}{2} = 0.3$

$\hat{S}_{KM}$ is the running product of the column to its left — each row carries forward everything before it and multiplies in one new factor.

Lecture erratum: at 26:00 the table header reads $1 - n_k/d_k$; it should be $1 - \dfrac{d_k}{n_k}$, as computed in the column itself.

Trace the denominators — they are where the censored subjects show up. All six are at risk at $t=0$. By $t=32$, ID 2 has already been censored at day 5, so $n = 5$. By $t=200$, IDs 1 and 6 have had the event and ID 5 was censored at 181, leaving only IDs 3 and 4: $n = 2$. Each censored subject silently shrinks a later denominator without ever adding to a $d_k$.

As a step function, $\hat{S}_{KM}$ holds each value until the next event time: $1$ on $[0,32)$, $0.8$ on $[32,95)$, $0.6$ on $[95,200)$, and $0.3$ from $200$ onward.

1.0 0.8 0.6 0.3 0.0 32 95 200 250 Time (days) Ŝ (t)

The vertical ticks on the curve mark the censored observations — days 5, 181 and

  1. They sit on the curve without causing a drop: a censoring event removes someone from the risk set but never steps $\hat{S}$ down. The curve ends at day 250 rather than falling to zero, because that last observation is censored.

Compare the three approaches at $t = 200$:

Approach $\hat{S}(200)$
1 — count censoring as events $0.167$
2 — delete censored rows $0$
3 — Kaplan–Meier $0.3$

Both naive estimators are pulled too low, and Approach 2 claims certain death by day 200 despite ID 4 being event-free at 250. Kaplan–Meier stays at $0.3$ and — note — never reaches zero: the largest observation (250) is censored, so the curve simply stops rather than dropping to $0$. With no observed event after 200, the data cannot say survival is zero, and $\hat{S}_{KM}$ does not pretend otherwise.

Kaplan–Meier: second example (with a tie)

ID $x_i$ (days) $\delta_i$
1 145 0
2 140 1
3 199 1
4 199 1
5 10 1
6 95 0

The $\delta_i = 1$ rows are IDs 2, 3, 4 and 5 — but IDs 3 and 4 share the time 199, and unique event times collapse ties. So $K = 3$:

\[10 < 140 < 199\] \[[0, 10) \;\cup\; [10, 140) \;\cup\; [140, 199) \;\cup\; [199, \infty)\]
$t$ $n_k$ $d_k$ $1 - \dfrac{d_k}{n_k}$ $\hat{S}_{KM}(t)$
$0$ $6$ $0$ $1 - 0/6 = 1$ $1$
$10$ $6$ $1$ $1 - 1/6 = 5/6$ $1 \cdot \frac{5}{6} = 0.833$
$140$ $4$ $1$ $1 - 1/4 = 3/4$ $1 \cdot \frac{5}{6} \cdot \frac{3}{4} = 0.625$
$199$ $2$ $2$ $1 - 2/2 = 0$ $1 \cdot \frac{5}{6} \cdot \frac{3}{4} \cdot 0 = 0$

The tie. At $t = 199$ two subjects have the event at once, so $d_3 = 2$ — the first time in these notes that $d_k > 1$. The factor is $1 - \frac{2}{2} = 0$: everyone still at risk had the event, so the estimated probability of surviving through 199 is zero, and $\hat{S}_{KM}$ drops to $0$ and stays there.

The denominators. All six are at risk at $t = 10$. By $t = 140$, ID 5 has had the event at 10 and ID 6 was censored at 95, leaving $n = 4$. By $t = 199$, ID 2 has had the event at 140 and ID 1 was censored at 145, leaving just IDs 3 and 4: $n = 2$.

1.0 0.833 0.625 0.0 10 140 199 Time (days) Ŝ (t)

Contrast with the first example, where the curve stopped at $0.3$ because the longest observation was censored. Here the largest time is an event time that empties the risk set, so the curve reaches $0$ — the data does support saying nobody survived past 199.