R/variableCorrelation.R

Defines functions variableCorrelation

Documented in variableCorrelation

#' variableCorrelation
#' 
#' Checks the correlation amongst the variables that contributes most to the
#' species modelling with maxent.
#'
#' @importFrom usdm vifcor
#' @param occ table containing columns with the species name, longitude, and
#' latitude.
#' @param path character, the path to the folder containing the variables.
#' @param th threshold of correlation. Default is 0.7.
#' @param original_format character, indicates the format of the layers.
#' @return This function return a table informing which variables are less
#' correlated than the defined threshold.
#' @export
variableCorrelation <- function(occ, path, th = 0.7, original_format = ".asc"){
  #get values of all variables in the occurrence points locations
  vars <- extractValues(path, occ_clean, original_format = original_format)
  vars2 <- vars[, -which(names(vars) %in% names(occ_clean))]
  if(length(unique(which(is.na(vars2)))) != 0){
    vars3 <- vars2[-is.na(vars2), ]
  }else{
    vars3 <- vars2
  }
  corel <- vifcor(vars3, th = 0.7)
  
  return(corel@results)
}
EduardoArle/nicheRealisation documentation built on Jan. 12, 2023, 1:50 a.m.