# Median based on number of entries instead of values

I’m writing a computer program that provides some useful statistical information about files. Calculating the mean is trivial, and the mode at least has a simple definition, but the median is proving tricky. I remember its general definition from school, but there is some ambiguity.

Median: the “middle number”.

But what does that mean? Is it the middle entry or the middle value?

The Wikipedia page for mean uses the sample data set 1, 2, 2, 6, 7, 8 and gives the median as 4 because the mean of the two middle entries (2 and 6) is 4.

But what about 6? The number 6 has the same number of values above (7,8) as it does below (1,2).

This is a pretty useful statistic as well. Is there a name for this?

-
You have to think it as an equilibrium point. – Sigur Aug 14 '13 at 1:07
The centre of gravity is the mean. – André Nicolas Aug 14 '13 at 1:41
By most reasonable interpretations, if you count 2 as just one "value", you'd still want to give it twice as much weight in almost anything you do, as you would if it had been there only once. – Michael Hardy Aug 14 '13 at 2:29
@Synetech : True: I've never thought the mode was good for much. – Michael Hardy Aug 14 '13 at 18:12
@Synetech : I had in mind the mode of a quantitative variable rather than a categorical one. (But I don't know how much the mode is worth in TV ratings either, unless it's for winning awards.) – Michael Hardy Aug 14 '13 at 18:24

The notion you are looking for is sample median (as opposed to population median).

Sort the sample values, respecting multiplicity. So if we got $7.8$ three times, we write it down $3$ times. One can use non-decreasing order or non-increasing order, it doesn't matter.

If the number of sample values is odd, say $2k+1$, then the sample median is the "middle" value, that is, the $(k+1)$-th value counting from the bottom (or top) of the sorted list.

If the number of sample values is odd, say $2k$, then the sample median is the ordinary average of the two "middle" values. the $k$-th and the $(k+1)$-th.

-
If you look a few lines down from the anchor you linked to on that page, you’ll see that it is the one that gives 4 as the median. I’m looking for a term for the calculation that would return 6. I tried looking for population median instead, but it was only used four times in the page and none of them defined it as what I’m wondering about (or at all for that matter). – Synetech Aug 14 '13 at 2:23
Population median is defined for a probability distribution. In the case of "ambiguity" of the type we meet with samples, all "middle" values are declared to be medians. So in our case it would be all numbers between $0$ and $6$ inclusive. The top of this range of medians, and the bottom, have no special names. In the finite case, any point $p$ that minimizes the sum of the absolute values $\sum |x_i-p|$ is a median. – André Nicolas Aug 14 '13 at 2:32
Discarding entries that happen to repeat would not make statistical sense. One could call the result $6$ the median of the set of values. – André Nicolas Aug 14 '13 at 2:39
Discarding entries that happen to repeat would not make statistical sense. How so? Most statistics ignore some attribute or another. The mode ignores all of the other values, and yet is frequently used. One could call the result 6 the median of the set of values. “Could” because there is no existing, formal name? – Synetech Aug 14 '13 at 4:22
There is no existing name that I know of used in Statistics. The median of the set of values is technically the correct name – André Nicolas Aug 14 '13 at 4:25