Learn R Programming

specmine (version 4.0.0)

raman_align_peaks: Align detected peaks across spectra into wavenumber bins

Description

Groups peaks detected in multiple spectra into wavenumber bins defined by a tolerance. The resulting feature matrix can be used in downstream analyses such as PCA, clustering or classification.

Usage

raman_align_peaks(
  peak_results,
  tolerance = 4,
  reference_wavenumbers = NULL,
  feature_method = "max_height"
)

Value

Data frame with one row per reference wavenumber and one column per sample. The first column, wavenumber, contains bin reference positions.

Arguments

peak_results

A non-empty list of peak-detection results, one per sample. Each element must contain sample_id, wavenumbers, peaks and properties.

tolerance

Positive numeric value defining the half-width, in wavenumbers, around each reference position.

reference_wavenumbers

Optional non-empty numeric vector of reference wavenumbers. If NULL, reference positions are derived from detected peaks and clustered according to tolerance.

feature_method

Character string defining the feature summarised within each bin. One of "max_height", "max_prominence", "presence" or "mean_height".

Details

Missing peaks are represented by zero in the returned feature matrix.

Examples

Run this code
wn = seq(400, 1800, by = 1)

x1 = dnorm(wn, mean = 1000, sd = 20) +
  0.01 * rnorm(length(wn))

x2 = dnorm(wn, mean = 1002, sd = 20) +
  0.01 * rnorm(length(wn))

p1 = raman_find_peaks(x1, height = 0.01, distance = 5)
p2 = raman_find_peaks(x2, height = 0.01, distance = 5)

peak_results = list(
  list(
    sample_id = "sample1",
    wavenumbers = wn,
    peaks = p1$peaks,
    properties = p1$properties
  ),
  list(
    sample_id = "sample2",
    wavenumbers = wn,
    peaks = p2$peaks,
    properties = p2$properties
  )
)

features = raman_align_peaks(
  peak_results,
  tolerance = 4,
  feature_method = "max_height"
)

head(features)

Run the code above in your browser using DataLab