Achi-squared test (alsochi-square orχ2 test) is astatistical hypothesis test used in the analysis ofcontingency tables when the sample sizes are large. In simpler terms, this test is primarily used to examine whether two categorical variables (two dimensions of the contingency table) are independent in influencing the test statistic (values within the table).[1] The test isvalid when the test statistic ischi-squared distributed under thenull hypothesis, specificallyPearson's chi-squared test and variants thereof. Pearson's chi-squared test is used to determine whether there is astatistically significant difference between the expectedfrequencies and the observed frequencies in one or more categories of acontingency table. For contingency tables with smaller sample sizes, aFisher's exact test is used instead.
In the standard applications of this test, the observations are classified into mutually exclusive classes. If thenull hypothesis that there are no differences between the classes in the population is true, the test statistic computed from the observations follows aχ2frequency distribution. The purpose of the test is to evaluate how likely the observed frequencies would be assuming the null hypothesis is true.
Test statistics that follow aχ2 distribution occur when the observations are independent. There are alsoχ2 tests for testing the null hypothesis of independence of a pair ofrandom variables based on observations of the pairs.
Chi-squared tests often refers to tests for which the distribution of the test statistic approaches theχ2 distributionasymptotically, meaning that thesampling distribution (if the null hypothesis is true) of the test statistic approximates a chi-squared distribution more and more closely assample sizes increase.
In the 19th century, statistical analytical methods were mainly applied in biological data analysis and it was customary for researchers to assume that observations followed anormal distribution, such asSir George Airy andMansfield Merriman, whose works were criticized byKarl Pearson in his 1900 paper.[2]
At the end of the 19th century, Pearson noticed the existence of significantskewness within some biological observations. In order to model the observations regardless of being normal or skewed, Pearson, in a series of articles published from 1893 to 1916,[3][4][5][6] devised thePearson distribution, a family of continuousprobability distributions, which includes the normal distribution and many skewed distributions, and proposed a method of statistical analysis consisting of using the Pearson distribution to model the observation and performing a test of goodness of fit to determine how well the model really fits to the observations.
In 1900, Pearson published a paper[2] on theχ2 test which is considered to be one of the foundations of modern statistics.[7] In this paper, Pearson investigated a test of goodness of fit.
Suppose thatn observations in a random sample from a population are classified intok mutually exclusive classes with respective observed numbers of observationsxi (fori = 1,2,…,k), and a null hypothesis gives the probabilitypi that an observation falls into theith class. So we have the expected numbersmi =npi for alli, where
Pearson proposed that, under the circumstance of the null hypothesis being correct, asn → ∞ the limiting distribution of the quantity given below is theχ2 distribution.
Pearson dealt first with the case in which the expected numbersmi are large enough known numbers in all cells assuming every observationxi may be taken asnormally distributed, and reached the result that, in the limit asn becomes large,X2 follows theχ2 distribution withk − 1 degrees of freedom.
However, Pearson next considered the case in which the expected numbers depended on the parameters that had to be estimated from the sample, and suggested that, with the notation ofmi being the true expected numbers andm′i being the estimated expected numbers, the difference
will usually be positive and small enough to be omitted. In a conclusion, Pearson argued that if we regardedX′2 as also distributed asχ2 distribution withk − 1 degrees of freedom, the error in this approximation would not affect practical decisions. This conclusion caused some controversy in practical applications and was not settled for 20 years until Fisher's 1922 and 1924 papers.[8][9]
Onetest statistic that follows achi-squared distribution exactly is the test that the variance of a normally distributed population has a given value based on asample variance. Such tests are uncommon in practice because the true variance of the population is usually unknown. However, there are several statistical tests where thechi-squared distribution is approximately valid:
For anexact test used in place of the 2 × 2 chi-squared test for independence when all the row and column totals were fixed by design, seeFisher's exact test. When the row or column margins (or both) are random variables (as in most common research designs) this tends to be overly conservative andunderpowered.[10]
For an exact test used in place of the 2 × 1 chi-squared test for goodness of fit, seebinomial test.
Using thechi-squared distribution to interpretPearson's chi-squared statistic requires one to assume that thediscrete probability of observedbinomial frequencies in the table can be approximated by the continuouschi-squared distribution. This assumption is not quite correct and introduces some error.
To reduce the error in approximation,Frank Yates suggested a correction for continuity that adjusts the formula forPearson's chi-squared test by subtracting 0.5 from the absolute difference between each observed value and its expected value in a2 × 2 contingency table.[11] This reduces the chi-squared value obtained and thus increases itsp-value.
If a sample of sizen is taken from a population having anormal distribution, then there is a result (seedistribution of the sample variance) which allows a test to be made of whether the variance of the population has a pre-determined value. For example, a manufacturing process might have been in stable condition for a long period, allowing a value for the variance to be determined essentially without error. Suppose that a variant of the process is being tested, giving rise to a small sample ofn product items whose variation is to be tested. The test statisticT in this instance could be set to be the sum of squares about the sample mean, divided by the nominal value for the variance (i.e. the value to be tested as holding). ThenT has a chi-squared distribution withn − 1degrees of freedom. For example, if the sample size is 21, the acceptance region forT with a significance level of 5% is between 9.59 and 34.17.
Suppose there is a city of 1,000,000 residents with four neighborhoods:A,B,C, andD. A random sample of 650 residents of the city is taken and their occupation is recorded as"white collar", "blue collar", or "no collar". The null hypothesis is that each person's neighborhood of residence is independent of the person's occupational classification. The data are tabulated as:
A | B | C | D | Total | |
---|---|---|---|---|---|
White collar | 90 | 60 | 104 | 95 | 349 |
Blue collar | 30 | 50 | 51 | 20 | 151 |
No collar | 30 | 40 | 45 | 35 | 150 |
Total | 150 | 150 | 200 | 150 | 650 |
Let us take the sample living in neighborhoodA, 150, to estimate what proportion of the whole 1,000,000 live in neighborhoodA. Similarly we take349/650 to estimate what proportion of the 1,000,000 are white-collar workers. By the assumption of independence under the hypothesis we should "expect" the number of white-collar workers in neighborhoodA to be
Then in that "cell" of the table, we have
The sum of these quantities over all of the cells is the test statistic; in this case,. Under the null hypothesis, this sum has approximately a chi-squared distribution whose number of degrees of freedom is
If the test statistic is improbably large according to that chi-squared distribution, then one rejects the null hypothesis of independence.
A related issue is a test of homogeneity. Suppose that instead of giving every resident of each of the four neighborhoods an equal chance of inclusion in the sample, we decide in advance how many residents of each neighborhood to include. Then each resident has the same chance of being chosen as do all residents of the same neighborhood, but residents of different neighborhoods would have different probabilities of being chosen if the four sample sizes are not proportional to the populations of the four neighborhoods. In such a case, we would be testing "homogeneity" rather than "independence". The question is whether the proportions of blue-collar, white-collar, and no-collar workers in the four neighborhoods are the same. However, the test is done in the same way.
Incryptanalysis, the chi-squared test is used to compare the distribution ofplaintext and (possibly) decryptedciphertext. The lowest value of the test means that the decryption was successful with high probability.[12][13] This method can be generalized for solving modern cryptographic problems.[14]
Inbioinformatics, the chi-squared test is used to compare the distribution of certain properties of genes (e.g., genomic content, mutation rate, interaction network clustering, etc.) belonging to different categories (e.g., disease genes, essential genes, genes on a certain chromosome etc.).[15][16]