# Create the class 0 density den0 <- dmvnorm(x.grid,mu0,Sigma) # Plot its contours (6 of them) contour(unique(x1.grid),unique(x2.grid),matrix(den0,40,48),nlevels=6,col='red') # identify the mean as 0 points(mu0[1],mu0[2], pch="0") # Repeat for the class 1 density den1 <- dmvnorm(x.grid,mu1,Sigma) # The following ensures that the drawing occurs as if the existing plot # were `new'. Otherwise the existing plot would be wiped clean before # adding the rest. par(new=T) contour(unique(x1.grid),unique(x2.grid),matrix(den1,40,48),nlevels=6,col='blue') points(mu1[1],mu1[2], pch="1") edecomp <- eigen(Sigma,symmetric=TRUE) evectors <- edecomp$vectors evalues <- edecomp$values o1 <- evectors[,1] o2 <- evectors[,2] b0 <- ((o1[1]*mu0[2]) - (mu0[1]*o1[2]))/o1[1] m0 <- o1[2]/o1[1] abline(coef=c(b0,m0)) b1 <- ((o1[1]*mu1[2]) - (mu1[1]*o1[2]))/o1[1] m1 <- o1[2]/o1[1] abline(coef=c(b1,m1)) b0 <- ((o2[1]*mu0[2]) - (mu0[1]*o2[2]))/o2[1] m0 <- o2[2]/o2[1] abline(coef=c(b0,m0)) b1 <- ((o2[1]*mu1[2]) - (mu1[1]*o2[2]))/o2[1] m1 <- o2[2]/o2[1] abline(coef=c(b1,m1))