BaseMMM.plot_posterior_predictive#

BaseMMM.plot_posterior_predictive(original_scale=False, hdi_list=None, add_mean=True, add_gradient=False, ax=None, **plt_kwargs)#

Plot the posterior predictive distribution from the model fit.

This function creates a visualization of the model’s posterior predictive distribution, allowing for comparison with observed data. It can include highest density intervals (HDI), mean predictions, and a gradient representation of the full distribution.

Parameters:
original_scalebool, optional

If True, plot in the original scale of the target variable. If False, plot in the transformed scale used for modeling. Default is False.

hdi_listlist of float, optional

List of HDI levels to plot. Default is [0.94] Provide an empty list to omit plotting the HDI.

add_meanbool, optional

If True, add the mean prediction to the plot. Default is True.

add_gradientbool, optional

If True, add a gradient representation of the full posterior distribution. Default is False.

axplt.Axes, optional

A matplotlib Axes object to plot on. If None, a new figure and axes will be created.

**plt_kwargsdict

Additional keyword arguments to pass to plt.subplots() when creating a new figure.

Returns:
plt.Figure

The matplotlib Figure object containing the plot.

Raises:
ValueError

If the length of the target variable doesn’t match the length of the date column in the posterior predictive data.

Notes

This function visualizes the model’s predictions against the observed data. The observed data is always plotted as a black line. Depending on the parameters, it can also show: - HDI (Highest Density Intervals) at 94% and 50% levels - Mean prediction line - Gradient representation of the full posterior distribution

If predicting out-of-sample, ensure that self.y is overwritten with the corresponding non-transformed target variable.