Learn R Programming

WeightIt (version 0.7.1)

weightit: Generate Balancing Weights

Description

weightit allows for the easy generation of balancing weights using a variety of available methods for binary, continuous, and multinomial 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.

Usage

weightit(formula,
         data = NULL,
         method = "ps",
         estimand = "ATE",
         stabilize = FALSE,
         focal = NULL,
         by = NULL,
         s.weights = NULL,
         ps = NULL,
         moments = 1,
         int = FALSE,
         verbose = FALSE,
         include.obj = FALSE,
         ...)

# S3 method for weightit print(x, ...)

Arguments

formula

a formula with a treatment variable on the left hand side and the covariates to be balanced on the right hand side. See glm for more details. Interactions and functions of covariates are allowed.

data

an optional data set in the form of a data frame that contains the variables in formula.

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 "ps".

estimand

the desired estimand. For binary and multinomial treatments, can be "ATE", "ATT", "ATC", and, for some methods, "ATO" or "ATM". The default for both is "ATE". This argument is ignored for continuous treatments. See the individual pages for each method for more information on which estimands are allowed with each method and what literature to read to interpret these estimands.

stabilize

logical; whether or not to stabilize the weights. For the methods that involve estimating propensity scores, this involves multiplying each unit's weight by the sum of the weights in that unit's treatment group. For the "ebal" method, this involves using ebalance.trim to reduce the variance of the weights. Default is FALSE.

focal

when multinomial treatments are used and the "ATT" is 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, estimand will automatically be set to "ATT".

by

a string containg the name of the variable in data for which weighting is to be done within categories or a one-sided formula with the stratifying variable on the right-hand side. For example, if by = "gender" or by = ~ gender, weights will be generated separately within each level of the variable "gender". The argument used to be called exact, which will still work but with a message. Only one by variable is allowed.

s.weights

A vector of sampling weights or the name of a variable in data that contains sampling weights. These can also be matching weights if weighting is to be used on matched data.

ps

A vector of propensity scores or the name of a variable in data containing propensity scores. If not NULL, method is ignored, and the propensity scores will be used to create weights. formula must include the treatment variable in data, but the listed covariates will play no role in the weight estimation.

moments

numeric; for entropy balancing, empirical balancing calibration weights, optimization-based weights, the greatest moment of the covariate distribution to be balanced. For example, if moments = 3, for all non-categorical covariates, the mean, second moment (variance), and third moments (skew) of the covariates will be balanced. This argument is ignored for other methods; to balance powers of the covariates, appropriate functions must be entered in formula.

int

logical; for entropy balancing, empirical balancing calibration weights, and optimization-based weights, whether first-order interactions of the covariates are to be balanced (essentially balancing the covariances between covariates). This argument is ignored for other methods; to balance interactions between the variables, appropriate functions must be entered in formula.

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 method = "ps", the glm objects containing the propensity score model will be included. See Details for information on what object will be included if TRUE.

...

other arguments for functions called by weightit that control aspects of fitting that are not covered by the above arguments. See Details.

x

a weightit object; the output of a call to weightit.

Value

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 method is "ps", "gbm", "cbps", or "super".

s.weights

The provided sampling weights.

focal

The focal variable if the ATT was requested with a multinomial treatment.

by

A data.frame containing the by variable when specified.

obj

When include.obj = TRUE, the fit object.

Details

The primary purpose of weightit is as a dispatcher to other functions in other packages that perform the estimation of balancing weights. These functions are identified by a name, which is used in method to request them. Each method has some slight distinctions in how it is called, but in general, simply entering the method will cause weightit to generate the weights correctly using the function. To use each method, the package containing the function must be installed, or else an error will appear. 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) and how missing values are treated.

  • "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.

  • "user-defined" - Weighting using a user-defined weighting function.

Examples

Run this code
# NOT RUN {
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 (multinomial)
(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)
# }

Run the code above in your browser using DataLab