# 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