Weighting for Covariate Balance in Observational Studies

Generates weights to form equivalent groups in observational studies by easing and extending the functionality of the R packages 'twang' (Ridgeway et al., 2017) < https://CRAN.R-project.org/package=twang> for generalized boosted modeling, 'CBPS' (Fong, Ratkovic, & Imai, 2018) < https://CRAN.R-project.org/package=CBPS> for covariate balancing propensity score weighting, 'ebal' (Hainmueller, 2014) < https://CRAN.R-project.org/package=ebal> for entropy balancing, 'optweight' (Greifer, 2018) < https://CRAN.R-project.org/package=optweight> for optimization-based weights, 'ATE' (Haris & Chan, 2015) < https://CRAN.R-project.org/package=ATE> for empirical balancing calibration weighting, and SuperLearner (Polley, LeDell, Kenney, & van der Laan, 2018) < https://CRAN.R-project.org/package=SuperLearner>. Also allows for assessment of weights and checking of covariate balance by interfacing directly with 'cobalt' (Greifer, 2018) < https://CRAN.R-project.org/package=cobalt>.

CRAN_Status_Badge CRAN_Downloads_Badge

WeightIt is a one-stop package to generate balancing weights for point and longitudinal treatments in observational studies. Contained within WeightIt are methods that call on other R packages to estimate weights. The value of WeightIt is in its unified and familiar syntax used to generate the weights, as each of these other packages have their own, often challenging to navigate, syntax. WeightIt extends the capabilities of these packages to generate weights used to estimate the ATE, ATT, and ATC for binary or multinomial treatments, and treatment effects for continuous treatments when available. In these ways, WeightIt does for weighting what MatchIt has done for matching, and MatchIt users will find the syntax familiar.

To install and load WeightIt, use the code below:

install.packages("WeightIt")  #CRAN version
devtools::install_github("ngreifer/WeightIt")  #Development version

The workhorse function of WeightIt is weightit(), which generates weights from a given formula and data input according to methods and other parameters sepcified by the user. Below is an example of the use of weightit() to generate weights for estimating the ATE:

data("lalonde", package = "cobalt")
W <- weightit(treat ~ age + educ + nodegree + married + race + re74 + re75, 
    data = lalonde, method = "ps", estimand = "ATE")
A weightit object
 - method: "ps" (propensity score weighting)
 - number of obs.: 614
 - sampling weights: none
 - treatment: 2-category
 - estimand: ATE
 - covariates: age, educ, nodegree, married, race, re74, re75

Evaluating weights has two components: evaluating the covariate balance produces by the weights, and evaluating whether the weights will allow for sufficient precision in the eventual effect estimate. For the first goal, functions in the cobalt package, which are fully compatible with WeightIt, can be used, as demonstrated below:

bal.tab(W, un = TRUE)
 weightit(formula = treat ~ age + educ + nodegree + married + 
    race + re74 + re75, data = lalonde, method = "ps", estimand = "ATE")

Balance Measures
                Type Diff.Un Diff.Adj
prop.score  Distance  1.7569   0.1360
age          Contin. -0.2419  -0.1676
educ         Contin.  0.0448   0.1296
nodegree      Binary  0.1114  -0.0547
married       Binary -0.3236  -0.0944
race_black    Binary  0.6404   0.0499
race_hispan   Binary -0.0827   0.0047
race_white    Binary -0.5577  -0.0546
re74         Contin. -0.5958  -0.2740
re75         Contin. -0.2870  -0.1579

Effective sample sizes
           Control Treated
Unadjusted 429.000 185.000
Adjusted   329.008  58.327

For the second goal, qualities of the distributions of weights can be assessed using summary(), as demonstrated below.

Summary of weights:

- Weight ranges:
           Min                                   Max
treated 1.1721 |---------------------------| 40.0773
control 1.0092 |-|                            4.7432

- Units with 5 greatest weights by group:
             137     124     116      68      10
 treated 13.5451 15.9884 23.2967 23.3891 40.0773
             597     573     411     381     303
 control  4.0301  4.0592  4.2397  4.5231  4.7432

          Ratio Coef of Var
treated 34.1921      1.4777
control  4.7002      0.5519
overall 39.7134      1.3709

- Effective Sample Sizes:
           Control Treated
Unweighted 429.000 185.000
Weighted   329.008  58.327

Desirable qualities include ratios close to 1, coefficients of variation close to 0, and large effective sample sizes.

The table below contains the available methods in WeightIt for estimating weights for binary, multinomial, and continuous treatments using various methods and functions from various packages.

