Why Simulate Stratified Randomization?
Randomization protects a trial from systematic treatment-assignment bias, but it does not guarantee that every realized allocation will have similar treatment groups. In a small trial, randomization can leave an important prognostic characteristic unevenly distributed across arms. Stratification addresses this concern by randomizing participants separately within categories of selected baseline factors. Its practical value depends on the trial size, the factors used, the allocation procedure, and the outcomes being analyzed.
A simulation can compare allocation procedures under the same hypothetical trial scenarios. It can show how often a clinically relevant imbalance occurs, how much precision changes, and whether subgroup effects remain estimable. The goal is not to find a randomization scheme that balances every characteristic in every trial. It is to assess whether a prespecified scheme performs well enough across plausible realizations.
What Balance Means
Balance is not one number that captures every design objective. For a binary stratum, one simple measure is the difference between the numbers assigned to treatment and control within that stratum. For a continuous covariate, an often-used scale-free summary is the standardized mean difference: the difference between treatment-group means divided by a reference standard deviation. For a categorical factor, one can compare arm-specific proportions in each category. These summaries describe observed allocation; they do not establish that the groups are identical on all prognostic factors.
For subgroup assessment, also record the treatment and control sample sizes within each subgroup. A small overall imbalance may coexist with a very small treatment or control cell in a rare subgroup. Such a cell can make a subgroup estimate imprecise or difficult to estimate, even if the overall allocation ratio is close to its target.
Before simulating, specify which factors are important enough to guide randomization, how strata are constructed, and which balance summaries matter. A factor should generally be measured before treatment and have a credible relationship to outcome or to the scientific subgroup question. Including many categories or combinations can create numerous sparse strata, making allocation difficult and the design less useful.
Allocation Variability: A Small-Trial Derivation
Consider a hypothetical trial with 40 participants: 20 in each of two strata. Suppose unstratified complete randomization assigns exactly 20 participants to each treatment group. Let \(X\) be the number of treatment participants in the first stratum. Because 20 of the 40 participants receive treatment, the treatment group is a random sample of 20 from the 40. Thus \(X\) has a hypergeometric distribution with population size 40, 20 members in the first stratum, and sample size 20.
For a hypergeometric count with population size \(N\), \(K\) members of the category of interest, and sample size \(n\), the mean is \(nK/N\) and the variance is \(n(K/N)(1-K/N)((N-n)/(N-1))\). Applying that result here gives:
The difference between the treatment and control counts in that stratum is \(D= X-(20-X)=2X-20\). Therefore, multiplying a random variable by 2 multiplies its standard deviation by 2:
The expected difference is zero, but that does not mean the realized difference will be zero. Under stratified randomization with exactly 10 participants assigned to each arm in each stratum, this particular count difference is zero by design. Other covariates and chance outcome variation remain. This calculation isolates one source of imbalance; it is not a claim that stratification guarantees overall comparability.
Worked Examples
Worked Example: Comparing Stratum Imbalance in a Small Trial
A hypothetical trial has 40 participants, 20 in each of two severity strata, and allocates 20 participants to each arm. Under unstratified complete randomization, suppose 12 participants from the first stratum receive treatment. Find the stratum-specific count difference and the treatment-group proportions from this stratum.
There are \(20-12=8\) control participants from the first stratum. The treatment-minus-control count difference is \(12-8=4\) participants. The first stratum makes up \(12/20=0.60\) of the treatment arm and \(8/20=0.40\) of the control arm, a difference of \(0.20\), or 20 percentage points.
With stratified allocation of 10 participants per arm within each stratum, both arms would have a first-stratum proportion of \(10/20=0.50\). That balances this stratification factor in this allocation, but says nothing by itself about continuous covariates, other prognostic factors, or outcomes.
Worked Example: Overall and Subgroup Precision
Consider a hypothetical stratified trial with two equally sized strata and 10 participants in each treatment arm within each stratum. Suppose the estimated treatment effects are 4 units in stratum 1 and 6 units in stratum 2. Assume the outcome standard deviation is 4 units in every treatment-by-stratum cell, with independent outcomes. Calculate the equally weighted overall effect and its standard error, and calculate the standard error of either stratum-specific effect.
The equally weighted overall estimate is \(0.5(4)+0.5(6)=5\) outcome units. For a difference of independent treatment and control means in one stratum, the variance is \(\sigma^2/n_T+\sigma^2/n_C\). Here this is \(16/10+16/10=3.2\), so the standard error for either subgroup effect is \(\sqrt{3.2}=1.789\) outcome units.
For the equally weighted overall estimate, the stratum estimates are independent and each receives weight 0.5. Its variance is \(0.5^2(3.2)+0.5^2(3.2)=1.6\), giving a standard error of \(\sqrt{1.6}=1.265\) outcome units. These calculations assume the stated cell sizes, equal within-cell variances, and independent outcomes. They illustrate that a subgroup effect is less precise than the weighted overall estimate in this example; the result is not a universal ordering for every design or estimand.
Worked Example: Simulating Small- and Large-Trial Balance
Suppose investigators simulate a hypothetical trial with two equally sized severity strata and a fixed 1:1 overall allocation. They compare unstratified complete randomization with stratified allocation, using 2,000 independent randomizations for each design and trial size. In each replicate, they record whether the absolute difference in the proportion of each arm from the higher-severity stratum exceeds 0.25. In the small-trial scenario, there are 40 participants; in the large-trial scenario, there are 400.
Suppose the simulated exceedance counts are 694 of 2,000 under unstratified randomization and 418 of 2,000 under stratified randomization for the small trial. The estimated exceedance proportions are \(694/2000=0.347\) and \(418/2000=0.209\), respectively. The estimated reduction is \(0.347-0.209=0.138\), or 13.8 percentage points. Stratification reduces, but does not eliminate, the simulated frequency of this imbalance threshold.
For the large trial, suppose the corresponding counts are 112 and 39. The estimated proportions are \(112/2000=0.0560\) and \(39/2000=0.0195\), a reduction of 0.0365, or 3.65 percentage points. The threshold was exceeded less often in the large-trial scenario under both procedures. These values are hypothetical simulation outputs, not universal operating characteristics. To quantify Monte Carlo uncertainty for the small-trial stratified estimate, its Monte Carlo standard error is approximately \(\sqrt{0.209(1-0.209)/2000}=0.00910\). The simulation should also compare precision and subgroup cell sizes; a balance threshold alone does not determine which design is preferable.
Connecting Balance to Precision
Balance matters for precision when the imbalanced factor predicts the outcome. To see the connection, suppose a continuous outcome follows the simple model \(Y=\mu+\tau A+\gamma S+\varepsilon\), where \(A\) indicates treatment, \(S\) indicates stratum, \(\tau\) is a common treatment effect, \(\gamma\) is the stratum difference, and the errors have mean zero. The unadjusted difference in overall treatment and control means contains both the treatment contrast and a term due to different stratum composition:
If the stratum proportions differ, the term \(\gamma(\bar{S}_T-\bar{S}_C)\) adds variation to the unadjusted contrast. When \(\gamma=0\), this particular composition term vanishes; when \(\gamma\) is large, a given imbalance can matter more. Stratified allocation can reduce variation in the composition term. An analysis that adjusts for the strata can also account for their prognostic contribution, but that is not the same as changing the allocation that occurred.
For an overall effect defined as a weighted average of stratum-specific effects, let \(W_s\) be the target weight for stratum \(s\), with weights summing to 1. Under independent observations and fixed treatment and control counts within each stratum, an estimator is \(\hat{\tau}=\sum_s W_s(\bar{Y}_{Ts}-\bar{Y}_{Cs})\). Its variance is:
This formula requires independent outcome observations, the specified fixed cell sizes, and finite variances within each treatment-by-stratum cell. It shows why subgroup precision depends on both the within-stratum variability and the numbers assigned to each arm in that stratum. Stratification can stabilize those counts for selected factors; it cannot create information in a rare subgroup unless the design assigns enough participants there.
Designing and Checking the Simulation
A useful comparison holds the clinical scenario and analysis fixed while changing the allocation rule. For each simulated trial, generate baseline strata and other covariates, randomize participants according to the specified procedure, generate outcomes under a stated treatment-effect model, and apply the planned analysis. Repeat the process independently enough times to estimate the desired operating characteristics with useful Monte Carlo precision.
State whether the target is an overall effect, a subgroup effect, or both. Vary trial size, stratum prevalence, prognostic strength, and treatment-effect heterogeneity across plausible scenarios.
For example, compare fixed 1:1 complete randomization with separate 1:1 allocation within each prespecified stratum. If the actual design uses blocks, simulate the intended block procedure rather than assuming exact balance without specifying how it is achieved.
Track arm-specific stratum counts, continuous-covariate summaries, subgroup cell sizes, and the frequency of prespecified imbalance thresholds.
For overall and subgroup effects, summarize bias, empirical standard deviation, average estimated standard error, and interval coverage as appropriate to the planned analysis.
Verify that allocation totals and stratum definitions are correct in every replicate. Report simulation uncertainty for estimated proportions and increase the number of replicates when it is too large for the decision being made.
The simulation should distinguish randomization balance from outcome precision. A design may greatly reduce imbalance in a selected factor but make little difference to precision if that factor is weakly prognostic. Conversely, the overall effect may become more precise while a rare subgroup effect remains highly uncertain. Examine distributions across replicates, not just average values: tail probabilities and occasional very small subgroup cells may be important.
Alternatives, Diagnostics, and Limitations
The main alternative is unstratified randomization followed by an analysis that adjusts for prognostic baseline covariates. This preserves unrestricted allocation across the trial while accounting for measured covariates in the analysis; it does not guarantee realized balance. Stratification changes allocation and can ensure intended balance on the selected factors when allocation is constrained within strata. The approaches address related but distinct parts of the design and analysis, and can be combined when the analysis appropriately accounts for the design.
Warning signs in a simulation include unexpectedly unequal total allocations, missing or misclassified strata, subgroup cells with zero or very few participants, and differences between the intended and implemented randomization procedure. Also inspect whether the simulated treatment effects and outcome variability match the stated assumptions. If every replicate appears perfectly balanced on every covariate, check for coding that inadvertently uses future or outcome information in allocation.
Stratification has limitations. It balances only the factors used to define strata, and only to the extent enforced by the chosen procedure. Many factors or many category combinations can produce a large number of small strata. Chance imbalances on unstratified factors remain, and imbalances in prognostic variables can still occur within a stratum. Moreover, a design that balances a factor does not remove the need to define the overall and subgroup effects clearly or to analyze the trial in a way consistent with its design.
Common Mistake
Check Your Understanding
Try each question, then compare your reasoning with the solutions below.
- In a trial with 30 participants in each of two strata and 30 participants assigned to treatment overall, \(X\) denotes the treatment count in the first stratum under unstratified complete randomization. What is \(E(X)\), and does it imply exact balance in the realized trial?
- Why can stratification improve overall precision when a stratification factor predicts outcome?
- A rare subgroup has 8 participants in each arm in a simulated trial. Is the subgroup effect necessarily precise because the overall trial allocation is balanced? Explain.
- Name two simulation diagnostics that can reveal a faulty implementation of stratified randomization.
Solutions. (1) \(E(X)=30(30/60)=15\), but an expected count of 15 does not imply that every realized allocation has 15 treatment participants in the first stratum. (2) If the factor predicts outcome, unequal stratum composition contributes variation to an unadjusted treatment contrast; reducing that composition imbalance can reduce this source of variation. (3) No. Eight participants per arm may still yield a highly imprecise subgroup estimate, depending on outcome variability and the effect model; overall balance does not supply additional subgroup information. (4) Check that each replicate has the intended total and within-stratum allocation counts, and check that all participants are assigned to exactly one correctly classified stratum. Comparing the observed allocation frequencies with the specified randomization rule is another useful check.