Skip to content

Commit 7fb2257

Browse files
asael697OriolAbril
andauthored
Add rope to plots arguments guide (#2210)
* Add a rope example Add a rope example of forest plots using ropes to the plot's arguments guide * Add link in rope argument Add the "Plots’ arguments guide" link to the rope argument in forest and posterior plots. * Update forestplot.py remove the forest plot with ropes examples from the `plot_forest()` documentation * Update plots_arguments_guide.md Correct the data set in the plot's guide example * Update rope's description Update rope's description * add examples of rope behaviour * update rope docstrings --------- Co-authored-by: Oriol (ZBook) <[email protected]>
1 parent 37540cd commit 7fb2257

File tree

3 files changed

+61
-22
lines changed

3 files changed

+61
-22
lines changed

arviz/plots/forestplot.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ def plot_forest(
8585
hdi_prob : float, default 0.94
8686
Plots highest posterior density interval for chosen percentage of density.
8787
See :ref:`this section <common_ hdi_prob>` for usage examples.
88-
rope : tuple or dictionary of tuples
89-
Lower and upper values of the Region of Practical Equivalence. If a list with one interval
90-
only is provided, the ROPE will be displayed across the y-axis. If more than one
91-
interval is provided the length of the list should match the number of variables.
88+
rope : list, tuple or dictionary of {str : tuples or lists}, optional
89+
A dictionary of tuples with the lower and upper values of the Region Of Practical
90+
Equivalence. See :ref:`this section <common_rope>` for usage examples.
9291
quartiles : bool, default True
9392
Flag for plotting the interquartile range, in addition to the ``hdi_prob`` intervals.
9493
r_hat : bool, default False
@@ -182,20 +181,6 @@ def plot_forest(
182181
>>> figsize=(9, 7))
183182
>>> axes[0].set_title('Estimated theta for 8 schools models')
184183
185-
Forestplot with ropes
186-
187-
.. plot::
188-
:context: close-figs
189-
190-
>>> rope = {'theta': [{'school': 'Choate', 'rope': (2, 4)}], 'mu': [{'rope': (-2, 2)}]}
191-
>>> axes = az.plot_forest(non_centered_data,
192-
>>> rope=rope,
193-
>>> var_names='~tau',
194-
>>> combined=True,
195-
>>> figsize=(9, 7))
196-
>>> axes[0].set_title('Estimated theta for 8 schools model')
197-
198-
199184
Ridgeplot
200185
201186
.. plot::

arviz/plots/posteriorplot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def plot_posterior(
3838
show=None,
3939
**kwargs
4040
):
41-
"""Plot Posterior densities in the style of John K. Kruschke's book.
41+
r"""Plot Posterior densities in the style of John K. Kruschke's book.
4242
4343
Parameters
4444
----------
@@ -83,9 +83,9 @@ def plot_posterior(
8383
Defaults to 'auto' i.e. it falls back to default set in rcParams.
8484
group: str, optional
8585
Specifies which InferenceData group should be plotted. Defaults to 'posterior'.
86-
rope: tuple or dictionary of tuples
87-
Lower and upper values of the Region Of Practical Equivalence. If a list is provided, its
88-
length should match the number of variables.
86+
rope : list, tuple or dictionary of {str: tuples or lists}, optional
87+
A dictionary of tuples with the lower and upper values of the Region Of Practical
88+
Equivalence. See :ref:`this section <common_rope>` for usage examples.
8989
ref_val: float or dictionary of floats
9090
display the percentage below and above the values in ref_val. Must be None (default),
9191
a constant, a list or a dictionary like see an example below. If a list is provided, its

doc/source/user_guide/plots_arguments_guide.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,60 @@ Matplotlib {doc}`mpl:tutorials/colors/colors` tutorial.
304304
Module {mod}`bokeh.colors`
305305
:::
306306

307+
(common_rope)=
308+
## `rope`
309+
310+
The rope argument is used to indicate the lower and upper limits of the Region Of Practical
311+
Equivalence (ROPE). These limits can be expressed in two ways, depending on whether
312+
the ROPE is common between all variables or not:
313+
314+
1. A single list. If a single list of two floats is given as `rope` argument,
315+
these two provided values will be used as limits of the ROPE in all plotted variables.
316+
2. A dictionary of lists.
317+
318+
Example of using a single list as `rope`
319+
320+
```{code-cell} ipython3
321+
az.plot_forest(non_centered_eight, var_names="~theta_t", rope=[-1, 2]);
322+
```
323+
324+
An example of using a dictionary as `rope` to highlight the ROPE for a single variable:
325+
326+
```{code-cell} ipython3
327+
rope = {'mu': [{"rope": (4, 5)}]}
328+
329+
az.plot_forest(non_centered_eight, rope=rope, var_names='~theta_t', combined=True);
330+
```
331+
332+
An example of using a dictionary as `rope` to highlight different ROPEs for different variables:
333+
334+
```{code-cell} ipython3
335+
rope = {
336+
"mu": [{"rope": (4, 5)}],
337+
"theta": [
338+
{"school": "Choate", "rope": (0, 3)},
339+
{"school": "Phillips Andover", "rope": (10, 14)},
340+
{"school": "Hotchkiss", "rope": (3, 9)},
341+
{"school": "St. Paul's", "rope": (3, 8)},
342+
]
343+
}
344+
345+
az.plot_forest(non_centered_eight, rope=rope, var_names="~theta_t", combined=True);
346+
```
347+
348+
Moreover, for multidimensional variables, it is easy to share a common ROPE for all its components
349+
with a different one for other variables:
350+
351+
```{code-cell} ipython3
352+
rope = {
353+
"mu": [{"rope": (4, 5)}],
354+
"theta": [{"rope": (0, 3)}],
355+
"tau": [{"rope": (0, 1)}],
356+
}
357+
358+
az.plot_forest(non_centered_eight, rope=rope, var_names="~theta_t", combined=True);
359+
```
360+
307361
(common_legend)=
308362
## `legend`
309363

0 commit comments

Comments
 (0)