Chi-Square Test Calculator

Test goodness of fit or independence using the chi-square distribution.

Goodness of Fit

Contingency Table

Chi-Square Statistic
—
Enter data and calculate
χ² Value
—
Degrees of Freedom
—
p-Value
—
Critical Value
—
Decision
—
Cramér\'s V
—

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

χ² = Σ [(O - E)² / E]

Where O = observed frequency, E = expected frequency

Types of Chi-Square Tests

TestPurposedf
Goodness of FitTest if data fits a distributionk - 1
IndependenceTest 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:

E = (row total × column total) / grand total

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:

χ² = 0.4 + 0.4 + 0.1 + 1.6 + 0.1 + 1.6 = 4.2

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 B1Group B2Row Total
Group A1203050
Group A2302050
Column Total5050100

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:

V = √(χ² / (n × min(r−1, c−1)))

For the 2×2 example above: V = √(4 / 100) = 0.20. Interpretation thresholds shrink as the table grows:

Smaller Side of TableWeak FromModerate FromStrong From
2 (any 2×k table)0.100.300.50
30.070.210.35
40.060.170.29
50.050.150.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 σ:

χ² = (n − 1) × s² / σ²    with df = n − 1

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
12.7063.8416.635
24.6055.9919.210
36.2517.81511.345
47.7799.48813.277
59.23611.07015.086
610.64512.59216.812
712.01714.06718.475
813.36215.50720.090
914.68416.91921.666
1015.98718.30723.209

How to Report Your Result

Report the statistic with degrees of freedom and sample size, plus the p-value. For the die example:

χ²(5, N = 60) = 4.20, p = 0.52

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 DataUse
Categorical counts, one variable vs expectedChi-square goodness of fit
Categorical counts, two variablesChi-square test of independence
Continuous means, one or two groupsT-test
Continuous means, three or more groupsANOVA
2×2 table with small expected countsFisher'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.

Frequently Asked Questions

When should I use chi-square test?
Use chi-square when testing relationships between categorical variables or comparing observed data to expected distributions. Not for continuous data.
What if expected frequencies are too small?
If any expected frequency is less than 5, consider using Fisher's Exact Test for contingency tables or combining categories.