🧮
🧮 Math & statistics

Chi-Square Test of Independence Calculator

Results update as you type.

Your numbers

Understanding the chi-square test of independence — concept and principle

The chi-square test of independence checks whether two categorical variables are related, using a contingency table of observed counts. Typical uses: does preference differ between groups, or is a treatment linked to recovery. You enter the table row by row, and the calculator returns χ², the degrees of freedom, the p-value and Cramér's V as a measure of strength.

Chi-square test of independence on a 2×2 tableObserved 20, 30, 30, 20 against expected 25 in every cell; each cell adds 1, so chi-square is 4 with 1 df, p about 0.046.Observed vs expected in every cellColumn 1Column 2totalRow 1O = 20E = 25 → +1O = 30E = 25 → +150Row 2O = 30E = 25 → +1O = 20E = 25 → +1505050100totalE = 50 × 50 ÷ 100 = 25 · each (±5)² ÷ 25 = 1χ² = 1+1+1+1 = 4 · df 1p ≈ 0.046 · Cramér’s V = 0.2
Every cell is 5 away from its expected 25, adding 1 each: χ² = 4, p ≈ 0.046.

How it is calculated

  1. For every cell, the expected count is E = row total × column total ÷ grand total.
  2. The statistic is χ² = Σ (O − E)² ÷ E, summed over all cells, where O is the observed count.
  3. Degrees of freedom: df = (rows − 1) × (columns − 1).
  4. The p-value is the upper-tail area of the chi-square distribution with df degrees of freedom beyond χ².
  5. Cramér's V = √(χ² ÷ (N × min(r − 1, c − 1))), where N is the grand total.

The principle

If the two variables were independent, the share of each column would be the same in every row, so each cell would be expected to hold its row total times the overall column share. That is exactly the expected-count formula. The statistic adds up squared gaps between what you saw and what independence predicts, scaled by E. When the null hypothesis is true and counts are large enough, this sum approximately follows a chi-square distribution, a result due to Karl Pearson (1900).

Worked example

  1. Table: row 1 = 20, 30; row 2 = 30, 20. Row totals 50 and 50, column totals 50 and 50, grand total 100.
  2. Every expected count is 50 × 50 ÷ 100 = 25.
  3. Each cell contributes (±5)² ÷ 25 = 1, so χ² = 4.
  4. df = (2 − 1)(2 − 1) = 1.
  5. Upper tail of χ² with 1 df beyond 4: p ≈ 0.0455.
  6. Cramér's V = √(4 ÷ (100 × 1)) = 0.2.

How to read the result

Where does your result fall?Not significant0.05SignificantNot significantYour result: 0.0455003 · SignificantReference: Conventional α = 0.05 significance level
Where does your result fall?

A p-value below your chosen significance level (often 0.05) means the observed pattern would be unusual if the variables were independent, so you reject independence. Cramér's V runs from 0 (no association) to 1 (perfect association); for a 2 × 2 table it equals the absolute phi coefficient. A V of 0.2 is a modest association even though it is statistically significant, so always report both.

Common mistakes

Keep in mind: The chi-square distribution is only an approximation. A common rule is that all expected counts should be at least 5 (or at least 80% of them, with none below 1). For small 2 × 2 tables use Fisher's exact test. This calculator does not apply Yates' continuity correction, so its p-value can be smaller than software that applies it by default for 2 × 2 tables.

Frequently asked questions

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

Independence compares two variables in one table; goodness of fit compares one variable's counts with a specified distribution.

Should I use Yates' correction?

It makes a 2 × 2 test more conservative. With the example table it gives χ² = 3.24 and p ≈ 0.072.

Sources: Pearson, K. (1900). Philosophical Magazine, 50(302), 157–175. · Agresti, A. An Introduction to Categorical Data Analysis (Wiley).

Checked 8 Nov 2026. Standard formulas, computed in your browser with double-precision numbers.

🧮 All math & statistics tools →🌍 Calculators by country →