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,
horvitz_thompson(). In addition, we include two functions for linear regression estimators,
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).
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("http://R.declaredesign.org", "https://cloud.r-project.org"))
Once the package is installed, getting appropriate estimates and standard errors is now both fast and easy.
library(estimatr) # 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.
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'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.