dadis: DA using the dissimilarity to class centers

View source: R/dadis.R

dadisR Documentation

DA using the dissimilarity to class centers

Description

Discriminant analysis using the dissimilarities (e.g. Euclidean or Mahalanobis distances) to the class centers.

For each observation to predict, the function calculates the dissimilarity between this observation and each of the class centers of the reference (= training) data. The final predicted class corresponds to the class for which the dissimilarity is the lowest.

Usage

dadis(Xr, Yr, Xu, Yu = NULL,
  diss = c("euclidean", "mahalanobis", "correlation"), sigma = NULL)

Arguments

Xr

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

Yr

A vector of length n, or a n x 1 matrix, of reference (= training) responses (class membership).

Xu

A m x p matrix or data frame of new (= test) observations to be predicted.

Yu

A vector of length m, or a m x 1 matrix, of the true response (class membership). Default to NULL.

diss

Type of dissimilarity used. Possible values are "euclidean" (Euclidean distances; default), "mahalanobis" (Mahalanobis distances), or "correlation" (correlation dissimilarities, calculated by sqrt(.5 * (1 - rho)) where rho is the correlation coefficient).

sigma

The covariance matrix (weight matrix) used for the Mahalanobis distance. If NULL (default), this is the average 'Within' covariance matrix (W) calculated by function matW for each class.

Value

A list of outputs, such as:

y

Responses for the test data.

fit

Predictions for the test data.

r

Residuals for the test data.

Examples


data(iris)

X <- iris[, 1:4]
y <- iris[, 5]
N <- nrow(X)

m <- round(.25 * N) 
n <- N - m          
s <- sample(1:N, m)
Xr <- X[-s, ]
yr <- y[-s]
Xu <- X[s, ]
yu <- y[s]

fm <- dadis(Xr, yr, Xu, yu)
names(fm)
headm(fm$y)
headm(fm$fit)
headm(fm$r)
fm$ni

err(fm)

fm <- dadis(Xr, yr, Xu, yu, diss = "mahalanobis")
err(fm)

nclas <- length(unique(yr))
W <- matW(Xr, yr)$W * n / (n - nclas)
fm <- dadis(Xr, yr, Xu, yu, diss = "mahalanobis", sigma = W)
err(fm)


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