R/select_sdmVariables.R

Defines functions select_sdmVariables

Documented in select_sdmVariables

#' Reduce potentially problematic multicollinearity by removing variables until
#' the variance inflation factors (VIFs) of all predictor variables are below
#' a user-defined value.
#'
#' @description Removes the variable that contributed the least to a default
#' Maxent model and had a VIF greater than a user-defined value until all
#' variables used in the species distribution model have VIFs less than the
#' user-defined value.
#'
#' @param predictor_vars raster stack of variables to be used as potential
#' predictor variables
#'
#' @param maxVIF numeric value that denotes the maximum allowed VIF value among
#' predictor variables.
#'
#' @return A raster stack of predictor variables that has been reduced
#' to limit potential problems with multicollinearity.
#'
#' @importFrom usdm vif
#'
#'
#' @keywords VIF multicollinearity SDM

#' Function to automatically select SDM variables

select_sdmVariables <- function(predictor_vars, maxVIF){
  vv <- predictor_vars

  while(max(usdm::vif(vv)$VIF) >= maxVIF){
    vv <- remove_singleVariables(pred_vars = vv, th = maxVIF)
  }

  return(vv)
}
mbelitz/autoSDM documentation built on Dec. 21, 2021, 3:55 p.m.