if (FALSE) {
# let's first fit a set of models and generate prediction and ensemble maps:
# get the path to the species data
file <- system.file("external/sp1.shp", package="sdm")
sp <- vect(file) # read the species records
path <- system.file("external", package="sdm") # path to the folder contains the data
lst <- list.files(path=path,pattern='asc$',full.names = T) # list of predictor filenames
preds <- rast(lst) # making a SpatRaster object (predictors)
d <- sdmData(formula=Occurrence~., train=sp, predictors=preds)
d
# fit two models:
m <- sdm(Occurrence~.,data=d,methods=c('glmp','brt'),replication='boot',n=1)
m
# predictions:
pr <- predict(m, newdata=preds)
plot(pr)
# ensemble::
en <- ensemble(m, newdata=preds,setting=list(method='weighted',stat='AUC'))
plot(en)
#########################
# let's convert probabilities to Presence/absences:
# threshold is extracted for both models based on opt=2 (max[se+sp])
pr.pa <- pa(pr, m, opt=2)
plot(pr.pa)
# if only one of them was needed:
pr.pa1 <- pa(pr[[1]],m, id=1,opt=2)
plot(pr.pa1)
#---------------
# if you have threshold values, you can directly use them in y:
th <- getEvaluation(m,stat='threshold',opt=1) # get threshold values
th
pr.pa <- pa(pr, y=th[,2])
plot(pr.pa)
#--------------
# to convert to PA based on "ensemble":
en.pa <- pa(en, m, id="ensemble", opt=2)
plot(en.pa)
}
Run the code above in your browser using DataLab