+254 786 524680

Chi-Square Goodness of Fit Test | Formula, Guide & Examples

Chi-Square Goodness of Fit Test | Formula, Guide & Examples

chi-square (Χ2) goodness of fit test is a type of Pearson’s chi-square test. You can use it to test whether the observed distribution of a categorical variable differs from your expectations.

Example: Chi-square goodness of fit test

You’re hired by a dog food company to help them test three new dog food flavors.You recruit a random sample of 75 dogs and offer each dog a choice between the three flavors by placing bowls in front of them. You expect that the flavors will be equally popular among the dogs, with about 25 dogs choosing each flavor.

Once you have your experimental results, you plan to use a chi-square goodness of fit test to figure out whether the distribution of the dogs’ flavor choices is significantly different from your expectations.

The chi-square goodness of fit test tells you how well a statistical model fits a set of observations. It’s often used to analyze genetic crosses.

What is the chi-square goodness of fit test?

A chi-square (Χ2) goodness of fit test is a goodness of fit test for a categorical variable. Goodness of fit is a measure of how well a statistical model fits a set of observations.

  • When goodness of fit is high, the values expected based on the model are close to the observed values.
  • When goodness of fit is low, the values expected based on the model are far from the observed values.

The statistical models that are analyzed by chi-square goodness of fit tests are distributions. They can be any distribution, from as simple as equal probability for all groups, to as complex as a probability distribution with many parameters.

Hypothesis testing

The chi-square goodness of fit test is a hypothesis test. It allows you to draw conclusions about the distribution of a population based on a sample. Using the chi-square goodness of fit test, you can test whether the goodness of fit is “good enough” to conclude that the population follows the distribution.

With the chi-square goodness of fit test, you can ask questions such as: Was this sample drawn from a population that has…

  • Equal proportions of male and female turtles?
  • Equal proportions of red, blue, yellow, green, and purple jelly beans?
  • 90% right-handed and 10% left-handed people?
  • Offspring with an equal probability of inheriting all possible genotypic combinations (i.e., unlinked genes)?
  • A Poisson distribution of floods per year?
  • A normal distribution of bread prices?
Example: Observed and expected frequencies

After weeks of hard work, your dog food experiment is complete and you compile your data in a table: 

Observed and expected frequencies of dogs’ flavor choices
FlavorObservedExpected
Garlic Blast2225
Blueberry Delight3025
Minty Munch2325

To help visualize the differences between your observed and expected frequencies, you also create a bar graph:

The president of the dog food company looks at your graph and declares that they should eliminate the Garlic Blast and Minty Munch flavors to focus on Blueberry Delight. “Not so fast!” you tell him.

You explain that your observations were a bit different from what you expected, but the differences aren’t dramatic. They could be the result of a real flavor preference or they could be due to chance.

To put it another way: You have a sample of 75 dogs, but what you really want to understand is the population of all dogs. Was this sample drawn from a population of dogs that choose the three flavors equally often?

Chi-square goodness of fit test hypotheses

Like all hypothesis tests, a chi-square goodness of fit test evaluates two hypotheses: the null and alternative hypotheses. They’re two competing answers to the question “Was the sample drawn from a population that follows the specified distribution?”

  • Null hypothesis (H0): The population follows the specified distribution.
  • Alternative hypothesis (Ha):  The population does not follow the specified distribution.

These are general hypotheses that apply to all chi-square goodness of fit tests. You should make your hypotheses more specific by describing the “specified distribution.” You can name the probability distribution (e.g., Poisson distribution) or give the expected proportions of each group.

Example: Null and alternative hypothesis
  • Null hypothesis (H0): The dog population chooses the three flavors in equal proportions (p1 = p2 = p3).
  • Alternative hypothesis (Ha): The dog population does not choose the three flavors in equal proportions.

When to use the chi-square goodness of fit test

The following conditions are necessary if you want to perform a chi-square goodness of fit test:

  1. You want to test a hypothesis about the distribution of one categorical variable. If your variable is continuous, you can convert it to a categorical variable by separating the observations into intervals. This process is known as data binning.
  2. The sample was randomly selected from the population.
  3. There are a minimum of five observations expected in each group.
Example: Chi-square goodness of fit test conditions

You can use a chi-square goodness of fit test to analyze the dog food data because all three conditions have been met:

  1. You want to test a hypothesis about the distribution of one categorical variable. The categorical variable is the dog food flavors.
  2. You recruited a random sample of 75 dogs.
  3. There were a minimum of five observations expected in each group. For all three dog food flavors, you expected 25 observations of dogs choosing the flavor.

How to calculate the test statistic (formula)

The test statistic for the chi-square (Χ2) goodness of fit test is Pearson’s chi-square:

