Re: Mode???? [message #13984] |
Thu, 14 January 1999 00:00 |
f055
Messages: 29 Registered: April 1995
|
Junior Member |
|
|
In article <Pine.SO4.4.03.9901131357520.19077-100000@virgil.gsfc.nasa.gov>, "Robert S. Hill" <bhill@virgil.gsfc.nasa.gov> writes:
-On Wed, 13 Jan 1999, Lisa Bryan wrote:
-> Mode refers to the most likely value in an array. The method that
-> jumps to mind is using the histogram function. The mode is the value
-> associated with the max of the histogram. Is there anything slicker
-> out there?
-
-Getting a good estimate of the mode is not trivial. If you don't have
-lots of counts in your histogram, either it will be noisy near the peak
-or you will have to use such a big bin size that the quantization error
-in your estimate is large. Two approaches that I have seen are to fit a
-function (e.g., gaussfit) to the histogram, or to forego the histogram
-altogether and to use the estimator mode=3*median-2*mean. (I don't have
-a reference for the question under what conditions the latter formula is
-applicable; my ancient CRC Tables lists it without further comment as
-"Empirical Relation Between Mean, Median, and Mode," so presumably the
-distribution should have a sort of skewed Gaussian shape.)
How about the function below? It's not been extensively tested (just
written it!), but by sorting and using the uniq function, the most
frequently occurring value should be the one with the biggest gap
between the locations of unique values (uniq returns the location of
the last in each run of identical values).
function mode,x
;
; Given a list of values x, compute and return its mode (the most frequently
; occurring value).
;
; Get size and make it 1 dimensional
n=n_elements(x)
y=reform(x,n)
;
; Sort into order and find location of unique values
y=y(sort(y))
itest=uniq(y)
ntest=n_elements(itest)
;
; The most frequently occurring value will show the biggest
; gap (in terms of location) between two unique values. Have to be careful
; in case the smallest value is the most frequent.
itest=[-1,itest]
igap=itest(1:ntest)-itest(0:ntest-1)
dummy=max(igap,iwant)
;
return,y(itest(iwant+1))
end
......................... Dr Tim Osborn . t.osborn@uea.ac.uk
.... ___/.. __ /.. /.. /. Senior Research Associate . phone:01603 592089
... /..... /. /.. /.. /.. Climatic Research Unit . fax: 01603 507784
.. /..... __/.. /.. /... School of Environmental Sciences.
. /..... /\ ... /.. /.... University of East Anglia .
____/.._/..\_..____/..... Norwich NR4 7TJ .
......................... UK .
|
|
|
Re: Mode???? [message #13988 is a reply to message #13984] |
Wed, 13 January 1999 00:00  |
Robert S. Hill
Messages: 11 Registered: January 1998
|
Junior Member |
|
|
On Wed, 13 Jan 1999, Lisa Bryan wrote:
> Mode refers to the most likely value in an array. The method that
> jumps to mind is using the histogram function. The mode is the value
> associated with the max of the histogram. Is there anything slicker
> out there?
Getting a good estimate of the mode is not trivial. If you don't have
lots of counts in your histogram, either it will be noisy near the peak
or you will have to use such a big bin size that the quantization error
in your estimate is large. Two approaches that I have seen are to fit a
function (e.g., gaussfit) to the histogram, or to forego the histogram
altogether and to use the estimator mode=3*median-2*mean. (I don't have
a reference for the question under what conditions the latter formula is
applicable; my ancient CRC Tables lists it without further comment as
"Empirical Relation Between Mean, Median, and Mode," so presumably the
distribution should have a sort of skewed Gaussian shape.)
Bob
--
Robert.S.Hill.1@gsfc.nasa.gov Phone: 301-286-3624
Raytheon ITSS / Code 681, NASA/GSFC, Greenbelt, MD 20771
|
|
|
Re: Mode???? [message #13990 is a reply to message #13988] |
Wed, 13 January 1999 00:00  |
lbryanNOSPAM
Messages: 21 Registered: July 1998
|
Junior Member |
|
|
Mode refers to the most likely value in an array. The method that
jumps to mind is using the histogram function. The mode is the value
associated with the max of the histogram. Is there anything slicker
out there?
On 13 Jan 1999 14:16:58 GMT, "RobertKehoe" <Robert_Kehoe_1@sbphrd.com>
wrote:
> Hi there
> I am trying to find an IDL function that returns the mode out of an array
> of numbers anyone know a way of doing this. It strange that there does not
> seem to be a function for this.
> Rob.
> --
> The opinions expressed in this communication are my own and do not
> necessarily reflect those of my employer.
>
Lisa Bryan
Arete Associates
Tucson, Arizona
lbryan@arete-az.com
|
|
|
Re: Mode???? [message #13991 is a reply to message #13988] |
Wed, 13 January 1999 00:00  |
rivers
Messages: 228 Registered: March 1991
|
Senior Member |
|
|
>> I am trying to find an IDL function that returns the mode out of
>> an array of numbers anyone know a way of doing this. It strange
>> that there does not seem to be a function for this.
>
> It would be (a lot!) easier to answer this question if you could
> explain what you mean by "returning the mode out of an array of
> numbers". But let me have one or two shots:
>
> If you mean the modulus of the numbers in an array, use the
> operator MOD, as in:
>
> answer = numbers mod 5 ;; Returns array "numbers" modulo 5
>
> If you mean the size of an array (mode out of an array, well
> could be..?) try the function size().
I bet he means the "mode", i.e. the value in the array with the most repeats.
I think the IDL "histogram" function is what one would use to get this
information.
Mark Rivers
|
|
|
Re: Mode???? [message #13992 is a reply to message #13988] |
Wed, 13 January 1999 00:00  |
steinhh
Messages: 260 Registered: June 1994
|
Senior Member |
|
|
Robert Kehoe wrote:
> I am trying to find an IDL function that returns the mode out of
> an array of numbers anyone know a way of doing this. It strange
> that there does not seem to be a function for this.
It would be (a lot!) easier to answer this question if you could
explain what you mean by "returning the mode out of an array of
numbers". But let me have one or two shots:
If you mean the modulus of the numbers in an array, use the
operator MOD, as in:
answer = numbers mod 5 ;; Returns array "numbers" modulo 5
If you mean the size of an array (mode out of an array, well
could be..?) try the function size().
Otherwise, please clarify.
Stein Vidar
|
|
|