Chi-Square Test Calculator

Test independence in contingency tables.

Enter at least 2 rows of data

Examples:

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 AOutcome BTotal
Group 1302050
Group 2153550
Total4555100

Observed frequencies: What we actually counted. Expected frequencies: What we'd expect if variables were independent.

Calculating Expected Frequencies

E=Row Total×Column TotalGrand TotalE = \frac{\text{Row Total} \times \text{Column Total}}{\text{Grand Total}}

For cell (Group 1, Outcome A):

E=50×45100=22.5E = \frac{50 \times 45}{100} = 22.5

ExpectedOutcome AOutcome B
Group 122.527.5
Group 222.527.5

If independent, both groups would have the same proportions (45% A, 55% B).

The Chi-Square Statistic

χ2=∑(O−E)2E\chi^2 = \sum \frac{(O - E)^2}{E}

Sum over all cells.

CellOE(O-E)²(O-E)²/E
G1, A3022.556.252.50
G1, B2027.556.252.05
G2, A1522.556.252.50
G2, B3527.556.252.05
Total9.09

χ2=9.09\chi^2 = 9.09

Degrees of Freedom

df=(r−1)×(c−1)df = (r - 1) \times (c - 1)

Where rr = rows, cc = columns.

For 2×2 table: df=1×1=1df = 1 \times 1 = 1

For 3×4 table: df=2×3=6df = 2 \times 3 = 6

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:

V=χ2n×min⁡(r−1,c−1)V = \sqrt{\frac{\chi^2}{n \times \min(r-1, c-1)}}

For 2×2: V = √(9.09 / 100) = 0.30

VInterpretation (df* = 1)
0.10Small
0.30Medium
0.50Large

df is the smaller of (r-1) or (c-1)

The Continuity Correction (Yates)

For 2×2 tables with small expected frequencies:

χ2=∑(∣O−E∣−0.5)2E\chi^2 = \sum \frac{(|O - E| - 0.5)^2}{E}

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 1Col 2
Row 1ab
Row 2cd

χ2=n(ad−bc)2(a+b)(c+d)(a+c)(b+d)\chi^2 = \frac{n(ad - bc)^2}{(a+b)(c+d)(a+c)(b+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

O−EE\frac{O - E}{\sqrt{E}}

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

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.