The backend-agnostic way to read the numbers used to judge whether a fit can be trusted. The result has the same shape whichever backend produced the fit.
backend_diagnostics() only reports; it applies no thresholds and signals no
warnings. Deciding what counts as a failed fit is left to the caller. The
current Stan guidance (Vehtari et al. 2021) is R-hat below 1.01, bulk and tail
ESS of at least 100 per chain, and no divergent transitions.
R-hat and ESS are computed by the 'posterior' package on both backends. The
sampler diagnostics delegate to cmdstanr's diagnostic_summary() and rstan's
get_bfmi(). RStan's divergence and treedepth helpers return totals, so their
counts are computed per chain here. Undefined E-BFMI values are normalized to
NA; a per-chain fallback preserves valid chains when cmdstanr cannot report
them independently of a chain with missing energy. A post-warmup transition
whose tree depth reaches max_treedepth counts as a hit, and E-BFMI is
sum(diff(energy)^2) / (N * var(energy)) for each chain,
where N is its number of post-warmup iterations.
Arguments
- raw_fit
a backend-native fit object (an rstan
stanfitor a cmdstanrCmdStanMCMC).- pars
character vector of parameter base names to summarize, with the same meaning as in
backend_extract().NULL, the default, summarizes every parameter, includinglp__, transformed parameters, and generated quantities; pass the parameters you care about to limit the cost on large models. The per-chain diagnostics are unaffected bypars.
Value
a list with elements:
parameters: adata.framewith one row per flat variable and columnsvariable,rhat,ess_bulk, andess_tail. A value isNAwhen it cannot be computed, e.g. for a variable that is constant across draws.chains: adata.framewith one row per chain and columnschain,num_divergent,num_max_treedepth, andebfmi(all post-warmup). A column isNAwhen the sampler did not record it (e.g.algorithm = "Fixed_param");ebfmiis alsoNAfor chains shorter than three iterations, non-finite energy, zero energy variance, or numerical overflow.n_chains: the number of chains.n_iter: the number of post-warmup iterations per chain.max_treedepth: the maximum tree depth setting the fit ran with, orNAwhen unavailable (e.g. a cmdstanr fixed-parameter fit).
See also
backend_has_draws() for the earlier check that a fit produced any
draws at all.