R Language Basic usage of Anova()


Example

When dealing with an unbalanced design and/or non-orthogonal contrasts, Type II or Type III Sum of Squares are necessary. The Anova() function from the car package implements these. Type II Sum of Squares assumes no interaction between main effects. If interactions are assumed, Type III Sum of Squares is appropriate.

The Anova() function wraps around the lm() function.


Using the mtcars data sets as an example, demonstrating the difference between Type II and Type III when an interaction is tested.

> Anova(lm(wt ~ factor(cyl)*factor(am), data=mtcars), type = 2)
Anova Table (Type II tests)

Response: wt
                       Sum Sq Df F value    Pr(>F)    
factor(cyl)            7.2278  2 11.5266 0.0002606 ***
factor(am)             3.2845  1 10.4758 0.0032895 ** 
factor(cyl):factor(am) 0.0668  2  0.1065 0.8993714    
Residuals              8.1517 26                      
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

> Anova(lm(wt ~ factor(cyl)*factor(am), data=mtcars), type = 3)
Anova Table (Type III tests)

Response: wt
                        Sum Sq Df F value    Pr(>F)    
(Intercept)            25.8427  1 82.4254 1.524e-09 ***
factor(cyl)             4.0124  2  6.3988  0.005498 ** 
factor(am)              1.7389  1  5.5463  0.026346 *  
factor(cyl):factor(am)  0.0668  2  0.1065  0.899371    
Residuals               8.1517 26                      
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1