Skip to contents

Flags values beyond Tukey's outer fences, Q1 - k * IQR and Q3 + k * IQR, with quartiles of type 7 (the R default). smart_cor() uses this rule as the first diagnostic for every pair with a continuous or count variable.

Usage

detect_outliers(x, k = 3)

# S3 method for class 'smartcor_outliers'
print(x, ...)

Arguments

x

A numeric vector (continuous, count, or ordinal). An ordered factor is replaced by its integer codes. Missing values are dropped.

k

Fence multiplier. Default: 3 (the outer fences).

...

Ignored.

Value

An object of class "smartcor_outliers": a list with has_outliers (logical), outliers (the outlying values), index (their positions in x), lower and upper (the fences), q1, q3, iqr, degenerate (TRUE when the IQR is 0), skewness, excess_kurtosis, and n (the number of non-missing values).

Details

Values strictly below the lower fence or strictly above the upper fence are outliers. When the IQR is 0 (more than half of the values are tied) the rule is degenerate: nothing is flagged, degenerate is TRUE, and the repeated values need separate inspection.

The skewness and excess kurtosis are moment estimators with divisor n, as used by the Jarque-Bera test.

Examples

csv = system.file("extdata", "gss_2024_casestudy.csv", package = "smartcor")
gss = read.csv(csv)
detect_outliers(gss$coninc)
#> No outliers outside [-140750, 223792]