spectrace_classify_spectra: Classify spectra

View source: R/spectrace_classify_spectra.R

spectrace_classify_spectraR Documentation

Classify spectra

Description

This function classifies each spectrum (i.e. row) by encoding the spectra using PCA on the reference data and calculating the pairwise distance between the reference and measured spectra. The reference spectrum with the minimum distance to the measured spectrum is taken as the classification.

Usage

spectrace_classify_spectra(
  lightData,
  referenceData = NULL,
  distance = c("euclidian"),
  return.encoded = FALSE
)

Arguments

lightData

(Grouped) data frame containing the (calibrated) light data. Data needs to be in wide format (see spectrace_to_wide). Classification will be performed on the aggregated data (e.g. median) per group.

referenceData

(Optional) data frame containing the reference spectra. Needs to contain the same wavelength columns as 'lightData'. Must consist of unique spectra and must contain a column named 'spectrum_id' identifying each spectrum. If not provided, the in-built reference spectra are used (see spectrace_reference_spectra).

distance

Distance metric to use. Options are: "euclidian" (default).

return.encoded

Logical. Add encoded principal components to data frame. Defaults to FALSE.

Value

The original data with a new column for the classification. If 'return.encoded' is TRUE then columns with the principal component loadings are added.


steffenhartmeyer/spectrace documentation built on Dec. 4, 2024, 4:13 p.m.