layerCor: Correlation between GRasters

layerCor,GRaster-methodR Documentation

Correlation between GRasters

Description

This function returns a correlation or covariance matrix between two or more GRaster layers. This function returns the sample correlation and covariance (i.e., the denominator is n - 1).

Usage

## S4 method for signature 'GRaster'
layerCor(x, fun = "cor")

Arguments

x

A GRaster with two or more layers.

fun

Character: Name of the statistic to calculate; either "cor" (default) or "cov".

Value

A numeric matrix.

See Also

terra::layerCor(), stats::cor(), stats::cov()

Examples

if (grassStarted()) {

# Setup
library(terra)

# Example data
madChelsa <- fastData("madChelsa")

# Convert a SpatRaster to a GRaster:
chelsa <- fast(madChelsa)

# Correlation
layerCor(chelsa, "cor")

# Covariance
layerCor(chelsa, "cov")

}

adamlilith/fasterRaster documentation built on Sept. 23, 2024, 1:28 a.m.