Sample median (source code)

= Sample median
{title2=$\widetilde X_n$}

The <sample median> is a central value of an ordered <statistical sample>. The usual numerical convention selects the middle <order statistic> for odd sample size and the <arithmetic mean> of the two central <order statistics> for even sample size:
$$
\widetilde X_n=\begin{cases}
X_{(m+1)},&n=2m+1,\\
\bigl(X_{(m)}+X_{(m+1)}\bigr)/2,&n=2m.
\end{cases}
$$
NIST uses this convention. https://www.itl.nist.gov/div898/handbook/eda/section3/eda351.htm[NIST: measures of location, median definition]{ref}. For $(0.7,0.1,0.9,0.4,0.2)$, the <sample median> is $0.4$; for $(0.1,0.2,0.4,0.7)$, it is $(0.2+0.4)/2=0.3$, which need not be an observed value.

More generally, every value between the two central <order statistics> in an even <statistical sample> is a <median> of its <empirical distribution function>. The generalized-inverse <sample quantile> at $p=1/2$ selects the lower central <order statistic> in that case, so it can differ from the midpoint convention. Ties are allowed in all these definitions.

The <sample median> measures the center using sorted positions. Changing the largest observation from $0.9$ to $9$ in the five-value example leaves the <sample median> at $0.4$, while the <sample mean> rises from $0.46$ to $2.08$. Its <sampling distribution> still depends on the population <probability distribution>: the <mean> $1/2$ found for five observations from a <uniform distribution> is a special calculation, and a <sample median>'s <expected value> need not equal the population <median> in general.

For a concrete counterexample, three <independent and identically distributed random variables> with rate-one <exponential distribution> have <sample median> $X_{(2)}$ with <expected value> $1/3+1/2=5/6$, by <independent exponential order-statistic spacings>. The population <median> instead solves $1-e^{-m}=1/2$, giving $m=\log2\approx0.693147$. Thus even the middle <order statistic> can have <mean> different from the population <median>.