Why You Need Chi-Square for Categorical Data
A political pollster surveys 500 voters to see whether party preference differs between urban and rural areas. A clinical researcher tests whether a new treatment works better than the standard one by comparing recovery rates. A quality manager checks whether defects occur equally across all shifts. In every case, the data is categorical — people belong to categories, not numbers on a continuous scale.
You cannot run a t-test or ANOVA on counts in categories. You need a test designed for categorical data. That test is the chi-square (χ²) test.
What Is the Chi-Square Test?
The chi-square test compares observed frequencies to expected frequencies. If the observed and expected counts are close, the test statistic is small and you have no evidence against the null hypothesis. If they diverge, the test statistic grows large and you may conclude the variables are not independent (or the distribution does not fit).
There are two main types:
- Chi-square test of independence: Do two categorical variables have a relationship? (e.g., is gender associated with voting preference?)
- Chi-square goodness of fit test: Does one categorical variable follow a specific distribution? (e.g., does a die produce each face equally?)
The Chi-Square Formula
The chi-square statistic is calculated as:
Where:
- O = observed frequency (what you actually counted)
- E = expected frequency (what you would expect if the null hypothesis were true)
- Σ = sum across all categories or cells in the table
The test statistic follows a chi-square distribution with degrees of freedom equal to (rows − 1) × (columns − 1) for the test of independence, or (categories − 1) for the goodness of fit test.
Chi-Square Test of Independence
The test of independence answers: are these two categorical variables related, or are they independent?
You start with a contingency table (also called a cross-tabulation or crosstab) that shows the frequency counts for each combination of categories. The null hypothesis states that the variables are independent — knowing one tells you nothing about the other.
The expected frequency for each cell is calculated as:
Chi-Square Goodness of Fit Test
The goodness of fit test answers: does one categorical variable follow a specific distribution? For example, is a six-sided die fair? Does a genetic cross produce offspring in a 9:3:3:1 ratio? Does customer preference follow a uniform distribution across four products?
You need only one categorical variable and a set of expected proportions. The degrees of freedom equal (number of categories − 1).
Assumptions of the Chi-Square Test
The chi-square test requires four assumptions:
- Categorical data: The variables must be categorical (nominal or ordinal), not continuous. You count frequencies in categories, not measure amounts.
- Independence: Each observation must be independent of every other observation. Each participant should contribute to only one cell in the table.
- Sufficient sample size: Expected frequencies in each cell should be at least 5. If expected counts are below 5, the chi-square approximation breaks down. Use Fisher’s exact test instead.
- Random sampling: Data should come from a random sample or randomized experiment.
When the expected frequency assumption is violated, you have several options: combine adjacent categories to increase expected counts, use Fisher’s exact test, or use a correction like Yates’ continuity correction for 2×2 tables.
Real-World Example: Gender and Product Preference
A marketing team surveys 300 customers about their preferred product color. They want to know if gender is associated with color preference. The contingency table is:
- Male: Red = 40, Blue = 60, Green = 50
- Female: Red = 60, Blue = 40, Green = 50
Running a chi-square test of independence produces χ²(2, N = 300) = 8.33, p = 0.016, Cramér’s V = 0.17. The result is significant at α = 0.05. Gender and product color preference are associated — males prefer blue, females prefer red.
The Cramér’s V of 0.17 indicates a small-to-moderate effect size. Even though the result is statistically significant, the practical importance is modest.
Effect Size: Cramér’s V
A significant chi-square tells you an association exists, but not how strong it is. Effect size measures like Cramér’s V fill this gap:
- Small effect: V = 0.10
- Medium effect: V = 0.30
- Large effect: V = 0.50
Cramér’s V ranges from 0 to 1, with 0 indicating no association and 1 indicating perfect association. For 2×2 tables, it equals the absolute value of the phi coefficient (φ).
Chi-Square vs. Other Tests
When should you use chi-square versus other tests?
- Chi-square vs. t-test: Use chi-square for categorical variables, t-test for comparing means of continuous variables.
- Chi-square vs. ANOVA: Same distinction — chi-square for counts in categories, ANOVA for means across groups.
- Chi-square vs. Fisher’s exact test: Use Fisher’s exact test when expected cell counts are below 5, or for small samples in 2×2 tables.
- Chi-square vs. McNemar’s test: Use McNemar’s test for paired categorical data (e.g., before/after measurements on the same subjects).
Reporting Chi-Square in APA Format
The APA style requires reporting the chi-square statistic, degrees of freedom, sample size, p-value, and effect size. The standard format is:
Example: χ²(2, N = 300) = 8.33, p = .016, Cramér’s V = .17. This tells the reader the test type, sample size, test statistic, significance, and effect size in one sentence.
When p < .001, report it as p < .001. For exact p-values, report to three decimal places (e.g., p = .023).
Common Mistakes
- Using chi-square on continuous data: Chi-square is for categories. If you have continuous data, use a t-test or ANOVA instead.
- Ignoring expected frequency assumptions: If expected counts are below 5, the chi-square test becomes unreliable. Check expected counts before running the test.
- Not reporting effect size: A significant chi-square with a tiny effect size (V < 0.10) may not be practically meaningful, regardless of sample size.
- Concluding causation: Chi-square tests for association, not causation. Two variables can be associated because of a confounding variable.
Next Steps
Chi-square tests are one of the most commonly used statistical tests in the social sciences, marketing research, and medicine. Our calculator handles both the test of independence and goodness of fit, returning the test statistic, p-value, and effect size with interpretation.
For more on categorical data analysis, read the full chi-square guide. If your data is paired or matched, the non-parametric tests guide covers alternatives like McNemar’s test.
Try it on your own data
DataTistics runs every test mentioned in this post, with interpretation already written for you.