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: about 2 months 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-04T18:41:19.000Z (about 2 months ago)
- Last Synced: 2024-11-04T19:36:11.334Z (about 2 months ago)
- Topics: causal-inference, inverse-probability-weights, observational-study, propensity-scores, r
- Language: R
- Homepage: https://ngreifer.github.io/WeightIt/
- Size: 14.4 MB
- Stars: 102
- Watchers: 4
- Forks: 13
- Open Issues: 5
-
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
install.packages("WeightIt")#Development version
remotes::install_github("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 <- lm_weightit(re78 ~ treat, data = lalonde,
weightit = W)summary(fit, ci = TRUE)
```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. Many of these methods do not require any other package to use (i.e., those with "-" in the Package column). See `vignette("installing-packages")` for information on how to install packages that are used.
Treatment type | Method (`method = `) | Package
-------------- | -------------------- | --------
**Binary** | Binary regression PS (`"glm"`) | various
- | Generalized boosted modeling PS (`"gbm"`) | `gbm`
- | Covariate balancing PS (`"cbps"`) | -
- | Non-parametric covariate balancing PS (`"npcbps"`) | `CBPS`
- | Entropy Balancing (`"ebal"`) | -
- | Inverse probability tilting (`"ipt"`) | -
- | Optimization-based Weights (`"optweight"`) | `optweight`
- | SuperLearner PS (`"super"`) | `SuperLearner`
- | Bayesian additive regression trees PS (`"bart"`) | `dbarts`
- | Energy balancing (`"energy"`) | -
**Multi-category** | Multinomial regression PS (`"glm"`) | various
- | Generalized boosted modeling PS (`"gbm"`) | `gbm`
- | Covariate balancing PS (`"cbps"`) | -
- | Non-Parametric covariate balancing PS (`"npcbps"`) | `CBPS`
- | Entropy balancing (`"ebal"`) | -
- | Inverse probability tilting (`"ipt"`) | -
- | Optimization-based weights (`"optweight"`) | `optweight`
- | SuperLearner PS (`"super"`) | `SuperLearner`
- | Bayesian additive regression trees PS (`"bart"`) | `dbarts`
- | Energy balancing (`"energy"`) | -
**Continuous** | Generalized linear model GPS (`"glm"`) | -
- | Generalized boosted modeling GPS (`"gbm"`) | `gbm`
- | Covariate balancing GPS (`"cbps"`) | -
- | Non-Parametric covariate balancing GPS (`"npcbps"`) | `CBPS`
- | Entropy balancing (`"ebal"`) | -
- | Optimization-based weights (`"optweight"`) | `optweight`
- | SuperLearner GPS (`"super"`) | `SuperLearner`
- | Bayesian additive regression trees GPS (`"bart"`) | `dbarts`
- | Distance covariance optimal weighting (`"energy"`) | -
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.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.