Zaheer Abbas
2012-Dec-05 15:09 UTC
[R] Incidence Matrix of Experimental Design Using R language Program
Hi I am working on educational assignment to produce an *Incidence matrix *from a *BIB design *using R language software. I found a web page *http://wiki.math.yorku.ca/index.php/R:_Incidence_matrix * about the problem. But it produces Data matrix instead of Incidence matrix. can you please help me out using R software. thanks and regards zaheer *following are the sample codes of my assignment with resultant "Incidence Matrix" as mentioned in above link, but this is, according to my knowledge, Data matrix of any experimental design. * b=4 #Number of Blocks t=4 #Number of Column z=c(1,2,3) #Shift m=NULL y=c(0) w=c(y,cumsum(z) %%t) print("The Initial Block is=") print(w) p=seq(from=0, to=t-1, by=1) l=NULL for(i in 1:b) { for(j in 1:t) { l=c(l,rep((w[i]+p[j]+t)%% t)) } } x= matrix(c(l),nrow=b,ncol=t,byrow = TRUE) print("The Design Layout is ") print.matrix <- function(x){ write.table(format(x, justify="right"), row.names=F,col.names=F,quote=F }) print(x) *"BIB design Output"* [,1] [,2] [,3] [,4] [1,] 0 1 2 3 [2,] 1 2 3 0 [3,] 3 0 1 2 [4,] 2 3 0 1 vec <- c(as.matrix(x)) # converting matrix into Vector for incidence correct matrix a=t(x)%*%x print.matrix <- function(a){ write.table(format(a, justify="right"), row.names=F, col.names=F, quote=F) } print("X’X ") print(a) A=contrasts( as.factor(x), contrasts =FALSE)[ as.factor(x),] print.matrix <- function(A){ write.table(format(A, justify="right"), row.names=F, col.names=F, quote=F) } print("The Incidence Matrix is=") print(A) *OUTPUT* 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1 0 0 *I need this * * 1 1 1 1* * 1 1 1 1* * 1 1 1 1* * 1 1 1 1* [[alternative HTML version deleted]]