Skip to content
Calcapedia
Statistics & Data

Chi-Square Test Calculator

Test whether your counts match what you expected, or whether two things in a table are related. Get the chi-square statistic, p-value, critical value and each cell's share.

Level: Grade 12 to college

Printable worksheet

Chi-Square Test Calculator

Know the answer you need? Pick an input to work backward.

Inputs
Test
Expected distribution

Any scale works (9:3:3:1, 25%, 0.25 or expected counts). They're scaled to match the observed total.

The false-positive rate you accept. 0.05 is the common choice; 0.01 is stricter.

Result

p-value

0.925426

χ² = 0.47 with 3 df gives p = 0.925426, which is not significant at α = 0.05.

At α = 0.05
Not significant: fail to reject H₀ (p > 0.05)
Chi-square statistic (χ²)
0.47
Degrees of freedom
3
Critical value at α = 0.05
7.8147
Smallest expected count
34.75
Total count (N)
556

See the step-by-step solution ↓

Observed and expected count for each category
Observed and expected count for each category
CategoryObservedExpectedContribution to χ²
1315312.750.0162
2108104.250.1349
3101104.250.1013
43234.750.2176

Step-by-step solution

  1. Scale the expected ratios to the total count N, so expected and observed add up the same: E = N × (ratio ÷ sum of ratios)

    N=556
  2. The expected count (E) for each category

    312.75, 104.25, 104.25, 34.75
  3. For every category, square the gap between observed (O) and expected (E), divide by E, and add them up

    χ²=(315−312.75)2312.75+(108−104.25)2104.25+(101−104.25)2104.25+(32−34.75)234.75=0.470024
  4. Count the degrees of freedom (df): the number of categories − 1, since the last one is fixed by the total

    df=4−1=3
  5. Find the p-value: the chance of a χ² at least this big if the hypothesis were true (chi-square curve with 3 df)

    p=P(χ² > 0.470024) = =0.9254258951
  6. p is above α, so the counts are consistent with the expected pattern

    Not significant: fail to reject H₀ (p > 0.05)

Test yourself

20 quick questions built from this calculator's formula: work out results, predict what happens when an input changes, and work backward from an answer. Every answer comes with the working.

What this calculator does

Find out whether the counts you got match what you expected, or whether two things are related. A chi-square (χ²) test compares observed counts with the counts you'd expect if an idea (a hypothesis) were true. The goodness-of-fit version checks one set of category counts against a predicted pattern, such as a fair die or a genetic ratio. The test of independence uses a two-way table of counts, called a contingency table. It asks whether two category variables, such as treatment and outcome, are related.

Enter your counts, and the calculator works out the expected counts. It adds up each category's (O − E)² ÷ E share, where O is observed and E is expected. Then it reports the χ² statistic, the degrees of freedom, the p-value and the critical value. It also gives a plain decision at the significance level you choose. For tables, it adds Cramér's V, a 0-to-1 measure of how strong the link is. For 2 × 2 tables, you can turn on Yates' correction. A table lists every observed and expected count, so you can see which cells drive the result.

Where it's used

Why this math matters outside the classroom:

  • Genetics experiments. A biology class checks whether 556 pea seeds fit Mendel's 9 : 3 : 3 : 1 ratio and finds χ² ≈ 0.47, a close fit.
  • Fair dice checks. A game club rolls a die 600 times and uses a goodness-of-fit test against 100 expected per face to check it is fair.
  • Survey analysis. A city surveys residents and tests whether support for a new park is independent of which neighbourhood they live in.
  • Medical studies. Researchers tabulate recovery against treatment group in a 2 × 2 table and test whether recovery rates differ.
  • Marketing tests. A shop tests whether customers' choice among three package designs differs from an equal one-third split.

How to use it

  1. Choose goodness of fit (one list of counts) or independence (a table).
  2. For goodness of fit, enter the observed counts. Then choose 'equally likely', or enter the expected ratios, percentages or counts in the same order.
  3. For independence, type the table row by row. Separate numbers with commas and rows with semicolons, for example 20, 30; 30, 20.
  4. Set α, your cutoff for calling a result significant. Then read the p-value and decision, the χ² statistic and the cell-by-cell table. Check that the smallest expected count is at least 5.

What the inputs mean

Observed counts, one per category
Use actual counts (how many times each thing happened), not percentages or averages. The test depends on the sample size.
Expected ratio for each category
Ratios such as 9, 3, 3, 1 are fine, and so are percentages or expected counts. The calculator scales them so the expected counts add up to the observed total.
Observed table (rows separated by semicolons)
For example 20, 30; 30, 20 is a table with two rows and two columns.
Apply Yates' continuity correction (2 × 2 tables only)
This small adjustment (the continuity correction) makes a 2 × 2 test more cautious when counts are small. Many statisticians now prefer Fisher's exact test for small tables instead.
Significance level (α)
The false-positive rate you accept. 0.05 is the common choice; 0.01 is stricter.

Formula and method

χ² = Σ (O − E)² ÷ E, over every category or cell
Goodness of fit: E = N × (expected share),  df = number of categories − 1
Independence: E = (row total × column total) ÷ N,  df = (rows − 1) × (columns − 1)
Yates (2 × 2): χ² = Σ (|O − E| − 0.5)² ÷ E
p = P(χ²_df > observed χ²);  Cramér's V = √(χ² ÷ (N × (min(rows, columns) − 1)))

