two way anova interaction
play

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


  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

  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  female ≤ 50 µ 1    female > 50 µ 2  = µ i male ≤ 50 µ 3    male > 50 µ 4   female a ≤ 50    a b female > 50 +  = male a c ≤ 50 +    a c b male > 50 + +  or put in tabular form: >50 ≤ 50 female a a + b male a + c a + b + c 2 / 23

  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

  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

  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

  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

  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  female ≤ 50 µ 1    female > 50 µ 2  = µ i male ≤ 50 µ 3    male > 50 µ 4   female a ≤ 50    female a b > 50 +  = a c male ≤ 50 +    male a c b + d > 50 + +  is an interaction model because of the interaction term d . 7 / 23

  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 or 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

  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

  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

  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 old ● ● young ● ● b Mean old c ● ● young ● ● M F 11 / 23

  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 young ● ● Mean old ● ● old ● ● young ● ● M F 12 / 23

  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

  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  no antibiotics no vitamins µ 1    no antibiotics vitamins µ 2  = µ i antibiotics no vitamins µ 3    antibiotics vitamins µ 4   no antibiotics no vitamins a    a b no antibiotics vitamins +  = antibiotics no vitamins a c +    a c b + d antibiotics vitamins + +  14 / 23

  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

  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

  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

  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 >

Recommend


More recommend