Learn R Programming

sda (version 1.0.2)

sda: 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, feature.idx, verbose=TRUE, ...)

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 training samples.
diagonal
Chooses between LDA (default, diagonal=FALSE) and DDA (diagonal=TRUE).
verbose
Report shrinkage intensities (sda) and number of used features (predict.sda).
object
An sda fit object obtained from the function sda.
Xtest
A matrix containing the test data set.
feature.idx
A vector indicating which features to employ for prediction (if unspecified all features will be used).
...
Additional arguments for generic predict.

Value

  • sda trains the classifier and returns an sda object with the following components needed for the subsequent prediction:
  • regularizationa vector containing the three estimated shrinkage intensities,
  • priorthe estimated class frequencies,
  • refmatrix containing the reference centroids,
  • coefmatrix containing the coefficients used for prediction, and
  • catmatrix containing the ``correlation-adjusted t scores'' for each feature and group.
  • predict.sda predicts class probabilities for each test sample and returns a list with two components:
  • classa factor with the most probable class assignment, and
  • posteriora matrix containing the class posterior probabilities for each test sample.

Details

The SDA approach is particularly suited for high-dimensional classification.

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.

See Also

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

Examples

Run this code
# load sda library
library("sda")

# load full Khan et al (2001) data set
data(khan2001)
dim(khan2001$x)
levels(khan2001$y)

# create data set containing only the SRBCT samples
del.idx = which( khan2001$y == "non-SRBCT" )
srbct.x = khan2001$x[-del.idx,]
srbct.y = factor(khan2001$y[-del.idx])
dim(srbct.x)
levels(srbct.y)

# divide into training and test data
train.x = srbct.x[1:63,]
train.y = srbct.y[1:63]
test.x = srbct.x[64:83,]
test.y = srbct.y[64:83]

# classification with correlation (shrinkage LDA)
sda.fit = sda(train.x, train.y)
ynew = predict(sda.fit, test.x)$class
sum(ynew != test.y) # 0

# classification with diagonal covariance (shrinkage DDA)
sda.fit = sda(train.x, train.y, diagonal=TRUE)
ynew = predict(sda.fit, test.x)$class
sum(ynew != test.y) # 4

Run the code above in your browser using DataLab