Metropolis–Hastings: a random walk on the Poisson posterior
Chapter 4, Exercise 4.8 · The model is Poisson regression, tn ~ Poisson(exp(w1 + w2un)), with a Gaussian prior N(0, σ²I) on the two weights. We can evaluate g(w) = prior × likelihood at any w but not the normaliser, so we sample with a random walk: propose a nearby w*, accept it with probability min(1, g(w*)/g(w)), otherwise stay put. The data are synthetic and are the same as in the Python script (the first n of 60 points).
The walk in weight space
━ contours of the true unnormalised posterior g(w) at drops of 0.5, 2, 4.5 and 8 in log height ╍ Laplace Gaussian at the same drops ◆ mode ● burn-in samples (discarded) ● kept samples grey line: the last 150 steps ● black: the current point the dashed segment shows the latest proposal: green if accepted, red cross if rejected.
Trace plots
Each weight along the chain. A good chain wanders around a level without drifting. The dashed vertical line marks the end of burn-in. The red line is the Laplace mean and the pale band is ±2 Laplace standard deviations.
Marginal histograms against the Laplace approximation
Bars: kept samples, which approximate the true posterior. Red curve: the Laplace Gaussian. Dotted line: the sample mean.