IndependentSigmas#
- class pymc_marketing.special_priors.IndependentSigmas(priors, dims=None)[source]#
One independent prior per level, for the scales of a
NestedZeroSumPrior.- Parameters:
priors (
dict[str,Any]) – The prior of each level’s scale, keyed by the term and interaction labels of theNestedZeroSumPriorthat uses it. Each prior must be a scalar (no dims). Level<level>of a prior named<name>creates<name>_sigma_<level>, and the levels are stacked into the vector<name>_sigmaon the dim<name>_sigma_level; on the saturationbeta, those aresaturation_beta_sigma_<level>andsaturation_beta_sigma.dims (
str|tuple[str,...] |None) – The level dim, whose model coord gives the levels and their order. Leave it unset in aNestedZeroSumPrior, which sets it on a copy.
Notes
A pymc_extras
VariableFactory:create_variable()returns one vector over the level dim, like aPriorwith that dim, so it can also be a parameter of aPrior.Examples
Use it as the
sigmaof aNestedZeroSumPrioron the saturationbetaof an MMM with dims("brand",):from pymc_extras.prior import Prior from pymc_marketing.mmm import GeometricAdstock, LogisticSaturation from pymc_marketing.mmm.mmm import MMM from pymc_marketing.special_priors import ( IndependentSigmas, NestedZeroSumPrior, Term, ) beta = NestedZeroSumPrior( mu=Prior("Normal", mu=0, sigma=0.5, dims="channel"), terms={"brand": Term()}, sigma=IndependentSigmas(priors={"brand": Prior("HalfNormal", sigma=0.2)}), ) mmm = MMM( date_column="date", channel_columns=["c0", "c1"], target_column="y", dims=("brand",), adstock=GeometricAdstock(l_max=4), saturation=LogisticSaturation(priors={"beta": beta}), )
The same prior in a YAML config for
build_mmm_from_yaml():saturation: class: pymc_marketing.mmm.LogisticSaturation kwargs: priors: beta: class: pymc_marketing.special_priors.NestedZeroSumPrior kwargs: mu: {distribution: Normal, mu: 0, sigma: 0.5, dims: channel} terms: brand: {} sigma: class: pymc_marketing.special_priors.IndependentSigmas kwargs: priors: brand: {distribution: HalfNormal, sigma: 0.2}
Methods
IndependentSigmas.__init__(priors[, dims])IndependentSigmas.create_variable(name[, xdist])Create one scalar scale per level, stacked into one vector.
Deserialize from a dictionary created by
to_dict().IndependentSigmas.to_dict([_orig])Attributes