cov2cor(V)

Convert a covariance matrix to a correlation matrix.

- V – A symmetric numeric matrix, typically positive-definite since it often represents a covariance matrix.

Example. A vector of 30 observations with a wide range of values is created and then converted into a 10-by-3 matrix. If we view this as a matrix of 10 observations (represented by the rows), then this is a small sample and we should expect fairly large sample correlations. We compute the covariance matrix, the correlation matrix, and then we use cov2cor to convert the covariance matrix to a correlation matrix.

> set.seed(5) > x <- rnorm(30, sd=runif(30, 2, 50)) > d <- matrix(x, 10) > V <- cov(d) > V [,1] [,2] [,3] [1,] 1875.3209 429.8712 462.4775 [2,] 429.8712 1306.9817 -262.8231 [3,] 462.4775 -262.8231 755.5193 > > cor(d) [,1] [,2] [,3] [1,] 1.0000000 0.2745780 0.3885349 [2,] 0.2745780 1.0000000 -0.2644881 [3,] 0.3885349 -0.2644881 1.0000000 > > cov2cor(V) [,1] [,2] [,3] [1,] 1.0000000 0.2745780 0.3885349 [2,] 0.2745780 1.0000000 -0.2644881 [3,] 0.3885349 -0.2644881 1.0000000