ArcLakeGroupSummary <- read_excel("~/Desktop/EPSRC Project /ArcLakeGroupSummary.xlsx")


Data1<-ArcLakeGroupSummary[, c( 3, 4, 5, 11, 12)]
Data1$Group<-factor(Data1$Group)


PC.Data <- ArcLakeGroupSummary[, c( 3, 11, 12)]
PC.Data$Group<-factor(PC.Data$Group)

1 Maps

1.1 Actual Map

mp1 <- NULL
mapWorld <- borders("world", colour="gray50", fill="gray50") # create a layer of borders
mp1 <- ggplot() +   mapWorld

mp1 <- mp1 + geom_point(data = Data1, mapping = aes(x=Longitude, y=Latitude, color = Group), size = 4, shape = 1) +
  labs(colour = "Class", title="Actual Map") +
  xlab("Longitude") + 
  ylab("Latitude")
  

mp1

1.2 QDA Map

qdafit<-qda(Group ~ PC1+PC2, data = PC.Data)

qda.y<-PC.Data$Group # This is the training error
qda.predy<-predict(qdafit, PC.Data)$class # This is the training error

qdafit
## Call:
## qda(Group ~ PC1 + PC2, data = PC.Data)
## 
## Prior probabilities of groups:
##          1          2          3          4          5          6 
## 0.07513661 0.05874317 0.10792350 0.16530055 0.33333333 0.05737705 
##          7          8          9 
## 0.02595628 0.03961749 0.13661202 
## 
## Group means:
##         PC1         PC2
## 1  23.66381  26.2872858
## 2  66.50153  26.5181533
## 3 124.82346  -0.5058272
## 4 -57.09390 -21.5758004
## 5 -42.14542   6.8994269
## 6  96.28750 -25.2998674
## 7 -12.99238 -62.4515947
## 8  41.41366 -56.0352703
## 9 -18.28499  22.5528829
mean(qda.y!=qda.predy) # This is the training error
## [1] 0.03961749
table(qda.y, qda.predy)
##      qda.predy
## qda.y   1   2   3   4   5   6   7   8   9
##     1  54   0   0   0   0   0   0   0   1
##     2   1  42   0   0   0   0   0   0   0
##     3   0   0  79   0   0   0   0   0   0
##     4   0   0   0 115   6   0   0   0   0
##     5   0   0   0   6 232   0   0   0   6
##     6   0   0   0   0   0  42   0   0   0
##     7   0   0   0   0   0   0  18   1   0
##     8   0   0   0   0   0   0   0  29   0
##     9   1   0   0   0   7   0   0   0  92
QDA.Map.Pred <- cbind(Data1, qda.predy)

Correct.QDA.Map.Pred<-QDA.Map.Pred[ QDA.Map.Pred$Group==QDA.Map.Pred$qda.predy,]
Wrong.QDA.Map.Pred<-QDA.Map.Pred[ QDA.Map.Pred$Group!=QDA.Map.Pred$qda.predy,]

mp2 <- NULL
mapWorld <- borders("world", colour="gray50", fill="gray50") # create a layer of borders
mp2 <- ggplot() +   mapWorld

mp2 <- mp2 + geom_point(data = Correct.QDA.Map.Pred, mapping = aes(x=Longitude, y=Latitude, color = qda.predy), size = 4, shape = 1) + 
  geom_point(data = Wrong.QDA.Map.Pred, mapping = aes(x=Longitude, y=Latitude, color = qda.predy), size = 4) +
  labs(colour = "Class", title="96.04% Correctly Classified QDA Map") +
  xlab("Longitude") + 
  ylab("Latitude")
  

mp2 

QDA.Map.Pred <- cbind(Data1, qda.predy)

Correct.QDA.Map.Pred<-QDA.Map.Pred[ QDA.Map.Pred$Group==QDA.Map.Pred$qda.predy,]
Wrong.QDA.Map.Pred<-QDA.Map.Pred[ QDA.Map.Pred$Group!=QDA.Map.Pred$qda.predy,]

