# 广义线性混合模型

广义线性混合模型（GLMM）是一种回归模型，它在广义线性模型的基础上加入了随机效应，使得对分组测量或对同一单元重复测量的非正态响应变量进行分析时，能够考虑组内相关性。一个GLMM包含在总体中共享的固定回归效应、描述各聚类系数如何变化的方差成分，以及假定从总体分布中随机抽取的聚类特定参数。<sup>[1](https://pubmed.ncbi.nlm.nih.gov/17067411/)</sup> 该框架现已成为生物统计学、生态学和农艺学的标准工具：在一项对1,133篇已发表论文的调查中，51%的论文报告了至少一个GLMM，而主要的R实现每年被下载超过1,000万次。<sup>[2](https://arxiv.org/abs/2609.24422)</sup>

| 关键事实 | 详情 |
|---|---|
| 估计什么 | 固定效应（总体水平）和随机效应方差（方差成分）<sup>[1](https://pubmed.ncbi.nlm.nih.gov/17067411/)</sup> |
| 核心计算问题 | 边际似然需要对随机效应积分，而对大多数GLMM而言该积分没有闭式解<sup>[1](https://pubmed.ncbi.nlm.nih.gov/17067411/)</sup> |
| 主要近似方法 | 惩罚拟似然（快速但有偏）、拉普拉斯近似（lme4和glmmTMB的默认方法）、自适应高斯-埃尔米特求积（精确，但限于少量随机效应）、贝叶斯MCMC<sup>[3](https://cran.r-project.org/web/packages/lme4/vignettes/glmer.pdf)</sup> |
| 解释 | 在非恒等连接函数下，GLMM固定效应描述的是条件（个体特定）效应；边际（总体平均）效应取决于连接函数和模型假设，并非普遍地向零衰减；在对数连接函数且随机截距与协变量独立的条件下，边际化会改变截距但保留协变量斜率<sup>[4](https://statistics4ecologists-v2a.netlify.app/glmm)</sup><sup> • </sup><sup>[34](https://journals.sagepub.com/doi/10.1191/0962280204sm368ra)</sup> |
| 最少分组水平数 | 不存在诸如五或八这样的通用阈值；随机效应可以在少于五个分组水平时使用，尽管此时估计其方差会变得困难或有偏<sup>[5](https://ms.mcmaster.ca/~bolker/R/misc/foxchapter/14-Fox-Chap13.pdf)</sup><sup> • </sup><sup>[35](https://repository.library.noaa.gov/view/noaa/65505/)</sup> |
| 已知偏差 | 对于聚类二值数据，PQL低估方差成分和固定效应；在一项模拟研究中，随机截距方差的中位绝对偏差在PQL下为48%，而求积法为29%<sup>[6](https://doi.org/10.1080/01621459.1993.10594284)</sup> |

## 工作原理

以随机效应为条件，GLMM就是一个普通的广义线性模型。条件均值和方差遵循GLM形式：\( \mathrm{var}(y_i \mid b) = \phi \cdot a_i \cdot v(\mu_i) \)，其中 \( v(\cdot) \) 为指定的方差函数，\( \phi \) 为离散度，\( a_i \) 为已知权重；连接函数将 \( \mu_i \) 与包含固定效应和随机效应的线性预测子联系起来。<sup>[6](https://doi.org/10.1080/01621459.1993.10594284)</sup> 随机效应 \( b_i \) 假定为高斯分布，均值为零，其离散度矩阵的未知参数即方差成分；过度离散、相关误差、收缩和平滑都可以纳入这一统一框架。<sup>[6](https://doi.org/10.1080/01621459.1993.10594284)</sup>

推断使用边际似然，即从联合密度中对随机效应积分得到：

\[ L(\beta, \Sigma_b; Y) = \prod_{i=1}^{n} \int \prod_{j} f(y_{ij} \mid b_i)\, f(b_i)\, db_i \]

对于大多数具有正态混合分布的GLMM，该积分没有闭式解析解，这正是迫使我们采用下文所述近似方法的原因。<sup>[4](https://statistics4ecologists-v2a.netlify.app/glmm)</sup> 解释因尺度而异。对于logit随机截距模型，条件系数与边际系数之间通常不存在精确转换：边际效应需要对随机效应分布进行积分或近似，且边际系数向零衰减，因此个体特定模型给出的协变量效应大于总体平均模型。<sup>[4](https://statistics4ecologists-v2a.netlify.app/glmm)</sup>

## 实现方法

估计方法分为两类：对难解积分的数值近似，以及对被积函数的解析近似。<sup>[1](https://pubmed.ncbi.nlm.nih.gov/17067411/)</sup> 按精度和成本大致递增的顺序排列：<sup>[5](https://ms.mcmaster.ca/~bolker/R/misc/foxchapter/14-Fox-Chap13.pdf)</sup>

1. **惩罚拟似然（PQL）。** 用拉普拉斯方法近似边际拟似然，得到均值参数的PQL估计方程和方差的伪似然，通过重复的REML型调用来实现。<sup>[6](https://doi.org/10.1080/01621459.1993.10594284)</sup> 它快速且灵活，但在二值数据或均值低于5的泊松计数下会给出有偏的随机效应方差。<sup>[5](https://ms.mcmaster.ca/~bolker/R/misc/foxchapter/14-Fox-Chap13.pdf)</sup>
2. **拉普拉斯近似。** 通过PIRLS最小化带惩罚的单位偏差之和，得到对数联合密度的局部二次近似，作为积分近似。<sup>[3](https://cran.r-project.org/web/packages/lme4/vignettes/glmer.pdf)</sup>
3. **自适应高斯-埃尔米特求积（AGQ）。** 求积节点以随机效应的经验贝叶斯估计为中心，并利用该子优化的海塞矩阵进行缩放；对于每个聚类中中等至大量的观测，它非常精确，但随着随机效应数量增加，由于积分的维数，计算上变得不可行。<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC3866838/)</sup> 计算时间大致按 \( (N_q)^u \) 增长，其中 \( N_q \) 为求积节点数，\( u \) 为随机效应数；拉普拉斯近似等价于单节点AGQ，通常7个或更少的节点就足够了。<sup>[8](https://joshua-nugent.github.io/pql/main.pdf)</sup>
4. **贝叶斯MCMC**，通过抽样避开积分。<sup>[5](https://ms.mcmaster.ca/~bolker/R/misc/foxchapter/14-Fox-Chap13.pdf)</sup>

软件默认设置各不相同：SAS PROC GLIMMIX默认为伪似然，R的glmer默认为单节点AGQ（拉普拉斯），Stata的meglm默认为7节点AGQ，SPSS默认为PQL且没有AGQ选项。<sup>[8](https://joshua-nugent.github.io/pql/main.pdf)</sup> 在lme4中，nAGQ参数控制这一点：默认nAGQ = 1为拉普拉斯，大于1的值为自适应求积，nAGQ = 0使用更快但不太精确的基于PIRLS的拟合。<sup>[9](https://lme4.github.io/lme4/reference/glmer.html)</sup> 典型公式使用竖线将设计矩阵与分组因子分开，例如 `cbind(incidence, size - incidence) ~ period + (1 | herd)` 配合 `family = binomial`。<sup>[9](https://lme4.github.io/lme4/reference/glmer.html)</sup> glmmTMB构建于TMB之上，假定线性预测子尺度上的高斯随机效应，通过带有自动微分梯度的拉普拉斯近似进行积分，并使用lme4风格的公式。<sup>[10](https://glmmtmb.r-universe.dev/glmmTMB/glmmTMB.pdf)</sup>

## 起源

GLMM建立在奈尔德和韦德伯恩于1972年提出的广义线性模型之上，随机效应扩展对其迭代拟合过程进行了线性化。<sup>[11](https://doi.org/10.2307/2344614)</sup> 带随机效应的广义线性模型中的估计由罗伯特·沙尔于1991年在《Biometrika》上处理。<sup>[12](https://doi.org/10.1093/biomet/78.4.719)</sup> 同年，斯科特·L·泽格和M·雷扎乌尔·卡里姆通过将模型置于贝叶斯框架并使用Gibbs采样器，完全避开了数值积分。<sup>[13](https://doi.org/10.1080/01621459.1991.10475006)</sup> N·E·布雷斯洛和D·G·克莱顿于1993年在《美国统计协会杂志》上巩固了频率派框架，将过度离散、相关误差、收缩估计和平滑纳入GLMM框架，并命名了线性化方法的边际拟似然变体。<sup>[6](https://doi.org/10.1080/01621459.1993.10594284)</sup> 到20世纪90年代初，研究已全面展开，但诸如SAS GLIMMIX和R lme4等相对易用的软件又花了十年或更长时间才广泛可用。<sup>[14](https://www.frontiersin.org/journals/horticulture/articles/10.3389/fhort.2024.1423462/full)</sup>

## 变体

**HGLM。** Y·李和J·A·奈尔德于1996年引入了分层广义线性模型，后来的GLMM综述将其视为统一该领域的综合框架。<sup>[15](https://doi.org/10.1111/j.2517-6161.1996.tb02105.x)</sup>

**过度离散和零膨胀混合模型。** glmmTMB拟合高斯、二项、贝塔-二项、泊松、负二项（NB1和NB2）、Conway-Maxwell-泊松、广义泊松、伽马、贝塔和Tweedie分布族，配合log、logit、probit、cloglog、逆和恒等连接函数，外加零膨胀（logit连接函数的ziformula）和障碍模型。<sup>[16](https://cran.r-project.org/web/packages/glmmTMB/vignettes/glmmTMB.pdf)</sup> 两种负二项参数化在方差-均值关系上不同：对于nbinom1，方差随均值线性增加，\( \sigma^2 = \mu \cdot (1 + \alpha) \)，而nbinom2的方差是均值的二次函数。<sup>[17](https://doi.org/10.32614/rj-2017-066)</sup> 结构化协方差矩阵（ar1、Matérn、降秩等）和离散度模型扩展了基本形式。<sup>[10](https://glmmtmb.r-universe.dev/glmmTMB/glmmTMB.pdf)</sup> glmmTMB还获得了降秩随机效应结构，将q维多元随机效应写成 \( d < q \) 个潜变量的线性组合，使数百或数千维的随机效应成为常规操作，并规避了近奇异性警告。<sup>[18](https://www.jstatsoft.org/article/download/v112i01/4676)</sup>

## 应用

生态学和进化生物学是旗舰领域：一份被广泛引用的实用指南于2009年为生态学家整合了GLMM流程。<sup>[19](https://doi.org/10.1016/j.tree.2008.10.008)</sup> lme4文档中的示例——15群牛的呼吸道疾病（56个二项观测）——展示了工作流程，包括为过度离散添加观测水平随机效应，使AIC从194.05改善到186.64。<sup>[9](https://lme4.github.io/lme4/reference/glmer.html)</sup> 在植物科学和农艺学中，GLMM处理来自设计实验的二项、泊松、负二项、伽马和贝塔响应。<sup>[14](https://www.frontiersin.org/journals/horticulture/articles/10.3389/fhort.2024.1423462/full)</sup> 在临床研究中，GLMM用于二值结局的稀有事件荟萃分析，模拟表明两组总共至少需要10个事件。<sup>[20](https://pmc.ncbi.nlm.nih.gov/articles/PMC7296731/)</sup>

## 局限性与替代方法

**分组数少。** 随机效应可以在少于五个分组水平时使用，尽管此时其方差估计可能困难或有偏，且不存在通用的五或八水平阈值；模拟指导建议，当准确的方差估计至关重要时使用超过1,000个水平，合理估计需要超过100个，低于10个水平时将变量视为固定效应。<sup>[5](https://ms.mcmaster.ca/~bolker/R/misc/foxchapter/14-Fox-Chap13.pdf)</sup><sup> • </sup><sup>[35](https://repository.library.noaa.gov/view/noaa/65505/)</sup>

**近似偏差。** 对于聚类二值数据，PQL低估方差成分和固定效应，当二项分母大于1时改善迅速。<sup>[6](https://doi.org/10.1080/01621459.1993.10594284)</sup> 在二值数据模拟中，随机截距方差的中位绝对偏差在求积法下为29%，PQL下为48%，但求积法的不收敛更频繁（8.8%对2.3%的情景）。<sup>[21](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0084601)</sup> 对于具有少量大聚类的整群随机试验，PQL对聚类水平协变量的渐近偏差为 \( O_p(1/m) \) 阶，与聚类大小成反比，因此PQL在该情境下表现良好。<sup>[22](https://www3.stat.sinica.edu.tw/statistica/oldpdf/A15n410.pdf)</sup> 哪种近似收敛最差尚无定论：稀疏荟萃分析模拟发现PQL收敛率低于20%，而拉普拉斯接近100%，<sup>[20](https://pmc.ncbi.nlm.nih.gov/articles/PMC7296731/)</sup> 但另一项模拟研究发现求积法比PQL更常出现不收敛。<sup>[21](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0084601)</sup> 线性化方法更通用，能处理条件和边际GLMM以及类REML方差估计，而求积法严格限于最大似然；没有放之四海而皆准的最佳方法。<sup>[23](https://ideas.repec.org/a/spr/jagbes/v25y2020i4d10.1007_s13253-020-00402-6.html)</sup>

**诊断与推断。** GLMM特有的首要检查是拟合是否奇异（随机效应方差估计为零，在lme4中可通过接近零的Cholesky元素检测）；blme包添加弱先验以避免奇异性，glmmTMB中的负二项模型或glmer中的对数正态-泊松模型是过度离散计数的快速补救方法。<sup>[24](https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html)</sup> 似然比检验在中小样本量下对固定效应不可靠，Wald检验可能严重失败（Hauck-Donner效应）；聚类数少时需要小样本校正，如参数自助法；Kenward-Roger校正为高斯线性混合模型开发，对广义模型缺乏明确的理论基础。<sup>[19](https://doi.org/10.1016/j.tree.2008.10.008)</sup> Kenward-Roger小样本校正由迈克尔·G·肯沃德和詹姆斯·H·罗杰于1997年提出。<sup>[25](https://doi.org/10.2307/2533558)</sup>

**替代方法。** 对于纵向数据，主要方法是GLMM和（加权）广义估计方程，它们不同的假设和参数解释对报告有重要影响。<sup>[26](https://pmc.ncbi.nlm.nih.gov/articles/PMC5434286/)</sup> 广义估计方程由梁恭义和斯科特·L·泽格于1986年提出，针对边际效应，但不提供用于拟合评估或个体水平预测的正式生成模型。<sup>[27](https://doi.org/10.1093/biomet/73.1.13)</sup> 随机效应、固定效应和广义估计方程模型基于关于协变量对均值效应的不同假设，选择应遵循所研究的问题。<sup>[28](https://onlinelibrary.wiley.com/doi/10.1002/sim.3478)</sup> 边际可解释GLMM提供了中间路径，满足 \( \int \mathrm{E}(Y \mid U = u) f_U(u)\, du = \mathrm{E}(Y) \)，尽管非线性连接函数下的常规GLMM检验可能检验错误的假设。<sup>[29](https://par.nsf.gov/servlets/purl/10250251)</sup> 完全贝叶斯拟合可通过brms获得，这是保罗-克里斯蒂安·比克纳于2017年开发的Stan接口。<sup>[30](https://doi.org/10.18637/jss.v080.i01)</sup>

**近期计算工作**针对经典拟合困难的场景。对于交叉随机效应，Krylov子空间方法（预条件共轭梯度和随机Lanczos求积，即沙尚卡·乌巴鲁、陈杰和优素福·萨阿德于2017年引入的迹估计技术<sup>[31](https://doi.org/10.1137/16m1104974)</sup>）相比基于Cholesky的计算实现了约两个数量级的运行时间缩减，其实现比默认设置下的lme4和glmmTMB快达10,000倍。<sup>[32](https://ar5iv.labs.arxiv.org/html/2505.09552)</sup> 对于空间GLMM，使用随机牛顿-拉夫森法的蒙特卡洛最大似然算法由塞缪尔·I·沃森、王一新和埃马努埃莱·乔治实现在R包glmmrBase中，在中等规模数据集上运行时间短于INLA。<sup>[33](https://doi.org/10.48550/arxiv.2601.16022)</sup> 在贝叶斯方面，metabeta——一个用于GLMM上下文贝叶斯推断的先验摊销预训练神经网络——匹配NUTS后验，同时快两到三个数量级；标准的快速替代方法ADVI则系统性地过度自信。<sup>[2](https://arxiv.org/abs/2609.24422)</sup>

## References

1. [Statistical inference in generalized linear mixed models: a review (Rijmen et al., British Journal of Mathematical and Statistical Psychology, 2006)](https://pubmed.ncbi.nlm.nih.gov/17067411/)
2. [Prior-Amortized In-Context Bayesian Inference for Generalized Linear Mixed-Effects Models (metabeta) (preprint)](https://arxiv.org/abs/2609.24422)
3. [Fitting generalized linear mixed models using lme4 (vignette)](https://cran.r-project.org/web/packages/lme4/vignettes/glmer.pdf)
4. [Chapter 19 Generalized linear mixed effects models (GLMMs) | Statistics for Ecologists](https://statistics4ecologists-v2a.netlify.app/glmm)
5. [Bolker, 'Linear and generalized linear mixed models' chapter in Fox et al., Ecological Statistics](https://ms.mcmaster.ca/~bolker/R/misc/foxchapter/14-Fox-Chap13.pdf)
6. [N. E. Breslow, D. G. Clayton (1993). Approximate Inference in Generalized Linear Mixed Models. Journal of the American Statistical Association.](https://doi.org/10.1080/01621459.1993.10594284)
7. [An assessment of estimation methods for generalized linear mixed models with binary outcomes](https://pmc.ncbi.nlm.nih.gov/articles/PMC3866838/)
8. [Bias induced by fitting GLMMs with dichotomous outcomes using penalized quasi-likelihood (preprint)](https://joshua-nugent.github.io/pql/main.pdf)
9. [Fitting Generalized Linear Mixed-Effects Models, glmer • lme4 (official documentation)](https://lme4.github.io/lme4/reference/glmer.html)
10. [glmmTMB reference manual (version 1.1.15)](https://glmmtmb.r-universe.dev/glmmTMB/glmmTMB.pdf)
11. [J. A. Nelder, R. W. M. Wedderburn (1972). Generalized Linear Models. Journal of the Royal Statistical Society Series A (General).](https://doi.org/10.2307/2344614)
12. [ROBERT SCHALL (1991). Estimation in generalized linear models with random effects. Biometrika.](https://doi.org/10.1093/biomet/78.4.719)
13. [Scott L Zeger, M. Rezaul Karim (1991). Generalized Linear Models with Random Effects; a Gibbs Sampling Approach. Journal of the American Statistical Association.](https://doi.org/10.1080/01621459.1991.10475006)
14. [The value of generalized linear mixed models for data analysis in the plant sciences (Frontiers, 2024)](https://www.frontiersin.org/journals/horticulture/articles/10.3389/fhort.2024.1423462/full)
15. [Y. Lee, J. A. Nelder (1996). Hierarchical Generalized Linear Models. Journal of the Royal Statistical Society Series B (Statistical Methodology).](https://doi.org/10.1111/j.2517-6161.1996.tb02105.x)
16. [glmmTMB: Getting started with the package (vignette)](https://cran.r-project.org/web/packages/glmmTMB/vignettes/glmmTMB.pdf)
17. [Mollie,E. Brooks and colleagues (2017). glmmTMB Balances Speed and Flexibility Among Packages for Zero-inflated Generalized Linear Mixed Modeling. The R Journal.](https://doi.org/10.32614/rj-2017-066)
18. [Parsimoniously Fitting Large Multivariate Random Effects in glmmTMB (Journal of Statistical Software)](https://www.jstatsoft.org/article/download/v112i01/4676)
19. [Benjamin M. Bolker and colleagues (2009). Generalized linear mixed models: a practical guide for ecology and evolution. Trends in Ecology & Evolution.](https://doi.org/10.1016/j.tree.2008.10.008)
20. [Laplace approximation, penalized quasi-likelihood, and adaptive Gauss–Hermite quadrature for GLMMs: towards meta-analysis of binary outcome with sparse data](https://pmc.ncbi.nlm.nih.gov/articles/PMC7296731/)
21. [Generalized Linear Mixed Models for Binary Data: Are Matching Results from Penalized Quasi-Likelihood and Numerical Integration Less Biased? (PLOS One)](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0084601)
22. [Asymptotic bias and variance of the PQL estimator in group-randomized trials (Bellamy, Li, Lin, Ryan, Statistica Sinica)](https://www3.stat.sinica.edu.tw/statistica/oldpdf/A15n410.pdf)
23. [Pseudo-Likelihood or Quadrature? What We Thought We Knew... (Journal of Agricultural, Biological, and Environmental Statistics, 2020)](https://ideas.repec.org/a/spr/jagbes/v25y2020i4d10.1007_s13253-020-00402-6.html)
24. [GLMM FAQ (Ben Bolker)](https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html)
25. [Michael G. Kenward, James H. Roger (1997). Small Sample Inference for Fixed Effects from Restricted Maximum Likelihood. Biometrics.](https://doi.org/10.2307/2533558)
26. [Modern methods for longitudinal data analysis, capabilities, caveats and cautions (2016)](https://pmc.ncbi.nlm.nih.gov/articles/PMC5434286/)
27. [KUNG-YEE LIANG, SCOTT L. ZEGER (1986). Longitudinal data analysis using generalized linear models. Biometrika.](https://doi.org/10.1093/biomet/73.1.13)
28. [Gardiner, Luo, Roman (2009), 'Fixed effects, random effects and GEE: What are the differences?', Statistics in Medicine](https://onlinelibrary.wiley.com/doi/10.1002/sim.3478)
29. [Marginally interpretable GLMMs (peer-reviewed methods paper, NSF public access repository)](https://par.nsf.gov/servlets/purl/10250251)
30. [Paul-Christian Bürkner (2017). brms : An R Package for Bayesian Multilevel Models Using Stan. Journal of Statistical Software.](https://doi.org/10.18637/jss.v080.i01)
31. [Shashanka Ubaru, Jie Chen, Yousef Saad (2017). Fast Estimation of $tr(f(A))$ via Stochastic Lanczos Quadrature. SIAM Journal on Matrix Analysis and Applications.](https://doi.org/10.1137/16m1104974)
32. [Scalable Computations for Generalized Mixed Effects Models with Crossed Random Effects Using Krylov Subspace Methods (preprint, 2025)](https://ar5iv.labs.arxiv.org/html/2505.09552)
33. [Watson, Samuel I., Wang, Yixin, Giorgi, Emanuele (2026). Approximate Likelihood-Based Inference for Spatial Generalized Linear Mixed Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2601.16022)
34. [journals.sagepub.com](https://journals.sagepub.com/doi/10.1191/0962280204sm368ra)
35. [repository.library.noaa.gov](https://repository.library.noaa.gov/view/noaa/65505/)

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

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Statistical inference, estimation, sampling, and testing › Regression analysis › Multilevel and mixed-effects regression

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/generalized-linear-mixed-model

English original: https://www.edgepedia.org/generalized-linear-mixed-model