Treatment type Method (method =) Function Package
Binary Binary regression PS ("ps") glm() base
- Generalized boosted modeling PS ("gbm") ps() twang
- Covariate Balancing PS ("cbps") CBPS() CBPS
- Non-Parametric Covariate Balancing PS ("npcbps") npCBPS() CBPS
- Entropy Balancing ("ebal") ebalance() ebal
- Empirical Balancing Calibration Weights ("ebcw") ATE() ATE
- Optimization-Based Weights ("optweight") optweight() optweight
- SuperLearner PS ("super") SuperLearner() SuperLearner
Multinomial Multiple binary regression PS ("ps") glm() base
- Multinomial regression PS ("ps") mlogit() mlogit
- Bayesian multinomial regression PS ("ps", link = "bayes.probit") MNP() MNP
- Generalized boosted modeling PS ("gbm") ps() twang
- Covariate Balancing PS ("cbps") CBPS() CBPS
- Non-Parametric Covariate Balancing PS ("npcbps") npCBPS() CBPS
- Entropy Balancing ("ebal") ebalance() ebal
- Stable Balancing Weights ("sbw") sbw() sbw
- Empirical Balancing Calibration Weights ("ebcw") ATE() ATE
- Optimization-Based Weights ("optweight") optweight() optweight
- SuperLearner PS ("super") SuperLearner() SuperLearner
Continuous Generalized linear model PS ("ps") glm() base
- Generalized boosted modeling PS ("gbm") ps.cont() WeightIt
- Covariate Balancing PS ("cbps") CBPS() CBPS
- Non-Parametric Covariate Balancing PS ("npcbps") npCBPS() CBPS
- Optimization-Based Weights ("optweight") optweight() optweight
- SuperLearner PS ("super") SuperLearner() SuperLearner

If you would like to see your package or method integrated into WeightIt, or for any other questions or comments about WeightIt, please contact Noah Greifer at [email protected].


WeightIt News and Updates

Version 0.5.1

  • Fixed a bug when using the ps argument in weightit().

  • Fixed a bug when setting include.obj = TRUE in weightitMSM().

  • Added warnings for using certain methods with longitudinal treatments as they are not validated and may lead to incorrect inferences.

Version 0.5.0

  • Added super method to estimate propensity scores using the SuperLearner package.

  • Added optweight method to estimate weights using optimization (but you should probably just use the optweight package).

  • weightit() now uses the correct formula to estimate weights for the ATO with multinomial treatments as described by Li & Li (2018).

  • Added include.obj option in weightit() and weightitMSM() to include the fitted object in the output object for inspection. For example, with method = "ps", the glm object containing the propensity score model will be included in the output.

  • Rearranged the help pages. Each method now has its own documentation page, linked from the weightit help page.

  • Propensity scores are now included in the output for binary tretaments with gbm and cbps methods. Thanks to @Blanch-Font for the suggestion.

  • Other bug fixes and minor changes.

Version 0.4.0

  • Added trim() function to trim weights.

  • Added ps.cont() function, which estimates generalized propensity score weights for continuous treatments using generalized boosted modeling, as in twang. This function uses the same syntax as ps() in twang, and can also be accessed using weightit() with method = "gbm". Support functions were added to make it compatible with twang functions for assessing balance (e.g., summary, bal.table, plot). Thanks to Donna Coffman for enlightening me about this method and providing the code to implement it.

  • The input formula is now much more forgiving, allowing objects in the environment to be included. The data argument to weightit() is now optional. To simplify things, the output object no longer contains a data field.

  • Under-the-hood changes to facilitate adding new features and debugging. Some aspects of the output objects have been slightly changed, but it shouldn't affect use for most users.

  • Fixed a bug where variables would be thrown out when method = "ebal".

  • Added support for sampling weights with stable balancing weighting and empirical balancing calibration weighting.

Version 0.3.2

  • Added new moments and int options for some weightit() methods to easily specify moments and interactions of covariates.

  • Fixed bug when using objects not in the data set in weightit(). Behavior has changed to include transformed covariates entered in formula in weightit() output.

  • Fixed bug resulting from potentially colinearity when using ebal or ebcw.

  • Added a vignette.

Version 0.3.1

  • Edits to code and help files to protect against missing CBPS package.

  • Corrected sampling weights functionality so they work correctly. Also expanded sampling weights to be able to be used with all methods, including those that do not natively allow for sampling weights (e.g., sbw and ATE)

  • Minor bug fixes and spelling corrections.

Version 0.3.0

  • Added weightitMSM() function (and supporting print() and summary() functions) to estimate weights for marginal structural models with time-varying treatments and covariates.

  • Fixed some bugs, including when using CBPS with continuous treatments, and when using focal incorrectly.

Version 0.2.0

  • Added method = "sbw" for stable balancing weights

  • Allowed for estimation of multinomial propensity scores using multiple binary regressions if mlogit is not installed

  • Allowed for estimation of multinomial CBPS using multiple binary CBPS for more than 4 groups

  • Added README and NEWS

Version 0.1.0

  • First version!

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.5.1 by Noah Greifer, 3 months ago


Report a bug at https://github.com/ngreifer/WeightIt/issues

Browse source code at https://github.com/cran/WeightIt

Authors: Noah Greifer [aut, cre]

Documentation:   PDF Manual  

GPL (>= 2) license

Imports cobalt

Suggests twang, CBPS, ebal, ATE, optweight, SuperLearner, class, gam, mlogit, MNP, survey, jtools, boot, wCorr, gbm, knitr, rmarkdown

Suggested by cobalt.

See at CRAN