Chi-Square Test Calculator
Test goodness of fit or independence using the chi-square distribution.
Goodness of Fit
Contingency Table
Quick Examples
Chi-Square Test
The chi-square test compares observed frequencies to expected frequencies to test hypotheses about categorical data. It answers two different questions: does my sample match an expected distribution (goodness of fit), or are two categorical variables related to each other (test of independence)? Both use the same core formula but compute expected values and degrees of freedom differently.
Chi-Square Formula
Where O = observed frequency, E = expected frequency
Types of Chi-Square Tests
| Test | Purpose | df |
|---|---|---|
| Goodness of Fit | Test if data fits a distribution | k - 1 |
| Independence | Test relationship between variables | (r-1)(c-1) |
Assumptions
- Data are counts/frequencies
- Observations are independent
- Expected frequency ≥ 5 for each cell
- Sample size is sufficiently large
How Expected Frequencies Are Computed
For goodness of fit, you supply the expected frequencies directly (or leave them blank for equal shares). For a test of independence, each cell's expected count is derived from the row and column totals:
This is the count each cell would have if the two variables were perfectly unrelated. Large gaps between observed and expected values push the chi-square statistic up.
Worked Example 1: Is the Die Fair?
A die is rolled 60 times. Observed faces: [8, 12, 9, 14, 11, 6]. Is the die fair at α = 0.05?
Step 1: If the die is fair, each face is expected 60 / 6 = 10 times. df = 6 − 1 = 5.
Step 2: Compute (O − E)² / E for each face:
Step 3: The critical value for df = 5 at α = 0.05 is 11.070. Since 4.2 < 11.070 (p ≈ 0.521), fail to reject the null hypothesis — there is no evidence the die is unfair.
Worked Example 2: 2×2 Test of Independence
A 2×2 table of counts has a grand total of 100, with every row and column totaling 50:
| Group B1 | Group B2 | Row Total | |
|---|---|---|---|
| Group A1 | 20 | 30 | 50 |
| Group A2 | 30 | 20 | 50 |
| Column Total | 50 | 50 | 100 |
Step 1: Each expected count is (50 × 50) / 100 = 25.
Step 2: Each cell contributes (20 − 25)² / 25 = 1, so χ² = 4.00. df = (2 − 1) × (2 − 1) = 1.
Step 3: The critical value for df = 1 at α = 0.05 is 3.841. Since 4.00 > 3.841 (p ≈ 0.0455), reject the null — the variables are associated.
Cramér's V: How Strong Is the Association?
The chi-square test only says whether an association exists, not how strong it is. With large samples, even trivial associations become significant. Cramér's V rescales the statistic into an effect size between 0 and 1:
For the 2×2 example above: V = √(4 / 100) = 0.20. Interpretation thresholds shrink as the table grows:
| Smaller Side of Table | Weak From | Moderate From | Strong From |
|---|---|---|---|
| 2 (any 2×k table) | 0.10 | 0.30 | 0.50 |
| 3 | 0.07 | 0.21 | 0.35 |
| 4 | 0.06 | 0.17 | 0.29 |
| 5 | 0.05 | 0.15 | 0.25 |
Always pair the chi-square p-value with an effect size. A significant result with V = 0.05 is real but practically negligible.
The Chi-Square Distribution
The test statistic follows the chi-square distribution, which is defined only for values at or above zero and is right-skewed — it has a long tail to the right that shrinks as the degrees of freedom grow. Its mean equals the degrees of freedom (mean = df) and its variance is 2df. A useful intuition: the chi-square distribution with df = k is the distribution of the sum of k squared independent standard normal variables, which is why it appears wherever squared deviations are summed.
Beyond Counts: The Chi-Square Test for Variance
The chi-square distribution also tests a population variance. Given a sample standard deviation s from n observations and a claimed population standard deviation σ:
Example: a manufacturer claims widgets have a standard deviation of 1 year in lifespan (σ = 1). A sample of 9 widgets has s = 0.95. The statistic is χ² = 8 × 0.95² / 1² = 8 × 0.9025 = 7.22 with df = 8. Since the median of a χ²(8) distribution is about 7.34, a value of 7.22 sits near the center — no evidence the claim is wrong. This is the one chi-square application that uses continuous data rather than counts.
Chi-Square Critical Value Table
If your computed χ² exceeds the table value for your df and α, reject the null hypothesis:
| df | α = 0.10 | α = 0.05 | α = 0.01 |
|---|---|---|---|
| 1 | 2.706 | 3.841 | 6.635 |
| 2 | 4.605 | 5.991 | 9.210 |
| 3 | 6.251 | 7.815 | 11.345 |
| 4 | 7.779 | 9.488 | 13.277 |
| 5 | 9.236 | 11.070 | 15.086 |
| 6 | 10.645 | 12.592 | 16.812 |
| 7 | 12.017 | 14.067 | 18.475 |
| 8 | 13.362 | 15.507 | 20.090 |
| 9 | 14.684 | 16.919 | 21.666 |
| 10 | 15.987 | 18.307 | 23.209 |
How to Report Your Result
Report the statistic with degrees of freedom and sample size, plus the p-value. For the die example:
For a test of independence, add the effect size: χ²(1, N = 100) = 4.00, p = 0.046, V = 0.20. Then inspect which cells deviate most — the raw residuals show where the action is.
Chi-Square vs Other Tests
| Your Data | Use |
|---|---|
| Categorical counts, one variable vs expected | Chi-square goodness of fit |
| Categorical counts, two variables | Chi-square test of independence |
| Continuous means, one or two groups | T-test |
| Continuous means, three or more groups | ANOVA |
| 2×2 table with small expected counts | Fisher's exact test (or Yates-corrected chi-square) |
Common Mistakes
- Entering percentages instead of counts: 60% of 10 and 60% of 10,000 carry very different evidence. Multiply back to counts first.
- Applying the ≥5 rule to observed counts: the rule concerns expected counts. An observed 0 is fine if the expected count is 12; an observed 9 is a problem if the expected count is 1.8.
- Using chi-square on continuous measurements: the test works on counts in categories. For comparing means of continuous variables, use a t-test or ANOVA.
- Claiming direction or causation: a significant chi-square says variables are associated, not which way the influence runs. Inspect residuals for direction; study design for causation.
- Counting one person twice: each observation belongs in exactly one cell. Before/after readings on the same people break the independence assumption.