10

I would like to know if a tiny stat/discretization js library ready to use exists.

I do know about the existence of jStat (which I may explore a little bit more thoroughly), and I know that mapfish has a geostats module/widget to create choropleth map - I found the code here. But it relies on openlayers and I would like to have a standalone lib and eventually be free to communicate with openlayers.

I would like to have few basics methods:

  • min
  • max
  • mean
  • median

and be able to implement the following discretization with the ability to specify the number of classes and the precision (decimal):

  • Quantile
  • Equal Interval
  • Natural Breaks (Jenks)

If it does not exist yet, I will probably code something myself and release it on github under free license. Any resource and advice is welcome.

2
  • 1
    This looks similar - code.google.com/p/pseudosavant/source/browse/trunk/mathStats/… Any reason for not going with jStat? Commented Jun 17, 2011 at 16:21
  • Indeed the library you mentioned could have been a good start. Why not jstat? Because I haven't see discretization methods and that's what I was actually looking for in priority - stats methods are kind of bonus
    – simo
    Commented Jun 17, 2011 at 19:38

4 Answers 4

20

Well, I coded something yesterday and released it under MIT License.

The library, named geostats is available on github. The package includes examples. You will also be able to see it in action on http://www.intermezzo-coop.eu/mapping/geostats/ (with a concrete choropleth representation sample).

It supports the 8 methods listed above :

  • Quantile
  • Equal Intervals
  • Standard deviation
  • Arithmetic progression
  • Geometric progression
  • Natural Breaks (Jenks) : The Jenks classification code has been taken from Doug Curl.
  • Unique values
  • User defined classification

The library also includes a method to render a legend in HTML format. See HTML legend samples to see available options (continuous, discontinuous, distinct classes).

Quantile classification sample :

quantile classification and legend

Unique Values classification sample : enter image description here

See a demo reading values directly from shapefile (using Marc Harter library).

If you want to make a try by yourself in 2 steps, using the jsconsole :

Do copy/paste into the console, first :

:load https://www.intermezzo-coop.eu/mapping/geostats/lib/geostats.js

Then, do copy/paste :

var data = Array(12, 22, 5, 8, 43, 2, 34, 12, 34, 36, 5, 21, 23, 45, 12, 31, 38); 
serie = new geostats(data); 
serie.getEqInterval(4);
alert('Classification method : ' + serie.method + "\n\nClasses : " + serie.ranges.join(' | '));

Please, let me know if you discover any bug. Once again, any idea or suggestion is welcome to enhance the library.

That's all! Hope it will also be useful to you.

1
  • Careful - the jsconsole link actually points to "jconsole.com" which is spammer squat. I do not have the required karma to fix this. Can anyone update the link? It could contain malicious code. Commented Feb 29, 2016 at 10:58
1

Zachary Forest Johnson has done a really great job to provide thematic analysis on openlayers.

The library is under BSD license, available on github. More explanations on the project and samples are available on his blog.

1

science.js is a well-implemented collection of stats & linear algebra functionality with no dependencies.

2
0

I think these days the best library is probably simple-statistics. It's very high quality, and used by TurfJS. It uses "ckmeans" as an improvement over Jenks.

An (older) demo: http://bl.ocks.org/tmcw/4969184

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.