[R] Understanding Anova (car) output

John Fox jfox at mcmaster.ca
Mon Mar 2 02:37:53 CET 2009


Dear Ista,

> -----Original Message-----
> From: istazahn at gmail.com [mailto:istazahn at gmail.com] On Behalf Of Ista
Zahn
> Sent: March-01-09 6:22 PM
> To: r-help at r-project.org
> Cc: John Fox
> Subject: Understanding Anova (car) output
> 
> Dear professor Fox and R helpers,
> I have a quick question about the Anova function in the car package.
> When using the default "type II" SS I get results that I don't
> understand (see below).
> 
> library(car)
> Data <- data.frame(y=rnorm(10), x1=factor(c(rep("a",4), rep("b",6))),
> x2 = factor(c(rep("j", 2), rep("k", 3), rep("j", 2), rep("k", 3))))
> Data$c1 <- recode(Data$x1, '"a"=-1;"b"=1', as.factor.result=FALSE)
> Data$c2 <- recode(Data$x2, '"j"=-1;"k"=1', as.factor.result=FALSE)
> Data$c3 <- Data$c1*Data$c2
> 
> options(contrasts=c("contr.Sum", "contr.poly"))
> 
> m1 <- lm(y ~ x1*x2, data=Data)
> m2 <- lm(y ~ c1 + c2 + c3, data=Data)
> 
> Anova(m1)#Why is this
> Anova(m2)#Different from this?

How could Anova() possibly know in m2 that c1 and c2 are marginal to c3 (as
in can tell in m1 that x1 and x2 are marginal to x1:x2)? What you're
getting, therefore, is equivalent to "type-III" tests:

> m1 <- lm(y ~ x1*x2, data=Data)
> m2 <- lm(y ~ c1 + c2 + c3, data=Data)

> Anova(m1)#Why is this
Anova Table (Type II tests)

Response: y
           Sum Sq Df F value Pr(>F)
x1         0.3313  1  0.1599 0.7031
x2         0.6800  1  0.3282 0.5875
x1:x2      0.1160  1  0.0560 0.8209
Residuals 12.4321  6               
> Anova(m2)#Different from this?

Anova Table (Type II tests)

Response: y
           Sum Sq Df F value Pr(>F)
c1         0.2715  1  0.1310 0.7298
c2         0.5891  1  0.2843 0.6131
c3         0.1160  1  0.0560 0.8209
Residuals 12.4321  6 
             
> Anova(m1, type=3)
Anova Table (Type III tests)

Response: y
             Sum Sq Df F value Pr(>F)
(Intercept)  0.5384  1  0.2598 0.6284
x1           0.2715  1  0.1310 0.7298
x2           0.5891  1  0.2843 0.6131
x1:x2        0.1160  1  0.0560 0.8209
Residuals   12.4321  6               
>

Regards,
 John

> 
> I would greatly appreciate it if someone can help me understand why
> the results differ.
> 
> Thanks,
> Ista




More information about the R-help mailing list