Checking Type III ANOVA results [duplicate]

2019-07-26 03:33发布

问题:

This question already has an answer here:

  • How to use formula in R to exclude main effect but retain interaction 3 answers
  • Why do I get NA coefficients and how does `lm` drop reference level for interaction 1 answer

Setting aside the debate about Type III ANOVA and the Principle of Marginality and all that...

I've set up two models whose sum of squares should be different (and Type III ANOVA would test that difference). Here's the code:

library(car)
library(openintro)
data(hsb2)
hsb2$gender <- factor(hsb2$gender)
contrasts(hsb2$gender) <- "contr.sum"
contrasts(hsb2$ses) <- "contr.sum"
math_gender_int <- lm(math ~ gender + gender:ses, data = hsb2)
math_gender_ses_int <- lm(math ~ gender + ses + gender:ses, data = hsb2)

Now I should be able to see a difference in the sum of squares between these two models. After all, the "full" model has one more term in it:

anova(math_gender_int, math_gender_ses_int)

But the output shows this:

Analysis of Variance Table

Model 1: math ~ gender + gender:ses
Model 2: math ~ gender + ses + gender:ses
  Res.Df   RSS Df  Sum of Sq F Pr(>F)
1    194 15858                       
2    194 15858  0 -1.819e-12      

What's going on here?

标签: r lm anova