Skip to contents

R package for implementing hierarchically regularized entropy balancing proposed by Xu and Yang (2022). It is suitable for estimating average treatment effect on the treated with binary treatments under strong ignorability. hbal is an extension of entropy balancing: it automatically expands the feature space by including higher-order terms (such as squared and cubic terms and interactions) of covariates and then achieves approximate balance on the expanded features using ridge penalties with a hierarchical structure.

Examples: R code used in the tutorial can be downloaded from here.

Reference: Eddie Yang & Yiqing Xu (2021). Hierarchically Regularized Entropy Balancing. Political Analysis, published online.


Installation

You can install the hbal package from CRAN:

You can also install the up-to-date development version from Github:

install.packages("devtools") # if not already installed
devtools::install_github("xuyiqing/hbal")

hbal depends on the following packages, which will be installed automatically when hbal is being installed; you can also install them manually:

install_all <- function(packages) {
  installed_pkgs <- installed.packages()[, "Package"]
  for (pkg in packages) {
    if (!pkg %in% installed_pkgs) {
      install.packages(pkg)
    }
  }
}

packages <- c("estimatr", "glmnet", "ggplot2", "gridExtra", "gtable",
              "nloptr", "Rcpp", "RcppEigen", "stringr", "generics")
install_all(packages)

Notes on installation failures

  1. Intel-Mac users who have updated to MacOS BigSur or higher will likely encounter compilation problems. See here for a potential solution.
  2. Windows users please consider upgrading R to 4.3.0 or higher and installing the latest Rtools to avoid C++17 complier errors when installing fastplm.
  3. For Rcpp, RcppArmadillo and MacOS “-lgfortran” and “-lquadmath” error, click here for details.
  4. Installation failure related to OpenMP on MacOS, click here for a solution.
  5. To fix these issues, try installing gfortran from here.

Report bugs

Please report bugs to yiqingxu [at] stanford.edu with your sample code and data file. Much appreciated!