---
title: "Chi-Square Tests for Categorical Data"
description: "Compare observed counts with the counts a model predicts. The same statistic serves goodness of fit, independence and homogeneity, with the degrees of freedom telling them apart."
canonical: https://lightmysky.com/learn/mathematics/chi-square-tests-for-categorical-data-mt_yxc87pzaXX
source: https://lightmysky.com/learn/mathematics/chi-square-tests-for-categorical-data-mt_yxc87pzaXX.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Chi-Square Tests for Categorical Data

Compare observed counts with the counts a model predicts. The same statistic serves goodness of fit, independence and homogeneity, with the degrees of freedom telling them apart.

Subject: Mathematics · Area: Data & Statistics · Ages 21 to 22
Page: https://lightmysky.com/learn/mathematics/chi-square-tests-for-categorical-data-mt_yxc87pzaXX

## Ready when they can

- Compute expected counts and the statistic for a contingency table
- State the degrees of freedom for each of the three tests
- Check the expected-count condition before trusting the result

## Lesson: Counts against the model

A goodness of fit test asks whether observed counts match a claimed distribution. For each category you compare the observed count with the expected count under the claim and add up the squared gap divided by the expected count across all categories. Large totals signal a poor fit. The degrees of freedom are the number of categories minus 1, and every expected count should reach at least 5.

A test of independence works on a table with rows for one variable and columns for the other. When the variables are unrelated, each cell expects its row total times its column total divided by the grand total, and the same sum of squared gaps over expected measures the distance from independence. The degrees of freedom are rows minus 1 times columns minus 1, and the same expected count rule of at least 5 applies.

**Example.** A cell sits in a row totalling 30 and a column totalling 40 with 120 observations overall. Its expected count is 30 times 40 divided by 120, which is 10. A table with 3 rows and 4 columns uses 2 times 3, which is 6 degrees of freedom.

**Tip.** Homogeneity looks numerically like independence but starts from several separate samples compared on one trait, while independence sorts one sample two ways. Read the design first: one sample sorted twice means independence, and several samples compared means homogeneity. Rejecting either test shows an association but never proves cause.

**Recap.** Expected counts set the target, the statistic measures the miss, and the design names the question.

## Practice

14 questions on this page, each with its working shown.

## Needs first

- [Comparing Two Populations](https://lightmysky.com/learn/mathematics/comparing-two-populations-mt_v34rZkMfqr)
- [Conditional Probability, Independence and Bayes' Theorem](https://lightmysky.com/learn/mathematics/conditional-probability-independence-and-bayes-theorem-mt_wIi_XRzwwK)

## Opens up

- [Fitting a Model to Data: Least Squares, Chi-Square and Goodness of Fit](https://lightmysky.com/learn/science/fitting-a-model-to-data-least-squares-chi-square-and-goodness-of-fit-mt_NN0WYlp0md)
- [One-Way Analysis of Variance](https://lightmysky.com/learn/mathematics/one-way-analysis-of-variance-mt_WYGK3Ktnqz)
