Learn R Programming

propagate (version 1.3-0)

cor2cov: 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)

Value

The corresponding covariance matrix.

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.

Author

Andrej-Nikolai Spiess

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.

References

Evaluation of measurement data - Guide to the expression of uncertainty in measurement.
JCGM 100:2008. Joint Committee for Guides in Metrology (2008).
tools:::Rd_expr_doi("10.59161/JCGM100-2008E")

Examples

Run this code
## 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)

Run the code above in your browser using DataLab