Skip to content

Chi-Square Calculator

Run a chi-square goodness-of-fit test or a test of independence on a contingency table, or get a p-value and critical value from χ² and degrees of freedom.

Calculator Details

P-value:0.4038See results ↓

Goodness of fit (one row of counts), independence (a table of counts) or a p-value from χ² and df

One count per category, separated by commas or spaces

Equal shares, proportions in any scale (9:3:3:1, 25%, 0.25) or expected counts

Subtract one degree of freedom for each (e.g. 1 when you fitted a Poisson mean from the same data)

0.05 is the usual choice; the critical value is the χ² with this much area to its right

Your Results

P-value: 0.4038

P-value

0.4038

Not significant at α = 0.05 (p ≥ 0.05)

Chi-square statistic (χ²)

5.1

Degrees of freedom

5

Critical value at α = 0.05

11.070498

χ² is below it

χ² = 5.1 with 5 degrees of freedom gives p = 0.404, not significant at the 5% level: the counts are consistent with the expected distribution.

Compare scenarios

Save these inputs as a scenario, change them, and compare the results side by side.

Loading, available in a moment

Chi-square distribution with 5 degrees of freedom

Chi-square distribution with 5 degrees of freedom

Detailed Breakdown

Observed and expected count in each category
CategoryObservedExpected(O − E)² ÷ E
Category 122200.2
Category 217200.45
Category 320200
Category 426201.8
Category 522200.2
Category 613202.45

χ² = sum of the last column = 5.1.

How This Calculator Works

How It’s Calculated

Each cell adds (observed − expected)² ÷ expected to the statistic. The p-value is the area of the chi-square curve to the right of your χ², from the regularised upper incomplete gamma function Q(df/2, χ²/2), computed to about 12 significant digits rather than read from a table.

N = 120 observations in 6 categories

E₁ = 20 → (22 − 20)² ÷ 20 = 0.2

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

df = k − 1 = 5

p = P(χ²(5) > 5.1) = Q(2.5, 2.55) = 0.4038

Critical value χ²(0.05, 5) = 11.070498

Frequently Asked Questions

What does a chi-square test tell you?

Whether counts you observed differ from the counts you would expect by more than chance would explain. The goodness-of-fit test compares one row of counts with an expected distribution; the test of independence asks whether two categorical variables in a table are related. A small p-value says the difference is unlikely to be chance alone.

How is the chi-square statistic calculated?

For each category or cell, take (observed − expected)², divide by the expected count, and add them up. Rolling a die 120 times and getting 22, 17, 20, 26, 22 and 13 against 20 expected each gives χ² = 5.1 with 5 degrees of freedom and p = 0.404: no evidence the die is unfair.

How do I work out the degrees of freedom?

Goodness of fit: the number of categories minus 1, minus one more for each parameter you estimated from the same data. Independence: (rows − 1) × (columns − 1), so a 2 × 3 table has 2. The distribution-mode critical value at α = 0.05 is 3.8415 for 1 df and 18.307 for 10 df.

How are expected counts found in a test of independence?

Expected count = row total × column total ÷ grand total. It is the count you would see if the row and column variables were unrelated, so each row would split across the columns in the same proportions as the whole table.

What if some expected counts are below 5?

The chi-square p-value is an approximation that works when expected counts are large enough; the usual rule is all expected counts at least 5 (some texts allow up to 20% of cells between 1 and 5). The calculator flags small expected counts. Merge sparse categories, collect more data, or use an exact test such as Fisher’s exact test for a 2 × 2 table.

When should I use the Yates continuity correction?

Only for 2 × 2 tables, and mainly when counts are small. It subtracts ½ from each |O − E| before squaring, which makes the test more conservative. For the table 12, 5 / 7, 15 the corrected χ² is 4.322 (p = 0.0376) against 5.77 uncorrected. R applies it by default to 2 × 2 tables; many textbooks do not.

Does Mendel’s pea data fit the 9:3:3:1 ratio?

