A chi-square test checks whether two categorical variables are related — for example, whether gender is associated with preferring coffee or tea — by comparing the counts you actually observed against the counts you'd expect if there were no relationship at all. If you're staring at a table of counts (yes/no, male/female, pass/fail) and wondering whether the pattern is real or just chance, this is almost certainly the test you need. The confusion usually starts because there are two different chi-square tests, and picking the wrong one wastes hours.
Key Takeaways
- The chi-square test of independence tests whether two categorical variables are related (e.g., treatment group vs. recovery outcome).
- The chi-square goodness-of-fit test tests whether one categorical variable matches an expected distribution (e.g., are dice rolls evenly spread?).
- Chi-square works on counts, not averages — use it when your data are frequencies in categories, not measurements like height or score.
- A result is statistically significant when p < .05, meaning the association you see is unlikely to be due to chance.
- Report effect size with Cramér's V or phi (φ), because a significant p-value alone doesn't tell you how strong the relationship is.
What is a chi-square test in plain English?
A chi-square test asks one simple question: are the counts in my categories different from what I'd expect by chance? It works entirely with frequencies — how many people fall into each box of a table. If you surveyed 200 people and recorded whether they smoke and whether they exercise, a chi-square test tells you whether smoking and exercising are linked, or whether the split you observed is just random noise.
The name comes from the test statistic, written χ² (the Greek letter "chi", pronounced "kye"). The bigger χ² is, the further your observed counts are from the "no relationship" scenario — and the more likely the relationship is real.
When should I use a chi-square test?
Use a chi-square test when both of your variables are categorical — nominal groups like yes/no, male/female/other, or brand A/B/C — and you want to know if they're related. It is not for continuous data. If you're comparing average test scores between two groups, you want a t-test; if you're comparing more than two group means, you want ANOVA.
There are two versions, and knowing which you need is half the battle:
| Test | Use it when | Example question |
|---|---|---|
| Chi-square test of independence | You have two categorical variables and want to know if they're associated | Is voting preference related to age group? |
| Chi-square goodness-of-fit | You have one categorical variable and want to compare it to an expected distribution | Are customers evenly split across four store locations? |
One practical rule: chi-square assumes each expected count is at least 5. If your table has tiny cells (many expected counts below 5), use Fisher's exact test instead — StatRyx flags this automatically and switches tests for you.
Chi-square test explained with a worked example
Let's walk through a chi-square test of independence with real numbers. Suppose you're a psychology student studying whether a new study-skills workshop affects exam outcomes. You track 120 students: some attended the workshop, some didn't, and you record whether each passed or failed.
Here's your observed contingency table:
| Passed | Failed | Row total | |
|---|---|---|---|
| Attended workshop | 45 | 15 | 60 |
| Did not attend | 30 | 30 | 60 |
| Column total | 75 | 45 | 120 |
Step 1: Calculate the expected counts
The expected count for each cell (assuming no relationship) is:
(row total × column total) ÷ grand total
For "Attended + Passed": (60 × 75) ÷ 120 = 37.5. Doing this for all four cells:
| Passed (expected) | Failed (expected) | |
|---|---|---|
| Attended | 37.5 | 22.5 |
| Did not attend | 37.5 | 22.5 |
Step 2: Compute the chi-square statistic
For each cell, calculate (observed − expected)² ÷ expected, then add them all up:
- (45 − 37.5)² ÷ 37.5 = 1.50
- (15 − 22.5)² ÷ 22.5 = 2.50
- (30 − 37.5)² ÷ 37.5 = 1.50
- (30 − 22.5)² ÷ 22.5 = 2.50
Sum: χ² = 1.50 + 2.50 + 1.50 + 2.50 = 8.00
Step 3: Find the degrees of freedom and p-value
Degrees of freedom = (rows − 1) × (columns − 1) = (2 − 1) × (2 − 1) = 1.
With χ²(1) = 8.00, the p-value is .005 — well below .05. Because p is small, you reject the idea that workshop attendance and passing are unrelated. Attendance and exam outcome are associated.
Step 4: Measure the effect size
A significant result tells you the relationship is real, not how big it is. For a 2×2 table, use phi (φ):
φ = √(χ² ÷ N) = √(8.00 ÷ 120) = √0.0667 = 0.26
A φ of about 0.26 is a small-to-moderate effect. For larger tables, use Cramér's V instead, interpreted the same way (0.1 = small, 0.3 = medium, 0.5 = large).
What counts as a significant result?
A chi-square result is statistically significant when the p-value is below your threshold — almost always .05 in psychology and the social sciences. A p of .005, as in our example, means there's only a 0.5% chance you'd see a difference this large if attendance and passing were genuinely unrelated. Crucially, "significant" does not mean "large" or "important" — that's what the effect size (φ or Cramér's V) is for. Always report both.
How do I report a chi-square test in APA 7 format?
APA 7 wants the test statistic, degrees of freedom, sample size, exact p-value, and an effect size. Italicise χ² and p, and drop the leading zero on p. For our example:
A chi-square test of independence showed a significant association between workshop attendance and exam outcome, χ²(1, N = 120) = 8.00, p = .005, φ = .26.
That single sentence is publication-ready. The (1, N = 120) gives the degrees of freedom and total sample size; φ = .26 communicates a small-to-moderate effect.
Getting the notation exactly right — italics, no leading zero, effect size included — is where a lot of manuscripts get flagged. StatRyx runs the chi-square test, checks your assumptions, and hands you the APA 7 sentence already formatted, so you can paste it straight into your results section.
Chi-square vs. Fisher's exact vs. the t-test
Choosing the right test trips up most non-statisticians. Here's the quick decision guide:
| If your data are… | Use… |
|---|---|
| Two categorical variables, expected counts ≥ 5 | Chi-square test of independence |
| Two categorical variables, small expected counts | Fisher's exact test |
| One categorical variable vs. expected distribution | Chi-square goodness-of-fit |
| A categorical group vs. a continuous outcome (2 groups) | Independent-samples t-test |
If you're deciding between comparing counts and comparing means, see our guide on choosing the right statistical test — it maps your variable types to the correct analysis in under a minute.
Stop calculating this by hand — run it free in StatRyx → Try StatRyx