is.outlier: Remove outliers from the provided vector and return vector...

Description Usage Arguments Details Value Author(s) References Examples

Description

Remove outliers from vector using a MAD value as cutoff.

Usage

1
is.outlier(x, mcut = 6.2)

Arguments

x

Vector of data points to remove outliers from

mcut

Number of MADs a data point needs to be from the median to be considered an outlier, default is 6.2

Details

See: Davies, P.L. and Gather, U. (1993). "The identification of multiple outliers" (with discussion) J. Amer. Statist. Assoc., 88, 782-801.

Value

A vector of same length as "x" with outliers changed to NA.

Author(s)

Greg Ziegler

References

Davies, P.L. and Gather, U. (1993).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
set.seed(1)
x <- rnorm(100)
x <- c(-10, x, 10)
y <- is.outlier(x)
summary(x)
summary(y)
## The function is currently defined as
function (x, mcut = 6.2) 
{
    y <- na.omit(x)
    lims <- median(y) + c(-1, 1) * mcut * mad(y, constant = 1)
    for (j in 1:length(x)) {
        if (is.na(x[j]) | x[j] < lims[1] | x[j] > lims[2]) {
            x[j] <- NA
        }
    }
    return(x)
  }

gziegler/ionomicsUtils documentation built on June 20, 2019, 8:04 p.m.