0

我正在尝试使用存在-不存在方法创建一个物种分布模型(SDM)。我已经完成了所有必要的步骤(在感兴趣的物种之一的完整代码下方)。为此,我从 WorldClim 下载了 19 个生物气候变量,并制作了欧洲(不包括俄罗斯)的作物。但是我需要做共线性来排除相关变量。问题是当我去搜索相关性时,它返回一个空数据框(数据不可用)(空数据框是代码末尾的“Vars_to_removemin”)。我已经使用了这些代码并且它们没有给我造成任何问题,有没有人知道一种以不同方式执行数据共线性的方法,或者他们知道为什么给我这个错误?以下是完整且完全可复现的代码(复现 5 分钟。

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)]) 

4

0 回答 0