Skip to content

Strange Result using weightedMedian

3 messages · Oliver Duerr, Dieter Menne, Frank E Harrell Jr

#
Dear all,
I found a strange result using R's weightedMedian function.
Consider the following:
In cases like above, when the weights are integers, one could argue that  
the weighted
median should be the same as the standard median with the elements  
repeated according to their weights. This is trivially true for the mean.
In the example above, we simply double the occurrence of the 0.5 entry
Does anyone know the answer to that inconsistency?
It must have to do with the interpolated version.
If you switch of the interpolation you get:
However, I prefer the interpolated version since it is continuous with  
respect to the weights. Is there a interpolated version of the  
weightedMedian which does not show this inconsistency?


All the best,
  Oliver
#
Oliver Duerr <Oliver.Duerr <at> genedata.com> writes:
....

I could not find weightedMedian on CRAN; I know there is such a function in 
some Java lib, googling gave a reference to limma (Linear Models for Microarray 
Data by Gordon Smyth and others).

Best contact the authors about the subject.

Dieter
#
Oliver Duerr wrote:
By the way:

 > library(Hmisc)
 > wtd.quantile(x,w)
    0%   25%   50%   75%  100%
0.200 0.275 0.400 0.500 0.500

Also see the type argument to wtd.quantile