Random assignment by design (randomizr)
Follow the analysis.
Select a node to explore the method
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)
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
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)
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
Log in to comment on this step.
Inputs & data
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 |
Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.
The estimate
\pi_i=\Pr(Z_i=1),\qquad \hat\tau_{\mathrm{HT}}=\frac1N\sum_i\Big(\frac{Z_i Y_i}{\pi_i}-\frac{(1-Z_i)Y_i}{1-\pi_i}\Big)
⚠️ 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
Discuss the workflow (0)
Log in to join the discussion.