#  This file  contains the Gauss2 code from Will Welch's notes Chapt. 1
#      
#  Authors:
#       W.J. Welch, 2002
#       R.W. Oldford, 2004
#
#

# just a handy function to capture the pathname for the files we will load.
web441 <- function(x)
         {paste('http://www.undergrad.math.uwaterloo.ca/~stat441/R-code/',
                 x,
                 sep='')
         }

# get code for creating densities  
# (in class we just loaded this file since the 
#  machine wasn't connected to the internet).
source(web441('Gauss2.R'))
# Plot the training data
 plot(0,0,xlim=c(0,8),ylim=c(0,15),xlab="x1",ylab="x2",type="n")
 points(Gauss2.train[Gauss2.train[,"y"] == 0, c("x1","x2")], pch="0")
 points(Gauss2.train[Gauss2.train[,"y"] == 1, c("x1","x2")], pch="+")


# Plot the test data
 points(Gauss2.test[, c("x1","x2")], pch="?")

library(MASS)
Gauss2.lda <- lda(y ~ x1 + x2 +x1*x2, data = Gauss2.train)

Gauss2.pred <- predict(Gauss2.lda, Gauss2.test)