ri (version 0.9)

genperms: Generates a permutation matrix for blocked, clustered (or simpler) designs

Description

Given complete randomization of clusters (even of length 1) in blocks (even of length N), genperms() produces either an exact or approximate permutation matrix. When the number of actual permutations exceeds a user specified value (maxiter), the function produces an approximate permutations matrix via repeated randomization

Usage

genperms(Z, blockvar = NULL, clustvar = NULL, maxiter = 10000)

Arguments

Z
binary vector (0 or 1) of N-length, treatment indicator
blockvar
positive integer vector of N-length, with unique values indicating different blocks
clustvar
positive integer vector of N-length, with unique values indicating different clusters
maxiter
maximum number of permutations to be included in the permutation matrix

Value

N-by-r permutation matrix, where r is the smaller of maxiter and the true number of permutations

Warning

genperms may use large amounts of memory and computational power, and may not be well-suited for large datasets. We recommend starting with maxiter set at low values before attempting to create a permutation matrix with a large number of permutations.

References

Gerber, Alan S. and Donald P. Green. 2012. Field Experiments: Design, Analysis, and Interpretation. New York: W.W. Norton.

Examples

Run this code
y <- c(8,6,2,0,3,1,1,1,2,2,0,1,0,2,2,4,1,1) 
Z <- c(1,1,0,0,1,1,0,0,1,1,1,1,0,0,1,1,0,0)
cluster <- c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9)
block <- c(rep(1,4),rep(2,6),rep(3,8))

perms <- genperms(Z,blockvar=block, clustvar=cluster) # all possible permutations
probs <- genprobexact(Z,blockvar=block, clustvar=cluster) # probability of treatment
ate <- estate(y,Z,prob=probs) # estimate the ATE

## Conduct Sharp Null Hypothesis Test of Zero Effect for Each Unit

Ys <- genouts(y,Z,ate=0) # generate potential outcomes under sharp null of no effect
distout <- gendist(Ys,perms, prob=probs) # generate sampling dist. under sharp null
dispdist(distout, ate)  # display characteristics of sampling dist. for inference

## Generate Sampling Distribution Around Estimated ATE

Ys <- genouts(y,Z,ate=ate) ## generate potential outcomes under tau = ATE
distout <- gendist(Ys,perms, prob=probs) # generate sampling dist. under tau = ATE
dispdist(distout, ate)  ## display characteristics of sampling dist. for inference

Run the code above in your browser using DataLab