FormulaExplanation
X^2 = \sum{\dfrac{(O-E)^2}{E}
  • Χ^2 is the chi-square test statistic
  • \sum is the summation operator (it means “take the sum of”)
  • O is the observed frequency
  • E is the expected frequency

The larger the difference between the observations and the expectations (O − in the equation), the bigger the chi-square will be.

To use the formula, follow these five steps:

Step 1: Create a table

Create a table with the observed and expected frequencies in two columns.

Example: Step 1
FlavorObservedExpected
Garlic Blast2225
Blueberry Delight3025
Minty Munch2325

Step 2: Calculate  E

Add a new column called “− E”. Subtract the expected frequencies from the observed frequency.

Example: Step 2
FlavorObservedExpectedO − E
Garlic Blast222522  25 = 3
Blueberry Delight30255
Minty Munch23252

Step 3: Calculate ( E)2

Add a new column called “(− E)2”. Square the values in the previous column.

Example: Step 3
FlavorObservedExpectedO − E( E)2
Garlic Blast22253(3)2 = 9
Blueberry Delight3025525
Minty Munch232524

Step 4: Calculate ( E)2 / E

Add a final column called “(O − E)² / E“. Divide the previous column by the expected frequencies.

Example: Step 4
FlavorObservedExpectedO − E( E)2(O − E)² / E
Garlic Blast2225399/25 = 0.36
Blueberry Delight30255251
Minty Munch2325240.16

Step 5: Calculate Χ2

Add up the values of the previous column. This is the chi-square test statistic (Χ2).

Example: Step 5
FlavorObservedExpectedO − E( E)2( E)E
Garlic Blast2225399/25 = 0.36
Blueberry Delight30255251
Minty Munch2325240.16

Χ2 = 0.36 + 1 + 0.16 = 1.52

We are a Team of Qualified Researchers and Data Analysts. Lets Help you with Data Analysis & Result Interpretation for your Project, Thesis or Dissertation?

We are Experts in SPSS, EVIEWS, AMOS, STATA, R, and Python

How to perform the chi-square goodness of fit test

The chi-square statistic is a measure of goodness of fit, but on its own it doesn’t tell you much. For example, is Χ2 = 1.52 a low or high goodness of fit?

To interpret the chi-square goodness of fit, you need to compare it to something. That’s what a chi-square test is: comparing the chi-square value to the appropriate chi-square distribution to decide whether to reject the null hypothesis.

To perform a chi-square goodness of fit test, follow these five steps (the first two steps have already been completed for the dog food example):

Step 1: Calculate the expected frequencies

Sometimes, calculating the expected frequencies is the most difficult step. Think carefully about which expected values are most appropriate for your null hypothesis.

In general, you’ll need to multiply each group’s expected proportion by the total number of observations to get the expected frequencies.

Step 2: Calculate chi-square

Calculate the chi-square value from your observed and expected frequencies using the chi-square formula.

  \begin{equation*}X^2 = \sum{\dfrac{(O-E)^2}{E}}\end{equation*}

Step 3: Find the critical chi-square value

Find the critical chi-square value in a chi-square critical value table or using statistical software. The critical value is calculated from a chi-square distribution. To find the critical chi-square value, you’ll need to know two things:

  • The degrees of freedom (df): For chi-square goodness of fit tests, the df is the number of groups minus one.
  • Significance level (α): By convention, the significance level is usually .05.
Example: Finding the critical chi-square value

Since there are three groups (Garlic Blast, Blueberry Delight, and Minty Munch), there are two degrees of freedom. 

For a test of significance at α = .05 and df = 2, the Χ2 critical value is 5.99.

Step 4: Compare the chi-square value to the critical value

Compare the chi-square value to the critical value to determine which is larger.

Example: Comparing the chi-square value to the critical value

Χ2 = 1.52 

Critical value = 5.99

The Χ2 value is less than the critical value

Step 5: Decide whether the reject the null hypothesis

  • If the Χ2 value is greater than the critical value, then the difference between the observed and expected distributions is statistically significant (p <  α).
    • The data allows you to reject the null hypothesis and provides support for the alternative hypothesis.
  • If the Χ2 value is less than the critical value, then the difference between the observed and expected distributions is not statistically significant (p >  α).
    • The data doesn’t allow you to reject the null hypothesis and doesn’t provide support for the alternative hypothesis.
Example: Deciding whether to reject the null hypothesis

The Χ2 value is less than the critical value. Therefore, you should not reject the null hypothesis that the dog population chooses the three flavors in equal proportions. There is no significant difference between the observed and expected flavor choice distribution (p > .05). This suggests that the dog food flavors are equally popular in the dog population.You report your findings back to the dog food company president. He decides not to eliminate the Garlic Blast and Minty Munch flavors based on your findings. The many dogs who love these flavors are very grateful!

Data Analytics Services
Need Our Services?
Econometrics & Statistics Modelling Services
Need Help, Whatsapp Us Now