Brandon LeBeau
  • Educate-R
  • Publications
  • Presentations
  • R Packages
  • Workshops
  • About

On this page

    • Randomizing a training trial within warehouses
    • Fixing the two-sided power cutoff

simglm 1.0.1 adds blocked randomization

R
simglm
package
power analysis
Simulate equal treatment allocation within blocks and apply the correct cutoff for two-sided p-values in power simulations.
Author

Brandon LeBeau

Published

December 3, 2026

I just released simglm 1.0.1. It adds a way to randomize treatments in equal numbers within each block of a nested design and fixes how compute_statistics() handles two-sided p-values. Feature request · Bug report

Randomizing a training trial within warehouses

Suppose a company wants to test whether a new training program reduces the time it takes workers to pack a standard order. Three warehouses enroll 12, 16, and 20 workers. Within each warehouse, half the workers are randomly assigned to the new training and half to the standard training.

In simglm, force_equal = TRUE balances the two training groups across the full sample by default. Adding balance_by = "warehouse" applies that balance separately within each warehouse. Simulation arguments vignette

The full code example is shown below.

library(simglm)

set.seed(42)

sim_args <- list(
  formula = packing_minutes ~ training + (1 | warehouse),
  fixed = list(training = list(
    var_type = "factor",
    levels = c("Standard", "New"),
    force_equal = TRUE,
    balance_by = "warehouse"
  )),
  reg_weights = c(15, -2),
  randomeffect = list(
    warehouse_shift = list(variance = 1.5^2, var_level = 2)
  ),
  error = list(variance = 2^2, dist = "rnorm"),
  sample_size = list(level1 = c(12, 16, 20), level2 = 3)
)

trial <- simglm(sim_args)
with(trial, table(warehouse, training))
         training
warehouse Standard New
        1        6   6
        2        8   8
        3       10  10

The warehouses assign 6, 8, and 10 workers per training group, respectively. This is exactly half of the number of workers for each warehouse. Each simulation draws a new assignment while keeping those counts fixed. For exact balance, each block’s number of assignment units must be divisible by the number of treatment groups.

Fixing the two-sided power cutoff

compute_statistics() now compares an already two-sided p-value directly with the specified alpha. At alpha = 0.05, a replicate with a two-sided p-value of 0.04 now counts as a rejection when estimating power. Version 1.0.0 used a cutoff of 0.025 for that comparison, which could underestimate power. Issue #117

 

Brandon LeBeau