Select environmental variables that have pairwise Pearson correlation lower than a user-defined threshold. NOTE that it only works on numeric variables, does not work on categorical variables.

dim_reduce(
  img_stack = NULL,
  threshold = 0.5,
  preferred_vars = NULL,
  samples = NULL
)

Arguments

img_stack

(stars or RasterStack) The image stack to work on.

threshold

(numeric) The threshold number of Pearson correlation that indicates two variables are strongly correlated. The default is 0.5.

preferred_vars

(vector of character) The preferred variables in order in dimension reduction. The preferred variables will move to the beginning before the reduction. So make sure they are placed in order. Furthermore, setting preferred_vars does not guarantee they can survive. For example, one preferred variable that is placed later has strong correlation with former preferred variable.

samples

(sf or sp) The samples to reduce dimension. If not NULL, it can take sf, sfc, SpatialPointsDataFrame, SpatialPoints, etc. If NULL, the whole raster stack would be used. The default is NULL.

Value

(ReducedImageStack) A list of

  • threshold (numeric) The threshold set in function inputs

  • img_reduced (stars) The image stack after dimension reduction

  • cors_original (data.frame) A table of Pearson correlations between all variables.

  • cors_reduced (data.frame) A table of Pearson correlations between variables after dimension reduction.

Examples

library(sf)
library(itsdm)
library(stars)
library(dplyr)
env_vars <- system.file(
  'extdata/bioclim_tanzania_10min.tif',
  package = 'itsdm') %>% read_stars()
img_reduced <- dim_reduce(env_vars, threshold = 0.7,
  preferred_vars = c('bio1', 'bio12'))