| Re: median function [message #16407] |
Thu, 22 July 1999 00:00 |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
Hi Harald,
Harald Frey wrote:
>
> I see a problem in the median function and would like to get your
> general opinion.
>
> 1. The median function has no /Nan option like total or mean.
I think you will be happy to know that the newly-released IDL 5.2.1 (see
www.rsinc.com for your update!) has the following release note:
MEDIAN Function Improvement:
----------------------------
The MEDIAN function now treats NaN values as missing data.
> IDL> a=findgen(9)
> IDL> print,total(a),mean(a),median(a)
> 36.0000 4.00000 4.00000
> IDL> a[0]=!values.f_nan
> IDL> print,total(a),mean(a),median(a)
> NaN NaN 4.00000
> % Program caused arithmetic error: Floating illegal operand
That was in 5.2, but now in 5.2.1, after the same instructions:
IDL> print,total(a),mean(a),median(a)
NaN NaN 5.00000
> 2. The Nan values are not properly handled in the determination of the
> median. In the first case the Nan values are interpreted as 0. and in
> the second case as very large.
>
> IDL> a=findgen(9)
> IDL> a[0]=!values.f_nan
> [...]
> IDL> a[1]=!values.f_nan
> IDL> print,a
> NaN NaN 2.00000 3.00000 4.00000
> 5.00000
> 6.00000 7.00000 8.00000
> IDL> print,median(a)
> 6.00000
> % Program caused arithmetic error: Floating illegal operand
Again, with the new 5.2.1:
IDL> print,median(a)
5.00000
I think you will find this satisfactory!
Cheers,
--
-Dick
Dick Jackson Fanning Software Consulting, Canadian Office
djackson@dfanning.com Calgary, Alberta Voice/Fax: (403) 242-7398
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|
| Re: median function [message #16416 is a reply to message #16407] |
Wed, 21 July 1999 00:00  |
Pavel Romashkin
Messages: 166 Registered: April 1999
|
Senior Member |
|
|
I ran into this limitation but spent no time thinking whether its right
or wrong. I just used FINITE function to clean up arrays before using
MEDIAN. It gets the job done not any worse than if a /NAN keyword were
available. After all, /NAN should not be allowed in calls to MEDIAN
which, by definition, should return the medium point of the (sorted)
array. Since NAN is not a number, there is no way to treat it
numerically correctly.
Good luck,
Pavel
|
|
|
|