Description Usage Arguments Details Value Author(s) References Examples
Function for tabulating the means of the covariates and assessing balance after weighting.
1 |
data_frame_weights |
a data frame with the treatment or nonresponse indicator, covariates, and weights organized in columns. |
t_ind |
a string with the name of the treatment or nonresponse indicator in |
bal_covs |
a vector of strings with the names of the covariates in |
weights |
a string with the name of the weights in |
target |
a string that determines whether the weights were calculated to estimate: (i) the average treatment effect (in which case the target sample are all the units in the treatment or nonresponse indicator |
digits |
a scalar indicating the number of digits to display in the columns of the table. |
mean_bal
is a function for tabulating the means of the covariates and assessing covariate balance after weighting.
A table with the following columns:
Mean Target |
mean of the target sample for each covariate; |
Mean Weighted |
mean of the weighted sample for each covariate; |
Std. Difference |
standardized differences in means after weighting for each covariate. |
Jose R. Zubizarreta <zubizarreta@columbia.edu>
Zubizarreta, J. R., "Stable Weights that Balance Covariates for Causal Inference and Estimation with Incomplete Data," submitted.
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 70 71 72 73 74 | # Simulate data
kangschafer = function(n_obs) {
#! Z are the true covariates
#! t is the indicator for the respondents (treated)
#! y is the outcome
#! X are the observed covariates
#! Returns Z, t y and X sorted in decreasing order by t
Z = mvrnorm(n_obs, mu=rep(0, 4), Sigma=diag(4))
p = 1/(1+exp(Z[, 1]-.5*Z[, 2]+.25*Z[, 3]+.1*Z[, 4]))
t = rbinom(n_obs, 1, p)
Zt = cbind(Z, p, t)
Zt = Zt[order(t), ]
Z = Zt[, 1:4]
p = Zt[, 5]
t = Zt[, 6]
y = 210+27.4*Z[, 1]+13.7*Z[, 2]+13.7*Z[, 3]+13.7*Z[, 4]+rnorm(n_obs)
X = cbind(exp(Z[, 1]/2), (Z[, 2]/(1+exp(Z[, 1])))+10, (Z[, 1]*Z[, 3]/25+.6)^3, (Z[, 2]+Z[, 4]+20)^2)
return(list(Z=Z, p=p, t=t, y=y, X=X))
}
set.seed(1)
n_obs = 200
aux = kangschafer(n_obs)
Z = aux$Z
p = aux$p
t = aux$t
y = aux$y
X = aux$X
# Data frame
t_ind = t
bal_covs = X
data_frame = as.data.frame(cbind(t_ind, bal_covs))
names(data_frame) = c("t_ind", "X1", "X2", "X3", "X4")
# Treatment indicator
t_ind = "t_ind"
# Moment covariates
bal_covs = c("X1", "X2", "X3", "X4")
# Moment tolerances
bal_tols = 1/100
# Whether the moment tolerances are expressed in standard deviations
bal_tols_sd = TRUE
# Here, the 0's in t_ind are weighted to "represent" the 1's and estimate the average treatment on the treated
target = "all"
# Here, the "ell-2" norm is used to minimize the variance of the weights
l_norm = "l_2"
# Minimum value of the weights
w_min = 0
# Here, the weights are constrained to add up to one
normalize = 1
# Solver
solver = "quadprog"
# Output display
display = 0
# Find optimal weights
out = sbw(data_frame, t_ind, bal_covs, bal_tols, bal_tols_sd, target, l_norm, w_min, normalize, solver, display)
# Check balance
data_frame_weights = out$data_frame_weights
t_ind = "t_ind"
bal_covs = c("X1", "X2", "X3", "X4")
weights = "weights"
target = "all"
meanbal(data_frame_weights, t_ind, bal_covs, weights, target, digits=2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.