Roever 2020 - DIRECT Algorithm Implementation and Calibration
Summary
bayesmeta()evaluates the 2-D posterior without MCMC: the marginal of is computed by one-dimensional numerical integration, and the marginal of (and of each and the prediction) is a finite mixture of normals whose support points and weights are chosen by the DIRECT algorithm (Röver and Friede 2017) to bound the Kullback-Leibler divergence by (default 1%). Correctness is verified by simulation-based calibration using probability integral transform (PIT) values.
Overview
The algorithm is only summarised in this paper (details: Röver and Friede 2017, Discrete approximation of a mixture distribution via restricted divergence). This note records what is specified here.
Main Content
Internals (Sec. 2.11)
- The posterior is 2-D; known up to a constant, normal (Eq. 24).
- Joint density = likelihood priors (analytic); -marginal normalised with R’s
integrate(); CDF by numerical integration; quantiles by root-findinguniroot()on the CDF. - -marginal (Eq. 26). The tuning parameters of the DIRECT algorithm are
delta(, bound on divergence) andepsilon(). In the example, 17 components suffice to keep the Kullback-Leibler divergence below ; they are stored in...$support. - Mixture density and CDF are linear combinations of component densities/CDFs; random generation and moments are simple (Seidel 2010; Lindsay 1995). Heavy reliance on
integrate(),uniroot(),optimize(),optim().
Symmetrised divergence between two normals (App. A.4, Eq. 45)
For and :
The DIRECT algorithm uses this to decide how close neighbouring must be. For the shrinkage distributions the maximum divergence across the effect posterior and all shrinkage distributions is used so a single -grid serves all three mixture types.
(The paper’s Eq. 45 is typeset with nested fractions that did not extract cleanly; the closed form above is the standard symmetrised Kullback-Leibler divergence for two normals, which is the quantity the text names.)
Calibration check (App. A.5)
PIT uniformity under correct Bayesian computation (Cook, Gelman and Rubin 2006; Gneiting et al. 2007)
If , and is the posterior CDF at the true value, then exactly for any sample size and any proper prior. Hence uniformity of PIT values over many simulations validates software. Bayesian credible intervals are calibrated on average over the prior (versus frequentist coverage at each parameter value).
Simulation protocol (1000 replicates): , , drawn at random, , ; analyse with matching priors; record pposterior(mu=mu) and pposterior(tau=tau). Fig. 8: empirical CDFs of PIT values for and are in close agreement with the uniform. One-sided 95% credible limits show about 95% empirical coverage. For , a curve above the diagonal reads as conservative (tendency to overestimate heterogeneity); for , a conservative procedure sits below the diagonal at the low end and above at the high end (wider intervals).
Examples
import numpy as np
from scipy import stats
def calibration_check(posterior_cdf_mu, nsim=1000, seed=1):
"""PIT of mu under the prior-generating process of Röver's App. A.5.
posterior_cdf_mu(y, sigma) -> callable F(mu) must be supplied by the analysis under test."""
rng = np.random.default_rng(seed); pit = []
for _ in range(nsim):
mu = rng.normal(0, 4); tau = abs(rng.normal(0, 0.5)); k = rng.choice([2,3,5,10,20])
sigma = rng.uniform(0.2, 1.0, k); y = rng.normal(mu, np.sqrt(sigma**2+tau**2))
pit.append(posterior_cdf_mu(y, sigma)(mu))
return np.array(pit) # should be ~ U(0,1): check with stats.kstest(pit, "uniform")Connections
- Marketing: any in-house Bayesian aggregation tool (a pooled-incrementality model, an MMM prior builder) should be validated this way (prior-predictive data in, PIT uniformity out); see Posterior Sampling and Summarization and the validation cluster in Model Validation and Interpretability - Overview.