Correlation matrix from Covariance matrix

Solution 1:

From a matrix algebra point of view the answer is fairly simple. Assume your covariance matrix is $\Sigma$ and let

$$ D =\sqrt{ \text{diag}\left( {\Sigma} \right)} $$

then the correlation matrix is given by $$ \varrho = D^{-1}\Sigma D^{-1} $$

Edit: fixed to include square root

Solution 2:

Suppose you have a random vector $\mathbf{g}$, then the covariance matrix of $\mathbf{g}$ is defined as $$\mathbf{K}=\mathbf{E}\{(\mathbf{g}-\bar{\mathbf{g}})(\mathbf{g}-\bar{\mathbf{g}})^{\dagger}\}$$ where $\mathbf{E}$ denotes expectation, $\bar{\mathbf{g}}$ denotes the mean of $\mathbf{g}$, $\dagger$ means transpose for real random vector, and conjugate transpose for complex random vector.

The correlation matrix is $$\mathbf{R}=\mathbf{E}\{\mathbf{g}\mathbf{g}^{\dagger}\}$$

So we have $$\mathbf{K}=\mathbf{R}-\bar{\mathbf{g}}\bar{\mathbf{g}}^{\dagger}$$

For zero-mean random vectors $\mathbf{K}=\mathbf{R}$.

EDIT: for another definition where the correlation matrix is the normalized covariance matrix, the relation is $$\mathbf{R}_{ij}=\frac{\mathbf{K}_{ij}}{\sigma_i \sigma_j}$$ where $\sigma_i, \sigma_j$ are the standard deviation of $\mathbf{g}_i$ and $\mathbf{g}_j$, respectively.

Solution 3:

Cribbing from the answer by Brian B., assume your covariance matrix is Σ and let

D = sqrt(diag(Σ)), a vector of square roots of the diagonal of Σ.

then the correlation matrix is given by ϱ = D-inverse Σ D-inverse-prime

D, here, is a p x 1 vector (from the diagonal of Σ) and its inverse is the item by item inverse of D -- i.e., vector of {one over element} for each element.

Solution 4:

Matlab has a function cov2corr to extract the correlation matrix from covariance matrix. If you're already using Matlab, no need to reinvent the wheel. The implementation of the function is similar to chaohuang's answer above (with some error checking).