Statistics tutorial · Chapter 09

Survival analysis

42 min read · 4 sections

This chapter deals with time-to-event data: the delay between an origin (enrollment, randomization, diagnosis, transplant) and an event (death, relapse, recovery, failure of an implant...). It first presents the nature of these data and censoring, then the two Variance analyses: Survival Curves (Kaplan-Meier), which estimates the survival curves of one or several groups and compares them, and Cox Proportional Hazards Regression, which estimates the effect of several variables at once on the risk of the event. General notions (confidence interval, P value, multiple comparisons) are covered in chapter 10; the choice of an analysis, in chapter 11.

The word "survival" comes from demography, but the event is not necessarily a death. This chapter says "death" or "event" interchangeably.

Survival data#

Survival times and censoring#

For each subject, you record the time elapsed since the origin and what happened at that time: either the event (code 1**), or the end of observation without the event (code **0: the subject is censored). A subject is censored when still alive at the end of follow-up, when lost to follow-up, or when leaving the study for a reason unrelated to the event. The true survival time is unknown: all you know is that it exceeds the observed time. This is right censoring, the only kind Variance handles.

Censoring rules out the usual methods. Excluding censored subjects, counting them as deaths, or averaging the observed times underestimates survival, since the true time of a censored subject is longer than the one recorded. Survival methods use each subject for as long as it is observed, then remove it from the subjects "at risk" without counting it as an event.

Decide before data collection: the origin (the same for everyone, and dated unambiguously: randomization rather than first symptom), the event (precise criteria, identical in all groups), the time unit and the date the follow-up ends.

Assumptions about censoring#

  • Noninformative (independent) censoring: a subject censored at time t has the same later risk as the subjects of its group who remain under follow-up. This is the central assumption of this chapter, and the data do not allow you to test it. It is reasonable for administrative censoring (end of the study). It is doubtful when a patient leaves the study because their condition worsens (survival is then overestimated) or because they feel better (it is underestimated). Checks: record the cause of each censoring; compare the proportion of censored subjects between groups ("Data summary" tab) and their distribution over time (censoring ticks on the graph). A group that is much more censored than the other, or dropouts among the most severe subjects, should raise concern.
  • No effect of entry date: subjects enrolled at the beginning and at the end of recruitment have the same prognosis (no change in practice in the meantime).
  • Exactly known times: if the event is only noted at visits (relapse discovered at a check-up), the recorded time is that of the visit; Variance does not handle such "interval-censored" data.
  • Competing risks: if another event prevents the one under study (death from another cause when studying relapse), censoring it amounts to describing a world in which that other event would not exist, and 1 − S(t) then overestimates the proportion of subjects who will have the event. Variance does not offer a cumulative incidence estimator suited to this case.

Entering the data#

The Kaplan-Meier analysis uses a Survival table (chapter 03): one row per subject; in the X column, its time, a number expressed in the unit chosen when the table was created ("Enter elapsed time as a number of" days, weeks, months or years); in the column of its group, 1** if the event occurred at that time, **0 if it is censored; the columns of the other groups stay empty. Any value other than 1 or 0 stops the analysis ("survival codes must be 1 (event) or 0 (censored)"), as does a negative time ("survival times cannot be negative"); a row without a time or without a code is ignored. The times can also be entered as start and end dates (chapter 03): Variance then computes each duration, in the unit chosen, and refuses an end date before the start date ("survival times cannot be negative (row …: end date before the start date)").

The Cox model uses a Multivariable table: one row per subject, one column for the time, one for the event (1 or 0) and one per covariate (age, sex, stage...).

To follow the examples: "Start" window, Survival type, "an example", example "Survival of two groups" (24 patients, 12 per treatment, "Standard" and "New treatment", times in days). For the Cox model: Multivariable type, example "Clinical study (continuous, categorical and outcome variables)", whose Time and Event variables give the survival of 40 subjects.


Survival Curves (Kaplan-Meier)#

This analysis estimates, for each group, the survival curve S(t), the probability of not having had the event at time t, by the Kaplan-Meier method (the "product-limit" estimator), with the median survival and its confidence interval. With two or more groups, it compares the curves (Mantel-Cox log-rank test, Gehan-Breslow-Wilcoxon test, log-rank test for trend from three groups, optional pairwise comparisons) and, with two groups, estimates the hazard ratio. It also counts the subjects at risk over time and produces two output tables: the survival curves and the "log minus log" plot that helps check the proportional hazards assumption.

When to use it#

  • Describe the survival of one group: proportion of subjects without the event over time, median survival.
  • Compare the survival of two or more groups defined from the origin of time: randomly assigned treatment, genotype, stage at diagnosis.
  • Look for a trend across ordered groups (increasing doses, stages): log-rank test for trend.
  • To account for other variables (confounders, prognostic factors), or for a continuous variable, use the Cox model (next section).

Assumptions and checks#

  • Noninformative censoring, no effect of entry date, exact times: see "Survival data".
  • Independent subjects, counted only once, with their first event only: a Survival table does not handle repeated events in the same subject.
  • Groups defined at the origin. Classifying subjects according to what happens to them afterwards ("responders" versus "nonresponders" to treatment) artificially favors the group defined later: to be counted among the responders, a subject must have lived until the response (immortal time bias).
  • Proportional hazards, for the log-rank test and the hazard ratio. The log-rank test is the most powerful when the ratio of the groups' instantaneous risks stays constant over time; otherwise it remains valid but loses power, especially if the curves cross, and a single hazard ratio no longer summarizes the difference. Checks: the curves do not cross; in the output table "Log-minus-log plot: ln(-ln S)", the curves of ln(−ln S) against ln t are roughly parallel (see Calculations); the Cox model with the group as a covariate gives a formal test ("Proportional hazards" tab).
  • Enough events: precision depends on the number of events, not on the number of subjects.

