Skip to content

Commit ec9a81c

Browse files
committed
Add new model ssdm implementations and update documentation. Introduced new methods: fda2, glmnet2, mars2, mda2, ranger2, rf2, and svm2
1 parent e933fd8 commit ec9a81c

File tree

14 files changed

+666
-480
lines changed

14 files changed

+666
-480
lines changed

.lintr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,7 @@ exclusions: list(
105105
"R/mod_prepare_hpc.R" = list(line_length_linter = Inf),
106106
"R/mod_postprocess.R" = list(line_length_linter = 1011:1100),
107107
"R/dwf_wetness_index.R" = list(line_length_linter = Inf),
108-
"R/dwf_soil.R" = list(line_length_linter = Inf)
108+
"R/dwf_soil.R" = list(line_length_linter = Inf),
109+
"inst/glmnet2.R" = list(undesirable_operator_linter = Inf),
110+
"inst/svm2.R" = list(undesirable_operator_linter = Inf)
109111
)

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Package: IASDT.R
33
Title: Modelling the Distribution of Invasive Alien Plant Species in
44
Europe
55
Version: 0.1.12
6-
Date: 2025-12-15
6+
Date: 2025-12-16
77
Authors@R:
88
person("Ahmed", "El-Gabbas", , "ahmed.el-gabbas@ufz.de", role = c("aut", "cre"),
99
comment = c(ORCID = "0000-0003-2225-088X"))

R/mod_ssdm_fit.R

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
#' predictors.
1414
#'
1515
#' @param sdm_method Character. A single SDM algorithm to use for fitting
16-
#' models. Valid values: "glm", "glmpoly", "gam", "glmnet", "mars", "mars2",
17-
#' "gbm", "rf", "ranger", "cart", "rpart", "maxent", "mlp", "rbf", "svm",
18-
#' "svm2", "mda", and "fda". These correspond to selected methods supported by
19-
#' the `sdm` package. For details and supported options, see
20-
#' [sdm::getmethodNames()].
16+
#' models. Valid values: "glm", "glmpoly", "gam", "glmnet/glmnet2",
17+
#' "mars/mars2", "gbm", "rf/rf2", "ranger/ranger2", "cart", "rpart", "maxent",
18+
#' "mlp", "rbf", "svm/svm2", "mda/mda2", and "fda/fda2". These correspond to
19+
#' selected methods supported by the `sdm` package. For details and supported
20+
#' options, see [sdm::getmethodNames()]. Note that some methods have
21+
#' custom implementations (e.g., "glmnet2", "mars2", "ranger2", "rf2",
22+
#' "svm2", "mda2", "fda2") to ensure consistent parameterization and
23+
#' performance across models.
2124
#' @param model_settings List or NULL. List of model-specific settings. If
2225
#' `NULL`, defaults to custom settings defined within the workflow.
2326
#' @param model_dir Character. Path to the directory containing model data and
@@ -200,14 +203,25 @@ fit_sdm_models <- function(
200203
"cross-validation type") %>%
201204
ecokit::info_chunk(cat_bold = TRUE, cat_red = TRUE, line_char_rep = 80L)
202205

203-
# Ensure that svm2 method is registered
204-
if (sdm_method == "svm2") {
205-
copy_svm2()
206-
}
206+
# Ensure that all methods are registered
207+
methods_to_copy <- c(
208+
"fda2", "mda2", "glmnet2", "mars2", "ranger2", "rf2", "svm2")
209+
210+
if (sdm_method %in% methods_to_copy) {
211+
sdm_path <- system.file("methods/sdm", package = "sdm")
212+
method_file <- system.file(paste0(sdm_method, ".R"), package = "IASDT.R")
207213

208-
# Ensure that mars2 method is registered
209-
if (sdm_method == "mars") {
210-
copy_mars2()
214+
if (!nzchar(method_file)) {
215+
ecokit::stop_ctx(
216+
paste0("`", method_file, "` method file not found in IASDT.R package"))
217+
}
218+
if (!fs::file_exists(method_file)) {
219+
ecokit::stop_ctx(
220+
paste0("`", method_file, "` method file does not exist"),
221+
method_file = method_file)
222+
}
223+
224+
fs::file_copy(path = method_file, new_path = sdm_path, overwrite = TRUE)
211225
}
212226

213227
# |||||||||||||||||||||||||||||||||||||||||||
@@ -216,8 +230,9 @@ fit_sdm_models <- function(
216230

217231
# rbf is not bounded; see https://github.com/babaknaimi/sdm/issues/42
218232
valid_sdm_methods <- c(
219-
"glm", "glmpoly", "gam", "glmnet", "mars", "mars2", "gbm", "rf", "ranger",
220-
"cart", "rpart", "maxent", "mlp", "svm", "svm2", "mda", "fda")
233+
"glm", "glmpoly", "gam", "glmnet", "glmnet2", "mars", "mars2", "gbm", "rf",
234+
"rf2", "ranger", "ranger2", "cart", "rpart", "maxent", "mlp", "svm",
235+
"svm2", "mda", "mda2", "fda", "fda2")
221236
sdm_method_valid <- any(
222237
is.null(sdm_method), length(sdm_method) != 1L,
223238
!is.character(sdm_method), !sdm_method %in% valid_sdm_methods)
@@ -300,6 +315,11 @@ fit_sdm_models <- function(
300315
rm(env_vars_to_read, envir = environment())
301316

302317
path_grid_r <- fs::path(path_grid, "grid_10_land_crop.RData")
318+
if (!fs::file_exists(path_grid_r)) {
319+
ecokit::stop_ctx(
320+
"Path for the Europe boundaries does not exist",
321+
path_grid_r = path_grid_r)
322+
}
303323

304324
# |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
305325

@@ -320,11 +340,14 @@ fit_sdm_models <- function(
320340
"glmpoly", NA_character_,
321341
"gam", "mgcv",
322342
"glmnet", "glmnet",
343+
"glmnet2", "glmnet",
323344
"mars", "earth",
324345
"mars2", "earth",
325346
"gbm", "gbm",
326347
"rf", "randomForest",
348+
"rf2", "randomForest",
327349
"ranger", "ranger",
350+
"ranger2", "ranger",
328351
"cart", "tree",
329352
"rpart", "rpart",
330353
"maxent", c("dismo", "rJava"),
@@ -333,7 +356,9 @@ fit_sdm_models <- function(
333356
"svm", "kernlab",
334357
"svm2", "e1071",
335358
"mda", "mda",
336-
"fda", "mda") %>%
359+
"mda2", "mda",
360+
"fda", "mda",
361+
"fda2", "mda") %>%
337362
dplyr::filter(mod_method == sdm_method) %>%
338363
dplyr::pull(packages) %>%
339364
unlist()
@@ -402,7 +427,7 @@ fit_sdm_models <- function(
402427
input_data = input_data, output_directory = output_directory,
403428
path_grid_r = path_grid_r, copy_maxent_html = copy_maxent_html),
404429
"fitted probabilities numerically",
405-
"Using formula(x) is deprecated when", "Consider formula")
430+
"Using formula.+ is deprecated when")
406431
},
407432
future.scheduling = Inf, future.seed = TRUE,
408433
future.packages = pkgs_to_load, future.globals = future_globals) %>%

0 commit comments

Comments
 (0)