Learn R Programming

MASSExtra (version 1.2.2)

eigen2: Generalized eigenvalue problem

Description

Solves the generalized eigenvalue problem (B - lambda*W)*alpha = 0, where B and W are symmetric matrices of the same size, W is positive definite, lambda is a scalar and alpha and 0 are vectors.

Usage

eigen2(B, W)

Value

A list with components values and vectors as for eigen

Arguments

B, W

Similarly sized symmetric matrices with W positive definite.

Details

If W is not specified, W = I is assumed.

Examples

Run this code
X <- as.matrix(subset(iris, select = -Species))
W <- crossprod(resid(aov(X ~ Species, iris)))
B <- crossprod(resid(aov(X ~ 1,       iris))) - W
n <- nrow(iris)
p <- length(levels(iris$Species))
(ev <- eigen2(B/(p - 1), W/(n - p)))  ## hand-made discriminant analysis
DF <- X %*% ev$vectors[, 1:2]
with(iris, {
     plot(DF, col = Species, pch = 20,
          xlab = expression(DF[1]), ylab = expression(DF[2]))
     legend("topleft", levels(Species), pch = 20, col = 1:3)
})

Run the code above in your browser using DataLab