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 docstringfor the full mathematical formulation and design rationale.- Parameters:
model (
MMM) – Fitted MMM model instance. Itsfrozen_deterministicsproperty decides which deterministics are held at their posterior values during counterfactual evaluation.idata (
DataTree|None) – DataTree containing posterior samples and fit data. Exactly one ofidataanddatamust be provided.data (
MMMIDataWrapper|None) – Existing data wrapper to reuse instead of building one fromidata.
- Attributes:
- model
MMM The fitted model whose graph the counterfactuals are evaluated on.
- idata
xr.DataTree Posterior samples and fit data.
- data
MMMIDataWrapper Data wrapper for accessing model data.
- model
- Raises:
ValueError – If both
idataanddataare 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_datawhile an instance is held is not detected by that instance; a freshmmm.incrementalitysees 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])Compute incremental channel contributions using counterfactual analysis.
Compute the incremental contribution of all channels together.
Incrementality.contribution_over_spend(frequency)Compute incremental contribution per unit of 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.