On Tue, Sep 15, 2009 at 10:34 AM, Peng Yu <pengyu...@gmail.com> wrote: > Hi, > > I run the following commands. 'A' has 3 levels and 'B' has 4 levels. > Should there be totally 3+4 = 7 coefficients (A1, A2, A3, B1, B2, B3, > B4)?
If you were to define a model matrix for those coefficients it would be rank deficient. (the sum of the first three columns is 1 and the sum of the last four columns is 1) You only have 6 degrees of freedom in total, not 7. Because of the -1 in the formula the first factor is expanded to the indicator columns but the second is represented with a set of 3 "contrasts" which are the contr.treatment version, by default. >> a=3 >> b=4 >> n=1000 >> A = rep(sapply(1:a,function(x){rep(x,n)}),b) >> B = as.vector(sapply(sapply(1:b, function(x){rep(x,n)}), >> function(x){rep(x,a)})) >> Y = A + B + rnorm(a*b*n) >> >> fr = data.frame(Y=Y,A=as.factor(A),B=as.factor(B)) >> afit=aov(Y ~ A + B - 1,fr) >> afit$coefficients > A1 A2 A3 B2 B3 B4 > 1.993067 2.969252 3.965888 1.005445 2.020717 3.023940 > > Regards, > Peng > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.