Statistics: Unlocking the Power of Data Lock 5 Testing Goodness-of- Fit for a Single Categorical Variable Kari Lock Morgan Section 7.1.

Slides:



Advertisements
Similar presentations
Chi-Square Tests 3/14/12 Testing the distribution of a single categorical variable :  2 goodness of fit Testing for an association between two categorical.
Advertisements

Statistics: Unlocking the Power of Data Lock 5 STAT 101 Dr. Kari Lock Morgan 10/23/12 Sections , Single Proportion, p Distribution (6.1)
Multinomial Experiments Goodness of Fit Tests We have just seen an example of comparing two proportions. For that analysis, we used the normal distribution.
Chapter 11 Inference for Distributions of Categorical Data
Chapter 26: Comparing Counts
CHAPTER 11 Inference for Distributions of Categorical Data
11-2 Goodness-of-Fit In this section, we consider sample data consisting of observed frequency counts arranged in a single row or column (called a one-way.
Chapter 26: Comparing Counts. To analyze categorical data, we construct two-way tables and examine the counts of percents of the explanatory and response.
Inference for Categorical Variables 2/29/12 Single Proportion, p Distribution Intervals and tests Difference in proportions, p 1 – p 2 One proportion or.
1 Chapter 20 Two Categorical Variables: The Chi-Square Test.
ANOVA 3/19/12 Mini Review of simulation versus formulas and theoretical distributions Analysis of Variance (ANOVA) to compare means: testing for a difference.
Chapter 13 Chi-Square Tests. The chi-square test for Goodness of Fit allows us to determine whether a specified population distribution seems valid. The.
Copyright © Cengage Learning. All rights reserved. 11 Applications of Chi-Square.
Chapter 13: Inference for Tables – Chi-Square Procedures
11.4 Hardy-Wineberg Equilibrium. Equation - used to predict genotype frequencies in a population Predicted genotype frequencies are compared with Actual.
CHP400: Community Health Program - lI Research Methodology. Data analysis Hypothesis testing Statistical Inference test t-test and 22 Test of Significance.
Goodness-of-Fit Tests and Categorical Data Analysis
Copyright © 2010, 2007, 2004 Pearson Education, Inc. Chapter 26 Comparing Counts.
Analysis of two-way tables - Formulas and models for two-way tables - Goodness of fit IPS chapters 9.3 and 9.4 © 2006 W.H. Freeman and Company.
1 Desipramine is an antidepressant affecting the brain chemicals that may become unbalanced and cause depression. It was tested for recovery from cocaine.
Statistics: Unlocking the Power of Data Lock 5 STAT 101 Dr. Kari Lock Morgan 11/1/12 ANOVA SECTION 8.1 Testing for a difference in means across multiple.
Chi-Square as a Statistical Test Chi-square test: an inferential statistics technique designed to test for significant relationships between two variables.
Chapter 11: Inference for Distributions of Categorical Data.
Chapter 11: Inference for Distributions of Categorical Data
Chi-square test or c2 test
Multinomial Experiments Goodness of Fit Tests We have just seen an example of comparing two proportions. For that analysis, we used the normal distribution.
Chapter 26 Chi-Square Testing
The Practice of Statistics, 5th Edition Starnes, Tabor, Yates, Moore Bedford Freeman Worth Publishers CHAPTER 11 Inference for Distributions of Categorical.
Chapter 11: Inference for Distributions of Categorical Data Section 11.1 Chi-Square Goodness-of-Fit Tests.
Chi-Square Procedures Chi-Square Test for Goodness of Fit, Independence of Variables, and Homogeneity of Proportions.
1 Section 8.3 Testing a claim about a Proportion Objective For a population with proportion p, use a sample (with a sample proportion) to test a claim.
CHAPTER 11 SECTION 2 Inference for Relationships.
1 Chapter 8 Hypothesis Testing 8.2 Basics of Hypothesis Testing 8.3 Testing about a Proportion p 8.4 Testing about a Mean µ (σ known) 8.5 Testing about.
FPP 28 Chi-square test. More types of inference for nominal variables Nominal data is categorical with more than two categories Compare observed frequencies.
+ Chi Square Test Homogeneity or Independence( Association)
Testing for an Association between two Categorical Variables
BPS - 5th Ed. Chapter 221 Two Categorical Variables: The Chi-Square Test.
Analysis of two-way tables - Inference for two-way tables IPS chapter 9.2 © 2006 W.H. Freeman and Company.
Warm up On slide.
Comparing Counts.  A test of whether the distribution of counts in one categorical variable matches the distribution predicted by a model is called a.
Bayesian Inference, Review 4/25/12 Frequentist inference Bayesian inference Review The Bayesian Heresy (pdf)pdf Professor Kari Lock Morgan Duke University.
Statistics: Unlocking the Power of Data Lock 5 Exam 2 Review STAT 101 Dr. Kari Lock Morgan 11/13/12 Review of Chapters 5-9.
Statistics: Unlocking the Power of Data Lock 5 STAT 101 Dr. Kari Lock Morgan 10/30/12 Chi-Square Tests SECTIONS 7.1, 7.2 Testing the distribution of a.
Chapter Outline Goodness of Fit test Test of Independence.
The table shows a random sample of 100 hikers and the area of hiking preferred. Are hiking area preference and gender independent? Hiking Preference Area.
Statistics: Unlocking the Power of Data Lock 5 STAT 250 Dr. Kari Lock Morgan SECTION 7.1 Testing the distribution of a single categorical variable : χ.
+ Chapter 11 Inference for Distributions of Categorical Data 11.1Chi-Square Goodness-of-Fit Tests 11.2Inference for Relationships.
11.2 Tests Using Contingency Tables When data can be tabulated in table form in terms of frequencies, several types of hypotheses can be tested by using.
Copyright © 2013, 2009, and 2007, Pearson Education, Inc. Chapter 11 Analyzing the Association Between Categorical Variables Section 11.2 Testing Categorical.
Lecture 11. The chi-square test for goodness of fit.
Chapter 13- Inference For Tables: Chi-square Procedures Section Test for goodness of fit Section Inference for Two-Way tables Presented By:
1 1 Slide © 2008 Thomson South-Western. All Rights Reserved Chapter 12 Tests of Goodness of Fit and Independence n Goodness of Fit Test: A Multinomial.
Comparing Counts Chapter 26. Goodness-of-Fit A test of whether the distribution of counts in one categorical variable matches the distribution predicted.
BPS - 5th Ed. Chapter 221 Two Categorical Variables: The Chi-Square Test.
+ Section 11.1 Chi-Square Goodness-of-Fit Tests. + Introduction In the previous chapter, we discussed inference procedures for comparing the proportion.
Statistics: Unlocking the Power of Data Lock 5 STAT 250 Dr. Kari Lock Morgan SECTION 7.1 Testing the distribution of a single categorical variable : 
Statistics: Unlocking the Power of Data Lock 5 STAT 250 Dr. Kari Lock Morgan SECTION 7.2 χ 2 test for association (7.2) Testing for an Association between.
11.1 Chi-Square Tests for Goodness of Fit Objectives SWBAT: STATE appropriate hypotheses and COMPUTE expected counts for a chi- square test for goodness.
Statistics: Unlocking the Power of Data Lock 5 Section 6.8 Confidence Interval for a Difference in Proportions.
CHAPTER 11: INFERENCE FOR DISTRIBUTIONS OF CATEGORICAL DATA 11.1 CHI-SQUARE TESTS FOR GOODNESS OF FIT OUTCOME: I WILL STATE APPROPRIATE HYPOTHESES AND.
Chapter 11: Categorical Data n Chi-square goodness of fit test allows us to examine a single distribution of a categorical variable in a population. n.
The Chi-Square Distribution  Chi-square tests for ….. goodness of fit, and independence 1.
11/12 9. Inference for Two-Way Tables. Cocaine addiction Cocaine produces short-term feelings of physical and mental well being. To maintain the effect,
 Check the Random, Large Sample Size and Independent conditions before performing a chi-square test  Use a chi-square test for homogeneity to determine.
Chi Square Test of Homogeneity. Are the different types of M&M’s distributed the same across the different colors? PlainPeanutPeanut Butter Crispy Brown7447.
Chi-Square Goodness-of-Fit Test
Chapter 10 Analyzing the Association Between Categorical Variables
Inference for Relationships
Analyzing the Association Between Categorical Variables
Inference for Distributions of Categorical Data
Presentation transcript:

Statistics: Unlocking the Power of Data Lock 5 Testing Goodness-of- Fit for a Single Categorical Variable Kari Lock Morgan Section 7.1

Statistics: Unlocking the Power of Data Lock 5 Multiple Categories So far, we’ve learned how to do inference for categorical variables with only two categories Today, we’ll learn how to do hypothesis tests for categorical variables with multiple categories

Statistics: Unlocking the Power of Data Lock 5 Rock-Paper-Scissors (Roshambo)

Statistics: Unlocking the Power of Data Lock 5 Rock-Paper-Scissors ROCKPAPERSCISSORS How would we test whether all of these categories are equally likely?

Statistics: Unlocking the Power of Data Lock 5 Hypothesis Testing 1.State Hypotheses 2.Calculate a statistic, based on your sample data 3.Create a distribution of this statistic, as it would be observed if the null hypothesis were true 4.Measure how extreme your test statistic from (2) is, as compared to the distribution generated in (3) test statistic

Statistics: Unlocking the Power of Data Lock 5 Hypotheses Let p i denote the proportion in the i th category. H 0 : All p i s are the same H a : At least one p i differs from the others OR H 0 : Every p i = 1/3 H a : At least one p i ≠ 1/3

Statistics: Unlocking the Power of Data Lock 5 Test Statistic Why can’t we use the familiar formula to get the test statistic? More than one sample statistic More than one null value We need something a bit more complicated…

Statistics: Unlocking the Power of Data Lock 5 Observed Counts The observed counts are the actual counts observed in the study ROCKPAPERSCISSORS Observed663914

Statistics: Unlocking the Power of Data Lock 5 Expected Counts The expected counts are the expected counts if the null hypothesis were true For each cell, the expected count is the sample size (n) times the null proportion, p i

Statistics: Unlocking the Power of Data Lock 5 Rock-Paper-Scissors ROCKPAPERSCISSORS Observed Expected

Statistics: Unlocking the Power of Data Lock 5 Chi-Square Statistic A test statistic is one number, computed from the data, which we can use to assess the null hypothesis The chi-square statistic is a test statistic for categorical variables:

Statistics: Unlocking the Power of Data Lock 5 Rock-Paper-Scissors ROCKPAPERSCISSORS Observed Expected39.7

Statistics: Unlocking the Power of Data Lock 5 What Next? We have a test statistic. What else do we need to perform the hypothesis test? A distribution of the test statistic assuming H 0 is true How do we get this? Two options: 1)Simulation 2)Distributional Theory

