# Chi-square distribution

This program calculates the tail-end and percentile values for points on a Chi-square (X2) distribution curve.

 You must provide the value of X2 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(
'Chi-square: ');

% 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 >= 1e-7
l = l + m;
v = v + 2;
m = m*w/v;

end

% Displays results
str = ['Tail end value: ' num2str(1-j*k*l)];
disp(str)
str = [
'Percentile: ' num2str(j*k*l)];
disp(str)

### Example - Calculate tail-end and percentile

A X2 statistic for a given study was computed to be 2.571108 with one degree of freedom. What are the tail-end and percentile values?

Running the Matlab program above, we enter and get:

Degrees of freedom: 1
Chi-square: 2.571108
Tail-end value: 0.10883
Percentile: 0.89117

From 'Chi-square' to home

From 'Chi-square' to 'Probability and Stats'

 Top Chi-Square Calculator Online Normal distribution Binomial distribution Poisson distribution F-distribution t-distribution Random numbers

## Related pages

algorithm to find gcd of two numbersgraphing piece wise functionscalculate simple interest loanmatlab invertnormal distribution bell curvescilab scicosnonlinear fit matlabmatlab binomial coefficientsolving systems of equations with matlabpoint and slope calculatorascii table enterbinomial distribution solved examplesplot in 3d matlabprincipal and interest calculator spreadsheethow to convert binary numbers to octalbinomial calculator onlineintegrals in matlabgraphical user interface matlabletters in asciiconvert to octallinear interpolation matlabmatlab basic commandshow to convert from cartesian to polarconversion of binary to gray codehow to graph in matlablinear fitting matlabsimpson method integrationtheorem calculatorwhat is salvage value in accountingsample matlab programsmatlab programming for beginnersconverting to octalanimated matrix movieplotting imaginary numbersinterest amortization tablescombinations calcbinary octal converterformula for sum of harmonic seriesascii character code tabledischarging rc circuitmaclaurin series solversimple interest to compound interest converterbell curve graph generatorsimple matlab gui examplesjordan matricestrapezoidal rule programsalvage value accountingharmonic sequence formula and examplessolve simultaneous equations matrixtrigonometric functions matlabdefinite integration calculatorpoly fitmatlab lookup tablelagrange polynomial in matlabeuclidean algorithm for gcfscilab matricesstepwise matlabmatlab reverse matrixconvert binary to hexamatlab draw rectangletrapezoidal rule examplesmatlab area under curveprime factorization examplehow to draw a piecewise functionmatlab solve system of nonlinear equationspythagorean calculatorformula for simple interest loanbinary ascii chartonline trapezoidal rule calculatorline in slope intercept form calculatoroctal numberingcolor codes in matlabsawtooth fourierkcl equationmatlab invsolving matrix in matlablegend matlabsolving matrix in matlabdepreciation rate calculatormatlab upper triangular matrix