library(MASS) # load the MASS library for LDA load('Jussac.RData') # load the observations # Linear Discriminant Analysis Type.lda <- lda(Type~., data=Jussac.learn) LD1 <- Type.lda$scaling[,1] # Axis 1 # Calculate projections onto Axis 1 proj=as.matrix(Jussac.learn[,-7])%*%LD1 # Plot the resulting projections plot(proj,Type=='Chien',xlab='LD1',ylab='Type', col=(Type=='Chien')+1,yaxt="n") axis(2,at=c(0,1),c('Loup','Chien')) # Classification quality CV=lda(Type~., data=Jussac.learn,CV=TRUE) Classe_est=CV$class # Confusion matrix table(Type,Classe_est) # Error rate mean(Classe_est!=Type) # ROC curve Prob=CV$posterior[,1] ROC(Type=='Chien',Prob,plot=TRUE) # Results for Jussac predict(Type.lda,Jussac)$class # Class predict(Type.lda,Jussac)$posterior # Posterior probabilities