FreeStatisticalTools.com

Chi-Square Test of Independence: Step-by-Step Guide with Example

Test whether two categorical variables are related, with a worked example, the expected-count rule, standardized residuals, Cramér's V and an APA write-up.

The chi-square (χ²) test of independence checks whether two categorical variables are related. Is product preference related to age group? Is vaccination status related to region? Do pass rates differ between schools? If both of your variables are categories rather than measurements, this is usually the test you need.

Free tool · runs in your browserChi-Square Test of Independence CalculatorFree chi-square test calculator from raw data or a contingency table: expected counts, Yates correction, likelihood ratio, Cramér’s V and residuals.Run a chi-square test →
In this guide
  1. When to use the chi-square test of independence
  2. Hypotheses
  3. How the test works
  4. Assumptions
  5. Worked example
    1. Which cells drive the result? Standardized residuals
    2. Effect size: Cramér's V
  6. How to report it in APA 7
  7. Yates' correction and the likelihood ratio test
  8. Common mistakes
  9. Frequently asked questions

When to use the chi-square test of independence

  • You have two categorical variables (nominal or ordinal), for example gender × voting intention, or treatment group × recovered (yes/no).
  • Each participant appears in exactly one cell of the table.
  • Your data are counts (frequencies), not percentages or means.

If you have a single categorical variable and want to compare its distribution with expected proportions (for example, "are the four flavours chosen equally often?"), use the chi-square goodness-of-fit test instead. For the same people measured twice on a yes/no outcome, use the McNemar test.

Hypotheses

  • H₀: the two variables are independent (no association).
  • H₁: the two variables are associated.

How the test works

The test compares the observed counts in each cell with the counts you would expect if the variables were unrelated. For each cell:

expected count = (row total × column total) ÷ grand total

The χ² statistic adds up the squared differences, scaled by the expected counts:

χ² = Σ (observed − expected)² ÷ expected

The degrees of freedom are (rows − 1) × (columns − 1). The bigger χ² is relative to its degrees of freedom, the stronger the evidence of an association.

Assumptions

  1. Independent observations. Each person is counted once.
  2. Adequate expected counts. No expected count below 1, and no more than 20% of cells with expected counts below 5. For 2×2 tables with small expected counts, use Fisher's exact test.
  3. Counts, not percentages. Convert percentages back to counts before running the test.

Worked example

A brand surveys 300 customers and asks whether they would recommend it. It wants to know if recommendation differs by age group.

Observed counts

Would recommend?18–2930–4950+Total
Yes624830140
No385270160
Total100100100300

Expected counts (if age and recommendation were unrelated): 46.7 "yes" and 53.3 "no" in every age group. All expected counts are well above 5, so the assumption is met.

Result: χ²(2, N = 300) = 20.68, p < .001.

Recommendation rates clearly differ by age group: 62% of 18–29-year-olds would recommend the brand, compared with 48% of 30–49-year-olds and 30% of those aged 50 and over.

Which cells drive the result? Standardized residuals

A significant χ² tells you there is an association somewhere. Adjusted standardized residuals show where. Values beyond ±1.96 indicate cells that differ significantly from expectation at α = .05 (beyond ±2.58 for α = .01).

Would recommend?18–2930–4950+
Yes+3.76+0.33−4.09
No−3.76−0.33+4.09

Younger customers recommend more often than expected, and customers aged 50+ less often. The middle group is close to expectation.

Effect size: Cramér's V

χ² grows with sample size, so it is not an effect size. Use Cramér's V:

V = √( χ² ÷ (N × (k − 1)) ), where k is the smaller of the number of rows and columns.

Here, V = √(20.68 ÷ (300 × 1)) = .26.

Rough benchmarks depend on the degrees of freedom. For df* = k − 1 = 1, Cohen's guidelines are .10 (small), .30 (medium) and .50 (large); for df* = 2 they are about .07, .21 and .35. So V = .26 is a small-to-medium association. For 2×2 tables, Cramér's V equals the phi coefficient (φ).

How to report it in APA 7

How to report it (APA 7)

A chi-square test of independence showed a significant association between age group and willingness to recommend the brand, χ²(2, N = 300) = 20.68, p < .001, Cramér's V = .26. Customers aged 18–29 were more likely to recommend the brand (62%) than those aged 30–49 (48%) or 50 and over (30%).

Include the contingency table (counts and percentages) in your results section or an appendix. Readers need it to understand the pattern.

Yates' correction and the likelihood ratio test

  • Yates' continuity correction is sometimes applied to 2×2 tables. It makes the test conservative, and many statisticians no longer recommend it; Fisher's exact test is a better option when counts are small.
  • The likelihood ratio chi-square (G²) is an alternative statistic that usually gives very similar results with adequate samples.

The free chi-square calculator reports Pearson's χ², the Yates-corrected value for 2×2 tables, the likelihood ratio test, expected counts, residuals and Cramér's V, so you can report whichever your field expects.

Common mistakes

  • Running the test on percentages. It needs raw counts.
  • Ignoring small expected counts. Merge sparse categories if that makes sense, or use Fisher's exact test.
  • Counting the same person more than once, for example with multiple-response survey questions.
  • Stopping at "significant". Report Cramér's V and describe which cells drive the effect.

Frequently asked questions

What is the minimum sample size for a chi-square test?

There is no fixed minimum sample size. The rule is about expected counts: no expected count below 1, and no more than 20% of cells below 5. If that fails in a 2×2 table, use Fisher's exact test.

What is the difference between chi-square test of independence and goodness of fit?

The test of independence checks whether two categorical variables are related. The goodness-of-fit test compares one categorical variable with a set of expected proportions.

How do I interpret Cramér's V?

Cramér's V runs from 0 (no association) to 1 (perfect association). Interpretation depends on table size; for a 2×2 table, about .10 is small, .30 medium and .50 large.

Can I use chi-square for ordinal variables?

Yes, but it ignores the ordering. If both variables are ordinal, a test of trend or a rank correlation such as Spearman's rho can be more powerful.

Cite the tool (APA 7)
Xavier, B. (2026). Chi-Square Test of Independence Calculator [Web application]. FreeStatisticalTools.com. https://freestatisticaltools.com/chi-square-test-calculator/

Free tools used in this guide

Cite this article

If this guide helped your thesis, paper or class, please cite it. If you ran the analysis with one of our tools, cite the tool as well (each tool page has its own citation).

bibinxavier54 (2026, October 14). Chi-Square Test of Independence: Step-by-Step Guide with Example. FreeStatisticalTools.com Blog. https://freestatisticaltools.com/blog/chi-square-test-of-independence/

About bibinxavier54

Bibin Xavier is a researcher and the creator of FreeStatisticalTools.com, a set of free, browser-based statistics tools for students and researchers.

Author profile →

Ask a question or leave a comment

Your email address will not be published. Required fields are marked *