Skip to main content

Chi-squared test calculator

Paste a contingency table (one row per line) for a test of independence, or a list of observed frequencies for goodness of fit. Every expected value is shown, so you can check your own table.

Numbers separated by spaces or commas.

χ² = 4.38, df = 2, p = 0.112
χ² statistic
4.38
Degrees of freedom
2
p-value
0.112
Critical value (5%)
5.99
Graph loads here
Show the working

H0: the two variables are independent. H1: they are not independent.

Expected frequencies: E = (row total × column total) ÷ grand total, with grand total 110.

Observed (expected)
Column 1Column 2Column 3
Row 118 (13.6)22 (22.7)10 (13.6)
Row 212 (16.4)28 (27.3)20 (16.4)

χ²calc = Σ (O − E)² ÷ E = 4.38

Degrees of freedom = (rows − 1)(columns − 1) = (2 − 1)(3 − 1) = 2

p-value = P(χ²2 ≥ 4.38) = 0.112; critical value at 5% = 5.99

p = 0.112 ≥ 0.05, so there is not enough evidence to reject H0 at the 5% level. (Equivalently, χ²calc ≤ the critical value.)

Answers are rounded to 3 significant figures, which is what IB papers ask for unless a question says otherwise.

How to do it by hand

  1. State the hypotheses. Independence: H₀ the variables are independent. Goodness of fit: H₀ the data follow the given distribution.
  2. Work out each expected frequency: (row total × column total) ÷ grand total for a contingency table, or probability × total for goodness of fit. Combine categories if any expected frequency is below 5.
  3. χ² = Σ (O − E)² ÷ E. Degrees of freedom: (rows − 1)(columns − 1), or categories − 1 − parameters estimated.
  4. Compare the p-value with the significance level (or χ² with the critical value) and give the conclusion in context.

Worked example

A school asks 150 students which of three lunch options they prefer, split by year group. Test at the 5% level whether preference is independent of year group. Year 12: 30, 25, 20. Year 13: 20, 35, 20.

Solution

H0: the two variables are independent. H1: they are not independent.

Expected frequencies: E = (row total × column total) ÷ grand total, with grand total 150.

Observed (expected)
Column 1Column 2Column 3
Row 130 (25.0)25 (30.0)20 (20.0)
Row 220 (25.0)35 (30.0)20 (20.0)

χ²calc = Σ (O − E)² ÷ E = 3.67

Degrees of freedom = (rows − 1)(columns − 1) = (2 − 1)(3 − 1) = 2

p-value = P(χ²2 ≥ 3.67) = 0.160; critical value at 5% = 5.99

p = 0.160 ≥ 0.05, so there is not enough evidence to reject H0 at the 5% level. (Equivalently, χ²calc ≤ the critical value.)

Answer: χ² = 3.67, df = 2, p = 0.160

Every number in this example is worked out by the same code as the tool above, and the code is tested against independent results from Python's SciPy library.

Where you need it

Where it is used in IB Maths
AA SLNot in the syllabus
AA HLNot in the syllabus
AI SLχ² tests for independence and goodness of fit.
AI HLχ² tests for independence and goodness of fit.

On your calculator

In the exam you use your own calculator, so practise it too. Our guides give the exact keystrokes for the Casio fx-CG50, TI-Nspire CX II and TI-84 Plus CE, with a worked example to check against:

Common mistakes

Questions students ask

What is the difference between a test for independence and a goodness of fit test?

Independence uses a two-way table to ask whether two variables are related. Goodness of fit uses one list of counts to ask whether they follow a given distribution, such as equally likely outcomes.

How do I find the degrees of freedom?

For an r × c contingency table it is (r − 1)(c − 1). For goodness of fit with k categories it is k − 1, minus one more for each parameter you estimated from the data.

Does this tool apply Yates' continuity correction?

No. For 2 × 2 tables some textbooks use Yates' correction; graphic calculators do not, and this tool matches them. If your course uses it, the χ² value will be slightly smaller.

More maths tools