The idea now is to apply some math treatments to the raw spectra and check which one improves the correlation with the parameters of interest. Normally there are some common scatter removal algorithms that I use:
Standard Normal Variate (SNV)
Detrend (linear or quadratic)
SNV + Detrend (linear or quadratic)
Multiple Scatter Correction
There are some packages in R which have these math treatment with this name or a similar one, or we can create functions to apply these algorithms to the spectra matrix.
Standard Normal Variate (SNV)
Let´s start using SNV, where we center every spectrum (subtracting the mean) and scale it (dividing by the standard deviation):
#The algorithm is applied to the columns, so we transpose the matrixabsorp_snv <-scale(t(absorp), center =TRUE, scale =TRUE)#Let´s convert the corrected matrix as usualabsorp_snv <-t(absorp_snv)matplot(colnames(absorp_snv), t(absorp_snv), type ="l", xlab ="Wavelength (nm)", ylab ="Absorbance", main ="SNV Meat Spectra")
Figure 1: Meat spectra treated with SNV.
We can add the matrix treated with the SNV math treatment to the tecator dataframe
tecator$snv_spec <- absorp_snv
Correlation between outcomes and predictors (with SNV)
Figure 2: Correlation SNV signal with the parametes.
Now, apart from the better correlation we can see an improvement in the definition of the correlations (positives and negatives), and the correlation spectra confirm what we have seen in the correlation between the parameters.