predict-SDMmodel-method: Predict

predict,SDMmodel-methodR Documentation

Predict

Description

Predict the output for a new dataset given a trained SDMmodel model.

Usage

## S4 method for signature 'SDMmodel'
predict(
  object,
  data,
  type = NULL,
  clamp = TRUE,
  filename = "",
  overwrite = FALSE,
  wopt = list(),
  extent = NULL,
  ...
)

Arguments

object

SDMmodel object.

data

data.frame, SWD or rast with the data for the prediction.

type

character. Output type, see details, used only for Maxent and Maxnet methods.

clamp

logical for clumping during prediction, used only for Maxent and Maxnet methods.

filename

character. If provided the raster map is saved in a file. It must include the extension.

overwrite

logical. If TRUE an existing file is overwritten.

wopt

list. Writing options passed to writeRaster.

extent

ext object, if provided it restricts the prediction to the given extent.

...

Additional arguments to pass to the predict function.

Details

  • filename, and extent are arguments used only when the prediction is run for a rast object.

  • For models trained with the Maxent method the argument type can be: "raw", "logistic" and "cloglog". The function performs the prediction in R without calling the MaxEnt Java software. This results in a faster computation for large datasets and might result in a slightly different output compared to the Java software.

  • For models trained with the Maxnet method the argument type can be: "link", "exponential", "logistic" and "cloglog", see maxnet for more details.

  • For models trained with the ANN method the function uses the "raw" output type.

  • For models trained with the RF method the output is the probability of class 1.

  • For models trained with the BRT method the function uses the number of trees defined to train the model and the "response" output type.

Value

A vector with the prediction or a rast object if data is a raster rast.

Author(s)

Sergio Vignali

References

Wilson P.D., (2009). Guidelines for computing MaxEnt model output values from a lambdas file.

Examples

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

# Split presence locations in training (80%) and testing (20%) datasets
datasets <- trainValTest(data,
                         test = 0.2,
                         only_presence = TRUE)
train <- datasets[[1]]
test <- datasets[[2]]

# Train a model
model <- train(method = "Maxnet",
               data = train,
               fc = "l")

# Make cloglog prediction for the test dataset
predict(model,
        data = test,
        type = "cloglog")

# Make logistic prediction for the whole study area
predict(model,
        data = predictors,
        type = "logistic")

## Not run: 
# Make logistic prediction for the whole study area and save it in a file.
# Note that the filename must include the extension. The function saves the
# file in your working directory
predict(model,
        data = predictors,
        type = "logistic",
        filename = "my_map.tif")
## End(Not run)

SDMtune documentation built on July 9, 2023, 6:03 p.m.