cor2cov: Convert a correlation matrix and standard deviations to a covariance matrix
Description
This is a simple function designed to convert a correlation matrix
(standardized covariance matrix) back to a covariance matrix.
It is the opposite of cov2cor.
Usage
cor2cov(V, sigma)
Value
an n x n covariance matrix
Arguments
V
an n x n correlation matrix. Should be numeric, square, and symmetric.
sigma
an n length vector of the standard deviations. The length of the
vector must match the number of columns in the correlation matrix.
# using a built in datasetcor2cov(cor(longley), sapply(longley, sd))
# should match the above covariance matarixcov(longley)
all.equal(cov(longley), cor2cov(cor(longley), sapply(longley, sd)))