-
Notifications
You must be signed in to change notification settings - Fork 0
/
dissertation-script-alces.R
2731 lines (2225 loc) · 172 KB
/
dissertation-script-alces.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
# Sample script to allow reproduction of my dissertation data
# Chapter 1 script
# jfb
# 19 jan 2022
# For your convenience this script has been outlined.
# This script was written for a single species, H.alces, and not for the nine species in the study
# This is an example, and some of the plot and analyses require the data results of different species, not written here
# These not runnable codes are presented, and we explain how to build the data to fit them
# This was a conscious choice
#rm(list = ls()) # clear the environment
path <- "~/Documents/Mestrado/" # set your main directory
setwd(path)
# Libraries ####
library(raster)
library(dplyr)
library(psych)
library(rgeos)
library(rgdal)
library(mapview)
library(sp)
library(sf)
library(maptools)
library(sdm)
library(tidyverse)
library(shapefiles)
library(mraster)
library(CoordinateCleaner)
library(tmap)
library(rworldmap)
library(corrplot)
library(RColorBrewer)
# Load and Prepare Data ####
## Occurrence Data ####
setwd('Occ_Data/Datasets') # path to where your occurrence data are
occ<-read.csv('occ_dataset.csv') # read occurrence data with collumns in DwC (GBIF) standard
occ <- filter(occ,specificEpithet == "alces") # this script will be written only for the species Heterophrynus alces, for simplicity. Comment this line out or include the name of other species if needed.
occ <- filter(occ,coordinateUncertaintyInMeters <=10000) # filtering occurrence data to 10km - the same resolution as our Environmental Data
occ <- as_tibble(occ) # transform to tibble
occ <- dplyr::select(occ,specificEpithet,decimalLatitude,decimalLongitude,coordinateUncertaintyInMeters) # Selecting only needed information
names(occ) <- c("species","lat","lon","uncertainty") # Renaming collumns for simplicity
sp <- as_tibble(occ) # we'll manipulate this object from now on, and leave the raw occ object in the environment in case we need it later
### Cleaning the coordinates #####
flags_spatial <- CoordinateCleaner::clean_coordinates(
x = sp,
species = "species",
lon = "lon",
lat = "lat",
tests = c("capitals", # radius around capitals
"centroids", # radius around countries and provinces centroids
"duplicates", # duplicates
"equal", # equal coordinates
"gbif", # radius around GBIF headquarters
#"institutions", # radius around biodiversity research institutions
"seas", # points on the ocean
#"urban", # points inside urban areas
"validity", # points outside the coordinate system
"zeros" # zeros e points where lat = lon
)
)
# the result flags problematic points
#' TRUE = "clean" coordinates
#' FALSE = potentially problematic coordinates
flags_spatial %>% head
summary(flags_spatial)
# removing flagged coords
occ_data_tax_date_spa <- sp %>%
dplyr::filter(flags_spatial$.summary == TRUE)
occ_data_tax_date_spa
# exporting the clean coordinates as a csv
setwd(path) ; dir.create('Script_output_files') ; setwd('Script_output_files') ; dir.create('Occ') ; setwd('Occ')
readr::write_csv(occ_data_tax_date_spa, paste0("alces.csv"))
### Making SpatialPoints object and .shp #####
# Ok. Now, before we continue, we need to transform our sp dataframe into
# a Spatial Points Dataframe. To do so, we need to tell R in which rows
# are our coordinates data:
#sp <- read.csv("alces.csv") # uncomment if you're running this part of the script separately, otherwise
coordinates(sp) <- ~lon + lat #same syntax as columns (see line 34)
proj4string(sp) <- projection(raster()) #assigning WGS84 projection
# now check class(sp), should read SpatialPointsDataFrame
#Now, we have presence only data and the species data has been loaded and cleaned.
writeOGR(obj=sp, dsn="alces.shp", layer=c("species","uncertainty"), driver="ESRI Shapefile") # to create a shapefile with cleaned occurrences
## Environmental Data ####
setwd(path)
setwd('Analises/Chapter1/0-RawEnvlayers') #path to your environmenatal datasets
setwd("BIOLCIM_wc2.1_5m_bio_download19aug2021") #bioclim layers folder
bioclimRaw <- dir(pattern = "tif$")
bioclimRaw <- raster::stack(bioclimRaw)
setwd('..') #one folder up
setwd("ENVIREM_NewWorld_current_5arcmin_generic_download19aug2021") #envirem layers folder
enviremRaw <- dir(pattern = "bil$")
enviremRaw <- raster::stack(enviremRaw)
setwd('..')
setwd("MERRA_5m_mean_00s_download19aug2021") #merraclim layers folder
merraRaw <- dir(pattern = "tif$")
merraRaw <- raster::stack(merraRaw)
# because MERRA resolution is more accurate (0.08333333) than Bioclim and ENVIREM (0.08331), we need to resample it to match the latter ones in order to compare the three
# But this will take a lot of machine time, so first, we'll crop the objects by the extents of South America, which is the region we're interested in:
plot(bioclimRaw[[1]])
extent <- drawExtent() # here I cropped to south america and these are the results:
#class: Extent xmin: -87.8773 xmax: -32.56272 ymin: -126.0932 ymax: 40.18543
# this process does not need to be perfect, we're just interested in reducing the layers for faster computation
bioclimsa <- raster::crop(bioclimRaw,extent)
enviremsa <- raster::crop(enviremRaw,extent)
merrasa <- raster::crop(merraRaw,extent)
setwd(path) ; setwd('Script_output_files') ; dir.create('Env') ; setwd('Env')
enviremsa <- raster::resample(enviremsa,bioclimsa)
merrasa <- raster::resample(merrasa,bioclimsa) # to solve the problem mentioned on line 108
### Correlation ####
#### Bioclim ####
dir.create('Bioclim') ; setwd('Bioclim')
# extracting the values
bioclim_da <- bioclimsa %>% #bioclim_da = adjusted dimension
raster::values() %>%
tibble::as_tibble() %>%
tidyr::drop_na()
# Correlation using Spearman method
cor_table_bioclim <- corrr::correlate(bioclim_da, method = "spearman")
# Creating a table with the results
cor_table_bioclim_summary <- cor_table_bioclim %>%
corrr::shave() %>%
corrr::fashion()
# And exporting it
readr::write_csv(cor_table_bioclim_summary, "correlacao.csv")
#### Envirem ####
setwd('..')
dir.create('Envirem') ; setwd('Envirem')
# extracting the values
envirem_da <- enviremsa %>% #envirem_da = adjusted dimension
raster::values() %>%
tibble::as_tibble() %>%
tidyr::drop_na()
# Correlation using Spearman method
cor_table_envirem <- corrr::correlate(envirem_da, method = "spearman")
# Creating a table with the results
cor_table_envirem_summary <- cor_table_envirem %>%
corrr::shave() %>%
corrr::fashion()
# And exporting it
readr::write_csv(cor_table_envirem_summary, "correlacao.csv")
#### Merraclim ####
setwd('..')
dir.create('Merra') ; setwd('Merra')
# extracting the values
envirem_da <- enviremsa %>% #envirem_da = adjusted dimension
raster::values() %>%
tibble::as_tibble() %>%
tidyr::drop_na()
# Correlation using Spearman method
cor_table_envirem <- corrr::correlate(envirem_da, method = "spearman")
# Creating a table with the results
cor_table_envirem_summary <- cor_table_envirem %>%
corrr::shave() %>%
corrr::fashion()
# And exporting it
readr::write_csv(cor_table_envirem_summary, "correlacao.csv")
#### Correlation between datasets' variables ####
setwd('..')
# to check correlation between the dataset variables, I'll first select only the variables I chose based on the correlation done before, these are: bio2,3,5 and 15 for Bioclim, bio2,3,5 and 8 for Merraclim and annualPET,aridityIndex,climaticMoistureIndex and thermicityIndex for ENVIREM
bioclimsa@data@names # to see the positions of the layers I need to drop
bioclimsa <- dropLayer(bioclimsa,c(1,2,3,4,5,6,8,9,10,11,14,16,17,18,19))
enviremsa@data@names # to see the positions of the layers I need to drop
enviremsa <- dropLayer(enviremsa,c(4,5,6,7,8,9,10,11,12,13,14,15))
merrasa@data@names # to see the positions of the layers I need to drop
merrasa <- dropLayer(merrasa,c(1,2,3,4,5,6,7,8,9,10,11,14,16,17,19))
# So we don't confuse bioclim and merra layers:
names(bioclimsa) <- c('bio15-bioclim','bio2-bioclim','bio3-bioclim','bio5-bioclim')
names(merrasa) <- c('bio2-merra','bio3-merra','bio5-merra','bio8-merra')
names(enviremsa) <- c('annualPET-envirem','aridityIndex-envirem','climaticMoisture-envirem','thermicityIndex-envirem')
env <- raster::stack(bioclimsa,enviremsa,merrasa) #put them all in a single object and run the same calculations as the previous sections
env_da <- env %>% #env_da = adjusted dimension
raster::values() %>%
tibble::as_tibble() %>%
tidyr::drop_na()
# Correlation using Spearman method
cor_table_env <- corrr::correlate(env_da, method = "spearman")
cor_table_env
# Creating a table with the results
cor_table_env_summary <- cor_table_env %>%
corrr::shave() %>%
corrr::fashion()
# And exporting it
readr::write_csv(cor_table_env_summary, "correlacao.csv")
# Selecting correlate variables
fi_75_env <- cor_table_env %>%
corrr::as_matrix() %>%
caret::findCorrelation(cutoff = .75, names = TRUE, verbose = TRUE) #chose 75% correlation as a threshold
fi_75_env #listing the correlate variables, roughness does not correlate with anything which I didn't expect
env_da_cor75 <- env_da %>% ###excluding correlate variables
dplyr::select(-fi_75_env)
env_da_cor75
# Checking the selected variables
env_da_cor75 %>%
corrr::correlate(method = "spearman") %>%
corrr::as_matrix() %>%
caret::findCorrelation(cutoff = .75, names = TRUE, verbose = TRUE)
# Correlation Plot
tiff("correlacao_plot.tiff", wi = 30, he = 25, un = "cm", res = 300, comp = "lzw")
pairs.panels(x = env_da_cor75 %>% dplyr::sample_n(1e3),
method = "spearman",
pch = 20,
ellipses = FALSE,
density = FALSE,
stars = TRUE,
hist.col = "gray",
digits = 2,
rug = FALSE,
breaks = 10,
ci = TRUE)
dev.off()
### Save Cropped, Selected (uncorrelated) Layers ####
# One final step: saving the selected, cropped layers on disk
setwd('Bioclim')
raster::writeRaster(x = bioclimsa,
filename = paste0("", names(bioclimsa)),
bylayer = TRUE,
options = c("COMPRESS=DEFLATE"),
format = "GTiff",
overwrite = TRUE)
setwd('..')
setwd("Merra")
raster::writeRaster(x = merrasa,
filename = paste0("", names(merrasa)),
bylayer = TRUE,
options = c("COMPRESS=DEFLATE"),
format = "GTiff",
overwrite = TRUE)
setwd('..')
setwd("Envirem")
raster::writeRaster(x = enviremsa,
filename = paste0("", names(enviremsa)),
bylayer = TRUE,
options = c("COMPRESS=DEFLATE"),
format = "GTiff",
overwrite = TRUE)
## Make Different M sizes for Env Datasets ####
# To make a Small M (sm), a medium M (mm) and a large M (here, bm) model for each dataset and algorithm, we start by defining the M size based on the distribution of occ records, like so:
radiussm <- 0.5 #1=100km
radiusmm <- 1
radiusbm <- 1.5 # bm = big M, same as LM or large model
#generating polygons around points:
occ.buffer.sm <- gBuffer(spgeom = sp, byid = T, # sm = small M
width = radiussm, quadsegs = 100,
capStyle = 'ROUND' , joinStyle = 'ROUND')
occ.buffer.mm <- gBuffer(spgeom = sp, byid = T, # mm = medium M
width = radiusmm, quadsegs = 100,
capStyle = 'ROUND' , joinStyle = 'ROUND')
occ.buffer.bm <- gBuffer(spgeom = sp, byid = T, # bm = big M
width = radiusbm, quadsegs = 100,
capStyle = 'ROUND' , joinStyle = 'ROUND')
#making it a single polygon
occ.buffer.sm <- aggregate(occ.buffer.sm,dissolve=T)
occ.buffer.mm <- aggregate(occ.buffer.mm,dissolve=T)
occ.buffer.bm <- aggregate(occ.buffer.bm,dissolve=T)
# Now, make the nine env datasets:
bio.sm <- raster::crop(x = bioclimsa, y = occ.buffer.sm)
bio.mm <- raster::crop(x = bioclimsa, y = occ.buffer.mm)
bio.bm <- raster::crop(x = bioclimsa, y = occ.buffer.bm)
merra.sm <- raster::crop(x = merrasa, y = occ.buffer.sm)
merra.mm <- raster::crop(x = merrasa, y = occ.buffer.mm)
merra.bm <- raster::crop(x = merrasa, y = occ.buffer.bm)
envirem.sm <- raster::crop(x = enviremsa, y = occ.buffer.sm)
envirem.mm <- raster::crop(x = enviremsa, y = occ.buffer.mm)
envirem.bm <- raster::crop(x = enviremsa, y = occ.buffer.bm)
# Modelling ####
setwd('..') ; setwd('..')
dir.create('M-preds') ; setwd('M-preds')
## Creating the Models + Predictions ####
## Ok now we have 3 clim datasets, with three different sizes, the next step is to apply SDMs to the three and compare them with Jimenez&Soberón's functions accum.occ and comp.accum (later section)
### Bioclim ####
# We need to remove all other collumns in the sp SpatialPointsDataFrame so the sdmData function can work
sp@data <- sp@data[1] #to remove uncertainty column
# Prepare Data for the sdm function:
d.bio.sm <- sdmData(formula = species~. , train = sp, predictors = bio.sm,
bg = list(n=200), method = 'gRandom')
d.bio.mm <- sdmData(formula = species~. , train = sp, predictors = bio.mm,
bg = list(n=200), method = 'gRandom')
d.bio.bm <- sdmData(formula = species~. , train = sp, predictors = bio.bm,
bg = list(n=200), method = 'gRandom')
# model
m.bio.sm <- sdm(formula = alces~.,
data = d.bio.sm, methods = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
replication = c('boot') , n = 10)
m.bio.mm <- sdm(formula = alces~.,
data = d.bio.mm, methods = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
replication = c('boot') , n = 10)
m.bio.bm <- sdm(formula = alces~.,
data = d.bio.bm, methods = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
replication = c('boot') , n = 10)
# prediction
p.bio.sm <- predict(m.bio.sm, bio.sm, 'predictions.bio.sm.img', mean = T, overwrite = T)
p.bio.mm <- predict(m.bio.mm, bio.mm, 'predictions.bio.mm.img', mean = T, overwrite = T)
p.bio.bm <- predict(m.bio.bm, bio.bm, 'predictions.bio.bm.img', mean = T, overwrite = T)
### Merraclim #####
## Same as above
# data
d.merra.sm <- sdmData(formula = species~. , train = sp, predictors = merra.sm,
bg = list(n=200), method = 'gRandom')
d.merra.mm <- sdmData(formula = species~. , train = sp, predictors = merra.mm,
bg = list(n=200), method = 'gRandom')
d.merra.bm <- sdmData(formula = species~. , train = sp, predictors = merra.bm,
bg = list(n=200), method = 'gRandom')
# model
m.merra.sm <- sdm(formula = alces~.,
data = d.merra.sm, methods = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
replication = c('boot') , n = 10)
m.merra.mm <- sdm(formula = alces~.,
data = d.merra.mm, methods = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
replication = c('boot') , n = 10)
m.merra.bm <- sdm(formula = alces~.,
data = d.merra.bm, methods = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
replication = c('boot') , n = 10)
# prediction
p.merra.sm <- predict(m.merra.sm, merra.sm, 'predictions.merra.sm.img', mean = T, overwrite = T)
p.merra.mm <- predict(m.merra.mm, merra.mm, 'predictions.merra.mm.img', mean = T, overwrite = T)
p.merra.bm <- predict(m.merra.bm, merra.bm, 'predictions.merra.bm.img', mean = T, overwrite = T)
### ENVIREM #####
# data
d.envirem.sm <- sdmData(formula = species~. , train = sp, predictors = envirem.sm,
bg = list(n=200), method = 'gRandom')
d.envirem.mm <- sdmData(formula = species~. , train = sp, predictors = envirem.mm,
bg = list(n=200), method = 'gRandom')
d.envirem.bm <- sdmData(formula = species~. , train = sp, predictors = envirem.bm,
bg = list(n=200), method = 'gRandom')
# model
m.envirem.sm <- sdm(formula = alces~.,
data = d.envirem.sm, methods = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
replication = c('boot') , n = 10)
m.envirem.mm <- sdm(formula = alces~.,
data = d.envirem.mm, methods = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
replication = c('boot') , n = 10)
m.envirem.bm <- sdm(formula = alces~.,
data = d.envirem.bm, methods = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
replication = c('boot') , n = 10)
# prediction
p.envirem.sm <- predict(m.envirem.sm, envirem.sm, 'predictions.envirem.sm.img', mean = T, overwrite = T)
p.envirem.mm <- predict(m.envirem.mm, envirem.mm, 'predictions.envirem.mm.img', mean = T, overwrite = T)
p.envirem.bm <- predict(m.envirem.bm, envirem.bm, 'predictions.envirem.bm.img', mean = T, overwrite = T)
## Evaluating the Models - AOcCs ####
# AUC, TSS and other statistics related to ENMs are all available in the M objects, easily accessible with the gui(m.bio.sm) function (for example)
# However, we want to analize the Accumulation of Occurrences Curve (AOcC), proposed by Jimenez & Soberon in 2020. <https://doi.org/10.1111/2041-210X.13479>
# For that, I modified the accum.occ function slightly to show method names on the plot titles. My version can be found at <https://github.com/jfberner/ENMs/blob/main/accum_curve_jfb.RData>
load("~/Documents/Mestrado/Analises/SDM-hyperTest-master/SDM-Hyper-Test-Master-Functions-Jul212021.RData") #original function from Jimenez's github
load("~/Documents/Mestrado/Analises/Model Comparison/accum_curve_jfb.RData") #my modified Jimenez&Soberon function with plot titles, loaded on top of the former to mask the accum.occ function
# We have to manipulate the data a bit to use the accum.occ and comp.accum functions from Laura Jimenez and Jorge Soberon
### Bioclim ####
#### sm ####
bd.bio.sm <- as.data.frame(bio.sm, row.names=NULL, na.rm=F,xy=F,long=F)
pd.bio.sm <- as.data.frame(p.bio.sm, row.names=NULL, na.rm=F,xy=T,long=F)
names(pd.bio.sm)<- c("long","lat","GLM","SVM","RF","BRT","MARS","MAXENT","MAXLIKE","GLMNET")
#GLM
pd.bio.sm.glm<-dplyr::select(pd.bio.sm,long,lat,GLM)
output.mod.bio.sm.glm<-cbind(pd.bio.sm.glm,bd.bio.sm)
occ.p_env.bio.sm <- raster::extract(bio.sm,sp,as.data.frame=T)
occ.p_preds.bio.sm.glm <- raster::extract(p.bio.sm[[1]],sp,as.data.frame=T)
occ.coords.bio.sm <- sp@coords
occ.pnts.bio.sm.glm <- cbind(occ.coords.bio.sm,occ.p_preds.bio.sm.glm,occ.p_env.bio.sm)
occ.pnts.bio.sm.glm <- as.data.frame(occ.pnts.bio.sm.glm)
occ.pnts.bio.sm.glm <-drop_na(occ.pnts.bio.sm.glm)
acc.bio.sm.glm<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.sm.glm,
occ.pnts = occ.pnts.bio.sm.glm,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
# SVM
pd.bio.sm.svm<-dplyr::select(pd.bio.sm,long,lat,SVM)
output.mod.bio.sm.svm<-cbind(pd.bio.sm.svm,bd.bio.sm)
occ.p_env.bio.sm <- raster::extract(bio.sm,sp,as.data.frame=T)
occ.p_preds.bio.sm.svm <- raster::extract(p.bio.sm[[2]],sp,as.data.frame=T)
occ.coords.bio.sm <- sp@coords
occ.pnts.bio.sm.svm <- cbind(occ.coords.bio.sm,occ.p_preds.bio.sm.svm,occ.p_env.bio.sm)
occ.pnts.bio.sm.svm <- as.data.frame(occ.pnts.bio.sm.svm)
occ.pnts.bio.sm.svm <-drop_na(occ.pnts.bio.sm.svm)
acc.bio.sm.svm<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.sm.svm,
occ.pnts = occ.pnts.bio.sm.svm,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#RF
pd.bio.sm.rf<-dplyr::select(pd.bio.sm,long,lat,RF)
output.mod.bio.sm.rf<-cbind(pd.bio.sm.rf,bd.bio.sm)
occ.p_env.bio.sm <- raster::extract(bio.sm,sp,as.data.frame=T)
occ.p_preds.bio.sm.rf <- raster::extract(p.bio.sm[[3]],sp,as.data.frame=T)
occ.coords.bio.sm <- sp@coords
occ.pnts.bio.sm.rf <- cbind(occ.coords.bio.sm,occ.p_preds.bio.sm.rf,occ.p_env.bio.sm)
occ.pnts.bio.sm.rf <- as.data.frame(occ.pnts.bio.sm.rf)
occ.pnts.bio.sm.rf <-drop_na(occ.pnts.bio.sm.rf)
acc.bio.sm.rf<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.sm.rf,
occ.pnts = occ.pnts.bio.sm.rf,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#BRT
pd.bio.sm.brt<-dplyr::select(pd.bio.sm,long,lat,BRT)
output.mod.bio.sm.brt<-cbind(pd.bio.sm.brt,bd.bio.sm)
occ.p_env.bio.sm <- raster::extract(bio.sm,sp,as.data.frame=T)
occ.p_preds.bio.sm.brt <- raster::extract(p.bio.sm[[4]],sp,as.data.frame=T)
occ.coords.bio.sm <- sp@coords
occ.pnts.bio.sm.brt <- cbind(occ.coords.bio.sm,occ.p_preds.bio.sm.brt,occ.p_env.bio.sm)
occ.pnts.bio.sm.brt <- as.data.frame(occ.pnts.bio.sm.brt)
occ.pnts.bio.sm.brt <-drop_na(occ.pnts.bio.sm.brt)
acc.bio.sm.brt<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.sm.brt,
occ.pnts = occ.pnts.bio.sm.brt,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#MARS
pd.bio.sm.mars<-dplyr::select(pd.bio.sm,long,lat,MARS)
output.mod.bio.sm.mars<-cbind(pd.bio.sm.mars,bd.bio.sm)
occ.p_env.bio.sm <- raster::extract(bio.sm,sp,as.data.frame=T)
occ.p_preds.bio.sm.mars <- raster::extract(p.bio.sm[[5]],sp,as.data.frame=T)
occ.coords.bio.sm <- sp@coords
occ.pnts.bio.sm.mars <- cbind(occ.coords.bio.sm,occ.p_preds.bio.sm.mars,occ.p_env.bio.sm)
occ.pnts.bio.sm.mars <- as.data.frame(occ.pnts.bio.sm.mars)
occ.pnts.bio.sm.mars <-drop_na(occ.pnts.bio.sm.mars)
acc.bio.sm.mars<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.sm.mars,
occ.pnts = occ.pnts.bio.sm.mars,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#MAXENT
pd.bio.sm.maxent<-dplyr::select(pd.bio.sm,long,lat,MAXENT)
output.mod.bio.sm.maxent<-cbind(pd.bio.sm.maxent,bd.bio.sm)
occ.p_env.bio.sm <- raster::extract(bio.sm,sp,as.data.frame=T)
occ.p_preds.bio.sm.maxent <- raster::extract(p.bio.sm[[6]],sp,as.data.frame=T)
occ.coords.bio.sm <- sp@coords
occ.pnts.bio.sm.maxent <- cbind(occ.coords.bio.sm,occ.p_preds.bio.sm.maxent,occ.p_env.bio.sm)
occ.pnts.bio.sm.maxent <- as.data.frame(occ.pnts.bio.sm.maxent)
occ.pnts.bio.sm.maxent <-drop_na(occ.pnts.bio.sm.maxent)
acc.bio.sm.maxent<-accum.occ(sp.name='Heterophrynus alces',
output.mod = output.mod.bio.sm.maxent,
occ.pnts = occ.pnts.bio.sm.maxent,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off() ; dev.off() ; dev.off()
#maxlike
pd.bio.sm.maxlike<-dplyr::select(pd.bio.sm,long,lat,MAXLIKE)
output.mod.bio.sm.maxlike<-cbind(pd.bio.sm.maxlike,bd.bio.sm)
occ.p_env.bio.sm <- raster::extract(bio.sm,sp,as.data.frame=T)
occ.p_preds.bio.sm.maxlike <- raster::extract(p.bio.sm[[7]],sp,as.data.frame=T)
occ.coords.bio.sm <- sp@coords
occ.pnts.bio.sm.maxlike <- cbind(occ.coords.bio.sm,occ.p_preds.bio.sm.maxlike,occ.p_env.bio.sm)
occ.pnts.bio.sm.maxlike <- as.data.frame(occ.pnts.bio.sm.maxlike)
occ.pnts.bio.sm.maxlike <-drop_na(occ.pnts.bio.sm.maxlike)
acc.bio.sm.maxlike<-accum.occ(sp.name='Heterophrynus alces',
output.mod = output.mod.bio.sm.maxlike,
occ.pnts = occ.pnts.bio.sm.maxlike,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off() ; dev.off() ; dev.off()
#GLMNet
pd.bio.sm.glmnet<-dplyr::select(pd.bio.sm,long,lat,GLMNET)
output.mod.bio.sm.glmnet<-cbind(pd.bio.sm.glmnet,bd.bio.sm)
occ.p_env.bio.sm <- raster::extract(bio.sm,sp,as.data.frame=T)
occ.p_preds.bio.sm.glmnet <- raster::extract(p.bio.sm[[8]],sp,as.data.frame=T)
occ.coords.bio.sm <- sp@coords
occ.pnts.bio.sm.glmnet <- cbind(occ.coords.bio.sm,occ.p_preds.bio.sm.glmnet,occ.p_env.bio.sm)
occ.pnts.bio.sm.glmnet <- as.data.frame(occ.pnts.bio.sm.glmnet)
occ.pnts.bio.sm.glmnet <-drop_na(occ.pnts.bio.sm.glmnet)
acc.bio.sm.glmnet<-accum.occ(sp.name='Heterophrynus alces',
output.mod = output.mod.bio.sm.glmnet,
occ.pnts = occ.pnts.bio.sm.glmnet,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off() ; dev.off() ; dev.off()
#### mm ####
bd.bio.mm <- as.data.frame(bio.mm, row.names=NULL, na.rm=F,xy=F,long=F)
pd.bio.mm <- as.data.frame(p.bio.mm, row.names=NULL, na.rm=F,xy=T,long=F)
names(pd.bio.mm)<- c("long","lat","GLM","SVM","RF","BRT","MARS","MAXENT","MAXLIKE","GLMNET")
#GLM
pd.bio.mm.glm<-dplyr::select(pd.bio.mm,long,lat,GLM)
output.mod.bio.mm.glm<-cbind(pd.bio.mm.glm,bd.bio.mm)
occ.p_env.bio.mm <- raster::extract(bio.mm,sp,as.data.frame=T)
occ.p_preds.bio.mm.glm <- raster::extract(p.bio.mm[[1]],sp,as.data.frame=T)
occ.coords.bio.mm <- sp@coords
occ.pnts.bio.mm.glm <- cbind(occ.coords.bio.mm,occ.p_preds.bio.mm.glm,occ.p_env.bio.mm)
occ.pnts.bio.mm.glm <- as.data.frame(occ.pnts.bio.mm.glm)
occ.pnts.bio.mm.glm <-drop_na(occ.pnts.bio.mm.glm)
acc.bio.mm.glm<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.mm.glm,
occ.pnts = occ.pnts.bio.mm.glm,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
# SVM
pd.bio.mm.svm<-dplyr::select(pd.bio.mm,long,lat,SVM)
output.mod.bio.mm.svm<-cbind(pd.bio.mm.svm,bd.bio.mm)
occ.p_env.bio.mm <- raster::extract(bio.mm,sp,as.data.frame=T)
occ.p_preds.bio.mm.svm <- raster::extract(p.bio.mm[[2]],sp,as.data.frame=T)
occ.coords.bio.mm <- sp@coords
occ.pnts.bio.mm.svm <- cbind(occ.coords.bio.mm,occ.p_preds.bio.mm.svm,occ.p_env.bio.mm)
occ.pnts.bio.mm.svm <- as.data.frame(occ.pnts.bio.mm.svm)
occ.pnts.bio.mm.svm <-drop_na(occ.pnts.bio.mm.svm)
acc.bio.mm.svm<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.mm.svm,
occ.pnts = occ.pnts.bio.mm.svm,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#RF
pd.bio.mm.rf<-dplyr::select(pd.bio.mm,long,lat,RF)
output.mod.bio.mm.rf<-cbind(pd.bio.mm.rf,bd.bio.mm)
occ.p_env.bio.mm <- raster::extract(bio.mm,sp,as.data.frame=T)
occ.p_preds.bio.mm.rf <- raster::extract(p.bio.mm[[3]],sp,as.data.frame=T)
occ.coords.bio.mm <- sp@coords
occ.pnts.bio.mm.rf <- cbind(occ.coords.bio.mm,occ.p_preds.bio.mm.rf,occ.p_env.bio.mm)
occ.pnts.bio.mm.rf <- as.data.frame(occ.pnts.bio.mm.rf)
occ.pnts.bio.mm.rf <-drop_na(occ.pnts.bio.mm.rf)
acc.bio.mm.rf<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.mm.rf,
occ.pnts = occ.pnts.bio.mm.rf,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#BRT
pd.bio.mm.brt<-dplyr::select(pd.bio.mm,long,lat,BRT)
output.mod.bio.mm.brt<-cbind(pd.bio.mm.brt,bd.bio.mm)
occ.p_env.bio.mm <- raster::extract(bio.mm,sp,as.data.frame=T)
occ.p_preds.bio.mm.brt <- raster::extract(p.bio.mm[[4]],sp,as.data.frame=T)
occ.coords.bio.mm <- sp@coords
occ.pnts.bio.mm.brt <- cbind(occ.coords.bio.mm,occ.p_preds.bio.mm.brt,occ.p_env.bio.mm)
occ.pnts.bio.mm.brt <- as.data.frame(occ.pnts.bio.mm.brt)
occ.pnts.bio.mm.brt <-drop_na(occ.pnts.bio.mm.brt)
acc.bio.mm.brt<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.mm.brt,
occ.pnts = occ.pnts.bio.mm.brt,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#MARS
pd.bio.mm.mars<-dplyr::select(pd.bio.mm,long,lat,MARS)
output.mod.bio.mm.mars<-cbind(pd.bio.mm.mars,bd.bio.mm)
occ.p_env.bio.mm <- raster::extract(bio.mm,sp,as.data.frame=T)
occ.p_preds.bio.mm.mars <- raster::extract(p.bio.mm[[5]],sp,as.data.frame=T)
occ.coords.bio.mm <- sp@coords
occ.pnts.bio.mm.mars <- cbind(occ.coords.bio.mm,occ.p_preds.bio.mm.mars,occ.p_env.bio.mm)
occ.pnts.bio.mm.mars <- as.data.frame(occ.pnts.bio.mm.mars)
occ.pnts.bio.mm.mars <-drop_na(occ.pnts.bio.mm.mars)
acc.bio.mm.mars<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.mm.mars,
occ.pnts = occ.pnts.bio.mm.mars,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#MAXENT
pd.bio.mm.maxent<-dplyr::select(pd.bio.mm,long,lat,MAXENT)
output.mod.bio.mm.maxent<-cbind(pd.bio.mm.maxent,bd.bio.mm)
occ.p_env.bio.mm <- raster::extract(bio.mm,sp,as.data.frame=T)
occ.p_preds.bio.mm.maxent <- raster::extract(p.bio.mm[[6]],sp,as.data.frame=T)
occ.coords.bio.mm <- sp@coords
occ.pnts.bio.mm.maxent <- cbind(occ.coords.bio.mm,occ.p_preds.bio.mm.maxent,occ.p_env.bio.mm)
occ.pnts.bio.mm.maxent <- as.data.frame(occ.pnts.bio.mm.maxent)
occ.pnts.bio.mm.maxent <-drop_na(occ.pnts.bio.mm.maxent)
acc.bio.mm.maxent<-accum.occ(sp.name='Heterophrynus alces',
output.mod = output.mod.bio.mm.maxent,
occ.pnts = occ.pnts.bio.mm.maxent,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off() ; dev.off() ; dev.off()
#maxlike
pd.bio.mm.maxlike<-dplyr::select(pd.bio.mm,long,lat,MAXLIKE)
output.mod.bio.mm.maxlike<-cbind(pd.bio.mm.maxlike,bd.bio.mm)
occ.p_env.bio.mm <- raster::extract(bio.mm,sp,as.data.frame=T)
occ.p_preds.bio.mm.maxlike <- raster::extract(p.bio.mm[[7]],sp,as.data.frame=T)
occ.coords.bio.mm <- sp@coords
occ.pnts.bio.mm.maxlike <- cbind(occ.coords.bio.mm,occ.p_preds.bio.mm.maxlike,occ.p_env.bio.mm)
occ.pnts.bio.mm.maxlike <- as.data.frame(occ.pnts.bio.mm.maxlike)
occ.pnts.bio.mm.maxlike <-drop_na(occ.pnts.bio.mm.maxlike)
acc.bio.mm.maxlike<-accum.occ(sp.name='Heterophrynus alces',
output.mod = output.mod.bio.mm.maxlike,
occ.pnts = occ.pnts.bio.mm.maxlike,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off() ; dev.off() ; dev.off()
#GLMNet
pd.bio.mm.glmnet<-dplyr::select(pd.bio.mm,long,lat,GLMNET)
output.mod.bio.mm.glmnet<-cbind(pd.bio.mm.glmnet,bd.bio.mm)
occ.p_env.bio.mm <- raster::extract(bio.mm,sp,as.data.frame=T)
occ.p_preds.bio.mm.glmnet <- raster::extract(p.bio.mm[[8]],sp,as.data.frame=T)
occ.coords.bio.mm <- sp@coords
occ.pnts.bio.mm.glmnet <- cbind(occ.coords.bio.mm,occ.p_preds.bio.mm.glmnet,occ.p_env.bio.mm)
occ.pnts.bio.mm.glmnet <- as.data.frame(occ.pnts.bio.mm.glmnet)
occ.pnts.bio.mm.glmnet <-drop_na(occ.pnts.bio.mm.glmnet)
acc.bio.mm.glmnet<-accum.occ(sp.name='Heterophrynus alces',
output.mod = output.mod.bio.mm.glmnet,
occ.pnts = occ.pnts.bio.mm.glmnet,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off() ; dev.off() ; dev.off()
#### bm ####
bd.bio.bm <- as.data.frame(bio.bm, row.names=NULL, na.rm=F,xy=F,long=F)
pd.bio.bm <- as.data.frame(p.bio.bm, row.names=NULL, na.rm=F,xy=T,long=F)
names(pd.bio.bm)<- c("long","lat","GLM","SVM","RF","BRT","MARS","MAXENT","MAXLIKE","GLMNET")
#GLM
pd.bio.bm.glm<-dplyr::select(pd.bio.bm,long,lat,GLM)
output.mod.bio.bm.glm<-cbind(pd.bio.bm.glm,bd.bio.bm)
occ.p_env.bio.bm <- raster::extract(bio.bm,sp,as.data.frame=T)
occ.p_preds.bio.bm.glm <- raster::extract(p.bio.bm[[1]],sp,as.data.frame=T)
occ.coords.bio.bm <- sp@coords
occ.pnts.bio.bm.glm <- cbind(occ.coords.bio.bm,occ.p_preds.bio.bm.glm,occ.p_env.bio.bm)
occ.pnts.bio.bm.glm <- as.data.frame(occ.pnts.bio.bm.glm)
occ.pnts.bio.bm.glm <-drop_na(occ.pnts.bio.bm.glm)
acc.bio.bm.glm<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.bm.glm,
occ.pnts = occ.pnts.bio.bm.glm,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
# SVM
pd.bio.bm.svm<-dplyr::select(pd.bio.bm,long,lat,SVM)
output.mod.bio.bm.svm<-cbind(pd.bio.bm.svm,bd.bio.bm)
occ.p_env.bio.bm <- raster::extract(bio.bm,sp,as.data.frame=T)
occ.p_preds.bio.bm.svm <- raster::extract(p.bio.bm[[2]],sp,as.data.frame=T)
occ.coords.bio.bm <- sp@coords
occ.pnts.bio.bm.svm <- cbind(occ.coords.bio.bm,occ.p_preds.bio.bm.svm,occ.p_env.bio.bm)
occ.pnts.bio.bm.svm <- as.data.frame(occ.pnts.bio.bm.svm)
occ.pnts.bio.bm.svm <-drop_na(occ.pnts.bio.bm.svm)
acc.bio.bm.svm<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.bm.svm,
occ.pnts = occ.pnts.bio.bm.svm,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#RF
pd.bio.bm.rf<-dplyr::select(pd.bio.bm,long,lat,RF)
output.mod.bio.bm.rf<-cbind(pd.bio.bm.rf,bd.bio.bm)
occ.p_env.bio.bm <- raster::extract(bio.bm,sp,as.data.frame=T)
occ.p_preds.bio.bm.rf <- raster::extract(p.bio.bm[[3]],sp,as.data.frame=T)
occ.coords.bio.bm <- sp@coords
occ.pnts.bio.bm.rf <- cbind(occ.coords.bio.bm,occ.p_preds.bio.bm.rf,occ.p_env.bio.bm)
occ.pnts.bio.bm.rf <- as.data.frame(occ.pnts.bio.bm.rf)
occ.pnts.bio.bm.rf <-drop_na(occ.pnts.bio.bm.rf)
acc.bio.bm.rf<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.bm.rf,
occ.pnts = occ.pnts.bio.bm.rf,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#BRT
pd.bio.bm.brt<-dplyr::select(pd.bio.bm,long,lat,BRT)
output.mod.bio.bm.brt<-cbind(pd.bio.bm.brt,bd.bio.bm)
occ.p_env.bio.bm <- raster::extract(bio.bm,sp,as.data.frame=T)
occ.p_preds.bio.bm.brt <- raster::extract(p.bio.bm[[4]],sp,as.data.frame=T)
occ.coords.bio.bm <- sp@coords
occ.pnts.bio.bm.brt <- cbind(occ.coords.bio.bm,occ.p_preds.bio.bm.brt,occ.p_env.bio.bm)
occ.pnts.bio.bm.brt <- as.data.frame(occ.pnts.bio.bm.brt)
occ.pnts.bio.bm.brt <-drop_na(occ.pnts.bio.bm.brt)
acc.bio.bm.brt<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.bm.brt,
occ.pnts = occ.pnts.bio.bm.brt,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#MARS
pd.bio.bm.mars<-dplyr::select(pd.bio.bm,long,lat,MARS)
output.mod.bio.bm.mars<-cbind(pd.bio.bm.mars,bd.bio.bm)
occ.p_env.bio.bm <- raster::extract(bio.bm,sp,as.data.frame=T)
occ.p_preds.bio.bm.mars <- raster::extract(p.bio.bm[[5]],sp,as.data.frame=T)
occ.coords.bio.bm <- sp@coords
occ.pnts.bio.bm.mars <- cbind(occ.coords.bio.bm,occ.p_preds.bio.bm.mars,occ.p_env.bio.bm)
occ.pnts.bio.bm.mars <- as.data.frame(occ.pnts.bio.bm.mars)
occ.pnts.bio.bm.mars <-drop_na(occ.pnts.bio.bm.mars)
acc.bio.bm.mars<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.bio.bm.mars,
occ.pnts = occ.pnts.bio.bm.mars,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#MAXENT
pd.bio.bm.maxent<-dplyr::select(pd.bio.bm,long,lat,MAXENT)
output.mod.bio.bm.maxent<-cbind(pd.bio.bm.maxent,bd.bio.bm)
occ.p_env.bio.bm <- raster::extract(bio.bm,sp,as.data.frame=T)
occ.p_preds.bio.bm.maxent <- raster::extract(p.bio.bm[[6]],sp,as.data.frame=T)
occ.coords.bio.bm <- sp@coords
occ.pnts.bio.bm.maxent <- cbind(occ.coords.bio.bm,occ.p_preds.bio.bm.maxent,occ.p_env.bio.bm)
occ.pnts.bio.bm.maxent <- as.data.frame(occ.pnts.bio.bm.maxent)
occ.pnts.bio.bm.maxent <-drop_na(occ.pnts.bio.bm.maxent)
acc.bio.bm.maxent<-accum.occ(sp.name='Heterophrynus alces',
output.mod = output.mod.bio.bm.maxent,
occ.pnts = occ.pnts.bio.bm.maxent,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off() ; dev.off() ; dev.off()
#maxlike
pd.bio.bm.maxlike<-dplyr::select(pd.bio.bm,long,lat,MAXLIKE)
output.mod.bio.bm.maxlike<-cbind(pd.bio.bm.maxlike,bd.bio.bm)
occ.p_env.bio.bm <- raster::extract(bio.bm,sp,as.data.frame=T)
occ.p_preds.bio.bm.maxlike <- raster::extract(p.bio.bm[[7]],sp,as.data.frame=T)
occ.coords.bio.bm <- sp@coords
occ.pnts.bio.bm.maxlike <- cbind(occ.coords.bio.bm,occ.p_preds.bio.bm.maxlike,occ.p_env.bio.bm)
occ.pnts.bio.bm.maxlike <- as.data.frame(occ.pnts.bio.bm.maxlike)
occ.pnts.bio.bm.maxlike <-drop_na(occ.pnts.bio.bm.maxlike)
acc.bio.bm.maxlike<-accum.occ(sp.name='Heterophrynus alces',
output.mod = output.mod.bio.bm.maxlike,
occ.pnts = occ.pnts.bio.bm.maxlike,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off() ; dev.off() ; dev.off()
#GLMNet
pd.bio.bm.glmnet<-dplyr::select(pd.bio.bm,long,lat,GLMNET)
output.mod.bio.bm.glmnet<-cbind(pd.bio.bm.glmnet,bd.bio.bm)
occ.p_env.bio.bm <- raster::extract(bio.bm,sp,as.data.frame=T)
occ.p_preds.bio.bm.glmnet <- raster::extract(p.bio.bm[[8]],sp,as.data.frame=T)
occ.coords.bio.bm <- sp@coords
occ.pnts.bio.bm.glmnet <- cbind(occ.coords.bio.bm,occ.p_preds.bio.bm.glmnet,occ.p_env.bio.bm)
occ.pnts.bio.bm.glmnet <- as.data.frame(occ.pnts.bio.bm.glmnet)
occ.pnts.bio.bm.glmnet <-drop_na(occ.pnts.bio.bm.glmnet)
acc.bio.bm.glmnet<-accum.occ(sp.name='Heterophrynus alces',
output.mod = output.mod.bio.bm.glmnet,
occ.pnts = occ.pnts.bio.bm.glmnet,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off() ; dev.off() ; dev.off()
#### Generating the AOcCs - comp.accplot ####
# Load the function from Jimenez&Soberon
load("~/Documents/Mestrado/Analises/SDM-hyperTest-master/SDM-Hyper-Test-Master-Functions-Jul212021.RData")
load("~/Documents/Mestrado/Analises/Model Comparison/accum_curve_jfb.RData") #my modified Jimenez&Soberon function with plot titles, load it again to overwrite the accum.occ function
# sm
bio.sm.comp <- list(acc.bio.sm.glm,acc.bio.sm.svm,acc.bio.sm.rf,acc.bio.sm.brt,acc.bio.sm.mars,acc.bio.sm.maxent,acc.bio.sm.maxlike,acc.bio.sm.glmnet)
comp.accplot(mods=bio.sm.comp,
nocc = length(sp),
ncells = raster::ncell(p.bio.sm),
sp.name = 'Heterophrynus alces',
mods.names = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
alpha = 0.05)
title("Small Model Comparison")
dev.off()
# mm
bio.mm.comp <- list(acc.bio.mm.glm,acc.bio.mm.svm,acc.bio.mm.rf,acc.bio.mm.brt,acc.bio.mm.mars,acc.bio.mm.maxent,acc.bio.mm.maxlike,acc.bio.mm.glmnet)
comp.accplot(mods=bio.mm.comp,
nocc = length(sp),
ncells = raster::ncell(p.bio.mm),
sp.name = 'Heterophrynus alces',
mods.names = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
alpha = 0.05)
title("Medium Model Comparison")
dev.off()
# bm
bio.bm.comp <- list(acc.bio.bm.glm,acc.bio.bm.svm,acc.bio.bm.rf,acc.bio.bm.brt,acc.bio.bm.mars,acc.bio.bm.maxent,acc.bio.bm.maxlike,acc.bio.bm.glmnet)
comp.accplot(mods=bio.bm.comp,
nocc = length(sp),
ncells = raster::ncell(p.bio.bm),
sp.name = 'Heterophrynus alces',
mods.names = c('glm','svm','rf','brt','mars','maxent','maxlike','glmnet'),
alpha = 0.05)
title("Big Model Comparison")
dev.off()
### Merraclim ####
#### sm ####
bd.merra.sm <- as.data.frame(merra.sm, row.names=NULL, na.rm=F,xy=F,long=F)
pd.merra.sm <- as.data.frame(p.merra.sm, row.names=NULL, na.rm=F,xy=T,long=F)
names(pd.merra.sm)<- c("long","lat","GLM","SVM","RF","BRT","MARS","MAXENT","MAXLIKE","GLMNET")
#GLM
pd.merra.sm.glm<-dplyr::select(pd.merra.sm,long,lat,GLM)
output.mod.merra.sm.glm<-cbind(pd.merra.sm.glm,bd.merra.sm)
occ.p_env.merra.sm <- raster::extract(merra.sm,sp,as.data.frame=T)
occ.p_preds.merra.sm.glm <- raster::extract(p.merra.sm[[1]],sp,as.data.frame=T)
occ.coords.merra.sm <- sp@coords
occ.pnts.merra.sm.glm <- cbind(occ.coords.merra.sm,occ.p_preds.merra.sm.glm,occ.p_env.merra.sm)
occ.pnts.merra.sm.glm <- as.data.frame(occ.pnts.merra.sm.glm)
occ.pnts.merra.sm.glm <-drop_na(occ.pnts.merra.sm.glm)
acc.merra.sm.glm<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.merra.sm.glm,
occ.pnts = occ.pnts.merra.sm.glm,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
# SVM
pd.merra.sm.svm<-dplyr::select(pd.merra.sm,long,lat,SVM)
output.mod.merra.sm.svm<-cbind(pd.merra.sm.svm,bd.merra.sm)
occ.p_env.merra.sm <- raster::extract(merra.sm,sp,as.data.frame=T)
occ.p_preds.merra.sm.svm <- raster::extract(p.merra.sm[[2]],sp,as.data.frame=T)
occ.coords.merra.sm <- sp@coords
occ.pnts.merra.sm.svm <- cbind(occ.coords.merra.sm,occ.p_preds.merra.sm.svm,occ.p_env.merra.sm)
occ.pnts.merra.sm.svm <- as.data.frame(occ.pnts.merra.sm.svm)
occ.pnts.merra.sm.svm <-drop_na(occ.pnts.merra.sm.svm)
acc.merra.sm.svm<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.merra.sm.svm,
occ.pnts = occ.pnts.merra.sm.svm,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#RF
pd.merra.sm.rf<-dplyr::select(pd.merra.sm,long,lat,RF)
output.mod.merra.sm.rf<-cbind(pd.merra.sm.rf,bd.merra.sm)
occ.p_env.merra.sm <- raster::extract(merra.sm,sp,as.data.frame=T)
occ.p_preds.merra.sm.rf <- raster::extract(p.merra.sm[[3]],sp,as.data.frame=T)
occ.coords.merra.sm <- sp@coords
occ.pnts.merra.sm.rf <- cbind(occ.coords.merra.sm,occ.p_preds.merra.sm.rf,occ.p_env.merra.sm)
occ.pnts.merra.sm.rf <- as.data.frame(occ.pnts.merra.sm.rf)
occ.pnts.merra.sm.rf <-drop_na(occ.pnts.merra.sm.rf)
acc.merra.sm.rf<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.merra.sm.rf,
occ.pnts = occ.pnts.merra.sm.rf,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#BRT
pd.merra.sm.brt<-dplyr::select(pd.merra.sm,long,lat,BRT)
output.mod.merra.sm.brt<-cbind(pd.merra.sm.brt,bd.merra.sm)
occ.p_env.merra.sm <- raster::extract(merra.sm,sp,as.data.frame=T)
occ.p_preds.merra.sm.brt <- raster::extract(p.merra.sm[[4]],sp,as.data.frame=T)
occ.coords.merra.sm <- sp@coords
occ.pnts.merra.sm.brt <- cbind(occ.coords.merra.sm,occ.p_preds.merra.sm.brt,occ.p_env.merra.sm)
occ.pnts.merra.sm.brt <- as.data.frame(occ.pnts.merra.sm.brt)
occ.pnts.merra.sm.brt <-drop_na(occ.pnts.merra.sm.brt)
acc.merra.sm.brt<-accum.occ(sp.name='Heterophrynus',
output.mod = output.mod.merra.sm.brt,
occ.pnts = occ.pnts.merra.sm.brt,
null.mod = "hypergeom",
conlev = 0.05, bios = 0)
dev.off () ; dev.off() ; dev.off()
#MARS
pd.merra.sm.mars<-dplyr::select(pd.merra.sm,long,lat,MARS)
output.mod.merra.sm.mars<-cbind(pd.merra.sm.mars,bd.merra.sm)
occ.p_env.merra.sm <- raster::extract(merra.sm,sp,as.data.frame=T)
occ.p_preds.merra.sm.mars <- raster::extract(p.merra.sm[[5]],sp,as.data.frame=T)
occ.coords.merra.sm <- sp@coords
occ.pnts.merra.sm.mars <- cbind(occ.coords.merra.sm,occ.p_preds.merra.sm.mars,occ.p_env.merra.sm)