Statistics function incorrectly computing median

Ben Abbott bpabbott at mac.com
Sat Jan 26 21:41:10 CST 2008


On Jan 26, 2008, at 6:39 AM, Miguel Garcia-Blanco wrote:

> My tests (using 40 samples with 6 observations ~N(0,100)) indicate
> everything seems to be okay, except quantile.m with METHOD = 3: For  
> six
> observations, the 3rd quartile should be the 4th order statistic.  
> Currently
> returns the 5th order statistic.
>
> -Miguel


I have the impression that the following is *almost* what is needed  
for METHOD = 3.

             cdf = ((1:m))./m;
             for q=1:n
               t = interp1 (cdf, 1:m, x(k(q)), 'nearest', 'extrap');
               inv(k(q)) = v(t);
             endfor

The problem is choosing how half values are treated. For example, it  
appears that R will convert 1.5  to 2 and 2.5 to 2 as well. While  
Octave always rounds upward.

I'm leaning toward that conclusion due to R's documentation ...

        3. Method 3: SAS definition: nearest *even* order statistic.

... and due to the results I obtain for for x = 1:4 and x = 1:5.

In any event, I've modified the algorithm in a very kludgy way, and  
attached a version of __quantile__.m what respects this interpretation.

Can you verify that this change works for the other examples.

Also, please post some examples that did (do ?) not work so that I may  
include them in the test script.

Ben

-------------- next part --------------
A non-text attachment was scrubbed...
Name: __quantile__.m
Type: application/octet-stream
Size: 4564 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080126/da6e3eba/attachment.obj 
-------------- next part --------------



More information about the Bug-octave mailing list