arviz_stats.loo_r2#
- arviz_stats.loo_r2(data, var_name, n_simulations=4000, summary=True, point_estimate=None, ci_kind=None, ci_prob=None, circular=False, round_to=None)[source]#
Compute LOO-adjusted \(R^2\).
- Parameters:
- data: DataTree or InferenceData
It should contain groups observed_data, posterior_predictive and log_likelihood.
- var_name
str Name of the observed variable
- n_simulations
int, default 4000 Number of Dirichlet-weighted bootstrap samples for variance estimation.
- circularbool, default
False Whether the variable is circular (angles in radians, range [-π, π]).
- summary: bool
Whether to return a summary (default) or an array of \(R^2\) samples. The summary is a named tuple with a point estimate and a credible interval
- point_estimate: str
The point estimate to compute. If None, the default value is used. Defaults values are defined in rcParams[“stats.point_estimate”]. Ignored if summary is False.
- ci_kind: str
The kind of credible interval to compute. If None, the default value is used. Defaults values are defined in rcParams[“stats.ci_kind”]. Ignored if summary is False.
- ci_prob: float
The probability for the credible interval. If None, the default value is used. Defaults values are defined in rcParams[“stats.ci_prob”]. Ignored if summary is False.
- circular: bool
Whether to compute the Bayesian \(R^2\) for circular data. Defaults to False. It’s assumed that the circular data is in radians and ranges from -π to π. We use the same definition of \(R^2\) for circular data as in the linear case, but using circular variance instead of regular variance.
- round_to: int or str or None, optional
- If integer, number of decimal places to round the result. Integers can be negative.
If string of the form ‘2g’ number of significant digits to round the result. Defaults to rcParams[“stats.round_to”] if None. Use the string “None” or “none” to return raw numbers.
- Returns:
Namedtupleorarray
See also
arviz_stats.bayesian_r2Bayesian \(R^2\).
arviz_stats.residual_r2Residual \(R^2\).
Examples
Calculate LOO-adjusted \(R^2\) for Bayesian logistic regression:
In [1]: from arviz_stats import loo_r2 ...: from arviz_base import load_arviz_data ...: data = load_arviz_data('anes') ...: loo_r2(data, var_name="vote") ...: Out[1]: loo_R2(mean=0.48, eti_lb=0.4, eti_ub=0.55)
Calculate LOO-adjusted \(R^2\) for circular regression:
In [2]: data = load_arviz_data('periwinkles') ...: loo_r2(data, var_name='direction', circular=True) ...: Out[2]: loo_R2(mean=0.8, eti_lb=0.72, eti_ub=0.87)