babaknaimi / sdm

sdm is an extensible framework to develop species distributions models using individual and community-based approaches, generate ensembles of models, evaluate the models, and predict species potential distributions in space and time.
20 stars 5 forks source link

Variables contribution and mapping of model predictions using presence-only data #14

Open flopesdematos opened 2 years ago

flopesdematos commented 2 years ago

Dear Babak,

I'm trying to extract the variables importance and map the model prediction of models fitted using presence-only. However, the following errors pop-up:

I include a reproducible example:

library(sdm)

file <- system.file("external/po_spatial_points.shp", package="sdm") # path to a shapefile

po <- shapefile(file)
class(po) 

head(po) 

path <- system.file("external", package="sdm") 
lst <- list.files(path=path,pattern='asc$',full.names = T) 

preds <- stack(lst) # making a raster object

d <- sdmData(formula=sp4~., train=po, predictors=preds)

d

m <- sdm(sp4~., data=d, methods=c("bioclim","domain"),
          replication='sub', test.percent=30, n=10)

getModelInfo(m)

getVarImp(m) 

p1 <- predict(m, newdata=preds)

There is an easy fix for this issue?

Thank you!

babaknaimi commented 2 years ago

Hi,

I understand that the methods you selected are presence-only, but it would currently be better to generate background as well, because they would be needed for model evaluations, so adding bg to sdmData would fix the issue.

d <- sdmData(formula=sp4~., train=po, predictors=preds,bg=list(n=100))

Hope this helps, Babak