# Posterior sampling

Posterior sampling is the task of drawing representative samples from the posterior distribution \( p(\theta \mid D) \) of model parameters \( \theta \) given data \( D \), so that moments, densities, quantiles, and uncertainty intervals can be estimated by [Monte Carlo](https://www.edgepedia.org/monte-carlo) averages when the posterior cannot be written in closed form. Because the posterior is known only up to a normalizing constant that is itself an intractable integral, the draws are usually produced by [Markov chain Monte Carlo](https://www.edgepedia.org/markov-chain-monte-carlo) (MCMC), a collection of algorithms that simulate a [Markov chain](https://www.edgepedia.org/markov-chain) whose equilibrium distribution is the target posterior.<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-040220-090158)</sup> The resulting samples are dependent rather than independent, and their quality is judged by diagnostics such as effective sample size and the R-hat statistic.<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-040220-090158)</sup>

| Key fact | Value or statement |
|---|---|
| What the method produces | Dependent draws from \( p(\theta \mid D) \), used to estimate posterior moments, densities, and quantiles<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-040220-090158)</sup> |
| Why direct sampling fails | The evidence \( p(D) \) in the denominator is an intractable integral; Metropolis-type ratios cancel it<sup>[2](https://www.cs.helsinki.fi/u/ahonkela/teaching/compstats1/book/bayesian-inference-with-mcmc.html)</sup> |
| Chain design requirement | The transition kernel leaves the target invariant<sup>[3](https://projecteuclid.org/journalArticle/Download?urlId=10.1214%2F154957804100000024&isResultClick=False)</sup> |
| Convergence screening | Rank-normalized split R-hat with a suggested threshold of 1.01<sup>[4](https://mc-stan.org/docs/reference-manual/analysis.html)</sup> |
| Sample quality metric | \( N_{\mathrm{eff}} = N / (1 + 2\sum \rho_{t}) \); Monte Carlo standard error scales as \( 1/\sqrt{N_{\mathrm{eff}}} \)<sup>[4](https://mc-stan.org/docs/reference-manual/analysis.html)</sup> |
| Cost per independent sample | HMC roughly \( O(D^{5/4}) \) in dimension \( D \) versus \( O(D^{2}) \) for random-walk Metropolis<sup>[5](https://jmlr.csail.mit.edu/papers/v15/hoffman14a.html)</sup> |
| Default sampler in Stan | Hamiltonian Monte Carlo with the no-U-turn sampler (NUTS)<sup>[4](https://mc-stan.org/docs/reference-manual/analysis.html)</sup> |

## How it works

[Bayes' theorem](https://www.edgepedia.org/bayes-theorem) gives \( p(\theta \mid D) = p(D \mid \theta)\, p(\theta) / p(D) \). The denominator, the marginal likelihood or evidence, is an integral over all parameter values that is rarely tractable, so the posterior cannot usually be sampled directly.<sup>[2](https://www.cs.helsinki.fi/u/ahonkela/teaching/compstats1/book/bayesian-inference-with-mcmc.html)</sup> MCMC sidesteps this by working with the unnormalized target \( \tilde{\pi}(\theta) = p(D \mid \theta)\, p(\theta) \): Metropolis-type acceptance decisions use ratios of target densities, from which the normalizing constant \( Z \) cancels.<sup>[6](https://predictivesciencelab.github.io/advanced-scientific-machine-learning/inverse/sampling/01_mcmc_basics.html)</sup>

The algorithms construct an easily simulated Markov chain whose stationary distribution is the complicated target \( \pi \).<sup>[3](https://projecteuclid.org/journalArticle/Download?urlId=10.1214%2F154957804100000024&isResultClick=False)</sup> The standard recipes, Metropolis–Hastings, Gibbs samplers, and component-wise Metropolis–Hastings, yield time-homogeneous chains for which \( F \cdot P = F \), so the target is invariant.<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-040220-090158)</sup> Metropolis–Hastings chains are reversible with respect to \( \pi \); detailed balance implies invariance, though it is sufficient rather than necessary, and some valid transitions are nonreversible.<sup>[3](https://projecteuclid.org/journalArticle/Download?urlId=10.1214%2F154957804100000024&isResultClick=False)</sup><sup> • </sup><sup>[6](https://predictivesciencelab.github.io/advanced-scientific-machine-learning/inverse/sampling/01_mcmc_basics.html)</sup>

## How it is done

A practical workflow has four phases: prepare by characterizing the target, warm up by tuning the sampler and letting chains equilibrate, collect samples, and analyze with diagnostics, with feedback between phases.<sup>[7](https://nucleartalent.github.io/LFD_for_Physicists/content/MCMC-sampling/mcmc-in-practice/sec-workflow-for-mcmc-sampling.html)</sup>

During warmup, tuning adapts sampler parameters, step length and proposal for Metropolis–Hastings, mass matrix, leapfrog step size, and number of steps for HMC, and equilibration moves chains into the high-probability region.<sup>[7](https://nucleartalent.github.io/LFD_for_Physicists/content/MCMC-sampling/mcmc-in-practice/sec-workflow-for-mcmc-sampling.html)</sup> All warmup samples are discarded, since during tuning the kernel keeps changing and the samples do not follow the target.<sup>[7](https://nucleartalent.github.io/LFD_for_Physicists/content/MCMC-sampling/mcmc-in-practice/sec-workflow-for-mcmc-sampling.html)</sup> Diagnostics follow: R-hat compares within-chain to pooled across-chain variance, equals one at equilibrium, and Vehtari et al. (2021) suggest a threshold of 1.01; Stan computes split R-hat by halving each chain and uses rank-normalized values for R-hat and effective sample size.<sup>[4](https://mc-stan.org/docs/reference-manual/analysis.html)</sup> [Effective sample size](https://www.edgepedia.org/effective-sample-size) is \( N_{\mathrm{eff}} = N / (1 + 2\sum \rho_{t}) \), and Monte Carlo standard error is proportional to \( 1/\sqrt{N_{\mathrm{eff}}} \).<sup>[4](https://mc-stan.org/docs/reference-manual/analysis.html)</sup> No diagnostic based on simulated values can prove the chain is representative: "no evidence of nonconvergence is not evidence of convergence"<sup>[1](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-040220-090158)</sup>, and existing diagnostics assess only necessary, not sufficient, conditions.<sup>[8](https://pmc.ncbi.nlm.nih.gov/articles/PMC7616193/)</sup>

## Origin

The [Metropolis](https://www.edgepedia.org/metropolis) algorithm appeared in "Equation of State Calculations by Fast Computing Machines" by [Nicholas Metropolis](https://www.edgepedia.org/nicholas-metropolis) and colleagues in The Journal of Chemical Physics in 1953, written for computing properties of substances composed of interacting individual molecules.<sup>[9](https://doi.org/10.1063/1.1699114)</sup><sup> • </sup><sup>[10](https://www.stat.rice.edu/~dcox/Stat552/Mcmc/tierneyMCMCAnnStat94.pdf)</sup> [W. K. Hastings](https://www.edgepedia.org/w-k-hastings) generalized the algorithm in Biometrika in 1970, with computations depending on the target density only through ratios \( p(x')/p(x) \).<sup>[11](https://doi.org/10.1093/biomet/57.1.97)</sup><sup> • </sup><sup>[12](https://www.probability.ca/hastings/hastings.pdf)</sup> MCMC was invented soon after ordinary Monte Carlo but remained little used among statisticians until after 1990.<sup>[13](https://archived.stat.ufl.edu/casella/Papers/MCMCHistory.pdf)</sup> Stuart Geman and Donald Geman introduced Gibbs sampling in 1984 in IEEE Transactions on Pattern Analysis and Machine Intelligence, for Bayesian restoration of images<sup>[14](https://doi.org/10.1109/tpami.1984.4767596)</sup><sup> • </sup><sup>[15](http://www-stat.wharton.upenn.edu/~steele/Courses/900/Library/MCMCHistory.pdf)</sup>; they coined the phrase "Gibbs sampling" because their problem used Gibbs random fields.<sup>[16](http://arxiv.org/pdf/2004.06425)</sup> Kirkpatrick, Gelatt, and Vecchi's 1983 simulated annealing paper built on the Metropolis algorithm.<sup>[17](https://doi.org/10.1126/science.220.4598.671)</sup><sup> • </sup><sup>[10](https://www.stat.rice.edu/~dcox/Stat552/Mcmc/tierneyMCMCAnnStat94.pdf)</sup> The extension of the Gibbs sampler to continuous distributions rekindled interest in dependent Markov-chain samples, and the papers set the stage for a revolution in Bayesian data analysis.<sup>[10](https://www.stat.rice.edu/~dcox/Stat552/Mcmc/tierneyMCMCAnnStat94.pdf)</sup><sup> • </sup><sup>[18](https://imsarchives.nus.edu.sg/oldwww/Programs/mcmc/files/besag_tl.pdf)</sup>

## Variants

**Metropolis–Hastings** produces a chain reversible with respect to \( \pi \); the symmetric Metropolis, random-walk, and independence-sampler variants simplify the acceptance probability.<sup>[3](https://projecteuclid.org/journalArticle/Download?urlId=10.1214%2F154957804100000024&isResultClick=False)</sup> **Gibbs sampling**, also known as the heat bath algorithm or [Glauber dynamics](https://www.edgepedia.org/glauber-dynamics), updates one component at a time from its full conditional distribution<sup>[3](https://projecteuclid.org/journalArticle/Download?urlId=10.1214%2F154957804100000024&isResultClick=False)</sup>; it uses conditional updates, but these do not generally break the curse of dimensionality, since high-dimensional Gibbs samplers can converge slowly, especially with poorly conditioned distributions, and it is a special case of Metropolis–Hastings with acceptance probability one.<sup>[19](https://ar5iv.labs.arxiv.org/html/2001.06249)</sup><sup> • </sup><sup>[29](https://genghis-l.github.io/assets/pdf/projects/High-Dimensional-Sampling-Methods/High_dimensional_Sampling.pdf)</sup>

**Hamiltonian Monte Carlo** uses gradient information, and the no-U-turn sampler removes the need to choose the path length \( L \) by recursively doubling a binary tree of leapfrog states, stopping when the endpoints turn back toward one another, while dual averaging adapts the step size during warmup.<sup>[5](https://jmlr.csail.mit.edu/papers/v15/hoffman14a.html)</sup><sup> • </sup><sup>[6](https://predictivesciencelab.github.io/advanced-scientific-machine-learning/inverse/sampling/01_mcmc_basics.html)</sup> **Slice sampling**, introduced by Radford M. Neal in The Annals of Statistics in 2003, samples uniformly from the region under the plot of the density function, alternating vertical and horizontal updates; it is often easier to implement than [Gibbs sampling](https://www.edgepedia.org/gibbs-sampling) and more efficient than simple Metropolis updates because it adaptively chooses the magnitude of changes.<sup>[20](https://doi.org/10.1214/aos/1056562461)</sup> Adaptive rejection Metropolis sampling within Gibbs sampling, by W. R. Gilks, N. G. Best, and K. K. C. Tan (1995), handles conditional densities that may not be log-concave.<sup>[21](https://doi.org/10.2307/2986138)</sup>

For large datasets, stochastic-gradient methods reduce per-update cost: SGLD applies [Langevin dynamics](https://www.edgepedia.org/langevin-dynamics) with stochastic gradients, and SGFS, described by S. Ahn, Anoop Korattikara, and [Max Welling](https://www.edgepedia.org/max-welling) at ICML 2012, extends it with a [preconditioner](https://www.edgepedia.org/preconditioner) and samples from a Gaussian approximation of the posterior at large stepsizes.<sup>[22](https://icml.cc/2012/papers/782.pdf)</sup> Sequential Monte Carlo samplers, by Pierre Del Moral, Arnaud Doucet, and Ajay Jasra (2006), approximate a sequence of distributions by a cloud of weighted samples propagated over time<sup>[23](https://doi.org/10.1111/j.1467-9868.2006.00553.x)</sup>, and particle MCMC methods, by Christophe Andrieu, Arnaud Doucet, and Roman Holenstein (2010), use SMC algorithms to design efficient high-dimensional proposals for MCMC.<sup>[24](https://doi.org/10.1111/j.1467-9868.2009.00736.x)</sup>

## Applications

Posterior sampling has become the standard computational workhorse of Bayesian data analysis<sup>[18](https://imsarchives.nus.edu.sg/oldwww/Programs/mcmc/files/besag_tl.pdf)</sup>, and Gibbs sampling was introduced for Bayesian restoration of images.<sup>[14](https://doi.org/10.1109/tpami.1984.4767596)</sup> On pedigree-based animal models with pig data, HMC and NUTS effective sample sizes were 1.7 to 2.0 and 3.2 to 22.6 times larger than Gibbs sampling, respectively.<sup>[25](https://link.springer.com/article/10.1186/s12711-019-0515-1)</sup> As a rule of thumb, \( N_{\mathrm{eff}} \approx N/\tau \) from the autocorrelation time \( \tau \); a posterior mean is well determined by a few hundred effective samples, while endpoints of a 95% credible interval require thousands.<sup>[7](https://nucleartalent.github.io/LFD_for_Physicists/content/MCMC-sampling/mcmc-in-practice/sec-workflow-for-mcmc-sampling.html)</sup>

## Limitations and alternatives

MCMC samples are typically positively correlated because of the [Markov property](https://www.edgepedia.org/markov-property), reducing the information they carry; with high autocorrelation, 5,000 correlated draws can carry the information of far fewer independent draws.<sup>[26](https://probability.ca/jeff/ftpdir/annrevCR.pdf)</sup> In multimodal targets, a random-walk chain may explore one mode well but take an unfeasibly long time to move between modes, causing extremely slow convergence.<sup>[26](https://probability.ca/jeff/ftpdir/annrevCR.pdf)</sup> The cost of HMC per independent sample from a target of dimension \( D \) is roughly \( O(D^{5/4}) \), against \( O(D^{2}) \) for random-walk Metropolis.<sup>[5](https://jmlr.csail.mit.edu/papers/v15/hoffman14a.html)</sup> With data of order hundreds of millions to billions, each iteration requires a likelihood with \( N \) terms, and a single iteration can take days<sup>[27](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-033121-110254)</sup>; when the likelihood itself becomes intractable, the Metropolis–Hastings acceptance probability cannot be computed analytically.<sup>[27](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-033121-110254)</sup>

Among alternatives, variational inference tends to be faster than MCMC and easier to scale to large data, but generally underestimates posterior variance; MCMC provides asymptotically exact samples, so it suits smaller datasets where precise samples justify heavier computation, while VI suits large datasets and quick model exploration.<sup>[28](https://arxiv.org/pdf/1601.00670v3)</sup> Deterministic approximations such as Laplace's approximation, expectation propagation, and Bayesian variational methods carry approximation errors that are usually unknown and cannot be corrected.<sup>[19](https://ar5iv.labs.arxiv.org/html/2001.06249)</sup> [Importance sampling](https://www.edgepedia.org/importance-sampling) can be more efficient than MCMC but has trouble covering all regions of the target's support<sup>[19](https://ar5iv.labs.arxiv.org/html/2001.06249)</sup>, and sequential Monte Carlo methods such as particle filters may be more appropriate in dynamical models where data arrives in bursts.<sup>[19](https://ar5iv.labs.arxiv.org/html/2001.06249)</sup>

## References

1. [Markov Chain Monte Carlo in Practice (Annual Review of Statistics)](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-040220-090158)
2. [Bayesian inference with MCMC, Computational Statistics I (University of Helsinki)](https://www.cs.helsinki.fi/u/ahonkela/teaching/compstats1/book/bayesian-inference-with-mcmc.html)
3. [General state space Markov chains and MCMC algorithms (Roberts, Probability Surveys)](https://projecteuclid.org/journalArticle/Download?urlId=10.1214%2F154957804100000024&isResultClick=False)
4. [Stan Reference Manual: Posterior Analysis](https://mc-stan.org/docs/reference-manual/analysis.html)
5. [The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo](https://jmlr.csail.mit.edu/papers/v15/hoffman14a.html)
6. [Basics of Markov Chain Monte Carlo, Advanced Scientific Machine Learning](https://predictivesciencelab.github.io/advanced-scientific-machine-learning/inverse/sampling/01_mcmc_basics.html)
7. [Workflow for MCMC sampling, Learning from Data materials](https://nucleartalent.github.io/LFD_for_Physicists/content/MCMC-sampling/mcmc-in-practice/sec-workflow-for-mcmc-sampling.html)
8. [Post-Processing of MCMC (South, Riabiz, Teymur, Ong; Statistics and Computing review)](https://pmc.ncbi.nlm.nih.gov/articles/PMC7616193/)
9. [Nicholas Metropolis and colleagues (1953). Equation of State Calculations by Fast Computing Machines. The Journal of Chemical Physics.](https://doi.org/10.1063/1.1699114)
10. [Markov Chains for Exploring Posterior Distributions (Tierney, Annals of Statistics 1994)](https://www.stat.rice.edu/~dcox/Stat552/Mcmc/tierneyMCMCAnnStat94.pdf)
11. [W. K. Hastings (1970). Monte Carlo sampling methods using Markov chains and their applications. Biometrika.](https://doi.org/10.1093/biomet/57.1.97)
12. [Monte Carlo sampling methods using Markov chains and their applications (Hastings 1970 paper text)](https://www.probability.ca/hastings/hastings.pdf)
13. [A Short History of Markov Chain Monte Carlo: Subjective Recollections from Incomplete Data (Casella)](https://archived.stat.ufl.edu/casella/Papers/MCMCHistory.pdf)
14. [Stuart Geman, Donald Geman (1984). Stochastic Relaxation, Gibbs Distributions, and the Bayesian Restoration of Images. IEEE Transactions on Pattern Analysis and Machine Intelligence.](https://doi.org/10.1109/tpami.1984.4767596)
15. [The Evolution of Markov Chain Monte Carlo Methods](http://www-stat.wharton.upenn.edu/~steele/Courses/900/Library/MCMCHistory.pdf)
16. [Computing Bayes: Bayesian Computation from 1763 to the 21st Century](http://arxiv.org/pdf/2004.06425)
17. [S. Kirkpatrick, C. D. Gelatt, M. P. Vecchi (1983). Optimization by Simulated Annealing. Science.](https://doi.org/10.1126/science.220.4598.671)
18. [Markov Chain Monte Carlo Methods for Statistical Inference (Besag lecture notes)](https://imsarchives.nus.edu.sg/oldwww/Programs/mcmc/files/besag_tl.pdf)
19. [Markov Chain Monte Carlo Methods, a survey with some frequent misunderstandings (Christian Robert)](https://ar5iv.labs.arxiv.org/html/2001.06249)
20. [Radford M. Neal (2003). Slice sampling. The Annals of Statistics.](https://doi.org/10.1214/aos/1056562461)
21. [W. R. Gilks, N. G. Best, K. K. C. Tan (1995). Adaptive Rejection Metropolis Sampling within Gibbs Sampling. Journal of the Royal Statistical Society Series C (Applied Statistics).](https://doi.org/10.2307/2986138)
22. [Bayesian Posterior Sampling via Stochastic Gradient Fisher Scoring (ICML 2012)](https://icml.cc/2012/papers/782.pdf)
23. [Pierre Del Moral, Arnaud Doucet, Ajay Jasra (2006). Sequential Monte Carlo Samplers. Journal of the Royal Statistical Society Series B (Statistical Methodology).](https://doi.org/10.1111/j.1467-9868.2006.00553.x)
24. [Christophe Andrieu, Arnaud Doucet, Roman Holenstein (2010). Particle Markov Chain Monte Carlo Methods. Journal of the Royal Statistical Society Series B (Statistical Methodology).](https://doi.org/10.1111/j.1467-9868.2009.00736.x)
25. [Performance of Hamiltonian Monte Carlo and No-U-Turn Sampler for estimating genetic parameters and breeding values](https://link.springer.com/article/10.1186/s12711-019-0515-1)
26. [Bayesian Computation Via Markov Chain Monte Carlo (Annual Review of Statistics)](https://probability.ca/jeff/ftpdir/annrevCR.pdf)
27. [Approximate Methods for Bayesian Computation (Annual Review of Statistics)](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-033121-110254)
28. [Variational Inference: A Review for Statisticians (Blei, Kucukelbir, McAuliffe)](https://arxiv.org/pdf/1601.00670v3)
29. [High Dimensional Sampling.pdf, genghis-l.github.io](https://genghis-l.github.io/assets/pdf/projects/High-Dimensional-Sampling-Methods/High_dimensional_Sampling.pdf)

---
*Topic: Encyclopedia › Physical world and mathematics › Mathematics and statistics › Statistics and probability › Bayesian statistics › Bayesian computation and software*

*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Oct 15, 2026 · Last review: Sep 30, 2026*

*Copyright 2026 EdgeChat AI, a subsidiary of Biostate AI.*

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license
