# The Chi-Square Test

> Chi-square measures how far observed counts sit from the counts a chance-only null hypothesis predicts, and you reject the null only when a gap that large would turn up by chance less than 5% of the time. Real counts never match a prediction exactly, so you need that rule to tell an ordinary gap from a telling one. You will run the test from the AP equations sheet on a monohybrid cross, a testcross that hints at linked genes, a mitotic-index count from root tips and a fruit-fly choice chamber. Afterwards you can choose when chi-square fits, state a null hypothesis, compute chi-square from counts, find the degrees of freedom and the critical value, and say what rejecting or failing to reject the null does and does not mean.

Course: AP® Biology exam preparation (Unit 5 Heredity). Level: grades 7–12. About 25 minutes.
Lesson page (link this one when citing): https://stemhop.com/lessons/ap-chi-square/
Note: parts of this lesson are still being checked ("Under review").

## What you'll learn

- Decide whether chi-square fits the data (counts in categories, not measurements), state the null hypothesis for a cross, a cell count or a choice experiment, and use it to calculate expected counts.
- Calculate chi-square with the equations-sheet formula, from counts, and find the degrees of freedom as the number of outcome categories minus one.
- Use the critical-value table at p = 0.05 to decide whether to reject or fail to reject the null hypothesis, and place the p-value in a range.
- Explain what failing to reject a null hypothesis does and does not show, and why rejecting it does not by itself identify the cause.

**Students release 60 fruit flies into the middle of a tube with damp cotton at one end and a dish of drying crystals (silica gel) at the other. When counted, 37 are on the humid side and 23 on the dry side.** (These counts are simulated.)

*Figure (AI-generated illustration).* Flies released in the middle of a two-condition tube settle on one side or the other, and 37 against 23 (simulated counts) looks like a preference, but the test asks whether chance alone could split 60 flies that unevenly. Image: a horizontal glass tube with damp cotton at the left end and a dish of drying crystals at the right end, a cluster of fruit flies released at the middle, and after the trial more flies resting on the damp-cotton half than on the crystal half.

That looks like a preference. But random choices do not split evenly every time either. How lopsided must a split be before chance stops being a good explanation? Chi-square answers that with one formula and one table, both on the AP® Biology equations sheet.

> **The one idea.** Real counts never match a prediction exactly. The **null hypothesis** is the chance-only model: it predicts the counts expected if nothing interesting were happening. Chi-square (χ²) turns the gap between observed and expected counts into one number. Ask: if only chance were at work, how often would a gap this large or larger turn up? That probability is **p**. If p < 0.05 (χ² exceeds the table’s critical value), **reject** the null. Otherwise chance remains a reasonable explanation, so **fail to reject** it. Failing to reject is not proof.
>
> *Scope:* use it on counts in categories, when three things hold. The null fixes expected proportions before you see the data. (For a treated group against a control, the null says both groups share one set of proportions, found by pooling; worked problem 3 shows how.) Count each individual once, independently. Every expected count is about 5 or more.

