# BUGS项目

**BUGS**（Bayesian inference Using Gibbs Sampling，使用吉布斯采样的贝叶斯推断）是一门声明式语言及一系列软件包，用于通过马尔可夫链蒙特卡洛（MCMC）方法进行贝叶斯统计推断，于1989年起在英国剑桥的医学研究理事会生物统计部（MRC-BSU）构思并初步开发。<sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup><sup> • </sup><sup>[2](https://sites.stat.columbia.edu/gelman/bayescomputation/lunnbugswithcomments.pdf)</sup> 用户以简单的声明式语言编写模型，软件便自动构建后验分布并从中采样，免去了用C或Fortran等语言手工编写采样器的需要。<sup>[3](https://www.cs.tufts.edu/comp/150FP/archive/walter-gilks/bugs.pdf)</sup> 在三十余年的生命周期中，BUGS被认为使常规贝叶斯建模对应用研究者变得切实可行，并启发了后来JAGS、Stan和NIMBLE等概率编程系统。<sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup><sup> • </sup><sup>[4](https://www.bayesianstatistics.com/WinBUGS)</sup>

| 关键事实 | 详情 |
|---|---|
| 全称 | Bayesian inference Using Gibbs Sampling（使用吉布斯采样的贝叶斯推断）<sup>[3](https://www.cs.tufts.edu/comp/150FP/archive/walter-gilks/bugs.pdf)</sup> |
| 起源 | 1989年随安德鲁·托马斯的加入而在剑桥MRC生物统计部启动；创始人物包括大卫·斯皮格哈尔特、尼基·贝斯特和沃利·吉尔克斯<sup>[2](https://sites.stat.columbia.edu/gelman/bayescomputation/lunnbugswithcomments.pdf)</sup><sup> • </sup><sup>[4](https://www.bayesianstatistics.com/WinBUGS)</sup> |
| 奠基论文 | 吉尔克斯、托马斯和斯皮格哈尔特，《用于复杂贝叶斯建模的语言和程序》，*The Statistician* 43: 169–177 (1994)<sup>[3](https://www.cs.tufts.edu/comp/150FP/archive/walter-gilks/bugs.pdf)</sup> |
| 采样方法 | MCMC每次更新一个标量参数，尽可能使用吉布斯采样（完全条件分布），否则使用自适应拒绝采样、切片采样或Metropolis跳转<sup>[5](https://mc-stan.org/docs/2_22/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html)</sup> |
| 主要版本 | ClassicBUGS、WinBUGS、OpenBUGS，以及并行实现MultiBUGS<sup>[6](https://www.multibugs.org/presentations/2019-01-09-presentation.pdf)</sup><sup> • </sup><sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup> |
| 当前状态 | WinBUGS和OpenBUGS仍可获取，但已不再积极开发；JAGS、Stan和NIMBLE将该方法延续下去<sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup> |
| 标志性应用 | 卫生技术评估中的贝叶斯网状荟萃分析，NICE技术支持文档中的WinBUGS代码被广泛采用<sup>[7](https://www.ispor.org/docs/default-source/euro2022/msr130-svenja-petersohn-pdf.pdf?sfvrsn=53c727e7_0)</sup> |

## 历史

BUGS项目于1989年在剑桥MRC生物统计部启动，当时安德鲁·托马斯加入该部门，软件工作随之开始。<sup>[2](https://sites.stat.columbia.edu/gelman/bayescomputation/lunnbugswithcomments.pdf)</sup> 一个在PC上运行的原型于1991年4月的第四届瓦伦西亚贝叶斯会议上展示。<sup>[2](https://sites.stat.columbia.edu/gelman/bayescomputation/lunnbugswithcomments.pdf)</sup> 奠基性论文由沃利·吉尔克斯、安德鲁·托马斯和大卫·斯皮格哈尔特撰写，于1994年发表在*The Statistician*上，题为《用于复杂贝叶斯建模的语言和程序》。<sup>[3](https://www.cs.tufts.edu/comp/150FP/archive/walter-gilks/bugs.pdf)</sup>

其动机是实用性的。在BUGS之前，常规使用吉布斯采样——一种从模型未知量的联合后验分布中模拟样本的技术——需要用低级或中级语言编写一次性代码；1994年的论文报告称，为一个中等复杂度的应用编写和调试吉布斯采样器可能需要几天到几周时间，事后修改则需要数小时。<sup>[3](https://www.cs.tufts.edu/comp/150FP/archive/walter-gilks/bugs.pdf)</sup> 其明确目标是使吉布斯采样的实现像GLIM或S等软件包中的广义线性模型一样简便。<sup>[3](https://www.cs.tufts.edu/comp/150FP/archive/walter-gilks/bugs.pdf)</sup>

项目于1996年迁至伦敦帝国理工学院，在那里开发了第二代软件WinBUGS；大卫·伦恩、安德鲁·托马斯、尼基·贝斯特和大卫·斯皮格哈尔特于2000年在*Statistics and Computing*上发表的论文对WinBUGS做了描述。<sup>[8](https://www.annualreviews.org/docserver/fulltext/statistics/10/1/annurev-statistics-122121-040905.pdf?accname=guest&checksum=741F9DF2415AA8436FA7D9CA9525DE06&expires=1778412999&id=id)</sup> 第三代OpenBUGS与WinBUGS并行开发，并以GNU通用公共许可证第3版作为开源软件发布。<sup>[8](https://www.annualreviews.org/docserver/fulltext/statistics/10/1/annurev-statistics-122121-040905.pdf?accname=guest&checksum=741F9DF2415AA8436FA7D9CA9525DE06&expires=1778412999&id=id)</sup><sup> • </sup><sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup> 伦恩、斯皮格哈尔特、托马斯和贝斯特于2009年在*Statistics in Medicine*上发表的综述给出了历史概述并对该项目的设计选择做了批判性评价，指出那些带来前所未有的灵活性的理念也有负面副作用。<sup>[9](https://pubmed.ncbi.nlm.nih.gov/19630097/)</sup>

## BUGS的工作原理

BUGS模型以一组描述数据和参数联合分布的语句写成，对应一个有向无环图（DAG），其中节点代表量，边代表依赖关系。<sup>[3](https://www.cs.tufts.edu/comp/150FP/archive/walter-gilks/bugs.pdf)</sup> 最初的BUGS系统由三部分组成：用于指定复杂模型的自然语言、用于决定获取吉布斯采样器所需样本的适当方法的“专家系统”，以及包含执行采样的数值例程的采样模块。<sup>[3](https://www.cs.tufts.edu/comp/150FP/archive/walter-gilks/bugs.pdf)</sup>

**采样。** BUGS通过每次更新一个标量参数来执行MCMC，但有一些例外，如JAGS对回归和广义线性模型的实现以及某些共轭多变量参数。它尽可能从完全条件分布（吉布斯采样）中采样，否则使用自适应拒绝采样、切片采样或Metropolis跳转。<sup>[5](https://mc-stan.org/docs/2_22/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html)</sup> 这一设计意味着当建模数据的某个子集缺失时，用户可以按原样重新运行BUGS或JAGS模型，而在Stan中缺失值必须在模型代码中声明为参数。<sup>[10](https://journals.sagepub.com/doi/10.3102/1076998615606113)</sup>

**语言。** BUGS语言是一种类似R的声明式语言，用于指定一类贝叶斯模型；BUGS模型是包含多种节点的图模型，在脚本文件的model语句中指定。<sup>[11](https://www.stats.ox.ac.uk/~ripley/MCMC_2010/MCMC-lects.pdf)</sup> 该语言在表达复杂模型架构方面的灵活性，是2009年综述所指出的既是优势也是该软件缺陷来源的特征之一。<sup>[9](https://pubmed.ncbi.nlm.nih.gov/19630097/)</sup>

## 版本与衍生

BUGS谱系贯穿多个程序：<sup>[6](https://www.multibugs.org/presentations/2019-01-09-presentation.pdf)</sup><sup> • </sup><sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup>

- **ClassicBUGS**，20世纪80年代末和90年代初的原始实现。
- **WinBUGS**，基于Windows的第二代，于2000年描述；1.4.3版仍可从MRC生物统计部下载。<sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup>
- **OpenBUGS**，在GPL v3下的开源延续。<sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup>
- **MultiBUGS**，2020年发布的并行实现，基于OpenBUGS和WinBUGS的算法和工具构建，可跨处理器核心自动并行化MCMC算法。<sup>[12](https://www.multibugs.org/)</sup>

MultiBUGS在每条链内并行化两类计算：对DAG中拥有众多子节点的参数进行乘积形式似然的求值，以及对条件独立参数集（如随机效应）的采样；一个启发式算法决定每个参数采用哪种方法并在各核心间分配工作。<sup>[13](https://www.jstatsoft.org/article/view/v095i07)</sup> 在一个包含425,112个观测和20,426个随机效应的层次回归示例中，OpenBUGS耗时32小时，而MultiBUGS使用48个核心仅耗时28分钟。<sup>[12](https://www.multibugs.org/)</sup>

**JAGS**（Just Another Gibbs Sampler）是一个独立的、跨平台的BUGS语言引擎，用C++编写，以GNU通用公共许可证第2版授权，设计上与R紧密协作并具有可扩展性，允许用户编写自己的函数、分布和采样器。<sup>[14](https://mcmc-jags.sourceforge.io/)</sup><sup> • </sup><sup>[15](https://github.com/jags/JAGS)</sup> OpenBUGS和JAGS都使用MCMC算法并基于BUGS语法。<sup>[16](https://pmc.ncbi.nlm.nih.gov/articles/PMC3582467/)</sup>

**Stan**自2012年起由安德鲁·盖尔曼、丹尼尔·李、郭继强及合作者开发，使用哈密顿蒙特卡洛（HMC）而非吉布斯采样，并编译用户指定的模型以进行基于梯度的计算。<sup>[10](https://journals.sagepub.com/doi/10.3102/1076998615606113)</sup><sup> • </sup><sup>[17](https://besjournals.onlinelibrary.wiley.com/doi/10.1111/2041-210X.12681)</sup> Stan的开发者将BUGS和JAGS描述为启发Stan开发的开拓性程序。<sup>[10](https://journals.sagepub.com/doi/10.3102/1076998615606113)</sup>

## 与后续软件的比较

由于BUGS系列程序每次只采样一个标量参数，对于参数强相关的模型可能较慢，某些模型的运行时间过长到不可接受；Stan的HMC有望为此类问题提高效率。<sup>[17](https://besjournals.onlinelibrary.wiley.com/doi/10.1111/2041-210X.12681)</sup> 2017年一项跨种群生态学模型的比较发现，首选软件取决于具体情况，当运行时间不成问题时、在模型原型设计和引入贝叶斯技术方面，JAGS仍有价值。<sup>[17](https://besjournals.onlinelibrary.wiley.com/doi/10.1111/2041-210X.12681)</sup> 同一研究指出一个诊断差异：Stan能自然地诊断病态，通过发散识别高曲率区域、通过过大的树深度识别平坦区域，而JAGS不提供此类反馈，病态在传统MCMC诊断下可能不明显。<sup>[17](https://besjournals.onlinelibrary.wiley.com/doi/10.1111/2041-210X.12681)</sup>

2021年一项系统性的模拟研究比较了JAGS、NIMBLE和Stan在线性、逻辑斯蒂、混合和加速失效时间模型上的表现，推荐JAGS用于共轭或半共轭线性模型，Stan用于lasso先验下的线性模型、逻辑斯蒂回归和加速失效时间模型；在线性模型情形下，Stan每秒生成约350个样本，而JAGS约900个、NIMBLE约2,500个，而在逻辑斯蒂回归中，JAGS和NIMBLE链的有效样本量低于30%，而Stan为55%至90%。<sup>[18](https://arxiv.org/abs/2107.09357)</sup>

## 应用

BUGS系列软件成为贝叶斯网状荟萃分析（NMA）——跨临床试验网络综合证据——的标准工具。NMA软件的综述将WinBUGS描述为首选软件包，部分原因是存在大量已发表的WinBUGS代码，包括美国国家卫生与临床优化研究所（NICE）证据综合技术支持文档中的代码。<sup>[7](https://www.ispor.org/docs/default-source/euro2022/msr130-svenja-petersohn-pdf.pdf?sfvrsn=53c727e7_0)</sup><sup> • </sup><sup>[19](https://www.rti.org/publication/comparison-bayesian-network-meta-analyses-winbugs-and-sas-framework)</sup> 一项对医学文献中发表的贝叶斯混合治疗比较的系统综述发现，全部34项纳入的闭环分析都使用了WinBUGS。<sup>[20](https://doi.org/10.1136/bmjopen-2013-003111)</sup> NetMetaXL等封装工具——在Microsoft Excel中运行并链接到WinBUGS——被构建出来以使这些分析更易开展并规范报告。<sup>[21](https://link.springer.com/article/10.1186/2046-4053-3-110)</sup>

BUGS也被用于临床试验设计；贝叶斯自适应试验模拟通过将SAS与WinBUGS或OpenBUGS配对来协调，利用该软件灵活的模型指定能力。<sup>[22](https://pmc.ncbi.nlm.nih.gov/articles/PMC6283249/)</sup>

## 现状与遗产

WinBUGS和OpenBUGS程序仍可从MRC生物统计部下载，但已不再积极开发；该部门将求助问题引导至一个公共邮件列表。<sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup> 该项目的教科书《The BUGS Book: A Practical Introduction to Bayesian Analysis》由伦恩、杰克逊、贝斯特、托马斯和斯皮格哈尔特撰写，于2012年出版。<sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup> MRC生物统计部认为BUGS在其三十余年的生命周期中对使贝叶斯方法的常规使用成为可能具有高度影响力，并列出JAGS、Stan、NIMBLE和基于Julia的Turing作为其启发的领域中当前广泛使用且积极开发的程序。<sup>[1](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)</sup>

## References

1. [The BUGS Project, MRC Biostatistics Unit, University of Cambridge](https://www.mrc-bsu.cam.ac.uk/software/bugs-project)
2. [Lunn D, Spiegelhalter D, Thomas A, Best N (2009). The BUGS project: Evolution, critique and future directions. Statistics in Medicine 28(25): 3049–67 (full text with comments)](https://sites.stat.columbia.edu/gelman/bayescomputation/lunnbugswithcomments.pdf)
3. [Gilks WR, Thomas A, Spiegelhalter DJ (1994). A language and program for complex Bayesian modelling. The Statistician 43: 169–177](https://www.cs.tufts.edu/comp/150FP/archive/walter-gilks/bugs.pdf)
4. [WinBUGS / OpenBUGS, BayesianStatistics.com](https://www.bayesianstatistics.com/WinBUGS)
5. [Some Differences in How BUGS and Stan Work, Stan User's Guide](https://mc-stan.org/docs/2_22/stan-users-guide/some-differences-in-how-bugs-and-stan-work.html)
6. [MultiBUGS presentation (2019): history of the BUGS project](https://www.multibugs.org/presentations/2019-01-09-presentation.pdf)
7. [Stephenson M, Fleetwood K, Yellowlees A (2015). Alternatives to WinBUGS for Network Meta-Analysis. Value in Health 18(7): A720](https://www.ispor.org/docs/default-source/euro2022/msr130-svenja-petersohn-pdf.pdf?sfvrsn=53c727e7_0)
8. [Simulation-Based Bayesian Analysis, Annual Review of Statistics and Its Application, Vol. 10 (2023)](https://www.annualreviews.org/docserver/fulltext/statistics/10/1/annurev-statistics-122121-040905.pdf?accname=guest&checksum=741F9DF2415AA8436FA7D9CA9525DE06&expires=1778412999&id=id)
9. [Lunn D et al. (2009). The BUGS project: Evolution, critique and future directions. Statistics in Medicine 28(25): 3049–67, PubMed](https://pubmed.ncbi.nlm.nih.gov/19630097/)
10. [Gelman A, Lee D, Guo J (2015). Stan. Journal of Educational and Behavioral Statistics](https://journals.sagepub.com/doi/10.3102/1076998615606113)
11. [The BUGS language, MCMC lecture notes, University of Oxford](https://www.stats.ox.ac.uk/~ripley/MCMC_2010/MCMC-lects.pdf)
12. [MultiBUGS: A parallel implementation of the BUGS modelling framework](https://www.multibugs.org/)
13. [Goudie RJB, Turner RM, De Angelis D, Thomas A (2020). MultiBUGS: A Parallel Implementation of the BUGS Modeling Framework for Faster Bayesian Inference. Journal of Statistical Software 95(7)](https://www.jstatsoft.org/article/view/v095i07)
14. [JAGS – Just Another Gibbs Sampler, project page](https://mcmc-jags.sourceforge.io/)
15. [JAGS source repository (GitHub mirror)](https://github.com/jags/JAGS)
16. [Bayesian models for comparative analysis integrating phylogenetic uncertainty, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC3582467/)
17. [Monnahan CC, Thorson JT, Branch TA (2017). Faster estimation of Bayesian models in ecology using Hamiltonian Monte Carlo. Methods in Ecology and Evolution](https://besjournals.onlinelibrary.wiley.com/doi/10.1111/2041-210X.12681)
18. [Beraha M, Falco D, Guglielmi A (2021). JAGS, NIMBLE, Stan: a detailed comparison among Bayesian MCMC software. arXiv:2107.09357](https://arxiv.org/abs/2107.09357)
19. [Le Moine J-G, Abeysinghe S (2016). Comparison of Bayesian Network Meta-Analyses in a WinBUGS and SAS Framework. Value in Health 19(7): A393, RTI International](https://www.rti.org/publication/comparison-bayesian-network-meta-analyses-winbugs-and-sas-framework)
20. [Methods used to conduct and report Bayesian mixed treatment comparisons published in the medical literature: a systematic review. BMJ Open (2014)](https://doi.org/10.1136/bmjopen-2013-003111)
21. [A Microsoft-Excel-based tool for running and critically appraising network meta-analyses: NetMetaXL. Systematic Reviews (2014)](https://link.springer.com/article/10.1186/2046-4053-3-110)
22. [A practical guide to pre-trial simulations for Bayesian adaptive trials using SAS and BUGS, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC6283249/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 11, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Bayesian statistics › Bayesian computation and software › Bayesian software › History and ecosystem of Bayesian software

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/bugs-project

English original: https://www.edgepedia.org/bugs-project
