Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2009 Pearson Education, Inc. Chapter 26 Comparing Counts.

Similar presentations


Presentation on theme: "Copyright © 2009 Pearson Education, Inc. Chapter 26 Comparing Counts."— Presentation transcript:

1

2 Copyright © 2009 Pearson Education, Inc. Chapter 26 Comparing Counts

3 Copyright © 2009 Pearson Education, Inc. Slide 1- 3 Objectives: The student will be able to: Perform chi-square tests for goodness-of-fit, homogeneity, and independence, to include: writing appropriate hypotheses, checking the necessary assumptions, drawing an appropriate diagram, computing the P-value, making a decision, and interpreting the results in the context of the problem.

4 Copyright © 2009 Pearson Education, Inc. Slide 1- 4 Goodness-of-Fit A test of whether the distribution of counts in one categorical variable matches the distribution predicted by a model is called a goodness-of-fit test. As usual, there are assumptions and conditions to consider…

5 Copyright © 2009 Pearson Education, Inc. Slide 1- 5 Assumptions and Conditions Counted Data Condition: Check that the data are counts for the categories of a categorical variable. Independence Assumption: The counts in the cells should be independent of each other. Randomization Condition: The individuals who have been counted and whose counts are available for analysis should be a random sample from some population.

6 Copyright © 2009 Pearson Education, Inc. Slide 1- 6 Assumptions and Conditions (cont.) Sample Size Assumption: We must have enough data for the methods to work. Expected Cell Frequency Condition: We should expect to see at least 5 individuals in each cell. This is similar to the condition that np and nq be at least 10 when we tested proportions.

7 Copyright © 2009 Pearson Education, Inc. Hypotheses for a goodness of fit test H 0 : The distribution of counts occurs in a manner consistent with our model. For example, if our model is a uniform distribution we might say p 1 =p 2 =p 3 =p 4 H A : the distribution of counts occurs in a manner which is inconsistent with our model. Note: the distribution of counts can vary from our model in many different ways! Slide 1- 7

8 Copyright © 2009 Pearson Education, Inc. Slide 1- 8 Calculations Since we want to examine how well the observed data reflect what would be expected, it is natural to look at the differences between the observed and expected counts (Obs – Exp). These differences are actually residuals, so we know that adding all of the differences will result in a sum of 0. That’s not very helpful.

9 Copyright © 2009 Pearson Education, Inc. Slide 1- 9 Calculations (cont.) We’ll handle the residuals as we did in regression, by squaring them. To get an idea of the relative sizes of the differences, we will divide these squared quantities by the expected values.

10 Copyright © 2009 Pearson Education, Inc. Slide 1- 10 Calculations (cont.) The test statistic, called the chi-square (or chi- squared) statistic, is found by adding up the sum of the squares of the deviations between the observed and expected counts divided by the expected counts:

11 Copyright © 2009 Pearson Education, Inc. Slide 1- 11 Calculations (cont.) The chi-square models are actually a family of distributions indexed by degrees of freedom (much like the t-distribution). The number of degrees of freedom for a goodness-of-fit test is n – 1, where n is the number of categories.

12 Copyright © 2009 Pearson Education, Inc. Slide 1- 12 Chi-Square P-Values The chi-square statistic is used only for testing hypotheses, not for constructing confidence intervals. If the observed counts don’t match the expected, the statistic will be large—it can’t be “too small.” So the chi-square test is always one-sided. If the calculated value is large enough, we’ll reject the null hypothesis.

13 Copyright © 2009 Pearson Education, Inc. Slide 1- 13 The mechanics may work like a one-sided test, but the interpretation of a chi-square test is in some ways many-sided. There are many ways the null hypothesis could be wrong. There’s no direction to the rejection of the null model—all we know is that it doesn’t fit. Chi-Square P-Values (cont.)

14 Copyright © 2009 Pearson Education, Inc. Slide 1- 14 The Chi-Square Calculation 1.Find the expected values: Every model gives a hypothesized proportion for each cell. The expected value is the product of the total number of observations times this proportion. 2.Compute the residuals: Once you have expected values for each cell, find the residuals, Observed – Expected. 3.Square the residuals.

15 Copyright © 2009 Pearson Education, Inc. Slide 1- 15 The Chi-Square Calculation (cont.) 4.Compute the components. Now find the components for each cell. 5.Find the sum of the components (that’s the chi- square statistic).

