#' A routine for identifying outliers in a vector of data based on IQR robust statistics.
#' @param x a data set.
#' @param b output boxplot of the four sweeps to remove outliers. Default is FALSE.
#' @keywords outliers, MU
#' @export
#'
outliers <- function (x, b = FALSE) {
xx <- sapply(x, as.numeric)
#xx <- sort(xx)
remove_outliers <- function(x, na.rm = TRUE, ...) {
qnt <- quantile(x, probs=c(.25, .75), na.rm = na.rm, ...)
H <- 1.5 * IQR(x, na.rm = na.rm)
y <- x
y[x < (qnt[1] - H)] <- NA
y[x > (qnt[2] + H)] <- NA
y
}
yy <- remove_outliers(xx)
ww <- remove_outliers(yy)
zz <- remove_outliers(ww)
diff.out <- data.frame(xx, yy, ww, zz)
if(b == TRUE){
boxplot(diff.out)
}
return(zz)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.