22 ene 2018

Analyzing Soy meal in transmitance (Part 4)

This is the fourth of the posts about analyzing soy meal unground in an Infratec, adding the sample directly to the conveyor in the same way that we do with wheat or barley. The range wavelength in the Infratec is from 850 to 1050nm, in steps of 2 nm, so we have a total of 100 data points.

 
I am use to look for outliers using the Mahalanobis distance (MD), which is based in the scores values for the samples in the Principal Component Space.
There are several packages in R, to see the value of the MD, and one of them is the package "Chemometrics", so we load this package and run sam script wit the values we have get from the previous  post.
We can fit to ablines to configure the MD, one for Warning with a vaue of 3.00 and another for the Action with a value of 4.00. The line for warning is orange and for action is orange.
 
library(chemometrics)
X_msc_pca<-princomp(X_msc,cor=TRUE)
res<-pcaDiagplot(X_msc,X_msc_pca,a=2)
plot(res$SDist,ylim=c(0,8),ylab="score distance",
     xlab="sample number")
identify(res$SDist)
abline(h=4,col="red")
abline(h=3,col="orange")
 
and we get this plots, where we can see how samples 298 and 373 appear as outliers, specially for their high scores values in the PC number 2 as we have seen in the previous posts.
 

21 ene 2018

Analyzing Soy Meal in transmitance (part 3)

This is the third of the posts about analyzing soy meal unground in an Infratec, adding the sample directly to the conveyor in the same way that we do with wheat or barley. The range wavelength in the Infratec is from 850 to 1050nm, in steps of 2 nm, so we have a total of 100 data points.
We can change the scale of the loading plots we have seen in the last post in order to over-plot them with the scores of the samples in the plane formed by the first two principal components.
So first step is to change the scale of the plot in the left to the scale on the right:
Now if we use the biplot function, we can see the scores and the loadings in the same plot:
biplot(X_msc_prcomp)

we see that all the samples are quite grouped in this plane, but there are samples (373 and 298) which are out of the group, specially in the direction of the second PC.
we want to keep these samples in a set called "extremes", to check them apart.
extremes<-c(298,373)
X_msc_extr<-scale(X_msc,scale=FALSE)[extremes,]
matplot(wavelengths,t(X_msc_extr),type="l",

        xlab="Wavelengths (nm)",ylab="Intensity (mean-scaled")
Now we can compare these samples with all the samples in the data set (including the extremes).
We can identify clearly sample 298 in the two plots, but 373 is not easy to see on the left plot, but it is in the direction of sample 298, so we can see the constituents values of this samples to have an idea why they are extremes in the second PC.




20 ene 2018

Analyzing Soy meal in transmitance (part 2)

This is the second of the posts about analyzing soy meal unground in an Infratec, adding the sample directly to the conveyor in the same way that we do with wheat or barley. The range wavelength in the Infratec is from 850 to 1050nm, in steps of 2 nm, so we have a total of 100 data points.

Once we have decided one of the math treatments to work, we can apply a Principal Components analysis to the data. This way we can understand better the structure of the data.
X_msc_prcomp<-prcomp(X_msc)

This way we obtain two importan matrices, the score matrix and the loadings matrix (We have been talking about this matrices in other posts).
In this post we are going to check the loadings that we can see graphically in two ways: as spectra or in the Principal Component space.
If we want to se them as spectra (first three loadings), run this script in R:
>matplot(wavelengths,X_msc_prcomp$center,type="l",
 xlab="wavelengths",ylab="transmitance")
Or we can see them in the Principal Components space, were we can see the range of variation
and this is the script for this last plot:
 par(mfrow=c(1,2),pty="s")
 offset<-c(0,0.09) # to create space for labels
 plot(X_msc_prcomp$rotation[,1:2],
      type="l",xlim=range(X_msc_prcomp$rotation[,1])+offset,
      xlab="PC1",ylab="PC2")
 #identify(X_msc_prcomp$rotation[,1:2])
 points(X_msc_prcomp$rotation[c(33,64,100),1:2],pos=4)
 text(X_msc_prcomp$rotation[c(33,64,100),1:2],pos=4,
      labels=paste(c(914,976,1050),"nm"))

offset<-c(-0.05,0.25) # to create space for labels
plot(X_msc_prcomp$rotation[,2:3],type="l",
     xlim=range(X_msc_prcomp$rotation[,1])+offset,
     xlab="PC2",ylab="PC3")
#identify(X_msc_prcomp$rotation[,2:3])
points(X_msc_prcomp$rotation[c(33,64,100),2:3],pos=4)
text(X_msc_prcomp$rotation[c(33,64,100),2:3],pos=4,
     labels=paste(c(914,976,1050),"nm"))
 
 


19 ene 2018

Implementing Good Product in Win ISI Diagram

New features Good Product added to Win ISI Diagram.
 

 

 
https://www.linkedin.com/feed/update/urn:li:activity:6357682248438943744
https://www.linkedin.com/feed/update/urn:li:activity:6357682248438943744

18 ene 2018

Analyzing Soy meal in transmitance (part 1)

One of the common applications in NIR analysis is the measure of soy meal, to predict Moisture, Protein, Fat and Fiber. As we know, Protein is the most important parameter and it is important to get an accurate prediction.

What about to measure soy meal in a transmittance instrument like Infratec?. Infratec has a smaller range, but this range (850 to 1050 nm) penetrate most into the sample, so we can measure in transmittance with a certain path length to avoid saturation. With this purpose, a certain number of samples with known reference value for the parameters was analyzed in the instrument, putting the soy meal unground and directly into the conveyor.

Spectra of the samples was export in a spectra file and lab values added.

Spectra file was export into R software as raw spectra, and a multiple scatter correction was added.


X<-as.matrix(sm_ift[,6:105])
wavelengths<-as.matrix(seq(850,1048,by=2))
matplot(wavelengths,t(X),type="l",

        xlab="wavelengths",ylab="transmitance")

#Math Treatments
#Multiple Scatter Correction
library(pls)
X_msc<-msc(X)

matplot(wavelengths,t(X_msc),type="l",
        xlab="wavelengths",ylab="transmitance")

#Mean Centering
  #We can check in wich areas is the variation of the data.
X_msc_mc<-scale(X_msc,scale=FALSE)


#We can see the variation at every wavelength with a boxplot.
boxplot(X_msc)