relative_eigen: Relative Eigenanalysis with Ecosystem Integration

View source: R/relative_eigen.R

relative_eigenR Documentation

Relative Eigenanalysis with Ecosystem Integration

Description

Perform a relative eigenanalysis between two groups, fully integrated with the pre-processing and projector ecosystem. The function computes the directions that maximize the variance ratio between two groups and returns a bi_projector object.

Usage

relative_eigen(
  XA,
  XB,
  ncomp = NULL,
  preproc = center(),
  reg_param = 1e-05,
  threshold = 2000,
  ...
)

Arguments

XA

A numeric matrix or data frame of observations for group A (n_A x p).

XB

A numeric matrix or data frame of observations for group B (n_B x p).

ncomp

The number of components to compute. If NULL (default), computes up to min(n_A, n_B, p) - 1.

preproc

A pre-processing pipeline created with prepper(). Defaults to center().

reg_param

A small regularization parameter to ensure numerical stability. Defaults to 1e-5.

threshold

An integer specifying the dimension threshold to switch between direct and iterative solvers. Defaults to 2000.

...

Additional arguments passed to lower-level functions.

Details

This function computes the leading eigenvalues and eigenvectors of the generalized eigenvalue problem \Sigma_A v = \lambda \Sigma_B v, fully integrated with the pre-processing ecosystem. It uses a direct solver when the number of variables p is less than or equal to threshold, and switches to an iterative method when p is greater than threshold.

Value

A bi_projector object containing the components, scores, and other relevant information.

Examples

# Simulate data for two groups
set.seed(123)
n_A <- 100
n_B <- 80
p <- 500  # Number of variables
XA <- matrix(rnorm(n_A * p), nrow = n_A, ncol = p)
XB <- matrix(rnorm(n_B * p), nrow = n_B, ncol = p)
# Perform relative eigenanalysis
res <- relative_eigen(XA, XB, ncomp = 5)

bbuchsbaum/multivarious documentation built on Dec. 23, 2024, 7:47 a.m.