The main goal of processing NIR spectra is attempting to remove noise and background variations that are not related to the variables (properties) of interest, in order to build robust models and improve prediction accuracy. This section will presents the most common methods employed to process NIR spectra before modelling. De Maesschalck et al. (1999), Rinnan et al. (2009), Huang et al. (2010) and Sandak et al. (2016) constitute excellent references on the basics of NIR spectra processing.
Plot the raw NIR spectra
Let’s plot the raw PHAZIR spectra just to see how they look like. Note that here I wanted to build a color scale to accompany the plot, which required the package squash. The package Hmisc is also used simply for adding tick marks on the plot axis. Moreover, since we are going to create numerous plots of this type, it is coded as a function so we can easily call it back in the future.