S5.2.4 Chapter 4

Testing results with chi squared

A cross should give 3 round seeds for every 1 wrinkled seed, but a gardener counts 84 round and 36 wrinkled. Is that close enough, or is the ratio wrong?

Your guess

Pick one before you read on. It is fine to be wrong.

Your guess
  • You picked A. Read on. At the end, the chapter comes back to your guess.

  • You picked B. Read on. At the end, the chapter comes back to your guess.

  • You picked C. Read on. At the end, the chapter comes back to your guess.

  • You picked D. Read on. At the end, the chapter comes back to your guess.

By the end you can

  • Use the chi squared test to compare observed and expected ratios
  • Interpret a p value and state a conclusion

A cross predicts a ratio, such as 3 : 1. The ratio is a chance for each offspring, not a promise for a small group. A real count never matches it exactly. The observed counts are the ones we find. The expected counts are the ones the ratio predicts.

To work out an expected count, divide the total in proportion to the ratio. With 120 offspring and a ratio of 3 : 1, the parts are 3 + 1 = 4. The expected counts are 3/4 × 120 = 90 and 1/4 × 120 = 30.

The question is how far apart the observed and expected counts may be before we stop blaming chance. The chi squared test, written χ², answers it. It starts with a null hypothesis: the difference between the counts and the ratio is due to chance alone.

The statistic is χ² = Σ (O − E)² ÷ E. For each class, take the observed count O minus the expected count E, square it, and divide by E. Then add up the classes. The square makes every gap positive, and dividing by E makes a gap matter more where the expected count is small.

Six steps of a chi squared test, from top to bottom: state the null hypothesis, work out the expected counts, calculate χ², find the degrees of freedom, compare with the critical value, write the conclusion.state the null hypothesiswork out the expected countscalculate χ²find the degrees of freedomcompare with the criticalvaluewrite the conclusion
The steps are the same for every chi squared test.

The degrees of freedom, df, is the number of classes minus 1. With a 3 : 1 ratio there are 2 classes, so df = 1. With a 9 : 3 : 3 : 1 ratio there are 4 classes, so df = 3. Once all but one of the counts are known, the last one is fixed by the total, so it is not free.

Each df has a critical value. If χ² is smaller than the critical value at p = 0.05, the gap is small enough that chance alone would make it more than 1 time in 20. We call the difference not significant. If χ² is equal to it or larger, the gap is significant: chance alone would make a gap this big less than 1 time in 20.

A table of critical values with the columns df, 0.05 and 0.01. df 1: 3.841 and 6.635. df 2: 5.991 and 9.210. df 3: 7.815 and 11.345. df 4: 9.488 and 13.277. df 5: 11.070 and 15.086.df0.050.0113.8416.63525.9919.21037.81511.34549.48813.277511.07015.086
Critical values of χ². The column 0.05 is for a chance of 5% and the column 0.01 is for a chance of 1%.

Worked example

A gardener counts 84 round seeds and 36 wrinkled seeds from a cross that should give 3 : 1. Test the ratio at the 5% level.

  1. The null hypothesis is that the counts fit 3 : 1. The total is 120, so the expected counts are 90 and 30.
  2. Round: (84 − 90)² ÷ 90 = 36 ÷ 90 = 0.4. Wrinkled: (36 − 30)² ÷ 30 = 36 ÷ 30 = 1.2.
  3. χ² = 0.4 + 1.2 = 1.6.
  4. There are 2 classes, so df = 1. The critical value at 0.05 is 3.841.
  5. 1.6 is less than 3.841, so the difference is not significant. The counts fit a 3 : 1 ratio.

Answer: 1.6

The p value is the chance of getting a gap at least as big as the one seen, if the null hypothesis is true. For χ² = 1.6 with df = 1, the p value is about 0.21. That is more than 0.05, so the same decision follows: the counts fit the ratio.

