# Theil–Sen估计器

**Theil–Sen估计器**是一种非参数方法，用于对数据拟合一条直线，其斜率估计为所有通过数据点对（x值不同）的直线斜率的中位数。它由荷兰计量经济学家亨利·泰尔（Henri Theil）于1950年提出，并由统计学家普拉纳布·K·森（Pranab K. Sen）于1968年推广，被用作普通最小二乘（OLS）回归的抗离群值替代方案，尤其适用于时间序列的趋势估计。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup><sup> • </sup><sup>[2](https://mathworld.wolfram.com/Theil-SenEstimator.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 斜率估计 | 所有满足\( x_i \neq x_j \)的点对之间斜率\( S_{ij} = (y_j - y_i)/(x_j - x_i) \)的中位数<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup> |
| 起源 | 泰尔（1950），*Indagationes Mathematicae*；由森（1968）推广，*Journal of the American Statistical Association*<sup>[2](https://mathworld.wolfram.com/Theil-SenEstimator.html)</sup> |
| 崩溃点 | 简单线性回归中约为29.3%，即最多可容许约29%的数据被污染，而不致使估计值任意偏移<sup>[3](https://scikit-learn.org/stable/auto_examples/linear_model/plot_theilsen.html)</sup> |
| 假设 | 变量之间存在线性关系；残差无需服从正态分布<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup> |
| 斜率数量 | 对于\( n \)个观测值，有\( n(n-1)/2 \)个斜率，这限制了可直接处理的样本量<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup> |
| 典型配套方法 | 水文学、气候学和空气质量趋势分析中的Mann–Kendall趋势检验<sup>[4](https://hess.copernicus.org/articles/27/229/2023/)</sup> |
| 软件 | `scipy.stats.theilslopes`（Python）、`TheilSenRegressor`（scikit-learn）、R包`mblm`，以及Dataplot的THEIL SEN FIT<sup>[5](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.theilslopes.html)</sup><sup> • </sup><sup>[6](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.TheilSenRegressor.html)</sup><sup> • </sup><sup>[7](https://www.stat.ethz.ch/CRAN/web/packages/mblm/index.html)</sup> |

## 定义与计算

给定\( n \)个观测值\( (x_i, y_i) \)，该方法计算通过每一对x值不同的点的直线斜率，然后取这些成对斜率的中位数作为\( \beta \)的估计。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup> x值相同的点对被省略，因为其斜率无定义。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup>南加利福尼亚大学心理学教授兰德·R·威尔科克斯（Rand R. Wilcox）指出一种等价的视角：该估计器寻找的斜率使得残差\( y_i - b x_i \)与预测变量之间的Kendall秩相关系数tau近似为零。<sup>[8](https://www.sciencedirect.com/topics/mathematics/sen-estimator)</sup>

截距有不止一种标准定义。美国国家标准与技术研究院的Dataplot文档将其估计为量\( y_i - \beta x_i \)的中位数。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup> SciPy的`theilslopes`同时提供这种“联合”形式和一种“分离”形式，即\( \mathrm{median}(y) - \beta \cdot \mathrm{median}(x) \)，并指出森的原始论文中未定义截距。<sup>[5](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.theilslopes.html)</sup>

斜率的置信区间可以解析计算。Dataplot使用标准误

\[ se_{\beta} = \sqrt{\frac{n (n-1) (2n+5)}{18}} \]

从排序后的斜率估计中构造边界；自助法和刀切法重采样是常见的替代方案。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup> openair项目将该方法应用于空气污染数据，报告称即使数据非正态且存在异方差性（即误差方差不恒定），该估计器也往往能给出准确的置信区间。<sup>[9](https://openair-project.github.io/book/sections/trend-analysis/theil-sen.html)</sup>

## 稳健性与效率

该估计器的吸引力在于数据不完美时的表现。OLS的影响函数无界，崩溃点为零，因此单个极端点就能任意移动拟合直线；当误差项存在异方差或非正态时，OLS斜率的常规置信区间也可能覆盖概率很低。<sup>[10](https://doi.org/10.1002/%28SICI%291521-4036%28199807%2940%3A3%3C261%3A%3AAID-BIMJ261%3E3.0.CO;2-V)</sup> Theil–Sen估计器则具有有界的影响函数，在单预测变量下有限样本崩溃点约为0.29，即需要改变约29%的数据才能使斜率或截距估计任意偏离原值。<sup>[8](https://www.sciencedirect.com/topics/mathematics/sen-estimator)</sup><sup> • </sup><sup>[10](https://doi.org/10.1002/%28SICI%291521-4036%28199807%2940%3A3%3C261%3A%3AAID-BIMJ261%3E3.0.CO;2-V)</sup>威尔科克斯1998年的模拟研究发现，其在异方差下的小样本效率与其他稳健估计器相比具有竞争力，在某些情况下还显著优于它们。<sup>[10](https://doi.org/10.1002/%28SICI%291521-4036%28199807%2940%3A3%3C261%3A%3AAID-BIMJ261%3E3.0.CO;2-V)</sup>

当不存在离群值时，Theil–Sen拟合与OLS拟合非常相似。<sup>[7](https://www.stat.ethz.ch/CRAN/web/packages/mblm/index.html)</sup>理论图景比简单的效率比较所暗示的更为微妙。彭汉祥（Hanxiang Peng）、王少利（Shaoli Wang）和王学勤（Xueqin Wang）在2008年证明，该估计器对任意误差分布是强相合的，当误差分布不连续时是超有效的，且一般不是渐近正态的，但在森所假设的绝对连续条件下是渐近正态的。<sup>[11](https://www.sciencedirect.com/science/article/pii/S0378375807003254)</sup>

## 计算成本与多变量扩展

成对斜率的数量以\( n(n-1)/2 \)增长，大致为\( n^2 \)量级，这限制了直接计算能处理的样本量。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup><sup> • </sup><sup>[9](https://openair-project.github.io/book/sections/trend-analysis/theil-sen.html)</sup>实际应对方法包括在数据对的随机子集上计算估计器（如Dataplot所建议），或像scikit-learn那样进行子采样。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup>

对于多预测变量，scikit-learn的`TheilSenRegressor`推广了这一思想：它在从样本中抽取的大小为`n_subsamples`的子集上计算最小二乘解，然后取所有这些解的空间中位数（L1中位数）。任何介于特征数和样本数之间的子集大小都在稳健性与效率之间给出折中，较小的子集给出更高的稳健性和较低的效率；当子集大小等于样本数时，该方法等同于最小二乘。由于可能的子集数量呈组合式增长，`max_subpopulation`限制（默认10,000）在达到限制后通过随机选择子集来限制计算量。<sup>[6](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.TheilSenRegressor.html)</sup>

一个密切相关但更稳健的方法是西格尔（Siegel）的重复中位数估计器（1982），它取中位数的中位数，达到50%的崩溃点；R包`mblm`同时提供两者。<sup>[7](https://www.stat.ethz.ch/CRAN/web/packages/mblm/index.html)</sup><sup> • </sup><sup>[12](https://www.mclibre.org/descargar/docs/revistas/the-r-journal/the-r-journal-30-en-202212.pdf)</sup>用于方法比较研究的Passing–Bablok回归也与此相关；区别在于Theil–Sen假设x值固定无误差，而Passing–Bablok假设x值带有测量误差。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup>

## 应用

该估计器是环境科学中单调趋势分析的标准工具，通常与Mann–Kendall检验配对使用，后者无分布假设且对离群值稳健。在一项澳大利亚河流流量研究中，Theil–Sen斜率量化了年和季节流量的趋势幅度，而修正的Mann–Kendall检验评估了序列相关和长期持续性下的显著性。<sup>[4](https://hess.copernicus.org/articles/27/229/2023/)</sup>美国地质调查局使用Theil–Sen斜率配合Conover截距方程绘制峰值流量趋势线，置信区间来自吉尔伯特（Gilbert）对该方法的修正。<sup>[13](https://pubs.usgs.gov/publication/sir20235064A/full)</sup>2023年水文学的一项蒙特卡洛研究发现，Theil–Sen斜率估计本身在不同平均窗口大小下准确且稳定，即使Mann–Kendall检验的效力随缺失数据和聚合方式而变化。<sup>[14](https://doi.org/10.1080/02626667.2023.2212166)</sup>

在环境科学之外，奥尔森（Ohlson）和金（Kim）将该估计器应用于横截面会计估值，其中OLS受困于有影响力的离群值和异方差误差；他们发现Theil–Sen在估计系数的跨期稳定性和拟合优度两方面都优于OLS，部分原因是OLS偶尔产生错误的系数符号。<sup>[15](https://research.manchester.ac.uk/en/publications/linear-valuation-without-ols-the-theil-sen-estimation-approach/)</sup>

## 局限性

该方法假设变量之间存在线性关系，且在其标准形式下假设数据序列独立；对自相关时间序列的趋势分析需要修正检验或块自助法推断，因为忽略依赖性会给出过于乐观的不确定性印象。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup><sup> • </sup><sup>[16](https://link.springer.com/article/10.1007/s00382-015-2838-0)</sup><sup> • </sup><sup>[9](https://openair-project.github.io/book/sections/trend-analysis/theil-sen.html)</sup>成对斜率的二次增长使精确计算对大样本不切实际，而用于绕开这一问题的随机子采样牺牲了估计器的一些数学性质。<sup>[1](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)</sup><sup> • </sup><sup>[3](https://scikit-learn.org/stable/auto_examples/linear_model/plot_theilsen.html)</sup>

## References

1. [THEIL SEN FIT, NIST/SEMATECH Dataplot Reference Manual](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/ts_fit.htm)
2. [Theil-Sen Estimator, Wolfram MathWorld](https://mathworld.wolfram.com/Theil-SenEstimator.html)
3. [Theil-Sen Regression example, scikit-learn documentation](https://scikit-learn.org/stable/auto_examples/linear_model/plot_theilsen.html)
4. [Regional significance of historical trends and step changes in Australian streamflow, Hydrology and Earth System Sciences 27, 229 (2023)](https://hess.copernicus.org/articles/27/229/2023/)
5. [scipy.stats.theilslopes, SciPy v1.18.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.theilslopes.html)
6. [TheilSenRegressor, scikit-learn 1.9.1 documentation](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.TheilSenRegressor.html)
7. [mblm: Median-Based Linear Models, CRAN](https://www.stat.ethz.ch/CRAN/web/packages/mblm/index.html)
8. [Sen Estimator: an overview, ScienceDirect Topics (Rand Wilcox, Introduction to Robust Estimation and Hypothesis Testing)](https://www.sciencedirect.com/topics/mathematics/sen-estimator)
9. [Theil-Sen trends, The openair book](https://openair-project.github.io/book/sections/trend-analysis/theil-sen.html)
10. [Wilcox, R. (1998). A Note on the Theil-Sen Regression Estimator When the Regressor Is Random and the Error Term Is Heteroscedastic. Biometrical Journal 40(3), 261–268.](https://doi.org/10.1002/%28SICI%291521-4036%28199807%2940%3A3%3C261%3A%3AAID-BIMJ261%3E3.0.CO;2-V)
11. [Peng, H., Wang, S., Wang, X. (2008). Consistency and asymptotic distribution of the Theil–Sen estimator. Journal of Statistical Planning and Inference 138(6), 1836–1850.](https://www.sciencedirect.com/science/article/pii/S0378375807003254)
12. [Theil-Sen and Siegel's repeated median slope in R, The R Journal 30 (2022)](https://www.mclibre.org/descargar/docs/revistas/the-r-journal/the-r-journal-30-en-202212.pdf)
13. [Peak streamflow trends and their relation to changes in climate in the upper Midwest United States, USGS Scientific Investigations Report 2023-5064-A](https://pubs.usgs.gov/publication/sir20235064A/full)
14. [Do the Mann-Kendall test and Theil-Sen slope fail to inform trend significance and magnitude in hydrology? Hydrological Sciences Journal (2023)](https://doi.org/10.1080/02626667.2023.2212166)
15. [Ohlson, J., Kim, S. (2014). Linear valuation without OLS: The Theil-Sen estimation approach. Review of Accounting Studies 20(1), 395–435.](https://research.manchester.ac.uk/en/publications/linear-valuation-without-ols-the-theil-sen-estimation-approach/)
16. [On trend estimation and significance testing for non-Gaussian and serially dependent data, Climate Dynamics (2015)](https://link.springer.com/article/10.1007/s00382-015-2838-0)

---
*Initially written Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Statistical inference, estimation, sampling, and testing › Estimation theory and estimator families › Robust statistics and resampling › Robust regression and outliers in modeling

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/theil-sen-estimator

English original: https://www.edgepedia.org/theil-sen-estimator
