Chi Square Test Calculator

This chi square test calculator checks whether two variables are related (test of independence) or whether counts match an expected distribution. Enter your table; the 2 × 2 example 30/20 and 15/35 gives χ² = 9.09 and p = 0.0026.

Source: 1.3.6.6.6, NIST/SEMATECH e-Handbook – Chi-square distribution. Updated: .

One line per table row, separate numbers with spaces or commas. Goodness of fit: line 1 = observed, optional line 2 = expected proportions (otherwise equal).
My ToolboxYour inputs are saved in this browser only.

Result

Test result
χ² = 9.091; df = 1; p = 0.002569
Decision
p = 0.002569 is below α = 5%: the association is statistically significant, so the variables are not independent (H₀ is rejected).
Critical value
At α = 5% and 1 degree(s) of freedom the critical value is χ² = 3.841. A larger χ² is significant.
Strength of association
Cramér’s V = 0.30 (moderate)
For comparison (2 × 2)
With Yates correction: χ² = 7.919, p = 0.004891
Steps
  • χ² = Σ (O − E)² / E
  • E = row total · column total / n (n = 100)
  • (30 − 22.5)² / 22.5 = 2.5
  • (15 − 22.5)² / 22.5 = 2.5
  • (20 − 27.5)² / 27.5 = 2.045
  • (35 − 27.5)² / 27.5 = 2.045
  • χ² = 9.091; df = (2 − 1) · (2 − 1) = 1
Expected counts
Column 1Column 2
Row 122.527.5
Row 222.527.5
Standardised residuals (O − E) / √E
Column 1Column 2
Row 11.58-1.43
Row 2-1.581.43

How it is calculated

The chi-square test compares observed with expected counts. As a test of independence it shows whether two variables (such as gender and product choice) are related; as a goodness-of-fit test it checks whether a distribution matches a given one (for example whether a die is fair).

How the test works

  1. Expected count per cell: E = row total · column total / grand total (independence) or n · expected proportion (goodness of fit).
  2. Test statistic: χ² = Σ (O − E)² / E, summed over all cells.
  3. Degrees of freedom: (rows − 1) · (columns − 1), or categories − 1.
  4. p-value: the probability of a χ² this large by chance if the null hypothesis is true. If p is below α (usually 5%), the result is significant.

Example

Of 50 people in group A, 30 buy; of 50 in group B only 15. The expected counts are 22.5 and 27.5. χ² = 9.09 with 1 degree of freedom, p = 0.0026 – the difference is significant. Cramér's V = 0.30 shows a moderate association.

Assumptions and limits

Frequently asked questions

How do you calculate a chi-square test?

First find the expected counts (row total · column total / grand total), then compute (O − E)² / E for each cell and add them up. The resulting χ² is turned into a p-value with the chi-square distribution (degrees of freedom = (rows − 1) · (columns − 1)).

What does the p-value mean in a chi-square test?

It is how likely a difference between observed and expected counts at least this large would be if there were really no association. A p below the level α (for example 0.05) speaks against the null hypothesis.

When do you use the Yates correction?

For a 2 × 2 table with small counts. It subtracts 0.5 from each distance |O − E| and makes the test more cautious. With large samples the difference is small.

What is Cramér’s V?

A measure of the strength of association between 0 (none) and 1 (complete): V = √(χ² / (n · min(rows − 1, columns − 1))). As a rule of thumb for 2 × 2: 0.1 weak, 0.3 moderate, 0.5 strong.

What if expected counts are below 5?

Merge neighbouring categories or collect more data. For a 2 × 2 table Fisher’s exact test is the better choice.

Sources and legal basis

As of: · Editorial policy

Related tools