NIT: Fatty acids study in R – Part 001

[This article was first published on NIR-Quimiometría, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)