Source-linked AI summary

bridgesampling: An R Package for Estimating Normalizing Constants

Quentin F. Gronau, Henrik Singmann, Eric-Jan Wagenmakers

arXiv:1710.08162v3stat.CO

TL;DR

Marginal likelihoods are needed for Bayesian model comparison and model averaging but are often difficult to compute because they involve analytically intractable high-dimensional integrals. The paper introduces an R package that estimates normalizing constants through bridge sampling, with automatic computation for suitable Stan models. In a Bayesian t-test example, the estimated Bayes factor closely matches the reference value BF10 = 17.259.

  • Problem

    Marginal likelihoods required for Bayes factor model selection and Bayesian model averaging are often high-dimensional integrals that cannot be solved analytically.

  • Method

    The bridgesampling R package uses bridge sampling to estimate marginal likelihoods and other normalizing constants from posterior samples and model-density information, with a simplified Stan interface.

  • Results

    BF10 = 17.259, and the bridgesampling estimate closely matches the Bayes factor obtained with the BayesFactor package.

  • Takeaways & Limitations

    The package provides a generic, user-friendly way to conduct Bayesian model comparisons and obtain marginal likelihood estimates.

  • Takeaways & Limitations

    Bridge sampling may not be ideal for nested models or very large model spaces, where Savage-Dickey or Reversible Jump MCMC may be faster or more appropriate.

Abstract

from arXiv · show

Statistical procedures such as Bayes factor model selection and Bayesian model averaging require the computation of normalizing constants (e.g., marginal likelihoods). These normalizing constants are notoriously difficult to obtain, as they usually involve high-dimensional integrals that cannot be solved analytically. Here we introduce an R package that uses bridge sampling (Meng & Wong, 1996; Meng & Schilling, 2002) to estimate normalizing constants in a generic and easy-to-use fashion. For models implemented in Stan, the estimation procedure is automatic. We illustrate the functionality of the package with three examples.

1. Introduction

The section motivates bridge sampling by explaining why marginal likelihoods are important yet difficult to compute, then introduces an R package that makes their estimation generic and user-friendly.

  • Marginal likelihoods are essential for Bayes factor comparisons and Bayesian model averaging because they determine posterior model probabilities and data-induced changes in model odds.
  • For complicated models such as hierarchical models, marginal likelihoods are high-dimensional integrals that usually cannot be solved analytically.
  • Existing normalizing-constant estimators differ in accuracy, speed, implementation complexity, and generality, motivating methods that are fast, accurate, easy to implement, general, and unsupervised.
  • Bridge sampling is presented as accurate in high-dimensional parameter spaces, while naive Monte Carlo, generalized harmonic mean, and importance sampling are special sub-optimal cases of its bridge identity.
  • The bridgesampling R package estimates marginal likelihoods and normalizing constants using posterior samples, an unnormalized log-posterior function, data, and parameter bounds.
  • The package produces an estimate of the log marginal likelihood and supports posterior model probabilities, Bayes factors, and approximate estimation errors through dedicated functions.
  • The bridge_sampler function accepts multiple posterior-sample object classes, including Stan, JAGS, and nimble outputs, so users need not program their own MCMC routines.
  • For Stan models that retain constants, passing the stanfit object alone enables an unsupervised, black-box computation of the marginal likelihood.

2. Bridge sampling: the algorithm

Bridge sampling estimates a normalizing constant by combining posterior and proposal samples through an optimally chosen bridge function and iterative updating. The package offers multivariate-normal and Warp-III proposal strategies, with transformations for constrained parameters and parallelizable evaluations.

  • Bridge sampling algorithm: Bridge sampling combines samples from posterior and proposal distributions, generalizing naive Monte Carlo, generalized harmonic mean, and importance sampling estimators.The simpler estimators use one distribution, whereas bridge sampling uses two, although particular bridge-function and proposal choices recover those special cases.
  • Bridge sampling algorithm: Posterior samples and proposal samples enter the bridge estimator separately, with the package evaluating their log-density terms l1,i and l2,j in parallel.These evaluations do not depend sequentially on one another, and parallel execution is enabled through the cores argument.
  • Bridge sampling algorithm: The package uses Meng and Wong’s optimal bridge function, which minimizes the estimator’s relative mean-squared error, followed by iterative marginal-likelihood updates.The iterative scheme typically converges within a few iterations.
  • Option I: the multivariate normal proposal distribution: The normal method fits a multivariate normal proposal whose mean vector and covariance matrix match the posterior samples, accounting for posterior correlations.It is the default method and assumes parameters can range over the entire real line, possibly after transformation.
  • Option I: the multivariate normal proposal distribution: Diffeomorphic transformations map constrained parameters to the real line while retaining the posterior normalizing constant through the Jacobian adjustment.Built-in transformations cover unbounded, lower-bounded, upper-bounded, and jointly lower- and upper-bounded parameters.
  • Option II: warping the posterior distribution: Warp bridge sampling fixes the proposal as a standard multivariate normal and warps the posterior while preserving its normalizing constant.Warp-III matches the posterior and proposal’s first three moments, including skewness, unlike the normal method’s mean and covariance matching.