In these lines, O is an observed count, E is an expected count, N is the total of all counts, and Σ means add up over every category. Each (O − E)² ÷ E measures how far one count is from what was expected, compared with the expected count. So a gap of 10 matters more when 20 were expected than when 2,000 were. Adding these up gives one number. It's 0 for a perfect match and gets larger as the match gets worse.

df stands for degrees of freedom, how many expected counts are free to vary once the totals are fixed. If the hypothesis is true, the statistic roughly follows a known curve, the chi-square distribution for that df. The p-value is the share of that curve beyond your statistic. P(χ²_df > observed χ²) means the chance of a statistic at least this big if the hypothesis were true.

For independence, each cell's expected count is what you'd get if the row variable told you nothing about the column variable. The cell's share of the grand total is then its row's share times its column's share.

The critical value is the χ² at which p would equal α. A statistic above it is significant. Cramér's V rescales χ² to remove the effect of sample size and table shape.

Worked example

Mendel's pea experiment produced 315 round yellow, 108 round green, 101 wrinkled yellow and 32 wrinkled green seeds. Do these fit the predicted 9 : 3 : 3 : 1 ratio at α = 0.05?

  1. Total N = 556. Expected counts: 556 × 9/16 = 312.75, 556 × 3/16 = 104.25 (twice) and 556 × 1/16 = 34.75.
  2. Contributions: (315 − 312.75)² ÷ 312.75 ≈ 0.0162, (108 − 104.25)² ÷ 104.25 ≈ 0.1349, (101 − 104.25)² ÷ 104.25 ≈ 0.1013 and (32 − 34.75)² ÷ 34.75 ≈ 0.2176.
  3. χ² ≈ 0.0162 + 0.1349 + 0.1013 + 0.2176 ≈ 0.4700, with 4 − 1 = 3 degrees of freedom.
  4. p = P(χ²₃ > 0.4700) ≈ 0.9254. The critical value at α = 0.05 is about 7.8147.

Result: χ² ≈ 0.4700 with 3 df and p ≈ 0.9254, far above 0.05. The counts are fully consistent with the 9 : 3 : 3 : 1 ratio.

Understanding the result

A small p-value (at or below α) means your counts would be unlikely if the hypothesis held. Either the pattern doesn't fit, or the variables are linked. A large p-value means the data are consistent with the hypothesis. It doesn't prove the hypothesis is true.

Look at the contribution column to see where a significant result comes from. The cells with the largest contributions are where observed and expected counts disagree most.

With very large samples, even tiny differences become significant. Cramér's V helps you judge whether a link is strong enough to matter. As a rough guide, about 0.1 is weak, around 0.3 is moderate, and 0.5 or more is strong.

Assumptions and limitations

  • The data are counts of separate, independent observations, each landing in exactly one category or cell.
  • Expected counts are big enough for the chi-square curve to be a good fit. A common rule is that all are at least 5, or at least 80% of them with none below 1.
  • For goodness of fit, the expected proportions are set in advance, not worked out from the same data.
  • When expected counts are small, the result is unreliable. Fisher's exact test is the usual alternative for 2 × 2 tables.
  • Sometimes the expected pattern is worked out from the data itself, for example fitting a Poisson mean (an average rate). Then the degrees of freedom should drop by one for each value estimated. This calculator doesn't do that.
  • Paired or repeated observations on the same people or items need McNemar's test instead.
  • Extremely small p-values are limited by the precision of computer arithmetic (double precision).

Frequently asked questions

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

Goodness of fit compares one variable's counts with a fixed expected pattern, such as checking that a die is fair. A test of independence uses a two-way table to check whether two variables are related. For example, does preference differ between age groups?

How are the degrees of freedom calculated?

For goodness of fit, it's the number of categories minus 1. For a contingency table, it's (rows − 1) × (columns − 1). So a 2 × 2 table has 1 degree of freedom and a 3 × 4 table has 6.

Can I use percentages instead of counts?

Not for the observed values. The chi-square statistic depends on the sample size, so 60% of 10 people and 60% of 1,000 people give very different results. Expected values, though, can be given as percentages or ratios.

What if some expected counts are less than 5?

The p-value may be off. You can combine small categories into larger ones or collect more data. For a 2 × 2 table, you can use Fisher's exact test. The calculator shows the smallest expected count and warns you when it's below 5.

Is the chi-square test one-tailed or two-tailed?

It uses only the upper tail, the high end of the curve. That's because any kind of mismatch between observed and expected counts makes χ² larger. A very small χ² isn't evidence against the hypothesis. Still, a suspiciously perfect fit can hint at problems with the data.

How this calculator is checked

Method: Pearson's chi-square statistic for goodness of fit and for independence in r × c tables, Yates' continuity correction for 2 × 2 tables, and Cramér's V; p-values from the regularized incomplete gamma function. Checked against Mendel's dihybrid data and hand-worked tables. The calculation is covered by automated tests with known reference values and edge cases. Last updated 2026-10-18. Found a problem? Tell us.

Embed this calculator

Put this Chi-Square Test Calculator on your own website or blog for free. Paste this code where you want it to appear: