chisq.test() — Chi-square test

Checks if your counts match what you expected.

chisq.test(observed, p = expected)

Key idea

Definition

the observed count in each cell
the expected count if the guess is true
the test statistic (bigger = worse fit)

In plain words

You roll a die 100 times expecting each face about the same. If one face shows up way too often, this test notices the die might be loaded.

Where you'd use it

Worked example 14

Expected 25, 25, 25, 25 but you rolled 22, 28, 30, 20. The gaps are small, so it looks fair (high p-value).

Frequently asked questions

What does chisq.test test?
Whether two categorical variables are associated (independence).
What if the cell counts are small?
The χ² approximation is unreliable when expected counts drop below ~5 — use Fisher’s exact test.