Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'd like to know if there is somewhere a tiny stat/discretization js library ready to use?

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

Actually, I'd 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 by myself and release it on github under free licence. Any resource and advice is most welcome.

share|improve this question
1  
This looks similar - code.google.com/p/pseudosavant/source/browse/trunk/mathStats/… Any reason for not going with jStat? – geographika Jun 17 '11 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 Jun 17 '11 at 19:38

3 Answers

up vote 9 down vote accepted

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.empreinte-urbaine.eu/mapping/geostats/ (with a concrete choropleth representation sample).

It supports the 3 methods listed above :

  • Quantile
  • Equal Interval
  • Natural Breaks (Jenks) : The Jenks classification code has been taken from Doug Curl.
  • Unique values

The library also includes a method to render a legend in HTML format.

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://raw.github.com/simogeo/geostats/master/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.

share|improve this answer
+1 very nice demo/samples – geographika Jun 17 '11 at 16:22

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

share|improve this answer
interesting, but I haven't seen classification methods. Are they? – simo Apr 23 '12 at 17:06
There are a few, like github.com/jasondavies/science.js/blob/master/src/stats/… – tmcw Apr 24 '12 at 14:38
indeed, thanks! – simo Apr 24 '12 at 15:48

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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