Chi-Square Test of Independence & ANOVA Basics0%

Chi-Square Test of Independence & ANOVA Basics

Beginner12 min read•Updated: Jul 11, 2026
Study Materials

Chi-Square Test of Independence & ANOVA Basics

Reading Time: 8 Mins | Level: Intermediate


1. When Categorical Data Meets Statistics: Chi-Square

While t-tests compare numerical means, the Chi-Square ($\chi^2$) Test of Independence evaluates whether two categorical variables are independent or related (e.g., Is Customer Churn related to Device Type: Mobile vs Desktop?).

Python
import pandas as pd
from scipy import stats
 
# Contingency Table: Device vs Churn
# Rows: Mobile, Desktop; Columns: Retained, Churned
contingency_table = [
[120, 30], # Mobile: 120 retained, 30 churned
[80, 50] # Desktop: 80 retained, 50 churned
]
 
chi2_stat, p_val, dof, expected = stats.chi2_contingency(contingency_table)
 
print(f"Chi2 Statistic: {chi2_stat:.4f}")
print(f"P-Value: {p_val:.4f}")

2. Comparing 3 or More Means: One-Way ANOVA

A common amateur mistake is running multiple t-tests to compare 3 or more groups (e.g. Sales across North, South, East, West). Doing so multiplies your Type I error rate!

Instead, use ANOVA (Analysis of Variance), which uses the F-statistic to evaluate whether at least one group mean differs:

Python
group_north = [45, 52, 48, 50]
group_south = [65, 70, 68, 72]
group_east = [55, 58, 54, 57]
 
f_stat, p_val = stats.f_oneway(group_north, group_south, group_east)
print(f"ANOVA F-Stat: {f_stat:.4f}, P-Value: {p_val:.4f}")

Interactive Quiz

Multiple Choice Questions

Question 1
Which statistical test evaluates whether two categorical variables are independent of each other?
Question 2
Why should you NOT perform multiple pairwise t-tests to compare 4 regional groups?
Question 3
What is the test statistic calculated during an ANOVA test?
Question 4
If an ANOVA test yields $p = 0.002$, what is the conclusion?
Question 5
In stats.chi2_contingency(), what does the 'expected' return array represent?

Next Lesson

A/B Testing Framework for Business & Product Decisions

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext