Statistical computation and diagnostics for ArviZ

1.0.0 · active · verified Thu Apr 16

arviz-stats is a Python package that provides statistical functions and diagnostics for the exploratory analysis of Bayesian models. It is a subpackage of the broader ArviZ library (along with arviz-base and arviz-plots) and focuses specifically on computational and numerical features like statistical summaries, diagnostics, and model comparison. The current version is 1.0.0, released on March 2, 2026. The ArviZ ecosystem, including arviz-stats, has a regular release cadence with several releases in the past year.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load an example Bayesian model's inference data using `arviz-base` and then apply `arviz-stats` functions like `summary` for posterior diagnostics and `mode` for statistical computation. For full functionality, especially with InferenceData, the `xarray` optional dependency is recommended.

import arviz_stats as azs
import arviz_base as azb
import numpy as np

# Load example data (InferenceData object)
data = azb.load_arviz_data("centered_eight")

# Compute summary statistics
print("\n--- Summary Statistics ---")
summary_df = azs.summary(data, var_names=["mu", "tau"])
print(summary_df)

# Compute a specific metric, e.g., Root Mean Square Error (RMSE)
print("\n--- RMSE Metric ---")
# For metrics, ensure you have posterior_predictive and observed_data in your InferenceData
# For simplicity here, we'll demonstrate a direct array calculation if data was available
# In a real scenario, `data` should have `posterior_predictive` and `observed_data` groups.
# Example: azs.metrics(data, kind="rmse")
# Let's simulate a simple array for mode calculation as per docs for demonstration
rand_data = np.random.normal(loc=5, scale=2, size=1000)
mode_val = azs.mode(rand_data)
print(f"Mode of simulated data: {mode_val}")

view raw JSON →