If predicting ratios is new, start with the high school [Punnett squares](https://stemhop.com/lessons/punnett-squares/) lesson. The college lesson [Probability, Crosses and the Chi-Square Test](https://stemhop.com/lessons/probability-and-crosses/) shows where the critical values come from.

## The five-step routine

First, check that chi-square fits. It is for **counts in categories**: kernels by color, offspring by phenotype, cells by stage, animals by chamber. It is not for measurements such as plant height, enzyme rate or mass change; for those, compare means and error bars (the lesson on graphs, means and error bars). Choosing the test is part of the skill.

Running the test is AP science practice 5.C, chi-square hypothesis testing. Use the same five steps every time, as in each worked problem below.

1. **State the null hypothesis.** It says the tested variable has no effect, or a simple model like 3:1 holds, so any gap is due to chance.
2. **Calculate expected counts** from the null: total times each predicted proportion.
3. **Calculate chi-square** from observed and expected *counts*.
4. **Find the degrees of freedom:** outcome categories minus one.
5. **Compare with the critical value** (the cutoff from the equations-sheet table) at p = 0.05. State the verdict in words (reject or fail to reject the null) and what it means for the biology.

### Step 1: the null hypothesis

The null hypothesis is not your prediction. It is the “nothing interesting is happening” model, chosen for its exact expected counts.

**Predict.** Back to the 60 flies in the humid-or-dry tube. Which is the null hypothesis: “the flies prefer the humid side” or “the flies show no preference”?

> **Check your prediction.** “The flies show no preference, so equal numbers end up on each side, and any difference is due to chance.” That gives expected counts of 30 and 30. “The flies prefer the humid side” is the research (alternative) hypothesis: it is what the students suspect, but it does not say how many flies to expect, so it cannot be tested directly. Naming the alternative when asked for the null is one of the most common slips on this skill.

For a cross, the null is the expected Mendelian ratio, such as “offspring occur in a 3:1 ratio, and any deviation is due to chance.” For a treatment, it is “the treatment has no effect” (worked problem 3 shows how to get its expected counts).

### Steps 2 to 5: the formula, the degrees of freedom and the table

Here is the formula exactly as the AP equations sheet writes it:

> **Equation card: One number for how far a set of observed counts is from the counts the null hypothesis predicts.**
>
>     χ² = Σ (o − e)² / e
>
> In words: Chi-square equals the sum, over every category, of observed minus expected, squared, divided by expected.
>
> - χ²: the test statistic: 0 when every count matches its expected count, larger as the counts stray
> - o: observed: the count you actually got in one category (individuals)
> - e: expected: the count the null hypothesis predicts in that category (the total times the predicted proportion) (individuals)
> - Σ: add the term for every category
>
> Sanity check: Squaring makes a shortfall and an excess both count. Dividing by e judges each miss against the size of its category, so a miss of 10 matters more when 30 are expected than when 300 are. The expected counts must add up to the same total as the observed counts.
> Try one number 60 flies, 37 on the humid side and 23 on the dry side; the null expects 30 and 30. (37 − 30)² / 30 = 49 / 30 = 1.633, and (23 − 30)² / 30 = 49 / 30 = 1.633. χ² = 1.633 + 1.633 ≈ 3.27.

Always put **counts** in the formula, never percentages or ratios; worked problem 1 shows what goes wrong.

**Degrees of freedom** equal outcome categories minus one. Once the total is fixed, the other counts set the last category, leaving (categories − 1) free to vary.

**Predict.** A cross produces 400 offspring in four phenotype classes. How many degrees of freedom does its chi-square test have?

> **Check your prediction.** Three: four categories minus one. The number of offspring does not enter the degrees of freedom. A common wrong answer is 399, the sample size minus one, which belongs to a different calculation (the standard deviation on the same sheet).

Then look up the **critical value**: the χ² value chance alone exceeds only 5% of the time if the null is true (1% for the stricter row). This is the table on the equations sheet:

| p value | 1 df | 2 df | 3 df | 4 df | 5 df | 6 df | 7 df | 8 df |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 0.05 | 3.84 | 5.99 | 7.81 | 9.49 | 11.07 | 12.59 | 14.07 | 15.51 |
| 0.01 | 6.63 | 9.21 | 11.34 | 13.28 | 15.09 | 16.81 | 18.48 | 20.09 |

Read it like this. Bigger gaps are rarer under chance, so **larger** χ² means **smaller** p. If χ² is **larger** than the 0.05 value for your df, p < 0.05: **reject** the null. If **smaller**, p > 0.05: **fail to reject**. Above the 0.01 value, p < 0.01. AP questions use p = 0.05 unless stated otherwise. You can also place p in a range: a 1-df value of 5.2 sits between 3.84 and 6.63, so 0.01 < p < 0.05.

**Film transcript: Crosses and Cells**

### Film transcript: Crosses and Cells

A 3 to 1 ratio predicts 300 purple kernels on this ear. It has 291. Is the ratio in trouble? The ear holds 400 kernels from two heterozygous parents, with purple dominant. So the null is the simple model: 3 to 1, and any gap is chance. Both bars miss by the same 9 kernels. But each term divides by its expected count. So the same miss counts three times as much in the small class. Together they make 1.08, far short of the gold line. Fail to reject. A miss of 9 in 400 is the kind of gap chance makes all the time. Now a testcross. A plant heterozygous for two genes is crossed with one that is recessive for both. If the genes assort independently, four classes should be equally common.

Here are the 400 offspring. Two classes tower over their lines. The other two fall far short. Before the verdict, find the degrees of freedom. Four classes and 400 offspring. Is it three, or 399? Three. It is the number of categories, minus one. The number of offspring never enters. With three degrees of freedom, the gold line moves out to 7.81. Chi-square here is over 150. It flies past both lines, so you reject the null, even at 0.01. But rejecting only says that one -to -one -to -one -to -one fits poorly. It does not say why. The biology has to do that. Look at which classes are too common. They are the parental combinations, the pairings this plant got from its own parents. That is the pattern expected when two genes sit close on one chromosome.

It is consistent with linkage, the next lesson. Same test, different lab. Students stain onion root tips and count cells in mitosis. Tips kept in water show 30 of 200. Tips soaked in a test solution show 48. The null says the solution changes nothing, so both groups share one proportion of cells in mitosis. The best estimate of it pools all 400 cells, and that sets the expected counts for both groups. Now chi-square takes one term for each of the table's four boxes, and they add to 5.16. Two outcome categories, so one degree of freedom. That passes the gold line, but not the stricter one. Reject the null at 0.05. The treated tips have a larger share of cells in mitosis than chance usually makes.

One caution. A tempting shortcut uses the control's share as the expected counts for the treated tips alone. It treats that share as known exactly, when it is only an estimate, and for these counts it more than doubles chi-square. Pool the groups, unless a question tells you which expected counts to use. And the test cannot say why the share rose. More cells may be entering mitosis, or cells may be staying in mitosis longer. So every problem runs the same five steps. State the null. Work out the expected counts. Compute chi-square from counts. Find the degrees of freedom. Then compare, and say what it means. Reject, and chance becomes a poor explanation, but the cause is still open.

Fail to reject, and chance is still enough, but nothing is proved.

From the film

- In the corn cross, 291 purple and 109 yellow kernels give χ² = 1.08, below the 1-df critical value of 3.84, so you fail to reject 3:1; the same miss of 9 weighs three times as much in the smaller class.
- Degrees of freedom are outcome categories minus one: a four-class testcross of 400 offspring has 3, not 399.
- The testcross gives χ² = 151.54, past 11.34, so you reject 1:1:1:1; the excess of parental classes is consistent with linkage, not proof of it.
- For treated against control root tips, pool both groups for the expected counts (161 and 39 per group): χ² = 5.16, so you reject the null with 0.01 < p < 0.05. Using the control alone as expected overstates the evidence.
- Rejecting says chance is a poor explanation, not why: more cells entering mitosis and cells staying in mitosis longer both fit.

## Worked problem 1: a monohybrid cross

Two corn plants, each heterozygous for kernel color (purple dominant to yellow), are crossed. One ear has 400 kernels: **291 purple and 109 yellow**.

**Predict.** A 3:1 ratio predicts 300 purple kernels and 100 yellow. This ear is 9 purple kernels short. Is that a reason to doubt the 3:1 model?

> **Check your prediction.** No. χ² = 1.08, well below the 1-df critical value of 3.84. A miss of 9 kernels in 400 is the kind of gap chance makes all the time.

**Work it through.**

1. *Null:* kernels occur in a 3:1 purple:yellow ratio; any deviation is due to chance.
2. *Expected:* 400 × 3/4 = 300 purple; 400 × 1/4 = 100 yellow.
3. *Chi-square:* (291 − 300)²/300 + (109 − 100)²/100 = 81/300 + 81/100 = 0.27 + 0.81 = **1.08**.
4. *df* = 2 categories − 1 = 1.
5. *Compare:* 1.08 < 3.84, so p > 0.05. **Fail to reject** the null. These data give no reason to doubt that kernel color is one gene with purple dominant.

Both categories missed by 9 kernels, yet the yellow term (0.81) is three times the purple term (0.27). The same miss is more surprising in the smaller category.

**A common slip.** Entered as percentages (72.75 and 27.25 against 75 and 25), these same kernels give 0.0675 + 0.2025 = 0.27, a quarter of the true 1.08. Percentages throw away the sample size; worked problem 4 shows why sample size matters.

## Worked problem 2: when the ratio breaks

Take a plant heterozygous for two genes, AaBb. It inherited A and B together from one parent, and a and b from the other. Cross it with an aabb plant: a **testcross**. If the genes assort independently, the AaBb plant makes four kinds of gametes in equal numbers, so the offspring should be 1:1:1:1. The 400 offspring are (AB means an offspring shows both dominant traits):

| Phenotype | AB | ab | Ab | aB |
| --- | --- | --- | --- | --- |
| Observed (o) | 165 | 158 | 39 | 38 |
| Expected (e) | 100 | 100 | 100 | 100 |
| (o − e)² / e | 42.25 | 33.64 | 37.21 | 38.44 |

1. *Null:* the genes assort independently, giving 1:1:1:1; any deviation is due to chance.
2. *Expected:* 400 × 1/4 = 100 per class.
3. *Chi-square* = 42.25 + 33.64 + 37.21 + 38.44 = **151.54**.
4. *df* = 4 − 1 = 3.
5. *Compare:* 151.54 exceeds both 7.81 and 11.34, so p < 0.01. **Reject** the null.

Rejecting tells you 1:1:1:1 fits these counts poorly, not why. Biology supplies the reason. The overrepresented classes, AB and ab, are parental combinations: A inherited with B, and a with b. That pattern appears when two genes sit close together on one chromosome and are usually inherited together: **linkage**. This is how AP expects you to spot a non-Mendelian pattern: the observed ratio differs statistically from the predicted one. Ab and aB are **recombinants**, new combinations the AaBb plant did not inherit together: 39 + 38 = 77 of 400, a recombination frequency of 19.25%. The next lesson, on linkage and sex-linked traits, turns that into a map distance.

*Figure (AI-generated illustration).* In an AaBb × aabb testcross, independent assortment predicts 100 offspring in each of four classes; the excess of parental AB (165) and ab (158) over recombinant Ab (39) and aB (38) rejects 1:1:1:1 and is consistent with, but does not prove, linkage. Image: a schematic testcross of a heterozygous AaBb plant with a homozygous aabb tester using plain vertical chromosome bars. The main panel shows an AaBb chromosome pair (one bar carrying A and B, its partner carrying a and b) crossed with an aabb pair (two bars carrying a and b), leading to four offspring classes: two parental classes (AB with 165 offspring, ab with 158) and two recombinant classes with swapped two-tone bars (Ab with 39, aB with 38), with a dashed bracket and question mark linking A and B on one bar. Two lower insets compare the independent-assortment null model (genes on separate chromosome pairs giving 1:1:1:1, 100 each) with linked genes close on one chromosome giving 77 of 400 recombinants.

## Worked problem 3: treated against control (mitotic index)

In the cell-division lab, students stain onion root tips and score cells under a microscope as interphase or mitosis. The **mitotic index** is the fraction in mitosis: cells in mitosis ÷ total cells counted. Here, 200 cells were scored from tips in water and 200 from tips in a test solution.

|  | Interphase | Mitosis | Mitotic index |
| --- | --- | --- | --- |
| Control | 170 | 30 | 30/200 = 0.15 (15%) |
| Treated | 152 | 48 | 48/200 = 0.24 (24%) |

The treated index looks higher. Is the difference larger than chance would usually make?

*Figure (AI-generated illustration).* Scoring 200 stained onion root-tip cells per group finds more cells in mitosis in the test solution (48 vs 30), and pooling all 400 cells sets one shared null expectation (161 interphase, 39 mitosis per group), though rejecting the null does not show whether more cells entered mitosis or stayed there longer. Image: experimental design for scoring onion root-tip mitosis. The main panel shows two side-by-side groups: onion root tips in a water control beaker leading to a circular microscope field of rectangular plant cells (200 scored: 170 interphase, 30 mitosis), and onion root tips in a test-solution beaker leading to a second microscope field with visibly more dividing cells (200 scored: 152 interphase, 48 mitosis). Bottom-left inset zooms into two stained rectangular plant cells comparing interphase (smooth round nucleus) and mitosis (condensed dividing chromosomes). Bottom-right inset shows both 200-cell groups pooled into 400 cells (322 interphase, 78 mitosis) to set one shared null expectation of 161 interphase and 39 mitosis per group.

1. *Null:* the test solution does not change the mitotic proportion; any difference is due to chance.
2. *Expected counts: pool the two groups.* If the solution has no effect, both groups share one proportion of cells in mitosis. The best estimate comes from all 400 cells together, not the control alone. This is how the AP lab manual for this investigation does it. Pooled, 322 of 400 cells are in interphase (0.805) and 78 of 400 in mitosis (0.195). Each 200-cell group expects 200 × 0.805 = 161 interphase and 200 × 0.195 = 39 mitosis.

Observed (o) and pooled expected (e) counts:

|  | Interphase (o / e) | Mitosis (o / e) |
| --- | --- | --- |
| Control | 170 / 161 | 30 / 39 |
| Treated | 152 / 161 | 48 / 39 |

1. *Chi-square,* one term for each of the table’s four boxes, control and treated alike: (170 − 161)²/161 + (30 − 39)²/39 + (152 − 161)²/161 + (48 − 39)²/39 = 81/161 + 81/39 + 81/161 + 81/39 = 0.50 + 2.08 + 0.50 + 2.08 = **5.16**.
2. *df:* two outcome categories (interphase and mitosis), so df = 2 − 1 = 1. Why 1 and not 3, with four terms? The group totals (200 and 200) and stage totals (322 and 78) are fixed, so filling one box fixes the other three. (The lab manual writes (2 − 1) × (2 − 1) = 1, for two groups and two stages; same answer.)
3. *Compare:* 5.16 > 3.84, so p < 0.05: **reject** the null. Below 6.63, so 0.01 < p < 0.05. Treated tips have a larger mitotic share than chance usually produces.

A tempting shortcut uses control proportions as expected treated counts and sums only the treated row. For these counts it gives 12.71, over twice 5.16. That treats the control’s 15% as known exactly when it is itself an estimate from 200 cells. Pooling avoids that. When a question tells you which expected values to use, use those.

The test says nothing about why the index rose. More cells could be starting mitosis, or cells could be staying in mitosis longer. The test cannot tell these apart; practice question 8 asks you to weigh them.

## Worked problem 4: a fruit-fly choice chamber

Now finish the opening puzzle. The equation card already gave χ² = 3.27 for the 37 and 23 flies, with 1 df.

**Predict.** Nearly two flies in three chose the humid side. At p = 0.05, do the students have evidence of a preference?

> **Check your prediction.** Not at p = 0.05. 3.27 < 3.84, so p > 0.05: **fail to reject** the null. Splits this uneven turn up over 5% of the time when 60 flies choose sides at random.
>
> That verdict feels harsh when 37 against 23 *looks* like a preference. It may well be one. The test says only that 60 flies are not enough to rule out chance.

**Predict 2.** The students repeat the test with 120 new flies: 74 on the humid side and 46 on the dry side, the same 61.7% proportion. Same verdict?

> **Check your prediction.** No. Expected counts are 60 and 60. χ² = (74 − 60)²/60 + (46 − 60)²/60 = 196/60 + 196/60 = 3.267 + 3.267 ≈ **6.53**. With 1 df, 6.53 > 3.84, so p < 0.05: **reject** the null. Just below 6.63, so 0.01 < p < 0.05.
>
> Only the sample size changed, not the proportion, yet the same lopsidedness became too large for chance. This is the clearest picture of what the first run’s “fail to reject” meant: *not enough evidence yet*, never *no preference*.

Count each fly once, at the end of the trial. If you count the same 60 flies every minute for ten minutes and add the counts, those “600 observations” are not independent. Chi-square will look far more convincing than the experiment is.

## What the verdict means, and what it does not

|  | **Reject the null** (χ² > critical value) | **Fail to reject the null** (χ² < critical value) |
| --- | --- | --- |
| What it means | A gap this large would happen less than 5% of the time if only chance were at work. Chance alone is a poor explanation. | A gap this large is common under chance. Chance is still a sufficient explanation. |
| What it does **not** mean | It does not prove a particular alternative (linkage, a preference, a faster cell cycle). Biology and further experiments decide that. Chance can still be the cause: at p = 0.05, about 1 true null in 20 gets rejected. | It does not prove the null. Do not write “accept the null” or “the data prove 3:1”. Other models may fit as well, and a small sample can hide a real difference, as the 60 flies did. |

## Before the exam

A good AP conclusion has three parts: the comparison (“χ² = 3.27 is less than the critical value of 3.84 at 1 df and p = 0.05”), the decision (“so we fail to reject the null hypothesis”), and the meaning in the experiment (“the difference between sides could be due to chance; these data do not show that the flies prefer the humid side”).

- **The opening flies.** 37 against 23 gives χ² = 3.27 (< 3.84): fail to reject. In 120 flies, the same split gives 6.53: reject. “Fail to reject” means *not enough evidence yet*, never *no preference*.
- **The routine.** Check for counts in categories, state the null, and put counts (not percentages) in the formula. Take df as categories minus one, and compare with the critical value at p = 0.05.
- **The limits.** Rejecting never proves a particular cause, and failing to reject never proves the null.

## Going deeper

*Beyond the AP exam.*

### Small expected counts

The table’s critical values become less reliable when an expected count is below about 5. That is one reason labs count dozens of flies rather than a handful.

### Not on the AP equations sheet

The equations sheet gives one rule for degrees of freedom: categories minus one. College statistics adds larger tables of the worked problem 3 kind, small-sample corrections, and exact p-values from software. Beyond what a question supplies, none of these is tested. The college lesson [Probability, Crosses and the Chi-Square Test](https://stemhop.com/lessons/probability-and-crosses/) also shows why a fit can be suspiciously *too* good.

---

From STEMhop (https://stemhop.com), free lessons by Christopher Deppmann. Lesson text © the authors. Practice questions: https://stemhop.com/lessons/ap-chi-square/
