Achievable logoAchievable logo
AP Statistics
Sign in
Sign up
Purchase
Textbook
Practice exams
Support
How it works
Resources
Exam catalog
Mountain with a flag at the peak
Textbook
Introduction
1. One variable data
2. Two variable data
3. Data collection
4. Probability and random variables
5. Sampling distributions
6. Categorical data
7. Quantitative data
8. Chi-square
8.1 Goodness of fit test
8.2 Independence test
8.3 Homogeneity test
9. Linear regression
Wrapping up
Achievable logoAchievable logo
8.1 Goodness of fit test
Achievable AP Statistics
8. Chi-square
Our AP Statistics course is currently in development and is a work-in-progress.

Goodness of fit test

6 min read
Font
Discuss
Share
Feedback

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.

Definitions
Chi-square goodness of fit test
A hypothesis test that compares observed counts in each category of a categorical variable to the counts you would expect if a claimed distribution were true.
Observed frequencies (Oi​)
The counts (or amounts) you actually see in your sample.
Expected frequencies (Ei​)
The counts you would expect if the null hypothesis were true.

Hypotheses:

The null hypothesis H0​ for a chi-square goodness of fit test is that the given theoretical distribution does accurately represent the data of the overall population.

The alternate hypothesis Ha​ for a chi-square goodness of fit test is that the given theoretical distribution does not accurately represent the data of the overall population.