Statistics: Unlocking the Power of Data Lock 5 Upper-Tail p-value To calculate the p-value for a chi-square test, we always look in the upper tail Why?  Values of the χ 2 are always positive  The higher the χ 2 statistic is, the farther the observed counts are from the expected counts, and the stronger the evidence against the null

Statistics: Unlocking the Power of Data Lock 5 Simulation

Statistics: Unlocking the Power of Data Lock 5 Chi-Square (χ 2 ) Distribution 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 Lock 5 Chi-Square Distribution

Statistics: Unlocking the Power of Data Lock 5 p-value using χ 2 distribution

Statistics: Unlocking the Power of Data Lock 5 Goodness of Fit A chi-square test for goodness of fit tests whether the distribution of a categorical variable is the same as some null hypothesized distribution The null hypothesized proportions for each category do not have to be the same

Statistics: Unlocking the Power of Data Lock 5 Chi-Square Test for Goodness of Fit 1.State null hypothesized proportions for each category, p i. Alternative is that at least one of the proportions is different than specified in the null. 2.Calculate the expected counts for each cell as np i. 3.Calculate the χ 2 statistic: 4.Compute the p-value as the proportion above the χ 2 statistic for either a randomization distribution or a χ 2 distribution with df = (# of categories – 1) if expected counts all > 5 5.Interpret the p-value in context.

Statistics: Unlocking the Power of Data Lock 5 Mendel’s Pea Experiment Source: Mendel, Gregor. (1866). Versuche über Pflanzen-Hybriden. Verh. Naturforsch. Ver. Brünn 4: 3–47 (in English in 1901, Experiments in Plant Hybridization, J. R. Hortic. Soc. 26: 1–32) In 1866, Gregor Mendel, the “father of genetics” published the results of his experiments on peas He found that his experimental distribution of peas closely matched the theoretical distribution predicted by his theory of genetics (involving alleles, and dominant and recessive genes)

Statistics: Unlocking the Power of Data Lock 5 Mendel’s Pea Experiment Mate SSYY with ssyy:  1 st Generation: all Ss Yy Mate 1 st Generation: => 2 nd Generation  Second Generation S, Y: Dominant s, y: Recessive PhenotypeTheoretical Proportion Round, Yellow9/16 Round, Green3/16 Wrinkled, Yellow3/16 Wrinkled, Green1/16

Statistics: Unlocking the Power of Data Lock 5 Mendel’s Pea Experiment PhenotypeTheoretical Proportion Observed Counts Round, Yellow9/16315 Round, Green3/16101 Wrinkled, Yellow3/16108 Wrinkled, Green1/1632 Let’s test this data against the null hypothesis of each p i equal to the theoretical value, based on genetics

Statistics: Unlocking the Power of Data Lock 5 Mendel’s Pea Experiment PhenotypeNull p i Observed Counts Expected Counts Round, Yellow 9/16315 Round, Green 3/16101 Wrinkled, Yellow 3/16108 Wrinkled, Green 1/1632

Statistics: Unlocking the Power of Data Lock 5 Mendel’s Pea Experiment χ 2 = 0.47 Two options: o Simulate a randomization distribution o Compare to a χ 2 distribution with 4 – 1 = 3 df

Statistics: Unlocking the Power of Data Lock 5 Mendel’s Pea Experiment p-value = Does this prove Mendel’s theory of genetics? Or at least prove that his theoretical proportions for pea phenotypes were correct? a)Yes b)No

