[R] Constructing Matrices

Liaw, Andy andy_liaw at merck.com
Thu Jan 20 14:40:52 CET 2005


I'm still not clear on exactly what your question is.  If you can plug in
the numbers you want in, say, the lower triangular portion, you can copy
those to the upper triangular part easily; something like:

m[upper.tri(m)] <- m[lower.tri(m)]

Is that what you're looking for?

Andy

> From: Doran, Harold
> 
> Dear List:
> 
> I am working to construct a matrix of a particular form. For the most
> part, developing the matrix is simple and is built as follows:
> 
> vl.mat<-matrix(c(0,0,0,0,0,64,0,0,0,0,64,0,0,0,0,64),nc=4)
> 
> Now to expand this matrix to be block-diagonal, I do the following:
> 
> sample.size <- 100 # number of individual students
> I<- diag(sample.size)
> bd.mat<-kronecker(I,vl.mat)
> 
> This creates a block-diagonal matrix with variances along the diagonal
> and covariances within-student to be zero (I am working with
> longitudinal student achievement data). However, across 
> student, I want
> to have the correlation equal to 1 for each variance term. To
> illustrate, here is a matrix for 2 students. The goal is for the
> correlation between the second variance term for student 1 to be
> perfectly correlated with the variance term for student 2. In other
> words, I need to plug in 64 at position (6,2) and (2,6), another 64 at
> position (7,3) and (3,7) and another 64 at positions (8,4) and (4,8).
> I'm having some difficulty conceptualizing how to construct 
> this part of
> the matrix and would appreciate any thoughts.
> 
> Thank you,
> Harold
> 
> 
>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
> [1,]    0    0    0    0    0    0    0    0
> [2,]    0   64    0    0    0    0    0    0
> [3,]    0    0   64    0    0    0    0    0
> [4,]    0    0    0   64    0    0    0    0
> [5,]    0    0    0    0    0    0    0    0
> [6,]    0    0    0    0    0   64    0    0
> [7,]    0    0    0    0    0    0   64    0
> [8,]    0    0    0    0    0    0    0   64
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list