blockTools

blockTools: Blocking, Assignment, and Diagnosing Interference in Randomized Experiments
Version 0.6-2
Ryan T. Moore and Keith Schnakenberg
Available as a CRAN package

Abstract

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

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.6-2) directly, download the package (here) and install using R CMD INSTALL.
To install the latest development, beta version (0.6-3) directly, download the package (here) and install using R CMD INSTALL.

Using blockTools

There are 3 primary functions of blockTools: block, assignment, and diagnose.

Helper Functions

You might find two recent helper functions useful: See the package documentation for more details.

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 in that version was 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, 20(4):460--479, Autumn 2012.

or

Moore, Ryan T. and Sally A. Moore. ``Blocking for Sequential Political Experiments''. Political Analysis, 21(4):507–523, 2013.

as appropriate. The software can be cited directly as

Moore, Ryan T. and Keith Schnakenberg. "blockTools: Blocking, Assignment, and Diagnosing Interference in Randomized Experiments", Version 0.6-2, January 2015.

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.

Previous versions (CHANGELOG):

0.6-2 (8 January 2015)
0.6-1 (22 May 2014)
0.5-8 (8 April 2014)
0.5-7 (30 July 2013)
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)