cor2cov: Converting a correlation matrix into a covariance matrix

View source: R/cor2cov.R

cor2covR Documentation

Converting a correlation matrix into a covariance matrix

Description

Converts a correlation matrix into a covariance matrix using variance information. It is therefore the inverse of cov2cor.

Usage

cor2cov(C, var = NULL)

Arguments

C

a symmetric numeric correlation matrix \mathbf{C}.

var

a vector of variances s_i^2, one per row/column of C. Required: the default NULL gives an error.

Details

Calculates the covariance matrix \mathbf{\Sigma} from a correlation matrix \mathbf{C} and the outer product of the vector of standard deviations \mathbf{s} = (s_1, \ldots, s_N)^T, with s_i^2 the elements of var, by the elementwise (Hadamard) product \circ:

\mathbf{\Sigma} = \mathbf{s}\mathbf{s}^T \circ \mathbf{C}, \qquad \Sigma_{ij} = s_i\, s_j\, C_{ij}

This is equivalent to \mathbf{\Sigma} = \mathbf{D}\mathbf{C}\mathbf{D} with \mathbf{D} = \mathrm{diag}(\mathbf{s}), the inverse of the relation r(x_i, x_j) = u(x_i, x_j)/(u(x_i)\, u(x_j)) of JCGM 100:2008, 5.2.2.

Value

The corresponding covariance matrix.

Author(s)

Andrej-Nikolai Spiess

References

Evaluation of measurement data - Guide to the expression of uncertainty in measurement.
JCGM 100:2008. Joint Committee for Guides in Metrology (2008).
\Sexpr[results=rd]{tools:::Rd_expr_doi("10.59161/JCGM100-2008E")}

Examples

## JCGM 100:2008, Annex H.2
## (see 'References'), simultaneous resistance
## and reactance measurement.
data(H.2)

## Original covariance matrix.
COV <- cov(H.2)
## extract variances
VAR <- diag(COV)

## cor2cov covariance matrix.
COV2 <- cor2cov(cor(H.2), VAR) 

## Equal to original covariance matrix.
all.equal(COV2, COV)

propagate documentation built on Nov. 10, 2026, 9:07 a.m.