[R] Weighted median

Henrik Bengtsson hb at maths.lth.se
Wed Feb 6 17:47:51 CET 2002


Is there a weighted median function out there similar to weighted.mean()
but for medians? If not, I'll try implement or port it myself.

The need for a weighted median came from the following optimization
problem:

  x* = arg_x min (a|x| + sum_{k=1}^n |x - b_k|)
 
where

  a  : is a *positive* real scalar
  x  : is a real scalar
  n  : is an integer
  b_k: are negative and positive scalars

which is a "median with a shift towards zero". This can be rewritten as

  x* = arg_x min (sum_{k=0}^n w_k|x - b_k|)

where w = (a, 1, 1, ..., 1) and b_0 = 0, which is a problem that could be
solved by a weighted median function. If someone has a better solution
(note that 'a' does *not* have to be an integer) to this specific
optimization problem I would be very happy to hear about it.

Thanks

Henrik Bengtsson
 
Dept. of Mathematical Statistics @ Centre for Mathematical Sciences
Lund Institute of Technology/Lund University, Sweden (+2h UTC)
Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax) 
h b @ m a t h s . l t h . s e
http://www.maths.lth.se/matstat/staff/hb/


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list