[R] coefficients of aov results has less number of elements?

Peng Yu pengyu.ut at gmail.com
Tue Sep 15 17:34:12 CEST 2009


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$coefficients
      A1       A2       A3       B2       B3       B4
1.993067 2.969252 3.965888 1.005445 2.020717 3.023940

Regards,
Peng




More information about the R-help mailing list