Skip to content
Calculator Collection

Chi-Square Test Calculator

Compute the chi-square test statistic contribution for one observed-vs-expected category pair using χ² = (observed − expected)² / expected. Sum these contributions across all categories to get the total χ² statistic for goodness-of-fit or independence tests.

Last updated: May 2026

Fill in the required fields to see your result.

Compare with similar

About this calculator

The chi-square statistic measures how far observed category counts deviate from what you would expect under the null hypothesis. The per-cell formula is (Oᵢ − Eᵢ)² / Eᵢ, where Oᵢ is the observed count in category i and Eᵢ is the expected count under H₀. The total chi-square statistic is the sum of per-cell contributions: χ² = Σ (Oᵢ − Eᵢ)² / Eᵢ. This calculator computes one cell’s contribution at a time; to get the full statistic, run it for each cell and sum the results. Once you have χ², compare it to the chi-square distribution with the appropriate degrees of freedom: df = k − 1 for goodness-of-fit with k categories, or df = (rows − 1)(columns − 1) for contingency tables (test of independence). The ‘categories’ field is informational only — it documents how many categories your test involves but does not enter the per-cell formula. Variables: O is the observed frequency from your data, E is the expected frequency under H₀. Both must be non-negative counts. Edge cases: when E = 0 the formula is undefined (divide by zero); when O = E the contribution is zero (perfect agreement); rule-of-thumb requires every expected cell ≥ 5 for the chi-square approximation to be valid — for sparse tables use Fisher’s exact test instead. The chi-square approximation is poor for very small samples or contingency tables with many zero cells; for those, use simulation-based p-values or exact tests.

How to use

Example 1 — Goodness-of-fit, one cell. A coin is flipped 100 times and lands heads 60 times. Under H₀ (fair coin), expected = 50 heads. Enter observed = 60, expected = 50, categories = 2. Contribution = (60 − 50)² / 50 = 100/50 = 2. ✓ Compute the tails cell similarly: observed = 40, expected = 50 → (40 − 50)² / 50 = 100/50 = 2. Total χ² = 2 + 2 = 4.0. Compare to χ²(df=1) critical at α = 0.05 = 3.84. Since 4.0 > 3.84, reject H₀ of fairness — the coin shows evidence of bias. Example 2 — Independence test, one cell of a 2×2 contingency table. In a survey, 60 of 100 men prefer Brand A; under H₀ (independence), expected = 50. Enter observed = 60, expected = 50, categories = 4. Contribution = (60 − 50)² / 50 = 2. ✓ Compute the same way for the other three cells, then sum. With df = (2−1)(2−1) = 1, compare the total χ² against χ²(df=1) critical values. A typical contingency-table problem has all four contributions in the 0–10 range depending on how strong the observed pattern is.

Frequently asked questions

What does the chi-square statistic actually measure?

Chi-square measures the discrepancy between observed counts and expected counts under a null hypothesis, weighted so that each cell’s contribution is proportional to the squared deviation relative to its expected count. A larger chi-square means the observed data deviates more from H₀ — providing more evidence against the null. The statistic is converted to a p-value using the chi-square distribution with appropriate degrees of freedom: small p-values reject H₀, suggesting the observed pattern is unlikely under the null. The weighting by 1/E means small expected counts have outsized influence — a cell with E = 2 and O = 5 contributes (3)²/2 = 4.5, while a cell with E = 100 and O = 110 contributes only (10)²/100 = 1.0. This is why ‘expected counts ≥ 5’ is the rule-of-thumb requirement for chi-square validity — smaller expected counts make the test sensitive to tiny absolute deviations that may not be meaningful.

What is the difference between goodness-of-fit and tests of independence?

Goodness-of-fit tests whether observed category frequencies match a single expected distribution — for example, whether a die is fair (expected 1/6 in each face), whether colour preferences match a marketer’s hypothesis, or whether genetic-cross outcomes match Mendelian ratios. Degrees of freedom = (number of categories) − 1 − (number of parameters estimated from data). Test of independence checks whether two categorical variables in a contingency table are associated — whether smoking status is related to lung cancer, or product preference to age group. Degrees of freedom = (rows − 1) × (columns − 1). Both use the same per-cell formula and the same chi-square reference distribution, but the degrees of freedom and the way expected counts are computed differ. Goodness-of-fit uses a pre-specified distribution; independence uses row and column marginals.

What are the assumptions of the chi-square test?

Three main assumptions: (1) observations are independent — each subject contributes to only one cell, not multiple; (2) expected counts are large enough — typically Eᵢ ≥ 5 in every cell for the asymptotic chi-square distribution to apply (some textbooks allow up to 20% of cells with E between 1 and 5, but no cell with E < 1); (3) data are random samples from the population, not biased or self-selected. Violations: paired or repeated-measures data needs McNemar’s test, not chi-square. Sparse contingency tables (many cells with low expected counts) need Fisher’s exact test instead. Continuity correction (Yates’ correction) is sometimes applied for 2×2 tables to improve the approximation, though modern practice often skips it because it is overly conservative. For very small samples (total n < 20) prefer exact tests; the chi-square approximation only kicks in around n ≥ 30–50.

What are the most common mistakes people make with chi-square tests?

The first is using chi-square on continuous data — chi-square is for categorical/count data; for continuous variables use t-tests, ANOVA, or correlations. The second is using counts smaller than the rule-of-thumb threshold (E ≥ 5), which inflates the false-positive rate or produces misleading p-values; use Fisher’s exact test in that regime. The third is using chi-square on paired data (the same subject measured twice) instead of McNemar’s test. The fourth is using the chi-square statistic without dividing by expected — just reporting Σ(O − E)² is not chi-square. The fifth is forgetting that significance depends on degrees of freedom: a χ² of 5 is significant at df = 1 but not at df = 5. The sixth is interpreting a significant χ² as evidence about which specific cells differ — for that you need post-hoc analysis (standardised residuals or pairwise comparisons with multiple-testing correction). And the seventh is treating chi-square as a measure of effect size — it’s not; use Cramér’s V or Cohen’s w for effect size in contingency tables.

When should I not use this calculator?

Skip it for continuous data — chi-square is only for counts of categorical observations. Avoid it when any expected cell count is less than 5 — use Fisher’s exact test or simulation-based p-values instead. It is the wrong tool for paired or repeated-measures categorical data; use McNemar’s test for 2×2 paired, or the Cochran-Mantel-Haenszel test for stratified designs. Do not use it for testing differences in means or variances — those require t-tests, ANOVA, or Levene’s test. Skip it for very small total samples (n < 20) where exact tests give more reliable answers. And do not use it as the sole tool for assessing the relationship between two categorical variables — pair it with an effect size (Cramér’s V, Cohen’s w) and a visualisation (mosaic plot, stacked bar chart) so readers can see both significance and magnitude.

Sources & references