Skip to main content

22  The Cox proportional hazards model

The log-rank test of Chapter 21 compares the survival of groups. It gives a p-value, but no measure of the size of the effect. It also cannot allow for other variables, such as age or the stage of a disease. Cox proposed a regression model for the hazard (Journal of the Royal Statistical Society, Series B, 1972). The model gives a hazard ratio for each variable, and it does not need a model for the shape of the hazard over time. Chapter 1 tells its story.

22.1 The problem

The Veterans’ Administration lung cancer trial compared two chemotherapy regimens, standard and test, in patients with advanced lung cancer. Patients were randomised to the two regimens. The data are in Kalbfleisch and Prentice (The Statistical Analysis of Failure Time Data, Wiley, 1980), and in the veteran data of the survival package. The time is the survival time in days.

vet <- veteran |>
  mutate(trt = factor(trt, 1:2, c("standard", "test")),
         prior = factor(prior, c(0, 10), c("no", "yes")))
glimpse(vet)
Rows: 137
Columns: 8
$ trt      <fct> standard, standard, standard, standard, standard, standard, s…
$ celltype <fct> squamous, squamous, squamous, squamous, squamous, squamous, s…
$ time     <dbl> 72, 411, 228, 126, 118, 10, 82, 110, 314, 100, 42, 8, 144, 25…
$ status   <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0…
$ karno    <dbl> 60, 70, 60, 60, 70, 20, 40, 80, 50, 70, 60, 40, 30, 80, 70, 6…
$ diagtime <dbl> 7, 5, 3, 9, 11, 5, 10, 29, 18, 6, 4, 58, 4, 9, 11, 3, 9, 2, 4…
$ age      <dbl> 69, 64, 38, 63, 65, 49, 69, 68, 43, 70, 81, 63, 63, 52, 48, 6…
$ prior    <fct> no, yes, no, yes, yes, no, yes, no, no, no, no, yes, no, yes,…

There are 137 patients, and 128 of them died during the study. Besides the regimen trt, the data give the type of tumour cell (celltype) and the Karnofsky performance score (karno). The Karnofsky score measures how well a patient can do daily tasks, from 10 (near death) to 100 (normal). The data also give the months from diagnosis (diagtime), the age and any prior therapy.

Show code
km_trt <- survfit(Surv(time, status) ~ trt, data = vet)
km_karno <- survfit(Surv(time, status) ~ karno >= 60, data = vet)
km_tidy <- function(fit, labels) {
  tibble(time = fit$time, surv = fit$surv,
         group = rep(labels, fit$strata)) |>
    bind_rows(tibble(time = 0, surv = 1, group = labels))
}
p1 <- km_tidy(km_trt, c("standard", "test")) |>
  ggplot(aes(time, surv, colour = group)) +
  geom_step(linewidth = 1) +
  scale_colour_manual(values = c(standard = "steelblue", test = "firebrick")) +
  labs(x = "days", y = "proportion alive", colour = "regimen")
p2 <- km_tidy(km_karno, c("below 60", "60 or more")) |>
  ggplot(aes(time, surv, colour = group)) +
  geom_step(linewidth = 1) +
  scale_colour_manual(values = c(`below 60` = "firebrick", `60 or more` = "steelblue")) +
  labs(x = "days", y = "proportion alive", colour = "Karnofsky")
p1 + p2
Figure 22.1: Kaplan–Meier curves of the lung cancer trial, by regimen (left) and by Karnofsky score (right). The curves of the two regimens cross and stay close. The patients with a low score die much sooner.

The log-rank test of the two regimens gives p = 0.93. The Karnofsky score has a much larger effect than the regimen. A comparison of the regimens can allow for this large difference between patients.

Does the test regimen change survival, once we allow for cell type and performance status?

22.2 Intuitive solution

22.2.1 Who dies next?

Look at the trial at the moment of each death. Some patients are still alive and in follow-up: the risk set. One of them dies. If the regimen has no effect, each patient in the risk set has the same chance to be the one who dies.

Now suppose that the test regimen multiplies the hazard by a constant \(\theta\) at all times. A patient on the test regimen then counts \(\theta\) times as much as a patient on the standard regimen. If the risk set has \(n_s\) standard and \(n_t\) test patients, the probability that the death is a given test patient is \(\theta / (n_s + n_t \theta)\).

first <- which.min(ifelse(vet$status == 1, vet$time, Inf))
at_risk <- vet$time >= vet$time[first]
n_s1 <- sum(at_risk & vet$trt == "standard")
n_t1 <- sum(at_risk & vet$trt == "test")
c(day = vet$time[first], standard_at_risk = n_s1, test_at_risk = n_t1)
             day standard_at_risk     test_at_risk 
               1               69               68 
vet$trt[first]
[1] test
Levels: standard test

At the first death, on day 1, all 137 patients are at risk: 69 standard and 68 test. The patient who died had the test regimen.

22.2.2 Multiply over all deaths

We do this at each death, and we multiply the probabilities of the deaths that occurred. The result is a function of \(\theta\). The best value of \(\theta\) is the value that makes the observed order of deaths most probable. Some patients died on the same day. Here we give each of these deaths the full risk set of that day, the simplest rule for ties.

x <- as.numeric(vet$trt == "test")
dead <- which(vet$status == 1)
log_plik <- function(beta) {
  sum(map_dbl(dead, \(i) {
    risk <- vet$time >= vet$time[i]                  # the risk set at this death
    beta * x[i] - log(sum(exp(beta * x[risk])))
  }))
}
theta <- exp(seq(log(0.5), log(2), length.out = 101))
curve_df <- tibble(theta, log_plik = map_dbl(log(theta), log_plik))
theta_best <- curve_df$theta[which.max(curve_df$log_plik)]
fit_breslow <- coxph(Surv(time, status) ~ trt, data = vet, ties = "breslow")
c(best_on_grid = theta_best, coxph = unname(exp(coef(fit_breslow))))
best_on_grid        coxph 
    1.013959     1.016462 
Show code
ggplot(curve_df, aes(theta, log_plik)) +
  geom_line(colour = "steelblue", linewidth = 1) +
  geom_vline(xintercept = exp(coef(fit_breslow)), colour = "firebrick") +
  scale_x_log10() +
  labs(x = "hazard ratio theta (log scale)", y = "log partial likelihood")
Figure 22.2: The log of the product of the death probabilities, as a function of the hazard ratio theta of the test regimen. The red line marks the maximum, which is the estimate of coxph().

The curve has its maximum at \(\theta =\) 1.01. coxph() gives 1.016 with the same rule for ties. Without adjustment, the hazard of death is almost the same with the two regimens.

The calculation uses only the order of the deaths and the risk sets. The real times matter only through this order. If we replace each time by its rank, the estimate does not change.

fit_trt <- coxph(Surv(time, status) ~ trt, data = vet)
c(times = coef(fit_trt),
  ranks = coef(coxph(Surv(rank(time, ties.method = "min"), status) ~ trt, data = vet)))
times.trttest ranks.trttest 
   0.01774257    0.01774257 

22.3 Formal solution

22.3.1 The model

The Cox model says that the hazard of a patient with covariates \(x_1, \dots, x_p\) is

\[ h(t \mid x) = h_0(t) \exp(\beta_1 x_1 + \dots + \beta_p x_p). \]

\(h_0(t)\) is the baseline hazard, the hazard of a patient with all \(x_k = 0\). The model puts no condition on its shape. The ratio of the hazards of two patients who differ by 1 unit in \(x_k\), with all other covariates equal, is

\[ \frac{h(t \mid x_k + 1)}{h(t \mid x_k)} = e^{\beta_k}. \]

