Concept Architecture
Gibbs Sampling in Bayesian Evidence Synthesis and Decision Models
Gibbs sampling simulates a Bayesian posterior distribution by breaking one hard sampling problem into a sequence of easier ones, updating one parameter or block of parameters at a time while the rest stay at their latest values. After enough cycles the stored values behave like correlated draws from the joint posterior. In health economics it sits behind many of the Bayesian evidence syntheses that feed decision models, because the BUGS family of software, used for the meta-analysis code in NICE Decision Support Unit Technical Support Document 2 (TSD 2), was built around it. Its draws are dependent, and strong correlation between parameters can make the chain crawl.
One parameter at a time from its full conditional
Gelman and colleagues, in Bayesian Data Analysis, describe the Gibbs sampler as a Markov chain Monte Carlo method that divides the parameter vector into components and, in each iteration, draws each component conditional on the value of all the others. With components there are steps per iteration.
where is the th component or block of the parameter vector, is the iteration number, is the observed data, and the conditioning set holds components already updated in iteration at their new values and the rest at their iteration values. The right-hand side is the full conditional, the posterior distribution of with everything else treated as known.
After warm-up, posterior quantities are estimated by averaging over the retained draws.
where is the number of draws kept after warm-up, is the parameter vector at retained iteration , and is any function of interest, such as a relative treatment effect or an incremental net benefit.
Why no draw is ever rejected
Gelman and colleagues show that Gibbs sampling is a special case of Metropolis-Hastings in which the proposal for each step is the full conditional itself. The acceptance ratio then equals 1 at every step, so every jump is accepted. A Gibbs sampler therefore has no proposal scale to tune, at the price that each full conditional must be available in a form that can be sampled.
Conditional conjugacy and the models that suit it
Many models in health economics are built as a chain of conditional distributions, such as trial-level effects drawn from a population distribution in a hierarchical model. Gelman and colleagues note that the conditional distributions in such models are often conjugate and easy to simulate, and they call the Gibbs sampler their first choice for conditionally conjugate models. Where some conditionals are standard and others are not, the sampler can use exact Gibbs draws where possible and one-dimensional Metropolis updates elsewhere.
Plummer, introducing JAGS, notes that BUGS stands for Bayesian inference Using Gibbs Sampling and that it made models with random effects, measurement error and missing data accessible to a wide audience.
Unobserved quantities can also be added to the parameter vector, which Gelman and colleagues call data augmentation, with indicators for a mixture model as one example. They trace the name of the sampler to Geman and Geman, whose 1984 image restoration paper made local changes by sampling from a local conditional probability distribution.
Worked example with an illustrative mean cost
All numbers in this example are illustrative. A cost model needs the mean annual cost per patient of a new care pathway, in GBP thousands, from patients with sample mean 4.0 and standard deviation 2.0. Costs are modelled as normal with unknown mean and precision , the inverse of the variance. The prior for is normal with mean 3.0 and standard deviation 2.0, and the prior for is gamma with shape 1 and rate 1. With these two independent priors the joint posterior has no standard form, but each full conditional does.
where is the prior mean, is the prior precision, is the sample mean, and the second argument is the conditional variance. This is the textbook normal result, in which posterior precision is prior plus data precision and the posterior mean is a precision-weighted average.
where and are the prior shape and rate, is the sample standard deviation, so , and is the sum of squared deviations of the costs from the current value of .
1. Iteration 1, update the mean. Starting from , a variance of 5, the conditional precision is 0.25 + 20 × 0.20 = 4.25. The numerator of the conditional mean is 0.25 × 3.0 + 20 × 0.20 × 4.0 = 16.75, so the mean is 16.75 / 4.25 = 3.941, with standard deviation . A standard normal draw of 0.40 gives = 3.941 + 0.40 × 0.485 = 4.135.
2. Iteration 1, update the precision. With = 4.135 the gap to the sample mean is 0.135, whose square is 0.0182, so = 76 + 20 × 0.0182 = 76.36. The gamma conditional has shape 1 + 10 = 11 and rate 1 + 76.36 / 2 = 39.18, so its mean is 11 / 39.18 = 0.281. Suppose the draw is 0.270, a variance of 1 / 0.270 = 3.70.
3. Iteration 2, update the mean. The precision is now 0.25 + 20 × 0.270 = 5.65. The numerator is 0.75 + 20 × 0.270 × 4.0 = 22.35, so the conditional mean is 22.35 / 5.65 = 3.956, with standard deviation . A standard normal draw of minus 1.10 moves the mean down by 1.10 × 0.421 = 0.463, giving = 3.956 minus 0.463, or 3.493.
4. Iteration 2, update the precision. The gap to the sample mean is 0.507, whose square is 0.257, so = 76 + 20 × 0.257 = 81.14 and the gamma conditional has shape 11 and rate 1 + 81.14 / 2 = 41.57, with mean 11 / 41.57 = 0.265.
5. Run and summarise. The exact marginal posterior, found by numerical integration, has mean 3.95 for and a 95% central credible interval of 3.07 to 4.82, that is GBP 3,070 to GBP 4,820, and one run of 60,000 iterations with the first 10,000 discarded as warm-up matched each figure to within 0.01. A rough check agrees. At a cost precision near 0.25 the data precision is about 20 × 0.25 = 5 against a prior precision of 0.25, so the data carry weight 5 / 5.25 = 0.952 and 0.952 × 4.0 + 0.048 × 3.0 = 3.95.
The mean is pulled slightly below the sample mean of 4.0 towards the prior mean of 3.0. Each retained value of already averages over the uncertainty in , and those draws, not a summary mean and interval, are what a probabilistic decision model would take as its cost input. Another run would give slightly different decimals because of Monte Carlo error.
Correlated parameters slow the chain
Updating one component at a time works badly when components are strongly correlated in the posterior. Gelman and colleagues show this with a bivariate normal posterior with unit variances, correlation and data at zero, where the two full conditionals are normal with means and and variance one minus . Substituting one update into the next shows how much each sweep remembers.
where and are independent normal errors with mean zero and variance one minus . The chain for therefore has autocorrelation at lag . Gelman and colleagues define the effective number of draws in terms of these autocorrelations.
where is the number of retained draws, is the lag- autocorrelation and is the number of independent draws carrying the same information about the mean. The second form uses the sum of the geometric series .
| Posterior correlation | Lag-1 autocorrelation | Draws per independent draw | Effective draws from 10,000 |
|---|---|---|---|
| 0.80 | 0.64 | 1.64 / 0.36 = 4.56 | 2,195 |
| 0.95 | 0.9025 | 1.9025 / 0.0975 = 19.5 | 512 |
| 0.99 | 0.9801 | 1.9801 / 0.0199 = 99.5 | 100 |
Spiegelhalter notes that baseline levels and treatment differences estimated from the same studies are likely to be strongly correlated, and TSD 2 advises choosing a reference treatment at the centre of a network meta-analysis to reduce correlations between treatment effects that can slow convergence. Gelman and colleagues note that the Gibbs sampler is most efficient when parameterised in terms of independent components. Remedies include linear reparameterisation, updating correlated parameters as one block, parameter expansion, or Hamiltonian Monte Carlo, which they describe as mixing faster in high dimensions. Diagnostics for MCMC output are covered under convergence.
Gibbs sampling in HTA evidence synthesis
TSD 2 notes that Bayesian MCMC has for many years been a mainstay of decision analysis and gives code for WinBUGS 1.4.3. Its beta-blocker results are based on 20,000 iterations on 3 chains after a burn-in of 10,000.
Posterior sampling also keeps the correlation induced by estimating parameters from the same data, and TSD 2 states that where the evidence contains closed loops the posterior samples should be used in the decision model, or the correlations otherwise propagated, because distributions based on the marginal summaries are not adequate. Spiegelhalter calls this the integrated approach, generally implemented with MCMC, and contrasts it with fitting distributions first and then propagating them in a probabilistic sensitivity analysis. The integrated route needs no parametric shapes for the posteriors and carries the dependence between unknowns.
Beyond meta-analysis, Sharples used the Gibbs sampler to estimate posterior distributions of transition rates between grades of coronary disease after cardiac transplantation, modelled as a continuous-time Markov process, the kind of input a Markov model needs.
Choices that change the output
Starting values and warm-up length decide how much of the early chain reflects the start rather than the posterior, and blocking and parameterisation decide how fast it mixes. Priors on variance parameters need care in sparse networks. TSD 2 describes a vague gamma prior on the precision, such as Gamma(0.001, 0.001), as once popular but since fallen out of favour, and notes that it puts more weight on between-trial standard deviations near zero. Where sparse data make MCMC sampling get stuck at zero, it adds, a gamma prior may improve numerical stability.
How it differs from neighbouring methods
Metropolis-Hastings proposes a whole move and accepts or rejects it, while Gibbs moves one coordinate at a time from the exact conditional and always accepts. Hamiltonian Monte Carlo uses gradients and momentum to travel further per iteration, and Gelman and colleagues describe Stan as implementing it, so Stan is not a Gibbs sampler.
The Monte Carlo step of a probabilistic sensitivity analysis usually takes independent draws from distributions fitted to each input, whereas a Gibbs sampler produces dependent draws from a posterior it is still exploring and often supplies those inputs.
Limitations and common misreadings
Most problems with Gibbs output come from treating the draws as better than they are. The result is a decision model input with the wrong precision or the wrong correlation.
- Treating draws as independent. Consecutive values are correlated, so at a posterior correlation of 0.99, 10,000 iterations carry the information of about 100 independent draws.
- Assuming conditionals are always easy. Logistic regressions and many other models have conditionals with no standard form, so the sampler has to update them another way, for example with Metropolis steps.
- Reading convergence from one chain. A chain stuck in one region can look stable, which is why TSD 2 asks for several chains from dispersed starts.
- Confusing computation with model adequacy. A well-mixed chain describes the posterior of the model as specified, whether or not its likelihood and priors are right.
Sources
- Dias S, Welton NJ, Sutton AJ, Ades AE. NICE DSU Technical Support Document 2: A generalised linear modelling framework for pairwise and network meta-analysis of randomised controlled trials. Decision Support Unit; August 2011, last updated September 2016. Sections 2.1 and 6. https://www.sheffield.ac.uk/sites/default/files/2022-02/TSD2-General-meta-analysis-corrected-2Sep2016v2.pdf
- Gelman A, Carlin JB, Stern HS, Dunson DB, Vehtari A, Rubin DB. Bayesian Data Analysis. 3rd ed. CRC Press; 2013. Sections 2.5, 11.1 to 11.5 and 12.1, the chapter 11 bibliographic note and the chapter 12 introduction. http://www.stat.columbia.edu/~gelman/book/BDA3.pdf
- Geman S, Geman D. Stochastic relaxation, Gibbs distributions, and the Bayesian restoration of images. IEEE Transactions on Pattern Analysis and Machine Intelligence. 1984;PAMI-6(6):721-741. https://doi.org/10.1109/TPAMI.1984.4767596
- Plummer M. JAGS: a program for analysis of Bayesian graphical models using Gibbs sampling. In: Hornik K, Leisch F, Zeileis A, eds. Proceedings of the 3rd International Workshop on Distributed Statistical Computing (DSC 2003). Vienna; 2003. https://www.r-project.org/conferences/DSC-2003/Proceedings/Plummer.pdf
- Sharples LD. Use of the Gibbs sampler to estimate transition rates between grades of coronary disease following cardiac transplantation. Statistics in Medicine. 1993;12(12):1155-1169. https://doi.org/10.1002/sim.4780121205
- Spiegelhalter DJ. Incorporating Bayesian ideas into health-care evaluation. Statistical Science. 2004;19(1):156-174. https://doi.org/10.1214/088342304000000080
Related Concepts (2)
Library
Publications
3
Parameter Estimation and Uncertainty: A Report of the ISPOR-SMDM Modeling Good Research Practices Task Force-6 — Briggs, Weinstein, Fenwick, Karnon, Sculpher & Paltiel, Task Force Report 6 ed., 2012 (Value in Health / Medical Decision Making)
Best-practice guidance on parameter estimation and the characterisation of uncertainty in decision models, covering probabilistic sensitivity analysis, distributional choices, and correlation between parameters.
Journal ArticleView source →Markov Chain Monte Carlo in Practice — W. R. Gilks, S. Richardson & D. J. Spiegelhalter (editors), 1st Edition ed., 1996 (Chapman & Hall)
A foundational collection on Markov chain Monte Carlo methodology and practice, linking stochastic simulation with Bayesian inference and Gibbs sampling.
BookView source →The BUGS Book: A Practical Introduction to Bayesian Analysis — David Lunn, Chris Jackson, Nicky Best, Andrew Thomas & David Spiegelhalter, 1st Edition ed., 2012 (Chapman & Hall / CRC Press)
A practical guide to Bayesian modeling with BUGS, covering prior specification, posterior simulation, model checking and Markov chain Monte Carlo computation.
BookView source →
Frequently Asked Questions (6)
What is Gibbs sampling?
Gibbs sampling is a Markov chain Monte Carlo method that fits Bayesian models, such as meta-analyses, by drawing each parameter in turn given the others.
Source: Gelman et al. 2013
What problem does Gibbs sampling address?
Bayesian models used in health economics, such as hierarchical meta-analyses, often give a joint posterior distribution with no standard form, so values cannot be drawn from it directly. Gibbs sampling replaces that single hard problem with a sequence of easier ones. Each parameter, or block of parameters, is drawn from its full conditional distribution, the posterior for that parameter with every other parameter held at its latest value. Gelman and colleagues note that in models built from a chain of conditional distributions these conditionals are often conjugate and easy to simulate. After enough cycles the stored values behave like correlated draws from the joint posterior, which can then be summarised or passed to a decision model.
Source: Gelman et al. 2013
How does Gibbs sampling work?
The sampler starts from initial values for every parameter and then updates the parameters in turn within each iteration. Each update draws a new value from that parameter's full conditional distribution, using the values already updated in the current iteration and the previous values for the rest, so a model with d components has d steps per iteration. Gelman and colleagues show that this is a special case of Metropolis-Hastings in which the proposal is the full conditional itself, so the acceptance ratio is 1 and no draw is rejected. Draws from an initial warm-up period are discarded, and posterior quantities are then estimated by averaging over the retained draws.
Source: Gelman et al. 2013
When is Gibbs sampling used?
In health economics, Gibbs sampling is mostly used to fit Bayesian evidence syntheses, such as pairwise and network meta-analyses, whose results feed decision models. NICE DSU Technical Support Document 2 describes Bayesian Markov chain Monte Carlo as a long-standing mainstay of decision analysis and gives its meta-analysis code for WinBUGS, software from the BUGS family that was built around Gibbs sampling. Its beta-blocker example reports results from 20,000 iterations on 3 chains after a burn-in of 10,000. Where the evidence network contains closed loops, the document advises using the posterior samples in the decision model, or otherwise propagating the correlations, because distributions based on marginal summaries are not adequate.
Source: Dias et al. 2011
What is the advantage of Gibbs sampling?
Because each proposal is drawn from the exact full conditional distribution, Gibbs sampling accepts every draw and has no proposal scale to tune, unlike a general Metropolis-Hastings sampler. Gelman and colleagues call it their first choice for conditionally conjugate models, a class that includes many of the hierarchical models used in evidence synthesis. Where only some conditionals have a standard form, exact Gibbs draws can still be used for those parameters and one-dimensional Metropolis updates for the rest. Unobserved quantities, such as group indicators in a mixture model, can also be added to the parameter vector so that the conditionals become easy to sample, a device known as data augmentation.
Source: Gelman et al. 2013
What are the limitations of Gibbs sampling?
Gibbs sampling mixes slowly when parameters are strongly correlated in the posterior, because each update moves one coordinate at a time. In the bivariate normal case analysed by Gelman and colleagues, a posterior correlation of 0.99 means that 10,000 iterations carry about the information of 100 independent draws. Every full conditional must also be available in a form that can be sampled, and models such as logistic regressions need another kind of update for some parameters, for example Metropolis steps. Consecutive draws are dependent, so treating them as independent overstates precision. Remedies include updating correlated parameters as one block or switching to Hamiltonian Monte Carlo, which Gelman and colleagues describe as mixing faster in high dimensions.
Source: Gelman et al. 2013
Trust Record
Verified by Dr Darrin Baines
British health economist
Professional identity: darrinbaines.org
Verification date: 26 Oct 2026
Content version: 1.0.1
Canonical Identity
- Persistent URI
- https://healtheconomics.wiki/concept/gibbs-sampling
- Term code
- HE-EM-MP-016
Stable URI · Machine-readable · Resolvable · CC BY 4.0
