# linear discriminant analysi d<-read.table("ExamA.dat") a<-rbind(d[1:200,],d[1001:1200,]) names(a)<-c("x1","x2","y") x1.max <- max(a$x1) x1.min <- min(a$x1) x2.max <- max(a$x2) x2.min <- min(a$x2) x1.lim = c(x1.min,x1.max) x2.lim = c(x2.min,x2.max) x<-seq(x1.min, x1.max, 0.5) y<-seq(x2.min, x2.max, 0.5) Xcon <- data.frame(rep(x,length(y)), rep(y, each=length(x))) names(Xcon) <- c("x1","x2") plot(a$x1,a$x2, xlim=x1.lim, ylim=x2.lim, col=a$y+1) g <- lda( y ~ x1 + x2 , data = a) Z <- predict(g, Xcon) zp <- Z$post[,1] - Z$post[,2] contour(x,y,matrix(zp,length(x),length(y)), add=T, levels=0, labex = 0) title("LDA compared to Logistic Regression") g.g <- glm( y ~ x1 + x2, data = a, family=binomial(logit)) Z.g <- predict(g.g, Xcon) contour(x,y,matrix(Z.g,length(x),length(y)), add=T, lty=2, levels=0.5, labex = 0)