STAT 215 Multifactor ANOVA I Colin Reimer Dawson Oberlin College - - PowerPoint PPT Presentation

stat 215 multifactor anova i
SMART_READER_LITE
LIVE PREVIEW

STAT 215 Multifactor ANOVA I Colin Reimer Dawson Oberlin College - - PowerPoint PPT Presentation

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms STAT 215 Multifactor ANOVA I Colin Reimer Dawson Oberlin College November 28, 2017 1 / 25 Outline Two-Way ANOVA: Additive Model FIT:


slide-1
SLIDE 1

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

STAT 215 Multifactor ANOVA I

Colin Reimer Dawson

Oberlin College

November 28, 2017 1 / 25

slide-2
SLIDE 2

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Outline

Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms 2 / 25

slide-3
SLIDE 3

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Alfalfa sprouts (Ex. 6.25) Some students were interested in the effect of acidic environments

  • n plant growth. They planted alfalfa seeds in fifteen cups and

randomly chose five to get plain water, five to get a moderate amount of acid and five to get a stronger acid solution. The cups were arranged indoors near a window in five rows of three with one cup from each Acid level in each row (with row a nearest the window, and row e farthest away). The response variable was average Height of the alfalfa sprouts after four days.

A model: Acid = µ + αk + ε, k = water, moderate, strong Any concerns about the ANOVA/regression conditions? The residuals might not be independent within rows! 4 / 25

slide-4
SLIDE 4

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Alfalfa Data

Treatment/Row a b c d e

  • Trt. mean

water 1.45 2.79 1.93 2.33 4.85 2.67 moderate acid 1.00 0.70 1.37 2.80 1.46 1.47 strong acid 1.03 1.22 0.45 1.65 1.07 1.08 Row mean 1.16 1.57 1.25 2.26 2.46 1.74 Since each treatment is applied to each row, we can include row as a predictor. 5 / 25

slide-5
SLIDE 5

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Means Plots

library("Stat2Data"); library("mosaic"); library("gplots") data("Alfalfa") plotmeans(Ht4 ~ factor(Acid, levels = c("water", "1.5HCl", "3.0HCl")), data = Alfalfa, xlab = "Solution", ylab = "Height (in.)") 1 2 3 4 Solution Height (in.)

  • water

1.5HCl 3.0HCl n=5 n=5 n=5

6 / 25

slide-6
SLIDE 6

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Means Plots

plotmeans(Ht4 ~ factor(Row), data = Alfalfa, xlab = "Row", ylab = "Height (in.)") −2 2 4 6 8 Row Height (in.)

  • a

b c d e n=3 n=3 n=3 n=3 n=3

7 / 25

slide-7
SLIDE 7

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

The One-way ANOVA Population Model (X categorical)

Y = f(X) + ε Y = µ + αk + ε, ε ∼ N(0, σ2

ε)

One αk for each level of X: group deviation from overall mean The Two-way ANOVA Additive Model (XA, XB categorical)

Y = f(X) + ε Y = µ + αj + βk + ε, ε ∼ N(0, σ2

ε)

One αj for each level of XA One βk for each level of XB

8 / 25

slide-8
SLIDE 8

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

FIT: Parameter Estimation

  • Population model:

yj,k,i = µ + αj + βk + εj,k,i

  • Estimate terms by

ˆ µ = ¯ ¯ y ˆ αj = ¯ yj − ¯ ¯ y ˆ βk = ¯ yk − ¯ ¯ y ˆ yj,k,i = ˆ µ + ˆ αj + ˆ βk ˆ εj,k,i = yj,k,i − ˆ yj,k,i 10 / 25

slide-9
SLIDE 9

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Sums of Squares

yj,k,i = ˆ µ + ˆ αj + ˆ βk + εj,k,i (yj,k,i − ˆ µ)2 = (ˆ αj + ˆ βk + εj,k,i)2 SSA=

  • j
  • k

nj,k

  • i=1

ˆ α2

j

SSB=

  • j
  • k

nj,k

  • i=1

ˆ β2

k

SSError=

  • j
  • k

nj,k

  • i=1

ˆ ε2

j,k,i

Note: SSTotal = SSA + SSB + SSError, since cross terms are all zero. 11 / 25

slide-10
SLIDE 10

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

The Two-Way ANOVA Table

Source d f SS MS F P Factor A J − 1 Factor B K − 1 Residuals N − J − K + 1 — — Total N − 1 — — Pair “Quiz”: Factor A has J = 3 levels, factor B has K = 5 levels, with one observation per cell. How many degrees of freedom in each row of the table above? 12 / 25

slide-11
SLIDE 11

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Two-Way ANOVA Table

library("mosaic"); library("Stat2Data") data("Alfalfa") two.way.model <- aov(Ht4 ~ Acid + Row, data = Alfalfa) summary(two.way.model) Df Sum Sq Mean Sq F value Pr(>F) Acid 2 6.852 3.426 4.513 0.0487 * Row 4 4.183 1.046 1.378 0.3235 Residuals 8 6.072 0.759

  • Signif. codes:

