How do I analyze survival data?

Kaplan–Meier curves, the log-rank test, Cox regression, and what censoring means

TL;DR

Use survival analysis for time-to-event data. How long until death, relapse, tumor onset, etc. especially when some subjects don't experience the event by the end of the study. Plot Kaplan–Meier curves, compare groups with the log-rank test, and use Cox proportional-hazards regression to estimate hazard ratios and adjust for covariates.

Why time-to-event needs its own toolkit

Two features break ordinary tests:

  • The outcome is a duration, and these times are usually skewed (not normal), so a t-test on "average survival time" is inappropriate.
  • Censoring: many subjects are still alive (or event-free) when the study ends, or drop out. You don't know their final event time, only that it's longer than their last observation. Survival methods use this partial information correctly instead of discarding it or pretending the study end is the event time.

Censoring is the whole point of survival analysis: subjects still event-free at study end carry real information. Don't drop them, and don't treat the study end as if it were the event.

Kaplan–Meier curves

The Kaplan–Meier estimator turns event times and censoring into a step-function curve showing the probability of remaining event-free over time. Censored subjects appear as tick marks. From the curve you can read median survival (the time at which the curve crosses 50%). Two groups' curves plotted together give an immediate visual comparison.

Each step down is a death; the tick marks are censored subjects. Toggle censoring on and off and hover any step to read the survival probability:

0.00.250.50.751.0survival S(t)0306090120days
TreatedControl

Each step down is a death; the curve stays flat between events. Tick marks are censored subjects (lost or still alive). They leave the at-risk pool without an event, which is exactly what an ordinary mean of survival times can't handle. Hover any step for S(t).

Comparing groups: the log-rank test

The log-rank test asks whether two or more KM curves differ overall. It's the standard significance test for comparing survival between groups (e.g., treated vs. control). It gives a p-value but not an effect size. For that you need Cox regression.

Cox proportional-hazards regression

Cox regression models the hazard (instantaneous event rate) and returns a hazard ratio (HR):

  • HR > 1: higher event rate (worse survival) in that group/per unit of predictor.
  • HR < 1: protective.
  • HR = 1: no difference.

Cox handles multiple covariates (adjust for age, sex, stage) and continuous predictors. Its key assumption is proportional hazards. The HR is roughly constant over time. Check this (e.g., Schoenfeld residuals); if curves cross, the assumption is violated and you need an alternative.

A biology example

You track tumor-free survival in two mouse cohorts over 120 days. Some mice are tumor-free at day 120 (right-censored). Plot KM curves, compare with the log-rank test (say p = 0.01), and fit a Cox model adjusting for starting weight, reporting HR = 0.45 (95% CI 0.24–0.83): the treated cohort had roughly half the hazard. Curves plus HR plus CI is the complete story.

Common mistakes

  • Ignoring censoring (e.g., running a t-test on survival times or excluding survivors entirely). This biases everything.
  • Miscoding the event indicator (swapping event/censored).
  • Reporting log-rank p without a hazard ratio.
  • Using Cox when hazards aren't proportional (crossing curves) without checking.
  • Comparing many subgroups without correcting for multiplicity.

Correlation and regression · Effect size and confidence intervals · Multiple comparisons

Ready to run this analysis on your own data?