[Calibration](https://developers.google.com/meridian/docs/basics/glossary#calibration) is the process of
using experiment results and other domain knowledge to set channel-specific
priors.

Meridian's default priors are moderately informative. Data can be noisy. It's
often helpful to calibrate
[treatment priors](https://developers.google.com/meridian/docs/advanced-modeling/how-to-choose-treatment-prior-types),
which allow you to "guide" the model with
your real-world business knowledge---whether that comes from rigorous experiments
or your professional expectations.

Think of a calibrated prior as a "guardrail." It can be tempting to have weak
or no guardrails (in the form of non-informative priors), but this could be
risky, and may lead to poor model results. For more information, see
[Flat Priors and Regularization](https://developers.google.com/meridian/docs/advanced-modeling/intro-priors#flat-priors-and-regularization).

For example, without a reasonably strong prior the model might estimate that a
channel with low spend is driving massive revenue. Calibrating priors helps
guide the model's estimates to a realistic range.

## Formulate your prior beliefs

Calibrating priors isn't a precise calculation; it
combines data with domain knowledge and subjective judgment.

> [!NOTE]
> **Note:** Prior to expressing your beliefs on priors, you will need to choose the business metric to define your belief. [Learn more on how to choose and configure treatment prior
> types](https://developers.google.com/meridian/docs/advanced-modeling/how-to-choose-treatment-prior-types).

After choosing your metric, you can proceed with calibration. When calibrating,
consider the following.

### Use incrementality experiments

Incrementality experiments are perhaps the strongest basis for formulating your
intuition, but translating experiment results into priors isn't a precise
formula.

#### From experiment to prior

There is no single formula to translate an experiment result into a prior. Prior
knowledge in the Bayesian sense is more broadly defined, and doesn't need to be
a formulaic calculation. You could combine different pieces of evidence---such as
results from multiple experiments or other domain knowledge---and their
uncertainties into a single prior distribution, rather than rigidly applying one
experiment's result.

Furthermore, experiments and MMMs often have different estimands and
measurement goals. In other words, they define ROI in different ways.
Experiments are related to the specific conditions of the experiment, such as
the time window, geographic regions, campaign settings. Although experiments
provide highly relevant information, remember that translating them into an MMM
prior involves an additional layer of uncertainty beyond just the experiment's
standard error.

To streamline this workflow, Meridian provides the `CalibrationBuilder`, which
automates the translation of incrementality experiments into calibrated ROI
priors and includes direct integration for [Meridian GeoX](https://developers.google.com/meridian/geox). For
more details on how to calibrate priors from past experiments and account for
differences in spend, recency, and duration, see
[Set custom ROI priors using past experiments](https://developers.google.com/meridian/docs/advanced-modeling/set-custom-priors-past-experiments).

#### Relevance considerations

If using past experiments, carefully consider their relevance. Before using
experiment results to inform priors, ask yourself these questions:

- **Recency**: Was the experiment run before, during, or after the time period covered by your MMM data? Results from a different time period might not be directly applicable.
- **Duration**: Was the experiment long enough to capture the long-term effects of marketing? Short experiments might not be.
- **Media granularity**: Was the experiment measuring media at the same granularity as the MMM? For example, using a campaign-level experiment to calibrate a channel-level MMM.
- **Population differences**: Was the population targeted in the experiment the same as the population considered in the MMM?
- **Complexity**: If the experiment involved a mixture of channels, it might be hard to get clear insights into individual channel performance.
- **Estimand differences**: The MMM counterfactual is zero spend, whereas some experiments might define ROI against a different baseline, such as reduced spend (a non-zero counterfactual). Experiments measuring marginal lift introduce an estimand mismatch with the MMM's zero-spend counterfactual.

#### Automated calibration with Meridian GeoX

Meridian's prior calibration methodology and the [Meridian GeoX](https://developers.google.com/meridian/geox)
experimental framework help address these considerations:

- **Calibration methodology (`CalibrationBuilder`)** : Automatically accounts for **recency** (via adjustments that add uncertainty to older experiments) and **duration** (via adjustments that scale point estimates and inflate uncertainty based on adstock decay carryover). It also applies spend adjustments to account for differences in spend scale and **media granularity** between the experiment and the modeled MMM channel. Additionally, adjustments for **complexity** can be made using the optional user-adjustment arguments. For more details, see [Set custom ROI priors using past experiments](https://developers.google.com/meridian/docs/advanced-modeling/set-custom-priors-past-experiments).
- **Meridian GeoX experimental design** : Supports geographic representativeness (**population differences** ) by employing [stratified sampling](https://developers.google.com/meridian/geox/design-methodology#stratified-sampling) across geographical units to ensure treatment and control groups are representative of the broader geographic population modeled in the MMM.

### Use domain knowledge and intuition

When possible, you can and should use domain
knowledge to inform your priors. Setting priors is about using your intuition to
define a plausible range of values for each marketing channel's performance.
This process relies on a blend of informed judgment, drawing from various
sources such as domain knowledge, previous results, industry benchmarks, and
especially incrementality experiments.

Incrementality experiments are perhaps the strongest basis for formulating your
intuition, but translating experiment results into priors isn't a precise
formula. Even experiments have limitations, and different experiments can yield
different results. Your ROI prior should be a synthesis of all the information
available to you.

If your intuition about a channel's performance is weak, setting a weak prior
(one with a large standard deviation) is acceptable. However, when your
intuition is stronger, incorporating it through priors makes your model more
powerful and less susceptible to noise in the data.

In practice, you almost always have some intuition. For example, you probably
believe that the probability of a causal ROI of 50 is quite low for most
channels. If your company has run many experiments over the years and has never
observed an ROI greater than 6 for a specific channel, then your prior should
reflect this by assigning very low probability to ROI values greater than 6. Use
whatever information you have to inform your priors.

No matter how you set your priors, we always recommend plotting them and
examining their percentiles. Ask yourself if the probabilities align with your
expectations. For example, if 80% of your prior probability distribution is
greater than an ROI of 1.0, does that reflect your prior confidence in the
channel's profitability?

### Use your confidence level to set the prior's standard deviation

Use the strength of your prior belief to inform the standard deviation of the
prior. If you have a strong belief in the effectiveness of a channel---for
example, from multiple experiments with similar ROI point estimates or results
from previous MMMs---you can set a smaller standard deviation for the prior to
indicate strong confidence. Conversely, if you are skeptical about how well an
experiment's results translate to the MMM, you can use a larger standard
deviation to reflect that uncertainty. Remember that priors are not rigid
constraints but rather starting points. If the data presents strong evidence
that contradicts the prior, the model will adjust accordingly; the prior's
standard deviation determines how much weight is given to your initial belief
versus the evidence in the data.

## Code examples

The following examples demonstrate how to set custom ROI priors in Meridian.

### Example: Calibrate ROI priors based on experiments

See
[Set custom ROI priors using past experiments](https://developers.google.com/meridian/docs/advanced-modeling/set-custom-priors-past-experiments)
for how to calibrate ROI priors based on experiment results.

### Example: Define a lognormal ROI prior

The lognormal distribution is a common distribution to use for an ROI prior.
Meridian provides two helper functions to help you construct lognormal
distributions from prior knowledge:

- [`prior_distribution.lognormal_dist_from_mean_std`](https://developers.google.com/meridian/reference/api/meridian/model/prior_distribution/lognormal_dist_from_mean_std): Constructs a lognormal distribution from a given mean and standard deviation.
- [`prior_distribution.lognormal_dist_from_range`](https://developers.google.com/meridian/reference/api/meridian/model/prior_distribution/lognormal_dist_from_range): Constructs a lognormal distribution where a specified probability mass (such as 95%) falls within a given lower and upper bound.

To construct a `LogNormal` distribution from a mean and standard deviation:

    import numpy as np
    from meridian.model import prior_distribution

    mean = [1.0, 3.0]  # Point estimate
    std = [0.3, 2.0]  # Standard deviation

    # Define the LogNormal distribution
    lognormal_dist = prior_distribution.lognormal_dist_from_mean_std(mean, std)
    # Define the PriorDistribution object
    prior = prior_distribution.PriorDistribution(roi_m=lognormal_dist)

To construct a `LogNormal` distribution from a range:

    import numpy as np
    from meridian.model import prior_distribution

    low = [0.1, 0.5]  # Range lower bound
    high = [2.0, 10.0]  # Range upper bound
    mass_percent = 0.95  # Probability mass

    # Define the LogNormal distribution
    lognormal_dist = prior_distribution.lognormal_dist_from_range(
      low, high, mass_percent=mass_percent
      )
    # Define the PriorDistribution object
    prior = prior_distribution.PriorDistribution(roi_m=lognormal_dist)

It is strongly recommended that you plot and visualize custom priors, especially
ROI priors. This can help you double check if the custom prior aligns with
your prior expectations.

    from matplotlib import pyplot as plt
    from meridian.model import prior_distribution
    import numpy as np

    # Define the LogNormal distribution
    lognormal_dist = prior_distribution.lognormal_dist_from_mean_std(2.0, 0.5)
    # Plot a histogram of samples from the LogNormal distribution
    plt.hist(lognormal_dist.sample(1000))

> [!NOTE]
> **Note:** If the mean you intend to set is near zero, you should consider whether your prior beliefs are accurately represented by a non-negative distribution such as the `LogNormal` distribution. We highly recommend plotting the prior distribution to confirm it matches your prior intuitions before proceeding with the analysis.

## Plot your priors to confirm they match intuition

It is recommended that you plot and visualize custom priors, especially
ROI priors. This helps you double-check if the custom prior aligns with your
expectations before you proceed with the analysis.

## Additional considerations for calibrating treatment priors

This section contains additional considerations for calibrating treatment
priors.

### Consider the ROI calibration period

You can consider using the `roi_calibration` argument in `ModelSpec` if your
prior information is only relevant for a specific time period. However, it's
recommended to set a prior on the full modeling time window whenever possible. All available information, including experiments and domain knowledge,
should be used to set this prior. For more
information, see
[Set the ROI calibration period](https://developers.google.com/meridian/docs/user-guide/configure-model#set-roi-calibration-period).

### Understand prior posterior shifts

Comparing shifts in distributions between the prior and posterior can inform
whether or not the model is learning from the data or being strongly influenced
from the prior you calibrated.

To learn more, check out Prior-Posterior shifts in Meridian's
[Post Modeling Quality Checks](https://developers.google.com/meridian/docs/post-modeling/quality-checks#prior-posterior-shift).