rbwPanel {rbw} | R Documentation |
Residual Balancing Weights for Analyzing Time-varying Treatments
Description
rbwPanel
is a function that produces residual balancing weights (rbw) for
estimating the marginal effects of time-varying treatments. The user supplies
a long format data frame (each row being a unit-period) and a list of
fitted model objects for the conditional mean of each post-treatment confounder given
past treatments and past confounders. The residuals of each time-varying confounder
are balanced across both the current treatment A_t
and the regressors of the confounder
model. In addition, when future > 0
, the residuals are also balanced across future
treatments A_{t+1},\ldots A_{t + future}
.
Usage
rbwPanel(
treatment,
xmodels,
id,
time,
data,
base_weights,
future = 1L,
max_iter = 200,
tol = 1e-04,
print_level = 1
)
Arguments
treatment |
A symbol or character string for the treatment variable in |
xmodels |
A list of fitted |
id |
A symbol or character string for the unit id variable in |
time |
A symbol or character string for the time variable in |
data |
A data frame containing all variables in the model. |
base_weights |
(Optional) A vector of base weights (or its name). |
future |
An integer indicating the number of future treatments in the balancing conditions. When
|
max_iter |
Maximum number of iterations for Newton's method in entropy minimization. |
tol |
Tolerance parameter used to determine convergence in entropy minimization.
See documentation for |
print_level |
The level of printing. See documentation for |
Value
A list containing the results.
weights |
A data frame containing the unit id variable and residual balancing weights. |
constraints |
A matrix of (linearly independent) residual balancing constraints |
eb_out |
Results from calling the |
call |
The matched call. |
Examples
# models for time-varying confounders
m1 <- lm(dem.polls ~ (d.gone.neg.l1 + dem.polls.l1 + undother.l1) * factor(week),
data = campaign_long)
m2 <- lm(undother ~ (d.gone.neg.l1 + dem.polls.l1 + undother.l1) * factor(week),
data = campaign_long)
xmodels <- list(m1, m2)
# residual balancing weights
rbwPanel_fit <- rbwPanel(treatment = d.gone.neg, xmodels = xmodels, id = id,
time = week, data = campaign_long)
summary(rbwPanel_fit$weights)
# merge weights into wide-format data
campaign_wide2 <- merge(campaign_wide, rbwPanel_fit$weights, by = "id")
# fit a marginal structural model (adjusting for baseline confounders)
if(require(survey)){
rbw_design <- svydesign(ids = ~ 1, weights = ~ rbw, data = campaign_wide2)
msm_rbwPanel <- svyglm(demprcnt ~ cum_neg * deminc + camp.length + factor(year) + office,
design = rbw_design)
summary(msm_rbwPanel)
}