Learn R Programming

JWileymisc (version 1.4.1)

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.

See Also

Examples

Run this code
# using a built in dataset
cor2cov(cor(longley), sapply(longley, sd))

# should match the above covariance matarix
cov(longley)
all.equal(cov(longley), cor2cov(cor(longley), sapply(longley, sd)))

Run the code above in your browser using DataLab