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:
q1
is the number of treated clusters.q0
is the number of control clusters.alpha
is the desired level of the test. Default isalpha=.05
.local=TRUE
looks 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:
x1
is a vector of cluster-level estimates from control clusters.x0
is a vector of cluster-level estimates from control clusters.alpha
is the desired level of the test.alphabar
will be calculated automatically ifalpha
is supplied as argument. Ifalphabar
is supplied, thenalpha
will be ignored.random=TRUE
computes 104 random permutations if the set of all permutations is larger than 104. Default isTRUE
.verbose=TRUE
provides 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.