GeometricAdstock#
- class pymc_marketing.mmm.components.adstock.GeometricAdstock(l_max=FieldInfo(annotation=NoneType, required=True, description='Maximum lag for the adstock transformation.', metadata=[Gt(gt=0)]), normalize=FieldInfo(annotation=NoneType, required=False, default=True, description='Whether to normalize the adstock values.'), mode=FieldInfo(annotation=NoneType, required=False, default=<ConvMode.After: 'After'>, description='Convolution mode.'), priors=FieldInfo(annotation=NoneType, required=False, default=None, description='Priors for the parameters.'), prefix=FieldInfo(annotation=NoneType, required=False, default=None, description='Prefix for the parameters.'), parametrization=FieldInfo(annotation=NoneType, required=False, default=None, description='Whether to parametrize the decay by alpha or half-life.'))[source]#
Wrapper around geometric adstock function.
Calls
pymc_marketing.mmm.transformers.geometric_adstock()with the wrapper’sl_max,normalizeandmodesettings.The decay can be parametrised either by the retention rate
alpha(the default) or by the half-life of the ad effect. Since the weight at lag \(t\) is \(\alpha^{t}\), a half-life \(h\) corresponds to\[\alpha = 0.5^{1 / h}\]which maps any positive half-life into \((0, 1)\) and holds exactly for every
l_maxand either setting ofnormalize. Under the half-life parametrisation the trace will containadstock_halflifeinstead ofadstock_alpha.The two defaults are matched, implying a median
alphaof 0.207 against 0.206. The priors imply a median half-life of 0.44 periods. A custom half-life prior should keep its mass away from zero, where the likelihood goes numerically flat. The adstock functions guide covers both points.- Parameters:
- alpha
tensor Retention rate of the ad effect; must be between 0 and 1. Default prior:
Prior("Beta", alpha=1, beta=3). Only used whenparametrization="alpha".- halflife
tensor Number of time periods after which the ad effect has decayed by half; must be positive. Default prior:
Prior("InverseGamma", alpha=2.6, beta=1). Only used whenparametrization="halflife".- parametrization
str Either
"alpha"or"halflife". When left unset it is inferred from the priors, defaulting to"alpha". Passing a prior for the parameter of the other parametrisation raises aValueError.
- alpha
Examples
Parametrise the decay by its half-life instead of the retention rate:
from pymc_extras.prior import Prior from pymc_marketing.mmm import GeometricAdstock adstock = GeometricAdstock( l_max=10, priors={"halflife": Prior("InverseGamma", alpha=4, beta=2)}, )
(
Source code,png,hires.png,pdf)
Methods
GeometricAdstock.__init__([l_max, ...])GeometricAdstock.apply(x, *[, core_dim, idx])Call within a model context.
Reconstruct a transformation from a dict.
GeometricAdstock.function(x[, alpha, halflife])Geometric adstock function.
GeometricAdstock.plot_curve(curve[, ...])Plot curve HDI and samples.
GeometricAdstock.plot_curve_hdi(curve[, ...])Plot the HDI of the curve.
GeometricAdstock.plot_curve_samples(curve[, ...])Plot samples from the curve.
GeometricAdstock.sample_curve(parameters[, ...])Sample the adstock transformation given parameters.
GeometricAdstock.sample_prior([coords])Sample the priors for the transformation.
Set the dims for all priors.
GeometricAdstock.to_dict([_orig])Convert the adstock transformation to a dictionary.
GeometricAdstock.update_priors(priors)Update the priors for a function after initialization.
Return a copy with default prior dims (dims=None) set to
dimsinstead.Return a copy with updated priors.
Attributes
Get the combined dims for all the parameters.
Get the priors for the function.
Mapping from variable name to prior for the model.
Get the priors for the function.
Mapping from parameter name to variable name in the model.