# Internal Documentation

Documentation for `CovarianceEstimation.jl`

's internal methods.

See Public Documentation for public package docs.

## Contents

## Index

`CovarianceEstimation.analytical_nonlinear_shrinkage`

`CovarianceEstimation.epanechnikov`

`CovarianceEstimation.epanechnikov_HT1`

`CovarianceEstimation.epanechnikov_HT2`

`CovarianceEstimation.linear_shrinkage`

`CovarianceEstimation.rescale`

`CovarianceEstimation.rescale!`

`CovarianceEstimation.sum_fij`

`CovarianceEstimation.sumij`

`CovarianceEstimation.sumij2`

`CovarianceEstimation.uccov`

## Internals

`CovarianceEstimation.epanechnikov`

— Function`epanechnikov(x)`

Return the Epanechnikov kernel evaluated at `x`

.

`CovarianceEstimation.epanechnikov_HT1`

— Function`epnanechnikov_HT(x)`

Return the Hilbert Transform of the Epanechnikov kernel evaluated at `x`

if `|x|≂̸√5`

.

`CovarianceEstimation.epanechnikov_HT2`

— Function`epnanechnikov_HT2(x)`

Return the Hilbert Transform of the Epanechnikov kernel evaluated at `x`

if `|x|=√5`

.

`CovarianceEstimation.rescale`

— Function`rescale(M, d)`

Internal function to scale the rows and the columns of a square matrix `M`

according to the elements in `d`

. This is useful when dealing with the standardised data matrix which can be written `Xs=Xc*D`

where `Xc`

is the centered data matrix and `D=Diagonal(d)`

so that its simple covariance is `D*S*D`

where `S`

is the simple covariance of `Xc`

. Such `D*M*D`

terms appear often in the computations of optimal shrinkage λ.

- Space complexity: $O(p^2)$
- Time complexity: $O(p^2)$

`CovarianceEstimation.rescale!`

— Function`rescale!(M, d)`

Same as `rescale`

but in place (no allocation).

`CovarianceEstimation.uccov`

— Function`uccov(X)`

Internal function to compute `X*X'/n`

where `n`

is the number of rows of `X`

. This corresponds to the uncorrected covariance of `X`

if `X`

is centered. This operation appears often in the computations of optimal shrinkage λ.

- Space complexity: $O(p^2)$
- Time complexity: $O(2np^2)$

`CovarianceEstimation.sumij`

— Function`sumij(S)`

Internal function to compute the sum of elements of a square matrix `S`

. A keyword `with_diag`

can be passed to indicate whether to include or not the diagonal of `S`

in the sum. Both cases happen often in the computations of optimal shrinkage λ.

- Space complexity: $O(1)$
- Time complexity: $O(p^2)$

`CovarianceEstimation.sumij2`

— Function`sumij2(S)`

Internal function identical to `sumij`

except that it passes the function `abs2`

to the sum so that it is the sum of the elements of `S`

squared which is computed. This is significantly more efficient than using `sumij(S.^2)`

for large matrices as it allocates very little.

- Space complexity: $O(1)$
- Time complexity: $O(2p^2)$

`CovarianceEstimation.sum_fij`

— Function`sum_fij(Xc, S, n, κ)`

Internal function corresponding to $∑_{i≂̸j}f_{ij}$ that appears in https://strimmerlab.github.io/publications/journals/shrinkcov2005.pdf p.11.

- Space complexity: $O(np + 2p^2)$
- Time complexity: $O(2np^2)$

`CovarianceEstimation.linear_shrinkage`

— Function`linear_shrinkage(target, Xc, S, λ, n, p, pvar, corrected, [weights])`

Performs linear shrinkage with target of type `target`

for data matrix `Xc`

of size `n`

by `p`

with covariance matrix `S`

and shrinkage parameter `λ`

. Calculates corrected covariance if `corrected`

is true.

`pvar == p`

or `pvar = p - sum(iszero, diag(S))`

, the number of non-zero diagonal variances in `S`

. The choice is controlled by `LinearShrinkage(...; drop_var0=true/false)`

.

`CovarianceEstimation.analytical_nonlinear_shrinkage`

— Function`analytical_nonlinear_shrinkage(S, n, p; decomp)`

Internal implementation of the analytical nonlinear shrinkage. The implementation is inspired from the Matlab code given in section C of Olivier Ledoit and Michael Wolf's paper "Analytical Nonlinear Shrinkage of Large-Dimensional Covariance Matrices". (Nov 2018) http://www.econ.uzh.ch/static/wp/econwp264.pdf