#BALANCED 2-WAY ANOVA require(car) #READ STRUCTURED DATA TABLE WITH NUMERIC CODED FACTOR K=read.table("c:/2008LinearModelsData/CastleBakeryR.txt") K attach(K) Y=sales A=factor(height) B=factor(width) detach(K) contrasts(A)=contr.sum contrasts(B)=contr.sum FM=lm(Y~A+B+A:B) summary(FM) anova(FM) Anova(FM, type="3") FM2=lm(Y~A*B) #SAME RESULT AS ABOVE summary(FM) Anova(FM2,type="3")