This function estimates Bayesian weights for time-varying treatment effects using specified models for each treatment time point. It uses JAGS for Bayesian inference and supports parallel computation to speed up the MCMC simulations.
Usage
bayesweight(
trtmodel.list,
data,
n.chains = 2,
n.iter = 25000,
n.burnin = 15000,
n.thin = 5,
seed = 890123,
parallel = TRUE
)
Arguments
- trtmodel.list
A list of formulas corresponding to each time point with the time-specific treatment variable on the left hand side and pre-treatment covariates to be balanced on the right hand side. The formulas must be in temporal order, and must contain all covariates to be balanced at that time point. Interactions and functions of covariates are allowed.
- data
A data set in the form of a data frame containing the variables in `trtmodel.list`. This must be a wide data set with exactly one row per unit.
- n.chains
Integer specifying the number of MCMC chains to run. Set to 1 for non-parallel computation. For parallel computation, it is required to use at least 2 chains. The default is 2.
- n.iter
Integer specifying the total number of iterations for each chain (including burn-in). The default is 25000.
- n.burnin
Integer specifying the number of burn-in iterations for each chain. The default is 15000.
- n.thin
Integer specifying the thinning rate for the MCMC sampler. The default is 5.
- seed
Starting seed for the JAGS model. The default is 890123.
- parallel
Logical scalar indicating whether to run the MCMC chains in parallel. The default is TRUE.
Examples
# Continuous outcome
testdata <- read.csv(system.file("extdata",
"continuous_outcome_data.csv",
package = "bayesmsm"))
weights <- bayesweight(trtmodel.list = list(a_1 ~ w1 + w2 + L1_1 + L2_1,
a_2 ~ w1 + w2 + L1_1 + L2_1 +
L1_2 + L2_2 + a_1),
data = testdata,
n.iter = 2500,
n.burnin = 1500,
n.thin = 5,
n.chains = 2,
seed = 890123,
parallel = TRUE)