BioCentral IB
BioCentral IB
BioCentral IB

Internal assessment › Statistics

The chi-squared (χ²) test

FreeAbout 12 minutesOpen the calculator
Named in the guide: yes p. 31, Tool 3: Mathematics Goodness of fit: D3.2.21 (HL) p. 101, syllabus statement D3.2.21 Association: C4.1.15 p. 83, syllabus statement C4.1.15 In the data booklet: formula and critical values
01

When to use it

Your data are counts in categories: individuals, seeds or quadrats sorted into groups. Two versions:

  • Goodness of fit: do the counts fit a ratio you predicted beforehand, such as 9:3:3:1 from a dihybrid cross?
  • Test of association: are two ways of sorting the same individuals linked? For example, is species A found with species B more or less often than chance would give?

Open the flowchart

02

Assumptions, in plain words

  • The numbers are raw counts: not percentages, not means, not measurements.
  • Each individual (or quadrat) is counted once, in one category only.
  • The categories were decided before counting.
  • Each expected count E should be at least 5 (a common rule of thumb; the guide and booklet don't set one). If not, merge categories or collect more data.
03

The hypotheses

Goodness of fit

H0
The F2 phenotypes occur in the ratio 9:3:3:1.
H1
The F2 phenotypes do not occur in the ratio 9:3:3:1.

Association

H0
The presence of species A is independent of the presence of species B (no association).
H1
Presence of species A is associated with presence of species B.
04

How to calculate it

Data booklet formula (Oi = observed, Ei = expected) χ2 = Σ (Oi − Ei)2Ei
  • Expected counts, goodness of fit: E = total count × that category's share of the ratio. For 9:3:3:1, the first share is 9/16.
  • Expected counts, association: E = row total × column total ÷ grand total, for each cell.
  • Degrees of freedom: goodness of fit, df = number of categories − 1. Association, df = (rows − 1) × (columns − 1).
  • Compare χ2 with the data booklet's critical value for your df at p = 0.05.
  • Spreadsheet: =CHISQ.TEST(observed range, expected range) returns p, once you have worked out the expected counts. =CHISQ.INV.RT(0.05, df) gives the critical value.
  • No correction: the booklet formula is used as it stands, with no continuity (Yates) correction for 2 × 2 tables. The calculator does the same. Some textbooks apply one; the guide and booklet do not mention it.
05

Worked examples

Invented data, written for teaching, checked with SciPy.

Goodness of fit: F2 offspring of a cereal plant with two kernel traits, against 9:3:3:1

Kernel phenotype counts, N = 552. Colour gene: allele A dominant to a; shape gene: allele B dominant to b. A_ means AA or Aa.
PhenotypeOE(O − E)² / E
A_B_ (dominant colour, dominant shape)312310.50.0072
A_bb (dominant colour, recessive shape)98103.50.2923
aaB_ (recessive colour, dominant shape)109103.50.2923
aabb (recessive colour, recessive shape)3334.50.0652
Total552552.0χ² = 0.6570
  1. E for A_B_ = 552 × 9/16 = 310.5. The others: 552 × 3/16 = 103.5, and 552 × 1/16 = 34.5.
  2. χ2 = 0.0072 + 0.2923 + 0.2923 + 0.0652 = 0.6570 (0.657 to 3 decimal places); df = 4 − 1 = 3.
  3. Critical value (data booklet, df 3, p = 0.05) = 7.81. 0.657 < 7.81; p = 0.883.

Load this into the calculator

Association: species A and species B in 40 quadrats

Observed counts of quadrats (expected counts in brackets)
B presentB absentRow total
A present6 (11)16 (11)22
A absent14 (9)4 (9)18
Column total202040
  1. E for “both present” = 22 × 20 ÷ 40 = 11. The other cells: 11, 9 and 9.
  2. χ2 = 2.2727 + 2.2727 + 2.7778 + 2.7778 = 10.1010 (10.101 to 3 decimal places); df = (2 − 1) × (2 − 1) = 1.
  3. Critical value (data booklet, df 1, p = 0.05) = 3.84. 10.101 > 3.84; p = 0.0015.

Look at the cells: A and B were found together in 6 quadrats where 11 were expected. They occur together less often than chance would give, which may point to interspecific competition. The test alone cannot show the cause. p. 83, syllabus statement C4.1.15

Python's SciPy and R's chisq.test apply Yates to 2 × 2 tables by default (8.18 here instead of 10.10); switch it off to match the booklet.

Load this into the calculator

06

How to report it: fill in the blanks

A χ2 goodness of fit / association test was used because the data are describe your data. H0: your null hypothesis. χ2 = value, df = value; the critical value at p = 0.05 is value. Because χ2 is below / above the critical value, H0 is rejected / not rejected.

Write the sentences yourself and name the software you used.

07

How to read the result

  • χ2 below the critical value: the gaps between O and E are small enough that chance alone could explain them. The counts are consistent with the ratio; that does not prove it.
  • χ2 at or above the critical value: evidence against H0. For association, compare O with E cell by cell to see the direction: together more often than expected, or less.
08

The graph that goes with it

0100200300 A_B_A_bbaaB_aabb Number of kernelsPhenotype observedexpected (9:3:3:1)
Observed beside expected counts for each category (A/a = colour alleles, B/b = shape alleles; capitals are dominant alleles). For association, a two-way table like the one above is usually clearer than a chart.
09

Common mistakes

  1. Using percentages or means instead of counts.
  2. Ignoring expected counts below 5. Each expected count E should be at least 5 (a common rule of thumb; the guide and booklet don't set one).
  3. The wrong df: the number of individuals instead of the number of categories.
  4. Saying the test “proves” the ratio. Evidence can support a claim but never prove it with certainty. p. 7, Nature of science
  5. Counting one quadrat or individual in two cells.
  6. Treating an association as proof of competition, or of any cause. p. 7, Nature of science; p. 83, syllabus statement C4.1.14
10

Named in the guide?

Yes. Tool 3 names the chi-squared test p. 31, Tool 3: Mathematics. D3.2.21 (HL) uses it on dihybrid crosses, with the p = 0.05 level, null and alternative hypotheses, and observed versus expected p. 101, syllabus statement D3.2.21. C4.1.15 uses it for association between two species from presence and absence data p. 83, syllabus statement C4.1.15. The formula and the critical values for df 1 to 8 are in the data booklet.