outliers: Depth-Based Outlier Detection

View source: R/depth_object.R

outliersR Documentation

Depth-Based Outlier Detection

Description

Flags observations whose depth falls below a threshold as outliers. The threshold can be specified as a quantile of the depth distribution (default) or as an absolute depth cutoff.

Usage

outliers(x, threshold = 0.05, absolute = FALSE, ...)

Arguments

x

A depth object from compute_depth().

threshold

Numeric scalar in (0, 1). Interpreted as a quantile of the depth distribution when absolute = FALSE (default): the bottom threshold fraction of observations are flagged as outliers. When absolute = TRUE, any observation with depth below threshold is flagged.

absolute

Logical. If TRUE, threshold is an absolute depth cutoff rather than a quantile. Default FALSE.

...

Ignored.

Value

A named list:

outlier

Logical vector of length n — TRUE for outliers.

indices

Integer vector of row indices of outlying observations.

points

Matrix of outlying observations.

depths

Depth values of outlying observations.

threshold

The actual depth cutoff used.

Examples


set.seed(42)
data <- matrix(rnorm(500), nrow = 100, ncol = 5)
dd   <- compute_depth(data)

# Flag bottom 5% by depth (default)
outliers(dd)

# Flag bottom 10%
outliers(dd, threshold = 0.10)

# Absolute depth cutoff
outliers(dd, threshold = 0.05, absolute = TRUE)



depthR documentation built on June 26, 2026, 5:07 p.m.