HOME

TheInfoList



OR:

In statistics, a weighted median of a sample is the 50% weighted percentile. It was first proposed by F. Y. Edgeworth in 1888. Like the median, it is useful as an estimator of
central tendency In statistics, a central tendency (or measure of central tendency) is a central or typical value for a probability distribution.Weisberg H.F (1992) ''Central Tendency and Variability'', Sage University Paper Series on Quantitative Applications in ...
,
robust Robustness is the property of being strong and healthy in constitution. When it is transposed into a system, it refers to the ability of tolerating perturbations that might affect the system’s functional body. In the same line ''robustness'' ca ...
against
outliers In statistics, an outlier is a data point that differs significantly from other observations. An outlier may be due to a variability in the measurement, an indication of novel data, or it may be the result of experimental error; the latter are ...
. It allows for non-uniform statistical weights related to, e.g., varying precision measurements in the sample.


Definition


General case

For n distinct ordered elements x_1, x_2,...,x_n with positive weights w_1, w_2,...,w_n such that \sum_^n w_i = 1, the weighted median is the element x_k satisfying :\sum_^ w_i \le 1/2 and \sum_^ w_i \le 1/2


Special case

Consider a set of elements in which two of the elements satisfy the general case. This occurs when both element's respective weights border the midpoint of the set of weights without encapsulating it; Rather, each element defines a partition equal to 1/2. These elements are referred to as the lower weighted median and upper weighted median. Their conditions are satisfied as follows: Lower Weighted Median :\sum_^ w_i < 1/2 and \sum_^ w_i = 1/2 Upper Weighted Median :\sum_^ w_i = 1/2 and \sum_^ w_i < 1/2 Ideally, a new element would be created using the mean of the upper and lower weighted medians and assigned a weight of zero. This method is similar to finding the median of an even set. The new element would be a true median since the sum of the weights to either side of this partition point would be equal.
Depending on the application, it may not be possible or wise to create new data. In this case, the weighted median should be chosen based on which element keeps the partitions most equal. This will always be the weighted median with the lowest weight.
In the event that the upper and lower weighted medians are equal, the lower weighted median is generally accepted as originally proposed by Edgeworth.


Properties

The sum of weights in each of the two partitions should be as equal as possible. If the weights of all numbers in the set are equal, then the weighted median reduces down to the median.


Examples

For simplicity, consider the set of numbers \ with each number having weights \ respectively. The median is 3 and the weighted median is the element corresponding to the weight 0.3, which is 4. The weights on each side of the pivot add up to 0.45 and 0.25, satisfying the general condition that each side be as even as possible. Any other weight would result in a greater difference between each side of the pivot. Consider the set of numbers \ with each number having uniform weights \ respectively. Equal weights should result in a weighted median equal to the median. This median is 2.5 since it is an even set. The lower weighted median is 2 with partition sums of 0.25 and 0.5, and the upper weighted median is 3 with partition sums of 0.5 and 0.25. These partitions each satisfy their respective special condition and the general condition. It is ideal to introduce a new pivot by taking the mean of the upper and lower weighted medians when they exist. With this, the set of numbers is \ with each number having weights \ respectively. This creates partitions that both sum to 0.5. It can easily be seen that the weighted median and median are the same for any size set with equal weights. Similarly, consider the set of numbers \ with each number having weights \{0.49; 0.01; 0.25; 0.25;\} respectively. The lower weighted median is 2 with partition sums of 0.49 and 0.5, and the upper weighted median is 3 with partition sums of 0.5 and 0.25. In the case of working with integers or non-interval measures, the lower weighted median would be accepted since it is the lower weight of the pair and therefore keeps the partitions most equal. However, it is more ideal to take the mean of these weighted medians when it makes sense instead. Coincidentally, both the weighted median and median are equal to 2.5, but this will not always hold true for larger sets depending on the weight distribution.


Algorithm

The weighted median can be computed by sorting the set of numbers and finding the smallest set of numbers which sum to half the weight of the total weight. This algorithm takes O(n \log n) time. There is a better approach to find the weighted median using a modified selection algorithm. // Main call is WeightedMedian(a, 1, n) // Returns lower median WeightedMedian(a ..n p, r) // Base case for single element if r = p then return a // Base case for two elements // Make sure we return the mean in the case that the two candidates have equal weight if r-p = 1 then if a w

a w return (a + a /2 if a w > a w return a else return a // Partition around pivot r q = partition(a, p, r) wl, wg = sum weights of partitions (p, q-1), (q+1, r) // If partitions are balanced then we are done if wl and wg both < 1/2 then return a else // Increase pivot weight by the amount of partition we eliminate if wl > wg then a w += wg // Recurse on pivot inclusively WeightedMedian(a, p, q) else a w += wl WeightedMedian(a, q, r)


Software/source code

* A fast weighted median algorithm is implemented in a C extension for Python in th
Robustats Python package
* R has many implementations, including matrixStats::weightedMedian(), spatstat::weighted.median(), and others.Is there a weighted.median() function?
/ref>


See also

*
Weighted arithmetic mean The weighted arithmetic mean is similar to an ordinary arithmetic mean (the most common type of average), except that instead of each of the data points contributing equally to the final average, some data points contribute more than others. The ...
*
Least absolute deviations Least absolute deviations (LAD), also known as least absolute errors (LAE), least absolute residuals (LAR), or least absolute values (LAV), is a statistical optimality criterion and a statistical optimization technique based minimizing the ''sum o ...
*
Median filter The median filter is a non-linear digital filtering technique, often used to remove noise from an image or signal. Such noise reduction is a typical pre-processing step to improve the results of later processing (for example, edge detection on an ...
*
Quickselect In computer science, quickselect is a selection algorithm to find the ''k''th smallest element in an unordered list. It is also known as the kth order statistics . It is related to the quicksort sorting algorithm. Like quicksort, it was devel ...


References

Means Robust statistics