% \VignetteIndexEntry{Glass - Comparing methods for discriminant analysis}
% \VignetteDepends{MASS, glmnet, nnet, mboost, party, class, e1071}

\documentclass[a4paper]{article}

\title{Glass - Comparing methods for discriminant analysis}

\begin{document}

\maketitle


<<echo=FALSE,eval=FALSE>>=
options(width=60)
set.seed(6)
@

<<eval=FALSE>>=
library(catdata)
data(glass)
source("disc_comp_roc.r")
@


<<eval=FALSE>>=
table(glass$type)
@

<<eval=FALSE>>=
# Computation with only three response categories:
data(glass)


glass <- glass[glass$type == "type1" | glass$type == "type2" | glass$type == "type7", ]
glass[,10] <- factor(glass[,10], labels = c("type1", "type2", "type7"))
x <- scale(as.matrix(glass[,1:9]), center = T, scale = T)
@
<<results=hide,eval=FALSE>>=
test <- disc.comp(glass$type, x, methods = c("lda", "qda", "rf", "neural", "sv", "knn"), nfold = 5, ntimes = 50)
@

@

<<fig=true,width=10,eval=FALSE>>=
par(cex.lab = 1.5, cex.axis = 1.5, mai = c(0.9,0.9,0.5,0.5))
#misclass error
boxplot(test$lda$misclass, test$qda$misclass, test$rf$misclass, test$neural$misclass, test$sv$misclass, test$knn$misclass, names = c("lda", "qda", "rf", "nnet", "sv", "knn"), main = "")
@

<<fig=true,width=10,eval=FALSE>>=
#squared error
boxplot(test$lda$sqerr, test$qda$sqerr, test$neural$sqerr, test$sv$sqerr, names = c("lda", "qda", "nnet", "sv"), main = "")
@

<<eval=FALSE>>=
# Computation with binary response:
data(glass)


glass <- glass[glass$type == "type1" | glass$type == "type2",]
glass[,10] <- factor(glass[,10],labels=c("type1", "type2"))
x <- scale(as.matrix(glass[,1:9]), center = T, scale = T)
@
<<results=hide,eval=FALSE>>=
test <- disc.comp(glass$type, x, nfold = 5, ntimes = 50)
@

<<fig=true,width=10,eval=FALSE>>=
par(cex.lab = 1.5, cex.axis = 1.5, mai = c(0.9,0.9,0.5,0.5))
roc.curve(test, roc.k = c("lda", "boost", "sv"))
@

<<fig=true,width=10,eval=FALSE>>=
 par(cex.main = 1.5, cex.lab = 1.4, cex.axis = 1.4)
boxplot(test$lda$misclass, test$qda$misclass, test$logistic$misclass, test$rf$misclass, test$boost$misclass, test$neural$misclass, test$sv$misclass, test$knn$misclass, names = c("lda", "qda", "log", "rf", "bst", "nnet", "sv", "knn"), main = "")
@

<<fig=true,width=10,eval=FALSE>>=
boxplot(test$lda$sqerr, test$qda$sqerr, test$logistic$sqerr,  test$boost$sqerr, test$neural$sqerr, test$sv$sqerr,  names = c("lda", "qda", "log",  "boost", "nnet", "sv" ), main = "")
@

\end{document}