# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
pattern = "grd",
full.names = TRUE)
predictors <- terra::rast(files)
# Prepare presence and background locations
p_coords <- virtualSp$presence
bg_coords <- virtualSp$background
# Create SWD object
data <- prepareSWD(species = "Virtual species",
p = p_coords,
a = bg_coords,
env = predictors,
categorical = "biome")
# Create 4 random folds splitting only the presence data
folds <- randomFolds(data,
k = 4,
only_presence = TRUE)
model <- train(method = "Maxnet",
data = data,
fc = "l",
folds = folds)
# Make cloglog prediction for the whole study area and get the result as
# average of the k models
predict(model,
data = predictors,
fun = "mean",
type = "cloglog")
# Make cloglog prediction for the whole study area, get the average, standard
# deviation, and maximum values of the k models, and save the output in three
# files.
# The following commands save the output in the working directory. Note that
# the `filename` must include the extension
if (FALSE) {
maps <- predict(model,
data = predictors,
fun = c("mean", "sd", "max"),
type = "cloglog",
filename = "prediction.tif")
# In this case three files are created: prediction_mean.tif,
# prediction_sd.tif and prediction_max.tif
plotPred(maps$mean)
plotPred(maps$sd)
plotPred(maps$max)
# Make logistic prediction for the whole study area, given as standard
# deviation of the k models, and save it in a file
predict(model,
data = predictors,
fun = "sd",
type = "logistic",
filename = "my_map.tif")}
Run the code above in your browser using DataLab