Generate Balancing Weights
weightit()
allows for the easy generation of balancing weights using a variety of available methods for binary, continuous, and multi-category treatments. Many of these methods exist in other packages, which weightit()
calls; these packages must be installed to use the desired method. Also included are print()
and summary()
methods for examining the output.
weightit(formula, data = NULL, method = "ps", estimand = "ATE", stabilize = FALSE, focal = NULL, by = NULL, s.weights = NULL, ps = NULL, moments = NULL, int = FALSE, subclass = NULL, missing = NULL, verbose = FALSE, include.obj = FALSE, ...) ## S3 method for class 'weightit' print(x, ...)
formula |
a formula with a treatment variable on the left hand side and the covariates to be balanced on the right hand side. See |
data |
an optional data set in the form of a data frame that contains the variables in |
method |
a string of length 1 containing the name of the method that will be used to estimate weights. See Details below for allowable options. The default is |
estimand |
the desired estimand. For binary and multi-category treatments, can be |
stabilize |
|
focal |
when multi-category treatments are used and ATT weights are requested, which group to consider the "treated" or focal group. This group will not be weighted, and the other groups will be weighted to be more like the focal group. If specified, |
by |
a string containing the name of the variable in |
s.weights |
A vector of sampling weights or the name of a variable in |
ps |
A vector of propensity scores or the name of a variable in |
moments |
|
int |
|
subclass |
|
missing |
|
verbose |
whether to print additional information output by the fitting function. |
include.obj |
whether to include in the output any fit objects created in the process of estimating the weights. For example, with |
... |
other arguments for functions called by |
x |
a |
The primary purpose of weightit()
is as a dispatcher to functions that perform the estimation of balancing weights using the requested method
. Below are the methods allowed and links to pages containing more information about them, including additional arguments and outputs (e.g., when include.obj = TRUE
), how missing values are treated, which estimands are allowed, and whether sampling weights are allowed.
"ps"
- Propensity score weighting using generalized linear models.
"gbm"
- Propensity score weighting using generalized boosted modeling.
"cbps"
- Covariate Balancing Propensity Score weighting.
"npcbps"
- Non-parametric Covariate Balancing Propensity Score weighting.
"ebal"
- Entropy balancing.
"ebcw"
- Empirical balancing calibration weighting.
"optweight"
- Optimization-based weighting.
"super"
- Propensity score weighting using SuperLearner.
"bart"
- Propensity score weighting using Bayesian additive regression trees (BART).
"energy"
- Energy balancing.
method
can also be supplied as a user-defined function; see method_user
for instructions and examples.
When using weightit()
, please cite both the WeightIt package (using citation("WeightIt")
) and the paper(s) in the references section of the method used.
A weightit
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. |
estimand |
The estimand requested. |
method |
The weight estimation method specified. |
ps |
The estimated or provided propensity scores. Estimated propensity scores are returned for binary treatments and only when |
s.weights |
The provided sampling weights. |
focal |
The focal variable if the ATT was requested with a multi-category treatment. |
by |
A data.frame containing the |
obj |
When |
info |
Additional information about the fitting. See the individual methods pages for what is included. |
Noah Greifer
weightitMSM()
for estimating weights with sequential (i.e., longitudinal) treatments for use in estimating marginal structural models (MSMs).
weightit.fit()
, which is a lower-level dispatcher function that accepts a matrix of covariates and a vector of treatment statuses rather than a formula and data frame and performs minimal argument checking and processing. It may be useful for speeding up simulation studies for which the correct arguments are known. In general weightit()
should be used.
library("cobalt") data("lalonde", package = "cobalt") #Balancing covariates between treatment groups (binary) (W1 <- weightit(treat ~ age + educ + married + nodegree + re74, data = lalonde, method = "ps", estimand = "ATT")) summary(W1) bal.tab(W1) #Balancing covariates with respect to race (multi-category) (W2 <- weightit(race ~ age + educ + married + nodegree + re74, data = lalonde, method = "ebal", estimand = "ATE")) summary(W2) bal.tab(W2) #Balancing covariates with respect to re75 (continuous) (W3 <- weightit(re75 ~ age + educ + married + nodegree + re74, data = lalonde, method = "cbps", over = FALSE)) summary(W3) bal.tab(W3)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.