Join the newly launched
Discord community for real-time discussions, peer support, and direct interaction with the Meridian team!
Run the model
Stay organized with collections
Save and categorize content based on your preferences.
When you run the model, you add your model specification, and then run the
commands to sample the prior distribution and the posterior distribution.
Markov Chain Monte Carlo (MCMC) algorithms are used to sample from the posterior
distribution. Meridian uses the
No-U-Turn
sampling method with step size and kernel adaptation.
To run the model:
Add your model specification.
Example:
model_spec = spec.ModelSpec(
prior=prior_distribution.PriorDistribution(),
media_effects_dist='log_normal',
hill_before_adstock=False,
max_lag=8,
unique_sigma_for_each_geo=False,
media_prior_type='roi',
roi_calibration_period=None,
rf_prior_type='coefficient',
rf_roi_calibration_period=None,
organic_media_prior_type='contribution',
organic_rf_prior_type='contribution',
non_media_treatments_prior_type='contribution',
knots=None,
baseline_geo=None,
holdout_id=None,
control_population_scaling_id=None,
)
Run the following commands to sample from the prior and posterior
distribution. Configure the parameters as needed:
meridian = model.Meridian(input_data=data, model_spec=model_spec)
meridian.sample_prior(500)
meridian.sample_posterior(n_chains=7, n_adapt=500, n_burnin=500, n_keep=1000)
Parameter |
Description |
n_chains |
The number of chains to be sampled in parallel. To reduce memory consumption, you can use a list of integers to allow for sequential MCMC sampling calls. Given a list, each element in the sequence corresponds to the n_chains argument for a call to windowed_adaptive_nuts . |
n_adapt |
The number of MCMC draws per chain, during which step size and kernel are adapted. These draws are always excluded. |
n_burnin |
An additional number of MCMC draws, per chain, to be excluded after the step size and kernel are fixed. These additional draws may be needed to ensure that all chains reach the stationary distribution after adaptation is completed, but in practice we often find that the chains reach the stationary distribution during adaptation and that n_burnin=0 is sufficient. |
n_keep |
The number of MCMC draws, per chain, to keep for the model analysis and results. |
Next, run modeling diagnostics to assess convergence, check the distributions,
and assess the model fit.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-11 UTC.
[null,null,["Last updated 2025-06-11 UTC."],[[["\u003cp\u003eThe model requires a defined model specification, which includes parameters like prior distribution, media effects, and other configurations.\u003c/p\u003e\n"],["\u003cp\u003eTo run the model, you first define the model specification and then use the \u003ccode\u003emeridian\u003c/code\u003e object to sample from both the prior and posterior distributions.\u003c/p\u003e\n"],["\u003cp\u003eMarkov Chain Monte Carlo (MCMC) methods are used for sampling from the posterior distribution, utilizing the No-U-Turn sampling method with step size and kernel adaptation.\u003c/p\u003e\n"],["\u003cp\u003eParameters like \u003ccode\u003en_chains\u003c/code\u003e, \u003ccode\u003en_adapt\u003c/code\u003e, \u003ccode\u003en_burnin\u003c/code\u003e, and \u003ccode\u003en_keep\u003c/code\u003e control the MCMC sampling process, determining the number of parallel chains, adaptation draws, burn-in draws, and draws to keep.\u003c/p\u003e\n"]]],["The process involves specifying a model using `ModelSpec`, defining parameters like prior distributions, media effects, and lag. Then, use the `Meridian` class to run the model by sampling from prior and posterior distributions. The posterior sampling employs the No-U-Turn algorithm with step size and kernel adaptation, and requires parameter configuration like `n_chains`, `n_adapt`, `n_burnin`, and `n_keep` to control the Markov Chain Monte Carlo draws. After sampling, you run model diagnostics to assess the quality of the results.\n"],null,["# Run the model\n\nWhen you run the model, you add your model specification, and then run the\ncommands to sample the prior distribution and the posterior distribution.\n\nMarkov Chain Monte Carlo (MCMC) algorithms are used to sample from the posterior\ndistribution. Meridian uses the\n[No-U-Turn](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/mcmc/windowed_adaptive_nuts)\nsampling method with step size and kernel adaptation.\n\nTo run the model:\n\n1. Add your model specification.\n\n **Example:** \n\n model_spec = spec.ModelSpec(\n prior=prior_distribution.PriorDistribution(),\n media_effects_dist='log_normal',\n hill_before_adstock=False,\n max_lag=8,\n unique_sigma_for_each_geo=False,\n media_prior_type='roi',\n roi_calibration_period=None,\n rf_prior_type='coefficient',\n rf_roi_calibration_period=None,\n organic_media_prior_type='contribution',\n organic_rf_prior_type='contribution',\n non_media_treatments_prior_type='contribution',\n knots=None,\n baseline_geo=None,\n holdout_id=None,\n control_population_scaling_id=None,\n )\n\n2. Run the following commands to sample from the prior and posterior\n distribution. Configure the parameters as needed:\n\n meridian = model.Meridian(input_data=data, model_spec=model_spec)\n meridian.sample_prior(500)\n meridian.sample_posterior(n_chains=7, n_adapt=500, n_burnin=500, n_keep=1000)\n\n | Parameter | Description |\n |------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | `n_chains` | The number of chains to be sampled in parallel. To reduce memory consumption, you can use a list of integers to allow for sequential MCMC sampling calls. Given a list, each element in the sequence corresponds to the `n_chains` argument for a call to `windowed_adaptive_nuts`. |\n | `n_adapt` | The number of MCMC draws per chain, during which step size and kernel are adapted. These draws are always excluded. |\n | `n_burnin` | An additional number of MCMC draws, per chain, to be excluded after the step size and kernel are fixed. These additional draws may be needed to ensure that all chains reach the stationary distribution after adaptation is completed, but in practice we often find that the chains reach the stationary distribution during adaptation and that `n_burnin=0` is sufficient. |\n | `n_keep` | The number of MCMC draws, per chain, to keep for the model analysis and results. |\n\nNext, run modeling diagnostics to [assess convergence, check the distributions,\nand assess the model fit](/meridian/docs/user-guide/model-diagnostics)."]]