MMMPlotSuite.sensitivity_analysis#

MMMPlotSuite.sensitivity_analysis(hdi_prob=0.94, ax=None, aggregation=None, subplot_kwargs=None, *, plot_kwargs=None, ylabel='Effect', xlabel='Sweep', title=None, add_figure_title=False, subplot_title_fallback='Sensitivity Analysis', hue_dim=None, legend=None, legend_kwargs=None, x_sweep_axis='relative')[source]#

Plot sensitivity analysis results.

Parameters:
hdi_probfloat, default 0.94

HDI probability mass.

axplt.Axes, optional

The axis to plot on.

aggregationdict, optional

Aggregation to apply to the data. E.g., {“sum”: (“channel”,)} to sum over the channel dimension.

Other Parameters:
plot_kwargsdict, optional

Keyword arguments forwarded to the underlying line plot. Defaults include {"color": "C0"}.

ylabelstr, optional

Y-axis label. Defaults to “Effect”.

xlabelstr, optional

X-axis label. Defaults to “Sweep”.

titlestr, optional

Figure-level title to add when add_figure_title=True.

add_figure_titlebool, optional

Whether to add a figure-level title. Defaults to False.

subplot_title_fallbackstr, optional

Fallback title used for subplot titles when no plotting dims exist. Defaults to “Sensitivity Analysis”.

hue_dimstr, optional

Dimension to draw multiple lines per subplot (e.g., “channel”). When provided, this dimension is excluded from the subplot grid.

legendbool, optional

Whether to show a legend when hue_dim is provided. Defaults to True when hue_dim is set.

legend_kwargsdict, optional

Keyword arguments forwarded to Axes.legend when hue_dim is set.

x_sweep_axis{“relative”, “absolute”}, optional

Controls how the X-axis values are displayed. Defaults to "relative".

  • "relative": Shows sweep multipliers (e.g., 0.5x, 1.0x, 2.0x).

  • "absolute": Shows absolute spend values by multiplying sweep values by the channel_scale from idata.constant_data. Requires hue_dim to be set so each line can be scaled appropriately. Each channel will have its own X-axis range based on its scale factor.

Examples

Basic run using stored results in idata:

# Assuming you already ran a sweep and stored results
# under idata.sensitivity_analysis via SensitivityAnalysis.run_sweep(..., extend_idata=True)
ax = mmm.plot.sensitivity_analysis(hdi_prob=0.9)

With aggregation over dimensions (e.g., sum over channels):

ax = mmm.plot.sensitivity_analysis(
    hdi_prob=0.9,
    aggregation={"sum": ("channel",)},
)

With multiple lines per subplot (e.g., channels within each geo):

fig, axes = mmm.plot.sensitivity_analysis(
    hdi_prob=0.9,
    hue_dim="channel",
    subplot_kwargs={"nrows": 2, "figsize": (12, 8)},
)

With absolute X-axis values (requires hue_dim to be set):

fig, axes = mmm.plot.sensitivity_analysis(
    hdi_prob=0.9,
    hue_dim="channel",
    x_sweep_axis="absolute",
    xlabel="Total Spend",
)