Yes, very closely. Mendel’s 315 round yellow, 108 round green, 101 wrinkled yellow and 32 wrinkled green peas give χ² = 0.47 with 3 df and p = 0.925. Enter the ratio as proportions (9, 3, 3, 1): the calculator scales it to the observed total.

What is Cramér’s V?

An effect size for a test of independence, from 0 (no association) to 1 (perfect association): V = √(χ² ÷ (N × (min(rows, columns) − 1))). A significant χ² in a very large sample can still have a tiny V, so report both. The default table has V = 0.202.

Included: Pearson’s chi-square goodness-of-fit test (equal, proportional or given expected counts, with estimated parameters), the test of independence on tables up to 400 cells with Cramér’s V and an optional Yates correction for 2 × 2 tables, and p-values and critical values from χ² and df (NIST/SEMATECH e-Handbook §1.3.5.15, §1.3.6.6.6). Left out: Fisher’s exact test and exact multinomial tests for small samples, the G-test (likelihood ratio), McNemar’s test for paired data, post-hoc residual tests and power analysis. Expected counts below 5 are flagged, not corrected.

Chi-Square Calculator: Goodness of Fit, Independence and P-Values

By FindMySum · Last reviewed

The chi-square (χ²) test answers one question about counts: are the differences between what you observed and what you expected bigger than chance alone would produce? This calculator runs the two everyday versions of the test, goodness of fit and independence, and also turns any χ² statistic and degrees of freedom into a p-value and a critical value.

Three ways to use the calculator

Goodness of fit compares one row of counts with an expected distribution. Is a die fair? Do customers arrive equally on each weekday? Do Mendel's peas follow a 9:3:3:1 ratio? Enter the observed counts, then say what you expected: equal shares, proportions or ratios in any scale, or expected counts that add up to the same total.

Test of independence works on a contingency table, a grid of counts with one categorical variable down the side and another across the top. Is preferred product related to age group? Is treatment related to outcome? Type one row per line (or separate rows with semicolons). The calculator finds every expected count, the statistic, the p-value and Cramér's V, a measure of how strong the association is.

P-value from χ² and df is for when you already have the statistic, from a textbook exercise or another program's output, and need the p-value or the critical value for a significance level.

The formula

For every category or cell:

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

where O is the observed count and E the expected count. Squaring makes every difference positive, and dividing by E scales each one: being 10 off when you expected 20 is a big miss; being 10 off when you expected 2,000 is not.

The p-value is the probability that a chi-square variable with the same degrees of freedom is larger than your statistic. The calculator computes it from the regularised upper incomplete gamma function, Q(df ÷ 2, χ² ÷ 2), to about 12 significant digits, so you do not need a table and you get an exact p rather than "between 0.05 and 0.10".

Worked example: is the die fair?

The calculator opens with 120 rolls of a die: 22 ones, 17 twos, 20 threes, 26 fours, 22 fives and 13 sixes. A fair die would give 20 of each.

FaceObservedExpected(O − E)² ÷ E
122200.20
217200.45
320200.00
426201.80
522200.20
613202.45

The statistic is the sum, χ² = 5.1, with 6 − 1 = 5 degrees of freedom. The area of the chi-square curve to the right of 5.1 is p = 0.404. At the usual 5% significance level the critical value for 5 df is 11.07, and 5.1 is well below it. There is no evidence the die is unfair: a spread like this happens in about 40% of fair runs of 120 rolls.

Degrees of freedom

Degrees of freedom count how many values could vary freely once the totals are fixed.

  • Goodness of fit: df = k − 1, where k is the number of categories. Once you know the total and k − 1 of the counts, the last one is fixed. If you estimated parameters of the expected distribution from the same data (for example, the mean of a Poisson distribution), subtract one more for each. The "parameters estimated" box does that.
  • Independence: df = (rows − 1) × (columns − 1). A 2 × 2 table has 1 degree of freedom, a 3 × 4 table has 6.

Expected counts in a contingency table

If the two variables were unrelated, every row would split across the columns in the same proportions as the whole table. That gives:

E = row total × column total ÷ grand total

