arviz.plot_posterior

arviz.plot_posterior(data, var_names=None, coords=None, figsize=None, textsize=None, credible_interval=0.94, round_to=1, point_estimate='mean', rope=None, ref_val=None, kind='kde', bw=4.5, bins=None, ax=None, **kwargs)[source]

Plot Posterior densities in the style of John K. Kruschke’s book.

Parameters
dataobj

Any object that can be converted to an az.InferenceData object Refer to documentation of az.convert_to_dataset for details

var_nameslist of variable names

Variables to be plotted, two variables are required.

coordsmapping, optional

Coordinates of var_names to be plotted. Passed to Dataset.sel

figsizetuple

Figure size. If None it will be defined automatically.

textsize: float

Text size scaling factor for labels, titles and lines. If None it will be autoscaled based on figsize.

credible_intervalfloat, optional

Credible intervals. Defaults to 0.94.

round_toint

Controls formatting for floating point numbers

point_estimate: str

Must be in (‘mode’, ‘mean’, ‘median’)

rope: tuple or dictionary of tuples

Lower and upper values of the Region Of Practical Equivalence. If a list is provided, its length should match the number of variables.

ref_val: float or dictionary of floats

display the percentage below and above the values in ref_val. If a list is provided, its length should match the number of variables.

kind: str

Type of plot to display (kde or hist) For discrete variables this argument is ignored and a histogram is always used.

bwfloat

Bandwidth scaling factor for the KDE. Should be larger than 0. The higher this number the smoother the KDE will be. Defaults to 4.5 which is essentially the same as the Scott’s rule of thumb (the default rule used by SciPy). Only works if kind == kde.

binsinteger or sequence or ‘auto’, optional

Controls the number of bins, accepts the same keywords matplotlib.hist() does. Only works if kind == hist. If None (default) it will use auto for continuous variables and range(xmin, xmax + 1) for discrete variables.

axaxes

Matplotlib axes. Defaults to None.

**kwargs

Passed as-is to plt.hist() or plt.plot() function depending on the value of kind.

Returns
axmatplotlib axes

Examples

Show a default kernel density plot following style of John Kruschke

>>> import arviz as az
>>> data = az.load_arviz_data('centered_eight')
>>> az.plot_posterior(data)
../_images/arviz-plot_posterior-1.png

Plot subset variables by specifying variable name exactly

>>> az.plot_posterior(data, var_names=['mu'])
../_images/arviz-plot_posterior-2.png

Plot Region of Practical Equivalence (rope) for all distributions

>>> az.plot_posterior(data, var_names=['mu', 'theta'], rope=(-1, 1))
../_images/arviz-plot_posterior-3.png

Plot Region of Practical Equivalence for selected distributions

>>> rope = {'mu': [{'rope': (-2, 2)}], 'theta': [{'school': 'Choate', 'rope': (2, 4)}]}
>>> az.plot_posterior(data, var_names=['mu', 'theta'], rope=rope)
../_images/arviz-plot_posterior-4.png

Add reference lines

>>> az.plot_posterior(data, var_names=['mu', 'theta_tilde'], ref_val=0)
../_images/arviz-plot_posterior-5.png

Show point estimate of distribution

>>> az.plot_posterior(data, var_names=['mu', 'theta_tilde'], point_estimate='mode')
../_images/arviz-plot_posterior-6.png

Plot posterior as a histogram

>>> az.plot_posterior(data, var_names=['mu'], kind='hist')
../_images/arviz-plot_posterior-7.png

Change size of credible interval

>>> az.plot_posterior(data, var_names=['mu'], credible_interval=.75)
../_images/arviz-plot_posterior-8.png