Bayesian Treatment Effect Weight Estimation for Censored Data
Source:R/bayesweight_cen.R
bayesweight_cen.Rd
This function computes posterior mean weights using Bayesian estimation for treatment models and censoring models across multiple time points. The models can be run in parallel to estimate the weights for censored data.
Usage
bayesweight_cen(
trtmodel.list,
cenmodel.list,
data,
n.iter = 25000,
n.burnin = 15000,
n.thin = 5,
parallel = TRUE,
n.chains = 2,
seed = 890123
)
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.
- cenmodel.list
A list of formulas for the censored data at each time point, with censoring indicators on the left-hand side and covariates on the right-hand side. The formulas must be in temporal order, and must contain all covariates to be balanced at that time point.
- data
A data set in the form of a data frame containing the variables in `trtmodel.list` and `cenmodel.list`. This must be a wide data set with exactly one row per unit.
- 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.
- parallel
Logical scalar indicating whether to run the MCMC chains in parallel. The default is TRUE.
- 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.
- seed
Starting seed for the JAGS model. The default is 890123.
Value
A vector of posterior mean weights, computed by taking the average of the weights across all MCMC iterations.
Examples
simdat_cen <- read.csv(system.file("extdata",
"sim_causal.csv",
package = "bayesmsm"))
weights_cen <- bayesweight_cen(trtmodel.list = list(A1 ~ L11 + L21,
A2 ~ L11 + L21 + L12 +
L22 + A1,
A3 ~ L11 + L21 + L12 +
L22 + A1 + L13 +
L23 + A2),
cenmodel.list = list(C1 ~ L11 + L21,
C2 ~ L11 + L21 + A1,
C3 ~ L11 + L21 + A1 +
L12 + L22 + A2),
data = simdat_cen,
n.iter = 1500,
n.burnin = 500,
n.thin = 1,
parallel = FALSE,
n.chains = 1,
seed = 890123)
#> module glm loaded
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 4836
#> Unobserved stochastic nodes: 44
#> Total graph size: 16501
#>
#> Initializing model
#>
#> Warning: Some parameters have not converged with Geweke index > 1.96. More iterations may be needed.