sweep
for hyperSpec
objects.sweep
for the spectra matrix.## S3 method for class 'hyperSpec':
sweep(x, MARGIN, STATS, FUN = "-",
check.margin = TRUE, ..., short = "sweep", user = NULL,
date = NULL)
hyperSpec object.
STATS
goees along.hyperSpec
object. hyperSpec offers a non-standard convenience function: if
STATS
is a function, this function is applied
first (with the same MARGIN
)
TRUE
(the default), warn if
the length or dimensions of STATS
do not match the
specified dimensions of x
. Set to FALSE
for a small speed gain when you know that
dimensions match.FUN
logentry
.hyperSpec
object.sweep
is useful for some spectra preprocessing,
like offset correction, substraction of background
spectra, and normalization of the spectra.sweep
## Substract the background / slide / blank spectrum
# the example data does not have spectra of the empty slide,
# so instead the overall composition of the sample is substracted
background <- apply (chondro, 2, quantile, probs = 0.05)
corrected <- sweep (chondro, 2, background, "-")
plot (corrected, "spcprctl5")
## Offset correction
offsets <- apply (chondro, 1, min)
corrected <- sweep (chondro, 1, offsets, "-")
plot (corrected, "spcprctl5")
## Min-max normalization (on max amide I)
# the minimum is set to zero by the offset correction.
factor <- apply (corrected, 1, max)
mm.corrected <- sweep (corrected, 1, factor, "/")
plot (mm.corrected, "spcprctl5")
## convenience: give function to compute STATS:
mm.corrected2 <- sweep (corrected, 1, max, "/")
plot (mm.corrected2)
## checking
stopifnot (all (mm.corrected2 == mm.corrected))
Run the code above in your browser using DataLab