Chi-Square Tests

Goodness of fit and independence tests

Chi-Square Tests

Chi-Square Goodness of Fit Test

Purpose: Test if observed frequencies match expected distribution

Example: Die rolled 60 times. Are outcomes equally likely?

Hypotheses:

  • H₀: Distribution matches expected (die is fair)
  • Hₐ: Distribution doesn't match expected (die is biased)

Test Statistic:

χ2=(OE)2E\chi^2 = \sum \frac{(O - E)^2}{E}

Where:

  • O = observed count
  • E = expected count
  • Sum over all categories

df = number of categories - 1

Example 1: Goodness of Fit

Roll die 60 times:

| Outcome | 1 | 2 | 3 | 4 | 5 | 6 | |---------|----|----|----|----|----|----| | Observed| 8 | 12 | 9 | 11 | 15 | 5 | | Expected| 10 | 10 | 10 | 10 | 10 | 10 |

STATE:

  • H₀: Die is fair (all outcomes equally likely)
  • Hₐ: Die is not fair
  • α = 0.05

PLAN:

  • Chi-square goodness of fit
  • Conditions: All expected ≥ 5 ✓

DO:

χ2=(810)210+(1210)210+...+(510)210\chi^2 = \frac{(8-10)^2}{10} + \frac{(12-10)^2}{10} + ... + \frac{(5-10)^2}{10}

=410+410+110+110+2510+2510=6.0= \frac{4}{10} + \frac{4}{10} + \frac{1}{10} + \frac{1}{10} + \frac{25}{10} + \frac{25}{10} = 6.0

df = 6 - 1 = 5

P-value = P(χ² ≥ 6.0) ≈ 0.306 (from chi2cdf)

CONCLUDE: P-value = 0.306 > 0.05, fail to reject H₀. No evidence die is biased.

Conditions for Goodness of Fit

  1. Random sample
  2. All expected counts ≥ 5
  3. Independent observations

If expected < 5: Combine categories if makes sense

Chi-Square Distribution

Properties:

  • Always positive (squared differences)
  • Right-skewed
  • Shape depends on df
  • As df increases, approaches normal

P-value: Always upper tail (larger χ² = worse fit)

Chi-Square Test of Independence

Purpose: Test if two categorical variables are independent

Setup: Two-way table (contingency table)

Hypotheses:

  • H₀: Variables are independent
  • Hₐ: Variables are associated (dependent)

Expected Counts for Independence

For each cell:

E=(row total)(column total)grand totalE = \frac{(\text{row total})(\text{column total})}{\text{grand total}}

If independent: Expected count = what we'd expect by chance alone

Example 2: Test of Independence

Relationship between gender and favorite sport (200 students):

| | Baseball | Basketball | Soccer | Total | |--------|----------|------------|--------|-------| | Male | 30 | 40 | 30 | 100 | | Female | 20 | 30 | 50 | 100 | | Total | 50 | 70 | 80 | 200 |

Expected for Male/Baseball:

E=100×50200=25E = \frac{100 \times 50}{200} = 25

All expected counts:

| | Baseball | Basketball | Soccer | |--------|----------|------------|--------| | Male | 25 | 35 | 40 | | Female | 25 | 35 | 40 |

STATE:

  • H₀: Gender and sport preference are independent
  • Hₐ: Gender and sport preference are associated
  • α = 0.05

DO:

χ2=(3025)225+(4035)235+...+(5040)240\chi^2 = \frac{(30-25)^2}{25} + \frac{(40-35)^2}{35} + ... + \frac{(50-40)^2}{40}

=1+0.714+2.5+1+0.714+2.5=8.43= 1 + 0.714 + 2.5 + 1 + 0.714 + 2.5 = 8.43

df = (rows - 1)(columns - 1) = (2-1)(3-1) = 2

P-value = P(χ² ≥ 8.43) ≈ 0.015

CONCLUDE: P-value = 0.015 < 0.05, reject H₀. Significant association between gender and sport preference.

Degrees of Freedom

Goodness of fit: df = k - 1 (k = number of categories)

