Incrementality#

class pymc_marketing.mmm.incrementality.Incrementality(model, idata=None, data=None)[source]#

Incrementality and counterfactual analysis for MMM models.

Computes incremental channel contributions by comparing predictions with actual spend vs. counterfactual (perturbed) spend, accounting for adstock carryover effects. See the module docstring for the full mathematical formulation and design rationale.

Parameters:
  • model (MMM) – Fitted MMM model instance. Its frozen_deterministics property decides which deterministics are held at their posterior values during counterfactual evaluation.

  • idata (DataTree | None) – DataTree containing posterior samples and fit data. Exactly one of idata and data must be provided.

  • data (MMMIDataWrapper | None) – Existing data wrapper to reuse instead of building one from idata.

Attributes:
modelMMM

The fitted model whose graph the counterfactuals are evaluated on.

idataxr.DataTree

Posterior samples and fit data.

dataMMMIDataWrapper

Data wrapper for accessing model data.

Raises:

ValueError – If both idata and data are provided, or neither is; or if the idata coordinates do not match the fitted model’s.

Notes

Computation reuses compiled evaluators cached on the fitted model, so repeated calls do not recompile. A call leases the evaluator it uses and returns it when it finishes, so concurrent calls on one model each hold their own evaluator – a call that finds the cache empty compiles one – rather than sharing the draws it is rebound to. An in-place edit of idata.constant_data while an instance is held is not detected by that instance; a fresh mmm.incrementality sees it.

Examples

>>> incr = mmm.incrementality
>>> roas = incr.contribution_over_spend(frequency="quarterly")
>>> cac = incr.spend_over_contribution(frequency="monthly")

Methods

Incrementality.__init__(model[, idata, data])

Incrementality.compute_incremental_contribution(...)

Compute incremental channel contributions using counterfactual analysis.

Incrementality.compute_joint_incremental_contribution(...)

Compute the incremental contribution of all channels together.

Incrementality.contribution_over_spend(frequency)

Compute incremental contribution per unit of spend.

Incrementality.marginal_contribution_over_spend(...)

Compute marginal contribution per additional unit of spend.

Incrementality.spend_over_contribution(frequency)

Compute spend per unit of incremental contribution.

Incrementality.split_incremental_contribution_current_future(...)

Split each period's incremental contribution into current and future.

Incrementality.split_incremental_contribution_over_time(...)

Split each period's incremental contribution by when it lands.