Presentation on theme: "Chi-square, Goodness of fit, and Contingency Tables"— Presentation transcript:
1 Chi-square, Goodness of fit, and Contingency Tables
2 What is the χ2 distribution Basically a distribution of squared differences
3 Useful for detecting categorical differences Calculate the χ2 test statistic= (observed-expected)2/expectedDegrees of freedom = number of categories -1Look up χ2 value for that degree of freedom and chosen alpha value. If test statistic > table value, then significant
4 Two sided test: find the column corresponding to α/2 in the table for upper critical values and reject the null hypothesis if the test statistic is greater than the tabled value.Use 1 - α /2 in the table for lower critical values and reject null if the test statistic is less than the tabled value.Upper one-sided test: find column corresponding to α in upper critical values table. If test statistic greater, reject.
5 Also useful for model fitting Assume you have a fit a model to some data and have some residual errors left over.You want to check if residuals are normally distributed. You bin them in a histogramEstimate proportions of residuals in each, compare to actual data
6 Model Fitting Example Consider a classic genetics experiment. The offspring of a cross between the F1 brassicas was 53 dark green and 11 yellow.If the plants are heterozygous for color the ratio of 3 dark green to 1 yellow would be expected.Dark GreenYellowTotalObserved numbers (O)531164Expected numbers (E)4816O - E5-5(O-E)225(O-E)2 / E25/48 = 0.5225/16 = 1.562.08
7 Compound Hypotheses and Directionality With multiple categories, compound hypotheses are possibleH0 Pr(cat 1) = 0.25, Pr(cat 2) = and Pr(cat 3) = 0.75HA: one of the above not the caseWhere there are 2 categories, a “directional alternative” is possible
8 Directional Alternatives Only in the case of “dichotomous variables” – two categories, effectively.Step 1: Check Directionality of trendIf not, p-value > 0.5 by necessityIf so, proceed to step 2The P-value is half what it would be if HA were non directional
9 Directional Alternative Example Two football teams records are compared against the average number of wins by an NFL team per year, 9.Team 1 won 14 games this year and several players were caught doping with HGF.Team 2 won 11 games this year and tested clean.Is there evidence that doping increased the number of wins by team 1?
10 Contingency Tables Use χ2 test statistic as above, but Calculate expected values for each element in table from E=(row total)*(column total)/Grand Total;Df =1
11 2x2 Contingency Tables Can indicate either Two independent samples with a dichotomous observed variabledOne sample with two dichotomous observed variablesFemaleMaleTot(col)HIV test9817No HIVtest5251103Tot (row)6159120
12 Relation to Independence of data You can interpret contingency tables in terms of conditional probabilitiesPr(HIV test | female)= 9/61Pr(female | HIV test) = 9/17Test becomes H0 : Likelihood of taking and HIV test is independent of sexFemaleMaleTot(col)HIV test9817No HIVtest5251103Tot (row)6159120
13 Rxk contingency tables Same as above, but degrees of freedom = (r-1)*(k-1).
14 Corrections to the Chi-Squared Test It is a requirement that a chi-squared test be applied to discrete data. Counting numbers are appropriate, continuous measurements are not. Assuming continuity in the underlying distribution distorts the p value and may make false positives more likely.Frank Yates proposed a correction to the chi-squared formula. Adding a small negative term to the argument. This tends to increase the p-value, and makes the test more conservative, making false positives less likely. However, the test may now be *too* conservative.Additionally, chi squared test should not be used when the observed values in a cell are <5. It is, at times not inappropriate to pad an empty cell with a small value, though, as one can only assume the result would be more significant with no value there.