PUBH-311 · Lesson 11 of 12 · 22 min

Survival analysis basics

▶ Video coming soon A video version of this lesson is on the way.

The text-message cessation trial from Lesson 6 had a follow-up study. The service wanted to know not just whether people had quit at six months, but how long they stayed smoke-free. Jonah began by calculating the proportion of quitters who had relapsed by two years. Then he hit a problem. Some participants had moved away after five months, some had joined only a year ago and had not yet been followed for two years, and a few had withdrawn. If he dropped them, he would throw away useful information and probably bias his estimate. If he counted them as non-relapsers, he would pretend to know something he did not. Dr. Osei handed him a paper from 1958 by Edward Kaplan and Paul Meier. “This,” she said, “is what survival analysis was invented for.”

Survival analysis, also called time-to-event analysis, studies how long it takes for an event to happen. The name comes from studies of death, but the event can be anything that happens once (or a first time): relapse to smoking, hospital readmission, diagnosis of a disease, discharge from hospital or return to work. This lesson introduces censoring, the survival and hazard functions, the Kaplan-Meier estimator, the log-rank test, hazard ratios and the Cox proportional hazards model.

Time-to-event data and censoring

Time-to-event data record, for each person, a time and whether the event occurred by that time. The time is measured from a defined starting point (enrollment, diagnosis, treatment, birth) until the event or the end of observation. What makes these data special is censoring: for some people we know only that the event had not happened by a certain time.

Right censoring, the most common type, occurs when follow-up ends before the event: the study closes, the person moves away or withdraws, or they die of something else (depending on the question). We know their event time is longer than their observed time, but not by how much. A censored observation still contains information: a person followed for 20 months without relapse tells us they did not relapse in each of those 20 months.

Two simple approaches to censored data are both wrong. Excluding censored people discards information and, because those with longer follow-up are more likely to be censored before the event, tends to make outcomes look worse. Treating censored people as event-free for the whole period assumes outcomes we did not observe and makes them look better. Survival methods use each person’s information for exactly as long as they were observed.

Standard methods assume non-informative censoring: people who are censored have the same future risk of the event as those who remain under observation at the same time. If people drop out of a cessation study because they have started smoking again and are embarrassed to report it, censoring is informative and estimates of staying smoke-free will be too optimistic. The assumption cannot be fully tested and should be discussed in any report.

Survival and hazard functions

The survival function, \(S(t)\), is the probability that a person remains event-free beyond time \(t\). It starts at 1 at time zero and declines (or stays level) over time. In the cessation study, \(S(12)\) is the probability of remaining smoke-free for more than 12 months.

The hazard function, \(h(t)\), is the instantaneous rate at which events occur at time \(t\) among people who are still event-free just before \(t\). It is a rate, not a probability, and describes how risk changes over time. Relapse after quitting smoking has a hazard that is very high in the first weeks and falls over time; the hazard of death for adults rises with age; the hazard of infection after surgery peaks in the first days. The survival function and hazard function carry the same information in different forms: a high hazard means a steeply falling survival curve.

The median survival time is the time at which \(S(t)\) falls to 0.5, the point by which half the group has had the event. Because time-to-event data are usually right-skewed and censored, the median is a better summary than the mean, which often cannot even be estimated.

The Kaplan-Meier estimator

The Kaplan-Meier estimator, also called the product-limit estimator, estimates the survival function from censored data. Its logic is simple. At each time an event occurs, calculate the conditional probability of surviving that time among those still at risk, then multiply these probabilities together:

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

where \(d_i\) is the number of events at time \(t_i\) and \(n_i\) is the number at risk just before \(t_i\), meaning people who have neither had the event nor been censored. Censored people contribute to the number at risk up to their censoring time and then leave the calculation. The resulting curve is a step function that drops at each event time and stays flat between them.

Worked problem

A Kaplan-Meier calculation by hand

