Bayesian Analysis

Computing the Bayes Factor from a Markov Chain Monte Carlo Simulation of the Posterior Distribution

Martin D. Weinberg

Full-text: Open access


Determining the marginal likelihood from a simulated posterior distribution is central to Bayesian model selection but is computationally challenging. The often-used harmonic mean approximation (HMA) makes no prior assumptions about the character of the distribution but tends to be inconsistent. The Laplace approximation is stable but makes strong, and often inappropriate, assumptions about the shape of the posterior distribution. Here, I argue that the marginal likelihood can be reliably computed from a posterior sample using Lebesgue integration theory in one of two ways: 1) when the HMA integral exists, compute the measure function numerically and analyze the resulting quadrature to control error; 2) compute the measure function numerically for the marginal likelihood integral itself using a space-partitioning tree, followed by quadrature. The first algorithm automatically eliminates the part of the sample that contributes large truncation error in the HMA. Moreover, it provides a simple graphical test for the existence of the HMA integral. The second algorithm uses the posterior sample to assign probability to a partition of the sample space and performs the marginal likelihood integral directly. It uses the posterior sample to discover and tessellate the subset of the sample space that was explored and uses quantiles to compute a representative field value. When integrating directly, this space may be trimmed to remove regions with low probability density and thereby improve accuracy. This second algorithm is consistent for all proper distributions. Error analysis provides some diagnostics on the numerical condition of the results in both cases.

Article information

Bayesian Anal., Volume 7, Number 3 (2012), 737-770.

First available in Project Euclid: 28 August 2012

Permanent link to this document

Digital Object Identifier

Mathematical Reviews number (MathSciNet)

Zentralblatt MATH identifier

Bayesian computation marginal likelihood algorithm Bayes factors model selection


Weinberg, Martin D. Computing the Bayes Factor from a Markov Chain Monte Carlo Simulation of the Posterior Distribution. Bayesian Anal. 7 (2012), no. 3, 737--770. doi:10.1214/12-BA725.

Export citation


  • Carlin, B. P. and Chib, S. (1995). “Bayesian model choice via Markov chain Monte Carlo methods.” Journal of the Royal Statistical Society, Series B, 57: 473–484.
  • Chib, S. and Jeliazkov, I. (2001). “Marginal Likelihood From the Metropolis-Hastings Output.” Journal of the American Statistical Association, 96(453): 270–281.
  • Cormen, T. H., Leiserson, C. E., Rivest, R. L., and Stein, C. (2001). Introduction to Algorithms. The MIT Press, 2nd edition.
  • de Berg, M., Cheong, O., van Kreveld, M., and Overmars, M. (2008). Computational Geometry: Algorithms and Applications. Springer-Verlag.
  • DiCiccio, T., Kass, R., Raftery, A., and Wasserman, L. (1997). “Computing Bayes factors by combining simulation and asymptotic approximations.” American Statistical Association, 92: 903–915.
  • Edelsbrunner, H. and Shah, N. (1966). “Incremental Topological Flipping Works for Regular Triangulations.” Algorithmica, 15(3): 223–241.
  • Gelman, A., Carlin, J. B., Stern, H. S., and Rubin, D. B. (2003). Bayesian Data Analysis. Texts in Statistical Science. Boca Raton, FL: CRC Press, 2nd edition.
  • Gelman, A. and Rubin, D. B. (1992). “Inference from iterative simulation using multiple sequences.” Statistical Science, 7: 457–472.
  • Geyer, C. (1991). “Markov chain Monte Carlo maximum likelihood.” In Computing Science and Statistics, Proceedings of the 23rd Symposium on the Interface, 156. American Statistical Association.
  • Giakoumatos, S. G., Vrontos, I. D., Dellaportas, P., and Politis, D. N. (1999). “An MCMC Convergence Diagnostic using Subsampling.” Journal of Computational and Graphical Statistics, 1: 431–451.
  • Green, P. and O’Hagan, A. (1998). “Model choice with MCMC on product spaces without using pseudo-priors.” Technical report, Nottingham University. Statistics Research Report 98-01.
  • Green, P. J. (1995). “Reversible jump Markov chain Monte Carlo computation and Bayesian model determination.” Biometrika, 82: 711–32.
  • Han, C. and Carlin, B. P. (2001). “MCMC Methods for Computing Bayes Factors: A Comparative Review.” Journal of the American Statistical Association, 96: 1122–1132.
  • Kass, R. E. and Raftery, A. E. (1995). “Bayes Factors.” Journal of the American Statistical Association, 90(430): 773–795.
  • Lavine, M. and Schervish, M. (1999). “Bayes Factors: What they are and what they are not.” American Statistician, 53: 119–122.
  • Neal, R. M. (1996). “Sampling from multimodal distributions using tempered transitions.” Statistics and Computing, 6: 353–366.
  • Newton, M. A. and Raftery, A. E. (1994). “Approximate Bayesian inference by the weighted likelihood bootstrap.” Journal of the Royal Statistical Society, Series B, 56: 3–48.
  • Philippe, A. and Robert, C. P. (2001). “Riemann sums for MCMC estimation and convergence monitoring.” Statistics and Computing, 11: 103–115.
  • Raftery, A. E., Newton, M. A., Satagopan, J. M., and Krivitsky, P. N. (2007). “Estimating the Integrated Likelihood via Posterior Simulation Using the Harmonic Mean Identity.” Bayesian Statistics, 8: 1–45.
  • Ter Braak, C. J. F. (2006). “A Markov chain Monte Carlo version of the genetic algorithm Differential Evolution: easy Bayesian computing for real parameter spaces.” Statistics and Computing, 16: 239–249.
  • Trotta, R. (2007). “Applications of Bayesian model selection to cosmological parameters.” Monthly Notices of the Royal Astronomical Society, 378: 72–82.
  • — (2008). “Bayes in the sky: Bayesian inference and model selection in cosmology.” Contemporary Physics, 49(2): 71–104.
  • Weinberg, M. D. (2012). “Computational statistics using the Bayesian Inference Engine.” Monthly Notices of the Royal Astronomical Society. Submitted.
  • Weinberg, M. D. and Moss, J. E. B. (2010). “The UMass Bayesian Inference Engine.” Technical report, University of Massachusetts/Amherst.
  • Williams, E. (1959). Regression Analysis. New York: Wiley.
  • Wolpert, R. L. (2002). “Stable Limit Laws for Marginal Probabilities from MCMC Streams: Acceleration of Convergence.” Discussion Paper 2002-22, Duke University ISDS.