# ====================================================================
#
# Copyright 2025, PBL Netherlands Environmental Assessment Agency
# See the copyright notice at the end of this file.
#
# ====================================================================


#10. Calculate the variable importance based on full model 


VarImpFunction <- function (Vars, myBiomodModelOut_GAMGLM_100p, myBiomodModelOut_BRT_100p, myRespName){
  
varimp_GAMGLM <- as.data.table(get_variables_importance(myBiomodModelOut_GAMGLM_100p))
varimp_BRT <- as.data.table(get_variables_importance(myBiomodModelOut_BRT_100p))

algo <- c("GLM","GAM","GBM")

Vartab <- data.table(Species=myRespName)

for (a in algo) {
    for (v in Vars) {
      
      if (a=="GLM" || a == "GAM"){
      x <- varimp_GAMGLM[algo == a & expl.var == v, var.imp]
      } else {
        x <- varimp_BRT[algo == a & expl.var == v, var.imp]
      }
      col_name <- paste0(v, "_", a)
      Vartab[,(col_name) := x]
    }
}

return (list (VarImpdt = Vartab))
}



# ====================================================================
#
# Copyright 2025, PBL Netherlands Environmental Assessment Agency
# 
# This source code of the BioScore model is owned by PBL Netherlands Environmental Assessment Agency. 
# It is not permitted to copy, redistribute, remix, transform, and build upon the material without written approval of PBL. 
# Permission for commercial purposes will not be granted. 
# This code is published to improve the transparency of the models used by PBL, 
# but without any warranty for fitness for any other purpose. 
# After approval of PBL to use the code, PBL will not provide any support.
#
# 
# ====================================================================

