Statistics function incorrectly computing median

Ben Abbott bpabbott at mac.com
Sun Jan 20 21:24:35 CST 2008


Michael Godfrey ran some calculations using Matlab's quantile function.

We can now compare Matlab's quantile (), R's summary(), and Maxima's  
 >> quantile (), with the new quantile.m I had hope to add to octave  
(my quantile() calls discrete_inv()).

Unfortunately, Matlab is an outlier :-(

 >> q = [0.00 0.25 0.50 0.75 1.00];
 >> quantile (1:4, q)
Matlab:  1.0000    1.5000    2.5000    3.5000    4.0000
Octave:  1.0000    1.7500    2.5000    3.2500    4.0000
R     :  1.0000    1.7500    2.5000    3.2500    4.0000
Maxima:  1.0000    1.7500    2.5000    3.2500    4.0000

 >> quantile (1:5, q)
Matlab:  1.0000    1.7500    3.0000    4.2500    5.0000
Octave:  1.0000    2.0000    3.0000    4.0000    5.0000
R     :  1.0000    2.0000    3.0000    4.0000    5.0000
Maxima:  1.0000    2.0000    3.0000    4.0000    5.0000

 >> quantile ([1, 2, 5, 9], q)
Matlab:  1.0000    1.5000    3.5000    7.0000    9.0000
Octave:  1.0000    1.7500    3.5000    6.0000    9.0000
R     :  1.0000    1.7500    3.5000    6.0000    9.0000
Maxima:  1.0000    1.7500    3.5000    6.0000    9.0000

 >> quantile ([1, 2, 5, 9, 11], q)
Matlab:  1.0000    1.7500    5.0000    9.5000   11.0000
Octave:  1.0000    2.0000    5.0000    9.0000   11.0000
R     :  1.0000    2.0000    5.0000    9.0000   11.0000
Maxima:  1.0000    2.0000    5.0000    9.0000   11.0000

 >> quantile ([16, 11, 15, 12, 15, 8, 11, 12, 6, 10], q)
Matlab:  6.0000   10.0000   11.5000   15.0000   16.0000
Octave:  6.0000   10.2500   11.5000   14.2500   16.0000
R     :  6.0000   10.2500   11.5000   14.2500   16.0000
Maxima:  6.0000   10.2500   11.5000   14.2500   16.0000

 >> quantile ([-0.58850548, 0.40048183, 0.49527124, -2.55147412,  
-0.52057029, -0.17840861, 0.05732226, -0.62523119, 0.04290641,  
0.12336620], q)
Matlab: -2.5515   -0.5885   -0.0678    0.1234    0.4953
Octave: -2.5515   -0.5715   -0.0678    0.1069    0.4953
R     : -2.5515   -0.5715   -0.0678    0.1069    0.4953
Maxima: -2.5515   -0.5715   -0.0678    0.1069    0.4953

I don't think it proper to introduce a new Octave function with the  
same name as a Matlab function that does not work in compatible way.  
Thus, if I cannot reverse engineer the approach used by Matlab, I  
think I'll drop my goal of adding the quantile.m script, and restrict  
my efforts to reconciling the statistics.m script with R and maxima  
(which I hope to finish quickly).

If someone has the time an inclination to reverse engineer the  
approach used by matlab, it would be appreciated.

Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080120/397f4e6c/attachment-0001.html 


More information about the Bug-octave mailing list