quivers.diagnostics¶
Adapter to the ArviZ Bayesian-analysis ecosystem. Converts quivers'
inference records into xarray.DataTree objects consumable by
every ArviZ 1.x function (plot_trace, plot_forest, plot_ppc,
loo, compare, hdi, ...).
diagnostics
¶
Adapter to the ArviZ Bayesian-analysis ecosystem.
Quivers' inference layer produces quivers.inference.MCMCResult
records and quivers.inference.guides.base.Guide fits. The
canonical 2026 Bayesian-analysis library is ArviZ,
whose
xarray.DataTree-based
data model is the lingua franca for posterior-summary, diagnostic,
posterior-predictive, model-comparison, and calibration tooling.
The functions in this subpackage convert quivers fits into ArviZ
DataTrees and wrap the canonical ArviZ entry points
(arviz.compare, arviz.loo, arviz.hdi,
arviz.plot_ppc) with shape-aware, quivers-typed signatures.
No posterior-analysis primitives are reimplemented here; ArviZ owns
the analytics.
to_datatree
¶
to_datatree(posterior: MCMCResult, *, observed_data: Mapping[str, Tensor] | None = None, posterior_predictive: Mapping[str, Tensor] | None = None, log_likelihood: Mapping[str, Tensor] | None = None, constant_data: Mapping[str, Tensor] | None = None, coords: Mapping[str, list] | None = None, dims: Mapping[str, list[str]] | None = None) -> DataTree
Convert an MCMCResult into an ArviZ-style DataTree.
| PARAMETER | DESCRIPTION |
|---|---|
posterior
|
Sampler output.
TYPE:
|
observed_data
|
Site name to observed tensor (the original data used at
fit time). Becomes the
TYPE:
|
posterior_predictive
|
Site name to posterior-predictive draws of shape
TYPE:
|
log_likelihood
|
Site name to per-observation log-likelihood of shape
TYPE:
|
constant_data
|
Site name to fixed covariate tensor (e.g. design matrix).
Becomes the
TYPE:
|
coords
|
Coordinate values per named axis (e.g.
TYPE:
|
dims
|
Per-site axis names (e.g.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataTree
|
Canonical ArviZ DataTree consumable by every plotting and diagnostic function in the ArviZ 1.x API. |
Source code in src/quivers/diagnostics/arviz_io.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
compare
¶
compare(fits: Mapping[str, DataTree], *, method: Literal['stacking', 'BB-pseudo-BMA', 'pseudo-BMA'] = 'stacking', var_name: str | None = None, reference: str | None = None) -> object
Rank candidate models by expected log predictive density.
Delegates to arviz.compare, which computes PSIS-LOO
via arviz.loo on each fit's log_likelihood group
and combines the resulting arviz.stats.ELPDData records
into a ranked comparison table.
| PARAMETER | DESCRIPTION |
|---|---|
fits
|
Per-model fit, each a DataTree produced by
TYPE:
|
method
|
Stacking weight estimator. Default
TYPE:
|
var_name
|
Name of the observed variable in
TYPE:
|
reference
|
Fit name to use as the reference for elpd-difference comparisons. Default is the top-ranked model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
ArviZ ranking table with columns |
Source code in src/quivers/diagnostics/comparison.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
posterior_predictive_check
¶
posterior_predictive_check(idata: DataTree, *, observed_name: str, statistic: str | Callable[[ndarray], float] = 'mean', by: str | None = None) -> Mapping[str, float | ndarray | str]
Compute a posterior-predictive p-value (PPP-value) for a user-chosen test statistic.
| PARAMETER | DESCRIPTION |
|---|---|
idata
|
Fit produced by
TYPE:
|
observed_name
|
Name of the observed site (must appear in both groups).
TYPE:
|
statistic
|
Either a key into
TYPE:
|
by
|
If given, computes the statistic per group along the named
dim (e.g.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Mapping[str, float or ndarray]
|
|
Source code in src/quivers/diagnostics/predictive_checks.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |