DelayedAdstock#

class pymc_marketing.mmm.components.adstock.DelayedAdstock(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.'))[source]#

Wrapper around delayed adstock function.

Calls pymc_marketing.mmm.transformers.delayed_adstock() with the wrapper’s l_max, normalize and mode settings.

Parameters:
alphatensor

Retention rate of the ad effect; must be between 0 and 1. Default prior: Prior("Beta", alpha=1, beta=3).

thetatensor

Delay of the peak effect; must be between 0 and l_max - 1. Default prior: Prior("HalfNormal", sigma=1).

.. plot::
context:

close-figs

import matplotlib.pyplot as plt import numpy as np from pymc_marketing.mmm import DelayedAdstock

rng = np.random.default_rng(0)

adstock = DelayedAdstock(l_max=10) prior = adstock.sample_prior(random_seed=rng) curve = adstock.sample_curve(prior) adstock.plot_curve(curve, random_seed=rng) plt.show()

Methods

DelayedAdstock.__init__([l_max, normalize, ...])

DelayedAdstock.apply(x, *[, dims, core_dim, idx])

Call within a model context.

DelayedAdstock.from_dict(data)

Reconstruct an adstock transformation from a dict.

DelayedAdstock.function(x, alpha, theta, *, dim)

Delayed adstock function.

DelayedAdstock.plot_curve(curve[, ...])

Plot curve HDI and samples.

DelayedAdstock.plot_curve_hdi(curve[, ...])

Plot the HDI of the curve.

DelayedAdstock.plot_curve_samples(curve[, ...])

Plot samples from the curve.

DelayedAdstock.sample_curve(parameters[, amount])

Sample the adstock transformation given parameters.

DelayedAdstock.sample_prior([coords])

Sample the priors for the transformation.

DelayedAdstock.set_dims_for_all_priors(dims)

Set the dims for all priors.

DelayedAdstock.to_dict([_orig])

Convert the adstock transformation to a dictionary.

DelayedAdstock.update_priors(priors)

Update the priors for a function after initialization.

DelayedAdstock.with_default_prior_dims(dims)

Return a copy with default prior dims (dims=None) set to dims instead.

DelayedAdstock.with_updated_priors(priors)

Return a copy with updated priors.

Attributes

combined_dims

Get the combined dims for all the parameters.

default_priors

function_priors

Get the priors for the function.

model_config

Mapping from variable name to prior for the model.

prefix

priors

Get the priors for the function.

variable_mapping

Mapping from parameter name to variable name in the model.