Home›Glossary›Chi-Square Test

Chi-Square Test

General

Pearson's Chi-Square Test

A statistical test that compares observed category counts against expected counts to determine whether a relationship between categorical variables (or a deviation from an expected distribution) is statistically real.

Definition

A chi-square test compares observed category counts against the counts you'd expect under some hypothesis — either that a variable follows a specific expected distribution, or that two categorical variables are unrelated. Unlike a t-test, which compares means of continuous measurements, a chi-square test works with counts and frequencies of categories: how many customers chose each product option, how many defective items appeared in each production batch, and similar tallying questions.

The Chi-Square Test Calculator takes your observed and expected frequency pairs and computes both the chi-square statistic and its corresponding p-value.

Formula

χ² = Ī£ [(Observed āˆ’ Expected)² Ć· Expected]

summed across every category (or cell, for a test of independence using a contingency table). The resulting statistic is compared against a chi-square distribution with the appropriate degrees of freedom to produce a p-value.

Worked Example

Testing whether a six-sided die is fair, after rolling it 60 times: expected count per face is 60 Ć· 6 = 10. Suppose observed counts were 8, 12, 9, 11, 7, 13 for faces 1 through 6. The chi-square statistic sums (8āˆ’10)²/10 + (12āˆ’10)²/10 + (9āˆ’10)²/10 + (11āˆ’10)²/10 + (7āˆ’10)²/10 + (13āˆ’10)²/10 = 0.4 + 0.4 + 0.1 + 0.1 + 0.9 + 0.9 = 2.8. With 5 degrees of freedom (6 categories āˆ’ 1), this modest chi-square value corresponds to a high p-value, meaning there's no strong evidence the die is unfair.

Key Things to Know

  • Works with counts, not measurements: chi-square is for categorical/frequency data, while a t-test handles continuous numeric means.
  • Two main forms: goodness-of-fit (one variable vs. an expected distribution) and test of independence (two variables' relationship via a contingency table).
  • Degrees of freedom shape the comparison: more categories or a larger contingency table require a different reference distribution to judge significance.
  • A low p-value signals a real deviation or relationship, not proof of the specific cause behind it.
  • Expected counts should generally be at least 5 per category for the test's approximation to be reliable — very sparse categories can distort results.

Frequently Asked Questions

A goodness-of-fit test checks whether one categorical variable's observed distribution matches an expected distribution, such as whether a die's rolls are evenly distributed across six faces. A test of independence checks whether two categorical variables are related, using a contingency table, such as whether product preference varies by customer region. Both use the same underlying chi-square formula, applied to different data setups.
Squaring the difference between observed and expected counts ensures that negative and positive deviations don't cancel each other out, and it also weights larger deviations more heavily than smaller ones. Dividing each squared difference by the expected count normalizes the deviation relative to how large that category was expected to be.
Degrees of freedom for a goodness-of-fit test equal the number of categories minus 1, while for a test of independence they equal (rows āˆ’ 1) Ɨ (columns āˆ’ 1) in the contingency table. Degrees of freedom determine which chi-square distribution to compare your test statistic against, since the shape of that distribution changes with more categories or table dimensions.
No — chi-square tests are designed specifically for categorical (count) data, not continuous measurements like height or income. If you have continuous data and want to compare group means, a t-test is the appropriate tool instead of chi-square.
A low p-value (typically below 0.05) suggests the observed counts differ from the expected counts by more than random chance alone would produce, indicating a real deviation from the expected distribution or a real relationship between the categorical variables tested. A high p-value means the data is consistent with the expected distribution or no relationship existing.