Introduction to Bayesian Graphical Models

Published: December 2025 · 10 min read

Authors: Shravan Goswami, Hong Ge, and Xianda Sun

Bayesian graphical models represent a powerful framework for reasoning under uncertainty. They combine the mathematical rigor of probability theory with the intuitive representation of dependencies through directed graphs. In this article, we will explore the core concepts, learn how to visualize them, and examine real-world examples.

What are Graphical Models?

A graphical model is a probabilistic model where a graph expresses the conditional dependence structure between random variables. The graph consists of nodes representing variables and edges representing probabilistic dependencies between them.

"The great power of graphical models lies in their ability to represent complex joint probability distributions through simple local relationships."

There are two main types of graphical models: directed graphical models (also known as Bayesian networks) and undirected graphical models (also known as Markov random fields). We focus here on directed acyclic graphs (DAGs).

Pumps: conjugate gamma-Poisson hierarchical model

To understand the utility of these models, let's look at the Pumps example [1]. This model analyzes the failure rates of 10 pumps in a nuclear power plant.

This is a conjugate gamma-Poisson hierarchical model. The number of failures ($x_i$) for each pump is modeled using a Poisson distribution: $x_i \sim \text{Poisson}(\theta_i t_i)$. Crucially, the failure rates ($\theta_i$) are drawn from a common Gamma prior, $\theta_i \sim \text{Gamma}(\alpha, \beta)$, with hyperparameters $\alpha$ and $\beta$ given Exponential and Gamma priors respectively. This structure leads to a non-standard posterior for $\alpha$, necessitating the use of Gibbs sampling.

Rats: a normal hierarchical model

Now let's look at a temporal model [2]. The Rats example tracks the weight of 30 rats measured weekly over five weeks.

This is a random effects linear growth curve model. The weights $Y_{ij}$ are normally distributed with a mean that is a linear function of time: $\alpha_i + \beta_i(x_j - \bar{x})$. Note that the time points $x_j$ are standardized around their mean ($\bar{x} = 22$) to reduce dependence between the intercept $\alpha_i$ and slope $\beta_i$. We estimate these random effects to capture both individual trajectories and population-level growth.

Why Use Graphical Models?

As seen in the examples above, graphical models offer distinct advantages:

Interpretability: The visual structure makes it easy to understand the relationships between variables. In the Rats model, seeing the connection between the population mean and individual rats helps clarify the hierarchical assumption.

Modularity: Complex models can be built from simpler components. We can easily add a new layer to our hierarchy without rewriting the entire mathematical derivation.

Seeds: Random effect logistic regression

Finally, let's look at a random effects logistic regression [3]. The Seeds example investigates germination rates across 21 plates arranged in a 2x2 factorial design by seed type and root extract.

The model accounts for overdispersion—variation greater than expected in a standard Binomial distribution—by introducing a random effect term $b_i$ for each plate. The probability of germination is modeled as $\text{logit}(p_i) = \alpha_0 + \alpha_1 x_{1i} + \alpha_2 x_{2i} + \alpha_{12} x_{1i}x_{2i} + b_i$, where $b_i \sim \text{Normal}(0, \tau)$, effectively capturing the unobserved heterogeneity.

Under the Hood: The BUGS Language

BUGS (Bayesian inference Using Gibbs Sampling) is a probabilistic programming language for specifying statistical models. The visual representations in the widgets above are automatically converted to valid BUGS code that can be executed in various inference engines.

For example, a simple hierarchical model might look like this:

model {
  for (i in 1:N) {
    y[i] ~ dnorm(mu, tau)
  }
  mu ~ dnorm(0, 0.001)
  tau ~ dgamma(0.001, 0.001)
}

Getting Started with JuliaBUGS

JuliaBUGS is a Julia implementation of the BUGS language that provides efficient inference for Bayesian graphical models. Combined with the DoodlePPL visual editor, it offers a complete workflow from model design to inference.

The widgets you see above are designed to integrate seamlessly with JuliaBUGS, allowing you to export your visual models as executable Julia code. This bridges the gap between intuitive model building and production-ready code.

DoodleWidget as Compound Documents

DoodleWidget implements the concept of compound documents [6]—interactive documents that combine formatted text, mathematical notation, visualizations, and executable models in a single interface. Unlike traditional workflows that require switching between separate programs for writing, modeling, and visualization, DoodleWidget provides an integrated environment where all these tools are readily available. You can build graphical models, view generated code, input data, and interact with the complete modeling workflow without leaving the document.

Conclusion

Bayesian graphical models provide a principled way to reason about uncertainty. With tools like DoodlePPL and JuliaBUGS, building and running these models has never been more accessible. We encourage you to explore the interactive widgets above to deepen your understanding of probabilistic modeling.

References

  1. George, E. I., Makov, U. E., & Smith, A. F. M. (1993). Conjugate likelihood distributions. Scandinavian Journal of Statistics, 20(2), 147-156.
  2. Gelfand, A. E., Hills, S. E., Racine-Poon, A., & Smith, A. F. M. (1990). Illustration of Bayesian inference in normal data models using Gibbs sampling. Journal of the American Statistical Association, 85(412), 972-985.
  3. Crowder, M. J. (1978). Beta-binomial ANOVA for proportions. Applied Statistics, 27(1), 34-37.
  4. Koller, D., & Friedman, N. (2009). Probabilistic Graphical Models: Principles and Techniques. MIT Press. [PDF]
  5. OpenBUGS Examples Volume I. [Link]
  6. OpenBUGS Compound Documents Manual. [Link]

Note: The examples and descriptions in this article are adapted from the classic BUGS examples collection [5], originally distributed with WinBUGS as part of the MRC Biostatistics Unit research at Cambridge.