impera Open Impera

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?

  • Accept H₀

  • Reject H₀

  • Do not reject H₀

  • Accept H₁ as proved

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.

  1. $H_0$: the variables are independent. $H_1$: they are not independent.
  2. Expected frequency for each cell $= \frac{\text{row total} \times \text{column total}}{\text{grand total}}$.
  3. The calculator finds $\chi^2_{\text{calc}} = \sum \frac{(O - E)^2}{E}$ and the p-value.
  4. Degrees of freedom $= (\text{rows} - 1)(\text{columns} - 1)$.
  5. 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.

Worked example

Gender and favourite activity

  1. 100 students: male–sport 30, male–music 20, female–sport 20, female–music 30.
  2. Every row and column total is 50, so every expected frequency is $\frac{50 \times 50}{100} = 25$.
  3. $\chi^2 = 4 \times \frac{5^2}{25} = 4$, with $(2 - 1)(2 - 1) = 1$ degree of freedom.
  4. The p-value is 0.0455, which is less than 0.05. (Equivalently, 4 > the critical value 3.841.)
  5. 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?

  • 6

  • 7

  • 12

  • 5

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.)
Worked example

Is the die fair?

  1. A die is rolled 60 times: 8, 9, 12, 11, 6, 14 for faces 1 to 6.
  2. If fair, each expected frequency is 10.
  3. $\chi^2 = \frac{4 + 1 + 4 + 1 + 16 + 16}{10} = 4.2$, with $6 - 1 = 5$ degrees of freedom.
  4. The p-value is 0.521, which is greater than 0.05 (and 4.2 < the critical value 11.07).
  5. 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?

  • 6

  • 8

  • 7

  • 9

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.
Worked example

Does a new method help?

  1. Group A (new method) scores: 12, 15, 14, 10, 13, 16. Group B (old method): 9, 11, 10, 8, 12, 10.
  2. Means: 13.33 and 10. $H_0$: $\mu_A = \mu_B$; $H_1$: $\mu_A > \mu_B$.
  3. The calculator's pooled 2-sample t-test gives $t = 3.16$ and p-value $= 0.00506$.
  4. $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?

  • μ_X = μ_Y

  • μ_X ≠ μ_Y

  • μ_X > μ_Y

  • μ_X < μ_Y

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}}$.

Worked example

Preferred drink by age group (200 people)

  1. 120 people are under 30; 90 people prefer tea.
  2. Expected number under 30 who prefer tea: $\frac{120 \times 90}{200} = 54$.
  3. 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?

  • 12

  • 7

  • 6

  • 5

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

  1. $H_0$: drink preference is independent of age group. $H_1$: they are not independent.
  2. Significance level: 5%.
  3. p-value from GDC: 0.012.
  4. Since $0.012 < 0.05$, reject $H_0$.
  5. 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?

  • Accept $H_1$ as proven beyond any doubt

  • Reject $H_0$; there is enough evidence for $H_1$

  • Do not reject $H_0$; there is insufficient evidence

  • The test is invalid and must be repeated

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