Chi-Square Test Calculator

Chi-Square Calculator

Test whether two categorical variables are related using a table of counts, or whether observed counts fit expected proportions, with the chi-square statistic, p-value and expected counts.

χ² = Σ (observed − expected)² ÷ expected

Each line is a row of the table, such as an age group; each column is a category, such as drink choice.

Enter your table of counts

What is a Chi-Square Test?

A chi-square test compares the counts you observed with the counts you'd expect if nothing interesting were going on. The bigger the gaps, the bigger χ², and the less plausible the "nothing going on" explanation.

The test of independence asks whether two categorical variables are linked, such as age group and drink choice. If they're unrelated, each row should split across the columns in the same proportions as the overall totals.

The goodness-of-fit test asks whether one set of counts matches a claimed pattern, such as a die landing on each face equally often, or customers spreading across days in the proportions a model predicts.

Chi-Square Formula

As given in OpenStax Introductory Statistics, sections 11.2 and 11.3. See Sources.

1. Expected counts

Independence: E = row total × column total ÷ grand total
Goodness of fit: E = n × expected share

2. The statistic

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

3. Degrees of freedom and strength

Independence: df = (rows − 1)(columns − 1) · goodness of fit: df = categories − 1
Cramér's V = √(χ² ÷ (n × (min(rows, columns) − 1)))

Worked Example: Drink Choice by Age Group

Given:
Under 30s chose tea, coffee or neither: 30, 50, 20. Over 30s: 45, 35, 20.
Step 1:
Expected counts (each row has 100 of 200):
tea 37.5 · coffee 42.5 · neither 20 in each row
Step 2:
Add up (O − E)² ÷ E:
2 × (1.5 + 1.324 + 0) = 5.647
Step 3:
Compare with χ²(2):
p = 0.0594 · critical value 5.991
Result:
χ²(2) = 5.65, p = 0.059

Just short of significance at 5%. Younger people leaned towards coffee in this sample, but 200 people aren't quite enough to rule out chance. Cramér's V of 0.17 marks the link as weak anyway.

Goodness of Fit: Is the Die Fair?

60 rolls of a die. A fair die expects 10 of each face.

Observed and expected counts for 60 die rolls
FaceObservedExpected(O − E)² ÷ E
18100.4
29100.1
312100.4
411100.1
56101.6
614101.6

χ²(5) = 4.2, p = 0.521: no evidence the die is unfair, despite one face coming up more than twice as often as another.

Common Chi-Square Mistakes

  • Entering percentages instead of counts. The test depends on how many observations there are. 30% of 10 and 30% of 1,000 are very different evidence.
  • Small expected counts. The chi-square approximation needs expected counts of about 5 or more. Combine categories or use an exact test.
  • Counting people more than once. Each observation must fall in exactly one cell. Multiple-answer survey questions break the test.
  • Reading significance as strength. With big samples, trivial links are significant. Cramér's V shows how strong the link actually is.

Chi-Square FAQs

What does the chi-square value mean on its own?

Not much without the degrees of freedom. A χ² of 6 is significant with 2 df but not with 10. The p-value puts it in context.

What is Cramér’s V?

A measure of association from 0 (none) to 1 (perfect). Roughly, 0.1 is weak, 0.3 moderate and 0.5 strong.

Should I use Yates’ continuity correction?

Some textbooks apply it to 2 × 2 tables. It makes the test more conservative; Fisher’s exact test is a better choice when counts are small.

Can I use percentages for the expected shares?

Yes, in goodness-of-fit mode. Enter them as 25, 25, 50 or 1, 1, 2; they’re rescaled to the total.

Does a significant result show cause?

No, only an association. Something else, such as income, could drive both variables.

How big can the table be?

Any size with at least 2 rows and 2 columns. Larger tables need more data to keep expected counts above 5.

How do I do this in Excel?

=CHISQ.TEST(observed_range, expected_range) gives the p-value; you need to build the expected table yourself.

What’s the difference from Fisher’s exact test?

Chi-square uses an approximation that works with decent counts. Fisher’s test is exact for 2 × 2 tables and better for small samples.

Sources

Related Tools