API reference#

Data reorganization#

arviz_base.extract(data[, group, ...])

Extract a group or group subset from a DataTree.

arviz_base.dataset_to_dataarray(ds[, ...])

Convert a Dataset to a stacked DataArray, using a labeller to set coordinate values.

arviz_base.dataset_to_dataframe(ds[, ...])

Convert a Dataset to a DataFrame via a stacked DataArray, using a labeller.

arviz_base.explode_dataset_dims(ds, dim[, ...])

Explode dims of a dataset so each slice along them becomes its own variable.

arviz_base.references_to_dataset(references, ds)

Generate an Dataset compabible with ds from references.

User facing converters#

arviz_base.convert_to_datatree(obj, **kwargs)

Convert a supported object to a DataTree object following ArviZ conventions.

arviz_base.from_dict(data, *[, name, ...])

Convert nested dictionary into a DataTree.

Library specific converters#

arviz_base.from_cmdstanpy([posterior, ...])

Convert CmdStanPy data into an InferenceData object.

arviz_base.from_emcee([sampler, var_names, ...])

Convert emcee data into a DataTree.

arviz_base.from_numpyro([posterior, prior, ...])

Convert NumPyro data into a DataTree object.

More coming soon…

Iteration and subsetting#

arviz_base.xarray_sel_iter(data[, ...])

Convert xarray data to an iterator over variable names and selections.

arviz_base.xarray_var_iter(data[, ...])

Convert xarray data to an iterator over vectors.

How to cite ArviZ and implemented methods#

arviz_base.citations([methods, filepath, ...])

List citations for ArviZ and the methods implemented in ArviZ.

Example datasets#

The behaviour of the functions in this section is partially controlled by the following environment variable:

ARVIZ_DATA#

If present, store remote datasets after downloading in the location indicated there. Otherwise, datasets are stored at ~/arviz_data/

arviz_base.load_arviz_data([dataset, data_home])

Load a local or remote pre-made dataset.

arviz_base.list_datasets()

Get a string representation of all available datasets with descriptions.

arviz_base.get_data_home([data_home])

Return the path of the arviz data dir.

arviz_base.clear_data_home([data_home])

Delete all the content of the data home cache.

Conversion utilities#

arviz_base.convert_to_dataset(obj, *[, group])

Convert a supported object to an xarray.Dataset.

arviz_base.dict_to_dataset(data, *[, attrs, ...])

Convert a dictionary of numpy arrays to an xarray.Dataset.

arviz_base.generate_dims_coords(shape, var_name)

Generate default dimensions and coordinates for a variable.

arviz_base.make_attrs([attrs, inference_library])

Make standard attributes to attach to xarray datasets.

arviz_base.ndarray_to_dataarray(ary, var_name, *)

Convert a numpy array to an xarray.DataArray.

Labels#

arviz_base.labels.BaseLabeller()

Base labeller class.

arviz_base.labels.DimCoordLabeller()

Labeller class to show both dimension and coordinate value information.

arviz_base.labels.IdxLabeller()

Labeller class to show positional index information.

arviz_base.labels.DimIdxLabeller()

Labeller class to show both dimension and positional index information.

arviz_base.labels.MapLabeller([...])

Labeller class to perform provided replacements to elements when converting to string.

arviz_base.labels.NoVarLabeller()

Labeller class to exclude the variable name from the generated labels.

arviz_base.labels.mix_labellers(labellers[, ...])

Combine Labeller classes dynamically.

Configuration#

Most ArviZ default values are regulated by arviz_base.rcParams, a class similar to a dictionary storing key-value pairs inspired by the one in matplotlib. It is similar to a dictionary and not a dictionary though because all keys are fixed, and each key has associated a validation function to help prevent setting nonsensical defaults.

ArviZ configuration file#

The rcParams class is generated and populated at import time. ArviZ checks several locations for a file named arvizrc and, if found, prefers those settings over the library ones.

The locations checked are the following:

  1. Current working directory, os.getcwd

  2. Location indicated by ARVIZ_DATA environment variable

  3. The third and last location checked is OS dependent:

    • On Linux: $XDG_CONFIG_HOME/arviz if exists, otherwise ~/.config/arviz/

    • Elsewhere: ~/.arviz/

Example arvizrc file
data.index_origin : 1
plot.backend : bokeh
stats.ci_kind : hdi
stats.ci_prob : 0.95

All available keys are listed below. The arvizrc file can have any subset of the keys, it isn’t necessary to include them all. For those keys without a user defined default, the library one is used.

Context manager#

A context manager is also available to temporarily change the default settings.

arviz_base.rc_context([rc, fname])

Return a context manager for managing rc settings.

rcParams#

Below, all keys available within rcParams are listed, along with their library default.

Keys can be accessed or modified via arviz_base.rcParams[key], for example, arviz_base.rcParams["data.sample_dims"].

Important

These defaults are subject to change. If you rely on a specific default value, you should create an arvizrc file with the key-value pairs you rely on.

The goal of the ArviZ team is to try and adapt to best practices as they evolve, which sometimes requires updating default values, for example to use new algorithms.

data#

data.http_protocol: str = "https"#

Protocol for loading remote datasets. Can be “https” or “http”.

data.index_origin: int = 0#

Index origin. By default, ArviZ adds coordinate values to all dimensions. If no coordinate values were provided, ArviZ generates integer indices as coordinate values starting at index_origin.

data.sample_dims: list = ["chain", "draw"]#

What the sampling dimensions are named. These are the dimensions that will be reduced by default when computing or plotting, therefore, they should be always present.

data.save_warmup: bool = False#

Whether to save warmup iterations.

stats#

stats.module: str or object = "base"#

Preferred module for stats computations. It accepts a custom user-created statistics class, which must have the necessary functions for stats and plots to work properly. When validating the input though, only the eti and rhat methods are checked.

stats.ci_kind: str = "eti"#

Type of credible interval to compute by default, one of “eti” or “hdi”.

stats.ci_prob: float = 0.94#

The default probability of computed credible intervals. Its default value here is also a friendly reminder of the arbitrary nature of commonly values like 95%

stats.ic_compare_method: str = "stacking"#

Method for comparing multiple models using their information criteria values, one of “stacking”, “bb-pseudo-bma” or “pseudo-mba”.

stats.ic_pointwise: bool = True#

Whether to return pointwise values when computing PSIS-LOO-CV.

stats.ic_scale: str = "log"#

The scale in which to return the PSIS-LOO-CV values, one of “deviance” (common in the past and reason of the information criterion naming), “log” or “negative_log”.

stats.point_estimate: str = "mean"#

Default statistical summary for centrality, one of “mean”, “median” or “mode”.

plots#

plot.backend: str = "auto"#

Default plotting backend for arviz_plots, one of “matplotlib”, “plotly”, “bokeh”, “none” or “auto”. If “auto” when setting the value (or when importing the library if using “auto” in a template) the available backends will be checked in the order above, the first one that is found to be available is set as the default plotting backend.

plot.density_kind: str = "kde"#

Default representation for 1D marginal densities, one of “kde”, “hist”, “ecdf” or “dot”.

plot.max_subplots: int = 40#

Maximum number of plots that can be generated at once.