Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ngreifer/weightit
WeightIt: an R package for propensity score weighting
https://github.com/ngreifer/weightit
causal-inference inverse-probability-weights observational-study propensity-scores r
Last synced: 5 days ago
JSON representation
WeightIt: an R package for propensity score weighting
- Host: GitHub
- URL: https://github.com/ngreifer/weightit
- Owner: ngreifer
- Created: 2017-11-22T16:17:18.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-13T00:50:17.000Z (about 1 month ago)
- Last Synced: 2024-12-15T23:01:40.099Z (12 days ago)
- Topics: causal-inference, inverse-probability-weights, observational-study, propensity-scores, r
- Language: R
- Homepage: https://ngreifer.github.io/WeightIt/
- Size: 14.5 MB
- Stars: 104
- Watchers: 4
- Forks: 14
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
Awesome Lists containing this project
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = FALSE,
warning = FALSE,
message = FALSE,
tidy = FALSE,
fig.align='center',
comment = "#>",
fig.path = "man/figures/README-"
)
```
# WeightIt: Weighting for Covariate Balance in Observational Studies[![CRAN status](https://www.r-pkg.org/badges/version/WeightIt?color=00622B)](https://CRAN.R-project.org/package=WeightIt)
[![CRAN_Downloads_Badge](https://cranlogs.r-pkg.org/badges/WeightIt?color=00622B)](https://cran.r-project.org/package=WeightIt)### Overview
*WeightIt* is a one-stop package to generate balancing weights for point and longitudinal treatments in observational studies. Support is included for binary, multi-category, and continuous treatments, a variety of estimands including the ATE, ATT, ATC, ATO, and others, and support for a wide variety of weighting methods, including those that rely on parametric modeling, machine learning, or optimization. *WeightIt* also provides functionality for fitting regression models in weighted samples that account for estimation of the weights in quantifying uncertainty. *WeightIt* uses a familiar formula interface and is meant to complement `MatchIt` as a package that provides a unified interface to basic and advanced weighting methods.
For a complete vignette, see the [website](https://ngreifer.github.io/WeightIt/articles/WeightIt.html) for *WeightIt* or `vignette("WeightIt")`.
To install and load *WeightIt* , use the code below:
```{r, eval = FALSE}
#CRAN version
pak::pkg_install("WeightIt")#Development version
pak::pkg_install("ngreifer/WeightIt")library("WeightIt")
```
```{r, include = FALSE}
library("WeightIt")
```The workhorse function of *WeightIt* is `weightit()`, which generates weights from a given formula and data input according to methods and other parameters specified by the user. Below is an example of the use of `weightit()` to generate propensity score weights for estimating the ATT:
```{r}
data("lalonde", package = "cobalt")W <- weightit(treat ~ age + educ + nodegree +
married + race + re74 + re75,
data = lalonde, method = "glm",
estimand = "ATT")
W
```Evaluating weights has two components: evaluating the covariate balance produced 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:
```{r}
library("cobalt")bal.tab(W, un = TRUE)
```For the second goal, qualities of the distributions of weights can be assessed using `summary()`, as demonstrated below.
```{r}
summary(W)
```Desirable qualities include small coefficients of variation close to 0 and large effective sample sizes.
Finally, we can estimate the effect of the treatment using a weighted outcome model, accounting for estimation of the weights in the standard error of the effect estimate:
```{r}
fit <- glm_weightit(re78 ~ treat, data = lalonde,
weightit = W)summary(fit, ci = TRUE)
```The tables below contains the available methods in *WeightIt* for estimating weights for binary, multi-category, and continuous treatments. Many of these methods do not require any other package to use; see `vignette("installing-packages")` for information on how to install packages that are used.
#### Binary TreatmentsMethod | `method`
-------------------- | --------
Binary regression PS | [`"glm"`](https://ngreifer.github.io/WeightIt/reference/method_glm.html)
Generalized boosted modeling PS | [`"gbm"`](https://ngreifer.github.io/WeightIt/reference/method_gbm.html)
Covariate balancing PS | [`"cbps"`](https://ngreifer.github.io/WeightIt/reference/method_cbps.html)
Non-Parametric covariate balancing PS | [`"npcbps"`](https://ngreifer.github.io/WeightIt/reference/method_npcbps.html)
Entropy balancing | [`"ebal"`](https://ngreifer.github.io/WeightIt/reference/method_ebal.html)
Inverse probability tilting | [`"ipt"`](https://ngreifer.github.io/WeightIt/reference/method_ipt.html)
Stable balancing weights | [`"optweight"`](https://ngreifer.github.io/WeightIt/reference/method_optweight.html)
SuperLearner PS | [`"super"`](https://ngreifer.github.io/WeightIt/reference/method_super.html)
Bayesian additive regression trees PS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html)
Energy balancing | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html)#### Multi-Category Treatments
Method | `method`
-------------------- | --------
Multinomial regression PS | [`"glm"`](https://ngreifer.github.io/WeightIt/reference/method_glm.html)
Generalized boosted modeling PS | [`"gbm"`](https://ngreifer.github.io/WeightIt/reference/method_gbm.html)
Covariate balancing PS | [`"cbps"`](https://ngreifer.github.io/WeightIt/reference/method_cbps.html)
Non-Parametric covariate balancing PS | [`"npcbps"`](https://ngreifer.github.io/WeightIt/reference/method_npcbps.html)
Entropy balancing | [`"ebal"`](https://ngreifer.github.io/WeightIt/reference/method_ebal.html)
Inverse probability tilting | [`"ipt"`](https://ngreifer.github.io/WeightIt/reference/method_ipt.html)
Stable balancing weights | [`"optweight"`](https://ngreifer.github.io/WeightIt/reference/method_optweight.html)
SuperLearner PS | [`"super"`](https://ngreifer.github.io/WeightIt/reference/method_super.html)
Bayesian additive regression trees PS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html)
Energy balancing | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html)
#### Continuous Treatments
Method | `method`
-------------------- | --------
Generalized linear model GPS | [`"glm"`](https://ngreifer.github.io/WeightIt/reference/method_glm.html)
Generalized boosted modeling GPS | [`"gbm"`](https://ngreifer.github.io/WeightIt/reference/method_gbm.html)
Covariate balancing GPS | [`"cbps"`](https://ngreifer.github.io/WeightIt/reference/method_cbps.html)
Non-Parametric covariate balancing GPS | [`"npcbps"`](https://ngreifer.github.io/WeightIt/reference/method_npcbps.html)
Entropy balancing | [`"ebal"`](https://ngreifer.github.io/WeightIt/reference/method_ebal.html)
Stable balancing weights | [`"optweight"`](https://ngreifer.github.io/WeightIt/reference/method_optweight.html)
SuperLearner GPS | [`"super"`](https://ngreifer.github.io/WeightIt/reference/method_super.html)
Bayesian additive regression trees GPS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html)
Distance covariance optimal weighting | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html)
In addition, *WeightIt* implements the subgroup balancing propensity score using the function `sbps()`. Several other tools and utilities are available, including `trim()` to trim or truncate weights, `calibrate()` to calibrate propensity scores, `get_w_from_ps()` to compute weights from propensity scores.*WeightIt* provides functions to fit weighted models that account for the uncertainty in estimating the weights. These include `glm_weightit()` for fitting generalized linear models, `ordinal_weightit()` for ordinal regression models, `multinom_weightit()` for multinomial regression models, and `coxph_weightit()` for Cox proportional hazards models. Several methods are available for computing the parameter variances, including asymptotically correct M-estimation-base variances, robust variances that treat the weights as fixed, and traditional and fractional weighted bootstrap variances. Clustered variances are supported. See `vignette("estimating-effects")` for information on how to use these after weighting to estimate treatment effects.
Please submit bug reports, questions, comments, or other issues to https://github.com/ngreifer/WeightIt/issues. If you would like to see your package or method integrated into *WeightIt*, please contact the author. Fan mail is greatly appreciated.