# 后验预测分布

**后验预测分布**是在已观测数据给定的条件下，对新观测值的概率分布；在贝叶斯推断中，它通过将抽样分布对模型参数的后验分布取平均而得到。设观测数据为 \( y \)，未观测数据为 \( \tilde{y} \)，参数为 \( \theta \)，则其密度为

\[ p(\tilde{y} \mid y) = \int p(\tilde{y} \mid \theta) \cdot p(\theta \mid y) \, \mathrm{d}\theta. \]

称之为“后验”，是因为一切都以观测数据 \( y \) 为条件；称之为“预测”，是因为它描述的是不属于训练集的新数据上的行为。<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup> 当预测变量 \( \tilde{x} \) 伴随新观测值时，密度写作 \( p(\tilde{y} \mid \tilde{x}, x, y) \)，且所有量都可以是多维的。<sup>[2](https://mc-stan.org/docs/2_38/stan-users-guide/posterior-prediction.html)</sup>

| 关键事实 | 细节 |
|---|---|
| 定义 | \( p(\tilde{y} \mid y) = \int p(\tilde{y} \mid \theta) \, p(\theta \mid y) \, \mathrm{d}\theta \)，即抽样分布在后验上的平均<sup>[2](https://mc-stan.org/docs/2_38/stan-users-guide/posterior-prediction.html)</sup> |
| 两种不确定性来源 | 抽样不确定性（即使 \( \theta \) 已知，\( \tilde{y} \) 仍有变异）与估计不确定性（\( \theta \) 是由有限样本 \( y \) 估计而来）<sup>[3](https://mc-stan.org/docs/2_31/stan-users-guide/sampling-from-the-posterior-predictive-distribution.html)</sup> |
| 模拟步骤 | 抽取 \( \theta^{(m)} \sim p(\theta \mid y) \)，再抽取 \( \tilde{y}^{(m)} \sim p(y \mid \theta^{(m)}) \)；两个阶段的随机抽取都必不可少<sup>[3](https://mc-stan.org/docs/2_31/stan-users-guide/sampling-from-the-posterior-predictive-distribution.html)</sup> |
| 主要用途 | 后验预测检验：将复制数据集 \( y^{\text{rep}} \) 的统计量与观测数据的同一统计量进行比较<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup> |
| 检验的起源 | Rubin（1984）提出了后验预测检验；Gelman、Meng 和 Stern（1996）将其形式化为经典拟合优度检验的贝叶斯推广<sup>[4](https://stat.columbia.edu/~gelman/research/published/A6n41.pdf)</sup> |
| 已知局限 | 后验预测 p 值对数据使用了两次，可能降低功效且无法控制第一类错误；留出预测检验可避免此问题<sup>[5](https://academic.oup.com/jrsssb/article/86/1/194/7274627)</sup> |
| 先验预测的类比 | 先验预测分布是同一构造在无观测数据时的情形，因此先验预测检验是后验预测检验在无数据时的极限情形<sup>[6](https://mc-stan.org/docs/2_23/stan-users-guide-2_23.pdf)</sup> |

## 两种不确定性来源

积分因式分解的形式将后验预测量所携带的两种不确定性分离开来。因子 \( p(\tilde{y} \mid \theta) \) 贡献抽样不确定性：即使参数精确已知，抽样分布在 \( \tilde{y} \) 上仍有变异。因子 \( p(\theta \mid y) \) 贡献估计不确定性：\( \theta \) 仅由数据样本 \( y \) 估计而来，因此参数本身并非已知。<sup>[3](https://mc-stan.org/docs/2_31/stan-users-guide/sampling-from-the-posterior-predictive-distribution.html)</sup>

这种分离决定了预测必须如何生成。给定后验抽样 \( \theta^{(m)} \sim p(\theta \mid y) \)，每个复制观测值都从代入该参数抽样的抽样分布中随机抽取，即 \( \tilde{y}^{(m)} \sim p(y \mid \theta^{(m)}) \)。在第二阶段随机抽取 \( \tilde{y} \) 至关重要；若只代入单个拟合参数值并读取点预测，则只能捕捉到不确定性的一部分。<sup>[3](https://mc-stan.org/docs/2_31/stan-users-guide/sampling-from-the-posterior-predictive-distribution.html)</sup>

## 实际模拟

在 Stan 中，复制在 `generated quantities` 块中编写，该块在每次后验抽样后运行。对于参数为 `alpha`、`beta` 和 `sigma`、预测变量为 `x` 的简单线性回归，一行代码即可生成完整的复制数据集：

```
generated quantities {
  array[N] real y_rep = normal_rng(alpha + beta * x, sigma);
}
```

向量化的正态随机数生成器使用原始预测变量和当前参数抽样，因此每个 \( y\_rep \) 在给定参数条件下与观测数据条件独立。<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup><sup> • </sup><sup>[7](https://bob-carpenter.github.io/stan-getting-started/stan-getting-started.html)</sup> 同一机制通过独立的生成量支持事件概率和两阶段推断。<sup>[2](https://mc-stan.org/docs/2_38/stan-users-guide/posterior-prediction.html)</sup> PyMC 提供了专门的函数从后验中采样数据，用于同一目的。<sup>[8](https://www.pymc.io/projects/docs/en/stable/learn/core_notebooks/posterior_predictive.html)</sup>

用于模型检验时，复制使用原始预测变量 \( x \) 而非新预测变量，因此预测针对的是实际观测到的数据。<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup> 该块还可以计算复制的统计量，如 `mean_y_rep` 和 `sd_y_rep`，以及记录复制统计量是否大于或等于原始数据统计量的指示变量。<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup>

## 后验预测检验

后验预测检验衡量模型是否捕捉到数据的相关方面，如均值、标准差和分位数。其工作方式是从拟合模型模拟复制数据集，并将施加于每个复制的统计量与施加于原始数据的同一统计量进行比较。<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup> 该方法源自 Rubin 1984 年的后验预测检验，由 Gelman、Meng 和 Stern（1996）发展为经典拟合优度检验的贝叶斯对应物，其差异量可以是参数和数据的函数。<sup>[4](https://stat.columbia.edu/~gelman/research/published/A6n41.pdf)</sup>

图形展示是标准形式。一种常见的检验将每个复制数据集的直方图与原始数据并排绘制，用肉眼进行比较；小多图布局将原始数据放在一个面板中，将若干复制放在其他面板中。<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup> Stan 文档用一个计数示例说明了其诊断价值：对于泊松数据和泊松模型，复制与原始数据相似，如果原始数据能轻易地从这样一组数据中被辨认出来，就说明有问题。对于均值相同但过度分散的数据，任何泊松模型都无法拟合，因为泊松变量的标准差与其均值绑定；此时复制明显比原始数据更对称、方差更小，表明模型未能捕捉到方差。<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup> R 中的 `posterior` 和 `bayesplot` 以及 Python 中的 ArviZ 等软件包提供了更全面的检验可视化。<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup>

标量汇总即后验预测 p 值，即复制数据的差异统计量至少与观测数据的差异统计量一样极端的概率。当该 p 值接近零时，模型可疑。<sup>[9](https://pmc.ncbi.nlm.nih.gov/articles/PMC2829996/)</sup>

## 双重使用的批评与替代方案

由于观测数据既用于形成后验，又再次作为检验的参照，后验预测 p 值被认为对数据使用了两次。在重复抽样中会产生两个后果：不正确的模型可能不被拒绝，因此检验功效可能偏低；p 值可能无法控制第一类错误率，因此可能未校准。留出预测检验使用来自总体的新鲜抽样作为参照，避免了这两个问题，并在某些假设下可证明是校准的。<sup>[5](https://academic.oup.com/jrsssb/article/86/1/194/7274627)</sup> 事后校准程序可以调整 p 值，但不会增加检测失拟的功效。<sup>[5](https://academic.oup.com/jrsssb/article/86/1/194/7274627)</sup>

哥伦比亚大学统计学教授 Andrew Gelman 对“双重使用”的框架提出异议，认为后验预测分布恰好在单一概率陈述 \( p(y^{\text{rep}} \mid y) \) 中以数据 \( y \) 为条件一次。<sup>[10](https://statmodeling.stat.columbia.edu/2007/10/31/controversies_o/)</sup> 同一讨论中引用的 Val Johnson 的相关批评是后验预测 p 值缺乏渐近均匀性。<sup>[10](https://statmodeling.stat.columbia.edu/2007/10/31/controversies_o/)</sup> 对三种贝叶斯 p 值（后验预测、抽样后验和校准后验预测）的比较工作推荐抽样后验 p 值，因其计算成本最低且最安全。<sup>[11](https://www.sciencedirect.com/science/article/pii/S0167947314001522)</sup>

## 与先验预测及模型选择的关系

先验预测分布以先验代替后验进行同样的平均，描述在见到数据之前与先验一致的数据会是什么样。先验预测检验检查此类模拟数据，以诊断过强、过弱、形状不佳或位置不当的先验；它们不用实际数据校准。<sup>[1](https://mc-stan.org/docs/stan-users-guide/ppcs.html)</sup> Stan 指南直接陈述了这一关系：先验预测检验是后验预测检验在无数据时的极限情形。<sup>[6](https://mc-stan.org/docs/2_23/stan-users-guide-2_23.pdf)</sup>

该分布还锚定了贝叶斯预测模型选择。方法按假设分类：\( \mathscr{M} \)-闭，即某个候选模型是真实的数据生成模型；\( \mathscr{M} \)-完备；以及 \( \mathscr{M} \)-开。最大化期望预测效用等价于最小化从真实数据生成分布到候选模型预测分布的 Kullback–Leibler 散度。<sup>[12](https://link.springer.com/article/10.1007/s11222-016-9649-y)</sup> 基于样本外预测的实用工具包括留一法交叉验证（LOO）和广泛适用信息准则（WAIC），它们从拟合模型的后验模拟中估计逐点的样本外预测精度。<sup>[13](https://arxiv.org/abs/1507.04544)</sup> 这一路线中较早的准则包括 Ghosh 及其同事的最小后验预测损失方法，其目标是在忠实于观测值的前提下对观测数据的复制进行良好预测。<sup>[14](https://proceedings.mlr.press/r2/ghosh99a.html)</sup>

## References

1. [Posterior and Prior Predictive Checks, Stan User's Guide](https://mc-stan.org/docs/stan-users-guide/ppcs.html)
2. [Posterior Predictive Sampling, Stan User's Guide 2.38](https://mc-stan.org/docs/2_38/stan-users-guide/posterior-prediction.html)
3. [27.3 Sampling from the posterior predictive distribution, Stan User's Guide 2.31](https://mc-stan.org/docs/2_31/stan-users-guide/sampling-from-the-posterior-predictive-distribution.html)
4. [Gelman, A., Meng, X.-L., and Stern, H. (1996). Posterior predictive assessment of model fitness via realized discrepancies. Statistica Sinica 6(4).](https://stat.columbia.edu/~gelman/research/published/A6n41.pdf)
5. [Holdout predictive checks for Bayesian model criticism, Journal of the Royal Statistical Society Series B (2023)](https://academic.oup.com/jrsssb/article/86/1/194/7274627)
6. [Stan User's Guide 2.23 (PDF)](https://mc-stan.org/docs/2_23/stan-users-guide-2_23.pdf)
7. [Getting Started with Bayesian Statistics, Bob Carpenter](https://bob-carpenter.github.io/stan-getting-started/stan-getting-started.html)
8. [Prior and Posterior Predictive Checks, PyMC documentation](https://www.pymc.io/projects/docs/en/stable/learn/core_notebooks/posterior_predictive.html)
9. [Bayesian Model Checking for Multivariate Outcome Data, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC2829996/)
10. [Controversies over posterior predictive checks, Statistical Modeling, Causal Inference, and Social Science (Gelman)](https://statmodeling.stat.columbia.edu/2007/10/31/controversies_o/)
11. [Comparative investigation of three Bayesian p values, Computational Statistics and Data Analysis](https://www.sciencedirect.com/science/article/pii/S0167947314001522)
12. [Comparison of Bayesian predictive methods for model selection, Statistics and Computing](https://link.springer.com/article/10.1007/s11222-016-9649-y)
13. [Vehtari, A., Gelman, A., Gabry, J. Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC, arXiv](https://arxiv.org/abs/1507.04544)
14. [Model choice: A minimum posterior predictive loss approach, Ghosh et al.](https://proceedings.mlr.press/r2/ghosh99a.html)

---
*Initially written Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Bayesian statistics › Bayesian probability and inference foundations › Prior and posterior analysis

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/posterior-predictive-distribution

English original: https://www.edgepedia.org/posterior-predictive-distribution
