<<

3/14/14

Section 7.1 Multiple Categories • So far, we’ve learned how to do inference Testing Goodness-of- for categorical variables with only two categories Fit for a Single Categorical Variable • Today, we’ll learn how to do hypothesis tests for categorical variables with multiple categories

Kari Lock Morgan

Statistics: Unlocking the Power of Lock5 : Unlocking the Power of Data Lock5

Rock-Paper-Scissors Rock-Paper-Scissors (Roshambo) ROCK PAPER SCISSORS 66 39 14

How would we test whether all of these categories are equally likely?

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Hypothesis Testing Hypotheses

1. State Hypotheses th Let pi denote the proportion in the i category.

2. Calculate a , based on your data H0 : All pi s are the same test statistic Ha : At least one pi differs from the others

3. Create a distribution of this statistic, as it would OR be observed if the null hypothesis were true

4. Measure how extreme your test statistic from (2) H0 : Every pi = 1/3 is, as compared to the distribution generated in (3) Ha : At least one pi ≠ 1/3

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

1 3/14/14

Test Statistic Observed Counts Why can’t we use the familiar formula • The observed counts are the actual sample statistic− null value counts observed in the study SE ROCK PAPER SCISSORS to get the test statistic? Observed 66 39 14

• More than one sample statistic • More than one null value

We need something a bit more complicated…

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Expected Counts Rock-Paper-Scissors

• The expected counts are the expected ROCK PAPER SCISSORS counts if the null hypothesis were true Observed 66 39 14 Expected • For each cell, the expected count is the

sample size (n) times the null proportion, pi

expected = npi

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Chi-Square Statistic Rock-Paper-Scissors • A test statistic is one number, computed from the data, which we can use to assess the ROCK PAPER SCISSORS null hypothesis Observed 66 39 14 Expected 39.7 39.7 39.7 • The chi-square statistic is a test statistic for categorical variables:

2 2 (observed - expected) χ = ∑ expected

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

2 3/14/14

What Next? Upper-Tail p-value We have a test statistic. What else do we need — To calculate the p-value for a chi-square test, to perform the hypothesis test? we always look in the upper tail A distribution of the test — Why? 2 statistic assuming H is true ¡ Values of the χ are always positive 0 ¡ The higher the χ2 statistic is, the farther the

How do we get this? observed counts are from the expected counts, and the stronger the evidence against the null Two options: 1) Simulation 2) Distributional Theory

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Simulation Chi-Square (χ2) Distribution www.lock5stat.com/statkey • If each of the expected counts are at least 5, AND if the null hypothesis is true, then the χ2 statistic follows a χ2 –distribution, with degrees of freedom equal to

df = number of categories – 1

• Rock-Paper-Scissors:

df = 3 – 1 = 2

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

2 Chi-Square Distribution p-value using χ distribution www.lock5stat.com/statkey

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

3 3/14/14

Goodness of Fit Chi-Square Test for

1. State null hypothesized proportions for each category, pi. • A chi-square test for goodness of it Alternative is that at least one of the proportions is different than speciied in the null. tests whether the distribution of a 2. Calculate the expected counts for each cell as npi . categorical variable is the same as some 2 2 3. Calculate the χ statistic: 2 (observed - expected) null hypothesized distribution χ = ∑ expected

