Data preparation for modelling for Pteronura brasiliensis, with the covariates bio_3, bio_5, woodysavanna, and wetland (selected in the previous step).
# calculate area in each raster cellPO_pbrasiliensis.area <- terra::cellSize(PO_pbrasiliensis_time1_raster[[1]], unit='m', transform=F) %>%classify(cbind(NaN, NA)) %>% terra::values()# calculate coordinates for each raster cellPO_pbrasiliensis.coords <- terra::xyFromCell(PO_pbrasiliensis_time1_raster, cell=1:ncell(PO_pbrasiliensis_time1_raster)) %>%as.data.frame()names(PO_pbrasiliensis.coords) <-c('X', 'Y')# number of cells in the rasters (both the same)PO_pbrasiliensis.cell <-1:ncell(PO_pbrasiliensis_time1_raster)# with the environmental variables values for each cellPO_pbrasiliensis.env <- env_100k_resampled[] # scaled values# with the mean accessibility value for each cellPO_pbrasiliensis.acce <- acce_100k_resampled # scaled values# calculate point count in each raster cellPO_pbrasiliensis_time1.count <- PO_pbrasiliensis_time1_raster %>%classify(cbind(NaN, NA)) %>% terra::values() %>% as_tibble %>% dplyr::select(count)PO_pbrasiliensis_time2.count <- PO_pbrasiliensis_time2_raster %>%classify(cbind(NaN, NA)) %>% terra::values() %>% as_tibble %>% dplyr::select(count)PO_pbrasiliensis.countries <- latam_countries %>%classify(cbind(NaN, NA))# save time1 and time2 datasets PO_pbrasiliensis_time1.model.data <-data.frame(PO_pbrasiliensis.coords,pixel = PO_pbrasiliensis.cell[],area = PO_pbrasiliensis.area,pt.count = PO_pbrasiliensis_time1.count,env = PO_pbrasiliensis.env,acce = PO_pbrasiliensis.acce[], country = PO_pbrasiliensis.countries[])PO_pbrasiliensis_time2.model.data <-data.frame(PO_pbrasiliensis.coords,pixel = PO_pbrasiliensis.cell[],area = PO_pbrasiliensis.area,pt.count = PO_pbrasiliensis_time2.count,env = PO_pbrasiliensis.env,acce = PO_pbrasiliensis.acce[], country = PO_pbrasiliensis.countries[])
The range (and interquartile range) of values for each covariate that is sampled by each dataset
Code
getRangeIQR <-function(env_PX){ env_PX.df <-tibble(env=character(),range =numeric(),iqr =numeric(),stringsAsFactors=FALSE)for (i in1:ncol(env_PX)){ df <-tibble(env =names(env_PX[i]),range =range(env_PX[[i]], na.rm=T)[2],iqr=IQR(env_PA[[i]], na.rm = T)) env_PX.df <-rbind(env_PX.df, df) }return(env_PX.df)}# covariates for PAenv_PA <- terra::extract(x = env, y =rbind(vect(PA_pbrasiliensis_time1_blobs), vect(PA_pbrasiliensis_time2_blobs)), fun = mean, na.rm=TRUE) %>%mutate(across(where(is.numeric), ~ifelse(is.nan(.), NA, .))) summary(env_PA[-1])
bio_3 bio_5 wetland woodysavanna
Min. : 0.1059 Min. : 2.509 Min. :0.00000 Min. :0.00000
1st Qu.:16.5121 1st Qu.:200.933 1st Qu.:0.00000 1st Qu.:0.00000
Median :19.4354 Median :245.688 Median :0.00000 Median :0.00000
Mean :19.7459 Mean :251.894 Mean :0.01943 Mean :0.04786
3rd Qu.:23.5625 3rd Qu.:294.838 3rd Qu.:0.00000 3rd Qu.:0.02628
Max. :27.4998 Max. :637.351 Max. :0.99773 Max. :1.00000
Code
env_PA.RangeIQR <-getRangeIQR(env_PA[-1]) %>%mutate(data='PA')for (i in2:ncol(env_PA)){ range <-range(env_PA[[i]], na.rm=T)[2] iqr <-IQR(env_PA[[i]], na.rm = T)print(str_glue('PA {names(env_PA[i])} -> range: {range} - IQR: {iqr}'))}
PA bio_3 -> range: 27.4998134613037 - IQR: 7.05035022519669
PA bio_5 -> range: 637.351318359375 - IQR: 93.9053077697754
PA wetland -> range: 0.997725650668144 - IQR: 0
PA woodysavanna -> range: 1 - IQR: 0.0262835070025176
bio_3 bio_5 wetland woodysavanna
Min. :-2.701 Min. : 1.181 Min. :0.0000000 Min. :0.0000000
1st Qu.:12.658 1st Qu.:132.409 1st Qu.:0.0000518 1st Qu.:0.0001956
Median :21.209 Median :227.126 Median :0.0008525 Median :0.0092380
Mean :18.395 Mean :223.743 Mean :0.0080587 Mean :0.0751433
3rd Qu.:24.919 3rd Qu.:315.360 3rd Qu.:0.0056681 3rd Qu.:0.0766570
Max. :27.235 Max. :720.784 Max. :0.4137636 Max. :0.8848116
Code
env_PO.RangeIQR <-getRangeIQR(env_PO) %>%mutate(data='PO')for (i in1:ncol(env_PO)){ range <-range(env_PO[[i]], na.rm=T)[2] iqr <-IQR(env_PO[[i]], na.rm = T)print(str_glue('PO {names(env_PO[i])} -> range: {range} - IQR: {iqr}'))}
PO bio_3 -> range: 27.2350292205811 - IQR: 12.2605299949646
PO bio_5 -> range: 720.784484863281 - IQR: 182.950798034668
PO wetland -> range: 0.413763552904129 - IQR: 0.00561631976961507
PO woodysavanna -> range: 0.884811639785767 - IQR: 0.0764613711871789