# 什么是矩生成函数（MGF）？

## MGF 的定义

$$\psi_{X}(t)=\mathbb{E}\left(e^{t X}\right)=\int e^{t x} \mathrm{d} F(x) = \int e^{tx} f(x) \mathrm{d}x$$

$$X(s) = \int_{0}^{+\infty } e^{-st} x(t) \mathrm{d}t$$

$$\psi^{\prime}(0)=\left[\dfrac{d}{d t} \mathbb{E} e^{t X}\right]_{t=0}=\mathbb{E}\left[\dfrac{d}{d t} e^{t X}\right]_{t=0}=\mathbb{E}\left[X e^{t X}\right]_{t=0}=\mathbb{E}(X)$$

$$\psi_{X}(t)=\mathbb{E} e^{t X}=\int_{0}^{\infty} e^{t x} e^{-x} \mathrm{d} x =\int_{0}^{\infty} e^{(t-1) x} \mathrm{d} x =\dfrac{1}{1-t}$$

（1）若 $Y = aX + b$ 则 $\psi_{Y}(t)=e^{b t} \psi_{X}(a t)$

（2）若 $X_1, \cdots , X_n$ 独立且 $Y = \sum_{i}^{X_i}$ 则 $\psi_{Y}(t)=\prod_{i} \psi\_{i}(t)$

## 离散分布的 MGF

$$M_X(t) = \mathbb{E}[e^{tX}] = \sum_i e^{tx_i}\cdot p(x_i)\notag$$

## 常见分布的 MGF

$$\begin{array}{ll} \text { Distribution } & \text { MGF } \psi(t) \\ \operatorname{Bernoulli}(p) & p e^{t}+(1-p) \\ \operatorname{Binomial}(n, p) & \left(p e^{t}+(1-p)\right)^ {n} \\ \operatorname{Poisson}(\lambda) & e^{\lambda\left(e^{t} -1\right)} \\ \operatorname{Normal}(\mu, \sigma) & \exp \left\{\mu t+\dfrac {\sigma^{2} t^{2}}{2}\right\} \\ \operatorname{Gamma}(\alpha, \beta) & \left(\dfrac{1} {1-\beta t}\right)^{\alpha} \text { for } t<1 / \beta\end {array}$$

## MGF 为什么能用？

$$$$e^{t x}=\dfrac{(t x)^{0}}{0 !}+\dfrac{(t x)^{\prime}}{1 !}+\dfrac{(t x)^{2}}{2 !}+\cdots$$$$

$$$$\mathbb{E}\left(e^{t x}\right)=\dfrac{t^{0}}{0 !} \mathbb{E}\left(x^{0}\right)+\dfrac{t^{1}}{1 !} \mathbb{E}\left(x^{1}\right)+\dfrac{t^{2}}{2 !} \mathbb{E}\left(x^{2}\right)+\cdots$$$$

$$$$\dfrac{\mathrm{d}}{\mathrm{d}t} \mathbb{E}\left(e^{t x}\right)=0+E(x)+\dfrac{2 t}{2 !} \mathbb{E}\left(x^{2}\right)+\cdots$$$$

$$$$\dfrac{\mathrm{d}^{2}}{\mathrm{d}t^{2}} \mathbb{E}\left(e^{t x}\right)=0+0+E\left(x^{2}\right)+\cdots$$$$

$$\frac{d}{dt}\left(\frac{e^{tb}-e^{ta}}{t\left(b-a\right)}\right)=\frac{be^{bt}t-ae^{at}t-e^{bt}+e^{at}}{t^2\left(b-a\right)}$$

## 各种 MGF 的推导

### 均匀分布

\begin{align} & \mathbb{E} \left(e^{t x}\right) \\ &=\int_{a}^{b} e^{t x} \cdot \dfrac{1}{b-a} \mathrm{d} x \\ &=\dfrac{1}{b-a} \cdot \dfrac{1}{t} \int_{a}^{b} e^{t x} \mathrm{d}(t x) \\ &=\left.\dfrac{1}{b-a} \cdot \dfrac{1}{t} e^{t x}\right|_{a} ^{b} \\ &=\dfrac{e^{b t}-e^{a t}}{t(b-a)} \end{align}

### 泊松分布

\begin{aligned} \mathbb{E}\left(e^{-t x}\right) &=\sum_{k=0}^{n} e^{t k} \cdot \dfrac{\lambda^{k} e^{-\lambda}}{k !} \\ &=\sum e^{t k-\lambda} \cdot \dfrac{\lambda^{k}}{k !} \\ &=e^{-\lambda} \sum e^{t k} \cdot \dfrac{\lambda^{k}}{k !} \\ &=e^{-\lambda} \sum \dfrac{\left(e^{t} \lambda\right)^{k}}{k !} \\ &=e^{-\lambda} \cdot e^{e^{t \lambda} \lambda} \\ &=e^{\left(e^{t}-1\right) \lambda} \end{aligned}

\begin{aligned} M_{X}^{\prime}(t) &=\left[e^{\left(e^{t-1}\right) \lambda}\right]^{\prime} \\ &=\left[\left(e^{t-1}\right) \lambda\right]^{\prime} \cdot e^{\left(e^{t}-1\right) \lambda} \\ &=\lambda e^{t} \cdot e^{\left(e^{t-1}\right) \lambda} \\ \mathbb{E}(x) &=\lambda . \end{aligned}

\begin{aligned} M {x}^{\prime\prime}(t) &=\left[\lambda e^{t} \cdot e^{\left(e^{t}-1\right) \lambda}\right]^{\prime} \\ &=\lambda e^{t} \cdot\left[e^{\left(e^{t}-1\right) \lambda}+\lambda e^{t} \cdot e^{\left(e^{t}-1\right) \lambda}\right] \\ &=\lambda e^{t}\left(\lambda e^{t}+1\right) e^{\left(e^{t}-1\right) \lambda} \\ \mathbb{E}\left(x^{2}\right) &=\lambda^{2}+\lambda \end{aligned}

