Two-way ANOVA. Interaction. Susanne Rosthj Section of Biostatistics - - PowerPoint PPT Presentation

two way anova interaction
SMART_READER_LITE
LIVE PREVIEW

Two-way ANOVA. Interaction. Susanne Rosthj Section of Biostatistics - - PowerPoint PPT Presentation

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s Faculty of Health Sciences Two-way ANOVA. Interaction. Susanne Rosthj Section of Biostatistics Department of Public Health University of


slide-1
SLIDE 1

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Faculty of Health Sciences

Two-way ANOVA. Interaction.

Susanne Rosthøj

Section of Biostatistics Department of Public Health University of Copenhagen sr@biostat.ku.dk

slide-2
SLIDE 2

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

The mean structure

µi =

        

µ1 female ≤ 50 µ2 female > 50 µ3 male ≤ 50 µ4 male > 50 =

        

a female ≤ 50 a + b female > 50 a + c male ≤ 50 a + c + b male > 50

  • r put in tabular form:

≤ 50 >50 female a a + b male a + c a + b + c

2 / 23

slide-3
SLIDE 3

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Estimating the parameters

> d <- read.dbf(’framingham.dbf’) > >> lm1 <- lm( sbp ~ factor(sex) + ageG, data = d) > summary( lm1 ) Call: lm(formula = sbp ~ factor(sex) + ageG, data = d) Residuals: Min 1Q Median 3Q Max

  • 65.181 -18.764
  • 5.011

12.989 153.067 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 146.933 1.367 107.474 < 2e-16 *** factor(sex)1

  • 8.169

1.467

  • 5.570 3.06e-08 ***

ageG51-62 8.248 1.506 5.476 5.14e-08 ***

  • Signif. codes:

0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 Residual standard error: 27.46 on 1403 degrees of freedom Multiple R-squared: 0.04122, Adjusted R-squared: 0.03985 F-statistic: 30.16 on 2 and 1403 DF, p-value: 1.502e-13 >

3 / 23

slide-4
SLIDE 4

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Estimating the differences

> confint( lm1 ) 2.5 % 97.5 % (Intercept) 144.251058 149.614821 factor(sex)1 -11.046340

  • 5.291901

ageG51-62 5.293244 11.201972

Give the interpretation of the estimates from this model on the next slide.

4 / 23

slide-5
SLIDE 5

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Interpretation of the model

Fill in the blanks and choose whether higher or lower is correct: In the adjusted analysis we find: The mean SBP for the older age group is mm/Hg (95% CI

  • ) higher / lower than the mean SBP

for the younger age group, p The mean SBP for males is mm/Hg (95% CI

  • ) higher / lower than the mean SBP

for females, p

5 / 23

slide-6
SLIDE 6

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

The model assumption

We are claiming that the effect of gender is the same over both age groups (and vice versa). How do we know whether

  • the difference between the two genders is the same for

both age groups?

  • the effect of age is the same for both genders?

6 / 23

slide-7
SLIDE 7

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Two-way ANOVA with interaction

µi =

        

µ1 female ≤ 50 µ2 female > 50 µ3 male ≤ 50 µ4 male > 50 =

        

a female ≤ 50 a + b female > 50 a + c male ≤ 50 a + c + b + d male > 50 is an interaction model because of the interaction term d.

7 / 23

slide-8
SLIDE 8

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Two-way ANOVA with interaction

≤ 50 >50 female a a + b male a + c a + b + c + d

We now have 4 parameters to describe the means in 4 cells. We find :

means ≤ 50 > 50 female 145.27 156.24 male 140.65 145.86

  • r put in another way as in our model

means ≤ 50 >50 female 145.27 145.27 + 10.97 male 145.27 - 4.62 145.27 + 10.97 - 4.62 - 5.76

8 / 23

slide-9
SLIDE 9

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Interaction in R

Interactions are specified using a ’*’ :

> lm2 <- lm( sbp ~ factor(sex)*factor(ageG), data=d ) > aov2 <- aov( lm2 ) > summary( aov2 ) Df Sum Sq Mean Sq F value Pr(>F) factor(sex) 1 22874 22874 30.382 4.22e-08 *** factor(ageG) 1 22622 22622 30.047 5.00e-08 *** factor(sex):factor(ageG) 1 2753 2753 3.657 0.056 . Residuals 1402 1055546 753

  • Signif. codes:

0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 >

NB : Only consider the p-value in the lower row.

Note :

  • variables are separated by ’*’.

9 / 23

slide-10
SLIDE 10

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Estimates from interaction model

> summary( lm2 ) Call: lm(formula = sbp ~ factor(sex) * factor(ageG), data = d) Residuals: Min 1Q Median 3Q Max

  • 66.242 -18.242
  • 5.268

13.758 154.732 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 145.268 1.620 89.691 < 2e-16 *** factor(sex)1

  • 4.616

2.366

  • 1.951

0.0513 . factor(ageG)51-62 10.974 2.073 5.294 1.39e-07 *** factor(sex)1:factor(ageG)51-62

  • 5.763

3.014

  • 1.912

0.0560 .

  • Signif. codes:

0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 Residual standard error: 27.44 on 1402 degrees of freedom Multiple R-squared: 0.04371, Adjusted R-squared: 0.04167 F-statistic: 21.36 on 3 and 1402 DF, p-value: 1.567e-13 >

We may also use confint(). Final model is the additive model (lm1).

10 / 23

slide-11
SLIDE 11

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

No interaction

Mean M F

  • c
  • ld

young

  • ld

young

  • b

11 / 23

slide-12
SLIDE 12

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Interaction / effect modification

Mean M F

  • ld

young

  • ld

young

12 / 23

slide-13
SLIDE 13

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