A curve of chi squared with 3 degrees of freedom, on a scale from 0 to 12. The x axis is labelled χ² value and the y axis is labelled relative chance. A dashed line at 7.815 marks the critical value. The tail to the right of it is hatched and labelled area 0.05. The label df = 3 is shown.00.10.20.3024681012χ² valuerelative chance7.815area 0.05df = 3
The curve for 3 degrees of freedom. The hatched tail beyond 7.815 has an area of 0.05. A result in the tail happens by chance 1 time in 20.

Worked example

Mendel counted 315, 108, 101 and 32 seeds in the four classes of a dihybrid cross. Test them against 9 : 3 : 3 : 1.

  1. The total is 556. The expected counts are 312.75, 104.25, 104.25 and 34.75.
  2. The parts of χ² are 0.016, 0.135, 0.101 and 0.218.
  3. χ² = 0.470 to three decimal places.
  4. There are 4 classes, so df = 3 and the critical value at 0.05 is 7.815.
  5. 0.470 is far below 7.815. The counts fit 9 : 3 : 3 : 1.

Answer: 0.47

A table of the working, with the columns Class, O, E and Part. Class 1: O 315, E 312.75, part 0.016. Class 2: 108, 104.25, 0.135. Class 3: 101, 104.25, 0.101. Class 4: 32, 34.75, 0.218. The classes are round yellow, round green, wrinkled yellow and wrinkled green.ClassOEPart1315312.750.0162108104.250.1353101104.250.10143234.750.218
The classes are round yellow, round green, wrinkled yellow and wrinkled green. The parts add to 0.470.

Worked example

In chapter 3, a test cross of fruit flies gave 965, 944, 206 and 185 offspring. If the two genes were on different chromosomes the ratio would be 1 : 1 : 1 : 1. Test it.

  1. The total is 2300, so the expected count in each class is 575.
  2. The parts are 264.5, 236.8, 236.8 and 264.5.
  3. χ² = 1002.6 to one decimal place.
  4. There are 4 classes, so df = 3 and the critical value at 0.05 is 7.815.
  5. 1002.6 is far above 7.815, so the difference is significant. The genes do not sort on their own: they are linked.

Answer: 1002.6

Write a conclusion in words and always link it to the null hypothesis. If χ² is less than the critical value, write that there is no significant difference between the observed and expected counts, so the results fit the ratio.

If χ² is larger than the critical value, write that there is a significant difference. The results do not fit the ratio, and something other than chance is probably acting.

Be careful about three things. Use counts, never percentages: 55 of 100 and 550 of 1000 are the same percentage, but 550 of 1000 is much stronger evidence. Each expected count should be at least 5, or the test is unreliable. And the classes must be separate, so each offspring is counted once.

A table with the columns Seeds, χ² and Significant. For 100 seeds with 55 round and 45 wrinkled against a 1 : 1 ratio, χ² is 1 and Significant is no. For 1000 seeds with 550 round and 450 wrinkled, χ² is 10 and Significant is yes.Seedsχ²Significant1001no100010yes
The ratio is 55 : 45 both times, but χ² is ten times bigger when there are ten times as many seeds. More counts give a more sensitive test.

See it three ways

As a picture

A curve of chi squared with 1 degree of freedom, on a scale from 0 to 8. The x axis is labelled χ² value and the y axis is labelled relative chance. A dashed line at 1.6 marks the gardener's result and a dashed line at 3.841 marks the critical value. The tail to the right of 3.841 is hatched and labelled area 0.05. The label df = 1 is shown.00.10.20.30.40.502468χ² valuerelative chance1.63.841area 0.05df = 1

In words

The gardener's result, 1.6, lies to the left of the critical value, outside the hatched tail. Chance alone could often give a gap this big. A result in the tail would be rare.

In symbols

χ² = Σ (O − E)² ÷ E. For df = 1, the critical value is 3.841. 1.6 is below it, so the difference is not significant.

Try it

Test a coin

You need: a coin, a piece of paper, a pencil.

  1. Toss the coin 40 times. Count the heads and the tails.
  2. If the coin is fair, the null hypothesis is that heads and tails are equally likely, so the expected counts are 20 and 20.
  3. Work out (O − E)² ÷ E for heads, and for tails, and add them to get χ².
  4. There are 2 classes, so df = 1. Compare χ² with 3.841.

What you will see: Almost every fair coin passes: about 19 coins in 20 give a χ² below 3.841. A coin that gives 23 heads and 17 tails has χ² = 0.9, which is nowhere near the critical value.

If you cannot try it, this is what happens.
A table of one example of 40 tosses, with the columns Side, O, E and Part. Heads: O 23, E 20, part 0.45. Tails: O 17, E 20, part 0.45. The total of the parts is 0.9.SideOEPartheads23200.45tails17200.45

A wrong idea many people have

If χ² is below the critical value, the ratio is proved right.

Why it feels right: The test says the difference is not significant, which sounds like the counts match the ratio exactly.

The test that breaks it: Take 20 seeds with 13 round and 7 wrinkled. Against 3 : 1, χ² is 1.07. Against 1 : 1, χ² is 1.8. Both are below 3.841, so both ratios fit. A small count cannot tell them apart, so passing the test proves nothing.

What is true: A result that is not significant means there is no evidence against the ratio. It does not prove the ratio. More counts could change the result.

Key words

observed
the counts that were found.
expected
the counts that the ratio predicts, from the total.
null hypothesis
the statement that the difference between observed and expected is due to chance alone.
chi squared test
a test that compares observed and expected counts, using χ² = Σ (O − E)² ÷ E.
degrees of freedom
the number of classes minus 1.
critical value
the value of χ² that chance alone gives only 1 time in 20 at p = 0.05.
significant
too big a difference to be explained by chance alone, at the level chosen.
p value
the chance of a gap as big as the one seen, if the null hypothesis is true.

Back to your guess

The answer is D: We cannot say from the ratio alone. We need a test that shows how often chance would make a gap this big.

Chance never gives an exact ratio. The chi squared test measures the gap between the counts and the ratio, and says how often chance alone would give a gap as big.

Check yourself

