Learn R Programming

hyperSpec (version 0.95)

decomposition: Convert Principal Component Decomposition or the like into a hyperSpec Object

Description

Decomposition of the spectra matrix is a common procedure in chemometrix data analysis. decomposition converts the result matrices into new hyperSpec objects.

Usage

decomposition(object, x, wavelength = seq_len (ncol (x)),
              label.wavelength, label.spc, scores = TRUE,
              retain.columns = FALSE,short = "", ...)

Arguments

object
A hyperSpec object.
x
matrix with the new content for object@data$spc.

May correspond to rows (like a scores matrix) or columns (like a loadings matrix) of object.

wavelength
for a scores-like x: the new object@wavelength.
label.wavelength
The new label for the wavelength axis (if x is scores-like)
label.spc
The new label for the spectra matrix
scores
is x a scores-like matrix?
retain.columns
for loading-like decompostition (i.e. x holds loadings, pure component spectra or the like), the data columns need special attention.

Columns with different values across the rows will be set to NA if retai

short, ...
handed over to logentry

Value

  • A hyperSpec object, updated according to x

Details

Multivariate data are frequently decomposed by methods like principal component analysis, partial least squares, linear discriminant analysis, and the like. These methods yield loadings (or latent variables, components, ...) that are linear combination coefficients along the wavelength axis and scores for each spectrum and loading.

The loadings matrix gives a coordinate transformation, and the scores are values in that new coordinate system.

The obtained loadings are spectra-like objects: a loading has a coefficient for each wavelength. If such a matrix (with the same number of columns as object has wavelengths) is given to decomposition, the spectra matrix is replaced by x. Moreover, all columns of object@data that did not contain the same value for all spectra are set to NA. Thus, for the resulting hyperSpec object, plotspc and related functions are meaningful. plotmap cannot be applied as the loadings are not laterally resolved. The scores-matrix needs to have the same number of rows as object has spectra. If such a matrix is given, the spectra matrix is replaced by x and object@wavelength is replaced by wavelength. The information related to each of the spectra is retained. For such a hyperSpec object, plotmap and plotc and the like can be applied. Of couse, it is also possible to use the spectra plotting, but the interpretation is not that of the spectrum any longer.

See Also

See %*% for matrix multiplication of hyperSpec objects.

See e.g. prcomp and princomp for principal component analysis, and package pls for Partial Least Squares Regression.

Examples

Run this code
pca <- prcomp (~ spc, data = flu$., center = FALSE)

  scores <- decomposition (flu, pca$x, label.wavelength = "PC",
                           label.spc = "score / a.u.")

  loadings <- decomposition (flu, t(pca$rotation), scores = FALSE,
     label.spc = "loading I / a.u.")

  plotspc (loadings, stacked = TRUE, col = matlab.palette(6))

  plotc (scores[,,1], plot.args = list(ylim = range(scores[[]])))
  for (i in 2 : nwl (scores))
     plotc (scores[,,i], add = TRUE, plot.args = list (col = matlab.palette(6)[i]))
  pca$sdev

  ## everything besides the first component is just noise
  ## Reconstructing the data using only the first PC results in a noise
  ## filtered data set.

  flu.filtered <- scores[,,1]

  ## example 2
  pca <- prcomp (~ spc, data = chondro$., tol = 0.1)

  scores <- decomposition (chondro, pca$x, label.wavelength = "PC",
                           label.spc = "score / a.u.")

  plotmap (scores[,,1])

Run the code above in your browser using DataLab