if (FALSE) {
file <- system.file("external/species.shp", package="sdm") # get the location of the species data
species <- vect(file) # read the shapefile
path <- system.file("external", package="sdm") # path to the folder contains the data
lst <- list.files(path=path,pattern='asc$',full.names = T) # list the name of the raster files
# stack is a function in the raster package, to read/create a multi-layers raster dataset
preds <- rast(lst) # making a raster object
names(preds) # 4 environmental variables are used!
d <- sdmData(formula=Occurrence~., train=species, predictors=preds)
d
# fit models:
m <- sdm(Occurrence~.,data=d,methods=c('rf','glm','brt'))
# ensemble using weighted averaging based on AUC statistic:
p1 <- ensemble(m, newdata=preds,setting=list(method='weighted',stat='AUC'))
plot(p1, main='Habitat Suitability in Geographic Space')
# Mapping Ecological Niche using selected two variables
niche(x=preds, h=p1, c('precipitation','temperature'))
niche(x=preds, h=p1, c('vegetation','temperature'))
# in case if you do not have the habitat suitability map but species data:
niche(x=preds, h=species, c('vegetation','temperature','Occurrence'))
niche(x=preds, h=d, n=c('vegetation','temperature','Occurrence'), rnd=2)
# rnd is the argument specifies the decimal degrees to which the values on axis rounded.
}
Run the code above in your browser using DataLab