optweight | R Documentation |
Estimate stable balancing weights for treatments and covariates specified in formula
. The degree of balance for each covariate is specified by tols
and the target population can be specified with targets
or estimand
. See Zubizarreta (2015) and Wang & Zubizarreta (2019) for details of the properties of the weights and the methods used to fit them.
optweight(
formula,
data = NULL,
tols = 0,
estimand = "ATE",
targets = NULL,
s.weights = NULL,
b.weights = NULL,
focal = NULL,
norm = "l2",
verbose = FALSE,
...
)
optweightMV(
formula.list,
data = NULL,
tols.list = list(0),
estimand = "ATE",
targets = NULL,
s.weights = NULL,
b.weights = NULL,
focal = NULL,
norm = "l2",
verbose = FALSE,
...
)
formula |
A formula with a treatment variable on the left hand side and the covariates to be balanced on the right hand side, or a list thereof. See |
data |
An optional data set in the form of a data frame that contains the variables in |
tols |
A vector of balance tolerance values for each covariate, or a list thereof. The resulting weighted balance statistics will be at least as small as these values. If only one value is supplied, it will be applied to all covariates. Can also be the output of a call to |
estimand |
The desired estimand, which determines the target population. For binary treatments, can be "ATE", "ATT", "ATC", or |
targets |
A vector of target population mean values for each baseline covariate. The resulting weights will yield sample means within |
s.weights |
A vector of sampling weights or the name of a variable in |
b.weights |
A vector of base weights or the name of a variable in |
focal |
When multi-category treatments are used and |
norm |
|
verbose |
|
... |
Arguments passed on to
|
formula.list |
A list of formulas, each with a treatment variable on the left hand side and the covariates to be balanced on the right hand side. |
tols.list |
A list of vectors of balance tolerance values for each covariate for each treatment. The resulting weighted balance statistics will be at least as small as these values. If only one value is supplied, it will be applied to all covariates. See Details. |
The optimization is performed by the lower-level function optweight.fit()
(for optweight()
) or optweightMV.fit()
(for optweightMV()
).
For binary and multi-category treatments, weights are estimated so that the weighted mean differences of the covariates are within the given tolerance thresholds (unless std.binary
or std.cont
are TRUE
, in which case standardized mean differences are considered for binary and continuous variables, respectively). For a covariate x
with specified tolerance \delta
, the weighted means of each each group will be within \delta
of each other. Additionally, when the ATE is specified as the estimand or a target population is specified, the weighted means of each group will each be within \delta/2
of the target means; this ensures generalizability to the same population from which the original sample was drawn.
If standardized tolerance values are requested, the standardization factor corresponds to the estimand requested: when the ATE is requested or a target population specified, the standardization factor is the square root of the average variance for that covariate across treatment groups, and when the ATT or ATC are requested, the standardization factor is the standard deviation of the covariate in the focal group. The standardization factor is computed accounting for s.weights
.
For continuous treatments, weights are estimated so that the weighted correlation between the treatment and each covariate is within the specified tolerance threshold. If the ATE is requested or a target population is specified, the means of the weighted covariates and treatment are restricted to be equal to those of the target population to ensure generalizability to the desired target population. The weighted correlation is computed as the weighted covariance divided by the product of the unweighted standard deviations. The means used to center the variables in computing the covariance are those specified in the target population.
Two types of constraints may be associated with each covariate: target constraints and balance constraints. Target constraints require the mean of the covariate to be at (or near) a specific target value in each treatment group (or for the whole group when treatment is continuous). Balance constraints require the means of the covariate in pairs of treatments to be near each other. For binary and multi-category treatments, balance constraints are redundant if target constraints are provided for a variable. For continuous variables, balance constraints refer to the correlation between treatment and the covariate and are not redundant with target constraints. In the duals
component of the output, each covariate has a dual variable for each nonredundant constraint placed on it.
The dual variable for each constraint is the instantaneous rate of change of the objective function at the optimum corresponding to a change in the constraint. Because this relationship is not linear, large changes in the constraint will not exactly map onto corresponding changes in the objective function at the optimum, but will be close for small changes in the constraint. For example, for a covariate with a balance constraint of .01 and a corresponding dual variable of 40, increasing (i.e., relaxing) the constraint to .025 will decrease the value of the objective function at the optimum by approximately (.025 - .01) * 40 = .6
.
For factor variables, optweight()
takes the sum of the absolute dual variables for the constraints for all levels and reports it as the the single dual variable for the variable itself. This summed dual variable works the same way as dual variables for continuous variables do.
For optweight()
, an optweight
object with the following elements:
weights |
The estimated weights, one for each unit. |
treat |
The values of the treatment variable. |
covs |
The covariates used in the fitting. Only includes the raw covariates, which may have been altered in the fitting process. |
s.weights |
The provided sampling weights. |
b.weights |
The provided base weights. |
estimand |
The estimand requested. |
focal |
The focal variable if the ATT was requested with a multi-category treatment. |
call |
The function call. |
tols |
The tolerance values for each covariate. |
duals |
A data.frame containing the dual variables for each covariate. See Details for interpretation of these values. |
info |
Information about the performance of the optimization at termination. |
For optweightMV()
, an optweightMV
object with the following elements:
weights |
The estimated weights, one for each unit. |
treat.list |
A list of the values of the treatment variables. |
covs.list |
A list of the covariates for each treatment used in the fitting. Only includes the raw covariates, which may have been altered in the fitting process. |
s.weights |
The provided sampling weights. |
b.weights |
The provided base weights. |
call |
The function call. |
tols |
A list of tolerance values for each covariate for each treatment. |
duals |
A list of data.frames containing the dual variables for each covariate for each treatment. See Details for interpretation of these values. |
info |
Information about the performance of the optimization at termination. |
Chattopadhyay, A., Cohn, E. R., & Zubizarreta, J. R. (2024). One-Step Weighting to Generalize and Transport Treatment Effect Estimates to a Target Population. The American Statistician, 78(3), 280–289. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/00031305.2023.2267598")}
Källberg, D., & Waernbaum, I. (2023). Large Sample Properties of Entropy Balancing Estimators of Average Causal Effects. Econometrics and Statistics. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.ecosta.2023.11.004")}
Wang, Y., & Zubizarreta, J. R. (2020). Minimal dispersion approximately balancing weights: Asymptotic properties and practical considerations. Biometrika, 107(1), 93–105. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biomet/asz050")}
Zubizarreta, J. R. (2015). Stable Weights that Balance Covariates for Estimation With Incomplete Outcome Data. Journal of the American Statistical Association, 110(511), 910–922. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/01621459.2015.1023805")}
optweight.fit()
, the lower-level function that performs the fitting. Links on that page can help with diagnosing and fixing more subtle issues with the optimization.
sbw, which was the inspiration for this package and provides some additional functionality for binary treatments.
WeightIt, which provides a simplified interface to optweight()
and a more efficient implementation of entropy balancing.
library("cobalt")
data("lalonde", package = "cobalt")
# Balancing covariates between treatment groups (binary)
(ow1 <- optweight(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
tols = c(.01, .02, .03, .04, .05),
estimand = "ATE"))
bal.tab(ow1)
# Exactly alancing covariates with respect to race (multi-category)
(ow2 <- optweight(race ~ age + educ + married +
nodegree + re74, data = lalonde,
tols = 0, estimand = "ATT",
focal = "black"))
bal.tab(ow2)
# Balancing covariates between treatment groups (binary)
# and requesting a specified target population
targets <- process_targets(~ age + educ + married +
nodegree + re74,
data = lalonde,
targets = c(26, 12, .4, .5,
1000))
(ow3a <- optweight(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
targets = targets,
estimand = NULL))
bal.tab(ow3a, disp.means = TRUE)
# Balancing covariates between treatment groups (binary)
# and not requesting a target population
(ow3b <- optweight(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
targets = NULL,
estimand = NULL))
bal.tab(ow3b, disp.means = TRUE)
# Balancing two treatments
(ow4 <- optweightMV(list(treat ~ age + educ + race + re74,
re75 ~ age + educ + race + re74),
data = lalonde))
summary(ow4)
bal.tab(ow4)
# Using a different norm
(ow1b <- optweight(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
tols = c(.01, .02, .03, .04, .05),
estimand = "ATE",
norm = "l1"))
summary(ow1b, weight.range = FALSE)
summary(ow1, weight.range = FALSE)
# Allowing for negative weights
ow5 <- optweight(treat ~ age + educ + married + race +
nodegree + re74 + re75,
data = lalonde,
estimand = "ATE",
min.w = -Inf)
summary(ow5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.