Statistics: Unlocking the Power of Data Lock 5 Chi-Square Goodness of Fit You just learned about a chi-square goodness of fit test, which compares a single categorical variable to null hypothesized proportions for each category: 1. Find expected (if H 0 true) counts for each cell: np i 2. Compute χ 2 statistic to measure how far observed counts are from expected: 3. Compare χ 2 statistic to χ 2 distribution with (df = # categories – 1) or randomization distribution to find upper-tailed p-value

Statistics: Unlocking the Power of Data Lock 5 ADHD or Just Young? In British Columbia, Canada, the cutoff date for entering school in any year is December 31 st, so those born late in the year are younger than those born early in the year Are children born late in the year (younger than their peers) more likely to be diagnosed with ADHD? Study on 937,943 children 6-12 years old in British Columbia Morrow, R., et. al., “Influence of relative age on diagnosis and treatment of attention- deficit/hyperactivity disorder in children,” Canadian Medical Association Journal, April 17, 2012; 184(7):

Statistics: Unlocking the Power of Data Lock 5 ADHD or Just Young? (BOYS) Birth Date Proportion of Births Jan-Mar0.244 Apr-Jun0.258 Jul-Sep0.257 Oct-Dec0.241

Statistics: Unlocking the Power of Data Lock 5 ADHD or Just Young? (BOYS) Birth DateProportion of Births ADHD Diagnoses Expected Counts Contribution to χ 2 Jan-Mar Apr-Jun Jul-Sep Oct-Dec

Statistics: Unlocking the Power of Data Lock 5 ADHD or Just Young (Boys) We have VERY (!!!) strong evidence that boys who are born later in the year, and so are younger than their classmates, are more likely to be diagnosed with ADHD. p-value ≈ 0

Statistics: Unlocking the Power of Data Lock 5 ADHD or Just Young? (Girls) Birth Date Proportion of Births ADHD Diagnoses Jan-Mar Apr-Jun Jul-Sep Oct-Dec Want more practice? Here is the data for girls. (χ 2 = 236.8)

Statistics: Unlocking the Power of Data Lock 5 Testing for an Association between Two Categorical Variables Kari Lock Morgan Section 7.2

Statistics: Unlocking the Power of Data Lock 5 Review: Chi-Square Goodness of Fit In the last section, a chi-square goodness of fit test, which compares a single categorical variable to null hypothesized proportions for each category: 1. Observed counts from data 2. Find expected (if H 0 true) counts for each cell 3. Compute χ 2 statistic to measure how far observed counts are from expected: 1. Compare χ 2 statistic to χ 2 distribution to find upper-tailed p-value

Statistics: Unlocking the Power of Data Lock 5 Two Categorical Variables The statistics behind a χ 2 test easily extends to two categorical variables A χ 2 test for association (often called a χ 2 test for independence) tests for an association between two categorical variables Everything is the same as a chi-square goodness-of-fit test, except: The hypotheses The expected counts Degrees of freedom for the χ 2 -distribution

Statistics: Unlocking the Power of Data Lock 5 Award Preference & SAT The data in StudentSurvey includes two categorical variables: Award = Academy, Nobel, or Olympic HigherSAT = Math or Verbal Do you think there is a relationship between the award preference and which SAT is higher? If so, in what way?

Statistics: Unlocking the Power of Data Lock 5 Award Preference & SAT HigherSATAcademyNobelOlympicTotal Math Verbal Total H 0 : Award preference is not associated with which SAT is higher H a : Award preference is associated with which SAT is higher Data are summarized with a 2×3 table for a sample of size n=355. If H 0 is true ⟹ The award distribution is expected to be the same in each row.

Statistics: Unlocking the Power of Data Lock 5 Expected Counts HigherSATAcademyNobelOlympicTotal Math Verbal Total Note: The expected counts maintain row and column totals, but redistribute the counts as if there were no association. HigherSATAcademyNobelOlympicTotal Math205 Verbal150 Total

Statistics: Unlocking the Power of Data Lock 5 Chi-Square Statistic HigherSATAcademyNobelOlympicTotal Math21 (17.9)68 (84.9)116 (102.2)205 Verbal10 (13.1)79 (62.1) 61 ( 74.8)150 Total HigherSATAcademyNobelOlympic Math Verbal

Statistics: Unlocking the Power of Data Lock 5 Randomization Test p-value=0.001 ⟹ Reject H 0 We have evidence that award preference is associated with which SAT score is higher.

Statistics: Unlocking the Power of Data Lock 5 Chi-Square (χ 2 ) Distribution 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 rows – 1)(number of columns – 1) Award by HigherSAT: df = (2 – 1)(3 – 1) = 2

Statistics: Unlocking the Power of Data Lock 5 Chi-Square Distribution For Higher SAT vs. Award: df = (2 – 1)(3 – 1) = 2 We have evidence that award preference is associated with which SAT score is higher.

Statistics: Unlocking the Power of Data Lock 5 Chi-Square Test for Association Note: The χ 2 -test for two categorical variables only indicates if the variables are associated. Look at the contribution in each cell for the possible nature of the relationship.

Statistics: Unlocking the Power of Data Lock 5 Chi-Square Test for Association 1.H 0 : The two variables are not associated H a : The two variables are associated 2.Calculate the expected counts for each cell: 3.Calculate the χ 2 statistic: 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 Lock 5 Metal Tags and Penguins Is there an association between type of tag and survival? Source: Saraux, et. al. (2011). “Reliability of flipper- banded penguins as indicators of climate change,” Nature, 469, Are metal tags detrimental to penguins? A study 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 survived, compared to 36% of the 189 electronic tagged penguins.

Statistics: Unlocking the Power of Data Lock 5 Metal Tags and Penguins 1. State Hypotheses H 0 : Type of tag and survival are not associated H a : Type of tag and survival are associated

Statistics: Unlocking the Power of Data Lock 5 Metal Tags and Penguins 2. Create two-way table of observed counts 20% of the 167 metal tagged penguins survived, compared to 36% of the 189 electronic tagged penguins. Tag\SurvivalSurvivedDiedTotal Metal Electronic Total

