[ncl-talk] compute mode?

Dennis Shea shea at ucar.edu
Wed Dec 4 11:23:00 MST 2019


*NCL*: As noted by DaveA. The following may be usefu*l*
*pdfx* <http://www.ncl.ucar.edu/Document/Functions/Contributed/pdfx.shtml>

*http://www.ncl.ucar.edu/Applications/pdf.shtml*
<http://www.ncl.ucar.edu/Applications/pdf.shtml>
*http://www.ncl.ucar.edu/Applications/histo.shtml*
<http://www.ncl.ucar.edu/Applications/histo.shtml>
*-------*

re: "*Discrete distributions (counts, etc.)*"
Note:
[1] There can be multiple modes in a distribution. See attached test script.
[2] It could be that each value is distinct. No repeat values. EG: random
numbers.

I had a *get_mode *function. I updated it [significantly] and used DaveA's
descriptor "discrete" in the function name.
It was renamed to *get_discrete_mode*. This emphasizes that the internal
functions work on discrete values.
It handles discrete values like integers.
It forces 'grouping' of float/double array into discrete values using the*
round * <http://www.ncl.ucar.edu/Document/Functions/Built-in/round.shtml>
function

; It groups values +/- of value
; eg: 82.5 ==> round(82.5,0) ==> 83.0
; eg: 83.4 ==> round(83.4,0) ==> 83.0
; eg: 82.4 ==> round(82.4,0) ==> 82.0
; eg: 81.5 ==> round(81.5,0) ==> 82.0

This may/may-not be appropriate. As I recall, this is what was desired in
the original use case.

---
%> ncl tst.get_discrete_mode.ncl | less

On Tue, Dec 3, 2019 at 6:07 PM Dave Allured - NOAA Affiliate via ncl-talk <
ncl-talk at ucar.edu> wrote:

> If your data are considered to be a continuous distribution, then compute
> the probability density function with NCL's pdfx function.  Then maxind()
> gives the position of the largest bin (i.e. highest density), which
> contains the mode.  You may need to adjust the number of bins to get the
> desired precision.
>
> See NCL examples pdf_1 and pdf_2 to get the general idea of PDF's.  Also
> refer to this Wikipedia page on mode:
> https://en.wikipedia.org/wiki/Mode_(statistics)
>
> Discrete distributions (counts, etc.) must be handled a little differently.
>
>
> On Tue, Dec 3, 2019 at 11:55 AM Lesley Smith - NOAA Affiliate via ncl-talk
> <ncl-talk at ucar.edu> wrote:
>
>> Greetings NCL folks!
>> Is there a way to compute the mode (most frequent value) of
>> data using NCL?
>> I'm not seeing anything...
>> Thanks so much!
>> Cheers,
>> -Lesley
>>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191204/3353b536/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: get_discrete_mode.ncl
Type: application/octet-stream
Size: 4090 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191204/3353b536/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst.get_discrete_mode.ncl
Type: application/octet-stream
Size: 2460 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20191204/3353b536/attachment-0001.obj>


More information about the ncl-talk mailing list