arviz_plots.plot_mcse

Contents

arviz_plots.plot_mcse#

arviz_plots.plot_mcse(dt, var_names=None, filter_vars=None, group='posterior', coords=None, sample_dims=None, rug=False, rug_kind='diverging', n_points=20, extra_methods=False, plot_collection=None, backend=None, labeller=None, aes_by_visuals=None, visuals=None, stats=None, **pc_kwargs)[source]#

Plot Monte Carlo standard error.

The Monte Carlo standard error (mcse) is a measure of the uncertainty associated with the estimation of a posterior distribution using Monte Carlo methods. See [1] for more details.

Parameters:
dtxarray.DataTree or dict of {strxarray.DataTree}

Input data. In case of dictionary input, the keys are taken to be model names. In such cases, a dimension “model” is generated and can be used to map to aesthetics.

var_namesstr or sequence of str, optional

One or more variables to be plotted. Prefix the variables by ~ when you want to exclude them from the plot.

filter_vars{None, “like”, “regex”}, default None

If None, interpret var_names as the real variables names. If “like”, interpret var_names as substrings of the real variables names. If “regex”, interpret var_names as regular expressions on the real variables names.

groupstr, default “posterior”

Group to be plotted.

coordsdict, optional
sample_dimsstr or sequence of hashable, optional

Dimensions to reduce unless mapped to an aesthetic. Defaults to rcParams["data.sample_dims"]

rugbool, default False

Add a rug plot for a specific subset of values.

rug_kindstr, default “diverging”

Variable in sample stats to use as rug mask. Must be a boolean variable.

n_pointsint, default 20

Number of points for which to plot their quantile/local mcse or number of subsets in the evolution plot.

extra_methodsbool, default False

Plot mean and sd mcse as horizontal lines.

plot_collectionPlotCollection, optional
backend{“matplotlib”, “bokeh”}, optional
labellerlabeller, optional
aes_by_visualsmapping of {strsequence of str or False}, optional

Mapping of visuals to aesthetics that should use their mapping in plot_collection when plotted. Valid keys are the same as for visuals.

By default, no aesthetic mappings are defined. Only when multiple models are present a color and x shift is generated to distinguish the data coming from the different models.

When mean or sd keys are present in aes_by_visuals but mean_text or sd_text are not, the respective _text key will be added with the same values as mean or sd ones.

visualsmapping of {strmapping or False}, optional

Valid keys are:

  • mcse -> passed to scatter_xy

  • rug -> passed to trace_rug

  • title -> passed to labelled_title

  • xlabel -> passed to labelled_x

  • ylabel -> passed to labelled_y

  • mean -> passed to line_xy

  • mean_text -> passed to annotate_xy

  • sd_text -> passed to annotate_xy

  • sd -> passed to line_xy

statsmapping, optional

Valid keys are:

  • mcse -> passed to mcse, method = ‘quantile’

  • mean -> passed to mcse, method=’mean’

  • sd -> passed to mcse, method=’sd’

**pc_kwargs

Passed to arviz_plots.PlotCollection.wrap

Returns:
PlotCollection

See also

Introduction to batteries-included plots

General introduction to batteries-included plotting functions, common use and logic overview

References

[1]

Vehtari et al. Rank-normalization, folding, and localization: An improved Rhat for assmcseing convergence of MCMC. Bayesian Analysis. 16(2) (2021) https://doi.org/10.1214/20-BA1221. arXiv preprint https://arxiv.org/abs/1903.08008

Examples

We can manually map the color to the variable, and have the mapping apply to the title too instead of only the mcse markers:

>>> from arviz_plots import plot_mcse, style
>>> style.use("arviz-variat")
>>> from arviz_base import load_arviz_data
>>> non_centered = load_arviz_data('non_centered_eight')
>>> pc = plot_mcse(
>>>     non_centered,
>>>     coords={"school": ["Choate", "Deerfield", "Hotchkiss"]},
>>>     aes={"color": ["__variable__"]},
>>>     aes_by_visuals={"title": ["color"]},
>>> )
../../_images/arviz_plots-plot_mcse-1.png

We can add extra methods to plot the mean and standard deviation as lines

>>> pc = plot_mcse(
>>>     non_centered,
>>>     coords={"school": ["Choate", "Deerfield", "Hotchkiss"]},
>>>     extra_methods=True,
>>> )
../../_images/arviz_plots-plot_mcse-2.png

Rugs can also be added:

>>> pc = plot_mcse(
>>>     non_centered,
>>>     coords={"school": ["Choate", "Deerfield", "Hotchkiss"]},
>>>     rug=True,
>>> )
../../_images/arviz_plots-plot_mcse-3.png

We can also adjust the number of points:

>>> pc = plot_mcse(
>>>     non_centered,
>>>     coords={"school": ["Choate", "Deerfield", "Hotchkiss"]},
>>>     n_points=10,
>>> )
../../_images/arviz_plots-plot_mcse-4.png