Derivation of the pdf for one degree of freedom
edit
Let random variable Y be defined as Y = X 2 where X has normal distribution with mean 0 and variance 1 (that is X ~ N (0,1)).
Then,
for
y
<
0
,
F
Y
(
y
)
=
P
(
Y
<
y
)
=
0
and
for
y
≥
0
,
F
Y
(
y
)
=
P
(
Y
<
y
)
=
P
(
X
2
<
y
)
=
P
(
|
X
|
<
y
)
=
P
(
−
y
<
X
<
y
)
=
F
X
(
y
)
−
F
X
(
−
y
)
=
F
X
(
y
)
−
(
1
−
F
X
(
y
)
)
=
2
F
X
(
y
)
−
1
{\displaystyle {\begin{alignedat}{2}{\text{for}}~y<0,&~~F_{Y}(y)=P(Y<y)=0~~{\text{and}}\\{\text{for}}~y\geq 0,&~~F_{Y}(y)=P(Y<y)=P(X^{2}<y)=P(|X|<{\sqrt {y}})=P(-{\sqrt {y}}<X<{\sqrt {y}})\\~~&=F_{X}({\sqrt {y}})-F_{X}(-{\sqrt {y}})=F_{X}({\sqrt {y}})-(1-F_{X}({\sqrt {y}}))=2F_{X}({\sqrt {y}})-1\end{alignedat}}}
f
Y
(
y
)
=
d
d
y
F
Y
(
y
)
=
2
d
d
y
F
X
(
y
)
−
0
=
2
d
d
y
(
∫
−
∞
y
1
2
π
e
−
t
2
2
d
t
)
=
2
1
2
π
e
−
y
2
(
y
)
y
′
=
2
1
2
π
e
−
y
2
(
1
2
y
−
1
2
)
=
1
2
1
2
Γ
(
1
2
)
y
−
1
2
e
−
y
2
{\displaystyle {\begin{aligned}f_{Y}(y)&={\tfrac {d}{dy}}F_{Y}(y)=2{\tfrac {d}{dy}}F_{X}({\sqrt {y}})-0=2{\frac {d}{dy}}\left(\int _{-\infty }^{\sqrt {y}}{\frac {1}{\sqrt {2\pi }}}e^{\frac {-t^{2}}{2}}dt\right)\\&=2{\frac {1}{\sqrt {2\pi }}}e^{-{\frac {y}{2}}}({\sqrt {y}})'_{y}=2{\frac {1}{{\sqrt {2}}{\sqrt {\pi }}}}e^{-{\frac {y}{2}}}\left({\frac {1}{2}}y^{-{\frac {1}{2}}}\right)\\&={\frac {1}{2^{\frac {1}{2}}\Gamma ({\frac {1}{2}})}}y^{-{\frac {1}{2}}}e^{-{\frac {y}{2}}}\end{aligned}}}
Where
F
{\displaystyle F}
and
f
{\displaystyle f}
are the cdf and pdf of the corresponding random variables.
Then
Y
=
X
2
∼
χ
1
2
.
{\displaystyle Y=X^{2}\sim \chi _{1}^{2}.}
The change of variable formula (implicitly derived above), for a monotonic transformation
y
=
g
(
x
)
{\displaystyle y=g(x)}
, is:
f
Y
(
y
)
=
∑
i
f
X
(
g
i
−
1
(
y
)
)
|
d
g
i
−
1
(
y
)
d
y
|
.
{\displaystyle f_{Y}(y)=\sum _{i}f_{X}(g_{i}^{-1}(y))\left|{\frac {dg_{i}^{-1}(y)}{dy}}\right|.}
In this case the change is not monotonic, because every value of
Y
{\displaystyle \scriptstyle Y}
has two corresponding values of
X
{\displaystyle \scriptstyle X}
(one positive and negative). However, because of symmetry, both halves will transform identically, i.e.
f
Y
(
y
)
=
2
f
X
(
g
−
1
(
y
)
)
|
d
g
−
1
(
y
)
d
y
|
.
{\displaystyle f_{Y}(y)=2f_{X}(g^{-1}(y))\left|{\frac {dg^{-1}(y)}{dy}}\right|.}
In this case, the transformation is:
x
=
g
−
1
(
y
)
=
y
{\displaystyle x=g^{-1}(y)={\sqrt {y}}}
, and its derivative is
d
g
−
1
(
y
)
d
y
=
1
2
y
.
{\displaystyle {\frac {dg^{-1}(y)}{dy}}={\frac {1}{2{\sqrt {y}}}}.}
So here:
f
Y
(
y
)
=
2
1
2
π
e
−
y
/
2
1
2
y
=
1
2
π
y
e
−
y
/
2
.
{\displaystyle f_{Y}(y)=2{\frac {1}{\sqrt {2\pi }}}e^{-y/2}{\frac {1}{2{\sqrt {y}}}}={\frac {1}{\sqrt {2\pi y}}}e^{-y/2}.}
And one gets the chi-squared distribution, noting the property of the gamma function :
Γ
(
1
/
2
)
=
π
{\displaystyle \Gamma (1/2)={\sqrt {\pi }}}
.
Derivation of the pdf for two degrees of freedom
edit
There are several methods to derive chi-squared distribution with 2 degrees of freedom. Here is one based on the distribution with 1 degree of freedom.
Suppose that
X
{\displaystyle X}
and
Y
{\displaystyle Y}
are two independent variables satisfying
X
∼
χ
1
2
{\displaystyle X\sim \chi _{1}^{2}}
and
Y
∼
χ
1
2
{\displaystyle Y\sim \chi _{1}^{2}}
, so that the probability density functions of
X
{\displaystyle X}
and
Y
{\displaystyle Y}
are respectively:
f
X
(
x
)
=
1
2
1
2
Γ
(
1
2
)
x
−
1
2
e
−
x
2
{\displaystyle f_{X}(x)={\frac {1}{2^{\frac {1}{2}}\Gamma ({\frac {1}{2}})}}x^{-{\frac {1}{2}}}e^{-{\frac {x}{2}}}}
and of course
f
Y
(
y
)
=
f
X
(
y
)
{\displaystyle f_{Y}(y)=f_{X}(y)}
. Then, we can derive the joint distribution of
(
X
,
Y
)
{\displaystyle (X,Y)}
:
f
(
x
,
y
)
=
f
X
(
x
)
f
Y
(
y
)
=
1
2
π
(
x
y
)
−
1
2
e
−
x
+
y
2
{\displaystyle f(x,y)=f_{X}(x)\,f_{Y}(y)={\frac {1}{2\pi }}(xy)^{-{\frac {1}{2}}}e^{-{\frac {x+y}{2}}}}
where
Γ
(
1
2
)
2
=
π
{\displaystyle \Gamma ({\tfrac {1}{2}})^{2}=\pi }
. Further[clarification needed ] , let
A
=
x
y
{\displaystyle A=xy}
and
B
=
x
+
y
{\displaystyle B=x+y}
, we can get that:
x
=
B
+
B
2
−
4
A
2
{\displaystyle x={\frac {B+{\sqrt {B^{2}-4A}}}{2}}}
and
y
=
B
−
B
2
−
4
A
2
{\displaystyle y={\frac {B-{\sqrt {B^{2}-4A}}}{2}}}
or, inversely
x
=
B
−
B
2
−
4
A
2
{\displaystyle x={\frac {B-{\sqrt {B^{2}-4A}}}{2}}}
and
y
=
B
+
B
2
−
4
A
2
{\displaystyle y={\frac {B+{\sqrt {B^{2}-4A}}}{2}}}
Since the two variable change policies are symmetric, we take the upper one and multiply the result by 2. The Jacobian determinant can be calculated as[clarification needed ] :
Jacobian
(
x
,
y
A
,
B
)
=
|
−
(
B
2
−
4
A
)
−
1
2
1
+
B
(
B
2
−
4
A
)
−
1
2
2
(
B
2
−
4
A
)
−
1
2
1
−
B
(
B
2
−
4
A
)
−
1
2
2
|
=
−
(
B
2
−
4
A
)
−
1
2
{\displaystyle \operatorname {Jacobian} \left({\frac {x,y}{A,B}}\right)={\begin{vmatrix}-(B^{2}-4A)^{-{\frac {1}{2}}}&{\frac {1+B(B^{2}-4A)^{-{\frac {1}{2}}}}{2}}\\(B^{2}-4A)^{-{\frac {1}{2}}}&{\frac {1-B(B^{2}-4A)^{-{\frac {1}{2}}}}{2}}\\\end{vmatrix}}=-(B^{2}-4A)^{-{\frac {1}{2}}}}
Now we can change
f
(
x
,
y
)
{\displaystyle f(x,y)}
to
f
(
A
,
B
)
{\displaystyle f(A,B)}
[clarification needed ] :
f
(
A
,
B
)
=
2
×
1
2
π
A
−
1
2
e
−
B
2
(
B
2
−
4
A
)
−
1
2
{\displaystyle f(A,B)=2\times {\frac {1}{2\pi }}A^{-{\frac {1}{2}}}e^{-{\frac {B}{2}}}(B^{2}-4A)^{-{\frac {1}{2}}}}
where the leading constant 2 is to take both the two variable change policies into account. Finally, we integrate out
A
{\displaystyle A}
[clarification needed ] to get the distribution of
B
{\displaystyle B}
, i.e.
x
+
y
{\displaystyle x+y}
:
f
(
B
)
=
2
×
e
−
B
2
2
π
∫
0
B
2
4
A
−
1
2
(
B
2
−
4
A
)
−
1
2
d
A
{\displaystyle f(B)=2\times {\frac {e^{-{\frac {B}{2}}}}{2\pi }}\int _{0}^{\frac {B^{2}}{4}}A^{-{\frac {1}{2}}}(B^{2}-4A)^{-{\frac {1}{2}}}dA}
Substituting
A
=
B
2
4
sin
2
(
t
)
{\displaystyle A={\frac {B^{2}}{4}}\sin ^{2}(t)}
gives:
f
(
B
)
=
2
×
e
−
B
2
2
π
∫
0
π
2
d
t
{\displaystyle f(B)=2\times {\frac {e^{-{\frac {B}{2}}}}{2\pi }}\int _{0}^{\frac {\pi }{2}}\,dt}
So, the result is:
f
(
B
)
=
e
−
B
2
2
{\displaystyle f(B)={\frac {e^{-{\frac {B}{2}}}}{2}}}
Derivation of the pdf for k degrees of freedom
edit
Consider the k samples
x
i
{\displaystyle x_{i}}
to represent a single point in a k -dimensional space. The chi square distribution for k degrees of freedom will then be given by:
P
(
Q
)
d
Q
=
∫
V
∏
i
=
1
k
(
N
(
x
i
)
d
x
i
)
=
∫
V
e
−
(
x
1
2
+
x
2
2
+
⋯
+
x
k
2
)
/
2
(
2
π
)
k
/
2
d
x
1
d
x
2
⋯
d
x
k
{\displaystyle P(Q)\,dQ=\int _{\mathcal {V}}\prod _{i=1}^{k}(N(x_{i})\,dx_{i})=\int _{\mathcal {V}}{\frac {e^{-(x_{1}^{2}+x_{2}^{2}+\cdots +x_{k}^{2})/2}}{(2\pi )^{k/2}}}\,dx_{1}\,dx_{2}\cdots dx_{k}}
where
N
(
x
)
{\displaystyle N(x)}
is the standard normal distribution and
V
{\displaystyle {\mathcal {V}}}
is that elemental shell volume at Q (x ), which is proportional to the (k − 1)-dimensional surface in k -space for which
Q
=
∑
i
=
1
k
x
i
2
{\displaystyle Q=\sum _{i=1}^{k}x_{i}^{2}}
It can be seen that this surface is the surface of a k -dimensional ball or, alternatively, an n-sphere where n = k - 1 with radius
R
=
Q
{\displaystyle R={\sqrt {Q}}}
, and that the term in the exponent is simply expressed in terms of Q . Since it is a constant, it may be removed from inside the integral.
P
(
Q
)
d
Q
=
e
−
Q
/
2
(
2
π
)
k
/
2
∫
V
d
x
1
d
x
2
⋯
d
x
k
{\displaystyle P(Q)\,dQ={\frac {e^{-Q/2}}{(2\pi )^{k/2}}}\int _{\mathcal {V}}dx_{1}\,dx_{2}\cdots dx_{k}}
The integral is now simply the surface area A of the (k − 1)-sphere times the infinitesimal thickness of the sphere which is
d
R
=
d
Q
2
Q
1
/
2
.
{\displaystyle dR={\frac {dQ}{2Q^{1/2}}}.}
The area of a (k − 1)-sphere is:
A
=
2
R
k
−
1
π
k
/
2
Γ
(
k
/
2
)
{\displaystyle A={\frac {2R^{k-1}\pi ^{k/2}}{\Gamma (k/2)}}}
Substituting, realizing that
Γ
(
z
+
1
)
=
z
Γ
(
z
)
{\displaystyle \Gamma (z+1)=z\Gamma (z)}
, and cancelling terms yields:
P
(
Q
)
d
Q
=
e
−
Q
/
2
(
2
π
)
k
/
2
A
d
R
=
1
2
k
/
2
Γ
(
k
/
2
)
Q
k
/
2
−
1
e
−
Q
/
2
d
Q
{\displaystyle P(Q)\,dQ={\frac {e^{-Q/2}}{(2\pi )^{k/2}}}A\,dR={\frac {1}{2^{k/2}\Gamma (k/2)}}Q^{k/2-1}e^{-Q/2}\,dQ}