superstats.diagnostics.plots.posterior_resimulation#

Posterior predictive resimulation plots.

Functions

plot_posterior_resimulation(pred_data, real_data)

Plot posterior predictive resimulations against the observed data.

superstats.diagnostics.plots.posterior_resimulation.plot_posterior_resimulation(pred_data, real_data, data_dim=0, kind='trajectory', aggregation=None, aggregate_strategy='full_uncertainty', uncertainty_fun='95hdi', smoothing=None, smoothing_window=5, marginal=True, spaghetti=False, num_cols=3, color='#356673', real_color='black', alpha=0.4, label_fontsize=14, tick_fontsize=12, figsize=None, max_discrete_values=30)[source]#

Plot posterior predictive resimulations against the observed data.

Parameters:
pred_datamapping of np.ndarray

Posterior resimulated data, mapping observation names to arrays of shape (num_datasets, num_resims, num_steps).

real_datamapping of np.ndarray

Observed data, mapping observation names to arrays of shape (num_datasets, num_steps).

data_dimint or str, optional, default: 0

Which observation variable to plot. Strings select by key and integers index the predictive mapping’s key order.

kind{“trajectory”, “dist”}, optional, default: “trajectory”

“trajectory”: band/center over steps. “dist”: distribution across steps.

aggregationcallable() or None, optional, default: None

None: one panel per dataset. callable: a single panel aggregated across datasets. Called as aggregation(x, axis=…) (e.g. np.mean, np.median). Also used (instead of a hardcoded median) to collapse resims into a per-dataset representative when aggregate_strategy=”no_epistemic”.

aggregate_strategy{“full_uncertainty”, “no_epistemic”}, optional, default: “full_uncertainty”

Only used when aggregation is not None. “full_uncertainty”: flatten datasets and posterior resims together, then summarize. Captures both epistemic and aleatoric uncertainty. “no_epistemic”: collapse resims to one representative trajectory per dataset first (via aggregation), then aggregate across datasets. Removes epistemic uncertainty.

uncertainty_fun{“std”, “95ci”, “mad”, “95hdi”} or callable() or None, optional, default: “95hdi”

“trajectory” mode only. Function to draw a band around the resimulated center line.

smoothing{“sma”, “ema”} or None, optional, default: None

“trajectory” mode only. Causal (past-only) smoothing applied to the real trajectories and, for resimulated data, to the trajectories that result after aggregate_strategy has pooled resims - i.e. pooling happens on raw data, smoothing is applied afterward, and the center/uncertainty band are computed on the smoothed result.

smoothing_windowint, optional, default: 5

Window size for sma, or span parameter for ema.

marginalbool, optional, default: True

“trajectory” mode only. Attach a marginal KDE panel of the resimulated draws to the right of each trajectory axis.

spaghettibool, optional, default: False

“trajectory” mode only. Per-dataset panels: overlay individual resim draws behind the band. Aggregated panel: overlay each dataset’s own representative trajectory (via aggregation) behind the aggregate band.

num_colsint, optional, default: 3

Number of columns when aggregation is None (per-dataset grid).

colorstr, optional, default: BASE_COLOR

Color for bands / centers / histograms.

real_colorstr, optional, default: “black”

Color for the observed data.

alphafloat in [0, 1], optional, default: 0.4

Alpha for spaghetti lines.

label_fontsizeint, optional, default: 14

The font size of the axis label texts.

tick_fontsizeint, optional, default: 12

The font size of the axis tick labels.

figsizetuple of two floats or None, optional, default: None

Explicit figure size in inches. If None, the default layout size is used.

max_discrete_valuesint, optional, default: 30

“dist” mode, per-dataset panels only. Maximum number of discrete categories to treat the data as discrete.

Returns:
figplt.Figure - the figure instance for optional saving
Raises:
ValueError

If kind is not “trajectory” or “dist”, if pred_data or real_data don’t have the expected shape, if their (num_datasets, num_steps) don’t match, or if aggregate_strategy is not “full_uncertainty” or “no_epistemic”.

Parameters:
Return type:

Figure