BT

jStat: A Lightweight Statistical JavaScript Library

by Abel Avram on Aug 18, 2011 |

jStat is a JavaScript library providing developers with statistical functions and the ability to plot graphics from within the browser. jStat can be used for statistical operations on all browsers without any external dependencies, and it requires jQuery and the flot plug-in for plotting data. jStat is a partial port of R - an open source statistical language and environment-, implementing a subset of R’s functionality.

InfoQ has talked to Matthew Williams, a Research Fellow at Aston University, Birmingham, England, and member of the jStat team, in order to find out what functionality does jStat provide:

The core of jStat is based on vectors and matrices (much like MatLab). The base unit is a matrix and can be constructed using the jStat function (j$):

§ var matrix = j$([[1,2,3],[4,5,6],[7,8,9]])

Each matrix then has a host of methods available to you including, addition, division, multiplication, subtraction, diagonal, anti-diagonal, transpose, dot product, normalize, min, max, mean, median, etc. 

We then have a host of probability distributions including: normal, log-normal, beta, gamma, weibull, Cauchy, chi-square, exponential, pareto, student T, etc. Each probability distribution can evaluate the PDF, CDF and inverse CDF at a given x value (or a matrix of values). You can also calculate the mean, median, mode, standard deviation and variance wherever possible. Also, most distributions are capable of producing random samples. 

jStat also includes a host of ‘special’ functions including: gamma function, inverse gamma function, beta function, inverse beta function, incomplete beta function, log-gamma function, inverse incomplete gamma function, error function, complimentary error function, inverse complimentary error function. It also includes a couple of additional random number generators: randn (randomly sample from the normal distribution) and randg (randomly sample from the gamma distribution).

Tushar Gupta, a student working at Aston over the summer, has added a number of other functions, such as “optimization using Nelder-Mead and non-linear conjugate gradient algorithms, further linear algebra functions including integration, differentiation and interpolation.”

jStat is a relatively young project, and what’s missing the most is rich plotting functionality, which is to be added in the future. Without having a clear roadmap ahead, the jStat team has plans for its future, including a plug-in architecture that would allow it to be extended by anyone interested in the project, said Williams:

We have lots of plans for the future of jStat. We are working on a regression package that will offer simple linear regression through to some more complex Bayesian approaches. We are looking at providing several more complex plots, including the ability to plot multivariate variables (3D). Also, a further ambition is to create a fully interactive jStat environment.

Much like cloud9 is an online IDE, jStat will hopefully provide an online Matlab/R environment with the ability to keep track of variables, interactive plots and the ability to save and resume your work.

We are also hoping to create a plugin architecture so that anyone can create plugins for jStat and extend the functionality further. I think with a fully-featured plugin system there is huge potential for jStat.

As for an official roadmap, it is difficult at this stage. We are currently busy refactoring and documenting the changes we have made, once that is done we will update the jStat website and provide tutorials. This will hopefully be achieved within the next couple of months and will represent a major step forwards. Once we reach this milestone we will be better placed to plan the future of jStat.

The latest version of the code can be found on Github/jstat, licensed under a permissive MIT license.

For a more robust and mature statistical solution, one can use R, a complete framework with necessary tools to perform all sorts of statistical computations and plotting on Unix, Mac and Windows. But R is best fit for writing statistical native applications, while jStat is suitable for light cross-browser web applications that do not need all the functionality and heaviness of a framework like R. (The minified version of jStat has 40KB, while the Windows installer for R has 39 MB.)

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT