Description Usage Arguments Value Examples
View source: R/entropy_balancing_dev.R
Compute optimal balancing weights via entropy balancing
1 2 3 4 5 6 7 8 |
formula |
Typical R style formula - ex. 'TA ~ X1 + X2' |
data |
R |
eb_pars |
R The list recommends including the following variables at a minimum:
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 For
For
|
suppress_warnings |
logical argument to suppress warnings of function checking |
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
wts
- Optimal weights for the estimand of interest and matched number of moments.
convergence
- Convergence code from optim
package
message
- Convergence message from optim
package
opt_obj
- optimization object from optim
package
eb_pars
- variable list the model was fit to
X
- Model frame created from data.
TA
- Vector of Exposure Assignments Used.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.