This post is a continuation of the previous post (Part 3a) on chi-squared test and is also part of a series of posts on chi-squared distribution. The first post (Part 1) is an introduction on the chi-squared distribution. The second post (Part 2) is on the chi-squared distribution as mathematical tools for inference involving quantitative variables. Part 3, which focuses on inference on categorical variables using the Pearson’s chi-squared statistic, is broken up in three posts. Part 3a is an introduction on the chi-squared test statistic and explains how to perform the chi-squared goodness-of-fit test. Part 3b (this post) focuses on using the chi-squared statistic to compare several populations (test of homogeneity). Part 3c (the next post) focuses on the test of independence.
Comparing Two Distributions
The interpretation of the chi-squared test discussed in this post is called chi-squared test of homogeneity. In this post, we show that the chi-squared statistic is employed to test whether the cell probabilities for certain categories are identical across several populations. We start by examining the two-population case, which will be fairly easily extended to the case of more than two populations.
Suppose that a multinomial experiment can result in distinct outcomes. Suppose that the experiment is performed two times with the two samples drawn from two different populations. Let be the probability that the outcome in the first experiment falls into the th category (or cell ) and let be the probability that the outcome in the second experiment falls into the th category (or cell ) where . Furthermore, suppose that there are and independent multinomial trials in the first experiment and the second experiment, respectively.
We are interested in the random variables and the random variables where is the number of trials in the first experiment whose outcomes fall into cell and is the number of trials in the second experiment whose outcomes fall into cell . Then the sampling distribution of each of the following
has an approximate chi-squared distribution with degrees of freedom (discussed here). Because the two experiments are independent, the following sum
has an approximate chi-squared distribution with degrees of freedom. When and , , are unknown, we wish to test the following hypothesis.
In other words, we wish to test the hypothesis that the cell probabilities associated with the two independent experiments are equal. Since the cell probabilities are generally unknown, we can use sample data to estimate and . How do we do that? If the null hypothesis is true, then the two independent experiments can be viewed as one combined experiment. Then the the following ratio
is the sample frequency of the event corresponding to cell , . Furthermore, we only have to estimate and using for since the estimator of and is . With all these in mind, the following is the test statistic we will need.
Since parameters are estimated, the degrees of freedom of this test statistic is obtained by subtracting from . Thus the degrees of freedom is . We test the null hypothesis against all alternatives using the upper tailed chi-squared test. We use two examples to demonstrate how this procedure is done.
A Million Random Digits with 100,000 Normal Deviates is a book with random numbers published by the RAND Corporation in 1955. It contains 1,000,000 random digits and was an important work in statistics and was used extensively in random number generation in the 20th century. A typical way to pick random numbers from the book is to randomly select a page and then randomly select a point on that page (row and column). Then read off the random digits from that point (going down and then continue with the next columns) until obtaining the desired number of digits. We selected 1,000 random digits in this manner from the book and compare them with the random digits generated in Excel using the Rand() function. The following table shows the frequency distributions of the digits from the two sources. In the following table, MRD = Million Random Digits. Test whether the distributions of digits are the same between MRD and Excel.
The frequencies of the digits are for the most part similar between MRD and Excel except for digits 1 and 4. The null hypothesis is that the frequencies or probabilities for the digits are the same between the two populations. The following is a precise statement of the null hypothesis.
where and is the probability that a random MRD digit is and is the probability that a random digit from Excel is . Under , an estimate of is the ratio . For digits 0 and 1, they are (90+93)/2000 = 0.0915, (112+96)/2000 = 0.104, respectively. The following two tables show the calculation for the chi-squared procedure.
Chi-Squared Statistic (MRD)
Chi-Squared Statistic (Excel)
The value of the chi-squared statistic is 7.841199966, the sum of the two individual ones. The degrees of freedom of the chi-squared statistic is 10 -1 = 9. At level of significance , the critical value (the upper area of the chi-squared density curve) is 16.9. Thus we do not reject the null hypothesis that the distributions of digits in these two sources of random numbers are the same. Given the value of the chi-squared statistic (7.84), the p-value is 0.55. Since the p-value is large, there is no reason to believe that the digit distributions are different between the two sources.
Two groups of drivers (500 drivers in each group) are observed for a 3-year period. The frequencies of accidents of the two groups are shown below. Test whether the accident frequencies are the same between the two groups of drivers.
To ensure that the expected count in the last cell is not too small, we collapse two cells (4 and 5 accidents) into one. The following two tables show the calculation for the chi-squared procedure.
Chi-Squared Statistic (Group 1)
Chi-Squared Statistic (Group 2)
The total value of the chi-squared statistic is 15.1258 with df = 4. At level of significance , the critical value is 13.2767. Since the chi-squared statistic is larger than 13.2767, we reject the null hypothesis that the loss frequencies are the same between the two groups of drivers. We also reach the same conclusion by looking at the p-value. The p-value of the chi-squared statistic of 15.128 is 0.004447242, which is quite small. So we have reason to believe that the value of the chi-squared statistic 15.1258 is too large to be explained by random fluctuation. Thus we have reason to believe that the two groups have different accident rates.
Comparing Two or More Distributions
The procedure demonstrated in the previous section can be easily extended to handle more than two distributions. Suppose that the focus of interest is a certain multinomial experiment that results in distinct outcomes. Suppose that the experiment is performed times with the samples drawn from different populations. The iterations of the experiment are independent. Note the following quantities.
is the probability that the outcome in the th experiment falls into the th cell where and .
is the number of times the th experiment is performed.
is the number of trials in the th experiment whose outcomes fall into cell where and .
With these in mind, consider the following chi-squared statistics
where . Each of the above statistic has an approximate chi-squared distribution with degrees of freedom. Since the experiments are independent, the sum of all these chi-squared statistics
has an approximate chi-squared distribution with df = . The null hypothesis is that the cell probabilities are the same across all populations. The following is the formal statement.
where . The unknown cell probabilities are to be estimated using sample data as follows:
where . The reasoning behind is that if is true, then the iterations of the experiment is just one large combined experiment. Then is simply the number of observations that fall into cell when is assumed to be true. Thus is an estimate of the cell probabilities for .
The next step is to replace the cell probabilities by the estimates to obtain the following chi-squared statistic.
Since we only have to estimate the cell probabilities for up to , the degrees of freedom of the above statistic is . In other words, the degrees of freedom is the number of experiments less one times the number of cells less one.
Once all the components are in place, we obtain the critical value of the chi-squared distribution of the df indicated above with an appropriate level of significance to decide on the rejection or acceptance of the null hypothesis. The p-value approach can also be used.
- Moore D. S., McCabe G. P., Craig B. A., Introduction to the Practice of Statistics, 7th ed., W. H. Freeman and Company, New York, 2012
- Wackerly D. D., Mendenhall III W., Scheaffer R. L.,Mathematical Statistics with Applications, Thomson Learning, Inc, California, 2008