R code and data for the Kerala Diabetes Prevention Program (K-DPP) application in Hierarchical Bayesian modeling of heterogeneous outcome variance in cluster randomized trials by Guangyu Tong, Jiaqi Tong, Yi Jiang, Denise Esserman, Michael O. Harhay, and Joshua L. Warren (Clinical Trials, 2024).
The analysis compares four Bayesian models for continuous outcomes in cluster randomized trials. These models estimate the intervention effect and characterize heterogeneity in outcome variances and intraclass correlations across treatment arms and clusters, including associations with cluster-level covariates.
| File | Description |
|---|---|
analysis.R |
Main script: prepares the data, fits the four models, and saves the results. |
function.R |
Functions for data preparation, JAGS model fitting, posterior summaries, and WAIC calculation. |
kdpp_cleaned.csv |
Cleaned K-DPP data used in the application. |
Install R and JAGS, then install the R packages:
install.packages(c("rjags", "coda"))Download or clone this repository and set the R working directory to the repository folder. Run:
source("analysis.R")Alternatively, run the script from a terminal in the repository folder:
Rscript analysis.RThe default settings in analysis.R use three MCMC chains per model, 30,000 burn-in iterations, 300,000 retained draws per chain, and no thinning (thin = 1).
The script writes table4.csv to the repository folder, with one row for each of Models 1–4. It contains posterior means, medians, and 95% highest posterior density (HPD) intervals for the intervention effect and variance regression coefficients, together with the widely applicable information criterion (WAIC). Variance regression summaries are reported for Models 3–4; the corresponding entries for Models 1–2 are NA.
When run in an R session, the posterior object retains the samples from each chain for further analysis and convergence assessment.
Tong G, Tong J, Jiang Y, Esserman D, Harhay MO, Warren JL. Hierarchical Bayesian modeling of heterogeneous outcome variance in cluster randomized trials. Clinical Trials. 2024;21(4):451–460. doi:10.1177/17407745231222018.