AP subjects/AP Biology/Chi-Square Goodness-of-Fit Calculator
CED 5.6AP Biology

Chi-Square Goodness-of-Fit Calculator

Use this free chi-square calculator to run a goodness-of-fit test on genetic-cross data. Enter observed and expected counts, and it calculates χ2\chi^2, the degrees of freedom, and the critical value at p=0.05p = 0.05, then tells you whether to reject the hypothesis.

chi-square also a cross-cutting stats practice; see REVIEW_NEEDED

Controls
presetobservedexpected

How to use the simulator

The simulator opens with Mendel's dihybrid data already loaded. It has these controls:
  • Preset cross menu. Pick Monohybrid 3:1 (2 classes), Incomplete dom. 1:2:1 (3 classes) or Dihybrid 9:3:3:1 (4 classes). Choosing a preset loads its category names and sample observed counts, and calculates the expected counts from the ratio.
  • Observed and Expected columns. Every count is a number box you can edit. Type in the counts from a lab or an exam question and the results update as you type.
  • Fill expected from ratio button. Rescales the selected preset's ratio to the total of your current observed counts and rewrites the Expected column, rounded to two decimal places. Click it each time you change the observed numbers, so that the expected counts add up to the same total.
The results box shows:
  • χ2\chi^2 statistic, to three decimal places
  • degrees of freedom: the number of categories with an expected count above zero, minus 1
  • critical value (α\alpha=0.05): the table value for that df (the simulator shows 3.841, 5.991 and 7.815, which the AP table rounds to 3.84, 5.99 and 7.81)
  • A verdict bar that reads either REJECT the hypothesis (deviation is significant) or FAIL TO REJECT (deviation likely due to chance)
In the bar chart, solid bars are observed counts and outlined bars are expected counts. Wherever the two heights differ a lot, that category adds a large share of χ2\chi^2.
The number of rows is fixed by the preset (2, 3 or 4 categories). For a cross with a different ratio, pick the preset with the right number of categories and type both columns yourself. Do not use the ratio button in that case, because it would overwrite your expected counts with the preset ratio.

The formula

χ2=∑(O−E)2E\chi^2 = \sum \frac{(O - E)^2}{E}
  • OO is the observed count in a category and EE is the expected count in that category.
  • Calculate (O−E)2/E(O - E)^2 / E for each category, then add all of them together.
  • Expected counts come from the hypothesis: (total observed) ×\times (that category's fraction of the ratio). For a 9:3:3:1 ratio, the fractions are 9/16, 3/16, 3/16 and 1/16.
  • Degrees of freedom: df=number of categories−1\text{df} = \text{number of categories} - 1.
Critical values at p=0.05p = 0.05 from the AP Biology table: 3.84 (df = 1), 5.99 (df = 2), 7.81 (df = 3), 9.49 (df = 4).
The decision rule: if χ2\chi^2 is greater than the critical value, reject the null hypothesis, because the difference between observed and expected is too large to be explained by chance alone. If χ2\chi^2 is less than or equal to the critical value, fail to reject it.

Worked example

Problem: A dihybrid cross (AaBb ×\times AaBb) produces 556 offspring: 315 A_B_, 108 A_bb, 101 aaB_ and 32 aabb. Do these results fit the 9:3:3:1 ratio expected for two independently assorting genes?
Step 1: State the null hypothesis. The genes assort independently, so the offspring classes occur in a 9:3:3:1 ratio. Any deviation is due to chance.
Step 2: Calculate expected counts. The total is 315+108+101+32=556315 + 108 + 101 + 32 = 556.
A_B_: 556×9/16=312.75556 \times 9/16 = 312.75
A_bb: 556×3/16=104.25556 \times 3/16 = 104.25
aaB_: 556×3/16=104.25556 \times 3/16 = 104.25
aabb: 556×1/16=34.75556 \times 1/16 = 34.75
Step 3: Calculate each term.
A_B_: (315−312.75)2/312.75=5.0625/312.75=0.0162(315 - 312.75)^2 / 312.75 = 5.0625 / 312.75 = 0.0162
A_bb: (108−104.25)2/104.25=14.0625/104.25=0.1349(108 - 104.25)^2 / 104.25 = 14.0625 / 104.25 = 0.1349
aaB_: (101−104.25)2/104.25=10.5625/104.25=0.1013(101 - 104.25)^2 / 104.25 = 10.5625 / 104.25 = 0.1013
aabb: (32−34.75)2/34.75=7.5625/34.75=0.2176(32 - 34.75)^2 / 34.75 = 7.5625 / 34.75 = 0.2176
Step 4: Add the terms. χ2=0.0162+0.1349+0.1013+0.2176=0.470\chi^2 = 0.0162 + 0.1349 + 0.1013 + 0.2176 = 0.470.
Step 5: Compare with the critical value. There are 4 categories, so df = 3 and the critical value is 7.81. Since 0.470<7.810.470 < 7.81, we fail to reject the null hypothesis. The data are consistent with independent assortment.
Check it in the simulator: this is the dihybrid preset that loads when the page opens. The results box should show 0.470, df 3, critical value 7.815, and the verdict FAIL TO REJECT.

Common mistakes on the AP exam

  • Using percentages or ratios instead of counts. Chi-square only works with raw counts. Entering 76 and 24 (percent) when the real counts were 152 and 48 gives the wrong χ2\chi^2.
  • Wrong degrees of freedom. df is the number of categories minus 1, not the number of offspring minus 1. A dihybrid cross with four phenotype classes has df = 3.
  • Dividing by O instead of E. The denominator is always the expected count.
  • Forgetting to square, or squaring the sum. Square each (O−E)(O - E) on its own, divide by E, and only then add. The plain differences (O−E)(O - E) always add up to zero.
  • Saying the hypothesis is "proven" or "accepted." A low χ2\chi^2 means you fail to reject the null hypothesis. It does not prove the hypothesis is true.
  • Stating a conclusion without the comparison. Free-response answers should give the χ2\chi^2 value, the df, the critical value, the comparison (for example 0.470<7.810.470 < 7.81) and what it means biologically.

When the AP exam uses this

Chi-square appears in topic 5.6 (Chromosomal Inheritance) for testing genetic-cross ratios, and the formula and critical value table are on the AP Biology formula sheet. Expect it with Mendelian crosses, linked genes (where a reject verdict points to linkage) and Hardy-Weinberg expected counts.
Embed this simulator on your class page

Free for classroom use. Paste this into your site, LMS page or blog; keep the credit link under it.