NIT: Fatty acids study in R – Part 001

March 1, 2012

(This article was first published on NIR-Quimiometría, and kindly contributed to R-bloggers)

This time I´m going to use my own data to develop a model to predict some fatty acid in the solid fat (pork).
Samples had been analyzed in a NIT (Near Infrared Transmittance) instrument. The range of the wavelengths is from 850 to 1048 nm (100 data points). This area cover usually second overtones.
I am quite novice in R, and it takes some time (in my case) to have the data organize in R to starts working with it.
We have together the X matrix (NIT absorbance’s) with the Y matrix (constituents). First of all was to import the”txt” file and create a data frame.
The TXT file has been exported from the software of the instrument.
> fat<-read.table(“C:\\tocino6.txt”,header=TRUE)
> NIT<-fat[,7:106]
> C16_0<-fat[,1]
> C16_1<-fat[,2]
> C18_0<-fat[,3]
> C18_1<-fat[,4]
> C18_2<-fat[,5]
> C18_3<-fat[,6]
> fattyac<-data.frame(C16_0=I(C16_0),C16_1=I(C16_1),C18_0=I(C18_0),
  + C18_1=I(C18_1),C18_2=I(C18_2),C18_3=I(C18_3),NIT=I(NIT))
> names(fattyac)
[1] “C16_0” “C16_1” “C18_0” “C18_1” “C18_2” “C18_3” “NIT” 
At this point we are ready to see the raw spectra.
We can see a high scatter, so a remove scatter pretreatment is necessary. Let´s try the MSC.
First we have to prepare the data, if not we will get some errors:
> NITm<-as.matrix(NIT)
> fattyac<-data.frame(C16_0=I(C16_0),C16_1=I(C16_1),C18_0=I(C18_0),
+ C18_1=I(C18_1),C18_2=I(C18_2),C18_3=I(C18_3),NITm=I(NITm))
> library(ChemometricsWithR)
> fat_msc<-msc(fattyac$NITm)
>  matplot(wavelengths,t(fat_msc),lty=1,
  + pch=21,xlab=”nm”,ylab=”abs”)

To leave a comment for the author, please follow the link and comment on their blog: NIR-Quimiometría. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...


Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)