Skip to content
StatsOtter A workspace for causal thinking
Method library WORKFLOW / 077
Research workflow/2 steps

Randomization inference, packaged (ri2)

01
The method workspace

Follow the analysis.

Select a node to explore the method

Method mapInput → 2 steps → output
START WITHInput data
ARRIVE ATResults
Read step 01
Inside the methodReasoning, equations & implementation
Step 1 of 2
01
Data prep

Declare the randomization

Data preparation — shapes the raw inputs into what the estimator expects.

What happens here

Describe exactly how treatment was assigned (here complete randomization of 10 of 20 units) with randomizr.

Reads fromNot specified Feeds into#2
Key code
# 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)

Reference / docs ↗

Discussion on this step (0)
StatsOtterDiscussion starter · Editorial note

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
  1. Which assumption matters most here, and what evidence could challenge it?
  2. What would you check before passing this output to the next step?

Peer discussion

  • Bring your experience, a question, or a different perspective.
02
Data contract

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
03
Read the evidence

Results & interpretation

1 figure Workflow discussion 0
01FigureRandomization distribution of the test statistic under the sharp null, with the observed estimate marked (exact p-value).

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}

Context & interpretation

⚠️ 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

Links: package · paper

Peer notes

Discuss the workflow (0)

  • No comments yet — start the conversation.
IN THE MARGINS

Peer discussion