taShrink: Bayesian Target-Averaged linear Shrinkage (TAS) covariance...

Description Usage Arguments Value References Examples

View source: R/taShrink.R

Description

Implements a Bayesian target-averaged linear shrinkage covariance estimator as in Gray et al. (2018). It is most useful when the observed data is high-dimensional (more variables than observations) and there are other datasets that can be used to include as prior data-driven targets to shrink towards.

Usage

1
2
3
4
5
6
7
8
taShrink(
  X,
  targets = "default",
  without = 0,
  alpha = seq(0.01, 0.99, 0.01),
  plots = TRUE,
  ext.data = FALSE
)

Arguments

X

matrix – data matrix with variables in rows and observations in columns. This method performs best when there are more variables than observations.

targets

character or array – "default" creates a target set of common literature targets, or the user may specify an array of targets to use, e.g. ones that have been derived from external data. All targets must be real symmetric positive definite matrices.

without

list – if targets=="default" then this indicates which of the default targets should be excluded from shrinkage. This can be useful when exploring the shrinkage behaviour with a subset of targets (e.g. through simulation).

alpha

list – the grid of shrinkage intensities in (0, 1) to be used. Recommended to be an equidistant grid that covers the whole interval. A short comparison of estimation accuracy versus granularity is provided in ...

plots

logical – if TRUE then create a barplot of the target-specific shrinkage weights. Recommend option FALSE if using many iterations.

ext.data

matrix – an external data matrix used a surrogate to estimate the parameters in the default target set for X. Never recommended unless there is a belief that ext.data is informative of the covariances of X.

Value

list

sigmahat

matrix – the estimated covariance matrix.

targets

array – the targets used for shrinkage.

weights

matrix – the weight of each (target, alpha) pair such that sum(weights)=1. The weights are calculated by normalising the log-marginal likelihood values below.

logmarginals

matrix – the values of the log marginal likelihood for each (target, alpha) pair.

alpha

list – the values of shrinkage intensities used.

References

Gray, H., Leday, G.G.R., Vallejos, C.A. and Richardson, S., 2018. Shrinkage estimation of large covariance matrices using multiple shrinkage targets. arXiv preprint.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
set.seed(101)
X <- matrix(rnorm(50), 10, 5) # p=10, n=5, identity covariance
X <- t(scale(t(X), center=TRUE, scale=FALSE)) # mean 0
tas <- taShrink(X, plots = FALSE) # apply shrinkage and view target weight bar plot
barplot(targetWeights(tas), names.arg = c(1:9, "S"),
main = "Target-specific shrinkage weights",
col = rainbow(dim(tas$targets)[3]+1), space = 0,
xlab = "Target", ylab = "Weight")
abs(tas$sigmahat - diag(10)) # inspect absolute differences
norm(tas$sigmahat-diag(10), type="F") # calculate loss
# compare this to each single target
norm(gcShrink(X, var=1, cor=1)$sigmahat-diag(10), type="F")
norm(gcShrink(X, var=2, cor=1)$sigmahat-diag(10), type="F")
norm(gcShrink(X, var=3, cor=1)$sigmahat-diag(10), type="F")
norm(gcShrink(X, var=1, cor=2)$sigmahat-diag(10), type="F")
norm(gcShrink(X, var=2, cor=2)$sigmahat-diag(10), type="F")
norm(gcShrink(X, var=3, cor=2)$sigmahat-diag(10), type="F")
norm(gcShrink(X, var=1, cor=3)$sigmahat-diag(10), type="F")
norm(gcShrink(X, var=2, cor=3)$sigmahat-diag(10), type="F")
norm(gcShrink(X, var=3, cor=3)$sigmahat-diag(10), type="F")

HGray384/TAS documentation built on Dec. 14, 2020, 8:41 p.m.