Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/shrink.estimates.R
The functions invcov.shrink
and invcor.shrink
implement an
algorithm to efficiently compute
the inverses of shrinkage estimates of covariance (cov.shrink
)
and correlation (cor.shrink
).
1 2 | invcov.shrink(x, lambda, lambda.var, w, verbose=TRUE)
invcor.shrink(x, lambda, w, verbose=TRUE)
|
x |
a data matrix |
lambda |
the correlation shrinkage intensity (range 0-1).
If |
lambda.var |
the variance shrinkage intensity (range 0-1).
If |
w |
optional: weights for each data point - if not specified uniform weights are assumed
( |
verbose |
output status while computing (default: TRUE) |
Both invcov.shrink
and invcor.shrink
rely on
powcor.shrink
. This allows to compute the inverses in
a very efficient fashion (much more efficient than directly inverting
the matrices - see the example).
invcov.shrink
returns the inverse of the output from cov.shrink
.
invcor.shrink
returns the inverse of the output from cor.shrink
.
Juliane Sch\"afer and Korbinian Strimmer (https://strimmerlab.github.io).
Sch\"afer, J., and K. Strimmer. 2005. A shrinkage approach to large-scale covariance estimation and implications for functional genomics. Statist. Appl. Genet. Mol. Biol. 4:32. <DOI:10.2202/1544-6115.1175>
powcor.shrink
, cov.shrink
, pcor.shrink
, cor2pcor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # load corpcor library
library("corpcor")
# generate data matrix
p = 500
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)
|
Estimating optimal shrinkage intensity lambda.var (variance vector): 0.8164
Specified shrinkage intensity lambda (correlation matrix): 0.23
user system elapsed
0.127 0.009 0.138
Estimating optimal shrinkage intensity lambda.var (variance vector): 0.8164
Specified shrinkage intensity lambda (correlation matrix): 0.23
user system elapsed
0.061 0.004 0.064
[1] 3.909542e-25
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.