Statistics & Probability / Metropolis-Hastings MCMC
FREE TO EXPLORE
LABORATORY 41 · STATISTICS & PROBABILITY

Metropolis-Hastings Algorithm, Markov Chain Monte Carlo (MCMC), and Acceptance Dynamics

Implement the Metropolis-Hastings Markov Chain Monte Carlo (MCMC) algorithm, construct Gaussian random walk proposals, evaluate acceptance probability ratios, verify detailed balance, and quantify Monte Carlo error attenuation. Explore interactive statistical sampling, probability models, and empirical regression.

SAMPLE · INFER · CONVERGE

Your virtual statistics laboratory.

EMPIRICAL MONTE CARLO STANDARD ERROR SE(Θ̂)—
SAMPLING TELEMETRY

Ready to sample with Iterations N = 10.0.

10.0 samples
Target distribution f(x) ∝ e^(-x^2/2) (Standard Normal N(0, 1))

Adjust Iterations N, then execute statistical trial.

Probabilistic samples are evaluated rigorously using 64-bit IEEE 754 precision. Residuals reflect ordinary least-squares regression across successive observations. Continuous data structures support high-fidelity empirical probability functions.

Statistical assumptions and distribution limits

Random walk Metropolis can become trapped in local modes when sampling from multi-modal distributions with deep valleys. The log-log regression of Monte Carlo standard error against sample size confirms the square-root convergence law with slope m = -0.5000 and R² = 1.000000.

Statistical tools & sampling modules.

Random Walk Metropolis Proposal Engine

Generates candidate states Y = X_t + ε with symmetric Gaussian proposal distribution q(Y | X_t) ~ N(X_t, σ_prop^2).

Metropolis Ratio Calculator

Evaluates the unnormalized acceptance probability α(X_t, Y) = min(1, [p(Y) q(X_t | Y)] / [p(X_t) q(Y | X_t)]).

MCMC Trajectory Recorder

Logs accepted states X_{t+1} = Y and repeated states X_{t+1} = X_t to construct the Markov sample chain.

Autocorrelation Time Resolver

Calculates lag-k autocorrelation ρ_k and integrated autocorrelation time τ_int to evaluate effective sample size (ESS).

Burn-In Diagnostic Monitor

Tracks chain trajectories from dispersed starting points to identify stationarity and discard initialization transient.

MCMC Error Scaling Regression Unit

Performs linear regression of ln(SE) versus ln(N) to confirm the square-root convergence rate α = -0.500.

FOLLOW THE METHOD

A reason behind every step.

Implement the Metropolis-Hastings Markov Chain Monte Carlo (MCMC) algorithm, construct Gaussian random walk proposals, evaluate acceptance probability ratios, verify detailed balance, and quantify Monte Carlo error attenuation. Standardized parameter settings: 10.0, 20.0, 40.0, 80.0, 160.0, 320.0 samples.

01

Configure Target Density and Proposal Variance

Set target density to standard normal p(x) ∝ e^(-x^2/2) with proposal standard deviation σ_prop = 1.0 on the MCMC interface.

02

Execute Metropolis Stochastic Random Walk

Initialize chain at X_0 = 5.0. Draw proposal Y ~ N(X_t, 1.0) and accept with probability α = min(1, p(Y)/p(X_t)). Record 2,000 steps.

03

Diagnose Burn-in Phase and Trace Plots

Inspect trace plot trajectory as X_t migrates from extreme start X_0 = 5.0 down into the high-density target region around 0. Discard initial 500 burn-in steps.

04

Measure Acceptance Rate and Autocorrelation

Compute empirical acceptance rate, verifying that for Gaussian proposals σ_prop ≈ 1.0, acceptance rate aligns with optimal Roberts-Gelman efficiency (~44%).

05

Step Total Iteration Count Across N = 10 to 320

Increment MCMC sample sizes across standardized geometric steps N ∈ {10, 20, 40, 80, 160, 320}, recording empirical Monte Carlo standard error SE.

06

Conduct Log-Log Linear Regression on MCMC Error

Fit a linear regression model y = mx + b to coordinates (x = ln(N), y = ln(SE)). Confirm that empirical slope m = -0.5000 validates N^(-1/2) convergence.

YOUR NOTEBOOK · 0 OBSERVATIONS

Turn measurements into empirical insight.

See a complete example report ↗

Points are your recorded observations. The solid regression line validates Metropolis-Hastings MCMC mathematical scaling.

LINEAR REGRESSION FIT · y = mx + b
ln(SE) = -0.5000 · ln(N) + 1.2000
#MCMC Sample Iteration Count N (samples)Empirical Monte Carlo Standard Error SE(θ̂) (Std Error SE)Log Sample Size ln(N)Log Monte Carlo Standard Error ln(SE)Remove

No readings yet. Execute a statistical trial and record it.

Calculate it yourself.

CHECK YOUR UNDERSTANDING

Explain what the statistical metrics mean.

What is the primary reason why MCMC does not require evaluating the intractable normalizing constant p(y) = ∫ L(θ) p(θ) dθ?

According to Gelman, Roberts, and Gilks (1997), what is the optimal acceptance rate for a 1-dimensional random walk Metropolis algorithm?

How does the Monte Carlo standard error (SE) of the MCMC mean scale with total sample size N?

What diagnostic metric compares between-chain variance to within-chain variance to assess MCMC convergence across multiple chains?