shrinkage_da: Shrinkage Discriminant Analysis

View source: R/shrinkda.R

shrinkage_daR Documentation

Shrinkage Discriminant Analysis

Description

This function provides a shrinkage-based discriminant analysis using the sda routine from the corpcor package. The method can regularize (shrink) the discriminant directions for high-dimensional data, potentially improving robustness and reducing overfitting.

Usage

shrinkage_da(
  X,
  Y,
  preproc = center(),
  lambda,
  lambda.var,
  lambda.freqs,
  diagonal = FALSE,
  verbose = FALSE
)

Arguments

X

A numeric matrix of size n \times d (samples by features).

Y

A factor or numeric vector of length n representing class labels. If numeric, it will be converted to a factor.

preproc

A pre-processing function or object from multivarious (e.g. center, scale), applied to X before shrinkage DA. Defaults to center.

lambda

Regularization parameter for the sda function (shrinkage of the discriminant directions). Typically in [0, 1].

lambda.var

Regularization parameter for the variance (covariance) terms, passed to sda.

lambda.freqs

Regularization parameter for class frequency shrinkage, passed to sda.

diagonal

Logical, if TRUE, the method restricts the covariance matrix to be diagonal. Defaults to FALSE.

verbose

Logical, if TRUE, prints progress messages from sda. Defaults to FALSE.

Details

Internally, the function:

  1. Preprocesses X using preproc.

  2. Calls sda with the specified lambda, lambda.var, lambda.freqs, etc.

  3. Extracts ret\$beta (the discriminant directions) and ret\$alpha (the intercept).

  4. Projects the preprocessed data to obtain the score matrix s.

  5. Constructs a discriminant_projector object with class "shrinkda".

Value

A discriminant_projector object (subclass "shrinkda") containing:

  • v : A d \times m matrix of discriminant directions (ret\$beta transposed).

  • s : An n \times m matrix of projected scores (the original data in the shrinkage discriminant space).

  • sdev : Standard deviations of each column in s.

  • labels : The class labels (in character form).

  • alpha : Intercept or offset term from sda result (if any).

  • preproc : The pre-processing object used.

  • classes : Includes the string "shrinkda".

See Also

sda, discriminant_projector

Examples

## Not run: 
library(multivarious)
data(iris)
X <- as.matrix(iris[, 1:4])
Y <- iris[, 5]

# Perform shrinkage DA with default centering
res <- shrinkage_da(X, Y, lambda=0.5)

# Inspect the projector
print(res)

# Project new data
# new_data <- ...
# projected_scores <- project(res, new_data)

## End(Not run)

bbuchsbaum/discursive documentation built on April 14, 2025, 4:57 p.m.