genperms.custom: Generates an approximate permutation matrix for an...

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/genperms.custom.R

Description

Generates a permutation matrix by replicating a user-supplied randomization function. Not intended to be used for designs handled by genperms (i.e., complete randomization of clusters within blocks)

Usage

1
genperms.custom(numiter = 10000, randfun = randfun.default, ...)

Arguments

numiter

a scalar for the number of replicates, default is 10000

randfun

a user supplied function outputting an N-length binary (0 or 1) vector. Default is an internal function.

...

other inputs for randfun

Value

an N-by-k permutation matrix, where k = numiter

Author(s)

Peter M. Aronow <peter.aronow@yale.edu>; Cyrus Samii <cds2083@nyu.edu>

References

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

See Also

genperms

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Rejected randomization scheme: reject if and only if there is significant imbalance

X <- c(1:200)

randfun <- function() {
  teststat <- -1
	while (teststat < 0.05) {
		Zri <- sample(c(rep(0,180),rep(1,20))) # imbalanced design
		fstat <- summary(lm(Zri~X))$fstatistic
		teststat <- pf(fstat[1],fstat[2],fstat[3],lower.tail=FALSE)  # extract F-test p-value
			}
	return(Zri)
}
perms <- genperms.custom(numiter=10000, randfun=randfun) # generate permutations
probs <- genprob(perms) # generate approximate probabilities from permutation matrix
cor(probs,(X-mean(X))^2) # observations with extreme X are less likely to be treated

Example output

[1] -0.2011943

ri documentation built on May 2, 2019, 6:51 a.m.