Achievable logoAchievable logo
AP Statistics
Sign in
Sign up
Purchase
Textbook
Practice exams
Support
How it works
Resources
Exam catalog
Mountain with a flag at the peak
Textbook
Introduction
1. One variable data
2. Two variable data
3. Data collection
4. Probability and random variables
5. Sampling distributions
6. Categorical data
7. Quantitative data
8. Chi-square
8.1 Goodness of fit test
8.2 Independence test
8.3 Homogeneity test
9. Linear regression
Wrapping up
Achievable logoAchievable logo
8.2 Independence test
Achievable AP Statistics
8. Chi-square
Our AP Statistics course is currently in development and is a work-in-progress.

Independence test

6 min read
Font
Discuss
Share
Feedback

Chi-square test of independence

The chi-square test of independence helps you decide whether two categorical variables are independent (unrelated) or whether there’s a statistically significant association between them. You use this test when your data are frequency counts (how many observations fall into each category combination) for two categorical variables.

Definitions
Chi-square test of independence
A hypothesis test used to determine whether two categorical variables, organized in a contingency table, are independent or associated.
Observed frequency (Oij​)
The actual count in the cell at the intersection of row i and column j.
Expected frequency (Eij​)
The count expected in cell (i,j) if the two variables were independent.

Hypotheses:

Null hypothesis (H0​): The two variables are independent and there is no association between them. Knowing the value of one variable provides no information about the value of the other.

Alternative hypothesis (Ha​): The two variables are not independent and there is an association between them. The distribution of one variable depends on the distribution of the other.

When to use this test

Some situations where the chi-square test of independence is appropriate:

  1. Is a customer’s preference for a product independent of the state that the customer lives in?
  2. Is level of education independent of opinion on a policy?
  3. Is the number of defective products independent of the time of day they were made?

Key equations

Definitions
Chi-square test statistic
Measures the total discrepancy between observed and expected frequencies. A large χ2 value indicates a large discrepancy, providing evidence against the null hypothesis of independence.

χ2​=∑Eij​(Oij​−Eij​)2​​

Expected frequency
The count expected in a cell if the two variables were independent.

Eij​​=Grand Total(Row Totali​)(Column Totalj​)​​

Degrees of freedom (df)
Defines the shape of the chi-square distribution used for the test, where r is the number of rows and c is the number of columns.

df​=(r−1)(c−1)​

Cramér’s V
A measure of the strength of the association (effect size).

V​=n⋅(min(r,c)−1)χ2​​​

Decision rule

  • If χcalculated2​>χcritical2​: Reject the null hypothesis H0​ and conclude there is a statistically significant association between the variables.
  • If χcalculated2​≤χcritical2​: Fail to reject H0​. There is not enough evidence to conclude an association exists.

For the test to be valid, the following assumptions must be met:

  1. Both variables must be categorical.
  2. The observations must be independent of one another (one person’s response doesn’t influence another person’s response).
  3. No more than 20% of the expected cells should have a frequency less than 5, and no expected cell count should be less than 1. Otherwise, the test may not be reliable.

Practice problem

Example:

A researcher wants to know if there is an association between a person’s age group and their preferred social media platform. They survey 300 people and obtain the following results:

Instagram TikTok Facebook Total
Teens 60 40 10 110
Adults 40 30 120 190
Total 100 70 130 300

Part a.

State the hypotheses.

Solution:

(spoiler)

Null hypothesis (H0​): Age group and social media preference are independent. There is no association between them.

Alternative hypothesis (Ha​): Age group and social media preference are not independent. There is an association between them.

Part b.

Calculate the expected frequencies Eij​.

Use the formula:

Eij​​=Grand Total(Row Totali​)(Column Totalj​)​​

Compute for each cell:

ET,IG​​=300(110)(100)​=30011,000​≈36.67​

ET,TT​​=300(110)(70)​=3007,700​≈25.67​

ET,FB​​=300(110)(130)​=30014,300​≈47.67​

EA,IG​​=300(190)(100)​=30019,000​≈63.33​

EA,TT​​=300(190)(70)​=30013,300​≈44.33​

EA,FB​​=300(190)(130)​=30024,700​≈82.33​

Solution:

(spoiler)
Instagram TikTok Facebook
Teens ≈36.67 ≈25.67 ≈47.67
Adults ≈63.33 ≈44.33 ≈82.33

All expected frequencies are greater than 5, so we can proceed with the test.

Part c.

Calculate the test statistic χ2.

Use the formula:

χ2​=∑Eij​(Oij​−Eij​)2​​

Compute each term:

36.67(60−36.67)2​​=36.67(23.33)2​=36.67544.29​≈14.84​

25.67(40−25.67)2​​=25.67(14.33)2​=25.67205.35​≈8.00​

47.67(10−47.67)2​​=47.67(−37.67)2​=47.671,419.03​≈29.78​

