Re: Checking my work: PERCENTILES.PRO [message #70940] |
Thu, 20 May 2010 18:01 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Ed Hyer writes:
> 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.
Maybe we should substitute this for the entire mess:
thisResult = Median(data[ix[ind]], /EVEN)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|