isOutlier: Detect outliers using MAD(Median Absolute Deviation) method

View source: R/SCP-cellqc.R

isOutlierR Documentation

Detect outliers using MAD(Median Absolute Deviation) method

Description

This function detects outliers in a numeric vector using the MAD (Median Absolute Deviation) method. It calculates the median and the MAD, and determines the boundaries for outliers based on the median and the selected number of MADs.

Usage

isOutlier(
  x,
  nmads = 2.5,
  constant = 1.4826,
  type = c("both", "lower", "higher")
)

Arguments

x

a numeric vector.

nmads

the number of median absolute deviations (MADs) from the median to define the boundaries for outliers. The default value is 2.5.

constant

a constant factor to convert the MAD to a standard deviation. The default value is 1.4826, which is consistent with the MAD of a normal distribution.

type

the type of outliers to detect. Available options are "both" (default), "lower", or "higher". If set to "both", it detects both lower and higher outliers. If set to "lower", it detects only lower outliers. If set to "higher", it detects only higher outliers.

Value

A numeric vector of indices indicating the positions of outliers in x.

Examples

x <- c(1, 2, 3, 4, 5, 100)
isOutlier(x) # returns 6

x <- c(3, 4, 5, NA, 6, 7)
isOutlier(x, nmads = 1.5, type = "lower") # returns 4

x <- c(10, 20, NA, 15, 35)
isOutlier(x, nmads = 2, type = "higher") # returns 3, 5

zh542370159/SCP documentation built on Nov. 22, 2023, 2:34 a.m.