ebalance: Entropy balancing

View source: R/ebalance.R

ebalanceR Documentation

Entropy balancing


This function implements entropy balancing, a data preprocessing procedure that allows users to reweight a dataset. The preprocessing is based on a maximum entropy reweighting scheme that assigns weights to each unit such that the covariate distributions in the reweighted data satisfy a set of moment conditions specified by the researcher. This can be useful to balance covariate distributions in observational studies with a binary treatment where the control group data can be reweighted to match the covariate moments in the treatment group. Entropy balancing can also be used to reweight a survey sample to known characteristics from a target population. The weights that result from entropy balancing can be passed to regression or other models to subsequently analyze the reweighted data.

By default, ebalance reweights the covariate distributions from a control group to match target moments that are computed from a treatment group such that the reweighted data can be used to analyze the average treatment effect on the treated.


ebalance(Treatment, X, base.weight = NULL, 
norm.constant = NULL, coefs = NULL, 
max.iterations = 200, 
constraint.tolerance = 1, print.level = 0)



A vector indicating the observations which are in the data group that should be reweighted (i.e. the control group) and those which are in the data group that should be used to compute the target moments (i.e. the treatment group). This can either be a logical vector or a real vector where 0 denotes control observations and 1 denotes treatment observations. By default the target moments are computed using the data from all treatment observations.


A matrix containing the variables that the researchers wants to include in the reweighting. To adjust the means of the covariates, the raw covariates can be included. To adjust the variances of the covariates, squared terms of the raw covariates can be included. To adjust co-moments, interaction terms can be included. All columns of this matrix must have positive variance and the matrix must be invertible. No missing data is allowed.


An optional vector of base weights for the maximum entropy reweighting (one weight for each control unit). The default is uniform base weights.


An optional normalizing constant. By default the weights are normalized such that the sum of the weights for the reweighted control group match the number of observations in the treatment grou.


An optional vector of model coefficients to start the reweighting.


Maximum number of iterations that will be run when attempting to reweight the data.


This is the tolerance level used by ebalance to decide if the moments in the reweighted data are equal to the target moments.


Controls the level of printing: 0 (normal printing), 2 (detailed), and 3 (very detailed).


If the user wants to pass different target moments these should be entered in a new row in the dataset which contains the target means for the covariate distributions.


An list object of class ebalance with the following elements:


A vector that contains the target moments coded from the covariate distributions of the treatment group.


A matrix that contains the covariate data from the control group.


A vector that contains the control group weights assigned by entropy balancing.


A vector that contains coefficients from the reweighting algorithm.


A scalar that contains the maximum deviation between the moments of the reweighted data and the target moments.


The tolerance level used for the balance constraints.


The base weight used.


The print level used.


Logical flag if algorithm converged within tolerance.


Jens Hainmueller


Hainmueller, J. (2012) 'Entropy Balancing for Causal Effects: A Multivariate Reweighting Method to Produce Balanced Samples in Observational Studies', Political Analysis (Winter 2012) 20 (1): 25–46.

Zaslavsky, A. (1988), 'Representing local reweighting area adjustments by of households', Survey Methodology 14(2), 265–288.

Ireland, C. and Kullback, S. (1968), 'Contingency tables with given marginals', Biometrika 55, 179–188.

Kullback, S. (1959), Information Theory and Statistics, Wiley, NY.

See Also

Also see ebalance.trim.


# create toy data: treatment indicator and three covariates X1-3
treatment   <- c(rep(0,50),rep(1,30))
X           <- rbind(replicate(3,rnorm(50,0)),replicate(3,rnorm(30,.5)))
colnames(X) <- paste("x",1:3,sep="")

# entropy balancing
eb.out <- ebalance(Treatment=treatment,
# means in treatment group data
# means in reweighted control group data
# means in raw data control group data

ebal documentation built on June 9, 2022, 9:05 a.m.

Related to ebalance in ebal...