compare_draws()

Extract and stack draws from multiple groups (e.g., posterior and prior).

Usage

compare_draws(
    dt,
    *var_names,
    groups=None,
    group_name="source",
)

Calls parameter_draws() for each group, adds a column identifying the source group, and concatenates the results into a single DataFrame for easy comparison.

Parameters

dt: xr.DataTree or arviz.InferenceData

ArviZ InferenceData or xarray DataTree object.

*var_names: str

Names of variables to extract (as for parameter_draws()).

groups: list[str] | None = None

Which groups to extract and stack. Defaults to ["posterior", "prior"] when None.

group_name: str = "source"
Name of the column identifying the source group. Default “source”.

Returns

pl.DataFrame
Stacked draws with an additional column (group_name) indicating source.

Example

Extract posterior and prior for side-by-side forest plots

compare_df = compare_draws(dt, “beta”, groups=[“posterior”, “prior”]) # -> columns: chain, draw, groups, beta, source # -> source in {“posterior”, “prior”}