#ANOVA AS LINEAR MODELS ?contrasts ?contr.treatment options(digits=12) #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #CELL MEANS MODEL #READ STRUCTURED DATA TABLE WITH NUMERIC CODED FACTOR K=read.table("c:/2008LinearModelsData/KentonFoodCMR.txt") K attach(K) FM=lm(Y~X1+X2+X3+X4-1) #FM for original data K & codes summary(FM) model.matrix(FM) anova(FM) detach(K) Kc=data.frame(scale(K,center=T,scale=F)) Kc attach(Kc) FM=lm(Y~X1+X2+X3+X4-1) #FM for centered data Kc anova(FM) detach(Kc) #------------------------------------------------- #TREATMENTS MODEL IN R #READ STRUCTURED DATA TABLE WITH NUMERIC CODED FACTOR K=read.table("c:/2008LinearModelsData/KentonFoodR.txt") K attach(K) Y=Sales X=factor(Design) # factor() IN DEFAULT SETTING NM=lm(Y~X) summary(NM) anova(NM) model.matrix(NM) #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #UNWEIGHTED FACTOR EFFECTS MODEL #READ STRUCTURED DATA TABLE WITH NUMERIC CODED FACTOR Kf=read.table("c:/2008LinearModelsData/KentonFoodFER.txt") Kf attach(Kf) TM=lm(Y~T1+T2+T3) summary(TM) anova(TM) model.matrix(TM) detach(Kf) #------------------------------------------------- #USE OF factor() AS SUM #READ STRUCTURED DATA TABLE WITH NUMERIC CODED FACTOR K=read.table("c:/2008LinearModelsData/KentonFoodR.txt") K attach(K) Y=Sales X=factor(Design) contrasts(X)=contr.sum #CONVERTS FACTOR CODING TO SUM SM=lm(Y~X) summary(SM) anova(SM) model.matrix(SM) #+++++++++++++++++++++++++++++++++++++++++++++++++