This is the hazard ratio (HR). The ratio is the same at all times \(t\), so the model assumes proportional hazards. The model has four assumptions:

  • The hazard ratio of each covariate is constant over time.
  • The log of the hazard is a linear function of each continuous covariate.
  • Censoring is non-informative (Chapter 21).
  • The patients are independent.

22.3.2 The partial likelihood

The intuitive solution gives the estimate. At the death of patient \(i\) at time \(t_i\), let \(R(t_i)\) be the risk set. The probability that the death is patient \(i\) is \(e^{x_i \beta} / \sum_{j \in R(t_i)} e^{x_j \beta}\), where \(x_i \beta = \beta_1 x_{i1} + \dots + \beta_p x_{ip}\). The partial likelihood is the product over the deaths:

\[ L(\beta) = \prod_{i\,:\ \text{death}} \frac{e^{x_i \beta}}{\sum_{j \in R(t_i)} e^{x_j \beta}}. \]

The baseline hazard cancels from each fraction, so the estimate does not need it. R finds the \(\beta\) that maximises \(L(\beta)\). The SE of each coefficient comes from the curvature of \(\log L\) at the maximum. The theory section below derives both.

22.3.3 The model in R

A model with all six covariates gives a p-value below 0.05 only for celltype and karno. We fit the model with the regimen and these two prognostic factors.

fit <- coxph(Surv(time, status) ~ trt + celltype + karno, data = vet)
summary(fit)
Call:
coxph(formula = Surv(time, status) ~ trt + celltype + karno, 
    data = vet)

  n= 137, number of events= 128 

                       coef exp(coef)  se(coef)      z Pr(>|z|)    
trttest            0.261744  1.299194  0.200923  1.303  0.19267    
celltypesmallcell  0.824980  2.281836  0.268911  3.068  0.00216 ** 
celltypeadeno      1.153994  3.170833  0.295038  3.911 9.18e-05 ***
celltypelarge      0.394625  1.483828  0.282243  1.398  0.16206    
karno             -0.031271  0.969213  0.005165 -6.054 1.41e-09 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

                  exp(coef) exp(-coef) lower .95 upper .95
trttest              1.2992     0.7697    0.8763    1.9262
celltypesmallcell    2.2818     0.4382    1.3471    3.8653
celltypeadeno        3.1708     0.3154    1.7784    5.6534
celltypelarge        1.4838     0.6739    0.8534    2.5801
karno                0.9692     1.0318    0.9595    0.9791

Concordance= 0.737  (se = 0.022 )
Likelihood ratio test= 61.07  on 5 df,   p=7e-12
Wald test            = 63.41  on 5 df,   p=2e-12
Score (logrank) test = 66.55  on 5 df,   p=5e-13
  • n, number of events: 137 patients and 128 deaths. The deaths carry the information.
  • coef: the estimate \(\hat\beta_k\), the log of the hazard ratio.
  • exp(coef): the hazard ratio. For trttest, it is 1.3: the hazard on the test regimen is 1.3 times the hazard on the standard regimen, at equal cell type and score.
  • celltypesmallcell, celltypeadeno, celltypelarge: hazard ratios against squamous cells, the first level of the factor. Adenocarcinoma has a hazard 3.17 times that of squamous cells.
  • karno: 0.969 per point of the score. For 10 points, the hazard ratio is \(e^{10\hat\beta} =\) 0.73. Each 10 points of score lowers the hazard by 27%.
  • se(coef), z, Pr(>|z|): the SE of \(\hat\beta_k\), the ratio \(z = \hat\beta_k / \text{SE}\) and its two-sided p-value. This is a Wald test of \(\beta_k = 0\).
  • exp(-coef): the inverse hazard ratio, for the comparison in the other direction.
  • lower .95, upper .95: the 95% confidence interval for the hazard ratio, \(e^{\hat\beta \pm 1.96\,\text{SE}}\). For the regimen, it is 0.88 to 1.93.
  • Concordance: 0.737. In a pair of patients, the patient with the higher predicted hazard died first in this proportion of the pairs that we can compare. A value of 0.5 is chance.
  • Likelihood ratio test, Wald test, Score (logrank) test: three tests of the null hypothesis that all 5 coefficients are 0. The df are the number of coefficients.