63.33(40−63.33)2​​=63.33(−23.33)2​=63.33544.29​≈8.59​

44.33(30−44.33)2​​=44.33(−14.33)2​=44.33205.35​≈4.63​

82.33(120−82.33)2​​=82.33(37.67)2​=82.331,419.03​≈17.24​

Sum the terms:

χ2​≈14.84+8.00+29.78+8.59+4.63+17.24​

Solution:

(spoiler)

χ2​≈83.08​

Part d.

Determine the degrees of freedom df.

Use the formula:

df​=(r−1)(c−1)​

There are r=2 rows (Teens, Adults) and c=3 columns (Instagram, TikTok, Facebook).

df​=(2−1)(3−1)=(1)(2)​

Solution:

(spoiler)

df​=2​

Part e.

Make a decision using the decision rule.

Compare the test statistic to the critical value from a chi-square distribution table with df=2 and a significance level of α=0.05:

χcritical2​​=5.991​

Compare the values:

83.08​>5.991​

Solution:

(spoiler)

Since χcalculated2​>χcritical2​, we reject the null hypothesis H0​.

Part f.

Interpret the results in context.

Solution:

(spoiler)

There is strong evidence that suggests age group and social media preference are not independent and that there is an association between them.

Chi-square test of independence: Purpose and hypotheses

  • Tests association vs. independence between two categorical variables
  • Null hypothesis (H0​): variables are independent (no association)
  • Alternative hypothesis (Ha​): variables are not independent (association exists)

When to use

  • Data: frequency counts for combinations of two categorical variables
  • Examples: product preference vs. state, education level vs. policy opinion

Key equations and calculations

  • Test statistic: χ2=∑Eij​(Oij​−Eij​)2​
    • Oij​: observed frequency in cell (i,j)
    • Eij​: expected frequency in cell (i,j)
  • Expected frequency: Eij​=Grand Total(Row Totali​)×(Column Totalj​)​
  • Degrees of freedom: df=(r−1)(c−1)
    • r: number of rows, c: number of columns
  • Effect size (Cramer’s V): V=n×(min(r,c)−1)χ2​​

Decision rules

  • If χcalculated2​>χcritical2​: reject H0​ (evidence of association)
  • If χcalculated2​≤χcritical2​: fail to reject H0​ (no evidence of association)
  • P-value approach:
    • p<α: reject H0​
    • p>α: fail to reject H0​

Assumptions and conditions

  • Both variables must be categorical
  • Observations must be independent
  • No more than 20% of expected cell counts <5; no expected cell <1

Interpreting results

  • Large χ2 (small p-value): strong evidence of association
  • Small χ2 (large p-value): little evidence against independence

Sign up for free to take 6 quiz questions on this topic

Previous
Next  | 8.3 Homogeneity test
All rights reserved ©2016 - 2026 Achievable, Inc.

Independence test

Chi-square test of independence

The chi-square test of independence helps you decide whether two categorical variables are independent (unrelated) or whether there’s a statistically significant association between them. You use this test when your data are frequency counts (how many observations fall into each category combination) for two categorical variables.

Definitions
Chi-square test of independence
A hypothesis test used to determine whether two categorical variables, organized in a contingency table, are independent or associated.
Observed frequency (Oij​)
The actual count in the cell at the intersection of row i and column j.
Expected frequency (Eij​)
The count expected in cell (i,j) if the two variables were independent.

Hypotheses:

Null hypothesis (H0​): The two variables are independent and there is no association between them. Knowing the value of one variable provides no information about the value of the other.

Alternative hypothesis (Ha​): The two variables are not independent and there is an association between them. The distribution of one variable depends on the distribution of the other.

When to use this test

Some situations where the chi-square test of independence is appropriate:

  1. Is a customer’s preference for a product independent of the state that the customer lives in?
  2. Is level of education independent of opinion on a policy?
  3. Is the number of defective products independent of the time of day they were made?

Key equations

Definitions
Chi-square test statistic
Measures the total discrepancy between observed and expected frequencies. A large χ2 value indicates a large discrepancy, providing evidence against the null hypothesis of independence.

χ2​=∑Eij​(Oij​−Eij​)2​​

Expected frequency
The count expected in a cell if the two variables were independent.

Eij​​=Grand Total(Row Totali​)(Column Totalj​)​​

Degrees of freedom (df)
Defines the shape of the chi-square distribution used for the test, where r is the number of rows and c is the number of columns.

df​=(r−1)(c−1)​

Cramér’s V
A measure of the strength of the association (effect size).

V​=n⋅(min(r,c)−1)χ2​​​

Decision rule

  • If χcalculated2​>χcritical2​: Reject the null hypothesis H0​ and conclude there is a statistically significant association between the variables.
  • If χcalculated2​≤χcritical2​: Fail to reject H0​. There is not enough evidence to conclude an association exists.

