DEV Community

Alan Matthew
Alan Matthew

Posted on

Are Your Dice Loaded? Chi-Square Explained Through Mendel's Peas (+ a Free Calculator)

In 1936, the statistician Ronald Fisher looked at Gregor Mendel's famous pea-plant data and noticed something odd. The results weren't too messy. They were too clean.

Mendel's counts matched his predicted ratios so closely that, by Fisher's analysis of the combined experiments, a fit that good should almost never happen by chance. Historians still argue about why. The tool Fisher used to make the case is one you can learn in about ten minutes: the chi-square test.

By the end of this post you'll be able to:

  • tell whether a die (or a genetics ratio) is plausibly fair,
  • test whether two categorical variables are related,
  • avoid the six mistakes that quietly wreck most chi-square homework,
  • and check your work with a free Chi-Square Test Calculator that shows every step.

The one-sentence version

A chi-square test asks: "Are the counts I observed close enough to the counts I expected that the difference could just be luck?"

The core formula:

χ² = Σ (O − E)² / E
Enter fullscreen mode Exit fullscreen mode
  • O = observed count in a category
  • E = expected count in that category
  • Add it up across all categories

Big gap between O and E gives a big χ². Small gap gives a small χ². Then you compare χ² to a threshold to decide whether "just luck" is still a believable explanation.

Two flavors (pick the right one first)

Most wrong answers start here.

Goodness-of-fit Test of independence
Question Does one variable match an expected distribution? Are two variables related?
Data shape One list of counts A two-way table (rows × columns)
Expected counts Given by a theory (3:1, 9:3:3:1, "all equal") Computed from the table's totals
Degrees of freedom k − 1 (rows − 1) × (columns − 1)
Typical example Is this die fair? Does this cross give 3:1? Is treatment group linked to recovery?

Example 1: Is this die loaded?

You roll a six-sided die 120 times. A fair die should land on each face 20 times, so E = 20 everywhere.

Face Observed (O−E)²/E
1 15 25/20 = 1.25
2 24 16/20 = 0.80
3 18 4/20 = 0.20
4 16 16/20 = 0.80
5 25 25/20 = 1.25
6 22 4/20 = 0.20

χ² = 4.50, with df = 6 − 1 = 5.

The critical value at α = 0.05 with 5 degrees of freedom is 11.0705. Our 4.50 is far below that, so

Top comments (0)