Learn R Programming

corpcor (version 1.1.2)

rebuild.cov: Rebuild Covariance Matrix from Correlation Matrix

Description

rebuild.cov takes a correlation matrix and a vector with variances and reconstructs the corresponding covariance matrix. For the inverse operation use cov2cor.

Usage

rebuild.cov(r, v)

Arguments

r
correlation matrix
v
variance vector

Value

  • A covariance matrix.

See Also

cor, cov

Examples

Run this code
# load corpcor library
library("corpcor")


# some statistics on the US states
data(state)
m <- t(state.x77)
dim(m) # sample size: 8, number of variables: 50

# covariance matrix
m.cov <- cov(m)
m.cov

# variances
m.var <- diag(m.cov)
m.var

# correlation matrix
m.cor.1 <- cor(m)
m.cor.1

# correlation matrix via covariance matrix
m.cor.2 <- cov2cor(m.cov)
m.cor.2

zapsmall(m.cor.1) == zapsmall(m.cor.2)

# reconstruct covariance matrix
rebuild.cov(m.cor.1, m.var)

Run the code above in your browser using DataLab