The test regimen has a hazard ratio of 1.3, with p = 0.19. The data give no evidence that the test regimen improves survival. The interval goes from a benefit of about 12% to a harm of about 93%. The Karnofsky score has the strongest effect.

The trial was randomised, so the two groups are balanced on average, and adjustment is not necessary to remove confounding. Adjustment for strong prognostic factors usually increases the power of the treatment comparison. The hazard ratio is also non-collapsible: the adjusted and the unadjusted hazard ratios estimate different quantities, even with perfect balance. The unadjusted hazard ratio is 1.02.

22.3.4 Survival curves from the model

The model also gives a survival curve for a patient with given covariates. The curve is \(\hat S(t \mid x) = \exp\big(-\hat H_0(t)\, e^{x \hat\beta}\big)\), where \(\hat H_0\) is the cumulative baseline hazard.

Show code
new <- tibble(trt = "standard", celltype = "squamous", karno = c(40, 80))
pred <- survfit(fit, newdata = new)
tibble(time = rep(pred$time, 2), surv = c(pred$surv),
       karno = rep(c("40", "80"), each = length(pred$time))) |>
  ggplot(aes(time, surv, colour = karno)) +
  geom_step(linewidth = 1) +
  scale_colour_manual(values = c(`40` = "firebrick", `80` = "steelblue")) +
  labs(x = "days", y = "predicted proportion alive", colour = "Karnofsky")
Figure 22.3: Survival curves from the Cox model for patients with squamous cells on the standard regimen, with a Karnofsky score of 40 (red) and 80 (blue).

The predicted median survival is 92 days with a score of 40 and 283 days with a score of 80.

22.4 Checking proportional hazards

22.4.1 Schoenfeld residuals

At each death, take the covariate of the patient who died. Subtract the weighted mean of the covariate in the risk set, with the weights \(e^{x_j \hat\beta}\). The result is the Schoenfeld residual. Schoenfeld described these residuals in Biometrika (1982). If the hazard ratio is constant, the residuals have mean 0 at all times.

Grambsch and Therneau (Biometrika, 1994) scaled them. The scaled residual plus \(\hat\beta_k\) estimates the coefficient at that time, \(\beta_k(t)\). A trend over time shows that the hazard ratio changes.

zph <- cox.zph(fit)
zph
          chisq df       p
trt       0.206  1 0.64968
celltype 14.532  3 0.00226
karno    12.813  1 0.00034
GLOBAL   22.860  5 0.00036
  • chisq, df, p: a test for each term of the null hypothesis that its coefficient is constant over time. The df are the number of coefficients of the term.
  • GLOBAL: one test for all the terms together.

The score karno gives p = 0.00034, and celltype gives p = 0.0023. Both hazard ratios change over time.

Show code
tibble(time = zph$time, beta_t = zph$y[, "karno"]) |>
  ggplot(aes(time, beta_t)) +
  geom_point(colour = "steelblue", alpha = 0.6) +
  geom_smooth(method = "loess", formula = y ~ x, se = FALSE, colour = "firebrick") +
  geom_hline(yintercept = b_karno, colour = "grey50") +
  scale_x_log10() +
  labs(x = "days (log scale)", y = "coefficient of karno at time t")
Figure 22.4: The scaled Schoenfeld residuals of the Karnofsky score against the time of death (log scale). The red curve is a smooth of the residuals, and the grey line is the estimate of the Cox model. The smooth lies below the grey line in the first months and rises close to 0 later. Few deaths occur after day 300, so the right end of the smooth is uncertain.

22.4.2 A coefficient for each period

