1 / 32

9.1 Inference for Two-Way Tables

9.1 Inference for Two-Way Tables. Two-way tables Expected cell counts The chi-square statistic The chi-square distributions The chi-square test Computations Computing conditional distributions Models for two-way tables. Perils of aggregation.

Download Presentation

9.1 Inference for Two-Way Tables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 9.1 Inference for Two-Way Tables • Two-way tables • Expected cell counts • The chi-square statistic • The chi-square distributions • The chi-square test • Computations • Computing conditional distributions • Models for two-way tables

  2. Perils of aggregation • This example was essentially a Three-Way Table with variables: airline, timing, airport. Such tables are often reported as several two-way tables. Think of a book, rather than a page. • Adding entries from such elementary tables (“pages”) to get the overall summary (for the “book”) is aggregation and leads to ignoring the third variable (here: airport). This may lead to false general conclusions.

  3. Hypothesis testing with 2-way tables • H0: there is no association between the row and column variables (they are independent) • Ha: there isan association between the row and column variables (they are related or dependent) • To test the hypotheses, compare: observed counts vs. expected counts (from actual data) (what is expected by H0) • Expected are calculated under the assumption that the null hypothesis is true.

  4. Expected Cell Counts The expected count in any cell of a two-way table when H0 is true is: To test this hypothesis, we compare actual countsfrom the sample data with expected counts, where the latter counts are those expected when there is no relationship between the two variables.

  5. Example: • Do men and women participate in sports for the same reasons? • 67 males and 67 females examined. Results: • HSC-HM female 14 • HSC-HM male 31 • HSC-LM female 7 • HSC-LM male 18 • LSC-HM female 21 • LSC-HM male 5 • LSC-LM female 25 • LSC-LM male 13 • Legend: HSC (LSC)-high (low) social comparison; HM (LM)-high (low) mastery

  6. SAS can do the work for us • Makes two-way table • Creates an expected column in our two-way table.

  7. In SAS… • add the expected option to the tables command in proc freq: procfreqdata=sports; tables goal*gender / expected ; weight count; run;

  8. The Chi-Square Statistic To see if the data give convincing evidence against the null hypothesis, we compare the observed counts from our sample with the expected counts assuming H0is true. Assume there are r rows in the two-way table and c columns, which means there are r  c cells. The test statistic that makes the comparison is the chi-square statistic. The chi-square statistic is a measure of how far the observed counts are from the expected counts. The formula for the statistic is: where “observed” represents an observed cell count, “expected” represents the expected count for the same cell, and the sum is over all r  c cells in the table.

  9. χ2distribution • Our example has DF = (4-1)(2-1) = 3 The Chi-Square Distributions The chi-square distributions are a family of distributions that take only positive values and are skewed to the right. A particular c2distribution is specified by giving its degrees of freedom. The c2test for a two-way table with r rows and c columns uses critical values from the c2distribution with (r – 1)(c – 1) degrees of freedom. The P-value is the area under the density curve of this c2distribution to the right of the value of the test statistic.

  10. Calculating P-values • P-valueis always the right tail of the distribution.

  11. Example Finale: • Do men and women participate in sports for the same reasons?

  12. Solution: • Recall:

  13. Remember procfreq? It does the work for us again! Note: We will be using SAS to do the computations for the test. Learn the general context, how to construct the two-way tables and how to read the P-values from Table F. procfreqdata=sports; tables goal*gender / expectedchisq; weight count; run;

  14. The FREQ Procedure (output):

  15. Cell Counts Required for the Chi-Square Test The chi-square test is an approximate method that becomes more accurate as the counts in the cells of the table get larger. We must therefore check that the counts are large enough to allow us to trust the P-value. Fortunately, the chi-square approximation is accurate for quite modest counts. Cell Counts Required for the Chi-Square Test You can safely use the chi-square test with critical values from the chi-square distribution when the average of the expected counts is 5 or more and all individual expected counts are 1 or greater. In the special case of a 2  2 table, all four expected counts should be 5 or more.

  16. Another Example: • 356 volunteers classified according socio-economic status (SES) and smoking habits. • Is smoking associated with SES?

  17. Smoking habits are associated to SES!

  18. Example (Aspirin study revisited): • 21,996 male American physicians. • Half of these took aspirin. • After 3 years, 139 of those who took aspirin and 239 of those who took placebo had heart attacks. • Determine whether there is an association of aspirin with heart attacks.

  19. χ2 Tests versus z (proportion) Tests • There is a close relationship between testing lack of association for 2x2 two-way tables with (two-sided) tests for equality of two population proportions of Chapter 8.2. • Under the right conditions, Χ2 = z2.

  20. Chi-square as a test of Independence • H0: There is NO association between the row and column variables  The two variables are independent Ha: There is an association between the row and column variables The two variables are NOT independent • H0: The two variables are independent Ha: The two variables are dependent

  21. 9.2 Goodness of Fit • The chi-square goodness of fit test

  22. The Chi-Square Test for Goodness of Fit Mars, Inc. makes milk chocolate candies. Here’s what the company’s Consumer Affairs Department says about the color distribution of its M&M’scandies: On average, the new mix of colors of M&M’s milk chocolate candies will contain 13 percent of each of browns and reds, 14 percent yellows, 16 percent greens, 20 percent oranges, and 24 percent blues. The one-way table below summarizes the data from a sample bag of M&M’s. In general, one-way tables display the distribution of a categorical variable for the individuals in a sample.

  23. The Chi-Square Test for Goodness of Fit Since the company claims that 24% of all M&M’s are blue, we might believe that something fishy is going on. We could use the z test for a proportion to test the hypotheses: H0: p = 0.24 Ha: p ≠ 0.24 where p is the true population proportion of blue M&M’S. We could then perform additional significance tests for each of the remaining colors. However, performing a one-sample z test for each proportion would be pretty inefficient and would lead to the problem of multiple comparisons, in which we have to adjust for the fact that several tests are done at the same time. More important, performing one-sample z tests for each color wouldn’t tell us how likely it is to get a random sample of 60 candies with a color distribution that differs as much from the one claimed by the company as this bag does (taking all the colors into consideration at one time). For that, we need a new kind of significance test, called a chi-square test for goodness of fit.

  24. The Chi-Square Test for Goodness of Fit We can write the hypotheses in symbols as: H0: pblue= 0.24, porange= 0.20, pgreen= 0.16, pyellow= 0.14, pred= 0.13, pbrown= 0.13, Ha: At least one of the proportions is different than claimed where pcolor = the true population proportion of M&M’s of that color. The idea of the chi-square test for goodness of fit is this: We compare the observed counts from our sample with the counts that would be expected if H0is true. The more the observed counts differ from the expected counts, the more evidence we have against the null hypothesis. In general, the expected counts can be obtained by multiplying the proportion of the population distribution in each category by the sample size.

  25. The Chi-Square Test for Goodness of Fit Assuming that the color distribution stated by Mars, Inc. is true, 24% of all M&M’s produced are blue. For random samples of 60 candies, the average number of blue M&M’s should be (0.24)(60) = 14.40. This is our expected count of blue M&M’s. Using this same method, we can find the expected counts for the other color categories: Orange: (0.20)(60) = 12.00 Green: (0.16)(60) = 9.60 Yellow: (0.14)(60) = 8.40 Red: (0.13)(60) = 7.80 Brown: (0.13)(60) = 7.80

  26. The Chi-Square Test for Goodness of Fit To calculate the chi-square statistic, use the same formula as you did earlier in the chapter.

  27. The Chi-Square Test for Goodness of Fit A categorical variable has k possible outcomes, with probabilities p1, p2, p3, … , pk. That is, piis the probability of the ith outcome. We have n independent observations from this categorical variable. To test the null hypothesis that the probabilities have specified values H0: p1 = ___, p2 = ___, …, pk = ___. find the expected count for each category assuming that H0is true. Then calculate the chi-square statistic: The Chi-Square Test for Goodness of Fit

  28. The Chi-Square Test for Goodness of Fit Since our P-value is between 0.05 and 0.10, it is greater than α = 0.05.Therefore, we fail to reject H0. We don’t have sufficient evidence to conclude that the company’s claimed color distribution is incorrect.

More Related