Skip to content

Commit

Permalink
remove deprecation warnings for credible_interval and include_circ (#…
Browse files Browse the repository at this point in the history
…1548)

* remove deprecation warnings credible_interval and include_circ_vars

* add missing file and update changelog

* fix docstring

* black
  • Loading branch information
aloctavodia authored Feb 14, 2021
1 parent 43e7999 commit 43f7ba6
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 157 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Deprecation
* Removed Geweke diagnostic ([1545](https://github.com/arviz-devs/arviz/pull/1545))
* Removed credible_interval and include_circ arguments ([1548](https://github.com/arviz-devs/arviz/pull/1548))

### Documentation

Expand Down
3 changes: 1 addition & 2 deletions arviz/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .energyplot import plot_energy
from .essplot import plot_ess
from .forestplot import plot_forest
from .hdiplot import plot_hdi, plot_hpd
from .hdiplot import plot_hdi
from .jointplot import plot_joint
from .kdeplot import plot_kde
from .khatplot import plot_khat
Expand All @@ -35,7 +35,6 @@
"plot_ess",
"plot_forest",
"plot_hdi",
"plot_hpd",
"plot_joint",
"plot_kde",
"plot_khat",
Expand Down
6 changes: 2 additions & 4 deletions arviz/plots/backends/bokeh/loopitplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def plot_loo_pit(
y,
color,
textsize,
credible_interval,
hdi_prob,
plot_kwargs,
backend_kwargs,
show,
Expand Down Expand Up @@ -96,9 +96,7 @@ def plot_loo_pit(
fill_kwargs.setdefault(
"step", "mid" if plot_kwargs["drawstyle"] == "steps-mid" else None
)
fill_kwargs.setdefault(
"legend_label", "{:.3g}% credible interval".format(credible_interval)
)
fill_kwargs.setdefault("legend_label", "{:.3g}% credible interval".format(hdi_prob))
elif use_hdi:
if hdi_kwargs is None:
hdi_kwargs = {}
Expand Down
6 changes: 3 additions & 3 deletions arviz/plots/backends/matplotlib/loopitplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def plot_loo_pit(
y,
color,
textsize,
credible_interval,
hdi_prob,
plot_kwargs,
backend_kwargs,
show,
Expand Down Expand Up @@ -92,7 +92,7 @@ def plot_loo_pit(
fill_kwargs.setdefault(
"step", "mid" if plot_kwargs["drawstyle"] == "steps-mid" else None
)
fill_kwargs.setdefault("label", "{:.3g}% credible interval".format(credible_interval))
fill_kwargs.setdefault("label", "{:.3g}% credible interval".format(hdi_prob))
elif use_hdi:
if hdi_kwargs is None:
hdi_kwargs = {}
Expand Down Expand Up @@ -129,7 +129,7 @@ def plot_loo_pit(
ax.tick_params(labelsize=xt_labelsize)
if legend:
if not (use_hdi or (ecdf and ecdf_fill)):
label = "{:.3g}% credible interval".format(credible_interval) if ecdf else "Uniform"
label = "{:.3g}% credible interval".format(hdi_prob) if ecdf else "Uniform"
ax.plot([], label=label, **plot_unif_kwargs)
ax.legend()

Expand Down
10 changes: 2 additions & 8 deletions arviz/plots/densityplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ..data import convert_to_dataset
from ..rcparams import rcParams
from ..utils import _var_names, credible_interval_warning
from ..utils import _var_names
from .plot_utils import default_grid, get_plotting_function, make_label, xarray_var_iter


Expand All @@ -29,7 +29,6 @@ def plot_density(
backend=None,
backend_kwargs=None,
show=None,
credible_interval=None,
):
"""Generate KDE plots for continuous variables and histograms for discrete ones.
Expand Down Expand Up @@ -102,13 +101,11 @@ def plot_density(
check the plotting method of the backend.
show : bool, optional
Call backend show function.
credible_interval: float, optional
deprecated: Please see hdi_prob
Returns
-------
axes : matplotlib axes or bokeh figures
Examples
--------
Plot default density plot
Expand Down Expand Up @@ -163,9 +160,6 @@ def plot_density(
>>> az.plot_density([centered, non_centered], var_names=["mu"], bw=.9)
"""
if credible_interval:
hdi_prob = credible_interval_warning(credible_interval, hdi_prob)

if not isinstance(data, (list, tuple)):
datasets = [convert_to_dataset(data, group=group)]
else:
Expand Down
8 changes: 1 addition & 7 deletions arviz/plots/forestplot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Forest plot."""
from ..data import convert_to_dataset
from ..rcparams import rcParams
from ..utils import _var_names, credible_interval_warning, get_coords
from ..utils import _var_names, get_coords
from .plot_utils import get_plotting_function


Expand Down Expand Up @@ -34,7 +34,6 @@ def plot_forest(
backend_config=None,
backend_kwargs=None,
show=None,
credible_interval=None,
):
"""Forest plot to compare HDI intervals from a number of distributions.
Expand Down Expand Up @@ -115,8 +114,6 @@ def plot_forest(
check the plotting method of the backend.
show: bool, optional
Call backend show function.
credible_interval: float, optional
deprecated: Please see hdi_prob
Returns
-------
Expand Down Expand Up @@ -183,9 +180,6 @@ def plot_forest(
>>> figsize=(9, 7))
>>> axes[0].set_title('Estimated theta for 8 schools model')
"""
if credible_interval:
hdi_prob = credible_interval_warning(credible_interval, hdi_prob)

if not isinstance(data, (list, tuple)):
data = [data]

Expand Down
12 changes: 0 additions & 12 deletions arviz/plots/hdiplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from ..rcparams import rcParams
from ..stats import hdi
from ..utils import credible_interval_warning
from .plot_utils import get_plotting_function


Expand All @@ -29,7 +28,6 @@ def plot_hdi(
backend=None,
backend_kwargs=None,
show=None,
credible_interval=None,
):
r"""
Plot HDI intervals for regression data.
Expand Down Expand Up @@ -76,8 +74,6 @@ def plot_hdi(
These are kwargs specific to the backend being used. Passed to ::``
show : bool, optional
Call backend show function.
credible_interval : float, optional
Deprecated: Please see hdi_prob
Returns
-------
Expand Down Expand Up @@ -114,9 +110,6 @@ def plot_hdi(
>>> az.plot_hdi(x_data, hdi_data=hdi_data[1], color="k", ax=ax, fill_kwargs={"alpha": .2})
"""
if credible_interval:
hdi_prob = credible_interval_warning(credible_interval, hdi_prob)

if hdi_kwargs is None:
hdi_kwargs = {}

Expand Down Expand Up @@ -189,8 +182,3 @@ def plot_hdi(
plot = get_plotting_function("plot_hdi", "hdiplot", backend)
ax = plot(**hdiplot_kwargs)
return ax


def plot_hpd(*args, **kwargs): # noqa: D103
warnings.warn("plot_hpd has been deprecated, please use plot_hdi", DeprecationWarning)
return plot_hdi(*args, **kwargs)
30 changes: 13 additions & 17 deletions arviz/plots/loopitplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def plot_loo_pit(
ecdf_fill=True,
n_unif=100,
use_hdi=False,
credible_interval=None,
hdi_prob=None,
figsize=None,
textsize=None,
color="C0",
Expand Down Expand Up @@ -49,8 +49,8 @@ def plot_loo_pit(
ecdf : bool, optional
Plot the difference between the LOO-PIT Empirical Cumulative Distribution Function
(ECDF) and the uniform CDF instead of LOO-PIT kde.
In this case, instead of overlaying uniform distributions, the beta ``credible_interval``
interval around the theoretical uniform CDF is shown. This approximation only holds
In this case, instead of overlaying uniform distributions, the beta ``hdi_prob``
around the theoretical uniform CDF is shown. This approximation only holds
for large S and ECDF values not vary close to 0 nor 1. For more information, see
`Vehtari et al. (2019)`, `Appendix G <https://avehtari.github.io/rhat_ess/rhat_ess.html>`_.
ecdf_fill : bool, optional
Expand All @@ -60,8 +60,8 @@ def plot_loo_pit(
Number of datasets to simulate and overlay from the uniform distribution.
use_hdi : bool, optional
Compute expected hdi values instead of overlaying the sampled uniform distributions.
credible_interval : float, optional
Theoretical credible interval. Works with ``use_hdi=True`` or ``ecdf=True``.
hdi_prob : float, optional
Probability for the highest density interval. Works with ``use_hdi=True`` or ``ecdf=True``.
figsize : figure size tuple, optional
If None, size is (8 + numvars, 8 + numvars)
textsize: int, optional
Expand Down Expand Up @@ -139,11 +139,11 @@ def plot_loo_pit(
unif = None
x_vals = None

if credible_interval is None:
credible_interval = rcParams["stats.hdi_prob"]
if hdi_prob is None:
hdi_prob = rcParams["stats.hdi_prob"]
else:
if not 1 >= credible_interval > 0:
raise ValueError("The value of credible_interval should be in the interval (0, 1]")
if not 1 >= hdi_prob > 0:
raise ValueError("The value of hdi_prob should be in the interval (0, 1]")

if ecdf:
loo_pit.sort()
Expand All @@ -152,20 +152,16 @@ def plot_loo_pit(
# ideal unnormalized ECDF of uniform distribution with n_data_points points
# it is used indistinctively as x or p(u<x) because for u~U(0,1) they are equal
unif_ecdf = np.arange(n_data_points + 1)
p975 = stats.beta.ppf(
0.5 + credible_interval / 2, unif_ecdf + 1, n_data_points - unif_ecdf + 1
)
p025 = stats.beta.ppf(
0.5 - credible_interval / 2, unif_ecdf + 1, n_data_points - unif_ecdf + 1
)
p975 = stats.beta.ppf(0.5 + hdi_prob / 2, unif_ecdf + 1, n_data_points - unif_ecdf + 1)
p025 = stats.beta.ppf(0.5 - hdi_prob / 2, unif_ecdf + 1, n_data_points - unif_ecdf + 1)
unif_ecdf = unif_ecdf / n_data_points
else:
x_vals, loo_pit_kde = kde(loo_pit)

unif = np.random.uniform(size=(n_unif, loo_pit.size))
if use_hdi:
n_obs = loo_pit.size
hdi_ = stats.beta(n_obs / 2, n_obs / 2).ppf((1 - credible_interval) / 2)
hdi_ = stats.beta(n_obs / 2, n_obs / 2).ppf((1 - hdi_prob) / 2)
hdi_odds = (hdi_ / (1 - hdi_), (1 - hdi_) / hdi_)

loo_pit_kwargs = dict(
Expand All @@ -192,7 +188,7 @@ def plot_loo_pit(
legend=legend,
y_hat=y_hat,
y=y,
credible_interval=credible_interval,
hdi_prob=hdi_prob,
plot_kwargs=plot_kwargs,
backend_kwargs=backend_kwargs,
show=show,
Expand Down
8 changes: 1 addition & 7 deletions arviz/plots/posteriorplot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Plot posterior densities."""
from ..data import convert_to_dataset
from ..rcparams import rcParams
from ..utils import _var_names, credible_interval_warning, get_coords
from ..utils import _var_names, get_coords
from .plot_utils import default_grid, filter_plotters_list, get_plotting_function, xarray_var_iter


Expand Down Expand Up @@ -30,7 +30,6 @@ def plot_posterior(
backend=None,
backend_kwargs=None,
show=None,
credible_interval=None,
**kwargs
):
"""Plot Posterior densities in the style of John K. Kruschke's book.
Expand Down Expand Up @@ -110,8 +109,6 @@ def plot_posterior(
check the plotting method of the backend.
show: bool, optional
Call backend show function.
credible_interval: float or str, optional
deprecated: Please see hdi_prob
**kwargs
Passed as-is to plt.hist() or plt.plot() function depending on the value of `kind`.
Expand Down Expand Up @@ -197,9 +194,6 @@ def plot_posterior(
>>> az.plot_posterior(data, var_names=['mu'], hdi_prob=.75)
"""
if credible_interval:
hdi_prob = credible_interval_warning(credible_interval, hdi_prob)

data = convert_to_dataset(data, group=group)
if transform is not None:
data = transform(data)
Expand Down
10 changes: 2 additions & 8 deletions arviz/plots/violinplot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Plot posterior traces as violin plot."""
from ..data import convert_to_dataset
from ..rcparams import rcParams
from ..utils import _var_names, credible_interval_warning
from ..utils import _var_names
from .plot_utils import default_grid, filter_plotters_list, get_plotting_function, xarray_var_iter


Expand All @@ -27,7 +27,6 @@ def plot_violin(
backend=None,
backend_kwargs=None,
show=None,
credible_interval=None,
):
"""Plot posterior of traces as violin plot.
Expand Down Expand Up @@ -97,8 +96,6 @@ def plot_violin(
check the plotting method of the backend.
show: bool, optional
Call backend show function.
credible_interval: float, optional
deprecated: Please see hdi_prob
Returns
-------
Expand All @@ -123,9 +120,6 @@ def plot_violin(
>>> az.plot_violin(data, var_names="tau", transform=np.log)
"""
if credible_interval:
hdi_prob = credible_interval_warning(credible_interval, hdi_prob)

data = convert_to_dataset(data, group="posterior")
if transform is not None:
data = transform(data)
Expand All @@ -141,7 +135,7 @@ def plot_violin(
hdi_prob = rcParams["stats.hdi_prob"]
else:
if not 1 >= hdi_prob > 0:
raise ValueError("The value of credible_interval should be in the interval (0, 1]")
raise ValueError("The value of hdi_prob should be in the interval (0, 1]")

violinplot_kwargs = dict(
ax=ax,
Expand Down
1 change: 0 additions & 1 deletion arviz/stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"bfmi",
"compare",
"hdi",
"hpd",
"kde",
"loo",
"loo_pit",
Expand Down
Loading

0 comments on commit 43f7ba6

Please sign in to comment.