removeFreq {ChemoSpecUtils}R Documentation

Remove Frequencies from a Spectra or Spectra2D Object

Description

This function removes specified frequencies from a Spectra or Spectra2D object. For instance, one might want to remove regions lacking any useful information (to reduce the data size), remove regions with large interfering peaks (e.g. the water peak in 1H NMR) or simply focus on a region of interest.

Usage

removeFreq(spectra, rem.freq = NULL, remF2 = NULL, remF1 = NULL)

Arguments

spectra

An object of S3 class ChemoSpec::Spectra() or ChemoSpec2D::Spectra2D().

rem.freq

For a Spectra object, a vector of logicals. rem.freq can be any valid R statement that leads to a vector of logicals (must be of length(Spectra$freq)). This vector should be TRUE for frequencies you want to be removed and FALSE for those frequencies which will be kept. In the examples, the | and & operators may seem backward in a sense, but R evaluates them one at a time and then combines them to give the desired result. You may wish to look at Comparison and Logic. See the examples. In addition, since January 2020 rem.freq may be a formula as described below.

remF2

Applies to Spectra2D objects. A formula giving the range of frequencies to be extracted. May include "low" or "high" representing the extremes of the spectra. Values outside the range of F2 are tolerated without notice and are handled as min or max. See the examples.

remF1

As for remF2.

Value

An object of S3 class ChemoSpec::Spectra() or ChemoSpec2D::Spectra2D().

Modifying Spectra2D Objects

Regarding Spectra2D objects, one cannot remove frequencies from the interior of a 2D NMR data set and expect to get a meaningful contour plot, because doing so puts unrelated peaks adjacent in the data set. This would lead to contours being drawn that don't exist in the original data set. However, one can remove data from the interior and run a PARAFAC analysis on the result, using the spectrum as an abstract object (that is, the spectrum may not plottable, but the resulting scores are still meaningful).

Author(s)

Bryan A. Hanson (DePauw University).

See Also

removeFreq for another way to remove data.

Examples

if (checkForPackageWithVersion("ChemoSpec", 6.0)) {
  library("ChemoSpec")
  data(SrE.IR)
  sumSpectra(SrE.IR)

  # Examples where rem.freq is a logical vector

  # Remove frequencies from one end:
  newIR <- removeFreq(SrE.IR, rem.freq = SrE.IR$freq > 3500)

  # Remove frequencies from both ends at once:
  newIR <- removeFreq(SrE.IR, rem.freq = SrE.IR$freq > 3500
    | SrE.IR$freq < 800)

  # Remove frequencies from the middle:
  newIR <- removeFreq(SrE.IR, rem.freq = SrE.IR$freq > 800
    & SrE.IR$freq < 1000)

  # The logic of this last one is as follows.  Any values
  # that are TRUE will be removed.
  values <- 1:7
  values > 2
  values < 6
  values > 2 & values < 6

  # Examples where rem.freq is a formula

  # Remove frequencies from one end:
  newIR <- removeFreq(SrE.IR, rem.freq = 3500 ~ high)

  # Remove frequencies from both ends is a two step process with formulas:
  newIR <- removeFreq(SrE.IR, rem.freq = 3500 ~ high)
  newIR <- removeFreq(newIR, rem.freq = low ~ 800)

  # Remove frequencies from the middle:
  newIR <- removeFreq(SrE.IR, rem.freq = 800 ~ 1000)

  # After any of these, inspect the results:
  sumSpectra(newIR)
}

if (checkForPackageWithVersion("ChemoSpec2D", 0.5)) {
  library("ChemoSpec2D")
# Note we will set contours a bit low to better
# show what is going on.

  data(MUD1)

  plotSpectra2D(MUD1, which = 7, lvls = 0.1, cols = "black",
    main = "MUD1 Sample 7: Complete Data Set")

  MUD1a <- removeFreq(MUD1, remF2 = 2.5 ~ 4)
  sumSpectra(MUD1a) # don't plot, removing peaks from interior is misleading

  MUD1b <- removeFreq(MUD1, remF2 = low ~ 2)
  sumSpectra(MUD1b)
  plotSpectra2D(MUD1b, which = 7, lvls = 0.1, cols = "black",
    main = "MUD1 Sample 7\nRemoved Peaks: F2 low ~ 2")

  MUD1c <- removeFreq(MUD1, remF1 = high ~ 23)
  sumSpectra(MUD1c)
  plotSpectra2D(MUD1c, which = 7, lvls = 0.1, cols = "black",
    main = "MUD1 Sample 7\nRemoved Peaks: F1 high ~ 23")

  MUD1d <- removeFreq(MUD1, remF2 = 2.5 ~ 4, remF1 = 45 ~ 55)
  sumSpectra(MUD1d)  # don't plot, removing peaks from interior is misleading

}

[Package ChemoSpecUtils version 1.0.4 Index]