## median

0
0
Edited Sep 1, 2015

[scalar]
y
←

median(
[vector]expr
)
NOTE: [PERFORMS TABLE SCAN]#### Unweighted Median Algorithm

The unweighted median is the middle value in a set of sorted values if there are an odd number of values. If there are an
even number of values, the unweighted median is the average of the middle two values.

#### Weighted Median Algorithm (beta)

**THERE IS A PROBLEM WITH WEIGHTED MEDIAN. DON'T USE IT.**
Note: This algorithm computes a slightly different value than that of SPSS's weighted median algorithm. But it appears to match the weighted
median algorithm of WinCross. As of now we cannot seem to get the algorithm to precisely match the algorithm described in SPSS's documentation and wonder
if there either exists a typo in the SPSS documentation or perhaps SPSS only supports a certain amount of decimal precision when cumulating the
weights. The exact algorithm Report Builder uses for weighted median is shown below. Additional testing and research is in progress. Please
talk to use if you have questions or suggestions about this.

*x* is a set of sorted values where

Calculate the sum of the weights and the midpoint of that sum:

Calculate the cumulative weight per entry:

Find the closest indexes

*a* and

*b* such that the values cw

_{a} and cw

_{b} are as close to midwt as possible.

Calculate distances from the midpoint weight for interpolation:

The weighted median equals: