PCA for NIR Spectra_part 005: "Reconstruction"
We saw how to plot the raw spectra (X), how to calculate the mean spectrum, how to center the sprectra (subtracting the mean spectrum from every spectra of the original matrix X). After that we have developed the PCAs with the NIPALS algorithm, getting two matrices: T (scores) and P (loadings).
We have to decide the number of PCs, looking to the plots, or to the numbers (explained variance).
Depending of the numbers of PCs, these matrices will have more or less columns.
With these two matrices we can reconstruct again the X centered matrix, but we´ll get also a residual matrix “E”.
Xc = T.Pt+E
This post just shows this in R:
If we add the mean spectrum to every spectra of the centered matrix we will get the X matrix reconstructed.
> resid3pc<-Xc- Xc3pc_reconst
We can see the plots of the X centered matrix reconstructed and the plot representing the residual variance or Error matrix “E”.
To leave a comment
for the author, please follow the link and comment on their blog: NIR-Quimiometría
offers daily e-mail updates
news and tutorials
on topics such as: Data science
, Big Data, R jobs
, visualization (ggplot2
), programming (RStudio
, Web Scraping
) statistics (regression
, time series
) and more...
If you got this far, why not subscribe for updates
from the site? Choose your flavor: e-mail
, or facebook