time=factor(rep(c(3,6),each=5)) temp=factor(rep(c(20,30,20,30),c(2,3,4,1))) y=c(2,5,9,12,15,6,6,7,7,16) d=data.frame(time,temp,y) d o=lm(y~time+temp+time:temp,data=d) anova(o) X1=matrix(1,nrow=10,ncol=1) X1 X2=model.matrix(~time) X2 X3=model.matrix(~time+temp) X3 X4=model.matrix(~time+temp+time:temp) X4 Px=function(X) { X%*%solve(t(X)%*%X)%*%t(X) } P1=Px(X1) P1 P2=Px(X2) P2 P3=Px(X3) P3 P4=Px(X4) P4 drop(t(y)%*%(P2-P1)%*%y) drop(t(y)%*%(P3-P2)%*%y) drop(t(y)%*%(P4-P3)%*%y) anova(o) #To understand the null hypothesis that is being #tested by the ANOVA table time test, we should #examine the noncentrality parameter of that test. #The noncentrality parameter for the test of time #is the squared length of the vector P2 E(y) - P1 E(y), #divided by sigma^2. #Note that E(y) is of the form # # mu_11 # mu_11 # mu_12 # mu_12 # mu_12 # mu_21 # mu_21 # mu_21 # mu_21 # mu_22 #Thus, P1 E(y) is the vector with 10 components #each identical to # # (2*mu_11+3*mu_12+4*mu_21+mu_22)/10. #P2 E(y) is has two distinct components: # # (2*mu_11+3*mu_12)/5 repeated five times #and # (4*mu_21+mu_22)/5 repeated five times. #It follows that the noncentrality parameter #will be zero if and only if # # 2*mu_11+3*mu_12=4*mu_21+mu_22. #Thus the time test in the ANOVA table is testing # # H_0: 2*mu_11+3*mu_12=4*mu_21+mu_22. #This is not a scientifically interesting test. #Now suppose the data are balanced. #For balanced data, the sequential sums of squares #are the same regardless of the order of the #terms in the anova table. time=factor(rep(c(3,6),each=4)) temp=factor(rep(c(20,30,20,30),c(2,2,2,2))) y=c(2,5,9,11,8,10,16,20) d=data.frame(time,temp,y) d o1=lm(y~time+temp+time:temp,data=d) o2=lm(y~temp+time+time:temp,data=d) anova(o1) anova(o2) o3=lm(y~time+temp,data=d) o4=lm(y~temp+time,data=d) anova(o3) anova(o4)