Chi-Square Calculator
Run χ² goodness-of-fit or independence tests, with row/column totals and expected counts spelled out.
Written by Golam Rabbani, Founder & Lead Engineer
How to use this chi-square calculator
- Pick Goodness-of-fit (1 × k) or Independence (r × c contingency).
- Enter the observed counts. For goodness-of-fit, also enter the expected counts.
- Choose the significance level α (0.001 to 0.10).
- Press Calculate to compare χ² with the bundled critical value and read the verdict.
About this chi-square calculator
The chi-square test compares observed counts with what you would expect under a hypothesis. The statistic χ² = Σ (O − E)² / E summarises the gap. For goodness-of-fit, you supply the expected counts directly and df = k − 1 (number of categories minus one). For independence, the calculator computes expected counts from the row and column totals (E = row total × column total / grand total) with df = (rows − 1) × (cols − 1). Critical values come from a bundled chi-square table (df 1–100) with a Wilson–Hilferty approximation for df > 100, so the verdict ships with the tool — no live API.
Worked example (goodness-of-fit). A die is rolled 60 times. Observed: 18, 22, 20, 40, 10, 50. Expected under fair-die: 33.333… for every face. Contributions: (18−33.333)²/33.333 ≈ 7.053, (22−33.333)²/33.333 ≈ 3.853, (20−33.333)²/33.333 ≈ 5.333, (40−33.333)²/33.333 ≈ 1.333, (10−33.333)²/33.333 ≈ 16.333, (50−33.333)²/33.333 ≈ 8.333. χ² ≈ 42.240, df = 5. At α = 0.05 the critical value is 11.070 (from the bundled table), so χ² ≫ critical — reject the null. The die is not fair.
FAQ
- When do I use goodness-of-fit vs independence?
- Goodness-of-fit checks whether one categorical variable matches a hypothesised distribution. Independence (a contingency table) tests whether two categorical variables are related.
- How are expected counts computed for independence?
- For cell (i, j): E = (row i total × col j total) / grand total. The calculator shows each cell's O and E.
- What is the rule of thumb for cell sizes?
- Chi-square is unreliable when many cells have expected counts below 5. Combine sparse categories or switch to Fisher's exact test in that case.
- Where do the critical values come from?
- A bundled chi-square critical-value table for df 1–100. For df > 100 the calculator uses the Wilson–Hilferty transformation of a standard normal.
- What does "reject H₀" mean here?
- For goodness-of-fit: observed differs significantly from expected. For independence: the two variables are not independent at the chosen α.