outlier_mad: Median absolute deviation test for outliers

Description Usage Arguments Details Examples

View source: R/outliers.r

Description

Performs a median absolute deviation (MAD) test for outliers.

Usage

1
2
3
4
5
6
7
outlier_mad(
  x,
  mask = !is.na(x),
  threshold = c(1.5, 3),
  k = 1/qnorm(0.75),
  return.score = FALSE
)

Arguments

x

A vector of data.

mask

A logical vector that defines which values in x will used when computing statistics. Useful when a subset of quality-assured data is available. Default mask is non-NA Values.

threshold

A length-two vector identifying thresholds for "mild" and "extreme" outliers.

k

A scale factor, defined as the reciprocal of the 75th percentile of the underlying distribution of the data. Default assumes a normal distribution.

return.score

if TRUE, return the numeric outlier score. If FALSE, return an ordered factor classifying the observations as one of "not outlier" (1), "mild outlier" (2), or "extreme outlier" (3).

Details

the values of threshold identify the thresholds used to identify mild and extreme outliers, as a multiple of k * median(x). Default values are 1.5 for "mild" outliers and 3.0 for "extreme" outliers.

Examples

1
2
3
4
5
6
7
8
9
x = seq(0, 34, by = 0.25)*pi
noise = rnorm(length(x), mean = 1, sd = 3)
y = sin(x) + noise
mask = noise < 1

outlier_mad(y)
outlier_mad(y, mask)
outlier_mad(y, mask, threshold = c(1, 2))
outlier_mad(y, return.score = TRUE)

mkoohafkan/wqptools documentation built on May 2, 2021, 8:12 p.m.