#NESTED ANOVA - UNBALANCED CASE require(car) #READ STRUCTURED DATA TABLE WITH NESTED CODE KNNL p. 1105 K=read.table("c:/2008LinearModelsData/TrainingSchoolUBcodedR.txt") K attach(K) Y=Score FM=lm(Y~X1+X2+X3+X4) summary(FM) anova(FM) RMa=lm(Y~X2+X3+X4) RMbina=lm(Y~X1) anova(RMa,FM) anova(RMbina,FM) detach(K) #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #READ STRUCTURED DATA TABLE WITH NUMERIC CODED FACTOR #THE FOLLOWING IS AS CODED BY KNNL K=read.table("c:/2008LinearModelsData/TrainingSchoolUBR.txt") K #THE FOLLOWING WITH RECODING FOR EMBEDDED FACTOR TO SIMPLIFY MODEL.MATRIX K=read.table("c:/2008LinearModelsData/TrainingSchoolUB2R.txt") K attach(K) Y=Score A=factor(School) B=factor(Instructor) contrasts(A)=contr.treatment contrasts(B)=contr.treatment FM=lm(Y~A+B%in%A) anova(FM) detach(K)