interpret.plot_comparisons()

Plot conditional adjusted comparisons.

Usage

Source

interpret.plot_comparisons(
    model,
    idata,
    contrast,
    conditional=None,
    average_by=None,
    target="mean",
    comparison="diff",
    use_hdi=True,
    prob=az.rcParams["stats.ci_prob"],
    transforms=None,
    sample_new_groups=None,
    fig_kwargs=None,
    subplot_kwargs=None,
    on=None,
)

Parameters

model: Model

The fitted Bambi model.

idata: DataTree

DataTree object containing the posterior samples.

contrast: str or dict[str, ConditionalValues]

Variable(s) to create contrasts for.

conditional: str, list[str], dict[str, ConditionalValues], or None = None

Variables to condition on for comparisons.

average_by: str or list or None = None

Variables to average comparisons over.

target: str = "mean"

Which quantity to extract. "mean" (default) for the posterior of the parent parameter (e.g. "mu"). Pass the response variable name (e.g. "mpg") for posterior predictive samples. Pass a distributional component name (e.g. "sigma") for the posterior of that component.

comparison: Callable[[DataArray, DataArray], DataArray] or str = "diff"

Comparison function or string name. Built-in options: “diff” (difference), “ratio” (ratio), “lift” (relative difference). Default is “diff”.

use_hdi: bool = True

Whether to use highest density interval. Default is True.

prob: float or list[float] or None = az.rcParams["stats.ci_prob"]

Probability or list of probabilities for credible intervals. Default is from arviz rcParams. When a list is provided, nested bands with decreasing opacity are drawn. Pass None to omit bands.

transforms: dict or None = None

Dictionary of transformations to apply to comparisons.

sample_new_groups: bool or None = None

Deprecated and has no effect. Bambi automatically determines how to predict for new groups based on the type of group. Default is None.

fig_kwargs: dict or None = None

Additional keyword arguments for figure customization. Use the ‘theme’ key to pass a dictionary of matplotlib rc parameters.

subplot_kwargs: dict[str, str] or None = None

Overrides default plotting sequence (main, group, panel).

on: Axes, Figure, SubFigure, or None = None
Matplotlib target on which to draw the plot. If None, a new figure is created.

Returns

Figure
A Matplotlib Figure. In Jupyter notebooks, the figure automatically displays. In scripts, call .show() to display it. The returned Figure can be customized through its axes (e.g., figure.axes[0].set_title(...)).

Raises

ValueError
If more than 3 conditional variables are provided without averaging.