Computational Tools: Introduction to MCMC and Bayesian Software
What you'll learn: How to compute Bayesian posteriors when conjugate priors aren't available, using Markov Chain Monte Carlo methods and modern software.
Why We Need Computational Methods
So far, you've worked with conjugate priors (Beta-Binomial, Normal-Normal) where the posterior has a nice, closed-form formula. But most real-world Bayesian models don't have conjugate relationships—the posterior distribution might be impossible to write down analytically. We still know it's proportional to likelihood × prior, but we can't integrate to normalize it or compute expectations directly.
Enter MCMC: Drawing Samples from Complex Posteriors
Markov Chain Monte Carlo (MCMC) methods solve this by generating random samples from the posterior distribution without needing its explicit formula. Think of it like exploring a dark cave with a flashlight: you can't see the whole space at once, but by wandering intelligently (following the Markov chain rules), you'll spend more time in the high-probability regions. After many steps, your collection of visited points accurately represents the posterior.
Popular MCMC algorithms include:
- Metropolis-Hastings: Propose moves, accept or reject based on posterior density ratios
- Gibbs sampling: Update one parameter at a time, cycling through conditionals
- Hamiltonian Monte Carlo (HMC): Uses gradient information for efficient exploration
Bayesian Software Packages
Modern tools make MCMC accessible:
- JAGS/BUGS: Specify models in a simple language; software runs Gibbs sampling
- Stan: Uses HMC for faster convergence; popular in research
- PyMC, NIMBLE: Flexible, programmable frameworks
These packages let you define your prior, likelihood, and data—then automatically generate posterior samples you can summarize (posterior means, credible intervals, etc.).
Key Takeaway: When analytical posteriors are intractable, MCMC methods generate representative samples from the posterior distribution, and modern Bayesian software automates this process for complex models.