# 第 11 章 卡方分佈 Chi-square distribution

## 11.1 卡方分佈的期望和方差的證明

$$X\sim N(0,1)$$ 時， $$X^2\sim \mathcal{X}_1^2$$

$$X_m^2+X_n^2=\mathcal{X}_{m+n}^2$$

## 11.2 卡方分佈的期望

$E(X_1^2)=Var(X)+[E(X)]^2=1+0=1$

$\Rightarrow E(X_n^2)=n$

## 11.3 卡方分佈的方差

\begin{aligned} Var(X_1^2) &= E(X_1^{2^2}) - E(X_1^2)^2 \\ &= E(X_1^4)-1 \end{aligned}

### 11.3.1 下面來求 $$E(X_1^4)$$

\begin{aligned} \because E(X_1) &= \int_{-\infty}^{+\infty} xf(x)dx \\ \therefore E(X_1^4) &= \int_{-\infty}^{+\infty} x^4f(x)dx \end{aligned}

\begin{aligned} E(X_1^4) &= \int_{-\infty}^{+\infty} x^4f(x)dx \\ &= \int_{-\infty}^{+\infty} x^4\frac{1}{\sqrt{2\pi}}e^{(-\frac{x^2}{2})}dx\\ &=\frac{1}{\sqrt{2\pi}}\int_{-\infty}^{+\infty}x^4e^{(-\frac{x^2}{2})}dx\\ &=\frac{-1}{\sqrt{2\pi}}\int_{-\infty}^{+\infty}x^3(-x)e^{(-\frac{x^2}{2})}dx \end{aligned}

$$u=x^3, v=e^{(-\frac{x^2}{2})},t=-\frac{x^2}{2}$$ 可以推導：

\begin{aligned} \frac{dv}{dx} &= \frac{dv}{dt}\frac{dt}{dx} \\ &= e^t(-\frac{1}{2}\times2x) \\ &= (-x)e^{(-\frac{x^2}{2})} \\ \Rightarrow dv &= (-x)e^{(-\frac{x^2}{2})}dx \end{aligned}

\begin{aligned} E(X_1^4) &= \frac{-1}{\sqrt{2\pi}}\int_{-\infty}^{+\infty}u\:dv \\ integrate\; &by\; parts:\\ E(X_1^4) &= \frac{-1}{\sqrt{2\pi}}\{[u\:v] \rvert_{-\infty}^{+\infty}-\int_{-\infty}^{+\infty}v\:du\} \\ &= \frac{-1}{\sqrt{2\pi}}\{[x^3e^{(-\frac{x^2}{2})}]\rvert_{-\infty}^{+\infty} -\int_{-\infty}^{+\infty}v\:du\} \\ &=\frac{-1}{\sqrt{2\pi}}\{0-0-\int_{-\infty}^{+\infty}e^{(-\frac{x^2}{2})}dx^3\} \\ &=\frac{-1}{\sqrt{2\pi}}[-3\int_{-\infty}^{+\infty}x^2e^{(-\frac{x^2}{2})}dx] \\ &=\frac{-3}{\sqrt{2\pi}}[\int_{-\infty}^{+\infty}x(-x)e^{(-\frac{x^2}{2})}dx] \\ \end{aligned}

$$a=x,b=e^{(-\frac{x^2}{2})},d\:b = (-x)e^{(-\frac{x^2}{2})}dx$$

\begin{aligned} E(X_1^4) &= \frac{-3}{\sqrt{2\pi}}\{[a\:b] \rvert_{-\infty}^{+\infty} - \int_{-\infty}^{+\infty}b\:da\} \\ &=\frac{-3}{\sqrt{2\pi}}\{[xe^{(-\frac{x^2}{2})}]\rvert_{-\infty}^{+\infty} -\int_{-\infty}^{+\infty}b\:da\} \\ &=\frac{-3}{\sqrt{2\pi}}\{0-0-\int_{-\infty}^{+\infty}e^{(-\frac{x^2}{2})}dx\} \\ &=\frac{-3}{\sqrt{2\pi}}[-\int_{-\infty}^{+\infty}e^{(-\frac{x^2}{2})}dx] \\ &=\frac{3}{\sqrt{2\pi}}\int_{-\infty}^{+\infty}e^{(-\frac{x^2}{2})}dx \end{aligned}

\begin{aligned} x&=r\:cos\theta\\ y&=r\:sin\theta\\ r^2&=x^2+y^2\\ \end{aligned}

\begin{aligned} I^2 &= \int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty}e^{(-\frac{x^2+y^2}{2})}dxdy \\ &= \int_{0}^{+\infty}\int_{0}^{2\pi}e^{(-\frac{r^2}{2})}rd\theta dr \\ \end{aligned}

\begin{aligned} I^2 &= 2\pi\int_{0}^{+\infty}e^{(-\frac{r^2}{2})}r\:dr \\ \because \frac{d(e^{\frac{-r^2}{2}})}{dr} &= -e^{(-\frac{r^2}{2})}r \\ \therefore I^2 &= 2\pi(-e^{\frac{-r^2}{2}})\rvert_0^{+\infty} \\ &= 0-(2\pi\times(-1)) \\ &= 2\pi\\ \Rightarrow I &= \sqrt{2\pi} \end{aligned}

\begin{aligned} E(X_1^4) &= \frac{3}{\sqrt{2\pi}}\int_{-\infty}^{+\infty}e^{(-\frac{x^2}{2})}dx \\ &= \frac{3}{\sqrt{2\pi}}\times I \\ &= 3 \\ \Rightarrow Var(X_1^2) &= E(X_1^4) - 1 \\ &= 3-1 =2 \end{aligned}

## 11.4 把上面的推導擴展

$\text{Suppose } \mathcal{X}^2_1, \cdots \mathcal{X}^2_k \stackrel{i.i.d}{\sim} \mathcal{X}^2_1 \\ \Rightarrow \sum_{i=1}^k \mathcal{X}^2_i \sim \mathcal{X}^2_k \\ \Rightarrow \text{E}(\sum_{i=1}^n\mathcal{X}^2_i)=\sum_{i-1}^n\text{E}(\mathcal{X}^2_i)=n\times1=n\\ \text{Var}(\sum_{i=1}^n\mathcal{X}^2_i)=\sum_{i=1}^n\text{Var}(\mathcal{X}^2_i) = n\times2=2n$

$n\rightarrow \infty, X_n^2\sim N(n, 2n)$