The score predicts the early deaths much better than the late deaths. We split each patient’s follow-up at 90 and 180 days and give the score a separate coefficient in each period. survSplit() makes one row for each patient and period. Surv(tstart, time, status) then says that a patient enters the risk set at tstart.

vet_split <- survSplit(Surv(time, status) ~ ., data = vet, cut = c(90, 180), episode = "period")
fit_split <- coxph(Surv(tstart, time, status) ~ trt + celltype + karno:strata(period), data = vet_split)
fit_split
Call:
coxph(formula = Surv(tstart, time, status) ~ trt + celltype + 
    karno:strata(period), data = vet_split)

                                  coef exp(coef)  se(coef)      z        p
trttest                       0.064030  1.066125  0.204817  0.313 0.754568
celltypesmallcell             0.917471  2.502951  0.278842  3.290 0.001001
celltypeadeno                 1.098203  2.998773  0.301184  3.646 0.000266
celltypelarge                 0.347523  1.415557  0.283921  1.224 0.220946
karno:strata(period)period=1 -0.045666  0.955361  0.006170 -7.401 1.35e-13
karno:strata(period)period=2  0.008044  1.008076  0.013131  0.613 0.540151
karno:strata(period)period=3  0.002173  1.002176  0.014647  0.148 0.882042

Likelihood ratio test=80.84  on 7 df, p=9.295e-15
n= 225, number of events= 128 
zph_split <- cox.zph(fit_split)
zph_split
                      chisq df     p
trt                   0.422  1 0.516
celltype              8.247  3 0.041
karno:strata(period)  2.678  3 0.444
GLOBAL               10.863  7 0.145
  • karno:strata(period)period=1: the score in the first 90 days. The hazard ratio for 10 points is 0.63.
  • period=2 and period=3: the score from day 90 to 180, and after day 180. The hazard ratios for 10 points are 1.08 and 1.02, with p = 0.54 and 0.88.
  • GLOBAL: the new cox.zph() gives p = 0.14. The test for celltype still gives p = 0.041.

A low score predicts death in the first 90 days. For a patient who survives 90 days, the score at entry no longer predicts the risk. The hazard ratio of the regimen is now 1.07, and it still shows no benefit. The cell type can also have a separate baseline hazard for each type, with strata(celltype) in the formula. The model then gives no hazard ratio for the cell type.

22.5 Ties

The partial likelihood assumes that no two deaths occur at the same time. In these data, 55 of the 128 deaths share a day with another death. R has three rules for tied deaths:

  • breslow: each tied death uses the full risk set. This is the rule of the intuitive solution.
  • efron: the R default. For \(d\) tied deaths, the \(k\)-th denominator removes the fraction \((k - 1)/d\) of the summed weights of the tied patients.
  • exact: the probability of the observed set of tied deaths, over all the sets of the same size in the risk set. The calculation is slow for large risk sets.
map_dfr(c("breslow", "efron", "exact"), \(m)
  tibble(ties = m, hr_test = exp(coef(coxph(Surv(time, status) ~ trt + celltype + karno, data = vet, ties = m))[["trttest"]])))
# A tibble: 3 × 2
  ties    hr_test
  <chr>     <dbl>
1 breslow    1.29
2 efron      1.30
3 exact      1.30

The three rules give almost the same hazard ratio here. Breslow’s rule differs most from the others when many deaths share a time.

22.6 The theory of the Cox model

22.6.1 Where the partial likelihood comes from

Suppose that one death occurs at time \(t\) in the risk set \(R(t)\). The probability that it is patient \(i\), given that it is one of them, is the ratio of the hazards:

\[ \frac{h_0(t)\, e^{x_i \beta}}{\sum_{j \in R(t)} h_0(t)\, e^{x_j \beta}} = \frac{e^{x_i \beta}}{\sum_{j \in R(t)} e^{x_j \beta}}. \]

