# 线性模型

线性模型将响应变量表示为预测变量的线性组合，其系数未知，并以矩阵形式写作 \( Y = X \cdot \beta + \varepsilon \)。其中 \( Y \) 是 \( n \times 1 \) 的观测响应向量，\( X \) 是 \( n \times p \) 的固定常数设计矩阵，\( \beta \) 是 \( p \times 1 \) 的未知参数向量，\( \varepsilon \) 是误差向量。<sup>[1](https://people.stat.sc.edu/tebbs/stat714/f10notes.pdf)</sup> 用最小二乘拟合该模型会得到系数估计、拟合值、标准误和检验统计量，而同一框架涵盖回归、方差分析（ANOVA）、协方差分析（ANCOVA）以及试验设计理论。<sup>[2](https://www.mathworks.com/help/stats/what-is-linear-regression.html)</sup><sup> • </sup><sup>[3](https://dornsife.usc.edu/larry-goldstein/wp-content/uploads/sites/221/2023/06/LinearModels.pdf)</sup> 系数 \( \beta_k \) 表示在其他所有预测变量保持不变时，一个预测变量每变化一个单位所引起的响应均值变化。<sup>[2](https://www.mathworks.com/help/stats/what-is-linear-regression.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义方程 | \( Y = X \cdot \beta + \varepsilon \)，其中 \( X \) 是 \( n \times p \) 设计矩阵，\( \beta \) 是 \( p \times 1 \) 参数向量<sup>[1](https://people.stat.sc.edu/tebbs/stat714/f10notes.pdf)</sup> |
| 估计量 | 当 \( X \) 满列秩时，\( \hat{\beta} = (X^{\top} \cdot X)^{-1}X^{\top} \cdot y \)<sup>[4](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M03_GREE1366_08_SE_C03.pdf)</sup> |
| 线性 | 指的是系数 \( \beta_k \)，而非预测变量；在 \( X \) 中含有多项式项或对数项的模型仍然是线性模型<sup>[2](https://www.mathworks.com/help/stats/what-is-linear-regression.html)</sup> |
| 最优性 | 高斯—马尔可夫定理：当 \( E(\varepsilon)=0 \) 且 \( \mathrm{cov}(\varepsilon)=\sigma^2 \cdot I \) 时，最小二乘在线性无偏估计量中具有最小方差<sup>[5](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M04_GREE1366_08_SE_C04.pdf)</sup> |
| 特例 | 回归、单因素和双因素方差分析、协方差分析以及混合模型都是 \( Y = X \cdot \beta + \varepsilon \) 的实例<sup>[1](https://people.stat.sc.edu/tebbs/stat714/f10notes.pdf)</sup> |

## 工作原理

“线性”一词指的是系数，而非预测变量。只要响应是系数 \( \beta_k \) 的线性函数，即使预测变量中含有多项式项或对数项，也仍然是线性模型；而一个对 \( \beta \) 非线性的模型，例如含有 \( 1/\beta_2 \) 的模型，则不是线性模型。<sup>[2](https://www.mathworks.com/help/stats/what-is-linear-regression.html)</sup> 因此，线性最小二乘问题由 \( y = \sum_k a_k g_k(X) \) 定义，它对未知系数 \( a_k \) 是线性的，即使对预测变量是非线性的；真正非线性的问题需要迭代求解。<sup>[6](https://wolberg.net.technion.ac.il/files/2017/03/history.pdf)</sup>

普通最小二乘（OLS）最小化残差平方和 \( \mathrm{SSR}(\beta) = \lVert y - X \cdot \beta \rVert^2 \)。使该式最小化的 \( \hat{\beta} \) 使残差向量与 \( X \) 的每一列正交，从而给出正规方程 \( X^{\top} \cdot (y - X \cdot \hat{\beta}) = 0 \)。<sup>[7](http://www2.stat.duke.edu/~pdh10/Teaching/721/Materials/notes.pdf)</sup> 等价地，\( \hat{\beta} \) 满足正规方程 \( X^{\top} \cdot X \cdot \hat{\beta} = X^{\top} \cdot y \)，而当 \( X \) 满列秩时，唯一的闭式解为 \( \hat{\beta} = (X^{\top} \cdot X)^{-1}X^{\top} \cdot y \)。<sup>[4](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M03_GREE1366_08_SE_C03.pdf)</sup>

文献将假设组织为若干模型类别：最小二乘模型不对误差作任何假设；高斯—马尔可夫模型假设 \( E(\varepsilon)=0 \) 且 \( \mathrm{cov}(\varepsilon)=\sigma^2 \cdot I \)；艾特肯模型假设 \( \mathrm{cov}(\varepsilon)=\sigma^2 \cdot V \)，其中 \( V \) 已知；一般线性混合模型假设 \( \mathrm{cov}(\varepsilon)=\Sigma(\theta) \)。<sup>[1](https://people.stat.sc.edu/tebbs/stat714/f10notes.pdf)</sup> 在高斯—马尔可夫条件下，最小二乘估计量 \( b \) 是 \( \beta \) 的最小方差线性无偏估计量，且对任意常数向量 \( w \)，\( w^{\top} \cdot b \) 是 \( w^{\top} \cdot \beta \) 的最小方差线性无偏估计量。<sup>[5](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M04_GREE1366_08_SE_C04.pdf)</sup>

## 实施方法

**构造设计矩阵。** 连续预测变量以列的形式进入；因子以虚拟（指示）变量进入，R 的 `lm` 等软件会自动为双因素方差分析及其他因子结构构建这些变量。<sup>[8](https://bookdown.org/ronsarafian/IntrotoDS/lm.html)</sup> 方差分析模型是带有虚拟变量的线性模型，而协方差分析模型将虚拟变量与连续协变量结合起来。<sup>[3](https://dornsife.usc.edu/larry-goldstein/wp-content/uploads/sites/221/2023/06/LinearModels.pdf)</sup>

**拟合并估计方差。** 用 `lm` 拟合是一个无假设的算法步骤；推断则需要对误差作假设。<sup>[8](https://bookdown.org/ronsarafian/IntrotoDS/lm.html)</sup> 当 \( \varepsilon \sim N(0, \sigma^2 \cdot I) \) 且 \( X \) 满列秩时，\( \hat{\beta} \sim N(\beta, (X^{\top} \cdot X)^{-1} \cdot \sigma^2) \) 精确成立，\( \hat{\sigma}^2 = \lVert y - X \cdot \hat{\beta} \rVert^2/(n-p) \) 是无偏的，推断使用 \( t_{n-p} \) 分布和精确 F 比率检验；其他误差协方差结构需要不同的方差估计和推断程序。<sup>[9](https://webhomes.maths.ed.ac.uk/~swood34/mgcv/tampere/linear-models.pdf)</sup>

**检验假设。** 单个系数的经典 \( t \) 统计量为 \( t_j = (\hat{\beta}_j - \beta_{j,0})/\mathrm{se}(\hat{\beta}_j) \)，在原假设下服从 \( t_{N-k} \) 分布；\( q \) 个约束的 \( F \) 统计量为 \( (\mathrm{SSR}_R - \mathrm{SSR}_U)/q \div \mathrm{SSR}_U/(N-k) \)，服从 \( F_{q,N-k} \) 分布。<sup>[10](https://www.luischanci.com/documents/Econometrics/OLS.pdf)</sup>

**评估拟合。** \( R^2 = (\mathrm{TSS} - \mathrm{RSS})/\mathrm{TSS} \) 衡量模型所解释的变异比例，在简单线性回归中等于观测值与预测值之间相关系数的平方。<sup>[11](https://ocw.mit.edu/courses/18-05-introduction-to-probability-and-statistics-spring-2022/mit18_05_s22_class26-prep.pdf)</sup> 由于只要加入任何回归变量，\( R^2 \) 都不会减小，调整 \( R^2 \) 即 \( \bar{R}^2 = 1 - (1-R^2)\frac{N-1}{N-k} \) 通过损失自由度对纳入变量进行惩罚，因此在模型构建中更受偏好。<sup>[10](https://www.luischanci.com/documents/Econometrics/OLS.pdf)</sup><sup> • </sup><sup>[12](https://online.stat.psu.edu/stat462/node/83/)</sup>

**诊断。** 如果模型充分，残差对拟合值的图应当是无结构图；弯曲趋势或其他系统性特征表明一个或多个假设失效。<sup>[13](https://us.sagepub.com/sites/default/files/upm-binaries/38503_Chapter6.pdf)</sup> 帽子矩阵 \( A = X \cdot (X^{\top} \cdot X)^{-1} \cdot X^{\top} \) 是幂等的，且 \( \mathrm{tr}(A)=p \)；其对角元素衡量各个数据点的杠杆，即它们影响拟合的潜力；实际影响还取决于残差，并用库克距离等度量来量化。<sup>[9](https://webhomes.maths.ed.ac.uk/~swood34/mgcv/tampere/linear-models.pdf)</sup>

## 起源

线性模型的统计理论通过一系列已发表的贡献发展起来。卡尔·皮尔逊（Karl Pearson）计算了相关系数，并在其 1896 年发表于《皇家学会哲学汇刊》的论文《回归、遗传与随机交配》中发表了数学回归理论。<sup>[14](https://rwr.nrhstat.org/1_introduction.html)</sup><sup> • </sup><sup>[15](https://doi.org/10.1098/rsta.1896.0007)</sup> A. C. 艾特肯（A. C. Aitken）1936 年发表于《爱丁堡皇家学会会刊》的论文《论最小二乘与观测值的线性组合》引入了带有协方差矩阵的加权最小二乘推广。<sup>[16](https://doi.org/10.1017/s0370164600014346)</sup> J. A. 内尔德（J. A. Nelder）和 R. W. M. 韦德伯恩（R. W. M. Wedderburn）在其 1972 年发表于《皇家统计学会杂志 A 辑》的论文《广义线性模型》中，通过连接函数和迭代加权最小二乘拟合统一了正态、二项（概率单位）、泊松和伽马情形。<sup>[17](https://doi.org/10.2307/2344614)</sup><sup> • </sup><sup>[18](https://www.maths.usyd.edu.au/u/jchan/GLM/Nelder1972GLM.pdf)</sup> 罗伯特·蒂布希拉尼（Robert Tibshirani）于 1996 年在《皇家统计学会杂志 B 辑》提出了套索，在系数绝对值之和小于一个常数的约束下最小化残差平方和，使一些系数恰好为零。<sup>[19](https://doi.org/10.1111/j.2517-6161.1996.tb02080.x)</sup>

## 变体

**方差分析、协方差分析与秩亏。** 回归、单因素和双因素方差分析、协方差分析以及混合模型都是 \( Y = X \cdot \beta + \varepsilon \) 的特例；秩取决于所选参数化，而非模型类型：为每个水平都包含一个指示变量再加一个截距的过参数化方差分析编码是秩亏的，而每个因子去掉一个水平的编码是满秩的，并且回归设计或方差分析设计都可能具有亏秩。<sup>[1](https://people.stat.sc.edu/tebbs/stat714/f10notes.pdf)</sup>

**GLS 与 WLS。** 当误差协方差为 \( \sigma^2 \cdot V \)，且 \( V \) 为已知正定矩阵时，广义最小二乘最小化 \( (y - X \cdot \beta)^{\top} \cdot \Omega^{-1} \cdot (y - X \cdot \beta) \)，并且是最佳线性无偏估计量，实际上按观测方差倒数对观测加权。<sup>[7](http://www2.stat.duke.edu/~pdh10/Teaching/721/Materials/notes.pdf)</sup><sup> • </sup><sup>[3](https://dornsife.usc.edu/larry-goldstein/wp-content/uploads/sites/221/2023/06/LinearModels.pdf)</sup>

**正则化。** 岭回归最小化 \( \lVert X \cdot w - y \rVert_2^2 + \alpha \cdot \lVert w \rVert_2^2 \)，其中 \( \alpha \) 越大，收缩越强，对共线性的稳健性也越高。<sup>[20](https://scikit-learn.org/stable/modules/linear%5Fmodel.html)</sup>

**稳健估计量。** 软件包为含有离群点的数据提供随机抽样一致、泰尔—森和休伯回归；泰尔—森在单变量简单线性回归中的崩溃点约为 29.3%，而休伯回归降低离群点的权重，而不是忽略它们。<sup>[20](https://scikit-learn.org/stable/modules/linear%5Fmodel.html)</sup>

**高维与检验变体。** 丹齐格选择器由埃马纽埃尔·坎德斯（Emmanuel Candes）和陶哲轩（Terence Tao）于 2007 年在《统计年鉴》提出，用于处理 \( p \) 远大于 \( n \) 时的统计估计。<sup>[21](https://doi.org/10.1214/009053606000001523)</sup> 用于高维受控变量选择的模型-X 仿冒变量由埃马纽埃尔·坎德斯及其同事于 2018 年在《皇家统计学会杂志 B 辑》提出。<sup>[22](https://doi.org/10.1111/rssb.12265)</sup> 用于回归系数检验的残差置换检验由温凯悦（Kaiyue Wen）、王腾耀（Tengyao Wang）和王宇浩（Yuhao Wang）于 2025 年在《统计年鉴》提出。<sup>[23](https://doi.org/10.1214/24-aos2479)</sup>

## 应用

就预测而言，线性模型仍然流行，因为它们简单、需要的数据少，并且即使略有偏差，其方差也可能足够小，从而比更灵活的替代方案更准确。<sup>[24](https://www.john-ros.com/Rcourse/lm.html)</sup> 一位评论者认为，自约 1980 年以来，线性回归在技术上已大体过时，但有三个例外：线性形式有真正的科学理由；应用重视计算简单性；以及小样本下有意为之的偏差—方差权衡。<sup>[25](https://www.stat.cmu.edu/~cshalizi/TALR/TALR.pdf)</sup>

## 局限与替代方案

**多重共线性。** 当特征相关且设计矩阵的列之间存在近似线性依赖时，矩阵会接近奇异，最小二乘估计会对观测目标中的随机误差高度敏感，产生大方差。<sup>[20](https://scikit-learn.org/stable/modules/linear%5Fmodel.html)</sup> 效应估计的标准误增大，而使用相关预测变量进行因果推断时难以解释，因为结果的变化可能归因于任何一个相关预测变量。<sup>[24](https://www.john-ros.com/Rcourse/lm.html)</sup> 岭回归正是为解决最小二乘在共线或多重共线设计中的缺陷而发展起来的。<sup>[26](https://arxiv.org/pdf/2412.15633)</sup>

**过拟合与外推。** 当且仅当真实关系恰好线性时，线性预测才没有系统误差；而非线性均值函数的任何全局线性近似都只在非常短的范围内可靠，这使外推变得危险。<sup>[25](https://www.stat.cmu.edu/~cshalizi/TALR/TALR.pdf)</sup> 收缩估计量，例如收缩样本均值 \( \frac{n}{n+\lambda} \cdot \bar{X} \)，其方差严格小于直观估计量，代价是引入偏差，但该偏差会随着 \( n \) 增大而趋于零，这说明了正则化背后的偏差—方差权衡。<sup>[25](https://www.stat.cmu.edu/~cshalizi/TALR/TALR.pdf)</sup>

**假设失效。** 最小二乘的无偏性对违反正态性和同方差性具有稳健性，但对违反外生性——即误差具有零条件均值这一假设——并不稳健。<sup>[5](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M04_GREE1366_08_SE_C04.pdf)</sup> 估计本身是纯算法性的，不需要分布假设；独立性、零均值误差和正态性仅用于对 \( \hat{\beta} \) 的推断。<sup>[24](https://www.john-ros.com/Rcourse/lm.html)</sup>

## References

1. [STAT 714 Linear Statistical Models course notes (Tebbs, Univ. of South Carolina)](https://people.stat.sc.edu/tebbs/stat714/f10notes.pdf)
2. [What Is a Linear Regression Model? - MATLAB & Simulink](https://www.mathworks.com/help/stats/what-is-linear-regression.html)
3. [Linear Models chapter (USC, Wasserman-style text)](https://dornsife.usc.edu/larry-goldstein/wp-content/uploads/sites/221/2023/06/LinearModels.pdf)
4. [Econometric Analysis, 8th ed., Chapter 3: Least Squares (Greene)](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M03_GREE1366_08_SE_C03.pdf)
5. [Econometric Analysis, 8th ed., Chapter 4: Estimating the Regression Model by Least Squares (Greene)](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M04_GREE1366_08_SE_C04.pdf)
6. [Wolberg, 'The Method of Least Squares' (book chapter history)](https://wolberg.net.technion.ac.il/files/2017/03/history.pdf)
7. [Classical Theory of Linear Statistical Models (Duke STAT 721 notes)](http://www2.stat.duke.edu/~pdh10/Teaching/721/Materials/notes.pdf)
8. [Chapter 7: Linear Models (Introduction to Data Science, Sarafian)](https://bookdown.org/ronsarafian/IntrotoDS/lm.html)
9. [Linear models lecture notes (Simon Wood)](https://webhomes.maths.ed.ac.uk/~swood34/mgcv/tampere/linear-models.pdf)
10. [Econometrics lecture notes: OLS estimation and inference](https://www.luischanci.com/documents/Econometrics/OLS.pdf)
11. [18.05 Reading 26: Linear regression (MIT OpenCourseWare)](https://ocw.mit.edu/courses/18-05-introduction-to-probability-and-statistics-spring-2022/mit18_05_s22_class26-prep.pdf)
12. [Lesson 5: Multiple Linear Regression (MLR) Model & Evaluation | STAT 462 (Penn State)](https://online.stat.psu.edu/stat462/node/83/)
13. [Chapter 6: Diagnosing Problems in Linear and Generalized Linear Models (Fox & Weisberg, An R Companion to Applied Regression)](https://us.sagepub.com/sites/default/files/upm-binaries/38503_Chapter6.pdf)
14. [Regression with R, Chapter 1 Introduction (Ekstrøm et al.)](https://rwr.nrhstat.org/1_introduction.html)
15. [Karl Pearson (1896). VII. Mathematical contributions to the theory of evolution., III. Regression, heredity, and panmixia. Philosophical Transactions of the Royal Society of London Series A Containing Papers of a Mathematical or Physical Character.](https://doi.org/10.1098/rsta.1896.0007)
16. [A. C. Aitken (1936). IV., On Least Squares and Linear Combination of Observations. Proceedings of the Royal Society of Edinburgh.](https://doi.org/10.1017/s0370164600014346)
17. [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)
18. [Generalized Linear Models (Nelder and Wedderburn, 1972)](https://www.maths.usyd.edu.au/u/jchan/GLM/Nelder1972GLM.pdf)
19. [Robert Tibshirani (1996). Regression Shrinkage and Selection Via the Lasso. Journal of the Royal Statistical Society Series B (Statistical Methodology).](https://doi.org/10.1111/j.2517-6161.1996.tb02080.x)
20. [1.1. Linear Models, scikit-learn documentation](https://scikit-learn.org/stable/modules/linear%5Fmodel.html)
21. [Emmanuel Candes, Terence Tao (2007). The Dantzig selector: Statistical estimation when p is much larger than n. The Annals of Statistics.](https://doi.org/10.1214/009053606000001523)
22. [Emmanuel Candès and colleagues (2018). Panning for Gold: ‘Model-X’ Knockoffs for High Dimensional Controlled Variable Selection. Journal of the Royal Statistical Society Series B (Statistical Methodology).](https://doi.org/10.1111/rssb.12265)
23. [Kaiyue Wen, Tengyao Wang, Yuhao Wang (2025). Residual permutation test for regression coefficient testing. The Annals of Statistics.](https://doi.org/10.1214/24-aos2479)
24. [Chapter 6 Linear Models | R (BGU course), John Ros](https://www.john-ros.com/Rcourse/lm.html)
25. [The Truth about Linear Regression (Cosma Shalizi, CMU lecture notes)](https://www.stat.cmu.edu/~cshalizi/TALR/TALR.pdf)
26. [Lecture notes on linear regression: least squares, ridgeless, ridge, and lasso (December 2024)](https://arxiv.org/pdf/2412.15633)

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

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

Copyright 2026 Edgepedia

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

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

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