Extract Rhat statistic that can be used to diagnose sampling behaviour of the algorithms applied by 'Stan' at the back-end of 'brms'. x should be of class bayesnecfit or bayesmanecfit.

# S3 method for class 'bayesnecfit'
rhat(x, rhat_cutoff = 1.01, ...)

# S3 method for class 'bayesmanecfit'
rhat(x, rhat_cutoff = 1.01, ...)

Arguments

x

An object of class bayesnecfit or bayesmanecfit.

rhat_cutoff

A numeric vector of length 1 indicating the Rhat cut-off used to test for model convergence. Defaults to 1.01 following Vehtari et al. (2021).

...

Unused.

Value

A list containing a vector of Rhat values returned for each parameter for a brmsfit object, for each of the fitted models, and the logical failed verdict against rhat_cutoff.

Which parameters are reported

The prior_* variables are excluded. bnec forces sample_prior = "yes", so every fit carries an independent draw from the prior for every parameter; the Rhat of those draws is Monte Carlo noise about a distribution the sampler never had to explore, and including them can fail a model on a variable that is not part of the model.

Parameters with no variance are excluded too, because their Rhat is undefined. That is what a constant() prior produces: a parameter fixed at a known value has nothing to converge to.

lp__ and lprior are kept. They are deterministic functions of the posterior draws rather than of the prior, so they do carry a convergence signal.

References

Vehtari, A., Gelman, A., Simpson, D., Carpenter, B., & Burkner, P.-C. (2021). Rank-normalization, folding, and localization: An improved Rhat for assessing convergence of MCMC (with discussion). Bayesian Analysis, 16(2), 667–718. doi:10.1214/20-BA1221

Examples

if (FALSE) { # \dontrun{
library(bayesnec)
rhat(manec_example)
nec4param <- pull_out(manec_example, model = "nec4param")
rhat(nec4param)
} # }