Learn
Interactive·

Chi-square Test

How can we tell whether two categorical variables move together or merely look different by chance?

An online store wants to know whether checkout completion differs by payment method. The outcomes of 600 customers are cross-tabulated below.

Observed and expected counts

If payment method and checkout completion were unrelated, how many customers would we expect in each cell?

CompletedAbandonedTotal
Card180120300
Digital wallet24060300
Total420180600
Under independence, both payment groups would have the same completion rate. The expected counts are 210 and 90 in each row.

Completion is 80% with a digital wallet and 60% with a card. The question is whether that pattern is stronger than we would expect from sampling variation alone.

Key question

How far are the observed counts from the counts expected if the two variables were independent?

1

Concept

How do observed and expected counts differ?

Under independence, the proportions should match

The null hypothesis for a chi-square test of independence says that the two categorical variables are unrelated. Expected counts are calculated from the row totals and column totals.

Expected count

(row total × column total) ÷ grand total

For card users who completed checkout, the expected count is 300 × 420 ÷ 600 = 210. The observed count is 180.

2

Why It Matters

How is the χ² statistic built?

χ² combines the discrepancies across all cells

For each cell, the observed-minus-expected difference is squared and divided by the expected count. The cell contributions are then added.

How each cell contributes to χ²

Larger gaps between observed and expected counts contribute more.

CellObserved OExpected E(O−E)²/E
Card × completed1802104.29
Card × abandoned1209010.00
Wallet × completed2402104.29
Wallet × abandoned609010.00

Reading χ²

A larger χ² means the observed table is farther from the pattern expected under independence. The p-value, calculated with the degrees of freedom, determines statistical significance.

3

How It Works

What does a significant result tell us?

A significant result indicates association

Chi-square test of independence

Payment method × checkout completion

Significant

χ²

28.57

df

1

p-value

< .001

Cramér’s V

0.22

A small p-value leads us to reject independence. It does not establish that payment method caused the difference in checkout completion.

Association is not causation

Customers who choose digital wallets may already differ in purchase intent. The test detects association, not a causal mechanism.

Report effect size as well

With a very large sample, even a small difference in proportions can be significant. Cramér’s V is commonly used to describe the strength of association.

4

Example

When should the test be used?

Two chi-square questions

TestQuestionExample
Goodness of fitDoes one categorical variable follow a stated distribution?Are four brands preferred equally?
IndependenceAre two categorical variables associated?Is payment method related to completion?

Check before testing

  • Observations should be independent.
  • Each person should contribute to one cell only.
  • Too many cells should not have very small expected counts.
  • For a sparse 2×2 table, consider Fisher’s exact test.

A non-significant result

p = .31 does not prove independence. It means the current table does not provide enough evidence against it.

5

Interactive

Change the cell counts

Change the cell counts

Adjust the four cells below. The expected counts, χ² statistic, p-value, and Cramér’s V update together.

χ²

28.57

p

<0.0001

Cramér's V

0.218

Total n

600

Expected counts

210.0 · 90.0 · 210.0 · 90.0

What to observe

  • What happens to χ² when the row proportions become more similar?
  • What happens to the p-value when sample size grows but the proportions stay the same?
  • Does Cramér’s V grow at the same rate as χ²?
  • What problem appears when an expected count becomes very small?

Key lesson

The chi-square test evaluates how different the pattern of category proportions is from the expected pattern.

Key takeaways

  • Chi-square tests compare categorical counts.
  • Observed counts are compared with counts expected under the null hypothesis.
  • The χ² statistic combines discrepancies across all cells.
  • A significant result indicates association, not causation.
  • Cramér’s V can summarize association strength.
  • Fisher’s exact test may be better for sparse 2×2 tables.

The chi-square test asks whether the pattern of proportions differs, not merely whether the raw counts differ.

Now analyse a real contingency tableOpen in Lab

Go Deeper

ANOVA