Chi-Square Test Calculator
Perform chi-square goodness-of-fit tests or tests of independence. Calculate the chi-square statistic, p-value, degrees of freedom, and Cramér's V for effect size. See also our Chi-Square Distribution Calculator, ANOVA Calculator, and P-Value Calculator.
How to Use the Chi-Square Test Calculator
The chi-square test is a non-parametric test for categorical data. The goodness-of-fit test determines whether observed frequencies match expected frequencies from a theoretical distribution. The test of independence determines whether two categorical variables are associated in a contingency table.
For goodness of fit, enter observed and expected frequencies for each category. For the test of independence, specify the number of rows and columns in your contingency table, then enter the observed counts. The calculator computes the chi-square statistic, degrees of freedom, p-value, and (for independence tests) Cramér's V as a measure of effect size.
Requirements: (1) data must be frequencies (counts), not percentages, (2) expected frequencies should be at least 5 in each cell (some texts allow 80% of cells ≥ 5), (3) observations must be independent. If expected counts are too small, consider combining categories or using Fisher's exact test.
Formula
Chi-Square Statistic:
χ² = Σ (Oᵢ - Eᵢ)² / Eᵢ
Degrees of Freedom:
Goodness of Fit: df = k - 1
Independence: df = (r - 1)(c - 1)
Expected Frequency (Independence):
Eᵢⱼ = (Row Total × Column Total) / Grand Total
Cramér's V (Effect Size):
V = √(χ² / (n × (min(r,c) - 1)))
Example Calculation
Test whether gender and product preference are independent (2×3 table):
Observed: [[50, 30, 20], [30, 40, 30]]
Row totals: [100, 100], Col totals: [80, 70, 50]
Grand total: 200
Expected: [[40, 35, 25], [40, 35, 25]]
χ² = (50-40)²/40 + (30-35)²/35 + (20-25)²/25
+ (30-40)²/40 + (40-35)²/35 + (30-25)²/25
= 2.5 + 0.714 + 1.0 + 2.5 + 0.714 + 1.0 = 8.429
df = (2-1)(3-1) = 2
p-value = 0.0148
Cramér's V = √(8.429/(200×1)) = 0.205
Conclusion: Reject H₀ at α=0.05. Gender and preference are associated (small-medium effect).
Chi-Square Critical Values Reference Table
| 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 |
| 8 | 13.362 | 15.507 | 20.090 |
| 10 | 15.987 | 18.307 | 23.209 |
Step-by-Step Decision Process
- Identify the test type: Goodness-of-fit (one variable, testing expected proportions) or Test of Independence (two categorical variables in a contingency table).
- State hypotheses: H0: Observed matches expected (or variables are independent). H1: They differ (or variables are associated).
- Check assumptions: All expected frequencies are at least 5. Data are counts (not percentages or means).
- Calculate expected values: For independence: E = (row total x column total) / grand total.
- Compute test statistic: chi-square = Sum of (O-E)^2 / E for all cells.
- Determine df: Goodness-of-fit: k-1. Independence: (rows-1)(cols-1).
- Find p-value and decide: Compare chi-square to the critical value. If chi-square > critical, reject H0.
Additional Solved Examples
Example: Goodness-of-Fit - Dice Fairness
A die is rolled 120 times. Results: 1(25), 2(17), 3(22), 4(18), 5(19), 6(19). Is the die fair at alpha = 0.05?
Expected for each face = 120/6 = 20
chi-sq = (25-20)^2/20 + (17-20)^2/20 + (22-20)^2/20 + (18-20)^2/20 + (19-20)^2/20 + (19-20)^2/20
= 25/20 + 9/20 + 4/20 + 4/20 + 1/20 + 1/20
= 1.25 + 0.45 + 0.20 + 0.20 + 0.05 + 0.05 = 2.20
df = 6 - 1 = 5
Critical value (0.05, 5) = 11.07
Since 2.20 < 11.07, fail to reject H0
Answer: There is no significant evidence the die is unfair (chi-sq(5) = 2.20, p = 0.821). The observed frequencies are consistent with a fair die. Minor deviations are expected due to random chance.
Example: Test of Independence - Smoking and Lung Disease
Data from 500 patients: Smokers with disease (120), Smokers without (80), Non-smokers with disease (100), Non-smokers without (200). Test independence at alpha = 0.01.
Row totals: Smokers=200, Non-smokers=300
Column totals: Disease=220, No Disease=280
Expected: E(S,D)=200x220/500=88, E(S,ND)=200x280/500=112
E(NS,D)=300x220/500=132, E(NS,ND)=300x280/500=168
chi-sq = (120-88)^2/88 + (80-112)^2/112 + (100-132)^2/132 + (200-168)^2/168
= 1024/88 + 1024/112 + 1024/132 + 1024/168
= 11.64 + 9.14 + 7.76 + 6.10 = 34.63
df = (2-1)(2-1) = 1
Critical (0.01, 1) = 6.635
Since 34.63 >> 6.635, strongly reject H0
Answer: There is a highly significant association between smoking status and lung disease (chi-sq(1) = 34.63, p < 0.001). Smoking and disease are not independent in this population.
Interpreting Results
Effect Size Measures
The chi-square statistic alone does not measure effect strength. Use Cramer's V = sqrt(chi-sq / (n x min(r-1, c-1))) where r and c are rows and columns. V ranges from 0 (no association) to 1 (perfect association). For 2x2 tables, the phi coefficient = sqrt(chi-sq/n) is equivalent. Small: 0.1, Medium: 0.3, Large: 0.5.
Key Takeaways
- Chi-square tests analyze categorical data (counts/frequencies), not means or measurements.
- The test is always right-tailed because larger chi-square values indicate greater deviation from expected.
- All expected cell counts should be at least 5. If not, combine categories or use Fisher exact test.
- A significant chi-square test tells you an association exists but not its direction or magnitude - examine the residuals.
- The chi-square test cannot establish causation, only statistical association between variables.
Frequently Asked Questions
What is the chi-square test of independence?
The chi-square test of independence determines whether there is a statistically significant association between two categorical variables. It compares observed frequencies in a contingency table to the frequencies expected if the variables were independent. A significant result means the variables are associated, but does not indicate the strength or direction of the relationship — use Cramér's V for effect size.
What is the goodness-of-fit test?
The chi-square goodness-of-fit test determines whether observed frequency data matches a specified theoretical distribution. For example, testing whether a die is fair (expected: equal frequencies), whether data follows a Poisson distribution, or whether survey responses match population proportions. The null hypothesis is that the data follows the expected distribution.
What is Cramér's V and how do I interpret it?
Cramér's V is a measure of association (effect size) for the chi-square test of independence. It ranges from 0 (no association) to 1 (perfect association). Guidelines: V < 0.1 = negligible, 0.1-0.3 = small, 0.3-0.5 = medium, > 0.5 = large. Unlike the chi-square statistic, V is not affected by sample size, making it useful for comparing effect sizes across studies.
What if expected frequencies are less than 5?
The chi-square approximation is unreliable when expected frequencies are too small. The common rule is that all expected values should be ≥ 5 (or at least 80% of cells ≥ 5 with none < 1). Solutions: combine adjacent categories, use Fisher's exact test (for 2×2 tables), use the likelihood ratio test, or collect more data. Yates' continuity correction can help for 2×2 tables.
How do I determine degrees of freedom?
For goodness of fit: df = k - 1, where k is the number of categories. If you estimated parameters from the data, subtract one additional df per parameter. For independence: df = (r-1)(c-1), where r is the number of rows and c is the number of columns. For a 2×2 table, df = 1; for a 3×4 table, df = 6.
Can I use percentages instead of counts?
No. The chi-square test requires raw frequency counts (integers), not percentages or proportions. Using percentages inflates or deflates the chi-square statistic depending on sample size. If you only have percentages, multiply by the total sample size to convert back to counts. The test is sensitive to sample size — larger samples are more likely to find significant results even for small effects.