outlier {kim}R Documentation

Outlier

Description

Return outliers in a vector

Usage

outlier(x = NULL, iqr = 1.5, na.rm = TRUE, type = 7, unique_outliers = FALSE)

Arguments

x

a numeric vector

iqr

a nonnegative constant by which interquartile range (IQR) will be multiplied to build a "fence," outside which observations will be considered outliers. For example, if iqr = 1.5, IQR * 1.5 will be the "fence" outside which observations will be considered to be outliers. By default, iqr = 1.5.

na.rm

logical. na.rm argument to be passed onto the 'quantile' function in the 'stats' package. If true, any NA and NaN's are removed from x before the quantiles are computed.

type

type argument to be passed onto the 'quantile' function in the 'stats' package. An integer between 1 and 9 selecting one of the nine quantile algorithms detailed below to be used. Type '?stats::quantile' for details. By default, type = 7

unique_outliers

logical. If unique_outliers = TRUE, the function will return the unique outlier values. If unique_outliers = FALSE, the function will return all the outlier values in the vector x. By default, unique_outliers = FALSE.

Value

the output will be a numeric vector with outliers removed.

Examples

# Example 1
outlier(c(1:10, 100))
# The steps below show how the outlier, 100, was obtained
# v1 is the vector of interest
v1 <- c(1:10, 100)
# quantile
stats::quantile(v1)
# first and third quartiles
q1 <- stats::quantile(v1, 0.25)
q3 <- stats::quantile(v1, 0.75)
# interquartile range
interquartile_range <- unname(q3 - q1)
# fence, using the default 1.5 as the factor to multiply the IQR
cutoff_low <- unname(q1 - 1.5 * interquartile_range)
cutoff_high <- unname(q3 + 1.5 * interquartile_range)
v1[v1 < cutoff_low | v1 > cutoff_high]

[Package kim version 0.5.422 Index]