entbal: Compute optimal balancing weights via entropy balancing

Description Usage Arguments Value Examples

View source: R/entropy_balancing_dev.R

Description

Compute optimal balancing weights via entropy balancing

Usage

1
2
3
4
5
6
7
8
entbal(
  formula,
  data = NULL,
  eb_pars = list(exp_type = "binary", n_moments = 3, max_iters = 1000, verbose = FALSE,
    bal_tol = 1e-05, opt_constraints = c(-100, 100), estimand = "ATE", optim_method =
    "L-BFGS-B"),
  suppress_warnings = F
)

Arguments

formula

Typical R style formula - ex. 'TA ~ X1 + X2'

data

R data.frame that contains the variables listed in the formula

eb_pars

R list of parameters required for entropy balancing.

The list recommends including the following variables at a minimum:

  • exp_type: choose from binary, multi, continuous

  • n_moments: number of moments to match in the entropy balancing procedure. Recommended 3

  • max_iters: maximum number of iterations for the optimization routine. Recommended 1000

  • verbose: logical for if the optimization should print information to the screen

  • optim_method: Choose L-BFGS-B or BFGS. Recommendation is L-BFGS-B

The function will attempt to set values to default values if variables are not specified and provide warnings when necessary. To ignore these warnings set the suppress_warnings variable to TRUE.

For exp_type = 'binary' or exp_type = 'multi' the following variables should also be set

  • estimand choose from ATE, ATT, ATC, ATZ.

  • which_z defines the referent variable for estimands: ATT, ATC, ATZ

For optim_method = 'L-BFGS-B' the following variables may also be set

  • bal_tol tolerance for the optimization routine

  • opt_constraints parameter constraints for the optimization. Recommend opt_constraints = c(-100,100). If the algorithm sets some of the parameter values to the boundary, try to relax these values further.

suppress_warnings

logical argument to suppress warnings of function checking eb_pars

Value

Object that contains the weights obtained from the balancing procedure and parameters from the optimization procedure

The object that is returned is a list that contains the following entries

Examples

 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
59
60
61
62
63
64
65
66
67
68
69
# Binary exposure example

library(entbal)
n_obs <- 10000
X1 <- rnorm(n_obs)
X2 <- rnorm(n_obs)
A <- rbinom(n_obs, 1, plogis(X1))
A <- factor(ifelse(A == 1, 'A', 'B'))
D <- data.frame(X1, X2, A)
par_list <-  list('exp_type' = 'binary',
                  'n_moments' = 3,
                  'max_iters' = 1000,
                  'estimand' = 'ATC',
                  'verbose' = FALSE,
                  'optim_method' = 'l-bfgs-b',
                  'bal_tol' = 1e-8,
                  'opt_constraints' = c(-1000,1000),
                  'which_z' = 'A')
Q <- entbal(A ~ X1 + X2,
            data = D,
            eb_pars = par_list,
            suppress_warnings = FALSE)
out1 <- summary(Q)

# ---------------------------------------------------------------------------
# Multi-valued exposure - ATZ Example

C <- sample(1:3, n_obs, replace = TRUE)
X1 <- NA
X1[C == 1] <- rnorm(sum(C==1), mean = -0.5, sd = 3)
X1[C == 2] <- rnorm(sum(C==2), mean = 0, sd = 3)
X1[C == 3] <- rnorm(sum(C==3), mean = 0.5)
X2 <- rnorm(n_obs)
D <- data.frame(C, X1, X2)

par_list <-  list('exp_type' = 'multi',
                  'n_moments' = 3,
                  'max_iters' = 1000,
                  'estimand' = 'ATZ',
                  'verbose' = FALSE,
                  'optim_method' = 'l-bfgs-b',
                  'bal_tol' = 1e-8,
                  'opt_constraints' = c(-1000,1000),
                  'which_z' = 3)


P <- entbal(C ~ X1 + X2, data = D, eb_pars = par_list, suppress_warnings = FALSE)
out2 <- summary(P)

# ---------------------------------------------------------------------------
# Continuous exposure example

X1 <- rnorm(n_obs)
X2 <- rnorm(n_obs)
G <- rnorm(n_obs, mean = X1 - X2)
D <- data.frame(G, X1, X2)

par_list <-  list('exp_type' = 'continuous',
                  'n_moments' = 3,
                  'max_iters' = 1000,
                  'estimand' = 'ATE',
                  'verbose' = TRUE,
                  'optim_method' = 'l-bfgs-b',
                  'bal_tol' = 1e-8,
                  'opt_constraints' = c(-1000,1000))


O <- entbal(G ~ X1 + X2, data = D, eb_pars = par_list, suppress_warnings = FALSE)
out3 <- summary(O, show_parameters = TRUE)

bvegetabile/entbal documentation built on July 28, 2021, 8:50 p.m.