/

Chi-Square Calculator — Goodness of Fit, Test of Independence & Critical Values

Chi-Square Calculator — Goodness of Fit, Test of Independence & Critical Values
Statistics Tool

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.

χ² = Σ [(O − E)² / E]
Chi-Square Calculator — Select Test Type

Test whether observed frequencies match a claimed distribution. Formula: χ² = Σ[(O−E)²/E], degrees of freedom df = k−1.

Probability sum: 0.0000 — must equal 1.0000
Category Observed (O) Probability (p) Expected (E)
Significance level α:
Chi-Square Distribution — Rejection Region
Rejection region (α)
Critical value χ²_crit
Your χ² statistic

χ² Statistic

df = —

p-value

χ²_crit = —

Sample Size n

α = —
Chi-Square Working Table — (O−E)²/E Contributions
CategoryO (Observed)E (Expected) O−E(O−E)²(O−E)²/E
Step-by-Step Working

Test whether two categorical variables are independent using a contingency table. df = (r−1)(c−1). Expected: E_ij = (Row_i × Col_j) / n.

Rows (r): 2
Columns (c): 2
α:
Chi-Square Distribution — Rejection Region
Rejection region
Critical value
Your χ²

χ² Statistic

df = —

p-value

χ²_crit = —

Cramér's V

Effect size

Effect Size — Cramér's V

0 — Negligible0.1 — Small 0.3 — Medium0.5 — Large1.0
Observed Frequencies (O)
Expected Frequencies (E = Row×Col/n)
Contributions (O−E)²/E
Step-by-Step Working
Chi-Square Distribution — Live Diagram
Rejection region (α)
Critical value χ²_crit
Your χ²

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
12.7063.8415.0246.63510.828
24.6055.9917.3789.21013.816
36.2517.8159.34811.34516.266
47.7799.48811.14313.27718.467
59.23611.07012.83315.08620.515
610.64512.59214.44916.81222.458
712.01714.06716.01318.47524.322
813.36215.50717.53520.09026.124
914.68416.91919.02321.66627.877
1015.98718.30720.48323.20929.588
1117.27519.67521.92024.72531.264
1218.54921.02623.33726.21732.909
1319.81222.36224.73627.68834.528
1421.06423.68526.11929.14136.123
1522.30724.99627.48830.57837.697
1623.54226.29628.84532.00039.252
1724.76927.58730.19133.40940.790
1825.98928.86931.52634.80542.312
1927.20430.14432.85236.19143.820
2028.41231.41034.17037.56645.315
2129.61532.67135.47938.93246.797
2230.81333.92436.78140.28948.268
2332.00735.17238.07641.63849.728
2433.19636.41539.36442.98051.179
2534.38237.65240.64644.31452.620
2635.56338.88541.92345.64254.052
2736.74140.11343.19546.96355.476
2837.91641.33744.46148.27856.892
2939.08742.55745.72249.58858.301
3040.25643.77346.97950.89259.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:

