Mathwords logoMathwords

Chi-Squared Test — Definition, Formula & Examples

A chi-squared test is a hypothesis test that determines whether observed counts in categories differ significantly from what you would expect by chance. It compares how far your actual data falls from a theoretical or expected distribution.

The chi-squared test is a nonparametric statistical test in which the test statistic χ2\chi^2 follows an approximate chi-squared distribution under the null hypothesis. It is used to assess goodness-of-fit, homogeneity of proportions, or independence between two categorical variables in a contingency table.

Key Formula

χ2=(OiEi)2Ei\chi^2 = \sum \frac{(O_i - E_i)^2}{E_i}
Where:
  • OiO_i = Observed count in category i
  • EiE_i = Expected count in category i under the null hypothesis
  • χ2\chi^2 = Chi-squared test statistic

How It Works

For each category, compute the expected count assuming the null hypothesis is true. Then calculate how much each observed count deviates from its expected count, square that difference, and divide by the expected count. Sum these values across all categories to get χ2\chi^2. A large χ2\chi^2 means the observed data deviate substantially from what was expected, providing evidence against the null hypothesis. You compare χ2\chi^2 to a critical value from the chi-squared distribution (or find a p-value) using the appropriate degrees of freedom.

Worked Example

Problem: A die is rolled 60 times. You expect each face to appear 10 times. The observed counts are: 1→8, 2→12, 3→10, 4→14, 5→7, 6→9. At the 0.05 significance level, is the die fair?
Step 1: Calculate the chi-squared statistic by comparing each observed count to the expected count of 10.
χ2=(810)210+(1210)210+(1010)210+(1410)210+(710)210+(910)210\chi^2 = \frac{(8-10)^2}{10} + \frac{(12-10)^2}{10} + \frac{(10-10)^2}{10} + \frac{(14-10)^2}{10} + \frac{(7-10)^2}{10} + \frac{(9-10)^2}{10}
Step 2: Simplify each term and sum.
χ2=410+410+010+1610+910+110=3.4\chi^2 = \frac{4}{10} + \frac{4}{10} + \frac{0}{10} + \frac{16}{10} + \frac{9}{10} + \frac{1}{10} = 3.4
Step 3: Degrees of freedom = 6 − 1 = 5. The critical value for df = 5 at α = 0.05 is 11.07. Since 3.4 < 11.07, we fail to reject the null hypothesis.
χ2=3.4<11.07=χcrit2\chi^2 = 3.4 < 11.07 = \chi^2_{\text{crit}}
Answer: There is not enough evidence at the 0.05 level to conclude the die is unfair.

Why It Matters

The chi-squared test appears on nearly every AP Statistics exam and is the go-to method whenever you work with categorical data rather than numerical measurements. In fields like genetics, market research, and quality control, it lets you test whether observed patterns match a theoretical model or whether two categorical variables are associated.

Common Mistakes

Mistake: Using observed percentages or proportions instead of raw counts in the formula.
Correction: The chi-squared formula requires actual counts (frequencies), not proportions. If you only have percentages, multiply by the total sample size to convert back to counts before computing χ².