Section 4.8

Survival Analysis & Kaplan–Meier

Sometimes the outcome is a when, not a number. Time until a patient relapses, a customer churns, a part fails, a participant drops out of a habit study. This is time-to-event ("survival") data, and it breaks ordinary tools for one stubborn reason: when the study ends, some events simply haven't happened yet. Those unfinished clocks are called censored observations, and handling them honestly is the entire point of survival analysis.

Why you can't just average the times

Suppose half your patients were still relapse-free when the study closed at 36 months. What's their "time to relapse"? You only know it's more than what you observed. Averaging observed times treats those unfinished clocks as if they'd rung, dragging the estimate down. Throwing censored cases away is even worse: you'd be deleting precisely the longest survivors. Either shortcut biases the result; censoring must be modeled, not ignored.

The Kaplan–Meier idea: survive one step at a time

The Kaplan–Meier estimator rebuilds the survival curve S(t), the probability of lasting beyond time t, from a chain of small, honest questions. At each observed event time: of the people still at risk right now, what fraction got through it? Multiply those step-by-step survival fractions together and you get the familiar staircase curve. Censored people count while they're observed and simply leave the "at risk" pool afterward — no guessing about their futures required.

🎮 Kaplan–Meier Playground

Two groups (say, treatment vs control), exponential event times over 36 months. Tick marks are censored subjects. Raise the hazard ratio to separate the curves, add censoring to see the estimator cope, and watch the log-rank test keep score.

Median survival A
Median survival B
Log-rank χ² (1 df)
p-value
Censored

Push the censoring slider up and a median may stop reporting a number, showing "> 36 mo" instead. Nothing has broken. If the curve never falls to 0.5 inside the follow-up window, the median survival has not happened yet, and papers write it as not reached. Inventing a number there, or extending the curve past your last observation to find one, is how a short study starts making long claims. When the median is out of reach, report survival at a fixed landmark instead, such as the 24-month rate with its confidence interval.

Comparing groups: the log-rank test

To test whether two survival curves differ, the log-rank test walks through every event time and asks: given how many people each group had at risk, how many of this moment's events "should" have landed in group A? Summing observed-minus-expected events across all times gives a χ² statistic with 1 degree of freedom, the survival-world sibling of the chi-square test. It weights every event equally and is most powerful when one group's hazard is a constant multiple of the other's (proportional hazards).

Beyond the curve

Kaplan–Meier describes and the log-rank test compares, but neither adjusts for covariates. That's the job of Cox proportional-hazards regression, which models the hazard ratio as a function of predictors, the survival cousin of the GLMs you've already met. The hazard-ratio slider in the playground is exactly the quantity a Cox model estimates.

When the hazards aren't proportional

The log-rank test and the Cox model lean on the same assumption: whatever the hazard ratio is, it holds steady across follow-up. A treatment that helps early and wears off later breaks it, and so does anything whose curves cross. The log-rank test is least forgiving of all, because an early advantage and a late disadvantage cancel inside its running sum.

There are three ways to check, in rising order of formality. The first is to look: crossing or converging curves are the visible symptom. The second is to plot log(−log S(t)) against log t for each group, where proportional hazards show up as parallel curves separated by a constant vertical gap of exactly log HR. The third is to test the Schoenfeld residuals, which record at every event time how far the person who had the event sat from the average of everyone still at risk. Under proportional hazards those residuals have no trend against time; R's cox.zph() turns that into a χ² per covariate plus a global test, and a small p-value is evidence against the assumption rather than for it.

The repair depends on which variable broke it. Stratify the Cox model on the offending variable and it gets a baseline hazard of its own while everything else keeps a single ratio. Let its coefficient change with time. Split the follow-up into periods and report a hazard ratio for each. Or leave hazard ratios behind and compare restricted mean survival time, the average event-free time up to a fixed horizon, which means the same thing whether or not the curves stay proportional.

Why it matters: whenever the outcome is "time until something happens," some clocks will still be running when you stop watching. Kaplan–Meier and the log-rank test extract every drop of information from finished and unfinished observations alike: no guessing, no discarding. For a study of your own, Plan My Analysis collects the assumptions to check and explains why survival power is counted in events rather than participants.

Ten patients, four of them censored, and a curve you can build with a calculator: Problem 36 in the practice problems walks the whole Kaplan–Meier table and shows what the two obvious averages get wrong.

Common questions

What is censoring in survival analysis?

A censored observation is an unfinished clock: the event hadn't happened when you stopped observing (study ended, participant moved away), so you know survival exceeded some time, but not by how much. It's information, not garbage: censored subjects rightly count in the at-risk pool while observed. Standard methods assume censoring is uninformative; dropping out mustn't be related to imminent risk.

What does a hazard ratio mean?

The instantaneous event-rate multiplier between groups: HR = 2 means at any moment, the exposed group's event rate is double the reference group's. It is not "twice as likely to die overall" nor "half the survival time." HR < 1 is protective; and a proportional-hazards model assumes this ratio is constant over follow-up — worth checking, not assuming.

How many participants does a survival study need?

Count events, not people. Power here is carried by how many participants actually reach the event, so a big sample watched briefly can be weaker than a small one followed properly. The standard planning formula asks for about 4(zα/2 + zβ)² ÷ (ln HR)² events in total: detecting a hazard ratio of 2 at α = .05 with 80% power takes roughly 65 to 70 events, and a hazard ratio of 1.5 takes nearly 200. Sample size is what you work out afterwards, from the event rate you expect and the follow-up you can afford. A Cox model adds a constraint of its own, around ten events for every covariate you want to adjust for.