Lesson 36: ANOVA II

Calendar

Block III calendar with a red box around Tuesday 1 December, Lesson 36, ANOVA II.


Admin

  • Project Products: Lesson 37 (3, 4 Dec)
  • Project starter code: Lesson 32

What We Did: Lessons 29 to 35

  • Least squares: choose \(\hat{\beta}_0\), \(\hat{\beta}_1\) to minimize \(\sum (y_i - \hat{y}_i)^2\)
  • \(\hat{\beta}_1 = \dfrac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}\), \(\hat{\beta}_0 = \bar{y} - \hat{\beta}_1\bar{x}\)
  • Slope: change in the mean of \(y\) for a one unit increase in \(x\)
  • Predict only inside the range of the \(x\) data
  • Slope test: \(H_0: \beta_1 = 0\), \(t = \hat{\beta}_1 / s_{\hat{\beta}_1}\), df \(= n - 2\)
  • \(r^2 = 1 - \text{SSE}/\text{SST}\): proportion of variation in \(y\) explained by the line
  • R: lm(y ~ x), summary(), predict()
  • Model: \(Y = \beta_0 + \beta_1 x + \varepsilon\), \(\varepsilon \sim N(0, \sigma^2)\), independent
  • LINE: Linear, Independent, Normal, Equal variance
  • Residual plot (residuals vs fitted): no pattern checks L, constant spread checks E
  • Histogram of residuals: checks N
  • Independence: comes from how the data were collected
  • Model: \(Y = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \cdots + \beta_k x_k + \varepsilon\)
  • Interpret \(\hat{\beta}_j\): holding all else constant, a one unit increase in \(x_j\) is a \(\hat{\beta}_j\) unit increase in \(y\), on average
  • Not significant? Drop it and refit
  • Categorical with 3 levels: 2 indicator variables; each coefficient is a difference from the baseline level
  • R: lm(y ~ x1 + x2 + x3)
  • Not significant? Drop the predictor and refit
  • Categorical: each indicator compares one level to the baseline; keep the variable if any level is significant
  • \(R^2\): proportion of the variation in \(y\) explained by the model; adjusted \(R^2\) penalizes extra predictors
  • LINE: same plots as Lesson 31, plot(model, which = 1) and hist(model$residuals)
  • Goal: compare \(I \ge 3\) population means with one test
  • \(H_0: \mu_1 = \mu_2 = \cdots = \mu_I\) versus \(H_a\): at least two of the \(\mu_i\)’s differ
  • \(F = \text{MSTr}/\text{MSE}\): between-group variability over within-group variability
  • P-value: 1 - pf(F, I-1, n-I), always the upper tail
  • R: summary(aov(y ~ group))

What We’re Doing: Lesson 36

Objectives

  • Apply Tukey’s multiple-comparisons procedure to identify which population means differ. (SLO 5)
  • Interpret Tukey’s results and acknowledge what one-way ANOVA and Tukey do and do not establish. (SLO 5, 6)

Required Reading

Devore 10.2


Break!

The Overlook

The family on a rocky overlook above a valley of fall colors
Reese standing on the rocks at the overlook

Reese Dr, Meet Cal Turner Dr

Reese standing on a truck bed, holding the Reese Dr street sign
Reese taking a selfie with the Reese Dr street sign
Cal pointing up at the Cal Turner Dr street sign

Cal Turner Dr: from Lesson 1.


DMath Intramurals

DMath Frisbee!!

Math vs USMAPS

?-?

The Army Math frisbee team posed on the field with the disc

Cal

Cal winding up to throw the disc
Cal reaching for a catch

The Game

A Math player throwing a forehand
A Math player catching the disc low
A Math player stretching out on a forehand throw
A Math player leaping for the disc
Players colliding as the disc arrives
A Math player skying a USMAPS defender for the disc
A Math player throwing past a USMAPS mark
A Math player starting a dive for the disc
The same player fully laid out, disc in hand

