Computes the Multivariate Median of the distribution provided in data (depth computations rely on the packages depth, OjaNP and ddalpha, while convex body minizers "MCD" and "MVE" use the package MASS).

median_mv(data, method = "Projection", sampleMedian = TRUE, warnings = FALSE)

Arguments

data

Matrix of numerical values containing the observations (one per row, with two columns for X and Y coordinates)

method

Method to use. Valid options are "CW", "MCD", "MVE", "L2", "Lui", "Mahalanobis", "Oja", "Projection" (default), "Spatial" and "Tukey"

sampleMedian

Logical value. If TRUE (default), the function will return the Sample Median (observation from data with the highest depth). If FALSE, it will return the classic Multivariate Median (point in space with the highest depth), when applicable (methods "Oja", "Turkey" and "Spatial")

warnings

Logical value, to display the warnings and error caught by the underlying functions

Value

Coordinates of the Multivariate Median

See also

Examples

# Illustrative data XY <- rbind( mvtnorm::rmvnorm(200, c(0, 0), diag(2)), mvtnorm::rmvnorm(100, c(15, 20), diag(2) * 3 - 1), mvtnorm::rmvnorm(150, c(-10, 15), diag(2) * 2 - 0.5), mvtnorm::rmvnorm(100, c(5, 5), diag(2) * 200) ) # Compute median m <- median_mv(XY, method = "L2", warnings = TRUE) # Plot results plot(XY, asp = 1, xlab = "X", ylab = "Y")
points(m[1], m[2], col = "red", pch = 3, cex = 1.5, lwd = 3)
## Others examples of medians if (FALSE) { median_mv(XY, method = "Oja") median_mv(XY, method = "Tukey", sampleMedian = TRUE) median_mv(XY, method = "Tukey", sampleMedian = FALSE) }