Statistics: Unlocking the Power of Data Lock 5 Metal Tags and Penguins 3. Calculate expected counts Tag\SurvivalSurvivedDiedTotal Metal 167 Electronic 189 Total

Statistics: Unlocking the Power of Data Lock 5 Metal Tags and Penguins 4. Calculate chi-square statistic SurvivedDied Metal Tag33 (47.4)134 (119.6) Electronic Tag68 (53.6)121 (135.4) SurvivedDied Metal Tag Electronic Tag

Statistics: Unlocking the Power of Data Lock 5 Metal Tags and Penguins 5. Compute p-value and interpret in context. p-value = (using a χ 2 -distribution with 1 df) There is strong evidence of an association between type of tag and survival of penguins, with electronically tagged penguins having better survival than metal tagged.

Statistics: Unlocking the Power of Data Lock 5 2 x 2 Table Note: because each of these variables only has two categories, we could have done this as a difference in proportions test We would have gotten the exact same p-value! For two categorical variables with two categories each, can do either difference in proportions or a chi-square test

Statistics: Unlocking the Power of Data Lock 5 Summary: Chi-Square Tests The χ 2 goodness-of-fit tests if one categorical variable differs from a null distribution The χ 2 test for association tests for an association between two categorical variables For both, you compute the expected counts in each cell (assuming H 0 ) and the χ 2 statistic: Find the proportion above the χ 2 statistic in a randomization or χ 2 -distribution (if all expected counts > 5)