20 feb. 2013

Improving my beginner function (still learning)

 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:

Nº Validation Samples  = 158 
RMSEP    : 0.723 
Bias     : -0.0642 
SEP      : 0.722 
Corr     : 0.942 
RSQ      : 0.888 
Slope    : 0.962 
Intercept: 2.14 
RER      : 14.9   Fair 
RPD      : 2.97   Poor 
BCL(+/-): 0.114 
***Bias adjustment in not necessary***
Residuals into 68 %   prob= 138 
Residuals into 95 %   prob= 154 
Residuals into 99.5 % prob= 158 

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":

           id    y    x  res
[1,] 13319319 53.7 51.9 1.78
[2,] 13318734 55.9 54.4 1.52
[3,] 13313943 54.3 52.8 1.53
[4,] 13313933 53.5 51.4 2.08

Plots given by the Function:

If  interested you can see the video: Monitor function 12-02-2013

No hay comentarios:

Publicar un comentario