arviz_stats.bayes_factor

Contents

arviz_stats.bayes_factor#

arviz_stats.bayes_factor(data, var_names, ref_vals=0, return_ref_vals=False, prior=None)[source]#

Compute Bayes factor using Savage–Dickey ratio.

Parameters:
dataxarray.DataTree, or InferenceData

The data object containing the posterior and optionally the prior distributions.

var_namesstr or list of str

Names of the variables for which the bayes factor should be computed.

ref_valsfloat or list of float, 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.

priordict, optional

Dictionary with prior distributions for each variable. If not provided, the prior will be taken from the prior group in the data object.

Returns:
dict

Dictionary with Bayes Factor values: BF10 and BF01 per variable.

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]: 
{'home': {'BF10': 0.04562934431592942, 'BF01': 21.915721450568714},
 'intercept': {'BF10': 1.5125981269765372, 'BF01': 0.6611141334670657}}