Chi-Square Test Formula

Chi-square test is a hypothesis test that compares observed frequencies to expected frequencies using the chi-square statistic to assess independence or goodness of fit.

The Formula

χ2=∑(Observed−Expected)2Expected

Ask yourself: Are the data counts of cases falling into categories, being compared to expected counts (rather than means or continuous values)?

Quick example

Roll a die 60 times. Expected: 10 per face. Observed: 8, 12, 11, 7, 13, 9. χ2=(8−10)210+(12−10)210+⋯+(9−10)210=2.8 Compare to χ2 critical value with df=5. Not significant—die appears fair.

Notation

χ2 is the test statistic. Degrees of freedom: goodness-of-fit df=k−1; independence/homogeneity df=(r−1)(c−1).

What this formula means

A hypothesis test that compares observed frequencies to expected frequencies using the chi-square statistic to assess independence or goodness of fit.

The chi-square statistic is a surprise score for a tally sheet. Each category adds its own surprise, the squared miss scaled by what was expected, and the total says how far the whole sheet strays from the prediction. Like any score, it means something only next to what chance alone usually produces, which the degrees of freedom pin down.

Formal view

χ2=∑i=1k(Oi−Ei)2Ei where Oi is observed count and Ei is expected count; df=k−1 (GOF) or (r−1)(c−1) (independence)

Worked examples

Example 1

medium
A die is rolled 60 times. Observed: 1→8, 2→12, 3→9, 4→11, 5→13, 6→7. Conduct a chi-square goodness-of-fit test at α=0.05.
Show solution

Answer

χ2=2.8<11.07. Fail to reject H0. No evidence the die is unfair.

First step

1.
Expected under H0 (fair die): E=60/6=10 for each outcome

See the full worked solution + why-it-works coaching

SetupKey insightWhy it worksCommon pitfallConnection

Free: full solutions on 3 topics a day. No card.

Every topic, every day: the Family plan

Example 2

hard
A 2×2 table: Men: 30 prefer A, 20 prefer B. Women: 15 prefer A, 35 prefer B. Test independence of gender and preference at α=0.05.

Example 3

medium
Observed counts: 40,30,30. Expected: 33.3,33.3,33.3. Compute χ2.

Common mistakes

  • Dividing by Observed instead of Expected - the formula is (O−E)2E, scaling each gap by the expected count.
  • Using percentages or means as the data - chi-square requires raw category counts, not proportions or averages.
  • Using the wrong degrees of freedom - goodness-of-fit uses df=k−1; a two-way independence test uses df=(r−1)(c−1).

Why this formula matters

Many questions have category answers, not numbers: is a die fair, do candy colors match the company's stated mix, does favorite lunch depend on grade? Means and t-tests can't handle these. The chi-square test gives one statistic for a whole table of counts, plus a p-value, so "these counts look a bit uneven" becomes a decision about whether the unevenness is more than chance.

Frequently asked questions

What is the Chi-Square Test formula?

A hypothesis test that compares observed frequencies to expected frequencies using the chi-square statistic to assess independence or goodness of fit.

How do you use the Chi-Square Test formula?

Use a chi-square test when the data are counts of cases in categories and the question is whether they fit a stated distribution (goodness of fit, df=k−1) or whether two categorical variables are independent (two-way table, df=(r−1)(c−1)). Each expected count should be at least about 5. If the data are numeric measurements and you are comparing means, use a t-test. For exactly two proportions, a two-proportion z-test gives the same answer as a 2×2 chi-square test.

What do the symbols mean in the Chi-Square Test formula?

χ2 is the test statistic. Degrees of freedom: goodness-of-fit df=k−1; independence/homogeneity df=(r−1)(c−1).

Why is the Chi-Square Test formula important in Math?

Many questions have category answers, not numbers: is a die fair, do candy colors match the company's stated mix, does favorite lunch depend on grade? Means and t-tests can't handle these. The chi-square test gives one statistic for a whole table of counts, plus a p-value, so "these counts look a bit uneven" becomes a decision about whether the unevenness is more than chance.

What do students get wrong about Chi-Square Test?

The procedure for chi-square test is the easy part; the trap is dividing by Observed instead of Expected. Asking "Are the data counts of cases falling into categories, being compared to expected counts (rather than means or continuous values)?" first is what keeps a correct-looking calculation from being attached to the wrong concept.

What should I learn before the Chi-Square Test formula?

Before studying the Chi-Square Test formula, you should understand: hypothesis testing, p value, probability.