arviz_plots.plot_ppc_rootogram

arviz_plots.plot_ppc_rootogram#

arviz_plots.plot_ppc_rootogram(dt, ci_prob=None, yscale='sqrt', data_pairs=None, var_names=None, filter_vars=None, group='posterior_predictive', coords=None, sample_dims=None, plot_collection=None, backend=None, labeller=None, aes_by_visuals=None, visuals=None, **pc_kwargs)[source]#

Rootogram with confidence intervals per predicted count.

Rootograms are useful to check the calibration of count models. A rootogram shows the difference between observed and predicted counts. The y-axis, showing frequencies, is on the square root scale. This makes easier to compare observed and expected frequencies even for low frequencies [1] and [2].

For more details on how to interpret this plot, see https://arviz-devs.github.io/EABM/Chapters/Prior_posterior_predictive_checks.html

Parameters:
dtxarray.DataTree

If group is “posterior_predictive”, it should contain the posterior_predictive and observed_data groups. If group is “prior_predictive”, it should contain the prior_predictive group.

ci_probfloat, optional

Probability for the credible interval. Defaults to rcParams["stats.ci_prob"].

yscalestr, optional

Scale for the y-axis. Defaults to “sqrt”, pass “linear” for linear scale. Currently only “matplotlib” backend is supported. For “bokeh” and “plotly” the y-axis is linear.

data_pairsdict, optional

Dictionary of keys prior/posterior predictive data and values observed data variable names. If None, it will assume that the observed data and the predictive data have the same variable name.

var_namesstr or list of str, optional

One or more variables to be plotted. Currently only one variable is supported. Prefix the variables by ~ when you want to exclude them from the plot.

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

If None (default), 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,

Group to be plotted. Defaults to “posterior_predictive”. It could also be “prior_predictive”.

coordsdict, optional

Coordinates to plot.

sample_dimsstr or sequence of hashable, optional

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

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

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

visualsmapping of {strmapping or False}, optional

Valid keys are:

observed_markers defaults to False, no observed data is plotted, if group is “prior_predictive”. Pass an (empty) mapping to plot the observed data.

**pc_kwargs

Passed to arviz_plots.PlotCollection.wrap

Returns:
PlotCollection

References

[1]

Kleiber C, Zeileis A. Visualizing Count Data Regressions Using Rootograms. The American Statistician, 70(3). (2016) https://doi.org/10.1080/00031305.2016.1173590

[2]

Säilynoja et al. Recommendations for visual predictive checks in Bayesian workflow. (2025) arXiv preprint https://arxiv.org/abs/2503.01509

Examples

Plot the rootogram for the crabs dataset.

>>> from arviz_plots import plot_ppc_rootogram, style
>>> style.use("arviz-variat")
>>> from arviz_base import load_arviz_data
>>> dt = load_arviz_data('crabs_poisson')
>>> plot_ppc_rootogram(dt)
../../_images/arviz_plots-plot_ppc_rootogram-1.png