A **Chi-Square goodness of fit test** is used to determine whether or not a categorical variable follows a hypothesized distribution.

This tutorial explains the following:

- The motivation for performing a Chi-Square goodness of fit test.
- The formula to perform a Chi-Square goodness of fit test.
- An example of how to perform a Chi-Square goodness of fit test.

**Chi-Square Goodness of Fit Test: Motivation**

A Chi-Square goodness of fit test can be used in a wide variety of settings. Here are a few examples:

- We want to know if a die is fair, so we roll it 50 times and record the number of times it lands on each number.
- We want to know if an equal number of people come into a shop each day of the week, so we count the number of people who come in each day during a random week.
- We want to know if the percentage of M&M’s that come in a bag are as follows: 20% yellow, 30% blue, 30% red, 20% other. To test this, we open a random bag of M&M’s and count how many of each color appear.

In each of these scenarios, we want to know if some variable follows a hypothesized distribution. In each scenario, we can use a Chi-Square goodness of fit test to determine if there is a statistically significant difference in the number of expected counts for each level of a variable compared to the observed counts.

**Chi-Square Goodness of Fit Test: Formula**

A Chi-Square goodness of fit test uses the following null and alternative hypotheses:

**H**A variable follows a hypothesized distribution._{0}: (null hypothesis)**H**A variable does not follow a hypothesized distribution._{1}: (alternative hypothesis)

We use the following formula to calculate the Chi-Square test statistic X^{2}:

**X ^{2} = Σ(O-E)^{2} / E**

where:

**Σ:**is a fancy symbol that means “sum”**O:**observed value**E:**expected value

If the p-value that corresponds to the test statistic X^{2} with n-1 degrees of freedom (where n is the number of categories) is less than your chosen significance level (common choices are 0.10, 0.05, and 0.01) then you can reject the null hypothesis.

**Chi-Square Goodness of Fit Test: Example**

A shop owner claims that an equal number of customers come into his shop each weekday. To test this hypothesis, an independent researcher records the number of customers that come into the shop on a given week and finds the following:

**Monday:**50 customers**Tuesday:**60 customers**Wednesday:**40 customers**Thursday:**47 customers**Friday:**53 customers

We will use the following steps to perform a Chi-Square goodness of fit test to determine if the data is consistent with the shop owner’s claim.

**Step 1: Define the hypotheses.**

We will perform the Chi-Square goodness of fit test using the following hypotheses:

**H**An equal number of customers come into the shop each day._{0}:**H**An equal number of customers do not come into the shop each day._{1}:

**Step 2: Calculate (O-E) ^{2} / E for each day.**

There were a total of 250 customers that came into the shop during the week. Thus, if we expected an equal amount to come in each day then the expected value “E” for each day would be 50.

**Monday:**(50-50)^{2}/ 50 = 0**Tuesday:**(60-50)^{2}/ 50 = 2**Wednesday:**(40-50)^{2}/ 50 = 2**Thursday:**(47-50)^{2}/ 50 = 0.18**Friday:**(53-50)^{2}/ 50 = 0.18

**Step 3: Calculate the test statistic X ^{2}.**

**X ^{2 }**= Σ(O-E)

^{2}/ E = 0 + 2 + 2 + 0.18 + 0.18 =

**4.36**

**Step 4: Calculate the p-value of the test statistic X ^{2}.**

According to the Chi-Square Score to P Value Calculator, the p-value associated with X^{2} = 4.36 and n-1 = 5-1 = 4 degrees of freedom is **0.359472**.

**Step 5: Draw a conclusion.**

Since this p-value is not less than 0.05, we fail to reject the null hypothesis. This means we do not have sufficient evidence to say that the true distribution of customers is different from the distribution that the shop owner claimed.

**Note: **You can also perform this entire test by simply using the Chi-Square Goodness of Fit Test Calculator.

**Additional Resources**

The following tutorials explain how to perform a Chi-Square goodness of fit test using different statistical programs:

How to Perform a Chi-Square Goodness of Fit Test in Excel

How to Perform a Chi-Square Goodness of Fit Test in Stata

Chi-Square Goodness of Fit Test on a TI-84 Calculator

Chi-Square Goodness of Fit Test Calculator