Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter Chi-Square Tests 15 Chi-Square Test for Independence Contingency Tables Chi-Square Test for Independence Chi-Square Tests for Goodnessof-Fit Uniform Goodness-of-Fit Test Poisson Goodness-of-Fit Test Normal Chi-Square Goodnessof-Fit Test ECDF Tests (Optional) McGraw-Hill/Irwin Copyright © 2009 by The McGraw-Hill Companies, Inc. • • 15-2 Chi-Square Test for Independence Chi-Square Test for Independence Contingency Tables • Chi-Square Test • For example: • • • Table 15.1 15-3 A contingency table is a cross-tabulation of n paired observations into categories. Each cell shows the count of observations that fall into the B category A defined by its row (r) and column (c) heading. 15-4 In a test of independence for an r x c contingency table, the hypotheses are H0: Variable A is independent of variable B H1: Variable A is not independent of variable B Use the chi-square test for independence to test these hypotheses. This non-parametric test is based on frequencies. The n data pairs are classified into c columns and r rows and then the observed frequency fjk is compared with the expected frequency ejk. Chi-Square Test for Independence Chi-Square Test for Independence Chi-Square Distribution • • • Chi-Square Distribution • The critical value comes from the chi-square probability distribution with ν degrees of freedom. ν = degrees of freedom = (r – 1)(c – 1) where r = number of rows in the table c = number of columns in the table Appendix E contains critical values for righttail areas of the chi-square distribution. The mean of a chi-square distribution is ν with variance 2ν. 15-5 Figure 15.1 15-6 Chi-Square Test for Independence Chi-Square Test for Independence Expected Frequencies • 15-7 Consider the shape of the chi-square distribution: Steps in Testing the Hypotheses Assuming that H0 is true, the expected frequency of row j and column k is: ejk = RjCk/n where Rj = total for row j (j = 1, 2, …, r) Ck = total for column k (k = 1, 2, …, c) n = sample size 15-8 • Step 1: State the Hypotheses H0: Variable A is independent of variable B H1: Variable A is not independent of variable B • Step 2: Specify the Decision Rule Calculate ν = (r – 1)(c – 1) For a given α, look up the right-tail critical value (χ2R) from Appendix E or by using Excel. Reject H0 if χ2R > test statistic. Chi-Square Test for Independence Steps in Testing the Hypotheses Chi-Square Test for Independence Steps in Testing the Hypotheses For example, for ν = 6 and α = .05, χ2.05 = 12.59. • • Here is the rejection region. Figure 15.2 15-9 Figure 15.3 15-10 Chi-Square Test for Independence Steps in Testing the Hypotheses • • Chi-Square Test for Independence Steps in Testing the Hypotheses Step 3: Calculate the Expected Frequencies ejk = RjCk/n For example, • Step 4: Calculate the Test Statistic The chi-square test statistic is calc • 15-11 15-12 Step 5: Make the Decision Reject H0 if χ2R > test statistic or if the p-value < α. Chi-Square Test for Independence Small Expected Frequencies • • • • Chi-Square Test for Independence Cross-Tabulating Raw Data The chi-square test is unreliable if the expected frequencies are too small. Rules of thumb: • Cochran’s Rule requires that ejk > 5 for all cells. • Up to 20% of the cells may have ejk < 5 Most agree that a chi-square test is infeasible if ejk < 1 in any cell. If this happens, try combining adjacent rows or columns to enlarge the expected frequencies. • Chi-square tests for independence can also be used to analyze quantitative variables by coding them into categories. For example, the variables Infant Deaths per 1,000 and Doctors per 100,000 can each be coded into various categories: Figure 15.6 15-13 15-14 Chi-Square Test for Goodness-ofFit Why Do a Chi-Square Test on Numerical Data? • • • 15-15 Chi-Square Test for Independence 3-Way Tables and Higher • The researcher may believe there’s a relationship between X and Y, but doesn’t want to use regression. There are outliers or anomalies that prevent us from assuming that the data came from a normal population. The researcher has numerical data for one variable but not the other. • • • 15-16 More than two variables can be compared using contingency tables. However, it is difficult to visualize a higher order table. For example, you could visualize a cube as a stack of tiled 2-way contingency tables. Major computer packages permit 3-way tables. Chi-Square Test for Goodness-ofFit Purpose of the Test • • Chi-Square Test for Goodness-ofFit Multinomial GOF Test • The goodness-of-fit (GOF) test helps you decide whether your sample resembles a particular kind of population. The chi-square test will be used because it is versatile and easy to understand. • A multinomial distribution is defined by any k probabilities π1, π2, …, πk that sum to unity. For example, consider the following “official” proportions of M&M colors. calc 15-17 15-18 Chi-Square Test for Goodness-ofFit Chi-Square Test for Goodness-ofFit Multinomial GOF Test Hypotheses for GOF • • The hypotheses are H0: π1 = .30, π2 = .20, π3 = .10, π4 = .10, π5 = .10, π6 = .20 • 15-19 The hypotheses are: H0: The population follows a _____ distribution H1: The population does not follow a ______ distribution H1: At least one of the πj differs from the hypothesized value No parameters are estimated (m = 0) and there are c = 6 classes, so the degrees of freedom are ν=c–m–1=6–0-1 • 15-20 The blank may contain the name of any theoretical distribution (e.g., uniform, Poisson, normal). Chi-Square Test for Goodness-ofFit Chi-Square Test for Goodness-ofFit Test Statistic and Degrees of Freedom for GOF Test Statistic and Degrees of Freedom for GOF • • Assuming n observations, the observations are grouped into c classes and then the chisquare test statistic is found using: • calc where fj = the observed frequency of observations in class j ej = the expected frequency in class j if H0 were true 15-21 15-22 Chi-Square Test for Goodness-ofFit Chi-Square Test for Goodness-ofFit Test Statistic and Degrees of Freedom for GOF Data-Generating Situations • v = c − m = c − 0 −1 = c −1 v = c − m = c −1−1 = c − 2 Instead of “fishing” for a good-fitting model, visualize a priori the characteristics of the underlying data-generating process. Mixtures: A Problem v = c − m = c − 2 −1 = c − 3 15-23 If the proposed distribution gives a good fit to the sample, the test statistic will be near zero. The test statistic follows the chi-square distribution with degrees of freedom ν=c–m–1 where c is the no. of classes used in the test m is the no. of parameters estimated • 15-24 Mixtures occur when more than one datagenerating process is superimposed on top of one another. Chi-Square Test for Goodness-ofFit Eyeball Tests • Uniform Goodness-of-Fit Test Uniform Distribution • A simple “eyeball” inspection of the histogram or dot plot may suffice to rule out a hypothesized population. • Small Expected Frequencies • Goodness-of-fit tests may lack power in small samples. As a guideline, a chisquare goodness-of-fit test should be avoided if n < 25. 15-25 • 15-26 Uniform Goodness-of-Fit Test Uniform GOF Test: Grouped Data • • • • • • 15-27 The uniform goodness-of-fit test is a special case of the multinomial in which every value has the same chance of occurrence. The chi-square test for a uniform distribution compares all c groups simultaneously. The hypotheses are: H0: π1 = π2 = …, πc = 1/c H1: Not all πj are equal Uniform Goodness-of-Fit Test Uniform GOF Test: Raw Data The test can be performed on data that are already tabulated into groups. Calculate the expected frequency ej for each cell. The degrees of freedom are ν = c – 1 since there are no parameters for the uniform distribution. Obtain the critical value χ2α from Appendix E for the desired level of significance α. The p-value can be obtained from Excel. Reject H0 if p-value < α. • • • • • • 15-28 First form c bins of equal width and create a frequency distribution. Calculate the observed frequency fj for each bin. Define ej = n/c. Perform the chi-square calculations. The degrees of freedom are ν = c – 1 since there are no parameters for the uniform distribution. Obtain the critical value from Appendix E for a given significance level α and make the decision. Uniform Goodness-of-Fit Test Uniform GOF Test: Raw Data • Uniform Goodness-of-Fit Test Uniform GOF Test: Raw Data Maximize the test’s power by defining bin width as • • • As a result, the expected frequencies will be as large as possible. 15-29 • 15-30 Poisson Goodness-of-Fit Test Poisson Data-Generating Situations • • • • 15-31 Calculate the mean and standard deviation of the uniform distribution as: µ = (a + b)/2 σ= [(b – a + 1)2 – 1)/12 If the data are not skewed and the sample size is large (n > 30), then the mean is approximately normally distributed. So, test the hypothesized uniform mean using Poisson Goodness-of-Fit Test Poisson Goodness-of-Fit Test In a Poisson distribution model, X represents the number of events per unit of time or space. X is a discrete nonnegative integer (X = 0, 1, 2, …) Event arrivals must be independent of each other. Sometimes called a model of rare events because X typically has a small mean. • • 15-32 The mean λ is the only parameter. Assuming that λ is unknown and must be estimated from the sample, the steps are: Step 1: Tally the observed frequency fj of each X-value. Step 2: Estimate the mean λ from the sample. Step 3: Use the estimated λ to find the Poisson probability P(X) for each value of X. Poisson Goodness-of-Fit Test Poisson Goodness-of-Fit Test • Poisson Goodness-of-Fit Test Poisson GOF Test: Tabulated Data Step 4: Multiply P(X) by the sample size n to get expected Poisson frequencies ej. Step 5: Perform the chi-square calculations. Step 6: Make the decision. You may need to combine classes until expected frequencies become large enough for the test (at least until ej > 2). 15-33 • c ^ λ= • Σx f j =1 j j n Using this estimate mean, calculate the Poisson probabilities either by using the Poisson formula P(x) = (λxe-λ)/x! or Excel. 15-34 Normal Chi-Square Goodness-of-Fit Test Poisson Goodness-of-Fit Test Poisson GOF Test: Tabulated Data • • • 15-35 Calculate the sample mean as: Normal Data Generating Situations For c classes with m = 1 parameter estimated, the degrees of freedom are ν=c–m–1 Obtain the critical value for a given α from Appendix E. Make the decision. • • • 15-36 Two parameters, µ and σ, fully describe the normal distribution. Unless µ and σ are know a priori, they must be estimated from a sample by using x and s. Using these statistics, the chi-square goodness-of-fit test can be used. Normal Chi-Square Goodness-of-Fit Test Normal Chi-Square Goodness-of-Fit Test Method 1: Standardizing the Data • Transform the sample observations x1, x2, …, xn into standardized values. • Count the sample observations fj within intervals of the form x + ks and compare them with the known frequencies ej based on the normal distribution. Method 1: Standardizing the Data Advantage is a standardized scale. Disadvantage is that data are no longer in the original units. Figure 15.14 15-37 15-38 Normal Chi-Square Goodness-of-Fit Test Method 2: Equal Bin Widths • 15-39 Normal Chi-Square Goodness-of-Fit Test Method 2: Equal Bin Widths To obtain equal-width bins, divide the exact data range into c groups of equal width. Step 1: Count the sample observations in each bin to get observed frequencies fj. Step 2: Convert the bin limits into standardized z-values by using the formula. • 15-40 Step 3: Find the normal area within each bin assuming a normal distribution. Step 4: Find expected frequencies ej by multiplying each normal area by the sample size n. Classes may need to be collapsed from the ends inward to enlarge expected frequencies. Normal Chi-Square Goodness-of-Fit Test Normal Chi-Square Goodness-of-Fit Test Method 3: Equal Expected Frequencies • • • • Method 3: Equal Expected Frequencies Define histogram bins in such a way that an equal number of observations would be expected within each bin under the null hypothesis. Define bin limits so that ej = n/c A normal area of 1/c in each of the c bins is desired. The first and last classes must be open-ended for a normal distribution, so to define c bins, we need c – 1 cutpoints. 15-41 • • • The upper limit of bin j can be found directly by using Excel. Alternatively, find zj for bin j using Excel and then calculate the upper limit for bin j as x + zjs Once the bins are defined, count the observations fj within each bin and compare them with the expected frequencies ej = n/c. 15-42 Normal Chi-Square Goodness-of-Fit Test Normal Chi-Square Goodness-of-Fit Test Method 3: Equal Expected Frequencies • Histograms • Standard normal cutpoints for equal area bins. • • The fitted normal histogram gives visual clues as to the likely outcome of the GOF test. Histograms reveal any outliers or other nonnormality issues. Further tests are needed since histograms vary. Table 15.16 Figure 15.15 15-43 15-44 Normal Chi-Square Goodness-of-Fit Test Critical Values for Normal GOF Test • ECDF Tests Kolmogorov-Smirnov and Lilliefors Tests Since two parameters, m and s, are estimated from the sample, the degrees of freedom are ν = c – m – 1 • • Table 15.19 • • At least 4 bins are needed to ensure 1 df. 15-45 There are many alternatives to the chi-square test based on the Empirical Cumulative Distribution Function (ECDF). The Kolmogorov-Smirnov (K-S) test statistic D is the largest absolute difference between the actual and expected cumulative relative frequency of the n data values: D = Max |Fa – Fe| The K-S test is not recommended for grouped data. 15-46 ECDF Tests Kolmogorov-Smirnov and Lilliefors Tests • • • • • ECDF Tests Kolmogorov-Smirnov and Lilliefors Tests Fa is the actual cumulative frequency at observation i. Fe is the expected cumulative frequency at observation i under the assumption that the data came from the hypothesized distribution. The K-S test assumes that no parameters are estimated. If parameters are estimated, use a Lilliefors test. Both of these tests are done by computer. K-S test for uniformity. Figure 15.20 15-47 15-48 ECDF Tests Kolmogorov-Smirnov and Lilliefors Tests ECDF Tests Anderson-Darling Tests • • • K-S test for normality. • The Anderson-Darling (A-D) test is widely used for non-normality because of its power. The A-D test is based on a probability plot. When the data fit the hypothesized distribution closely, the probability plot will be close to a straight line. The A-D test statistic measures the overall distance between the actual and the hypothesized distributions, using a weighted squared distance. Figure 15.21 15-49 15-50 Applied Statistics in Business & Economics ECDF Tests Anderson-Darling Tests with MINITAB End of Chapter 15 Figure 15.22 15-51 15-52 McGraw-Hill/Irwin Copyright © 2009 by The McGraw-Hill Companies, Inc.