Testing for Independence—Pets and Sports |
Tutorials > Testing for Independence—Pets and Sports A survey of 325 middle school students from a city school district asks, among other things, for students’ gender, whether they prefer cats or dogs, and whether they prefer basketball or football. With these data, we can investigate whether, in this city, girls prefer cats over dogs, whether gender matters in terms of favorite sport, and whether there is a relationship between favorite pet and favorite sport. This tutorial is not for the faint of heart; it’s a marathon. We’ll be combining classical statistical inference techniques with a computer-intensive method called scrambling. You will simulate the null hypothesis to generate a distribution, and you will also plug the data into a chi-square test for independence. We’ll assume that you are familiar with the basic techniques of using Fathom.
Using a Ribbon Chart 1.Open PetSportSurvey.ftm from the Tutorial Starters folder in Sample Documents. Look at the 12 cases that appear in the open collection. Simply by looking at a small number of the 325 cases in the sample, it’s impossible to make any valid predictions about what trends there might be in the whole population. We’ll concentrate on the question of whether there is any relationship between a student’s sex and his or her pet preference.
Computing Proportions A ribbon chart does a good job of displaying differences in proportions. But if we want to know the computed values, we need a summary table.
The Null Hypothesis and Choosing a Test Statistic The heart of statistical inference is determining whether an observed difference is due to random variation or an actual difference in the population. The difference of proportions, 68% – 58%, or 10%, is fairly small. Perhaps it is due to chance. Just how likely is it that a random sample would have a difference of proportions this large if there were actually no difference in pet preferences between boys and girls ? The assumption that sex is unrelated to pet preference is the null hypothesis in this situation. Another way to phrase our question is: If the null hypothesis were true, what is the probability of getting a difference of proportions of 10% or greater? (We have to add the “or greater” because a greater difference is even stronger evidence in favor of there being a relationship between sex and pet preference.) The difference of proportions is an example of a test statistic. Using simulation and techniques similar to those used in the tutorial, Simulation - Polling Voters, we could determine the probability of getting the observed difference of 10%. For the purposes of this tutorial, we’re going to use a closely related test statistic, called the chi-square statistic, which is commonly used for testing whether a relationship exists between two categorical attributes.
Expected Versus Observed
The fractional boys and girls may seem strange, but it’s okay as long as we keep it hypothetical. Let’s compute these numbers in the summary table. 10. Double-click the formula below the table. 11. In the formula editor, type the expression shown here and click OK. columnTotal, rowTotal, and grandTotal are all keywords you can use only when writing a formula for a summary table. They are in the Special list in the formula editor. You can also enter them in a formula by double-clicking them in this list. You should see the expected values computed in each cell. Because this is such a common computation, Fathom has a shortcut for it. 12. Double-click the formula again and substitute the single word expected for the more complicated expression. (This keyword is also in the Special list.) Click OK. You should get the same results. The term expected, or expected value, has a very general meaning in statistics. Here, in Fathom, we’re applying it to the very particular situation of a chi-square test where the null hypothesis is that the row and column attributes are independent. We now want to compare the expected values with the observed values.
Computing the Chi-Square StatisticThere are many different statistics we could invent using the observed 15. Add the formula shown at right to the summary table. The chi-square statistic is simply the sum of the numbers we just
19. Define a second measure, pValue, for this collection. Give it the formula shown here. ChiSquareCumulative is a function built in to Fathom. It takes two arguments: the first is the value of chi-square that we have computed (the first measure we made); the second is the number of degrees of freedom available, in this case, 1. (If you know all the row totals and column totals, degrees of freedom is the number of cell counts you could fill in before all the rest were determined for you.) The function computes the probability of getting that value of chi-square or less under the assumption that the two attributes are independent. Because we’re interested in “or greater,” we subtract the function’s value from 1.
What are we to make of this result? We can say that if there were no difference between boys’ and girls’ pet preferences, and if we repeated the random sampling many times, we would get a result this extreme or more extreme about 1 time in 20. For many situations, especially in the social sciences, this level of probability is persuasive enough to say that we have probably found something. But in other situations, especially in medical research, we would not be able to say we had found something, because the consequences of being wrong would be too great. Testing for Independence—The Simple WayYou may be thinking that this was an awful lot of work to accomplish a fairly routine calculation. You’re right; and Fathom has the ability to do this computation quickly and simply. Here’s how. You may want to hide or delete objects to free up some space. Keep the original collection and its case table.
Graphing the Chi-Square Distribution
Simulating the Null Hypothesis With Fathom, we can simulate conditions under which the null hypothesis is true and repeatedly perform the sampling and computation of a chi-square statistic. Although this does not tell us anything more about the particular experiment, it does shed light on the process of statistical inference. The null hypothesis states that there is no relationship between the two attributes Sex and Pet. What if we were to take all the values for the attribute Sex and scramble them so that “boy” and “girl” got reassigned randomly to each case? Any relationship that might exist between the two attributes would be wiped out by the scrambling. Any remaining relationship would have to be due to chance alone. 25. Select the PetSportSurvey collection. 26. Choose Collection | Scramble Attribute Values. A new collection should appear labeled Scrambled PetSportSurvey.
29. Make a ribbon chart for the scrambled collection, just as you did in steps 2–4. As we scramble, we can see the variation in the relative proportions. This variation is due solely to chance. 30. Make a new test for independence. This time, drop attributes from the scrambled collection into it. Each time you scramble again, the chi-square statistic and the P-value are recomputed. Because you’re simulating the conditions of the null hypothesis, the chi-square values will not be very large, and the P-values will not be very small. Now we want to collect many chi-square values from the scrambled collection. We will build up a distribution of these values and see what shape it has. 31. Select the scrambled test and choose Test | Collect Results as Measures. Fathom will scramble the scrambled collection five times, each time collecting values computed by the test for independence and putting them in a new collection, labeled Measures from Test of Scrambled PetSportSurvey. 32. Make a case table for the measures collection. Your screen should look similar to that shown below (in nonverbose mode). The two important columns in the table are chiSquareValue and pValue. 33. Make a histogram of each of the attributes, chiSquareValue and pValue. Your histograms won’t look like much yet, because you have only collected the results of five scrambles. You need some more.
Going Further •Consider the other two pairs of attributes possible: Sex versus Sport and Pet versus Sport. Would you expect them to show more or less independence than Sex versus Pet? Look at the corresponding ribbon charts. Do the observed differences in proportions look significant? Perform a chi-square test on each of these pairs. Explain why one result is so much more significant than the other. •Though the ribbon chart is probably the easiest way to see relationships between categorical attributes, three other displays are possible, shown below. Make these three displays (using Fathom Help as needed), and learn how to interpret them. Think about circumstances in which you might prefer one versus another. |