Chisquare
distribution
This program calculates
the tailend and percentile values
for points on a Chisquare
(X^{2})
distribution
curve.

You must provide
the value of X^{2}
and the degrees of freedom. No special instruction or
Matlab toolbox is used. Since the summation in
the calculation of Z cannot
actually extend to infinity, we
stop summation when the next term is less than a chosen level of
precision. Our precision is limited to approx. 1×10^{7}.

The Matlab program to accomplish this, is:
%
Clears
screen and variables in workspace
clc;
clear
%
Asks the
user for the relevant input
v
= input('Degrees
of
freedom: ');
w = input('Chisquare:
');
%
Calculates the denominator product
r
= 1;
for
i = v : 2 : 2
r
= r*i;
end
%
Calculates the numerator product
k
=
w^(floor((v+1)/2))*exp(w/2)/r;
%
If
degrees of freedom are odd, then uses the pi factor
if
floor(v/2) ==
v/2
j
= 1;
else
j =
sqrt(2/(w*pi));
end
l
= 1;
m = 1;
v = v + 2;
m = m*w/v;
%
Summation factor
while
m >= 1e7
l
= l + m;
v
= v + 2;
m
= m*w/v;
end
%
Displays
results
str
= ['Tail
end
value: '
num2str(1j*k*l)];
disp(str)
str = ['Percentile:
'
num2str(j*k*l)];
disp(str)
Example
 Calculate tailend and percentile
A X^{2} statistic for
a given study was computed to be 2.571108 with one degree of freedom.
What are the tailend and percentile values?
Running the Matlab program above, we enter and get:
Degrees of freedom: 1
Chisquare:
2.571108
Tailend
value: 0.10883
Percentile:
0.89117
From
'Chisquare' to home
From
'Chisquare' to 'Probability and Stats'
