Incrementality.contribution_over_spend#
- Incrementality.contribution_over_spend(frequency, start_date=None, end_date=None, include_carryover=True, num_samples=None, random_state=None, central_tendency='median')[source]#
Compute incremental contribution per unit of spend.
Wraps
compute_incremental_contribution()(withcounterfactual_spend_factor=0) and divides by total spend. The interpretation depends on the model’s target variable – e.g. ROAS when the target is revenue, customers per dollar when the target is acquisitions.- Parameters:
- frequency{“original”, “weekly”, “monthly”, “quarterly”, “yearly”, “all_time”}
Time aggregation frequency.
- start_date, end_date
strorpd.Timestamp, optional Date range for computation.
- include_carryoverbool, default=True
Include adstock carryover effects.
- num_samples
intorNone, optional Number of posterior samples to use. If None, all samples are used.
- random_state
RandomStateorGeneratororNone, optional Random state for reproducible subsampling.
- central_tendency{“median”, “mean”}, default=”median”
Central tendency of the counterfactual predictions. Only meaningful for non-linear links; see
compute_incremental_contribution().
- Returns:
xr.DataArrayContribution per unit spend with dimensions
(chain, draw, date, channel, *custom_dims). Zero spend results in NaN for that channel/period.
- Raises:
ValueErrorIf
frequencyis invalid, the requested dates fall outside the fitted data range, orcentral_tendencyis not"median"or"mean"; or, at compute time, if amu_effect’s declared reach is narrower than what was measured, or a post-fit mutation of an auxiliary input (e.g.MMM.sample_posterior_predictive(..., clone_model=False)) is detected; or if the model produces non-finite predictions. Seespend_reachfor the full story on each.NotImplementedErrorIf the model’s link function has no
IncrementalReducer, if a channel-dependentmu_effecthas not opted in viaincrementality_spec(), or if the accounted nodes do not reproduce the full move in the linear predictor.
- Warns:
UserWarningIf a spend counterfactual’s reach could not be measured (no interior date could be probed), the evaluation falls back to the full date axis, which is correct but slower than a window, and the completeness check above is skipped for lack of anything to compare. See
measure().
Examples
>>> roas = mmm.incrementality.contribution_over_spend( ... frequency="quarterly", ... start_date="2024-01-01", ... end_date="2024-12-31", ... )