StatsOtter Causal inference workflows
11
Workflow·2 steps

Randomization inference, packaged (ri2)

Summary by StatsOtter

Exact Fisher randomization tests and sharp-null confidence intervals for any randomization scheme — the packaged version of the design-based test.

1

Input · what goes in

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
2

Pipeline · the recipe

↑ Click any step in the diagram to read its logic, code, assumptions & discussion.

1
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 from the input data 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)
  • No comments on this step yet — be the first.
2
Inference

Conduct randomization inference

Uncertainty quantification — standard errors, intervals, and aggregation.

What happens here

conduct_ri re-randomizes thousands of times and compares the observed statistic to the exact reference distribution.

Formula
p=\frac{1}{|\Omega|}\sum_{z\in\Omega}\mathbf 1\big\{|T(z,Y)|\ge|T^{\mathrm{obs}}|\big\}
Reads from #1 Feeds into the final output
Key code
ri <- conduct_ri(Y ~ Z, declaration = decl, assignment = "Z",
                 sharp_hypothesis = 0, data = dat)
summary(ri)

Reference / docs ↗

Discussion on this step (0)
  • No comments on this step yet — be the first.
3

Output · what you get

Randomization distribution of the test statistic under the sharp null, with the observed estimate marked (exact p-value).
Fig 1Randomization 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.

Result · the numbers

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

Links: package · paper

Discussion (0)

  • No comments yet — start the conversation.