comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Checking my work: PERCENTILES.PRO
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Checking my work: PERCENTILES.PRO [message #70940] Thu, 20 May 2010 18:01
David Fanning is currently offline  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.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Checking my work: PERCENTILES.PRO
Next Topic: Re: Negative values with incrementation

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 20:05:40 PDT 2025

Total time taken to generate the page: 0.00568 seconds