Learn R Programming

corpcor (version 1.2.0)

invcov.shrink: Fast Computation of the Inverse of the Covariance and Correlation Matrix

Description

The functions invcov.shrink and invcor.shrink implement an algrithm to *efficiently* compute the inverses of shrinkage estimates of covariance (cov.shrink) and correlation (cor.shrink).

Usage

invcov.shrink(x, lambda, w, verbose=TRUE)
invcor.shrink(x, lambda, w, verbose=TRUE)

Arguments

x
a data matrix
lambda
the shrinkage intensity (range 0-1). If $\lambda$ is is not specified (the default) a suitable value is automatically chosen such that the resulting shrinkage estimate has minimal MSE (see below for details). For $\lambda=0$ not shrinkage occur
w
optional: weights for each data point - if not specified uniform weights are assumed (w = rep(1/n, n) with n = dim(x)[1]).
verbose
output status while computing (default: TRUE)

Value

  • invcov.shrink returns the inverse of the output from cov.shrink. invcor.shrink returns the inverse of the output from cor.shrink.

Details

The trick that allows the fast computation of the inverses of the shrinkage covariance and correlation matrices is the Woodbury matrix identity (http://en.wikipedia.org/wiki/Woodbury_matrix_identity).

References

Schaefer, J., and Strimmer, K. (2005). A shrinkage approach to large-scale covariance estimation and implications for functional genomics. Statist. Appl. Genet. Mol. Biol.4:32. (http://www.bepress.com/sagmb/vol4/iss1/art32/)

See Also

cov.shrink, pcor.shrink, cor2pcor

Examples

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

# generate data matrix
p <- 2000
n <- 10
X <- matrix(rnorm(n*p), nrow = n, ncol = p)

lambda <- 0.23  # some arbitrary lambda

# slow
system.time(
  W1 <-  solve(cov.shrink(X, lambda)) 
)

# very fast
system.time(
  W2 <- invcov.shrink(X, lambda)
)

# no difference
sum((W1-W2)^2)

Run the code above in your browser using DataLab