mp3 <- NULL
mapWorld <- borders("world", colour="gray50", fill="gray50") # create a layer of borders
mp3 <- ggplot() +   mapWorld

mp3 <- mp3 + geom_point(data = Correct.QDA.Map.Pred, mapping = aes(x=Longitude, y=Latitude, color = qda.predy), size = 4, shape = 1) + 
  geom_point(data = Wrong.QDA.Map.Pred, mapping = aes(x=Longitude, y=Latitude), color = "black", shape = 4, size = 4) +
  labs(colour = "Class", title="96.04% Correctly Classified QDA Map") +
  xlab("Longitude") + 
  ylab("Latitude")
  

mp3 

1.3 SVM Radial Map

svmfit<-svm(Group ~ PC1+PC2, data = PC.Data, kernel="radial", cost = 1538065, gamma = 0.02650774)

svm.y<-PC.Data$Group # This is the training error
svm.predy<-predict(svmfit, PC.Data) # This is the training error

svmfit
## 
## Call:
## svm(formula = Group ~ PC1 + PC2, data = PC.Data, kernel = "radial", 
##     cost = 1538065, gamma = 0.02650774)
## 
## 
## Parameters:
##    SVM-Type:  C-classification 
##  SVM-Kernel:  radial 
##        cost:  1538065 
##       gamma:  0.02650774 
## 
## Number of Support Vectors:  73
mean(svm.y!=svm.predy) # This is the training error
## [1] 0.009562842
table(svm.y, svm.predy)
##      svm.predy
## svm.y   1   2   3   4   5   6   7   8   9
##     1  55   0   0   0   0   0   0   0   0
##     2   0  43   0   0   0   0   0   0   0
##     3   0   0  79   0   0   0   0   0   0
##     4   0   0   0 117   4   0   0   0   0
##     5   0   0   0   1 241   0   0   0   2
##     6   0   0   0   0   0  42   0   0   0
##     7   0   0   0   0   0   0  19   0   0
##     8   0   0   0   0   0   0   0  29   0
##     9   0   0   0   0   0   0   0   0 100
SVM.Map.Pred <- cbind(Data1, svm.predy)

Correct.SVM.Map.Pred<-SVM.Map.Pred[ SVM.Map.Pred$Group==SVM.Map.Pred$svm.predy,]
Wrong.SVM.Map.Pred<-SVM.Map.Pred[ SVM.Map.Pred$Group!=SVM.Map.Pred$svm.predy,]

mp4 <- NULL
mapWorld <- borders("world", colour="gray50", fill="gray50") # create a layer of borders
mp4 <- ggplot() +   mapWorld

mp4 <- mp4 + geom_point(data = Correct.SVM.Map.Pred, mapping = aes(x=Longitude, y=Latitude, color = svm.predy), size = 4, shape = 1) +
  geom_point(data = Wrong.SVM.Map.Pred, mapping = aes(x=Longitude, y=Latitude, color = svm.predy), size = 4) +
  labs(colour = "Class", title="99.04% Correctly Classified SVM Radial Map") +
  xlab("Longitude") + 
  ylab("Latitude")
  

mp4 

SVM.Map.Pred <- cbind(Data1, svm.predy)

Correct.SVM.Map.Pred<-SVM.Map.Pred[ SVM.Map.Pred$Group==SVM.Map.Pred$svm.predy,]
Wrong.SVM.Map.Pred<-SVM.Map.Pred[ SVM.Map.Pred$Group!=SVM.Map.Pred$svm.predy,]

mp5 <- NULL
mapWorld <- borders("world", colour="gray50", fill="gray50") # create a layer of borders
mp5 <- ggplot() +   mapWorld

mp5 <- mp5 + geom_point(data = Correct.SVM.Map.Pred, mapping = aes(x=Longitude, y=Latitude, color = svm.predy), size = 4, shape = 1) +
  geom_point(data = Wrong.SVM.Map.Pred, mapping = aes(x=Longitude, y=Latitude), color = "black", shape = 4, size = 4) +
  labs(colour = "Class", title="99.04% Correctly Classified SVM Radial Map") +
  xlab("Longitude") + 
  ylab("Latitude")
  

mp5