ABD 3e Chapter 8
By the end of this lecture, you should be able to:
In biology, we often observe counts in categories:
But a key question is:
Do the observed counts match what we would expect under a probability model?
This is the central idea behind the chi-squared goodness-of-fit test.
Frequency data = counts of observations in each category of a single categorical variable.
Each row in the table tells us:
Frequency table showing the activities of 88 people at the time they were attacked and killed by tigers near Chitwan National Park, Nepal, from 1979 to 2006 (Table 2.2-1, Whitlock & Schluter 2015)
| Activity | Frequency (number of people) |
|---|---|
| Collecting grass or fodder for livestock | 44 |
| Collecting non-timber forest products | 11 |
| Fishing | 8 |
| Herding livestock | 7 |
| Disturbing tiger at its kill | 5 |
| Collecting fuel wood or timber | 5 |
| Sleeping in a house | 5 |
| Walking in forest | 3 |
| Using an outside toilet | 2 |
| Total | 88 |
A model is a simplified description of a system used to:
Types of models:
In this course, we focus on probability models.
A probability model describes how likely various outcomes are
In many biological problems, the null hypothesis assumes that outcomes occur in fixed proportions.
A proportional model states that:
We compare observed counts to these expected counts.
The binomial model is a special case with two categories.
Observed data: number of births on each day of the week.
Null hypothesis (proportional model):
If the model is correct:
Do these data appear consistent with equal proportions?
\(n=350\) births in the U.S. in 1999
The chi-squared goodness-of-fit test evaluates whether observed frequency data are consistent with a specified probability model.
It is used when:
It asks:
Are the observed frequencies close enough to what the model predicts?
Example: births by day of the week
Null hypothesis (proportional model):
\(H_0\): Births are equally likely on each day of the week.
Alternative hypothesis:
\(H_A\): Births are not equally likely on each day of the week.
Expected proportion for a day = (number of that day in 1999) / 365
Expected count = total births × that proportion
Proportions are therefore not exactly 1/7
| Day | Number of days in 1999 | Proportion of days in 1999 | Expected frequency of births |
|---|---|---|---|
| Sunday | 52 | 52/365 | 49.863 |
| Monday | 52 | 52/365 | 49.863 |
| Tuesday | 52 | 52/365 | 49.863 |
| Wednesday | 52 | 52/365 | 49.863 |
| Thursday | 52 | 52/365 | 49.863 |
| Friday | 53 | 53/365 | 50.822 |
| Saturday | 52 | 52/365 | 49.863 |
| Sum | 365 | 1 | 350 |
We need a way to measure the discrepancy between:
The chi-square statistic measures total discrepancy across all categories.
\[ \chi^2 = \sum \frac{(O - E)^2}{E} \]
For each category:
Large values of \(\chi^2\) indicate greater disagreement with the model.
Let’s calculate the chi-squared contribution for Sunday.
Observed births:
\(O = 33\)
Expected births:
\(E = 49.863\)
We plug these into the formula:
\[ \frac{(O - E)^2}{E} \]
\[ \frac{(33 - 49.863)^2}{49.863} \\=\frac{(-16.863)^2}{49.863} \\=\frac{284.36}{49.863} \\\approx 5.70 \]
Sunday contributes 5.70 to the total chi-squared statistic.
The total \(\chi^2\) is the sum of all days’ contributions.
\[ \chi^2 = \sum \frac{(O - E)^2}{E} \]
\[ \chi^2 = 15.05 \]
This value summarizes the total discrepancy between observed and expected frequencies.
| Day | Observed number of births | Expected number of births | \[ \frac{(O - E)^2}{E} \] |
|---|---|---|---|
| Sunday | 33 | 49.863 | 5.70 |
| Monday | 41 | 49.863 | 1.58 |
| Tuesday | 63 | 49.863 | 3.46 |
| Wednesday | 63 | 49.863 | 3.46 |
| Thursday | 47 | 49.863 | 0.16 |
| Friday | 56 | 50.822 | 0.53 |
| Saturday | 47 | 49.863 | 0.16 |
| Sum | 1 | 350 | 15.05 |
Assume the null hypothesis is true.
If we repeatedly take random samples of \(n = 350\) births and compute \(\chi^2\) each time:
Tells us how unusual our observed \(\chi^2\) value would be under \(H_0\).
\[ df=\\(\text{Number of categories})-1\\-(\text{Number of parameters}\\\text{ estimated from the data}) \]
\[ df = 7-1-0=6 \]
Choose a significance level \(\alpha\) (e.g., 0.05).
Decision rule:
When using software:
When working by hand:
Both approaches lead to the same conclusion.
In general, a critical value is the value of a test statistic that marks the boundary of a specified area in the tail (or tails) of the sampling distribution under \(H_0\).
After comparing \(P\) to \(\alpha\):
If \(P \le \alpha\):
Reject \(H_0\).
The data provide evidence that the observed frequencies differ from the proportions specified by the null model.
If \(P > \alpha\):
Fail to reject \(H_0\).
The data are consistent with the null model.
Example:
Important:
Rejecting \(H_0\) does not prove the model is false.
Failing to reject \(H_0\) does not prove the model is true.
We are evaluating evidence, not proving certainty.
For the chi-squared approximation to be valid:
1. Independence
2. Correct null model
3. Expected count conditions
| Test | Scientific Question | Data Structure | Distribution Used | Lecture | R Function |
|---|---|---|---|---|---|
| Binomial test | Is a single proportion equal to a hypothesized value (e.g., \(p = 0.3\))? | One group, two outcomes | Exact binomial | Lecture 9 | binom.test() |
| Chi-squared test for proportions | Is a proportion equal to a hypothesized value (large \(n\)), or do two group proportions differ? | One or two groups, two outcomes | Chi-squared (approximation) | Lecture 10 | prop.test() |
| Chi-squared test of independence | Are two categorical variables associated? | Two variables, \(r \times c\) table | Chi-squared | Lecture 12 | chisq.test() |
Notes:
prop.test() and the chi-squared test of independence are mathematically equivalent.prop.test() because our sample size was large, making the chi-squared approximation appropriate and computationally efficient.
BIOL 275 Biostatistics | Spring 2026