arviz_stats.bayes_factor#
- arviz_stats.bayes_factor(data, var_names, ref_vals=0, return_ref_vals=False, prior=None, circular=False)[source]#
Compute Bayes factor using Savage–Dickey ratio.
- Parameters:
- data
xarray.DataTree, orInferenceData The data object containing the posterior and optionally the prior distributions.
- var_names
strorlistofstr Names of the variables for which the Bayes factor should be computed.
- ref_vals
floatorlistoffloat, default 0 Reference value for each variable. Must match var_names in length if list.
- return_ref_valsbool, default
False If True, return the reference density values for the posterior and prior.
- prior
dict, optional Dictionary with prior distributions for each variable of interest. If not provided, the prior will be taken from the prior group in the data object.
- circularbool, default
False Whether the variables are circular (e.g. angles). This affects KDE computation, which is used to estimate the density at the reference value.
- data
- Returns:
xr.DatasetDataset with one variable per requested variable. Each DataArray has a
bf_typedimension with coordinates["BF10", "BF01"], plus any non-sample coordinates of the original variable (e.g.school).
References
[1]Heck DW. A caveat on the Savage-Dickey density ratio: The case of computing Bayes factors for regression parameters. Br J Math Stat Psychol, 72. (2019) https://doi.org/10.1111/bmsp.12150
Examples
Compute Bayes factor for a home and intercept variable in a rugby dataset using a reference value of 0.15 for home and 3 for intercept.
In [1]: from arviz_base import load_arviz_data ...: from arviz_stats import bayes_factor ...: dt = load_arviz_data("rugby") ...: bayes_factor(dt, var_names=["home", "intercept"], ref_vals=[0.15, 3]) ...: Out[1]: <xarray.Dataset> Size: 64B Dimensions: (bf_type: 2) Coordinates: * bf_type (bf_type) <U4 32B 'BF10' 'BF01' Data variables: home (bf_type) float64 16B 0.04563 21.92 intercept (bf_type) float64 16B 1.513 0.6611