Checking my work: PERCENTILES.PRO [message #70942] |
Thu, 20 May 2010 17:40 |
MarioIncandenza
Messages: 231 Registered: February 2005
|
Senior Member |
|
|
This routine, I think many people use, and it has this code:
;; Special treatment for median of data sets with even number of
;; elements: compute average between two center values
IF ABS(value[i]-0.5) LT 1.e-3 AND n MOD 2 EQ 0 AND n GT 1 THEN $
thisresult = 0.5 * ( data[ix[long(n/2)]]+data[ix[long(n/
2)+1]] ) $
ELSE $
thisresult = data[ix[ind]]
If you should happen to give PERCENTILES() a two-element array, this
will crash. What's more, if N=4, this gives the median as
MEAN(DATA[2:3]), which is clearly wrong. Should be:
thisresult = 0.5 * ( data[ix[long(n/2)-1]]+data[ix[long(n/
2)]] ) $
Does that make sense? Anyway, if I am right, you may want to check
your libraries to see if this code is in there.
--Edward H.
|
|
|