Skip to contents

Using the Weiszfeld algorithm an iterative method to compute the geometric median of a set of points in Euclidean space. In general, measures of central tendency minimize the sum of the Euclidean distance from the center to each point in the set. We try to come up with an estimate of this center by first using our best guess and then approximating it by calculating the distance from each point to a newly chosen point in the set and updating the center if the distance is smaller than that calculated using our best, initial guess.

Usage

geom.median(x, iters = 1000, tol = 1e-08, na.rm = FALSE)

Arguments

x

vector of non-collinear points

iters

number of iterations used in Weiszfeld algorithm

tol

tolerance value used to check convergence of changes between successive guesses.Default set to 1e-8.

na.rm

set to FALSE. To handle NAs, set to TRUE.

Value

a numeric vector of length 1L.

Details

If your sample is a 1D set of points use median or grouped.median instead. The geom.median function is used for samples of points in +2D space.

Examples

d <- rlnorm(60,1,1.4)
geom.median(d,iters = 100)
#> [1] 2.7419

x <- matrix(rlnorm(60,1,1.4),ncol = 4)
mapply(geom.median, as.data.frame(x))
#>        V1        V2        V3        V4 
#> 0.7132444 1.2380142 2.7550766 2.5423200