Learn R Programming

SDMtune (version 0.1.0)

predict,SDMmodel-method: Predict

Description

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

Usage

# S4 method for SDMmodel
predict(object, data, type, clamp = TRUE,
  filename = "", format = "GTiff", extent = NULL, parallel = FALSE,
  progress = "", ...)

Arguments

object

'>SDMmodel object.

data

data.frame, '>SWD, stack.

type

character. Output type, see details.

clamp

logical for clumping during prediction, default is TRUE.

filename

character. Output file name for the prediction map, if provided the output is saved in a file.

format

character. The output format, see writeRaster for all the options, default is "GTiff".

extent

Extent object, if provided it restricts the prediction to the given extent, default is NULL.

parallel

logical to use parallel computation during prediction, default is FALSE.

progress

character to display a progress bar: "text", "window" or "" (default) for no progress bar.

...

Additional arguments to pass to the writeRaster function.

Value

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

Details

  • For models trained with the Maxent method the argument type can be: "raw", "logistic" and "cloglog".

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

  • Parallel computation increases the speed only for large datasets due to the time necessary to create the cluster. For Maxent models the function performs the prediction in R without calling the MaxEnt java software. This results is a faster computation for large datasets.

References

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

Examples

Run this code
# NOT RUN {
# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
                    pattern = "grd", full.names = TRUE)
predictors <- raster::stack(files)

# Prepare presence locations
p_coords <- condor[, 1:2]

# Prepare background locations
bg_coords <- dismo::randomPoints(predictors, 5000)

# Create SWD object
presence <- prepareSWD(species = "Vultur gryphus", coords = p_coords,
                       env = predictors, categorical = "biome")
bg <- prepareSWD(species = "Vultur gryphus", coords = bg_coords,
                 env = predictors, categorical = "biome")

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

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

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

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

# }
# NOT RUN {
# Make logistic prediction for the all study area and save it in a file
predict(model, data = predictors, type = "logistic", filename = "my_map")
# }

Run the code above in your browser using DataLab