← SciSim / Statistics
Survival Analysis — Kaplan-Meier & Hazard
📊 Tier: Standard Undergraduate
§1 Interactive Simulation — Kaplan-Meier Estimator
n subjects
50
Events
Censored
Median survival
S(t) at query t
Censoring rate
Hazard model
n subjects 50
Censoring rate % 30
Query time t 1.5
Scale (mean survival) 2.0
§2 The Idea, Step by Step

Imagine you plant 50 tomato seedlings and check every week to see which have sprouted. Some sprout early, some late — and a few you give to a neighbor before they sprout, so you never find out when (or if) they would have. Survival analysis is the math of "how long until something happens" when you can't always wait around to watch it happen.

The quantity we track is the survival function $S(t)$ — the fraction of subjects that have not had the event yet by time $t$. It starts at $S(0)=1$ (everyone is still waiting) and steps down a little each time an event happens. The clever part is the seedlings you gave away: these are censored observations. They count as still-at-risk right up until you lose track of them, then they quietly leave the pool without being recorded as an event. The Kaplan-Meier estimate multiplies the survival odds across each event time:

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

If 50 people are at risk and 3 have the event, the curve drops by a factor $1-3/50=0.94$ — so $S$ falls from $1.00$ to $0.94$. Multiply such factors together as you march along in time.

Each factor is just the conditional probability of surviving one event time given you reached it; chaining them with the product gives cumulative survival. The companion view is the hazard $h(t)=-\frac{d}{dt}\log S(t)$ — the instantaneous risk rate at time $t$. A flat hazard (Exponential) is memoryless: a brand-new part fails as readily as an old one. A rising hazard (Weibull, $k>1$) is wear-and-tear; a falling hazard ($k<1$) is early "infant mortality." The sliders map straight onto these ideas: Scale sets the typical survival time, Censoring rate controls how many subjects leave before their event, and n subjects sets the sample size (bigger $n$ = smoother, more trustworthy steps).

Try this in the sim above: (1) push Censoring rate to 80% and watch the curve turn jagged and stop well above zero — that is exactly why the median, not the mean, is the honest summary. (2) Switch the Hazard model to "Weibull increasing" and open the Hazard tab — the cumulative-hazard line now bends upward instead of staying straight. (3) Open the Log-Rank tab to watch two groups pull apart; that separation is the picture behind the test for "did the treatment help?"

§3 Mathematical Derivation

Kaplan-Meier Estimator — Kaplan & Meier, 1958

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

$d_i=$ deaths at time $t_i$, $n_i=$ risk set at $t_i$. Censored observations contribute to $n_i$ before censoring time.

tn at riskevents dcensoredS(t)
0.550311-(3/50)=0.940
1.046400.940×(1-4/46)=0.858
1.542230.858×(1-2/42)=0.817
HAZARD FUNCTION

$h(t)=\lim_{\Delta t\to0}\frac{P(t\le T<t+\Delta t\mid T\ge t)}{\Delta t}=-\frac{d}{dt}\log S(t)$. Exponential: $h(t)=\lambda$ (constant — memoryless). Weibull: $h(t)\propto t^{k-1}$ (increasing if $k>1$, decreasing if $k<1$). Cumulative hazard: $H(t)=-\log S(t)$.

LOG-RANK TEST

Two-group test: $H_0: S_1(t)=S_2(t)$. Statistic: $\chi^2=\left(\sum_i(d_{1i}-e_{1i})\right)^2/\text{Var}\sim\chi^2_1$ where $e_{1i}=n_{1i}d_i/n_i$ is expected deaths in group 1. Large $\chi^2$ → groups differ.

Kleinbaum & Klein — Survival Analysis, Springer
Collett — Modelling Survival Data in Medical Research, CRC Press
§4 FAQ
§5 Misconceptions & Common Errors
❌ Misconception 1

"Censored observations should be excluded from survival analysis."
NEVER exclude censored observations — they contain valuable information! A censored observation (subject lost to follow-up or study ended) tells us they survived AT LEAST until censoring time. The K-M estimator properly handles censoring by including censored subjects in the risk set up to their censoring time, then removing them.
📖 Kleinbaum & Klein — Survival Analysis, Ch. 2

❌ Error 1

Using the mean survival time when the curve doesn't reach 0
✅ If the K-M curve doesn't reach 0 (many censored), the mean is undefined or unreliable. Use MEDIAN survival time (time when S(t)=0.5) instead — it's always estimable when at least 50% of subjects had events.
🔍 Reporting mean survival when 40% of subjects are censored at end of study.

❌ Error 2

Comparing survival curves with t-test or standard regression
✅ Survival times are non-normal, right-skewed, and have censoring — t-tests are inappropriate. Use Log-Rank test for comparing two K-M curves. Use Cox proportional hazards for adjusting for covariates. Never regress survival time on covariates without accounting for censoring.
🔍 t-testing survival times from two groups, ignoring censored observations.

Kleinbaum & Klein — Survival Analysis, Springer
Collett — Modelling Survival Data, CRC Press