{"id":7004,"library":"arviz-stats","title":"Statistical computation and diagnostics for ArviZ","description":"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.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/arviz-devs/arviz-stats","tags":["bayesian","statistics","mcmc","diagnostics","data-analysis","xarray","probabilistic-programming"],"install":[{"cmd":"pip install \"arviz-stats[xarray]\"","lang":"bash","label":"Recommended for full functionality"},{"cmd":"pip install arviz-stats","lang":"bash","label":"Minimal installation (NumPy & SciPy only)"}],"dependencies":[{"reason":"Core dependency for numerical operations.","package":"numpy","optional":false},{"reason":"Core dependency for scientific computing functions.","package":"scipy","optional":false},{"reason":"Highly recommended for working with InferenceData objects and most high-level features. Required for the xarray interface.","package":"xarray","optional":true},{"reason":"Provides core data structures (DataTree) used by arviz-stats. Often installed as part of the ArviZ ecosystem.","package":"arviz-base","optional":true}],"imports":[{"symbol":"azs","correct":"import arviz_stats as azs"},{"note":"arviz-base is commonly imported alongside arviz-stats for data handling, especially with InferenceData/DataTree.","symbol":"azb","correct":"import arviz_base as azb"},{"note":"Most arviz-stats functionality is also exposed via the main `arviz` package for convenience.","symbol":"az","correct":"import arviz as az"}],"quickstart":{"code":"import arviz_stats as azs\nimport arviz_base as azb\nimport numpy as np\n\n# Load example data (InferenceData object)\ndata = azb.load_arviz_data(\"centered_eight\")\n\n# Compute summary statistics\nprint(\"\\n--- Summary Statistics ---\")\nsummary_df = azs.summary(data, var_names=[\"mu\", \"tau\"])\nprint(summary_df)\n\n# Compute a specific metric, e.g., Root Mean Square Error (RMSE)\nprint(\"\\n--- RMSE Metric ---\")\n# For metrics, ensure you have posterior_predictive and observed_data in your InferenceData\n# For simplicity here, we'll demonstrate a direct array calculation if data was available\n# In a real scenario, `data` should have `posterior_predictive` and `observed_data` groups.\n# Example: azs.metrics(data, kind=\"rmse\")\n# Let's simulate a simple array for mode calculation as per docs for demonstration\nrand_data = np.random.normal(loc=5, scale=2, size=1000)\nmode_val = azs.mode(rand_data)\nprint(f\"Mode of simulated data: {mode_val}\")","lang":"python","description":"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."},"warnings":[{"fix":"To explicitly get an `xarray.Dataset` from a DataTree group, use `dt[\"group\"].dataset` for a view or `dt[\"group\"].to_dataset()` for a mutable copy.","message":"With ArviZ 1.0 (and thus arviz-stats 1.0), the `arviz.InferenceData` object has been replaced by `xarray.DataTree` in `arviz-base`. Direct access like `dt[\"group\"]` will now return a `DataTree` instead of an `xarray.Dataset`.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Update your code to explicitly set `ci_prob` (e.g., `az.rcParams['stats.ci_prob'] = 0.94`) and `ci_kind` if you rely on the previous defaults.","message":"The default credible interval probability (`ci_prob`) for functions like `summary` and `hdi` has changed from 0.94 to 0.89. Additionally, a new `ci_kind` setting (defaulting to \"eti\" for equal-tailed interval) has been introduced.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For most end-user workflows, install with `xarray` dependencies: `pip install \"arviz-stats[xarray]\"`.","message":"Installing `arviz-stats` without the `[xarray]` extra (`pip install arviz-stats`) limits it to a low-level array-only interface, primarily for developers. Many features, especially those that process `InferenceData` objects, will be unavailable and raise errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set `rounding=None` to return raw numbers for programmatic use, or provide an integer for specific decimal places.","message":"Using `rounding=\"auto\"` (the default) in functions like `azs.summary()` is intended for display purposes. The output values are converted to strings, which can lead to issues if you intend to perform further numerical computations on the results.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"If you need `Dataset` specific functionality, explicitly convert or access the dataset view: `my_datatree_group.to_dataset()` or `my_datatree_group.dataset`.","cause":"In ArviZ 1.0+, `InferenceData` groups are now `xarray.DataTree` objects, not `xarray.Dataset` objects directly.","error":"AttributeError: 'DataTree' object has no attribute 'to_dataset' (or similar error when treating DataTree as Dataset)"},{"fix":"Ensure that the `log_likelihood` group variables have well-defined and consistent dimension names (e.g., `chain`, `draw`, `obs_id`) and shapes that align with the `InferenceData` schema. Review how `log_likelihood` is created during inference.","cause":"This error typically occurs during model comparison or refitting when the `log_likelihood` group within your `InferenceData` has ambiguous or inconsistent dimensions across variables, preventing `xarray` from correctly broadcasting.","error":"Found several log likelihood arrays var_name cannot be None"},{"fix":"Inspect your model's sampling diagnostics (`rhat`, `ess`). Consider re-parameterizing the model, increasing `target_accept` in your PPL's sampler, or filtering out divergent transitions. Ensure your input data to `arviz-stats` functions is clean and doesn't contain unexpected `NaN`s.","cause":"Indicates numerical instability or issues within the sampled data, such as `NaN` values, extreme numbers, or poorly converging chains, leading to undefined statistical calculations.","error":"RuntimeWarning: invalid value encountered in [...] (e.g., in diagnostics.py or related statistical computations)"},{"fix":"Uninstall the minimal `arviz-stats` and reinstall it with the recommended `xarray` optional dependency: `pip uninstall arviz-stats && pip install \"arviz-stats[xarray]\"`.","cause":"`arviz-stats` was installed with the minimal dependency set, which does not include `xarray`, but you are attempting to use functionality that relies on `xarray` and `InferenceData` objects.","error":"ModuleNotFoundError: No module named 'xarray' (or similar error when using InferenceData features after minimal install)"}]}