incrementality#

Incrementality and counterfactual analysis for Marketing Mix Models.

This module provides functionality to compute incremental channel contributions using counterfactual analysis, properly accounting for adstock carryover effects.

Concept#

Incrementality measures the causal impact of a marketing channel by comparing two scenarios:

  1. Actual: the model prediction with real spend data.

  2. Counterfactual: the model prediction with spend removed or perturbed.

The difference between these two predictions is the incremental contribution of that channel. Because MMMs include adstock transformations, spend at time t affects outcomes at t, t + 1, …, t + l_max. A naïve element-wise comparison ignores this temporal attribution; this module handles it correctly by extending the evaluation window to capture both carry-in and carry-out effects.

Total incrementality (zero-out counterfactual):

\[\Delta Y_m = \sum_{t=t_0}^{t_1 + L - 1} \bigl[\hat{Y}_t(x;\,\Omega) - \hat{Y}_t(x^{\text{cf}};\,\Omega)\bigr]\]

where the counterfactual spend zeroes out only the evaluation period:

\[\begin{split}x^{\text{cf}}_{s,m} = \begin{cases} 0 & s \in [t_0,\, t_1] \\ x_{s,m} & \text{otherwise} \end{cases}\end{split}\]

Marginal incrementality (small perturbation):

\[\delta Y_m = \sum_{t=t_0}^{t_1 + L - 1} \bigl[\hat{Y}_t(\tilde{x};\,\Omega) - \hat{Y}_t(x;\,\Omega)\bigr]\]

where the perturbed spend scales only the evaluation period:

\[\begin{split}\tilde{x}_{s,m} = \begin{cases} \alpha\, x_{s,m} & s \in [t_0,\, t_1] \\ x_{s,m} & \text{otherwise} \end{cases}\end{split}\]

Here m is the channel, x the spend vector, L the adstock window length (l_max), Ω the posterior parameter samples, and α the counterfactual_spend_factor. Spend outside \([t_0, t_1]\) is always kept at its actual value so that adstock carry-in is correctly accounted for.

Incrementality is a general-purpose building block. Dividing incremental contribution by spend gives ROAS (Return on Ad Spend) when the model’s target variable is revenue; taking the reciprocal (spend / contribution) gives CAC (Customer Acquisition Cost) when the target is customer count. The same logic applies to any target variable.

Examples#

Compute quarterly incremental contributions:

incremental = mmm.incrementality.compute_incremental_contribution(
    frequency="quarterly",
    period_start="2024-01-01",
    period_end="2024-12-31",
)

Compute quarterly ROAS (when target variable is revenue):

roas = mmm.incrementality.contribution_over_spend(
    frequency="quarterly",
    period_start="2024-01-01",
    period_end="2024-12-31",
)

Compute monthly CAC (when target variable is customer count):

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

Compute marginal ROAS (return on next dollar):

mroas = mmm.incrementality.marginal_contribution_over_spend(
    frequency="quarterly",
)

References#

Google MMM Paper: https://storage.googleapis.com/gweb-research2023-media/pubtools/3806.pdf

Classes

Incrementality(model, idata)

Incrementality and counterfactual analysis for MMM models.