notesonly.in

One notebook for every subject — open it anywhere.

Log in

Chi Square Test: Explained with Examples, Notes and FAQs

The chi-square (χ²) test is the go-to tool for categorical data — counts of things falling into groups rather than measurements like height or weight. It answers questions such as "is this die fair?" or "do customers prefer packaging A, B, or C?"

This matters because a huge share of real-world data is categorical: survey answers, defect types, blood groups, website clicks by page. Means and t-tests cannot handle such data at all, so without chi-square you would have no rigorous way to judge whether observed counts differ from expectation by more than chance.

Key Concepts

  • Observed vs expected frequencies: O = the counts you actually saw; E = the counts H₀ predicts. The test measures the gap between them.
  • Goodness-of-fit test: checks whether one categorical variable follows a claimed distribution (for example, a die giving each face with probability 1/6).
  • Test of independence: checks whether two categorical variables are related, using a contingency table (for example, gender vs product preference).
  • Degrees of freedom: df = k − 1 for goodness-of-fit with k categories; df = (rows − 1)(columns − 1) for independence.
  • The "expected ≥ 5" rule: the test is unreliable if any expected count is below 5 — combine small categories first.
  • One-sided by nature: χ² is always ≥ 0, and large values mean "far from H₀", so you always use the right tail.

Formulas

  • Test statistic: χ² = Σ (O − E)² / E, summed over all cells or categories. Each term is the squared surprise in that cell, scaled by what was expected.
  • Goodness-of-fit df: k − 1, where k is the number of categories.
  • Independence df: (r − 1)(c − 1) for a table with r rows and c columns.
  • Expected count (independence): E = (row total × column total) / grand total.

Assumptions: random sampling, categorical data, independent observations, and every expected frequency at least 5.

Worked Example

Roll a die 60 times. Observed counts: 8, 12, 9, 11, 10, 10. Is the die fair? (H₀: each face has probability 1/6; α = 0.05.)

  1. Expected counts: 60 × (1/6) = 10 for each face.
  2. Compute each term: (8−10)²/10 = 0.4; (12−10)²/10 = 0.4; (9−10)²/10 = 0.1; (11−10)²/10 = 0.1; (10−10)²/10 = 0; (10−10)²/10 = 0.
  3. Sum: χ² = 0.4 + 0.4 + 0.1 + 0.1 + 0 + 0 = 1.0.
  4. Degrees of freedom: 6 − 1 = 5. Critical value at α = 0.05 is 11.07.
  5. Decision: 1.0 < 11.07, so fail to reject H₀.
  6. Conclusion: no evidence the die is unfair — these wobbles around 10 are exactly what chance produces.

Common Misconceptions

  • Chi-square is for counts, not measurements. Feeding it averages or percentages directly is wrong — convert percentages back to raw frequencies first.
  • Small expected counts break the test. If some E < 5, the χ² approximation fails; merge rare categories before testing.
  • A significant result does not say where the difference is. It only says the table as a whole deviates from independence — inspect individual cells (large (O−E)²/E contributions) to find the story.

Real-World Applications

  • Genetics: Mendel's pea-plant ratios (9:3:3:1) are still verified with goodness-of-fit chi-square tests.
  • Marketing: testing whether ad preference is independent of age group before targeting campaigns.
  • Medicine: checking whether recovery rates differ across three treatments in a contingency table.
  • Quality control: testing whether defect types occur in the same proportions across three factory shifts.

The chi-square test turns "these counts look uneven" into a measured verdict: square each deviation, scale by expectation, sum, and compare. For categorical data, it is the single most useful test in the toolbox.