mcrpure: Multivariate curve resolution based on pure variables

View source: R/mcrpure.R

mcrpureR Documentation

Multivariate curve resolution based on pure variables

Description

mcrpure allows to resolve spectroscopic data to linear combination of individual spectra and contributions using the pure variables approach.

Usage

mcrpure(
  x,
  ncomp,
  purevars = NULL,
  offset = 0.05,
  exclrows = NULL,
  exclcols = NULL,
  info = ""
)

Arguments

x

spectra of mixtures (matrix or data frame).

ncomp

maximum number of components to calculate.

purevars

vector with indices for pure variables (optional, if you want to provide the variables directly).

offset

offset for correcting noise in computing maximum angles (should be value within [0, 1)).

exclrows

rows to be excluded from calculations (numbers, names or vector with logical values).

exclcols

columns to be excluded from calculations (numbers, names or vector with logical values).

info

a short text with description of the case (optional).

Details

The method estimates purity of each variable and then uses the purest ones to decompose the spectral data into spectra ('resspec') and contributions ('rescont') of individual chemical components by ordinary least squares.

The pure variabes are identified using stepwise maximum angle calculations and described in detail in [1]. So the purity of a spectral variable (wavelength, wavenumber) is actually an angle (measured in degrees) between the variable and vector of ones for the first component; and between the variable and space formed by previously found pure variables for the other components.

Value

Returns an object of mcrpure class with the following fields:

resspec

matrix with resolved spectra.

rescont

matrix with resolved contributions.

purevars

indices of the selected pure variables.

purevals

purity values for the selected pure variables.

purityspec

purity spectra (matrix with purity values for each variable and component).

expvar

vector with explained variance for each component (in percent).

cumexpvar

vector with cumulative explained variance for each component (in percent).

offset

offset value used to compute the purity

ncomp

number of resolved components

info

information about the model, provided by user when build the model.

More details and examples can be found in the Bookdown tutorial.

Author(s)

Sergey Kucheryavskiy (svkucheryavski@gmail.com)

References

1. Willem Windig, Neal B. Gallagher, Jeremy M. Shaver, Barry M. Wise. A new approach for interactive self-modeling mixture analysis. Chemometrics and Intelligent Laboratory Systems, 77 (2005) 85–96. DOI: 10.1016/j.chemolab.2004.06.009

See Also

Methods for mcrpure objects:

summary.mcrpure shows some statistics for the case.
unmix.mcrpure makes unmixing of new set of spectra.
predict.mcrpure computes contributions by projection of new spectra to the resolved ones.

Plotting methods for mcrpure objects:

plotPurity.mcrpure shows plot with maximum purity of each component.
plotPuritySpectra.mcrpure shows plot with purity spectra.
plotSpectra.mcr shows plot with resolved spectra.
plotContributions.mcr shows plot with resolved contributions.
plotVariance.mcr shows plot with explained variance.
plotCumVariance.mcr shows plot with cumulative explained variance.

Examples

library(mdatools)

# resolve mixture of carbonhydrates Raman spectra

data(carbs)
m = mcrpure(carbs$D, ncomp = 3)

# examples for purity spectra plot (you can select which components to show)
par(mfrow = c(2, 1))
plotPuritySpectra(m)
plotPuritySpectra(m, comp = 2:3)

# you can do it manually and combine e.g. with original spectra
par(mfrow = c(1, 1))
mdaplotg(
   list(
      "spectra" = prep.norm(carbs$D, "area"),
      "purity" = prep.norm(mda.subset(mda.t(m$resspec), 1), "area")
   ), col = c("gray", "red"), type = "l"
)

# show the maximum purity for each component
par(mfrow = c(1, 1))
plotPurity(m)

# plot cumulative and individual explained variance
par(mfrow = c(1, 2))
plotVariance(m)
plotCumVariance(m)

# plot resolved spectra (all of them or individually)
par(mfrow = c(2, 1))
plotSpectra(m)
plotSpectra(m, comp = 2:3)

# plot resolved contributions (all of them or individually)
par(mfrow = c(2, 1))
plotContributions(m)
plotContributions(m, comp = 2:3)

# of course you can do this manually as well, e.g. show original
# and resolved spectra
par(mfrow = c(1, 1))
mdaplotg(
   list(
      "original" = prep.norm(carbs$D, "area"),
      "resolved" = prep.norm(mda.subset(mda.t(m$resspec), 1), "area")
   ), col = c("gray", "red"), type = "l"
)

# in case if you have reference spectra of components you can compare them with
# the resolved ones:
par(mfrow = c(3, 1))
for (i in 1:3) {
   mdaplotg(
      list(
         "pure" = prep.norm(mda.subset(mda.t(carbs$S), 1), "area"),
         "resolved" = prep.norm(mda.subset(mda.t(m$resspec), 1), "area")
      ), col = c("gray", "red"), type = "l", lwd = c(3, 1)
   )
}

# See bookdown tutorial for more details.


mdatools documentation built on Aug. 13, 2023, 1:06 a.m.