blockTools: Blocking, Assignment, and Diagnosing Interference in Randomized Experiments
Ryan T. Moore, with contributions from Keith Schnakenberg
Available as a CRAN package
Causal inference in social and biomedical research often relies on estimates from randomized experiments. blockTools offers functionality for designing, conducting, and analyzing aspects of randomized experiments. "Blocking" involves sorting experimental units into homogeneous groups prior to randomization. Randomization then occurs within those groups. blockTools allows experimentalists to easily
block experimental units using many background covariates simultaneously (including continuous ones)
incorporate substantive knowledge via weights on variables
randomly assign blocked units to treatment conditions within blocks
detect possible interference between treatment and control units ("contamination", or "spillovers")
quickly write tables of proposed blocks or experimental assignment protocols to .tex or .csv files
details the many options associated with this functionality.
To install and load blockTools, open R and type
> install.packages("blockTools") > library(blockTools)
To install the latest version (0.5-6) directly, download the package
(here) and install using R CMD INSTALL.
There are 3 primary functions of blockTools: block, assignment, and diagnose.
block creates experimental blocks.
assignment assigns one unit in each block to each treatment condition.
diagnose detects units of different treatment assignments that are "too close" or "too far away" from each other on some variable.
You might find these two (minimally-documented) helper functions
useful. Just download and source the code linked below to use them. Look for them in a future release of the package.
createBlockIDs takes an assignment object and creates a
vector of block IDs.
interfaces between an assignment object and xBalance from package RItools
At the R prompt, type: > data(x100) ## load the example data > out <- block(x100, id.vars = "id", block.vars = c("b1", "b2")) ## create blocked pairs > assg <- assignment(out) ## assign one member of each pair to treatment/control > diag <- diagnose(assg, x100, id.vars = "id", suspect.var = "b1", suspect.range = c(0,1)) ## detect unit pairs with different treatment assignments that are within 1 unit of each other on variable "b1"
To view the results: > out$blocks ## blocked pairs > assg ## assigned pairs > diag ## pairs with small distances on covariates between them
Speed and Dataset Size
As of version 0.5-1, all blocking is done in C. The block()
function has been tested on a desktop machine (iMac, Intel Core i5,
3.6 GHz, 8 GB) and successfully completed these runs:
Note on Variable Restrictions
If you use the valid.var and valid.range arguments
of the block function, this may result in fewer than the
maximum possible number of blocks. To see why, consider how
algorithm = "optGreedy" or algorithm = "naiveGreedy"
would handle distance matrix below. Either would select only the pair
(1,2), rather than, e.g., pairs (1,3) and (2,4), as would
algorithm = "optimal".
If you use this package, please cite the paper
Moore, Ryan T. ``Multivariate Continuous Blocking to Improve Political Science
Experiments''. Political Analysis, 2012.
the software can be cited directly as
Moore, Ryan T. "blockTools: Blocking, Assignment, and Diagnosing
Interference in Randomized Experiments", Version 0.5-6, August 2012.
For an application, see:
King, Gary, Emmanuela Gakidou, Nirmala Ravishankar, Ryan T. Moore, Jason Lakin, Manett Vargas, Martha María Téllez-Rojo, Juan Eugenio Hernández Ávila, Mauricio Hernández Ávila and Héctor Hernández Llamas. 2007. "A 'Politically Robust' Experimental Design for Public Policy Evaluation, with Application to the Mexican Universal Health Insurance Program". Journal of Policy Analysis and Management, 26(3): 479-509.