Abacus Core Mixins: Plotting Parameter (plotting_parameter.py)

This module provides the ParameterPlottingMixin class, designed to be inherited by Marketing Mix Model (MMM) classes in Abacus. It offers methods to visualise the posterior distributions of key model parameters, particularly those associated with individual marketing channels.

ParameterPlottingMixin Class

This mixin assumes the inheriting class provides attributes like:

  • fit_result: An ArviZ InferenceData object containing the model trace (posterior samples).

  • channel_columns: A list of channel names used in the model.

Methods

plot_channel_parameter

def plot_channel_parameter(
    self, param_name: Literal["alpha", "lam", "beta_channel"], **plt_kwargs: Any
) -> plt.Figure:

Plots the posterior distribution for a specified channel-specific parameter (alpha, lam, or beta_channel) across all channels using violin plots.

Violin plots combine a box plot with a kernel density estimate, providing a rich visualisation of the distribution’s shape, central tendency, and spread for each channel’s parameter estimate.

Parameters:

  • param_name (Literal["alpha", "lam", "beta_channel"]): The name of the channel parameter to plot. Must be one of:

    • "alpha": Typically represents the saturation limit in saturation functions.

    • "lam": Typically represents the shape parameter in saturation functions (e.g., the point of half-saturation in Michaelis-Menten).

    • "beta_channel": Represents the effectiveness or coefficient associated with each channel’s contribution after adstock and saturation.

  • **plt_kwargs: Additional keyword arguments passed to matplotlib.pyplot.subplots.

Returns:

  • plt.Figure: The matplotlib Figure object containing the violin plot.

Raises:

  • ValueError: If param_name is not one of the allowed values ("alpha", "lam", "beta_channel").

  • RuntimeError (implicitly): If self.fit_result is not available or does not contain the specified param_name.