R code for “Permutation inference with a finite number of heterogeneous clusters”
This page provides R code for “Permutation inference with a finite number of heterogeneous clusters” [PDF].
Download: hagemann_ap.R
Include this file in R with include('hagemann_ap.R'). Alternatively, load it into R directly with
include('https://hgmn.github.io/assets/hagemann_ap.R')
The code supplies two functions:
ApAlphaBar returns α̅ as in Table 1 of the paper for combinations of q1 and q0 up to 32 by accessing this list. It has the following arguments:
q1is the number of treated clusters.q0is the number of control clusters.alphais the desired level of the test. Default isalpha=.05.local=TRUElooks for critial value tables in the working directory if set toTRUE. Default isFALSE.
ApTest calculates the test decision as in Algorithm 3.3. It has the following arguments:
x1is a vector of cluster-level estimates from control clusters.x0is a vector of cluster-level estimates from control clusters.alphais the desired level of the test.alphabarwill be calculated automatically ifalphais supplied as argument. Ifalphabaris supplied, thenalphawill be ignored.random=TRUEcomputes 104 random permutations if the set of all permutations is larger than 104. Default isTRUE.verbose=TRUEprovides a verbal summary of the test decision. Otherwise the value is a 1/0 decision. Default isTRUE.
The code also contains two auxiliary functions for generating permutations.