20 Parametric Two-Sample Comparison
20.1 Comparing two groups
Suppose individuals belong to one of two groups (e.g., two treatment arms, male/female, exposed/unexposed). We wish to test whether the survival distributions in the two groups are the same.
Let \(h_j(t)\) denote the hazard in group \(j\) (\(j = 1, 2\)). For each group, observe \((t_{ji}, \delta_{ji})\) for \(i = 1, \ldots, n_j\).
Define: - \(r_j = \sum_i \delta_{ji}\): number of events in group \(j\), - \(v_j = \sum_i t_{ji}\): total person-time in group \(j\).
20.2 Exponential two-sample model
Under the exponential model, \(h_j(t) = \lambda_j\) (constant), and the MLEs are \(\hat\lambda_j = r_j / v_j\) (from Chapter 19).
To compare the two groups, we use the hazard ratio \[ \psi = \frac{\lambda_2}{\lambda_1}, \] which is estimated by \(\hat\psi = \hat\lambda_2/\hat\lambda_1 = (r_2 v_1)/(r_1 v_2)\).
The log hazard ratio has an approximately normal distribution: \[ \log\hat\psi \;\dot\sim\; \mathrm{N}\!\left(\log\psi,\; \frac{1}{r_1} + \frac{1}{r_2}\right), \] giving a \(95\%\) confidence interval for \(\psi\): \[ \exp\!\left(\log\hat\psi \pm 1.96\sqrt{\frac{1}{r_1} + \frac{1}{r_2}}\right). \]
A likelihood ratio test of \(H_0: \psi = 1\) (equal hazards) uses \[ \Lambda = -2(\hat\ell_0 - \hat\ell_1) \;\dot\sim\; \chi^2_1 \] under \(H_0\), where \(\hat\ell_0\) is the maximised log-likelihood under \(\lambda_1 = \lambda_2\) and \(\hat\ell_1\) is the maximised log-likelihood with separate \(\lambda_j\).
20.3 Graphical check: the log-cumulative hazard
Before fitting any parametric model, it is important to check whether the chosen family is appropriate. For the exponential model: \[ H_j(t) = \lambda_j t \quad \Rightarrow \quad \log H_j(t) = \log\lambda_j + \log t. \]
A plot of \(\log\widehat{H}(t)\) against \(\log t\) should be linear with slope 1 for both groups. If the slopes differ from 1 but are equal to each other, a Weibull model with a common shape \(\gamma\) may be more appropriate.
For two groups with proportional hazards, \(\log H_2(t) - \log H_1(t) = \log\psi\) is constant, so the two curves should be parallel (a constant vertical gap). Do not expect perfect parallelism: the estimate \(\log\widehat{H}(t)\) rests on very few events at small \(t\), so it is noisy there, and curves can even cross early on. Judge parallelism over the range where each group has a reasonable number of events.
20.4 Weibull two-sample model
The exponential model forces a constant hazard in each group. A more flexible model allows the hazard to change over time while keeping the two groups comparable: take a common shape \(\gamma\) but different scales \(\lambda_1, \lambda_2\), so that \[ h_j(t) = \lambda_j \gamma t^{\gamma - 1}, \qquad H_j(t) = \lambda_j t^{\gamma}, \qquad S_j(t) = \exp(-\lambda_j t^{\gamma}). \] The exponential model is the special case \(\gamma = 1\).
20.4.1 The hazard ratio
As before, the hazard ratio is \[ \psi = \frac{\lambda_2}{\lambda_1}. \] Because the shape is shared, the factor \(\gamma t^{\gamma-1}\) cancels: \[ \frac{h_2(t)}{h_1(t)} = \frac{\lambda_2 \gamma t^{\gamma-1}}{\lambda_1 \gamma t^{\gamma-1}} = \psi \qquad \text{for all } t > 0. \] So the same properties hold as for the exponential model, even though the hazards themselves now vary with \(t\) (increasing if \(\gamma > 1\), decreasing if \(\gamma < 1\)):
- \(\psi\) is constant in \(t\): this is the proportional hazards (PH) property, explored in detail in Chapter 21.
- The cumulative hazards are also proportional, \(H_2(t) = \psi H_1(t)\), and the survival functions are related by \(S_2(t) = S_1(t)^{\psi}\).
- \(\psi > 1\) means group 2 has the higher hazard (worse survival) at every time, and \(\psi < 1\) the reverse; \(\psi = 1\) means the groups have identical survival distributions.
- On the log-cumulative hazard plot, \(\log H_j(t) = \log\lambda_j + \gamma\log t\), so the two groups give parallel straight lines with common slope \(\gamma\) and vertical gap \(\log\psi\).
If the shapes differ, \(\gamma_1 \neq \gamma_2\), the ratio \(h_2(t)/h_1(t) \propto t^{\gamma_2-\gamma_1}\) changes with \(t\) and the hazards are not proportional. Proportional hazards is therefore a consequence of the common-shape assumption, not of the Weibull family as such.
20.4.2 Estimation and inference
The log-likelihood with censoring is \[ \ell(\lambda_1,\lambda_2,\gamma) = \sum_{j=1}^{2}\Bigl\{ r_j\log(\lambda_j\gamma) + (\gamma-1)\sum_{i:\,\delta_{ji}=1}\log t_{ji} - \lambda_j\sum_i t_{ji}^{\gamma}\Bigr\}. \] For fixed \(\gamma\), maximising over \(\lambda_j\) gives \[ \hat\lambda_j(\gamma) = \frac{r_j}{\sum_i t_{ji}^{\gamma}}, \] and \(\hat\gamma\) is then found numerically by maximising the resulting profile log-likelihood. Writing \(\hat\lambda_j = \hat\lambda_j(\hat\gamma)\), the estimated hazard ratio is \[ \hat\psi = \frac{\hat\lambda_2}{\hat\lambda_1} = \frac{r_2 \sum_i t_{1i}^{\hat\gamma}}{r_1 \sum_i t_{2i}^{\hat\gamma}}. \] This is exactly the exponential formula \(\hat\psi = r_2 v_1/(r_1 v_2)\) with the person-times \(v_j\) replaced by \(\sum_i t_{ji}^{\hat\gamma}\). The reason is a useful fact: if \(T\) is Weibull with parameters \((\lambda,\gamma)\) then \(T^{\gamma}\) is exponential with rate \(\lambda\). For a known \(\gamma\), the Weibull two-sample problem is therefore the exponential two-sample problem on the transformed times \(t^{\gamma}\), and \[ \log\hat\psi \;\dot\sim\; \mathrm{N}\!\left(\log\psi,\; \frac{1}{r_1} + \frac{1}{r_2}\right) \] as before.
In practice \(\gamma\) is estimated, and this extra uncertainty is not captured by \(1/r_1 + 1/r_2\), which is then a lower bound for the variance of \(\log\hat\psi\). The interval \(\exp\bigl(\log\hat\psi \pm 1.96\sqrt{1/r_1+1/r_2}\bigr)\) is therefore somewhat too narrow, especially for small \(r_j\). For the correct standard error, use the observed information matrix of the full model (and the delta method), as software does; see the code below.
Likelihood ratio tests. Each is compared with \(\chi^2_1\):
- \(H_0: \psi = 1\) (no difference between groups, allowing a common Weibull shape): compare the model with common \(\lambda\) and \(\gamma\) (2 parameters) against the model with separate \(\lambda_j\) and common \(\gamma\) (3 parameters).
- \(H_0: \gamma_1 = \gamma_2\) (the common-shape, hence PH, assumption): compare common \(\gamma\) against separate \(\gamma_j\), each with separate \(\lambda_j\) (3 versus 4 parameters). A small \(p\)-value is evidence against proportional hazards within the Weibull family, and is a formal counterpart of the parallel-lines check above.
- \(H_0: \gamma = 1\) (exponential is adequate): compare the Weibull and exponential fits within the model.
20.5 Fitting in R
Code
library(survival)
# Fit separate exponential models
fit1 <- survreg(Surv(t1, delta1) ~ 1, dist = "exponential")
fit2 <- survreg(Surv(t2, delta2) ~ 1, dist = "exponential")
# Or jointly using a group explanatory variable
# (see Chapter 22 for regression interpretation)
d <- data.frame(t = c(t1, t2), delta = c(d1, d2),
group = c(rep(0, n1), rep(1, n2)))
fit_joint <- survreg(Surv(t, delta) ~ group, data = d,
dist = "exponential")
summary(fit_joint)
# coefficient on 'group' = -log(psi)/gamma, and gamma=1 for exponential
# (note: sign convention depends on parametrisation)For the Weibull two-sample model, fit with dist = "weibull" and convert from the AFT output to the PH hazard ratio using the box above:
Code
fit_w <- survreg(Surv(t, delta) ~ group, data = d, dist = "weibull")
summary(fit_w)
gamma_hat <- 1 / fit_w$scale # common shape
beta_aft <- coef(fit_w)["group"] # AFT coefficient
psi_hat <- exp(-gamma_hat * beta_aft) # hazard ratio
# Likelihood ratio test of psi = 1 (common shape in both models)
fit_w0 <- survreg(Surv(t, delta) ~ 1, data = d, dist = "weibull")
anova(fit_w0, fit_w)Exercises
20.1. A randomised trial compared two surgical approaches for a procedure, measuring operating time (minutes) until the surgeon achieved an adequate result. Times marked \(^*\) are right-censored: the procedure was stopped without achieving the result, either because the 120-minute time limit was reached or (for the robot-assisted observation at 66 minutes) because it was abandoned early for an unrelated reason:
- Group 1 (robot-assisted): 50, 51, 66\(^*\), 82, 92, 120\(^*\), 120\(^*\), 120\(^*\)
- Group 2 (traditional): 63, 65, 69, 69, 79, 82, 82, 120\(^*\)
Write R code to enter these data and produce a single plot showing the Kaplan–Meier survival curves for both groups, with appropriate labels, a legend, and 95% confidence intervals.
Based on the KM curves, which surgical approach achieves the adequate result sooner? Comment on the degree of overlap of the confidence intervals.
Use survfit(Surv(t, d) ~ group) and then plot() with col, lty, and legend(). A lower KM curve means events occur sooner; in this context that is the favourable outcome.