forked from EcoDynIZW/d6_teaching_collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 19.3 KB
/
.Rhistory
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
birds1
# 1. transpose the data
birds1.transpose <- as.data.frame(t(birds1[, -1]))
birds1.transpose
colnames(birds1.transpose) <- birds1$Species
birds1.transpose
# Get diversity value
?diversity
H_vegan <- diversity(birds1.transpose, index = "shannon")
H_vegan
# We create a second community with no species in common with the first one
birds2 <- data.frame(Species = c('Sparrow', 'Dove', 'Crow'),
Abundance = c(4,5,20))
birds2
# the transpose matrix for the analysis
birds2.transpose <- as.data.frame(t(birds2[, -1]))
colnames(birds2.transpose) <- birds2$Species
birds2.transpose
birds.both <- merge(birds1, birds2, by = 'Species', all = T)
birds.both
birds.both$Abundance.x[is.na(birds.both$Abundance.x)] <- 0
birds.both$Abundance.y[is.na(birds.both$Abundance.y)] <- 0
birds.both
birds.all <- rowSums(birds.both[,2:3])
birds.all
both.trans <- as.data.frame(t(birds.both[, -1]))
colnames(both.trans) <- birds.both$Species
rownames(both.trans) <- c("birds1", "birds2")
both.trans
all.trans <- colSums(both.trans)
# shannon diversity for each sample and for the sum
H1 <- diversity(both.trans, index = "shannon")
H1
H2 <- diversity(all.trans, index = "shannon")
H2
birds1$Abundance
# Hill number order 1 (library iNEXT)
HN1.birds1 <- iNEXT(birds1$Abundance)
HN1.birds1
HN1.birds1$AsyEst
HN1.birds2 <- iNEXT(birds2$Abundance)
HN1.birds2$AsyEst
HN1.birdsboth <- iNEXT(birds.all)
HN1.birdsboth$AsyEst
data(spider)
str(spider)
?spider
example1 <- iNEXT(spider, q = 0, datatype = "abundance")
example1$DataInfo
#Show a summary of the data with diversity estimates in rarefied and extrapolated samples
example1$iNextEst
# show asymptotic estimates
example1$AsyEst
# We define the number of samples size that we want to use for estimation
m <- c(1, 50, 100, 200, 400)
example2 <- iNEXT(spider, q = c(0,1,2), datatype = "abundance", size = m)
example2$iNextEst
ggiNEXT(example1, type=1) # Curve for sample size
ggiNEXT(example2, type=1, facet.var="Assemblage")
ggiNEXT(example2, type=1, facet.var="Both")
ggiNEXT(example2, type=1, facet.var="Assemblage")
?ggiNEXT
ggiNEXT(example2, type=1, facet.var="Order.q")
inext_spiders <- iNEXT(spider, q = 0, datatype = "abundance")
info_spiders <- inext_spiders$DataInfo
inext_spiders$DataInfo
max(info_spiders$n)
estINEXTsize <- estimateD(spider, datatype = "abundance", base = "size", level = 252,
conf = 0.95)
estINEXTsize
estINEXTcover2 <- estimateD(spider, datatype = "abundance", base = "size", level = 252,
conf = 0.95)
estINEXTcover2
habitat <- factor(c("Girdled", "Logged"))
# plot simple
mysub <- subset(estINEXTcover2, estINEXTcover2$Order.q == 0 )
mysub
plot(mysub$qD ~ habitat, border = c("green4", "red"),
xlab = "Habitats", ylab = "Est. Species richness")
# plot with confidence interval in ggplot
ggplot(mysub, aes(x = habitat, y = qD)) +
geom_point(colour = c("green4", "red"), size = 5) +
geom_errorbar(aes(ymin = qD.LCL, ymax = qD.UCL),
colour = c("green4", "red"),
width = 0.2) +
xlab("Habitats") +
ylab("Est. Species richness") +
theme_bw()
# plot with confidence interval in ggplot
ggplot(mysub, aes(x = habitat, y = qD)) +
geom_point(colour = c("green4", "red"), size = 5) +
geom_errorbar(aes(ymin = qD.LCL, ymax = qD.UCL-10),
colour = c("green4", "red"),
width = 0.2) +
xlab("Habitats") +
ylab("Est. Species richness") +
theme_bw()
# plot with confidence interval in ggplot
ggplot(mysub, aes(x = habitat, y = qD)) +
geom_point(colour = c("green4", "red"), size = 5) +
geom_errorbar(aes(ymin = qD.LCL, ymax = qD.UCL-5),
colour = c("green4", "red"),
width = 0.2) +
xlab("Habitats") +
ylab("Est. Species richness") +
theme_bw()
# plot with confidence interval in ggplot
ggplot(mysub, aes(x = habitat, y = qD)) +
geom_point(colour = c("green4", "red"), size = 5) +
geom_errorbar(aes(ymin = qD.LCL, ymax = qD.UCL),
colour = c("green4", "red"),
width = 0.2) +
xlab("Habitats") +
ylab("Est. Species richness") +
theme_bw()
# Bird data
bird_data <- read.csv(here("data","data_berlin","animal_data",
"Birds_Berlin_exercise_planillo2021.csv") )
head(bird_data)
bird_data
str(bird_data)
head(bird_data)
head(bird_data)
str(bird_data)
summary(bird_data)
# get the data in the proper format
bird_data <- column_to_rownames(bird_data, "site")
bird_data
bird_data <- t(bird_data)
bird_data
# run inext function
birds_inext <- iNEXT(bird_data, q = 0, datatype = "abundance") # q = 0 -> species richness
#Show a summary of the data
birds_inext$DataInfo
#Show a summary of the data with diversity estimates in rarefied and extrapolated samples
head(birds_inext$iNextEst)
# show asymptotic estimates
birds_inext$AsyEst
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="none") # not all plots sampled equally
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None") # not all plots sampled equally
?ggiNEXT
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None", color.var = "None") # not all plots sampled equally
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None", color.var = "Order.q") # not all plots sampled equally
# get minimum number of individuals from data
min_abund <- min(birds_inext$DataInfo$n)
min_abund
# use 2x minimum number of individuals for rarefaction/extrapolation
birds_estINEXTsize <- estimateD(bird_data, datatype = "abundance", base = "size", level = (min_abund*2),
conf = NULL)
# use 2x minimum number of individuals for rarefaction/extrapolation
birds_estINEXTsize <- estimateD(bird_data, datatype = "abundance", base = "size", level = (min_abund*2),
conf = NULL)
?estimateD
# use 2x minimum number of individuals for rarefaction/extrapolation
birds_estINEXTsize <- estimateD(bird_data, q = 0, datatype = "abundance", base = "size", level = (min_abund*2),
conf = NULL)
bird_data
head(bird_data)
str(bird_data)
# use 2x minimum number of individuals for rarefaction/extrapolation
birds_estINEXTsize <- estimateD(as.data.frame(bird_data), q = 0, datatype = "abundance", base = "size", level = (min_abund*2),
conf = NULL)
as.data.frame(bird_data)
bird_data2 <- as.data.frame(bird_data)
bird_data2
str(bird_data2)
# use 2x minimum number of individuals for rarefaction/extrapolation
birds_estINEXTsize <- estimateD(bird_data2, q = 0, datatype = "abundance", base = "size", level = (min_abund*2),
conf = NULL)
# use 2x minimum number of individuals for rarefaction/extrapolation
birds_estINEXTsize <- estimateD(bird_data2, q = 0, datatype = "abundance", base = "size", level = (149*2),
conf = NULL)
# use 2x minimum number of individuals for rarefaction/extrapolation
birds_estINEXTsize <- estimateD(bird_data2, q = 0, datatype = "abundance", base = "size", level = 200,
conf = NULL)
# use 2x minimum number of individuals for rarefaction/extrapolation
birds_estINEXTsize <- estimateD(bird_data2, q = 0, datatype = "abundance", base = "size", level = 200,
conf = 0.95)
# use 2x minimum number of individuals for rarefaction/extrapolation
birds_estINEXTsize <- estimateD(bird_data, q = 0, datatype = "abundance", base = "size", level = (min_abund * 2),
conf = 0.95)
birds_estINEXTsize
# extract species richness
birds_est_sprich <- as.data.frame(cbind(site = colnames(bird_data),
sp_rich = birds_estINEXTsize$Order.q))
birds_est_sprich
birds_est_sprich
# extract species richness
birds_est_sprich <- as.data.frame(cbind(site = colnames(bird_data),
sp_rich = birds_estINEXTsize$qD))
birds_est_sprich
env_cov <- read.csv(here("data","data_berlin","animal_data",
"birds_transects_allenvir_100m.csv") )
head(env_cov)
str(env_cov)
summary(env_cov)
colnames(env_cov)
birds_est_sprich
env_cov
# Put all data together: add environmental variables to birds data
#my_model_data <- left_join(birds_est_sprich, env_cov, by = "site")
my_model_data <- merge(birds_est_sprich,env_cov,by = "site")
my_model_data
my_model_data <- my_model_data[, c('site', 'sp_rich', 'tree_cover',
'impervious_surface', 'noise')]
str(my_model_data) # do you also have a chr for sp_rich?
my_model_data$sp_rich <- as.numeric(my_model_data$sp_rich)
str(my_model_data)
# explore relationships between variables
ggplot(my_model_data, aes(y = sp_rich, x = tree_cover)) +
geom_point() +
geom_smooth()
ggplot(my_model_data, aes(y = sp_rich, x = impervious_surface)) +
geom_point() +
geom_smooth()
ggplot(my_model_data, aes(y = sp_rich, x = noise)) +
geom_point() +
geom_smooth()
# build linear regression model
birds_model <- glm(sp_rich ~ tree_cover + impervious_surface + noise,
family = "gaussian",
data = my_model_data)
# View results of the model
summary(birds_model)
# view the regression line through impervious surface only:
ggplot(my_model_data, aes(y = sp_rich, x = impervious_surface)) +
geom_point(size=7,alpha=0.5) +
geom_smooth(method = "lm", se = TRUE, col='red') +
xlab('impervious surface')
plot(birds_model)
# view the regression line through impervious surface only:
ggplot(my_model_data, aes(y = sp_rich, x = impervious_surface)) +
geom_point(size=7,alpha=0.5) +
geom_smooth(method = "lm", se = TRUE, col='red') +
xlab('impervious surface')
##
## set working directory for maps, e.g. here geoTiffs ##
tree_raster <- rast(here::here("data","data_berlin","geo_raster_current_gtif","tree_cover_density_2012_100m_3035.tif"))
imperv_raster <- rast(here::here("data","data_berlin","geo_raster_current_gtif","imperviousness_2012_100m_3035.tif"))
noise_raster <- rast(here::here("data","data_berlin","geo_raster_current_gtif","noise_daynight_2017_100m_3035.tif"))
water_raster <- rast(here::here("data","data_berlin","geo_raster_current_gtif","water_bodies_2010_100m_3035.tif"))
## this works
my_env_stack<- rast(list(tree_raster, imperv_raster, noise_raster))
my_env_stack
my_env_stack
my_env_stack
# the raster the same name as the variables in the model
names(my_env_stack) <- c("tree_cover", "impervious_surface", "noise")
my_env_stack
my_env_stack_2 <- my_env_stack/100 # correct values of the rasters
my_env_stack_2
sp_rich_pred <- terra::predict(object = my_env_stack_2,
model = birds_model)
sp_rich_pred
sp_rich_pred[sp_rich_pred < 0] <- 0 # Abundance cannot be < 0
# define colors
my_palette <- c("#440154FF", "#2D708EFF", "#56C667FF", "#DCE318FF", "#FDE725FF")
# plot map
plot(sp_rich_pred, col = my_palette, breaks = c(seq(5, 55, by = 10)))
plot(water_raster, col = "darkslategray1", legend=FALSE, add = TRUE)
library(iNEXT)
library(here)
# Bird data
bird_data <- read.csv(here("data","data_berlin","animal_data",
"Birds_Berlin_exercise_planillo2021.csv") )
head(bird_data)
str(bird_data)
summary(bird_data)
bird_data
# get the data in the proper format
bird_data <- column_to_rownames(bird_data, "site")
bird_data <- t(bird_data)
# run inext function
birds_inext <- iNEXT(bird_data, q = 0, datatype = "abundance") # q = 0 -> species richness
#Show a summary of the data
birds_inext$DataInfo
library(tidyverse)
# Bird data
bird_data <- read.csv(here("data","data_berlin","animal_data",
"Birds_Berlin_exercise_planillo2021.csv") )
head(bird_data)
str(bird_data)
summary(bird_data)
bird_data
# get the data in the proper format
bird_data <- column_to_rownames(bird_data, "site")
bird_data <- t(bird_data)
# run inext function
birds_inext <- iNEXT(bird_data, q = 0, datatype = "abundance") # q = 0 -> species richness
#Show a summary of the data
birds_inext$DataInfo
library(scico)
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None", color.var = "Order.q") + # not all plots sampled equally
scale_color_manual(values =c("blue", "green"))
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None") + # not all plots sampled equally
scale_color_manual(values =c("blue", "green"))
install.packages("scico")
install.packages("paletteer")
library(scico)
library(paletteer)
library(paletter)
library(paletteer)
paletteer::paletteer_c(scico::berlin)
?paletteer_c
paletteer::paletteer_c("scico::berlin", 29)
my_palette_inext <- paletteer::paletteer_c("scico::berlin", 29)
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None") + # not all plots sampled equally
scale_color_manual(values =my_palette_inext)
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None") + # not all plots sampled equally
scale_color_manual(values =my_palette_inext) +
scale_shape_manual(values = 1)
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None") + # not all plots sampled equally
scale_color_manual(values = my_palette_inext) +
scale_shape_manual(values = 1)
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None") + # not all plots sampled equally
scale_color_manual(palette = my_palette_inext) +
scale_shape_manual(values = 1)
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None") + # not all plots sampled equally
scale_color_manual(values = my_palette_inext) +
scale_shape_manual(values = seq(1:29))
# Species accumulation curves
ggiNEXT(birds_inext, type=1, facet.var="None") + # not all plots sampled equally
scale_color_manual(values = my_palette_inext) +
scale_fill_manual(values = my_palette_inext) +
scale_shape_manual(values = seq(1:29))
### The packages (repetition) ###
library(here)
library(sp)
library(sf)
library(tmap)
library(dismo)
library(terra)
# library(GISTools)
library(rgdal)
library(maptools)
library(viridis)
library(rgeos)
library(rgl)
# library(rasterVis)
library(unmarked)
library(spatstat)
## check that the package raster is detached!
# detach(package:raster)
### The workspace (repetition) ###
getwd() # you can also use the package 'here()'
# my data are outside my course-folder, therefore I have to do it the old-fashioned way.
root_wd <- here::here()
root_wd
# relative to work-wd
maps_wd <- paste(root_wd,"/","data/data_borneo/geo_raster_current_asc",sep='') # or:
maps_wd
vecs_wd <- here::here("data","data_borneo","geo_vector") # shapefile
recs_wd <- here::here("data","data_borneo","animal_data") # location data
# the output folder should have been created by you during Tutorial 2 'R goes spatial'.
# It should contain the hillshade.asc
output_wd <- here::here("output")
output_wd
setwd(output_wd) ## set to the OUTPUT folder!
getwd() # check
paste(maps_wd,'/bio_asc_01.asc')
ras1 <- terra::rast(x = paste(maps_wd,'/bio_asc_01.asc',sep=''))
ras1
ras24 <- terra::rast(here("data","data_borneo", "geo_raster_current_asc", "bio_asc_24.asc")) #DEM
ras42 <- terra::rast(x = here(maps_wd,"bio_asc_42.asc")) # land use
hillsh <- terra::rast(x = paste(maps_wd,'/borneo_hillshade.asc',sep=''))
# the list.files command is very helpful to check what is in the folders
# use 'pattern' for searching for special file types, here .asc-files:
files <- list.files(path= maps_wd, pattern='.asc$',
full.names=TRUE )
files # these are just names! To load them as spatial objects, use rast()
## note that I only load 4 rasters:
# predictors <- c(files[c(9,12,22,24)]) # for full data set
predictors <- rast(x = c(files[c(1,5,6,7)]) ) # for github repository data
predictors
plot(predictors, col = viridis(100)) # might take some time depending on your computer
### Read in some Shapefiles (repetition) ###
## package sf (new and maintained)
## Borneo outline polygon
Borneo_shp_sf <- st_read(dsn = vecs_wd,
layer = "borneo_admin",
stringsAsFactors = FALSE)[,c(1:3,5,7,17,18)]
# Protected areas (PA) polygon
PA_shp_sf <- st_read(dsn = vecs_wd,
layer = "Bor_PA",
stringsAsFactors = FALSE)[, c(1:4)]
# Rivers lines
River_shp_sf <- st_read(dsn = vecs_wd,
layer = "sn_100000",
stringsAsFactors = FALSE)
# filename
spec_pt_filename <- paste(recs_wd,'/','MyNewSpecies.csv', sep='')
spec_pt_filename
# read the file
sp_recs <- read.csv(file = spec_pt_filename, header=TRUE, sep=',')
head(sp_recs)
#convert it to spatial object (sf here)
sp_recs_sf <- st_as_sf(x = sp_recs,
coords = c("long","lat"), # columns for the coordinates
crs = 4326, # define crs, 4326 is the EPSG code
sf_column_name = "geometry",
remove=F) # sf needs a geometry column and you have to name it
# load a second species
river_pt_filename <- here(recs_wd,"RIVERsim.csv")
river_recs <- read.csv(file = river_pt_filename, header=TRUE, sep=',')
river_recs_sf <- st_as_sf(x = river_recs,
coords = c("long", "lat"),
crs = 4326,
sf_column_name = "geometry")
plot(ras42, col=grey.colors(20))
plot(PA_shp_sf$geometry,border='green', lwd=1.8, add=T)
head(river_recs_sf)
river_recs_sf <- st_as_sf(x = river_recs,
coords = c("long", "lat"),
crs = 4326,
sf_column_name = "geometry", remove=FALSE)
river_recs_sf
plot(sp_recs_sf$geometry, pch= '*',cex=1,col='deeppink',add=T)
text(112, 6, 'Starting with SDMs', cex=1.5, col= 'red')
plot(River_shp_sf[,3], col='dodgerblue4', add=T)
# workaround for slow computers. First, aggregate the 1 km² resolution into 50*50 km
agg_pred <- aggregate(x=predictors,fact=50,FUN=mean)
plot(agg_pred)
terra::pairs(agg_pred, method = 'spearman')
# Plot the differences (residuals) between the rasters:
diff <- terra::focalPairs(x = agg_pred, w = 3, 'pearson', na.rm = TRUE)
plot(diff)
head(Borneo_shp_sf)
plot(Borneo_shp_sf[,3]) # column 3 is NAME_0 = main country names
Mal_ras <- rasterize(x=Borneo_shp_sf[Borneo_shp_sf$NAME_0 %in%
c("Brunei","Malaysia"),], y=ras24, field=1,
background=0.1)
plot(Mal_ras)
Sab_ras <- rasterize(x=Borneo_shp_sf[Borneo_shp_sf$NAME_1 == 'Sabah',],
y=ras24, field=1, background=0.1)
PA_ras <- rasterize(x=PA_shp_sf, y=ras24, field=1, background=0.1)
plot(Sab_ras)
plot(PA_ras) #n.b.: only 1 and small values, no NA
ras24_300 <- ras24 <= 300
plot(ras24_300)
bias_tmp <- ras24_300 + Sab_ras + Mal_ras + PA_ras
bias_tmp
plot(bias_tmp)
# get the maximum value in the layer, standardize it and round to two decimals
maxval <- max(values(bias_tmp),na.rm=T)
maxval
bias_tmp2 <- bias_tmp/maxval
bias_tmp3 <- round(bias_tmp2, digits=2)
## same as in one go:
bias1 <- round(bias_tmp/max(values(bias_tmp),na.rm=T),digits=2)
table(values(bias1))
terra::compareGeom(ras24,bias1) # the same?
# Are they really the same???
length(which(!is.na(values(bias1))))
length(which(!is.na(values(ras24))))
### Plot the bias file
plot(bias1, col = viridis(7)) #or col = grey.colors(7)
infiles
# new argument 'recursive' means, that also subfolders are checked!
infiles <- list.files(path=paste(output_wd,'/MaxEntRes',
sep=''),pattern='_avg.asc$',
full.names=TRUE,recursive=TRUE )
infiles
?list.files
me_stack <- rast(infiles[c(1:4)])
me_stack
# name sequence according to infiles list above
names(me_stack) <- c('curr_noBias','fut_noBias',
'curr_withBias','fut_withBias')
plot(me_stack,col=viridis(100)) # note: I might use a different example than you did in MaxEnt
boxplot(me_stack,layers = c(1,3,2,4),notch=T,outline=F)
me_res <- list.files(path=paste(output_wd,'/MaxEntRes',sep=''),
pattern='maxentResults.csv',
full.names=TRUE,recursive=TRUE )
me_res
store_res <- lapply(me_res,FUN=read.csv) #store as list obj.
store_res
str(store_res)
zename<-'X10.percentile.training.presence.logistic.threshold' # check if the column name is the same !!!!!
zecol <-which(colnames(store_res[[1]]) == zename)
zecol
## a little head twister:
## access each element of your list, which is a whole dataset with store_res[[1]]
## and inside this list object = data.frame, access the element of
## the last row (nrow), and the column zecol] containing the threshold value
t_noBias <- store_res[[1]][nrow(store_res[[1]]),zecol]
t_withBias <- store_res[[2]][nrow(store_res[[2]]),zecol]
t_noBias #the thresholds
t_withBias
all_bias <- rep(c(t_noBias,t_withBias), each=2)
all_bias
binary_thresh <- me_stack >= all_bias
plot(binary_thresh)
# Extract relative probability values inside protected areas PAs
# check if overlay correct - only works when you have NOT aggregated the maps
compareGeom(PA_ras,me_stack[[1]])
ex <- which(values(PA_ras)==1) ##remember PA_ras == 1 where the PAs are
ex
# ex # gives Pointer to elements/ Index
ex_stack <- extract(x=me_stack, y=ex)
head(ex_stack)
boxplot(ex_stack,na.rm=T)