The baseline hazard cancels. The partial likelihood is the product of these conditional probabilities. It is not the full likelihood of the data, because it leaves out the information in the times between the deaths. Cox (Biometrika, 1975) showed that it behaves like a likelihood. The score has mean 0, and its variance is the information.

22.6.2 Score, information and Newton–Raphson

The log partial likelihood is

\[ \ell(\beta) = \sum_{i\,:\ \text{death}} \left[ x_i \beta - \log \sum_{j \in R(t_i)} e^{x_j \beta} \right]. \]

For one covariate, let \(\bar x(\beta, t)\) be the mean of \(x\) in the risk set, with the weights \(w_j = e^{x_j \beta}\). Its derivative with respect to \(\beta\) is the weighted variance \(V(\beta, t)\) of \(x\) in the risk set. The first and second derivatives of \(\ell\) are then

\[ U(\beta) = \sum_{i\,:\ \text{death}} \big(x_i - \bar x(\beta, t_i)\big), \qquad I(\beta) = -\ell''(\beta) = \sum_{i\,:\ \text{death}} V(\beta, t_i). \]

The score \(U\) is the sum of the Schoenfeld residuals. The estimate solves \(U(\hat\beta) = 0\): at each death, the patient who died is, on average, a typical member of the risk set. Newton–Raphson finds the solution with the step \(\beta \leftarrow \beta + U(\beta) / I(\beta)\). The SE is \(1/\sqrt{I(\hat\beta)}\).

score <- function(b) sum(map_dbl(dead, \(i) {
  risk <- vet$time >= vet$time[i]; w <- exp(b * x[risk])
  x[i] - sum(w * x[risk]) / sum(w)
}))
info <- function(b) sum(map_dbl(dead, \(i) {
  risk <- vet$time >= vet$time[i]; w <- exp(b * x[risk])
  m <- sum(w * x[risk]) / sum(w)
  sum(w * (x[risk] - m)^2) / sum(w)
}))
b <- 0
for (step in 1:4) b <- b + score(b) / info(b)
c(newton = b, coxph = unname(coef(fit_breslow)),
  se_newton = 1 / sqrt(info(b)), se_coxph = sqrt(vcov(fit_breslow)[1, 1]))
    newton      coxph  se_newton   se_coxph 
0.01632787 0.01632787 0.18065161 0.18065161 

Four steps give the estimate and the SE of coxph() with Breslow’s rule. The log partial likelihood is concave, so Newton–Raphson converges fast from \(\beta = 0\).

22.6.3 The log-rank test is a score test

At \(\beta = 0\), all weights are 1. For a 0/1 covariate, \(\bar x(0, t_j)\) is the proportion \(n_{1j}/n_j\) of group 1 in the risk set. Thus

\[ U(0) = \sum_j \left(d_{1j} - d_j \frac{n_{1j}}{n_j}\right) = O_1 - E_1, \]

the observed minus the expected deaths of the log-rank test. The score test of \(\beta = 0\) is \(U(0)^2 / I(0)\). With Breslow’s rule, \(I(0) = \sum_j d_j p_j (1 - p_j)\) with \(p_j = n_{1j}/n_j\), a binomial variance. With the exact rule, \(I(0)\) is the hypergeometric variance of the log-rank test. We check this on the aml data of Chapter 21.

xa <- as.numeric(aml$x == "Maintained")
dead_a <- which(aml$status == 1)
U0 <- sum(map_dbl(dead_a, \(i) xa[i] - mean(xa[aml$time >= aml$time[i]])))
I0 <- sum(map_dbl(dead_a, \(i) { p <- mean(xa[aml$time >= aml$time[i]]); p * (1 - p) }))
c(O_minus_E = U0,
  score_breslow_by_hand = U0^2 / I0,
  score_breslow = unname(summary(coxph(Surv(time, status) ~ x, data = aml, ties = "breslow"))$sctest["test"]),
  score_exact = unname(summary(coxph(Surv(time, status) ~ x, data = aml, ties = "exact"))$sctest["test"]),
  log_rank = survdiff(Surv(time, status) ~ x, data = aml)$chisq)
            O_minus_E score_breslow_by_hand         score_breslow 
            -3.689336              3.322561              3.322561 
          score_exact              log_rank 
             3.396389              3.396389 

