# 随机变量的换元法

随机变量的换元法是一条公式，它利用变换之逆的雅可比行列式（导数），直接由 X 的密度给出变换后随机变量 Y = g(X) 的概率密度。它是微积分中积分换元定理在概率论中的对应物，既适用于单个变量，也适用于同维数的随机向量。

| 关键事实 | 陈述 |
|---|---|
| 单变量公式（单调 g） | 在像支撑集上，\(f_{Y}(y) = f_{X}(g^{-1}(y)) \cdot \| d/dy \, g^{-1}(y) \|\) <sup>[1](https://randomservices.org/random/dist/Transformations.html)</sup> |
| 非单调映射 | 将定义域拆分为若干单调分支并求其贡献之和；把 y = z² 当作一一映射处理，得到的密度恰好只有正确值的一半 <sup>[2](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)</sup> |
| 多变量公式 | 对可逆可微的 \(g: \mathbb{R}^{n} \to \mathbb{R}^{n}\)，\(f_Y(y) = f_X(g^{-1}(y)) \cdot \|\det J_{g^{-1}}(y)\|\) <sup>[3](https://www.stat.umn.edu/geyer/old/5102/n.pdf)</sup> |
| 维数约束 | 该公式只适用于从 Rᵐ 到 Rᵐ 的变换；否则不存在方阵雅可比，必须引入辅助变量 <sup>[4](https://math.iisc.ac.in/~gadgil/MA261/notes/chapter-19.html)</sup> |
| 为何取绝对值 | 行列式可以为负，表示定向反转；而密度必须非负，故取绝对值 <sup>[5](https://web.williams.edu/Mathematics/sjmiller/public_html/probabilitylifesaver/supplementalchap_changeofvar.pdf)</sup> |
| 经典结果 | 标准正态变量的平方服从自由度为 1 的卡方分布 <sup>[2](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)</sup> |
| 机器学习中的用途 | 归一化流将可逆层串联起来，每一层都为对数密度贡献 log\|det J\| <sup>[6](https://www.varsitytutors.com/practice/subjects/statistics-graduate-level/lessons/transformations-and-jacobians)</sup> |

## 问题的提出：从 X 到 g(X)

仅知道 X 的密度，并不能直接得到 Y = g(X) 的密度。Y 的概率是 X 的概率经映射推送后的结果，而映射会扭曲长度和体积，因此把 g⁻¹(y) 直接代入 f_X 是错的：它是在尺寸不对的区间里计算概率质量。修正因子就是雅可比行列式，即描述 n 维体积在变换下如何变化的无穷小尺度因子 <sup>[1](https://randomservices.org/random/dist/Transformations.html)</sup>。

用最紧凑的微分形式来写，规则为 g(y)\|dy\| = f(x)\|dx\|，其中 x 通过逆函数用 y 表示 <sup>[1](https://randomservices.org/random/dist/Transformations.html)</sup>。同一个雅可比也出现在多重积分的换元定理中，而后者正是密度变换结果的数学基础 <sup>[3](https://www.stat.umn.edu/geyer/old/5102/n.pdf)</sup>；该积分定理要求映射是一一满射，且雅可比行列式 J 存在 <sup>[5](https://web.williams.edu/Mathematics/sjmiller/public_html/probabilitylifesaver/supplementalchap_changeofvar.pdf)</sup>。

## 单变量公式

设 \(X\) 连续，密度为 \(f_{X}\)，且 \(y = h(x)\)，其中 \(h\) 严格单调、连续可微，逆为 \(x = g(y)\) <sup>[2](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)</sup>。则 \(Y = h(X)\) 连续，其密度为

\(f_Y(y) = f_X(g(y)) \cdot \|g'(y)\| = f_X(x) \cdot \|1/h'(x)\|\)，在 \(x = h^{-1}(y)\) 处取值，

对支撑集的像中的 y 成立，其余处为 0 <sup>[1](https://randomservices.org/random/dist/Transformations.html)</sup><sup> • </sup><sup>[7](https://dlsun.github.io/skis/multivariate/transformations.html)</sup>。绝对值同时覆盖了 h 递增与递减两种情形 <sup>[7](https://dlsun.github.io/skis/multivariate/transformations.html)</sup>。

该公式通过对 Y 的累积分布函数求导来证明。当 h 递增时，\(P(Y \leq y) = P(X \leq g(y)) = F_X(g(y))\)；求导得 \(f_Y(y) = f_X(g(y)) \cdot g'(y)\)。多变量证明走同一条路，只是要用到多变量微积分恒等式 \(dy = \|J_f(x)\|\,dx\) <sup>[8](https://statproofbook.github.io/P/pdf-invfct.html)</sup>。公式成立要求 h 是一一映射、连续可微，且在关键处 \(g'(y) \neq 0\)；先求累积分布函数再求导的一般策略对任意 g 都适用，而这条直接配方不过是可微、严格单调情形下的捷径 <sup>[7](https://dlsun.github.io/skis/multivariate/transformations.html)</sup>。

支撑集很重要。若 X 的密度支撑集为 \([a, b]\)，且 h 严格递增，则 \(f_Y\) 的支撑集恰好是像区间 \([h(a), h(b)]\) <sup>[2](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)</sup>。

## 非单调变换：按分支求和

当 h 不是全局单调时，例如 h(x) = x² 定义在整个 R 上，就不存在单一的逆。解决办法是把定义域拆成 h 单调的若干区间，对每一段套用公式，再把各分支的贡献相加 <sup>[9](https://androma.org/theorems/1138)</sup>。

标准例子是 \(Y = X^2\)，其中 \(X\) 服从标准正态。这里有两个分支，\(x = \pm\sqrt{y}\)，各自以密度权重 \(f_X(\pm\sqrt{y}) \cdot 1/(2\sqrt{y})\) 贡献；两者相加得 \(f_Y(y) = (1/(\sqrt{2\pi}\sqrt{y}))\,e^{-y/2}\)，对 \(y \ge 0\) 成立，这正是自由度为 1 的卡方分布 <sup>[2](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)</sup>。若改为 \(X \sim \mathrm{Exp}(\lambda)\)，此时在支撑集上只有正分支起作用，则 \(Y = X^2\) 的密度为 \(f_Y(y) = (\lambda/(2\sqrt{y}))\,e^{-\lambda\sqrt{y}}\)，对 \(y > 0\) 成立 <sup>[9](https://androma.org/theorems/1138)</sup>。

分支求和不是可有可无的记账。由于映射 y = z² 是二对一的，直接套用一一映射的配方（即“工程师做法”）得到的恰好是正确答案的一半 <sup>[2](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)</sup>。

## 多变量公式与雅可比行列式

设随机向量 \(X\) 有联合密度 \(f_{X}\)，\(g\) 是可逆可微映射且雅可比行列式非零，则 \(Y = g(X)\) 的密度为

\(f_Y(y) = f_X(g^{-1}(y)) \cdot \|J_{g^{-1}}(y)\|\)，

在支撑集的像上成立，其余处为 0；其中 \(J\) 是逆映射的一阶导数（偏导数）矩阵的行列式 <sup>[3](https://www.stat.umn.edu/geyer/old/5102/n.pdf)</sup><sup> • </sup><sup>[8](https://statproofbook.github.io/P/pdf-invfct.html)</sup>。同一结果也可用正向雅可比写成 \(f_X(x) \cdot \|\det[\partial(x_{1},\ldots,x_{n})/\partial(y_{1},\ldots,y_{n})]\|\)，在 y 的原像处取值 <sup>[7](https://dlsun.github.io/skis/multivariate/transformations.html)</sup>。其根本原因在于几何：y 的小邻域在变换下面积或体积的改变倍数为 \(\|\det(DT^{-1}(y))\|\) <sup>[4](https://math.iisc.ac.in/~gadgil/MA261/notes/chapter-19.html)</sup>。

有两点实用改进。第一，由逆函数定理，x 关于 y 的雅可比行列式是正向行列式的倒数，因此两者任算其一即可，哪个方便用哪个 <sup>[7](https://dlsun.github.io/skis/multivariate/transformations.html)</sup>。第二，对仿射映射 y = a + Bx，密度简化为 g(y) = (1/\|det(B)\|) f(B⁻¹(y − a)) <sup>[1](https://randomservices.org/random/dist/Transformations.html)</sup>；例如，把仿射映射 (z, ρz + √(1−ρ²)w) 作用于两个独立标准正态变量，其雅可比行列式为 √(1 − ρ²) <sup>[7](https://dlsun.github.io/skis/multivariate/transformations.html)</sup>。

**只用方阵雅可比。** 多变量换元只有在同维空间之间进行，即从 Rⁿ 到 Rⁿ，才可能可逆 <sup>[3](https://www.stat.umn.edu/geyer/old/5102/n.pdf)</sup>。要找一个把两个随机变量降为一个的统计量（如 X₁ + X₂）的密度，公式不能直接套用。标准变通办法是引入辅助变量，例如令 Y₁ = X₁ + X₂、Y₂ = X₁/(X₁ + X₂)，对二维映射套用方阵雅可比公式，再从联合密度中将辅助变量积分消去 <sup>[4](https://math.iisc.ac.in/~gadgil/MA261/notes/chapter-19.html)</sup>。

这一辅助变量技巧给出了独立变量 X、Y（密度分别为 f、g，定义在 (0, ∞) 上）的经典乘积密度与比值密度：V = XY 的密度为 h(v) = ∫₀^∞ f(x) g(v/x) (1/x) dx，W = Y/X 的密度为 k(w) = ∫₀^∞ f(x) g(wx) x dx <sup>[1](https://randomservices.org/random/dist/Transformations.html)</sup>。

## 与累积分布函数法、变换法的比较

雅可比法要求变换（分段）可逆且可微。累积分布函数法——先算 \(F_Y(y) = P(g(X) \leq y)\) 再求导——适用范围更广：可用于不可逆的 g（如 \(Y = X^2\)、最大值或次序统计量），也可用于离散与连续混合的情形，尽管求导这一步可能难以处理。矩母函数法对独立随机变量之和最为有力 <sup>[6](https://www.varsitytutors.com/practice/subjects/statistics-graduate-level/lessons/transformations-and-jacobians)</sup>。实践中，当 g 可微且严格单调时，优先走雅可比这条路，因为它是直接配方，而不是极限计算 <sup>[7](https://dlsun.github.io/skis/multivariate/transformations.html)</sup>。

## 用数字说话：经典的导出分布

若干典型分布都是由换元法导出的：

- 标准正态变量的平方服从自由度为 1 的卡方分布，密度为 \((1/(\sqrt{2\pi}\sqrt{y}))\,e^{-y/2}\)，对 \(y \geq 0\) 成立 <sup>[2](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)</sup>。
- Exp(λ) 变量的平方，密度为 \((\lambda/(2\sqrt{y}))\, e^{-\lambda\sqrt{y}}\)，对 \(y > 0\) 成立 <sup>[9](https://androma.org/theorems/1138)</sup>。
- 仿射变换把密度按 1/\|det(B)\| 重新缩放，这正是位置-尺度族背后的机制 <sup>[1](https://randomservices.org/random/dist/Transformations.html)</sup>。
- 独立变量的乘积密度与比值密度，由辅助变量映射加一维积分得到 <sup>[1](https://randomservices.org/random/dist/Transformations.html)</sup>。

## 练习与陷阱

**常见错误**大致可归为几种反复出现的模式：

- 忘记取绝对值。行列式可以为负；负行列式表示定向反转，而不是概率质量为负，而密度非负，故绝对值必须始终取上 <sup>[5](https://web.williams.edu/Mathematics/sjmiller/public_html/probabilitylifesaver/supplementalchap_changeofvar.pdf)</sup><sup> • </sup><sup>[6](https://www.varsitytutors.com/practice/subjects/statistics-graduate-level/lessons/transformations-and-jacobians)</sup>。
- 把雅可比用反了方向。导数既可从 ∂y/∂x 求，也可从逆关系 ∂x/∂y 求，后者的值是前者的倒数；把两者搞混是常见的困惑点 <sup>[10](https://pages.stat.wisc.edu/~st309-1/jacobian.pdf)</sup>。
- 支撑集判断错误。Y 的支撑集是 X 的支撑集在 g 下的像，变换后的密度在该像之外为零；对 [a, b] 上递增的 h，像为 [h(a), h(b)] <sup>[6](https://www.varsitytutors.com/practice/subjects/statistics-graduate-level/lessons/transformations-and-jacobians)</sup><sup> • </sup><sup>[2](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)</sup>。
- 把多对一映射当作一一映射，结果要么完全丢掉分支贡献，要么使密度减半，如 y = z² 的情形 <sup>[2](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)</sup>。

**应用。** 把累积分布函数本身当作变换，会得到均匀随机变量；这一概率积分变换正是逆变换抽样的理论基础 <sup>[9](https://androma.org/theorems/1138)</sup>。在机器学习中，归一化流把 K 个可逆层串联起来，满足 \(\log f_Y = \log f_X(g^{-1}(y)) + \sum \log \lvert \det J_k \rvert\)，并且架构设计的目标是让雅可比计算从 \(O(n^3)\) 降到 \(O(n)\)；变分推断中的重参数化技巧也基于同一公式 <sup>[6](https://www.varsitytutors.com/practice/subjects/statistics-graduate-level/lessons/transformations-and-jacobians)</sup>。

## References

1. [Transformations of Variables (Random Services, Kyle Siegrist)](https://randomservices.org/random/dist/Transformations.html)
2. [Change of Variable handout (University of Maryland STAT400)](https://math.umd.edu/~millson/teaching/STAT400/handouts/changeofvariable.pdf)
3. [Stat 5101 Lecture Notes (University of Minnesota, Geyer)](https://www.stat.umn.edu/geyer/old/5102/n.pdf)
4. [Probability Models and Statistics — Change of variable (IISc MA261)](https://math.iisc.ac.in/~gadgil/MA261/notes/chapter-19.html)
5. [The Probability Lifesaver: Change of Variable Theorem](https://web.williams.edu/Mathematics/sjmiller/public_html/probabilitylifesaver/supplementalchap_changeofvar.pdf)
6. [Transformations & Jacobians (Varsity Tutors)](https://www.varsitytutors.com/practice/subjects/statistics-graduate-level/lessons/transformations-and-jacobians)
7. [Multivariate Transformations – The Art of Chance](https://dlsun.github.io/skis/multivariate/transformations.html)
8. [Probability density function of an invertible function of a continuous random vector — The Book of Statistical Proofs](https://statproofbook.github.io/P/pdf-invfct.html)
9. [Density of a Transformed Variable — Statement & Proof (Androma)](https://androma.org/theorems/1138)
10. [Jacobian notes (UW–Madison Statistics 309)](https://pages.stat.wisc.edu/~st309-1/jacobian.pdf)

---
*Initially written Sep 17, 2026 · Edited: Oct 11, 2026; Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Probability theory › Random variables › Algebra and transformations of random variables › Change of variables for random variables

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/change-of-variables-for-random-variables

English original: https://www.edgepedia.org/change-of-variables-for-random-variables
