Survival analysis for prognostic studies
Kaplan-Meier curves, log-rank tests and Cox regression: an introduction for medical students, with the prognosis module for jamovi
A patient with a new cancer diagnosis asks two questions: will I be cured? and how long do I have? The second one is about time. Prognostic studies follow patients from a starting point (diagnosis, surgery, randomisation) until an event (death, relapse, graft failure) and try to answer it: how likely is the event by one year, by five years, and for which patients is it more likely?
The data from such studies have a peculiarity that breaks the methods you already know: when the study ends, many patients have not had the event yet. We know they survived at least this long, but not how long they will survive. Survival analysis is the set of methods that handles this correctly. This tutorial introduces the three tools you will meet in almost every clinical paper with a time-to-event outcome:
- the Kaplan-Meier estimator, which draws the survival curve and gives median survival and survival at fixed times;
- the log-rank test and its relatives, which compare survival curves between groups;
- Cox regression, which estimates hazard ratios, adjusts them for other variables, and comes with assumptions you should check.
It assumes you know what a p-value, a 95% confidence interval and a 2×2 table are. Each method has a short theory page, then a worked example that you can repeat step by step in jamovi, a free point-and-click statistics program, with the prognosis module. Its menu has the same two entries as this tutorial: Prognosis → Kaplan-Meier and Prognosis → Cox Regression.
What you need
- jamovi (desktop, from jamovi.org).
- The prognosis module. Download the
.jmofile for your jamovi from the releases page; the module README says which of the four files to pick. In jamovi, click Modules (the ⊕ icon, top right) → Sideload and choose the file. A new Prognosis menu appears in the Analyses tab. - The teaching dataset: lung.omv (open it with File → Open). A plain lung.csv is also available; if you use it, read the tip below.
The dataset used throughout
All the examples use one dataset: patients with advanced non-small-cell lung cancer followed in a study of the North Central Cancer Treatment Group, which looked at which features predict survival (Loprinzi et al. 1994). It ships with the R package survival as lung. We keep the 226 patients whose performance status was rated 0, 1 or 2 by their physician (only one patient had ECOG 3).
| Variable | Type in jamovi | Meaning |
|---|---|---|
time |
continuous | months from enrolment to death or to the last contact |
event |
nominal: alive, dead |
status at the last contact; dead means the event was observed |
sex |
nominal: Male, Female |
|
age |
continuous | age in years |
ecog |
ordinal: ECOG 0, ECOG 1, ECOG 2 |
ECOG performance status (Oken et al. 1982): 0 = fully active; 1 = symptoms, but walks and does light work; 2 = up and about more than half of the day, cannot work |
163 of the 226 patients died during follow-up. The median age was 63 years and 40% were women.
jamovi sorts text levels alphabetically when it imports a CSV, so sex gets the levels Female, Male, and ecog is imported as nominal. The analyses use the first level as the reference, so your hazard ratios would compare men with women instead of women with men. To match this tutorial, open the Data tab, select sex, click Setup and move Male to the top of the levels list; set the measure type of ecog to Ordinal. The .omv file already has both.
How to use this tutorial
Read the four Foundations pages first. They explain the ideas behind each method with small examples you could compute by hand. Then open jamovi and work through the worked examples: each one says what to put in each box of the analysis panel, shows the output the module gives, and explains how to read it and how to write it up. Reporting collects what a paper should say, and the glossary defines every term.
Every table and plot in the worked examples is produced by running the prognosis analyses themselves on the teaching dataset, so they are exactly what you will see in jamovi. The folded jamovi syntax blocks show the equivalent R call; jamovi shows the same text above the results when you switch on Syntax mode (in the ⋮ menu, top right).
Notation
| Symbol | Meaning |
|---|---|
| \(T\) | the time until the event for a patient (unknown until it happens) |
| \(t_i\), \(\delta_i\) | the observed time of patient \(i\) and whether it ended with the event (\(\delta_i = 1\)) or with censoring (\(\delta_i = 0\)) |
| \(S(t)\) | survival function: the probability of being event-free at time \(t\), \(P(T > t)\) |
| \(h(t)\) | hazard: the rate of the event at time \(t\) among those still event-free |
| \(H(t)\) | cumulative hazard, the hazard added up from 0 to \(t\); \(S(t) = e^{-H(t)}\) |
| \(n_j\), \(d_j\) | number at risk and number of events at the \(j\)-th event time |
| HR | hazard ratio |
Map of the module
| You want to … | In jamovi | Theory | Example |
|---|---|---|---|
| estimate survival, median survival, survival at 1 or 2 years | Kaplan-Meier: tables | Kaplan-Meier | KM example |
| compare survival between groups | Kaplan-Meier: Tests | Log-rank | KM example |
| draw survival curves with the number at risk | Kaplan-Meier: Plots | Kaplan-Meier | KM example |
| estimate hazard ratios, crude and adjusted | Cox Regression | Cox model | Cox example |
| check that the hazard ratios are constant over time | Cox: Proportional hazards test, Schoenfeld residuals; KM: Log-log plot | Cox model | Assumptions |
| ask whether the effect of one variable depends on another | Cox: Interactions | Cox model | Interactions |
| draw survival curves adjusted for other variables | Cox: Adjusted survival curves | Cox model | Adjusted curves |
Further reading
For a short, readable introduction aimed at clinicians, see the series Survival analysis in the British Journal of Cancer (Clark et al. 2003; Bradburn et al. 2003a, 2003b) and the BMJ statistics notes on the Kaplan-Meier method and the log-rank test (Bland and Altman 1998, 2004). The standard textbook on the Cox model is Therneau and Grambsch (2000).