50% off | Unlimited Data & AI Learning
Get 50% off unlimited learning

corpcor (version 1.1.2)

varcov: Variance of the Entries of the Covariance Matrix

Description

varcov computes both the standard empirical covariance matrix ($S$) and a matrix containing the estimated variances $var(s_{ij})$ of the individual components of ($S$).

Usage

varcov(x, type=c("unbiased", "ML"), verbose=TRUE)

Arguments

x
a data matrix
type
estimate unbiased or ML variant of empirical covariance matrix (default: "unbiased", as in cov)
verbose
report progress while computing (default: TRUE)

Value

  • varcov returns a list with the following two components:
  • Sthe empirical covariance matrix.
  • var.Sa matrix containing the variances of each element in S.

Details

The variances of the empirical covariance matrix are needed to compute shrinkage estimates - see Schaefer and Strimmer (2005).

References

Schaefer, J., and Strimmer, K. (2005). A shrinkage approach to large-scale covariance estimation and implications for functional genomics. Submitted to SAGMB.

See Also

cov.shrink.

Examples

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

# small n, large p
p <- 100
n <- 20

# generate random pxp covariance matrix
sigma <- matrix(rnorm(p*p),ncol=p)
sigma <- crossprod(sigma)+ diag(rep(0.1, p))

# simulate multinormal data of sample size n  
sigsvd <- svd(sigma)
Y <- t(sigsvd$v %*% (t(sigsvd$u) * sqrt(sigsvd$d)))
X <- matrix(rnorm(n * ncol(sigma)), nrow = n) %*% Y


# estimate covariance matrix
S <- cov(X)

# varcov produces the same results as cov
vc <- varcov(X)
sum(abs(vc$S-S))

Run the code above in your browser using DataLab