Ten recent quitters receiving usual care (Group A) were followed for up to 24 months. Times to relapse in months, with + marking censored observations, were: 3, 5+, 6, 8, 8+, 11, 14+, 17, 20+, 24+. Estimate the survival function and the median time to relapse.

Show solution
  1. Order the times. At 3 months, 10 are at risk and 1 relapses: \(S = 1 \times (1 - 1/10) = 0.900\).
  2. At 5 months one person is censored; S does not change, but the number at risk falls to 8.
  3. At 6 months, 8 at risk, 1 relapse: \(S = 0.900 \times 7/8 = 0.788\).
  4. At 8 months, 7 at risk, 1 relapse (the person censored at 8 months is counted as at risk, because by convention censoring is assumed to occur just after events at the same time): \(S = 0.788 \times 6/7 = 0.675\). Then one is censored, leaving 5.
  5. At 11 months, 5 at risk, 1 relapse: \(S = 0.675 \times 4/5 = 0.540\). One censored at 14 months leaves 3.
  6. At 17 months, 3 at risk, 1 relapse: \(S = 0.540 \times 2/3 = 0.360\). The remaining two are censored at 20 and 24 months.
  7. Median: S first falls to 0.5 or below at 17 months.

Answer: Estimated probability of remaining smoke-free is 0.90 at 3 months, 0.54 at 12 months and 0.36 at 24 months; median time to relapse is 17 months. Simply counting relapses (5 of 10) would have ignored the five censored people.

Table 1. Kaplan-Meier calculation for Group A (invented data).
Time (months)At riskRelapsesCensoredConditional survivalKaplan-Meier S(t)
310109/100.900
590110.900
68107/80.788
87116/70.675
115104/50.540
1440110.540
173102/30.360
2020110.360
2410110.360
Kaplan-Meier step curves for two groups over 25 months. Group A, usual care, drops in steps from 1.0 to 0.90, 0.79, 0.68, 0.54 and 0.36, crossing 0.5 at 17 months. Group B, the new program, drops more slowly to 0.90, 0.79 and 0.66. Small vertical tick marks show censored observations.
Figure 1. Kaplan-Meier curves for time to relapse in two groups of ten quitters (invented data). Tick marks show censoring.

Kaplan-Meier curves should be presented with the number at risk shown beneath the time axis at regular intervals, because estimates at later times rest on fewer people and are less reliable. Confidence intervals, usually from Greenwood’s formula, can be drawn around the curve; they widen as the number at risk falls. A long flat tail with only one or two people at risk should not be over-interpreted.

Comparing groups: the log-rank test

To compare survival curves between groups, the most widely used method is the log-rank test, developed from work by Nathan Mantel and others in the 1960s. At each event time, it compares the number of events observed in each group with the number expected if both groups had the same hazard, given how many people in each group were at risk at that moment. These observed-minus-expected differences are summed over all event times, and the resulting statistic is compared with a chi-square distribution with 1 degree of freedom (for two groups) or \(g - 1\) degrees of freedom for \(g\) groups.

For the two groups in Figure 1, Group A had 5 relapses where 3.1 were expected under the null hypothesis, and Group B had 3 where 4.9 were expected. The log-rank statistic is 1.96 with 1 df, p = 0.16. Despite the visibly different curves, ten people per group cannot show convincingly that the program delays relapse. A real trial would need far more participants, or a longer follow-up generating more events. In survival analysis, power depends mainly on the number of events, not the number of participants.

The log-rank test gives equal weight to events at all times and is most powerful when one group’s hazard is a constant multiple of the other’s. If curves cross, it can miss real differences, and alternatives that weight early or late events differently, such as the Wilcoxon (Breslow) test, may be considered.

Hazard ratios

The hazard ratio (HR) compares the hazard in one group with that in another. An HR of 2 means that, at any given time, people in the first group who are still event-free are experiencing the event at twice the rate of those in the second group. An HR of 0.6 means a 40 percent lower hazard. For the small example, a rough estimate is the ratio of observed to expected events in each group: \((5/3.1)/(3/4.9) = 2.6\), meaning usual care was associated with about 2.6 times the hazard of relapse compared with the program, though with very wide uncertainty. The hazard ratio is the standard effect measure in trials with time-to-event outcomes, such as cancer and cardiovascular trials.

A hazard ratio is not the same as a risk ratio. It compares instantaneous rates throughout follow-up, while a risk ratio compares cumulative proportions at one time point. When events are rare they are similar; when many events occur they can differ considerably.

The Cox proportional hazards model

Just as logistic regression extends the odds ratio to several predictors, the Cox proportional hazards model, introduced by the British statistician David Cox in 1972, extends the hazard ratio. It models the hazard for a person with predictors \(x_1, \dots, x_k\) as

\[h(t) = h_0(t) \, e^{\beta_1 x_1 + \beta_2 x_2 + \dots + \beta_k x_k}\]

where \(h_0(t)\) is the baseline hazard, the hazard for a person with all predictors equal to zero. The model’s great strength is that it does not require any assumption about the shape of the baseline hazard, which can rise, fall or fluctuate over time; only the effect of the predictors is modeled. For this reason it is called semi-parametric. Cox’s paper is among the most cited in all of statistics.

As in logistic regression, coefficients are exponentiated: \(e^{\beta_j}\) is the hazard ratio for a one-unit increase in \(x_j\), holding the other predictors constant. Table 2 shows illustrative output from a larger cessation follow-up study.

Table 2. Cox model for time to relapse among 420 quitters (invented results; 196 relapses).
PredictorCoefficient (β)Hazard ratio (e^β)95 percent CIp-value
Text-message program (vs usual care)−0.480.620.45 to 0.850.003
Cigarettes per day before quitting (per 10)0.261.301.08 to 1.560.005
Lives with a smoker (vs not)0.411.511.10 to 2.070.011
Age (per 10 years)−0.110.900.79 to 1.020.10

Reading Table 2: among people of the same smoking history, household and age, those in the text-message program had a 38 percent lower hazard of relapse at any time during follow-up (HR 0.62, 95 percent CI 0.45 to 0.85). Each additional 10 cigarettes per day before quitting was associated with a 30 percent higher hazard, and living with a smoker with a 51 percent higher hazard. The age association was compatible with no effect.

The proportional hazards assumption

The Cox model assumes that hazard ratios are constant over time: whatever the baseline hazard does, the ratio between groups stays the same. This is the proportional hazards assumption. On a Kaplan-Meier plot, curves that cross suggest it may be violated. It is checked formally with tests based on Schoenfeld residuals or by plotting log-log survival curves, which should be roughly parallel. If a predictor’s effect changes over time (for example, a surgical treatment that carries early risk but later benefit), the model can include time-varying effects or the follow-up can be split into periods.

Other ideas worth knowing

Person-time rates. A simple summary of censored data is the event rate per person-time: the number of events divided by the total time at risk, such as 12 relapses per 100 person-years. Principles of Epidemiology introduced incidence rates of this kind; they assume a constant hazard, which survival methods relax. Poisson regression models such rates with several predictors.

Life tables. Actuarial life tables, which group time into intervals, predate the Kaplan-Meier method and are still used for large populations. National statistical agencies use period life tables to calculate life expectancy.

Competing risks. Sometimes another event prevents the event of interest from occurring. In a study of time to hip fracture among older adults, death from other causes is a competing risk. Treating deaths as censored assumes the dead would have had the same fracture risk as survivors, which is not meaningful, and the Kaplan-Meier method then overestimates the probability of fracture. Methods based on the cumulative incidence function, such as the Fine-Gray model, are used instead.

Time origin and immortal time. Choosing the starting point matters. In studies of treatments that begin some time after a diagnosis, counting people as treated from diagnosis gives them a period of "immortal time" during which they could not have died and still received treatment, biasing results in favor of treatment. Careful definition of time zero avoids this.

