Trimming Weights for Entropy Balancing
ebalance.trim.RdFunction to trim weights obtained from entropy balancing. It takes the output from a call to ebalance and trims the data weights (subject to the moment conditions) such that the ratio of the maximum/minimum weight to the mean weight is reduced to satisfy a user specified target. If no user target is specified the maximum weight ratio is automatically trimmed as far as is feasible given the data.
Usage
ebalance.trim(
ebalanceobj,
max.weight = NULL,
min.weight = 0,
max.trim.iterations = 200,
max.weight.increment = 0.92,
min.weight.increment = 1.08,
print.level = 0
)Arguments
- ebalanceobj
An object from a call to ebalance.
- min.weight
Optional target for the ratio of the minimum to mean weight.
- max.trim.iterations
Maximum number of trimming iterations.
- max.weight.increment
Increment for iterative trimming of the ratio of the maximum to mean weight (a scalar between 0-1, .92 indicates that the attempted reduction in the max ratio is 8 percent).
- min.weight.increment
Increment for iterative trimming of the ratio of the minimum to mean weight (a scalar > 1, 1.08 indicates that the attempted reduction in the max ratio is 8 percent).
- print.level
Controls the level of printing: 0 (normal printing), 2 (detailed), and 3 (very detailed).
- max.weightOptional
target for the ratio of the maximum to mean weight.
Value
A list object of class ebalance.trim with the following elements:
- target.margins
A vector that contains the target moments coded from the covariate distributions of the treatment group.
- co.xdata
A matrix that contains the covariate data from the control group.
- w
A vector that contains the control group weights assigned by trimming entropy balancing algorithm.
- coefs
A vector that contains coefficients from the reweighting algorithm.
- maxdiff
A scalar that contains the maximum deviation between the moments of the reweighted data and the target moments.
- norm.constant
Normalizing constant used.
- constraint.tolerance
The tolerance level used for the balance constraints.
- max.iterations
Maximum number of trimming iterations used.
- base.weight
The base weight used.
- converged
Logical flag if algorithm converged within tolerance.
References
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.
Examples
# 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, X=X)
# means in treatment group data
apply(X[treatment==1,],2,mean)
#> x1 x2 x3
#> 0.7945 0.7303 0.5580
# means in reweighted control group data
apply(X[treatment==0,],2,weighted.mean,w=eb.out$w)
#> x1 x2 x3
#> 0.7788 0.7152 0.5526
# means in raw data control group data
apply(X[treatment==0,],2,mean)
#> x1 x2 x3
#> 0.15098 -0.02915 -0.12521
eb.out.tr = ebalance.trim(eb.out)
#> Automated trimmig of max weight ratio
#> Trim iteration 1 Max Weight Ratio: 12.36
#> Trim iteration 2 Max Weight Ratio: 12.36
#> Trim iteration 3 Max Weight Ratio: 11.28
#> Trim iteration 4 Max Weight Ratio: 9.415
#> Trim iteration 5 Max Weight Ratio: 9.415
#> Trim iteration 6 Max Weight Ratio: 7.573
#> Trim iteration 7 Max Weight Ratio: 7.573
#> Trim iteration 8 Max Weight Ratio: 7.573
#> Trim iteration 9 Max Weight Ratio: 6.75
#> Converged within tolerance
eb.out.tr %>% str
#> List of 10
#> $ target.margins : NULL
#> $ co.xdata : num [1:50, 1:4] 1 1 1 1 1 1 1 1 1 1 ...
#> ..- attr(*, "dimnames")=List of 2
#> .. ..$ : NULL
#> .. ..$ : chr [1:4] "" "x1" "x2" "x3"
#> $ w : num [1:50] 0.77023 0.01913 0.19367 0.00864 0.14447 ...
#> $ coefs : Named num [1:4] -0.861 0.675 0.477 1.083
#> ..- attr(*, "names")= chr [1:4] "" "" "" ""
#> $ maxdiff : num 0.494
#> $ norm.constant : int 30
#> $ constraint.tolerance: num 1
#> $ max.iterations : num 200
#> $ base.weight : num [1:50] 1 1 1 1 1 1 1 1 1 1 ...
#> $ converged : logi TRUE
#> - attr(*, "class")= chr "ebalance.trim"
# means in reweighted control group data
apply(X[treatment==0,],2,weighted.mean,w=eb.out.tr$w)
#> x1 x2 x3
#> 0.7942 0.7272 0.5738
# untrimmed and trimmed weights
round(summary(eb.out$w),2)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.02 0.11 0.26 0.61 0.56 7.76
round(summary(eb.out.tr$w),2)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.00 0.02 0.14 0.59 0.45 3.98