crtBayes: Bayesian analysis of Cluster Randomised Education Trials...

View source: R/crtBayes.R

crtBayesR Documentation

Bayesian analysis of Cluster Randomised Education Trials (CRT) using Vague Priors.

Description

crtBayes performs Bayesian multilevel analysis of cluster randomised education trials, utilising vague priors and JAGS language to fit the model. It assumes hierarchical clustering, such as students within schools, and estimates treatment effects while accounting for this structure.

Usage

crtBayes(formula, random, intervention, nsim = 10000, data)

Arguments

formula

The model to be analysed. It should be of the form y ~ x1 + x2 + ..., where y is the outcome variable and Xs are the predictors.

random

A string specifying the "clustering variable" (e.g., schools or sites) as found in the dataset.

intervention

A string specifying the "intervention variable" as it appears in the formula.

nsim

Number of MCMC iterations to be performed. A minimum of 10,000 is recommended to ensure convergence.

data

A data frame containing the variables referenced in the formula, including predictors, the clustering variable, and the intervention.

Details

The function provides posterior estimates for fixed effects (predictors) and random effects (clustering) under a Bayesian framework. Effect sizes are computed using Hedges' g, and variance components are decomposed into between-cluster and within-cluster variances.

Value

S3 object; a list consisting of:

  • Beta: Estimates and credible intervals for the predictors specified in the model (posterior distributions).

  • ES: Hedges' g effect size for the intervention(s). If bootstrapping is not used, 95% credible intervals are computed based on MCMC sampling.

  • covParm: Variance components broken down into between-cluster variance (e.g., between schools), within-cluster variance (e.g., within pupils), and intra-cluster correlation (ICC)..

  • ProbES: A matrix showing the probability of observing an effect size larger than various thresholds (0, 0.05, 0.10, ...).

  • Unconditional: A list containing the unconditional effect size and variance decomposition.

Examples

if(interactive()){

  data(crtData)

  ########################################################
  ## Bayesian analysis of cluster randomised trials     ##
  ########################################################

  output <- crtBayes(formula = Posttest ~ Prettest + Intervention,
                     random = "School",
                     intervention = "Intervention",
                     nsim = 10000,
                     data = crtData)
  output

  ### Fixed effects
  beta <- output$Beta
  beta

  ### Effect size
  ES1 <- output$ES
  ES1

  ## Covariance matrix
  covParm <- output$covParm
  covParm

  ## Prob ES
  ProbES <- output$ProbES
  ProbES

  ## Unconditional
  Unconditional <- output$Unconditional
  Unconditional


  ### plot random effects for schools

  plot(output)

  ### plot posterior probability of an effect size to be bigger than a pre-specified threshold

  plot(output,group=1)


  ###########################################################################################
  ## Bayesian analysis of cluster randomised trials using informative priors for treatment ##
  ###########################################################################################

  ### define priors for explanatory variables

  my_prior <- normal(location = c(0,6), scale = c(10,1))

  ### specify the priors for the conditional model only

  output2 <- crtBayes(Posttest~ Prettest+Intervention,random="School",
                     intervention="Intervention",nsim=2000,data=crtData,
                     condopt=list(prior=my_prior))

  ### Fixed effects
  beta2 <- output2$Beta
  beta2

  ### Effect size
  ES2 <- output2$ES
  ES2
}


germaine86/eefAnalytics documentation built on Oct. 12, 2024, 11:32 a.m.