Test of independence: df = (r - 1)(c - 1)

  • r = number of rows
  • c = number of columns

Conditions for Test of Independence

  1. Random sample
  2. All expected counts ≥ 5
  3. Independent observations

Check expected counts, not observed!

Chi-Square vs Other Tests

Use chi-square when:

  • Categorical variables (not quantitative)
  • Comparing distributions
  • Testing independence

Use t-test when:

  • Quantitative variable
  • Comparing means

Use z-test for proportions when:

  • Single proportion or comparing two proportions
  • Binary outcome (special case of categorical)

Interpreting Results

Large χ²:

  • Observed far from expected
  • Evidence against H₀

Small χ²:

  • Observed close to expected
  • Consistent with H₀

Always use P-value for decision!

Calculator Commands (TI-83/84)

Goodness of fit:

  • Enter observed in list
  • STAT → TESTS → D:χ²GOF-Test
  • Enter expected counts

Test of independence:

  • Enter observed in matrix
  • STAT → TESTS → C:χ²-Test
  • Calculator computes expected

P-value: chi2cdf(χ², 99999, df)

Relationship Between Variables

If reject H₀ in test of independence:

  • Variables are associated
  • But doesn't tell us HOW they're related
  • Examine cell contributions and patterns

Cell contribution: (O - E)²/E for that cell

  • Large contribution → cell differs most from expected

Chi-Square for Homogeneity

Test if distribution is same across multiple populations

Setup: Same as independence (two-way table)
Difference: Conceptual (comparing populations vs testing independence)
Calculation: Identical to test of independence

Example: Do three schools have same distribution of favorite colors?

Common Mistakes

❌ Using chi-square for quantitative data
❌ Checking observed instead of expected counts
❌ Wrong df formula
❌ Two-tail P-value (always use upper tail!)
❌ Confusing goodness of fit with independence

Quick Reference

Goodness of Fit:

  • Tests if observed matches expected distribution
  • df = k - 1

Test of Independence:

  • Tests if two categorical variables independent
  • df = (r - 1)(c - 1)
  • Expected: (row total × column total) / grand total

Test Statistic: χ2=(OE)2E\chi^2 = \sum \frac{(O - E)^2}{E}

Conditions: Random, all expected ≥ 5, independent observations

Remember: Chi-square tests work with counts/frequencies of categorical variables. Large χ² = poor fit or strong association. Always check expected counts!

📚 Practice Problems

1Problem 1easy

Question:

A candy company claims their candy bags contain equal proportions of red, blue, green, and yellow candies. A bag contains 30 red, 25 blue, 20 green, and 25 yellow candies. What type of chi-square test should be used, and what are the expected counts?

💡 Show Solution

Test type: Chi-square goodness-of-fit test (Testing if observed distribution matches a claimed distribution)

Total candies = 30 + 25 + 20 + 25 = 100

If proportions are equal, each color should be 25% of total: Expected count for each color = 100 × 0.25 = 25

Expected counts: • Red: 25 • Blue: 25 • Green: 25 • Yellow: 25

All expected counts ≥ 5, so conditions are met.

2Problem 2medium

Question:

A researcher surveys 200 people about their exercise habits and stress levels. The results are shown below. Calculate the chi-square test statistic.

           Low Stress | High Stress

Exercise 60 | 40 No Exercise 30 | 70

💡 Show Solution

Step 1: Calculate expected counts Row totals: Exercise = 100, No Exercise = 100 Column totals: Low Stress = 90, High Stress = 110 Grand total = 200

Expected = (row total × column total) / grand total

Expected counts: • Exercise & Low: (100 × 90)/200 = 45 • Exercise & High: (100 × 110)/200 = 55 • No Exercise & Low: (100 × 90)/200 = 45 • No Exercise & High: (100 × 110)/200 = 55

Step 2: Calculate χ² χ² = Σ[(Observed - Expected)² / Expected]

