Chi-square test for genetics
A chi-square test asks whether the offspring counts you observed are close enough to the counts a genetic model predicts. You compare each observed count with its expected count to get one number, then compare that number with a critical value set by the degrees of freedom. If the number is smaller, the model fits. If it is larger, the model is in doubt.
For students and parents planning test prep or coursework: one hour with George Li, one to one by video, is $180, $200 or $160, by subject. You leave with a written plan within one working day.
Book your first session| Degrees of freedom | 0.05 | 0.01 |
|---|---|---|
| 1 | 3.841 | 6.635 |
| 2 | 5.991 | 9.210 |
| 3 | 7.815 | 11.345 |
| 4 | 9.488 | 13.277 |
| 5 | 11.070 | 15.086 |
Degrees of freedom equal the number of phenotype classes minus 1. A chi-square larger than the value in the column rejects the model at that level.
Standard values, recomputed in code for this page from the chi-square distribution
What are the steps?
Follow five steps in the same order each time. State the model, which is the null hypothesis: for a cross of two heterozygotes for one gene with complete dominance, it is a 3 to 1 ratio of the two phenotypes. Find each expected count by multiplying the total by that class's share of the ratio. Compute chi-square as the sum, over all classes, of the squared difference between observed and expected, divided by expected. Find the degrees of freedom, which is the number of classes minus 1. Then compare chi-square with the critical value at the 0.05 level.
The test works on counts, not percentages. If you convert counts to percentages first, the result is meaningless. It also needs expected counts that are not tiny, and a common rule of thumb is at least 5 in every class.
What does a worked case look like?
Suppose 200 offspring from a cross of two heterozygotes are counted, with 140 showing the dominant phenotype and 60 the recessive. The model predicts 150 and 50.
Chi-square is (140 minus 150) squared over 150, plus (60 minus 50) squared over 50. That is 100 over 150, or 0.667, plus 100 over 50, or 2. The total is 2.667. With two classes there is one degree of freedom, and the 0.05 critical value there reads 3.841. Because 2.667 is smaller, the data are consistent with a 3 to 1 ratio. The p-value is about 0.10, so a gap this size would turn up about one time in ten by chance alone.
Worked example: A two-gene cross with a good fit and a poor fit
Two heterozygotes for two independent genes are crossed, and 160 offspring are counted. The model is 9 to 3 to 3 to 1, so the expected counts are 90, 30, 30 and 10.
Case A: observed 90, 33, 27 and 10.
- The differences from expected are 0, 3, -3 and 0.
- Chi-square is 0 + 9/30 + 9/30 + 0, which is 0.6.
- There are four classes, so 3 degrees of freedom, and the critical value is 7.815. Since 0.6 is much smaller, the model fits. The p-value is about 0.90.
Case B: observed 70, 48, 30 and 12.
- The differences are -20, 18, 0 and 2.
- Chi-square is 400/90 + 324/30 + 0 + 4/10, which is 4.444 + 10.8 + 0 + 0.4, or 15.644.
- With 3 degrees of freedom, 15.644 is above both 7.815 and 11.345. The p-value is about 0.0013, so a gap this large would be very unlikely if the model were true.
In Case B the second class is far above its expected count and the first is far below. That pattern shows where the model fails, so follow it up with a larger sample, a recheck of how the offspring were scored or a test cross, and do not stop at the number.
Source: Original example by George Li Tutoring; every chi-square and p-value was computed in code.
A graphing calculator can run the test for you, which is allowed on many courses and exams. Enter the observed counts in one list and the expected counts in another, choose the goodness-of-fit test from its statistics menu, and give it the degrees of freedom. It returns the chi-square value and the p-value. Still write out the steps by hand once, because you need to be able to show the expected counts and the degrees of freedom.
What conditions must hold first?
Three checks come before any arithmetic. Sampling must be random, or the cross fair, so that each offspring counts as one independent observation and no individual is counted twice. You must work with counts of individuals in separate classes, and each individual belongs to exactly one class. And the expected count in every class should be at least 5, a common rule of thumb. When a class is too small, join it to a neighboring class or collect more offspring, and count the classes again to get the new degrees of freedom.
The cutoff of 0.05 is a convention that scientists agreed to use, not a law of nature. It says that you will call a result unusual when it would happen less than one time in twenty if the model were true. Some labs use 0.01 when a wrong rejection would be costly. Choose the level before you look at the result, and report the p-value as well as the decision.
One refinement matters when a model has a parameter that you estimate from the same data, such as a gene frequency. Each estimated parameter takes one more degree of freedom away, so the degrees of freedom are the number of classes minus 1 minus the number of parameters estimated. For a fully specified ratio such as 3 to 1 or 9 to 3 to 3 to 1, nothing is estimated, and the rule stays classes minus 1. The 0.10 column of a critical value table, 2.706 for one degree of freedom, is sometimes used as a looser screen, but the 0.05 level is the usual standard.
What if you compare two traits, or two groups?
The same statistic handles two other questions, and the difference is in how you find the expected counts. In a goodness-of-fit test the model hands you the expected counts. In a test of independence or homogeneity there is no model, so the expected counts come from the table itself: multiply the row total by the column total and divide by the grand total. The degrees of freedom are then (rows minus 1) times (columns minus 1).
- A test of independence takes one sample and records two traits on each individual, such as seed shape and seed color. The question is whether the two traits are associated.
- A test of homogeneity takes separate samples from two or more groups, such as two vials of flies, and records one trait. The question is whether the groups have the same proportions.
The arithmetic is identical, and the wording of the question is what differs.
Worked example: Are seed shape and seed color independent? A student scores 200 pea seeds from one cross and finds 98 round and yellow, 42 round and green, 36 wrinkled and yellow, and 24 wrinkled and green.
- The row totals are 140 round and 60 wrinkled, and the column totals are 134 yellow and 66 green.
- The expected counts are 140 times 134 over 200, which is 93.8, then 46.2, 40.2 and 19.8.
- Chi-square is 4.2 squared over 93.8, plus 4.2 squared over 46.2, plus 4.2 squared over 40.2, plus 4.2 squared over 19.8. That is 0.188 plus 0.382 plus 0.439 plus 0.891, which is 1.900.
- There are (2 minus 1) times (2 minus 1), or 1, degree of freedom, and the 0.05 critical value there reads 3.841. The p-value is about 0.17.
Answer: 1.900 is below 3.841, so the data give no evidence that the two traits are associated. That fits genes on different chromosomes.
Worked example: Do two vials show the same proportions? Vial A has 80 normal and 20 mutant flies, and vial B has 60 normal and 40 mutant. The totals are 140 normal and 60 mutant out of 200, so each vial of 100 is expected to have 70 and 30. Chi-square is 100/70 plus 100/30 plus 100/70 plus 100/30, which is 9.524. With 1 degree of freedom, 9.524 is above 6.635, and the p-value is about 0.002. The vials do not share the same proportions.
Method: original examples written for this page; every chi-square and p-value was computed in code.
How do you write the conclusion?
Say what you tested, what you found and what it means for the cross, in one or two sentences. For example: "With a chi-square of 2.667 and 1 degree of freedom, the p-value of about 0.10 is above 0.05, so the counts agree with a 3 to 1 ratio." Then add what you would do next, such as a larger sample. Avoid claiming that the cross follows the ratio for certain, and avoid saying that the result is due to chance alone.
What does the result mean, and what does it not?
A small chi-square means the data do not contradict the model. It does not prove the model, because many models can fit the same counts. A large chi-square means the data are hard to explain by chance if the model were true, so something about the model is off. The model may be wrong, the genes may be linked, some genotypes may be less likely to survive, or the sample may not have been random.
The common slip is in the wording. Write that the model is not rejected, or that the counts agree with the ratio, and never that the ratio is proven. In a lab report, say what you would test next, such as a larger sample or a test cross.
What mistakes cost points?
Using percentages in place of counts is the most common. Next come using the wrong degrees of freedom, which should be classes minus 1 and not the number of offspring minus 1, and computing expected counts from the observed ratio when they should come from the model. Last is mixing up which way the decision goes: a chi-square above the critical value rejects the model.
Keep a short check list on your lab bench: counts, model, expected, chi-square, degrees of freedom, critical value, decision in a sentence. The steps are the same for any ratio, including a 1 to 1 test cross or a 1 to 2 to 1 incomplete dominance cross.
For help with a lab or a course, see high school and exam prep tutoring, college course tutoring or book a first session. The study planner can set a weekly practice schedule.
Common questions
Why is the degrees of freedom classes minus 1?
Once you know the counts in all but one class and the total, the last count is fixed. So only classes minus 1 of them can vary freely.
What does a p-value of 0.10 mean here?
If the model were true, differences this large would occur about one time in ten by chance. That is not unusual, so the model is not rejected at the 0.05 level.
Can I use chi-square with small counts?
The test needs expected counts that are not tiny, and a common rule of thumb is at least 5 in each class. With very small samples, combine classes or gather more data.
What is the difference between a test of independence and a test of homogeneity?
A test of independence records two traits on one sample and asks whether they are associated. A test of homogeneity compares the proportions of one trait across separate groups. The arithmetic and the degrees of freedom are the same.
Does a good fit prove the cross is Mendelian?
No. It shows the counts are consistent with the model. Other models might fit as well.