Skip to main content

DigitalCalculators.net

Chi-Square Calculator

Run a chi-square test of independence on a contingency table, or a goodness-of-fit test on observed and expected counts, with the χ² statistic, degrees of freedom, p-value and expected counts.

Results

ItemValue

Steps

StepWorking

Expected counts

RowExpected counts
Counts must be whole-number frequencies, not percentages. The test works best when every expected count is at least 5. For goodness of fit, expected values can be counts or proportions; they are scaled to the observed total.

Quick Answer

The chi-square statistic is χ² = Σ (O − E)² ÷ E. For the 2 × 2 table 20, 30 / 30, 20, every expected count is 25, so χ² = 4 × 25 ÷ 25 = 4 with 1 degree of freedom, giving p ≈ 0.0455, which is significant at 0.05.

Last updated: 3 November 2026 ·How we calculate this: Pearson’s chi-square test

Table of Contents

How This Chi-Square Calculator Works

For a test of independence, type your table of counts, one row per line. The calculator finds each expected count from the row and column totals, adds up (O − E)² ÷ E over every cell, and finds the p-value from the chi-square distribution with (rows − 1) × (columns − 1) degrees of freedom. For goodness of fit, enter the observed counts and the expected counts or proportions, and it tests whether the data match.

Quick explanation: chi-square measures how far observed counts are from what you would expect.

  • Large χ²: big differences from expected.
  • Small p-value: the differences are unlikely to be due to chance.
  • Counts only: use frequencies, not percentages or averages.

How to Use the Chi-Square Calculator

  1. Choose a test of independence or goodness of fit.
  2. Enter the table of counts, or the observed and expected counts.
  3. Enter the significance level.
  4. Press Calculate.
  5. Read χ², df, the p-value and the expected counts.

Core Formulas

  • Chi-square: χ² = Σ (O − E)² ÷ E
  • Independence expected count: E = row total × column total ÷ grand total
  • Independence df: (rows − 1) × (columns − 1)
  • Goodness-of-fit df: number of categories − 1
  • Cramér’s V: √(χ² ÷ (N × (min(rows, columns) − 1)))

Key Terms

  • Observed count (O): the count you recorded.
  • Expected count (E): the count you would expect if the null hypothesis is true.
  • Contingency table: a table of counts for two categorical variables.
  • Degrees of freedom: the number of values free to vary, which sets the χ² curve.
  • Cramér’s V: an effect size from 0 (no link) to 1 (strong link).

Worked Example

A die is rolled 60 times: 5, 8, 9, 8, 10, 20. Is it fair?

  • Expected: 10 for each face
  • χ² = (25 + 4 + 1 + 4 + 0 + 100) ÷ 10 = 13.4
  • With 5 df, p ≈ 0.020, so at α = 0.05 the die looks unfair

Real-Life Examples

  • Marketing: do preferences differ between age groups?
  • Genetics: do offspring match a 3:1 ratio? Enter expected as 3, 1.
  • Quality control: are defects spread evenly across shifts?
  • Surveys: is the answer to one question related to another?

Chi-Square vs T-Test

  • Chi-square: for counts in categories.
  • T-test: for comparing means of numeric data.
  • Choose by data type: categories use chi-square, measurements use t-tests.

Chi-Square Critical Values

If your χ² is above the value for your df and α, the result is significant.

dfα = 0.10α = 0.05α = 0.01
12.7063.8416.635
24.6055.9919.210
36.2517.81511.345
47.7799.48813.277
59.23611.07015.086
610.64512.59216.812
813.36215.50720.090
1015.98718.30723.209

When to Use Chi-Square

  • Independence: is there a link between two categories, such as gender and product choice?
  • Goodness of fit: do counts match a claimed distribution?
  • Expected counts: should mostly be 5 or more.
  • Independent observations: each subject should be counted once.

After a significant result, compare the observed and expected tables cell by cell. The cells where the observed count is much higher or lower than expected show where the relationship comes from. For example, if more younger customers than expected chose product A, that cell adds a lot to χ². A significant test tells you there is a link, and this comparison tells you what the link looks like.

Common Mistakes to Avoid

  • Using percentages. Enter raw counts.
  • Small expected counts. Combine categories or use Fisher’s exact test for tiny samples.
  • Counting people twice. Each observation must fall in one cell only.
  • Reading significance as strength. Use Cramér’s V for the size of the effect.
  • Mismatched lists. Observed and expected must line up in the same order.

Frequently Asked Questions

Sum (O − E)² ÷ E over every cell or category.

(rows − 1) × (columns − 1) for independence, and categories − 1 for goodness of fit.

The chance of a χ² this large or larger if there is really no relationship or the claimed distribution is right.

No. Use the actual counts.

The test may be less reliable. Combine categories or use an exact test.

Type one row per line, with numbers separated by spaces or commas.

Yes. For goodness of fit, they are scaled to your total.

A test of independence with two rows and two columns, with 1 degree of freedom.

The test uses the upper tail of the chi-square distribution.

A measure of how strong the association is, from 0 to 1.

No. It reports Pearson’s chi-square without continuity correction.

Enough that most expected counts are at least 5.

References & Sources

SourceUsed ForLink
Wikipedia, Pearson’s chi-squared test Goodness of fit and independence tests. https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test
NIST/SEMATECH e-Handbook, Chi-Square Goodness-of-Fit Test Formula and assumptions. https://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm