An open API service indexing awesome lists of open source software.

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

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

[![CRAN_Status_Badge](http://r-pkg.org/badges/version-last-release/optweight?color=0047ab
)](https://cran.r-project.org/package=optweight)
[![CRAN_Downloads_Badge](http://cranlogs.r-pkg.org/badges/optweight?color=0047ab
)](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`.