# Chi-squared goodness of fit test¶

This method deals with the modelling of a probability distribution of a random vector . It seeks to verify the compatibility between a sample of data and a candidate probability distribution previous chosen. The use of the Goodness-of-Fit test allows to answer this question in the one dimensional case , and with a discrete distribution.

Let us limit the case to . Thus we denote . We also note that as we are considering discrete distributions i.e. those for which the possible values of belong to a discrete set , the candidate distribution is characterized by the probabilities .

The chi squared test is based on the fact that if the candidate distribution is appropriate, the number of values in the sample x1, x2, …, xN that are equal to should be on average equal to . The idea is therefore to compare the “theoretical values” with the actual observed values. This comparison is performed with the aid of the following “distance”.

where denotes the elements of which have been observed at least once in the data sample and where denotes the number of data values in the sample that are equal to .

The probability distribution of the distance is asymptotically known (i.e. as the size of the sample tends to infinity), and this asymptotic distribution does not depend on the candidate distribution being tested. If is sufficiently large, this means that for a probability , one can calculate the threshold / critical value) such that:
• if , we reject the candidate distribution with a risk of error ,

• if , the candidate distribution is considered acceptable.

An important notion is the so-called “-value” of the test. This quantity is equal to the limit error probability under which the candidate distribution is rejected. Thus, the candidate distribution will be accepted if and only if is greater than the value desired by the user. Note that the higher , the more robust the decision.

Examples: