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: 2 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 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-28T16:49:51.000Z (over 2 years ago)
- Last Synced: 2025-03-01T05:31:59.835Z (3 months 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
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = FALSE,
warning = FALSE,
message = FALSE,
tidy = TRUE,
fig.align='center',
comment = "",
fig.path = "inst/figures/README-"
)
```
# optweight[](https://cran.r-project.org/package=optweight)
[](https://cran.r-project.org/package=optweight)`optweight` contains functions to estimate weights that balance treatments to given balance thresholds. It solves a quadratic programming problem to minimize an objective function of the weights using `solve_osqp()` in the `osqp` package. This is the method described in Zubizarreta (2015). `optweight` extends the method to multinomial, continuous, and longitudinal treatments and provides a simple user interface and compatibility with the `cobalt` package.
Below is an example of estimating weights with `optweight` and assessing balance on the covariates with `cobalt`.
```{r, eval = FALSE}
devtools::install_github("ngreifer/optweight") #development version
library("optweight")
library("cobalt")
```
```{r, include = FALSE}
library("optweight")
library("cobalt")
```
```{r}
data("lalonde")#Estimate weights
ow <- optweight(treat ~ age + educ + race + nodegree + married +
re74 + re75 + I(re74 == 0) + I(re75 == 0),
data = lalonde, estimand = "ATT", tols = .01)
ow
summary(ow)
bal.tab(ow)#Estimate a treatment effect
library("jtools")
summ(lm(re78 ~ treat, data = lalonde, weights = ow$weights),
confint = TRUE, robust = TRUE, model.fit = FALSE,
model.info = FALSE)
```The lower-level function `optweight.fit` operates on the covariates and treatment variables directly.
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 the function `optweight.svy`.