MMMPlotSuite.residuals_posterior_distribution#

MMMPlotSuite.residuals_posterior_distribution(quantiles=None, aggregation=None)[source]#

Plot the posterior distribution of residuals.

Displays the distribution of residuals (true - predicted) across all time points and dimensions. Users can choose to aggregate across dimensions using mean or sum.

Parameters:
quantileslist of float, optional

Quantiles to display on the distribution plot. Default is [0.25, 0.5, 0.75]. Each value must be between 0 and 1.

aggregationstr, optional

How to aggregate residuals across non-chain/draw dimensions. Options: “mean”, “sum”, or None (default). - “mean”: Average residuals across date and other dimensions - “sum”: Sum residuals across date and other dimensions - None: Plot distribution for each dimension combination separately

Returns:
figmatplotlib.figure.Figure

The Figure object containing the subplots.

axesnp.ndarray of matplotlib.axes.Axes

Array of Axes objects corresponding to each subplot.

Raises:
ValueError

If y_original_scale is not in posterior_predictive. If target_data is not in constant_data. If any quantile is not between 0 and 1. If aggregation is not one of “mean”, “sum”, or None.

Examples

Plot residuals distribution with default quantiles:

mmm.plot.residuals_posterior_distribution()

Plot with custom quantiles and aggregation:

mmm.plot.residuals_posterior_distribution(
    quantiles=[0.05, 0.5, 0.95], aggregation="mean"
)