2
$\begingroup$

I'm learning about two way ANOVA possibly with interaction. I'm following this tutorial http://www.sthda.com/english/wiki/two-way-anova-test-in-r

This is their code.

my_data <- ToothGrowth
my_data$dose <- factor(my_data$dose, 
                       levels = c(0.5, 1, 2),
                       labels = c("D0.5", "D1", "D2"))

res.aov2 <- aov(len ~ supp + dose, data = my_data)
summary(res.aov2)

res.aov3 <- aov(len ~ supp + dose + supp:dose, data = my_data)
summary(res.aov3)

Their results show there is a significant interaction between the 2 categorical variables using what I understand as Type I ANOVA.

And I have 2 questions:

  1. As type I ANOVA is supposed to be sequential, why do I get exactly the same results? That is,

    >res.aov3 <- aov(len ~ supp + dose + supp:dose, data = my_data)
    > summary(res.aov3)
    
        Df Sum Sq Mean Sq F value   Pr(>F)    
    supp         1  205.4   205.4  15.572 0.000231 ***
    dose         2 2426.4  1213.2  92.000  < 2e-16 ***
    supp:dose    2  108.3    54.2   4.107 0.021860 *  
    Residuals   54  712.1    13.2                     
    ---
    Signif. codes:  
    0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
    
    > res.aov4 <- aov(len ~ dose + supp + supp:dose, data = my_data)
    > summary(res.aov4)
                Df Sum Sq Mean Sq F value   Pr(>F)    
    dose         2 2426.4  1213.2  92.000  < 2e-16 ***
    supp         1  205.4   205.4  15.572 0.000231 ***
    dose:supp    2  108.3    54.2   4.107 0.021860 *  
    Residuals   54  712.1    13.2                     
    ---
    Signif. codes:  
    0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
  2. When I compare the 3 types of ANOVAs, why the results for type I and II are the same?

    library(car)
    > anova(res.aov3)  # type I
    Analysis of Variance Table
    
    Response: len
              Df  Sum Sq Mean Sq F value    Pr(>F)    
    supp       1  205.35  205.35  15.572 0.0002312 ***
    dose       2 2426.43 1213.22  92.000 < 2.2e-16 ***
    supp:dose  2  108.32   54.16   4.107 0.0218603 *  
    Residuals 54  712.11   13.19                      
    ---
    Signif. codes:  
    0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
    > Anova(res.aov3, type=2)  # type II
    Anova Table (Type II tests)
    
    Response: len
               Sum Sq Df F value    Pr(>F)    
    supp       205.35  1  15.572 0.0002312 ***
    dose      2426.43  2  92.000 < 2.2e-16 ***
    supp:dose  108.32  2   4.107 0.0218603 *  
    Residuals  712.11 54                      
    ---
    Signif. codes:  
    0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
    > Anova(res.aov3, type=3)   # type III
    Anova Table (Type III tests)
    
    Response: len
    Sum Sq Df F value    Pr(>F)    
    (Intercept) 1750.33  1 132.730 3.603e-16 ***
    supp         137.81  1  10.450  0.002092 ** 
    dose         885.26  2  33.565 3.363e-10 ***
    supp:dose    108.32  2   4.107  0.021860 *  
    Residuals    712.11 54                      
    ---
    Signif. codes:  
    0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
$\endgroup$
1
  • $\begingroup$ Welcome to the site, please consider registering your account (you can find information on how to do this in the My Account section of our help center). $\endgroup$ Dec 21, 2018 at 4:22

1 Answer 1

3
$\begingroup$

The type I, II, III (etc.) sums of squares distinction has to do with how the total sums of squares are partitioned. When your variables are not orthogonal, there is no single unique partition, but there are many ways to divvy up the sums of squares between the different variables. (It may help to read my answer here: How to interpret type I, type II, and type III ANOVA and MANOVA?) The issue with applying this to the ToothGrowth dataset is that the variables in that study were orthogonal, so the distinction does not come into play:

with(ToothGrowth, table(dose, supp))
#      supp
# dose  OJ VC
#   0.5 10 10
#   1   10 10
#   2   10 10
$\endgroup$
2
  • $\begingroup$ Thank you for your reply. Just modified the data and the results are indeed different. Cheers! $\endgroup$
    – user231906
    Dec 21, 2018 at 5:58
  • $\begingroup$ You're welcome, @user231906. $\endgroup$ Dec 21, 2018 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.