Reproducible random assignment — simple, complete, block, cluster, stratified — with the exact assignment probabilities design-based inference needs.
Input · what goes in
The number of units (and optional block/cluster IDs and target sizes).
Show data format & exampleHide example
| unit | block |
|---|---|
| 1 | A |
| 2 | A |
| 3 | B |
| 4 | B |
Pipeline · the recipe
↑ Click any step in the diagram to read its logic, code, assumptions & discussion.
Define the blocks
Data preparation — shapes the raw inputs into what the estimator expects.
Set up strata (blocks) within which treatment will be balanced.
# Install: install.packages("randomizr")
library(randomizr)
blocks <- rep(c("A", "B"), each = 5)
- No comments on this step yet — be the first.
Log in to comment on this step.
Block-randomize and recover probabilities
The core estimate — where the causal quantity itself is computed.
block_ra assigns treatment within each block; block_ra_probabilities returns the exact assignment probabilities.
Z <- block_ra(blocks = blocks)
prob <- block_ra_probabilities(blocks = blocks)
table(blocks, Z)
- No comments on this step yet — be the first.
Log in to comment on this step.
Output · what you get
Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.
Result · the numbers
⚠️ Unofficial community showcase of randomizr (docs). Not affiliated with the authors — all credit to Alexander Coppock & Jasper Cooper (DeclareDesign); this summarizes public documentation.
What it does. randomizr generates the random-assignment procedures that underpin design-based causal inference (the assignment mechanisms whose finite-population properties Peng Ding studies — blocking, complete randomization, rerandomization-compatible designs).
How it works. Functions like complete_ra(), block_ra() and cluster_ra() draw assignments with exactly controlled probabilities, and the matching *_probabilities() functions return each unit's assignment probability — the inverse-probability weights and design information needed for unbiased Neyman/Horvitz–Thompson estimation and randomization inference.
Assumptions. None statistical — it is the assignment mechanism; correct use makes the design known and replicable.
Implements design-based tools associated with Prof. Ding's work; package authored by the DeclareDesign team.
What you get — A reproducible assignment vector plus the exact per-unit assignment probabilities for design-based estimation.
Example output
Z
blocks 0 1
A 2 3
B 3 2

Discussion (0)
Log in to join the discussion.