0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Caution: The F tests here amount to sequential nested F-tests, so order matters if there is any collinearity (here there is none, since the design is perfectly balanced) 13 / 25

slide-12
SLIDE 12

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Getting Means

## Note: this only works if you used aov(), not lm() model.tables(two.way.model, type = "means") Tables of means Grand mean 1.74 Acid Acid 1.5HCl 3.0HCl water 1.466 1.084 2.670 Row Row a b c d e 1.16 1.57 1.25 2.26 2.46

14 / 25

slide-13
SLIDE 13

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Getting “Effects” (αs and βs)

## Note: this only works if you used aov(), not lm() model.tables(two.way.model, type = "effects") Tables of effects Acid Acid 1.5HCl 3.0HCl water

  • 0.274 -0.656

0.930 Row Row a b c d e

  • 0.58 -0.17 -0.49

0.52 0.72 ## Notice that the alphas and betas each sum to zero

15 / 25

slide-14
SLIDE 14

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Post-Hoc Pairwise Comparisons

TukeyHSD(two.way.model) Tukey multiple comparisons of means 95% family-wise confidence level Fit: aov(formula = Ht4 ~ Acid + Row, data = Alfalfa) $Acid diff lwr upr p adj 3.0HCl-1.5HCl -0.382 -1.95650626 1.192506 0.7739299 water-1.5HCl 1.204 -0.37050626 2.778506 0.1338368 water-3.0HCl 1.586 0.01149374 3.160506 0.0484908 $Row diff lwr upr p adj b-a 0.41 -2.04758 2.86758 0.9750089 c-a 0.09 -2.36758 2.54758 0.9999282 d-a 1.10 -1.35758 3.55758 0.5642564 e-a 1.30 -1.15758 3.75758 0.4211177 c-b -0.32 -2.77758 2.13758 0.9899007 d-b 0.69 -1.76758 3.14758 0.8613573 e-b 0.89 -1.56758 3.34758 0.7251160 d-c 1.01 -1.44758 3.46758 0.6333208 e-c 1.21 -1.24758 3.66758 0.4830625 e-d 0.20 -2.25758 2.65758 0.9983249

17 / 25

slide-15
SLIDE 15

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Additive vs. Interaction Model

The Two-way ANOVA Additive Model (XA, XB categorical)

Y = f(X) + ε Y = µ + αj + βk + ε, ε ∼ N(0, σ2

ε)

One αj for each level of XA One βk for each level of XB

Assumes the “effect” of Factor A is the same at each level of Factor B (like parallel lines models in regression). 19 / 25

slide-16
SLIDE 16

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Interaction Model

The Two-way ANOVA Interaction Model (XA, XB categorical)

Y = f(X) + ε Y = µ + αj + βk + γjk + ε, ε ∼ N(0, σ2

ε)

One αj for each level of XA One βk for each level of XB One γjk for each combination of XA and XB

  • Predicted “effect” of level j of factor A, when at level k
  • f factor B: αj + γjk.
  • Predicted “effect” of level k of factor B, when at level j
  • f factor A: βk + γjk.
  • “Effects” are modulated by the interaction term, γjk: a

“difference of differences”. 20 / 25

slide-17
SLIDE 17

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Example: Glue!

An experiment recorded the amount of force in Newtons (the response) that it takes to separate two pieces of plastic that have been glued together, for three different thicknesses of material (thin, moderate, thick), and two types of glue (wood

  • vs. plastic). There are two cases at each combination of
  • factors. The data is below usual one-row-per-case form.

Thickness/Glue Plastic Wood Mean Thin 52, 64 72, 60 62 Moderate 67, 55 78, 68 67 Thick 86, 72 43, 51 63 Mean 66 62 64 21 / 25

slide-18
SLIDE 18

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Glue!

library("mosaic") GlueData <- read.file("http://colinreimerdawson.com/data/glue.csv") ### Plot the means with(GlueData, interaction.plot(Thickness, Glue, Force)) 50 55 60 65 70 75 80 Thickness mean of Force Moderate Thick Thin Glue Wood Plastic

22 / 25

slide-19
SLIDE 19

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Glue!

We can write down a two-way ANOVA model with an interaction as follows: Y = µ + αj + βk + γj,k + ε How do we interpret each coefficient? 23 / 25

slide-20
SLIDE 20

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Fitting the Model

Demo 24 / 25

slide-21
SLIDE 21

Outline Two-Way ANOVA: Additive Model FIT: Estimating Parameters Pairwise Comparisons Interaction Terms

Degrees of Freedom

With J levels of factor A and K levels of factor B:

  • J different αs, but J − 1 degrees of freedom (they must

sum to zero)

  • K different βs, but K − 1 degrees of freedom (they must

sum to zero)

  • JK different γs, but only (J − 1)(K − 1) df (must sum

to zero at each J and each K) The interaction model has enough flexibility to fit any pattern

  • f cell means. Need more than one obs. per cell to estimate

fit / to do hypothesis tests. 25 / 25