attach(olives) library(MASS) plot(palmitoleic, oleic, col=Region) plot.contours2d(palmitoleic[Region==1], oleic[Region==1], clevels=0.95, label=F) plot.contours2d(palmitoleic[Region==2], oleic[Region==2], clevels=0.95, label=F) plot.contours2d(palmitoleic[Region==3], oleic[Region==3], clevels=0.95, label=F) ### # # Generate Grid for Prediction rast.x<- rep(seq(min(palmitoleic), max(palmitoleic),length=75), 75) rast.y<- rep(seq(min(oleic), max(oleic), length=75), rep(75, 75)) ### # # 1. LDA o.lda <- lda( cbind(palmitoleic, oleic), Region ) table(predict(o.lda, cbind(palmitoleic, oleic))$class, Region) sum(diag(as.matrix(table(predict(o.lda, cbind(palmitoleic, oleic))$class, Region))))/length(Region) pred<-predict(o.lda, cbind(rast.x, rast.y)) col<-unclass(pred$class) points(rast.x, rast.y, col=col, pch="+") ### # # 2. QDA o.qda <- qda( cbind(palmitoleic, oleic), Region ) table(predict(o.qda, cbind(palmitoleic, oleic))$class, Region) sum(diag(as.matrix(table(predict(o.qda, cbind(palmitoleic, oleic))$class, Region))))/length(Region) pred<-predict(o.qda, cbind(rast.x, rast.y)) col<-unclass(pred$class) points(rast.x, rast.y, col=col, pch="+")