Randomization inference, packaged (ri2)
Follow the analysis.
Select a node to explore the method
Declare the randomization
Data preparation — shapes the raw inputs into what the estimator expects.
Describe exactly how treatment was assigned (here complete randomization of 10 of 20 units) with randomizr.
# Install: install.packages("ri2")
library(ri2); library(randomizr)
dat <- data.frame(Y = rnorm(20), Z = c(rep(0,10), rep(1,10)))
decl <- declare_ra(N = 20, m = 10)
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.
Conduct randomization inference
Uncertainty quantification — standard errors, intervals, and aggregation.
conduct_ri re-randomizes thousands of times and compares the observed statistic to the exact reference distribution.
ri <- conduct_ri(Y ~ Z, declaration = decl, assignment = "Z",
sharp_hypothesis = 0, data = dat)
summary(ri)
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
Outcome Y, treatment Z, and a declaration of the randomization scheme.
Show data format & exampleHide example
| Y | Z |
|---|---|
| 0.8 | 0 |
| 1.4 | 1 |
| -0.2 | 0 |
| 0.9 | 1 |
Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.
The estimate
p=\frac{1}{|\Omega|}\sum_{z\in\Omega}\mathbf 1\big{|T(z,Y)|\ge|T^{\mathrm{obs}}|\big}
⚠️ Unofficial community showcase of ri2 (docs). Not affiliated with the authors — all credit to Alexander Coppock (DeclareDesign); this summarizes public documentation.
What it does. ri2 is the maintained, general-purpose implementation of the Fisher randomization test that anchors Peng Ding's design-based program: it computes exact p-values for the sharp null and sharp-null confidence intervals by re-running the actual assignment mechanism.
How it works. You declare how units were randomized with randomizr (declare_ra), then conduct_ri() re-randomizes thousands of times, recomputes the test statistic under each draw, and compares the observed statistic to that exact reference distribution. It handles blocks, clusters, and arbitrary statistics.
Assumptions. A known assignment mechanism and SUTVA; the basic test targets the sharp null of no effect for any unit.
Implements methods Prof. Ding is known for; package authored by Alexander Coppock.
What you get — An exact randomization p-value (and optionally a sharp-null confidence interval) for the estimate.
Example output
term estimate two_tailed_p_value
1 Z -0.214 0.612
Discuss the workflow (0)
Log in to join the discussion.