The standard Meridian model is a geo-level hierarchical model with
non-linear parametric transformations on the media variables. Random
coefficients account for heterogeneity across geographical regions.

We recommend using geo-level data as it provides more reliable estimation. A
national model, essentially a single-geo model, is available for cases where
geo-level data is unavailable. See [National-level modeling](https://developers.google.com/meridian/docs/advanced-modeling/national-models)
for more details.

The Meridian model is an extension of Bayesian models previously
proposed ([Jin et al.
2017](https://research.google/pubs/bayesian-methods-for-media-mix-modeling-with-carryover-and-shape-effects/)
and [Sun et al. 2017](https://research.google/pubs/geo-level-bayesian-hierarchical-media-mix-modeling/)).
Extensions include the use of reach and frequency data ([Zhang et al.
2023](https://research.google/pubs/bayesian-hierarchical-media-mix-model-incorporating-reach-and-frequency-data/)), the inclusion of time-varying intercept terms to model trend and seasonality
(related to trend and seasonality modeling by [Ng et al.
2021](https://arxiv.org/abs/2106.03322)) and the addition of non-media
treatments and organic media variables.

The model is represented as follows:
$$ \\begin{align\*} y_{g,t} = \\mu_t + \\tau_g \&+ \\sum\\limits_{i=1}\^{N_{C}} \\gamma\^{\[C\]}_{g,i} z_{g,t,i} \\\\ \&+ \\sum\\limits_{i=1}\^{N_N} \\gamma\^{\[N\]}_{g,i} x\^{\[N\]}_{g,t,i} \\\\ \&+ \\sum\\limits_{i=1}\^{N_M} \\beta\^{\[M\]}_{g,i} HillAdstock \\left( \\left\\{ x\^{\[M\]}_{g,t-s,i} \\right\\}\^L_{s=0}\\ ;\\ \\alpha\^{\[M\]}_i, ec\^{\[M\]}_i, \\ slope\^{\[M\]}_i \\right) \\\\ \&+ \\sum\\limits_{i=1}\^{N_{OM}} \\beta\^{\[OM\]}_{g,i} HillAdstock \\left( \\left\\{ x\^{\[OM\]}_{g,t-s,i} \\right\\}\^L_{s=0}\\ ;\\ \\alpha\^{\[OM\]}_i, ec\^{\[OM\]}_{i}, \\ slope\^{\[OM\]}_{i} \\right) \\\\ \&+ \\sum\\limits_{i=1}\^{N_{RF}} \\beta\^{\[RF\]}_{g,i} Adstock \\left( \\left\\{ r\^{\[RF\]}_{g,t-s,i} \\cdot Hill \\left( f\^{\[RF\]}_{g,t-s,i};\\ ec\^{\[RF\]}_{i},\\ slope\^{\[RF\]}_{i} \\right) \\right\\}\^L_{s=0}\\ ;\\ \\alpha\^{\[RF\]}_{i} \\right) \\\\ \&+ \\sum\\limits_{i=1}\^{N_{ORF}} \\beta\^{\[ORF\]}_{g,i} Adstock \\left( \\left\\{ r\^{\[ORF\]}_{g,t-s,i} \\cdot Hill \\left( f\^{\[ORF\]}_{g,t-s,i};\\ ec\^{\[ORF\]}_{i},\\ slope\^{\[ORF\]}_{i} \\right) \\right\\}\^L_{s=0}\\ ;\\ \\alpha\^{\[ORF\]}_{i} \\right) \\\\ \&+ \\epsilon_{g,t} \\end{align\*} $$

> [!NOTE]
> **Note:** If you are unfamiliar with the specific Greek letters, subscripts, or functions used in this equation, refer to the [Mathematical notation reference](https://developers.google.com/meridian/docs/basics/math-notation) for a complete breakdown of each symbol.

## Basic details

The basic details are:

- Index variables, as defined in [Input
  data](https://developers.google.com/meridian/docs/advanced-modeling/input-data):

  - \\(g=1,\\ldots,G\\) indexes the geographical units
  - \\(t=1,\\ldots,T\\) indexes the time units
  - \\(i=1,\\ldots,N_C\\) indexes the control variables
  - \\(i=1,\\ldots,N_N\\) indexes the non-media treatments
  - \\(i=1,\\ldots,N_M\\) indexes the paid media channels *without* reach and frequency data
  - \\(i=1,\\ldots, N_{OM}\\) indexes the organic media channels *without* reach and frequency data
  - \\(i=1,\\ldots,N_{RF}\\) indexes the paid media channels *with* reach and frequency data
  - \\(i=1,\\ldots, N_{ORF}\\) indexes the organic media channels *with* reach and frequency data
- \\(\\tau_b = 0\\) for identifiability for some baseline geo \\(b\\). Any geo
  can be set as the baseline using the `baseline_group` argument.

- \\(\\{q_{t-s}\\}\^L_{s=0}\\) denotes the vector
  \\((q_t, q_{t-1}, \\ldots, q_{t-L})\\).
  This notation is used to denote Adstock function input values.

- The integer value \\(L\\) is the media maximum lag duration, such as the
  maximum media effect duration. This parameter can be set using the `max_lag`
  argument.

- Note the following about the \\(\\text{Hill}()\\) and \\(\\text{Adstock}()\\)
  functions. For more information, see [Media saturation and lagging](https://developers.google.com/meridian/docs/advanced-modeling/media-saturation-lagging)
  and [Set the adstock_decay_spec parameter](https://developers.google.com/meridian/docs/advanced-modeling/set-adstock-decay-spec-parameter).

  $$ \\text{Adstock} \\left( \\left\\{ q_{t-s} \\right\\}\^L_{s=0},\\ \\alpha \\right) = \\dfrac{\\sum\\limits\^{L}_{s=0}\\ w(s; \\alpha) q_{t-s} }{\\sum\\limits\^L_{s=0}\\ w(s; \\alpha)} $$

  Where:
  - \\(q\>0\\)
  - \\(w(s; \\alpha) \\) is the [decay parameterization](https://developers.google.com/meridian/docs/advanced-modeling/set-adstock-decay-spec-parameter)
  - \\(\\alpha\\ \\in\\ \[0, 1\]\\) is the decay parameter.

  $$ \\text{Hill} \\left( q, ec, \\text{slope} \\right) = \\left( 1 + \\left( \\dfrac{q}{ec} \\right)\^{- \\text{slope} } \\right)\^{-1} $$

  Where:
  - \\(q\>0,\\ ec\>0,\\ \\text{slope} \> 0\\)
  - \\(ec, \\text{slope}\\) are Hill function shape and slope parameters.
- The \\(\\text{HillAdstock}()\\) function depends on the `hill_before_adstock`
  argument.

  - If the default `hill_before_adstock = False`, then \\(\\text{HillAdstock}(q;\\ \\alpha, ec, \\text{slope}) = \\text{Hill}(\\text{Adstock}(q;\\ \\alpha);\\ ec, \\text{slope})\\)
  - If `hill_before_adstock = True`, then \\(\\text{HillAdstock}(q;\\ \\alpha, ec, \\text{slope}) = \\text{Adstock}(\\text{Hill}(q;\\ ec, \\text{slope}); \\alpha)\\)

## \\( \\mu_t \\) parameters

The \\(\\mu_t\\) parameters are time-varying intercepts that contribute a trend
and seasonality component to the model:

- \\(\\mu_t\\) are determined by a series of `knot` parameters
  \\(b_1,b_2,\\dots,b_K\\) located at corresponding time points
  \\(s_1,s_2,\\dots,s_K\\).

- The time points $s_1,\\dots,s_K$ are located between \\(1\\) and \\(T\\) and
  are specified by the `knots` argument.

  - You can specify a list of knot locations, or just the number of knots.

  - If the number of knots is specified, then knots are evenly spaced with
    two of the knots at the endpoints ($s_1=1$ and $s_K=T$).

  - When there are multiple geos (\\(G\>1\\)), the default places a knot at
    each time point ($s_1=1,s_2=2,\\dots,s_K=T$, where $K=T$).

  - When \\(G=1\\) (such as a national-level model), the default is a single
    knot, which is effectively a common intercept across all time periods.

- The \\(\\mu_t\\) values are a weighted average of the two closest neighboring
  knots, with more weight given to the closer knot. (For example, say there
  are knots at time 9 and time 18. The estimate for $\\mu_{16}$ will be
  influenced by both the knot at time 9 and the knot at time 18, with more
  weight given to the knot at time 18.) The precise weight calculation is as
  follows. For any \\(t\\), define the following:

  - $\\ell(t)$ and $u(t)$ represent the knot indices of the nearest neighboring
    knots. Usually $\\ell(t) \< u(t)$, but note that $\\ell(t) = u(t)$ if $t$ is
    precisely one of the knot locations, or if $t$ is before the first knot or
    after the last knot (as can be the case when custom knot locations are set,
    or if only one knot is used).

    - \\(\\ell(t) = \\max \\{\\{1\\} \\cup \\{k: s_k \\leq t\\}\\}\\)

      - Note: $\\ell(t) = 1$ if $t \< s_1$.
    - \\(u(t) = \\min \\{\\{K\\} \\cup \\{k: s_k \> t\\}\\}\\)

      - Note: $u(t) = K$ if $t \> s_K$.
  - \\(w(t) = 1\\) if \\(\\ell(t) = u(t)\\) ; otherwise
    \\(w(t) = \\dfrac{s_{u(t)}-t}{s_{u(t)}-s_{\\ell(t)}}\\).

  - \\(\\mu_t = w(t)b_{\\ell(t)} + (1-w(t))b_{u(t)}\\)

- The knot values \\(b_1,b_2,\\dots,b_K\\) have a user-specified prior
  distribution.

This methodology is based on [Bayesian Time Varying Coefficient Model with
Applications to Marketing Mix Modeling](https://arxiv.org/abs/2106.03322), with
key distinctions, including a different weight function, distinct priors,
the absence of autoregression, and other differences.

For more information about setting knots, see [How the `knots` argument
works](https://developers.google.com/meridian/docs/advanced-modeling/setting-knots#how-knots-argument-works).

## Other parameter distributions

Other parameter distributions are as follows:

- Note that here Meridian parameterizes the Normal distribution in
  terms of its mean and standard deviation.

  - \\(\\gamma_{g,i}\^{\[C\]} \\sim \\text{Normal}(\\gamma_i\^{\[C\]},\\xi_i\^{\[C\]})\\)
  - \\(\\gamma_{g,i}\^{\[N\]} \\sim \\text{Normal}(\\gamma_i\^{\[N\]},\\xi_i\^{\[N\]})\\)
- The \\(\\beta\\) distributions depend on the `media_effects_dist`
  argument, as follows:

  - \\(log(\\beta_{g,i}\^{\[M\]})\\sim \\text{Normal}( \\beta_i\^{\[M\]},\\eta_i\^{\[M\]})\\)
  - \\(log(\\beta_{g,i}\^{\[OM\]})\\sim \\text{Normal}( \\beta_{i}\^{\[OM\]},\\eta_{i}\^{\[OM\]})\\)
  - \\(log(\\beta_{g,i}\^{\[RF\]})\\sim \\text{Normal}( \\beta_{i}\^{\[RF\]},\\eta_{i}\^{\[RF\]})\\)
  - \\(log(\\beta_{g,i}\^{\[ORF\]})\\sim \\text{Normal}(
    \\beta_{i}\^{\[ORF\]},\\eta_{i}\^{\[ORF\]})\\)

    if `media_effects_dist = LOG_NORMAL`
  - \\(\\beta_{g,i}\^{\[M\]} \\sim \\text{Normal}(
    \\beta_i\^{\[M\]},\\eta_i\^{\[M\]})\\)

  - \\(\\beta_{g,i}\^{\[OM\]} \\sim \\text{Normal}(
    \\beta_{i}\^{\[OM\]},\\eta_{i}\^{\[OM\]})\\)

  - \\(\\beta_{g,i}\^{\[RF\]} \\sim \\text{Normal}(
    \\beta_{i}\^{\[RF\]},\\eta_{i}\^{\[RF\]})\\)

  - \\(\\beta_{g,i}\^{\[ORF\]} \\sim \\text{Normal}(
    \\beta_{i}\^{\[ORF\]},\\eta_{i}\^{\[ORF\]})\\)

    if `media_effects_dist = NORMAL`
- \\(\\epsilon_{g,t}\\sim \\text{Normal}(0,\\sigma_g)\\):

  - The residuals are independent of each other, all media and control
    variables, and all model parameters.

  - If `unique_sigma_for_each_geo = False` (which is the default), then
    \\(\\sigma_1=\\sigma_2=\\cdots=\\sigma_G=\\sigma\\).

- The remaining parameters all have user-specified prior distributions:

  \\(
  \\{\\gamma_i\^{\[C\]}\\}, \\{\\gamma_i\^{\[N\]}\\},
  \\{\\xi_i\^{\[C\]}\\}, \\{\\xi_i\^{\[N\]}\\},
  \\)

  \\(
  \\{\\beta_i\^{\[M\]}\\}, \\{ \\beta_{i}\^{\[OM\]} \\},
  \\{ \\beta_{i}\^{\[RF\]} \\}, \\{ \\beta_{i}\^{\[ORF\]} \\},
  \\)

  \\(
  \\{\\eta_i\^{\[M\]}\\}, \\{ \\eta_{i}\^{\[OM\]} \\},
  \\{\\eta_{i}\^{\[RF\]}\\}, \\{ \\eta_{i}\^{\[ORF\]} \\},
  \\)

  \\(
  \\{\\alpha_i\^{\[M\]}\\}, \\{ \\alpha_{i}\^{\[OM\]} \\},
  \\{\\alpha_{i}\^{\[RF\]}\\}, \\{ \\alpha_{i}\^{\[ORF\]} \\},
  \\)

  \\(
  \\{ec_i\^{\[M\]}\\}, \\{ ec_{i}\^{\[OM\]} \\},
  \\{ec_{i}\^{\[RF\]}\\}, \\{ ec_{i}\^{\[ORF\]} \\},
  \\)

  \\(
  \\{slope_i\^{\[M\]}\\}, \\{ slope_{i}\^{\[OM\]} \\},
  \\{slope_{i}\^{\[RF\]}\\}, \\{ slope_{i}\^{\[ORF\]} \\},
  \\)

  \\(
  \\{\\tau_g\\}, \\{\\sigma_g\\}.
  \\)

You can change some aspects of the model specification, based on modeling
options covered in the following sections:
[Media saturation and lagging](https://developers.google.com/meridian/docs/advanced-modeling/media-saturation-lagging),
[Reach and frequency](https://developers.google.com/meridian/docs/basics/reach-frequency),
[Paid search](https://developers.google.com/meridian/docs/advanced-modeling/paid-search-modeling),
[Calibrate treatment priors](https://developers.google.com/meridian/docs/advanced-modeling/roi-priors-and-calibration),
[Set the adstock_decay_spec parameter](https://developers.google.com/meridian/docs/advanced-modeling/set-adstock-decay-spec-parameter),
[Set the max_lag parameter](https://developers.google.com/meridian/docs/advanced-modeling/set-max-lag-parameter),
[Set knots](https://developers.google.com/meridian/docs/advanced-modeling/setting-knots),
and
[Prevent a negative baseline](https://developers.google.com/meridian/docs/advanced-modeling/prevent-negative-baseline).
You can also customize the
[default prior distributions](https://developers.google.com/meridian/docs/advanced-modeling/default-prior-distributions).