Pearson's chi-squared test or Pearson's χ2 test is a statistical test applied to sets of categorical data to evaluate how likely it is that any observed difference between the sets arose by chance. It is the most widely used of many chi-squared tests (e.g., Yates, likelihood ratio, portmanteau test in time series, etc.) – statistical procedures whose results are evaluated by reference to the chi-squared distribution. Its properties were first investigated by Karl Pearson in 1900. In contexts where it is important to improve a distinction between the test statistic and its distribution, names similar to Pearson χ-squared test or statistic are used. It is a p-value test. A simple example is testing the hypothesis that an ordinary six-sided die is "fair" (i. e., all six outcomes are equally likely to occur). In this case, the observed data is (O1,O2,...,O6), the number of times that the die has fallen on each number. The null hypothesis is Multinomial(N;1/6,...,1/6), and χ2:=∑i=16(Oi−N/6)2N/6. As detailed below, if χ2>11.07, then the fairness of the die can be rejected at the level of p<0.05.
Procedure The setup is as follows:
Before the experiment, the experimenter fixes a certain number N of samples to take. The observed data is (O1,O2,...,On), the count number of samples from a finite set of given categories. They satisfy ∑iOi=N. The null hypothesis is that the count numbers are sampled from a multinomial distribution Multinomial(N;p1,...,pn). That is, the underlying data is sampled IID from a categorical distribution Categorical(p1,...,pn) over the given categories. The Pearson's chi-squared test statistic is defined as χ2:=∑i(Oi−Npi)2Npi. The p-value of the test statistic is computed either numerically or by looking it up in a table. If the p-value is small enough (usually p < 0.05 by convention), then the null hypothesis is rejected, and we conclude that the observed data does not follow the multinomial distribution.
Usage Pearson's chi-squared test is used to assess three types of comparison: goodness of fit, homogeneity, and independence.
A test of goodness of fit establishes whether an observed frequency distribution differs from a theoretical distribution. A test of homogeneity compares the distribution of counts for two or more groups using the same categorical variable (e.g. choice of activity—college, military, employment, travel—of graduates of a high school reported a year after graduation, sorted by graduation year, to see if number of graduates choosing a given activity has changed from class to class, or from decade to decade). A test of independence assesses whether observations consisting of measures on two variables, expressed in a contingency table, are independent of each other (e.g. polling responses from people of different nationalities to see if one's nationality is related to the response). For all three tests, the computational procedure includes the following steps:
Calculate the chi-squared test statistic, χ2, which resembles a normalized sum of squared deviations between observed and theoretical frequencies (see below). Determine the degrees of freedom, df, of that statistic. For a test of goodness-of-fit, df = Cats − Params, where Cats is the number of observation categories recognized by the model, and Params is the number of parameters in the model adjusted to make the model best fit the observations: The number of categories reduced by the number of fitted parameters in the distribution. For a test of homogeneity, df = (Rows − 1)×(Cols − 1), where Rows corresponds to the number of categories (i.e. rows in the associated contingency table), and Cols corresponds to the number of independent groups (i.e. columns in the associated contingency table). For a test of independence, df = (Rows − 1)×(Cols − 1), where in this case, Rows corresponds to the number of categories in one variable, and Cols corresponds to the number of categories in the second variable. Select a desired level of confidence (significance level, p-value, or the corresponding alpha level) for the result of the test. Compare χ2 to the critical value from the chi-squared distribution with df degrees of freedom and the selected confidence level (one-sided, since the test is only in one direction, i.e. is the test value greater than the critical value?), which in many cases gives a good approximation of the distribution of χ2. Sustain or reject the null hypothesis that the observed frequency distribution is the same as the theoretical distribution based on whether the test statistic exceeds the critical value of χ2. If the test statistic exceeds the critical value of χ2, the null hypothesis (H0 = there is no difference between the distributions) can be rejected, and the alternative hypothesis (H1 = there is a difference between the distributions) can be accepted, both with the selected level of confidence. If the test statistic falls below the threshold χ2 value, then no clear conclusion can be reached, and the null hypothesis is sustained (we fail to reject the null hypothesis), though not necessarily accepted.
Test for fit of a distribution
Discrete uniform distribution In this case N observations are divided among n cells. A simple application is to test the hypothesis that, in the general population, values would occur in each cell with equal frequency. The "theoretical frequency" for any cell (under the null hypothesis of a discrete uniform distribution) is thus calculated as Ei=Nn, and the reduction in the degrees of freedom is p=1, notionally because the observed frequencies Oi are constrained to sum to N. One specific example of its application would be its application for log-rank test.
… excerpt ends here. Continue reading the full article.
