# Box–Cox 变换

Box–Cox 变换是一族作用于严格取正值的响应变量的幂变换，以参数 λ 为索引，其选取使变换后的数据更好地满足正态理论线性模型的假设：误差方差恒定、近似正态性以及简单的可加结构。<sup>[1](https://doi.org/10.1214/20-STS778)</sup> 1964 年的原始论文假定，只有在响应经过适当变换之后，正态、同方差线性模型才是适用的。<sup>[2](https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1964.tb00553.x)</sup> 由于数据必须为正，该方法要么要求观测值为正，要么需要加上一个常数，即如平移幂变换中那样。<sup>[3](https://link.springer.com/chapter/10.1007/978-3-031-88365-1_6)</sup>

| 关键事实 | 细节 |
|---|---|
| 公式 | 当 \( \lambda \neq 0 \) 时，\( y^{(\lambda)} = (y^{\lambda} - 1)/\lambda \)；当 \( \lambda = 0 \) 时，\( \log y \)<sup>[1](https://doi.org/10.1214/20-STS778)</sup> |
| 特殊值 | \( \lambda = 1 \) 不变换，\( \lambda = 1/2 \) 平方根，\( \lambda = 0 \) 对数，\( \lambda = -1 \) 倒数<sup>[1](https://doi.org/10.1214/20-STS778)</sup> |
| 估计 | λ 的最大似然估计使变换后响应上回归的残差平方和 \( R(\lambda) \) 达到最小<sup>[1](https://doi.org/10.1214/20-STS778)</sup> |
| 数据要求 | 严格取正值的观测；SciPy 对负值输入返回 NaN，且不提供平移参数<sup>[4](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PowerTransformer.html)</sup> |
| 推荐做法 | 在置信区域内选用一个可解释的 λ（如 0 或 −1），而非最大似然估计本身<sup>[1](https://doi.org/10.1214/20-STS778)</sup> |
| 样本量注意事项 | 当 λ 接近 1 且样本量远低于 1000 时，λ 的置信区间可能覆盖几乎整个 [0, 1]，使得可靠估计成为不可能<sup>[5](https://www.mdpi.com/2571-905X/7/1/11)</sup> |
| 起源 | G. E. P. 博克斯与 D. R. 考克斯，《变换分析》，Journal of the Royal Statistical Society Series B，1964 年<sup>[2](https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1964.tb00553.x)</sup> |

## 工作原理

该变换族定义为

\[ y^{(\lambda)} = \frac{y^{\lambda} - 1}{\lambda} \quad (\lambda \neq 0), \qquad y^{(0)} = \log y. \]

λ = 0 处的对数情形由洛必达法则在 λ → 0 时得到，这消除了简单幂 \( y^{\lambda} \) 在零点处原本会出现的不连续性。<sup>[3](https://link.springer.com/chapter/10.1007/978-3-031-88365-1_6)</sup>

在线性模型 \( y^{(\lambda)} = X\beta(\lambda) + \epsilon \) 中，目标是得到一个误差具有恒定方差且近似正态分布的响应。<sup>[1](https://doi.org/10.1214/20-STS778)</sup> 估计 λ 需要对 \( y^{(\lambda)} \) 随 λ 变化产生的尺度变化做雅可比（尺度校正因子，用于校正变换对单位的改变）校正。给定 λ 后，经雅可比归一化的响应 \( z(\lambda) \) 进入一个标准最小二乘问题，\( \hat{\beta}(\lambda) = (X^{T}X)^{-1}X^{T}z(\lambda) \)，轮廓对数似然为

\[ L_{\max}(\lambda) = -\frac{n}{2}\log\left\{ \frac{R(\lambda)}{n - p} \right\}, \]

因此 λ 的最大似然估计使残差平方和 \( R(\lambda) \) 达到最小。<sup>[1](https://doi.org/10.1214/20-STS778)</sup> λ 的合理取值通过似然比统计量 \( T_{\mathrm{LR}} = n\log\{R(\lambda_{0})/R(\hat{\lambda})\} \) 进行比较。<sup>[1](https://doi.org/10.1214/20-STS778)</sup> 逆变换可恢复原始尺度：若 \( \lambda = 0 \)，则 \( X_{\mathrm{original}} = \exp(X_{\mathrm{trans}}) \)；否则为 \( (X \cdot \lambda + 1)^{1/\lambda} \)。<sup>[4](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PowerTransformer.html)</sup>

## 具体做法

实际工作流程如下。首先确认数据为正。然后尝试若干 λ 值，用轮廓对数似然概括正态分布对每个变换后数据集的拟合优度；轮廓对数似然最大的 λ 即为最佳猜测，并在其周围构造 λ 的置信区间。<sup>[6](https://paulnorthrop.github.io/stat0002/articles/stat0002-ch2d-box-cox-transformation-vignette.html)</sup> \( 100(1-\alpha)\% \) 置信区域由满足 \( f(x,\lambda) \geq f(x,\hat{\lambda}) - 0.5\,\chi^{2}_{1-\alpha,1} \) 的那些 λ 组成，其中 \( \hat{\lambda} \) 为最大似然估计量。<sup>[7](https://www.itl.nist.gov/div898/handbook/pmc/section5/pmc52.htm)</sup>

博克斯与考克斯本人并不推荐用 \( \hat{\lambda} \) 来变换数据；他们推荐在置信区域内选取一个属于物理上可解释取值网格的值，例如对数（\( \lambda = 0 \)）或倒数（\( \lambda = -1 \)）。<sup>[1](https://doi.org/10.1214/20-STS778)</sup> 在软件中，R MASS 包的 `boxcox` 函数绘制轮廓对数似然对 λ 的图并附带 95% 置信区间，在用户自定义或默认的 λ 网格（从 −2 到 2，步长 0.1）上计算似然。<sup>[6](https://paulnorthrop.github.io/stat0002/articles/stat0002-ch2d-box-cox-transformation-vignette.html)</sup><sup> • </sup><sup>[8](https://www.css.cornell.edu/faculty/dgr2/_static/files/R_html/Transformations.html)</sup> 在变换后的尺度上拟合回归之后，模型右端不变，但系数作用于变换后的单位，因此预测值必须经逆变换才能在原始单位下解读。<sup>[8](https://www.css.cornell.edu/faculty/dgr2/_static/files/R_html/Transformations.html)</sup>

## 起源

该方法由 G. E. P. 博克斯与 D. R. 考克斯在《变换分析》一文中提出，发表于 Journal of the Royal Statistical Society, Series B (Methodological)，第 26 卷第 2 期（1964 年），第 211–252 页。<sup>[2](https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1964.tb00553.x)</sup><sup> • </sup><sup>[9](https://users.encs.concordia.ca/~raojw/crd/reference/reference003125.html)</sup> 该文通过大样本似然理论推导变换参数的最大似然估计，并在第二种方法中对参数做贝叶斯积分以得到后验分布；对固定的 λ，最大化后的似然退化为标准最小二乘问题。<sup>[2](https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1964.tb00553.x)</sup> 将 \( \lambda = 0 \) 方便地定义为对数的缩放幂变换（常以有序的“阶梯”式重表达呈现）早于 1964 年的论文；已发表文献对这一前身工作的年代说法不一（1947、1957 或 1977），因此此处不认定单一日期。<sup>[10](https://onlinestatbook.com/2/transformations/contents.pdf)</sup>

## 变体

**平移形式。** 为容纳负观测值，可将对 y 的变换替换为对 \( y + \mu \) 的变换，其中 \( \mu > -y_{\min} \)。<sup>[3](https://link.springer.com/chapter/10.1007/978-3-031-88365-1_6)</sup> 这一平移族的结果可能严重依赖于本质上任意的起点，且通常避免同时估计 \( (\lambda, \delta) \)，因为平移的对数似然轮廓往往近乎平坦。<sup>[11](https://doi.org/10.37920/sasj.2017.51.2.5)</sup>

**Yeo–Johnson 变换。** I.-K. 杨 2000 年发表于 Biometrika 的论文通过为两类响应使用不同的 Box–Cox 型表达式，将该族推广到可正可负的观测值。<sup>[12](https://doi.org/10.1093/biomet/87.4.954)</sup> 对 \( y \geq 0 \)，为 \( ((y+1)^{\lambda} - 1)/\lambda \)（\( \lambda \neq 0 \)）或 \( \log(y+1) \)（\( \lambda = 0 \)）；对 \( y < 0 \)，为 \( -\{(-y+1)^{2-\lambda} - 1\}/(2-\lambda) \)（\( \lambda \neq 2 \)）或 \( -\log(-y+1) \)（\( \lambda = 2 \)），两种符号使用同一个 λ。<sup>[3](https://link.springer.com/chapter/10.1007/978-3-031-88365-1_6)</sup>

**BCN 变换与曼利。** 霍金斯与 S. 韦斯伯格引入了 BCN（允许非正值的 Box–Cox）族，这是一个将幂变换与广义对数（glog）变换结合的两参数修正；在 λ = 0 时它退化为 glog 变换的一个重参数化形式，而 glog 本身又是 Johnson SU 变换的变体。<sup>[11](https://doi.org/10.37920/sasj.2017.51.2.5)</sup> 更早还有针对负响应的指数变换被提出。<sup>[13](https://doi.org/10.1016/j.jspi.2009.02.002)</sup>

**软件。** `scipy.stats.boxcox` 返回变换后的数据集，并在未提供 λ 时返回使对数似然最大的 λ，可选返回置信限；它要求输入为正，且不施加平移参数。<sup>[14](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.boxcox.html)</sup> `sklearn.preprocessing.PowerTransformer` 支持 `method='yeo-johnson'`（默认，可处理正值和负值）和 `method='box-cox'`（仅限严格正值），通过最大似然估计 λ，并默认对输出施加零均值、单位方差标准化。<sup>[4](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PowerTransformer.html)</sup>

**稳健变体。** 由于 λ 的最大似然估计对离群值敏感，人们设计了 Box–Cox 与 Yeo–Johnson 变换的稳健版本。<sup>[15](https://doi.org/10.1007/s10994-026-06994-3)</sup> 亚历克斯·兹瓦嫩堡与斯特芬·勒克在 2026 年 Machine Learning 的论文中提出了位置与尺度不变的 Box–Cox 和 Yeo–Johnson 变换，以缓解传统方法对位置、尺度和离群值的敏感性。<sup>[15](https://doi.org/10.1007/s10994-026-06994-3)</sup>

## 应用

在博克斯与考克斯的第一个例子中，48 个中毒动物的生存时间给出 \( \hat{\lambda} = -0.75 \)，近似 95% 置信区间为 [−1.13, −0.37]，最终选择了倒数变换（\( \lambda = -1 \)）；在 \( 3^{3} \) 羊毛数据析因实验（n = 27）中，\( \hat{\lambda} = -0.06 \)，区间为 [−0.18, 0.06]，最终选择了对数变换。<sup>[1](https://doi.org/10.1214/20-STS778)</sup> 在检验医学中，Box–Cox 变换用于计算和验证参考区间。<sup>[5](https://www.mdpi.com/2571-905X/7/1/11)</sup> 在医疗费用数据中，对数变换使结果仍非正态，而采用估计值 \( \lambda = -0.36 \) 的 Box–Cox 变换产生了近似正态分布（正态性 p = 0.621）。<sup>[16](https://www.sciencedirect.com/science/article/pii/S2213398422000859)</sup> 在机器学习中，幂变换是标准的预处理步骤；在 scikit-learn 对对数正态、卡方、韦布尔、高斯、均匀和双峰分布的对比中，Box–Cox 在对数正态和卡方输入上似乎优于 Yeo–Johnson，但不能接受负值。<sup>[17](https://scikit-learn.org/stable/auto_examples/preprocessing/plot_map_data_to_normal.html)</sup>

## 局限与替代方法

**失效模式。** 基于似然的 λ 估计可能受到离群值的强烈影响，且在某些情形下，当 λ 未知时，基于已知 λ 的通常极限理论不再成立；为此已有稳健估计程序被提出。<sup>[18](https://encyclopediaofmath.org/wiki/Box%E2%80%93Cox_transformation)</sup> 比克尔与多克萨姆 1981 年的再分析表明，同时估计 λ 和 β 可使系数估计的边际方差相对于固定 λ 下的条件方差膨胀极大倍数，从而使 Box–Cox 程序在误差方差从小到中等的结构化模型中不稳定。<sup>[19](https://doi.org/10.1080/01621459.1981.10477649)</sup> 博克斯与考克斯回应说，当 λ 确定得很差时，在依赖数据的 \( y^{\lambda} \) 尺度上陈述效应量在科学上没有意义，并指出若使用雅可比归一化的 \( z(\lambda) \)，本可避免那些严重的相关性效应。<sup>[20](https://nd.psychstat.org/_media/lab/papers/box_cox_1982.pdf)</sup> 当结果中有小比例零值或负值，或理论已提示需要变换时（如博克斯与考克斯自己的化学反应例子中物理理论提示对数线性速率定律），不推荐使用该变换。<sup>[16](https://www.sciencedirect.com/science/article/pii/S2213398422000859)</sup><sup> • </sup><sup>[8](https://www.css.cornell.edu/faculty/dgr2/_static/files/R_html/Transformations.html)</sup>

**解释与逆变换。** 对对数变换后数据做 t 检验，更接近于检验几何均值或中位数而非算术均值，因此变换可能悄然改变所检验的假设。<sup>[21](https://www.casrai.org/guides/log-and-other-data-transformations)</sup>

**替代方法。** 幂变换很少能同时满足线性性、正态性和同方差性，这促生了变换广义线性模型（TGLM），即结合 Box–Cox 模型与 GLM。<sup>[13](https://doi.org/10.1016/j.jspi.2009.02.002)</sup> 对正偏态的连续数据，伽马 GLM 是直接的替代方案；对数连接 GLM 的残差图相对于对数 Box–Cox 变换呈直线，而倒数连接则明显弯曲。<sup>[3](https://link.springer.com/chapter/10.1007/978-3-031-88365-1_6)</sup>

## References

1. [The Box-Cox transformation: review and extensions (Atkinson, Riani & Corbellini, 2021, Statistical Science 36(2):239–255)](https://doi.org/10.1214/20-STS778)
2. [An Analysis of Transformations (Box & Cox, 1964, JRSS B, publisher/DOI page)](https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1964.tb00553.x)
3. [Transformations (Springer book chapter, Atkinson, Riani & Corbellini)](https://link.springer.com/chapter/10.1007/978-3-031-88365-1_6)
4. [PowerTransformer, scikit-learn documentation](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PowerTransformer.html)
5. [Importance and Uncertainty of λ-Estimation for Box–Cox Transformations to Compute and Verify Reference Intervals in Laboratory Medicine (Stats 7(1):11, 2024)](https://www.mdpi.com/2571-905X/7/1/11)
6. [Chapter 2: Transformation Of Variable (stat0002 vignette, UCL)](https://paulnorthrop.github.io/stat0002/articles/stat0002-ch2d-box-cox-transformation-vignette.html)
7. [NIST/SEMATECH e-Handbook: What do we do when data are non-normal](https://www.itl.nist.gov/div898/handbook/pmc/section5/pmc52.htm)
8. [Box-cox transformation (Cornell course notes, D. G. Rossiter)](https://www.css.cornell.edu/faculty/dgr2/_static/files/R_html/Transformations.html)
9. [CRDReference: Box, G. E. P. and Cox, D. R. 1964, An analysis of transformations](https://users.encs.concordia.ca/~raojw/crd/reference/reference003125.html)
10. [Online Statistics Education, Tukey's Transformation Ladder](https://onlinestatbook.com/2/transformations/contents.pdf)
11. [D. M. Hawkins, S. Weisberg (2022). Combining the Box-Cox power and generalised log transformations to accommodate nonpositive responses in linear and mixed-effects linear models. South African Statistical Journal.](https://doi.org/10.37920/sasj.2017.51.2.5)
12. [I.-K. Yeo (2000). A new family of power transformations to improve normality or symmetry. Biometrika.](https://doi.org/10.1093/biomet/87.4.954)
13. [Gauss M. Cordeiro, Marinho G. de Andrade (2009). Transformed generalized linear models. Journal of Statistical Planning and Inference.](https://doi.org/10.1016/j.jspi.2009.02.002)
14. [scipy.stats.boxcox, SciPy v1.18.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.boxcox.html)
15. [Alex Zwanenburg, Steffen Löck (2026). Location and Scale-Invariant Power Transformations for Transforming Data to Normality. Machine Learning.](https://doi.org/10.1007/s10994-026-06994-3)
16. [Preferring Box-Cox transformation, instead of log transformation to convert skewed distribution of outcomes to normal in medical research](https://www.sciencedirect.com/science/article/pii/S2213398422000859)
17. [Map data to a normal distribution, scikit-learn example](https://scikit-learn.org/stable/auto_examples/preprocessing/plot_map_data_to_normal.html)
18. [Box-Cox transformation, Encyclopedia of Mathematics](https://encyclopediaofmath.org/wiki/Box%E2%80%93Cox_transformation)
19. [Peter J. Bickel, Kjell A. Doksum (1981). An Analysis of Transformations Revisited. Journal of the American Statistical Association.](https://doi.org/10.1080/01621459.1981.10477649)
20. [An Analysis of Transformations Revisited, Rebutted (Box & Cox, JASA 1982)](https://nd.psychstat.org/_media/lab/papers/box_cox_1982.pdf)
21. [Log and Other Data Transformations: When to Use Them and What They Cost](https://www.casrai.org/guides/log-and-other-data-transformations)

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

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

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/box-cox-transformation

English original: https://www.edgepedia.org/box-cox-transformation
