LogSaturation#

class pymc_marketing.mmm.components.saturation.LogSaturation(priors=None, prefix=None)[source]#

Logarithmic saturation for log-log models.

Applies \(\beta \, \log(1 + x)\) to the raw (unscaled) channel input, mapping spend through a concave logarithmic curve with diminishing returns.

When combined with link="log" in the MMM, the model becomes a log-log specification and \(\beta\) is an approximate elasticity – the percentage change in the response per one percent change in spend. For this interpretation to hold, the channel input must not be rescaled: an elasticity is dimensionless, so dividing spend by an arbitrary channel_scale would change \(\beta\) (because \(\log(1 + x)\) is not invariant under multiplicative rescaling of \(x\)). This class therefore sets requires_unscaled_input to True, which makes the MMM feed raw spend to the saturation and force channel_scale = 1 for the affected channels.

log(1 + x) (rather than log(x)) is used so that the transform is finite at x = 0 – common for paused or cold-start channels – while remaining numerically indistinguishable from log(x) once spend is large, where the elasticity interpretation is exact in the limit \(\partial \log y / \partial \log x \to \beta\).

(Source code, png, hires.png, pdf)

../../_images/pymc_marketing-mmm-components-saturation-LogSaturation-1.png

Methods

LogSaturation.__init__([priors, prefix])

LogSaturation.apply(x, *[, core_dim, idx])

Call within a model context.

LogSaturation.from_dict(data)

Reconstruct a saturation transformation from a dict.

LogSaturation.function(x, beta, *[, dim])

Logarithmic saturation function: beta * log(1 + x).

LogSaturation.plot_curve(curve[, n_samples, ...])

Plot curve HDI and samples.

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

Plot the HDI of the curve.

LogSaturation.plot_curve_samples(curve[, n, ...])

Plot samples from the curve.

LogSaturation.sample_curve([parameters, ...])

Sample the curve of the saturation transformation given parameters.

LogSaturation.sample_prior([coords])

Sample the priors for the transformation.

LogSaturation.set_dims_for_all_priors(dims)

Set the dims for all priors.

LogSaturation.to_dict([_orig])

Convert the transformation to a dictionary.

LogSaturation.update_priors(priors)

Update the priors for a function after initialization.

LogSaturation.with_default_prior_dims(dims)

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

LogSaturation.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.

requires_unscaled_input

Whether the saturation must receive raw (unscaled) channel inputs.

variable_mapping

Mapping from parameter name to variable name in the model.