Chi-Square Test of Independence
Test whether two categorical variables are associated using the chi-square test — from constructing contingency tables to interpreting Cramér's V effect size.
You'll learn
How to test for association between two categorical variables.
Use this when
You want to test if sex, smoking, or treatment is associated with a categorical outcome.
What the Chi-Square Test Does
The chi-square test of independence determines whether there is a statistically significant association between two categorical variables. It compares the observed frequencies in each cell of a contingency table to the frequencies you would expect if the variables were completely independent.
- ●Example: Is there an association between smoking status (yes/no) and lung cancer diagnosis (yes/no)?
- ●Example: Does treatment group (placebo/drug A/drug B) affect diabetes status (diabetic/non-diabetic)?
- ●H₀: The two variables are independent (no association)
- ●H₁: The two variables are associated
The Contingency Table
A contingency table (cross-tabulation) shows the joint frequency distribution of two categorical variables. For a 2×2 table with variables A (yes/no) and B (yes/no):
- ●Each cell shows the observed count (O)
- ●Row totals and column totals (marginals) are used to calculate expected counts (E)
- ●Expected count for each cell: E = (Row total × Column total) / Grand total
Calculating and Interpreting χ²
χ² = Σ [ (O - E)² / E ]
Large χ² values indicate large deviations between observed and expected counts — suggesting the variables are not independent. The p-value comes from comparing χ² to a chi-square distribution with df = (rows-1) × (columns-1).
- ●df = (r-1)(c-1) where r = number of rows, c = number of columns
- ●For a 2×2 table: df = 1
- ●For a 3×2 table: df = 2
- ●Assumption: Expected count in every cell should be ≥ 5. If not, use Fisher's exact test.
Effect Size: Cramér's V
Like all tests, χ² can be significant with large samples even for trivial associations. Use Cramér's V to measure effect size:
V = √[ χ² / (N × min(r-1, c-1)) ]
- ●V = 0.1 → Small effect
- ●V = 0.3 → Medium effect
- ●V = 0.5 → Large effect
- ●V ranges from 0 (no association) to 1 (perfect association)
How to Report Results
Example: "There was a significant association between smoking status and lung cancer diagnosis, χ²(1, N = 500) = 24.8, p < 0.001, V = 0.22 (small-to-medium effect). Lung cancer was present in 35% of smokers vs. 12% of non-smokers."
Always report: the χ² value, degrees of freedom, N, p-value, Cramér's V, and the actual percentages in each cell.
Practice with your own dataset
Upload a dataset with two categorical variables and run the Chi-Square test to check for association.
Required variables
- • Two categorical variables
- 1.Upload a dataset with two categorical variables (e.g., sex and diabetes)
- 2.Select "Chi-Square" from the analysis menu
- 3.Assign the two categorical variables to Variable 1 and Variable 2
- 4.Review χ², df, p-value, and Cramér's V in the output
Trusted sources behind this lesson
Further reading
Read next
Correlation Analysis
Measure and interpret linear relationships between continuous variables using Pearson and Spearman correlations, and understand why correlation does not equal causation.