### 伽马分布

\begin{aligned} \mathbb{E}\left(e^{x t}\right) &=\int_{-\infty}^{\infty} e^{x t} \cdot f(x) \mathrm{d} x \\ &=\int_{-\infty}^{\infty} e^{x t} \cdot \dfrac{\lambda^{\alpha} x^{\alpha-1} e^{-\lambda x}}{\Gamma(\alpha)} \mathrm{d} x \\ &=\dfrac{\lambda^{\alpha}}{\Gamma(\alpha)} \int_{0}^{\infty} e^{-(\lambda-t) x} \cdot x^{\alpha-1} \mathrm{d} x \\ &{\color{#22a097}{\operatorname{let} u=( \lambda-t) x \text{ then } \mathrm{d}u=(\lambda-t) \mathrm{d} x}} \\ \mathbb{E}\left(e^{t x}\right) &=\dfrac{\lambda^{\alpha}}{r(\alpha)} \int_{0}^{\infty} e^{-u} \cdot\left(\dfrac{1}{\lambda-t}\right)^{\alpha} \cdot\left(\dfrac{1}{\lambda-t}\right)^{-1} \dfrac{\mathrm{d}u}{\lambda-t} \\ &=\dfrac{\lambda^{\alpha}}{\Gamma(\alpha)} \cdot\left(\dfrac{1}{\lambda-t}\right)^{\alpha} \int_{0}^{\infty} e^{-u} \cdot u^{\alpha-1} \mathrm{d}u \\ &=\dfrac{\lambda^{\alpha}}{\Gamma(\alpha)} \cdot\left(\dfrac{1}{\lambda-t}\right)^{\alpha} \quad \Gamma(\alpha) \\ &=\dfrac{\lambda^{\alpha}}{\Gamma(\alpha)} \cdot \dfrac{\Gamma(\alpha)}{(\lambda-t)^{\alpha}} \\ &=\left(\dfrac{\lambda}{\lambda-t}\right)^{\alpha} \\ &=\left(\dfrac{1}{1-\beta t}\right)^{\alpha} \end{aligned}

\begin{aligned} M_{x}^{\prime}(t) &=\left(\dfrac{1}{1-\beta t}\right)^{\prime} \cdot \alpha\left(\dfrac{1}{1-\beta t}\right)^{\alpha-1} \\ &=\beta \cdot \dfrac{\alpha}{(1-\beta t)^{\alpha+1}} \end{aligned}

$$\mathbb{E}(X) = \alpha \beta$$

\begin{aligned} M_{x}^{\prime \prime}(t) &=\alpha \beta\left[\left(\dfrac{1}{1-\beta t}\right)^{\alpha+1}\right]^\prime \\ &=\alpha \beta\left[(\alpha+1)\left(\dfrac{1}{1-\beta t}\right)^{\alpha} \cdot\left(\beta \cdot \dfrac{1}{(1-\beta t)^{2}}\right)\right] \\ &=\alpha \beta\left[(\alpha+1) \beta \cdot \dfrac{1}{(1-\beta t)^{\alpha+2}}\right] \\ &=\alpha(\alpha+1) \beta^{2} \cdot(1-\beta t)^{-(\alpha+2)} \end{aligned}

$$\mathbb{E}(X^2) = \alpha (\alpha +1)\beta ^{2}$$ $$\mathbb{V}(X) = \alpha \beta ^{2}$$

### 指数分布

$$\dfrac{\lambda }{\lambda - t}$$

### 正态分布

\begin{aligned} N(x) &=\left(\frac{1}{2 \pi}\right)^{\frac{1}{2}} \exp \left\{-\frac{x^{2}}{2}\right\} \\ \mathbb{E}\left(e^{x t}\right) &=\int_{-\infty}^{\infty} e^{x t}\left(\frac{1}{2 \pi}\right)^{\frac{1}{2}} \exp \left\{-\frac{x^{2}}{2}\right\} \mathrm{d}x \\ &=\left(\frac{1}{2 \pi}\right)^{\frac{1}{2}} \int_{-\infty}^{\infty} \exp \left\{-\frac{1}{2} x^{2}+x t\right\} \mathrm{d}x \\ &=\left(\frac{1}{2 \pi}\right)^{\frac{1}{2}} \int_{-\infty}^{\infty} \exp \left\{-\frac{1}{2}\left(x^{2}-2 x t+t^{2}\right)+\frac{1}{2} t^{2}\right\} \mathrm{d}x \\ &=\left(\frac{1}{2 \pi}\right)^{\frac{1}{2}} \int_{-\infty}^{\infty} \exp \left\{-\frac{1}{2}(x-t)^{2}\right\} \exp \left\{\frac{1}{2} t^{2}\right\} \mathrm{d}x \\ &=\left(\frac{1}{2 \pi}\right)^{\frac{1}{2}} e^{\frac{t^{2}}{2}} \int_{-\infty}^{\infty} e^{-\frac{1}{2}(x-t)^{2}} \mathrm{d}x \\ &=e^{\frac{t^{2}}{2}} \int_{-\infty}^{\infty} \frac{1}{\sqrt{2 \pi}} e^{-\frac{(x-t)^{2}}{2}} \mathrm{d}x \\ &=e^{\frac{t^{2}}{2}} \cdot 1 \\ &=e^{\frac{t^{2}}{2}} \end{aligned}

## 参考

All of statistics

https://www.bilibili.com/video/BV1sJ411i75s/