Re: [R] Converting variance covariance matrix to correlation matrix

2008-05-19 Thread Peter Dalgaard
Peter Dalgaard wrote: > Arun Kumar Saha wrote: >> Suppose I have a Variance-covariance matrix A. Is there any fast way to >> calculate correlation matrix from 'A' and vice-versa without emplying >> any >> 'for' loop? >> > C <- cov2cor(A) > > The other way around is ill-defined, but if d is the v

Re: [R] Converting variance covariance matrix to correlation matrix

2008-05-19 Thread Dimitris Rizopoulos
check the following: # covariance matrix V <- var(matrix(rnorm(10*4), 10, 4)) cov2cor(V) # correlation matrix R <- cov2cor(V) # vector of std. dev. sds <- rnorm(4)^2 R * sds * rep(sds, each = nrow(R)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Pu

Re: [R] Converting variance covariance matrix to correlation matrix

2008-05-19 Thread Peter Dalgaard
Arun Kumar Saha wrote: Suppose I have a Variance-covariance matrix A. Is there any fast way to calculate correlation matrix from 'A' and vice-versa without emplying any 'for' loop? C <- cov2cor(A) The other way around is ill-defined, but if d is the vector of variances, d <- sqrt(diag(A)) A