[R] Strange Result using weightedMedian
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Tue Sep 20 20:40:44 CEST 2005
Oliver Duerr wrote:
> 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)
> 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)
> 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,
By the way:
0% 25% 50% 75% 100%
0.200 0.275 0.400 0.500 0.500
Also see the type argument to wtd.quantile
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help