Improving script_001: “Monitor”

May 6, 2012

(This article was first published on NIR-Quimiometría, and kindly contributed to R-bloggers)

After having a look to this video: from rtwotutorials, and reading some tutorials, I decided to modified the script from the previous post: Practicing Script with “ R”: Monitor ,
 in order to make it more robust .
If there are NA values in our X and Y variables, the results for all the statistics will be NA (see also the video:, that is not nice, so it´s better to write a warning and stop the analysis to check our data set.
So the new script is:

         print(“There are NA values in X or Y, remove these samples for calculation”)
 cat(“Bias :”,bias,”\n”)}
 cat(“SEP  :”,sep,”\n”)}
 cat(“Corr :”,r,”\n”)}
 cat(“RSQ  :”,rsq,”\n”)}

After having some samples with NA values (not reference value for that sample or not predicted value) the output will be:

“There are NA values in X or Y, remove these samples for calculation”

If not it will continue with the calculations:

RMSEP: 0.4373108
Bias : 0.03814815
SEP  : 0.4439425
Corr : 0.4864254
RSQ  : 0.2366097

Possible improvements I think right now:

The function gives me the position of the samples with NA values, so location is easier
 that the function removes these samples and the calculations can be done without them.


To leave a comment for the author, please follow the link and comment on their blog: NIR-Quimiometría. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...


Comments are closed.

Search R-bloggers


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)