markmfredrickson edited this page Jun 3, 2011 · 6 revisions

(RItools) Randomization Inference Tools

This page contains the R package RItools which is a joint project of Jake Bowers, Ben Hansen and Mark Fredrickson.

For Use Within R

Installation and Configuration

The source code packaged for OS X or other Unices is can be downloaded from within R using:


The source and binary code is available via the CRAN repository system for versions of R later than 2.7.0 so installation should simply use:

If you want to install RItools for versions of R more current than 2.2 but earlier than 2.7, you’ll have to use:
If you don’t already have the SparseM package installed, you will need the tools required to compile fortran libraries installed in order to build SparseM.

For Use Within Stata

It is now possible to access some of the basic capabilities of RItools from within Stata. The workhorse of the package is the xbalance command. At this time only default usage and output is possible from within Stata.

Installation and Configuration

To use xBalance within Stata, you must install R, available from CRAN. You must also install the RItools package. From your R prompt:


Next, from your Stata prompt, install xbalance from the SSC repository:

ssc install xbalance

You can see the source of the Stata files at the SSC repository.

After installing the xbalance.ado file, you will need to install Roger Newson’s Rsource Stata package. To install Rsource from SSC at the Stata prompt type:
ssc install rsource

You must set the global {hi:Rterm_path} prior to running xbalance. Examples, on Windows and Unix (such as Mac OS X) respectively:

global Rterm_path `"c:\r\R-2.5.0\bin\Rterm.exe"' global Rterm_path `"/usr/bin/R"'

You may find it convenient to add the appropriate R path settings to your profile.do.

Relevant Papers and Presentations

A how-to guide on blocking, balance testing, and analysis using RItools and Optmatch appears in the Newsletter of the APSA Experimental Section 2.1.

The paper which develops and explains the test statistics and tests used in RItools is: Covariate Balance in Simple, Stratified and Clustered Comparative Studies (with Ben Hansen) * Statistical Science * 2008, Vol. 23, No. 2, 219–236. Note that a typo on page 4 exists such that the variance of d should be Var(d) = (m/(m~t~m~c~))s^2^.

A poster that we presented at the Political Methodology Summer Conference in 2008 is here. This poster presents the results of some joint work with Dan Carpenter

A poster that we presented at the useR! Conference during late June of 2006 is here. This poster presents the results of some joint work with Dan Carpenter

This material is based upon work supported by the National Science Foundation under Grant Numbers SES–0753164 and SES–0753168. Any opinions, findings and conclusions or recomendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation (NSF).