variable_correlation: Evaluates correlation among variables

View source: R/variable_correlation.R

variable_correlationR Documentation

Evaluates correlation among variables

Description

variable_correlation helps in evaluating correlation among distinct variables.

Usage

variable_correlation(variables, sample_size = 10000, correlation_limit = 0.8,
                     save = FALSE, name = "correlation", corrplot = FALSE,
                     magnify_to = NULL, ...)

Arguments

variables

RasterStack, RasterBrick, or matrix. If matrix, columns represent distinct variables for analysis, otherwise, group of raster layers.

sample_size

(numeric) sample size to be taken from all variables; default = 10000.

correlation_limit

(numeric) absolute value of correlation limit; default = 0.8.

save

(logical) whether or not to save the results; default = FALSE.

name

(character) name of the csv files to be writen; default = "correlation".

corrplot

(logical) whether or not to plot the results; default = FALSE.

magnify_to

(numeric) optional value to be used to magnify all values with absolute correlations above correlation_limit. Default = NULL.

...

other arguments to be passed to corrplot. Arguments "type", "tl.col", and "tl.srt" are fixed.

Details

If magnify_to is defined and save = TRUE, an additional csv file named as "name_magnified.csv" will be written.

Value

A correlation matrix. If argument corrplot = TRUE correlation values are shown in a plot.

Examples

# raster layers of environmental data
vars <- raster::stack(list.files(system.file("extdata", package = "ellipsenm"),
                                 pattern = "bio", full.names = TRUE))

# simple correlation matrix
cors <- variable_correlation(variables, sample_size = 5000)

# correlation matrix and plot (values correlated above |0.8| are magnified)
cors <- variable_correlation(variables, sample_size = 5000, corrplot = TRUE,
                             magnified = 2)

# to save results check arguments "save" and "name"

marlonecobos/ellipsenm documentation built on Oct. 18, 2023, 8:09 a.m.