ConvergenceTest#

class cultivars.bayes.chains.ConvergenceTest(*, names, mean, sd, mcse, ess_bulk, ess_tail, rhat, geweke, n_chains, n_draws, rhat_tol, min_ess, source)[source]#

Per-parameter convergence diagnostics of a Markov chain Monte Carlo run.

One row per scalar quantity: its posterior mean and spread, the Monte Carlo standard error of that mean, rank-normalized bulk and tail effective sample sizes, rank-normalized split-R-hat with folding, and the largest-magnitude Geweke score across chains. The verdict applies the Vehtari et al. (2021) thresholds the report carries, so two reports are comparable only when their thresholds are.

A parameter whose chain never moved has nan in every column and is listed under degenerate rather than counted against the verdict: the report cannot tell a parameter fixed by construction from a sampler that is stuck, and refuses to guess. Read the list.

With a single chain, split-R-hat compares the two halves of that chain, which detects drift but not a chain stuck in one of several modes; the summary says so. The between-chain reading needs a second run with a different seed passed alongside the first. Two half-chains also make the statistic noisy when they are short: an independent sequence of 200 draws exceeds 1.01 about a fifth of the time and one of 500 draws about a fiftieth, so a flag close to the threshold on a short single chain is a reason to run longer, not a verdict.

Variables:
  • names (tuple[str, ...]) – Label of every scalar quantity, in row order.

  • mean (NDArray[double]) – (d,) posterior means.

  • sd (NDArray[double]) – (d,) posterior standard deviations.

  • mcse (NDArray[double]) – (d,) Monte Carlo standard errors of the means.

  • ess_bulk (NDArray[double]) – (d,) bulk effective sample sizes.

  • ess_tail (NDArray[double]) – (d,) tail effective sample sizes.

  • rhat (NDArray[double]) – (d,) split-R-hat statistics.

  • geweke (NDArray[double]) – (d,) signed Geweke scores, the one of largest magnitude across chains; nan when the chains are too short for the default segments.

  • n_chains (int) – Independent chains the diagnostics pooled.

  • n_draws (int) – Kept draws per chain.

  • rhat_tol (float) – R-hat above which a parameter is flagged.

  • min_ess (float) – Effective draws per chain below which a parameter is flagged, so the floor applied is min_ess * n_chains.

  • source (str) – What was assessed, for the summary title.

See also

Attributes#

names

Label of every scalar quantity, in row order.

mean

(d,) posterior means.

sd

(d,) posterior standard deviations.

mcse

(d,) Monte Carlo standard errors of the means.

ess_bulk

(d,) bulk effective sample sizes.

ess_tail

(d,) tail effective sample sizes.

rhat

(d,) split-R-hat statistics.

geweke

(d,) signed Geweke scores, the one of largest magnitude across chains; nan when the chains are too short for the default segments.

n_chains

Independent chains the diagnostics pooled.

n_draws

Kept draws per chain.

rhat_tol

R-hat above which a parameter is flagged.

min_ess

Effective draws per chain below which a parameter is flagged, so the floor applied is min_ess * n_chains.

source

What was assessed, for the summary title.

converged

Whether no assessed quantity is flagged.

degenerate

Quantities whose chain never moved, excluded from the verdict.

ess_floor

Total effective draws below which a parameter is flagged.

flagged

Quantities failing the R-hat or either effective-sample-size test.

Methods#

summary(*[, top])

Render as a table sorted by R-hat, descending.

worst([n])

The n quantities with the largest R-hat, degenerate ones last.