In the post "Using R: NIPALS Spectra Reconstruction ", we reconstruct the original Matrix from the T (score matrix) and the "P" (loadings matrix). Knowing X (the original matrix), was easy to calculate the error matrix "E".
But we have reconstructed the X matrix centeres.
Now we have to add the mean spectrum of the training data set to every spectrum in the X matrix, to have the real spectra.
I called "Xtest" to the matrix : T.t(P) + E, and the spectra is exactly the same than the "Xorig", but centered, because NIPALS center the matrix to develop the algorithm.
Now is simply to add the mean spectrum (sflw.msc3.tra.cent) to every spectrum vector of the "Xorig" matrix.We can start by the first one:
Xorig_1<-(Xtest[1,]) + sflw.msc3.tra.cent
so the spectrum change from this plot:
+ ylab="log 1/R")
to this one: