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:
- Other Parameters:
- plot_kwargs
dict, optional Keyword arguments forwarded to the underlying line plot. Defaults include
{"color": "C0"}.- ylabel
str, optional Y-axis label. Defaults to “Effect”.
- xlabel
str, optional X-axis label. Defaults to “Sweep”.
- title
str, 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_fallback
str, optional Fallback title used for subplot titles when no plotting dims exist. Defaults to “Sensitivity Analysis”.
- hue_dim
str, 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_dimis provided. Defaults toTruewhenhue_dimis set.- legend_kwargs
dict, optional Keyword arguments forwarded to
Axes.legendwhenhue_dimis 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 thechannel_scalefromidata.constant_data. Requireshue_dimto be set so each line can be scaled appropriately. Each channel will have its own X-axis range based on its scale factor.
- plot_kwargs
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_dimto be set):fig, axes = mmm.plot.sensitivity_analysis( hdi_prob=0.9, hue_dim="channel", x_sweep_axis="absolute", xlabel="Total Spend", )