stats-array

array prototype for statistical calculations

stats-array

an array prototype extension for performing statistical calculations

npm install stats-array

 
var StatsArray = require('stats-array')
 
var arr = [ 50, 40, 30, 20, 30, 40, 50 ]
 
console.log(arr.stdDeviation()) 
// 11.126972805283735 
 
console.log(arr.stdDeviation(0.95)) 
// also calculates 95% confidence interval 
// { 
//   confidence: 0.95,  
//   lower:  7.17014792596768,  
//   upper:  24.502329752802414,  
//   value:  11.126972805283735,  
//   length: 7,  
//   alpha:  0.05 
// } 
 

calculate the standard deviation of the set and return the value, or optionally pass in a confidence interval (0.01-0.99) which will change the return value to an object hash

calculate the variance of the set

maximum value in the set

minimum value in the set

sum of all values in the set

returns the average

returns the range between the min and max values

divides the set into a matrix of subarrays

sort the set with smallest values first

sort the set with largest values first

calls Math.round on every value in the set

round every value to num places

 
[ 1.2555, 1.2557, 1.256001 ].roundTo(1000)
// => [ 1.256, 1.256, 1.256 ] 
 
[ 955642, 443234, 350460.256001 ].roundTo(0.001)
// => [ 956000, 443000, 350000 ] 
 
[ 1.2555, 1.2557, 1.256001 ].tan().roundTo(100)
// => [ 3.07, 3.07, 3.07 ] 
 

calls Math.abs on every value in the set

calls Math.acos on every value in the set

calls Math.asin on every value in the set

calls Math.atan on every value in the set

calls Math.ceil on every value in the set

calls Math.exp on every value in the set

calls Math.floor on every value in the set

calls Math.log on every value in the set

calls Math.pow on every value in the set

calls Math.sin on every value in the set

calls Math.sqrt on every value in the set

calls Math.tan on every value in the set

calls Math.sin on every value in the set

calculate the confidence of value which was created from a set of length using a gaussian (normal) distribution

npm install -g tap && npm test

Extending the Array.prototype causes no significant loss in performance compared with native arrays.

node bench/stats-array.js

(The MIT License)

Copyright (c) 2012 Thomas Blobaum tblobaum@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.