Chi-Square Test Calculator
Test independence in contingency tables.
Enter at least 2 rows of data
Enter a contingency table to test for independence
What Is the Chi-Square Test of Independence?
The chi-square test of independence determines whether two categorical variables are associated or independent.
Question answered: "Is there a relationship between these two categorical variables?"
Examples:
- "Is voting preference related to gender?"
- "Is treatment outcome associated with treatment type?"
- "Is product preference related to age group?"
Independence vs. Association
Independent variables: Knowing one tells you nothing about the other.
Associated variables: Knowing one changes your prediction of the other.
Example: If 60% of men prefer Product A and 60% of women also prefer Product A, gender and preference are independent. If 70% of men but only 40% of women prefer Product A, they're associated.
The Contingency Table
Data is organized in a two-way table:
| Outcome A | Outcome B | Total | |
|---|---|---|---|
| Group 1 | 30 | 20 | 50 |
| Group 2 | 15 | 35 | 50 |
| Total | 45 | 55 | 100 |
Observed frequencies: What we actually counted. Expected frequencies: What we'd expect if variables were independent.
Calculating Expected Frequencies
For cell (Group 1, Outcome A):
| Expected | Outcome A | Outcome B |
|---|---|---|
| Group 1 | 22.5 | 27.5 |
| Group 2 | 22.5 | 27.5 |
If independent, both groups would have the same proportions (45% A, 55% B).
The Chi-Square Statistic
Sum over all cells.
| Cell | O | E | (O-E)² | (O-E)²/E |
|---|---|---|---|---|
| G1, A | 30 | 22.5 | 56.25 | 2.50 |
| G1, B | 20 | 27.5 | 56.25 | 2.05 |
| G2, A | 15 | 22.5 | 56.25 | 2.50 |
| G2, B | 35 | 27.5 | 56.25 | 2.05 |
| Total | 9.09 |
Degrees of Freedom
Where = rows, = columns.
For 2×2 table:
For 3×4 table:
Finding the P-Value
Compare χ² to chi-square distribution with appropriate df.
For χ² = 9.09, df = 1: p = 0.0026
Conclusion: Significant association between group and outcome (p < 0.01).
Effect Size: Cramér's V
Chi-square increases with sample size. For interpretable effect size:
For 2×2: V = √(9.09 / 100) = 0.30
| V | Interpretation (df* = 1) |
|---|---|
| 0.10 | Small |
| 0.30 | Medium |
| 0.50 | Large |
df is the smaller of (r-1) or (c-1)
The Continuity Correction (Yates)
For 2×2 tables with small expected frequencies:
Reduces chi-square slightly, making the test more conservative.
Use when: Any expected frequency is between 5 and 10.
Modern recommendation: Often unnecessary with adequate sample sizes.
Assumptions and Requirements
Expected Frequencies
Traditional rule: All expected values ≥ 5.
Modern guidance:
- No expected frequency < 1
- No more than 20% of cells with expected < 5
If violated: Use Fisher's Exact Test.
Independence of Observations
Each observation belongs to exactly one cell. No subject appears in multiple cells.
Random Sampling
Data represents random sample from population of interest.
2×2 Tables: Direct Formula
For the standard 2×2 layout:
| Col 1 | Col 2 | |
|---|---|---|
| Row 1 | a | b |
| Row 2 | c | d |
Equivalent to the general formula but computationally simpler.
Larger Tables
For r×c tables beyond 2×2, the test indicates whether association exists anywhere in the table.
Significant result: At least one cell deviates from independence.
Next steps: Examine standardized residuals to identify which cells deviate most.
Standardized Residuals
Values > 2 or < -2 indicate cells that contribute most to the association.
Applications
Medical Research
Treatment response by treatment group. Disease incidence by exposure category.
Social Sciences
Political affiliation by demographic variables. Survey responses by respondent characteristics.
Marketing
Purchase decisions by customer segments. Brand preference by geographic region.
Quality Control
Defect types by production line. Pass/fail by shift or operator.
Genetics
Allele frequencies across populations. Phenotype associations.
Common Misconceptions
Chi-Square Shows Causation
False. It shows association, not causation. Other variables may explain the relationship.
Large χ² Means Strong Association
Partially true. χ² depends on sample size. Use Cramér's V for effect size.
Always Use Chi-Square for Categorical Data
False. For paired/matched data, use McNemar's test. For ordered categories, consider ordinal methods.
Chi-Square vs. Other Tests
Fisher's Exact Test
Use when expected frequencies are too small for chi-square.
Z-Test for Proportions
For comparing two proportions directly. Equivalent to chi-square for 2×2 tables.
G-Test (Likelihood Ratio)
Similar properties to chi-square. Some prefer for theoretical reasons.
McNemar's Test
For paired categorical data (before-after on same subjects).
Reporting Results
APA format:
"A chi-square test of independence revealed a significant association between group membership and outcome, χ²(1) = 9.09, p = .003, V = .30. Group 1 was more likely to show Outcome A (60%) compared to Group 2 (30%)."
Include:
- Chi-square value and df
- P-value
- Effect size (Cramér's V)
- Descriptive percentages or counts
Historical Context
Karl Pearson developed the chi-square test in 1900, making it one of the oldest formal hypothesis tests still in common use.
Pearson was motivated by the need to compare observed frequencies with theoretical expectations—initially for testing whether dice were fair or inheritance patterns followed predicted ratios.
The chi-square distribution itself had been described earlier, but Pearson established its application to contingency tables and goodness-of-fit testing.
Related Calculations
- Chi-Square Goodness-of-Fit — One variable
- Fisher's Exact Test — Small samples
- Two-Proportion Z-Test — Comparing proportions
- Chi-Square Distribution — P-values
- Odds Ratio Calculator — 2×2 effect size
Summary
The chi-square test of independence assesses whether two categorical variables are associated by comparing observed frequencies to those expected under independence. Calculate expected values as (row total × column total) / grand total, compute χ² = Σ(O-E)²/E, and compare to the chi-square distribution with (r-1)(c-1) degrees of freedom. Assumptions require adequate expected frequencies (≥5 in most cells). Report chi-square, df, p-value, and Cramér's V for effect size. For 2×2 tables with small expected values, use Fisher's Exact Test instead.