Section 9.3 Chi-Square Distribution
The following distribution is related to both the Normal Distribution and to the Gamma Distribution 8.4.3. Initially, consider a gamma distribution with probability function given by the formula
y=xr−1⋅e−x/μΓ(r)⋅μr.
Replacing μ=2 and r with r/2 gives the special case
y=xr/2−1⋅e−x/2Γ(r/2)⋅2r/2
which is given a special name below.
Definition 9.3.1. Chi-Square Probability Function.
Given an natural number r, suppose X is a random variable over the space R=(0,∞) with probability function given by
f(x)=xr/2−1e−x/2Γ(r/2)2r/2.
Then X has a Chi-Square distribution with r degrees of freedom. This is often denoted χ2(r).
xxxxxxxxxx
# Chi-Square Grapher
def _(r=slider(1,20,1,3,label='r =')):
f = x^(r/2-1)*e^(-x/2)/(gamma(r/2)*2^(r/2))
plot(f,x,0,40).show(title="Chi-Square Graph",figsize=[5,3])
Theorem 9.3.2. χ2 statistics.
μ=r
σ2=2r
γ1=2√2/r
γ2=12r+3
Proof.
\begin{equation*}
\mu = \frac{r}{2}2 = r
\end{equation*}
\begin{equation*}
\sigma^2 = \frac{r}{2}2^2 = 2r
\end{equation*}
\begin{equation*}
\gamma_1 = \frac{2}{\sqrt{\frac{r}{2}}} = \frac{2^{3/2}}{\sqrt{r}}
\end{equation*}
\begin{equation*}
\gamma_2 = \frac{6}{\frac{r}{2}} + 3 = \frac{12}{r} + 3
\end{equation*}
X1,X2,X3,...,Xn.
You can then create a new random variable that might be a combination of those variables. One such random variable that is often chosen is by taking the sum of these theoretical values such as
Y=n∑k=1Xk=X1+X2+X3+...+Xn
or the average of these variables to create the variable ¯X where
¯X=∑nk=1Xkn=X1+X2+X3+...+Xnn.
Below, notice that the new variable created comes by taking the sum of the squares of standard normal variables. This is indeed yet another possible function on random variables that establishes a relationship between normal and χ2.
Theorem 9.3.3. Relationship between Normal and χ2.
If Z1,Z2,...,Zr are r standard normal variables, then
X=r∑k=1Z2k
is χ2(r).xxxxxxxxxx
# Chi-Square Calculator
pretty_print("Calculator for Chi Square Probabilities")
layout=dict(top=[['a', 'b']],bottom=[['r']])) (
def _(a=input_box(0,width=10,label='a = '),
b=input_box(2,width=10,label='b = '),
r=input_box(2,width=8,label='r =')):
f = x^(r/2-1)*e^(-x/2)/(gamma(r/2)*2^(r/2))
P = numerical_integral(f,a,b)[0]
# T = RealDistribution('chisquared', r) # use built-in
# P = T.cum_distribution_function(b)-T.cum_distribution_function(a)
​
pretty_print(html("$$ P("+str(a)+" < X < "
+str(b)+") \\approx "+str(P)+"$$"))
Checkpoint 9.3.4.
xxxxxxxxxx
# Inverse Chi-Square Calculator
pretty_print("Calculator for Inverse Chi-Square")
var("x")
layout=dict(top=[['p0', 'r0']])) (
def _(p0=input_box(1/2,width=10,label='probability= '),
r0=input_box(5,width=8,label='$$r= $$')):
T = RealDistribution('chisquared', r0) # use built-in
x0 = T.cum_distribution_function_inv(p0) # rel tol 1e-14
pretty_print(html("$$ P(X < x_0) = "+str(p0)+" \\; \\; " +
"\\Rightarrow \\; \\; x_0 ="+str(x0)+"$$"))
f = x^(r0/2-1)*e^(-x/2)/(gamma(r0/2)*2^(r0/2))
G = (plot(f,(x,0,x0),fill=True, fillcolor='green') +
plot(f,(x,0,4*r0),thickness=3, color='black'))
G.show(figsize=[5,3])