Problems when I try to predict future distribution

I am trying to run a sdm but I keep getting this message "Error in o[[id[j]]] : index out of limits", the error just happens when I try to predict the future distribution, I am using the functions "predict" and "ensemble", the same error appear after running both.
The functions 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.

Here is the code that I am using:



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)

dbio<-exclude(dbio, v)

#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')

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)

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

v1<- vifstep(ex1)

dbiofuture<-exclude(dbiofuture, v1)

#Modeling future species distribution

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

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.