Module 11

Chi-Square Tests

Testing categorical data relationships

Chi-Square Applications

  • 01

    Goodness of Fit

    Does data match expected proportions?

  • 02

    Independence

    Are two categorical variables related?

  • 03

    Expected Frequencies

    What we'd see if H₀ were true

  • 04

    Interpretation

    Effect size and practical meaning

01

Goodness of Fit Test

Interactive Chi-Square Calculator

Chi-Square Calculator
Outcome AOutcome B
Group 1
Group 2
χ² statistic-
Degrees of freedom-
p-value-
Cramér's V-
Enter frequencies and click Calculate

Test for independence between two categorical variables! Enter observed frequencies in the 2×2 contingency table and click Calculate. The calculator computes χ², degrees of freedom, p-value, and Cramér's V effect size. Try different patterns to see when variables are associated vs. independent.

Testing Expected Proportions

Are dice fair? Roll 60 times:
⚀
Obs: 8
Exp: 10
⚁
Obs: 12
Exp: 10
⚂
Obs: 9
Exp: 10
⚃
Obs: 11
Exp: 10
⚄
Obs: 7
Exp: 10
⚅
Obs: 13
Exp: 10
Do observed frequencies match expected (1/6 each)?

Goodness of fit tests whether observed frequencies match expected proportions. If dice are fair, each face should appear equally often. Does the data fit this expectation?

The χ² Statistic

χ² = Σ (O - E)² / E
O
Observed frequency
E
Expected frequency
(O-E)²/E
Contribution to χ²

For each category, calculate (Observed - Expected)² / Expected. Sum these values. Larger χ² = bigger discrepancy between observed and expected frequencies.

Step-by-Step Calculation

FaceOEO-E(O-E)²(O-E)²/E
1810-240.4
21210240.4
..................
Sumχ² = 2.8
df = k - 1 = 6 - 1 = 5 | Critical value at α=.05: 11.07
χ² = 2.8 < 11.07 → Fail to reject H₀ (dice are fair)

With χ² = 2.8 and df = 5, p > 0.05. We fail to reject H₀—the dice appear fair. The observed variation from expected is within normal random fluctuation.

02

Test of Independence

Are Two Variables Related?

Is smoking related to lung disease?
DiseaseNo DiseaseTotal
Smoker9060150
Non-Smoker30120150
Total120180300

The test of independence asks: Are two categorical variables related, or are they independent? If independent, knowing one variable doesn't help predict the other.

Calculating Expected Frequencies

E = (Row Total × Column Total) / Grand Total
Smoker + Disease
E = (150 × 120) / 300 = 60
Observed was 90
Non-Smoker + Disease
E = (150 × 120) / 300 = 60
Observed was 30
Expected = what we'd see if variables were independent

If smoking and disease were independent, we'd expect 60 smokers with disease (not 90). The big gap between observed (90) and expected (60) suggests a relationship.

Independence Hypotheses

H₀
Variables are independent
Smoking and disease are unrelated
Hₐ
Variables are associated
There IS a relationship
df = (rows - 1) × (columns - 1) = (2-1) × (2-1) = 1

H₀: The variables are independent (no relationship). Hₐ: The variables are associated. This is a two-tailed test—we don't specify the direction of association.

Interpreting the Result

Result: χ²(1) = 60.0, p < .001
Reject H₀: Smoking and lung disease are significantly associated
What this means:
• The relationship is statistically significant
• Smokers have higher disease rates than expected
• Does NOT prove causation
• Need effect size for practical significance

χ² = 60.0 is highly significant—there's a clear association between smoking and disease. But chi-square only tells us there IS an association, not how strong it is.

03

Assumptions & Rules

Chi-Square Assumptions

✓ Required
• Random sampling
• Independent observations
• Categorical variables
• Mutually exclusive categories
⚠️ Expected Frequency Rule
• All E ≥ 1
• At least 80% of E ≥ 5
• If violated: use Fisher's exact test or combine categories

Chi-square requires categorical data, independence, and adequate expected frequencies. The 'rule of 5' says most expected frequencies should be ≥ 5 for the approximation to work well.

When Expected < 5

Problem: Expected frequency < 5
Chi-square approximation becomes unreliable
Solutions:
1. Fisher's Exact Test
Calculates exact p-value, no approximation needed
2. Combine Categories
Merge sparse categories to increase expected counts
3. Collect More Data
Larger sample increases expected frequencies

When expected frequencies are small, the chi-square distribution is a poor approximation. Fisher's exact test is the gold standard for small samples or sparse tables.

Continuity Correction