Conditions for inference

  1. Random sample: Data should come from a random sample or randomized experiment.
  2. Independence: Each observation should be independent (if sampling without replacement, sample size <10% of population).
  3. Sample size: All expected frequencies must be at least 5 (Ei​≥5 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 H0​. You fail to reject H0​.
  • If that chance is small, the discrepancies are unlikely under H0​. You reject H0​ and conclude the claimed distribution is not a good fit for the population.
Definitions
Chi-square test statistic (χ2)
A measure of how far the observed counts are from the expected counts. The smaller the χ2 value, the better the fit.

χ2​=∑Ei​(Oi​−Ei​)2​​

p-value
The probability of obtaining a χ2 value as extreme as (or more extreme than) the one obtained, assuming the null hypothesis is true.

How large is “large” for χ2?

A χ2 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.

Definitions
Chi-square (χ2) distribution
A probability distribution that is right-skewed and takes only non-negative values. There is a different chi-square distribution for each number of degrees of freedom — the larger the degrees of freedom, the less skewed the distribution becomes, and the closer it is to a normal distribution.
Degrees of freedom (df)
A value that determines which specific chi-square distribution applies.

df​=(number of categories)−1​

Practice problem

Example:

Candy World company claims that its premium chocolate mix is made up of the following percentages by weight:

  • 30% caramel delights
  • 25% almond clusters
  • 20% coconut dreams
  • 15% mint swirls
  • 10% pecan turtles

A customer purchases a bag, sorts the contents, and finds that in her bag she received:

  • 170 grams of caramel delights
  • 110 grams of almond clusters
  • 90 grams of coconut dreams
  • 80 grams of mint swirls
  • 50 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:

(spoiler)

Null hypothesis (H0​): The distribution of the candy types in the bag matches that of the company’s claimed distribution.

Alternative hypothesis (Ha​): 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:

Total weight​=170+110+90+80+50=500 grams​

To find each expected frequency, multiply each claimed proportion by the total weight:

Ei​​=pi​×Total weight​

Solution:

(spoiler)

Caramel delights:Almond clusters:Coconut dreams:Mint swirls:Pecan turtles:​0.30×500=150 g (observed: 170)0.25×500=125 g (observed: 110)0.20×500=100 g (observed: 90)0.15×500=75 g (observed: 80)0.10×500=50 g (observed: 50)​

Part c.

Calculate the chi-square test statistic (χ2).

Use the formula:

χ2​=∑E(O−E)2​​

Substitute the observed and expected values:

χ2​=150(170−150)2​+125(110−125)2​+100(90−100)2​+75(80−75)2​+50(50−50)2​=150400​+125225​+100100​+7525​+0=2.667+1.800+1.000+0.333+0​

Solution:

(spoiler)

χ2​≈5.8​

Part d.

Determine the degrees of freedom and find the p-value.

The number of categories is k=5.

Compute the degrees of freedom:

df​=k−1=5−1​

The p-value is the right-tail probability:

p​=P(χdf2​≥5.8)​

Solution:

(spoiler)

dfp​=4≈0.215​

Part e.

Using a significance level α=0.05, what is your conclusion about the company’s claim in the context of the problem?

Compare the p-value to α:

0.215​>0.05​

Solution:

(spoiler)

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:

(spoiler)

Because we failed to reject H0​, 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.

Chi-square goodness of fit test: Purpose and hypotheses

  • Tests if observed categorical data matches a claimed (theoretical) distribution
  • Null hypothesis (H0​): sample matches claimed distribution
  • Alternative hypothesis (Ha​): sample does not match claimed distribution

Conditions for inference

  • Data from a random sample or randomized experiment
  • Observations are independent
    • If sampling without replacement: sample size <10% of population
  • All expected frequencies Ei​≥5

Test procedure and interpretation

  • Compare observed frequencies (Oi​) to expected frequencies (Ei​)
  • Test statistic: χ2=∑Ei​(Oi​−Ei​)2​
  • Large p-value: discrepancies are plausible under H0​ (fail to reject H0​)
  • Small p-value: discrepancies unlikely under H0​ (reject H0​)

Chi-square distribution and degrees of freedom

  • Right-skewed, non-negative values
  • Shape depends on degrees of freedom ($df = $ number of categories −1)
  • More degrees of freedom: distribution less skewed, closer to normal

Example application steps

  • State hypotheses about distribution matching claim
  • Calculate expected frequencies: claimed proportion × total sample size
  • Compute χ2 statistic using observed and expected values
  • Find degrees of freedom (df=k−1)
  • Determine p-value and compare to significance level (α)
  • Draw conclusion: reject or fail to reject H0​

Errors and consequences

  • Type II error possible if failing to reject H0​ when a real difference exists
    • Consequence: failing to detect a mismatch between actual and claimed distributions

Sign up for free to take 7 quiz questions on this topic

Previous
Next  | 8.2 Independence test
All rights reserved ©2016 - 2026 Achievable, Inc.

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.

Definitions
Chi-square goodness of fit test
A hypothesis test that compares observed counts in each category of a categorical variable to the counts you would expect if a claimed distribution were true.
Observed frequencies (Oi​)
The counts (or amounts) you actually see in your sample.
Expected frequencies (Ei​)
The counts you would expect if the null hypothesis were true.

Hypotheses:

The null hypothesis H0​ for a chi-square goodness of fit test is that the given theoretical distribution does accurately represent the data of the overall population.

The alternate hypothesis Ha​ for a chi-square goodness of fit test is that the given theoretical distribution does not accurately represent the data of the overall population.

Conditions for inference

  1. Random sample: Data should come from a random sample or randomized experiment.
  2. Independence: Each observation should be independent (if sampling without replacement, sample size <10% of population).
  3. Sample size: All expected frequencies must be at least 5 (Ei​≥5 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 H0​. You fail to reject H0​.
  • If that chance is small, the discrepancies are unlikely under H0​. You reject H0​ and conclude the claimed distribution is not a good fit for the population.
Definitions
Chi-square test statistic (χ2)
A measure of how far the observed counts are from the expected counts. The smaller the χ2 value, the better the fit.

χ2​=∑Ei​(Oi​−Ei​)2​​

p-value
The probability of obtaining a χ2 value as extreme as (or more extreme than) the one obtained, assuming the null hypothesis is true.

How large is “large” for χ2?

A χ2 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.

Definitions
Chi-square (χ2) distribution
A probability distribution that is right-skewed and takes only non-negative values. There is a different chi-square distribution for each number of degrees of freedom — the larger the degrees of freedom, the less skewed the distribution becomes, and the closer it is to a normal distribution.
Degrees of freedom (df)
A value that determines which specific chi-square distribution applies.

df​=(number of categories)−1​

Practice problem

Example:

Candy World company claims that its premium chocolate mix is made up of the following percentages by weight:

  • 30% caramel delights
  • 25% almond clusters
  • 20% coconut dreams
  • 15% mint swirls
  • 10% pecan turtles

A customer purchases a bag, sorts the contents, and finds that in her bag she received:

  • 170 grams of caramel delights
  • 110 grams of almond clusters
  • 90 grams of coconut dreams
  • 80 grams of mint swirls
  • 50 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:

(spoiler)

Null hypothesis (H0​): The distribution of the candy types in the bag matches that of the company’s claimed distribution.

Alternative hypothesis (Ha​): 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:

Total weight​=170+110+90+80+50=500 grams​

To find each expected frequency, multiply each claimed proportion by the total weight:

Ei​​=pi​×Total weight​

Solution:

(spoiler)

Caramel delights:Almond clusters:Coconut dreams:Mint swirls:Pecan turtles:​0.30×500=150 g (observed: 170)0.25×500=125 g (observed: 110)0.20×500=100 g (observed: 90)0.15×500=75 g (observed: 80)0.10×500=50 g (observed: 50)​

Part c.

Calculate the chi-square test statistic (χ2).

Use the formula:

χ2​=∑E(O−E)2​​

Substitute the observed and expected values:

χ2​=150(170−150)2​+125(110−125)2​+100(90−100)2​+75(80−75)2​+50(50−50)2​=150400​+125225​+100100​+7525​+0=2.667+1.800+1.000+0.333+0​

Solution:

(spoiler)

χ2​≈5.8​

Part d.

Determine the degrees of freedom and find the p-value.

The number of categories is k=5.

Compute the degrees of freedom:

df​=k−1=5−1​

The p-value is the right-tail probability:

p​=P(χdf2​≥5.8)​

Solution:

(spoiler)

dfp​=4≈0.215​

Part e.

Using a significance level α=0.05, what is your conclusion about the company’s claim in the context of the problem?

Compare the p-value to α:

0.215​>0.05​

Solution:

(spoiler)

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:

(spoiler)

Because we failed to reject H0​, 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.

Key points

Chi-square goodness of fit test: Purpose and hypotheses

  • Tests if observed categorical data matches a claimed (theoretical) distribution
  • Null hypothesis (H0​): sample matches claimed distribution
  • Alternative hypothesis (Ha​): sample does not match claimed distribution

Conditions for inference

  • Data from a random sample or randomized experiment
  • Observations are independent
    • If sampling without replacement: sample size <10% of population
  • All expected frequencies Ei​≥5

Test procedure and interpretation

  • Compare observed frequencies (Oi​) to expected frequencies (Ei​)
  • Test statistic: χ2=∑Ei​(Oi​−Ei​)2​
  • Large p-value: discrepancies are plausible under H0​ (fail to reject H0​)
  • Small p-value: discrepancies unlikely under H0​ (reject H0​)

Chi-square distribution and degrees of freedom

  • Right-skewed, non-negative values
  • Shape depends on degrees of freedom ($df = $ number of categories −1)
  • More degrees of freedom: distribution less skewed, closer to normal

Example application steps

  • State hypotheses about distribution matching claim
  • Calculate expected frequencies: claimed proportion × total sample size
  • Compute χ2 statistic using observed and expected values
  • Find degrees of freedom (df=k−1)
  • Determine p-value and compare to significance level (α)
  • Draw conclusion: reject or fail to reject H0​

Errors and consequences

  • Type II error possible if failing to reject H0​ when a real difference exists
    • Consequence: failing to detect a mismatch between actual and claimed distributions

More from Chi-square

  • Independence test
  • Homogeneity test