IB Diploma Mathematics AI · Statistics and probability
Chi-squared tests and the t-test
1Hypothesis testing
A hypothesis test uses sample data to decide between two statements about a population.
- The null hypothesis $H_0$ is the "nothing special" statement: no association, no difference, the data fit the model.
- The alternative hypothesis $H_1$ is what you suspect instead.
- The significance level (often 5%) is how unlikely the data must be under $H_0$ before you reject it.
- The p-value is the probability of getting results at least as extreme as the sample, if $H_0$ is true.
Decision: if the p-value is less than the significance level, reject $H_0$. Otherwise, do not reject $H_0$. Never say $H_0$ is "proved" or "accepted".
Always write the conclusion in context.
Check yourself
The p-value is 0.03 and the significance level is 5%. What is the decision?
Show the answer
Reject H₀
0.03 is less than 0.05.
2The chi-squared test for independence
This test checks whether two categorical variables are independent, using a contingency table of observed counts.
- $H_0$: the variables are independent. $H_1$: they are not independent.
- Expected frequency for each cell $= \frac{\text{row total} \times \text{column total}}{\text{grand total}}$.
- The calculator finds $\chi^2_{\text{calc}} = \sum \frac{(O - E)^2}{E}$ and the p-value.
- Degrees of freedom $= (\text{rows} - 1)(\text{columns} - 1)$.
- Compare the p-value with the significance level (or $\chi^2_{\text{calc}}$ with the critical value).
All expected frequencies should be at least 5. If not, combine rows or columns.
Gender and favourite activity
- 100 students: male–sport 30, male–music 20, female–sport 20, female–music 30.
- Every row and column total is 50, so every expected frequency is $\frac{50 \times 50}{100} = 25$.
- $\chi^2 = 4 \times \frac{5^2}{25} = 4$, with $(2 - 1)(2 - 1) = 1$ degree of freedom.
- The p-value is 0.0455, which is less than 0.05. (Equivalently, 4 > the critical value 3.841.)
- Reject $H_0$: at the 5% level, there is evidence that favourite activity is not independent of gender.
Check yourself
A contingency table has 3 rows and 4 columns. How many degrees of freedom are there?
Show the answer
6
(3 − 1)(4 − 1) = 6.
3The chi-squared goodness of fit test
This test checks whether observed data fit a given distribution (such as equal frequencies, or a binomial model).
- $H_0$: the data fit the distribution. $H_1$: they do not.
- Expected frequencies come from the model.
- Degrees of freedom = number of categories − 1. (In Maths AI HL, subtract one more for each parameter estimated from the data.)
Is the die fair?
- A die is rolled 60 times: 8, 9, 12, 11, 6, 14 for faces 1 to 6.
- If fair, each expected frequency is 10.
- $\chi^2 = \frac{4 + 1 + 4 + 1 + 16 + 16}{10} = 4.2$, with $6 - 1 = 5$ degrees of freedom.
- The p-value is 0.521, which is greater than 0.05 (and 4.2 < the critical value 11.07).
- Do not reject $H_0$: there is not enough evidence that the die is biased.
The chi-squared distribution with 5 degrees of freedom: the die test falls outside the critical region
Check yourself
A goodness of fit test has 8 categories and no estimated parameters. How many degrees of freedom are there?
Show the answer
7
Number of categories minus 1.
4The t-test
The t-test compares the means of two groups, to see whether the difference is significant or could be due to chance.
- Assumes both populations are roughly normal with equal variances, and the samples are random and independent. (This is the "pooled" two-sample t-test.)
- $H_0$: $\mu_1 = \mu_2$ (no difference in means).
- $H_1$: $\mu_1 \ne \mu_2$ (two-tailed), or $\mu_1 > \mu_2$ or $\mu_1 < \mu_2$ (one-tailed), depending on the question's wording.
Does a new method help?
- Group A (new method) scores: 12, 15, 14, 10, 13, 16. Group B (old method): 9, 11, 10, 8, 12, 10.
- Means: 13.33 and 10. $H_0$: $\mu_A = \mu_B$; $H_1$: $\mu_A > \mu_B$.
- The calculator's pooled 2-sample t-test gives $t = 3.16$ and p-value $= 0.00506$.
- $0.00506 < 0.05$, so reject $H_0$: there is evidence that the new method gives higher mean scores.
Read the question for the direction: "is there a difference" is two-tailed; "is A greater than B" is one-tailed.
Check yourself
A question asks "is the mean time for group X less than for group Y?" Which alternative hypothesis fits?
Show the answer
μ_X < μ_Y
It is a one-tailed test in the direction stated.
5Expected frequencies in a contingency table
For a test for independence, expected frequency $= \frac{\text{row total} \times \text{column total}}{\text{grand total}}$.
Preferred drink by age group (200 people)
- 120 people are under 30; 90 people prefer tea.
- Expected number under 30 who prefer tea: $\frac{120 \times 90}{200} = 54$.
- If any expected frequency is below 5, combine categories before testing.
Degrees of freedom: $(\text{rows} - 1)(\text{columns} - 1)$. A 3 × 2 table has $2 \times 1 = 2$ degrees of freedom.
Check yourself
What are the degrees of freedom for a 3 × 4 contingency table?
Show the answer
6
$(3 - 1)(4 - 1)$.
6Writing a hypothesis test conclusion
A good conclusion compares the p-value with the significance level and answers in context.
Worked example
- $H_0$: drink preference is independent of age group. $H_1$: they are not independent.
- Significance level: 5%.
- p-value from GDC: 0.012.
- Since $0.012 < 0.05$, reject $H_0$.
- Conclusion: there is sufficient evidence at the 5% level that drink preference depends on age group.
Avoid saying a test "proves" anything; it gives evidence.
Check yourself
If the p-value is 0.08 at the 5% significance level, what do you conclude?
Show the answer
Do not reject $H_0$; there is insufficient evidence
$0.08 > 0.05$.
Now test yourself
This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.
Practise in Impera