Last two: the layout.


The Takeaway for Today

NoteKey Concepts from Lesson 36
  • ANOVA rejects \(H_0\): some means differ. Tukey says which.
  • R: TukeyHSD(model); a pair differs when its interval does not contain 0 (p adj \(\le\) 0.05)
  • Fail to reject in ANOVA? Stop. No Tukey.
  • Neither shows cause unless the groups were randomly assigned

Where We Left Off: Paper Airplane PE

Same workbook as Lesson 35. Open it back up.

Download the Excel Workbook Change any throw (yellow cells) and the whole ANOVA updates.

\(H_0: \mu_1 = \mu_2 = \mu_3\) versus \(H_a\): at least two of the airplane means differ.

Each section’s ANOVA from the workbook, same numbers in R:

model <- aov(dist ~ airplane, data = b2)
summary(model)

Dot plot of one section's paper airplane throw distances for three airplane designs, with each airplane's mean as a bar and the grand mean as a dashed line.

            Df  Sum Sq Mean Sq F value    Pr(>F)    
airplane     2 1562.74  781.37   31.16 4.757e-08 ***
Residuals   30  752.27   25.08                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

P-value < 0.001 \(\le\) 0.05: reject \(H_0\). At least two airplanes have different true mean distances.

Dot plot of one section's paper airplane throw distances for three airplane designs, with each airplane's mean as a bar and the grand mean as a dashed line.

            Df Sum Sq Mean Sq F value    Pr(>F)    
airplane     2 4055.4 2027.71   55.01 3.808e-13 ***
Residuals   48 1769.3   36.86                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

P-value < 0.001 \(\le\) 0.05: reject \(H_0\). At least two airplanes have different true mean distances.

Dot plot of one section's paper airplane throw distances for three airplane designs, with each airplane's mean as a bar and the grand mean as a dashed line.

            Df Sum Sq Mean Sq F value Pr(>F)
airplane     2  434.3  217.17  2.0001 0.1464
Residuals   48 5211.8  108.58               

P-value = 0.146 \(>\) 0.05: fail to reject \(H_0\). Not sufficient evidence that the airplanes differ.

B2 and C2: at least two airplanes differ.

Which airplanes?

ANOVA can’t say. Today we find out. Start with B2.


Why Not Three \(t\) Tests?

\(\binom{3}{2} = 3\) pairs. Three tests at \(\alpha = 0.05\):

\[P(\text{at least one false positive}) = 1 - (0.95)^3 = 0.143\]

Same problem as Lesson 35. Bonferroni fixes it but misses real differences.

NoteThe fix: Tukey

Compares every pair of means while holding the chance of any false positive, across all the pairs, at \(\alpha\).


Tukey’s Procedure

ImportantTukey’s Procedure

For every pair of groups \(i\) and \(j\), an interval for \(\mu_i - \mu_j\):

\[(\bar{y}_{i\cdot} - \bar{y}_{j\cdot}) \pm Q_{\alpha,\,I,\,n-I}\sqrt{\frac{\text{MSE}}{J}}\]

\(Q\) comes from the studentized range distribution. It is bigger than a \(t\) critical value, so each interval is wider: that is what holds the chance of any false positive, across all the pairs, at \(\alpha\).

  1. Run ANOVA. Reject \(H_0\) first.
  2. Run TukeyHSD(model).
  3. Any pair whose interval does not contain 0 differs.
TipReading it
  • Interval does not contain 0 (p adj \(\le\) 0.05): that pair differs
  • Interval contains 0: no evidence that pair differs
  • The sign of diff says which mean is bigger
TukeyHSD(model)
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = dist ~ airplane, data = b2)

$airplane
                           diff         lwr        upr     p adj
Airplane 2-Airplane 1   4.50000  -0.7639336   9.763934 0.1052822
Airplane 3-Airplane 1 -11.81818 -17.0821154  -6.554248 0.0000150
Airplane 3-Airplane 2 -16.31818 -21.5821154 -11.054248 0.0000000

Tukey 95 percent intervals for the three B2 differences. Airplane 2 minus Airplane 1 crosses zero; Airplane 3 minus Airplane 1 and Airplane 3 minus Airplane 2 sit entirely below zero.

Airplane 3 flies a shorter true mean distance than both Airplane 1 and Airplane 2. No evidence that Airplanes 1 and 2 differ.

TukeyHSD(model)
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = dist ~ airplane, data = c2)

$airplane
                            diff        lwr       upr     p adj
Airplane 2-Airplane 1 -14.088235 -19.124603 -9.051868 0.0000001
Airplane 3-Airplane 1   7.411765   2.375397 12.448132 0.0024092
Airplane 3-Airplane 2  21.500000  16.463632 26.536368 0.0000000

Tukey intervals for C2. None of the three intervals contains zero.

All three intervals miss 0: every pair differs. Airplane 3 flies farthest, then Airplane 1, then Airplane 2.

WarningANOVA did not reject

D2’s ANOVA P-value = 0.146 \(>\) 0.05: fail to reject \(H_0\). We would stop here. Tukey shown only to see that it agrees.

TukeyHSD(model)
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = dist ~ airplane, data = d2)

$airplane
                           diff        lwr       upr     p adj
Airplane 2-Airplane 1 -6.911765 -15.555636  1.732107 0.1402492
Airplane 3-Airplane 1 -5.035294 -13.679165  3.608577 0.3444480
Airplane 3-Airplane 2  1.876471  -6.767401 10.520342 0.8595014

Tukey intervals for D2. All three intervals contain zero.

All three intervals contain 0: no pair differs, same story as the ANOVA. There is not sufficient evidence that any of the airplanes have different true mean distances.

WarningSame airplanes, different answers

B2 says Airplanes 1 and 2 do not differ. C2 says they do. Different throwers, different throws. Each result describes the population that section’s data came from.


What ANOVA and Tukey Do and Do Not Establish

ImportantThey DO
  • ANOVA: whether at least two population means differ
  • Tukey: which pairs differ, how big the gap is (interval), with an overall false positive rate of \(\alpha\)
WarningThey DO NOT
  • Show cause unless the groups were randomly assigned. Compare four companies’ AFT scores and find a difference: the company did not necessarily cause it.
  • Prove means are equal. An interval that contains 0 (or a fail to reject) is no evidence of a difference, not evidence of no difference.
  • Say a difference matters. A significant 1 point gap may be too small to care about. Look at the interval.
  • Reach beyond the data. B2’s throws say nothing about C2’s throwers.

Complete the Table

A battalion compares rifle qualification scores across four training methods, 10 Soldiers per method.

Source Sum of Squares df Mean Square \(F\)
Treatments (Method) 120 3 ? ?
Error 432 36 ?
Total 552 39

\(H_0: \mu_1 = \mu_2 = \mu_3 = \mu_4\) versus \(H_a\): at least two of the method means differ.

\[\text{MSTr} = \frac{120}{3} = 40.00 \qquad \text{MSE} = \frac{432}{36} = 12.00 \qquad F = \frac{40.00}{12.00} = 3.333\]

1 - pf(3.333, 3, 36)

P-value = 0.030

0.030 \(\le\) 0.05: reject \(H_0\). There is sufficient evidence that at least two of the four training methods have different true mean qualification scores.


Board Problems

Problem 1: Complete the Table

A company compares Indoor Obstacle Course Test (IOCT) times (seconds) across four platoons, 12 cadets per platoon.

Source Sum of Squares df Mean Square \(F\)
Treatments (Platoon) 180 3 ? ?
Error 880 44 ?
Total 1060 47

\(H_0: \mu_1 = \mu_2 = \mu_3 = \mu_4\) versus \(H_a\): at least two of the platoon means differ.

\[\text{MSTr} = \frac{180}{3} = 60.00 \qquad \text{MSE} = \frac{880}{44} = 20.00 \qquad F = \frac{60.00}{20.00} = 3.000\]

1 - pf(3, 3, 44)

P-value = 0.041

0.041 \(\le\) 0.05: reject \(H_0\). There is sufficient evidence that at least two of the four platoons have different true mean IOCT times.


Problem 2: Ruck Times by Platoon

A company commander compares 12 mile ruck times (minutes) across four platoons, 8 Soldiers each. ANOVA P-value < 0.001.

  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = minutes ~ platoon, data = ruck)

$platoon
         diff        lwr      upr     p adj
2nd-1st  5.00 -6.3706087 16.37061 0.6315610
3rd-1st 17.00  5.6293913 28.37061 0.0018112
4th-1st 19.25  7.8793913 30.62061 0.0004299
3rd-2nd 12.00  0.6293913 23.37061 0.0356563
4th-2nd 14.25  2.8793913 25.62061 0.0098360
4th-3rd  2.25 -9.1206087 13.62061 0.9483829
  1. Which pairs of platoons differ?

  2. Which platoons are slower?

  3. The commander concludes the 3rd and 4th Platoons are slow because their platoon leaders are new. Do the data support that?

  1. 3rd vs 1st, 4th vs 1st, 3rd vs 2nd, 4th vs 2nd. Those intervals do not contain 0. No evidence 1st and 2nd differ, or 3rd and 4th.

  2. 3rd and 4th. Every diff against 1st and 2nd is positive: more minutes.

  3. No. Tukey shows 3rd and 4th are slower than 1st and 2nd, not why. Platoons were not randomly assigned their leaders (or their Soldiers), so the data cannot show cause.


Problem 3: Cadet Sleep by Class Year

A survey asks 20 cadets from each class how many hours they slept last night. ANOVA P-value = 0.007.

  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = hours ~ class, data = sleep)

$class
               diff         lwr       upr     p adj
Yuk-Plebe     0.370 -0.29900246 1.0390025 0.4709262
Cow-Plebe     0.685  0.01599754 1.3540025 0.0427280
Firstie-Plebe 0.860  0.19099754 1.5290025 0.0062427
Cow-Yuk       0.315 -0.35400246 0.9840025 0.6055973
Firstie-Yuk   0.490 -0.17900246 1.1590025 0.2267623
Firstie-Cow   0.175 -0.49400246 0.8440025 0.9017061
  1. Why is it appropriate to run Tukey here?

  2. Which pairs of classes differ?

  3. Interpret the Firstie-Plebe row.

  4. The Yuk-Plebe interval contains 0. Does that show Yuks and Plebes sleep the same amount on average?

  5. Does this show that being a Plebe causes less sleep?

  1. ANOVA rejected \(H_0\) (0.007 \(\le\) 0.05): at least two classes differ, so we ask which.

  2. Cow vs Plebe and Firstie vs Plebe. Every other interval contains 0.

  3. Firsties slept 0.86 hours more than Plebes in the sample. We are 95% confident the true mean difference is between 0.19 and 1.53 hours (Firsties more).

  4. No. It means there is not sufficient evidence of a difference. A real difference of up to 1.04 hours is still plausible.

  5. No. Class year was not randomly assigned. Plebes differ from Firsties in schedule, duties, and more. This shows a difference, not its cause.


Before You Leave

Today

  • ANOVA says whether; Tukey says which
  • TukeyHSD(model): interval misses 0 means that pair differs
  • Fail to reject in ANOVA: stop
  • No cause without random assignment; no proof of equal means

Any questions?


Next Lesson

Lesson 37: Project Drop

  • 3, 4 Dec
  • Project Products due

Upcoming Graded Events

  • Project Products: Lesson 37 (3, 4 Dec)
  • Project Presentations: Lessons 38 and 39 (7 to 10 Dec)
  • TEE: 15 to 18 Dec 2026