stats-lite
Advanced tools
Comparing version 2.1.1 to 2.2.0
{ | ||
"name": "stats-lite", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "A light statistical package that operates on numeric Arrays.", | ||
@@ -5,0 +5,0 @@ "main": "stats.js", |
@@ -35,14 +35,16 @@ stats-lite | ||
console.log("standard deviation: %s", stats.stdev(rolls)) | ||
console.log("sample standard deviation: %s", stats.sampleStdev(rolls)) | ||
console.log("85th percentile: %s", stats.percentile(rolls, 0.85)) | ||
console.log("histogram:", stats.histogram(rolls)) | ||
console.log("histogram:", stats.histogram(rolls, 10)) | ||
/* Your exact numbers may vary, but they should be pretty similar: | ||
sum: 21006 | ||
mean: 7.002 | ||
sum: 21041 | ||
mean: 7.0136666666666665 | ||
median: 7 | ||
mode: 7 | ||
variance: 5.907329333333325 | ||
standard deviation: 2.430499811424252 | ||
variance: 5.8568132222220415 | ||
standard deviation: 2.4200853749861886 | ||
sample standard deviation: 2.4204888234135953 | ||
85th percentile: 10 | ||
histogram { values: [ 86, 159, 253, 335, 907, 405, 339, 270, 146, 100 ], | ||
histogram { values: [ 94, 163, 212, 357, 925, 406, 330, 264, 164, 85 ], | ||
bins: 10, | ||
@@ -99,3 +101,3 @@ binWidth: 1.05, | ||
Calculate the [variance](http://en.wikipedia.org/wiki/Variance) from the mean. | ||
Calculate the [variance](http://en.wikipedia.org/wiki/Variance) from the mean for a population. | ||
@@ -105,4 +107,15 @@ `stdev(vals)` | ||
Calculate the [standard deviation](http://en.wikipedia.org/wiki/Standard_deviation) of the values from the mean. | ||
Calculate the [standard deviation](http://en.wikipedia.org/wiki/Standard_deviation) of the values from the mean for a population. | ||
`sampleVariance(vals)` | ||
--- | ||
Calculate the [variance](http://en.wikipedia.org/wiki/Variance) from the mean for a sample. | ||
`sampleStdev(vals)` | ||
--- | ||
Calculate the [standard deviation](http://en.wikipedia.org/wiki/Standard_deviation) of the values from the mean for a sample. | ||
`percentile(vals, ptile)` | ||
@@ -109,0 +122,0 @@ --- |
41
stats.js
@@ -8,4 +8,8 @@ "use strict"; | ||
module.exports.mode = mode | ||
module.exports.variance = variance | ||
module.exports.stdev = stdev | ||
module.exports.variance = populationVariance | ||
module.exports.sampleVariance = sampleVariance | ||
module.exports.populationVariance = populationVariance | ||
module.exports.stdev = populationStdev | ||
module.exports.sampleStdev = sampleStdev | ||
module.exports.populationStdev = populationStdev | ||
module.exports.percentile = percentile | ||
@@ -102,4 +106,6 @@ module.exports.histogram = histogram | ||
// Variance = average squared deviation from mean | ||
function variance(vals) { | ||
// This helper finds the mean of all the values, then squares the difference | ||
// from the mean for each value and returns the resulting array. This is the | ||
// core of the varience functions - the difference being dividing by N or N-1. | ||
function valuesMinusMeanSquared(vals) { | ||
vals = numbers(vals) | ||
@@ -111,10 +117,29 @@ var avg = mean(vals) | ||
} | ||
return mean(diffs) | ||
return diffs | ||
} | ||
// Standard Deviation = sqrt of variance | ||
function stdev(vals) { | ||
return Math.sqrt(variance(vals)) | ||
// Population Variance = average squared deviation from mean | ||
function populationVariance(vals) { | ||
return mean(valuesMinusMeanSquared(vals)) | ||
} | ||
// Sample Variance | ||
function sampleVariance(vals) { | ||
var diffs = valuesMinusMeanSquared(vals) | ||
if (diffs.length <= 1) return NaN | ||
return sum(diffs) / (diffs.length - 1) | ||
} | ||
// Population Standard Deviation = sqrt of population variance | ||
function populationStdev(vals) { | ||
return Math.sqrt(populationVariance(vals)) | ||
} | ||
// Sample Standard Deviation = sqrt of sample variance | ||
function sampleStdev(vals) { | ||
return Math.sqrt(sampleVariance(vals)) | ||
} | ||
function percentile(vals, ptile) { | ||
@@ -121,0 +146,0 @@ vals = numbers(vals) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11311
182
141