Exploiting conjugate prior pairs for efficient Gibbs sampling.
mcmc
sampling
bayesian
Demonstrates Gibbs sampling that exploits conjugate prior pairs like Beta-Binomial. Shows how conditional posteriors simplify to known distributions, making each Gibbs step a direct sample from a standard distribution.
Published
April 23, 2025
Gibbs with conditional a conjugate
%matplotlib inlineimport numpy as npfrom scipy import statsfrom scipy.stats import norm, gammafrom scipy.stats import distributionsimport matplotlib.pyplot as pltimport seaborn as snsimport timesns.set_style('whitegrid')sns.set_context('poster')
//anaconda/envs/py35/lib/python3.5/site-packages/matplotlib/__init__.py:872: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
warnings.warn(self.msg_depr % (key, alt_key))
We now going to take a look at a slightly more complicated case that was originally outlined in full generality by Casella and George (1992). Suppose we have a nasty looking joint distribution given as:
\[p(x,y) = \binom{16}{y} x^{y+1} (1-x)^{19-y}\]
Looks like a binomial
For such a situation the two conditional distributions are not exactly obvious. Clearly we have a binomial term staring at us, so we should be looking to try and express part of the function as a binomial of the form,