\(U(0) =\) -3.69, the observed minus the expected deaths of the maintained group in Chapter 21. The score test with the exact rule is equal to the log-rank statistic. With Breslow’s rule, it is a little smaller, because the binomial variance has no factor \((n_j - d_j)/(n_j - 1)\). Without ties, the two variances are equal.

22.6.4 The Breslow estimate of the baseline hazard

The model leaves \(h_0(t)\) free. Given \(\hat\beta\), Breslow’s estimate of the cumulative baseline hazard is

\[ \hat H_0(t) = \sum_{t_j \le t} \frac{d_j}{\sum_{k \in R(t_j)} e^{x_k \hat\beta}}. \]

At \(\beta = 0\), the denominator is \(n_j\), and \(\hat H_0\) is the Nelson–Aalen estimate of Chapter 21.

dt <- sort(unique(vet$time[dead]))
H0 <- cumsum(map_dbl(dt, \(t) {
  sum(vet$time == t & vet$status == 1) / sum(exp(coef(fit_breslow) * x[vet$time >= t]))
}))
bh <- basehaz(fit_breslow, centered = FALSE)
max(abs(bh$hazard[match(dt, bh$time)] - H0))
[1] 1.332268e-15

The hand calculation agrees with basehaz() to the precision of the computer.

22.6.5 A simulation with two baseline hazards

The estimate of \(\beta\) does not depend on the shape of \(h_0(t)\). We simulate 200 patients with a 0/1 covariate and a true hazard ratio of 2, under two baselines. One is constant, \(h_0(t) = 0.1\). The other increases with time, \(h_0(t) = 0.02\,t\). Censoring times are uniform from 0 to 20.

set.seed(1972)
beta_true <- log(2)
sims <- map_dfr(1:300, \(i) {
  n <- 200
  z <- rbinom(n, 1, 0.5)
  t_const <- rexp(n, 0.1 * exp(beta_true * z))                       # H0(t) = 0.1 t
  t_incr  <- sqrt(-log(runif(n)) / (0.01 * exp(beta_true * z)))      # H0(t) = 0.01 t^2
  cens <- runif(n, 0, 20)
  tibble(constant   = coef(coxph(Surv(pmin(t_const, cens), t_const <= cens) ~ z)),
         increasing = coef(coxph(Surv(pmin(t_incr, cens), t_incr <= cens) ~ z)))
})
summarise(sims, across(everything(), list(mean = mean, sd = sd)))
# A tibble: 1 × 4
  constant_mean constant_sd increasing_mean increasing_sd
          <dbl>       <dbl>           <dbl>         <dbl>
1         0.693       0.166           0.691         0.196

The true \(\beta\) is \(\log 2 =\) 0.693. The mean estimate is 0.693 with the constant baseline and 0.691 with the baseline that increases. The model estimated the hazard ratio without a model of \(h_0(t)\). The standard deviations (SDs) of the estimates differ. The precision depends on the number and the times of the deaths, and the baseline changes both.

22.7 Summary

  • The Cox model multiplies an unspecified baseline hazard by \(e^{x\beta}\), so \(e^{\beta_k}\) is the hazard ratio for 1 unit of \(x_k\).
  • The partial likelihood compares, at each death, the patient who died with the risk set. The baseline hazard cancels, so only the order of the deaths matters.
  • The proportional hazards assumption needs a check with Schoenfeld residuals. In the lung cancer trial, the effect of the Karnofsky score fades after the first months.
  • The log-rank test is the score test of the Cox model with one 0/1 covariate.