Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 6

Calculating Degrees of Freedom for Chi-Square Tests

Recommended resources

Introduction

In our last lesson, we learned how to calculate the Pearson chi-square () statistic, which gives us a single number summarizing the total difference between our observed data and the counts we would expect if the null hypothesis were true. We ended with a crucial question: How large does this value need to be for us to declare the result statistically significant?

This lesson provides the answer. We will connect the statistic to a formal hypothesis test by introducing the concept of degrees of freedom (df). Understanding degrees of freedom allows us to find the p-value associated with our test statistic and, ultimately, to draw a conclusion about our hypothesis.

By the end of this 60-minute lesson, you will be able to determine the degrees of freedom for any contingency table, use it to find the p-value for a chi-square test, and confidently decide whether to reject or fail to reject the null hypothesis.


Degrees of Freedom and the Chi-Square Distribution

Your statistic is a measure of evidence. To interpret it, we need to compare it to a theoretical distribution. For the chi-square test, this is—unsurprisingly—the chi-square () distribution.

However, there isn't just one chi-square distribution; there's a whole family of them. The specific shape of the distribution we use is determined by the degrees of freedom (df).

What are Degrees of Freedom?

Conceptually, degrees of freedom represent the number of values in a calculation that are free to vary. In a contingency table, once you've fixed the row and column totals (which are determined by your sample), only a certain number of cell counts can be chosen freely before the rest are automatically determined.

The formula to calculate degrees of freedom for a contingency table is simple and essential for your exam:

Or, more compactly, .

Example:
For a 2x2 table: .
For a 3x2 table: .

The Chi-Square Distribution's Shape

The image below shows how the shape of the chi-square distribution changes with different degrees of freedom. Notice that all values are non-negative (since they are sums of squared numbers) and the distributions are skewed to the right.

Chi-Square Distributions with Varying Degrees of Freedom and P-value Illustration
This image displays several chi-square probability density functions for different degrees of freedom (df). The curve for df=2 is highlighted. As df increases, the peak of the distribution shifts to the right.

From Test Statistic to p-value and Conclusion

Once we have our calculated statistic and the degrees of freedom, we can determine the p-value.

The p-value is the probability of observing a statistic as large as, or larger than, the one we calculated, assuming the null hypothesis of independence (or homogeneity) is true.

Visually, the p-value is the area under the chi-square distribution curve to the right of our calculated value. A small p-value means our observed result was very unlikely if the null hypothesis were true, giving us grounds to reject it.

Let's watch a video that ties these concepts together: calculating degrees of freedom, finding a p-value, and making a decision.

Chi-Square Test of Independence | Contingency Table | Hypothesis Test

The video 'Chi-Square Test of Independence' by Joshua Emmanuel provides a concise walkthrough of the final steps of the hypothesis test. It clearly explains how to use degrees of freedom to reach a conclusion.

Please watch from 04:10 to 06:24. The video covers three key steps: (04:10 - 04:26) Calculating the degrees of freedom. (04:26 - 05:10) Using the 'critical value' approach to make a decision. (05:10 - 06:24) Using the 'p-value' approach, which is more common in software output and what you should focus on.

The Decision Rule

As the video explained, the process for making a conclusion is straightforward. First, you must set a significance level (alpha, ), which is the threshold for your decision. This is typically set at 0.05 (or 5%) but could be 0.10 or 0.01 depending on the context.

The rule is simple:

  • If p-value < , we reject the null hypothesis (). We conclude there is a statistically significant association between the variables.
  • If p-value , we fail to reject the null hypothesis (). We conclude there is not enough evidence to claim an association between the variables.

A Complete Worked Example

Let's apply this to the "Political Affiliation and Opinion on Tax Reform" example from the Penn State resource. This is a classic test of independence.

The observed data was in a 2x3 table:

  • Rows: Democrat, Republican
  • Columns: Favor, Indifferent, Opposed

In the previous lesson, you would have learned to calculate the statistic for this data. Let's see the full analysis, including the final conclusion.

8 Chi-Square Test for Independence

The resource from Penn State, 'Chi-Square Test for Independence', provides a complete analysis using Minitab, a statistical software package. This is similar to the output you might see from other tools like SPSS, R, or Python libraries.

Read through the sections 'Chi-Square Test Statistic' and 'Minitab: Chi-Square Test of Independence'. Focus on these key points: Degrees of Freedom: See how they calculate df = (2-1)(3-1) = 2. Test Statistic: Note the calculated Chi-Square value is 22.152. The p-value: In the Minitab output table, find the DF (2) and P-Value (0.000). The Conclusion: Read the final paragraph where they compare the p-value (0.000) to alpha (0.05) and reject the null hypothesis.

This resource perfectly demonstrates the workflow:

  1. Calculate statistic (Result: 22.152)
  2. Determine df (Result: 2)
  3. Find p-value (Result: p < 0.001)
  4. Compare p-value to and conclude. Since p < 0.05, they reject and conclude there is a dependent relationship between political affiliation and opinion on the tax bill.

Here is another example of what this kind of software output looks like.

Chi-Square Test Output for Gender and Party Affiliation
This is a typical output from statistical software (SPSS). The 'Chi-Square Tests' table shows the Pearson Chi-Square value (1.118), the degrees of freedom (df = 2), and the p-value (Asymp. Sig. = 0.572). In this case, since 0.572 > 0.05, we would fail to reject the null hypothesis.

Practice Problem

Let's test your understanding. A food services manager wants to know if there is a relationship between gender and preferred hot dog condiment. They collect the following data:

Gender Ketchup Mustard Relish Total
Male 15 23 10 48
Female 25 19 8 52
Total 40 42 18 100

Instructions:

  1. State the hypotheses for this test of independence.
  2. Calculate the degrees of freedom for this contingency table.
  3. The calculated chi-square statistic for this data is , and the corresponding p-value is 0.2288. Using a significance level of , what is your conclusion?

Take a few minutes to work through this before revealing the solution.

Click for Solution
  1. Hypotheses:

    • : Gender and preferred condiment are independent.
    • : Gender and preferred condiment are not independent (i.e., they are associated).
  2. Degrees of Freedom:

    • The table has 2 rows (Male, Female) and 3 columns (Ketchup, Mustard, Relish).
    • .
  3. Conclusion:

    • The given p-value is 0.2288.
    • The significance level is .
    • We compare the p-value to alpha: 0.2288 > 0.10.
    • Since the p-value is greater than the significance level, we fail to reject the null hypothesis. There is not enough statistical evidence to conclude that a relationship exists between gender and preferred condiment choice at this park.

Conclusion

You now have the complete toolkit to perform and interpret a chi-square test. You've connected the calculation of the statistic from the last lesson to a formal decision-making process.

Key Takeaways:

  • Degrees of Freedom (): Calculated as , this determines which chi-square distribution to use as a reference.
  • p-value: This is the probability of obtaining your result (or a more extreme one) if the null hypothesis is true. It is found using the statistic and the degrees of freedom.
  • Decision Rule: The most important step for your exam is comparing the p-value to your significance level (). If p-value < , you reject .

So, is the chi-square test always the right tool? Not quite. The chi-square distribution is an approximation that works well for large samples. But what happens if our sample is small and some expected counts are tiny? The approximation breaks down. In our next lesson, we will cover the key assumption of the chi-square test regarding expected frequencies and learn how to identify situations where you must use an alternative, more precise method: an exact test.