-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_2.R
60 lines (45 loc) · 1.57 KB
/
cluster_2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
##########Cluster 2 #######################
################################################################################
############## CLuster with PCA rearrange time-station data ####################
################################################################################
rm(list = ls())
setwd('D:/trabajo/IGP/CLIM_PEZ/victoria_vera/')
dir()
library(readxl)
library(vegan)
library(ade4)
data1<-read_excel("TOTAL_PCA.xlsx", sheet = "Clust")
View(data1)
data_fisica<-data1[,2:6]
View(data_fisica)
boxplot(data_fisica)
#Primero con todos los datos fisicos del 2003 al 2015 promedio anual
row.names(data_fisica)<-data1$Yr_st
# here we reduce the distance
datalt<-log(data_fisica+1)
#we reduce the distance between points
#distort the distances
View(datalt)
plot(datalt)
#step 4
#Calculate the matrix of association using the coefficient
#matdist<-as.dist(datalt)
matdist<-vegdist(datalt,method='euclidian')
#Step 5: Apply clustering method and genearte the dendrogram
# group average clustering method
#View(matdist)
LS<-hclust(matdist,method = 'single')
LC<-hclust(matdist,method='complete')
GA<-hclust(matdist,method='average')
#par(mfrow=c(1,3))
#plot(LS,ylab='Euclidian Method',
# xlab='stations',main='Single linkage')
#abline(b=0,a=0.65,col='red')
#plot(LC,ylab='Euclidian Method',
# xlab='stations',main='Complete linkage')
#abline(b=0,a=0.65,col='red')
windows()
plot(GA,ylab='Euclidian Method',
xlab='stations',main='Group Average linkage')
abline(b=0,a=0.65,col='red')
groupe<-cutree(GA,3);groupe