Chi Square Distribution
The chi square (χ2) distribution with n degrees of freedom models the distribution of the sum of the squares of n independent normal variables. It is best known for its use in the Testing Goodness-Of-Fit, and for the one sample Testing Variances of a sample. The chi square distribution is a special case of the gamma distribution.
The chi square distribution has one parameter: the degrees of freedom. This value is usually an integer, but this is not an absolute requirement. The probability density function (PDF) is:
$$f(x) = \frac{x^{n/2-1}e^{-x/2}}{\Gamma(\frac{1}{2}n)2^{n/2}}$$where n is the degrees of freedom.
The chi square distribution is a special case of the gamma distribution, with scale parameter 2 and shape parameter n/2.
The chi square distribution is implemented by the ChiSquareDistribution class. It has one constructor which takes the degrees of freedom as its only argument. The following constructs a chi square distribution with 10 degrees of freedom:
var chiSquare = new ChiSquareDistribution(10);
The ChiSquareDistribution class has one specific property, DegreesOfFreedom, that returns the degrees of freedom of the distribution.
ChiSquareDistribution has one static (Shared in Visual Basic) method, Sample, which generates a random sample using a user-supplied uniform random number generator.
var random = new MersenneTwister();
double sample = ChiSquareDistribution.Sample(random, 10);
The above example uses the MersenneTwister to generate uniform random numbers.
For details of the properties and methods common to all continuous distribution classes, see the topic on continuous distributions..