You are on page 1of 20

Monte Carlo for Bayesian Analysis

Lucas Morton University of Wisconsin Madison

Bayesian Analysis Discussion Group Madison, WI January 27, 2012

Outline

Recap MCMC overview Markov Chains Metropolis-Hastings Method Convergence, mixing and burn-in Output Examples Codes

Recap

Goal: draw samples from posterior


Assume a good uniform random generator Known distributions
Map from uniform R.V. to desired space Use inverse of CDF: F-1(p)

Unknown distribution
Draw samples from known distribution (proposal) Correct probability by rejecting some samples

Markov Chain: samples are dependent


Proposal depends on previous accepted sample

Markov Chain MC: Overview

Use Markov chains to sample distribution


Create process which converges to target distribution

Samples are statistically dependent Advantage: achieves good scaling with dimension
Unlike independent sampling methods

Disadvantage: random walk process


Can be inefficient, since samples not independent Can fail to converge Uncertainty of results

Markov Chains

MC is sequence of random vectors Probability of next vector depends only on present one Transition matrix T(x,x): distribution from which next vector is drawn An ergodic MC converges to invariant distrib p(x)
P(x) is characteristic of the transition matrix

Goal: construct T(x,x) s.t. its invariant distribution is the target distribution

MCMC Intro: Metropolis-Hastings Algorithm

Metropolis: most popular and general Propose step away from current position in parameter space
Using Gaussian centered at current position, for example

Proposal must be symmetric (in time) Acceptance of step with probability:

Metropolis-Hastings: generalized to asymmetric proposals

Illustration of M-H Method: von Toussaint

Metropolis with 2-D Gaussian proposal


Note multimodality

Convergence

Convergence guaranteed @ only


Time until initial conditions forgotten: burn-in How long to run?

Convergence diagnostics
Plot trace of parameter values, running avgs Compare many chains All diagnostics can give false positives

Illustration of convergence & lack thereof

*Neal, Technical Report CRG-TR-93-1, U. Toronto

Mixing

Slow mixing / large autocorrelation


Less info per sample Larger error in estimate

* Handbook

of Markov Chain Monte Carlo, Ch7 (Flegal & Jones)

Illustrations of mixing rates

Goldilocks principle: 25-50% acceptance


Achieve by fine-tuning proposal distribution
From J.S. Rosenthal in Ch4 of Handbook of MCMC

Correlated Variables

Causes MCMC to run slowly


Small steps due to narrow distribution

Causes spurious features in marginals


Left: actual TS result (Fischer et al PPCF 45 1095 (2003)) Right: indeterminate problem: data=X*Y, both unknown
Y appears to be determined, however!

Approaches to Correlated Variables

Use anisotropic proposal distribution


Match covariance of target distribution Wont help with pathological distributions
Esp. multimodal

Reparameterize
Ex: use ne, Pe=(Te*ne) as alternate params Rotate, rescale axes according to (co)variances Aim to make distribution spherical

Summarizing Results

Inference tools
Point Estimator
MLE/mode, median, mean/1st moment
Mean is better estimate than MLE

Interval Estimator
Easy: Quantiles, mean +/- standard deviation Tougher: credible region (requires marginal distrib.)

Marginal distribution
Histogram Kernel estimate of density function (smooth histogram) Analytic approximations

Monte Carlo Error: Flegal & Jones

Need to estimate MC Standard Error (MCSE) May use subsample batch method:
Find variance of batches of samples
Use batch size bn~

Predict variance of estimate:

Example: Flegal & Jones

Interval estimate with MCSE error bars


True values shown for comparison

Smoothed Histograms: Flegal & Jones

Example: Verdoolaege
6-D M-H w/ Cauchy proposal fake data

Example: Verdoolaege
Histograms from real data run

Code

PyMC 2.0
Metropolis-Hastings algorithm as a Python class

BUGS
http://www.mrc-bsu.cam.ac.uk/bugs/ R or GUI version, using Gibbs sampler

AMCMC
http://probability.ca/amcmc/ Open-source C/R Adaptive Metropolis-Hastings MCMC

Flegal and Jones:


http://arxiv.org/pdf/1006.5690v1.pdf R scripts available for examples in paper

You might also like