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 the NestedZeroSumPrior that 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>_sigma on the dim <name>_sigma_level; on the saturation beta, those are saturation_beta_sigma_<level> and saturation_beta_sigma.

  • dims (str | tuple[str, ...] | None) – The level dim, whose model coord gives the levels and their order. Leave it unset in a NestedZeroSumPrior, which sets it on a copy.

Notes

A pymc_extras VariableFactory: create_variable() returns one vector over the level dim, like a Prior with that dim, so it can also be a parameter of a Prior.

Examples

Use it as the sigma of a NestedZeroSumPrior on the saturation beta of 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.

IndependentSigmas.from_dict(data)

Deserialize from a dictionary created by to_dict().

IndependentSigmas.to_dict([_orig])

Attributes