Skip to contents

This vignette describes the use of functions within the bayesiantrials package to perform a Bayesian design and analysis of two-arm cluster randomised trials using assurance. This approach is described in Wilson (2022). We will describe the use of the following functions:

  • SimulateGaussianCopula
  • CalculateSampleSize
  • CalculateAssurance

We will apply the Bayesian approach to calculate an appropriate sample size for the ICONS cluster RCT Thomas et al. (2015). The trial considers the effectiveness of a systematic voiding programme for people admitted to NHS stroke units with urinary incontinence. The primary outcome is the incontinence symptom severity total score at 3 months post-randomisation. The voiding programme was compared to usual care.

First we will load the package,

Set the number of samples and define the priors,

# Number of samples
N = 10000    

# Minimal clinically important difference delta
deltaMean = 3.5
deltaSd = 0.9 
deltaPrior = rnorm(N, deltaMean, deltaSd)

# Cluster size coefficient of variation nu
nuMean = 0.49
nuSd = 0.066
nuPrior = rgamma(N, (nuMean^2 / nuSd^2), (nuMean / nuSd^2)) 

# Overall mean effect lambda
lambdaMean = 1
lambdaSd = 0.001
lambdaPrior = rnorm(N, lambdaMean, lambdaSd)

We can load the ICC estimates directly from the package as icons_icc_data,

# Estimates of intra-cluster correlation rho
rho = icons_icc_data

# Standard deviation sigma
sigmaMean = 8.32
sigmaSd = 1

We define a joint prior distribution between \(\rho\) and \(\sigma\) via a Gaussian copula

# Correlation parameter for Gaussian Copula
gamma = 0.44

sim <- SimulateGaussianCopula(N, rho, sigmaMean, sigmaSd, gamma)

rhoPrior = sim[,1]
sigmaPrior = sim[,2]

sigmabPrior = sqrt(rhoPrior)*sigmaPrior
sigmawPrior = sigmaPrior*sqrt(1-rhoPrior)

Combine all priors into a matrix,

design = cbind(lambdaPrior, deltaPrior, nuPrior, sigmabPrior, sigmawPrior)

Calculate sample size,

# Standard value for posterior probability
prob = 0.05 

# Try with a cluster size of 45
clusterSize = 45

ss = CalculateSampleSize(1:50, design, L = 100, K = 1000, C = clusterSize, target = 0.8, alpha = prob)
ss*clusterSize
#> [1] 225

Check the assurance for this sample size,

CalculateAssurance(ss, design, L = 10, K = 1000, C = clusterSize)
#>  5% 
#> 0.9
CalculateAssurance(ss, design, L = 100, K = 1000, C = clusterSize)
#>   5% 
#> 0.88
CalculateAssurance(ss, design, L = 100, K = 1000, C = clusterSize)
#>   5% 
#> 0.86

The CalculateSampleSize and CalculateAssurance functions use a default model file for Bayesian inferences with rjags:

model {

  for (i in 1:N){

    Y[i] ~ dnorm(mu[i],taub)

    mu[i] = alpha + X[i]*delta + c[Cl[i]]


  }

  for (j in 1:Nclust){

    c[j] ~ dnorm(0,tauw)

  }

  alpha ~ dnorm(1,0.001)
  delta ~ dnorm(0,0.001)

  taub ~ dgamma(eps,eps)
  tauw ~ dgamma(eps,eps)

}

The user can also provide their own file for the JAGS model by specifying the relative path:

filename = "User/my_model_file.dat"

ss = CalculateSampleSize(1:50, design, L = 100, K = 1000, C = clusterSize, target = 0.8, modelFilePath = filename)

assure = CalculateAssurance(ss, design, L = 100, K = 1000, C = clusterSize, modelFilePath = filename)

References

Thomas, Lois H, Beverley French, Christopher J Sutton, Denise Forshaw, Michael J Leathley, Christopher R Burton, Brenda Roe, et al. 2015. “Identifying Continence OptioNs After Stroke (ICONS): An Evidence Synthesis, Case Study and Exploratory Cluster Randomised Controlled Trial of the Introduction of a Systematic Voiding Programme for Patients with Urinary Incontinence After Stroke in Secondary Care.” Programme Grants for Applied Research 3 (1).
Wilson, Kevin J. 2022. “Bayesian Design and Analysis of Two-Arm Cluster Randomised Trials Using Assurance.” arXiv Preprint arXiv:2208.12509. https://arxiv.org/abs/2208.12509.