Chi-Square Test Calculator
Run chi-square goodness of fit tests and chi-square tests of independence with complete (O−E)²/E working tables, p-values, critical values, degrees of freedom, and Cramér's V effect size — for any contingency table up to 6×6.
Test whether observed frequencies match a claimed distribution. Formula: χ² = Σ[(O−E)²/E], degrees of freedom df = k−1.
| Category | Observed (O) | Probability (p) | Expected (E) |
|---|
χ² Statistic
p-value
Sample Size n
| Category | O (Observed) | E (Expected) | O−E | (O−E)² | (O−E)²/E |
|---|---|---|---|---|---|
Test whether two categorical variables are independent using a contingency table. df = (r−1)(c−1). Expected: E_ij = (Row_i × Col_j) / n.
χ² Statistic
p-value
Cramér's V
Effect Size — Cramér's V
A: Find p-value
B: Find Critical Value
C: CDF Probability
Hardcoded chi-square critical values for df = 1–30 at five significance levels. Reject H₀ if your computed χ² statistic exceeds the critical value at your chosen α. Degrees of freedom appears in every row — df = k−1 (goodness of fit) or df = (r−1)(c−1) (independence).
| df | α = 0.10 | α = 0.05 ★ | α = 0.025 | α = 0.01 | α = 0.001 |
|---|---|---|---|---|---|
| 1 | 2.706 | 3.841 | 5.024 | 6.635 | 10.828 |
| 2 | 4.605 | 5.991 | 7.378 | 9.210 | 13.816 |
| 3 | 6.251 | 7.815 | 9.348 | 11.345 | 16.266 |
| 4 | 7.779 | 9.488 | 11.143 | 13.277 | 18.467 |
| 5 | 9.236 | 11.070 | 12.833 | 15.086 | 20.515 |
| 6 | 10.645 | 12.592 | 14.449 | 16.812 | 22.458 |
| 7 | 12.017 | 14.067 | 16.013 | 18.475 | 24.322 |
| 8 | 13.362 | 15.507 | 17.535 | 20.090 | 26.124 |
| 9 | 14.684 | 16.919 | 19.023 | 21.666 | 27.877 |
| 10 | 15.987 | 18.307 | 20.483 | 23.209 | 29.588 |
| 11 | 17.275 | 19.675 | 21.920 | 24.725 | 31.264 |
| 12 | 18.549 | 21.026 | 23.337 | 26.217 | 32.909 |
| 13 | 19.812 | 22.362 | 24.736 | 27.688 | 34.528 |
| 14 | 21.064 | 23.685 | 26.119 | 29.141 | 36.123 |
| 15 | 22.307 | 24.996 | 27.488 | 30.578 | 37.697 |
| 16 | 23.542 | 26.296 | 28.845 | 32.000 | 39.252 |
| 17 | 24.769 | 27.587 | 30.191 | 33.409 | 40.790 |
| 18 | 25.989 | 28.869 | 31.526 | 34.805 | 42.312 |
| 19 | 27.204 | 30.144 | 32.852 | 36.191 | 43.820 |
| 20 | 28.412 | 31.410 | 34.170 | 37.566 | 45.315 |
| 21 | 29.615 | 32.671 | 35.479 | 38.932 | 46.797 |
| 22 | 30.813 | 33.924 | 36.781 | 40.289 | 48.268 |
| 23 | 32.007 | 35.172 | 38.076 | 41.638 | 49.728 |
| 24 | 33.196 | 36.415 | 39.364 | 42.980 | 51.179 |
| 25 | 34.382 | 37.652 | 40.646 | 44.314 | 52.620 |
| 26 | 35.563 | 38.885 | 41.923 | 45.642 | 54.052 |
| 27 | 36.741 | 40.113 | 43.195 | 46.963 | 55.476 |
| 28 | 37.916 | 41.337 | 44.461 | 48.278 | 56.892 |
| 29 | 39.087 | 42.557 | 45.722 | 49.588 | 58.301 |
| 30 | 40.256 | 43.773 | 46.979 | 50.892 | 59.703 |
What Is the Chi-Square Test? — Definition and Formula
The chi-square calculator on this page performs both the chi-square goodness of fit test and the chi-square test of independence, computing p-values, degrees of freedom, critical values, and the complete (O−E)²/E contribution table with step-by-step working. The chi-square test is one of the most widely used statistical tests for categorical data.
The chi-square test statistic measures how far observed frequencies deviate from expected frequencies. The formula is:
Key properties: χ² is always non-negative (χ² ≥ 0). A chi-square statistic of zero means observed frequencies exactly match expected frequencies. Larger χ² means greater deviation from expected — more evidence against H₀. The chi-square test is always right-tailed (one-tailed) because χ² cannot be negative.
The chi-square test applies to two situations: (1) chi-square goodness of fit — does one categorical variable follow a specific distribution? and (2) chi-square test of independence — are two categorical variables associated? Both use the same formula χ² = Σ[(O−E)²/E] but differ in how expected frequencies are calculated and how degrees of freedom are determined.
Why χ² is always non-negative: Each term (O−E)² is squared (always ≥ 0), and E is always positive. Therefore every term in the sum is non-negative, and the chi-square statistic χ² = Σ[(O−E)²/E] ≥ 0. This is why the chi-square test is always one-tailed (right-tailed) — we only look at large positive values.
Chi-Square Goodness of Fit Test — When and How to Use It
The chi-square goodness of fit test is used when you have one categorical variable and want to test whether the observed frequency distribution matches a specified theoretical distribution (uniform, Mendelian ratios, Hardy-Weinberg, etc.).
Hypotheses:
H₀: The data follow the specified distribution (observed frequencies match expected)
H₁: The data do not follow the specified distribution
Degrees of freedom: df = k − 1, where k is the number of categories. We lose one degree of freedom because the expected probabilities must sum to 1 (one constraint).
Expected frequencies: E_i = n × p_i, where n = total sample size and p_i = claimed probability for category i. All p_i must sum to 1.0.
Key assumption: All expected frequencies must be ≥ 5. When this assumption is violated, the chi-square approximation becomes unreliable. Consider combining adjacent categories or using Fisher's exact test (for 2×2 tables).
Worked Example 1 — Dice Fairness Test
A die is rolled 120 times. Observed counts: [18, 22, 17, 24, 15, 24]. Test whether the die is fair (each face equally likely).
- H₀: Die is fair — each face has probability p = 1/6
- Expected: E_i = 120 × (1/6) = 20 for all six faces
- χ² = Σ[(O−E)²/E]:
(18−20)²/20 + (22−20)²/20 + (17−20)²/20 + (24−20)²/20 + (15−20)²/20 + (24−20)²/20
= 4/20 + 4/20 + 9/20 + 16/20 + 25/20 + 16/20 = 74/20 = 3.700 - df = 6 − 1 = 5
- Critical value at α=0.05, df=5: χ²_crit = 11.070
- Decision: 3.700 < 11.070 → Fail to reject H₀ — no significant evidence the die is unfair. p-value ≈ 0.594
Worked Example 2 — Mendelian Genetic Ratio Test (3:1)
In a Mendelian cross, offspring observed: [75 dominant, 25 recessive]. Total n = 100. Expected ratio: 3:1 → p₁ = 0.75, p₂ = 0.25.
- Expected: E₁ = 100 × 0.75 = 75, E₂ = 100 × 0.25 = 25
- χ² = (75−75)²/75 + (25−25)²/25 = 0/75 + 0/25 = 0.000
- df = 2 − 1 = 1
- Decision: χ² = 0 < 3.841 → Fail to reject H₀. Data perfectly fit the 3:1 Mendelian ratio.
The chi-square goodness of fit test is also used to test whether allele frequencies in a population conform to Hardy-Weinberg expectations. See our Hardy-Weinberg calculator which uses this same chi-square test for HWE testing.
Chi-Square Test of Independence — Contingency Tables
The chi-square test of independence determines whether two categorical variables are statistically independent or associated. Data are arranged in an r×c contingency table where r = number of row categories and c = number of column categories.
Hypotheses:
H₀: The two variables are independent (no association)
H₁: The two variables are associated (not independent)
Degrees of freedom: df = (r−1)(c−1). For a 2×2 table: df = 1. For a 3×3 table: df = 4.
Expected cell frequencies: E_ij = (Row_i total × Column_j total) / Grand total. This formula ensures that if the variables were truly independent, the expected proportions would match the marginal proportions.
Cramér's V effect size: V = √(χ²/(n × min(r−1, c−1))). Interpretation: V < 0.1 = negligible, 0.1–0.3 = small, 0.3–0.5 = medium, > 0.5 = large association. Cramér's V ranges from 0 to 1 and does not depend on sample size.
Worked Example — 2×2 Contingency Table: Gender vs Preference
| Preference A | Preference B | Row Total | |
|---|---|---|---|
| Male | 30 | 10 | 40 |
| Female | 20 | 40 | 60 |
| Col Total | 50 | 50 | 100 |
- Expected frequencies E_ij = (Row_i × Col_j)/n:
E(M,A) = 40×50/100 = 20 | E(M,B) = 40×50/100 = 20
E(F,A) = 60×50/100 = 30 | E(F,B) = 60×50/100 = 30 - χ² = (30−20)²/20 + (10−20)²/20 + (20−30)²/30 + (40−30)²/30
= 100/20 + 100/20 + 100/30 + 100/30 = 5 + 5 + 3.333 + 3.333 = 16.667 - df = (2−1)(2−1) = 1
- Critical value at α=0.05, df=1: 3.841
- Decision: 16.667 > 3.841 → Reject H₀. Significant association. p ≈ 0.000045
- Cramér's V = √(16.667/(100×min(1,1))) = √(0.16667) = 0.4082 — medium-large effect
How to Calculate the Chi-Square Test Statistic — Step-by-Step
Use this six-step method for both chi-square goodness of fit and test of independence. The chi-square formula χ² = Σ[(O−E)²/E] applies to both test types.
- State H₀ and H₁: For goodness of fit — H₀: data follow [distribution]. For independence — H₀: variables are independent.
- Calculate expected frequencies: Goodness of fit: E_i = n × p_i. Independence: E_ij = (Row_i total × Col_j total) / grand total.
- Compute (O−E)²/E for each cell/category: Subtract expected from observed, square the result, divide by expected. Build the complete working table.
- Sum to get χ²: χ² = Σ[(O−E)²/E] — add all contributions from every cell or category.
- Find degrees of freedom: Goodness of fit: df = k−1. Independence: df = (r−1)(c−1).
- Compare to critical value or compute p-value: If χ² > χ²_critical, reject H₀. If p-value < α, reject H₀. Both methods give identical decisions.
Chi-Square Distribution — Degrees of Freedom and Critical Values
The chi-square distribution with df degrees of freedom is always right-skewed and non-negative. It has these properties:
- Mean = df (the distribution centers at its degrees of freedom)
- Variance = 2 × df
- For small df (1–3): highly right-skewed, peak near zero
- For large df (> 30): approaches a normal distribution
The same χ² statistic gives different p-values depending on degrees of freedom. With df=1, χ²=3.841 gives p=0.05 exactly. With df=5, χ²=3.841 gives p≈0.57. Always use the correct degrees of freedom for your test.
Reading the critical value table: Find your degrees of freedom (df = k−1 or df = (r−1)(c−1)) in the left column, then find the column matching your significance level α. If your computed χ² exceeds the table value, reject H₀.
Chi-Square Test Assumptions — When the Test Is Valid
Four assumptions must be met for the chi-square test to be valid. Violating these assumptions can produce incorrect p-values and wrong conclusions.
- Categorical data: The variables must be categorical (nominal or ordinal), not continuous. Do not apply chi-square directly to continuous measurements — first convert to categories if appropriate.
- Independent observations: Each observation must come from a different, independent subject. The chi-square test is not appropriate for paired/matched data or repeated measures — use McNemar's test instead.
- Expected frequencies ≥ 5: This is the most critical and most frequently violated assumption. Every cell should have E_ij ≥ 5. When violated: (a) combine adjacent categories to increase expected counts, (b) use Fisher's exact test for 2×2 tables, or (c) collect more data. If more than 20% of cells have E < 5, the chi-square approximation becomes unreliable.
- Random sampling: Data must come from a random sample of the population. Convenience samples may introduce bias regardless of the statistical test used.
Common Mistakes in Chi-Square Tests
Mistake 1 — Using proportions instead of counts
- ❌ Wrong: Using O = [0.30, 0.25, 0.45] (proportions) as observed values
- ✅ Correct: Use actual counts O = [30, 25, 45] (raw frequencies)
- The chi-square formula χ² = Σ[(O−E)²/E] requires raw counts, not percentages or proportions.
Mistake 2 — Computing expected frequencies incorrectly
- ❌ Wrong (independence): Using E = n/(r×c) = equal split
- ✅ Correct: E_ij = (Row_i total × Column_j total) / Grand total — uses marginal totals
- ❌ Wrong (goodness of fit): Using E = n/k — only valid for uniform distribution
- ✅ Correct: E_i = n × p_i using the claimed probabilities p_i
Mistake 3 — Wrong degrees of freedom
- ❌ Wrong (goodness of fit): df = k instead of df = k−1
- ❌ Wrong (independence): df = r×c instead of df = (r−1)(c−1)
- ✅ Correct: df = k−1 for goodness of fit; df = (r−1)(c−1) for independence
Mistake 4 — Ignoring the E ≥ 5 assumption
- If any expected frequency is below 5, the chi-square approximation may be unreliable.
- Solution: Combine categories with small expected counts, or use Fisher's exact test for 2×2 tables.
- Our chi-square calculator automatically warns you when this assumption is violated.
Mistake 5 — Using two-tailed p-value
- The chi-square test is always one-tailed (right-tailed) because χ² = Σ[(O−E)²/E] ≥ 0.
- ❌ Wrong: Dividing p-value by 2 as you would for a two-tailed t-test
- ✅ Correct: p-value = P(χ²_df > χ²_observed) — always the right-tail probability
Worked Examples — Full Step-by-Step Solutions
Example 1 — Dice Fairness (Goodness of Fit)
Observed: [18, 22, 17, 24, 15, 24], n=120, each p_i=1/6, E_i=20 for all
χ² = (18−20)²/20+(22−20)²/20+(17−20)²/20+(24−20)²/20+(15−20)²/20+(24−20)²/20
= 4/20+4/20+9/20+16/20+25/20+16/20 = 74/20 = 3.700
df=5, χ²_crit(α=0.05)=11.070, p≈0.594 → Fail to reject H₀
Example 2 — Genetic Ratio 3:1
Observed: [140 dominant, 60 recessive], n=200, p₁=0.75, p₂=0.25
E₁=200×0.75=150, E₂=200×0.25=50
χ²=(140−150)²/150+(60−50)²/50=100/150+100/50=0.667+2.000=2.667
df=1, χ²_crit=3.841, p≈0.102 → Fail to reject H₀. Data consistent with 3:1 ratio.
Example 3 — 2×2 Contingency Table
As shown above: Gender vs Preference, χ²=16.667, df=1, p≈0.000045, V=0.408 → Reject H₀
Example 4 — 3×3 Table: Education vs Income
Education (Low/Mid/High) vs Income (Low/Mid/High), n=300
df=(3−1)(3−1)=4, χ²_crit(α=0.05)=9.488
If computed χ²=12.3 > 9.488 → Reject H₀ — significant association between education and income
Example 5 — Finding Critical Value
Test of independence, 4×3 table, α=0.01: df=(4−1)(3−1)=6
From critical value table: χ²_crit(df=6, α=0.01) = 16.812
Example 6 — Finding p-value from χ²
χ²=5.991, df=2: Using chi-square CDF, P(χ²₂ > 5.991) = 0.0500
This is the definition of the critical value at α=0.05, df=2.
Example 7 — Cramér's V Interpretation
χ²=16.667, n=100, 2×2 table: V=√(16.667/(100×min(1,1)))=√(0.16667)=0.4082
0.3 ≤ V ≤ 0.5 → Medium effect size — substantial association between the variables.
Example 8 — Violated E≥5 Assumption with Category Combining
Original 5 categories: E = [8, 3, 2, 4, 83]. Two cells have E < 5 (40% of cells).
Solution: Combine categories 2, 3, 4 into one group → new E = [8, 9, 83]. All E ≥ 5 ✓
New df = 3−1=2 instead of original 5−1=4. Proceed with combined categories.
Frequently Asked Questions
Related Calculators
Share This Calculator
Share the Chi-Square Calculator with students and researchers!