Back to the cessation service

Jonah’s final report presented Kaplan-Meier curves for the program and usual care groups with numbers at risk, the median time to relapse in each group and the hazard ratio from a Cox model adjusted for baseline smoking and household smoking. He noted that 14 percent of participants were lost to follow-up and that if those people had relapsed more often than others, the program’s benefit could be overstated. The service added a brief check-in call at three months, the period when the hazard of relapse was highest.

Common mistakes

  • MistakeExcluding censored participants or counting them as event-free.

    InsteadUse survival methods, which include each person for exactly the time they were observed.

  • MistakeReporting the mean survival time from censored data.

    InsteadReport the median survival time and survival probabilities at specific times.

  • MistakeOver-interpreting the far right of a Kaplan-Meier curve.

    InsteadShow the number at risk and confidence intervals; late estimates rest on few people.

  • MistakeInterpreting a hazard ratio as a ratio of cumulative risks.

    InsteadA hazard ratio compares instantaneous event rates over follow-up; it approximates a risk ratio only when events are rare.

  • MistakeFitting a Cox model without checking proportional hazards.

    InsteadInspect curves and Schoenfeld residuals; model time-varying effects if needed.

Summary and key terms

  • Survival analysis studies time to an event and handles right-censored observations, assuming censoring is non-informative.
  • The survival function S(t) is the probability of remaining event-free beyond t; the hazard h(t) is the instantaneous event rate among those still at risk.
  • The Kaplan-Meier estimator multiplies conditional survival probabilities at each event time; report the median and numbers at risk.
  • The log-rank test compares survival curves using observed and expected events; power depends on the number of events.
  • The hazard ratio compares hazards between groups; it is not the same as a risk ratio.
  • The Cox proportional hazards model estimates adjusted hazard ratios without specifying the baseline hazard, assuming proportional hazards.
  • Person-time rates, life tables, competing risks and correct choice of time zero are related ideas in time-to-event analysis.
Censoring
Incomplete observation of an event time, usually because follow-up ends before the event.
Survival function
The probability of remaining event-free beyond a given time.
Hazard
The instantaneous rate of the event at a given time among those still at risk.
Kaplan-Meier estimator
A method of estimating the survival function from censored data by multiplying conditional survival probabilities.
Number at risk
The number of people still under observation and event-free just before a given time.
Median survival time
The time at which the estimated survival probability falls to 0.5.
Log-rank test
A test comparing survival curves between groups.
Hazard ratio
The ratio of hazards in two groups.
Cox proportional hazards model
A regression model for time-to-event data that estimates hazard ratios without specifying the baseline hazard.
Competing risk
An event that prevents the event of interest from occurring.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Five patients were followed after discharge for readmission (days): 10, 15+, 20, 30+, 40. Calculate the Kaplan-Meier estimate at each event time.

    Show answer

    Day 10: 5 at risk, S = 4/5 = 0.80. Day 20: 3 at risk, S = 0.80 × 2/3 = 0.533. Day 40: 1 at risk, S = 0.533 × 0/1 = 0.

  2. A Cox model gives a coefficient of 0.69 for diabetes in a study of time to heart failure. Interpret it.

    Show answer

    HR = e^0.69 ≈ 2.0: people with diabetes have about twice the hazard of heart failure at any time, compared with people without diabetes who have the same values of the other predictors.

  3. In a dementia study of adults over 85, many participants die before developing dementia. Why is the standard Kaplan-Meier estimate of dementia risk problematic?

    Show answer

    Death is a competing risk. Treating deaths as censored assumes the dead would have had the same dementia risk as survivors, which overestimates the cumulative incidence; competing-risks methods should be used.

  4. Two Kaplan-Meier curves cross at 12 months. What assumption may be violated, and why does it matter?

    Show answer

    The proportional hazards assumption; a single hazard ratio would misrepresent effects that differ over time, and the log-rank test may lose power.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz