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$).varcov(x, type=c("unbiased", "ML"), verbose=TRUE)
cov
)varcov
returns a list with the following two components:cov.shrink
.# 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