Chi-Square Test of Independence
Test whether two categorical variables are associated using a contingency table. Get the chi-square statistic, degrees of freedom, p-value and an effect-size measure, with expected-count conditions checked.
Run Independence Test →What is a Chi-Square Test of Independence?
A chi-square test of independence examines whether two categorical variables are related. The data is arranged in a contingency table, with the categories of one variable as rows and the other as columns, and the cells holding the observed counts of each combination.
Under the null hypothesis of independence, the two variables are unrelated, and the expected count in each cell is determined purely by the row and column totals. The test compares these expected counts against the observed counts; a large discrepancy indicates the variables are associated.
The test reports whether an association exists but not how strong it is. Because a large sample can make even a trivial association statistically significant, an effect-size measure such as Cramer's V or the phi coefficient should accompany the p-value to convey the practical strength of the relationship.
In plain terms: You have two categorical things, say region and preferred product, laid out in a grid of counts. This test asks whether the two are linked or just independent. It tells you if there's a relationship; an effect-size number tells you whether that relationship is big enough to care about.
Key Points
Contingency Table
Two categorical variables cross-tabulated into rows and columns; each cell holds the observed count of that combination.
Expected from Margins
Under independence, each cell's expected count is (row total × column total) / grand total.
Effect Size
Cramer's V or phi measures the strength of association, essential because significance alone can be driven by large samples.
Key Formulas
Interpreting the Result
A small p-value means the two variables are associated: the observed cell counts differ from what independence predicts by more than chance. But significance says nothing about strength.
Always report an effect size. With a large sample, a negligible association can be statistically significant, so Cramer's V (ranging from 0 to 1) is what tells you whether the relationship matters in practice.
Assumptions & Validation
Independent Observations
Each observation is counted in exactly one cell and is independent of the others.
If violated: Paired categorical data needs McNemar's test.
Adequate Expected Counts
Expected cell counts are large enough (commonly at least 5 in most cells).
If violated: Combine categories or use Fisher's exact test.
Categorical Data
Both variables are categorical, with counts not percentages.
If violated: Use correlation or regression for continuous variables.
⚠️ Check assumptions first
As with goodness-of-fit, the chi-square independence test needs adequate expected cell counts, commonly at least 5 in most cells; sparse tables make the p-value unreliable, and Fisher's exact test is the alternative for small samples. Just as important, statistical significance is not strength: in large samples a trivial association can be significant, so always report Cramer's V or phi alongside the p-value.
When NOT to Use Chi-Square Test of Independence
Single Variable
To test one variable's distribution against an expectation, use the goodness-of-fit test.
Small or Sparse Tables
For small samples or many low-count cells, use Fisher's exact test.
Paired Categorical Data
For matched or before-and-after categorical outcomes, use McNemar's test.
Industry Applications
Market Segmentation
Test whether a preference or behavior is associated with a demographic category.
Quality vs Factor
Test whether defect type is associated with shift, line, or supplier.
Survey Cross-Tabs
Test whether two survey responses are related in a contingency table.
Treatment vs Outcome
Test whether a categorical outcome is associated with a categorical group.
Frequently Asked Questions
What does the chi-square test of independence tell me?
It tells you whether two categorical variables are associated, that is, whether the distribution of one variable depends on the other. Using a contingency table, it compares the observed cell counts against the counts expected if the variables were independent. A significant result means an association exists, but it does not, on its own, indicate how strong that association is or its direction.
How are expected counts calculated in a contingency table?
Under the null hypothesis of independence, each cell's expected count equals the product of its row total and column total divided by the grand total. This reflects the counts you would expect if the two variables had no relationship and only the marginal totals mattered. The test then measures how far the observed counts stray from these expected values across all cells.
Why do I need an effect size like Cramer's V?
The chi-square statistic and its p-value tell you whether an association is statistically significant, but with a large sample even a trivial association can reach significance. Cramer's V, which ranges from 0 to 1, measures the strength of the association independently of sample size. Reporting it alongside the p-value distinguishes a meaningful relationship from one that is statistically detectable but practically negligible.
What are the degrees of freedom for this test?
The degrees of freedom equal the number of rows minus one, multiplied by the number of columns minus one. For a two-by-two table this gives one degree of freedom, while larger tables have more. The degrees of freedom set the shape of the chi-square distribution used to convert the test statistic into a p-value.
When should I use Fisher's exact test instead?
Fisher's exact test is preferred when the sample is small or the contingency table has cells with low expected counts, typically below 5, where the chi-square approximation becomes unreliable. Fisher's test computes exact probabilities rather than relying on the chi-square distribution, so it remains valid for sparse tables, most commonly two-by-two tables with small samples.
Does a significant chi-square test prove causation?
No. A significant result shows that two categorical variables are associated, but association is not causation. A third, confounding variable may drive the relationship, or the causal direction may be unclear. Establishing causation requires a controlled experiment or careful adjustment for confounders; the chi-square test only detects that the variables are statistically related.
Test Association Between Two Categories
Run a chi-square independence test with effect size. Free during Beta.
Run Independence Test →