The principleProposals are not samples. Accept with the Hastings probability; otherwise record the previous state again. Small moves can be accepted often while exploring very slowly.
Cross: proposed point. Open circle: previous state. Filled circle: retained state. Dashed orange path shows the attempted move, including a return on rejection. + marks the data-generating parameters, not the posterior mean. Dense clouds draw at most 1,500 states per chain; diagnostics use every retained state.
The acceptance decision
Quantity
Value
Has the chain explored the posterior?
Trace: parameter 1
Trace: parameter 2
Marginal: parameter 1
Marginal: parameter 2
Parameter
Sample mean
Sample SD
Target mean ≈
Target SD ≈
Split R̂
ACF ESS ≈
Teal curves / stems and target moments use deterministic numerical quadrature over the entire prior support, not a fitted Gaussian or the region visited by the chain. For N, the reference sums over every allowed integer. These are numerical approximations, not exact credible regions. Histograms pool retained states; chain traces stay separate.
Only iterations revealed by playback enter sample diagnostics. Burn-in discards the first B attempted transitions; the initial starting point is not a sample. Thinning retains iterations B + 1, B + 1 + k, … and does not create independent information.
Dependence survives acceptance
Autocorrelation: parameter 1
Autocorrelation: parameter 2
Successive retained states: parameter 1
Successive retained states: parameter 2
Chain
Accepted / attempted
Acceptance rate
Retained states
ACFs are computed within each chain and averaged, never across concatenated chain boundaries. Constant chains have undefined ACF. Split R̂ needs at least two chains with four retained states each; a value near 1 is not proof of convergence. The simple ACF-based ESS truncates at 40 retained lags and can overstate information for slowly mixing chains.
A Metropolis–Hastings iteration
Start at x with finite positive posterior density π(x).
Propose y from q(y | x), even when it falls outside the target support.
Compute the acceptance probability using both proposal directions.
Draw U uniformly in (0, 1). Accept y if log U < log α; otherwise keep x. Record one state either way.
log r = log π(y) − log π(x)
+ log q(x | y) − log q(y | x)
log α = min(0, log r)
x[t+1] = y if log U < log α, otherwise x[t]
The unknown posterior normalising constant cancels. Log densities avoid underflow. An out-of-support proposal has log π(y) = −∞ and is rejected, not clipped, reflected or repeatedly redrawn.
The selected model
Proposal families
Gaussian random walk: independent N(0, s²) increments in both coordinates. For the Binomial model, N instead moves by −1, 0 or +1 with equal probability. These proposals are symmetric; their ratio cancels, including at the support boundaries because invalid moves are rejected.
Independent global: continuous coordinates are drawn from Gaussians centred at prior midpoints, with SD = range width / 3. N is drawn uniformly over all prior integers. The forward and reverse densities generally differ.
Mixture: select the global proposal with probability w, otherwise the local random walk. The Hastings ratio uses the full mixture density in both directions, not only the selected component. This is a proposal mixture, not a mixture target.
Try these experiments
Compare tiny and large local proposal SDs. High acceptance can mean tiny, highly correlated moves; very large steps can leave long repeated-state plateaus.
For Gaussian data, increase correlation. A spherical proposal struggles along a narrow diagonal posterior even when every density evaluation is correct.
Use Binomial data. N must stay integer and at least the largest observed count; a boundary attempt is rejected rather than silently rounded back into support.
Compare chains, then adjust burn-in and thinning without changing the cached trajectories. Different starts can reveal lack of exploration that one smooth-looking trace hides.
Try a local/global proposal mixture. Better travel is possible, but global proposals are not accepted automatically; their proposal-density ratio matters.
Reproducibility and limits
Playback starts paused. All chains and all acceptance decisions are cached using a local seeded generator. Play, pause, next, rewind, seek and display changes reveal exactly the same run. Model or sampler changes regenerate the run. The data use a separate seeded stream, so changing proposal settings leaves observations unchanged. JavaScript and R random generators differ: equal seeds do not imply identical paths across languages.
The scale is fixed for the entire chain. Naively adapting proposals from the current sampling history can invalidate stationary-distribution arguments; any warm-up adaptation would need an explicit valid scheme and must not be mistaken for retained stationary sampling. No adaptation is performed here.
This demonstration infers two parameters from simulated observations; it is not an optimiser or a production convergence guarantee. The Gaussian data covariance is known. Gamma uses rate, not scale. Bounded priors define the target, so moving their bounds can legitimately change inference.