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, adstock_decay_spec='geometric', enable_aks=False, )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_chainsThe 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_chainsargument for a call towindowed_adaptive_nuts.n_adaptThe number of MCMC draws per chain, during which step size and kernel are adapted. These draws are always excluded. n_burninAn 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=0is sufficient.n_keepThe 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.