
psMathStats 2.0
I just pushed the latest version of psMathStats to GitHub. It had been sitting on the shelf 95% done for probably a year, but it is out at last. There are some new methods and while the syntax is almost exactly the same, it isn’t a dropin replacement for 1.0 as it now uses my ps namespace.
New Features
A full breakdown of all the methods and functions of 2.0 are available on GitHub, but these are some of the new features.
 Array.sample
 Array.histogram
 Array.countByType
 Array.percentile
 ps.math.even
 ps.math.odd
 ps.math.product
 ps.math.randomBetween
 ps.math.randomNormal
Array.sample
Probably the biggest new feature is the ability to do sampling for any of the Array methods using Array.sample. It returns a randomly sampled array of any length less than or equal to the source array length. You can use it to quickly do calculations over large datasets (1MM+ rows) very quickly while sacrificing only a small amount of accuracy.
Here is an example:
// This will take a long time (many seconds) to run. // Makes the browser become unresponsive tenMillionRowArray.stdDev(); // Takes only a few milliseconds to run, and the // returned value is almost exactly the same. tenMillionRowArray.sample(20000).stdDev();
Suggestions
As always, if you have any other useful math or statistics functions you’d like to see implemented just drop me a line at Twitter or GitHub with some details on how to perform the calculation. Even better, just send me a pullrequest with your implementation. ;)
Filed In: JavaScriptJune 14, 2013