| cov_eigen {sparsediscrim} | R Documentation |
Computes the eigenvalue decomposition of the maximum likelihood estimators (MLE) of the covariance matrices for the given data matrix
Description
For the classes given in the vector y, we compute the eigenvalue
(spectral) decomposition of the class sample covariance matrices (MLEs) using
the data matrix x.
Usage
cov_eigen(x, y, pool = FALSE, fast = FALSE, tol = 1e-06)
Arguments
x |
data matrix with |
y |
class labels for observations (rows) in |
pool |
logical. Should the sample covariance matrices be pooled? |
fast |
logical. Should the Fast SVD be used? See details. |
tol |
tolerance value below which the singular values of |
Details
If the fast argument is selected, we utilize the so-called Fast
Singular Value Decomposition (SVD) to quickly compute the eigenvalue
decomposition. To compute the Fast SVD, we use the corpcor::fast.svd()
function, which employs a well-known trick for tall data (large n,
small p) and wide data (large p, small n) to compute the
SVD corresponding to the nonzero singular values. For more information about
the Fast SVD, see corpcor::fast.svd().
Value
a list containing the eigendecomposition for each class. If
pool = TRUE, then a single list is returned.
Examples
cov_eigen(x = iris[, -5], y = iris[, 5])
cov_eigen(x = iris[, -5], y = iris[, 5], pool = TRUE)
cov_eigen(x = iris[, -5], y = iris[, 5], pool = TRUE, fast = TRUE)
# Generates a data set having fewer observations than features.
# We apply the Fast SVD to compute the eigendecomposition corresponding to the
# nonzero eigenvalues of the covariance matrices.
set.seed(42)
n <- 5
p <- 20
num_classes <- 3
x <- lapply(seq_len(num_classes), function(k) {
replicate(p, rnorm(n, mean = k))
})
x <- do.call(rbind, x)
colnames(x) <- paste0("x", 1:ncol(x))
y <- gl(num_classes, n)
cov_eigen(x = x, y = y, fast = TRUE)
cov_eigen(x = x, y = y, pool = TRUE, fast = TRUE)