# 残差平方和

**残差平方和**（residual sum of squares，RSS）是对所有观测值，取观测响应值与拟合回归模型预测值之差的平方的总和：RSS = Σᵢ(yᵢ − ŷᵢ)²，其中 ŷᵢ 为拟合值<sup>[1](https://statproofbook.github.io/P/slr-sss.html)</sup>。它正是普通最小二乘法（OLS）为估计系数而最小化的量，也是计算 R²、残差标准误与 F 检验的原材料<sup>[2](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)</sup>。

| 关键事实 | 细节 |
|---|---|
| 定义 | RSS = Σᵢ(yᵢ − ŷᵢ)²，即残差平方之和；残差为 eᵢ = yᵢ − f(xᵢ; β̂)，即观测值减拟合值<sup>[1](https://statproofbook.github.io/P/slr-sss.html)</sup><sup> • </sup><sup>[3](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd44.htm)</sup> |
| 最小化者 | OLS 求解正规方程 X′Xb = X′y；当 X 列满秩时，解 b = (X′X)⁻¹X′y 唯一<sup>[4](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M03_GREE1366_08_SE_C03.pdf)</sup> |
| R² | R² = 1 − RSS/TSS，其中 TSS = Σᵢ(yᵢ − ȳ)²；对于含截距的 OLS 回归，等价地有 R² = cor(y, ŷ)²<sup>[2](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)</sup> |
| 误差方差 | E(RSS) = σ²(n − p − 1)，故 σ̂² = RSS/(n − p − 1) 无偏；σ̂ 即残差标准误<sup>[5](https://www.stat.berkeley.edu/~aditya/resources/LectureSEVEN.pdf)</sup> |
| 分布 | 在高斯线性模型下，RSS/σ² 服从自由度为 n − p − 1 的卡方分布，其中 p 为斜率参数个数<sup>[6](https://statproofbook.github.io/P/mlr-rssdist.html)</sup> |
| 解释的局限 | RSS 未标准化：它不针对数据的尺度或样本量进行调整，因此拟合优度相同的模型也可能给出相差悬殊的 RSS 值<sup>[7](https://statisticsbyjim.com/regression/residual-sum-of-squares-rss/)</sup> |
| 记号陷阱 | 有些教材用 RSS 指回归（被解释）平方和；SSE、SSR、ESS、TSS 在不同教科书里含义各异<sup>[8](https://econometricstutor.com/econometrics/simple-linear-regression-ols/goodness-of-fit/sst-ssr-sse-decomposition/)</sup><sup> • </sup><sup>[7](https://statisticsbyjim.com/regression/residual-sum-of-squares-rss/)</sup> |

## 定义与计算

对第 i 个观测，残差是观测响应值与由回归函数算出的预测值之差：eᵢ = yᵢ − f(xᵢ; β̂)<sup>[3](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd44.htm)</sup>。残差是模型误差项 εᵢ 的估计，而残差平方和度量数据与估计模型之间的总体差异；值越小，估计越好<sup>[9](https://help.reliasoft.com/articles/content/hotwire/issue86/relbasics86.htm)</sup>。

用矩阵形式表示，对于响应向量为 y、设计矩阵为 X 的线性模型，被最小化的准则为 S(b) = (y − Xb)′(y − Xb)<sup>[4](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M03_GREE1366_08_SE_C03.pdf)</sup>。RSS 的单位是响应变量单位的平方，这也是它很少被单独解释的原因之一<sup>[2](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)</sup><sup> • </sup><sup>[26](https://epurdom.github.io/Stat131A/book/multiple-regression.html)</sup>。

## 在最小二乘估计中的作用

普通最小二乘法选择使残差平方和最小的系数向量。令 S(b) 的导数为零，得到正规方程 X′Xb = X′y<sup>[4](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M03_GREE1366_08_SE_C03.pdf)</sup>。若 X 列满秩，则 X′X 正定，解 b = (X′X)⁻¹X′y 唯一，且使残差平方和最小；若不满秩，最小化者不唯一<sup>[4](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M03_GREE1366_08_SE_C03.pdf)</sup>。拟合值可通过帽子矩阵 P = Z(Z′Z)⁻¹Z′ 写出，该矩阵对称且幂等，残差等于 (Iₙ − P)y；正是这种投影视角使最小二乘的几何结构得以成立<sup>[10](https://bookdown.org/peter_neal/math4081-lectures/Sec_Linear_LSE.html)</sup>。

对线性模型，最小化通常用微积分解析地完成；对非线性模型，则几乎总是必须用迭代数值算法完成<sup>[11](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm)</sup>。

**历史渊源。** 最小二乘法最早由阿德里安-马里·勒让德（Adrien-Marie Legendre）在1805年的著作《确定彗星轨道的若干新方法》（*Nouvelles méthodes pour la détermination des orbites des comètes*）中命名并发表，作为题为“论最小平方方法”（Sur la Méthode des moindres quarrés）的附录<sup>[12](https://hedibert.org/wp-content/uploads/2016/08/plackett1972-thediscoveryofthemethodofleastsquares.pdf)</sup><sup> • </sup><sup>[13](https://www.york.ac.uk/depts/maths/histstat/legendre.htm)</sup>。卡尔·弗里德里希·高斯（Carl Friedrich Gauss）自约1795年起就在使用该方法，他1809年的论述引发了与勒让德的优先权之争<sup>[12](https://hedibert.org/wp-content/uploads/2016/08/plackett1972-thediscoveryofthemethodofleastsquares.pdf)</sup>。勒让德把最小二乘发展为一种不假设随机性的近似工具，而高斯则在随机变量与分布的框架下工作，并首次证明：在正态性下的标准线性模型中，最大似然估计量等于最小二乘公式<sup>[14](https://link.springer.com/article/10.1007/s00407-022-00291-w)</sup>。在1805年之前约五十年间，就已存在以最小化最大偏差或绝对偏差之和为目标的竞争性准则；对最小二乘胜出的一种解释是几何解释——内积产生夹角与正交性，从而统一了一般线性模型、方差分析、充分性与时间序列的诸多结果<sup>[15](https://www.tandfonline.com/doi/abs/10.1198/000313006X151109)</sup>。

## 与其他平方和的关系及记号

在含截距的回归中，总平方和分解为 TSS = ESS + RSS，这是一个代数恒等式，只要回归含截距，在每一个样本中都成立<sup>[8](https://econometricstutor.com/econometrics/simple-linear-regression-ols/goodness-of-fit/sst-ssr-sse-decomposition/)</sup>。对简单线性回归，各部分可用样本矩写出：TSS = (n−1)s_y²，ESS = (n−1)s_xy²/s_x²，RSS = (n−1)(s_y² − s_xy²/s_x²)<sup>[1](https://statproofbook.github.io/P/slr-sss.html)</sup>。将恒等式两边除以 n，即得方差分析中组间加组内的方差分解，说明回归与方差分析不过是同一恒等式的不同标签<sup>[8](https://econometricstutor.com/econometrics/simple-linear-regression-ols/goodness-of-fit/sst-ssr-sse-decomposition/)</sup>。

各缩写在不同教科书中相互冲突。伍尔德里奇（Wooldridge）用 SSE 指被解释平方和，斯托克与沃森（Stock and Watson）把同一量称为 ESS，而许多应用统计学教材用 SSE 指误差平方和，即残差平方和<sup>[8](https://econometricstutor.com/econometrics/simple-linear-regression-ols/goodness-of-fit/sst-ssr-sse-decomposition/)</sup>。有些教材用 SSR 指残差平方和<sup>[8](https://econometricstutor.com/econometrics/simple-linear-regression-ols/goodness-of-fit/sst-ssr-sse-decomposition/)</sup>。某些记号甚至用 RSS 指回归平方和而非残差平方和<sup>[7](https://statisticsbyjim.com/regression/residual-sum-of-squares-rss/)</sup>。例如在斯坦福 Stats 191 的约定中，SSE 表示自由度为 n − 2 的残差量，SSR 表示自由度为 1 的被解释量，SST 表示自由度为 n − 1 的总量<sup>[16](https://web.stanford.edu/class/stats191/Chapter8/Simple_Linear_Regression_Assumptions.html)</sup>。稳妥的做法是核对某一来源的缩写究竟指哪个量，而不要轻信字母本身。

## 用数字说话：R²、残差方差与标准误

RSS 与两种最常见的拟合摘要相联系。对含截距的 OLS 模型，决定系数为 R² = 1 − RSS/TSS，取值在 0 与 1 之间；对同一数据拟合的模型增加解释变量时，它不会减小<sup>[2](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)</sup><sup> • </sup><sup>[5](https://www.stat.berkeley.edu/~aditya/resources/LectureSEVEN.pdf)</sup>。一个 R 语言的算例，计算 `sum((ft1$residuals)^2)` 得 RSS = 11359.07，R² = 0.8535076，后者经 cor(y, fitted)² 验证<sup>[2](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)</sup>。

**自由度。** 由于拟合 p 个斜率参数加一个截距要消耗 p + 1 个自由度，残差自由度为 df = n − p − 1<sup>[2](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)</sup>。RSS 的期望值为 σ²(n − p − 1)，故误差方差的无偏估计量为 σ̂² = RSS/(n − p − 1)，σ̂ 称为残差标准误<sup>[5](https://www.stat.berkeley.edu/~aditya/resources/LectureSEVEN.pdf)</sup>。关于计数的约定并不一致：美国国家标准与技术研究院手册写作 σ̂ = √(Q/(n−p))，其中 p 为模型函数部分的参数个数<sup>[11](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm)</sup>，而简单回归教材除以 n − 2，即 β̂₀ 与 β̂₁ 各占一个自由度<sup>[8](https://econometricstutor.com/econometrics/simple-linear-regression-ols/goodness-of-fit/sst-ssr-sse-decomposition/)</sup><sup> • </sup><sup>[17](https://www.investopedia.com/terms/r/residual-sum-of-squares.asp)</sup>。

在高斯线性模型下，当 p 为斜率参数个数时，RSS/σ² 服从自由度为 n − p − 1 的卡方分布，这正是建立在 RSS 之上的 t 检验与 F 推断背后的分布事实<sup>[6](https://statproofbook.github.io/P/mlr-rssdist.html)</sup>。同一个 σ̂ 也进入系数标准误：β̂ᵢ 的标准误等于 σ̂ 乘以 (X′X)⁻¹ 第 i 个对角元的平方根<sup>[5](https://www.stat.berkeley.edu/~aditya/resources/LectureSEVEN.pdf)</sup>。残差本身方差不等，var(êᵢ) = σ²(1 − hᵢᵢ)，其中 hᵢᵢ 为帽子矩阵第 i 个对角元；除以 σ̂√(1 − hᵢᵢ) 即得标准化残差<sup>[5](https://www.stat.berkeley.edu/~aditya/resources/LectureSEVEN.pdf)</sup>。

RSS 单独很难解释，因为它未标准化：它不针对数据的尺度或样本量进行调整，因此两个拟合优度相同的数据集也可能给出相差悬殊的 RSS 值；RSS 主要充当通往 R²、RMSE 与回归标准误的踏脚石<sup>[7](https://statisticsbyjim.com/regression/residual-sum-of-squares-rss/)</sup>。

## 在推断与模型比较中的用途

检验 H₀: β₁ = … = βₚ = 0 的总体 F 统计量为 [(TSS − RSS)/p] / [RSS/(n − p − 1)]，即把每个预测变量所解释的方差与每个残差自由度所剩余的方差相比较<sup>[2](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)</sup>。在简单回归中，它化为 F = (n − 2)R²/(1 − R²)<sup>[16](https://web.stanford.edu/class/stats191/Chapter8/Simple_Linear_Regression_Assumptions.html)</sup>。在比较受约束模型与嵌套的更全模型时，F = [(SSE_R − SSE_F)/(df_R − df_F)] / (SSE_F/df_F)<sup>[16](https://web.stanford.edu/class/stats191/Chapter8/Simple_Linear_Regression_Assumptions.html)</sup>。

增加一个预测变量只能使 RSS 减小或保持不变，因为 OLS 在更大的参数空间上重新寻优；去掉一个预测变量只能使 RSS 增大或保持不变<sup>[2](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)</sup>。正是这种单调性使得原始 RSS 无法用于模型选择：调整后 R² = 1 − [RSS/(n−p−1)]/[TSS/(n−1)] 对自由度施加惩罚，在加入弱预测变量时可能下降<sup>[2](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)</sup>。在设计实验中，误差自由度等于观测数超出未知参数数的部分，例如 7 个观测、3 个未知参数给出 4；检验失拟时，分母为纯误差的均方，而检验模型项时，分母为残差均方<sup>[9](https://help.reliasoft.com/articles/content/hotwire/issue86/relbasics86.htm)</sup>。

## 假设、局限与稳健或惩罚变体

平方使离群点在模型拟合过程中的影响显著大于常规数据点，可能使模型产生偏倚；而且 RSS 低并不能保证最小二乘的假设——线性性、误差独立性与同方差性（即误差方差在各观测间恒定的假设）——得到满足<sup>[7](https://statisticsbyjim.com/regression/residual-sum-of-squares-rss/)</sup>。由于 RSS 对所有残差等权，离群点可能对其产生不成比例的影响，而违反线性性、误差独立性或同方差性可能导致错误的推断<sup>[17](https://www.investopedia.com/terms/r/residual-sum-of-squares.asp)</sup>。在重尾数据的高维情形下，最小二乘类估计量的经典优良性质（如无偏性与校准性）会失效，这促使人们在次高斯特征与有界噪声方差之外寻求稳健的替代方案<sup>[18](https://iopscience.iop.org/article/10.1088/1742-5468/ad65e6/meta)</sup>。

**稳健替代方案**改变施加于残差的函数。当误差重尾或含离群点时，最小二乘估计量表现很差<sup>[19](https://ar5iv.labs.arxiv.org/html/2202.10329)</sup>。最小截断平方（LTS，罗素（Rousseeuw），1984年）对残差平方排序，截去较大者，至少保留 ⌊n/2⌋ 个，并最小化其和；一种深度截断变体（LST）在渐近意义下可抵抗高达 50% 的污染而不崩溃，相比之下经典最小二乘估计量的崩溃点为 0%<sup>[19](https://ar5iv.labs.arxiv.org/html/2202.10329)</sup>。平均绝对误差赋予所有误差同等重要性，对离群点最为稳健，但在原点不可微；Huber 损失与 Log-Cosh 损失被提出作为可微近似，而更新的平滑损失如 SMAE 在小误差时近似 MSE、在大误差时近似 MAE<sup>[20](https://arxiv.org/html/2606.22068v1)</sup>。最小绝对残差（LAR）方法对应于误差服从双指数（拉普拉斯）分布时的最大似然估计量，并且比最小二乘（高斯误差下的 MLE）对离群观测更稳健；两者都属于 Lp 范数族，最小二乘对应 p = 2，p = ∞ 则为极小极大准则<sup>[21](https://encyclopediaofmath.org/wiki/Least_absolute_residuals_procedure)</sup>。Huber 回归本身也已通过其相对于 OLS 的渐近相对效率下界得到研究<sup>[22](https://www.mdpi.com/2227-7390/14/7/1138)</sup>。

**惩罚变体**保留 RSS 项但加入约束或惩罚。当变量数超过观测数时，传统 LS 估计量不再唯一，且当设计矩阵接近共线时方差很大<sup>[23](https://arxiv.org/pdf/2309.01666v1.pdf)</sup>。岭回归在 L2 约束下最小化残差平方和，闭式解为 β̂_ridge(λ) = (X′X + λI)⁻¹X′Y<sup>[23](https://arxiv.org/pdf/2309.01666v1.pdf)</sup>。lasso 在 L1 约束下最小化残差平方和，将 LS 估计量向零收缩，并可将某些系数精确置零，起到变量选择算子的作用<sup>[23](https://arxiv.org/pdf/2309.01666v1.pdf)</sup>。

## 用数字说话：比较拟合度量

OLS 回归中常用三种统计量评价模型拟合：R²、总体 F 检验与均方根误差（RMSE）<sup>[24](https://cscu.cornell.edu/wp-content/uploads/regfit.pdf)</sup>。RMSE 是残差方差的平方根，是与响应变量同单位的绝对拟合度量，而 R² 是相对度量；RMSE 越低表示拟合越好，当模型目的在于预测时，RMSE 是最重要的准则<sup>[24](https://cscu.cornell.edu/wp-content/uploads/regfit.pdf)</sup>。因此，“好”的 RSS 没有绝对阈值；它要通过这些经过缩放的相关指标、并在同一数据上与可比模型对照来评判。

平方误差准则有精确的依据：在独立同分布误差服从正态分布时，最大化似然等同于最小化偏差平方和<sup>[14](https://link.springer.com/article/10.1007/s00407-022-00291-w)</sup>。当误差非高斯时，这种等价一般失效；重尾误差或离群点会使平方误差成为糟糕的选择，原因如上<sup>[19](https://ar5iv.labs.arxiv.org/html/2202.10329)</sup><sup> • </sup><sup>[20](https://arxiv.org/html/2606.22068v1)</sup>。高维稳健回归的近期实践也已把调参从样本内准则转移开：通过最小化样本外误差估计来选择稳健 M 估计损失的调节参数 λ，可在所考虑的区间上得到最优的样本外误差，这反映了从样本内残差摘要转向样本外误差估计的趋势<sup>[25](https://jmlr.org/papers/volume26/24-0060/24-0060.pdf)</sup>。

## References

1. [The Book of Statistical Proofs: Sums of squares for simple linear regression](https://statproofbook.github.io/P/slr-sss.html)
2. [Lecture 19: Multiple Linear Regression II (STAT 131A, UC Berkeley)](https://stat131a.berkeley.edu/fall-2025/build/Lecture19_STAT131A-69058beb8ee096d24a9cacd20765393a.pdf)
3. [NIST/SEMATECH e-Handbook, Section 4.4.4: How can I tell if a model fits my data?](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd44.htm)
4. [Greene, Econometric Analysis, 8th ed., Chapter 3: Least Squares](https://pages.stern.nyu.edu/~wgreene/Text/Edition8/PDF/M03_GREE1366_08_SE_C03.pdf)
5. [Fall 2013 Statistics 151, Lecture Seven, UC Berkeley](https://www.stat.berkeley.edu/~aditya/resources/LectureSEVEN.pdf)
6. [The Book of Statistical Proofs: Distribution of residual sum of squares in multiple linear regression](https://statproofbook.github.io/P/mlr-rssdist.html)
7. [Statistics By Jim: Residual Sum of Squares (RSS) Explained](https://statisticsbyjim.com/regression/residual-sum-of-squares-rss/)
8. [EconometricsTutor: SST = SSE + SSR decomposition](https://econometricstutor.com/econometrics/simple-linear-regression-ols/goodness-of-fit/sst-ssr-sse-decomposition/)
9. [ReliaSoft HotWire Issue 86: Discussion of the Residual Sum of Squares in DOE](https://help.reliasoft.com/articles/content/hotwire/issue86/relbasics86.htm)
10. [Chapter 17: Least Squares Estimation for Linear Models (Foundations of Statistics, bookdown)](https://bookdown.org/peter_neal/math4081-lectures/Sec_Linear_LSE.html)
11. [NIST/SEMATECH e-Handbook, Section 4.4.3.1: Least Squares](https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm)
12. [Plackett (1972), The Discovery of the Method of Least Squares](https://hedibert.org/wp-content/uploads/2016/08/plackett1972-thediscoveryofthemethodofleastsquares.pdf)
13. [English translation of Legendre's 1805 appendix, University of York](https://www.york.ac.uk/depts/maths/histstat/legendre.htm)
14. [Gauss on least-squares and maximum-likelihood estimation, Archive for History of Exact Sciences](https://link.springer.com/article/10.1007/s00407-022-00291-w)
15. [The Victory of Least Squares and Orthogonality in Statistics, The American Statistician (2006)](https://www.tandfonline.com/doi/abs/10.1198/000313006X151109)
16. [Stanford Stats 191: Assumptions for simple linear regression](https://web.stanford.edu/class/stats191/Chapter8/Simple_Linear_Regression_Assumptions.html)
17. [Investopedia: Residual Sum of Squares (RSS)](https://www.investopedia.com/terms/r/residual-sum-of-squares.asp)
18. [High-dimensional robust regression under heavy-tailed data, Journal of Statistical Mechanics](https://iopscience.iop.org/article/10.1088/1742-5468/ad65e6/meta)
19. [Least sum of squares of trimmed residuals regression, arXiv preprint](https://ar5iv.labs.arxiv.org/html/2202.10329)
20. [New Smooth Loss functions for Robust Regression that Closely Approximate Absolute Error, arXiv preprint](https://arxiv.org/html/2606.22068v1)
21. [Least absolute residuals procedure, Encyclopedia of Mathematics](https://encyclopediaofmath.org/wiki/Least_absolute_residuals_procedure)
22. [Lower Bounds for the Asymptotic Relative Efficiency of Huber Regression, Mathematics (MDPI)](https://www.mdpi.com/2227-7390/14/7/1138)
23. [Robust penalized least squares of depth trimmed residuals regression for high-dimensional data, arXiv preprint](https://arxiv.org/pdf/2309.01666v1.pdf)
24. [Assessing the Fit of Regression Models, Cornell Statistical Consulting Unit](https://cscu.cornell.edu/wp-content/uploads/regfit.pdf)
25. [Error estimation and adaptive tuning for unregularized robust M-estimator, Journal of Machine Learning Research](https://jmlr.org/papers/volume26/24-0060/24-0060.pdf)
26. [Chapter 6 Multiple Regression, Statistical Methods for Data Science](https://epurdom.github.io/Stat131A/book/multiple-regression.html)

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

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

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/residual-sum-of-squares

English original: https://www.edgepedia.org/residual-sum-of-squares
