[R] Singular model.matrix of nested designs
Peng Yu
pengyu.ut at gmail.com
Tue Sep 22 16:30:29 CEST 2009
Hi,
I want to do ANOVA for nested designs like following. I don't
understand why the matrix (t(X) %*% X) is singular. Can somebody help
me understand it?
Regards,
Peng
> a=2
> b=3
> n=4
> A = as.vector(sapply(1:a,function(x){rep(x,b*n)}))
> B = as.vector(sapply(1:(a*b), function(x){rep(x,n)}))
> cbind(A,B)
A B
[1,] 1 1
[2,] 1 1
[3,] 1 1
[4,] 1 1
[5,] 1 2
[6,] 1 2
[7,] 1 2
[8,] 1 2
[9,] 1 3
[10,] 1 3
[11,] 1 3
[12,] 1 3
[13,] 2 4
[14,] 2 4
[15,] 2 4
[16,] 2 4
[17,] 2 5
[18,] 2 5
[19,] 2 5
[20,] 2 5
[21,] 2 6
[22,] 2 6
[23,] 2 6
[24,] 2 6
> 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)
> X=model.matrix(afit)
> solve(t(X) %*% X)
Error in solve.default(t(X) %*% X) :
Lapack routine dgesv: system is exactly singular
More information about the R-help
mailing list