I'm confused about how type III SS are calculated for a "main effect". According to what I have read, Type III SS is calculated by evaluating the change in the SSE by removing only the variable in question, not interactions involving that variable. So, I took a dataset (for a 2x2 ANOVA) and evaluated it with Type III SS (using ezANOVA in R; car's Anova gives same results). I then recoded the IVs as simple indicator variables, and calculated a third indicator for the interaction. I then used lm() to fit a series of linear models in which one term was dropped, and calculated SSE vs. full model. SSE difference was equivalent to the SS term for the interaction in the ezANOVA model, but it was not correct for the main effects terms! What am I not understanding about how Type III SS is calculated for main effects? Example code below.
library(dplyr)
library(ez)
df = read.table("http://personality-project.org/r/datasets/R.appendix2.data", header=T)
ezANOVA(data=df, between=.(Gender,Dosage),dv=Alertness, wid=Observation, type=3, detailed=TRUE)
# from above, Type III SS for...
# Gender:Doseage is 0.0625
# Gender is 76.56
# Doseage is 5.06
# recoding variables as indicators for regression
df %>% mutate(male=ifelse(Gender=="m",1,0)) %>% mutate(dosea=ifelse(Dosage=="a",1,0)) %>% mutate(intx = ifelse(male&dosea, 1, 0)) -> df
# calculate SS for interaction by dropping interaction term on the left-hand side
# result is 0.0625, like ezANOVA
deviance(lm(Alertness~male+dosea,data=df)) - deviance(lm(Alertness~male+dosea+intx, data=df))
# calculate SS for doseage by dropping dosea term on left side
# result is 2, doesn't match ezANOVA output (5.06)
deviance(lm(Alertness~male+intx,data=df)) - deviance(lm(Alertness~male+dosea+intx, data=df))
# calculate SS for gender by dropping male term on left side
# result is 36.125, doesn't match ezANOVA output (76.56)
deviance(lm(Alertness~dosea+intx,data=df)) - deviance(lm(Alertness~male+dosea+intx, data=df))
EDIT: I think I figured the issue out. If I code the main effects as 1's and 0's, and take the product of the two as the interaction, then I get a vector that is correlated with the main effects. If I recode factors as 1 and -1 (i.e, mean-center), instead, then the interaction term is not correlated. In this case, I get the correct values.