car::Anova in R gives different p-values for TypeII vs TypeIII even though I have a balanced design?

Viewed 63

I have tried in vain to find the answer to this question in the other two way ANOVA discussions I have found, so I hope this isn't a repeat.

I have a balanced design (5 observations in each of 4 groups). To my understanding, this means that performing a two-way ANOVA using type I, II, or III sums of squares should all give the same results for the main effects and/or interaction.

My linear model is as such:

mod <- lm(X2HG ~ Genotype * Diet, data = df)  

When I run typeII in R using:

Anova(mod, type=2)
Anova Table (Type II tests)
Response: X2HG
                  Sum Sq Df F value   Pr(>F)   
Genotype      2.9033e+11  1  4.5914 0.047854 * 
Diet          8.4475e+11  1 13.3594 0.002136 **
Genotype:Diet 5.5728e+11  1  8.8132 0.009051 **
Residuals     1.0117e+12 16                    

The F and p-values are VERY different to typeIII:

Anova(mod, type=3)
Anova Table (Type III tests)

Response: X2HG
                  Sum Sq Df F value    Pr(>F)    
(Intercept)   1.5182e+12  1 24.0103 0.0001602 ***
Genotype      2.1568e+10  1  0.3411 0.5673422    
Diet          1.4894e+10  1  0.2355 0.6340278    
Genotype:Diet 5.5728e+11  1  8.8132 0.0090510 ** 
Residuals     1.0117e+12 16                      

Can anyone explain why the difference? Am I wrong in thinking they should be the same?

EDIT: For further clarity, I get the same output using type 2 and type 3 anova from the bioinfokit package in python so this isn't specific to the car package in R.

2 Answers

No. Type III effects are adjusted for all other terms in the model. Type II effects are adjusted for all terms other than those which contain them. One effect contains another if the other effect can be expressed as a linear combination of the first effect's terms. Thus, interactions cantain the main effects of the constituent terms.

That's why you see the statistics for everything except the interaction term changing. The Type I, II and III effects will be equal for balanced data only in the absence of interaction terms.

You can reconstruct the Type III SS using Type I SS by changing the order in which terms are added to the model: the Type III SS for each effect is equal to the Type I SS when that effect is added to the model last. This means you need to fit multiple models to get the Type II effects in this way.

You can do a similar thing to recover the Type II effects from the Type I effects by ensuring that the main effect terms are all fitted before any interaction term.

As per this reference: https://mcfromnz.wordpress.com/2011/03/02/anova-type-iiiiii-ss-explained/

First, it is necessary to set the contrasts option in R. Because the multi-way ANOVA model is over-parameterised, it is necessary to choose a contrasts setting that sums to zero, otherwise the ANOVA analysis will give incorrect results with respect to the expected hypothesis. (The default contrasts type does not satisfy this requirement.)"

Anova(lm(X2HG ~ Genotype * Diet, data = df, contrasts=list(Genotype=contr.sum, Diet=contr.sum)), type=3)

Doing this gave the following output:

Anova Table (Type III tests)

Response: X2HG
                  Sum Sq Df  F value    Pr(>F)    
(Intercept)   1.0085e+13  1 159.4960 9.779e-10 ***
Genotype      2.9033e+11  1   4.5914  0.047854 *  
Diet          8.4475e+11  1  13.3594  0.002136 ** 
Genotype:Diet 5.5728e+11  1   8.8132  0.009051 ** 
Residuals     1.0117e+12 16  

Which gives the same as the type II and aov() function (which defaults to type I).

Related