第 11 章 卡方分佈 Chi-square distribution

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

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

如果 \(X_1, \dots, X_n\stackrel{i.i.d}{\sim} N(0,1)\), 那麼 \(\sum_{i=1}^nX_i^2\sim\mathcal{X}_n^2\)

其中: \(\mathcal{X}_n^2\) 表示自由度爲 \(n\) 的卡方分佈。

\(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}\]

已知: \(f(x)=\frac{1}{\sqrt{2\pi}}e^{(-\frac{x^2}{2})}\) 代入上式:

\[ \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} \]

下面令 \(I=\int_{-\infty}^{+\infty}e^{(-\frac{x^2}{2})}dx\\ \Rightarrow I^2=\int_{-\infty}^{+\infty}\int_{-\infty}^{+\infty}e^{(-\frac{x^2+y^2}{2})}dxdy\)

接下來需要用到 座標轉換的知識,將 \(x,y\) 表示的笛卡爾座標,轉換爲用角度 \(\theta\) 和半徑 \(r\) 表示的形式。之後的證明可以在油管上看到,但是我還是繼續證明下去。

直角座標系 (cartesian coordinators) 和 極座標系 (polar coordinators) 之間轉換的關係如下:

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

座標轉換以後可以繼續求 \(E(X_1^4)\)。 在那之前我們先求 \(I^2\)。 注意轉換座標系統以後,\(\theta\in[0,2\pi], r\in[0,+\infty]\)

\[ \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} \]

由於先從中間的 \(\int_{0}^{2\pi}e^{(-\frac{r^2}{2})}rd\theta\) 開始積分,\(\theta\) 以外都可以視爲常數,那麼這個 \([0,2\pi]\) 上的積分就的等於 \(2\pi e^{(-\frac{r^2}{2})}r\)

因此上面的式子又變爲:

\[ \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 \]

結論:\(X_1, \dots, X_n\stackrel{i.i.d}{\sim} N(0,1)\) 時,\(\sum_{i=1}^nX_i^2\sim\mathcal{X}_n^2\) 服從卡方分佈,其期望 \(E(X_n^2)=n\),方差 \(Var(X_n^2)=2n\)。 根據中心極限定理(Section 8)

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