3. Toy example: Bayesian t-test

The toy example uses a Bayesian paired-samples t-test to compare two drugs’ effects on sleep for ten patients, estimating marginal likelihoods with bridge sampling and then computing a Bayes factor. The alternative is strongly favored, with an estimated Bayes factor of 17.26001 and a small approximate percentage error of 0.087%.

  • Data and hypotheses: The sleep data contain paired measurements from ten patients who received two soporific drugs, with the dependent measure being hours of sleep gained over control.Difference scores are formed from the two drug conditions for Bayesian model comparison.
  • Data and hypotheses: The null model fixes the standardized effect size δ to zero, whereas the alternative estimates δ with a zero-centered Cauchy prior and models difference scores with mean σδ.The alternative also assigns Jeffreys’s prior to the variance σ^2.
  • Bridge-sampling workflow: The estimated log marginal likelihood for H1 is -27.17103, obtained in five iterations using the default normal bridge-sampling method.The package provides error estimates through error_measures and its summary method.
  • Results: The marginal-likelihood estimate has a relative mean-squared error of 7.564225e-07, coefficient of variation 0.0008697255, and approximate percentage error 0.087%.The reported error measures are approximate.
  • Results: The estimated Bayes factor for H1 over H0 is 17.26001, closely matching the BayesFactor package’s BF10 = 17.259.The authors interpret this as strong evidence for a difference in effectiveness between the two drugs.

4. A “black box” Stan interface

The bridgesampling package provides a near-automatic Stan interface for estimating marginal likelihoods, provided models retain the relevant density constants. Users must handle truncation renormalization correctly, while custom samplers require additional inputs.

  • Custom samplers: Custom samplers require posterior samples, an unnormalized log posterior function, data, and parameter bounds.These are the same core steps needed to compute the marginal likelihood outside the automatic Stan interface.
  • Model specification: Retaining constants in Stan requires replacing sampling statements with target += distribution_lpdf or distribution_lpmf expressions.This explicitly specifies the log target density while preserving distribution constants.
  • Model specification: Truncated distributions require correct renormalization, such as subtracting the appropriate normal cdf or ccdf term from the log density.The implementation must also declare the variable with the correct lower and upper bounds.
  • Automatic Stan interface: Stan users can estimate a model’s marginal likelihood by passing a stanfit object to bridge_sampler, provided the model retains constants.The interface uses Stan’s unconstrained parameters and access to the log unnormalized posterior density.
  • Examples: The turtle GLMM example reproduced a Bayes factor near 1.273, while the more complex random-effects model had the larger estimation error.The results did not support strong claims about whether clutch membership affects survival.
  • Examples: The factor-analysis example found that the 2-factor model received most support from the observed exchange-rate data, consistent with earlier results.The 1-factor and 2-factor bridge-sampling log marginal likelihoods were also reported as very similar to earlier values.

5. Discussion

The discussion presents bridgesampling as a generic, accurate, user-friendly solution for computing marginal likelihoods and Bayesian model comparisons, while emphasizing careful diagnostics, prior specification, and method selection.

  • Contribution: The package combines bridge sampling with Stan to provide an automatic, general-purpose way to compare complex Bayesian models.For Stan models, the interface can produce log marginal likelihood estimates automatically from a stanfit object.
  • Practical advice: Users should verify that posterior samples are sufficiently numerous and representative before applying bridge sampling.The authors stress efficient sampling and checking MCMC chains because successful estimation depends on adequate posterior samples.
  • Practical advice: Estimate uncertainty empirically by repeating bridge sampling with fresh posterior samples whenever computationally feasible.Repeated Bayes factor estimates quantify variability directly; approximate errors are recommended for method = "normal" but not method = "warp3".
  • Practical advice: The Warp-III method may improve precision when better overlap between the posterior and proposal distributions is needed.The package states that method = "warp3" is at least as precise as method = "normal", though it is more time-consuming.
  • Prior specification: Meaningful Bayesian model comparisons still require carefully chosen prior distributions and, where appropriate, sensitivity analyses.The package removes the computational hurdle but does not eliminate the influence of parameter priors on model comparisons.
  • Scope and alternatives: Bridge sampling is not always the fastest or easiest choice for nested models or very large model spaces.The discussion identifies Savage-Dickey density ratios and Reversible Jump MCMC as possible alternatives in those settings.
Loading 1710.08162v3…