Step by step in Variance#

  1. Enter a Survival table (see "Entering the data") or open the example "Survival of two groups".
  2. Choose Analysis › Survival › Survival Curves (Kaplan-Meier), or the Analyze button of the ribbon and then the analysis in the "Choose an Analysis" window.
  3. The "Survival Curves (Kaplan-Meier) – settings" window opens. Input tab:
    • "Plot": "Survival probability" (S(t), descending curve; default) or "Probability of the event" (1 − S(t), ascending curve);
    • "Show results as percentages" (checked): survival as a percentage (0 to 100) rather than a fraction (0 to 1), in the output table and on the graph;
    • "Error bars / bands": "None" (default), "Standard error" (band S ± SE) or "Confidence interval" (log-log interval, see Calculations) around the curves: the analysis adds these bands, as gray steps in the color of each group, to the graphs of the data table. Independently of the analysis, the graph type "Survival staircase with error bars" shows S ± SE bars at each event time on its own.
  4. Multiple comparisons tab (three or more groups):
    • "Compare each pair of curves" (unchecked): one log-rank test for each pair of groups;
    • "Correction for multiple comparisons": "Bonferroni" (default), "Holm-Šídák", "Hochberg (step-up)", "FDR, two-stage method (BKY)" or "None".
  5. Number at risk tab: "Number at risk at times" receives the times at which to count the subjects at risk, separated by commas or semicolons (decimals are then written with a point). When empty (default), Variance takes 0, then the multiples of a "round" step (10, 20, 25, 50...) close to one fifth of the largest time, up to that largest time.
  6. Options tab: "Confidence level (%)" (95 by default; it sets the CI of the median, those of the hazard ratios and the confidence band), "Significance level (alpha)" (0.05; threshold of the "Survival curves differ significantly at α = …" row), "Significant digits" and "P value format".
  7. Data sets tab: check the groups to analyze, then click OK. Variance creates the results sheet and adds the analysis curves to the graphs of the data table (it creates one if there is none): a step at each event time, a small vertical tick at each censoring time, and the requested bands.

Calculations#

Kaplan-Meier curve. The distinct times t1 < t2 < ... at which at least one event occurs are taken in order. At each tj:

nj = number of subjects at risk just before tj (subjects whose time is ≥ tj)
dj = number of events at time tj
S(t) = Π (1 − dj / nj)        product over all tj ≤ t

S(t) equals 1 before the first event and changes only at event times: it is a step function. A subject censored at time tj counts among the nj (censoring is assumed to follow the events of the same instant), then leaves the subjects at risk. A censoring therefore never makes the curve drop: it reduces the denominator of the following steps, which become taller.

Greenwood standard error.

SE[S(t)] = S(t) · √v(t)        with   v(t) = Σ dj / (nj · (nj − dj))   (sum over tj ≤ t)

When all the subjects still at risk have the event (nj = dj), S drops to 0; the term, infinite, is omitted and SE equals 0.

Confidence interval of S(t), log-log transformation. Variance builds the interval on the scale of ln(−ln S), then goes back to the scale of S (method of Kalbfleisch and Prentice). The resulting interval is asymmetric and always stays between 0 and 1:

SE_LL = √v(t) / |ln S(t)|
lower limit = S(t) ^ exp(+z · SE_LL)
upper limit = S(t) ^ exp(−z · SE_LL)
z = quantile of order (1 + C)/2 of the normal distribution (1.96 for C = 95%)

For S = 1 (before the first event) and for S = 0, the interval reduces to the point S. The "Standard error" band is simply S ± SE, clamped between 0 and 1.

Median survival and its interval. The median is the first event time at which S(t) ≤ 0.5 ("Undefined" if the curve never drops to 50%). If the curve stays exactly at 0.5 over a plateau, Variance takes the start of the plateau (other software takes the midpoint). The confidence interval is obtained by reading where the log-log confidence band crosses 50%, following the principle of Brookmeyer and Crowley:

lower limit = first event time at which the lower limit of S(t) is ≤ 0.5
upper limit = first event time at which the upper limit of S(t) is ≤ 0.5

If the upper limit of the band never drops to 0.5, the upper limit of the interval does not exist and is displayed as "???"; if even the lower limit does not reach it, the cell stays empty.

Log-rank test (Mantel-Cox). At each distinct time tj at which at least one event occurs (all groups pooled), the events observed in each group are compared with those expected if the risk were the same in all groups:

nij, dij = subjects at risk and events of group i at time tj
nj = Σi nij        dj = Σi dij
Eij = dj · nij / nj                         (expected events)
Oi = Σj dij        Ei = Σj Eij
Vii' = Σj [dj (nj − dj) / (nj − 1)] · (nij / nj) · (δii' − ni'j / nj)
       (δii' = 1 if i = i', 0 otherwise; term is zero when nj = 1)
χ² = (O − E)ᵀ V⁻¹ (O − E)    over the first k − 1 groups      df = k' − 1

With two groups, this reduces to:

χ² = (O1 − E1)² / V11      with   V11 = Σj [dj (nj − dj) / (nj − 1)] · n1j · n2j / nj²

k' is the number of groups with expected events: a group whose subjects are all censored before the first event brings no information. V is then singular and V⁻¹ is its pseudo-inverse (the same rule as R's survdiff). The factor (nj − dj)/(nj − 1) accounts for simultaneous events (hypergeometric variance). Without any event, k' = 0: the df shown is 0 and the test is not computed. The P value comes from the χ² distribution with k' − 1 df: it is an approximation, accurate when events are not too rare, not an exact P value. The test applies to the entire curves and gives the same weight to each event, whether early or late.

