Incrementality.spend_over_contribution#

Incrementality.spend_over_contribution(frequency, start_date=None, end_date=None, include_carryover=True, num_samples=None, random_state=None, central_tendency='median')[source]#

Compute spend per unit of incremental contribution.

Reciprocal of contribution_over_spend(). The interpretation depends on the model’s target variable – e.g. CAC (Customer Acquisition Cost) when the target is customer count.

Parameters:
frequency{“original”, “weekly”, “monthly”, “quarterly”, “yearly”, “all_time”}

Time aggregation frequency.

start_date, end_datestr or pd.Timestamp, optional

Date range for computation.

include_carryoverbool, default=True

Include adstock carryover effects.

num_samplesint or None, optional

Number of posterior samples to use. If None, all samples are used.

random_stateRandomState or Generator or None, 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.DataArray

Spend per unit contribution with dimensions (chain, draw, date, channel, *custom_dims). Zero contribution results in Inf; zero spend results in NaN.

Raises:
ValueError, NotImplementedError

Delegates to contribution_over_spend(); see there for the full list.

Warns:
UserWarning

Delegates to contribution_over_spend(); see there for the full-axis fallback warning.

Examples

>>> cac = mmm.incrementality.spend_over_contribution(
...     frequency="monthly",
... )