χ² = Σ [(O − E)² / E] O = observed frequency · E = expected frequency · Σ = sum over all categories/cells

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).

  1. H₀: Die is fair — each face has probability p = 1/6
  2. Expected: E_i = 120 × (1/6) = 20 for all six faces
  3. χ² = Σ[(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
  4. df = 6 − 1 = 5
  5. Critical value at α=0.05, df=5: χ²_crit = 11.070
  6. 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.

  1. Expected: E₁ = 100 × 0.75 = 75, E₂ = 100 × 0.25 = 25
  2. χ² = (75−75)²/75 + (25−25)²/25 = 0/75 + 0/25 = 0.000
  3. df = 2 − 1 = 1
  4. 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 APreference BRow Total
Male301040
Female204060
Col Total5050100
  1. 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
  2. χ² = (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
  3. df = (2−1)(2−1) = 1
  4. Critical value at α=0.05, df=1: 3.841
  5. Decision: 16.667 > 3.841 → Reject H₀. Significant association. p ≈ 0.000045
  6. 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.

  1. State H₀ and H₁: For goodness of fit — H₀: data follow [distribution]. For independence — H₀: variables are independent.
  2. Calculate expected frequencies: Goodness of fit: E_i = n × p_i. Independence: E_ij = (Row_i total × Col_j total) / grand total.
  3. Compute (O−E)²/E for each cell/category: Subtract expected from observed, square the result, divide by expected. Build the complete working table.
  4. Sum to get χ²: χ² = Σ[(O−E)²/E] — add all contributions from every cell or category.
  5. Find degrees of freedom: Goodness of fit: df = k−1. Independence: df = (r−1)(c−1).
  6. Compare to critical value or compute p-value: If χ² > χ²_critical, reject H₀. If p-value < α, reject H₀. Both methods give identical decisions.
Goodness of Fit: df = k − 1 k = number of categories
Independence: df = (r−1)(c−1) r = rows, c = columns in contingency table

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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

What is the chi-square test?
The chi-square test is a statistical test that uses the formula χ² = Σ[(O−E)²/E] to measure how much observed frequencies deviate from expected frequencies. It is always non-negative, and larger values indicate greater deviation from H₀. Two main uses: goodness of fit (one variable vs a claimed distribution) and test of independence (are two categorical variables related?). The chi-square test is always right-tailed because χ² ≥ 0.
What is the difference between goodness of fit and test of independence?
Goodness of fit tests one categorical variable against a claimed distribution (df = k−1, E_i = n×p_i). Test of independence tests whether two categorical variables are associated using a contingency table (df = (r−1)(c−1), E_ij = Row×Col/n). Both use χ² = Σ[(O−E)²/E] but differ in how expected frequencies are calculated and how degrees of freedom are determined.
How do you calculate expected frequencies?
Goodness of fit: E_i = n × p_i, where n is the total sample size and p_i is the claimed probability for category i (all p_i must sum to 1). Test of independence: E_ij = (Row_i total × Column_j total) / Grand total. This uses marginal totals from the contingency table — it is not simply n divided by the number of cells.
What is degrees of freedom in a chi-square test?
Degrees of freedom determines which chi-square distribution to use. Goodness of fit: df = k−1 (one constraint because probabilities sum to 1). Independence: df = (r−1)(c−1). Larger degrees of freedom shift the chi-square distribution rightward — you need a larger χ² to reach the same significance level.
When should you not use a chi-square test?
Do not use chi-square when: (1) data are continuous, not categorical counts; (2) expected frequencies are below 5 in any cell — use Fisher's exact test for 2×2 tables or combine categories; (3) observations are not independent; (4) data are paired/matched — use McNemar's test; (5) you are using percentages or proportions rather than actual counts as observed values.
What is Cramér's V?
Cramér's V = √(χ²/(n × min(r−1, c−1))) measures the strength of association (effect size) independent of sample size. Range: 0 to 1. Interpretation: V < 0.1 = negligible, 0.1–0.3 = small, 0.3–0.5 = medium, > 0.5 = large. Unlike the p-value which depends on n, Cramér's V tells you the practical significance of any association found.
How do you find the chi-square p-value?
The p-value = P(χ²_df > χ²_observed) = 1 − CDF(χ²_observed, df). Our calculator uses the Wilson-Hilferty transformation (a cube-root approximation) to convert the chi-square distribution to a standard normal, then computes the tail probability. If p < α, reject H₀.
Is the chi-square test one-tailed or two-tailed?
The chi-square test is always one-tailed (right-tailed). Because χ² = Σ[(O−E)²/E] is always non-negative, large deviations always produce large positive χ² values. We only reject H₀ for large χ² in the right tail. There is no left-tail rejection region. This differs from t-tests which can be one-tailed or two-tailed.

Related Calculators

Key Formulas
χ² = Σ[(O−E)²/E]Chi-square statistic
df = k−1Goodness of fit
df = (r−1)(c−1)Test of independence
E_i = n × p_iGOF expected frequencies
E_ij = Row_i×Col_j/nIndependence expected
V = √(χ²/(n×min(r-1,c-1)))Cramér's V effect size
p = P(χ²_df > χ²_obs)p-value (right-tail)
All E_i ≥ 5 requiredKey assumption
Quick Examples
🎲 Dice: χ²=3.700, p=0.594
👥 Gender×Pref: χ²=16.667
🧬 3:1 Genetic ratio test
📊 3×3 Education×Income
📊 Uniform distribution test
Critical Values (α=0.05)
df=1: 3.8412×2 table
df=2: 5.9913 categories
df=3: 7.8154 categories
df=4: 9.4883×3 table
df=5: 11.0706 categories
df=9: 16.9194×4 table (df=9)

Share This Calculator

Share the Chi-Square Calculator with students and researchers!

Free chemistry, physics, biology & math calculators with step-by-step solutions. Trusted by 100,000+ students. Solve any science problem instantly!

Newsletter

Subscribe to our Newsletter to be updated. We promise not to spam.

Copyright © 2026 SciSolveLab. All Rights Reserved

Scroll to Top