In a previous post, we showed that Bayesian hierarchical models (BHMs) win when group structure is describable, Bayesian neural networks (BNNs) win when the signal is complex, and their ensemble hedges across both scenarios.

It has been revealed that but what about the case where your data has both — known group structure and complex nonlinear signal? Neither the BHM nor the BNN is ideal:.

In a recent development, enter the hierarchical Bayesian neural network (HBNN) — a model that combines partial pooling over groups with a flexible neural network function class. This post adds the HBNN to our comparison and reveals when each of the four approaches excels.

The HBNN adds partially-pooled group intercepts to the neural network. The non-centered parameterization lets Stan explore the posterior efficiently:.

Sources indicate that line by line, this is a BNN with one addition: alpha[g[n]] — a group-specific intercept drawn from a learned population distribution. The neural network learns the shared nonlinear signal f(x), and the hierarchical intercepts capture group-level shifts. Each component does what it's best at.

The signal is linear and the heterogeneity is in group-specific intercepts and slopes. The BHM is perfectly specified — its functional form matches the DGP exactly. The HBNN's neural network component adds unnecessary flexibility here, making it a close second but slightly less efficient due to the additional parameters.

It has been revealed that no group-level heterogeneity — the group labels are noise. Both the BHM and the HBNN waste capacity estimating group intercepts that don't exist, but the BNN focuses entirely on learning the nonlinear signal. The HBNN is close because partial pooling drives the unnecessary group intercepts toward zero, but the BNN's simpler parameterization gives it an edge.

It has been revealed that now the data has both group-specific offsets and a complex nonlinear signal. This is the scenario the HBNN was built for:.

↓ Lower CRPS = lower out-of-sample prediction error (winner).

The HBNN isn't always the best model — it's the best model when the data has the structure it's designed for. That's the No Free Lunch theorem in action: every model has a niche, and the art is matching the model to the problem.

Recent findings suggest that in domains like portfolio optimization, clinical trials, and marketing mix modeling, the data often has exactly this structure: known grouping variables (sectors, treatment arms, channels) with complex nonlinear effects. The HBNN architecture — encoding the structure you know and learning the rest — represents a principled middle ground between pure specification and pure flexibility.

According to recent reports, the complete R script is available at hbnn_comparison_reprex.R. It requires cmdstanr, scoringRules, and tidyverse. Runtime is approximately 4–5 minutes.

→ Read original article