The formula
χ² = Σ (observed − expected)² / expected
What it means
Each category contributes the difference between observed and expected, squared and divided by the expected. That division is the key: a gap of ten is enormous if you expected five and negligible if you expected a thousand. The total of all those contributions is compared against the chi-square distribution, which says how unusual that total would be if the gaps were pure chance.
How to work it out by hand
- Note the observed frequency of each category
- Work out the expected ones: split evenly, or in whatever proportion applies
- In each category, subtract, square and divide by the expected value
- Add all the contributions and compare against the critical value
What is worth knowing
The approximation breaks down when any expected frequency drops below five, which is why you get a warning: with cells that small the p-value stops being trustworthy and categories need merging, or an exact test is called for. Watch what goes into the table too: chi-square works on counts, never on percentages or averages. Feeding it percentages is a silent mistake, because the arithmetic works and the answer means nothing.