[R-sig-Geo] ENFA in R: crossprod(Ze, DpZ) error

ASANTOS @|ex@ndre@@nto@br @end|ng |rom y@hoo@com@br
Wed Aug 7 02:32:17 CEST 2019


Dear Members,

I've like to use ENFA approach with my data set, but I have an *Error in 
crossprod(Ze, DpZ) : non-conformable arguments* as output when I try to 
use this function. I check my input objects and my coordinates are 
in??'SpatialPointsDataFrame' and??the environmental attributes as 
SpatialPixelsDataFrame" like in the help of the enfa() function. But, in 
my example:

#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


*Error in crossprod(Ze, DpZ) : non-conformable arguments*

1: In x * pr : longer object length is not a multiple of shorter object 
length ...


Any ideas about I can fix it?

Thanks in advanced

-- 
======================================================================
Alexandre dos Santos
Prote????o Florestal
IFMT - Instituto Federal de Educa????o, Ci??ncia e Tecnologia de Mato Grosso
Campus C??ceres
Caixa Postal 244
Avenida dos Ramires, s/n
Bairro: Distrito Industrial
C??ceres - MT?????????????????????????????????????????? CEP: 78.200-000
Fone: (+55) 65 99686-6970 (VIVO) (+55) 65 3221-2674 (FIXO)

alexandre.santos using cas.ifmt.edu.br
Lattes: http://lattes.cnpq.br/1360403201088680
OrcID: orcid.org/0000-0001-8232-6722
Researchgate: www.researchgate.net/profile/Alexandre_Santos10
LinkedIn: br.linkedin.com/in/alexandre-dos-santos-87961635
Mendeley:www.mendeley.com/profiles/alexandre-dos-santos6/
======================================================================





	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list