fda: Factorial discriminant analysis

View source: R/fda.R

fdaR Documentation

Factorial discriminant analysis

Description

Functions fda and fdasvd fit a factorial discriminant analysis (FDA). The functions maximize the compromise p'Bp / p'Wp, i.e. max p'Bp with constraint p'Wp = 1. Vectors p are the linear discrimant coefficients "LD".

Function fda uses an eigen decomposition of W^(-1)B (if W is singular, W^(-1) can be replaced by a pseudo-inverse, with argument pseudo), and function fdasvd a weighted SVD decomposition of the matrix of the class centers. See the code for details.

Usage


fda(Xr, Yr, Xu = NULL, ncomp = NULL, pseudo = FALSE)

fdasvd(Xr, Yr, Xu = NULL, ncomp = NULL, ...)

Arguments

Xr

A n x p matrix of reference (= training) observations.

Yr

A vector of length n of reference (= training) responses (class membership).

Xu

A m x p matrix or data frame of new (= test) observations to be projected in the calculated reference FDA score space (Xu is not used in the calculation of this score space). Default to NULL.

ncomp

The maximum number of components to consider (ncomp <= min(p, nb. classes - 1)).

pseudo

For function fda. Logical indicating if matrix W has to be inverted by pseudo-inverse. Default to FALSE.

...

For function fdasvd. Optionnal arguments to pass in function pca.

Value

A list of outputs (see examples), such as:

Tr

The Xr-score matrix (n x ncomp).

Tu

The Xu-score matrix (m x ncomp).

Tcenters

The Xr-class centers score matrix (nb. classes x ncomp).

P

The Xr-loadings matrix (p x ncomp). Coefficients of linear discriminants: P = "LD" of lda of package MASS.

explvar

Proportions of explained variance by PCA of the class centers in transformed scale.

And other outputs ("z" outputs relate on transformed data; see the code).

References

Saporta G., 2011. Probabilités analyse des données et statistique. Editions Technip, Paris, France.

Examples


data(iris)

Xr <- iris[, 1:4]
yr <- iris[, 5]

fm <- fda(Xr, yr)
names(fm)

# Xr-scores
headm(fm$Tr)

# Xr-class centers scores
fm$Tcenters

# Xr-loadings matrix
# = coefficients of linear discriminants
# = "LD" of function lda of MASS package
fm$P

# Explained variance by PCA of the class centers 
# in transformed scale
fm$explvar

plotxy(fm$Tr, group = yr, ellipse = TRUE)
points(fm$Tc, pch = 8, col = "blue")

# Object Tcenters is the projection of the class centers in the score space
fm <- fda(Xr, yr)
fm$Tcenters
centers <- centr(Xr, yr)$centers
centers
fm <- fda(Xr, yr, centers)
fm$Tu


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.