Technical papers and textbooks demand complex estimation strategies that are often difficult to implement, even for scientists who are expert coders. The result is slow code copied and pasted from the internet, where the result is taken on faith.

estimatr provides a small set of commonly-used estimators (methods for estimating quantities of interest like treatment effects or regression parameters), written in C++ for speed, and implemented in R with simple, accessible syntax. We include two functions that implement means estimators, difference_in_means() and horvitz_thompson(). In addition, we include two functions for linear regression estimators, lm_robust() and lm_lin(). In each case, scientists can choose an estimator to reflect cluster-randomized, block-randomized, and block-and-cluster-randomized designs.

Fast estimators also enable fast simulation of research designs to learn about their properties (see DeclareDesign).

This software is not yet ready for general release. Please contact the authors before using in experiments or published work. Specifications, names, and arguments of functions are subject to change.

Installing estimatr

If you would like to use the current development release of estimatr, please ensure that you are running version 3.3 or later of R and run the following code:

install.packages("estimatr", dependencies = TRUE,
  repos = c("", ""))

Easy to use

Once the package is installed, getting appropriate estimates and standard errors is now both fast and easy.


# robust standard errors
lm_robust(y ~ z, data = sample_dat)

# cluster robust standard errors
lm_robust(y ~ z, data = sample_dat, clusters = my_cluster_var)

# blocked designs
difference_in_means(y ~ z, data = sample_dat, blocks = my_block_var)

The Getting Started guide describes each estimator provided by estimatr and how it can be used in your analysis.

Fast to use

Getting estimates and robust standard errors is also faster than it used to be. Compare our package to using lm() and the sandwich package to get HC2 standard errors.

# estimatr
lm_robust(y ~ x1 + x2 + x3 + x4, data = dat)

# usual specification (lm + sandwich)
lm_out <- lm(y ~ x1 + x2 + x3 + x4, data = dat)
lmtest::coeftest(lm_out, vcov = sandwich::vcovHC(lm_out, type = 'HC2'))

This project is generously supported by a grant from the Laura and John Arnold Foundation and seed funding from Evidence in Governance and Politics (EGAP).