hats_alignSpectra2D {ChemoSpec2D}R Documentation

Align the Spectra in a Spectra2D Object using the HATS algorithm.

Description

Align the spectra in a Spectra2D object using an implementation of the HATS algorithm described by Robinette et al.. Currently, only global, not local, alignment is carried out.

Usage

hats_alignSpectra2D(
  spectra,
  maxF2 = NULL,
  maxF1 = NULL,
  dist_method = "cosine",
  minimize = FALSE,
  thres = 0.99,
  no.it = 20L,
  restarts = 2L,
  method = "MBO",
  fill = "noise",
  plot = FALSE,
  debug = 1
)

Arguments

spectra

An object of S3 class Spectra2D.

maxF2

Integer. The most extreme positive F2step to allow during the alignment process (units are data points). Search for the optimal alignment will cover the region -maxF2 ... maxF2 and -maxF1 ... maxF1. Defaults to about 10% of the number of points.

maxF1

Integer. As for maxF2, but for F1.

dist_method

Character. The distance method to use in the objective function. See rowDist for options.

minimize

Logical. Is the goal to minimize the objective function? If so, use TRUE.

thres

Numeric. Prior to launching the optimization, the objective function is evaluated for no shift in case this is actually the best alignment (saving a great deal of time). If this initial check exceeds the value of thres (when minimize = FALSE), or is below thres when minimize = TRUE, no optimization is performed and the unshifted spectra are returned.

no.it

Integer. The maximum number of iterations in the optimization.

restarts

Integer. The maximum number of independent rounds of optimization.

method

Character. Currently only method = "MBO" is available which uses the HATS algorithm plus model based optimization (aka Bayesian optimization) method to align the spectra. Use plot = TRUE to see this in action.

fill

Aligning spectra requires that at least some spectra be shifted left/right and up/down. When a spectrum is shifted, spaces are opened that must be filled with something:

  • If fill = "zeros" the spaces are filled with zeros.

  • If fill = "noise" the spaces are filled with an estimate of the noise from the original spectrum.

plot

Logical. Shall a plot of the alignment progress be made? The plot is useful for diagnostic purposes. Every step of the alignment has a corresponding plot so you should probably direct the output to a pdf file.

debug

Integer.

  • Values >= 1 give messages about alignment progress in black text.

  • Values >= 2 print the merge matrix from the hclust object, if plot is also TRUE. This is the guide tree.

  • For method = "MBO" values less than 2 suppress some messages and warnings from the underlying functions. If the alignment doesn't work well, set debug = 2.

  • Setting plot = TRUE also gives a view of alignment diagnostics.

Value

An object of S3 class Spectra2D.

Advice

Author(s)

Bryan A. Hanson, DePauw University.

References

Roughly follows the algorithm described in Robinette et al. 2011 Anal. Chem. vol. 83, 1649-1657 (2011) dx.doi.org/10.1021/ac102724x

Examples

## Not run: 
set.seed(123)
library("ggally") # for diagnostic plots
data(MUD2)
sumSpectra(MUD2)
mylvls <- seq(3, 30, 3)

# Plot before alignment
plotSpectra2D(MUD2,
  which = c(2, 3, 5, 6), showGrid = TRUE,
  lvls = LofL(mylvls, 4),
  cols = LofC(c("black", "red", "blue", "green"), 4, 10, 2)
)

# Carry out alignment
# You might want to direct the diagnostic output here to a pdf file
# This alignment takes about 90 seconds including the plotting overhead
MUD2a <- hats_alignSpectra2D(MUD2, method = "MBO", debug = 1, plot = TRUE)

# Plot after alignment
plotSpectra2D(MUD2a,
  which = c(2, 3, 5, 6), showGrid = TRUE,
  lvls = LofL(mylvls, 4),
  cols = LofC(c("black", "red", "blue", "green"), 4, 10, 2)
)

## End(Not run)


[Package ChemoSpec2D version 0.5.0 Index]