cor2cov: Convert a correlation matrix and standard deviations to a...

View source: R/utils.R

cor2covR Documentation

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)

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.

Value

an n x n covariance matrix

See Also

cov2cor

Examples

# 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)))

JWiley/JWileymisc documentation built on Feb. 15, 2024, 12:23 p.m.