diff --git a/CHANGELOG.md b/CHANGELOG.md index 07759c1e70..5f8d4b3810 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ * Add classifier to `setup.py` including Matplotlib framework (#1133) * Image thumbs generation updated to be Bokeh 2 compatible (#1116) * Add new examples for `plot_pair` (#1110) - +* Add examples for `psislw` and `r2_score` (#1129) ## v0.7.0 (2020 Mar 2) diff --git a/arviz/stats/stats.py b/arviz/stats/stats.py index cec2e3f836..7ebfe0e6f8 100644 --- a/arviz/stats/stats.py +++ b/arviz/stats/stats.py @@ -693,6 +693,22 @@ def psislw(log_weights, reff=1.0): Smoothed log weights kss : array Pareto tail indices + + References + ---------- + * Vehtari et al. (2015) see https://arxiv.org/abs/1507.02646 + + Examples + -------- + Get Pareto smoothed importance sampling (PSIS) log weights: + + .. ipython:: + + In [1]: import arviz as az + ...: data = az.load_arviz_data("centered_eight") + ...: log_likelihood = data.sample_stats.log_likelihood.stack(sample=("chain", "draw")) + ...: az.psislw(-log_likelihood, reff=0.8) + """ if hasattr(log_weights, "sample"): n_samples = len(log_weights.sample) @@ -874,6 +890,19 @@ def r2_score(y_true, y_pred): Pandas Series with the following indices: r2: Bayesian R² r2_std: standard deviation of the Bayesian R². + + Examples + -------- + Calculate R² for Bayesian regression models : + + .. ipython:: + + In [1]: import arviz as az + ...: data = az.load_arviz_data('regression1d') + ...: y_true = data.observed_data["y"].values + ...: y_pred = data.posterior_predictive.stack(sample=("chain", "draw"))["y"].values.T + ...: az.r2_score(y_true, y_pred) + """ _numba_flag = Numba.numba_flag if y_pred.ndim == 1: