MyNixOS website logo
Description

Targeted Stable Balancing Weights Using Optimization.

Use optimization to estimate weights that balance covariates for binary, multinomial, and continuous treatments in the spirit of Zubizarreta (2015) <doi:10.1080/01621459.2015.1023805>. The degree of balance can be specified for each covariate. In addition, sampling weights can be estimated that allow a sample to generalize to a population specified with given target moments of covariates.

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")
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
An optweight object
 - number of obs.: 614
 - sampling weights: none
 - treatment: 2-category
 - estimand: ATT (focal: 1)
 - covariates: age, educ, race, nodegree, married, re74, re75, I(re74 == 0), I(re75 == 0)
summary(ow)
Summary of weights:

- Weight ranges:
        Min                                  Max
treated   1     ||                        1.0000
control   0 |---------------------------| 7.4319

- Units with 5 greatest weights by group:
                                           
              2      3      4      5      6
 treated      1      1      1      1      1
            608    574    559    573    303
 control 7.2344 7.3161 7.4058 7.4058 7.4319

        Coef of Var Mean Abs Dev
treated      0.0000       0.0000
control      1.9019       1.3719
overall      1.5897       0.9585

- Effective Sample Sizes:
           Control Treated
Unweighted 429.000     185
Weighted    92.917     185
bal.tab(ow)
Call
 optweight(formula = treat ~ age + educ + race + nodegree + married + 
    re74 + re75 + I(re74 == 0) + I(re75 == 0), data = lalonde, 
    tols = 0.01, estimand = "ATT")

Balance Measures
                Type Diff.Adj
age          Contin.     0.01
educ         Contin.     0.01
race_black    Binary     0.01
race_hispan   Binary     0.00
race_white    Binary    -0.01
nodegree      Binary     0.01
married       Binary    -0.01
re74         Contin.     0.01
re75         Contin.     0.01
I(re74 == 0)  Binary     0.01
I(re75 == 0)  Binary     0.01

Effective sample sizes
           Control Treated
Unadjusted 429.000     185
Adjusted    92.917     185
#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)

Est.

2.5%

97.5%

t val.

p

(Intercept)

5342.94

4058.75

6627.13

8.17

0.00

treat

1006.20

-710.34

2722.74

1.15

0.25

Standard errors: Robust, type = HC3

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.

Metadata

Version

0.2.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows