cm.rbd3: Calculate 3-Band Correlation Array for Spectral Data...

View source: R/cm.rbd3.R

cm.rbd3R Documentation

Calculate 3-Band Correlation Array for Spectral Data correlating with another variable x

Description

This function computes the squared Pearson correlation (R^2) between a response vector x and a derived variable V for every possible combination of three distinct spectral bands. The derived variable V is calculated using the formula:

V = \frac{R_k - R_j}{R_j - R_i}

where R_i, R_j, and R_k represent the reflectance values at bands i, j, and k, respectively.

Usage

cm.rbd3(
  S,
  x,
  w = wavelength(S),
  w.unit = NULL,
  cm.plot = FALSE,
  plot.method = "default"
)

Arguments

S

A spectral data object or matrix. Each column corresponds to a spectral band.

x

A numeric vector representing the response variable (e.g., chlorophyll).

w

A numeric vector of wavelengths; by default, it is derived using wavelength(S).

w.unit

Character string specifying the unit of wavelengths (optional).

cm.plot

Logical. If TRUE, a 3D slice plot of the correlation array is generated.

plot.method

Character string specifying the plotting method. Currently, the plotting option uses plot3D.

Details

The function prints the maximum R^2 value and the corresponding band wavelengths. Optionally, it can produce a 3D slice plot of the correlation array using plot3D::slice3D.

For every combination of three distinct bands (i, j, k), the function computes

V = \frac{R_k - R_j}{R_j - R_i}

and then calculates the squared Pearson correlation between x and V. The maximum R^2 value and its associated band combination are printed.

If cm.plot is set to TRUE, the function generates a 3D slice plot of the correlation array using the best band combination, where the slices correspond to the wavelengths of the bands.

Value

A 3-dimensional array of squared correlation (R^2) values with dimensions corresponding to the combinations of bands i, j, and k.

Examples

## Not run: 
  library(visa)
  data(NSpec.DF)
  x <- NSpec.DF$N # nitrogen
  # Below resamples spectra to 20 nm for fast computation
  S <- NSpec.DF$spectra[, seq(1, ncol(NSpec.DF$spectra), 20)]
  # S is a spectral data object and x is a numeric vector.
  Rsq3 <- cm.rbd3(S, x, cm.plot = TRUE)

## End(Not run)


visa documentation built on April 4, 2025, 5:40 a.m.