R/sdm_spec_maxent.R

Defines functions sdm_spec_maxent

Documented in sdm_spec_maxent

#' Model specification for a MaxEnt for SDM
#'
#' This function returns a [parsnip::model_spec] for a MaxEnt model to be used
#' in Species Distribution Models.
#'
#' @param ... parameters to be passed to [maxent()] to customise the model. See
#'   the help of that function for details.
#' @param tune character defining the tuning strategy. Valid strategies are:
#' * "sdm" chooses hyper-parameters that are most important to tune for
#'   an sdm (for *maxent*, 'feature_classes' and 'regularization_multiplier')
#' * "all" tunes all hyperparameters (for *maxent*, 'feature_classes' and
#'  'regularization_multiplier', the same as with tune = "sdm")
#' * "custom" passes the options from '...'
#' * "none" does not tune any hyperparameter
#' @returns a [parsnip::model_spec] of the model.
#' @examples
#' test_maxent_spec <- sdm_spec_maxent(tune = "sdm")
#' test_maxent_spec
#' # setting specific values
#' sdm_spec_maxent(tune = "custom", feature_classes = "lq")
#' @export
#' @family "sdm model specifications"

sdm_spec_maxent <- function(..., tune = c("sdm", "all", "custom", "none")) {
  tune <- rlang::arg_match(tune)
  if (tune == "sdm") {
    base_spec <- maxent(
      feature_classes = tune::tune(),
      regularization_multiplier = tune::tune(),
      ...
    )
  } else if (tune == "all") {
    base_spec <- maxent(
      feature_classes = tune::tune(),
      regularization_multiplier = tune::tune(),
      ...
    )
  } else if ((tune == "custom") || (tune == "none")) {
    base_spec <- maxent(...)
  }
  base_spec
}

Try the tidysdm package in your browser

Any scripts or data that you put into this service are public.

tidysdm documentation built on April 3, 2025, 9:56 p.m.