Hello I can construct a correlation matrix from an (ordered) vector of correlation coefficients as follows: x <- c(0.1,0.2,0.3,0.4,0.5) n <- length(x) cmat <- diag(rep(0.5,n)) cmat[lower.tri(cmat,diag=0)] <- x cmat <- cmat+t(cmat) But how to do the reverse operation, i.e. produce x from cmat? Thanks for help, Serguei Kaniovski [[alternative HTML version deleted]]
Serguei Kaniovski wrote:> Hello > > I can construct a correlation matrix from an (ordered) vector of > correlation coefficients as follows: > > x <- c(0.1,0.2,0.3,0.4,0.5) > n <- length(x) > cmat <- diag(rep(0.5,n)) > cmat[lower.tri(cmat,diag=0)] <- x > cmat <- cmat+t(cmat) > > But how to do the reverse operation, i.e. produce x from cmat?This comes close: cmat[lower.tri(cmat)] It produces a vector of length 10 because x was recycled in your line 4. Duncan Murdoch
At 09:58 22/11/2007, Serguei Kaniovski wrote:>Hello > >I can construct a correlation matrix from an (ordered) vector of >correlation coefficients as follows: > >x <- c(0.1,0.2,0.3,0.4,0.5) >n <- length(x) >cmat <- diag(rep(0.5,n)) >cmat[lower.tri(cmat,diag=0)] <- x >cmat <- cmat+t(cmat)> cmat [,1] [,2] [,3] [,4] [,5] [1,] 1.0 0.1 0.2 0.3 0.4 [2,] 0.1 1.0 0.5 0.1 0.2 [3,] 0.2 0.5 1.0 0.3 0.4 [4,] 0.3 0.1 0.3 1.0 0.5 [5,] 0.4 0.2 0.4 0.5 1.0 > Is that really what you intended?>But how to do the reverse operation, i.e. produce x from cmat? > >Thanks for help, >Serguei Kaniovski > [[alternative HTML version deleted]]Michael Dewey http://www.aghmed.fsnet.co.uk