Problems after running function "ensemble"

I am trying to run a sdm but I keep getting this message "Error in o[[id[j]]] : index out of limits" after running the function "ensemble" from the package sdm.
The function runs for quite some time, but in the end this message always appear .
If anyone could help with this error I would appreciate a lot.

Hi,

In order for us to help you with your question, please provide us a minimal reproducible example where you provide a minimal (dummy) dataset and code that can recreate the issue. Once we have that, we can go from there. For help on creating a Reprex, see this guide:

Good luck!
PJ

Hi, thank you for your attention, here is a the simplifide version of the code that I'm using. I forgot to say that this problem only occur when I try to use the 'ensemble' function for the future data and that the same problem occur when I try to use the 'predict' function for future data.

library(sdm)
library(dismo)
library(usdm)
library(dplyr)
library(tidyr)
library(mapview)
library(rgeos)

installAll()

Aus<-gbif("Austroblechnum", "penna-marina", download = T)

#Filtering the data
Aus <- Aus %>% filter (country %in% c("Brazil", "Argentina", "Bolivia",
"Chile", "Costa Rica","Ecuador", "Mexico"))

Aus <- Aus %>% filter (basisOfRecord %in% c("HUMAN_OBSERVATION","PRESERVED_SPECIMEN"))

#Selecting the variables and deleting the records with no coordinates
Austro <- Aus %>% select(lon,lat)

Austro<- Austro %>% drop_na()
Austro$species <- 1

#Transforming 'Austro' from data frame to Spatial point data frame

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

#Getting climate data from worldclim

dbio<-raster::getData('worldclim', var='bio', res=10)

#Selecting the study area and cropping the plot map
e <- drawExtent()

Austro<- crop(Austro, e)
dbio <- crop(dbio, e)

#verifing the correlation between variables using variance inflation factor

ex<-raster::extract(dbio, Austro)

v<- vifstep(ex)
v

dbio<-exclude(dbio, v)
dbio

#Creating a sdmData object
sdm<-sdmData(species~., Austro, predictors= dbio, bg = list(method='gRandom',n=1000))

#Modeling the current distribution
gj <- sdm(species~., sdm, methods=c('maxent', 'rf', 'glm','gbm','gam','tree'),
replication = c('boot', 'cv'),test.p=30, n=3,
parallelSettings=list(ncore=4, method='parallel'))

vb <-predict(gj, dbio, filename='testing again1.img')
vb

ensaustro <- ensemble(gj, vb, filename='ensemble test12.img',
setting = list(method='weighted',stat ='AIC', opt=2))

#Getting future climate data
dbiofuture<- raster::getData('CMIP5', var='bio', res=2.5, rcp=85, model='AC', year=70)

#Changing future varaibles names
dbio123<-raster::getData('worldclim', var='bio', res=10)

names(dbiofuture)
names(dbio123)
names(dbiofuture)<- names(dbio123)

#verifing the correlation between future variables using variance inflation factor
ex1<-raster::extract(dbiofuture, Austro)

ex1
v1<- vifstep(ex1)

dbiofuture<-exclude(dbiofuture, v1)

#Modeling future species distribution

sdmf<-sdmData(species~., Austro, predictors= dbiofuture, bg = list(method='gRandom',n=1000))
sdmf

Austrofuture<-sdm(species~., sdmf , methods=c('maxent', 'rf', 'glm','gbm','gam','tree'),
replication = c('boot', 'cv'), test.p=30, n=5,
parallelSettings=list(ncore=4, method='parallel'))

testaustrofuture <- predict(Austrofuture, dbiofuture, filename ='testfuture.img')

en1<-ensemble(gj, dbiofuture, filename='ensemble test f.img',
setting = list(method='pa',stat ='AIC', opt=2))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.