-
Notifications
You must be signed in to change notification settings - Fork 2
/
artificialSps_backup.R
1741 lines (1414 loc) · 133 KB
/
artificialSps_backup.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
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#########################################################################################
####SCRIPT PARA FAZER A DISTRIBUICAO REAL DAS ESPECIES EM VARIOS MOMENTOS DO TEMPO####
#########################################################################################
##pacotes necessarios
library(virtualspecies)
library(maptools)
library(dismo)
library(raster)
library(phyloclim) #para funcao niche.overlap()
#source("/home/anderson/R/R-Scripts/TSSmaxent.R")
#source("/home/anderson/R/R-Scripts/AUCrand.R")
###PRIMEIRA PARTE: criando sps virtuais###
###Parametros necessarios###
##Workstation
## envVarFolder = "J:/Anderson_Eduardo/dados_projeto" #pasta com as variaveis ambientais
## caminhosCamadasTemp = list.files(path=envVarFolder, full.names=T) #lista com os caminhos das camadas no sistema (comp.)
## projectFolder = "J:/Anderson_Eduardo/spsArtificiais/" #pasta do projeto
## AmSulShape = rgdal::readOGR("J:/Anderson_Eduardo/shapefiles/Am_Sul/borders.shp") #shape da America do Sul
##Meu notebook
envVarFolder = "/home/anderson/gridfiles/dados_projeto" #pasta com as variaveis ambientais
caminhosCamadasTemp = list.files(path=envVarFolder, full.names=T) #lista com os caminhos das camadas no sistema (comp.)
projectFolder = "/home/anderson/Projetos/Sps artificiais/" #pasta do projeto
AmSulShape = rgdal::readOGR("/home/anderson/shapefiles/Am_Sul/borders.shp") #shape da America do Sul
############################
ynorm = (dnorm(temp,230,10) - min(dnorm(temp,230,10)))/( max(dnorm(temp,230,10)) - min(dnorm(temp,230,10)) )
plot(ynorm ~ temp)
points(betaTemp ~ temp, t='l')
ynorm = (dnorm(prec,2750,300) - min(dnorm(prec,2750,300)))/( max(dnorm(prec,2750,300)) - min(dnorm(prec,2750,300)) )
plot(ynorm ~ prec)
points(betaPrec ~ prec, t='l')
for (i in 1:length(caminhosCamadasTemp)){
##variaveis preditoras
predictors = stack(paste(caminhosCamadasTemp[i],'/bioclim_01.asc',sep=''),paste(caminhosCamadasTemp[i],'/bioclim_12.asc',sep='')) #carregando as variaveis ambientais
predictors = mask(predictors,AmSulShape) #recortando as variaveis ambientais
nameScenario = basename(caminhosCamadasTemp[i])
##funcoes especie de clima quente e umido
parametersHW <- formatFunctions(bioclim_01=c(fun='betaFun',p1=200,p2=295,alpha=1,gamma=1),bioclim_12=c(fun='betaFun',p1=2000,p2=3500,alpha=1,gamma=1)) #criando as respostas da especie às variaveis ambientais
##funcoes especie de clima quente e seco
parametersHD <- formatFunctions(bioclim_01=c(fun='betaFun',p1=200,p2=260,alpha=1,gamma=1),bioclim_12=c(fun='betaFun',p1=50,p2=1800,alpha=1,gamma=1)) #criando as respostas da especie às variaveis ambientais
##funcoes especie de clima frio e seco
parametersCD <- formatFunctions(bioclim_01=c(fun='betaFun',p1=50,p2=220,alpha=1,gamma=1),bioclim_12=c(fun='betaFun',p1=50,p2=1800,alpha=1,gamma=1)) #criando as respostas da especie às variaveis ambientais
##criando distribuicao geografica das sps
spHW <- generateSpFromFun(predictors, parametersHW) #criando a especie artifical (clima quente e umido)
spHD <- generateSpFromFun(predictors, parametersHD) #criando a especie artifical (clima quente e seco)
spCD <- generateSpFromFun(predictors, parametersCD) #criando a especie artifical (clima frio e seco)
##empilhando distribuicoes geradas
auxVector=stack(c(spHW$suitab.raster,spHD$suitab.raster,spCD$suitab.raster))
names(auxVector) = c('spHW', 'spHD', 'spCD')
##ajustando o raster e salvando
for(j in 1:dim(auxVector)[3]){
projection(auxVector[[j]]) = CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0') #ajustando CRS
writeRaster(auxVector[[j]], filename=paste(projectFolder,'NichoReal/',names(auxVector[[j]]),'/',nameScenario,'.asc',sep=""), overwrite=TRUE,prj=TRUE) #salvando o raster do mapa da sp
}
}
###SEGUNDA PARTE: amostragem de pontos de ocorrencia em diferentes camadas de tempo###
##pacotes
library(raster)
## ##definindo variaveis e parametros (LORIEN)
## envVarFolder = "J:/Pesquisadorxs/Anderson_Eduardo/dados_projeto" #pasta com as variaveis ambientais
## projectFolder = "J:/Pesquisadorxs/Anderson_Eduardo/spsArtificiais" #pasta do projeto
## mainSampleFolder = 'J:/Pesquisadorxs/Anderson_Eduardo/spsArtificiais/Amostras' #caminho para pasta onde a anilha com os pontos amostrados sera salva
## AmSulShape = rgdal::readOGR("J:/Pesquisadorxs/Anderson_Eduardo/shapefiles/Am_Sul/borders.shp") #shape da America do Sul
## crs(AmSulShape) = CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0')
## biasLayer = raster('J:/Pesquisadorxs/Anderson_Eduardo/spsArtificiais/biasLayer.grd')
## #biomodFolder = '/home/anderson/Documentos/Projetos/Sps artificiais/biomod/' #pasta para resultados do maxent
## spsTypes = c('spHW', 'spCD') #c('spHW', 'spHD', 'spCD') #nomes das especies
## sampleSizes = c(10, 50, 100) #c(5,10,20,40,80,160) #tamanhos das amostras
## NumRep = 5 #10 #numero de replicas (de cada cenario amostral)
## Tmax = 22 #idade maxima (no passado)
## bgPoints = 1000 #numero de pontos de background
##definindo variaveis e parametros (NOTEBOOK)
envVarFolder = "/home/anderson/PosDoc/dados_ambientais/dados_projeto" #pasta com as variaveis ambientais
projectFolder = "/home/anderson/Documentos/Projetos/Sps artificiais/" #pasta do projeto
mainSampleFolder = '/home/anderson/Documentos/Projetos/Sps artificiais/Amostras/' #caminho para pasta onde a planilha com os pontos amostrados sera salva
AmSulShape = rgdal::readOGR("/home/anderson/PosDoc/shapefiles/Am_Sul/borders.shp") #shape da America do Sul
crs(AmSulShape) = CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0')
biasLayer = raster('/home/anderson/Documentos/Projetos/Sps artificiais/biasLayer.grd')
spsTypes = c('spHW', 'spCD') #c('spHW', 'spHD', 'spCD') #nomes das especies
sampleSizes = c(10,50,100) #c(5,10,20,40,80,160) #tamanhos das amostras
NumRep = 5 #numero de replicas (de cada cenario amostral)
Tmax = 22 #idade maxima (no passado)
bgPoints = 5000 #numero de pontos de background
##PARA SDM MULTITEMPORAL E SEM VIES AMOSTRAL
sampleData = data.frame()
sampleDataBG = data.frame()
for (i in 1:length(spsTypes)){ #loop sobre os 'tipos de especies'
##criando uma pasta da especie, se nao exisitir
if(!file.exists(paste(projectFolder,'/Amostras','/multitemporal/',spsTypes[i],sep=''))){
dir.create(paste(projectFolder,'/Amostras','/multitemporal/',spsTypes[i],sep=''),recursive=TRUE)}
for (sSize in sampleSizes){ #numero de pontos (registros, dados) na amostra
sampledAges = vector()
sampledAges = round(runif(sSize,0,Tmax)) #selecionando 'n' camadas de tempo aleatoriamente
nicheRealFolder = paste(projectFolder,'/NichoReal/',spsTypes[i],sep='') #pasta com os mapas de nicho real da sp
nicheRealPath = list.files(path=nicheRealFolder, full.names=TRUE, pattern='.asc') #lista com os enderecos dos mapas de distribuicao da
for (j in 1:NumRep){ #replicas do cenario amostral
for (sAge in unique(sampledAges)){ #amostrando em cada camada de tempo que consta na amostra
## occ pts
sampleData_i = dismo::randomPoints(mask=raster(nicheRealPath[sAge+1])>0.2,prob=TRUE, n=sum(sAge==sampledAges)) #amostra d ponto
#sampleData_i = randomPoints(mask=raster(nicheRealPath[sAge+1]), n=1) #amostra d ponto
scenarioName = basename(nicheRealPath[1:24][sAge+1]) #tempo vinculado ao cenario para variaveis ambientais
scenarioName = gsub('.asc','',scenarioName) #retirando do nome o '.asc'
layers_i = extract(
x=stack(list.files(path=paste(envVarFolder,'/',scenarioName,sep=''), pattern='asc', full.names=TRUE)),
y=sampleData_i) #extraindo variaveis ambientais do ponto, em sua respectiva camada de tempo
sampleData = rbind(sampleData, cbind(sampleData_i,layers_i,sAge)) #juntando com os dados das outras camadas de tempo amostradas
## background points
envVarPath = list.files(path=envVarFolder,full.names=TRUE)[sAge+1] #lista com os enderecos das variaveis ambientais no tempo corresposndente a interacao
envData = list.files(envVarPath,full.names=TRUE)
sampleDataBG_i = dismo::randomPoints(mask = raster(envData[1],
crs = CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0')),
n = sum(sAge==sampledAges)*(round(bgPoints/length(sampledAges)))) #amostra dos pontos
scenarioName = list.files(path=paste(envVarFolder))[sAge+1] #nome do cenario
layersBG_i = extract(
x=stack(list.files(path=paste(envVarFolder,'/',scenarioName,sep=''), pattern='asc', full.names=TRUE)),
y=sampleDataBG_i) #extraindo variaveis ambientais do ponto, em sua respectiva camada de tempo
sampleDataBG = rbind(sampleDataBG, data.frame(lon=sampleDataBG_i[,1],lat=sampleDataBG_i[,2],layersBG_i,kyrBP=sAge)) #juntando com os dados das outras camadas de tempo amostradas
}
## occ pts
names(sampleData) = c('lon','lat',names(as.data.frame(layers_i)),'kyrBP') #ajustando os nomes
write.csv(sampleData,paste(projectFolder,'/Amostras/multitemporal/',spsTypes[i],'/occ_',sSize,'pts_multitemporal_', j ,'rep.csv',sep=''),row.names=FALSE) #salvando
sampleData = data.frame() #devolvendo data.frame vazio para proxima rodada
## background pts
names(sampleDataBG) = c('lon','lat',names(as.data.frame(layersBG_i)),'kyrBP') #ajustando os nomes
write.csv(sampleDataBG,paste(projectFolder,'/Amostras/multitemporal/',spsTypes[i],'/bg_',sSize,'pts_multitemporal_', j ,'rep.csv',sep=''),row.names=FALSE) #salvando
sampleDataBG = data.frame() #devolvendo data.frame vazio para proxima rodada
}
}
}
##PARA SDM MULTITEMPORAL E COM VIES AMOSTRAL
sampleData = data.frame()
sampleDataBG = data.frame()
for (i in 1:length(spsTypes)){ #loop sobre os 'tipos de especies'
##criando uma pasta da especie, se nao exisitir
if(!file.exists(paste(projectFolder,'/Amostras','/multitemporal/',spsTypes[i],sep=''))){
dir.create(paste(projectFolder,'/Amostras','/multitemporal/',spsTypes[i],sep=''), recursive=TRUE)}
for (sSize in sampleSizes){ #numero de pontos (registros, dados) na amostra
sampledAges = vector()
sampledAges = round(runif(sSize,0,Tmax)) #selecionando 'n' camadas de tempo aleatoriamente
nicheRealFolder = paste(projectFolder,'/NichoReal/',spsTypes[i],sep='') #pasta com os mapas de nicho real da sp
nicheRealPath = list.files(path=nicheRealFolder, full.names=TRUE, pattern='.asc') #lista com os enderecos dos mapas de distribuicao da
biasLayerAdjusted = projectRaster(biasLayer,raster(nicheRealPath[1])) #alinhando o biasLayer com os rasters do projeto
for (j in 1:NumRep){ #replicas do cenario amostral
for (sAge in unique(sampledAges)){ #amostrando em cada camada de tempo que consta na amostra
## occ pts
sampleData_i = dismo::randomPoints(mask=raster(nicheRealPath[sAge+1])*biasLayerAdjusted, prob=TRUE, n=sum(sAge==sampledAges)) #amostra d ponto
#sampleData_i = randomPoints(mask=raster(nicheRealPath[sAge+1])*biasLayerAdjusted, n=1, prob=TRUE) #amostra d ponto
scenarioName = basename(nicheRealPath[1:24][sAge+1]) #tempo vinculado ao cenario para variaveis ambientais
scenarioName = gsub('.asc','',scenarioName) #retirando do nome o '.asc'
layers_i = extract(
x=stack(list.files(path=paste(envVarFolder,'/',scenarioName,sep=''), pattern='asc', full.names=TRUE)),
y=sampleData_i) #extraindo variaveis ambientais do ponto, em sua respectiva camada de tempo
sampleData = rbind(sampleData, cbind(sampleData_i,layers_i,sAge)) #juntando com os dados das outras camadas de tempo amostradas
## background points
envVarPath = list.files(path=envVarFolder,full.names=TRUE)[sAge+1] #lista com os enderecos das variaveis ambientais no tempo corresposndente a interacao
envData = list.files(envVarPath,full.names=TRUE)
sampleDataBG_i = dismo::randomPoints(mask = raster(envData[1],
crs = CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0')),
n = sum(sAge==sampledAges)*(round(bgPoints/length(sampledAges)))) #amostra dos pontos
scenarioName = list.files(path=paste(envVarFolder))[sAge+1] #nome do cenario
layersBG_i = extract(
x=stack(list.files(path=paste(envVarFolder,'/',scenarioName,sep=''), pattern='asc', full.names=TRUE)),
y=sampleDataBG_i) #extraindo variaveis ambientais do ponto, em sua respectiva camada de tempo
sampleDataBG = rbind(sampleDataBG, data.frame(lon=sampleDataBG_i[,1],lat=sampleDataBG_i[,2],layersBG_i,kyrBP=sAge)) #juntando com os dados das outras camadas de tempo amostradas
}
## occ pts
names(sampleData) = c('lon','lat',names(as.data.frame(layers_i)),'kyrBP') #ajustando os nomes
write.csv(sampleData,paste(projectFolder,'/Amostras/multitemporal/',spsTypes[i],'/occ_',sSize,'pts_multitemporal_comVIES_', j ,'rep.csv',sep=''),row.names=FALSE) #salvando
sampleData = data.frame() #devolvendo data.frame vazio para proxima rodada
## background pts
names(sampleDataBG) = c('lon','lat',names(as.data.frame(layersBG_i)),'kyrBP') #ajustando os nomes
write.csv(sampleDataBG,paste(projectFolder,'/Amostras/multitemporal/',spsTypes[i],'/bg_',sSize,'pts_multitemporal_', j ,'rep.csv',sep=''),row.names=FALSE) #salvando
sampleDataBG = data.frame() #devolvendo data.frame vazio para proxima rodada
}
}
}
##PARA SDM MONOTEMPORAL (pode ser presente ou passado) E SEM VIES AMOSTRAL (obviamente, pq esse vies e para fosseis)
sampleData = data.frame()
sampleDataBg = data.frame()
for (i in 1:length(spsTypes)){ #loop sobre os 'tipos de especies'
##criando uma pasta da especie, se nao exisitir
if(!file.exists(paste(projectFolder,'/Amostras','/monotemporal/',spsTypes[i],sep=''))){
dir.create(paste(projectFolder,'Amostras','/monotemporal/',spsTypes[i],sep=''), recursive=TRUE)}
for (sSize in sampleSizes){ #numero de pontos (registros, dados) na amostra
for (j in 1:NumRep){ #replicas do cenario amostral
sampledAge = round(runif(1,0,Tmax)) #selecionando a camada de tempo aleatoriamente
nicheRealFolder = paste(projectFolder,'/NichoReal/',spsTypes[i],sep='') #pasta com os mapas de nicho real da sp
nicheRealPath = list.files(path=nicheRealFolder, full.names=TRUE, pattern='.asc') #lista com os enderecos dos mapas de distribuicao da
sampleData_i = dismo::randomPoints(mask=raster(nicheRealPath[sampledAge])>0.2, prob=TRUE, n=sSize) #amostra do ponto
scenarioName = basename(nicheRealPath[1:24][sampledAge]) #tempo vinculado ao cenario para variaveis ambientais
scenarioName = gsub('.asc','',scenarioName) #retirando do nome o '.asc'
layers_i = extract(
x=stack(list.files(path=paste(envVarFolder,'/',scenarioName,sep=''), pattern='asc', full.names=TRUE)),
y=sampleData_i) #extraindo variaveis ambientais do ponto, em sua respectiva camada de tempo
sampleData = rbind(sampleData, cbind(sampleData_i,layers_i,sampledAge)) #juntando com os dados das outras camadas de tempo amostradas
names(sampleData) = c('lon','lat',names(as.data.frame(layers_i)),'kyrBP') #ajustando os nomes
write.csv(sampleData,paste(projectFolder,'/Amostras/monotemporal/',spsTypes[i],'/occ_',sSize,'pts_monotemporal_',j,'rep','.csv',sep=''),row.names=FALSE) #salvando
sampleData = data.frame() #devolvendo data.frame vazio para proxima rodada
##background points##
sampleDataBg_i = dismo::randomPoints(mask=raster(nicheRealPath[sampledAge]),
n=bgPoints) #amostra dos pontos
# scenarioName = list.files(path=paste(envVarFolder))[sAge+1] #nome do cenario
layersBg_i = extract(
x=stack(list.files(path=paste(envVarFolder,'/',scenarioName,sep=''), pattern='asc', full.names=TRUE)),
y=sampleDataBg_i) #extraindo variaveis ambientais do ponto, em sua respectiva camada de tempo
sampleDataBg = rbind(sampleDataBg, data.frame(lon=sampleDataBg_i[,1],lat=sampleDataBg_i[,2],layersBg_i,kyrBP=sampledAge)) #juntando com os dados das outras camadas de tempo amostradas
names(sampleDataBg) = c('lon','lat',names(as.data.frame(layersBg_i)),'kyrBP') #ajustando os nomes
write.csv(sampleDataBg,paste(projectFolder,'/Amostras/monotemporal/',spsTypes[i],'/bg_',sSize,'pts_monotemporal_',j,'rep','.csv',sep=''),row.names=FALSE) #salvando
sampleDataBg = data.frame() #devolvendo data.frame vazio para proxima rodada
}
}
}
###TERCEIRA PARTE: SDM usando de pontos de ocorrencia em diferentes camadas de tempo (do atual ate 120 kyr BP)###
#######################################################
####################### MAXENT ########################
#######################################################
##pacotes
library(biomod2)
## ##definindo variaveis e parametros (LORIEN)
## options(java.parameters = "-Xmx7g") ###set available memmory to java
## projectFolder = "J:/Anderson_Eduardo/spsArtificiais" #pasta do projeto
## envVarFolder = "J:/Anderson_Eduardo/dados_projeto" #pasta com as variaveis ambientais
## envVarPaths = list.files(path=envVarFolder, full.names=TRUE) #lista com os caminhos das camadas no sistema (comp.)
## AmSulShape = rgdal::readOGR("J:/Anderson_Eduardo/shapefiles/Am_Sul/borders.shp") #shape da America do Sul
## mainSampleFolder = "J:/Anderson_Eduardo/spsArtificiais/Amostras" #caminho para pasta onde a planilha
## maxentFolder = 'C:/Users/WS/Documents/R/win-library/3.4/dismo/java' #pasta para resultados do maxent
## spsTypes = c('spHW','spCD') #c('spHW', 'spHD', 'spCD') #nomes das especies
## sdmTypes = c('monotemporal') #c('multitemporal','monotemporal')
## #source("/home/anderson/R/R-Scripts/TSSmaxent.R")
## sampleSizes = 50 #c(10,100) #c(5,10,20,40,80,160) #tamanhos das amostras
## NumRep = 3 #10 #numero de replicas (de cada cenario amostral)
## #statResults = data.frame() #tabela de estatisticas basicas do modelo
##definindo variaveis e parametros (NOTEBOOK)
options(java.parameters = "-Xmx7g") ###set available memmory to java
projectFolder = "/home/anderson/Documentos/Projetos/Sps artificiais" #pasta do projetoenvVarPaths = list.files(path=envVarFolder, full.names=TRUE) #lista com os caminhos das camadas no sistema (comp.)
envVarFolder = "/home/anderson/PosDoc/dados_ambientais/dados_projeto" #pasta com as variaveis ambientais
envVarPaths = list.files(path=envVarFolder, full.names=T) #lista com os caminhos das camadas no sistema (comp.)
mainSampleFolder = '/home/anderson/Documentos/Projetos/Sps artificiais/Amostras' #caminho para pasta onde a planilha com os pontos
maxentFolder = '/home/anderson/R/x86_64-pc-linux-gnu-library/3.3/dismo/java' #pasta para resultados do maxent
AmSulShape = rgdal::readOGR("/home/anderson/PosDoc/shapefiles/Am_Sul/borders.shp") #shape da America do Sul
spsTypes = c('spHW','spCD') #nomes das especies #c('spHW', 'spHD', 'spCD') #nomes das especies
sdmTypes = c('multitemporal','monotemporal')
#source("/home/anderson/R/R-Scripts/TSSmaxent.R")
sampleSizes = c(10,50,100) #c(5,10,20,40,80,160) #tamanhos das amostras
NumRep = 5 #numero de replicas (de cada cenario amostral)
timeStart = Sys.time()
#statResults = data.frame() #tabela de estatisticas basicas do modelo
##algoritmo da analise do projeto
for (h in 1:length(sdmTypes)){
for (i in 1:length(spsTypes)){
statResults = data.frame() #tabela de estatisticas basicas do modelo
for (j in 1:length(sampleSizes)){
for (k in 1:NumRep){ #loop sobre o numero de replicas
tryCatch({
##ajustando o diretorio de trabalho (pois o biomod roda e salva tudo simultaneamente)
if(!file.exists(file.path(projectFolder,'maxent',sdmTypes[h], spsTypes[i],sep=''))){
dir.create(file.path(projectFolder,'maxent',sdmTypes[h],spsTypes[i],sep=''),recursive=TRUE)
}
setwd(file.path(projectFolder,'maxent',sdmTypes[h],spsTypes[i]))
##definindo variaveis e parametros locais
occPoints = read.csv(paste(mainSampleFolder,sdmTypes[h],'/',spsTypes[i],'/occ_',sampleSizes[j],'pts_',sdmTypes[h],'_',k,'rep.csv',sep=''),header=TRUE) #abrindo pontos de ocorrencia
backgroundPoints = read.csv(paste(mainSampleFolder,sdmTypes[h],'/',spsTypes[i],'/bg_',sampleSizes[j],'pts_',sdmTypes[h],'_',k,'rep.csv',sep=''),header=TRUE) #abrindo pontos de background
##agrupando ocorrencias e pseudo-ausencias
names(backgroundPoints) = names(occPoints) #certificando que os nomes das colunas estão iguais (cuidado aqui...)
dataSet = data.frame(cbind(rbind(occPoints,backgroundPoints),pres=c(rep(1,nrow(occPoints)),rep(0,nrow(backgroundPoints))))) #planilha de dados no formato SWD
##variaveis e parametros locais especificos para o biomod2
myRespName <- paste(spsTypes[i],'_sample',sampleSizes[j],'_replica',k,sep='') # nome do cenario atual (para biomod2)
myResp <- dataSet[,c('pres')] # variavel resposta (para biomod2)
myRespXY <- dataSet[,c('lon','lat')] # coordenadas associadas a variavel resposta (para biomod2)
myExpl = dataSet[,c('bioclim_01','bioclim_12')] #variavel preditora (para biomod2)
##ajuste de dados de entrada para biomod2
myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,
expl.var = myExpl,
resp.xy = myRespXY,
resp.name = myRespName)
## ##inspecionando o objeto gerado pela funcao do biomod2
## myBiomodData
## plot(myBiomodData)
##parametrizando os modelos
myBiomodOption <- BIOMOD_ModelingOptions(
MAXENT.Phillips=list(
path_to_maxent.jar=maxentFolder,
maximumiterations=1000,
linear=TRUE,
quadratic=TRUE,
product=FALSE,
threshold=FALSE,
hinge=FALSE,
maximumiterations=1000,
convergencethreshold=1.0E-5,
threads=2))
##rodando o(s) algoritmo(s) (i.e. SDMs)
myBiomodModelOut <- BIOMOD_Modeling(
myBiomodData,
models = c('MAXENT.Phillips'),
models.options = myBiomodOption,
NbRunEval = 3,
DataSplit = 75,
VarImport = 5,
models.eval.meth = c('TSS','ROC'),
SaveObj = TRUE,
rescal.all.models = TRUE,
do.full.models = FALSE,
modeling.id = paste(myRespName))
##My output data
evaluationScores = get_evaluations(myBiomodModelOut)
##gravando estatistcas basicas do modelo
statResults = rbind(statResults,cbind(
modelType = sdmTypes[h],
sp = spsTypes[i],
sampleSize = sampleSizes[j],
replicate = k,
AUC = mean(evaluationScores['ROC','Testing.data',,,]),
TSS = mean(evaluationScores['TSS','Testing.data',,,]),
numbOfTimeLayers = length(unique(occPoints$kyrBP)),
medianKyr = median(occPoints$kyrBP),
minAge = min(occPoints$kyrBP),
maxAge = max(occPoints$kyrBP)))
write.csv(statResults,file=paste(projectFolder,'/maxent/',sdmTypes[h],'/',spsTypes[i],'/StatisticalResults-',spsTypes[i],'.csv',sep=''),row.names=FALSE)
##implementando projecoes do modelo
for (l in 1:length(envVarPaths[1:24])){
##definindo variaveis e parametros internos
predictors = stack(list.files(path=envVarPaths[l],full.names=TRUE, pattern='.asc')) #predictors com todas as variaveis (presente)
predictors = predictors[[c('bioclim_01','bioclim_12')]]
##predictors = mask(predictors,AmSulShape) #recortando as variaveis ambientais
crs(predictors) = CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0') #ajustando CRS
##selecionando o melhor modelo para projecao
whichModel = names(evaluationScores['TSS','Testing.data',,,][which(evaluationScores['TSS','Testing.data',,,]== max(evaluationScores['TSS','Testing.data',,,]) )])
modelName = grep(pattern=whichModel, [email protected], value=TRUE)
##rodando algortmo de projecao (i.e. rodando a projecao)
myBiomodProj <- BIOMOD_Projection(
modeling.output = myBiomodModelOut,
new.env = predictors,
proj.name = paste(l-1,'kyr',sep=''),
selected.models = modelName,
binary.meth = 'TSS',
compress = 'TRUE',
build.clamping.mask = 'TRUE',
output.format = '.grd')
##gerando e salvando um mapa binario (threshold 10%)
## projStack = get_predictions(myBiomodProj) #extrai as projecoes
## projStackBIN = BinaryTransformation(stack(mean(projStack)),'10')
## writeRaster(projStackBIN,file=paste(projectFolder,'/maxent/',sdmTypes[h],'/',spsTypes[i],'/',spsTypes[i],'.sample',sampleSizes[j],'.replica',k,'/proj_',l,'kyr/proj_',i,'kyr','.sample',sampleSizes[j],'.replica',k,'_BIN.asc',sep=''),overwrite=TRUE)
}
}, error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}
}
}
}
##tempo gasto
print(Sys.time() - timeStart)
###QUARTA PARTE: comparando projecao do SDM e a distribuicao espacial real do nicho da sp###
##abrindo pacotes necessarios
library(raster)
library(ecospat)
## ##definindo variaveis e parametros (LORIEN)
## options(java.parameters = "-Xmx7g") ###set available memmory to java
## projectFolder = "J:/Anderson_Eduardo/spsArtificiais" #pasta do projeto
## envVarFolder = "J:/Anderson_Eduardo/dados_projeto" #pasta com as variaveis ambientais
## envVarPaths = list.files(path=envVarFolder, full.names=TRUE) #lista com os caminhos das camadas no sistema (comp.)
## AmSulShape = rgdal::readOGR("J:/Anderson_Eduardo/shapefiles/Am_Sul/borders.shp") #shape da America do Sul
## mainSampleFolder = "J:/Anderson_Eduardo/spsArtificiais/Amostras" #caminho para pasta onde a planilha
## maxentFolder = 'C:/Users/WS/Documents/R/win-library/3.4/dismo/java' #pasta para resultados do maxent
## spsTypes = c('spHW','spCD') #c('spHW', 'spHD', 'spCD') #nomes das especies
## sdmTypes = c('multitemporal','monotemporal')
## #source("/home/anderson/R/R-Scripts/TSSmaxent.R")
## sampleSizes = c(10,100) #c(5,10,20,40,80,160) #tamanhos das amostras
## NumRep = 3 #10 #numero de replicas (de cada cenario amostral)
## outputData = data.frame()
##definindo variaveis e parametros (NOTEBOOK)
projectFolder = "/home/anderson/Documentos/Projetos/Sps artificiais/" #pasta do projeto
mainSampleFolder = '/home/anderson/Documentos/Projetos/Sps artificiais/Amostras/' #caminho para pasta onde a planilha com os pontos amostrados sera salva
spsTypes = c('spHW','spCD') #c('spHW', 'spHD', 'spCD') #nomes das especies
sdmTypes = c('multitemporal','monotemporal')
sampleSizes = c(10,50,100) #c(5,10,20,40,80,160) #aqui, deve ser igual ao usasado nas partes anteriores do script
NumRep = 5
envVarFolder = "/home/anderson/PosDoc/dados_ambientais/dados_projeto" #pasta com as variaveis ambientais
envVarPaths = list.files(path=envVarFolder, full.names=T) #lista com os caminhos das camadas no sistema (comp.)
AmSulShape = rgdal::readOGR("/home/anderson/PosDoc/shapefiles/Am_Sul/borders.shp") #shape da America do Sul
timeStart = Sys.time()
outputData = data.frame()
##algoritmo da analise do projeto
for (h in 1:length(sdmTypes)){
for (i in 1:length(spsTypes)){
##definindo variaveis e parametros locais
nicheRealFolder = paste(projectFolder,'NichoReal/',spsTypes[i],sep='') #pasta com os mapas de nicho real da sp
nicheRealPath = list.files(path=nicheRealFolder,pattern='.asc',full.names=TRUE) #lista com os enderecos dos mapas de distribuicao da sp
##loop sobre as cadamdas de tempo
for (l in 1:length(nicheRealPath[1:24])){ #1:length(nicheRealPath[1:24])){
##definindo variaveis e parametros locais
realNiche = nicheRealPath[l] #nicho real
##amostrando pontos da distribuicao real para compracao dos SDMs
binMap = raster(realNiche)>0.2 #mapa binario do real
realNicheDataOccCoord = dismo::randomPoints(binMap,1000) #amostrando 1000 pontos do binario real
realNicheDataOccPres = extract(binMap,realNicheDataOccCoord,na.rm=TRUE) #definindo occ e ausencias para os pontos
realNicheDataOcc = data.frame(longitude=realNicheDataOccCoord[,1], latitude=realNicheDataOccCoord[,2], pres=realNicheDataOccPres) #tabela lon, lat e pres
predictors = stack(list.files(path=envVarPaths[l],full.names=TRUE, pattern='.asc')) #predictors com todas as variaveis
predictors = predictors[[c('bioclim_01','bioclim_12')]] #selecionando as variaveis usadas
predictors = mask(predictors,AmSulShape) #recortando as variaveis ambientais
projection(predictors) = CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0') #ajustando CRS
realNicheDataPred = extract(x=predictors,y=realNicheDataOcc[,c('longitude','latitude')],na.rm=TRUE) #extraindo variaveis ambientais do ponto, em sua respectiva camada de tempo
realNicheData = data.frame(realNicheDataOcc, realNicheDataPred) #juntando com os dados das outras camadas de tempo amostradas
##loop sobre os tamanhos amostrais
for (m in sampleSizes){
## ##timeSampleData = list.files(path=projectionsFolder, pattern=glob2rx(paste('*Time',l-1,'*Sample',m,'.asc',sep='')),full.names=TRUE)
## timeSampleData = list.files(path=paste(projectFolder,'maxent/',sdmTypes[h],'/',spsTypes[i],sep=''), pattern=glob2rx(paste('*',l,'kyr','*sample',m,'*.asc',sep='')), recursive=TRUE, full.names=TRUE) #pasta com as projecoes do cenario
##loop sobre replicas de cada combinacao de tempo e tamanho amostral
for(n in 1:NumRep){
tryCatch({
##definindo variaveis e parametros locais
##outputData = data.frame() #tabela de dados de saida
## projectionsFolder = paste(projectFolder,'maxent/',sdmTypes[h],'/',spsTypes[i],'/',spsTypes[i],'.sample',m,'.replica',n,sep='') #pasta com as projecoes do cenario
## projectionsPath = list.files(path=projectionsFolder, pattern='.asc',recursive=TRUE,full.names=T) #caminhos para os .asc na paste do cenario
sdmNichePath = paste(projectFolder,'maxent/',sdmTypes[h],'/',spsTypes[i],'/',spsTypes[i],'.sample',m,'.replica',n,'/proj_',l-1,'kyr/','proj_',l-1,'kyr_',spsTypes[i],'.sample',m,'.replica',n,'_TSSbin.grd',sep='') #caminho do mapa de suitability gerado por SDM
sdmNicheStack = stack(sdmNichePath)
binMapSDM = sdmNicheStack #sum(sdmNicheStack)#>0.5
# binMapSDM = sdmNicheStack[[round(runif(1,0.5,nlayers(sdmNicheStack)))]] #mapa de suitability gerado por SDM
# binMapSDM = biomod2::BinaryTransformation(data=mean(sdmNiche), threshold=10) #fazendo mapa binario, threshold 10%
SDMDataOccCoord = dismo::randomPoints(binMapSDM, 1000)
SDMDataOccPres = extract(binMapSDM, SDMDataOccCoord, na.rm=TRUE)
SDMDataOcc = data.frame(longitude=SDMDataOccCoord[,1],latitude=SDMDataOccCoord[,2],pres=as.numeric(SDMDataOccPres))
SDMDataPred = extract(x=predictors,y=SDMDataOcc[,c('longitude','latitude')],na.rm=TRUE) #extraindo variaveis ambientais do ponto, em sua respectiva camada de tempo
SDMData = data.frame(SDMDataOcc, SDMDataPred) #juntando com os dados das outras camadas de tempo amostradas
SDMData = SDMData[complete.cases(SDMData),]
##The PCA is calibrated on all the sites of the study area
pca.env <- dudi.pca(rbind(realNicheData,SDMData)[,c('bioclim_01','bioclim_12')],scannf=F,nf=2)
#ecospat.plot.contrib(contrib=pca.env$co, eigen=pca.env$eig) #grafico
##PCA scores for the whole study area
scores.globclim <- pca.env$li
##PCA scores for the species native distribution
scores.sp.realNiche <- suprow(pca.env,realNicheData[which(realNicheData[,'pres']==1),c('bioclim_01','bioclim_12')])$li
##PCA scores for the species invasive distribution
scores.sp.SDMniche <- suprow(pca.env,SDMData[which(SDMData[,'pres']==1),c('bioclim_01','bioclim_12')])$li
##PCA scores for the whole native study area
scores.clim.realNiche <-suprow(pca.env,realNicheData[,c('bioclim_01','bioclim_12')])$li
##PCA scores for the whole invaded study area
scores.clim.SDMniche <- suprow(pca.env,SDMData[,c('bioclim_01','bioclim_12')])$li
##gridding the native niche
grid.clim.realNiche <-ecospat.grid.clim.dyn(glob=scores.globclim,glob1=scores.clim.realNiche,sp=scores.sp.realNiche, R=100,th.sp=0)
##gridding the invasive niche
grid.clim.SDMniche <- ecospat.grid.clim.dyn(glob=scores.globclim,glob1=scores.clim.SDMniche,sp=scores.sp.SDMniche, R=100,th.sp=0)
##equivalencia de nicho
##OBS: Compares the observed niche overlap between z1 and z2 to overlaps between random niches z1.sim
## and z2.sim, which are built from random reallocations of occurences of z1 and z2.
##'alternative' argument specifies if you want to test for niche conservatism (alternative = "greater", i.e. the
## niche overlap is more equivalent/similar than random) or for niche divergence (alternative = "lower",
## i.e. the niche overlap is less equivalent/similar than random).
eq.test <- ecospat.niche.equivalency.test(grid.clim.realNiche, grid.clim.SDMniche,rep=100, alternative = "greater")
##similaridade de nicho
##OBS: Compares the observed niche overlap between z1 and z2 to overlaps between z1 and random niches
## (z2.sim) as available in the range of z2 (z2$Z). z2.sim has the same pattern as z2 but the center is
## randomly translatated in the availabe z2$Z space and weighted by z2$Z densities. If rand.type = 1,
## both z1 and z2 are randomly shifted, if rand.type =2, only z2 is randomly shifted.
## 'alternative' specifies if you want to test for niche conservatism (alternative = "greater", i.e. the
## niche overlap is more equivalent/similar than random) or for niche divergence (alternative = "lower",
## i.e. the niche overlap is less equivalent/similar than random)
sim.test <- ecospat.niche.similarity.test(grid.clim.realNiche, grid.clim.SDMniche, rep=100, alternative = "greater")
Dobs_equiv = eq.test$obs$D #indice D observado no teste de equivalencia de nicho
Iobs_equiv = eq.test$obs$I #indice I observado no teste de equivalencia de nicho
DpValue_equiv = eq.test$p.D #p-valor indice D no teste de equivalencia de nicho
IpValue_equiv = eq.test$p.I #p-valor indice I no teste de equivalencia de nicho
##
Dobs_simi = sim.test$obs$D #indice D observado no teste de similaridade de nicho
Iobs_simi = sim.test$obs$I #indice I observado no teste de similaridade de nicho
DpValue_simi = sim.test$p.D #p-valor indice D no teste de similaridade de nicho
IpValue_simi = sim.test$p.I #p-valor indice I no teste de similaridade de nicho
##abrindo planilha de pontos para extrair dados do cenario
occPoints = read.csv(paste(mainSampleFolder,'/',sdmTypes[h],'/',spsTypes[i],'/occ_',m,'pts_',sdmTypes[h],'_', n ,'rep.csv',sep=''),header=TRUE)
occPoints[occPoints==0] = NA
occPoints = occPoints[complete.cases(occPoints),]
occPoints = round(occPoints, digits=2)
occPoints = occPoints[!duplicated(occPoints),]
outputData = rbind(outputData,data.frame(sdmType = sdmTypes[h],
sp = spsTypes[i],
kyrBP = l-1,
sampleSize = m,
replicate = n,
numbOfTimeLayers = length(unique(occPoints$kyrBP)),
medianKyr = median(occPoints$kyrBP),
minAge = min(occPoints$kyrBP),
maxAge = max(occPoints$kyrBP),
Schoeners_D_equiv = Dobs_equiv,
p_value_equiv = DpValue_equiv,
Hellinger_I_equiv = Iobs_equiv,
p_value_equiv = IpValue_equiv,
Schoeners_D_simi = Dobs_simi,
p_value_simi = DpValue_simi,
Hellinger_I_simi = Iobs_simi,
p_value_simi = IpValue_simi))
write.csv(outputData, file=paste(projectFolder,'/maxent/output.csv',sep=''),row.names=FALSE) #salvando os dados do cenario
}, error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}
}
}
}
}
##registro do tempo
print(Sys.time() - timeStart)
### QUINTA PARTE: construindo graficos dos resultados ###
## ##definindo parametros e variaveis (LORIEN)
## spsTypes = c('spHW', 'spCD') #c('spHW', 'spHD', 'spCD') #nomes das especies
## outputData = list() #tabela de dados de saida
## vetor.nomes = vector()
## projectFolder = "J:/Anderson_Eduardo/spsArtificiais" #pasta do projeto
##definindo parametros e variaveis (NOTEBOOK)
spsTypes = c('spHW', 'spCD') #c('spHW', 'spHD', 'spCD') #nomes das especies
outputData = list() #tabela de dados de saida
vetor.nomes = vector()
projectFolder = "/home/anderson/Projetos/Sps artificiais" #pasta do projeto
#projectFolder = '/media/anderson/PIBi/ANDERSON EDUARDO/Sps artificiais'
### AUC e TSS dos modelos
##multitemporal, spHW
spHWmulti = read.csv(paste(projectFolder,'/maxent/multitemporal/spHW/StatisticalResults-spHW.csv', sep=''), header=TRUE)
##multitemporal, spCD
spCDmulti = read.csv(paste(projectFolder,'/maxent/multitemporal/spCD/StatisticalResults-spCD.csv', sep=''), header=TRUE)
##monotemporal, spHW
spHWmono = read.csv(paste(projectFolder,'/maxent/monotemporal/spHW/StatisticalResults-spHW.csv', sep=''), header=TRUE)
##monotemporal, spCD
spCDmono = read.csv(paste(projectFolder,'/maxent/monotemporal/spCD/StatisticalResults-spCD.csv', sep=''), header=TRUE)
## boxplots modelo X AUC e TSS, dados totais
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplotModelos&Acuracia_dadosTotais.jpeg', width=800)
par(mfrow=c(1,2), las=2, mar=c(8,5,1,1), cex=1.3)
boxplot(rbind(spHWmulti,spCDmulti,spHWmono,spCDmono)$AUC ~ rbind(spHWmulti,spCDmulti,spHWmono,spCDmono)$modelType, ylim=c(0,1), ylab='AUC')
boxplot(rbind(spHWmulti,spCDmulti,spHWmono,spCDmono)$TSS ~ rbind(spHWmulti,spCDmulti,spHWmono,spCDmono)$modelType, ylim=c(0,1), ylab='TSS')
dev.off()
##testes (ambos deram nao significativos)
kruskal.test( rbind(spHWmulti,spCDmulti,spHWmono,spCDmono)$AUC ~ rbind(spHWmulti,spCDmulti,spHWmono,spCDmono)$modelType )
kruskal.test( rbind(spHWmulti,spCDmulti,spHWmono,spCDmono)$TSS ~ rbind(spHWmulti,spCDmulti,spHWmono,spCDmono)$modelType )
## boxplots modelo X AUC e TSS, especies
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplotModelos&Acuracia_sps.jpeg', height=600)
par(mfrow=c(2,2), las=2, mar=c(8,5,2,1), cex=1.1)
boxplot(rbind(spHWmulti,spHWmono)$AUC ~ rbind(spHWmulti,spHWmono)$modelType, ylim=c(0,1), ylab=c('AUC'), main='HW species')
boxplot(rbind(spCDmulti,spCDmono)$AUC ~ rbind(spCDmulti,spCDmono)$modelType, ylim=c(0,1), ylab=c('AUC'), main='CD species')
boxplot(rbind(spHWmulti,spHWmono)$TSS ~ rbind(spHWmulti,spHWmono)$modelType, ylim=c(0,1), ylab=c('TSS'), main='HW species')
boxplot(rbind(spCDmulti,spCDmono)$TSS ~ rbind(spCDmulti,spCDmono)$modelType, ylim=c(0,1), ylab=c('TSS'), main='CD species')
dev.off()
##testes (todos deram nao significativos)
kruskal.test(rbind(spHWmulti,spHWmono)$AUC ~ rbind(spHWmulti,spHWmono)$modelType)
kruskal.test(rbind(spCDmulti,spCDmono)$AUC ~ rbind(spCDmulti,spCDmono)$modelType)
kruskal.test(rbind(spHWmulti,spHWmono)$TSS ~ rbind(spHWmulti,spHWmono)$modelType)
kruskal.test(rbind(spCDmulti,spCDmono)$TSS ~ rbind(spCDmulti,spCDmono)$modelType)
## boxplots sp X AUC e TSS, dados totais
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplotSps&Acuracia.jpeg')
par(mfrow=c(2,2), mar=c(3,4,5,1),cex=1.1)
boxplot(rbind(spHWmulti,spCDmulti)$AUC ~ rbind(spHWmulti,spCDmulti)$sp, ylim=c(0,1), ylab=c('AUC'), main='Multitemporal')
boxplot(rbind(spHWmono,spCDmono)$AUC ~ rbind(spHWmono,spCDmono)$sp, ylim=c(0,1), ylab=c('AUC'), main='Monotemporal')
boxplot(rbind(spHWmulti,spCDmulti)$TSS ~ rbind(spHWmulti,spCDmulti)$sp, ylim=c(0,1), ylab=c('TSS'), main='Multitemporal')
boxplot(rbind(spHWmono,spCDmono)$TSS ~ rbind(spHWmono,spCDmono)$sp, ylim=c(0,1), ylab=c('TSS'), main='Monotemporal')
dev.off()
##teste (tanto para AUC quanto para TSS, deu diferenca significativa apenas para SDMmulti, e nao para SDMmono)
kruskal.test(rbind(spHWmulti,spCDmulti)$AUC ~ rbind(spHWmulti,spCDmulti)$sp)
kruskal.test(rbind(spHWmono,spCDmono)$AUC ~ rbind(spHWmono,spCDmono)$sp)
kruskal.test(rbind(spHWmulti,spCDmulti)$TSS ~ rbind(spHWmulti,spCDmulti)$sp)
kruskal.test(rbind(spHWmono,spCDmono)$TSS ~ rbind(spHWmono,spCDmono)$sp)
## boxplots sampleSize X AUC e TSS, dados totais
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplotSampleSize&Acuracia_dadosTotais.jpeg')
par(mfrow=c(2,2))
boxplot(rbind(spHWmulti,spCDmulti)$AUC ~ rbind(spHWmulti,spCDmulti)$sampleSize, ylim=c(0,1), ylab='AUC', main='Multitemporal')
boxplot(rbind(spHWmono,spCDmono)$AUC ~ rbind(spHWmono,spCDmono)$sampleSize, ylim=c(0,1), ylab='AUC', main='Monotemporal')
boxplot(rbind(spHWmulti,spCDmulti)$TSS ~ rbind(spHWmulti,spCDmulti)$sampleSize, ylim=c(0,1), ylab='TSS', main='Multitemporal')
boxplot(rbind(spHWmono,spCDmono)$TSS ~ rbind(spHWmono,spCDmono)$sampleSize, ylim=c(0,1), ylab='TSS', main='Monotemporal')
dev.off()
## boxplots sampleSize X AUC, especies
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplotSampleSize&Acuracia_spHW.jpeg')
par(mfrow=c(2,2), mar=c(3,4,5,1))
boxplot(rbind(spHWmulti)$AUC ~ rbind(spHWmulti)$sampleSize, ylim=c(0,1), ylab='AUC', main='Multitemporal')
boxplot(rbind(spHWmono)$AUC ~ rbind(spHWmono)$sampleSize, ylim=c(0,1), ylab='AUC', main='Monotemporal')
boxplot(rbind(spHWmulti)$TSS ~ rbind(spHWmulti)$sampleSize, ylim=c(0,1), ylab='TSS', main='Multitemporal')
boxplot(rbind(spHWmono)$TSS ~ rbind(spHWmono)$sampleSize, ylim=c(0,1), ylab='TSS', main='Monotemporal')
title('spHW', outer=TRUE, line=-1)
dev.off()
## boxplots modelo X AUC, especies
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplotSampleSize&Acuracia_spCD.jpeg')
par(mfrow=c(2,2), mar=c(3,4,5,1))
boxplot(rbind(spCDmulti)$AUC ~ rbind(spCDmulti)$sampleSize, ylim=c(0,1), ylab='AUC', main='Multitemporal')
boxplot(rbind(spCDmono)$AUC ~ rbind(spCDmono)$sampleSize, ylim=c(0,1), ylab='AUC', main='Monotemporal')
boxplot(rbind(spCDmulti)$TSS ~ rbind(spCDmulti)$sampleSize, ylim=c(0,1), ylab='TSS', main='Multitemporal')
boxplot(rbind(spCDmono)$TSS ~ rbind(spCDmono)$sampleSize, ylim=c(0,1), ylab='TSS', main='Monotemporal')
title('spCD', outer=TRUE, line=-1)
dev.off()
### Sobreposicao de nicho
outputData = read.csv(file=paste(projectFolder,'/maxent/output.csv',sep=''), header=TRUE)
##outputData = read.csv(file=paste(projectFolder,'/Resultados Lorien/output.csv',sep=''),header=TRUE)
##outputData = read.csv(file=paste(projectFolder,'/maxent/output_uni.csv',sep=''), header=TRUE)
#vetor.nomes = append(vetor.nomes,paste(spsTypes[i],sep=''))
## Schoener e Hellinger para resultados totais
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplotDadosTotais.jpeg', width=600)
par(mfrow=c(1,2), mar=c(8,3,3,1), cex=1.4, las=2)
boxplot(outputData$Schoeners_D_simi~ outputData$sdmType, ylim=c(0,1), main="Schoeners' D")
boxplot(outputData$Hellinger_I_simi~ outputData$sdmType, ylim=c(0,1), main='Hellinger')
dev.off()
##testes (nao houve diferencas significativas pra nenhum)
kruskal.test(Schoeners_D_simi ~ sdmType, data = outputData)
kruskal.test(Hellinger_I_simi ~ sdmType, data = outputData)
## bosplots das sps
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplotSps.jpeg', height=650)
par(mfrow=c(2,2), mar=c(7,4.5,6,1), cex=1.1, las=2)# cex.axis=2.5, cex.lab=3, cex.main=3)
boxplot(outputData[outputData$sp == 'spHW',]$Schoeners_D_simi ~ outputData[outputData$sp == 'spHW',]$sdmType, ylim=c(0,1), ylab="Schoener's D", main='HW species')
boxplot(outputData[outputData$sp == 'spHW',]$Hellinger_I_simi ~ outputData[outputData$sp == 'spHW',]$sdmType, ylim=c(0,1), ylab="Hellinger", main='HW species')
boxplot(outputData[outputData$sp == 'spCD',]$Schoeners_D_simi ~ outputData[outputData$sp == 'spCD',]$sdmType, ylim=c(0,1), ylab="Schoener's D", main='CD species')
boxplot(outputData[outputData$sp == 'spCD',]$Hellinger_I_simi ~ outputData[outputData$sp == 'spCD',]$sdmType, ylim=c(0,1), ylab="Hellinger", main='CD species')
dev.off()
##testes (nenhuma diferenca significativa)
kruskal.test(outputData[outputData$sp == 'spHW',]$Schoeners_D_simi ~ outputData[outputData$sp == 'spHW',]$sdmType)
kruskal.test(outputData[outputData$sp == 'spHW',]$Hellinger_I_simi ~ outputData[outputData$sp == 'spHW',]$sdmType)
kruskal.test(outputData[outputData$sp == 'spCD',]$Schoeners_D_simi ~ outputData[outputData$sp == 'spCD',]$sdmType)
kruskal.test(outputData[outputData$sp == 'spCD',]$Hellinger_I_simi ~ outputData[outputData$sp == 'spCD',]$sdmType)
## Densidade para dados totais
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/densidadeDadosTotais.jpeg', width=600, height = 400)
par(mfrow=c(1,2), lwd=2, cex=1)
plot(density(outputData[outputData$sdmType == 'multitemporal',]$Schoeners_D_simi),ylim=c(0,5), lwd=2, col='red', main='', xlab="Schoener's D", ylab='Density')
lines(density(outputData[outputData$sdmType == 'monotemporal',]$Schoeners_D_simi), lwd=2)
#
plot(density(outputData[outputData$sdmType == 'multitemporal',]$Hellinger_I_simi),ylim=c(0,5), lwd=2, col='red', main='', xlab='Hellinger', ylab='Density')
lines(density(outputData[outputData$sdmType == 'monotemporal',]$Hellinger_I_simi), lwd=2)
##
legend(x='topright', legend=c('Multitemporal calibration', 'Monotemporal calibration'), lty=1, col=c('red','black'), bty='n')
dev.off()
## Densidade para as sps
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/densidade_sps.jpeg')
par(mfrow=c(2,2), mar=c(5,4,3,1), lwd=2, cex=1)
#
plot(density(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$Schoeners_D_simi),ylim=c(0,7), lwd=2, col='red', main='HW species', xlab="Schoener's D", ylab='Density')
lines(density(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW',]$Schoeners_D_simi), lwd=2)
#
plot(density(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$Hellinger_I_simi),ylim=c(0,5), lwd=2, col='red', main='HW species', xlab="Hellinger", ylab='Density')
lines(density(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW',]$Hellinger_I_simi), lwd=2)
legend(x='topright', legend=c('Multitemporal calibration', 'Monotemporal calibration'), lty=1, col=c('red','black'), bty='n', cex=0.8)
#
plot(density(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$Schoeners_D_simi),ylim=c(0,5), lwd=2, col='red', main='CD species', xlab="Schoener's D", ylab='Density')
lines(density(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD',]$Schoeners_D_simi), lwd=2)
#
plot(density(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$Hellinger_I_simi),ylim=c(0,5), col='red', lwd=2, main='CD species', xlab="Hellinger", ylab='Density')
lines(density(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD',]$Hellinger_I_simi), lwd=2)
dev.off()
## Schoener e Hellinger no tempo
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/Shoener&HellingerXtempo.jpeg',width=600, height=600)
par(mfrow=c(2,2), mar=c(4,4,4,1), cex=1.2)
plot(outputData[outputData$sdmType == 'multitemporal',]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal',]$kyrBP),type='p',ylab="Schoeners' D", xlab="Time (kyr BP)", ylim=c(0,1), col=rgb(0,0,0,alpha=0.5), main='Multitemporal')
#
plot(outputData[outputData$sdmType == 'multitemporal',]$Hellinger_I_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal',]$kyrBP),type='p',ylab="Hellinger",xlab="Time (kyr BP)",ylim=c(0,1),col=rgb(0,0,0,alpha=0.5), main='Multitemporal')
#
plot(outputData[outputData$sdmType == 'monotemporal',]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'monotemporal',]$kyrBP),type='p',ylab="Schoeners' D",xlab="Time (kyr BP)",ylim=c(0,1),col=rgb(0,0,0,alpha=0.5), main='Monotemporal')
#
plot(outputData[outputData$sdmType == 'monotemporal',]$Hellinger_I_simi ~ as.factor(outputData[outputData$sdmType == 'monotemporal',]$kyrBP),type='p',ylab="Hellinger",xlab="Time (kyr BP)",ylim=c(0,1),col=rgb(0,0,0,alpha=0.5), main='Monotemporal')
dev.off()
## Shoener e Hellinger no tempo - sps
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/Shoener&HellingerXtempo_sps.jpeg', width=1200, height=1200)
par(mfrow=c(2,2), pch=1, mar=c(7,7,3,3), cex=1.5, cex.lab=2, cex.axis=2, cex.main=2)
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='HW species', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$Hellinger_I_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$kyrBP),type='p',ylab="Hellinger",xlab="Time (kyr BP)", main='HW species',ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$kyrBP),type='p',ylab="Schoeners' D",xlab="Time (kyr BP)", main='CD species', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$Hellinger_I_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$kyrBP),type='p',ylab="Hellinger",xlab="Time (kyr BP)", main='CD species',ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
dev.off()
## Schoener X sample size X tempo - spHW
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/SchoenerXtempoXsample_spHW.jpeg', width=1200, height=1200)
par(mfrow=c(3,2), pch=1, mar=c(7,7,3,3), cex=1.5, cex.lab=2, cex.axis=2, cex.main=2)
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 10,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 10,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='10 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 10,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 10,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='10 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 50,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 50,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='50 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 50,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 50,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='50 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 100,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 100,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='100 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 100,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW' & outputData$sampleSize == 100,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='100 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
dev.off()
## Schoener X sample size X tempo - spCD
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/SchoenerXtempoXsample_spCD.jpeg', width=1200, height=1200)
par(mfrow=c(3,2), pch=1, mar=c(7,7,3,3), cex=1.5, cex.lab=2, cex.axis=2, cex.main=2)
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 10,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 10,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='10 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 10,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 10,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='10 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 50,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 50,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='50 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 50,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 50,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='50 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 100,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 100,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='100 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
#
plot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 100,]$Schoeners_D_simi ~ as.factor(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD' & outputData$sampleSize == 100,]$kyrBP),type='p',ylab="Schoener's D",xlab="Time (kyr BP)", main='100 pts', ylim=c(0,1), col=rgb(0,0,0,alpha=0.5))
dev.off()
## Tamanho amostral - dados totais
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplot_sampleSize_dadosTotais.jpeg', width=800, height=900)
par(mfrow=c(2,2), cex=1.5)
boxplot(outputData[outputData$sdmType == 'multitemporal',]$Schoeners_D_simi~ outputData[outputData$sdmType == 'multitemporal',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Schoeners' D", main='Multitemporal')
boxplot(outputData[outputData$sdmType == 'monotemporal',]$Schoeners_D_simi ~ outputData[outputData$sdmType == 'monotemporal',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Schoeners' D", main='Monotemporal')
boxplot(outputData[outputData$sdmType == 'multitemporal',]$Hellinger_I_simi ~ outputData[outputData$sdmType == 'multitemporal',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Hellinger", main='Multitemporal')
boxplot(outputData[outputData$sdmType == 'monotemporal',]$Hellinger_I_simi ~ outputData[outputData$sdmType == 'monotemporal',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Hellinger", main='Monotemporal')
dev.off()
## Tamanho amostral - spHW
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplot_sampleSize_spHW.jpeg', width=800, height=900)
par(mfrow=c(2,2), cex=1.5)
boxplot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$Schoeners_D_simi ~ outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Schoener's D", main='Multitemporal')
boxplot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW',]$Schoeners_D_simi ~ outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Schoener's D", main='Monotemporal')
boxplot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$Hellinger_I_simi ~ outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Hellinger", main='Multitemporal')
boxplot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW',]$Hellinger_I_simi ~ outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spHW',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Hellinger", main='Monotemporal')
dev.off()
## Tamanho amostral - spCD
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplot_sampleSize_spCD.jpeg', width=800, height=900)
par(mfrow=c(2,2), cex=1.5)
boxplot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$Schoeners_D_simi ~ outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Schoeners' D", main='Multitemporal')
boxplot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD',]$Schoeners_D_simi ~ outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Schoener's D", main='Monotemporal')
boxplot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$Hellinger_I_simi ~ outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Hellinger", main='Multitemporal')
boxplot(outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD',]$Hellinger_I_simi ~ outputData[outputData$sdmType == 'monotemporal' & outputData$sp == 'spCD',]$sampleSize, ylim=c(0,1), xlab='Sample Size', ylab="Hellinger", main='Monotemporal')
dev.off()
## Shoener's D e Hellinger X número de camadas no SDMmultitemporal
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/boxplot_NumberOfTimeLayers.jpeg', height=1000, width=600)
par(mfrow=c(3,2), cex=1.3)
boxplot(outputData[outputData$sdmType == 'multitemporal',]$Schoeners_D_simi ~ outputData[outputData$sdmType == 'multitemporal',]$numbOfTimeLayers, xlab='Number of time layers', ylab="Schoener's D", main='Full dataset')
##
boxplot(outputData[outputData$sdmType == 'multitemporal',]$Hellinger_I_simi ~ outputData[outputData$sdmType == 'multitemporal',]$numbOfTimeLayers, xlab='Number of time layers', ylab="Hellinger", main='Full dataset')
##
boxplot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$Schoeners_D_simi~ outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$numbOfTimeLayers, xlab='Number of time layers', ylab="Schoener's D", main='HW species')
##
boxplot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$Hellinger_I_simi~ outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spHW',]$numbOfTimeLayers, xlab='Number of time layers', ylab="Hellinger", main='HW species')
##
boxplot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$Schoeners_D_simi~ outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$numbOfTimeLayers, xlab='Number of time layers', ylab="Schoener's D", main='CD species')
##
boxplot(outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$Hellinger_I_simi~ outputData[outputData$sdmType == 'multitemporal' & outputData$sp == 'spCD',]$numbOfTimeLayers, xlab='Number of time layers', ylab="Hellinger", main='CD species')
dev.off()
##graficos para clamping
projectFolder = "/home/anderson/Projetos/Sps artificiais/"
sdmTypes = c("multitemporal", "monotemporal")
spsTypes = c("spHW", "spCD")
sampleSizes = c(10, 50, 100)
numRep = 5
clampList = list()
territory = list()
for(h in 1:length(sdmTypes)){
for(i in 1:length(spsTypes)){
for(m in 1:length(sampleSizes)){
for(n in 1:numRep){
for(l in 1:24){
##mapa de clamping
sdmClampPath = paste(projectFolder,'maxent/',sdmTypes[h],'/',spsTypes[i],'/',spsTypes[i],'.sample',sampleSizes[m],'.replica',n,'/proj_',l-1,'kyr/','proj_',l-1,'kyr_ClampingMask.grd',sep='') #caminho do mapa de suitability gerado por SDM
clampLayer_i = raster(sdmClampPath)
scenName = paste(sdmTypes[h],'_proj_',l-1,'kyr_',spsTypes[i],'.sample',sampleSizes[m],'.replica',n,sep='')
clampList[[scenName]] = clampLayer_i
clamping = (sum(getValues(clampLayer_i)>0, na.rm=TRUE)/ncell(getValues(clampLayer_i))) * 100
##mapa de distribuicao da especie
sdmDistPath = paste(projectFolder,'maxent/',sdmTypes[h],'/',spsTypes[i],'/',spsTypes[i],'.sample',sampleSizes[m],'.replica',n,'/proj_',l-1,'kyr/','proj_',l-1,'kyr_',spsTypes[i],'.sample',sampleSizes[m],'.replica',n,'_TSSbin.grd',sep='') #caminho do mapa de suitability gerado por SDM
distLayer_i = raster(sdmDistPath)
##calculo da porporcao de clamping na area de distribuicao modelada
distUnderClamp = (clampLayer_i + distLayer_i)==2
distUnderClamp = ( freq(distUnderClamp, value=1)/sum(freq(distUnderClamp)[1:2,2]) ) * 100
##tabela de dados final
outputDF = outputData[ which(outputData$sdmType==sdmTypes[h] & outputData$sp==spsTypes[i] & outputData$sampleSize==sampleSizes[m] & outputData$replicate==n & outputData$kyrBP==l-1 ), ]
if(nrow(outputDF)>0){
territory[[scenName]] = data.frame( outputDF,
clamping = clamping,
distUnderClamp = distUnderClamp )
}
}
}
}
}
}
##tranformando a lista em stack de gridfiles
clampStack = stack(clampList)
##multitemporal
##todos os mapas de clamping - multitemporal, spHW, sample 10 pts (todos as camadas temporais)
scenNames = grep(pattern='^multitemporal.*spHW.*sample10.*replica1', x=names(clampStack), value=TRUE) #separando os nomes
scenNames = grep(pattern='^multitemporal.*spHW.*sample100.*replica1', x=scenNames, value=TRUE, invert=TRUE) #separando os nomes
clampStack[[scenNames]] = mask(clampStack[[scenNames]], AmSulShape)
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/Clamping/clamp_Multitemporal_SpHW_sample10_replica1.jpg', width=1000, height=1100)
rasterVis::levelplot(clampStack[[scenNames[1:23]]],
col.regions=colorRampPalette(c("lightgrey","red")),
main='spHW, sample size = 10',
names.attr=c(paste('spHW ',0:22,'kyr BP',sep='')))
dev.off()
##todos os mapas de clamping - multitemporal, spCD, sample 10 pts (todos as camadas temporais)
scenNames = grep(pattern='^multitemporal.*spCD.*sample10.*replica1', x=names(clampStack), value=TRUE) #separando os nomes
scenNames = grep(pattern='^multitemporal.*spCD.*sample100.*replica1', x=scenNames, value=TRUE, invert=TRUE) #separando os nomes
clampStack[[scenNames]] = mask(clampStack[[scenNames]], AmSulShape)
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/Clamping/clamp_Multitemporal_SpCD_sample10_replica1.jpg', width=1000, height=1100)
rasterVis::levelplot(clampStack[[scenNames[1:23]]],
col.regions=colorRampPalette(c("lightgrey","red")),
main='spCD, sample size = 10',
names.attr=c(paste('CD sp. ',0:22,'kyr BP',sep='')))
dev.off()
##todos os mapas de clamping - multitemporal, spHW, sample 50 pts (todos as camadas temporais)
scenNames = grep(pattern='^multitemporal.*spHW.*sample50.*replica1', x=names(clampStack), value=TRUE) #separando os nomes
clampStack[[scenNames]] = mask(clampStack[[scenNames]], AmSulShape)
jpeg('/home/anderson/Documentos/Projetos/Sps artificiais/graficos - resultados oficiais/Clamping/clamp_Multitemporal_SpHW_sample50_replica1.jpg', width=1000, height=1100)
rasterVis::levelplot(clampStack[[scenNames[1:23]]],
col.regions=colorRampPalette(c("lightgrey","red")),
main='spHW, sample size = 50',
names.attr=c(paste('HW sp. ',0:22,'kyr BP',sep='')))
dev.off()