Gehan-Breslow-Wilcoxon test. Same computation, but each time is weighted by the total number of subjects at risk wj = nj: the statistic uses Σj nj (dij − Eij) and the variance Σj nj² × (the Vii' term at time tj). The early times, when many subjects are still at risk, weigh more: the test is more sensitive to early differences, less to late ones, and depends on the pattern of censoring. When hazards are proportional, the log-rank test is more powerful.

Log-rank test for trend (three or more groups). The groups receive the scores s = 1, 2, ..., k in the order of their columns in the table:

U = Σi si (Oi − Ei)        Var(U) = Σi Σi' si si' Vii'
χ² trend = U² / Var(U)       1 df

This test makes sense only if the order of the groups is meaningful (doses, stages); equally spaced scores assume regular gaps between successive groups.

Pairwise comparisons. With "Compare each pair of curves" and at least three groups, Variance runs a log-rank test for each of the k(k − 1)/2 pairs, using only the data of the two groups concerned, then adjusts the P values by the chosen correction: Bonferroni, Holm-Šídák, the two-stage procedure of Benjamini, Krieger and Yekutieli (false discovery rate control) or none (chapter 10, "Multiple comparisons").

Hazard ratio (exactly two groups). Group 1 is the first data set analyzed, group 2 the second; the ratio compares the instantaneous risk of group 1 with that of group 2. Variance gives two estimates, with Wald intervals on the logarithmic scale:

"Mantel-Haenszel":  L = (O1 − E1) / V11          HR = e^L
                    CI = exp( L ± z / √V11 )
"Log-rank":         HR = (O1 / E1) / (O2 / E2)
                    SE(ln HR) = √(1/E1 + 1/E2)
                    CI = exp( ln HR ± z · SE(ln HR) )

The first formula, also called the "O − E over V" or Peto estimator, is (in the absence of ties) the first step of the Newton-Raphson algorithm of the one-covariate Cox model (group 1 versus group 2) started from β = 0: it approximates the Cox estimate well as long as the hazard ratio is not too far from 1. The second is the classic approximation by the ratio of the O/E values. The two coincide when the effect is small and diverge when it is strong; the Cox model gives the maximum likelihood estimate.

Subjects at risk. The number of subjects at risk at time t is the number of subjects whose time (event or censoring) is ≥ t.

Output tables. The first, named "Percent survival" (or "Fraction survival", "Percent death", "Fraction death" depending on the options), has in X the time 0 and every event or censoring time of all groups, and one column per group with S(t) (or 1 − S(t)) at that time. The second, "Log-minus-log plot: ln(-ln S)", has in X ln t and, for each group, ln(−ln S(t)) at its own times (empty cells when S equals 0 or 1). Under the proportional hazards assumption, S1(t) = S2(t)^HR, so ln(−ln S1) = ln HR + ln(−ln S2): the two curves are parallel, at a vertical distance ln HR.

Reading the results#

  • "Curve comparison" tab (two or more groups): under "Log-rank (Mantel-Cox) test", "Chi square", "df", "P value", "Significance code" and "Survival curves differ significantly at α = 0.05" ("Yes" if P < alpha); then "Log-rank test for trend" (three or more groups) and "Gehan-Breslow-Wilcoxon test". The P value is the probability of observing a gap at least as large between observed and expected events if the population survival curves were identical. A small P says that the curves differ, not where or by how much; a large P does not establish that the survivals are equal (look at the hazard ratio interval instead).
  • "Median survival" tab: "Median" and "95% CI" for each group. "Undefined" means that the curve did not drop to 50%: the median is not reached.
  • "Observed vs expected events" tab: "Observed", "Expected" and "O/E" of the log-rank test for each group. O/E > 1: more events than if all groups had the same risk.
  • "Hazard ratio" tab (two groups): rows "Mantel-Haenszel: A / B" and "Log-rank: A / B" (A and B: the titles of the data sets), columns "Ratio" and "95% CI". A hazard ratio of 2 means that at any time, among the subjects still at risk, the instantaneous risk of the event is twice as high in group A. It is neither the ratio of the medians nor that of the proportions of survivors. For the inverse ratio (B / A), take 1/HR and invert the limits.
  • "Pairwise comparisons" tab: a header row "Log-rank tests," followed by the correction ("Bonferroni-Dunn", "Holm-Šídák", "Hochberg", "Two-stage FDR of Benjamini, Krieger and Yekutieli" or "no correction"), then one row per pair "A vs. B": "P value" (unadjusted), "Adjusted P" and "Summary" (stars of the adjusted P).
  • "Data summary" tab: "Number of subjects", "Deaths or events", "Number censored" for each group.
  • "Number at risk" tab: one row per time, one column per group.

Variance does not display a table of S(t) with its standard error and interval at each time: S(t) is read in the output table "Percent survival"; the standard error and the interval are used for the bands and for the interval of the median. The table "Log-minus-log plot: ln(-ln S)" is plotted with Plot These Results from its tab (⊞).

The last tab, "Narrative results", states in sentences the comparison of the curves (log-rank test, and test for trend from three groups on), the median survival of each group with its confidence interval ("undefined" when more than half of the subjects survive to the end) and, for two groups, the hazard ratio.

Worked example#

"Survival of two groups" data (times in days; "+" marks a censoring):

Standard        7, 10, 12, 14, 23+, 26, 26, 26+, 30, 33, 42, 46
New treatment   11, 21, 21+, 29, 31, 49, 55, 55, 67+, 74, 79, 101

With the default options, Variance displays (successive tabs):

Log-rank (Mantel-Cox) test
Chi square                                          7.447
df                                                  1
P value                                             0.0064
Significance code                                   **
Survival curves differ significantly at α = 0.05   Yes
Gehan-Breslow-Wilcoxon test
Chi square                                          4.895
df                                                  1
P value                                             0.0269
Significance code                                   *

Median survival          Median    95% CI
Standard                 26        10 to 42
New treatment            55        21 to 79

Observed vs expected     Observed  Expected  O/E
Standard                 10        5.216     1.917
New treatment            10        14.78     0.6764

Hazard ratio                                  Ratio   95% CI
Mantel-Haenszel: Standard / New treatment     4.743   1.551 to 14.51
Log-rank: Standard / New treatment            2.834   1.045 to 7.69

Number at risk           0    20   40   60   80   100
Standard                 12   8    2    0    0    0
New treatment            12   11   7    4    1    1

The "Data summary" tab shows 12 subjects, 10 deaths and 2 censored in each group.

Curve of the Standard group, by hand (95% CI, z = 1.96):

DaynjdjCensoredS(t)v(t)SE95% log-log CI
712100.91670.007580.07980.5390 to 0.9878
1011100.83330.016670.10760.4817 to 0.9555
1210100.75000.027780.12500.4084 to 0.9117
149100.66670.041670.13610.3370 to 0.8597
238010.66670.041670.13610.3370 to 0.8597
267210.47620.098810.14970.1823 to 0.7237
304100.35710.182140.15240.0983 to 0.6332
333100.23810.348810.14060.0402 to 0.5270
422100.11900.848810.10970.0069 to 0.4021
461100-0-

Detail of the day 26 row (the subject censored that day still counts among the 7 subjects at risk):

S(26)  = 0.6667 × (1 − 2/7) = 0.4762
v(26)  = 0.04167 + 2 / (7 × 5) = 0.09881
SE     = 0.4762 × √0.09881 = 0.4762 × 0.3143 = 0.1497
SE_LL  = 0.3143 / |ln 0.4762| = 0.3143 / 0.7419 = 0.4237      exp(1.96 × 0.4237) = 2.294
CI     = 0.4762^2.294 to 0.4762^(1/2.294) = 0.1823 to 0.7237

Median: S(14) = 0.6667 > 0.5 and S(26) = 0.4762 ≤ 0.5, so the median is 26 days. The lower limit of the band drops below 0.5 as early as day 10 (0.4817) and the upper limit at day 42 (0.4021): 95% CI from 10 to 42 days. For New treatment, the same computation gives 55 days (CI 21 to 79).

Log-rank test, by hand (group 1 = Standard, group 2 = New treatment; Vj = dj (nj − dj)/(nj − 1) · n1j n2j / nj²):

Dayn1n2d1d2E1Vj
71212100.50000.2500
101112100.47830.2495
111012010.45450.2479
121011100.47620.2494
14911100.45000.2475
21811010.42110.2438
2679200.87500.4594
2949010.30770.2130
3048100.33330.2222
3138010.27270.1983
3337100.30000.2100
4227100.22220.1728
4617100.12500.1094
Total1045.21603.0733

After day 46, no Standard patient is at risk any more: the six following deaths in the new treatment group (days 49 to 101) have E1 = 0 and Vj = 0.

O1 − E1 = 10 − 5.2160 = 4.7840              E2 = 20 − 5.2160 = 14.7840
χ² log-rank = 4.7840² / 3.0733 = 7.447       1 df, P = 0.0064

Gehan: U = Σ nj (d1j − E1j) = 12 + 12 − 10 + 11 + 11 − 8 + 18 − 4 + 8 − 3 + 7 + 7 + 7 = 68
       V = Σ nj² Vj = 944.6        χ² = 68² / 944.6 = 4.895      P = 0.027

HR "Mantel-Haenszel": L = 4.7840 / 3.0733 = 1.5566      HR = e^1.5566 = 4.743
        CI = exp(1.5566 ± 1.96 / √3.0733) = exp(1.5566 ± 1.1180) = 1.551 to 14.51
HR "Log-rank": (10 / 5.2160) / (10 / 14.7840) = 1.9172 / 0.6764 = 2.834
        SE = √(1/5.2160 + 1/14.7840) = 0.5093      CI = exp(1.0418 ± 0.9982) = 1.045 to 7.690

Interpretation. With the standard treatment, half of the patients have died by 26 days, against 55 days with the new treatment, and the log-rank test concludes that there is a difference (P = 0.006). The two hazard ratios differ markedly because the effect is strong; the Cox model applied to the same data (Multivariable table with a variable equal to 1 for Standard and 0 for New treatment) gives 4.68 (95% CI 1.41 to 15.51), close to the "Mantel-Haenszel" estimate. With 12 patients per group, the intervals are wide: a risk 1.5 times as well as 15 times higher under the standard treatment remains compatible with the data. The Gehan P value (0.027) is larger than that of the log-rank test, because the gap between observed and expected comes mostly from the Standard deaths on days 30 to 46, when few subjects remained at risk, times to which the Gehan test gives less weight. Beyond 40 days, only 2 patients remain at risk in the Standard group: the end of its curve, down to the drop to 0 at day 46, rests on one or two subjects. The graph of the table "Log-minus-log plot: ln(-ln S)" shows two roughly parallel curves, and the Grambsch and Therneau test of the corresponding Cox model does not signal any departure from proportional hazards (P = 0.48).

Writing up the results#

"Median survival was 26 days (95% CI 10 to 42) under the standard treatment and 55 days (95% CI 21 to 79) under the new treatment (12 patients and 10 deaths per group; Kaplan-Meier estimate). The survival curves differed (log-rank test, χ² = 7.45, 1 df, P = 0.006). The hazard ratio of the standard treatment relative to the new treatment was 4.7 (95% CI 1.6 to 14.5)."

Common pitfalls#

  • Ignoring censoring: excluding censored subjects, counting them as deaths or averaging the observed times biases all the results.
  • Reading the tail of the curve: when few subjects remain at risk, each event makes a large step and the curve becomes very imprecise. Show the numbers at risk and the confidence interval, and do not comment on (or cut off) the part where fewer than 10 to 20% of the subjects remain.
  • Median not reached ("Undefined"): write "not reached" and give the lower limit of its interval, or the survival at a time fixed in advance; do not replace it with the last observed time or with an average of the times.
  • Comparing survivals at a time chosen after the fact (the one at which the curves are furthest apart): this is a hidden multiple test that inflates the α risk. Test the entire curves, or a time fixed in the protocol.
  • Choosing the test after seeing the P values: log-rank or Gehan is decided before the analysis.
  • Crossing curves: the log-rank test loses its power and a single hazard ratio no longer makes sense; describe the curves and the survival at times fixed in advance.
  • Groups defined after the origin (response to treatment, adherence): immortal time bias.
  • Pairwise comparisons without correction, or a trend test applied to unordered groups.
  • Direction of the hazard ratio: it is always the first data set over the second; check which one is in the numerator before concluding.

Cox Proportional Hazards Regression#

The Cox model relates the instantaneous risk of the event (the "hazard" h(t)) to several explanatory variables at once, the covariates, without assuming anything about the shape of the survival curve. Each coefficient gives a hazard ratio adjusted for the other covariates. Variance estimates the coefficients by maximum partial likelihood and gives, with the hazard ratios and their intervals, three global tests, the AIC, Harrell's concordance index, a test of the proportional hazards assumption based on Schoenfeld residuals and the predicted survival curve for an "average" subject. The analysis belongs to the Curves and Regression family and uses a Multivariable table.

When to use it#

  • Estimate the effect of a factor (treatment, exposure) on survival while accounting for other variables: confounders in an observational study, prognostic factors in a trial.
  • Study a continuous variable (age, level of a marker) without cutting it into classes (hazard ratio per unit), or several prognostic factors together.
  • With a single binary covariate, the model gives the maximum likelihood hazard ratio and its interval; its score test is then the log-rank test.
  • It is not suitable when the effect of a variable changes markedly over time (crossing survival curves), when the value of a covariate changes during follow-up (time-dependent covariates, not supported by Variance), or for clustered subjects (centers, families).

Assumptions and checks#

  • Proportional hazards: the hazard ratio of each covariate stays the same throughout follow-up. Checks in Variance:
    • the "Proportional hazards" tab: Grambsch and Therneau test for each coefficient and global test;
    • the graph of the output table "Scaled Schoenfeld residuals" against time: under the assumption, the points form a horizontal band around β; a slope or a curvature shows an effect that changes with time. To see it better, open the tab of this table, click Analyze These Results and fit a curve with Smoothing Curve (Spline, LOWESS);
    • for a categorical covariate, the Kaplan-Meier analysis of the groups it defines and its table "Log-minus-log plot: ln(-ln S)" (roughly parallel curves);
    • a nonsignificant test with few events does not prove the assumption. If it is false for a covariate, analyze the subgroups of that variable separately, or report distinct effects by follow-up period: Variance offers neither strata nor time-dependent covariates.
  • Log-linearity of continuous covariates: each additional unit multiplies the risk by the same factor (going from 40 to 50 years has the same effect as from 60 to 70). Check: create a version of the variable in classes (categorical variable), fit the model with it and verify that the hazard ratios of the classes progress steadily; otherwise, transform the variable (logarithm...).
  • Noninformative censoring once the covariates are accounted for; independent subjects (one row per subject); covariates measured at the origin.
  • Enough events: count at least about ten events per estimated coefficient (each level of a categorical variable other than the reference counts as one). Below that, the coefficients are biased and their intervals unreliable.
  • No strong collinearity between covariates (weight and height, for example): their standard errors blow up. Look at the correlations first (Correlation, chapter 16).

Step by step in Variance#

  1. Create a Multivariable table: one row per subject, a time variable (numbers ≥ 0), an event variable (1 = event, 0 = censoring) and the covariates. A text variable (M/F) is categorical; a numeric variable is continuous, unless you give it the Categorical type (right-click on the column header). The reference level is the first level encountered reading the table from top to bottom (chapter 16, "Multiple Linear Regression"). To follow the example: "Clinical study" data.
  2. Choose Analysis › Curves and Regression › Cox Proportional Hazards Regression.
  3. Model tab:
    • "Elapsed time variable": the time variable (by default, the first variable of the table; choose Time in the example);
    • "Event variable (1 = event, 0 = censored)": the event variable (by default, the second; choose Event). It must contain only 1s and 0s: any other value, as well as a negative time, is refused with a message ("the event variable must be 1 (event) or 0 (censored)...", "elapsed times cannot be negative");
    • "Covariates": check boxes. If none is checked, Variance takes all the variables checked in the "Data sets" tab, except the time, the event and the variables of Label type;
    • "Ties": handling of equal event times, "Efron" (default) or "Breslow";
    • "Model terms" (empty by default): the terms of the model, one per line or separated by commas: a variable (Age), an interaction (Age*Sex, Age*Sex*Dose) or a power (Age^2, Age^3); names are written as in the table, case ignored, a space may be written _. Empty: the covariates checked above; with terms, these boxes are ignored.
  4. Compare tab: "Compare with the same model without" (empty by default): the terms to remove to obtain a simpler model, nested in the first, separated by commas (for example Age*Sex, Age^2). Both models are fitted to the same rows and compared (see Calculations).
  5. Options tab: "Confidence level (%)", "Significance level (alpha)" (threshold of the "Proportional?" column), "Significant digits" and "P value format".
  6. Data sets tab, then OK. Only complete rows (time, event and all covariates filled in) are used; at least one more than the number of coefficients is needed (otherwise "not enough complete rows for this model"), with at least one event (otherwise "too few subjects or events"); with no covariate, the message is "choose at least one covariate". Variance also creates a step graph of the first output table, "Predicted survival (mean covariates)".

Calculations#

Model.

h(t | x) = h0(t) · exp(β1 x1 + β2 x2 + … + βp xp)
hazard ratio for one more unit of xk = exp(βk)      (other covariates held fixed)

h0(t), the baseline hazard, is neither assumed nor estimated to obtain the β (semiparametric model). The ratio of the risks of two subjects, exp(β·(x − x')), does not depend on t: this is the proportional hazards assumption. A categorical variable becomes a 0/1 indicator variable for each level other than the reference, named "Variable[level]" (Sex[F] equals 1 for a woman, 0 for a man); its coefficient compares that level with the reference. The model has no constant, which is absorbed into h0.

Partial likelihood. At each event time ti, the subject who has the event is compared with those still at risk, R(ti) (subjects whose time is ≥ ti):

L(β) = Π  exp(β·xi) / Σ_{j ∈ R(ti)} exp(β·xj)        (product over the events)
β·x = β1 x1 + … + βp xp

When d events (set D) share the same time t, the contribution of that time to ln L depends on the "Ties" option:

S0 = Σ_{j ∈ R(t)} exp(β·xj)         SD = Σ_{i ∈ D} exp(β·xi)
Breslow :  Σ_{i ∈ D} β·xi − d · ln S0
Efron   :  Σ_{i ∈ D} β·xi − Σ_{l = 0 … d−1} ln( S0 − (l/d) · SD )

Without ties, the two formulas coincide. With ties, Efron's formula better approximates the exact likelihood; Breslow's brings the coefficients slightly closer to 0.

Estimation. Variance maximizes ln L by the Newton-Raphson method starting from β = 0: β ← β + I(β)⁻¹ U(β), where U is the vector of first derivatives of ln L (the score) and I the information matrix (negative of the second derivatives). A step that would lower ln L is halved, up to 20 times; the computation stops when the gain in ln L falls below 10⁻¹⁰ and the coefficients change by less than 10⁻⁸, or after 50 iterations. The computation uses the covariates centered and scaled, then the coefficients and covariance are moved back to the original scale. The covariance matrix of the coefficients is V = I(β̂)⁻¹; a direction where the information vanishes (a coefficient going to infinity) gets an infinite variance, and a "Warning" row says so. A covariate constant in the rows analysed, or an exact linear combination of the others, is refused with a message.

Coefficients and hazard ratios (Wald method):

SE(βk) = √Vkk          z = βk / SE(βk)          P = 2 · [1 − Φ(|z|)]
CI of βk = βk ± z* · SE(βk)          z* = normal quantile of order (1 + C)/2
HR = e^βk              CI of the HR = e^(lower limit) to e^(upper limit)

Global tests of the hypothesis "all the βk are zero", compared with the χ² distribution with p df (p = number of coefficients):

likelihood ratio :  LR = 2 · [ln L(β̂) − ln L(0)]
Wald             :  W  = β̂ᵀ I(β̂) β̂
score            :  Sc = U(0)ᵀ I(0)⁻¹ U(0)

With a single binary covariate, the score test is the log-rank test: identical in the absence of ties, very close otherwise ("Survival of two groups" data: 7.499 with Efron, against 7.447 for the log-rank test).

Goodness of fit. AIC = −2 ln L(β̂) + 2p. Harrell's C is the proportion of concordant pairs among comparable pairs: a pair (i, j) is comparable when subject i had the event and the time of j is strictly longer; it is concordant when i has the higher linear predictor β̂·x (the higher predicted risk); a tie in the predictor counts for ½. Pairs with equal times are not comparable.

Schoenfeld residuals and the Grambsch and Therneau test. For each event i, at time ti, the Schoenfeld residual of each covariate is the difference between the subject's value and the mean of the subjects at risk weighted by their risk; the scaled residual adds β̂ to it:

x̄(ti) = Σ_{j ∈ R(ti)} xj · exp(β̂·xj) / Σ_{j ∈ R(ti)} exp(β̂·xj)
ri    = xi − x̄(ti)                    raw residual (p values)
rsi   = β̂ + d · V · ri                scaled residual (d = number of events)

With "Breslow", simultaneous events share the same mean x̄(ti). With "Efron", the expected mean of m simultaneous events is the mean of the m means of the Efron approximation, in which the weights of the tied subjects are reduced by r/m (r = 0 … m − 1): the sum of the raw residuals is then 0, like the score at the maximum of the likelihood. Under the proportional hazards assumption, component k of rsi fluctuates around βk; its graph against time shows how the effect βk(t) varies. The test uses the rank of the event times, gi = 1, 2, …, d (average rank for equal times), centered (g̃i = gi − ḡ):

u          = Σi g̃i · ri                                (p values)
χ²k        = d · (V u)k² / ( Vkk · Σi g̃i² )            1 df, for each coefficient
global χ²  = d · uᵀ V u / Σi g̃i²                        p df
"Correlation with time" = Pearson correlation between component k of the rsi and gi

This is the classic form of the Grambsch and Therneau (1994) test with the "rank of time" transformation; some recent software uses a more exact variant, hence small differences.

Predicted survival. The baseline cumulative hazard is estimated by Breslow's formula (whatever the "Ties" option), then survival is computed for a subject whose every covariate equals its mean x̄:

H0(t)     = Σ_{ti ≤ t} di / Σ_{j ∈ R(ti)} exp(β̂·xj)
S(t | x̄)  = exp( −H0(t) · exp(β̂·x̄) )            displayed in %

Terms and comparison of models. The terms are written as for multiple linear regression (chapter "Correlation and regression"), without a constant. The comparison with the model without the terms given uses the partial likelihood ratio test: χ² = 2 (lnL_full − lnL_simpler), with as many df as coefficients removed, and the AIC (AIC = −2 lnL + 2k) of both models, with the probability of the better model (Akaike weights). With no term left, the simpler model is the null model: the comparison gives back the overall "Partial likelihood ratio test".

Reading the results#

  • "Parameter estimates" tab: one row per coefficient (variable name, or "Variable[level]"); columns "β" (logarithm of the hazard ratio), "Std. Error", "95% CI" (of β), "|z|" and "P value" (Wald test of the hypothesis βk = 0).
  • "Hazard ratios" tab: "Hazard ratio" (e^β) and its "95% CI". For a continuous variable, it is the ratio of the instantaneous risks for one more unit, the other covariates remaining equal; for k units, take e^(k·β), and likewise for the limits. For a level of a categorical variable, it is the ratio of the risks of that level to those of the reference level.
  • "Model tests" tab: "Partial likelihood ratio test", "Wald test" and "Score (logrank) test" (columns "Statistic", "DF", "P value") test all the covariates together. They agree when events are numerous; if they diverge, prefer the likelihood ratio test. Under "Goodness of fit": "Partial log likelihood", -2*Log likelihood, "AIC" (to compare models fitted on the same subjects: the smaller is preferable), "Harrell's C (concordance)" (0.5: no better than chance; 1: subjects perfectly ranked according to their risk) and "Subjects / events".
  • "Proportional hazards" tab (at least three events): under "Test of the scaled Schoenfeld residuals (Grambsch-Therneau, rank of time)", one row per coefficient then "Global test"; columns "Correlation with time", "Chi-square", "P value" and "Proportional?" ("Yes" if P ≥ α, the threshold of the Options tab; "No" otherwise).
  • Output tables: "Scaled Schoenfeld residuals" and "Schoenfeld residuals" (in X the time of each event, one column per coefficient); "Forest plot (hazard ratios)" ("Hazard ratio", "Lower limit", "Upper limit"), which is plotted with Plot These Results as a forest plot on a logarithmic axis; "Predicted survival (mean covariates)", the predicted survival (in %) for the average subject, first output table and graph created with the analysis.
  • "Comparison of models" tab (Compare tab filled in): "Simpler model" ("without" followed by the terms removed), "Test", then "Chi-square" and "df", "P value", "Preferred model (alpha = 0.05)" (the full model if P < 0.05, otherwise the simpler model), "AIC (simpler model)", "AIC (full model)" and "Probability the full model is better (%)".

The last tab, "Narrative results", states in sentences the partial likelihood ratio test (does the model predict survival better than no covariate at all?), Harrell's C, then the hazard ratio of each covariate with its confidence interval and its P value, and the comparison with the nested model, when it is requested.

Worked example#

"Clinical study" data: Time (follow-up time) and Event of 40 subjects, with 30 events and 10 censorings; covariates Age (years) and Sex (M or F; reference M, the value in the first row). Options: "Elapsed time variable" = Time, "Event variable (1 = event, 0 = censored)" = Event, "Covariates" = Age and Sex, "Ties" = Efron. Variance displays:

Parameter estimates   β         Std. Error   95% CI               |z|      P value
Age                   0.1199    0.02745      0.06608 to 0.1737    4.367    <0.0001
Sex[F]                -0.3825   0.4074       -1.181 to 0.416      0.9389   0.3478

Hazard ratios         Hazard ratio   95% CI
Age                   1.127          1.068 to 1.19
Sex[F]                0.6821         0.307 to 1.516

Model tests                      Statistic   DF   P value
Partial likelihood ratio test    24.92       2    <0.0001
Wald test                        19.68       2    <0.0001
Score (logrank) test             23.15       2    <0.0001
Goodness of fit
Partial log likelihood           -70.43
-2*Log likelihood                140.9
AIC                              144.9
Harrell's C (concordance)        0.7838
Subjects / events                40 / 30

Proportional hazards   Correlation with time   Chi-square   P value   Proportional?
Age                    0.0108                  0.003761     0.9511    Yes
Sex[F]                 -0.1766                 0.9193       0.3377    Yes
Global test                                    0.92         0.6313    Yes

Check by hand:

HR (Age)       = e^0.11989 = 1.1274
95% CI         = e^(0.11989 ± 1.96 × 0.027453) = e^0.06608 to e^0.17369 = 1.0683 to 1.1897
z              = 0.11989 / 0.027453 = 4.367             P = 1.3 × 10⁻⁵
per decade     = e^(10 × 0.11989) = 3.32                95% CI: e^0.6608 to e^1.7369 = 1.94 to 5.68
ln L(0)        = −82.895 (all β zero)                   ln L(β̂) = −70.433
LR             = 2 × (−70.433 + 82.895) = 24.92         2 df, P = 3.9 × 10⁻⁶
AIC            = 140.867 + 2 × 2 = 144.87
Harrell's C    = 464 concordant pairs (ties counted ½) / 592 comparable pairs = 0.7838

Interpretation. At equal sex, each year of age multiplies the instantaneous risk of the event by 1.127 (95% CI 1.068 to 1.190), that is by 3.3 per decade (CI 1.9 to 5.7). At equal age, the hazard ratio of women relative to men is 0.68, but its interval (0.31 to 1.52) runs from a risk divided by three to a risk increased by half: the data do not allow a conclusion about sex. The three global tests agree. No departure from proportional hazards is detected (global P = 0.63); the scaled residuals of Age, centered on 0.12, show no trend with time (correlation 0.003). With 30 events, this does not prove that the assumption is exact. With "Ties" = Breslow, the results change little (β of Age 0.1183, HR 1.126; HR of Sex[F] 0.672; LR 24.44). Finally, note that the 10 censored subjects of this fictitious example are all women: in a real study, the reason would have to be understood before accepting that the censoring is noninformative.

Writing up the results#

"In a Cox model including age and sex (40 subjects, 30 events; ties handled by Efron's method), the risk of the event increased with age: hazard ratio 1.13 per year (95% CI 1.07 to 1.19; P < 0.0001), or 3.3 per decade (95% CI 1.9 to 5.7). The hazard ratio of women relative to men was 0.68 (95% CI 0.31 to 1.52; P = 0.35). The Grambsch and Therneau test showed no departure from the proportional hazards assumption (global P = 0.63)."

Common pitfalls#

  • Too many covariates for too few events (about ten events per coefficient). Choose the covariates before the analysis, based on the question and on domain knowledge, rather than by stepwise selection on the P values.
  • Misread hazard ratio: it is a ratio of instantaneous risks, not a ratio of probabilities of death nor of median survivals.
  • Unit of continuous covariates: the hazard ratio depends on the unit. With the five covariates of the example (Age, Weight, Height, Sex, Response), the one for Height is given per meter: 0.044, CI from 2.6 × 10⁻⁷ to 7,254. Express it for a useful difference (10 cm), and note that Height and Weight, highly correlated (r = 0.86), compete for the same effect.
  • Numeric codes treated as continuous: a stage coded 1, 2, 3 is a continuous variable for Variance; give it the Categorical type if the gaps between codes are meaningless.
  • Reference level: it is the first level encountered in the table; check which one is in the denominator of the hazard ratios.
  • Monotone likelihood: if a level of a variable has no event, or if all the events of one group precede those of the other, β heads toward infinity: huge coefficient and standard error, CI "0 to ???", Wald P close to 1. Variance then adds a "Warning" row to the "Parameter estimates" tab ("the coefficient may be infinite (monotone likelihood)"), as when the likelihood has not converged. The likelihood ratio test remains usable; merge the levels or simply describe the data.
  • Proportional hazards not checked, or judged satisfied on a single nonsignificant test.
  • Covariates measured after the origin (response to treatment, treatment received later): the model does not know they depend on time and their effect is biased.
  • "Predicted survival (mean covariates)" curve: it is the survival of an average subject who does not exist (Sex[F] = 0.5, for example), not the average survival of the sample.
  • Optimistic Harrell's C: it is computed on the data used to fit the model; a prognostic model must be validated on other data.

References#

Books:

  • Kleinbaum DG, Klein M. Survival Analysis: A Self-Learning Text, 3rd ed. Springer, 2012.
  • Collett D. Modelling Survival Data in Medical Research, 3rd ed. Chapman & Hall/CRC, 2015.
  • Machin D, Cheung YB, Parmar MKB. Survival Analysis: A Practical Approach, 2nd ed. Wiley, 2006.
  • Kalbfleisch JD, Prentice RL. The Statistical Analysis of Failure Time Data, 2nd ed. Wiley, 2002.
  • Therneau TM, Grambsch PM. Modeling Survival Data: Extending the Cox Model. Springer, 2000.
  • Altman DG. Practical Statistics for Medical Research. Chapman & Hall, 1991.
  • Motulsky H. Intuitive Biostatistics, 4th ed. Oxford University Press, 2018.

Articles:

  • Greenwood M. The natural duration of cancer. Reports on Public Health and Medical Subjects 1926;33:1-26.
  • Kaplan EL, Meier P. Nonparametric estimation from incomplete observations. Journal of the American Statistical Association 1958;53:457-481.
  • Gehan EA. A generalized Wilcoxon test for comparing arbitrarily singly-censored samples. Biometrika 1965;52:203-223.
  • Mantel N. Evaluation of survival data and two new rank order statistics arising in its consideration. Cancer Chemotherapy Reports 1966;50:163-170.
  • Breslow N. A generalized Kruskal-Wallis test for comparing K samples subject to unequal patterns of censorship. Biometrika 1970;57:579-594.
  • Cox DR. Regression models and life-tables. Journal of the Royal Statistical Society B 1972;34:187-220.
  • Peto R, Peto J. Asymptotically efficient rank invariant test procedures. Journal of the Royal Statistical Society A 1972;135:185-207.
  • Breslow NE. Covariance analysis of censored survival data. Biometrics 1974;30:89-99.
  • Efron B. The efficiency of Cox's likelihood function for censored data. Journal of the American Statistical Association 1977;72:557-565.
  • Brookmeyer R, Crowley J. A confidence interval for the median survival time. Biometrics 1982;38:29-41.
  • Schoenfeld D. Partial residuals for the proportional hazards regression model. Biometrika 1982;69:239-241.
  • Grambsch PM, Therneau TM. Proportional hazards tests and diagnostics based on weighted residuals. Biometrika 1994;81:515-526.
  • Peduzzi P, Concato J, Feinstein AR, Holford TR. Importance of events per independent variable in proportional hazards regression analysis. II. Accuracy and precision of regression estimates. Journal of Clinical Epidemiology 1995;48:1503-1510.
  • Harrell FE, Lee KL, Mark DB. Multivariable prognostic models: issues in developing models, evaluating assumptions and adequacy, and measuring and reducing errors. Statistics in Medicine 1996;15:361-387.
  • Pocock SJ, Clayton TC, Altman DG. Survival plots of time-to-event outcomes in clinical trials: good practice and pitfalls. Lancet 2002;359:1686-1689.