[R] Vectorize a correlation matrix

Michael Dewey info at aghmed.fsnet.co.uk
Thu Nov 22 18:50:53 CET 2007


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



More information about the R-help mailing list