'Error to perform Collinearity with findCorrelation () function (creation SDM)

I'm trying to create a species distribution model (SDM) with the presence-absence methodology. I have done all the necessary steps (below the complete code of one of the interested species). To do this, I downloaded the 19 bioclimatic variables from WorldClim and made a crop of Europe, excluding Russia. However I need to do the collinearity to exclude the correlated variables. The problem is that when I go to search correlations, it returns me an empty dataframe (data not available)(the empty dataframe is "Vars_to_removemin" at the end of code). I have already used these codes and they have not created any problems for me, does anyone know a way to perform the collinearity of the data in a different way or do they know why they give me this error? Below is the complete and fully reproducible code (5 minutes to reproduce. Thank you if you will help me, i hope you have a good day and good job!

library(raster)
library(dismo)
library(dplyr)
library(rnaturalearth)
library(caret)


#Import data miniopterus
minio<- gbif("Miniopterus", "schreibersii" , download=T)


#Filter data miniopterus

minio<- minio%>%
  filter(!is.na(lat))%>%
  filter(!is.na(lon))%>%
  filter(year>1980)%>%
  filter(basisOfRecord %in% c("HUMAN_OBSERVATION", "OBSERVATION"))


#Create miniogeo (lon, lat)
miniogeo<-minio%>%
  select(lon,lat)
head(miniogeo)

miniogeo$species<-1
coordinates(miniogeo) <-c("lon","lat")
 

#set  crs
crs(miniogeo) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
proj4string(miniogeo) <- CRS("+init=epsg:4326")

#Worlclim data and Europe map
Europe <- ne_countries(scale="medium", type="map_units", returnclass="sf", continent="Europe")

Worldclim<-raster::getData('worldclim', var='bio', res=2.5) 

Europe <- Europe %>%
  dplyr::select(geometry,name_long)  %>%  
  filter(name_long!='Russian Federation')

envData<-crop(Worldclim, Europe)
EuropePred <- mask(envData, Europe) 


#sample 5000
set.seed(999)

minio5000<- miniogeo%>%
  as.data.frame()%>%
  sample_n(5000)

coordinates(minio5000) <-c("lon","lat")

crs(minio5000) <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
proj4string(minio5000) <- CRS("+init=epsg:4326")


#(Re)create a dataframe miniopterus
xypMinio<-as.data.frame(minio5000,row.names = NULL) 


#Absences miniopterus
colnames(xypMinio) <- c("x","y","presence")

sample_abxy<- randomPoints(EuropePred, 12500, p=minio5000)


#dataframe uniti pres/abs
sample_abxydf<-as.data.frame(sample_abxy)
sample_abxydf$presence<-0

minPresAbs<-rbind(sample_abxydf, xypMinio)

#predictors
predictors_min<- raster::extract(EuropePred, minPresAbs[,1:2], df=T)
predictors_min<- predictors_min[,-1]

crs(minPresAbs)<-crs(EuropePred)

#collineary test
Vars_to_removemin <- data.frame(BIO=findCorrelation(cor(predictors_min), cutoff = .6, names = T))
intersection1 <- colnames(predictors_min) %in% Vars_to_removemin$BIO

#remove the intersection
predictors_min <- predictors_min[!intersection1]
sdmData_min<- data.frame(pres =minPresAbs[,1], predictors_min[1:ncol(predictors_min)]) 



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source