MMMPlotSuite.allocated_contribution_by_channel_over_time#
- MMMPlotSuite.allocated_contribution_by_channel_over_time(samples, hdi_prob=0.85, backend=None)[source]#
Plot channel contributions over time from budget allocation optimization.
Visualizes how contributions from each channel evolve over time given an optimized budget allocation. Shows mean contribution lines per channel with HDI uncertainty bands.
- Parameters:
- samples
xr.Dataset Dataset from budget allocation optimization containing channel contributions over time. Required dimensions: - ‘channel’: Channel names - ‘date’: Time dimension - ‘sample’: MCMC samples
Required variables: - Variable containing ‘channel_contribution’ (e.g., ‘channel_contribution’
or ‘channel_contribution_original_scale’)
Typically obtained from:
mmm.allocate_budget_to_maximize_response(...)- hdi_prob
float, default 0.85 Probability mass for HDI interval (between 0 and 1).
- backend
str|None, optional Backend to use for plotting. If None, uses global backend configuration.
- samples
- Returns:
PlotCollectionarviz_plots PlotCollection object containing the plot.
Use
.show()to display or.save("filename")to save. Unlike the legacy suite which returned(Figure, Axes), this provides a unified interface across all backends.
- Raises:
ValueErrorIf required dimensions (‘channel’, ‘date’, ‘sample’) not found in samples.
ValueErrorIf no variable containing ‘channel_contribution’ found in samples.
See also
budget_allocation_roasPlot ROI distributions from same allocation results
LegacyMMMPlotSuite.allocated_contribution_by_channel_over_timeLegacy implementation
Notes
Breaking changes from legacy implementation:
Returns PlotCollection instead of (Figure, Axes)
Lost scale_factor, lower_quantile, upper_quantile, figsize, ax parameters
Now uses HDI instead of quantiles for uncertainty
Automatic handling of extra dimensions (creates subplots)
Examples
Basic usage with budget optimization results:
allocation_results = mmm.allocate_budget_to_maximize_response( total_budget=100_000, budget_bounds={"lower": 0.5, "upper": 2.0} ) pc = mmm.plot.allocated_contribution_by_channel_over_time( allocation_results ) pc.show()
Custom HDI probability:
pc = mmm.plot.allocated_contribution_by_channel_over_time( allocation_results, hdi_prob=0.94 ) pc.show()
Use different backend:
pc = mmm.plot.allocated_contribution_by_channel_over_time( allocation_results, backend="plotly" ) pc.show()