Learn R Programming

outstandR (version 1.0.0)

calc_gcomp_bayes: Bayesian G-computation using Stan

Description

Calculate draws of binary responses from posterior predictive distribution from the Bayesian G-computation method using Hamiltonian Monte Carlo.

Usage

calc_gcomp_bayes(strategy, analysis_params, ...)

Value

A list containing:

  • means: A list containing:

    • A: Posterior means for comparator treatment group "A".

    • C: Posterior means for reference treatment group "C".

  • model: A list containing the fit object (from stan_glm), rho, N, and stan_args.

Arguments

strategy

A list specifying the model strategy, including:

  • formula: A linear regression formula object.

  • family: A family object specifying the distribution and link function (e.g., binomial).

  • iter: Number of iterations for the MCMC sampling.

  • warmup: Number of warmup iterations for the MCMC sampling.

  • chains: Number of MCMC chains.

analysis_params

List of analysis parameters. Must contain ipd and ald.

...

Additional arguments passed to rstanarm::stan_glm().

Examples

Run this code
strategy <- list(
  formula = y ~ trt:X1,
  family = binomial(),
  rho = NA,
  N = 1000L,
  marginal_distns = NA,
  marginal_params = NA,
  trt_var = "trt",
  iter = 2000,
  warmup = 500,
  chains = 4)

ipd <- data.frame(
   trt = sample(c("A", "C"), size = 100, replace = TRUE),
   X1 = rnorm(100, 1, 1),
   y = sample(c(1,0), size = 100, prob = c(0.7, 0.3), replace = TRUE))

ald <- data.frame(
  trt = c(NA, NA, "B", "C", "B", "C"),
  variable = c("X1", "X1", "y", "y", NA, NA),
  statistic = c("mean", "sd", "sum", "sum", "N", "N"),
  value = c(0.5, 0.1, 10, 12, 20, 25))

calc_gcomp_bayes(
  strategy,
  analysis_params = list(
    ipd = ipd, ald = ald, 
    ref_trt = "C",
    ipd_comp = "A"))

Run the code above in your browser using DataLab