Kaplan-Meier and Cox for a First Event: KM Describes, Cox Models

On this page
อ่านฉบับภาษาไทย (Thai version)
Abstract
First-event survival analysis asks how long it takes until the first occurrence of an event. Examples are a first recurrence, a first admission and death; later repetitions are ignored for that analysis. Two tools share the work. Kaplan-Meier describes: it estimates the survival function S(t), the probability of remaining event-free beyond time t. It is used to plot survival curves, estimate survival probabilities, estimate the median survival when it is reached and compare groups visually. The Cox model models: it estimates the relative hazard between groups while allowing adjustment for covariates. An output such as HR = 0.70 means a lower estimated hazard in one group, subject to the model assumptions. The critical one is proportional hazards, a roughly constant hazard ratio over time. Three traps follow: a hazard ratio is not a risk ratio, Kaplan-Meier adjusts for nothing, and the median may not be reached. This article teaches one rule: first event, Kaplan-Meier describes, Cox models.
A trial report with a curve and a ratio
A cardiologist reads a heart-failure trial report. The outcome is the time from randomisation to death from any cause. One figure shows a Kaplan-Meier curve for each arm, one line gives a Cox hazard ratio of 0.70, and a colleague sums it up as 30% fewer deaths.
The trial is fictional. Before trusting either number, she asks two plain questions: what question does the analysis answer, and what does each of the two tools add?
One clock per patient, stopped at the first event
Each patient contributes one time: from a starting point, such as randomisation, to the first event. A patient admitted three times counts only the time to the first admission; the second and third admissions play no part in this analysis. Part 6 of the series counts every admission instead.
Typical first-event outcomes are:
- time to first recurrence
- time to death
- time to first admission
- time to first myocardial infarction
- time to treatment failure
A patient whose follow-up ends before any event is censored: known to be event-free up to that time and unobserved after it. Both tools below use these censored times rather than discarding them. Part 1 shows how a first-event question differs from the other kinds of time-to-event question.
Kaplan-Meier describes: the survival function
Let $T$ be the time to the first event. Kaplan-Meier estimates the survival function
$$S(t) = P(T > t)$$read as the probability of remaining event-free beyond time $t$. It estimates this from follow-up that ends early for some patients, with no model for the shape of the curve [1].
Kaplan-Meier is primarily descriptive. It is useful for:
- plotting survival curves
- estimating survival probabilities
- estimating median survival, when it is reached
- comparing groups visually
The four uses on ten patients
Ten patients with heart failure are followed from randomisation for up to 24 months, and the event is death from any cause. Five die, at months 6, 10, 14, 18 and 20. One is lost to follow-up at month 8, and four are still alive when follow-up closes at month 24.
At each death time $t_j$, the curve is multiplied by the share of the at-risk set, everyone still event-free and under follow-up just before $t_j$, who survive it:
$$\hat S(t) = \prod_{t_j \le t} \left(1 - \frac{d_j}{n_j}\right)$$Here $n_j$ is the number at risk and $d_j$ the number of deaths at $t_j$. A censored patient leaves the at-risk set without making the curve step down.
| Month | At risk ($n_j$) | Deaths ($d_j$) | Censored | Factor ($1 - d_j/n_j$) | Survival ($\hat S$) |
|---|---|---|---|---|---|
| 6 | 10 | 1 | 0 | 0.9 | 0.9 |
| 8 | 9 | 0 | 1 (lost) | no step | 0.9 |
| 10 | 8 | 1 | 0 | 0.875 | 0.7875 |
| 14 | 7 | 1 | 0 | 0.857 | 0.675 |
| 18 | 6 | 1 | 0 | 0.833 | 0.5625 |
| 20 | 5 | 1 | 0 | 0.8 | 0.45 |
| 24 | 4 | 0 | 4 (follow-up closes) | no step | 0.45 |
Reading the four uses off the curve
Plotting the curve. The survival column, drawn as steps, is the Kaplan-Meier curve: flat between deaths and one step down at each death.
Survival probabilities. The estimate at a given month is the last step at or before it: 0.7875 at month 12 and 0.45 at month 24.
Median survival, when reached. The median survival is the first time the curve reaches one half or below. Five of the ten patients die, the curve falls from 0.5625 to 0.45 at month 20, and the median survival is 20 months.
Comparing groups visually. With one curve per group drawn on the same axes, the eye compares the groups. The next section does this for the two arms of a simulated trial.
Comparing two arms: a simulated trial
The same descriptive reading scales up. A simulated trial enrolled 1,500 adults after a heart-failure admission, 750 per arm. It followed them from randomisation to death from any cause for 24 to 36 months, and 825 died.
Kaplan-Meier survival at 12 months was 0.688 in the control arm and 0.743 in the treatment arm. At 24 months it was 0.473 and 0.569. Both curves fell to one half within follow-up, so both medians were reached: 22.6 months in the control arm and 28.3 months in the treatment arm.
These numbers describe how each arm fared. Randomisation makes the arms comparable on average, yet the curves themselves adjust for nothing: they are one estimate per arm, not a model.
R: Kaplan-Meier survival at 12 and 24 months
# ---------------------------------------------------------------- all-cause death: Kaplan-Meier
# time origin = randomisation; censoring = end of study or loss to follow-up
km <- survfit(Surv(fu_months, death) ~ arm, data = w3)
s <- summary(km, times = c(12, 24))
print(s)
> km <- survfit(Surv(fu_months, death) ~ arm, data = w3)
> s <- summary(km, times = c(12, 24))
> print(s)
Call: survfit(formula = Surv(fu_months, death) ~ arm, data = w3)
arm=0
time n.risk n.event survival std.err lower 95% CI upper 95% CI
12 498 230 0.688 0.0171 0.656 0.722
24 332 153 0.473 0.0186 0.438 0.511
arm=1
time n.risk n.event survival std.err lower 95% CI upper 95% CI
12 542 190 0.743 0.0161 0.713 0.776
24 400 125 0.569 0.0184 0.534 0.606
summary(km, times = c(12, 24)) prints, for each arm and month, the number at risk, the deaths since the previous listed month, the survival estimate and its 95% confidence interval. An excerpt of the simulation script: the lines that run this analysis, with the run's output beside them; w3 is the simulated trial, read in earlier in the script. The simulated trial file itself is not published.Cox models: the relative hazard
The hazard is the event rate at time $t$ among patients still event-free: a rate per unit of time, not a probability of having had the event. The hazard ratio (HR) divides one group's hazard by another's.
The Cox model estimates the relative hazard between groups while allowing adjustment for covariates [2]. Covariates added to the model, such as age or the severity of heart failure, are adjusted for, so an adjusted hazard ratio comes from a Cox model and not from Kaplan-Meier curves. The model leaves the shape of the hazard over time unspecified.
Typical output:
$$HR = 0.70$$This means the estimated hazard is lower in one group relative to another, subject to the model assumptions.
The same trial, summarised by the model
In the simulated trial, stcox arm gives an HR of 0.78 for treatment versus control, with a 95% confidence interval (CI) of 0.68 to 0.90. The estimated hazard of death is lower in the treatment arm than in the control arm, subject to the model assumptions.
On the same data the two tools did different jobs. Kaplan-Meier described each arm with a curve, survival at stated months and a median; Cox summarised the comparison in one ratio that could also carry covariates. That one ratio rests on an assumption, which the next section turns to.
Stata: the Cox model for all-cause death
* ---------------------------------------------------------------- all-cause death: Cox model
* hazard ratio for treatment versus control (Breslow ties; there are no tied times)
stcox arm
. * ---------------------------------------------------------------- all-cause death: Cox model
. * hazard ratio for treatment versus control (Breslow ties; there are no tied times)
. stcox arm
Failure _d: death==1
Analysis time _t: fu_months
Iteration 0: Log likelihood = -5648.1152
Iteration 1: Log likelihood = -5641.8514
Iteration 2: Log likelihood = -5641.8514
Refining estimates:
Iteration 0: Log likelihood = -5641.8514
Cox regression with no ties
No. of subjects = 1,500 Number of obs = 1,500
No. of failures = 825
Time at risk = 29,562.8078
LR chi2(1) = 12.53
Log likelihood = -5641.8514 Prob > chi2 = 0.0004
------------------------------------------------------------------------------
_t | Haz. ratio Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
arm | .7812631 .0545882 -3.53 0.000 .681275 .8959261
------------------------------------------------------------------------------
stcox arm reports the HR for treatment versus control with its 95% CI, from 1,500 patients and 825 deaths; "no ties" means that no two deaths share a time. An excerpt of the simulation script: the lines that run this analysis, with the run's output beside them. The model uses the survival-time setup declared earlier in the script, stset fu_months, failure(death == 1). The simulated trial file itself is not published.The critical assumption: proportional hazards
The ordinary Cox model assumes that the hazard ratio is approximately constant over time. One HR then describes the whole follow-up.
If the survival curves suggest that the treatment effect
- changes magnitude greatly over time,
- crosses over, or
- reverses direction,
then a single constant HR may be misleading [3, 4]. When the ratio does change, the one number a Cox model returns is a weighted average of the changing ratio, with weights set by when events happen and how long patients are followed [4].
A trial whose effect reverses
A variant of the simulated trial is built so that the treatment HR for death is 0.60 in months 0 to 12 and 1.10 afterwards: the effect reverses direction at one year. A single Cox model fitted to this variant returns 0.84 (95% CI 0.74 to 0.96). That number describes neither period: it is too high for the first year and too low for the time after it.
Stata: one hazard ratio for the variant trial
* one hazard ratio averaged over follow-up, then the PH check
stcox arm
. * one hazard ratio averaged over follow-up, then the PH check
. stcox arm
Failure _d: death==1
Analysis time _t: fu_months
ID variable: id
Iteration 0: Log likelihood = -5860.3193
Iteration 1: Log likelihood = -5857.1468
Iteration 2: Log likelihood = -5857.1468
Refining estimates:
Iteration 0: Log likelihood = -5857.1468
Cox regression with no ties
No. of subjects = 1,500 Number of obs = 1,500
No. of failures = 861
Time at risk = 29,758.7835
LR chi2(1) = 6.35
Log likelihood = -5857.1468 Prob > chi2 = 0.0118
------------------------------------------------------------------------------
_t | Haz. ratio Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
arm | .8421581 .0574503 -2.52 0.012 .7367606 .9626332
------------------------------------------------------------------------------
stcox arm returns one HR for the whole follow-up, 0.84 with a 95% CI of 0.74 to 0.96.What to use when the ratio changes
Possible alternatives include:
- Time-varying effects. The HR is allowed to differ between periods of follow-up. Splitting the variant's follow-up at month 12 gives 0.62 (95% CI 0.51 to 0.77) for months 0 to 12 and 1.07 (95% CI 0.89 to 1.28) after month 12, close to the 0.60 and 1.10 built into the simulation; the cut point is fixed before seeing the data.
- Flexible survival models. The hazard over time is modelled as a smooth curve, so the treatment effect can also change smoothly with time instead of being forced to one constant.
- Restricted mean survival time (RMST) at a prespecified horizon. The area under the survival curve up to a horizon $\tau$ chosen in advance is the mean event-free time within that window [5]. In the variant, up to 24 months, it is estimated at 16.9 months in the control arm and 18.7 months in the treatment arm; Part 3 works through it.
Stata: one hazard ratio per period for the variant trial
* split follow-up at 12 months and give each period its own treatment hazard ratio
stsplit late, at(12)
generate byte arm_0_12 = arm * (late == 0)
generate byte arm_12plus = arm * (late == 12)
stcox arm_0_12 arm_12plus
. * split follow-up at 12 months and give each period its own treatment hazard ratio
. stsplit late, at(12)
(1,075 observations (episodes) created)
. generate byte arm_0_12 = arm * (late == 0)
. generate byte arm_12plus = arm * (late == 12)
. stcox arm_0_12 arm_12plus
Failure _d: death==1
Analysis time _t: fu_months
ID variable: id
Iteration 0: Log likelihood = -5860.3193
Iteration 1: Log likelihood = -5849.6257
Iteration 2: Log likelihood = -5849.6247
Refining estimates:
Iteration 0: Log likelihood = -5849.6247
Cox regression with no ties
No. of subjects = 1,500 Number of obs = 2,575
No. of failures = 861
Time at risk = 29,758.7835
LR chi2(2) = 21.39
Log likelihood = -5849.6247 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
_t | Haz. ratio Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
arm_0_12 | .6245692 .0650446 -4.52 0.000 .5092532 .7659976
arm_12plus | 1.067557 .0982992 0.71 0.478 .8912784 1.278699
------------------------------------------------------------------------------
stsplit cuts each patient's follow-up at month 12, and stcox with one treatment term per period gives an HR of 0.62 (95% CI 0.51 to 0.77) for months 0 to 12 and 1.07 (95% CI 0.89 to 1.28) after month 12.Three traps
-
Trap 1: an HR is not a risk ratio (HR ≠ RR)
An HR of 0.70 does not mean that the event probability is exactly 30% lower at every follow-up time. The HR compares event rates among patients still event-free; the share who have had the event by a given time is read from the survival curves. In the simulated trial one HR of 0.78 sits behind survival of 0.688 against 0.743 at month 12 and 0.473 against 0.569 at month 24.
Fix: Read the absolute difference at a stated time from the survival curves and report it beside the HR.
-
Trap 2: Kaplan-Meier is not multivariable adjustment
Kaplan-Meier curves are descriptive and unadjusted unless additional modelling is performed. In a randomised trial that is usually acceptable; in an observational cohort, curves split by exposure carry any confounding.
Fix: Use a Cox model, or adjusted curves built from a model, when the question needs adjustment, and label plain Kaplan-Meier curves as unadjusted.
-
Trap 3: median survival is not always estimable
If fewer than 50% experience the event, the median survival may not be reached. In the ten-patient example five of ten die and the median is 20 months; had the deaths at months 18 and 20 been losses to follow-up instead, only three of ten would have died, the curve would stay at 0.675, and the median would not be reached.
Fix: Report survival at a stated time, such as month 12 or 24, or RMST, together with the length of follow-up, instead of a median that was not reached.
From a report's wording to the method
| When a report says | Think of |
|---|---|
| first recurrence | first-event survival |
| time to death | survival analysis |
| Kaplan-Meier curve | survival function |
| adjusted hazard ratio | Cox regression |
| proportional hazards violated | do not rely blindly on one Cox HR |
| effect changes direction over time | time-varying effect / RMST |
Glossary
- first-event survival analysis
- Analysis of the time until the first occurrence of an event; later repetitions are ignored.
- censoring (การเซ็นเซอร์ (censoring))
- Follow-up that ends before the event, so the patient is known to be event-free only up to that time.
- survival function (ฟังก์ชันการรอดชีพปลอดเหตุการณ์)
- S(t) = P(T > t), the probability of remaining event-free beyond time t.
- Kaplan-Meier estimator (ตัวประมาณ Kaplan-Meier)
- A descriptive estimate of the survival function built as a product of the share surviving each event time; it steps down at each event and allows for censoring.
- at-risk set
- The patients still event-free and under follow-up just before a given time.
- median survival
- The first time the survival curve reaches one half or below; it is not reached if the curve never gets there within follow-up.
- hazard (ฮาซาร์ด (hazard))
- The event rate at a given time among patients still event-free; a rate, not a probability.
- hazard ratio (อัตราส่วนฮาซาร์ด (hazard ratio, HR))
- The ratio of the hazards in two groups, which is not a ratio of risks.
- Cox proportional hazards model (แบบจำลอง Cox (Cox proportional hazards model))
- A regression model for the hazard that estimates the relative hazard between groups, allows adjustment for covariates and leaves the shape of the hazard over time unspecified.
- proportional hazards assumption (ข้อสมมติฮาซาร์ดเป็นสัดส่วน (proportional hazards))
- The assumption that the hazard ratio stays approximately constant over follow-up.
- time-varying effect
- A treatment effect allowed to change over follow-up, for example one hazard ratio per period.
- restricted mean survival time (ระยะเวลารอดชีพเฉลี่ยแบบจำกัดช่วง (RMST))
- The area under the survival curve up to a prespecified horizon: the mean event-free time within that window.
References
- Kaplan EL, Meier P. Nonparametric estimation from incomplete observations. J Am Stat Assoc. 1958;53(282):457-481. doi:10.1080/01621459.1958.10501452 https://doi.org/10.1080/01621459.1958.10501452
- Cox DR. Regression models and life-tables. J R Stat Soc Series B Stat Methodol. 1972;34(2):187-202. doi:10.1111/j.2517-6161.1972.tb00899.x https://doi.org/10.1111/j.2517-6161.1972.tb00899.x
- Hernán MA. The hazards of hazard ratios. Epidemiology. 2010;21(1):13-15. doi:10.1097/EDE.0b013e3181c1ea43 https://doi.org/10.1097/EDE.0b013e3181c1ea43
- Stensrud MJ, Hernán MA. Why test for proportional hazards? JAMA. 2020;323(14):1401-1402. doi:10.1001/jama.2020.1267 https://doi.org/10.1001/jama.2020.1267
- Royston P, Parmar MKB. Restricted mean survival time: an alternative to the hazard ratio for the design and analysis of randomized trials with a time-to-event outcome. BMC Med Res Methodol. 2013;13:152. doi:10.1186/1471-2288-13-152 https://doi.org/10.1186/1471-2288-13-152
Key takeaways
- First-event survival analysis asks how long it takes until the first occurrence of an event; later repetitions are ignored for that analysis.
- Kaplan-Meier estimates S(t) = P(T > t), the probability of remaining event-free beyond time t; it is primarily descriptive and adjusts for nothing, and if fewer than 50% have the event its median may not be reached.
- The Cox model estimates the relative hazard between groups while allowing adjustment for covariates; an HR of 0.70 means a lower estimated hazard in one group, not an event probability exactly 30% lower at every time.
- The ordinary Cox model assumes a roughly constant hazard ratio; when the curves show an effect that changes magnitude greatly, crosses over or reverses direction, consider time-varying effects, flexible survival models or RMST at a prespecified horizon.
- First event → KM describes; Cox models.
Related in the wiki: [[time-to-event-survival-analysis]]