16 Copyright © 2009 Pearson Education, Inc. Slide 1- 16 The Chi-Square Calculation (cont.) 6.Find the degrees of freedom. It’s equal to the number of cells minus one. 7.Test the hypothesis.  Use your chi-square statistic to find the P-value. (Remember, you’ll always have a one-sided test.)  Large chi-square values mean lots of deviation from the hypothesized model, so they give small P-values.

17 Copyright © 2009 Pearson Education, Inc. Using our calculator -- only for TI 84+ χ 2 Goodness-of-Fit Test for the TI-84 Plus Calculator It is relatively easier to conduct a χ2 goodness-of-fit test if you happen to have a TI-84 Plus calculator. Enter the observed frequencies in L1 and the expected frequencies in L2 Go to Stat -> Tests -> D:X 2 GOF-Test Your calculator will prompt you for the list with the observed frequencies ( L1 for this example) and the list with the expected frequencies (L2 for this example), and the number of degrees of freedom. You can find the degrees of freedom by subtracting 1 from the number of categories (k – 1). Then press Calculate Slide 1- 17

18 Copyright © 2009 Pearson Education, Inc. TI-83+ for x 2 Goodness of Fit test Enter the observed frequencies in L 1 and the expected frequencies in L 2. Highlight L 3 and type (L 1 - L 2 ) 2 / L 2 enter The computed values should appear in L 3 We now need to sum the values in L 3. We do this by going to List (2 nd Stat) -> MATH -> 5: sum Sum(L 3 ) this gives us our x 2 statistic. To find the p-value we need to go to DISTR (2 nd Vars) -> 7: x 2 cdf(Ans, 1E99, df) Where Ans is the x 2 statistic just calculated 1E99 is a very large number, and df is (# categories – 1) Slide 1- 18

19 Copyright © 2009 Pearson Education, Inc. A die is filled with a lead weight and then rolled 200 times with the following results: 1: 27 2: 31 3: 42 4: 40 5: 28 6: 32 Use an alpha of 0.05 to test the claim that the outcomes are not equally likely (Triola 2008). H0: The die rolls are evenly distributed over 1-6. HA: The die rolls are not evenly distributed over 1-6 (i.e. the die is not “fair”). Test Statistic (X2) = 5.86 P-Value = 0.32 Conclusion: Since the P-value is greater than alpha, we cannot reject the null hypothesis. Therefore, there is not enough statistical evidence to support the claim that the die is not fair. Slide 1- 19

20 Copyright © 2009 Pearson Education, Inc. 37. The following data lists automobile fatalities by day of week: Sun: 132 Mon: 98 Tue: 95 Wed: 98 Thu: 105 Fri: 133 Sat: 158 Use an alpha of 0.05 to test the claim that the outcomes are not uniformly spread across the days of the week (Triola 2008). H0: Automobile fatalities are evenly distributed over all seven days of the week. HA: Automobile fatalities are not evenly distributed over all seven days of the week. Test Statistic (X2) = 30.02 P-Value = Small # Conclusion: Since the P-value is less than alpha, we can reject the null hypothesis. Therefore, the statistical evidence suggests that driving fatalities are not evenly spread throughout the days of the week. Slide 1- 20

21 Copyright © 2009 Pearson Education, Inc. 38. The following data lists the birth months of Oscar-winning actors: Jan: 9 Feb: 5 Mar: 7 Apr: 14 May: 8 Jun: 1 Jul:7 Aug: 6 Sep: 4 Oct: 5 Nov: 1 Dec: 9 Use an alpha of 0.05 to test the claim that the outcomes are not uniformly spread across the months (Triola 2008). H0: Actor birth months are uniformly spread out over all 12 months. HA: Actor birth months are not uniformly spread out over all 12 months. Test Statistic (X2) = 22.54 P-Value = 0.02 Conclusion: Since the P-value is less than alpha, we can reject the null hypothesis. Therefore, the statistical evidence suggests that actor birth months are NOT evenly spread out throughout the year. Slide 1- 21

22 Copyright © 2009 Pearson Education, Inc. 39. You are planning to open an old time soda fountain and your partner claims that the public will not prefer any flavor over another. The flavors you serve are cherry, strawberry, orange, lime and grape. After several customers, you stop and take a look at how sales are going and here are the results. The following numbers of people ordered the flavor shown. Cherry 35, Strawberry 32, Orange 29, Lime 26 and Grape 25. Test to see if there was a preference at the 0.05 significance level. H0: The customers have no preference for any flavor. HA: The customers have flavor preferences. Test Statistic (X2) = 2.35 P-Value = 0.67 Conclusion: Since the P-value is larger than alpha, we cannot reject the null hypothesis. Therefore, there is no statistical evidence that customers prefer some flavors more than others. Slide 1- 22

23 Copyright © 2009 Pearson Education, Inc. Slide 1- 23 But I Believe the Model… Goodness-of-fit tests are likely to be performed by people who have a theory of what the proportions should be, and who believe their theory to be true. Unfortunately, the only null hypothesis available for a goodness-of-fit test is that the theory is true. As we know, the hypothesis testing procedure allows us only to reject or fail to reject the null.

24 Copyright © 2009 Pearson Education, Inc. Slide 1- 24 But I Believe the Model… (cont.) We can never confirm that a theory is in fact true. At best, we can point out only that the data are consistent with the proposed theory. Remember, it’s that idea of “not guilty” versus “innocent.”

25 Copyright © 2009 Pearson Education, Inc. Slide 1- 25 Comparing Observed Distributions A test comparing the distribution of counts for two or more groups on the same categorical variable is called a chi-square test of homogeneity. A test of homogeneity is actually the generalization of the two-proportion z-test.

26 Copyright © 2009 Pearson Education, Inc. Slide 1- 26 Comparing Observed Distributions (cont.) The statistic that we calculate for this test is identical to the chi-square statistic for goodness- of-fit. In this test, however, we ask whether choices have changed (i.e., there is no model). The expected counts are found directly from the data and we have different degrees of freedom.

27 Copyright © 2009 Pearson Education, Inc. Slide 1- 27 Assumptions and Conditions The assumptions and conditions are the same as for the chi-square goodness-of-fit test: Counted Data Condition: The data must be counts. Randomization Condition and 10% Condition: As long as we don’t want to generalize, we don’t have to check these condition. Expected Cell Frequency Condition: The expected count in each cell must be at least 5.

28 Copyright © 2009 Pearson Education, Inc. Slide 1- 28 Calculations To find the expected counts, we multiply the row total by the column total and divide by the grand total. We calculated the chi-square statistic as we did in the goodness-of-fit test: In this situation we have (R – 1)(C – 1) degrees of freedom, where R is the number of rows and C is the number of columns. We’ll need the degrees of freedom to find a P-value for the chi-square statistic.

29 Copyright © 2009 Pearson Education, Inc. Slide 1- 29 Independence Contingency tables categorize counts on two (or more) variables so that we can see whether the distribution of counts on one variable is contingent on the other. A test of whether the two categorical variables are independent examines the distribution of counts for one group of individuals classified according to both variables in a contingency table. A chi-square test of independence uses the same calculation as a test of homogeneity.

30 Copyright © 2009 Pearson Education, Inc. Slide 1- 30 Assumptions and Conditions We still need counts and enough data so that the expected values are at least 5 in each cell. If we’re interested in the independence of variables, we usually want to generalize from the data to some population. In that case, we’ll need to check that the data are a representative random sample from that population.

31 Copyright © 2009 Pearson Education, Inc. Hypotheses for a x 2 test of independence H 0 : the variables are independent i.e. the distribution of counts is the same for each group. H A : the variables are not independent OR can say: (they are dependent, i.e. associated) i.e. the distribution of counts are different among the groups. Slide 1- 31

32 Copyright © 2009 Pearson Education, Inc. X 2 test for Independence using the TI A sociologist wishes to see whether the number of years of college a person has completed is related to his or her place of residence. A sample of 84 is selected and classified as shown. (The best way to arrange data for a study involving independence is to create a contingency table made up of "i" rows and "j" columns.) LocationNo CollegeBachelorsMasters PhD Urban1512165 Suburban815119 Rural67127 At  =0.05, can the sociologist conclude that the years of college education are independent of the residence location? We need to get this contingency table into the TI using the Matrx function. Matrx…Edit…enter to get into the matrix [A]. A matrix is called by its rows first and then its columns. So this is a 3 x 4 matrix. Enter these numbers accordingly. Next fill in the matrix as it appears above. Remember to hit enter after each data entry. Then 2 nd Quit. Stat -> Test -> #C x 2 -test. We placed the observed data in [A] and the TI will place the expected values in [B] or anywhere you stipulate. Then ask the TI to calculate. You get a computed x 2 of 6.22794437 and a p-value of,398. Thus we cannot reject the null hypothesis. This suggests independence. Therefore, place of residence and education level are independent of each other Slide 1- 32

33 Copyright © 2009 Pearson Education, Inc. Here is a table showing who survived the sinking of the Titanic based on whether they were crew members or passengers booked in first, second or third-class staterooms: CrewFirstSecond ThirdTotal Alive 212 203 118 178 711 Dead 673 122 167 528 1490 Total 885 325 285 706 2201 Determine if surviving was independent of cabin status (use alpha=0.01). H0: Cabin class and survivorship are independent. HA: Cabin class and survivorship are dependent. Test Statistic (X2) = 190.4 P-Value = Tiny, tiny # Conclusion: Since the P-value is smaller than alpha, we reject the null hypothesis. Therefore, we can conclude that there is an association (dependence) between cabin class and survivorship. Slide 1- 33

34 Copyright © 2009 Pearson Education, Inc. 34. Use the following data to do a test of independence to see if left-handedness is independent of gender (use alpha=0.05): Left-HandedRight-Handed Male1783 Female 16184 H0: “Handedness” and gender are independent. HA: Handedness and gender are dependent. Test Statistic (X2) = 5.52 P-Value = 0.019 Conclusion: Since the P-value is smaller than alpha, we reject the null hypothesis. Therefore, we can conclude that there is an association (dependence) between handedness and gender. Slide 1- 34

35 Copyright © 2009 Pearson Education, Inc. 35. Use the following data to do a test of independence to see if height is independent of gender (use alpha=0.05) ShortTall Male325 Female172 H0: Height and gender are independent. HA: Height and gender are not independent. Test Statistic (X2) = 28.72 P-Value = Small # Conclusion: Since the P-value is smaller than alpha, we reject the null hypothesis. Therefore, we can conclude that there is an association (dependence) between height and gender. Slide 1- 35

36 Copyright © 2009 Pearson Education, Inc. Slide 1- 36 Chi-Square and Causation Chi-square tests are common, and tests for independence are especially widespread. We need to remember that a small P-value is not proof of causation. Since the chi-square test for independence treats the two variables symmetrically, we cannot differentiate the direction of any possible causation even if it existed. And, there’s never any way to eliminate the possibility that a lurking variable is responsible for the lack of independence.

37 Copyright © 2009 Pearson Education, Inc. Slide 1- 37 Chi-Square and Causation (cont.) In some ways, a failure of independence between two categorical variables is less impressive than a strong, consistent, linear association between quantitative variables. Two categorical variables can fail the test of independence in many ways. Examining the standardized residuals can help you think about the underlying patterns.

38 Copyright © 2009 Pearson Education, Inc. Slide 1- 38 What Can Go Wrong? Don’t use chi-square methods unless you have counts. Just because numbers are in a two-way table doesn’t make them suitable for chi-square analysis. Beware large samples. With a sufficiently large sample size, a chi-square test can always reject the null hypothesis. Don’t say that one variable “depends” on the other just because they’re not independent. Association is not causation.

39 Copyright © 2009 Pearson Education, Inc. Slide 1- 39 What have we learned? We’ve learned how to test hypotheses about categorical variables. All three methods we examined look at counts of data in categories and rely on chi-square models. Goodness-of-fit tests compare the observed distribution of a single categorical variable to an expected distribution based on theory or model. Tests of homogeneity compare the distribution of several groups for the same categorical variable. Tests of independence examine counts from a single group for evidence of an association between two categorical variables.

40 Copyright © 2009 Pearson Education, Inc. Slide 1- 40 What have we learned? (cont.) Mechanically, these tests are almost identical. While the tests appear to be one-sided, conceptually they are many-sided, because there are many ways that the data can deviate significantly from what we hypothesize. When we reject the null hypothesis, we know to examine standardized residuals to better understand the patterns in the data.


Download ppt "Copyright © 2009 Pearson Education, Inc. Chapter 26 Comparing Counts."

Similar presentations


Ads by Google