Statistics & Probability · Grades 11, 12
Chi-Square Tests: Goodness of Fit and Independence
Quick answer
A chi-square test asks whether observed counts differ from expected counts by more than chance allows. The statistic χ² = Σ(O − E)²/E adds up the squared gaps, each scaled by its expected count. A goodness-of-fit test compares one variable with a claimed distribution, using k − 1 degrees of freedom for k categories. A test of independence compares a two-way table with the counts expected if the variables were unrelated, using (rows − 1)(columns − 1) degrees of freedom.
What you'll learn
- Compute expected counts and the χ² statistic
- Run a goodness-of-fit test
- Run a test of independence on a two-way table
- Find degrees of freedom and interpret the p-value
Observed against expected
A die is rolled times. If it is fair, each face should come up about times. The counts are:
| Face | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Observed | ||||||
| Expected |
Is the die loaded, or is this ordinary luck? The chi-square statistic measures the total mismatch:
Why the gaps are squared and scaled
Squaring makes every gap count as positive, so a surplus in one category cannot cancel a shortage in another, and it weights big gaps more heavily. Dividing by judges each gap against the size of its category: being off where were expected is a lot, where were expected it is noise. Under the null hypothesis, each term behaves like the square of a standardized gap, so is a sum of squared z-scores, and its sampling distribution, the chi-square distribution, is known. Its shape depends on the degrees of freedom: for categories, , since the counts must add to the total and the last one is not free.
- chi-square, 5 df
For the die, with degrees of freedom gives a p-value of about . At (critical value ), we reject the hypothesis that the die is fair: six came up far too often.
Worked examples
Common mistakes
Practice problems
-
A coin lands heads times in tosses. Compute for the fair-coin hypothesis.
Answer
Full solution
. With degree of freedom the p-value is about : no evidence of bias.
-
A bag of candies of colors, claimed equally common, has counts , , , . Find and decide at (critical value ).
Answer
; fail to reject
Full solution
. The p-value is about .
-
How many degrees of freedom does a test of independence on a table have?
Answer
Full solution
.
-
In a two-way table, a row total is , a column total is and the grand total is . Find that cell’s expected count.
Answer
Full solution
.
-
Why is the χ² statistic never negative?
Answer
It is a sum of squares divided by positive expected counts.
Full solution
Each term is at least , and it is only when every observed count equals its expected count.
-
In Example 2, what would the observed counts be if the treatments worked equally well, with the same totals?
Answer
and in each row, the expected counts
Full solution
Equal success rates of in both groups give improved in each. Then .
-
A goodness-of-fit test gives with degrees of freedom. Using the critical value , what do you conclude at ?
Answer
Fail to reject the null hypothesis.
Full solution
is well below the critical value, so the data are consistent with the claimed distribution.
-
A student computes for the die using . What is wrong?
Answer
The denominator must be the expected count .
Full solution
The test asks how unusual the observations are under the null hypothesis, so gaps are scaled by what the null predicts, .
Frequently asked questions
What does a chi-square test measure?
How far observed counts are from the counts expected under a null hypothesis, through χ² = Σ(O − E)²/E. The bigger χ², the stronger the evidence against the null.
What is a goodness-of-fit test?
A test of whether one categorical variable follows a claimed distribution, such as a fair die landing on each face 1/6 of the time. It has k − 1 degrees of freedom for k categories.
What is a chi-square test of independence?
A test of whether two categorical variables in a two-way table are related. The expected count for each cell is (row total × column total)/grand total, and there are (r − 1)(c − 1) degrees of freedom.
Why divide by the expected count?
A gap of 10 matters more when 20 were expected than when 1,000 were. Dividing by E scales each gap to the size of its category.
When is the chi-square test valid?
When the data are counts from a random sample and every expected count is at least 5.
Standards alignment
This lesson covers the following Common Core State Standards for Mathematics.
- CCSS.MATH.CONTENT.HSS.IC.B.5Making Inferences and Justifying ConclusionsUse data from a randomized experiment to compare two treatments; use simulations to decide if differences between parameters are significant.
- CCSS.MATH.CONTENT.HSS.CP.A.4Conditional Probability and the Rules of ProbabilityConstruct and interpret two-way frequency tables of data when two categories are associated with each object being classified. Use the two-way table as a sample space to decide if events are independent and to approximate conditional probabilities.