https://github.com/ngreifer/optweight
R package for estimating balancing weights using optimization
https://github.com/ngreifer/optweight
causal-inference inverse-probability-weights observational-study optimization propensity-scores
Last synced: 3 months ago
JSON representation
R package for estimating balancing weights using optimization
- Host: GitHub
- URL: https://github.com/ngreifer/optweight
- Owner: ngreifer
- Created: 2018-07-08T22:26:40.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-10-28T16:49:51.000Z (over 3 years ago)
- Last Synced: 2025-03-01T05:31:59.835Z (over 1 year ago)
- Topics: causal-inference, inverse-probability-weights, observational-study, optimization, propensity-scores
- Language: R
- Homepage: https://ngreifer.github.io/optweight/
- Size: 604 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
Awesome Lists containing this project
README
---
output: github_document
bibliography: vignettes/references.bib
link-citations: true
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = FALSE,
warning = FALSE,
message = FALSE,
tidy = FALSE,
fig.align = 'center',
comment = "#>",
fig.path = "man/figures/README-"
)
```
# *optweight*: Optimization-Based Stable Balancing Weights 
[](https://cran.r-project.org/package=optweight)
[](https://cran.r-project.org/package=optweight)
*optweight* contains functions to estimate stable balancing weights that balance covariates up to given thresholds. It solves a convex optimization problem to minimize a function of the weights that captures their variability (or divergence from a set of base weights). This is the method described in @zubizarretaStableWeightsThat2015, @kallbergLargeSampleProperties2023, and @wangMinimalDispersionApproximately2020. *optweight* extends the method to multi-category, continuous, and multivariate treatments and provides a simple user interface and compatibility with the [*cobalt*](https://ngreifer.github.io/cobalt/) package for balance assessment. See `vignette("optweight")` for a more thorough description of the package's capabilities.
To install *optweight*, use the code below:
```{r, eval = FALSE}
#CRAN version
install.packages("optweight")
#Development version
pak::pkg_install("ngreifer/optweight")
```
Below is an example of estimating weights with *optweight* and assessing balance on the covariates with *cobalt*.
```{r}
library("optweight")
library("cobalt")
data("lalonde")
# Estimate weights
ow <- optweight(treat ~ age + educ + race + nodegree + married +
re74 + re75,
data = lalonde,
estimand = "ATT",
tols = .01,
min.w = 0)
ow
# Information about the weights
summary(ow)
# Covariate balance
bal.tab(ow)
```
We can see that all standardized mean differences are at or below .01 in absolute value, as requested using the `tols` argument. Because we set `min.w = 0`, some units received weights of 0, effectively dropping them from the sample (by default, the smallest weight allowed is $10^{-8}$).
We can use `plot()` to examine the dual variables for each constraint, which represent how active that constraint is at the optimal point. Highly active constraints affect the objective function value the most when their tolerances are changed.
```{r, fig.width = 6, fig.height=3}
plot(ow)
```
We can see that `race` has the highest dual variable; relaxing the constraint on `race` would yield the biggest improvement in effective sample size, while tightening its constraint would yield the biggest decrease in effective sample size.
The lower-level function `optweight.fit()` operates on the covariates and treatment variables directly. `optweightMV()` supports multivariate (i.e., multiple) treatments.
In addition to estimating balancing weights for estimating treatment effects, *optweight* can estimate sampling weights for generalizing an estimate to a new target population defined by covariate moments using `optweight.svy()`, which implements the methods described in @jacksonAlternativeWeightingSchemes2021 for matching-adjusted indirect comparison (MAIC).
To cite *optweight*, please use `citation("optweight")` to generate the correct reference. Be sure to include the version of the package. Please submit bug reports, questions, comments, or other issues to https://github.com/ngreifer/optweight/issues.
## References