# HP Forums

Full Version: median
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was a little surprised to see that median, for an even number of elements in a list, both in Home and CAS, returns the smaller element of the two middle elements of the ordered list, e.g.,

median({1,2,3,4}) returns 2.

But, as far as I know, the statistical convention is to return the arithmetic mean of the ordered, two middle elements, so what should be returned for the above example is 2.5 in Home, and 5/2 in CAS.
The two conventions exist. I prefer to return an element of the sequence, because it applies to any ordered sequence without requiring to be able to add two elements and divide an element by 2. It is also easier to implement.
Hi,
I am a math teacher. I know the fact that median can be found by arranging all the observations from lowest value to highest value and picking the middle one. So the first group is <= median and median < the second group.. So the Prime is OK but... why don't take the usually convention!
I will have to say at my students "Don't take your Prime to do the median" this is sad.
Marcel
In math classrooms in the United States, there is only one convention: the median of a dataset is the middle value if there is an odd number of values. If there is an even number of values, the median is the average of the two middle values.
I'm not aware of any other computer program, language, or calculator that defaults to the lower element. I just tested Mathematica, Matlab, R and Excel and they all return the average of the two central elements. In 10 minutes of googling I couldn't find one example where the author didn't just average the two central elements... I'm not saying you're wrong per se; but this will probably bork many things; silently and without error. Like spreadsheets.
I too am not aware of any software package that follow this method. Anyone ever encountered it?
(09-13-2014 08:25 PM)Marcel Wrote: [ -> ]Hi,
I am a math teacher. I know the fact that median can be found by arranging all the observations from lowest value to highest value and picking the middle one. So the first group is <= median and median < the second group.. So the Prime is OK but... why don't take the usually convention!
I will have to say at my students "Don't take your Prime to do the median" this is sad.
Marcel

Or simply have them type this once into the Define window via [Shift] [x t θ n]:

Name: med
Function: (median(M1)+median(tail(M1)))/2

From then on, they can use med() instead of median(), and get the expected answer.
Yes, this will do nicely (if the array or list is already sorted).

Otherwise: (median(M1)+median(tail(SORT(M1))))/2.
Wikipedia (French) tells
"Pour une liste ordonnée de 2N éléments, toute valeur comprise entre l'élément N et l'élément N+1 est une médiane;"
(evey value between element N and N+1 is a median if the list has 2N elements).
Wikipedia (English) "If there is an even number of observations, then there is no single middle value; the median is then usually defined to be the mean of the two middle values", observe the word "usually".
If you are using median to describe a statistical serie, using one definition or another is not important. Those who insist on the arithmetic mean definition are using medians for a different purpose, not related to statistics.
(09-14-2014 04:35 AM)Helge Gabert Wrote: [ -> ]Yes, this will do nicely (if the array or list is already sorted).

Otherwise: (median(M1)+median(tail(SORT(M1))))/2.

Yikes, I forgot that it might not be pre-sorted. Good catch!
BTW, I can easily add code to return the arit mean for the Prime (like I did for geogebra) but this will not extend to quartiles.
(09-14-2014 09:37 AM)parisse Wrote: [ -> ]BTW, I can easily add code to return the arit mean for the Prime (like I did for geogebra) but this will not extend to quartiles.

I've never seen a median of an even number of items defined as the smaller of them.

Are you using the linear time algorithm for the median and quartiles?

- Pauli
Much nicer to guarantee the median returning an element from the set for several applications I came across. OTOH, the algorithm given is clearly biased towards "lower" values .
(09-14-2014 09:51 AM)Paul Dale Wrote: [ -> ]Are you using the linear time algorithm for the median and quartiles?
No, it's O(n*ln(n)) where n=size(v), v is sorted first then v[(n-1)/2] (indices starting at 0 and /2 is integer division).
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :