LogNormalPrior#
- class pymc_marketing.special_priors.LogNormalPrior(dims=None, centered=True, **parameters)[source]#
Lognormal prior parameterized by positive-scale mean and std.
A lognormal prior parameterized by mean and standard deviation on the positive domain, with optional centered or non-centered parameterization.
This prior differs from the standard
LogNormaldistribution, which takes log-scale parameters (mu_log,sigma_log). Instead, it is parameterized directly in terms of the mean and standard deviation (mean,std) on the positive scale, making it more intuitive and suitable for hierarchical modeling.To achieve this, the lognormal parameters are computed internally from the positive-domain parameters:
\[\begin{split}\mu_{\log} &= \ln \left( \frac{\mean^2}{\sqrt{\mean^2 + \std^2}} \right) \\ \sigma_{\log} &= \sqrt{ \ln \left( 1 + \frac{\std^2}{\mean^2} \right) }\end{split}\]where \(\\mean > 0\) and \(\\std > 0\).
The prior is then defined as:
\[\begin{split}\\phi &\\sim \text{LogNormal}(\\mu_{\\log}, \\sigma_{\\log})\end{split}\]This construction ensures that the resulting random variable has approximately the intended mean and variance on the positive scale, even when \(\\mean\) and \(\\std\) are themselves random variables.
- Parameters:
- mean
Prior,float,int, array_like The mean of the distribution on the positive scale.
- std
Prior,float,int, array_like The standard deviation of the distribution on the positive scale.
- dims
tuple[str, …], optional The dimensions of the distribution, by default None.
- centeredbool, optional
Whether to use the centered parameterization, by default True.
- mean
References
Saunders, A positive constrained non-centered prior that sparks joy.
Wikipedia, Log-normal distribution — Definitions.
Examples
Build a non-centered hierarchical model where information is shared across groups:
from pymc_marketing.special_priors import LogNormalPrior prior = LogNormalPrior( mean=Prior("Gamma", mu=1.0, sigma=1.0), std=Prior("HalfNormal", sigma=1.0), dims=("geo",), centered=False, )
Methods
LogNormalPrior.__init__([dims, centered])Create a variable from the prior distribution.
LogNormalPrior.from_dict(data)Create a LogNormalPrior prior from a dictionary.
LogNormalPrior.sample_prior([coords, name])Sample from the prior distribution.
Convert the prior distribution to a dictionary.