-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster_27_abril.R
More file actions
324 lines (240 loc) · 8.87 KB
/
cluster_27_abril.R
File metadata and controls
324 lines (240 loc) · 8.87 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
##############################################################
####################### CLIMPEZ ############################
##############################################################
rm(list = ls())
setwd('D:/trabajo/IGP/CLIM_PEZ/victoria_vera/')
dir()
library(readxl)
library(vegan)
library(ade4)
data1<-read_excel("clusters_casos.xlsx", sheet = "yr_hidrol-R2")
View(data1)
data_fisica<-data1[,2:11]
View(data_fisica)
boxplot(data_fisica)
#Primero con todos los datos fisicos del 2003 al 2015 promedio anual
row.names(data_fisica)<-c(2003:2015)
# 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')
plot(GA,ylab='Euclidian Method',
xlab='stations',main='Group Average linkage')
abline(b=0,a=0.65,col='red')
groupe<-cutree(GA,3);groupe
################################################################################
################################## ESCENARIO I Biological ##################################
################################################################################
data_c_bio<-data1[,12:26]
View(data_c_bio)
par(mfrow=c(1,1))
boxplot(data_c_bio)
#Primero con todos los datos fisicos del 2003 al 2015 promedio anual
row.names(data_c_bio)<-c(2003:2015)
# here we reduce the distance
datalt_c_bio<-log(data_c_bio+1)
#we reduce the distance between points
#distort the distances
View(datalt_c_bio)
plot(datalt_c_bio)
#step 4
#Calculate the matrix of association using the coefficient
#matdist<-as.dist(datalt)
matdist_c_bio<-vegdist(datalt_c_bio,method='bray')
#Step 5: Apply clustering method and genearte the dendrogram
# group average clustering method
#View(matdist)
LS<-hclust(matdist_c_bio,method = 'single')
LC<-hclust(matdist_c_bio,method='complete')
GA<-hclust(matdist_c_bio,method='average')
par(mfrow=c(1,3))
plot(LS,ylab='Bray Curtis Method',
xlab='stations',main='Single linkage')
abline(b=0,a=0.1,col='red')
plot(LC,ylab='Bray Curtis Method',
xlab='stations',main='Complete linkage')
abline(b=0,a=0.1,col='red')
plot(GA,ylab='Bray Curtis Method',
xlab='stations',main='Group Average linkage')
abline(b=0,a=0.1,col='red')
groupe<-cutree(GA,4);groupe
############################################################################
##### other clusters just because
data_bio_t<-t(data_c_bio)
View(data_bio_t)
par(mfrow=c(1,1))
boxplot(data_bio_t)
#Primero con todos los datos fisicos del 2003 al 2015 promedio anual
#row.names(data_c_bio)<-c(2003:2015)
# here we reduce the distance
datalt_bio_t<-log(data_bio_t+1)
#we reduce the distance between points
#distort the distances
View(datalt_bio_t)
plot(datalt_bio_t)
#step 4
#Calculate the matrix of association using the coefficient
#matdist<-as.dist(datalt)
matdist_bio_t<-vegdist(datalt_bio_t,method='bray')
#Step 5: Apply clustering method and genearte the dendrogram
# group average clustering method
#View(matdist)
LS<-hclust(matdist_bio_t,method = 'single')
LC<-hclust(matdist_bio_t,method='complete')
GA<-hclust(matdist_bio_t,method='average')
par(mfrow=c(1,3))
plot(LS,ylab='Bray Curtis Method',
xlab='stations',main='Single linkage')
abline(b=0,a=0.25,col='red')
plot(LC,ylab='Bray Curtis Method',
xlab='stations',main='Complete linkage')
abline(b=0,a=0.25,col='red')
plot(GA,ylab='Bray Curtis Method',
xlab='stations',main='Group Average linkage')
abline(b=0,a=0.25,col='red')
groupe<-cutree(GA,3);groupe
## most representative species
library(labdsv)
data7<-data_c_bio[,colSums(data_c_bio)!=0] #delete the columns with 0 values
indval(data7,groupe)->IV;IV
IV$relfrq#faithfulness
IV$relabu #specificity
IV$indval #value of indval from 0 to 1
#GA<-hclust(matdist,method='average')
#plot(GA,ylab='Euclidian distance',
# xlab='stations',main='Group Average linkage') #probar con cluster sin huecos
################# Escenario 2 ##############################################
############################################################################
######################## años del 2000 al 2017 sin incluir Caudal en chizuta
data2<-read_excel("variables_1.xlsx", sheet = "no_chizuta")
View(data2)
data_fisica2<-data2[,2:9]
View(data_fisica2)
boxplot(data_fisica2)
#Primero con todos los datos fisicos del 2003 al 2015 promedio anual
row.names(data_fisica2)<-c(2000:2017)
# here we reduce the distance
datalt2<-log(data_fisica2+1)
#we reduce the distance between points
#distort the distances
View(datalt2)
plot(datalt2)
#step 4
#Calculate the matrix of association using the coefficient
#matdist<-as.dist(datalt)
matdist2<-vegdist(datalt2,method='euclidian')
#Step 5: Apply clustering method and genearte the dendrogram
# group average clustering method
#View(matdist)
LS2<-hclust(matdist2,method = 'single')
LC2<-hclust(matdist2,method='complete')
GA2<-hclust(matdist2,method='average')
par(mfrow=c(1,3))
plot(LS2,ylab='Euclidian Method',
xlab='stations',main='Single linkage')
abline(b=0,a=0.65,col='red')
plot(LC2,ylab='Euclidian Method',
xlab='stations',main='Complete linkage')
abline(b=0,a=0.65,col='red')
plot(GA2,ylab='Euclidian Method',
xlab='stations',main='Group Average linkage')
abline(b=0,a=0.65,col='red')
groupe<-cutree(LC2,4);groupe
################################################################################
############################## Completed Data ##################################
################################################################################
#Fisical
rm(list = ls())
setwd('D:/trabajo/IGP/CLIM_PEZ/victoria_vera/')
dir()
library(readxl)
library(vegan)
library(ade4)
data_c<-read_excel("variables_1.xlsx", sheet = "completed_data")
View(data_c)
data_c_fis<-data_c[,2:10]
View(data_c_fis)
boxplot(data_c_fis)
#Primero con todos los datos fisicos del 2003 al 2015 promedio anual
row.names(data_c_fis)<-c(2000:2019)
# here we reduce the distance
datalt_c_fis<-log(data_c_fis+1)
#we reduce the distance between points
#distort the distances
View(datalt_c_fis)
plot(datalt_c_fis)
#step 4
#Calculate the matrix of association using the coefficient
#matdist<-as.dist(datalt)
matdist_c_fis<-vegdist(datalt_c_fis,method='euclidian')
#Step 5: Apply clustering method and genearte the dendrogram
# group average clustering method
#View(matdist)
LS<-hclust(matdist_c_fis,method = 'single')
LC<-hclust(matdist_c_fis,method='complete')
GA<-hclust(matdist_c_fis,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')
plot(GA,ylab='Euclidian Method',
xlab='stations',main='Group Average linkage')
abline(b=0,a=0.65,col='red')
groupe<-cutree(GA,4);groupe
################################################################################
################################## Biological ##################################
################################################################################
data_c_bio<-data_c[,11:25]
View(data_c_bio)
boxplot(data_c_bio)
#Primero con todos los datos fisicos del 2003 al 2015 promedio anual
row.names(data_c_bio)<-c(2000:2019)
# here we reduce the distance
datalt_c_bio<-log(data_c_bio+1)
#we reduce the distance between points
#distort the distances
View(datalt_c_bio)
plot(datalt_c_bio)
#step 4
#Calculate the matrix of association using the coefficient
#matdist<-as.dist(datalt)
matdist_c_bio<-vegdist(datalt_c_bio,method='bray')
#Step 5: Apply clustering method and genearte the dendrogram
# group average clustering method
#View(matdist)
LS<-hclust(matdist_c_bio,method = 'single')
LC<-hclust(matdist_c_bio,method='complete')
GA<-hclust(matdist_c_bio,method='average')
par(mfrow=c(1,3))
plot(LS,ylab='Bray Curtis Method',
xlab='stations',main='Single linkage')
abline(b=0,a=0.15,col='red')
plot(LC,ylab='Bray Curtis Method',
xlab='stations',main='Complete linkage')
abline(b=0,a=0.15,col='red')
plot(GA,ylab='Bray Curtis Method',
xlab='stations',main='Group Average linkage')
abline(b=0,a=0.15,col='red')
groupe<-cutree(GA,4);groupe