Skip to contents

This function performs Bayesian non-parametric bootstrap to estimate causal effects in Bayesian marginal structural models. It supports both continuous (gaussian) and binary (binomial) outcome variables.

Usage

bayesmsm(
  ymodel,
  nvisit,
  reference = c(rep(0, nvisit)),
  comparator = c(rep(1, nvisit)),
  family = "gaussian",
  data,
  wmean = rep(1, nrow(data)),
  nboot = 1000,
  optim_method = "BFGS",
  seed = 890123,
  parallel = TRUE,
  ncore = 4
)

Arguments

ymodel

Model statement for the outcome variable.

nvisit

Number of visits or time points to simulate.

reference

Vector denoting the intervention to be used as the reference across all visits for calculating the risk ratio and risk difference. The default is a vector of all 0's with length nvisit (i.e. never treated).

comparator

Vector denoting the intervention to be used as the comparator across all visits for calculating the risk ratio and risk difference. The default is a vector of all 1's with length nvisit (i.e. always treated).

family

Character string specifying the outcome distribution family. The possible distributions are: "gaussian" (default) for continuous outcomes, and "binomial" for binary outcomes.

data

Data table containing the variable names in `ymodel`.

wmean

Vector of treatment assignment weights. The default is rep(1, nrow(data)).

nboot

Integer specifying the number of bootstrap iterations. The default is 1000.

optim_method

Character string specifying the optimization method to be used. The default is 'BFGS'.

seed

Starting seed for simulations and bootstrapping. The default is 890123.

parallel

Logical scalar indicating whether to parallelize bootstrapping to multiple cores. The default is TRUE.

ncore

Integer specifying the number of CPU cores to use in parallel simulation. This argument is required when parallel is set to TRUE, and the default is 4.

Value

It returns an object of class `bayesmsm` that contains the information about the data, model, etc.

An object of class `bayesmsm` is a list containing at least the following components: * `mean`, the mean of the bootstrap estimates * `sd`, the standard deviation of the bootstrap estimates * `quantile`, the 95 * `bootdata`, a data frame of bootstrapped estimates * `reference`, the reference intervention level * `comparator`, the camparison intervention level

Examples

# Continuous outcome
testdata <- read.csv(system.file("extdata",
                                 "continuous_outcome_data.csv",
                                 package = "bayesmsm"))
model <- bayesmsm(ymodel = y ~ a_1+a_2,
                           nvisit = 2,
                           reference = c(rep(0,2)),
                           comparator = c(rep(1,2)),
                           family = "gaussian",
                           data = testdata,
                           wmean = rep(1, 1000),
                           nboot = 100,
                           optim_method = "BFGS",
                           seed = 890123,
                           parallel = TRUE,
                           ncore = 2)