tukey_depth: Tukey (Halfspace) Depth

View source: R/tukey_depth.R

tukey_depthR Documentation

Tukey (Halfspace) Depth

Description

Computes the Tukey halfspace depth of one or more query points with respect to a reference distribution estimated from data.

Usage

tukey_depth(
  x,
  data,
  tol = 0.01,
  batch_size = 100L,
  min_batches = 5L,
  patience = 3L,
  seed = 42L
)

Arguments

x

Numeric matrix of query points (m x d), or a numeric vector of length d for a single point.

data

Numeric matrix of reference data (n x d).

tol

Convergence tolerance for the adaptive stopping rule. Default 0.01 (1% relative change).

batch_size

Number of random projections per batch. Default 100.

min_batches

Minimum number of batches before checking convergence. Default 5.

patience

Number of consecutive stable batches to declare convergence. Default 3.

seed

Integer random seed for reproducibility. Default 42.

Details

Tukey depth is the canonical multivariate depth function. The deepest point — the Tukey median — is a genuine robust generalization of the univariate median, with breakdown point up to 1/(d+1). Depth is defined purely geometrically via halfspaces with no distributional assumptions.

Exact computation is O(n^(d-1)) and infeasible for d > 3. This implementation uses an adaptive random projection approximation: depth is estimated as the minimum over random unit vector projections of the fraction of data points on either side of the query point's projection. The stopping rule automatically determines when the estimate has stabilised.

Value

Numeric vector of depth values in [0, 0.5], one per query point.

References

Tukey, J. W. (1975). Mathematics and the picturing of data. Proceedings of the International Congress of Mathematicians, 2, 523–531.

Zuo, Y. & Serfling, R. (2000). General notions of statistical depth function. Annals of Statistics, 28(2), 461–482.

Examples


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

# Basic usage
tukey_depth(x, data)

# Via compute_depth for full depth object
dd <- compute_depth(data, depth_fn = tukey_depth)
median(dd)
outliers(dd)



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