Peng Yu
2009-Sep-15 15:34 UTC
[R] coefficients of aov results has less number of elements?
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)?> 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$coefficientsA1 A2 A3 B2 B3 B4 1.993067 2.969252 3.965888 1.005445 2.020717 3.023940 Regards, Peng
Douglas Bates
2009-Sep-16 12:39 UTC
[R] coefficients of aov results has less number of elements?
On Tue, Sep 15, 2009 at 10:34 AM, Peng Yu <pengyu.ut at 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 at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Apparently Analagous Threads
- Why F value and Pr are not show in summary() of an aov() result?
- The equivalence of t.test and the hypothesis testing of one way ANOVA
- "1 observation deleted due to missingness" from summary() on the result of aov()
- What does model.matrix() return?
- What are the return values of aov?