An example with an interaction

12 rats randomized to antibiotics (yes/no) and vitamins (yes/no). Response is growth (ratio).

ratid antibiotic vitamins growth 1 no no 1.30 2 no no 1.19 3 no no 1.08 4 no yes 1.26 5 no yes 1.21 6 no yes 1.19 7 yes no 1.05 8 yes no 1.00 9 yes no 1.05 10 yes yes 1.52 11 yes yes 1.56 12 yes yes 1.55

13 / 23

slide-14
SLIDE 14

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

The model

µi =

        

µ1 no antibiotics no vitamins µ2 no antibiotics vitamins µ3 antibiotics no vitamins µ4 antibiotics vitamins =

        

a no antibiotics no vitamins a + b no antibiotics vitamins a + c antibiotics no vitamins a + c + b + d antibiotics vitamins

14 / 23

slide-15
SLIDE 15

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Test of interaction

> d <- read.dbf( ’ratgrowth.dbf’ ) > lm1 <- lm( growth ~ antibiotic*vitamins, data=d ) > aov1 <- aov( lm1 ) > summary( aov1 ) Df Sum Sq Mean Sq F value Pr(>F) antibiotic 1 0.02083 0.02083 5.682 0.044292 * vitamins 1 0.21870 0.21870 59.645 5.62e-05 *** antibiotic:vitamins 1 0.17280 0.17280 47.127 0.000129 *** Residuals 8 0.02933 0.00367

  • Signif. codes:

0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 >

15 / 23

slide-16
SLIDE 16

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Parameter estimates

> summary(lm1) Call: lm(formula = growth ~ antibiotic * vitamins, data = d) Residuals: Min 1Q Median 3Q Max

  • 0.110000 -0.025000

0.003333 0.016667 0.110000 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.19000 0.03496 34.039 6.06e-10 *** antibioticyes

  • 0.15667

0.04944

  • 3.169 0.013220 *

vitaminsyes 0.03000 0.04944 0.607 0.560818 antibioticyes:vitaminsyes 0.48000 0.06992 6.865 0.000129 ***

  • Signif. codes:

0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 Residual standard error: 0.06055 on 8 degrees of freedom Multiple R-squared: 0.9336, Adjusted R-squared: 0.9087 F-statistic: 37.48 on 3 and 8 DF, p-value: 4.659e-05 >

16 / 23

slide-17
SLIDE 17

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Interpreting the interaction

We can either report

  • the effect of vitamins for each level of antibiotics
  • the effect of antibiotics for each level of vitamins

I.e. the effect of vitamins is modified by antibiotics (and vice versa). Another word for interaction is effect modification.

17 / 23

slide-18
SLIDE 18

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Quantifying the effect of vitamins

> lm2 <- lm( growth ~ antibiotic + antibiotic:vitamins, data=d ) > summary( lm2 ) Call: lm(formula = growth ~ antibiotic + antibiotic:vitamins, data = d) Residuals: Min 1Q Median 3Q Max

  • 0.110000 -0.025000

0.003333 0.016667 0.110000 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.19000 0.03496 34.039 6.06e-10 *** antibioticyes

  • 0.15667

0.04944

  • 3.169

0.0132 * antibioticno:vitaminsyes 0.03000 0.04944 0.607 0.5608 antibioticyes:vitaminsyes 0.51000 0.04944 10.315 6.73e-06 ***

  • Signif. codes:

0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 Residual standard error: 0.06055 on 8 degrees of freedom Multiple R-squared: 0.9336, Adjusted R-squared: 0.9087 F-statistic: 37.48 on 3 and 8 DF, p-value: 4.659e-05 >

18 / 23

slide-19
SLIDE 19

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Quantifying the effect of vitamins

The effect of vitamins depends on whether antibiotics was given or not: For rats not receiving antibiotics, we see an / no effect of vitamins : The mean growth is increased / decreased by , p For rats receiving antibiotics, we see an / no effect of vitamins : The mean growth is increased / decreased by , p

19 / 23

slide-20
SLIDE 20

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

No interaction

For illustrative purposes consider

> summary( lm( logFEV ~ factor(Gender) + Age, data=fev ) )

For each gender, determine the estimated regression line from:

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.004991 0.029313 0.170 0.865 factor(Gender)1 0.098128 0.016158 6.073 2.13e-09 *** Age 0.086599 0.002736 31.651 < 2e-16 ***

20 / 23

slide-21
SLIDE 21

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Interaction (fitted with a *)

> summary( lm( logFEV ~ factor(Gender) * Age, data=fev ) )

For each gender, determine the estimated regression line from:

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.132068 0.039990 3.303 0.00101 ** factor(Gender)1

  • 0.147755

0.055855

  • 2.645

0.00836 ** Age 0.073688 0.003894 18.923 < 2e-16 *** factor(Gender)1:Age 0.024774 0.005394 4.593 5.26e-06 ***

21 / 23

slide-22
SLIDE 22

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Interaction (fitted with a :)

> summary( lm( logFEV ~ factor(Gender)+factor(Gender):Age, data=fev ))

For each gender, determine the estimated regression line from:

Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.132068 0.039990 3.303 0.00101 ** factor(Gender)1

  • 0.147755

0.055855

  • 2.645

0.00836 ** factor(Gender)0:Age 0.073688 0.003894 18.923 < 2e-16 *** factor(Gender)1:Age 0.098462 0.003733 26.377 < 2e-16 ***

22 / 23

slide-23
SLIDE 23

u n i v e r s i t y o f c o p e n h a g e n d e p a r t m e n t o f b i o s t a t i s t i c s

Illustration of the interaction model

5 10 15 0.5 1.0 1.5

Predicted values

Age log(FEV) Boys Girls

23 / 23