Σ
SDCalc
进阶概念·12 min

稳健统计学:MAD、IQR 与抗异常值方法

稳健统计学完全指南,包括中位数绝对偏差 (MAD) 和四分位距 (IQR)。学习何时使用抗异常值的离散度指标,附示例和 Python 代码。

为什么需要稳健统计?

标准差是一个强大的离散度指标,但它有一个致命弱点:对异常值极其敏感。一个极端值就能大幅推高标准差,给出对典型变异的误导性描述。

稳健统计提供的离散度指标能够抵御异常值的影响,在现实数据中尤为重要——因为测量误差、数据录入错误或真正的极端情况都很常见。

示例:异常值的影响

数据:10, 12, 11, 13, 12, 11, 100(一个异常值) 标准差:32.4(被异常值主导) MAD:1.0(忽略了异常值) IQR:1.5(忽略了异常值)

崩溃点

统计量的“崩溃点”是指数据中极端值达到多少比例时,该统计量才会变得毫无意义。标准差的崩溃点为 0%(一个异常值就能破坏它)。MAD 和 IQR 的崩溃点为 50%——即使一半数据是异常值,它们仍然有效。

中位数绝对偏差 (MAD)

MAD 是最稳健的离散度指标。它计算的是各数据点与中位数的绝对偏差的中位数:

MAD 公式

MAD = median(|xᵢ - median(x)|)
1

求中位数

计算数据集的中位数。
2

计算偏差

用每个数值减去中位数,取绝对值。
3

求 MAD

计算这些绝对偏差的中位数。

用 MAD 估计 σ:对于正态分布数据,MAD ≈ 0.6745 × σ。要从 MAD 估算标准差,乘以 1.4826:

由 MAD 估计标准差

σ̂ = 1.4826 × MAD

为什么是 1.4826?

这个缩放系数来源于正态分布下 MAD 与标准差之间的关系。它确保缩放后的 MAD 在数据服从正态分布时是真实标准差的无偏估计量。

四分位距 (IQR)

IQR 衡量的是数据中间 50% 的离散程度——即第 25 百分位数与第 75 百分位数之间的范围:

IQR 公式

IQR = Q3 - Q1 = 第 75 百分位数 - 第 25 百分位数

IQR 被广泛使用,因为它易于理解、在箱线图中直观呈现,并且是常见的“1.5×IQR 法则”异常值检测的基础。

用 IQR 估计 σ:对于正态数据,IQR ≈ 1.35 × σ。要从 IQR 估算标准差:

由 IQR 估计标准差

σ̂ = IQR / 1.35 ≈ 0.7413 × IQR

稳健指标对比

标准差

使用所有数据点 · 对正态数据效率最高 · 对异常值极其敏感 · 崩溃点:0%

MAD

最稳健的指标 · 使用中位数(而非均值) · 不受任何异常值影响 · 崩溃点:50%

IQR

易于理解 · 用于箱线图 · 忽略极端 50% 的数据 · 崩溃点:25%

何时使用稳健统计

  • 探索性分析:当你不确定是否存在异常值时,先使用稳健指标
  • 数据质量问题:当数据可能包含错误或测量问题时
  • 厚尾分布:当极端值在预期之中时(金融收益、保险理赔)
  • 小样本:当异常值因观测值少而影响过大时
  • 异常值检测:用标准差来检测异常值是循环论证;应该用 IQR 或 MAD

代码实现

Python
import numpy as np
from scipy import stats

def mad(data):
    """Median Absolute Deviation"""
    median = np.median(data)
    return np.median(np.abs(data - median))

def scaled_mad(data):
    """MAD scaled to estimate SD (for normal data)"""
    return 1.4826 * mad(data)

def iqr(data):
    """Interquartile Range"""
    return np.percentile(data, 75) - np.percentile(data, 25)

# Compare on data with outlier
data = [10, 12, 11, 13, 12, 11, 100]
print(f"SD: {np.std(data, ddof=1):.2f}")
print(f"MAD: {mad(data):.2f}")
print(f"Scaled MAD: {scaled_mad(data):.2f}")
print(f"IQR: {iqr(data):.2f}")

Further Reading

How to Read This Article

A statistics tutorial is a practical interpretation guide, not just a formula dump. It refers to the assumptions, notation, and reporting language that analysts need when they explain a result to a teacher, manager, client, or reviewer. The article body covers the specific topic, while the sections below create a common interpretation frame that readers can reuse across related metrics.

Reading goalWhat to focus onCommon mistake
DefinitionWhat the metric is and what quantity it summarizesTreating the formula as self-explanatory
Formula choiceSample versus population assumptions and notationUsing n when n-1 is required or vice versa
InterpretationWhether the result indicates concentration, spread, or riskCalling a large value good or bad without context

Frequently Asked Questions

How should I interpret a high standard deviation?

A high standard deviation means the observations are spread farther from the mean on average. Whether that spread is acceptable depends on the context: wide dispersion might signal risk in finance, instability in manufacturing, or genuine natural variation in scientific data.

Why do some articles mention n while others mention n-1?

The denominator reflects the difference between population and sample formulas. Population variance and population standard deviation use N because the full dataset is known. Sample variance and sample standard deviation often use n-1 because Bessel’s correction reduces bias when estimating population spread from a sample.

What is a statistical interpretation guide?

A statistical interpretation guide is a page that moves beyond arithmetic and explains meaning. It tells you what a metric is, when the formula applies, and how to describe the result in plain English without overstating certainty.

Can I cite this article in a report?

You should cite the underlying authoritative reference for formal work whenever possible. This page is best used as an explanatory bridge that helps you understand the concept before quoting the original standard or handbook.

Why include direct citations on every article page?

Direct citations give readers a route to verify the definition, notation, and assumptions. That improves trust and reduces the chance that a simplified explanation is mistaken for the entire technical standard.

Authoritative References

These sources define the concepts referenced most often across our articles. Bessel's correction is a sample adjustment, variance is a squared measure of spread, and standard deviation is the square root of variance expressed in the same units as the data.