# this R code produces similar output to the corresponding SAS code data <- matrix(scan(),ncol=3,byrow=TRUE) 7 1 1 5 1 1 3 1 1 5 1 2 9 2 1 6 2 2 9 2 2 12 2 2 data Unbal1 <- data.frame(data) colnames(Unbal1) <- c("y","factor1","factor2") rm(data) Unbal1$factor1 <- as.factor(Unbal1$factor1) # to make sure that factor1 is a factor, not numeric Unbal1$factor2 <- as.factor(Unbal1$factor2) # to make sure that factor2 is a factor, not numeric Unbal1$x1 <- (Unbal1$factor1 == "1")*1 - (Unbal1$factor1 == "2")*1 # this replicates the coding scheme used in the SAS program Unbal1$x2 <- (Unbal1$factor2 == "1")*1 - (Unbal1$factor2 == "2")*1 # this replicates the coding scheme used in the SAS program Unbal1$x3 <- Unbal1$x1*Unbal1$x2 Unbal1 anova(lm(y ~ factor1 + factor2 + factor1:factor2 , data = Unbal1)) # note that anova uses Type I SS anova(lm(y ~ factor2 + factor1 + factor1:factor2 , data = Unbal1)) anova(lm(y ~ x1 , data = Unbal1)) # The SS per term can be added to get the model SS anova(lm(y ~ x2 , data = Unbal1)) anova(lm(y ~ x1 + x2 , data = Unbal1)) anova(lm(y ~ x2 + x3 , data = Unbal1)) anova(lm(y ~ x1 + x2 + x3 , data = Unbal1)) library(car) Anova(lm(y ~ factor2 + factor1 + factor1:factor2, data = Unbal1)) # the Anova function from the car package can produce Type II or Type III SS # it produces Type II SS by default rm(Unbal1) # erase objects when we are finished