Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aloctavodia committed Jun 22, 2020
1 parent b021105 commit 8089468
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## v0.x.x Unreleased

### New features
* loo-pit plot. The kde is computed over the data interval (this could be shorter than [0, 1]). The hdi is computed analitically (#1215)
* loo-pit plot. The kde is computed over the data interval (this could be shorter than [0, 1]). The hdi is computed analitically (#1215)
* plot_bpv. A new plot intented to plot Bayesian p-values (#1222)

### Maintenance and fixes

Expand Down
31 changes: 27 additions & 4 deletions arviz/plots/bpvplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

def plot_bpv(
data,
kind="kde",
kind="u_value",
t_stat="median",
bpv=True,
mean=True,
reference=None,
reference="samples",
n_ref=100,
hdi_prob=0.94,
color="C0",
Expand Down Expand Up @@ -128,6 +128,26 @@ def plot_bpv(
Returns
-------
axes: matplotlib axes or bokeh figures
Examples
--------
Plot Bayesian p_values.
.. plot::
:context: close-figs
>>> import arviz as az
>>> data = az.load_arviz_data("regression1d")
>>> az.plot_bpv(data, kind="p_value")
Plot custom t statistic comparison.
.. plot::
:context: close-figs
>>> import arviz as az
>>> data = az.load_arviz_data("regression1d")
>>> az.plot_bpv(data, kind="t_stat", t_stat=lambda x:np.percentile(x, q=50, axis=-1))
"""
if group not in ("posterior", "prior"):
raise TypeError("`group` argument must be either `posterior` or `prior`")
Expand All @@ -139,8 +159,11 @@ def plot_bpv(
if kind.lower() not in ("t_stat", "u_value", "p_value"):
raise TypeError("`kind` argument must be either `t_stat`, `u_value`, or `p_value`")

if reference.lower() not in ("analytical", "samples", None):
raise TypeError("`reference` argument must be either `analytical`, `samples`, or `None`")
if reference is not None:
if reference.lower() not in ("analytical", "samples"):
raise TypeError(
"`reference` argument must be either `analytical`, `samples`, or `None`"
)

if hdi_prob is None:
hdi_prob = rcParams["stats.hdi_prob"]
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ def matplotlib_kwarg_dealiaser(args, kind, backend="matplotlib"):
"plot": mpl.lines.Line2D,
"hist": mpl.patches.Patch,
"hexbin": mpl.collections.PolyCollection,
"fill_between": mpl.collections.PolyCollection,
"hlines": mpl.collections.LineCollection,
"text": mpl.text.Text,
"contour": mpl.contour.ContourSet,
Expand Down
10 changes: 10 additions & 0 deletions examples/bokeh/bokeh_plot_bpv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Bayesian p-value Posterior plot
===============================
_thumb: .6, .5
"""
import arviz as az

data = az.load_arviz_data("regression1d")
az.plot_bpv(data, backend="bokeh")
10 changes: 10 additions & 0 deletions examples/bokeh/bokeh_plot_bpv_tstat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Bayesian p-value Posterior plot
===============================
_thumb: .6, .5
"""
import arviz as az

data = az.load_arviz_data("regression1d")
az.plot_bpv(data, kind="t_stat", t_stat="0.5", backend="bokeh")
15 changes: 15 additions & 0 deletions examples/matplotlib/mpl_plot_bpv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Bayesian p-value Posterior plot
===============================
_thumb: .6, .5
"""
import matplotlib.pyplot as plt
import arviz as az

az.style.use("arviz-darkgrid")

data = az.load_arviz_data("regression1d")
az.plot_bpv(data)

plt.show()
15 changes: 15 additions & 0 deletions examples/matplotlib/mpl_plot_bpv_tstat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Bayesian p-value Posterior plot
===============================
_thumb: .6, .5
"""
import matplotlib.pyplot as plt
import arviz as az

az.style.use("arviz-darkgrid")

data = az.load_arviz_data("regression1d")
az.plot_bpv(data, kind="t_stat", t_stat="0.5")

plt.show()

0 comments on commit 8089468

Please sign in to comment.