IncrementalitySpec#
- class pymc_marketing.mmm.additive_effect.IncrementalitySpec(**data)[source]#
Declaration that an effect may take part in incrementality analysis.
Returned by
MuEffect.incrementality_spec(). Only effects whose contribution depends onchannel_dataneed one: a spend counterfactual cannot reach any other effect, so those are part of the baseline and are left alone.Nothing has to be filled in. An empty
IncrementalitySpec()opts the effect in and letsIncrementalitywork the rest out from the graph: the date-indexedpm.Datathe effect reads is discovered by traversal, and how far in time the effect carries a change in spend is measured by perturbing one date and watching where the contribution moves. The fields below override that measurement when a caller would rather state the answer than have it derived.- Parameters:
- additional_carryover_lags
int, optional Number of periods beyond the model’s own
adstock.l_maxover which a change in spend at time t can still move this effect’s contribution. For an effect that chains a second adstock behind the model’s – as a funnel mediator does, withupper_transformfeedingdemand_transform– it is thel_maxof that second adstock. Left atNoneit is measured. A declared value is allowed to be larger than the measured reach (a wider window only costs compute) but a smaller one is rejected, since it would silently truncate the mediated tail and understate the increment.- evaluation_mode{“auto”, “window”, “full”}, default=”auto”
How much of the date axis the effect needs to see to be evaluated correctly.
"window"is the cheap case: the effect propagates spend forward over a bounded number of periods, so a counterfactual can be evaluated on a window around each period."full"is required by an effect that reads the whole series at once – anything with a reduction overdate, such as a normalisation byx.mean("date")– because such an effect takes a different value on a truncated axis."auto"measures which of the two applies.
- additional_carryover_lags
Examples
Opt in and let everything be measured:
class FunnelEffect(DataVarMuEffect): def incrementality_spec(self) -> IncrementalitySpec: return IncrementalitySpec()
Declare the carryover instead, for a funnel whose mediator applies a second adstock of
l_max=8:class FunnelEffect(DataVarMuEffect): def incrementality_spec(self) -> IncrementalitySpec: return IncrementalitySpec( additional_carryover_lags=self.demand_transform.adstock.l_max )
Methods
IncrementalitySpec.__init__(**data)Create a new model by parsing and validating input data from keyword arguments.
IncrementalitySpec.construct([_fields_set])IncrementalitySpec.copy(*[, include, ...])Returns a copy of the model.
IncrementalitySpec.dict(*[, include, ...])IncrementalitySpec.json(*[, include, ...])Compute the class name for parametrizations of generic classes.
IncrementalitySpec.parse_file(path, *[, ...])IncrementalitySpec.parse_raw(b, *[, ...])IncrementalitySpec.schema([by_alias, ...])IncrementalitySpec.schema_json(*[, ...])IncrementalitySpec.update_forward_refs(**localns)IncrementalitySpec.validate(value)Attributes
model_computed_fieldsmodel_configConfiguration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].model_extraGet extra fields set during validation.
model_fieldsmodel_fields_setReturns the set of fields that have been explicitly set on this model instance.
additional_carryover_lagsevaluation_mode