sda {sda}R Documentation

Shrinkage discriminant analysis

Description

rda trains a LDA or DDA classifier using Stein-type shrinkage estimation.

predict.sda performs the corresponding class prediction.

Usage

sda(Xtrain, L, diagonal=FALSE, verbose=TRUE)
## S3 method for class 'sda':
predict(object, Xtest, ...)

Arguments

Xtrain A matrix containing the training data set. Note that the rows are sample observations and the columns are variables.
L A factor with the class labels of the traning samples.
diagonal Chooses between LDA (default, diagonal=FALSE) and DDA (diagonal=TRUE).
verbose Report shrinkage intensities.
object An sda fit object obtained from the function sda.
Xtest A matrix containing the test data set..
... Additional arguments for generic predict.

Details

In order to train the LDA or DDA classifier, three separate shrinkage estimators are employed:

class frequencies
the estimator freqs.shrink from Hausser and Strimmer (2008),
variances
the estimator var.shrink from Opgen-Rhein and Strimmer (2007),
correlations
the estimator invcor.shrink from Sch"afer and Strimmer (2005).

These estimates are plugged into the LDA and DDA discriminant function for prediction. Note that the three corresponding regularization parameters are obtained analytically without resorting to computer intensive resampling.

This approach is particularly suited for high-dimensional classification.

Value

sda trains the classifier and returns an sda object with the following components:

regularization a vector containing the three estimated shrinkage intensities,
prior the estimated class frequencies,
means a matrix containing the group means (centroids), and
invcov the inverse of the estimated pooled covariance matrix (this is a matrix in the LDA and a vector in the DDA case).
yhat a factor with the the most likely class assignment, and
probs a matrix containing the class probabilities for each test sample.

Author(s)

Korbinian Strimmer (http://strimmerlab.org).

See Also

freqs.shrink, var.shrink, invcor.shrink.

Examples

library("sda")

## prepare data set
data(iris) # good old iris data
X = as.matrix(iris[,1:4])
Y = iris[,5]

# divide into test and traing data set
tr.index = sample(1:length(Y), 2/3*length(Y))
train.x = X[tr.index,]                     
train.y = Y[tr.index]
test.x = X[-tr.index,] 
test.y = Y[-tr.index]

## shrinkage LDA
sda.fit = sda(Xtrain=train.x, L=train.y)
sda.fit

predict(sda.fit, test.x)

ynew = predict(sda.fit, test.x)$yhat
sum(ynew != test.y)

## shrinkage DDA
sda.fit = sda(Xtrain=train.x, L=train.y, diagonal=TRUE)
sda.fit

predict(sda.fit, test.x)

ynew = predict(sda.fit, test.x)$yhat
sum(ynew != test.y)

[Package sda version 1.0.0 Index]