Randomization inference (RI) is procedure for conducting hypothesis tests in randomized experiments. RI is useful for calculating the the probability that:

  • a test statistic would be as extreme or more as observed…
  • if a particular null hypothesis were true…
  • over the all the possible randomizations that could have occurred acccording to the design.

That probability is sometimes called a \(p\)-value.

Randomization inference has a beautiful logic to it that may be more appealing to you than traditional hypothesis frameworks that rely on \(t\)- or \(F\)-tests. For a really lovely introduction to randomization inference, read Chapter 3 of Gerber and Green (2012).

The hard part of actually conducting randomization inference is the accounting. We need to enumerate all (or a random subset of all) the possible randomizations, correctly implement the null hypothesis, maybe figure out the inverse probability weights, then calculate the test statistics over and over. You can do this by hand with loops. The ri2 package for r was written so that you don’t have to.1

Basic syntax

Gerber and Green (2012) describe a hypothetical experiment in which 2 of 7 villages are assigned a female council head and the outcome is the share of the local budget allocated to water sanitation. Their table 2.2 describes one way the experiment could have come out.

In order to conduct randomization inference, we need to supply 1) a test statistic, 2) a null hypothesis, and 3) a randomization procedure.

  1. The test statistic. The formula argument of the conduct_ri function is similar to the regression syntax of r’s built-in lm function. Our test statistic is the coefficient on Z from a regression of Y on Z, or more simply, the difference-in-means.
  2. The null hypothesis. The sharp_hypothesis argument of the conduct_ri function indicates that we are imagining a (hypothetical!) world in which the true difference in potential outcomes is exactly 0 for all units.
  3. The randomization procedure: The declare_ra function from the randomizr package allows us to declare a randomization procedure. In this case, we are assigning 2 units to treatment out of 7 total units.
## Loading required package: randomizr
## Loading required package: estimatr
##   coefficient estimate two_tailed_p_value null_ci_lower null_ci_upper
## 1           Z      6.5          0.3809524          -7.5            10

More complex designs

The ri2 package has specific support for all the randomization procedures that can be described by the randomizr package:

  1. Simple
  2. Complete
  3. Blocked
  4. Clustered
  5. Blocked and clustered

See the randomizr vignette for specifics on each of these procedures.

By way of illustration, let’s take the blocked-and-clustered design from the ri package help files as an example. The call to conduct_ri is the same as it was before, but we need to change the random assignment declaration to accomodate the fact that clusters of two units are assigned to treatment and control (within three separate blocks). Note that in this design, the probabilities of assignment to treatment are not constant across units, but the conduct_ri function by default incorporates inverse probability weights to account for this design feature.

##      Z
## block 0 1
##     1 2 2
##     2 2 4
##     3 4 4
## Random assignment procedure: Blocked and clustered random assignment 
## Number of units: 18 
## Number of blocks: 3 
## Number of clusters: 9 
## Number of treatment arms: 2 
## The possible treatment categories are 0 and 1.
## The probabilities of assignment are NOT constant across units. Your analysis strategy must account for differential probabilities of assignment, typically by employing inverse probability weights.
##   coefficient estimate two_tailed_p_value null_ci_lower null_ci_upper
## 1           Z        2          0.1944444     -2.055556      2.222222

Comparing nested models

A traditional ANOVA hypothesis testing framework (implicitly or explicitly) compares two models, a restricted model and an unrestricted model, where the restricted model can be said to “nest” within the unrestricted model. The difference between models is summarized as an \(F\)-statistic. We then compare the observed \(F\)-statistic to a hypothetical null distribution that, under some possibly wrong assumptions can be said to follow an \(F\)-distribution.

In a randomization inference framework, we’re happy to use the \(F\)-statistic, but we want to construct a null distribution that corresponds to the distribution of \(F\)-statistics that we would obtain if a particular (typically sharp) null hypothesis were true and we cycled through all the possible random assignments.

To do this in the ri2 package, we need to supply model formulae to the model_1 and model_2 arguments of conduct_ri.

Three Arm Trial

In this example, we consider a three-arm trial. We want to conduct the randomization inference analogue of an \(F\)-test to see if any of the treatments influenced the outcome. We’ll consider the sharp null hypothesis that each unit would express exactly the same outcome regardless of which of the three arms it was assigned to.

