Skip to contents

Computes R-hat and effective sample size (ESS) across two or more independently-seeded chains, for both the regression coefficients (BETA) and the variance components (VC). ESS is computed on the pooled draws, so genuinely non-converged chains report a low ESS rather than an inflated one.

Usage

compute_mcmc_diagnostics(chain_list)

Arguments

chain_list

A list of independently seeded fits from the same model: either ame/lame objects carrying BETA, or lame_robust objects. Do not mix fit classes. A single fit made with chains of two or more is accepted too, and its stored diagnostics are returned.

Value

A list with rhat, rhat_classic, ess (the total effective draws over all chains, the ESS column of summary(); the ess and ess_chain columns of fit$rhat count effective draws per split chain instead), rhat_threshold, informative, param_names (over BETA and VC), n_chains and n_samples. For robust fits, additionally returns ess_bulk, ess_tail, a full diagnostics data frame, and pass.

Details

rhat is the split rank-normalised R-hat of Vehtari et al. (2021), the larger of the bulk and tail values, as posterior::rhat() reports it. It is the statistic of the between-chain gate of ame and lame, computed on the first min(n_samples) draws of every chain, so for a two-chain fit it equals fit$rhat for every monitored coefficient and variance component, and it is the Rhat column of summary(). It is NA for a quantity that is constant in every chain and for chains with fewer than 8 draws. rhat_classic is the Gelman-Rubin statistic of the whole chains, without splitting or rank normalisation. rhat_threshold and informative are the gate's rule applied to these quantities (the threshold of each, at the family-wise level over all of them, and whether the chains hold enough effective draws to be compared on it; see Gate thresholds in lame), and the printed verdict names every quantity above its threshold or short of effective draws.

For lame_robust fits, the posterior package is required. Diagnostics include static coefficients, time intercepts, actor paths and levels, estimated hyperparameters, every off-diagonal latent product, and persistent pair precisions. Unused rank-zero factor hyperparameters and fixed Gaussian precisions are excluded. Chains must have identical inputs and priors, different seeds, and equal lengths of at least four retained draws. Robust pass applies the gate's rule to every included parameter (split rank-normalised R-hat at most its threshold, at the family-wise level over all of them, and enough effective draws to compare the chains) and requires finite positive ESS, bulk ESS and tail ESS; rhat_threshold, informative and parameter_pass hold it per parameter. The individual R-hat and effective sample size values are reported for every included parameter. The existing ame/lame diagnostic scope remains coefficients and variance components.

Author

Cassy Dorff, Shahryar Minhas, Tosin Salau

Examples

# \donttest{
set.seed(1)
n <- 12
Y <- matrix(rnorm(n * n), n, n); diag(Y) <- NA
# each fit is one chain (chains = 1); compute_mcmc_diagnostics() compares them
fit1 <- ame(Y, R = 1, nscan = 200, burn = 50, odens = 1, seed = 1, verbose = FALSE, chains = 1)
fit2 <- ame(Y, R = 1, nscan = 200, burn = 50, odens = 1, seed = 2, verbose = FALSE, chains = 1)
diag_out <- compute_mcmc_diagnostics(list(fit1, fit2))
#> 
#> ── MCMC convergence diagnostics 
#> Number of chains: 2
#> Samples per chain: "200, 200"
#> Diagnostics cover regression coefficients and variance components.
#> ✔ Every parameter passes the between-chain check (R-hat at most its threshold).
diag_out$rhat
#> intercept        va       cab        vb       rho        ve 
#>  1.010552  1.004534  1.016733  1.001682  1.010396  1.005345 
# }