crtBayes: Bayesian analysis of cluster randomised education trials...

View source: R/crtBayes.R

crtBayesR Documentation

Bayesian analysis of cluster randomised education trials using Vague Priors.

Description

crtBayes performs analysis of cluster randomised education trials using a multilevel model under a Bayesian setting, assuming vague priors.

Usage

crtBayes(
  formula,
  random,
  intervention,
  baseln,
  adaptD,
  nsim = 2000,
  condopt,
  uncopt,
  data,
  threshold = 1:10/10,
  ...
)

Arguments

formula

the model to be analysed is of the form y ~ x1+x2+.... Where y is the outcome variable and Xs are the independent variables.

random

a string variable specifying the "clustering variable" as contained in the data. See example below.

intervention

a string variable specifying the "intervention variable" as appearing in the formula and the data. See example below.

baseln

A string variable allowing the user to specify the reference category for intervention variable. When not specified, the first level will be used as a reference.

adaptD

As this function uses rstanarm, this term provides the target average proposal acceptance probability during Stan’s adaptation period. Default is NULL.

nsim

number of MCMC iterations per chain. Default is 2000.

condopt

additional arguments of stan_glm to be passed only to the conditional model specification (for example, defining priors only for the conditional model, etc.).

uncopt

additional arguments of stan_glm to be passed only to the unconditional model specification (for example, defining priors only for the unconditional model, etc.).

data

data frame containing the data to be analysed.

threshold

a scalar or vector of pre-specified threshold(s) for estimating Bayesian posterior probability such that the observed effect size is greater than or equal to the threshold(s).

...

additional arguments of stan_lmer to be passed both to the conditional and unconditional model specifications.

Value

S3 object; a list consisting of

  • Beta: Estimates and credible intervals for variables specified in the model. Use summary.eefAnalytics to get Rhat and effective sample size for each estimate.

  • ES: Conditional Hedges' g effect size and its 95% credible intervals.

  • covParm: A vector of variance decomposition into between cluster variance (Schools) and within cluster variance (Pupils). It also contains intra-cluster correlation (ICC).

  • SchEffects: A vector of the estimated deviation of each school from the intercept.

  • ProbES: A matrix of Bayesian Posterior Probabilities such that the observed effect size is greater than or equal to a pre-specified threshold(s).

  • Model: A stan_glm object used in ES computation, this object can be used for convergence diagnostic.

  • Unconditional: A list of unconditional effect sizes, covParm and ProbES obtained based on between and within cluster variances from the unconditional model (model with only the intercept as a fixed effect).

Examples

if(interactive()){

  data(crtData)

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

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

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

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

  ## Covariance matrix
  covParm <- output$covParm
  covParm

  ### 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
}


eefAnalytics documentation built on May 31, 2023, 9:24 p.m.