- Introduced by
- Koller, Friedman, and colleagues
- Year
- 1990s–2000s
- Type
- probabilistic graphical model
- Family
- Bayesian / computational
What does it do?
A hierarchical Bayesian network is a probabilistic graphical model in which variables are organised across two or more levels, and higher-level nodes set the prior distributions of lower-level nodes through hyperparameters.
This allows information to be shared across groups, contexts, or data subsets while the model keeps the directed acyclic graph (DAG) representation of conditional dependencies.
The intuition behind the method
Think of a company with multiple regional offices, each collecting customer data. A flat Bayesian network would model each office independently. A hierarchical Bayesian network adds a top level representing company-wide tendencies that shape each regional model. Information is shared upward and downward through the hierarchy: offices with sparse data borrow strength from the global level, while offices with rich data pull the global estimate toward their own evidence. The graph encodes both the within-level dependencies and the between-level governing structure.
History
Bayesian networks as a formalism are commonly traced to early work on probabilistic reasoning in artificial intelligence. The hierarchical extension combines this formalism with multi-level Bayesian modelling and has no single dated origin. Koller and Friedman (2009) give a textbook treatment of probabilistic graphical models, including the Bayesian network framework on which this model is built. Friedman et al. (1999) concern learning probabilistic relational models, a related but distinct formalism.
When to use it
Use a hierarchical Bayesian network when data are naturally grouped (patients within hospitals, students within schools, items within categories) and you want to share information across groups while keeping group-specific estimates. It is especially valuable when some groups have sparse data and would benefit from borrowing strength from the global level. Do not use it when the hierarchy is not motivated by the data-generating process, because an unnecessary hierarchy adds computational cost and can over-smooth genuinely distinct groups. Avoid it when a flat Bayesian network or a simpler hierarchical regression is sufficient.
Limitations and considerations
- The hierarchy, including which variables sit at which level and which groups share a hyperparameter, must be fixed before fitting; a wrong grouping structure biases estimates at every level.
- Posteriors rarely have closed forms, so fitting relies on MCMC or variational approximations whose cost grows with the number of nodes and levels.
- When data are sparse, hyperparameters and group-level parameters are often strongly correlated, which can slow MCMC mixing and makes convergence checks necessary at every level.
- Interpreting joint uncertainty across many levels of parameters is harder than interpreting a single-level network.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Partial pooling shrinks group-level estimates toward a shared hyperparameter distribution, which stabilises estimates for groups with little data while still allowing groups to differ.
- Hyperparameter uncertainty propagates into group-level and new-group predictions, so the predictive uncertainty reflects the shared layer as well as the group data.
- Each CPD is specified separately, so domain knowledge can be encoded at each level rather than in a single global prior.
- The DAG states which variables are conditionally independent given their parents, so these assumptions can be inspected directly in the graph.
Applications
- Medical diagnosis across multiple hospital sites, pooling case data while preserving site-specific disease prevalence.
- Educational assessment models that estimate student ability within schools and schools within districts.
- Natural language processing models with hierarchical priors over topic or word distributions across document collections.
- Genomics studies linking gene-level observations to pathway-level and organism-level latent factors.
- Sensor networks where device-level readings are governed by shared environmental hyperparameters.
- Risk modelling in insurance or finance where claims from many sub-portfolios share an industry-level prior.
How it works
How it works
Define a directed acyclic graph whose nodes span two or more hierarchical levels. Top-level nodes represent hyperparameters or latent factors shared by all groups. Mid- and bottom-level nodes represent group-specific parameters and observed variables. Each node is conditionally independent of its non-descendants given its parents, and the graph makes these independence assumptions visible.
Assign hyperprior distributions to the top-level nodes. The hyperpriors govern the prior distributions of lower-level parameters, which expresses the assumption that parameters in different groups are drawn from a shared population distribution. The marginal prior on a group-specific parameter, p(θ) = ∫ p(θ | α) p(α) dα, integrates over the hyperparameters α.
Formula
p(\theta) = \int p(\theta \mid \alpha)\, p(\alpha)\, d\alpha
Specify the conditional probability distribution (CPD) of each observed node given its parents, written p(X | pa(X), θ_X). For continuous variables a Gaussian CPD is common; for discrete variables a categorical or Dirichlet-multinomial CPD is common. The CPD at each level is parameterised by the variables above it in the hierarchy. As a simple two-level illustration, let observations y_ij in group j follow N(θ_j, σ²), with group means θ_j ~ N(μ, τ²), and treat the hyperparameters μ and τ as given. The posterior mean of θ_j is then (1 − B_j) ȳ_j + B_j μ, where ȳ_j is the mean of the n_j observations in group j and B_j = (σ²/n_j) / (σ²/n_j + τ²). Groups with few observations (large B_j) are pulled toward μ, while groups with many observations stay close to their own means. This is the partial pooling behaviour described above. The example is a standard conjugate result for this simple model, not a general property of every hierarchical network.
Formula
p(X \mid pa(X), \theta_X)
The posterior over the latent parameters and hyperparameters is proportional to the likelihood p(x | θ) times the conditional prior p(θ | α) times the hyperprior p(α). With more levels, the product extends over every CPD and hyperprior in the graph. The marginal posterior of a single parameter requires integrating out the hyperparameters, which is generally intractable. The joint posterior is therefore usually approximated by MCMC (for example Gibbs sampling or Hamiltonian Monte Carlo) or by variational inference.
Formula
p(\theta \mid \mathbf{x}) \propto p(\mathbf{x} \mid \theta)\, p(\theta \mid \alpha)\, p(\alpha)After sampling or approximating the posterior, answer a query about any variable by marginalising over the unobserved nodes. For a new group, the prediction integrates over the posterior of the hyperparameters, so it typically falls between a fully pooled estimate and a fully group-specific estimate.
Common pitfalls
- Adding levels without a reason tied to how the data were generated; an unnecessary hierarchy inflates complexity and can over-smooth distinct groups.
- Checking convergence only for top-level parameters. Diagnostics such as R-hat and effective sample size should be inspected for the hyperparameters and for the group-level parameters. As common practice, aim for R-hat close to 1, adequate effective sample size for each parameter of interest, and few or no divergent transitions under Hamiltonian Monte Carlo, and run prior predictive checks before fitting.
- Using vague hyperpriors when there are few groups, which can leave the between-group variance poorly constrained and the posterior unstable.
- Using a centred parameterisation of group-level parameters when data are sparse, which can produce funnel-shaped posteriors that samplers explore poorly; a non-centred reparameterisation is a common remedy.
- Treating a hierarchical Bayesian network as a plain Bayesian network with more nodes. The defining feature is the hyperparameter layer that governs lower-level distributions, not the size of the graph.
Frequently asked questions
How does a hierarchical Bayesian network differ from a plain Bayesian network?
A plain Bayesian network has one level of nodes with fixed or estimated parameters. A hierarchical Bayesian network adds one or more layers of hyperparameter nodes whose distributions govern the parameters of lower nodes. This enables partial pooling of information across groups and explicit modelling of between-group variation.
What is plate notation and how does it relate to this model?
Plate notation is a compact convention for drawing repeated substructures in a Bayesian network: a rectangle (plate) around a set of nodes indicates they are replicated for each group or observation. Plates are a common way to draw hierarchical models without writing out every node.
Can I use variational inference instead of MCMC for large hierarchical networks?
Yes. Mean-field variational inference and its structured variants, such as stochastic variational inference, scale to large networks where full MCMC is impractical. Variational posteriors are approximations and can understate posterior uncertainty, so comparing them with MCMC results on a smaller version of the model is advisable.
When does partial pooling hurt rather than help?
Partial pooling can over-smooth estimates when groups genuinely differ. If between-group variance is large, the hierarchical prior pulls group estimates toward the global mean more than the data justify. Adding group-level covariates as predictors of the hyperparameters is one way to let the model explain between-group differences instead of shrinking them; whether this helps depends on the data and should be checked.
What software packages support hierarchical Bayesian networks?
Stan (through RStan or PyStan), PyMC and JAGS can all be used to specify multi-level models with custom hierarchical structure. pgmpy and bnlearn provide general Bayesian network tooling; check their documentation for support of hierarchical priors before relying on them.
Related methods
Sources
Koller, D. & Friedman, N. (2009). Probabilistic Graphical Models: Principles and Techniques. MIT Press.
ISBN: 978-0262013192Friedman, N., Getoor, L., Koller, D. & Pfeffer, A. (1999). Learning probabilistic relational models. Proceedings of the 16th International Joint Conference on Artificial Intelligence (IJCAI-99), 1300-1307.
Open publication reference