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

Home » Public Forums » archive » Re: Mode????
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Mode???? [message #13984] Thu, 14 January 1999 00:00 Go to previous message
f055 is currently offline  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 .
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Routine_info bug in 5.2
Next Topic: Re: Problem with IDL output files

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

Current Time: Sat Oct 11 18:40:21 PDT 2025

Total time taken to generate the page: 1.83766 seconds