🐈

Chi-squared distribution

2024/01/03に公開

Suppose

\begin{align*} Z_1, \cdots, Z_n \sim \mathcal{N}(0, 1) \end{align*}

let

\begin{align*} X = Z_1^2 + \cdots + Z_n^2 \end{align*}

then, X follows a chi-squared distribution \chi_n^2(x) with n degrees of freedom.

\begin{align*} \chi_n^2(x) &= \frac{1}{2^{\frac{n}{2}} \Gamma(\frac{n}{2})} x^{\frac{n}{2}-1} e^{-\frac{x}{2}} \\ \end{align*}

where x > 0, when x \le 0, \chi_n^2(x) = 0.


Let's use mathematical induction to derive a chi-squared distribution with n dgrees of freedom.

When n=1, X = Z_1^2, z_1 = \sqrt{x}, dz_1 = \frac{1}{2} x^{-\frac{1}{2}} dx, z_1: 0 \rightarrow \infty.

\begin{align*} 1 = \int_0^{\infty} f_X(x) dx &= \int_{-\infty}^{\infty} f_{Z_1}(z_1) d_1z \\ &= 2 \int_{0}^{\infty} f_{Z_1}(z_1) dz_1 \\ &= 2 \int_{0}^{\infty} f_{Z_1}(\sqrt{x}) \frac{1}{2} x^{-\frac{1}{2}} dx \\ &= 2 \int_{0}^{\infty} \frac{1}{\sqrt{2 \pi}} \exp \left( -\frac{1}{2} (\sqrt{x})^2 \right)\frac{1}{2} x^{-\frac{1}{2}} dx \\ &= \int_{0}^{\infty} \frac{1}{\sqrt{2 \pi}} x^{-\frac{1}{2}} \exp \left( -\frac{1}{2} x \right) dx \\ &= \int_{0}^{\infty} \frac{1}{2^{\frac{1}{2}} \Gamma(\frac{1}{2})} x^{\frac{1}{2}-1} e^{-\frac{x}{2}} dx \\ &= \int_{0}^{\infty} \chi_1^2(x) dx \\ \end{align*}

therefore

\begin{align*} f_X(x) = \chi_1^2(x) \end{align*}

When n=2, let
X = Z_1^2 + Z_2^2 = Y_1 + Y_2
, y_2 = x - y_1
, y_2: 0 \rightarrow x,
, dy_2 = dx

\begin{align*} 1 = \int_0^{\infty} f_X(x) dx &= \int_{-\infty}^{\infty}\int_{-\infty}^{\infty} f_{Z_1 Z_2}(z_1, z_2) dz_1 dz_2 \\ &= \int_{-\infty}^{\infty}\int_{-\infty}^{\infty} f_{Z_1}(z_1) f_{Z_2}(z_2) dz_1 dz_2 \\ &= \int_{0}^{\infty}\int_{0}^{\infty} \chi_1^2(y_1) \chi_1^2(y_2) dy_1 dy_2 \\ &= \int_{0}^{\infty}\int_{0}^{x} \chi_1^2(y_1) \chi_1^2(x - y_1) dy_1 dx \\ &= \int_{0}^{\infty}\int_{0}^{x} \frac{1}{2^{\frac{1}{2}} \Gamma(\frac{1}{2})} y_1^{\frac{1}{2}-1} e^{-\frac{y_1}{2}} \frac{1}{2^{\frac{1}{2}} \Gamma(\frac{1}{2})} (x - y_1)^{\frac{1}{2}-1} e^{-\frac{x - y_1}{2}} dy_1 dx \\ &= \int_{0}^{\infty} \frac{1}{2 \pi} e^{-\frac{x}{2}} \int_{0}^{x} y_1^{-\frac{1}{2}} (x - y_1)^{- \frac{1}{2}} dy_1 dx \\ \end{align*}

Here let y_1 = ux
, u: 0 \rightarrow 1
, dy_1 = x du

\begin{align*} &= \int_{0}^{\infty} \frac{1}{2 \pi} e^{-\frac{x}{2}} \int_{0}^{1} (ux)^{-\frac{1}{2}} (x - ux)^{- \frac{1}{2}} x du dx \\ &= \int_{0}^{\infty} \frac{1}{2 \pi} e^{-\frac{x}{2}} \int_{0}^{1} u^{-\frac{1}{2}} (1 - u)^{- \frac{1}{2}} du dx \\ &= \int_{0}^{\infty} \frac{1}{2 \pi} e^{-\frac{x}{2}} \Beta(\frac{1}{2}, \frac{1}{2}) dx \\ &= \int_{0}^{\infty} \frac{1}{2} e^{-\frac{x}{2}} dx \\ &= \int_{0}^{\infty} \chi_2^2(x) dx \\ \end{align*}

therefore

\begin{align*} f_X(x) = \chi_2^2(x) \end{align*}

Suppose a hypothesis,

\begin{align*} f_X(x) = \chi_k^2(x) \end{align*}

when n=k.


When n=k+1, let
X = Z_1^2 + \cdots + Z_{k+1}^2 = Y_1 + \cdots + Y_{k+1}
, y = y_1 + \cdots + y_k
, y_{k+1} = x - y
, y_{k+1}: 0 \rightarrow x,
, dy_{k+1} = dx