For the test to be valid, the following assumptions must be met:

  1. Both variables must be categorical.
  2. The observations must be independent of one another (one person’s response doesn’t influence another person’s response).
  3. No more than 20% of the expected cells should have a frequency less than 5, and no expected cell count should be less than 1. Otherwise, the test may not be reliable.

Practice problem

Example:

A researcher wants to know if there is an association between a person’s age group and their preferred social media platform. They survey 300 people and obtain the following results:

Instagram TikTok Facebook Total
Teens 60 40 10 110
Adults 40 30 120 190
Total 100 70 130 300

Part a.

State the hypotheses.

Solution:

(spoiler)

Null hypothesis (H0​): Age group and social media preference are independent. There is no association between them.

Alternative hypothesis (Ha​): Age group and social media preference are not independent. There is an association between them.

Part b.

Calculate the expected frequencies Eij​.

Use the formula:

Eij​​=Grand Total(Row Totali​)(Column Totalj​)​​

Compute for each cell:

ET,IG​​=300(110)(100)​=30011,000​≈36.67​

ET,TT​​=300(110)(70)​=3007,700​≈25.67​

ET,FB​​=300(110)(130)​=30014,300​≈47.67​

EA,IG​​=300(190)(100)​=30019,000​≈63.33​

EA,TT​​=300(190)(70)​=30013,300​≈44.33​

EA,FB​​=300(190)(130)​=30024,700​≈82.33​

Solution:

(spoiler)
Instagram TikTok Facebook
Teens ≈36.67 ≈25.67 ≈47.67
Adults ≈63.33 ≈44.33 ≈82.33

All expected frequencies are greater than 5, so we can proceed with the test.

Part c.

Calculate the test statistic χ2.

Use the formula:

χ2​=∑Eij​(Oij​−Eij​)2​​

Compute each term:

36.67(60−36.67)2​​=36.67(23.33)2​=36.67544.29​≈14.84​

25.67(40−25.67)2​​=25.67(14.33)2​=25.67205.35​≈8.00​

47.67(10−47.67)2​​=47.67(−37.67)2​=47.671,419.03​≈29.78​

63.33(40−63.33)2​​=63.33(−23.33)2​=63.33544.29​≈8.59​

44.33(30−44.33)2​​=44.33(−14.33)2​=44.33205.35​≈4.63​

82.33(120−82.33)2​​=82.33(37.67)2​=82.331,419.03​≈17.24​

Sum the terms:

χ2​≈14.84+8.00+29.78+8.59+4.63+17.24​

Solution:

(spoiler)

χ2​≈83.08​

Part d.

Determine the degrees of freedom df.

Use the formula:

df​=(r−1)(c−1)​

There are r=2 rows (Teens, Adults) and c=3 columns (Instagram, TikTok, Facebook).

df​=(2−1)(3−1)=(1)(2)​

Solution:

(spoiler)

df​=2​

Part e.

Make a decision using the decision rule.

Compare the test statistic to the critical value from a chi-square distribution table with df=2 and a significance level of α=0.05:

χcritical2​​=5.991​

Compare the values:

83.08​>5.991​

Solution:

(spoiler)

Since χcalculated2​>χcritical2​, we reject the null hypothesis H0​.

Part f.

Interpret the results in context.

Solution:

(spoiler)

There is strong evidence that suggests age group and social media preference are not independent and that there is an association between them.

Key points

Chi-square test of independence: Purpose and hypotheses

  • Tests association vs. independence between two categorical variables
  • Null hypothesis (H0​): variables are independent (no association)
  • Alternative hypothesis (Ha​): variables are not independent (association exists)

When to use

  • Data: frequency counts for combinations of two categorical variables
  • Examples: product preference vs. state, education level vs. policy opinion

Key equations and calculations

  • Test statistic: χ2=∑Eij​(Oij​−Eij​)2​
    • Oij​: observed frequency in cell (i,j)
    • Eij​: expected frequency in cell (i,j)
  • Expected frequency: Eij​=Grand Total(Row Totali​)×(Column Totalj​)​
  • Degrees of freedom: df=(r−1)(c−1)
    • r: number of rows, c: number of columns
  • Effect size (Cramer’s V): V=n×(min(r,c)−1)χ2​​

Decision rules

  • If χcalculated2​>χcritical2​: reject H0​ (evidence of association)
  • If χcalculated2​≤χcritical2​: fail to reject H0​ (no evidence of association)
  • P-value approach:
    • p<α: reject H0​
    • p>α: fail to reject H0​

Assumptions and conditions

  • Both variables must be categorical
  • Observations must be independent
  • No more than 20% of expected cell counts <5; no expected cell <1

Interpreting results

  • Large χ2 (small p-value): strong evidence of association
  • Small χ2 (large p-value): little evidence against independence

More from Chi-square

  • Goodness of fit test
  • Homogeneity test