|
Boost Users : |
Subject: Re: [Boost-users] statistics: exact median, first and third quartile
From: James Hirschorn (James.Hirschorn_at_[hidden])
Date: 2013-03-01 10:51:25
gast128 wrote:
> Steven Watanabe <watanabesj <at> gmail.com> writes:
>>
>> This is called std::nth_element.
>>
>
> Thx, but are you sure? Median is defined as the middle element in odd
> distributions but is the average of the 2 middle elements in even
> distributions.
So? For a collection c of size 2n, you would use:
nth_element( begin(c), begin(c) + n - 1, end(c) );
nth_element( begin(c), begin(c) + n, end(c) );
auto median = (c[n - 1] + c[n]) / 2;
> For quartiles (or generalized quantiles) its even worse:
> there are multiple definitions for quartiles. I even had an article listed
> 11 definitions of calculating the quartile:
> http://www.amstat.org/publications/jse/v14n3/langford.html. Still it would
> have been better if Boost had done the thinking for me :)
Definitely!
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net