[R] Strange Result using weightedMedian
Oliver Duerr
Oliver.Duerr at genedata.com
Tue Sep 20 18:10:48 CEST 2005
Dear all,
I found a strange result using R's weightedMedian function.
Consider the following:
> x <- c (0.2, 0.3, 0.5)
> w <- c (1,1,2)
> weightedMedian(x,w)
> 0.3666
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
> x1 <- c(0.2, 0.3, 0.5, 0.5)
> median(x1) 0.4
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:
> weightedMedian(x,w,interpolate=FALSE)
> 0.4
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
More information about the R-help
mailing list