schaferStrimmer_cov | R Documentation |
Computes the Schäfer Strimmer shrinkage estimator for a covariance matrix from a matrix of samples.
schaferStrimmer_cov(x)
x |
matrix of samples with dimensions nxp (n samples, p dimensions). |
This function computes the shrinkage to a diagonal covariance with unequal variances.
Note that here we use the estimators S = X X^T/n
and T = diag(S)
and we internally
use the correlation matrix in place of the covariance to compute the optimal shrinkage factor.
A list containing the shrinkage estimator and the optimal lambda. The list has the following named elements:
shrink_cov
: the shrinked covariance matrix (p
x p
);
lambda_star
: the optimal lambda for the shrinkage;
Schäfer, Juliane, and Korbinian Strimmer. (2005). A Shrinkage Approach to Large-Scale Covariance Matrix Estimation and Implications for Functional Genomics. Statistical Applications in Genetics and Molecular Biology 4: Article32. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2202/1544-6115.1175")}.
# Generate some multivariate normal samples
# Parameters
nSamples <- 200
pTrue <- 2
# True moments
trueSigma <- matrix(c(3,2,2,2), nrow=2)
chol_trueSigma <- chol(trueSigma)
trueMean <- c(0,0)
# Generate samples
set.seed(42)
x <- replicate(nSamples, trueMean) +
t(chol_trueSigma)%*%matrix(stats::rnorm(pTrue*nSamples),
nrow = pTrue, ncol = nSamples)
x <- t(x)
res_shrinkage <- schaferStrimmer_cov(x)
res_shrinkage$lambda_star # should be 0.01287923
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.