Median

Median(x)={x(n+12)ifnis odd(x(n2)+x(n2+1))/2ifnis even\begin{aligned} \operatorname{Median}(\mathbf{x}) = \begin{cases} x_{(\frac{n+1}{2})} & \text{if} n \text{is odd} \\ (x_{(\frac{n}{2})} + x_{(\frac{n}{2}+1)}) / 2 & \text{if} n \text{is even} \end{cases} \end{aligned}

The value splitting a sorted sample into two equal parts.

  • Also known as — 50th percentile, second quartile (Q2)
  • Asymptotic — value where P(XMedian)=0.5P(X \leq \operatorname{Median}) = 0.5
  • ComplexityO(n)O(n)
  • Domain — any real numbers
  • Unit — same as measurements

Notation

  • x(1),,x(n)x_{(1)}, \ldots, x_{(n)} order statistics (sorted sample)

Properties

  • Shift equivariance Median(x+k)=Median(x)+k\operatorname{Median}(\mathbf{x} + k) = \operatorname{Median}(\mathbf{x}) + k
  • Scale equivariance Median(kx)=kMedian(x)\operatorname{Median}(k \cdot \mathbf{x}) = k \cdot \operatorname{Median}(\mathbf{x})

Example

  • Median([1, 2, 3, 4, 5]) = 3
  • Median([1, 2, 3, 4]) = 2.5

Median\operatorname{Median} provides maximum protection against outliers and corrupted data. It achieves a 50% breakdown point, meaning that up to half of the data can be arbitrarily bad before the estimate becomes meaningless. However, this extreme robustness comes at a cost: the median is less precise than Center\operatorname{Center} when data is clean. For most practical applications, Center\operatorname{Center} offers a better tradeoff (29% breakdown with 95% efficiency). Reserve Median\operatorname{Median} for situations with suspected contamination levels above 29% or when the strongest possible robustness guarantee is needed.

Algorithm

The Median\operatorname{Median} algorithm sorts the sample and selects the middle element:

  • Sort Arrange the sample to obtain x(1)x(2)x(n)x_{(1)} \leq x_{(2)} \leq \ldots \leq x_{(n)}.

  • Select If nn is odd, return x(n+12)x_{(\frac{n+1}{2})}. If nn is even, return x(n2)+x(n2+1)2\frac{x_{(\frac{n}{2})} + x_{(\frac{n}{2}+1)}}{2}.

The time complexity is O(nlogn)O(n \log n) dominated by the sort. This standard algorithm is used as a building block by other estimators; no specialized implementation is needed beyond the languages built-in sort.

Tests

Median(x)\operatorname{Median}(\mathbf{x})

No reference test data exists for Median\operatorname{Median} yet. The tests/median/ directory has not been created. Test cases will be added when the Median\operatorname{Median} test generator is implemented.