• The null hypothesized proportions for 4. Compute the p-value as the proportion above the χ2 statistic for either a distribution or a χ2 distribution with each category do not have to be the same df = (# of categories – 1) if expected counts all > 5 5. Interpret the p-value in context.

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Mendel’s Pea Mendel’s Pea Experiment Mate SSYY with ssyy: • In 1866, Gregor Mendel, the “father of genetics” Þ 1st Generation: all Ss Yy published the results of his on peas Mate 1st Generation: • He found that his experimental distribution of => 2nd Generation peas closely matched the theoretical distribution ß Second Generation predicted by his theory of genetics (involving alleles, and dominant and recessive genes) Phenotype Theoretical Proportion Round, Yellow 9/16 Source: Mendel, Gregor. (1866). Versuche über Planzen-Hybriden. Verh. Round, Green 3/16 Naturforsch. Ver. Brünn 4: 3–47 (in English in 1901, Experiments in S, Y: Dominant Wrinkled, Yellow 3/16 Plant Hybridization, J. R. Hortic. Soc. 26: 1–32) s, y: Recessive Wrinkled, Green 1/16 Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Mendel’s Pea Experiment Mendel’s Pea Experiment

Phenotype Theoretical Observed Phenotype Null pi Observed Expected Counts Proportion Counts Counts Round, Yellow 9/16 315 Round, Yellow 9/16 315 Round, Green 3/16 101 Round, Green 3/16 101 Wrinkled, Yellow 3/16 108 Wrinkled, Yellow 3/16 108 Wrinkled, Green 1/16 32 Wrinkled, Green 1/16 32

Let’s test this data against the null hypothesis of each

pi equal to the theoretical value, based on genetics

H01:pppp==== 9 /16, 2 3 /16, 3 3 /16, 4 1/16

H ai:At least one p is not as specified in H0 Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

4 3/14/14

Mendel’s Pea Experiment Mendel’s Pea Experiment 2 • χ = 0.47 • Two options: p-value = 0.925 o Simulate a randomization distribution Does this prove Mendel’s theory of genetics? 2 o Compare to a χ distribution with 4 – 1 = 3 df Or at least prove that his theoretical proportions for pea phenotypes were correct?

a) Yes b) No

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Chi-Square Goodness of Fit ADHD or Just Young? — You just learned about a chi-square goodness of — In British Columbia, Canada, the cutoff date it test, which compares a single categorical for entering school in any year is December variable to null hypothesized proportions for 31st, so those born late in the year are younger each category: than those born early in the year 1. Find expected (if H0 true) counts for each cell: npi — Are children born late in the year (younger 2. Compute χ2 statistic to measure how far observed than their peers) more likely to be diagnosed 2 counts are from expected: observed expected 2 ( − ) with ADHD? χ = ∑ expected — Study on 937,943 children 6-12 years old in 3. Compare χ2 statistic to χ2 distribution with (df = # categories – 1) or randomization distribution to British Columbia Morrow, R., et. al., “Inluence of relative age on diagnosis and treatment of attention- ind upper-tailed p-value deicit/hyperactivity disorder in children,” Canadian Medical Association Journal, April 17, 2012; 184(7): 755-762. Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

ADHD or Just Young? (BOYS) ADHD or Just Young? (BOYS)

Birth Proportion Birth Date Proportion ADHD Expected Contribution of Births Diagnoses Counts to χ2 Date of Births Jan-Mar 0.244 6880 Jan-Mar 0.244 Apr-Jun 0.258 7982 Apr-Jun 0.258 Jul-Sep 0.257 9161 Jul-Sep 0.257 Oct-Dec 0.241 8945 Oct-Dec 0.241

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

5 3/14/14

ADHD or Just Young (Boys) ADHD or Just Young? (Girls)

— Want more practice? — Here is the data for girls. (χ2 = 236.8)

p-value ≈ 0 Birth Proportion ADHD Date of Births Diagnoses Jan-Mar 0.243 1960 Apr-Jun 0.258 2358 We have VERY (!!!) strong evidence that boys who are born later in the year, and Jul-Sep 0.257 2859 so are younger than their classmates, are Oct-Dec 0.242 2904 more likely to be diagnosed with ADHD. Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Review: Chi-Square Goodness of Fit Section 7.2 — In the last section, a chi-square goodness of it test, which compares a single categorical variable to null Testing for an hypothesized proportions for each category: Association between 1. Observed counts from data 2. Find expected (if H0 true) counts for each cell Two Categorical 3. Compute χ2 statistic to measure how far observed counts are from expected: 2 Variables observed expected 2 ( − ) χ = ∑ expected Kari Lock Morgan 4. Compare χ2 statistic to χ2 distribution to ind upper-tailed p-value

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Two Categorical Variables Award Preference & SAT • The statistics behind a χ2 test easily extends to two categorical variables The data in StudentSurvey includes two • A χ2 test for association (often called a χ2 test categorical variables: for independence) tests for an association Award = Academy, Nobel, or Olympic between two categorical variables HigherSAT = Math or Verbal • Everything is the same as a chi-square goodness-of-it test, except: Do you think there is a relationship • The hypotheses between the award preference and • The expected counts which SAT is higher? If so, in what way? • Degrees of freedom for the χ2-distribution

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

6 3/14/14

Award Preference & SAT Expected Counts row total × column total HigherSAT Academy Nobel Olympic Total Expected Count = n Math 21 68 116 205 Verbal 10 79 61 150 HigherSAT Academy Nobel Olympic Total Total 31 147 177 355 Math 21 68 116 205 Data are summarized with a 2×3 table for a sample of size n=355. Verbal 10 79 61 150 Total 31 147 177 355 H0 : Award preference is not associated with which SAT is higher

Ha : Award preference is associated with which SAT is higher

If H0 is true ⟹ The award distribution is expected to be the same in each row. Note: The expected counts maintain row and column totals, but redistribute the counts as if there were no association. Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Chi-Square Statistic Randomization Test www.lock5stat.com/statkey HigherSAT Academy Nobel Olympic Total Math 21 (17.9) 68 (84.9) 116 (102.2) 205 Verbal 10 (13.1) 79 (62.1) 61 ( 74.8) 150 Total 31 147 177 355

HigherSAT Academy Nobel Olympic Math Verbal

p-value=0.001 ⟹ Reject H 2 0 2 (observed - expected) χ = We have evidence that award preference is ∑ expected associated with which SAT score is higher. Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Chi-Square (χ2) Distribution Chi-Square Distribution • If each of the expected counts are at least 5, For Higher SAT vs. Award: df = (2 – 1)(3 – 1) = 2 AND if the null hypothesis is true, then the χ2 statistic follows a χ2 –distribution, with degrees of freedom equal to

df = (number of rows – 1)(number of columns – 1) We have evidence that award • Award by HigherSAT: preference is associated df = (2 – 1)(3 – 1) = 2 with which SAT score is higher.

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

7 3/14/14

Chi-Square Test for Association Chi-Square Test for Association

Note: The χ2-test for two categorical variables only 1. H0 : The two variables are not associated H : The two variables are associated indicates if the variables are associated. Look at the a contribution in each cell for the possible nature of 2. Calculate the expected counts for each cell: row total × column total the relationship. Expected Count = n 2 2 3. Calculate the χ statistic: 2 (observed - expected) χ = ∑ expected 4. Compute the p-value as the area in the tail above the χ2 statistic using either a randomization distribution, or a χ2 distribution with df = (r – 1) (c – 1) if all expected counts > 5 5. Interpret the p-value in context.

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Metal Tags and Penguins Metal Tags and Penguins

Are metal tags detrimental to penguins? A study 1. State Hypotheses looked at the 10 year survival rate of penguins tagged either with a metal tag or an electronic tag. 20% of the 167 metal tagged penguins H0: Type of tag and survival are not associated survived, compared to 36% of the 189 electronic tagged penguins. Ha: Type of tag and survival are associated

Is there an association between type of tag and survival?

Source: Saraux, et. al. (2011). “Reliability of lipper- banded penguins as indicators of climate change,” Nature, 469, 203-206. Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

Metal Tags and Penguins Metal Tags and Penguins

2. Create two-way table of observed counts 3. Calculate expected counts Tag\Survival Survived Died Total Tag\Survival Survived Died Total Metal Metal 167 Electronic Electronic 189 Total Total 101 255 356

row total × column total

20% of the 167 metal tagged penguins survived, compared n to 36% of the 189 electronic tagged penguins.

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

8 3/14/14

Metal Tags and Penguins Metal Tags and Penguins 4. Calculate chi-square statistic 5. Compute p-value and interpret in context. Survived Died Metal Tag 33 (47.4) 134 (119.6) Electronic Tag 68 (53.6) 121 (135.4) p-value = 0.0007 (using a χ2-distribution with 1 df) Survived Died Metal Tag Electronic Tag There is strong evidence of an association 2 between type of tag and survival of penguins, 2 (observed - expected) χ = ∑ expected with electronically tagged penguins having better survival than metal tagged. Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

2 x 2 Table Summary: Chi-Square Tests

— Note: because each of these variables only has — The χ2 goodness-of-it tests if one categorical two categories, we could have done this as a variable differs from a null distribution difference in proportions test — The χ2 test for association tests for an association between two categorical variables — We would have gotten the exact same p-value! — For both, you compute the expected counts in each — For two categorical variables with two cell (assuming H ) and the χ2 statistic: 0 2 categories each, can do either difference in 2 (observed - expected) χ = proportions or a chi-square test ∑ expected — Find the proportion above the χ2 statistic in a randomization or χ2-distribution (if all expected counts > 5)

Statistics: Unlocking the Power of Data Lock5 Statistics: Unlocking the Power of Data Lock5

9