# Chi-square test of independence

This test checks whether two categorical variables are related. The null says they are independent. Compute the sum of (O - E) squared / E over all cells, with (rows - 1) x (columns - 1) degrees of freedom.

Statistics (university) · Part 07: Comparing categories and many groups · Card 3 of 8 · Last updated 2026-10-19

## Analogy

Do people in group A answer yes more often than people in group B?

## Example

**A 2 by 2 table**

Observed 30, 20, 20, 30; expected 25 each
Each cell: 25 / 25 = 1
Chi-square = 4 x 1 = 4.0
df = 1, critical = 3.841
p = 0.046: reject independence

## In practice

Used for survey results, such as whether preference depends on age group.

## Practice

### Flashcards

- **Degrees of freedom for an r by c table?** (r - 1) x (c - 1).

### Interview questions

**In a 2 by 2 table the observed counts are 30, 20, 20 and 30. Test whether the two variables are independent at the 5% level.**

- Expected count 25 in every cell
- Chi-square = 4.0
- df = 1, critical 3.841
- Reject independence

## Questions people ask

### How do I find the degrees of freedom for a table?

Multiply the number of rows minus 1 by the number of columns minus 1. A 3 by 4 table has 2 x 3 = 6 degrees of freedom. A 2 by 2 table has 1. This counts how many cells can vary once the totals are fixed.

### Does a significant chi-square show that one variable causes the other?

No. It only shows the variables are associated. Other factors may explain the link, and the direction of any cause is unknown. Only a well-designed experiment with random assignment can support a causal claim. A survey can show that two things travel together, but not why they do.

## Related concepts

- [Expected counts](https://studyvisually.com/learn/science/statistics-university/statistics-university-part-7/statistics-university-part-7-concept-2)
- [Chi-square goodness of fit](https://studyvisually.com/learn/science/statistics-university/statistics-university-part-7/statistics-university-part-7-concept-1)

Web page: https://studyvisually.com/learn/science/statistics-university/statistics-university-part-7/statistics-university-part-7-concept-3
Study this card in the app: https://studyvisually.com/app/learn?category=statistics-university&card=statistics-university-part-7-concept-3
