Chi-Square Test Calculator
Goodness of fit and test for independence — enter your data, get χ², p-value, degrees of freedom, and Cramér's V with full step-by-step working.
Calculating...
Choose Goodness of Fit or Test for Independence, fill in the data, then click Calculate χ².
What Is the Chi-Square Test?
The chi-square test (χ² test) is one of the most widely used tools in statistics. It answers a fundamental question: is the pattern you observe in your data the result of genuine structure, or could it simply be random variation? Unlike tests that compare means, the chi-square test works entirely with counts — how many items fall into each category.
Two versions of the test are most common. The goodness-of-fit test takes a single categorical variable and compares your observed frequency distribution to an expected one. Did the die land on each face the expected number of times? Do blood type frequencies in your sample match the known population distribution? The test for independence takes two categorical variables — typically arranged in a contingency table — and asks whether they are associated. Does smoking status depend on disease status? Is product preference related to customer age group?
Both tests compute the same core statistic: χ² = Σ((O − E)² / E), where O is the observed count and E is the expected count in each cell. A large χ² value indicates the observed data deviate substantially from what independence or the specified distribution would predict.
Chi-Square Goodness of Fit: Formula and Example
The goodness-of-fit test compares one observed frequency distribution to a theoretical one. You have k categories, each with an observed count O_i and an expected count E_i. The test statistic is:
χ² = Σ ( (O_i − E_i)² / E_i )
df = k − 1
Example — Dice fairness test: Roll a die 60 times. If the die is fair, you expect 10 rolls on each face. Your actual results are [8, 12, 9, 11, 7, 13]. Compute each cell's contribution: (8−10)²/10 + (12−10)²/10 + (9−10)²/10 + (11−10)²/10 + (7−10)²/10 + (13−10)²/10 = 0.4 + 0.4 + 0.1 + 0.1 + 0.9 + 0.9 = 2.8. With df = 5, the right-tail p-value is approximately 0.73 — the die appears fair.
If the user does not know the expected distribution, it is valid to assume equal proportions across all categories. This tests the null hypothesis that every category is equally likely. Geneticists use this for Mendelian ratios; marketers use it for survey response distributions; educators use it for grade distributions across classes.
Chi-Square Test for Independence: Contingency Tables
The test for independence uses a two-way contingency table — a grid where each row represents one categorical variable and each column represents another. The cells contain the observed counts at each combination of categories.
E_ij = (row total_i × col total_j) / grand total
χ² = Σ_i Σ_j ( (O_ij − E_ij)² / E_ij )
df = (rows − 1) × (cols − 1)
Example — Smoking and disease: In a study of 100 people, 50 are smokers and 50 are non-smokers. 30 smokers have disease, 20 do not; 10 non-smokers have disease, 40 do not. The expected counts under independence are E[smoker, disease] = 50×40/100 = 20, and so on. The resulting χ²(1) ≈ 16.67 with p < 0.001 — a highly significant association between smoking and disease.
Common applications include survey analysis (gender × satisfaction level), A/B testing (device type × click-through), biology (treatment group × outcome), and social science research. The only requirement is that the data consist of counts in mutually exclusive categories, not means or percentages.
How the Chi-Square Formula Works
Step 1 — Each cell
(O − E)² / E
Squared deviation relative to expectation
Step 2 — Sum all cells
χ² = Σ (O − E)² / E
Larger = more deviation from expected
Goodness of Fit df
df = k − 1
k = number of categories
Independence df
df = (r − 1)(c − 1)
r = rows, c = columns
Cohen's w (GoF)
w = √(χ² / n)
n = total observations
Cramér's V (Independence)
V = √(χ² / (n × min(r−1, c−1)))
Ranges 0–1; 0 = no association
p < α → Reject H₀
Evidence of association or non-uniform distribution. The observed pattern is unlikely under the null hypothesis.
p ≥ α → Fail to Reject H₀
Insufficient evidence of association. Data are consistent with the null hypothesis.
How to Interpret Your Chi-Square Result
The chi-square test returns three key numbers: the χ² statistic, degrees of freedom, and p-value. A large χ² relative to the degrees of freedom produces a small p-value, which is evidence against the null hypothesis.
The p-value is always a right-tail probability — the probability of observing a χ² at least as large as yours if the null hypothesis were true. Because deviations from the null are always positive (squared), chi-square tests are inherently one-directional (right-tailed only).
Conventional thresholds: p < 0.05 is "significant at the 5% level"; p < 0.01 is "significant at the 1% level"; p < 0.001 is "highly significant." However, statistical significance does not imply practical importance. Use Cramér's V or Cohen's w to gauge effect size:
| V or w value | Interpretation | Practical meaning |
|---|---|---|
| < 0.10 | Negligible | Barely detectable association |
| 0.10 – 0.29 | Small | Weak association; visible in large samples |
| 0.30 – 0.49 | Medium | Moderate association; practically meaningful |
| ≥ 0.50 | Large | Strong association; clearly visible in data |
Chi-Square Assumptions and When the Test Fails
The chi-square test rests on four key assumptions. Violating them does not always make the test useless, but it does reduce its reliability.
- 1Random sampling: The data should come from a random or representative sample. Results from a self-selected sample (e.g., online opt-in surveys) may not generalise to the broader population.
- 2Independence of observations: Each observation must belong to exactly one cell. If one person can appear in multiple categories, the chi-square approximation breaks down.
- 3Expected cell count ≥ 5: This is the most commonly violated assumption. When expected frequencies are small, the chi-square distribution is a poor approximation to the true sampling distribution. The calculator warns you when any expected cell falls below 5.
- 4Counts, not proportions: Enter the raw counts of observations, not percentages or proportions. If you only have relative frequencies, you must know the total sample size to back-calculate actual counts.
When expected cell counts are small and you have a 2×2 table, consider Fisher's exact test instead. For larger sparse tables, consider combining adjacent categories before running the chi-square test.
Chi-Square Critical Values Reference Table
If your calculated χ² exceeds the critical value for your chosen α and df, reject the null hypothesis. All values are right-tail critical points.
| df | α = 0.10 | α = 0.05 | α = 0.01 | α = 0.001 |
|---|---|---|---|---|
| 1 | 2.706 | 3.841 | 6.635 | 10.828 |
| 2 | 4.605 | 5.991 | 9.210 | 13.816 |
| 3 | 6.251 | 7.815 | 11.345 | 16.266 |
| 4 | 7.779 | 9.488 | 13.277 | 18.467 |
| 5 | 9.236 | 11.070 | 15.086 | 20.515 |
| 6 | 10.645 | 12.592 | 16.812 | 22.458 |
| 7 | 12.017 | 14.067 | 18.475 | 24.322 |
| 8 | 13.362 | 15.507 | 20.090 | 26.124 |
| 9 | 14.684 | 16.919 | 21.666 | 27.877 |
| 10 | 15.987 | 18.307 | 23.209 | 29.588 |
The α = 0.05 column is highlighted in teal — the conventional significance threshold used in most research.
Chi-Square Test FAQ
What is a chi-square test used for?
The chi-square test measures how far observed categorical counts deviate from expected counts. It is used in two main scenarios: goodness of fit (does one frequency distribution match an expected distribution?) and test for independence (are two categorical variables associated in a contingency table?). It is one of the most common tests in social science, biology, marketing, and quality control.
What is the difference between goodness of fit and test for independence?
Goodness of fit has a single categorical variable with observed and expected counts for each category — you are testing whether the observed distribution matches a theoretical one. Test for independence has two categorical variables in a cross-tabulation — you are testing whether the row and column variables are related. Both compute χ² = Σ((O−E)²/E), but the degrees of freedom differ: k−1 for goodness of fit, (r−1)(c−1) for independence.
How do I calculate degrees of freedom for a chi-square test?
For a goodness-of-fit test: df = k − 1, where k is the number of categories. For a 6-faced die, df = 5. For a test for independence on an r×c contingency table: df = (r − 1) × (c − 1). For a 2×3 table, df = (2−1)(3−1) = 2.
What does a low p-value mean in a chi-square test?
A low p-value (typically p < 0.05) means your observed data are unlikely under the null hypothesis. For goodness of fit, it means the observed distribution significantly differs from the expected distribution. For independence, it means the two categorical variables are significantly associated. A low p-value does not tell you the magnitude or direction of the association — use Cramér's V or Cohen's w for effect size.
What are the assumptions of the chi-square test?
Four assumptions: (1) Data are a random sample from the population of interest. (2) Observations are independent — each subject contributes to exactly one cell. (3) Expected cell counts should be 5 or more in every cell; sparse expected counts make the chi-square approximation unreliable. (4) Variables must be categorical counts, not means or continuous measurements.
What is Cramér's V and how do I interpret it?
Cramér's V measures the strength of association between two categorical variables after a chi-square test for independence. It ranges from 0 (no association) to 1 (perfect association), and is computed as V = √(χ² / (n × min(r−1, c−1))). Rough benchmarks: V < 0.1 negligible, 0.1–0.3 small, 0.3–0.5 medium, ≥ 0.5 large. Unlike the p-value, Cramér's V does not depend on sample size — it tells you how strong the association actually is, not just whether it can be detected.
When should I use Fisher's exact test instead of chi-square?
Use Fisher's exact test when you have a 2×2 contingency table with small expected cell counts (any cell E < 5). Fisher's exact test computes the exact probability of the observed table under the null hypothesis rather than relying on the chi-square approximation. For larger tables (2×3, 3×3, etc.) with low expected counts, consider combining categories or using Monte Carlo simulation methods.
Related Calculators
P-Value Calculator
Convert any z, t, F or χ² statistic to a p-value
t-Test Calculator
Compare means with one-sample or two-sample t-test
Probability Calculator
Union, intersection, conditional probability and complements
Bayesian Calculator
Update probabilities with new evidence using Bayes' Theorem
Standard Deviation Calculator
Population and sample variance, standard deviation, and mean
Confidence Interval Calculator
Margin of error, critical values, and interval bounds