Goodness of fit test
Chi-square goodness of fit test
The chi-square goodness of fit test checks whether a sample of categorical data is consistent with a claimed (theoretical) distribution. In other words, it helps you judge whether the differences between the observed counts and the expected counts are small enough to be explained by random sampling variation.
A perfect match between sample data and a theoretical distribution is unlikely. The real question is whether the mismatch you see is reasonable if the claimed distribution is true.
Conditions for inference
- Random sample: Data should come from a random sample or randomized experiment.
- Independence: Each observation should be independent (if sampling without replacement, sample size of population).
- Sample size: All expected frequencies must be at least ( for all categories).
How the test works
The test asks: If the claimed distribution is correct, how likely is it to see discrepancies at least as large as the ones in our sample?
- If that chance (the p-value) is large, the discrepancies are plausible under . You fail to reject .
- If that chance is small, the discrepancies are unlikely under . You reject and conclude the claimed distribution is not a good fit for the population.
How large is “large” for ?
A value is considered “large” when it falls far out in the right tail of the appropriate chi-square distribution (which depends on the degrees of freedom). That’s exactly what the p-value measures. To see why, it helps to know the basic shape of the chi-square distribution.
Practice problem
Example:
Candy World company claims that its premium chocolate mix is made up of the following percentages by weight:
- caramel delights
- almond clusters
- coconut dreams
- mint swirls
- pecan turtles
A customer purchases a bag, sorts the contents, and finds that in her bag she received:
- grams of caramel delights
- grams of almond clusters
- grams of coconut dreams
- grams of mint swirls
- grams of pecan turtles
Part a.
State the hypotheses for a chi-square goodness of fit test if the goal is to determine if the customer’s bag differs significantly from the company’s claim.
Solution:
Null hypothesis (): The distribution of the candy types in the bag matches that of the company’s claimed distribution.
Alternative hypothesis (): The distribution of the candy types in the bag does not match the company’s claimed distribution.
Part b.
Calculate the expected frequencies.
First, find the total weight of the candies in the bag:
To find each expected frequency, multiply each claimed proportion by the total weight:
Solution:
Part c.
Calculate the chi-square test statistic ().
Use the formula:
Substitute the observed and expected values:
Solution:
Part d.
Determine the degrees of freedom and find the p-value.
The number of categories is .
Compute the degrees of freedom:
The p-value is the right-tail probability:
Solution:
Part e.
Using a significance level , what is your conclusion about the company’s claim in the context of the problem?
Compare the p-value to :
Solution:
Since the p-value is greater than , we fail to reject the null hypothesis.
Conclusion (in context): There is not sufficient evidence to suggest that the bag’s composition differs from the company’s claim.
Part f.
What type of error might have been made and what would the potential consequences of that error be in context?
Solution:
Because we failed to reject , the possible error is a Type II error, which involves failing to detect a real difference when the true mix proportions differ from the claim.
If a Type II error occurred, Candy World’s chocolates might not actually match the advertised percentages, but our test did not identify this. Consumers may be misled about the product composition.