Chi-Square Calculator

Run a chi-square goodness-of-fit test or a test of independence — with expected frequencies, exact p-values from the χ² distribution, critical values and a plain-language significance verdict.

CategoryObservedExpected (count)
#1
#2
#3
#4
#5
#6

Chi-square test explained, step by step

A chi-square test compares observed frequencies against expected frequencies under H₀. Each card below covers one variant this calculator runs and the piece of the formula behind it.

1. What χ² measures — observed vs expected counts

Chi-square compares observed frequencies in categorical data against what H₀ predicts. Each cell contributes (O − E)² / E, so under- and over-counts both count as evidence and gaps are weighted by how big E is — a difference of 5 out of an expected 10 matters more than 5 out of 1000.

χ² = Σ (Oᵢ − Eᵢ)² / Eᵢ
Oobserved count in a cell·Eexpected count under H₀
Example
Given
die rolls 8,9,12,11,6,14 (E = 10 each)
Substitute
χ² = 0.4+0.1+0.4+0.1+1.6+1.6
Answer
χ² = 4.2

2. Goodness of fit — one categorical variable

Use this when you have counts across k categories and a hypothesised distribution (uniform, Poisson, historical proportions…). Degrees of freedom are k − 1 (subtract one more for every parameter you estimated from the data).

df = k − 1
Example
Given
k = 6 die faces, χ²
= 4.2
Substitute
df = 6 − 1
= 5
α = 0.05
Answer
p ≈ 0.521 → fail to reject

3. Test of independence — r × c contingency table

For two categorical variables cross-tabulated, expected counts come from the row and column marginals: Eᵢⱼ = Rᵢ·Cⱼ / N. Degrees of freedom are (r − 1)(c − 1) because once the top-left block is filled the rest is fixed by the totals.

Eᵢⱼ = (Rᵢ · Cⱼ) / N   df
= (r − 1)(c − 1)
Rᵢrow total·Cⱼcolumn total·Ngrand total
A
B
C
M
20
30
20
F
30
40
10
Example
Given
2×3 table, χ² = 6.12
Substitute
df = (2−1)(3−1)
= 2
Answer
p ≈ 0.047 → reject H₀

4. When χ² breaks — small expected counts

The χ² approximation is unreliable when any expected count drops below about 5. Merge categories to raise expected counts, or use Fisher's exact test on 2×2 tables. Also use raw counts (not percentages) and remember χ² is an omnibus test — inspect cell contributions to see what's driving a significant result.

reliable when Eᵢ ≳ 5 in every cell
E ≥ 5 in every cell → χ² OK
E < 5 → merge cells or Fisher's exact
percentages instead of counts
paired data → use McNemar's test
Example
Given
2×2 table
Eᵢⱼ = 3
Substitute
χ² approximation unstable
Answer
switch to Fisher's exact

Features of this calculator

  • Two tools in one page — goodness of fit and test of independence.
  • Editable contingency table up to 6 × 6 with adjustable dimensions.
  • Expected inputs accepted as either counts or proportions on the goodness-of-fit tool.
  • Exact p-values from the χ² CDF (not table lookups).
  • Critical value at your chosen α with a reject / fail-to-reject verdict in plain language.
  • Shows the expected-frequency table beside the observed table, plus per-cell (O − E)²/E contributions.
  • Warns when expected cell counts fall below 5, where the χ² approximation gets unreliable.
  • Copy a text summary or download the results as a PNG.

Frequently asked questions

+Is chi-square one-tailed or two-tailed?
The chi-square test is inherently one-tailed on the right. Large χ² values mean big discrepancies between observed and expected, and those are the values that count as evidence against H₀.
+What if some expected counts are less than 5?
Combine small categories with neighbouring ones so no expected count falls below ~5, or switch to Fisher's exact test for 2 × 2 tables. Ignoring the rule inflates the false-positive rate.
+How is this different from a t-test or ANOVA?
T-tests and ANOVA compare means of numeric outcomes. Chi-square compares frequencies of categorical outcomes.
+Can I use chi-square on 2 × 2 tables?
Yes. With df = 1 many textbooks recommend Yates's continuity correction for small samples, though modern practice often prefers Fisher's exact test when any expected count is below 5. This calculator reports the uncorrected χ², which matches most software defaults.
+What effect size should I report alongside χ²?
For a 2 × 2 table use the phi coefficient (φ = √(χ²/N)). For larger tables use Cramér's V (V = √(χ² / (N · min(r−1, c−1)))).
+Does a significant chi-square tell me which cells are driving the result?
No — it's an omnibus test. Inspect the per-cell (O − E)² / E contributions (this calculator shows them) or compute standardised residuals to see which cells deviate most from independence.

Related calculators