##   coefficient estimate two_tailed_p_value null_ci_lower null_ci_upper
## 1 F-statistic 1.532795              0.224    0.01821524      4.279474
## Analysis of Variance Table
## 
## Model 1: Y ~ 1
## Model 2: Y ~ Z
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1     99 77.748                           
## 2     97 75.366  2    2.3819 1.5328 0.2211

Interaction terms

Oftentimes in an experiment, we’re interested the difference in average treatment effects by subgroups defined by pre-treatment characteristics. For example, we might want to know if the average treatment effect is larger for men or women. If we want to conduct a formal hypothesis test, we’re not interested in testing against the sharp null of no effect for any unit – we want to test against the null hypothesis of constant effects. In the example below, we test using the null hypothesis that all units have a constant effect equal to the estimated ATE. See Gerber and Green (2012) Chapter 9 for more information on this procedure.

##          Z 
## -0.0223385

##   coefficient estimate two_tailed_p_value null_ci_lower null_ci_upper
## 1 F-statistic 12.81859                  0   0.001263264      4.696894
## Analysis of Variance Table
## 
## Model 1: Y ~ Z + X
## Model 2: Y ~ Z + X + Z * X
##   Res.Df     RSS Df Sum of Sq      F    Pr(>F)    
## 1     97 109.842                                  
## 2     96  96.903  1    12.939 12.819 0.0005406 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Arbitrary test statistics

A major benefit of randomization inference is we can specify any scalar test statistic, which means we can conduct hypothesis tests for estimators beyond the narrow set for which statisticians have derived the variance. The ri2 package accommodates this with the test_function argument of conduct_ri. You supply a function that takes a data.frame as its only argument and returns a scalar; conduct_ri does the rest!

Difference-in-variances

For example, we can conduct a difference-in-variances test against the sharp null of no effect for any unit:

## [1] 0.2464177

##             coefficient  estimate two_tailed_p_value null_ci_lower
## 1 Custom Test Statistic 0.2464177                  0    -0.1425035
##   null_ci_upper
## 1      0.145496

Balance Test

Researchers sometimes conduct balance tests as a randomization check. Rather than conducting separate tests covariate-by-covariate, we might be interested in conducting an omnibus test.

Imagine we’ve got three covariates X1, X2, and X3. We’ll get a summary balance stat (the \(F\)-statistic in this case), but it really could be anything!

##    value 
## 3.754223
## Warning in data.frame(est_sim = test_stat_sim, est_obs = test_stat_obs, :
## row names were found from a short variable and have been discarded

##             coefficient estimate two_tailed_p_value null_ci_lower
## 1 Custom Test Statistic 3.754223              0.004    0.06306746
##   null_ci_upper
## 1      2.990419
## 
## Call:
## lm(formula = Z ~ X1 + X2 + X3, data = dat)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.76657 -0.43393  0.07567  0.46852  0.83179 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.84068    0.11656   7.212 1.27e-10 ***
## X1           0.03668    0.05122   0.716  0.47567    
## X2          -0.11377    0.09782  -1.163  0.24769    
## X3          -0.09632    0.03145  -3.063  0.00284 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4828 on 96 degrees of freedom
## Multiple R-squared:  0.105,  Adjusted R-squared:  0.07703 
## F-statistic: 3.754 on 3 and 96 DF,  p-value: 0.01344

Conclusion

All of the randomization inference procedures had to, somehow or other, provide three pieces of information:

  1. a test statistic (the difference-in-means, a regression coefficient, the difference-in-variances, an \(F\)-statistic, etc.)
  2. a sharp null hypothesis. The “sharp” in this context means that the null hypothesis has something specific to say about every unit’s potential outcomes. For example, the sharp null hypothesis of no effect for any unit means hypothesizes that each unit’s treatment and control potential outcome are identical.
  3. A randomization procedure. We discussed simple, complete, blocked, clustered, and blocked and clustered designs, but these are not an exhaustive list of every kind of random assignment. Whatever your randomization procedure is, you have respect it!

Randomization inference is a useful tool because we can conduct hypothesis tests without making additional assumptions about the distributions of outcomes or estimators. We can also do tests for arbitrary test statistics – we’re not just restricted to the set for which statisticians have worked out analytic hypothesis testing procedures.

A downside is that RI can be a pain to set up – the ri2 package is designed to make this part easier.


  1. The ri2 package is the successor to the ri package, written by Peter Aronow and Cyrus Samii. ri was lightweight, fast, and correct for the set of tasks it handled. ri2 hopes to be all that and more.