\begin{align*} 1 = \int_0^{\infty} f_X(x) dx &= \int_{0}^{\infty}\int_{0}^{x} \chi_k^2(y) \chi_1^2(x - y) dydx \\ &= \int_{0}^{\infty}\int_{0}^{x} \frac{1}{2^{\frac{k}{2}} \Gamma(\frac{k}{2})} y^{\frac{k}{2}-1} e^{-\frac{y}{2}} \frac{1}{2^{\frac{1}{2}} \Gamma(\frac{1}{2})} (x-y)^{-\frac{1}{2}} e^{-\frac{x-y}{2}} dydx \\ &= \int_{0}^{\infty}\int_{0}^{x} \frac{1}{2^{\frac{k}{2}} \Gamma(\frac{k}{2})} y^{\frac{k}{2}-1} \frac{1}{2^{\frac{1}{2}} \Gamma(\frac{1}{2})} (x-y)^{-\frac{1}{2}} e^{-\frac{x}{2}} dydx \\ &= \int_{0}^{\infty} \frac{1}{2^{\frac{k+1}{2}} \Gamma(\frac{k}{2})\Gamma(\frac{1}{2})} e^{-\frac{x}{2}} \int_{0}^{x} y^{\frac{k}{2}-1} (x-y)^{-\frac{1}{2}} dydx \\ \end{align*}

Here let y = ux
, u: 0 \rightarrow 1
, dy = x du

\begin{align*} &= \int_{0}^{\infty} \frac{1}{2^{\frac{k+1}{2}} \Gamma(\frac{k}{2})\Gamma(\frac{1}{2})} e^{-\frac{x}{2}} \int_{0}^{x} (ux)^{\frac{k}{2}-1} (x-ux)^{-\frac{1}{2}} x du dx \\ &= \int_{0}^{\infty} \frac{1}{2^{\frac{k+1}{2}} \Gamma(\frac{k}{2})\Gamma(\frac{1}{2})} e^{-\frac{x}{2}} x^{\frac{k+1}{2}} \int_{0}^{1} u^{\frac{k}{2}-1} (1-u)^{\frac{1}{2} - 1} du dx \\ &= \int_{0}^{\infty} \frac{1}{2^{\frac{k+1}{2}} \Gamma(\frac{k}{2})\Gamma(\frac{1}{2})} e^{-\frac{x}{2}} x^{\frac{k+1}{2}} \Beta(\frac{k}{2}, \frac{1}{2}) dx \\ &= \int_{0}^{\infty} \frac{1}{2^{\frac{k+1}{2}} \Gamma(\frac{k}{2})\Gamma(\frac{1}{2})} e^{-\frac{x}{2}} x^{\frac{k+1}{2}} \frac{\Gamma(\frac{k}{2}) \Gamma(\frac{1}{2})}{\Gamma(\frac{k+1}{2})} dx \\ &= \int_{0}^{\infty} \frac{1}{2^{\frac{k+1}{2}} \Gamma(\frac{k+1}{2})} e^{-\frac{x}{2}} x^{\frac{k+1}{2}} dx \\ &= \int_{0}^{\infty} \chi_{k+1}^2(x) dx \\ \end{align*}

Therefore, the hypothesis also holds when n = k + 1.


Next, let's think about mean and variance of the chi-squared distribution.

The moment generating function of the chi-squared distribution is,

\begin{align*} M(\theta) &= E[e^{\theta X}] \\ &= \int e^{\theta x} \chi_n^2(x) dx \\ &= \int e^{\theta x} \frac{1}{2^{\frac{n}{2}} \Gamma(\frac{n}{2})} x^{\frac{n}{2}-1} e^{-\frac{x}{2}} dx \\ &= \frac{1}{2^{\frac{n}{2}} \Gamma(\frac{n}{2})} \int x^{\frac{n}{2}-1} e^{- (\frac{1}{2} - \theta) x } dx \\ \end{align*}

let (\frac{1}{2} - \theta)x = t, x = (\frac{1}{2} - \theta)^{-1} t , dx = (\frac{1}{2} - \theta)^{-1} dt, t: 0 \rightarrow \infty.

\begin{align*} &= \frac{1}{2^{\frac{n}{2}} \Gamma(\frac{n}{2})} \int_0^\infty ((\frac{1}{2} - \theta)^{-1} t)^{\frac{n}{2}-1} e^{- t } (\frac{1}{2} - \theta)^{-1} dt\\ &= \frac{1}{2^{\frac{n}{2}} \Gamma(\frac{n}{2})} \frac{1}{(\frac{1}{2} - \theta)^{\frac{n}{2}}} \int_0^\infty t^{\frac{n}{2}-1} e^{- t } dt\\ &= \frac{1}{2^{\frac{n}{2}} \Gamma(\frac{n}{2})} \frac{1}{(\frac{1}{2} - \theta)^{\frac{n}{2}}} \Gamma(\frac{n}{2})\\ &= \frac{1}{2^{\frac{n}{2}} (\frac{1}{2} - \theta)^{\frac{n}{2}}} \\ &= (1 - 2\theta)^{- \frac{n}{2}} \\ \end{align*}
\begin{align*} M'(\theta) &= - \frac{n}{2}(1 - 2\theta)^{- \frac{n}{2} - 1} (-2) \\ &= n (1 - 2\theta)^{- \frac{n}{2} - 1} \\ M''(\theta) &= n (- \frac{n}{2} - 1) (1 - 2\theta)^{- \frac{n}{2} - 2} (-2)\\ &= (n^2 + 2n)(1 - 2\theta)^{- \frac{n}{2} - 2} \end{align*}

The mean and variance are

\begin{align*} E[X] &= M'(0) = n \\ V[X] &= M''(0) - M'(0)^2 \\ &= (n^2 + 2n) - n^2 \\ &= 2n \\ \end{align*}

Discussion