# shrink.intensity: Estimation of Shrinkage Intensities In corpcor: Efficient Estimation of Covariance and (Partial) Correlation

## Description

The functions `estimate.lambda` and `estimate.lambda.var` shrinkage intensities used for correlations and variances used in `cor.shrink` and `var.shrink`, respectively.

## Usage

 ```1 2``` ```estimate.lambda(x, w, verbose=TRUE) estimate.lambda.var(x, w, verbose=TRUE) ```

## Arguments

 `x` a data matrix `w` optional: weights for each data point - if not specified uniform weights are assumed (`w = rep(1/n, n)` with `n = nrow(x)`). `verbose` report shrinkage intensities (default: TRUE)

## Details

`var.shrink` computes the empirical variance of each considered random variable, and shrinks them towards their median. The corresponding shrinkage intensity `lambda.var` is estimated using

λ_{var}^{*} = ( ∑_{k=1}^p Var(s_{kk}) )/ ∑_{k=1}^p (s_{kk} - median(s))^2

where median(s) denotes the median of the empirical variances (see Opgen-Rhein and Strimmer 2007).

Similarly, `cor.shrink` computes a shrinkage estimate of the correlation matrix by shrinking the empirical correlations towards the identity matrix. In this case the shrinkage intensity `lambda` equals

λ^{*} = ∑_{k \neq l} Var(r_{kl}) / ∑_{k \neq l} r_{kl}^2

(Sch\"afer and Strimmer 2005).

Ahdesm\"aki suggested (2012) a computationally highly efficient algorithm to compute the shrinkage intensity estimate for the correlation matrix (see the R code for the implementation).

## Value

`estimate.lambda` and `estimate.lambda.var` returns a number between 0 and 1.

## Author(s)

Juliane Sch\"afer, Rainer Opgen-Rhein, Miika Ahdesm\"aki and Korbinian Strimmer (http://strimmerlab.org).

## References

Opgen-Rhein, R., and K. Strimmer. 2007. Accurate ranking of differentially expressed genes by a distribution-free shrinkage approach. Statist. Appl. Genet. Mol. Biol. 6:9. <DOI:10.2202/1544-6115.1252>

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>

`cor.shrink`, `var.shrink`.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26``` ```# 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 # correlation shrinkage intensity estimate.lambda(X) c = cor.shrink(X) attr(c, "lambda") # variance shrinkage intensity estimate.lambda.var(X) v = var.shrink(X) attr(v, "lambda.var") ```