Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdm_eval fails for presence-only tune_max #308

Closed
wardfont opened this issue Jul 4, 2022 · 1 comment
Closed

sdm_eval fails for presence-only tune_max #308

wardfont opened this issue Jul 4, 2022 · 1 comment

Comments

@wardfont
Copy link

wardfont commented Jul 4, 2022

When using tune_max with presence-only data and background, the evaluation step fails since both the number of absences and presences have to be greater than zero in line 152 of sdm_eval: if (na == 0 | np == 0).

Is there a way to use tune_max with presence-only data?

@sjevelazco
Copy link
Owner

Hi
Thank you so much for reporting it. Now fit_max, tune_max, and esm_max functions can fit maxent model with presences and background points. However, if you intend to compare maxent with other algorithms (e.g., RF, SVM, GAM), I strongly recommend fitting maxent with presences-pseudo-absences (or presences-absences) and background points. If those three data types are used in fit_max, tune_max, and esm_max, models will be fitted with presences and background points and validated with presence and pseudo-absences (or absences). See in the new package documentation about these fitting options.

Here is an example of how to fit maxent with only with presences and background points

Cheers

require(flexsdm)
require(dplyr)

data("abies")
data("backg")
abies # environmental conditions of presence-absence data
backg # environmental conditions of background points

# Using k-fold partition method
# Remember that the partition method, number of folds or replications must
# be the same for presence-absence and background points datasets

abies <- abies %>% dplyr::filter(pr_ab==1) %>% dplyr::slice_sample(prop = 0.5)
abies2 <- part_random(
  data = abies,
  pr_ab = "pr_ab",
  method = c(method = "kfold", folds = 3)
)
abies2

backg <- backg %>% dplyr::slice_sample(prop = 0.5)
set.seed(1)
backg <- dplyr::sample_n(backg, size = 2000, replace = FALSE)
backg2 <- part_random(
  data = backg,
  pr_ab = "pr_ab",
  method = c(method = "kfold", folds = 3)
)
backg

gridtest <-
  expand.grid(
    regmult = seq(0.1, 3, 0.5),
    classes = c("l", "lq", "lqh")
  )

max_t1 <- tune_max(
  data = abies2,
  response = "pr_ab",
  predictors = c("aet", "pH", "awc", "depth"),
  predictors_f = c("landform"),
  partition = ".part",
  background = backg2,
  grid = gridtest,
  thr = "max_sens_spec",
  metric = "TSS",
  clamp = TRUE,
  pred_type = "cloglog",
  n_cores = 6 # activate six cores for speed up this process
)

max_t1
plot(max_t1$model, type="cloglog")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants