spatial_depth: Spatial Depth

View source: R/spatial_depth.R

spatial_depthR Documentation

Spatial Depth

Description

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

Usage

spatial_depth(x, data)

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).

Details

Spatial depth is defined as 1 minus the norm of the mean unit vector pointing from the data toward the query point. Unlike other depth functions in this package, it has a closed-form sample estimate with no Monte Carlo approximation required — making it the fastest depth function here, suitable for very large n and d.

Spatial depth is orthogonally invariant but not affine invariant. For affine invariant depth use projection_depth or tukey_depth.

Value

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

References

Vardi, Y. & Zhang, C.-H. (2000). The multivariate L1-median and associated data depth. Proceedings of the National Academy of Sciences, 97(4), 1423–1426.

Examples


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

spatial_depth(x, data)

dd <- compute_depth(data, depth_fn = spatial_depth)
median(dd)
outliers(dd)



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