
Ch. 26 Resources
Chapter 26: Comparing Counts
Chapter 26 covers three types of tests: goodness-of-fit tests, tests for homogeneity and tests for independence. The mechanics for these procedures are remarkably similar (and in the case of the last two, pretty much identical) and in most cases we will rely on technology to compute P-values. The challenge will be to decide which test is appropriate for a given situation and then properly interpret the P-value.
Goodness-of-Fit
Plain M&M's candies come in six colors: orange, yellow, brown, green, blue and red. Masterfoods (the company that makes M&M's) claims that 24% of all regular M&M's are blue, 20% orange, 16% green, 14% yellow, 13% brown and 13% are red.
To test this I purchased a king-size package of M&M's and counted the number of each color of candy: of 102 candies in the package, 11 were blue, 25 orange, 26 green, 8 yellow, 17 brown and 15 red. There seems to be a discrepancy between the colors of the candies in our package and the proportions claimed by Masterfoods. Is this evidence that Masterfoods' claim is incorrect? Or did we get a sample that varies from the actual proportions due to natural sampling error?
This is a goodness-of-fit problem. We know it is of this type because we are comparing observed data (the counts of the colors in our package) to a model (the proportions found on the M&M's Web site). The hypotheses are:
H0: The colors of regular M&M candies follow the distribution found on the M&M's Web site.
HA: The colors of regular M&M candies do not follow the distribution found on the M&M's Web site.
Next we check conditions.
Counted Data Condition: We have counts of the number of candies in each of six color categories.
Randomization Condition: This is a cluster sample, but there's reason to believe the candies in this one bag are representative of all plain M&M's.
Expected Cell Frequency Condition: If the proportions on the M&M's Web site are correct, we would expect that among 102 randomly selected candies 24% of them, or 102×0.24 = 24.48, would be blue; similarly we expect to find 20.4 orange, 16.32 green, 14.28 yellow, 13.26 brown and 13.26 red. All of these counts are at least 5, so this condition is satisfied.
In this last condition, note that it's the expected counts we check, not the observed counts, and since these expected counts are theoretical counts based on a hypothesized model, they need not be integers.
The computation of χ2 is not difficult, but it is tedious. The calculator can help us expedite this procedure, but what you do depends on what type of calculator you have.
For the TI-84 (with OS 2.30 or better):
Clear two lists; we will use L1 and L2. Enter the observed counts (11, 25, 26, 8, 17, 15) into L1. Enter the expected counts into L2 (you can type 102×0.24, 102×0.20, 102×0.16, 102×0.14, 102×0.13 and 102×0.13 and the expected counts will appear); make sure there are six entries in each list.
Press QUIT, then STAT and move the cursor to TESTS then down until you find χ2GOF–Test and press ENTER.
Specify L1 for the Observed list, L2 for the Expected list, 5 for df (the number of degrees of freedom is given by k-1 where k is the number of categories), then highlight Calculate or Draw and press ENTER. The TI-84 will report the value of χ2 as well as the P-value, df (which you had to enter yourself prior to running this test) and a list of the components of χ2 (in a list called CNTRB, for contributions).
Note that in the graph of the χ2 model for df = 5, the mode is located at df-2 = 3; the expected value (mean) of this model is df = 5, which is to the right of the mode since this distribution is skewed to the right.
For the TI-83 (or a TI-84 with OS below 2.30):
Clear three lists; we will use L1, L2 and L3. Enter the observed counts (11, 25, 26, 8, 17, 15) into L1. Enter the expected counts into L2 (you can type 102×0.24, 102×0.20, 102×0.16, 102×0.14, 102×0.13 and 102×0.13 and the expected counts will appear); make sure there are six entries in each list.
Now move the cursor to L3 and up so that the list name (L3) is highlighted.
Press ENTER; the cursor should now be blinking at the bottom of the screen.
Type (L1-L2)2/L2.
Now press ENTER. The components of the χ2 statistic should appear in L3.
We need to add these components to get χ2. Press QUIT, then 2ND and then STAT to get to the LIST menu; move the cursor over to MATH, then down to sum(.
Press ENTER and then type L3) and press ENTER again. The calculator should display 18.24662429, which is the value of χ2.
Now we need to compute the P-value for the hypothesis test. Press 2ND and VARS (to get to the DISTR menu), move down to χ2cdf( and press ENTER, then type 18.24662429,1E99,5) and press ENTER.
The TI-83 should display 0.00265268, which is the P-value for this test. Note that χ2cdf is very much like tcdf, but the number of degrees of freedom is given by k−1 where k is the number of categories.
Since the P-value is quite small, we reject the null hypothesis and conclude that there is significant evidence (P = 0.003) that the color proportions found on the M&M's Web site are incorrect.
Since we rejected the null hypothesis, we should check the standardized residuals. The TI-84 does not compute these for us directly, but since we have the observed counts in L1 and the expected counts in L2, we can move the cursor to L3 and up so that the list name (L3) is highlighted and then press ENTER so that the cursor is blinking at the bottom of the screen. Now type (L1-L2)/√(L2) and finally press ENTER so that the standardized residuals appear in L3.
We can see that the largest standardized residuals (in absolute value) correspond to blue and green: the negative residual for blue indicates that there were far fewer blue M&M's in our sample than we expected and the positive residual for green indicates that there were far more green M&M's in our sample that we expected.
Homogeneity
Now suppose we want to investigate whether the color distribution of peanut M&M's is the same as the color distribution of plain M&M's. Our hypotheses are:
H0: The colors of plain M&M candies and the colors of peanut M&M candies have the same distribution.
HA: The colors of plain M&M candies and the colors of peanut M&M candies do not have the same distribution.
To test this I purchased a king-size package of plain M&M's (as mentioned above) and counted the number of each color of candy: of 102 candies in the package, 11 were blue, 25 orange, 26 green, 8 yellow, 17 brown and 15 red. I also purchased a king-size bag of peanut M&M's and counted the number of each color: of 41 candies, 7 were orange, 3 yellow, 2 brown, 8 green, 16 blue and 5 red.
Notice that we are now comparing two samples to each other, so we use a test for homogeneity. If we wanted we could display this sample data in a two-way table:
plain | peanut | |
blue | 11 | 16 |
orange | 25 | 7 |
green | 26 | 8 |
yellow | 8 | 3 |
brown | 17 | 2 |
red | 15 | 5 |
Next we check conditions.
Counted Data Condition: We have counts of the number of candies in each of six categories for two different samples.
Randomization Condition: These are cluster samples, but there's reason to believe the candies in these two bags are representative of all plain and peanut M&M's, respectively.
Expected Cell Frequency Condition: We could compute the expected counts by hand. (For example, our of 102+41 = 143 candies, 11+16 = 27 are blue, so if the distribution of colors is the same for both types, we would expect 27/143 ≈ 18.9%, meaning that we would expect 102×0.189 ≈ 19.26 blue plain M&M's and 41×0.189 ≈ 7.74 blue peanut M&M's.) But the calculator will (eventually) compute the expected counts for all of the cells, so let's put this condition "on hold" and return to it later.
We now need to enter these counts into the calculator. The data is displayed in a two-way table, so we will enter it into the calculator as a matrix. If you have a standard TI-83, press the MATRX button; if you have a TI-83 Plus or TI-84, press 2ND and x-1 to access the MATRIX menu. Move the cursor over to EDIT.
Now press ENTER. Type 6 and ENTER (since there are 6 rows in our two-way table) then 2 and ENTER (since there are 2 columns). Now enter the data by typing each count (11, 16, 25, 7, etc.) and pressing ENTER after each new number.
Now press QUIT, then STAT, move the cursor over to TESTS, move down to χ2–Test.
Press ENTER. The default setting for the Observed matrix should be [A] and for the Expected matrix it should be [B]; leave these alone and move the cursor down to Calculate or Draw.
Press ENTER. The calculator should display the value of χ2 and the P-value along with a graph of the χ2 model or the number of degrees of freedom: (6-1)(2-1) = 5.
Before we continue with the hypothesis test, however, we need to check the expected counts; the calculator has stored these counts in matrix [B]. Go back to the MATRIX menu, move the cursor over to EDIT, then move the cursor down to [B].
Press ENTER and you will see the expected counts.
Notice that the expected count for yellow peanut M&M's is less than 5, so the Expected Cell Frequency Condition is not satisfied. We should not proceed with the test for homogeneity. (If we were to proceed, we would need to make sure that we check the standardized residuals carefully; the TI-84 does not do this automatically.)
Independence
The calculator method for the test for independence follows exactly the same steps as the test for homogeneity. The difference is that instead of having two (or more) samples compared via a single variable, a test for independence involves one sample and two variables.
Remember the Coke vs. Pepsi data discussed at length in the Chapter 3 Resources? Here's the data to refresh your memory:
female | male | |
Coke | 7 | 9 |
Pepsi | 10 | 4 |
neither | 8 | 3 |
We have one sample (a group of Statistics students) and two variables (beverage preference and gender) so a test for independence is appropriate here. The Counted Data condition is certainly satisfied since we have counts of students, and while these students are not randomly selected they should at least be representative of all Statistics students at EdCC. We'll wait to check the Expected Cell Frequency condition until we perform the mechanics of the test.
Enter the Coke vs. Pepsi data into your calculator (following the steps listed above for the homogeneity test) and compute the P-value (and be sure to check that all the expected counts are at least 5). Look back at the Chapter 3 Resources: do you reach the same conclusion with the test for independence that we did earlier just looking at side-by-side pie charts?
Homework
Work the following exercises in Chapter 26: 1, 3, 9, 23, 27–35 odd, 39 and 41
Errata
The For Example on page 706 should read "With 2 df" (not 3).
ActivStats
Work through the lessons on pages 26-1 through 26-3 in the ActivStats lesson book, as time permits; you can skip the activity about using the χ2-table on page 26-3.
Additional Resources
- Performing A Chi-Square Test
- A flash tutorial on using the χ2-Test feature of the TI-83 to perform a χ2-test for independence.
- Chi-Square Probabilities
- An applet for visualizing the chi-square distribution for various degrees of freedom.