Try each one before you look. A wrong answer tells you where to go next.

  1. A cross gives four classes of offspring, which should be in the ratio 9 : 3 : 3 : 1. How many degrees of freedom does the test have?

    Tap your answer.
    1. Not this one. 4 is the number of classes. The degrees of freedom is one less, because the last count is fixed by the total. Read this page again. Try another.

    2. Not this one. 1 would be right for two classes. Here there are four. Read this page again. Try another.

    3. Not this one. 16 is the number of boxes in the square, not the number of classes. Read this page again. Try another.

    4. Yes, that is right. There are 4 classes, so df = 4 − 1 = 3.

    See the answer

    3

    There are 4 classes, so df = 4 − 1 = 3.

    • If you chose A: 4 is the number of classes. The degrees of freedom is one less, because the last count is fixed by the total. Read this page again.
    • If you chose B: 1 would be right for two classes. Here there are four. Read this page again.
    • If you chose C: 16 is the number of boxes in the square, not the number of classes. Read this page again.
  2. A 3 : 1 cross gives 18 round and 12 wrinkled seeds, 30 in all. What is χ²?

    See the answer

    3.6

    The expected counts are 22.5 and 7.5. (18 − 22.5)² ÷ 22.5 = 0.9 and (12 − 7.5)² ÷ 7.5 = 2.7. 0.9 + 2.7 = 3.6.

  3. A test with 1 degree of freedom gives χ² = 1.6. The critical value at 0.05 is 3.841. What is the conclusion?

    Tap your answer.
    1. Not this one. A difference is significant only when χ² is at least the critical value. 1.6 is less than 3.841. Read this page again. Try another.

    2. Yes, that is right. 1.6 is less than 3.841. Chance alone could often make a gap this big, so there is no evidence against the ratio.

    3. Not this one. A test cannot prove a ratio right. It can only say there is no evidence against it. Read this page again. Try another.

    See the answer

    The difference is not significant, so the counts fit the ratio.

    1.6 is less than 3.841. Chance alone could often make a gap this big, so there is no evidence against the ratio.

    • If you chose A: A difference is significant only when χ² is at least the critical value. 1.6 is less than 3.841. Read this page again.
    • If you chose C: A test cannot prove a ratio right. It can only say there is no evidence against it. Read this page again.
  4. A dihybrid cross gives χ² = 12.4 with 3 degrees of freedom. The critical value at 0.05 is 7.815. What is the conclusion?

    Tap your answer.
    1. Not this one. 12.4 is larger than 7.815, so the difference is significant. Read this page again. Try another.

    2. Not this one. A χ² of 0 would mean exactly as predicted. 12.4 is a large gap. Read this page again. Try another.

    3. Yes, that is right. 12.4 is larger than 7.815, so chance alone would make a gap this big less than 1 time in 20.

    4. Not this one. The test works with any number of degrees of freedom. Only the critical value changes. Read this page again. Try another.

    See the answer

    The difference is significant, so the results do not fit 9 : 3 : 3 : 1.

    12.4 is larger than 7.815, so chance alone would make a gap this big less than 1 time in 20.

    • If you chose A: 12.4 is larger than 7.815, so the difference is significant. Read this page again.
    • If you chose B: A χ² of 0 would mean exactly as predicted. 12.4 is a large gap. Read this page again.
    • If you chose D: The test works with any number of degrees of freedom. Only the critical value changes. Read this page again.
  5. A test gives a p value of 0.03. Which statement is correct?

    Tap your answer.
    1. Not this one. The p value is not the chance that the ratio is right. It is the chance of a gap this big if the ratio is right. Read this page again. Try another.

    2. Yes, that is right. A p value is the chance of results at least this far from expected, if the null hypothesis is true. 0.03 is 3 in 100, and it is below 0.05, so the result is significant.

    3. Not this one. The p value says nothing about how often the ratio is right. It is about the chance of the gap, if the ratio is right. Read this page again. Try another.

    See the answer

    If the ratio is right, a gap this big would happen about 3 times in 100.

    A p value is the chance of results at least this far from expected, if the null hypothesis is true. 0.03 is 3 in 100, and it is below 0.05, so the result is significant.

    • If you chose A: The p value is not the chance that the ratio is right. It is the chance of a gap this big if the ratio is right. Read this page again.
    • If you chose C: The p value says nothing about how often the ratio is right. It is about the chance of the gap, if the ratio is right. Read this page again.
  6. From an earlier chapter

    Two RrYy plants are crossed and give 320 seeds. About how many are expected to be round and green?

    Tap your answer.
    1. Yes, that is right. Round green is 3 boxes in 16. 320 × 3 ÷ 16 = 60.

    2. Not this one. 20 is the expected number of wrinkled green seeds, 1 box in 16. Go to S5.2.2. Try another.

    3. Not this one. 180 is the expected number of round yellow seeds, 9 boxes in 16. Go to S5.2.2. Try another.

    See the answer

    60

    Round green is 3 boxes in 16. 320 × 3 ÷ 16 = 60.

    • If you chose B: 20 is the expected number of wrinkled green seeds, 1 box in 16. Go to S5.2.2.
    • If you chose C: 180 is the expected number of round yellow seeds, 9 boxes in 16. Go to S5.2.2.
  7. Mendel counted 5 474 round and 1 850 wrinkled seeds, 7 324 in all. The expected counts for 3 : 1 are 5 493 and 1 831. What is χ², to 2 decimal places?

    See the answer

    0.26

    (5 474 − 5 493)² ÷ 5 493 = 361 ÷ 5 493 = 0.066. (1 850 − 1 831)² ÷ 1 831 = 361 ÷ 1 831 = 0.197. The sum is 0.263, or 0.26.

  8. A cross should give a ratio of 1 : 1 and 40 offspring are counted, 24 of one kind and 16 of the other. What is χ²?

    See the answer

    1.6

    The expected counts are 20 and 20. (24 − 20)² ÷ 20 = 0.8 and (16 − 20)² ÷ 20 = 0.8. The sum is 1.6.

  9. Look at the table of critical values. What is the critical value at 0.01 for 2 degrees of freedom?

    A table of critical values with the columns df, 0.05 and 0.01. df 1: 3.841 and 6.635. df 2: 5.991 and 9.210. df 3: 7.815 and 11.345. df 4: 9.488 and 13.277. df 5: 11.070 and 15.086.df0.050.0113.8416.63525.9919.21037.81511.34549.48813.277511.07015.086
    Tap your answer.
    1. Not this one. 5.991 is for 2 degrees of freedom at 0.05, not at 0.01. Read this page again. Try another.

    2. Not this one. 6.635 is for 1 degree of freedom at 0.01. The row for 2 degrees of freedom is the second row. Read this page again. Try another.

    3. Yes, that is right. Read the row for df = 2 and the column 0.01. The value is 9.210.

    4. Not this one. 11.345 is for 3 degrees of freedom at 0.01. Read this page again. Try another.

    See the answer

    9.210

    Read the row for df = 2 and the column 0.01. The value is 9.210.

    • If you chose A: 5.991 is for 2 degrees of freedom at 0.05, not at 0.01. Read this page again.
    • If you chose B: 6.635 is for 1 degree of freedom at 0.01. The row for 2 degrees of freedom is the second row. Read this page again.
    • If you chose D: 11.345 is for 3 degrees of freedom at 0.01. Read this page again.
  10. Look at the table of two samples of seeds. Against a 1 : 1 ratio, in which sample is the difference significant at the 5% level?

    A table of two samples with the columns Seeds, Round and Wrinkled. The first sample has 100 seeds, 60 round and 40 wrinkled. The second sample has 1000 seeds, 520 round and 480 wrinkled.SeedsRoundWrinkled10060401000520480
    Tap your answer.
    1. Yes, that is right. For 60 and 40 the expected counts are 50 and 50. The parts are 2 and 2, so χ² is 4, which is above 3.841. The sample of 1000 has a gap of 20 in 500, and its χ² is only 1.6. A small sample can be significant when its gap is wide enough.

    2. Not this one. For 520 and 480 the expected counts are 500 and 500. The parts are 0.8 and 0.8, so χ² is 1.6, which is below 3.841. Read this page again. Try another.

    3. Not this one. Only one of them is. The sample of 1000 gives χ² = 1.6, which is below 3.841. Read this page again. Try another.

    See the answer

    The sample of 100 seeds

    For 60 and 40 the expected counts are 50 and 50. The parts are 2 and 2, so χ² is 4, which is above 3.841. The sample of 1000 has a gap of 20 in 500, and its χ² is only 1.6. A small sample can be significant when its gap is wide enough.

    • If you chose B: For 520 and 480 the expected counts are 500 and 500. The parts are 0.8 and 0.8, so χ² is 1.6, which is below 3.841. Read this page again.
    • If you chose C: Only one of them is. The sample of 1000 gives χ² = 1.6, which is below 3.841. Read this page again.

Keep it

Copy this into your exercise book.

χ² = Σ (O − E)² ÷ E. Degrees of freedom are the classes minus 1. Below the critical value at 0.05, the difference is not significant. At or above it, it is significant. Use counts.

Draw: A curve with the right tail hatched and a dashed line at the critical value.

Reading with a child? A short page for the adult: what this chapter teaches and three questions to ask.

No internet tomorrow? Save the whole book as one file (1.1 MB). It opens on any phone.