χ²_Yates = Σ (|O - E| - 0.5)² / E
When to Use
2×2 tables with small samples (some argue always for 2×2)
Effect
Makes test more conservative (reduces χ², increases p)
⚠️ Controversial: Many statisticians prefer uncorrected or Fisher's

Yates' correction subtracts 0.5 from each |O-E| before squaring. It makes the test more conservative. For 2×2 tables, many prefer Fisher's exact test over Yates' correction.

04

Effect Size

Measuring Association Strength

V = √(χ² / (n × min(r-1, c-1)))
V = .10
Small
V = .30
Medium
V = .50
Large

Cramér's V ranges from 0 (no association) to 1 (perfect association). Unlike χ², it doesn't depend on sample size. Use it to describe how STRONG the relationship is.

Phi for 2×2 Tables

φ = √(χ² / n)
Only for 2×2 tables
Interpretation (same as correlation):
• φ = 0: No association
• φ = ±0.1: Small
• φ = ±0.3: Medium
• φ = ±0.5: Large
• φ = ±1.0: Perfect association
φ = Cramér's V when table is 2×2

Phi (φ) is a special case of Cramér's V for 2×2 tables. It equals Cramér's V when both dimensions have 2 categories. Interpreted like a correlation coefficient.

Odds Ratio for 2×2 Tables

DiseaseNo Disease
Smokera=90b=60
Non-Smokerc=30d=120
OR = (a × d) / (b × c) = (90 × 120) / (60 × 30) = 6.0
Smokers have 6× the odds of disease compared to non-smokers

The odds ratio shows how much more likely an outcome is in one group vs another. OR = 6 means smokers have 6 times the odds of disease. Very useful for medical/epidemiological interpretation.

Complete Reporting

Example write-up:

"A chi-square test of independence was performed to examine the relation between smoking status and lung disease. The relation between these variables was significant, χ²(1, N = 300) = 60.0, p < .001. Smokers were more likely to have lung disease (60%) than non-smokers (20%). The effect size was large (Cramér's V = .45, OR = 6.0, 95% CI [3.5, 10.3])."

Report χ²(df, N) = value, p-value, direction of effect (percentages), and effect size (V or φ). For 2×2 tables, odds ratios with confidence intervals are especially informative.

★

Real-World Examples

Apply your knowledge to practical scenarios

01

Testing Casino Dice

A casino regulator suspects a die is loaded. They roll it 600 times and record: Face 1: 85, Face 2: 95, Face 3: 105, Face 4: 100, Face 5: 110, Face 6: 105. Is the die fair?

Sample Data
{
  "observed": [
    85,
    95,
    105,
    100,
    110,
    105
  ],
  "expected": [
    100,
    100,
    100,
    100,
    100,
    100
  ],
  "n": 600
}
Q What type of chi-square test is appropriate? +
A Goodness of fit test—we're comparing observed frequencies to expected frequencies under the hypothesis that each face has 1/6 probability.
Q Calculate the expected frequency for each face. +
A E = 600 / 6 = 100 for each face. Under H₀ (fair die), each face should appear 100 times.
Q Calculate χ² for this data. +
A χ² = Σ(O-E)²/E = (85-100)²/100 + (95-100)²/100 + (105-100)²/100 + (100-100)²/100 + (110-100)²/100 + (105-100)²/100 = 2.25 + 0.25 + 0.25 + 0 + 1 + 0.25 = 4.0
Q With df = 5 and α = 0.05, critical χ² = 11.07. Is the die loaded? +
A χ² = 4.0 < 11.07. We fail to reject H₀. There's insufficient evidence that the die is unfair—the variation is within normal random fluctuation.
Key Insights
  • Goodness of fit tests compare observed to theoretical proportions
  • Expected values are calculated from H₀ assumptions
  • Even 'fair' processes produce variation—that's randomness
02

Gender and Career Choice

A university studies whether gender is associated with STEM vs. Humanities major choice. Data from 400 students:

