-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
58 lines (48 loc) · 2.11 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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`.