pair_corr: Pairwise correlations

View source: R/pair_corr.R

pair_corrR Documentation

Pairwise correlations

Description

Calculates pairwise correlations between landscape metrics.

Usage

pair_corr(
  x,
  method = "pearson",
  fun = NULL,
  raster = NULL,
  classes = NULL,
  radii = NULL,
  c_level = NULL,
  l_level = NULL,
  ext_raster = NULL,
  classnames = FALSE,
  display = "radii",
  ...
)

Arguments

x

An object of class 'MultiLandMetrics' generated with metrics().

method

The method to be used to calculate pair correlations: "pearson" (default), "spearman" or "kendall".

fun

A user-defined function to calculate correlations. See Details.

raster, ext_raster, classes, radii, l_level, c_level

Parameters to subset calculations of correlations. See Details.

classnames

Logical. If TRUE, row and column of returned matrices will be identified with the names of the classes, if available in x. Default FALSE.

display

Defines how correlations are presented: "radii" (default), "rl" or "both". See Details.

...

Other arguments passed to function cor() or to the user-defined function provided in fun.

Details

Correlations are calculated, by default, through the function cor(), by specifying the method through the argument method. Alternatively, a user-defined function can be provided in the argument fun. If not NULL, the function will assume that a user-defined function have been provided. This must be a function already loaded in the environment, and must take at least two arguments. These initial pair of arguments should be capable of receiving two numeric vectors (one in each argument), process them in some way, and return a numeric value (i.e. the supposed correlation).

Arguments raster, ext_raster, classes, radii, c_level and l_level can be defined to subset the calculations of pair correlations. In each one of these, an all-positive or an all-negative vector can be passed, whether to include (all-postive) or exclude (all-negative) the elements to be taken into account for the subsetting:

  • raster: a numeric vector with the number of the rasterlayers to be included/excluded. For example: c(1, 2, 4) to include rasterlayers 1, 2 and 4; c(-2, -3) to exclude rasterlayers 2 and 3.

  • ext_raster: a numeric vector with the number of the extra rasterlayers to be included/excluded, as in the raster slot.

  • classes: must be a list with as many elements as defined rasterlayers in argument raster. Each element of the list must be a numeric vector (classes identities) with the classes to be included/excluded. If provided a character vector, pair_corr() assumes that classes names are provided. For example, for the case with 2 rasterlayers: list(c(3, 20, 35), c("Forest", "Crops")) would include classes 3, 20 and 35 from rasterlayer 1 and classes "Forest" and "Crops" for rasterlayer 2. For the case of a unique rasterlayer, there is no need to input a list. For example, for the case of a unique rasterlayer and the exclusion of some classes: c(-5, -10, -15) to exclude classes 5, 10 and 15 of the unique rasterlayer; c("-Forest", "-Grassland") to exclude classes "Forest" and "Grassland". Note the "-" before each class name to indicate the exclusion of the classes.

  • radii: a numeric vector to include/exclude particular radii. For example: c(1000, 2000) to include only radii of 1000 and 2000 m; c(-500, -1500) to exclude radii of 500 and 1500 m.

  • c_level: character vector with the class-level metrics to be included/excluded from the analysis. For example: c("np", "pland") will include only the metrics "number of patches" ("np") and "percentage of the landscape" ("pland") in the analysis, whereas c("-np", "-pland") will exclude them. Note the "-" before each metric name to indicate the exclusion of the metrics.

  • l_level: character vector with the landscape-level metrics to be included/excluded from the analysis. Extra calculations for extra rasterlayers are considered as landscape-level metrics, and must be provided as "fun_" + the name of the function (e.g. "fun_mean").

Names of the available metrics of the 'MultiLandMetrics' object provided in x can be accessed with x@metrics and x@ext_calc.

Note that patch-level metrics, if exists in x metric's data.frame, are excluded from calculations, as this function works at a landscape-scale analysis.

Argument display defines how correlation values will be presented. If equals to "radii" (default), correlation values are disaggregated by radii. If "rl", correlation values are disaggregated by rasterlayer: correlations between different radii will be presented. If "both", correlation values are firstly disaggregated by rasterlayer, and by radii secondly. Disaggregations by rasterlayers only make sense for 'MultiLandMetrics' objects with more than one rasterlayer.

Value

A list with matrices containing correlation values between pair of metrics. Matrices are disaggregated by radius if display = "radii", by rasterlayer if display = "rl" or by rasterlayer and radii if display = "both". Metrics names are presented as row and column names of the matrices, with the following format: "level""metric_name""radius". For a landscape-level metric, a plausible metric name could be "l_np_1500" indicating a landscape-level metric, which is "np" ("number of patches") at a scale (radius) of 1500 m. For a class-level metric a plausible metric name could be "c4_pland_1000", indicating a class-level metric of class 4 (the value of the raster), which is "pland" ("percentage of landscape") at a scale (radius) of 1000 m. If more that one rasterlayer is being analyzed, the prefix "r1", "r2", "r3", ..., "rn" (referring to rasterlayer 1, 2, 3, ..., n) is added to the metric name.

See Also

metrics(), pair_plots()

Examples

# Calculates pearson correlations between metrics of a MultiLandMetrics object
pair_corr(ed_metrics)

# Only for radius 5000 m and with classes names rather than classes values
pair_corr(ed_metrics, radii = 5000, classnames = TRUE)

# Only selecting the metric "pland"
pair_corr(ed_metrics, radii = 5000, classnames = TRUE, c_level = "pland")

# Excluding the metric "pland"
pair_corr(ed_metrics, radii = 5000, classnames = TRUE, c_level = "-pland")

# Excluding the metric radii of 4000 and 5000 m
pair_corr(ed_metrics, radii = c(-4000, -5000), classnames = TRUE)

# Correlations of metric "pland" between classes 1 to 3, an between radii 1000 and 5000 m
# and disaggregating by rasterlayer.
pair_corr(ed_metrics, radii = c(1000, 5000), classes = 1:3, c_level = "pland", display = "rl")

phuais/multilandR documentation built on Feb. 11, 2024, 9:27 p.m.