The point c that minimises the weighted sum of distances
sum(w * |p - c|) to the points: the Weber point or spatial median,
which, unlike the median centre, does not depend on the axes. It is
found by Weiszfeld's iteration with the modification of Vardi and Zhang
(2000), which keeps every step defined and the sum non-increasing when
an iterate lands on a data point. The optimality gap certifies the
answer: it is 0 exactly at a minimiser. The minimiser is unique unless
all the points lie on one line with the weight split evenly.
Arguments
- x, y
The points:
xandynumeric vectors of equal length; orxa matrix or data frame with columns namedxandy(orXandY, assf::st_coordinates()names them, orlonandlatwithlonlat = TRUE) andyNULL; orxan sf or sfc object of POINT geometries, whose coordinate reference system must agree withlonlat. An unnamed two-column matrix is read asxtheny; other columns are never taken by position. Vectors given separately (x,y, andwortwhere a function takes them) are matched by name when every one is named and no name repeats, as elsewhere in the package; otherwise by position. No missing or infinite values.- w
NULLfor equal weights, or one non-negative weight per point (counts at a location, say), with a positive sum.- start
NULLto start at the mean centre, orc(x, y)(in degrees whenlonlat = TRUE).- tol
Stop when a step is at most
toltimes the root mean squared distance to the mean centre: one positive number.- maxit
The largest number of steps: one whole number from 0.
- lonlat
FALSE(the default) whenxandyare planar coordinates in one length unit;TRUEwhen they are longitude and latitude in degrees, which are then projected to metres byeqproj()about their own centre, and centres are returned in degrees. It is never guessed.
Value
A named numeric vector: x, y (the centre, in degrees when
lonlat = TRUE), obj (the weighted sum of distances), gap (the
optimality gap, 0 at a minimiser), iter (steps taken) and code: 2
at an exact minimiser, 1 when the step fell below tol, 0 when
maxit was reached.
References
Weiszfeld, E. and Plastria, F. (2009). On the point for which the sum of the distances to n given points is minimum. Annals of Operations Research, 167, 7-41 (translation of the 1937 paper). doi:10.1007/s10479-008-0352-z
Vardi, Y. and Zhang, C.-H. (2000). The multivariate L1-median and associated data depth. Proceedings of the National Academy of Sciences, 97(4), 1423-1426. doi:10.1073/pnas.97.4.1423