How to make the results of the maxent model in biomod2 consistent with those in the package dismo in R?

I have prepared a set of point data and a set of raster data (both of which are tutorial data from the Maxent official website). Next, I used the package tidysdm to generate a pseudo absence dataset, and applied this pseudo absence dataset to the Maxent model. At the same time, I set relevant parameters in the model to ensure that the parameters of the maxent model in biomod2 and dismo are consistent. However, in the final results, whether it is the importance of variables, the response curve plot, or the predicted values of raster data for the entire study scope, their results are inconsistent. Here is my code. How should I set up my code to ensure that the maxent models of these two extension packages run exactly the same?

# load packages
if (!require(tidyverse)) install.packages("tidyverse")
if (!require(sf)) install.packages("sf")
if (!require(raster)) install.packages("raster")
if (!require(terra)) install.packages("terra")
if (!require(tidyterra)) install.packages("tidyterra")
if (!require(remotes)) install.packages("remotes")
if (!require(biomod2)) remotes::install_version("biomod2", version = "4.2-3-5")
if (!require(dismo)) install.packages("dismo")
if (!require(tidysdm)) install.packages("tidysdm")

# input presence points
occ <- read.csv("tutorial-data/samples/bradypus.csv") %>%
  dplyr::select(-1)
head(occ)

# input raster file
fnames <- list.files(path = "tutorial-data/layers", pattern = ".asc$", full.names = TRUE)
predictors <- raster::stack(fnames)
predictors

# generate pseudo absence
pts_df <- tidysdm::sample_pseudoabs(data = st_as_sf(occ,coords = c("dd.long","dd.lat"),crs = 4326),
                          raster = terra::subset(rast(predictors),1),
                          n = 3*nrow(occ),
                          method = "random")

# get presence points
occ <- pts_df %>% 
  dplyr::filter(class == "presence") %>% 
  st_coordinates() %>% 
  as.data.frame() %>% 
  setNames(c("dd.long","dd.lat"))
# get pseudo absence points
abs <- pts_df %>% 
  dplyr::filter(class == "pseudoabs") %>% 
  st_coordinates() %>% 
  as.data.frame() %>% 
  setNames(c("dd.long","dd.lat"))

# generate maxent model with package "dismo"
# Here set the explain variable "ecoreg" into factor type
maxent_arg <- c("betamultiplier=1", "noautofeature", "noquadratic", "noproduct", "nothreshold", "nohinge")
me <- dismo::maxent(
  x = predictors,
  p = occ,
  a = abs,
  factors = "ecoreg",
  removeDuplicates = FALSE,
  path = "testrun",
  args = maxent_arg
)
# make prediction on raster file
r <- predict(me, predictors)


# generate biomod2 presence and absence points data
biomod2_df <- occ %>% 
  mutate(PA1 = TRUE) %>% 
  mutate(resp.var = 1) %>% 
  rbind(abs %>% 
          mutate(PA1 = TRUE) %>% 
          mutate(resp.var = NA)) %>% 
  rename(lon = dd.long,lat = dd.lat) %>% 
  as.data.frame()

# input raster file and transform the variable ecoreg into factor
predictors <- list.files(path = "tutorial-data/layers", pattern = ".asc$", full.names = TRUE) %>% 
  rast() %>% 
  mutate(across(.cols = ecoreg,.fns = as.factor))

myBiomodData <- BIOMOD_FormatingData(resp.var = biomod2_df$resp.var,
                     expl.var = predictors,
                     resp.xy = biomod2_df[,c("lon","lat")],
                     resp.name = "occ",
                     PA.strategy = 'user.defined',
                     PA.user.table = dplyr::select(biomod2_df,PA1))

mod <- "MAXENT"
maxentlqpht <- c(T, F, F, F, F)
betamult <- 1
myBiomodOption <- BIOMOD_ModelingOptions(
  MAXENT = list(
    path_to_maxent.jar = "maxent.jar",
    memory_allocated = NULL,
    maximumiterations = 500,
    betamultiplier = betamult,
    beta_lqp = 0.05,
    linear = maxentlqpht[1],
    quadratic = maxentlqpht[2],
    product = maxentlqpht[3],
    hinge = maxentlqpht[4],
    threshold = maxentlqpht[5]
  )
)
myBiomodModelOut <- BIOMOD_Modeling(
  bm.format = myBiomodData,
  models = mod,
  bm.options = myBiomodOption,
  var.import = 5,
  metric.eval = c("KAPPA", "TSS", "ROC"),
  do.full.models = F,
  CV.perc = .25,
  modeling.id = "biomod2_test"
)
myMODRespPlot2D <-
  bm_PlotResponseCurves(
    bm.out = myBiomodModelOut,
    models.chosen = get_built_models(myBiomodModelOut, run = "RUN1"),
    fixed.var = "median",
    Data = get_formal_data(myBiomodModelOut, "expl.var"),
    show.variables = get_formal_data(myBiomodModelOut, "expl.var.names"),
    do.bivariate = FALSE
  )

enter image description here

response(me)

enter image description here

plot(me)

enter image description here

get_variables_importance(myBiomodModelOut) %>% 
  group_by(expl.var) %>% 
  summarise(var.imp = mean(var.imp)) %>% 
  arrange(desc(var.imp))

enter image description here

myBiomodProj <- BIOMOD_Projection(
  bm.mod = myBiomodModelOut,
  proj.name = "maxent_biomod2",
  new.env = predictors,
  models.chosen = "all",
  metric.binary = "all",
  metric.filter = "all",
  build.clamping.mask = TRUE,
  output.format = ".img",
  do.stack = FALSE
)


temp_r <- rast(c(
  biomod2 = rast("proj_maxent_biomod2_occ_PA1_RUN1_MAXENT.img"),
  dismo = app(x = rast(r), fun = function(x) ifelse(is.na(x), x, 1000 * x))
)) %>%
  mutate(difference = biomod2 - dismo) %>%
  mutate(across(.cols = everything(), .fns = as.numeric))
temp_r
ggplot() +
  geom_spatraster(data = temp_r) +
  facet_wrap(~lyr) +
  scale_fill_whitebox_c(
    palette = "muted"
  ) +
  theme_light()

enter image description here

New contributor

zmj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật