01 / 20
\(\chi^2\)

Chi-Square
Goodness-of-Fit

Learn how to test whether observed data matches an expected distribution using the \(\chi^2\) goodness-of-fit test: a cornerstone of biostatistics.

Biostatistics

What Is the \(\chi^2\) Test?

The chi-square goodness-of-fit test is a non-parametric hypothesis test that determines whether a set of observed frequencies differs significantly from a set of expected frequencies.

It is widely used in genetics, ecology, epidemiology, and clinical trials to compare observed outcomes against theoretical models.

Key Vocabulary

Observed (\(O\))
The actual count you measure or record from your experiment or survey.
Expected (\(E\))
The count predicted by the null hypothesis or theoretical distribution.
Degrees of Freedom
\(df = k - 1\), where \(k\) is the number of categories.

When Do We Use It?

1
One categorical variable with two or more levels (e.g., phenotype colors, blood types).
2
A theoretical model predicts the expected proportions (e.g., Mendelian 9:3:3:1 ratio).
3
Data are independent observations: each subject is counted in exactly one category.
4
Expected counts \(\geq 5\) in every category (rule of thumb for validity).

The \(\chi^2\) Formula

\(O_i\)
Observed count in category \(i\)
\(E_i\)
Expected count in category \(i\)
\(k\)
Total number of categories

Each term measures how far an observed count deviates from its expectation, scaled by the expected count. Squaring ensures all deviations contribute positively.

The \(\chi^2\) Distribution

\(\chi^2\) statistic Density 0 3 6 9 12 15
\(df = 2\)
\(df = 4\)
\(df = 6\)

Setting Up Hypotheses

\(H_0\): Null Hypothesis
The observed data follow the expected distribution. Any differences are due to random sampling variation.
\(H_a\): Alternative Hypothesis
The observed data do not follow the expected distribution. At least one category differs significantly.

Goodness-of-Fit vs Independence

Goodness-of-Fit Test of Independence
Variables 1 categorical variable 2 categorical variables
Data Layout Single row of counts Two-way contingency table
Question Does data fit a model? Are the variables related?
Degrees of Freedom \(k - 1\) \((r-1)(c-1)\)
Example Is a die fair? Is drug response related to gender?

Step-by-Step Procedure

1
State hypotheses. Write \(H_0\) (data fits the model) and \(H_a\) (data does not fit).
2
Calculate expected counts. Multiply total \(n\) by each expected proportion: \(E_i = n \cdot p_i\).
3
Check conditions. All \(E_i \geq 5\) and observations are independent.
4
Compute the test statistic. \(\chi^2 = \sum \frac{(O_i - E_i)^2}{E_i}\).
5
Find the p-value. Use the \(\chi^2\) table with \(df = k - 1\). Compare to \(\alpha\).
6
Make a decision. If \(p \leq \alpha\), reject \(H_0\): the data do not fit the model.

Example 1: Fair Die

A die is rolled 60 times. If it is fair, we expect each face to appear \(E = 60/6 = 10\) times. The observed results are:

1 2 3 4 5 6 10 8 12 9 7 14 Observed Expected (10)

Example 1: Decision

1
Test statistic: \(\chi^2 = 3.4\).
2
Degrees of freedom: \(df = 6 - 1 = 5\).
3
Critical value at \(\alpha = 0.05\): \(\chi^2_{0.05, 5} = 11.07\).
4
Decision: Since 3.4 < 11.07, we fail to reject \(H_0\).

Example 2: Mendelian Genetics

A dihybrid cross predicts a 9:3:3:1 phenotype ratio. A biologist observes 160 offspring:

Phenotype Observed (\(O\)) Expected (\(E\)) \(\frac{(O-E)^2}{E}\)
Round Yellow 98 90 0.711
Round Green 28 30 0.133
Wrinkled Yellow 26 30 0.533
Wrinkled Green 8 10 0.400

Example 3: A Significant Result

A hospital tests whether patient admissions are evenly distributed across 4 departments. With 200 total admissions, each department should have \(E = 50\). Observed data:

Department \(O\) \(E\) \(\frac{(O-E)^2}{E}\)
Cardiology72509.68
Neurology38502.88
Orthopedics55500.50
Oncology35504.50

Understanding the P-value

\(\chi^2_{\text{crit}}\)= 7.815 Rejection Region (p < 0.05) Fail to Reject \(\chi^2\) statistic

Common Mistakes

✕ Using Percentages
Plugging in proportions (0.25) instead of raw counts (25). The formula requires actual frequencies.
✕ Ignoring Conditions
Running the test when expected counts are below 5. Combine small categories or use Fisher's exact test instead.
✕ Wrong df
Using \(df = k\) instead of \(df = k - 1\). Always subtract 1 from the number of categories for GOF.

Question 1 of 5

A researcher observes 200 organisms in 4 categories with expected proportions of 25% each. What are the expected counts for each category?

Question 2 of 5

A \(\chi^2\) goodness-of-fit test is run with 6 categories. What are the degrees of freedom?

Question 3 of 5

In a \(\chi^2\) GOF test, the calculated \(\chi^2 = 12.4\) and the critical value at \(\alpha = 0.05\) is \(9.49\). What is the correct conclusion?

Question 4 of 5

Which condition must be met before performing a \(\chi^2\) goodness-of-fit test?

Question 5 of 5

A biologist crosses plants expecting a 3:1 ratio. Of 80 offspring, 54 show the dominant trait and 26 the recessive. What is \(\chi^2\)?