Moore1 <- read.table("c:/temp/moore.txt",header=F,skip=1) names(Moore1) <- c("partner","status","conformity","fcategory","fscore") # defining deviation-coded variables Moore1$statuslow <- as.numeric(Moore1$status == "low") - as.numeric(Moore1$status == "high") Moore1$fcatlow <- as.numeric(Moore1$fcategory == "low") - as.numeric(Moore1$fcategory == "high") Moore1$fcatmed <- as.numeric(Moore1$fcategory == "medium") - as.numeric(Moore1$fcategory == "high") # defining crossproduct variables used to test for interaction Moore1$statLcatL <- Moore1$statuslow*Moore1$fcatlow Moore1$statLcatM <- Moore1$statuslow*Moore1$fcatmed # individual regression models anova(lm(conformity ~ statuslow +fcatlow +fcatmed +statLcatL +statLcatM, data=Moore1 ) ) anova(lm(conformity ~ statuslow +fcatlow +fcatmed, data=Moore1 ) ) anova(lm(conformity ~ statuslow +statLcatL +statLcatM, data=Moore1 ) ) anova(lm(conformity ~ fcatlow +fcatmed +statLcatL +statLcatM, data=Moore1 ) ) anova(lm(conformity ~ statuslow, data=Moore1 ) ) anova(lm(conformity ~ fcatlow +fcatmed, data=Moore1 ) ) # the car package contains a function 'Anova' that can calculate Type II or Type III SS # it calculates Type II SS by default library(car) # this produces the same results as in Table 8.4 for Type II tests Anova(lm(conformity ~ status +fcategory +status:fcategory, data=Moore1 ),type="II") # this output does not match the Type III tests from Table 8.4, but the regression models # above can be used to match the output in the text Anova(lm(conformity ~ status +fcategory +status:fcategory, data=Moore1 ),type="III")