This function computes species distribution models using two modelling algorithms: generalized linear models, and maximum entropy (only if rJava is available). Note: this is an experimental function, and may change in the future.

  predictors = NULL,
  pol = NULL,
  thin = TRUE,
  thin.size = 500,
  algorithm = "all",
  size = 50,
  width = 50000,
  mask = FALSE



A dataframe containing the species occurrences and geographic coordinates. Column 1 labeled as "species", column 2 "lon", column 3 "lat".


A SpatRaster to extract values from the locations in x on which the models will be projected.


A vector polygon specifying the boundary to restrict the prediction. If NULL, the extent of input points is used.


Whether to thin occurrences


The size of the thin occurrences.


Character. The choice of algorithm to run the species distribution model. Available algorithms include:

  • “all”: Calls all available algorithms: GLM, and MAXENT.

  • “GLM”: Calls only Generalized linear model.

  • “MAXENT”: Calls only Maximum entropy.


Minimum number of points required to successfully run a species distribution model especially for species with few occurrences.


Width of buffer in meter if x is in longitude/latitude CRS.


logical. Should y be used to mask? Only used if pol is a SpatVector


A list with the following objects:

  • ensemble_raster The ensembled raster that predicts the potential species distribution based on the algorithms selected.

  • data The dataframe of occurrences used to implement the model.

  • polygon Map polygons of the predicted distributions analogous to extent-of-occurrence range polygon.

  • indiv_models Raster layers for the separate models that predict the potential species distribution.


Zurell, D., Franklin, J., König, C., Bouchet, P.J., Dormann, C.F., Elith, J., Fandos, G., Feng, X., Guillera‐Arroita, G., Guisan, A., Lahoz‐Monfort, J.J., Leitão, P.J., Park, D.S., Peterson, A.T., Rapacciuolo, G., Schmatz, D.R., Schröder, B., Serra‐Diaz, J.M., Thuiller, W., Yates, K.L., Zimmermann, N.E. and Merow, C. (2020), A standard protocol for reporting species distribution models. Ecography, 43: 1261-1277.


# \donttest{
# get predictor variables
f <- system.file("ex/bio.tif", package="predicts")
preds <- rast(f)

# get species occurrences
b <- file.path(system.file(package="predicts"), "ex/bradypus.csv")
d <- read.csv(b)

# fit ensemble model for four algorithms
m <- sdm(d, predictors = preds, algorithm = "all")
#> Warning: [spatSample] fewer cells returned than requested
#> Warning: prediction from a rank-deficient fit may be misleading
#> Warning: prediction from a rank-deficient fit may be misleading
#> Warning: prediction from a rank-deficient fit may be misleading
#> Warning: prediction from a rank-deficient fit may be misleading
#> Loading required namespace: rJava
#> This is maxent_model version 3.4.3 
#> Warning: [spatSample] more non-NA cells requested than available
#> Warning: SpatVector objects are converted to sf objects in smoothr. This conversion may introduce errors and increase the time required to perform smoothing.
# plot(m$ensemble_raster)
# plot(m$polygon, add=TRUE)
# }