29 abr 2015

Centered Spectra vs. Loading Spectra

I´m preparing a presentation for a training about Chemometrics and PCAs,  so I´m going to use R Graphics, because are really fantastic to introduce NIR users to R.
 Following with the centered spectra, this time I overplot the centered spectra with the first 4 loadings. Every centered spectrum can be rebuild using a linear combination with their scores and the loading vectors (eigenvectors), remaining a residual noisy spectra (e).

28 abr 2015

Centered spectra vs. Std Spectrum



In my last post I added a video, with the idea of the centered spectra. The video is in Spanish, but I hope you can follow the script with R. 
The idea of this post is overplot the centered spectra with the standard deviation spectrum which also explain the wavelengths of the spectrum which has more variation. The script has to consider that we have two scales, so I put one on the left (centered spectra) and on the right the scale for the standard deviation spectra. We can see that the zone of variation matches.
NIR.mc<-scale(gasoline$NIR,center=TRUE,scale=FALSE)
matplot(wavelengths,t(NIR.mc),type="l",lty=1,
        col="blue",col.axis="blue",
        xlab="wavelength",ylab="log 1/R",
        main="Centered Spectra + STD Spectrum")
par(new=T)
#The standard deviation spectrum for gasoline$NIR is:
NIR.sd<-apply(gasoline$NIR,2,sd)
matplot(wavelengths,NIR.sd,type="l",lty=1,lwd=4,col="red",
        xlab="wavelength",ylab="log 1/R",
        axes=FALSE)
axis(4,col.axis="red")

24 abr 2015

Aquaphotomics "Waiting for a new package in R".

Nice to know, that a new  R package will be available for "Aquaphotomics", hopefully this year, developed by members of the Kobe University - NIRS Group.
The presentation, from the authors, at the last at the "5th Kobe University Brussels European Center Symposium" is available from this link.

13 abr 2015

Using "Identify" function to check extreme variable weights

With the identify function we can check which wavelengths have more weights in the loadings.
Here I plot the first four loadings after calculating the PCs, using the "gasoline" data from the package "ChemometricsWithR".
This is the code to identify the weights in the case of the first one:
matplot(wavelengths,gas.loadings[,1],type="l",lty=1,col="red",
       +xlab="wavelength",ylab="log 1/R",
       +main="loading nº1")

identify(wavelengths,gas.loadings[,1],
         +labels=row.names(gas.loadings))