gnu-octave / statistics

The Statistics package for GNU Octave
GNU General Public License v3.0
24 stars 22 forks source link

Correct median value of binomial distribution when p = 0.5 and N is odd #142

Closed rlaboiss closed 5 months ago

rlaboiss commented 5 months ago

For a thorough discussion on this issue, see:

Nowakowski S (2021) Uniqueness of a median of a binomial distribution with rational probability. Advances in Mathematics: Scientific Journal 10(4):1951-1958. (http://dx.doi.org/10.37418/amsj.10.4.9)

Essentially, when p = 0.5 and N is odd, there would be two "median values" (both integer values around N/2). In this case, the median value should be the fully trimmed mid-range, which happens to be equal to the mean value.

Notice that these changes only cope with the untruncated case. For the general truncated case, the solution seems not to be straightforward. In particular, the code below:

pd = BinomialDistribution (5, 0.5);
t = truncate (pd, 0, 5)
t.median ()

will produce value 3, which is wrong (it should be 2.5).

At any rate, this change is bug-compatible with Matlab, thanks to the use of __traditional_().