Remove environmental variables that have high correlation with others.
Source:R/dim_reduce.R
dim_reduce.RdSelect 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.
Arguments
- img_stack
(
starsorRasterStack) 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
(
vectorofcharacter) 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
(
sforsp) The samples to reduce dimension. If notNULL, it can takesf,sfc,SpatialPointsDataFrame,SpatialPoints, etc. IfNULL, the whole raster stack would be used. The default isNULL.
Value
(ReducedImageStack) A list of
threshold (
numeric) The threshold set in function inputsimg_reduced (
stars) The image stack after dimension reductioncors_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.