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:
- data
xarray.DataTree
, orInferenceData
The data object containing the posterior and optionally the prior distributions.
- var_names
str
orlist
ofstr
Names of the variables for which the bayes factor should be computed.
- ref_vals
float
orlist
offloat
, 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. If not provided, the prior will be taken from the prior group in the data object.
- data
- 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}}