corVar: Print Correlated Variables

Description Usage Arguments Value Author(s) Examples

View source: R/corVar.R

Description

Utility that prints the name of correlated variables and the relative correlation coefficient value.

Usage

1
2
3
4
5
6
7
corVar(
  bg,
  method = "spearman",
  cor_th = NULL,
  order = TRUE,
  remove_diagonal = TRUE
)

Arguments

bg

SWD object with the locations used to compute the correlation between environmental variables.

method

character. The method used to compute the correlation matrix, default is spearman.

cor_th

numeric. If provided it prints only the variables whose correlation coefficient is higher or lower than the given threshold, default is NULL.

order

logical, if TRUE the variable are ordered from the most to the less highly correlated, default is TRUE.

remove_diagonal

logical, if TRUE the values in the diagonal are, removed, default is TRUE.

Value

The name of the correlated variables.

Author(s)

Sergio Vignali

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
                    pattern = "grd", full.names = TRUE)
predictors <- raster::stack(files)

# Prepare background locations
bg_coords <- dismo::randomPoints(predictors, 10000)

# Create SWD object
bg <- prepareSWD(species = "Virtual species", a = bg_coords,
                 env = predictors, categorical = "biome")

# Get the correlation among all the environmental variables
corVar(bg, method = "spearman")

# Get the environmental variables that have a correlation greater or equal to
# the given threshold
corVar(bg, method = "pearson", cor_th = 0.8)

Example output

   _____  ____   __  ___ __
  / ___/ / __ \ /  |/  // /_ __  __ ____   ___
  \__ \ / / / // /|_/ // __// / / // __ \ / _ \
 ___/ // /_/ // /  / // /_ / /_/ // / / //  __/
/____//_____//_/  /_/ \__/ \__,_//_/ /_/ \___/  version 1.1.3

To cite this package in publications type: citation("SDMtune").
sh: 1: awk: Permission denied
sh: 1: awk: Permission denied
Warning message:
In dismo::randomPoints(predictors, 10000) :
  generated random points = 0.5642 times requested number
Extracting predictor information for absence/background locations...
sh: 1: awk: Permission denied
sh: 1: awk: Permission denied
sh: 1: awk: Permission denied
sh: 1: awk: Permission denied
sh: 1: awk: Permission denied
sh: 1: awk: Permission denied
sh: 1: awk: Permission denied
sh: 1: awk: Permission denied
sh: 1: awk: Permission denied
Info: 4 absence/background locations are NA for some environmental variables, they are discarded!
    Var1  Var2       value
1   bio1  bio6  0.95170086
2  bio12 bio16  0.94240484
3   bio6  bio7 -0.88497855
4   bio1  bio8  0.84696636
5  bio16  bio6  0.74317385
6   bio6  bio8  0.73285104
7   bio1  bio7 -0.72957506
8  bio16  bio7 -0.70163496
9   bio1 bio16  0.70106527
10 bio12  bio6  0.68484145
11 bio12 bio17  0.68452508
12 bio12  bio7 -0.67394431
13  bio5  bio8  0.64078810
14  bio1 bio12  0.62637594
15  bio1  bio5  0.52840365
16  bio7  bio8 -0.46629146
17 bio16  bio8  0.45558219
18 bio16 bio17  0.45346691
19 bio12  bio8  0.38587986
20 bio17  bio7 -0.34712389
21  bio5  bio6  0.29641540
22 bio17  bio6  0.26761016
23  bio1 bio17  0.17840889
24 bio16  bio5  0.16232605
25 bio17  bio5 -0.14030336
26 bio12  bio5  0.10153440
27  bio5  bio7  0.09492232
28 bio17  bio8  0.08236502
   Var1  Var2      value
1 bio12 bio16  0.9288599
2  bio1  bio6  0.9280780
3  bio6  bio7 -0.8669439
4  bio1  bio8  0.8560933

SDMtune documentation built on July 17, 2021, 9:06 a.m.