Professor Digitalfor studentsSign in

Chi-Square Test: Independence and Goodness of Fit, With Examples

Reviewed by Prof. Dr. Alexander Holtermann · Updated 16 October 2026 · 5 min read

The chi-square test checks whether two categorical variables are related (independence) or whether frequencies match an expected distribution.

Key takeaways

  • The chi-square test of independence analyzes a contingency table of two nominal or ordinal variables, for example study group membership × passing the exam.
  • It compares observed with expected frequencies: χ² = Σ (O − E)² / E, where E = row total × column total / N.
  • Degrees of freedom: (rows − 1) × (columns − 1) for independence; categories − 1 for goodness of fit.
  • Assumption: expected frequencies of at least 5 in (almost) all cells. Otherwise use Fisher’s exact test.
  • Report φ (2 × 2 tables) or Cramér’s V as the effect size: .10 small, .30 medium, .50 large for df = 1.

Two chi-square tests

The name chi-square test (χ² test, Pearson’s chi-square) covers two related tests for categorical data, i.e. counts of how many cases fall into each category.

  • Data: frequencies (counts), never means or percentages.
  • Each person appears in exactly one cell. Repeated measurements of the same people need McNemar’s test instead.
  • The test ignores the order of categories; for ordinal variables there are more powerful trend tests.
TestQuestionExampledf
Test of independenceAre two categorical variables related?Is passing related to joining a study group?(r − 1)(c − 1)
Goodness-of-fit testDoes one variable follow an expected distribution?Do students choose all three exam dates equally often?k − 1

Worked example: test of independence (2 × 2)

One hundred students are asked whether they joined a study group and whether they passed the statistics exam.

PassedFailedTotal
Study group40 (E = 32.5)10 (E = 17.5)50
No study group25 (E = 32.5)25 (E = 17.5)50
Total6535100

Larger tables and Cramér’s V

The same logic works for any r × c table. For tables larger than 2 × 2 the effect size is Cramér’s V: V = √(χ² / (N · (k − 1))), where k is the smaller of the number of rows and columns.

Preferred exam preparationFlashcardsSummariesPractice examsTotal
Bachelor’s students30201060
Master’s students20253580
Total504545140

Worked example: goodness-of-fit test

Sixty students can choose one of three exam dates. If there were no preference, you would expect 20 per date. Observed: 18, 30, 12.

χ² = (18 − 20)² / 20 + (30 − 20)² / 20 + (12 − 20)² / 20 = 0.2 + 5.0 + 3.2 = 8.40

df = 3 − 1 = 2, critical value 5.99, p = .015. The dates are not chosen equally often; the second date is clearly preferred.

Assumptions and small samples

The chi-square distribution is only an approximation, and it works well when the expected frequencies are not too small.

  • Expected frequencies: all E ≥ 5 is the classic rule; a common relaxed version allows up to 20% of cells with E < 5 as long as none is below 1.
  • Fisher’s exact test computes the exact p-value and is the standard alternative for small 2 × 2 tables.
  • Yates’ continuity correction for 2 × 2 tables makes the test more conservative. In the study-group example it gives χ² = 8.62, p = .003. Many statisticians consider it unnecessary today; whichever you use, say so.
  • Independence of observations: each person is counted once. Do not enter multiple answers of the same person as separate cases.
  • Do not merge categories after looking at the data just to obtain significance; merge only for substantive reasons or to meet the expected-frequency rule.

Sample size and power

For a 2 × 2 table, the power analysis tool estimates the sample size from the effect size w (equal to φ for 2 × 2): to detect a medium effect (w = .30) with α = .05 and power .80 you need 88 people in total; for a small effect (w = .10), 785.

How to report a chi-square test in APA style

Give the chi-square value with degrees of freedom and sample size in parentheses, the p-value and an effect size. Report the percentages that show the direction of the association, because χ² itself has no direction.

Doing this in SPSS, R or JASP

All programs compute the same Pearson chi-square. Note that R applies Yates’ continuity correction to 2 × 2 tables by default, so its value can differ slightly from the uncorrected statistic in SPSS.

ProgramHow to run it
SPSSAnalyze → Descriptive Statistics → Crosstabs; Statistics: Chi-square, Phi and Cramér’s V; Cells: Expected counts
Rchisq.test(table(df$a, df$b)); without Yates’ correction: correct = FALSE
JASP / jamoviFrequencies → Contingency Tables; tick Phi and Cramér’s V and expected counts
Statatabulate a b, chi2 V

Frequently asked questions

When do I use a chi-square test?

When both variables are categorical (nominal or ordinal with few categories) and you have counts: for example gender × choice of major, or yes/no answers in two groups.

What is the difference between chi-square and Fisher’s exact test?

The chi-square test uses an approximation that needs expected frequencies of about 5 or more. Fisher’s exact test computes the exact probability and is preferred for small samples, especially in 2 × 2 tables.

How do I calculate expected frequencies?

For each cell: row total × column total / overall total. In the example, 50 × 65 / 100 = 32.5.

Can I use percentages in a chi-square test?

No. The test needs absolute counts. Percentages hide the sample size, and the result would change with the scale.

What effect size goes with chi-square?

φ (phi) for 2 × 2 tables and Cramér’s V for larger tables. For df = 1, values of .10, .30 and .50 are considered small, medium and large.

Sources and further reading

  • Agresti, A., & Finlay, B. (2018). Statistical Methods for the Social Sciences (5th ed.). Pearson.
  • Howell, D. C. (2013). Statistical Methods for Psychology (8th ed.). Wadsworth Cengage Learning.
  • Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences (2nd ed.). Lawrence Erlbaum.

Your university’s examination regulations and style guide always take precedence.

Related articles