The target is a mixture of two Gaussians, 0.3 N(−20, 102) + 0.7 N(20, 102). Four chains start at 20, −40, 5 and 60. A random walk Metropolis chain proposes x′ = x + τε: with a tiny τ it creeps and never finds the second mode, with a huge τ it is almost always rejected and sticks. The Gibbs sampler alternates the component label z and x. The diagnostics (R-hat across the four chains and the effective sample size) tell the cases apart.
Random walk Metropolis accepts x′ with probability min(1, p(x′)/p(x)), (12.1); the normalising constant is never needed. Gibbs draws z from p(z | x) by (12.35), then x ~ N(μz, 102), and accepts every move. R-hat is (12.100) over the four chains; the effective sample size is (12.110) with the chain-averaged autocorrelation summed up to the first lag where it is not positive. The true Pr(x < 0) is 0.309.
code/ch12_mcmc.py (rwm, gibbs_gmm1d, rhat, ess, demo_mh_run); Figures 12.1, 12.4 and 12.17 in the code index.