In the calculator's default table, 32, 18, 10 in the first row and 20, 25, 15 in the second, the first row and first column both have known totals (60 and 52) and the grand total is 120, so the expected count in the top-left cell is 60 × 52 ÷ 120 = 26. The calculator lists every cell's observed and expected count and its share of χ² in the breakdown table, so you can see which cells drive the result.

Checking the assumptions

The chi-square p-value is an approximation. It is reliable when:

  1. The data are counts of independent observations: each person or item is counted once, in one cell.
  2. Expected counts are large enough. The usual rule is at least 5 in every cell; a common relaxation allows up to 20% of cells between 1 and 5 with none below 1. The calculator flags every expected count below 5 and highlights those rows.
  3. The categories are fixed in advance, not chosen after looking at the data.

When expected counts are too small, combine neighbouring categories, collect more data, or use an exact test. For a 2 × 2 table, Fisher's exact test is the standard alternative.

The Yates correction

For 2 × 2 tables, the chi-square approximation tends to give p-values that are slightly too small. Frank Yates proposed subtracting ½ from each |O − E| before squaring. The corrected statistic is smaller and the test more conservative. R's chisq.test applies it to 2 × 2 tables by default; Excel's CHISQ.TEST and many textbooks do not. The calculator shows both values when you switch it on, and ignores the setting for bigger tables, where it does not apply.

Effect size: Cramér's V

A p-value only says whether an association is likely to be real, not whether it matters. With thousands of observations, a trivial association becomes "significant". Cramér's V puts the strength on a 0-to-1 scale:

V = √(χ² ÷ (N × (min(r, c) − 1)))

As a rough guide for a 2 × 2 table, 0.1 is a small association, 0.3 medium and 0.5 large; the thresholds fall as the table gets bigger. Report V alongside χ² and p.

Reading the result

  • p below α (for example, below 0.05): reject the null hypothesis. For goodness of fit, the counts do not follow the expected distribution; for independence, the variables appear related.
  • p at or above α: the data are consistent with the null hypothesis. That is not proof the null is true; a small sample may simply lack the power to show a difference.
  • The chart shows the chi-square curve for your degrees of freedom, the critical value and your statistic. The p-value is the area to the right of your χ².

Common mistakes

  • Running the test on percentages or averages instead of counts.
  • Counting the same person in more than one cell.
  • Using a goodness-of-fit test when you have two variables (use independence) or the other way round.
  • Reading a non-significant result as proof that two things are unrelated.
  • Testing many tables and reporting only the significant ones, which inflates false positives.

More questions

Can I use percentages instead of counts in a chi-square test?

Not for the observed values. The statistic depends on the sample size: 60% of 10 people and 60% of 1,000 people give very different evidence, and percentages throw that away. Enter the observed counts; the expected distribution can be given as percentages or ratios, which the calculator scales to the observed total.

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

The p-value is the area in the right tail of the chi-square distribution, because any departure from the expected counts, in any direction, makes χ² larger. In that sense it is a one-tailed test of a non-directional hypothesis. A χ² that is suspiciously close to 0 (a left-tail result) can point to data that fit too well, which is how Fisher questioned Mendel's numbers.

What is the difference between a chi-square test and a t-test?

A chi-square test works on counts in categories (how many people chose each option). A t-test compares the means of a measured quantity (average height, average score). If your data are numbers you averaged, use a t-test; if they are tallies, use chi-square.

Can the observed counts be decimals?

The calculator accepts them, but the test assumes whole-number counts of independent observations. Weighted survey totals or rates per 100 people are not counts, and a chi-square test on them gives a misleading p-value. Convert back to the number of people or items first.

What does a p-value of exactly 1 mean?

That χ² is 0: every observed count equals its expected count. It does not prove the expected distribution is right; it only means this sample shows no difference from it at all, which with real data is rare and worth a second look.

Sources

This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.

Spotted a wrong result or a bug? Report a problem

May we count your visits with Invoker Analytics? It keeps a random visitor number in your browser. Your calculator inputs are never sent. Privacy policy