Chi-Square Calculator
Run a chi-square goodness-of-fit test or test of independence: χ², degrees of freedom, p-value, expected counts, contributions and a clear decision.
One categorical variable: do the observed counts match an expected distribution?
- Chi-square (χ²)
- 2
- Degrees of freedom
- 3
- k − 1
- p-value
- 0.5724
- Right-tail probability
- Critical value (α = 0.05)
- 7.8147
- χ² is below it
- Categories (k)
- 4
- n = 100
Null hypothesis (H₀)
The observed category frequencies are consistent with the specified expected distribution.
Alternative hypothesis (H₁)
The observed category frequencies differ from the specified expected distribution.
Statistical significance is not practical importance. With a large sample, a tiny difference can be significant; with a small one, a large difference may not be. A chi-square test shows association, not causation.
Observed vs expected
The largest contribution comes from A (20 observed vs 25 expected, 1 of the total χ² 2).
Contribution table
| Category | Observed O | Expected E | O − E | (O − E)² | (O − E)² / E |
|---|---|---|---|---|---|
| A | 20 | 25 | −5 | 25 | 1 |
| B | 30 | 25 | 5 | 25 | 1 |
| C | 25 | 25 | 0 | 0 | 0 |
| D | 25 | 25 | 0 | 0 | 0 |
| Total | 100 | 100 | χ² = 2 |
Where χ² falls on the chi-square distribution
Step-by-step calculation
Step 1: Expected counts
Expected frequencies are as entered. Total observed = 100, total expected = 100.
E(A) = 25
E(B) = 25
E(C) = 25
E(D) = 25
Step 2: Contribution of each category: (O − E)² / E
A: (20 − 25)² / 25 = 1
B: (30 − 25)² / 25 = 1
C: (25 − 25)² / 25 = 0
D: (25 − 25)² / 25 = 0
Step 3: Chi-square statistic
χ² = Σ (O − E)² / E = 1 + 1 + 0 + 0 = 2
Step 4: Degrees of freedom
k categories, minus 1 because the counts must add up to the total.
df = k − 1 = 4 − 1 = 3
Step 5: p-value and decision
The p-value is the right-tail area of the chi-square distribution with 3 degrees of freedom beyond χ² = 2.
p = 0.5724 (critical value at α = 0.05: 7.8147)
p ≥ α, so fail to reject H₀
Chi-square formulas
Both testsχ² = Σ (O − E)² / E
Goodness-of-fitE from the specified distribution, df = k − 1
IndependenceE = (row total × column total) / grand total, df = (r − 1)(c − 1)
Cramér’s VV = √(χ² / (n × min(r − 1, c − 1)))
O = observed count, E = expected count, k = categories, r and c = rows and columns, n = grand total. If you estimated parameters from the data to get the expected counts, subtract one degree of freedom for each.
| Goodness-of-fit | Test of independence |
|---|---|
| One categorical variable | Two categorical variables |
| Compares observed counts with an expected distribution | Tests whether the variables are associated |
| Expected counts are specified or modelled | Expected counts come from row and column totals |
| df often k − 1 | df = (r − 1)(c − 1) |
Chi-square tests are for counts in categories. If you are measuring the relationship between two numerical variables instead, use the Correlation Calculator or the Linear Regression Calculator. For single-event chances, try the Probability Calculator, and to plan a survey, the Sample Size Calculator.
A chi-square test compares observed categorical counts with the counts expected under a null hypothesis. This chi-square calculator runs both common versions: the goodness-of-fit test, for one categorical variable against an expected distribution, and the test of independence, for two categorical variables in a contingency table.
Enter your counts and a significance level to get the chi-square statistic, degrees of freedom, p-value, critical value and a plain decision (reject or fail to reject H₀), along with expected counts, each category's or cell's contribution to χ², Cramér's V, charts and every calculation step. For small 2 × 2 tables you can add Yates' correction or Fisher's exact test.
Worked Calculation Examples
| Scenario | Result | Calculation Step |
|---|---|---|
| Goodness-of-fit: is a die fair? (hypothetical) | χ² = 4.5, df = 5, p ≈ 0.480 | Contributions: 25/20, 4/20, 4/20, 25/20, 16/20, 16/20 = 1.25, 0.2, 0.2, 1.25, 0.8, 0.8, total 4.5. With df = 6 − 1 = 5, p ≈ 0.480 > 0.05, so fail to reject H₀: the rolls are consistent with a fair die. This does not prove the die is fair; 120 rolls cannot detect a small bias. |
| Test of independence: education vs preferred product (hypothetical) | χ² ≈ 33.24, df = 4, p < 0.0001 | n = 265. The expected count for High school × Basic is 90 × 80 / 265 ≈ 27.17, against 42 observed. Summing (O − E)² / E over the 9 cells gives χ² ≈ 33.24 with df = (3 − 1)(3 − 1) = 4, p ≈ 0.000001, so reject H₀: preferred tier is associated with education level in these data. Cramér’s V ≈ 0.25 indicates a moderate association. It does not show that education causes the preference. |
| Small expected counts (hypothetical 2 × 2) | χ² ≈ 5.40, p ≈ 0.020; Fisher p ≈ 0.041 | With only 15 people, every expected count is below 5 (4.8, 3.2, 4.2, 2.8), so the chi-square approximation is doubtful. Fisher’s exact test gives p ≈ 0.041. Both are below 0.05 here, but the exact p-value is twice as large, which matters for a borderline result. |
What Is a Chi-Square Test?
A chi-square test compares observed categorical frequencies with the frequencies expected under a specified null hypothesis. The bigger the gaps between observed and expected counts, relative to the expected counts, the larger the χ² statistic and the smaller the p-value.
The two main uses are the goodness-of-fit test, which asks whether one categorical variable follows a specified distribution (is this die fair?), and the test of independence, which asks whether two categorical variables are associated (does product preference differ by education level?). Both use χ² = Σ (O − E)² / E, but they get the expected counts and the degrees of freedom differently, and they answer different questions.
How to Calculate a Chi-Square Goodness-of-Fit Test
1. List the categories with their observed counts O.
2. Work out the expected count E for each category from the hypothesized distribution: equal counts, given percentages, or a model.
3. For each category compute (O − E)² / E.
4. Add them up to get χ².
5. Degrees of freedom: df = k − 1 for k categories, minus one more for every parameter estimated from the data.
6. Find the p-value, the right-tail area of the chi-square distribution beyond χ², and compare it with α.
Example: a die rolled 120 times gives 15, 22, 18, 25, 16 and 24 for faces 1 to 6. If the die is fair, each face is expected 20 times. χ² = (25 + 4 + 4 + 25 + 16 + 16) / 20 = 4.5 with df = 5, so p ≈ 0.480. At α = 0.05 we fail to reject H₀: the counts are consistent with a fair die (which is not the same as proving it is fair).
How to Calculate a Chi-Square Test of Independence
1. Put the counts in an r × c contingency table and add the row totals, column totals and grand total n.
2. For each cell, the expected count is E = (row total × column total) / n.
3. Compute (O − E)² / E for every cell and add them to get χ².
4. Degrees of freedom: df = (r − 1)(c − 1).
5. Find the p-value and compare it with α.
Example: 50 people in Group A and 50 in Group B; 30 and 15 of them purchased. The column totals are 45 purchased and 55 did not, so each group's expected counts are 50 × 45 / 100 = 22.5 and 27.5. χ² = 2 × 7.5² / 22.5 + 2 × 7.5² / 27.5 ≈ 9.09 with df = 1, p ≈ 0.0026. At α = 0.05 we reject H₀: the data provide evidence that purchasing is associated with the group.
How to Interpret the Chi-Square p-Value
The p-value is the probability of getting a χ² at least as large as yours if the null hypothesis were true. It is always a right-tail probability, because any difference between observed and expected counts, in either direction, makes χ² bigger.
If p < α, reject H₀: the result is statistically significant at that level. If p ≥ α, fail to reject H₀: the data do not provide enough evidence against it. Failing to reject is not proof that H₀ is true; a small sample may simply be unable to detect a difference.
Statistical significance is not practical importance. With thousands of observations a trivial difference can be significant. For a test of independence, Cramér's V (from 0 to 1) describes the strength of the association separately from the p-value.
When to Use a Chi-Square Test
Goodness-of-fit: comparing observed category counts with an expected distribution, such as whether customer visits are spread evenly across weekdays, whether a die or spinner is fair, or whether offspring follow a 9:3:3:1 genetic ratio.
Test of independence: comparing how category membership is distributed across groups, such as whether preferred product tier differs by education level, or whether the purchase rate differs between two website designs.
Chi-square tests are not for continuous measurements, means or correlations between numbers. To compare two numerical variables, use correlation or regression instead. Each observation must be independent and counted in exactly one cell; the same person counted twice, or before-and-after measurements on the same people, need other methods.
Small Expected Counts
Chi-square tests rely on an approximation that may perform poorly with sparse expected counts. A widely taught rule of thumb asks for expected counts of at least 5 in every cell; some texts accept up to 20% of cells below 5 as long as none is below 1. These are guidelines, not laws.
When expected counts are small, combining categories can help if the combined categories still make sense for your question; do not merge categories just to force a test to run. For 2 × 2 tables, Fisher's exact test calculates the p-value exactly instead. In the small-counts example (7 and 1 improved vs not improved in treatment, 2 and 5 in control), every expected count is below 5; the chi-square p-value is about 0.020 while Fisher's exact test gives about 0.041.
Yates' Correction and Fisher's Exact Test
Yates' continuity correction, for 2 × 2 tables only, subtracts 0.5 from each |O − E| before squaring. It makes the test more conservative (a smaller χ², a larger p-value) to compensate for approximating discrete counts with a continuous distribution; in the purchase example it changes χ² from 9.09 to 7.92 and p from 0.0026 to 0.0049. Many statisticians consider it overly conservative, so it is off by default here.
Fisher's exact test computes the exact probability of all 2 × 2 tables with the same row and column totals that are as extreme as, or more extreme than, the observed one. It does not depend on large expected counts. The calculator shows it alongside the chi-square result when you ask for it, never as a silent replacement.
How to Use the Chi-Square Calculator
- Choose the test: goodness-of-fit for one categorical variable compared with an expected distribution, or test of independence for two categorical variables in a contingency table.
- Enter the observed counts. For goodness-of-fit, give expected counts, expected percentages, or choose equal expected frequencies; for independence, fill in the table and add or remove rows and columns as needed.
- Choose the significance level α (0.05 by default, or 0.01, 0.10 or a custom value) before looking at the result.
- Read χ², the degrees of freedom, the p-value and the decision (reject or fail to reject H₀), with a plain-language interpretation and, for independence, Cramér’s V.
- Check the contribution and expected-count tables, the charts and any small-expected-count warning, and follow the step-by-step calculation.
Frequently Asked Questions
What is a chi-square test?
A test that compares observed counts in categories with the counts expected under a null hypothesis, using χ² = Σ (O − E)² / E. The two main versions are the goodness-of-fit test and the test of independence.
What is the chi-square statistic?
χ² = Σ (O − E)² / E, the sum over all categories or cells of the squared difference between observed and expected counts, divided by the expected count. Larger values mean bigger departures from what H₀ predicts.
What is a chi-square goodness-of-fit test?
It tests whether the counts of one categorical variable match a specified distribution, such as equal counts, given percentages or a theoretical ratio. df = k − 1 for k categories.
What is a chi-square test of independence?
It tests whether two categorical variables in a contingency table are associated. H₀ says they are independent. df = (r − 1)(c − 1).
How do you calculate expected frequency?
For goodness-of-fit, multiply the total count by each category’s hypothesized proportion. For independence, E = (row total × column total) / grand total for each cell.
How do you calculate degrees of freedom?
Goodness-of-fit: df = k − 1, minus one for each parameter estimated from the data. Test of independence: df = (r − 1)(c − 1), such as 1 for a 2 × 2 table and 4 for a 3 × 3 table.
What does the chi-square p-value mean?
The probability of a χ² at least as large as the one observed if the null hypothesis were true. It is a right-tail probability of the chi-square distribution.
What does it mean when p is less than 0.05?
At the 0.05 significance level you reject H₀: the counts provide evidence of a difference from the expected distribution, or of an association. It does not show the effect is large or important.
What is the difference between goodness-of-fit and independence?
Goodness-of-fit uses one categorical variable and compares it with a specified distribution. Independence uses two categorical variables and tests whether they are associated, with expected counts taken from the row and column totals.
When should you use a chi-square test?
When your data are counts of independent observations in categories, for example survey answers, outcomes or group membership. Do not use it for means, continuous measurements or paired before-and-after data.
What happens when expected frequencies are too small?
The chi-square approximation can give inaccurate p-values. A common guideline asks for expected counts of at least 5. Consider combining categories where that makes sense, or use Fisher’s exact test for a 2 × 2 table.
Does a chi-square test prove causation?
No. A significant test of independence shows evidence of an association between two variables, not that one causes the other.
Related Calculators
Probability Calculator
Calculate simple probability from favorable and total outcomes, as a percentage, decimal, and simplified fraction, with the complement and step-by-step working.
Correlation Calculator
Calculate the Pearson correlation coefficient (r) from paired X and Y data, with its strength, direction, r², a scatter plot and the full calculation.
Linear Regression Calculator
Find the least-squares regression line from X and Y data: slope, intercept, R², r, predictions, residuals, a scatter plot and every calculation step.
Sample Size Calculator
Find the minimum sample size for a survey from the confidence level, margin of error, expected proportion and optional population size, with every step shown.
Confidence Interval Calculator
Calculate a confidence interval for a population mean from the sample mean, standard deviation and sample size, using t or z, with the margin of error and every step.
Z-Score Calculator
Calculate a z-score from a value, mean and standard deviation, with the steps, what it means, a bell-curve chart and the normal-distribution percentile.
Last updated: September 27, 2026.