1 ene 2013

Standard Normal Variate (SNV: Other way)

This is another way to pre-treat aspectra set with the SNV math-treatment
 (Standard Normal Variate). You can see the other one in the post :

In this post, I use the R function "sweep".

library(ChemometricsWithR)

#in a first step I calculate the average value
#of all the data points for every spectrum and
#subtract it to every data point of the
#spectrum using the function "colMeans"
#from the package "ChemometricsWhithR"
#the mean value for every spectrum is now cero.
NIR.1<-sweep(gasoline$NIR,MARGIN=1,
+colMeans(t(gasoline$NIR)),FUN="-")

#sd function calculates the SD for all the data
#points of every #spectrum.
#We divide now the value of every data point
#by the SD of all the values of that spectrum.
NIR.2<-sweep(NIR.1,MARGIN=1,
+sd(t(gasoline$NIR)),FUN="/")

#Now the spectrum has a mean of cero and a SD of 1.
#Use matplot to plot the spectra. 
matplot(wavelengths,t(NIR.2),type="l",lty=1,
+xlab="nm",ylab="log 1/R",
+main="SNV Gasoline Spectra",col="blue")

We have to take consider that in the Gasoline matrix, the rows are the
samples and the columns the wavelengths, so we have to transpose the matrix
for some calculations.

Gasoline is a data set included in the “pls” package. Is not a set to see the benefits
 of the SNV math treatment (not enough scatter), but you can try
with other data sets as "yarn".

21 dic 2012

Happy Christmas / Feliz Navidad


Desearos a todos los lectores de NIR-Quimiometría una ¡Feliz Navidad!.
y un Prospero y Feliz Año
 2013

I wish to all "NIR-Quimiometría" readers a Happy Christmas.

John Lennon says "Happy Christmas War is over"
Let´s hope to tell you some day:
"Happy Christmas Crisis is over"



13 dic 2012

Videos from Coursera’s four week course in R

Good information from the blog Revolution. Go to his post for more details.

Let´s keep these links in my label: "VIDEO: R Tutorials" to improve our R knowledge.

Laura Suttle : R tutorial videos

Laura Suttle : R tutorial videos

"R" : Identifying peaks

The function "identify"  from "R",  is very useful to check the spectrum for peaks or areas of interest. I use it here to see the wavelength with the highest variability in the Shootout-2012 Calibration Set.

This wavelength has a high variability due to the changes in concentration of the Active component in the mixture.

See the video to see how I use the function:



There are two books that I recomend to have to practice Chemometrics in R, you can find the links to get them from Amazon. Now that Christmas time is coming they can be nice presents to somebody. I will use them quite often as Bibliography in this blog.

We can use the identify option to check for the variables in X with the highest extreme loadings. In this case I use the element "rotation" generated by the object "prcomp".

Let´s use the same sample set as before: Shootout-2012 Calibration Set, and see the video:



As you can see the 216 value has the extreme value in both plots.