Skip to contents

vignette("model", package = "retrogroup") derives \(p_{ik}\), an estimate of the posterior probability that patient \(i\) belongs to subgroup level \(k\) (\(i = 1, \ldots, n\), \(k = 1, \ldots, K\)). This vignette explains a method to sample subgroup levels \(x_1, \ldots, x_n\) given fixed posterior probability estimates \(p_{ik}\).

Over a large number of simulations, subgroup hazard ratios computed on the simulated datasets should approximately match the assumed hazard ratios on average, provided the patient-level data are consistent with the model. However, each individual simulated dataset is subject to random variation and may not exactly match the assumed statistics. vignette("optimization", package = "retrogroup") defines methods to refine an individual dataset so the observed and assumed subgroup hazard ratios match.

Unconstrained sampling

If we treat subgroup levels as unconstrained, each \(x_i\) has its own independent categorical distribution with probabilities \(p_{i1}, \ldots, p_{iK}\). Independently for each patient \(i = 1, \ldots, n\), we draw:

\[ x_i \sim \text{Categorical}(p_{i1}, \ldots, p_{iK}) \]

Unconstrained sampling is simple, but it does not guarantee that the resulting subgroup assignments match \(n_k\), the assumed number of patients in each subgroup level \(k\) from vignette("framing", package = "retrogroup"). To preserve the subgroup sample sizes, we need constrained sampling.

Constrained sampling

Constrained sampling forces the sampled subgroup levels to match the assumed sample size \(n_k\) for each subgroup level \(k\). To preserve these counts, we iterate through a random permutation of patients and assign each one to a random subgroup level with fewer than \(n_k\) patients.

Let \(\rho_1, \ldots, \rho_n\) be a random permutation of patient indexes \(1, \ldots, n\). At arbitrary patient \(\rho_j\) (\(j = 1, \ldots, n\)), patients \(\rho_1, \ldots, \rho_{j-1}\) have already been assigned to subgroup levels, with \(n^*_{jk}\) patients in subgroup level \(k\) so far:

\[ n^*_{jk} := \sum_{h = 1}^{j - 1} I(x_{\rho_h} = k) \]

We draw \(x_{\rho_j}\) from a categorical distribution:

\[ x_{\rho_j} \sim \text{Categorical}(q_{{\rho_j}1}, \ldots, q_{{\rho_j}K}) \]

where probabilities \(q_{{\rho_j}k}\) are normalized versions of \(p_{{\rho_j}k}\) that exclude subgroup levels that have already reached their assumed counts:

\[ q_{{\rho_j}k} := \begin{cases} \dfrac{p_{{\rho_j}k}}{\sum_{l = 1}^K I(n^*_{jl} < n_l) p_{{\rho_j}l}}, & \text{if } n^*_{jk} < n_k \\ 0, & \text{if } n^*_{jk} = n_k \end{cases} \]

We assume \(\sum_{k = 1}^K n_k = n\), so at least one subgroup level has room at every step. Every \(p_{ik}\) is strictly positive, as shown in vignette("model", package = "retrogroup"), so the denominator above is positive. This scheme guarantees the assumed counts, but it is only an approximate draw from independent categorical distributions conditional on those counts, because patients late in the permutation can only join subgroup levels that still have room.

Constrained sampling preserves the sample sizes \(n_k\) but does not guarantee the event counts \(e_k\). The event counts enter only through the estimated prognostic effects \(\hat{\gamma}_k\) from vignette("estimates", package = "retrogroup"), and the loss function in vignette("optimization", package = "retrogroup") targets hazard ratios only, so the observed event counts are not guaranteed to match. vignette("prognostic", package = "retrogroup") examines the prognostic information of reconstructed subgroups.