14

Using Apache Commons Math, how do I get the median from a series of numbers?

The Commons Math User Guide says DescriptiveStatistics supports median, yet the JavaDocs for DescriptiveStatistics makes no mention of it. It does mention geometric mean, is this the same thing as median?

I do see getPercentile(double). Is getPercentile(50) the same as median?

Steve Kuo
  • 58,491
  • 75
  • 189
  • 247
  • 3
    The median is the number in the middle in sorted order: it is greater than half the elements, and less than the other half. The 50th percentile is greater than 50% of the elements, and less than the other 50%. Yes, they're the same. – Louis Wasserman Apr 06 '14 at 02:31

2 Answers2

17

DescriptiveStatistics.getPercentile

The 50th percentile is, by definition, the median.

Louis Wasserman
  • 172,699
  • 23
  • 307
  • 375
0

Apache Commons Math is like a hurricane, so one has to check for the version he is going to mention. I am using the v3.6.1 now, and it includes Median (a Percentile override with fixed quantile = 50) and Percentile classes.

Aram Paronikyan
  • 1,534
  • 17
  • 21