Sample Data
{
  "table": {
    "headers": [
      "",
      "STEM",
      "Humanities",
      "Total"
    ],
    "rows": [
      [
        "Male",
        120,
        80,
        200
      ],
      [
        "Female",
        90,
        110,
        200
      ],
      [
        "Total",
        210,
        190,
        400
      ]
    ]
  }
}
Q What are the expected frequencies for each cell under independence? +
A E = (Row × Column) / Total. Male+STEM: (200×210)/400 = 105. Male+Hum: (200×190)/400 = 95. Female+STEM: 105. Female+Hum: 95.
Q Calculate χ² for this table. +
A χ² = (120-105)²/105 + (80-95)²/95 + (90-105)²/105 + (110-95)²/95 = 2.14 + 2.37 + 2.14 + 2.37 = 9.02
Q With df = (2-1)(2-1) = 1, critical χ² at α = 0.05 is 3.84. What's the conclusion? +
A χ² = 9.02 > 3.84. We reject H₀. There IS a significant association between gender and major choice. Males are overrepresented in STEM, females in Humanities.
Q Calculate Cramér's V for effect size. +
A V = √(χ²/n) = √(9.02/400) = √0.0226 = 0.15. This is a small effect. While statistically significant, the association is weak.
Key Insights
  • Independence test examines association between two categorical variables
  • Significant χ² means variables are associated, not independent
  • Effect size (Cramér's V) may be small even when χ² is significant
03

Treatment Effectiveness Study

A clinical trial compares a new treatment to placebo for recovering from illness within 7 days:

Sample Data
{
  "table": {
    "headers": [
      "",
      "Recovered",
      "Not Recovered",
      "Total"
    ],
    "rows": [
      [
        "Treatment",
        80,
        20,
        100
      ],
      [
        "Placebo",
        50,
        50,
        100
      ],
      [
        "Total",
        130,
        70,
        200
      ]
    ]
  }
}
Q What is the recovery rate in each group? +
A Treatment: 80/100 = 80%. Placebo: 50/100 = 50%. The treatment appears to increase recovery rate by 30 percentage points.
Q Chi-square test gives χ²(1) = 19.78, p < 0.001. What does this mean? +
A There's a highly significant association between receiving treatment and recovery. The treatment group has significantly higher recovery rates than placebo.
Q Calculate the odds ratio. +
A OR = (80×50)/(20×50) = 4000/1000 = 4.0. Patients receiving treatment have 4× the odds of recovery compared to placebo.
Q A patient asks: 'Does this mean I have 4× the probability of recovering?' How do you respond? +
A Not exactly. OR = 4 means odds ratio, not probability ratio. The risk ratio (RR) = 80%/50% = 1.6. So probability of recovery is 1.6× higher, not 4×. Odds ≠ probability!
Key Insights
  • Chi-square tests association but doesn't quantify effect direction
  • Odds ratio (OR) and risk ratio (RR) give different perspectives on effect
  • Odds ratios can be misleading—always consider absolute differences too
?

Chi-Square Tests Quiz

Test your understanding • Passing score: 70%

0 of 10 answered
Q1 multiple-choice

What type of data is required for chi-square tests?

Explanation: Chi-square tests are designed for categorical data—counts of observations in different categories. They don't require normality or continuous scales.
Q2 multiple-choice

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

Explanation: Goodness-of-fit: Does ONE categorical variable match expected proportions? Independence: Are TWO categorical variables associated with each other?
Q3 calculation

For a 3×4 contingency table, what are the degrees of freedom?

Explanation: df = (rows - 1) × (columns - 1) = (3-1) × (4-1) = 2 × 3 = 6
Q4 multiple-choice

The 'expected frequency rule' states that chi-square is valid when:

Explanation: For reliable chi-square approximation, expected (not observed) frequencies should all be ≥ 1, with at least 80% being ≥ 5. Small expected values violate assumptions.
Q5 multiple-choice

When expected frequencies are too small, what alternative test should be used?

Explanation: Fisher's exact test calculates exact p-values without the chi-square approximation. It's the gold standard for small samples and sparse tables.
Q6 multiple-choice

What does Cramér's V measure?

Explanation: Cramér's V measures association STRENGTH, ranging 0 (no association) to 1 (perfect association). Unlike χ², it's independent of sample size.
Q7 calculation

In a 2×2 table: a=40, b=10, c=20, d=30. What is the odds ratio?

Explanation: OR = (a×d)/(b×c) = (40×30)/(10×20) = 1200/200 = 6.0
Q8 multiple-choice

A chi-square test gives χ²(1) = 4.5, p = 0.034. With α = 0.05, you should:

Explanation: Since p = 0.034 < α = 0.05, we reject H₀. The variables are significantly associated. χ² = 4.5 exceeds the critical value of 3.84 for df = 1.
Q9 multiple-choice

Why might a large χ² value still indicate a weak effect?

Explanation: χ² scales with sample size—even tiny effects become 'significant' with large n. That's why effect size (Cramér's V) matters. A huge sample with V = 0.05 is significant but meaningless.
Q10 multiple-choice

Yates' continuity correction is applied to:

Explanation: Yates' correction is applied to 2×2 tables, subtracting 0.5 from |O-E| before squaring. It makes the test more conservative. Many prefer Fisher's exact test instead.

Quiz Results

0 %

← ANOVA Next: Non-parametric Methods →