View source: R/relative_eigen.R
relative_eigen | R Documentation |
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.
relative_eigen(
XA,
XB,
ncomp = NULL,
preproc = center(),
reg_param = 1e-05,
threshold = 2000,
...
)
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 |
preproc |
A pre-processing pipeline created with |
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. |
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
.
A bi_projector
object containing the components, scores, and other relevant information.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.