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 CRAN_Downloads_Badge

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.

devtools::install_github("ngreifer/optweight") #development version
library("optweight")
library("cobalt")
library("optweight")
library("cobalt")
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.



ngreifer/optweight documentation built on Nov. 2, 2022, 10:05 a.m.