Statistics Extensions for Ignition

After discussions elsewhere with @Brian on the forum, I’ve ported the statsutils library from http://boltons.readthedocs.io

some changes from the originaL

  • Removed the format_histogram functions, as they were using unsupported string formatting. Maybe when Ignitions’s Jython gets upgraded, I can look at it again.

  • Renamed remaining histogram function to histogram. Brevity is good.

  • Added ‘raw’ flag to histogram function to give a one-dimensional list with repeat histogram values, instead of a list of (value, count) tuples.

  • added mode and all_modes functions. Read the doc for more info.

statsutils_2018-02-22_1158.proj (11.8 KB)
statsutils for Ignition.pdf (168.3 KB)

1 Like

@Brian, You had mentioned about using mode on binned values.

  1. Make a Stats instance of the list

  2. grab the histogram with whatever bins you want to use and setting the ‘raw’ flag. This list will be what you run against mode.

  3. make another Stats instance with the new list.

  4. get the mode

from shared.statsutils import Stats

listIn = [1.234, 5.678, 9.012, 3.456, 7.890, 2.345, 4.567]

statsList1 = Stats(listIn)

print 'histogram:', statsList1.histogram(bins = 6, bin_digits = 2)

statsList2 =  Stats(statsList1.histogram(bins = 6, bin_digits = 2, raw = 1))

print 'mode:', statsList2.mode

Cool!! I’ll import and play around with this the next time I get a chance!

Thanks!!

Don't do this. After this executes on this module's load, if shared.statsutils is updated, this module won't get the changes. You should always use spelled-out names for shared.* and project.* functions and objects. Don't import them.

Thanks, Phil. It was for demonstration purposes only, and to make the example more reader-friendly.

You hear that kids? Don’t do it!

1 Like

And get off my lawn!
{ Goes with my grey beard... }

2 Likes

I finally had a chance to play around with this code. I think I like the math.mode function that I came up with best for calculating modes. Or at least, matches what excel will give me for a mode on values rounded to 3 digits.

With the statsutils version, I have to try to calculate the number of bins ahead of time to get a fine-grained enough binning. With the other method, the bins are auto-created as needed, so to speak.

I’ll definitely be using the statsutils for other statistical functions though! Very useful stuff!

Thanks again!