我喜欢使用通过adehabitatHS软件包使用的ENFA(生态位生态因子分析)方法,但是当我尝试使用此功能时,我的输出为Error in crossprod(Ze, DpZ): non-conformable arguments
。我检查了输入对象,并且坐标在SpatialPointsDataFrame
中,环境属性为SpatialPixelsDataFrame
,就像在enfa()函数的帮助下一样。但是,在我的示例中:
#Packages
library(dismo)
library(raster)
library(adehabitatMA)
library(adehabitatHS)
#Bradypus presence data set
file <- paste(system.file(package="dismo"), "/ex/bradypus.csv", sep="")
bradypus <- read.table(file, header=TRUE, sep="," )
# I don't need the first column
bradypus <- bradypus[,-1]
id=1:length(bradypus[,1])
bradypus.data <- as.data.frame(cbind(bradypus,id))
coordinates(bradypus.data) <- ~lon+lat
bradypus.data<-as(bradypus.data, 'SpatialPointsDataFrame')
proj4string(bradypus.data) <- CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
#Environmental variables
clim=getData('worldclim', var='bio', res=10)
clim.bradypus<-raster::crop(clim,c(-85.9333, -40.0667, -23.45, 13.95)) # trim to a smaller region
plot(clim.bradypus[[1]])
plot(bradypus.data,add=T)
bradypus.map<-as(clim.bradypus, "SpatialPixelsDataFrame")
proj4string(bradypus.map) <- CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
## We prepare the data for the ENFA
tab <-bradypus.map
pr <- slot(count.points(bradypus.data, bradypus.map), "data")[,1]
# Run ENFA and make predictions of habitat suitability index
#First I create and removed NA (my original data set has NA)
idx = sample(1:nrow(tab),100)
tab[idx,] = NA
f1 <- function(vec) {
m <- mean(vec, na.rm = TRUE)
vec[is.na(vec)] <- m
return(vec)
}
tab2 = apply(tab,2,f1)
enfa.pink<- enfa(dudi.pca(tab2, scannf=FALSE), pr, scannf=FALSE, nf=2)## Applied ENFA
crossprod(Ze,DpZ)中的错误:参数不一致
1:在x * pr中:较长的对象长度不是较短的对象长度的倍数...
关于我可以解决的任何想法吗?
感谢进阶