Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stats-lite

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stats-lite

A light statistical package that operates on numeric Arrays.

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
114K
decreased by-2.11%
Maintainers
1
Weekly downloads
 
Created
Source

stats-lite

NPM

A fairly light statistical package for Node.js. Works with numeric arrays, and will automatically filter out non-numeric values and attempt to convert string numeric values.

Example

Live Demo using Browserify!

var stats = require("stats-lite")

var dice = require("dice")

var rolls = []
for (var i = 0; i < 3000; i++) {
  rolls.push(dice.sum(dice.roll("2d6")))
}

console.log("sum: %s", stats.sum(rolls))
console.log("mean: %s", stats.mean(rolls))
console.log("median: %s", stats.median(rolls))
console.log("mode: %s", stats.mode(rolls))
console.log("variance: %s", stats.variance(rolls))
console.log("standard deviation: %s", stats.stdev(rolls))
console.log("85th percentile: %s", stats.percentile(rolls, 0.85))

/* Your exact numbers may vary, but they should be pretty similar:
sum: 21006
mean: 7.002
median: 7
mode: 7
variance: 5.907329333333325
standard deviation: 2.430499811424252
85th percentile: 10
*/

Compatibility Notice: Version 2.0.0+ of this library use features that require Node.js v4.0.0 and above

API

All of the exported functions take vals which is an array of numeric values. Non-numeric values will be removed, and string numbers will be converted to Numbers.

NOTE: This will impact some operations, e.g. mean([null, 1, 2, 3]) will be calculated as mean([1, 2, 3]), (e.g. 6 / 3 = 2, NOT 6 / 4 = 1.5)

numbers(vals)

Accepts an array of values and returns an array consisting of only numeric values from the source array. Converts what it can and filters out anything else. e.g.

numbers(["cat", 1, "22.9", 9])
// [1, 22.9, 9]

sum(vals)

Sum the values in the array.

mean(vals)

Calculate the mean average value of vals.

median(vals)

Calculate the median average value of vals.

mode(vals)

Calculate the mode average value of vals.

If vals is multi-modal (contains multiple modes), mode(vals) will return a ES6 Set of the modes.

variance(vals)

Calculate the variance from the mean.

stdev(vals)

Calculate the standard deviation of the values from the mean.

percentile(vals, ptile)

Calculate the value representing the desired percentile (0 < ptile <= 1). Uses the Estimation method to interpolate non-member percentiles.

LICENSE

MIT

Keywords

FAQs

Package last updated on 18 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc