Is always good to look videos in the Web, trying to find some inspiration to improve a function in R. In this case I wanted to add a Normal Distribution line in order to compare the histogram of residuals with it. Looking to the video "Plotting in R: Part II" , I adapted some part of the script to the function.
If the Residual plot is well distributed, is good, that means that our calibration is quite robust without Bias and we have a very good idea of the errors we can expect in the future for our model.
In this case I have validated the Oleic Acid with NIT spectra (850-1150 nm), the sample is Pig Fat and the idea of this calibration is to know how the pig was feed. Calibration gives also another fatty acids parameters.
Probably is not possible to improve the calibration to get a lower SEP (Standar Error of Prediction), but this error is good for some purposes.
The function tells me with an independent set of 158 samples:
It tells me also the number of samples that pass the LWL (lower warning limits = -2*SEP) and UWL(upper warning limits = 2*SEP) in this case "four":