Skip to content

Repository files navigation

hbal

Lifecycle: stable License: MIT downloads: CRAN

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 hbal in three ways. The CRAN release is the stable version:

install.packages("hbal")

The main branch on GitHub mirrors the CRAN release:

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

The dev branch carries the up-to-date development version. New features and fixes land there first and reach CRAN with the next release:

devtools::install_github("xuyiqing/hbal@dev")

Installing from GitHub compiles the package’s C++ code. That needs a compiler: Rtools on Windows, or the Xcode command-line tools on macOS.

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!

About

Hierarchically Regularized Entropy Balancing

Resources

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages