# sum of coefficients not the same as cell mean

 set.seed(12)
f1<-gl(n=2,k=30,labels=c("Low","High"))
f2<-as.factor(rep(c("A","B","C"),times=20))
modmat<-model.matrix(~f1*f2,data.frame(f1=f1,f2=f2))
coeff<-c(1,3,-2,-4,1,-1.2)
y<-rnorm(n=60,mean=modmat%*%coeff,sd=0.1)
dat<-data.frame(y=y,f1=f1,f2=f2)
mod<-lm(y~f1+f2,data=dat)


My understanding is that I can get the mean of f1High f2B by summing up the first three coefficients

 a<-sum(mod$$coefficients[1:3]) > 2.467899 b<-mean(dat[dat$$f1=="High" & dat$f2=="B","y"]) > 2.992012  It's a perfectly balanced design, can someone please give me a clear explanation why a and b are different? • Perhaps if you created a minimal reproducible example, that would permit you to inspect modmat, the coefficients, and any other details, thereby revealing what's going on. You should have no trouble reducing modmat to a$4\times 4\$ matrix, which will be accessible. In particular, take a look at model.matrix(mod) and compare it to modmat. – whuber Feb 7 at 22:10
• @whuber, unfortunately my R skills are not as good as I wish they were (the example I provide was taken from the Internet). Anyway, I can tell that the difference between modmat and model.matrix(mod) is the inclusion of interactions in the former. As suggested in Greg Snow's answer, the addition of the interactions saturates the model, giving the same means. But I'm still confused why. The data are the same regardless of whether or not I include interactions in my model. This must relate to a statistical property that I'm failing to understand, but I suppose that is what I'm asking. – locus Feb 8 at 1:12