9 feb. 2014

Using R: NIPALS Spectra Reconstruction

This is a simple exercise. I start wit some expectra in the NIR zone, and firs I wan to run the PCA with the NIPALS algorithm from the package "Chemometrics".

The name of the spectra I´m going to use to develop the Principal Components Analysis is: sflw.msc3.tra$NIRmsc

Now with the NIPALS function:

The result fom names are two matrices: T (scores matrix) and P (loading matrix).I´m going to give them another name:

Which are the dimensions of these matrices?
> dim(P_nipals)
[1] 2800   10

> dim(T_nipals)
[1] 75 10

2800 is the number of wavelenths of the spectra
 10 is the number of PCs
 75 is the number of samples

We can call Xorig to the original matrix (75 rows, 2800 columns)
 from our "sflw.msc3.tra$NIRmsc".

As we know:   Xorig = Xrecon + E
beeing             Xrecon = T * t(P)
E is the Residual Matrix.

In R we have to proceed like this:
Xorig is the original spectra centered.

So, the Error matrix is:

Now we can check that:
gives a TRUE response for all the values

2 comentarios:

  1. Congrats Jose Ramón!!! Two very interesting posts about NIPALS function with R software. I worked with the NIPALS function in Pirouette software and it is a very useful tool to extract internal information of the data set.

  2. Thanks Antonio.
    I really apreciate your comments.