χ² = (60-45)²/45 + (40-55)²/55 + (30-45)²/45 + (70-55)²/55 χ² = 225/45 + 225/55 + 225/45 + 225/55 χ² = 5 + 4.09 + 5 + 4.09 χ² ≈ 18.18

df = (rows - 1)(columns - 1) = (2-1)(2-1) = 1

3Problem 3medium

Question:

A die is rolled 120 times with the following results: 1(15), 2(18), 3(22), 4(25), 5(20), 6(20). Test at α = 0.05 if the die is fair.

💡 Show Solution

H₀: The die is fair (all outcomes equally likely) Hₐ: The die is not fair

Expected count for fair die: 120/6 = 20 for each outcome

χ² = Σ[(O - E)² / E] χ² = (15-20)²/20 + (18-20)²/20 + (22-20)²/20 + (25-20)²/20 + (20-20)²/20 + (20-20)²/20 χ² = 25/20 + 4/20 + 4/20 + 25/20 + 0/20 + 0/20 χ² = 1.25 + 0.2 + 0.2 + 1.25 + 0 + 0 χ² = 2.9

df = 6 - 1 = 5

P-value: P(χ² > 2.9) ≈ 0.715

Decision: Since p-value (0.715) > α (0.05), fail to reject H₀

Conclusion: There is insufficient evidence to conclude the die is unfair.

4Problem 4hard

Question:

A study examines the relationship between smoking status and lung disease in 500 people:

           Disease | No Disease

Smoker 80 | 120 Non-smoker 20 | 280

Perform a chi-square test at α = 0.01 to determine if smoking and lung disease are independent.

💡 Show Solution

H₀: Smoking status and lung disease are independent Hₐ: Smoking status and lung disease are associated

Step 1: Calculate expected counts Row totals: Smoker = 200, Non-smoker = 300 Column totals: Disease = 100, No Disease = 400 Total = 500

Expected counts: • Smoker & Disease: (200×100)/500 = 40 • Smoker & No Disease: (200×400)/500 = 160 • Non-smoker & Disease: (300×100)/500 = 60 • Non-smoker & No Disease: (300×400)/500 = 240

Step 2: Calculate χ² χ² = (80-40)²/40 + (120-160)²/160 + (20-60)²/60 + (280-240)²/240 χ² = 1600/40 + 1600/160 + 1600/60 + 1600/240 χ² = 40 + 10 + 26.67 + 6.67 χ² ≈ 83.34

df = (2-1)(2-1) = 1

P-value: P(χ² > 83.34) < 0.0001

Decision: Reject H₀

Conclusion: There is very strong evidence (p < 0.01) that smoking status and lung disease are associated.

5Problem 5hard

Question:

A school surveys students from three grades about their favorite subject. Results:

Grade 9: Math(40), Science(30), English(30) Grade 10: Math(35), Science(35), English(30) Grade 11: Math(25), Science(45), English(30)

Test if the distribution of favorite subject is the same across grades at α = 0.05.

💡 Show Solution

H₀: Distribution of favorite subject is the same across grades Hₐ: Distribution differs by grade

Step 1: Set up table Math | Science | English | Total Grade 9 40 | 30 | 30 | 100 Grade 10 35 | 35 | 30 | 100 Grade 11 25 | 45 | 30 | 100 Total 100 | 110 | 90 | 300

Step 2: Calculate expected counts E = (row total × column total) / grand total

For each cell: Grade 9 & Math: (100×100)/300 = 33.33 Grade 9 & Science: (100×110)/300 = 36.67 Grade 9 & English: (100×90)/300 = 30 [Continue for all cells...]

Step 3: Calculate χ² χ² = (40-33.33)²/33.33 + (30-36.67)²/36.67 + ... (all 9 cells) χ² ≈ 1.33 + 1.21 + 0 + 0.09 + 0.08 + 0 + 2.08 + 1.89 + 0 χ² ≈ 6.68

df = (3-1)(3-1) = 4

P-value: P(χ² > 6.68) ≈ 0.154

Decision: Fail to reject H₀

Conclusion: There is insufficient evidence that the distribution of favorite subject differs across grades.