--- title: "Approximating event counts using confidence intervals of assumed hazard ratios" output: rmarkdown::html_vignette bibliography: ../inst/bibliography.bib vignette: > %\VignetteIndexEntry{Approximating event counts using confidence intervals of assumed hazard ratios} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` ```{r setup} library(retrogroup) ``` The methods in this package assume the subgroup-level event counts $e_1, \ldots, e_K$ are available. `retrogroup` uses these event counts to estimate prognostic effects for the model used to sample subgroup levels (see `vignette("estimates", package = "retrogroup")`). However, these counts are not always published in the literature. This appendix vignette defines a method for approximating them using two-sided confidence intervals of the subgroup-level hazard ratios, implemented in the `group_data_events()` function. Notation follows `vignette("framing", package = "retrogroup")`. The method takes the following as input: 1. $(b_k^-, b_k^+)$, a two-sided confidence interval for the hazard ratio $\exp(\beta_k)$, for each subgroup level $k = 1, \ldots, K$. 2. The confidence level $1 - \alpha$ of the two-sided confidence interval above. 3. The treatment assignments $z_i$ for each patient $i = 1, \ldots, n$. 4. The event indicator $d_i$ for each patient $i = 1, \ldots, n$. 5. The subgroup sample sizes $n_1, \ldots, n_K$. Because $(b_k^-, b_k^+)$ is a $1 - \alpha$ confidence interval for $\exp(\beta_k)$, the interval $(\log(b_k^-), \log(b_k^+))$ is a $1 - \alpha$ confidence interval for $\beta_k$. We assume $(b_k^-, b_k^+)$ is a Wald confidence interval computed on the log scale and thus $(\log(b_k^-), \log(b_k^+))$ is symmetric about $\beta_k$, as is standard for hazard ratios from a Cox model. In terms of the standard error $\sigma_k$ of $\beta_k$: $$ \log(b_k^-) = \beta_k - c \sigma_k \qquad \qquad \log(b_k^+) = \beta_k + c \sigma_k $$ where $c := \Phi^{-1}(1 - \alpha / 2)$ is the $(1 - \alpha/2)$ quantile of the standard normal distribution. The two equations above imply the following expression for the variance $\sigma_k^2$: $$ \sigma_k^2 = \frac{\left ( \log(b_k^+) - \log(b_k^-) \right )^2}{4c^2} $$ Following @parmar1998 and @tierney2007, we use an approximation of the variance $\sigma_k^2$ that goes back to @schoenfeld1983: $$ \sigma_k^2 \approx \frac{1}{e_k \bar{z} (1 - \bar{z})} $$ where $\bar{z}$ is the proportion of patients randomized to treatment: $$ \bar{z} := \frac{1}{n}\sum_{i = 1}^n z_i $$ The treatment allocation within each subgroup level is generally not available, so we use the overall proportion $\bar{z}$ for every level $k$, an assumption that randomization supports. Equating the two expressions for $\sigma_k^2$ and solving for $e_k$, we find: $$ \begin{aligned} \frac{\left ( \log(b_k^+) - \log(b_k^-) \right )^2}{4c^2} &\approx \frac{1}{e_k \bar{z} (1 - \bar{z})}\\ e_k &\approx \frac{1}{\bar{z} (1 - \bar{z})} \frac{4c^2}{\left ( \log(b_k^+) - \log(b_k^-) \right )^2} \end{aligned} $$ The result is approximate for at least two reasons. First, the treatment allocation within level $k$ may differ from the overall proportion $\bar{z}$, especially in small subgroups, if randomization is not stratified within subgroup. Second, publications round confidence bounds, usually to two decimal places, which can change $e_k$ noticeably when the confidence interval is narrow. There may be other reasons not listed here, and some may cause stronger deviations. These approximate event counts are generally not integers, they do not necessarily sum to the total number of events in the patient-level data, and they may exceed the subgroup sample sizes. So `retrogroup` reconciles them deterministically, separately for each subgroup variable. First, it rounds each approximate count to the nearest integer and clamps it to the interval $[0, n_k]$. Then it makes passes over the levels $k = 1, \ldots, K$ in order. In each pass, it adds 1 to each level with $e_k < n_k$ if the counts sum to less than $\sum_{i = 1}^n d_i$, or subtracts 1 from each level with $e_k > 0$ if they sum to more, stopping as soon as $\sum_{k = 1}^K e_k = \sum_{i = 1}^n d_i$. The result satisfies $0 \le e_k \le n_k$ for each level $k$. A solution exists if and only if $\sum_{i = 1}^n d_i \le \sum_{k = 1}^K n_k$, which always holds when $\sum_{k = 1}^K n_k = n$. This is only one of many possible ways to reconcile the counts. The final choice is up to the judgment of the statistician, and any downstream subgroup analyses should explicitly state the subgroup event counts used and how they were chosen. ## Usage `group_data_events(patient, summary, lower, upper, confidence = 0.95)` takes the output of `group_data_patient()`, the output of `group_data_summary()` with `events = NULL`, vectors `lower` and `upper` of confidence bounds $b_k^-$ and $b_k^+$ with one element per row of `summary`, and the confidence level $1 - \alpha$. It returns a copy of `summary` with the reconciled event counts, ready for the rest of the workflow. ```{r} patient <- group_data_patient( group_example_patient(), arm = "arm", treatment = "Lev+5FU", time = "time", event = "event" ) data <- group_example_summary() summary <- group_data_summary( data, variable = "variable", level = "level", patients = "patients", events = NULL, hazard_ratio = "hazard_ratio" ) group_data_events(patient, summary, lower = data$lower, upper = data$upper) ``` ## References