Reports, per candidate model, whether the sampler explored the posterior: the largest Rhat, the smallest effective sample size, and the number of divergent transitions with their proportion of the retained draws. The other checks are check_chains (chain mixing, visually), check_priors (the priors) and check_fit (the fit against the data).

check_sampling(
  x,
  rhat_cutoff = 1.01,
  ess_cutoff = 400,
  divergence_cutoff = 0.00125
)

# S3 method for class 'bayesnecfit'
check_sampling(
  x,
  rhat_cutoff = 1.01,
  ess_cutoff = 400,
  divergence_cutoff = 0.00125
)

# S3 method for class 'bayesmanecfit'
check_sampling(
  x,
  rhat_cutoff = 1.01,
  ess_cutoff = 400,
  divergence_cutoff = 0.00125
)

# S3 method for class 'bayesnechurdlefit'
check_sampling(
  x,
  rhat_cutoff = 1.01,
  ess_cutoff = 400,
  divergence_cutoff = 0.00125
)

# S3 method for class 'bayesnecgroupfit'
check_sampling(
  x,
  rhat_cutoff = 1.01,
  ess_cutoff = 400,
  divergence_cutoff = 0.00125
)

# S3 method for class 'bayesnecjointfit'
check_sampling(
  x,
  rhat_cutoff = 1.01,
  ess_cutoff = 400,
  divergence_cutoff = 0.00125
)

# Default S3 method
check_sampling(x, ...)

Arguments

x

An object of class bayesnecfit, bayesmanecfit, bayesnechurdlefit, bayesnecgroupfit or bayesnecjointfit.

rhat_cutoff

A numeric vector of length 1.

ess_cutoff

A numeric vector of length 1.

divergence_cutoff

A numeric vector of length 1. The proportion of retained draws, from 0 to less than 1, above which the divergent transitions fail a model. Defaults to 0.00125, which is 10 of 8,000 draws. Inf turns the divergence criterion off.

...

Unused by the default method, which names unsupported classes.

Value

A data.frame with one row per candidate model and columns model, max_rhat, min_ess, min_ess_ratio, n_divergent, divergent_ratio and failed. divergent_ratio is n_divergent divided by the number of retained draws, and is NA where there are none. For a bayesnecgroupfit or a bayesnecjointfit, the same table includes a leading level column. For a bayesnechurdlefit, a named list of two such tables — growth and survival — as rhat also returns for that class.

A one-row sampler diagnostic table for this fit.

A sampler diagnostic table with one row per candidate model.

A named list of growth and survival diagnostic tables.

A diagnostic table with one row per candidate and level.

A diagnostic table with one row per joint level.

An error naming the unsupported class.

Details

check_sampling() asks did this model sample properly, where check_fit asks does this model reproduce the data. Both feed the same downstream question — which candidates belong in the averaged set — which is why screen_models screens on this one and reports the other beside it rather than acting on it.

Thresholds

All three are arguments; the defaults are recommendations, not rules, and whichever ships will be quoted in methods sections.

Rhat 1.01 follows Vehtari et al. (2021), which is also the reference vignette("example2") cites. rhat and summary default to the same value.

ESS 400 is Vehtari's recommendation that both bulk and tail ESS exceed 100 per chain, at the four chains bnec fits by default. The reported min_ess is the minimum over parameters of min(bulk-ESS, tail-ESS), obtained as min(neff_ratio(x)) * ndraws(x).

Divergences 0.125% is a proportion of the retained draws: a model fails where more than 0.125% of its retained draws are divergent transitions. That is 10 of the 8,000 draws bnec retains by default, so at the defaults a model with 11 or more fails. The value has no analysis of bias behind it, and is a working default rather than a recommendation. Stan's guidance is that any divergence means the sampler may not have explored the posterior, and the published tolerances we found are proportions, for example 0.1% of post-warm-up iterations in Fuglstad et al. (2020). A value of 1 or more is refused, and Inf turns the divergence criterion off.

Stan records sampler diagnostics only on the iterations it saves. Thinning therefore lowers the number of divergent transitions recorded, but not, in expectation, their proportion of the retained draws, and a longer run at the same rate of divergence records more of them in the same proportion.

A heavily thinned fit can fail ESS that a ratio would pass

At three chains, thin = 3 and roughly a thousand retained draws, an min_ess of 400 needs a ratio of 0.40, which is demanding for these correlated non-linear parameterisations. Under bnec defaults — 8000 draws — the same cutoff is a ratio of 0.05 and is trivially met. So this screen fails some heavily thinned fits that a ratio-based screen passed. The correct response is to retain more draws, not to lower the cutoff: thinning lowers ESS by construction, and the tempting fix is the wrong one. min_ess_ratio is reported alongside so that "passed because we drew 8000" can be told apart from "passed efficiently".

Which parameters are reduced over

The same set rhat reports: the prior_* draws that sample_prior = "yes" adds are excluded, because their Rhat and ESS describe a distribution the sampler never had to explore, and a parameter with no variance is excluded because both quantities are undefined for it — which is what a constant() prior produces. failed is a logical by construction and is never NA: a model that cannot be assessed is not the same thing as a model that failed, and folding the two together silently turns screen_models into a no-op.

Grouped fits

A bayesnecgroupfit is diagnosed one level at a time because its levels were fitted independently. The result is one table with a level column, rather than a list of tables, so that an equation which passes at one level and fails at another can be compared directly.

A bayesnecjointfit gives the same table, with one row per level. The Rhat and ESS of a row are reduced over that level's own coefficients and the parameters the levels share, such as lp__. n_divergent is the count for the whole fit, because a divergent transition cannot be attributed to one level, and divergent_ratio divides it by the draws of the whole fit.

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

Fuglstad, G.-A., Hem, I. G., Knight, A., Rue, H., & Riebler, A. (2020). Intuitive joint priors for variance parameters. Bayesian Analysis, 15(4), 1109–1137. doi:10.1214/19-BA1185

Examples

if (FALSE) { # \dontrun{
library(bayesnec)
check_sampling(manec_example)
} # }