blockTools: Blocking, Assignment, and Diagnosing Interference in Randomized Experiments
Version 0.5-6
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
Documentation
The manual
details the many options associated with this functionality.
Installation
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.
Using blockTools
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.
Helper Functions
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.
assg2xBalance
interfaces between an assignment object and xBalance from package RItools
Examples
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:
Units
Variables
Algorithm
Time
1000
5
optGreedy
0m 1s
5000
5
optGreedy
1m 35s
10,000
2
optGreedy
12m 53s
10,000
5
optGreedy
12m 38s
10,000
5
naiveGreedy
0m 43s
20,000
5
optGreedy
101m 16s
20,000
5
naiveGreedy
3m 59s
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".
Inf
2
3
4
2
Inf
5
6
3
5
Inf
Inf
4
6
Inf
Inf
Citation
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.
0.5-6 (1 August 2012)
0.5-5 (11 June 2012)
0.5-4 (7 May 2012)
0.5-3 (4 March 2011)
0.5-2 (16 November 2010)
0.5-1 (6 October 2010)
0.4-1 (28 October 2009)
0.3 (29 April 2009)
0.2 (10 April 2008)