hbcc: hbcc : Hierarchical Bayesian Convergence Checks

View source: R/hbcc.R

hbccR Documentation

hbcc : Hierarchical Bayesian Convergence Checks

Description

This function is designed to evaluate the convergence and quality of a Bayesian hierarchical model. It performs several diagnostic tests and generates various plots to assess Markov Chain Monte Carlo performance.

Usage

hbcc(
  model,
  diag_tests = c("rhat", "geweke", "heidel", "raftery"),
  plot_types = c("trace", "dens", "acf", "nuts_energy", "rhat", "neff")
)

Arguments

model

A brmsfit or hbmfit object.

diag_tests

Character vector of diagnostic tests (default:"rhat", "geweke", "raftery", "heidel")

plot_types

Character vector of plot types (default: trace","dens","acf", "nuts_energy", "rhat", "neff")

Details

Hierarchical Bayesian Convergence Checks

Value

An object of class hbcc_results, which is a list containing:

rhat_ess

Matrix of Rhat, Bulk_ESS, and Tail_ESS values for fixed and random effects.

geweke

Geweke diagnostic results (if selected).

raftery

Raftery-Lewis diagnostic results (if selected).

heidel

Heidelberger-Welch diagnostic results (if selected).

plots

A list of generated MCMC diagnostic plots, which may include:

  • "trace" - Trace plot of the MCMC chains.

  • "dens" - Density plot of the posterior distributions.

  • "acf" - Autocorrelation function plot.

  • "nuts_energy" - NUTS energy diagnostic plot.

  • "rhat" - Rhat plot (if available).

  • "neff" - Effective sample size plot.

Author(s)

Achmad Syahrul Choir and Saniyyah Sri Nurhayati

References

Bürkner, P. C. (2017). brms: An R package for Bayesian multilevel models using Stan. Journal of Statistical Software, 80(1), 1-28.

Examples



library(hbsaems)
data("data_fhnorm")

# Prepare the dataset
data <- data_fhnorm

# Fit the Basic Model
model <- hbm(
formula = bf(y ~ x1 + x2 + x3), # Formula model
hb_sampling = "gaussian", # Gaussian family for continuous outcomes
hb_link = "identity", # Identity link function (no transformation)
data = data, # Dataset
chains = 4, # Number of MCMC chains
iter = 4000, # Total MCMC iterations
warmup = 2000, # Number of warmup iterations
cores = 2 # Parallel processing
)
summary(model)

# Convergence Checks
hbcc(model)



hbsaems documentation built on Aug. 8, 2025, 7:28 p.m.