# 分层贝叶斯分析

分层贝叶斯分析是一种统计建模方法，其中参数被赋予先验分布，而这些先验分布本身又按多个层级组织，从而在贝叶斯推断过程中实现数据组间的部分信息汇聚。它用于估计与预测问题，其中观测数据按组、个体、站点或研究组织，且分别估计每一组会噪声过大，而假设所有组完全相同又过于僵硬。

| 关键事实 | 详情 |
| --- | --- |
| 核心机制 | 部分汇聚：完全汇聚（一个共享效应）与不汇聚（每组单独估计）之间的折中 <sup>[1](https://stat.columbia.edu/~gelman/research/published/multiple2f.pdf)</sup> |
| 模型结构 | 参数被组织为可交换的组，从共享的父组中汲取共同的先验信息 <sup>[2](https://ar5iv.labs.arxiv.org/html/1312.0906)</sup> |
| 超先验 | 完全贝叶斯分层模型还对总体分布的超参数放置先验 <sup>[3](https://vioshyvo.github.io/Bayesian_inference/hierarchical-models.html)</sup> |
| 汇聚强度 | 由总体模型 \( \pi(\theta_{k} \mid \phi) \) 的形状决定；窄的总体模型强制强汇聚 <sup>[4](https://betanalpha.github.io/assets/case_studies/hierarchical_modeling.html)</sup> |
| 收敛标准 | \( \hat{R} \) 不应超过 1.01；每条链的有效样本量至少 100（四条链为 400） <sup>[5](https://link.springer.com/article/10.3758/s13428-023-02204-3)</sup> |
| 主要病态 | 数据稀疏时后验呈漏斗形，在八校风格的例子中 HMC 发散聚集在尺度参数 \( \tau \) 的小值处 <sup>[2](https://ar5iv.labs.arxiv.org/html/1312.0906)</sup><sup> • </sup><sup>[6](https://betanalpha.github.io/assets/case_studies/divergences_and_bias.html)</sup> |
| 奠基论文 | D. V. Lindley 与 A. F. M. Smith，“Bayes Estimates for the Linear Model”（1972） <sup>[7](https://doi.org/10.1111/j.2517-6161.1972.tb00885.x)</sup> |

## 工作原理

分层模型为每一组观测分配各自的参数，例如组特定效应 \( \theta_{j} \)，然后将这些组级参数视为从共同总体分布中抽取的样本，该总体分布由超均值 \( \beta \) 和超协方差矩阵 \( V \) 等超参数控制。在多级正态模型中，对于 \( i = 1, \ldots, m \)，这写作 \( X_{i} \sim N_{k}(\theta_{i}, I) \) 和 \( \theta_{i} \sim N_{k}(\beta, V) \)。<sup>[8](https://www2.stat.duke.edu/~berger/papers/tang.pdf)</sup> 各层级之间的交互使各组能够相互学习而不牺牲各自的独特情境，通过部分汇聚数据来改进推断。<sup>[2](https://ar5iv.labs.arxiv.org/html/1312.0906)</sup>

汇聚行为介于两个极端之间。完全汇聚假设处理效应在所有站点相同，即对所有 \( j \) 有 \( \delta_{j} = \delta \)；不汇聚为每个站点分别估计处理效应；多级折中称为部分汇聚。<sup>[1](https://stat.columbia.edu/~gelman/research/published/multiple2f.pdf)</sup> 部分汇聚不是膨胀不确定性估计，而是将点估计相互拉近并拉向跨站点的总体效应。<sup>[1](https://stat.columbia.edu/~gelman/research/published/multiple2f.pdf)</sup> 当模型包含组级预测变量时，推断结果向拟合的组级回归曲面而非共同均值部分汇聚。<sup>[1](https://stat.columbia.edu/~gelman/research/published/multiple2f.pdf)</sup>

可交换性是分层模型中一种常见的建模假设：当组级参数的联合分布对组的置换不变时，它们是可交换的，即在给定共享参数和任何纳入的预测变量的条件下，没有哪一组因排序、时间或分组而与其他组区分开来；其他分层模型则明确表示不可交换的结构。<sup>[9](https://users.aalto.fi/~ave/BDA3.pdf)</sup> 汇聚的强度由总体模型 \( \pi(\theta_{k} \mid \phi) \) 的形状决定；窄的总体模型强制跨情境的强汇聚，在总体模型无限窄的极限下汇聚变为完全汇聚。<sup>[4](https://betanalpha.github.io/assets/case_studies/hierarchical_modeling.html)</sup> 在完全贝叶斯处理中，由数据估计的总体分布方差决定抽样分布参数向共同均值收缩的程度。<sup>[3](https://vioshyvo.github.io/Bayesian_inference/hierarchical-models.html)</sup>

## 实施方法

实践者的工作流程从模型设定到采样再到检查：

1. **设定模型。** 写出每组的似然、组级参数上的总体分布，以及超参数上的先验。
2. **选择采样器。** 哈密顿蒙特卡洛利用微分几何技术生成跨越全边际方差的转移，消除了随机游走 Metropolis 和 Gibbs 采样器固有的随机游走行为。<sup>[2](https://ar5iv.labs.arxiv.org/html/1312.0906)</sup>
3. **调优采样器。** 心理学中分层回归的实用指南报告将 \( \texttt{adapt\_delta} \) 从默认的 0.8 提高到 0.9–0.99，将 \( \texttt{max\_treedepth} \) 从 10 提高到 12–15，以确保采样可处理。<sup>[10](https://www.frontiersin.org/journals/psychology/articles/10.3389/fpsyg.2026.1643463/full)</sup>
4. **检查收敛。** 在分裂形式中，\( \hat{R} \) 比较跨链合并样本的方差（每条链分成两半）与链内样本的平均方差；如果链尚未收敛到共同分布，\( \hat{R} \) 大于 1，当前标准是 \( \hat{R} \) 不应超过 1.01。哈密顿蒙特卡洛中的发散转移表明数值积分问题，应通过发散诊断评估而非从 \( \hat{R} \) 推断。<sup>[5](https://link.springer.com/article/10.3758/s13428-023-02204-3)</sup> 每条链的有效样本量应至少为 100，四条链为 400；批量 ESS 评估后验中心，尾部 ESS 评估尾部。<sup>[5](https://link.springer.com/article/10.3758/s13428-023-02204-3)</sup>
5. **检查模型。** 后验预测检查、后验预测 \( p \) 值、DIC 和 WAIC 在竞争的贝叶斯估计方法之间提供关于模型拟合和预测性能的互补证据。<sup>[11](https://arxiv.org/abs/2512.12857)</sup> 基于模拟的校准由 Sean Talts 及其同事（2018）提出，更一般地验证贝叶斯推断算法。<sup>[12](https://doi.org/10.48550/arxiv.1804.06788)</sup>

## 起源

线性模型的分层贝叶斯表述由 D. V. Lindley 和 A. F. M. Smith 在“Bayes Estimates for the Linear Model”（《皇家统计学会杂志 B 辑》，1972）中报告，该文使用最小二乘变换技巧将线性模型写成可交换形式。<sup>[7](https://doi.org/10.1111/j.2517-6161.1972.tb00885.x)</sup>

该方法所基于的早期工作来自经验贝叶斯传统。“经验贝叶斯”一词由 Herbert Robbins（1955）创造，他在引入时并未显式估计先验分布。<sup>[13](https://files.eric.ed.gov/fulltext/ED395003.pdf)</sup> Charles Stein 在 1955 年（1956 年发表于第 3 届伯克利研讨会论文集）表明，使用来自 \( k \geq 3 \) 个正态总体的各自样本均值来估计其自身总体均值，可以通过将样本均值向常向量收缩，对每个可能的 \( \mu \) 一致地改进。<sup>[14](https://ar5iv.labs.arxiv.org/html/1203.5610)</sup> 为同时估计多个参数发展了技术，所得经验贝叶斯模型也称为分层或多级线性模型。<sup>[13](https://files.eric.ed.gov/fulltext/ED395003.pdf)</sup>

## 变体

**非参数分层。** 分层狄利克雷过程由 Yee Whye Teh 及其同事报告（《美国统计协会杂志》，2006），解决分组数据问题，其中组内每个观测是混合模型的抽取，混合成分数量事先未知，且希望在组间共享混合成分。<sup>[15](https://doi.org/10.1198/016214506000000302)</sup> 其基本构建块是一个递归，其中狄利克雷过程的基础测度本身是狄利克雷过程的抽取，\( G_{0} \sim DP(\gamma, H) \) 且 \( G \sim DP(\alpha, G_{0}) \)。<sup>[16](https://www.stats.ox.ac.uk/%7Eteh/research/npbayes/TehJor2010a.pdf)</sup>

**元分析。** 分层元回归（HMR）方法是一种集成的贝叶斯偏差建模方法，用于在元分析中合并不同证据（如随机和非随机研究）时使用。<sup>[17](https://onlinelibrary.wiley.com/doi/10.1002/bimj.201700266)</sup><sup> • </sup><sup>[18](https://www.intechopen.com/chapters/56655)</sup>

**软件。** Stan、JAGS、PyMC 和 brms 是主要的通用平台。在多级仅截距模型的基准测试中，JAGS 的平均有效样本量为 74,334，Stan 为 86,486，且 Stan 采样 100,000 个值的速度约快一倍。<sup>[19](https://www.mdpi.com/2624-8611/3/4/48)</sup> hbm4ecology 基准给出不同图景：对于简单模型，计入编译时间和预热时 JAGS 大大优于 Stan，但随着模型复杂度增长 JAGS 性能衰减而 Stan 保持稳定。<sup>[20](https://sirs.agrocampus-ouest.fr/bayes_V2/rpackage/articles/stan-jags-performance-comparaison-for-hbmforecology.html)</sup>

## 应用

**认知与行为科学。** 用于群体研究中同时进行模型拟合与比较的分层贝叶斯推断框架显示出比其他方法更小的参数估计误差，包括分层参数估计（HPE）程序，后者根据组统计量正则化个体估计。<sup>[21](https://journals.plos.org/ploscompbiol/article?id=10.1371%2Fjournal.pcbi.1007043)</sup> 贝叶斯分层模型为个体间和个体内变异提供了直观解释，特别适合重复测量设计。<sup>[5](https://link.springer.com/article/10.3758/s13428-023-02204-3)</sup>

**政治学。** 分层贝叶斯 Aldrich–McKelvey 标度法将个体级参数视为来自共同总体分布的样本，其超参数本身也被估计；利用跨个体的信息通常允许在有限数据下更准确地估计个体级参数。<sup>[22](https://www.cambridge.org/core/services/aop-cambridge-core/content/view/3855DB675CCAD44ED480761A1991FF08/S1047198723000189a.pdf/hierarchical_bayesian_aldrichmckelvey_scaling.pdf)</sup>

**联邦学习。** FedHB 是一种分层贝叶斯联邦学习方法，被证明是渐近最优的，并将 FedAvg（McMahan 等，2017）和 FedProx（Li 等，2018）作为特例包含在内。<sup>[23](https://www.jmlr.org/papers/volume26/23-1350/23-1350.pdf)</sup>

## 局限与替代方案

**漏斗几何与发散。** 使强大建模成为可能的同一分层结构也诱发了限制推断性能的严峻病态。<sup>[2](https://ar5iv.labs.arxiv.org/html/1312.0906)</sup> 当数据稀疏时，单层分层模型的密度看起来像一个“漏斗”，在低密度高体积区域下方有高密度低体积区域，任何成功的采样器都必须管理曲率的剧烈变化。<sup>[2](https://ar5iv.labs.arxiv.org/html/1312.0906)</sup> 联合推断超参数 \( \mu \) 和 \( \sigma \) 与组级参数 \( \theta_{1}, \ldots, \theta_{8} \) 允许模型跨组汇聚数据并降低后验方差，但汇聚将后验挤压成阻碍几何遍历性并使 MCMC 估计产生偏差的几何形状。<sup>[6](https://betanalpha.github.io/assets/case_studies/divergences_and_bias.html)</sup> 哈密顿蒙特卡洛中的发散发生在转移遇到极大曲率区域时，例如分层漏斗的开口；在八校风格的例子中，它们聚集在 \( \tau \) 的小值处，此时分层分布和所有组级 \( \theta_{n} \) 被挤压。<sup>[6](https://betanalpha.github.io/assets/case_studies/divergences_and_bias.html)</sup> Neal 漏斗是坏后验几何的典型例子，非中心化参数化改善了八校模型中的采样几何。<sup>[24](https://predictivesciencelab.github.io/advanced-scientific-machine-learning/inverse/hbayes/03_bad_post_geometry.html)</sup>

**诊断并非万无一失。** 在参数众多的分层建模中，更可能出现参数的 \( \hat{R} \) 值超过阈值而参数估计并无问题的情况。<sup>[5](https://link.springer.com/article/10.3758/s13428-023-02204-3)</sup>

**变分替代方案。** 随机变分推断由 Matthew D. Hoffman 及其同事报告（《机器学习研究杂志》，2013），将变分方法扩展到可规模化设置。<sup>[25](https://doi.org/10.5555/2567709.2502622)</sup> 一项 2025 年关于完全贝叶斯分层线性模型的模拟研究发现，变分推断和随机变分推断以 MCMC 计算时间的一小部分恢复全局回归效应和聚类结构，但扭曲后验依赖性并产生不稳定的 WAIC 和 DIC 值。<sup>[11](https://arxiv.org/abs/2512.12857)</sup> 摊销贝叶斯多级模型由 Daniel Habermann 及其同事报告（《贝叶斯分析》，2025），开发神经网络架构，利用多级模型似然的概率分解来实现近乎瞬时的摊销后验推断，并通过基于模拟的校准、后验预测检查以及后验收缩与 Stan 的比较进行验证。<sup>[26](https://paulbuerkner.com/publications/pdf/2025__Habermann_et_al__Bayesian_Analysis.pdf)</sup><sup> • </sup><sup>[12](https://doi.org/10.48550/arxiv.1804.06788)</sup>

## References

1. [Gelman: Multilevel (hierarchical) modeling: what it can and cannot do](https://stat.columbia.edu/~gelman/research/published/multiple2f.pdf)
2. [Hamiltonian Monte Carlo for Hierarchical Models (Betancourt and Girolami)](https://ar5iv.labs.arxiv.org/html/1312.0906)
3. [Bayesian Inference 2019, Chapter 6: Hierarchical models](https://vioshyvo.github.io/Bayesian_inference/hierarchical-models.html)
4. [Hierarchical Modeling (Betancourt case study)](https://betanalpha.github.io/assets/case_studies/hierarchical_modeling.html)
5. [Bayesian hierarchical modeling: an introduction and reassessment (Behavior Research Methods)](https://link.springer.com/article/10.3758/s13428-023-02204-3)
6. [Diagnosing Biased Inference with Divergences](https://betanalpha.github.io/assets/case_studies/divergences_and_bias.html)
7. [D. V. Lindley, A. F. M. Smith (1972). Bayes Estimates for the Linear Model. Journal of the Royal Statistical Society Series B (Statistical Methodology).](https://doi.org/10.1111/j.2517-6161.1972.tb00885.x)
8. [Shrinkage/multilevel normal model paper (Berger and Tang)](https://www2.stat.duke.edu/~berger/papers/tang.pdf)
9. [Bayesian Data Analysis 3 (Gelman et al.), Chapter 5](https://users.aalto.fi/~ave/BDA3.pdf)
10. [Hierarchical Bayesian Regression for experimental psychology: a case study of cognitive control](https://www.frontiersin.org/journals/psychology/articles/10.3389/fpsyg.2026.1643463/full)
11. [Variational Inference for Fully Bayesian Hierarchical Linear Models](https://arxiv.org/abs/2512.12857)
12. [Talts, Sean and colleagues (2018). Validating Bayesian Inference Algorithms with Simulation-Based Calibration. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1804.06788)
13. [Empirical Bayes Methods: A Tool for Exploratory Analysis (Braun, ETS, 1988)](https://files.eric.ed.gov/fulltext/ED395003.pdf)
14. [Shrinkage Estimation in Multilevel Normal Models](https://ar5iv.labs.arxiv.org/html/1203.5610)
15. [Yee Whye Teh and colleagues (2006). Hierarchical Dirichlet Processes. Journal of the American Statistical Association.](https://doi.org/10.1198/016214506000000302)
16. [Hierarchical Bayesian Nonparametric Models with Applications](https://www.stats.ox.ac.uk/%7Eteh/research/npbayes/TehJor2010a.pdf)
17. [The hierarchical metaregression approach and learning from clinical evidence (Biometrical Journal)](https://onlinelibrary.wiley.com/doi/10.1002/bimj.201700266)
18. [Two Examples of Bayesian Evidence Synthesis with the Hierarchical Meta-Regression Approach](https://www.intechopen.com/chapters/56655)
19. [Comparing the MCMC Efficiency of JAGS and Stan for the Multi-Level Intercept-Only Model in the Covariance- and Mean-Based and Classic Parametrization](https://www.mdpi.com/2624-8611/3/4/48)
20. [Stan and Jags performance comparaison for Hierarchical Bayesian Modeling for Ecological Data • hbm4ecology](https://sirs.agrocampus-ouest.fr/bayes_V2/rpackage/articles/stan-jags-performance-comparaison-for-hbmforecology.html)
21. [Hierarchical Bayesian inference for concurrent model fitting and comparison for group studies](https://journals.plos.org/ploscompbiol/article?id=10.1371%2Fjournal.pcbi.1007043)
22. [Hierarchical Bayesian Aldrich–McKelvey Scaling](https://www.cambridge.org/core/services/aop-cambridge-core/content/view/3855DB675CCAD44ED480761A1991FF08/S1047198723000189a.pdf/hierarchical_bayesian_aldrichmckelvey_scaling.pdf)
23. [FedHB: Hierarchical Bayesian Federated Learning](https://www.jmlr.org/papers/volume26/23-1350/23-1350.pdf)
24. [Improving Posterior Geometry, Advanced Scientific Machine Learning](https://predictivesciencelab.github.io/advanced-scientific-machine-learning/inverse/hbayes/03_bad_post_geometry.html)
25. [Matthew D. Hoffman and colleagues (2013). Stochastic variational inference. Journal of Machine Learning Research.](https://doi.org/10.5555/2567709.2502622)
26. [Amortized Bayesian Multilevel Models (Habermann et al., Bayesian Analysis)](https://paulbuerkner.com/publications/pdf/2025__Habermann_et_al__Bayesian_Analysis.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026; Oct 25, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Bayesian statistics

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/hierarchical-bayesian-analysis

English original: https://www.edgepedia.org/hierarchical-bayesian-analysis
