Randomization Inference Tools

Tools for randomization inference.

Stable version: CRAN_Status_Badge

The RItools package implements useful functions for implementing randomization inference based statistical tests. The package provides tools for testing balance of observed covariates in observational studies using the methodology of:

Ben B. Hansen and Jake Bowers (2008). Covariate balance in simple,
  stratified and clustered comparative studies. Statistical Science.

See the online documentation for xbalance for more details.

The package also provides outcome analysis of simple or block randomized trials (or matched observational studies) based on user defined models and test statistics. See the online documentation of parameterizedRandomizationDistribution for more details.

RItools is available on CRAN: > library("RItools")

Using a development version of RItools

These directions will install development version in a way that will not overwrite an existing installation of RItools from CRAN. You will will need to know the name of the branch you wish to install.

  1. master: The current released version of RItools and a holding place for small bug changes.
  2. randomization-distribution: Experimental work on outcome analysis using user defined models of effects and test statistics. This branch contains the tools necessary to compute estimated treatment effects, p-values, and confidence intervals (regions) using direct simulation from the randomization distribution implied by the design of the experiment (or using the exact randomization distribution if the number of possible ways for the treatment to be assigned is relatively small).

Install and load the devtools package:

> install.packages("devtools")
> library("devtools")

Next, pick a location to install the package. For example, create a directory called ~/R/RItools.experimental/ (~ is short for my home directory on a UNIX system). For this session, we will set the library path to look in this location first and install the package there:

> .libPaths("~/R/RItools.experimental/") # <- your path here
> install_github("markmfredrickson/RItools")

The function install_github will load the package automatically. To install from a branch of the repository, e.g. the randomization-distribution branch, instead use

> install_github("markmfredrickson/[email protected]")

In the future, if you wish load the downloaded version of RItools in a new R session you can use this one-liner:

> library("RItools", lib.loc = "~/R/RItools.experimental") # <- your path here



This is a maintenance release.

  • Fixed a problem where the test suite was calling an external package that was not a formal dependency of the core functionality of the package.


This is a maintenance release.

  • Fixed an obscure bug in which we indirectly fiddled with data.table related global options (#69)
  • Disabled tests of RSVGTipsDevice-dependent functionality on Windows platforms, where (as of this writing) RSVGTipsDevice does not build and check reliably and is not distributed in binary through CRAN (#71)


This version was submitted to CRAN prematurely and ultimately was not released.


  • With xBalance, you can now specify strata "foo" and "bar" by including "+ strata(foo) + strata(bar)" in the fmla argument, without need to give a separate strata argument (eg `strata=list(foo=~foo, bar=~bar)).


  • Switched to base graphics instead of the lattice package for balance plots.
  • Option to make plots on absolute, instead of signed, values.
  • Added the ability to include tooltips to balance plots when using the RSVGTipsDevice package.
  • Added a balanceplot function to handle plotting matrices, not just xbal objects.
  • Balance plots can be grouped into related variables. By default factors are automatically grouped for xbal objects.
  • Some performance improvements when certain results are not requested.
  • post.alignment.transform argument to xBalance allows modifying the data after per-stratum centering.
  • subset method for xbal objects.

CHANGES in RItools v. 0.1-11


  • the null SD of the difference in adjusted means is now reportable as "adj.means.diffs.sd"
  • report="all" provides all relevant statistics
  • Entering "args(xBalance)" is now useful as a reminder of report= options.


  • The default imputation method for missing data is the median. Before 0.1-9 it was the mean. To use the mean, use impfn=mean.default.
  • Passing strata=NULL to xBalance is depracated, as it can be easy to do inadvertently, with a misspelling of a non-null intended argument. For no stratification, use list(unstrat=NULL), as is now the default.


  • display, align, etc arguments to xtable.xbal() have been enabled.
  • In xBalance, when specifying a stratification using a formula with several variables, as in "~x+y", the stratification you get is now interaction(x,y) rather than just y.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.1-16 by Jake Bowers, 8 months ago


Browse source code at https://github.com/cran/RItools

Authors: Jake Bowers <[email protected]> , Mark Fredrickson <[email protected]> , and Ben Hansen <[email protected]>

Documentation:   PDF Manual  

GPL (>= 2) license

Imports grDevices, abind, xtable, svd, stats, graphics, methods, survival

Depends on SparseM

Suggests testthat, roxygen2, MASS, RSVGTipsDevice

Enhances optmatch

Imported by optmatch.

Depended on by uplift.

Suggested by blockTools.

See at CRAN