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

simple-statistics

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-statistics - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

2

bower.json
{
"name": "simple-statistics",
"version": "2.0.0",
"version": "4.0.0",
"description": "Simple Statistics",

@@ -5,0 +5,0 @@ "repo": "simple-statistics/simple-statistics",

@@ -0,1 +1,32 @@

# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="4.0.0"></a>
# [4.0.0](https://github.com/simple-statistics/simple-statistics/compare/v3.0.0...v4.0.0) (2017-04-25)
### Bug Fixes
* Remove mixin method ([#215](https://github.com/simple-statistics/simple-statistics/issues/215)) ([85036e2](https://github.com/simple-statistics/simple-statistics/commit/85036e2)), closes [#211](https://github.com/simple-statistics/simple-statistics/issues/211)
### Performance Improvements
* **binomialDistribution:** avoid expensive factorial calculations ([#205](https://github.com/simple-statistics/simple-statistics/issues/205)) ([525f9c0](https://github.com/simple-statistics/simple-statistics/commit/525f9c0))
* **core:** Improve performance of min, max, sumNthPowerDeviations, variance, sampleVariance ([#195](https://github.com/simple-statistics/simple-statistics/issues/195)) ([9d2569a](https://github.com/simple-statistics/simple-statistics/commit/9d2569a))
* **distributions:** return array instead of object ([#209](https://github.com/simple-statistics/simple-statistics/issues/209)) ([6c5df5f](https://github.com/simple-statistics/simple-statistics/commit/6c5df5f))
* **poissonDistribution:** avoid expensive factorial calculation ([#206](https://github.com/simple-statistics/simple-statistics/issues/206)) ([b34aceb](https://github.com/simple-statistics/simple-statistics/commit/b34aceb))
* **poissonDistribution:** use Math.exp instead of Math.pow ([#208](https://github.com/simple-statistics/simple-statistics/issues/208)) ([6491dfa](https://github.com/simple-statistics/simple-statistics/commit/6491dfa))
* **sampleSkewness:** Improve sampleSkewness performance ([#197](https://github.com/simple-statistics/simple-statistics/issues/197)) ([03d37eb](https://github.com/simple-statistics/simple-statistics/commit/03d37eb))
* **sum:** Switch from Kahan to Kahan-Babuska algorithm ([1b42d7f](https://github.com/simple-statistics/simple-statistics/commit/1b42d7f))
### BREAKING CHANGES
* Removes .mixin(). Instead use simple-statistics in a functional style.
* **distributions:** The return value of bernoulliDistribution, binomialDistribution, and poissonDistribution is no longer an Object with number keys, it is now an Array of numbers.
<a name="3.0.0"></a>

@@ -2,0 +33,0 @@ # [3.0.0](https://github.com/simple-statistics/simple-statistics/compare/v2.5.0...v3.0.0) (2017-04-06)

@@ -1,2 +0,2 @@

!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r;r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,r.ss=t()}}(function(){return function t(r,n,e){function o(a,u){if(!n[a]){if(!r[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(i)return i(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[a]={exports:{}};r[a][0].call(c.exports,function(t){var n=r[a][1][t];return o(n||t)},c,c.exports,t,r,n,e)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<e.length;a++)o(e[a]);return o}({1:[function(t,r,n){"use strict";var e=r.exports={};e.linearRegression=t(24),e.linearRegressionLine=t(25),e.standardDeviation=t(59),e.rSquared=t(47),e.mode=t(35),e.modeFast=t(36),e.modeSorted=t(37),e.min=t(32),e.max=t(26),e.minSorted=t(33),e.maxSorted=t(27),e.sum=t(62),e.sumSimple=t(64),e.product=t(43),e.quantile=t(44),e.quantileSorted=t(45),e.iqr=e.interquartileRange=t(22),e.medianAbsoluteDeviation=e.mad=t(30),e.chunk=t(9),e.sampleWithReplacement=t(55),e.shuffle=t(56),e.shuffleInPlace=t(57),e.sample=t(49),e.ckmeans=t(10),e.uniqueCountSorted=t(67),e.sumNthPowerDeviations=t(63),e.equalIntervalBreaks=t(17),e.sampleCovariance=t(51),e.sampleCorrelation=t(50),e.sampleVariance=t(54),e.sampleStandardDeviation=t(53),e.sampleSkewness=t(52),e.permutationsHeap=t(40),e.combinations=t(11),e.combinationsReplacement=t(12),e.addToMean=t(2),e.combineMeans=t(13),e.combineVariances=t(14),e.geometricMean=t(20),e.harmonicMean=t(21),e.mean=e.average=t(28),e.median=t(29),e.medianSorted=t(31),e.subtractFromMean=t(61),e.rootMeanSquare=e.rms=t(48),e.variance=t(68),e.tTest=t(65),e.tTestTwoSample=t(66),e.bayesian=t(3),e.perceptron=t(39),e.epsilon=t(16),e.factorial=t(19),e.bernoulliDistribution=t(4),e.binomialDistribution=t(5),e.poissonDistribution=t(41),e.chiSquaredGoodnessOfFit=t(8),e.zScore=t(69),e.cumulativeStdNormalProbability=t(15),e.standardNormalTable=t(60),e.errorFunction=e.erf=t(18),e.inverseErrorFunction=t(23),e.probit=t(42),e.mixin=t(34),e.bisect=t(6)},{10:10,11:11,12:12,13:13,14:14,15:15,16:16,17:17,18:18,19:19,2:2,20:20,21:21,22:22,23:23,24:24,25:25,26:26,27:27,28:28,29:29,3:3,30:30,31:31,32:32,33:33,34:34,35:35,36:36,37:37,39:39,4:4,40:40,41:41,42:42,43:43,44:44,45:45,47:47,48:48,49:49,5:5,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:59,6:6,60:60,61:61,62:62,63:63,64:64,65:65,66:66,67:67,68:68,69:69,8:8,9:9}],2:[function(t,r,n){"use strict";function e(t,r,n){return t+(n-t)/(r+1)}r.exports=e},{}],3:[function(t,r,n){"use strict";function e(){this.totalCount=0,this.data={}}e.prototype.train=function(t,r){this.data[r]||(this.data[r]={});for(var n in t){var e=t[n];void 0===this.data[r][n]&&(this.data[r][n]={}),void 0===this.data[r][n][e]&&(this.data[r][n][e]=0),this.data[r][n][e]++}this.totalCount++},e.prototype.score=function(t){var r,n={};for(var e in t){var o=t[e];for(r in this.data)n[r]={},this.data[r][e]?n[r][e+"_"+o]=(this.data[r][e][o]||0)/this.totalCount:n[r][e+"_"+o]=0}var i={};for(r in n){i[r]=0;for(var a in n[r])i[r]+=n[r][a]}return i},r.exports=e},{}],4:[function(t,r,n){"use strict";function e(t){if(t<0||t>1)throw new Error("bernoulliDistribution requires probability to be between 0 and 1 inclusive");return o(1,t)}var o=t(5);r.exports=e},{5:5}],5:[function(t,r,n){"use strict";function e(t,r){if(!(r<0||r>1||t<=0||t%1!=0)){var n=0,e=0,a={};do{a[n]=i(t)/(i(n)*i(t-n))*(Math.pow(r,n)*Math.pow(1-r,t-n)),e+=a[n],n++}while(e<1-o);return a}}var o=t(16),i=t(19);r.exports=e},{16:16,19:19}],6:[function(t,r,n){"use strict";function e(t,r,n,e,i){if("function"!=typeof t)throw new TypeError("func must be a function");for(var a=0;a<e;a++){var u=(r+n)/2;if(0===t(u)||Math.abs((n-r)/2)<i)return u;o(t(u))===o(t(r))?r=u:n=u}throw new Error("maximum number of iterations exceeded")}var o=t(58);r.exports=e},{58:58}],7:[function(t,r,n){"use strict";var e={1:{.995:0,.99:0,.975:0,.95:0,.9:.02,.5:.45,.1:2.71,.05:3.84,.025:5.02,.01:6.63,.005:7.88},2:{.995:.01,.99:.02,.975:.05,.95:.1,.9:.21,.5:1.39,.1:4.61,.05:5.99,.025:7.38,.01:9.21,.005:10.6},3:{.995:.07,.99:.11,.975:.22,.95:.35,.9:.58,.5:2.37,.1:6.25,.05:7.81,.025:9.35,.01:11.34,.005:12.84},4:{.995:.21,.99:.3,.975:.48,.95:.71,.9:1.06,.5:3.36,.1:7.78,.05:9.49,.025:11.14,.01:13.28,.005:14.86},5:{.995:.41,.99:.55,.975:.83,.95:1.15,.9:1.61,.5:4.35,.1:9.24,.05:11.07,.025:12.83,.01:15.09,.005:16.75},6:{.995:.68,.99:.87,.975:1.24,.95:1.64,.9:2.2,.5:5.35,.1:10.65,.05:12.59,.025:14.45,.01:16.81,.005:18.55},7:{.995:.99,.99:1.25,.975:1.69,.95:2.17,.9:2.83,.5:6.35,.1:12.02,.05:14.07,.025:16.01,.01:18.48,.005:20.28},8:{.995:1.34,.99:1.65,.975:2.18,.95:2.73,.9:3.49,.5:7.34,.1:13.36,.05:15.51,.025:17.53,.01:20.09,.005:21.96},9:{.995:1.73,.99:2.09,.975:2.7,.95:3.33,.9:4.17,.5:8.34,.1:14.68,.05:16.92,.025:19.02,.01:21.67,.005:23.59},10:{.995:2.16,.99:2.56,.975:3.25,.95:3.94,.9:4.87,.5:9.34,.1:15.99,.05:18.31,.025:20.48,.01:23.21,.005:25.19},11:{.995:2.6,.99:3.05,.975:3.82,.95:4.57,.9:5.58,.5:10.34,.1:17.28,.05:19.68,.025:21.92,.01:24.72,.005:26.76},12:{.995:3.07,.99:3.57,.975:4.4,.95:5.23,.9:6.3,.5:11.34,.1:18.55,.05:21.03,.025:23.34,.01:26.22,.005:28.3},13:{.995:3.57,.99:4.11,.975:5.01,.95:5.89,.9:7.04,.5:12.34,.1:19.81,.05:22.36,.025:24.74,.01:27.69,.005:29.82},14:{.995:4.07,.99:4.66,.975:5.63,.95:6.57,.9:7.79,.5:13.34,.1:21.06,.05:23.68,.025:26.12,.01:29.14,.005:31.32},15:{.995:4.6,.99:5.23,.975:6.27,.95:7.26,.9:8.55,.5:14.34,.1:22.31,.05:25,.025:27.49,.01:30.58,.005:32.8},16:{.995:5.14,.99:5.81,.975:6.91,.95:7.96,.9:9.31,.5:15.34,.1:23.54,.05:26.3,.025:28.85,.01:32,.005:34.27},17:{.995:5.7,.99:6.41,.975:7.56,.95:8.67,.9:10.09,.5:16.34,.1:24.77,.05:27.59,.025:30.19,.01:33.41,.005:35.72},18:{.995:6.26,.99:7.01,.975:8.23,.95:9.39,.9:10.87,.5:17.34,.1:25.99,.05:28.87,.025:31.53,.01:34.81,.005:37.16},19:{.995:6.84,.99:7.63,.975:8.91,.95:10.12,.9:11.65,.5:18.34,.1:27.2,.05:30.14,.025:32.85,.01:36.19,.005:38.58},20:{.995:7.43,.99:8.26,.975:9.59,.95:10.85,.9:12.44,.5:19.34,.1:28.41,.05:31.41,.025:34.17,.01:37.57,.005:40},21:{.995:8.03,.99:8.9,.975:10.28,.95:11.59,.9:13.24,.5:20.34,.1:29.62,.05:32.67,.025:35.48,.01:38.93,.005:41.4},22:{.995:8.64,.99:9.54,.975:10.98,.95:12.34,.9:14.04,.5:21.34,.1:30.81,.05:33.92,.025:36.78,.01:40.29,.005:42.8},23:{.995:9.26,.99:10.2,.975:11.69,.95:13.09,.9:14.85,.5:22.34,.1:32.01,.05:35.17,.025:38.08,.01:41.64,.005:44.18},24:{.995:9.89,.99:10.86,.975:12.4,.95:13.85,.9:15.66,.5:23.34,.1:33.2,.05:36.42,.025:39.36,.01:42.98,.005:45.56},25:{.995:10.52,.99:11.52,.975:13.12,.95:14.61,.9:16.47,.5:24.34,.1:34.28,.05:37.65,.025:40.65,.01:44.31,.005:46.93},26:{.995:11.16,.99:12.2,.975:13.84,.95:15.38,.9:17.29,.5:25.34,.1:35.56,.05:38.89,.025:41.92,.01:45.64,.005:48.29},27:{.995:11.81,.99:12.88,.975:14.57,.95:16.15,.9:18.11,.5:26.34,.1:36.74,.05:40.11,.025:43.19,.01:46.96,.005:49.65},28:{.995:12.46,.99:13.57,.975:15.31,.95:16.93,.9:18.94,.5:27.34,.1:37.92,.05:41.34,.025:44.46,.01:48.28,.005:50.99},29:{.995:13.12,.99:14.26,.975:16.05,.95:17.71,.9:19.77,.5:28.34,.1:39.09,.05:42.56,.025:45.72,.01:49.59,.005:52.34},30:{.995:13.79,.99:14.95,.975:16.79,.95:18.49,.9:20.6,.5:29.34,.1:40.26,.05:43.77,.025:46.98,.01:50.89,.005:53.67},40:{.995:20.71,.99:22.16,.975:24.43,.95:26.51,.9:29.05,.5:39.34,.1:51.81,.05:55.76,.025:59.34,.01:63.69,.005:66.77},50:{.995:27.99,.99:29.71,.975:32.36,.95:34.76,.9:37.69,.5:49.33,.1:63.17,.05:67.5,.025:71.42,.01:76.15,.005:79.49},60:{.995:35.53,.99:37.48,.975:40.48,.95:43.19,.9:46.46,.5:59.33,.1:74.4,.05:79.08,.025:83.3,.01:88.38,.005:91.95},70:{.995:43.28,.99:45.44,.975:48.76,.95:51.74,.9:55.33,.5:69.33,.1:85.53,.05:90.53,.025:95.02,.01:100.42,.005:104.22},80:{.995:51.17,.99:53.54,.975:57.15,.95:60.39,.9:64.28,.5:79.33,.1:96.58,.05:101.88,.025:106.63,.01:112.33,.005:116.32},90:{.995:59.2,.99:61.75,.975:65.65,.95:69.13,.9:73.29,.5:89.33,.1:107.57,.05:113.14,.025:118.14,.01:124.12,.005:128.3},100:{.995:67.33,.99:70.06,.975:74.22,.95:77.93,.9:82.36,.5:99.33,.1:118.5,.05:124.34,.025:129.56,.01:135.81,.005:140.17}};r.exports=e},{}],8:[function(t,r,n){"use strict";function e(t,r,n){for(var e,a,u=o(t),s=0,f=r(u),c=[],h=[],l=0;l<t.length;l++)void 0===c[t[l]]&&(c[t[l]]=0),c[t[l]]++;for(l=0;l<c.length;l++)void 0===c[l]&&(c[l]=0);for(a in f)a in c&&(h[+a]=f[a]*t.length);for(a=h.length-1;a>=0;a--)h[a]<3&&(h[a-1]+=h[a],h.pop(),c[a-1]+=c[a],c.pop());for(a=0;a<c.length;a++)s+=Math.pow(c[a]-h[a],2)/h[a];return e=c.length-1-1,i[e][n]<s}var o=t(28),i=t(7);r.exports=e},{28:28,7:7}],9:[function(t,r,n){"use strict";function e(t,r){var n=[];if(r<1)throw new Error("chunk size must be a positive number");if(Math.floor(r)!==r)throw new Error("chunk size must be an integer");for(var e=0;e<t.length;e+=r)n.push(t.slice(e,e+r));return n}r.exports=e},{}],10:[function(t,r,n){"use strict";function e(t,r){for(var n=[],e=0;e<t;e++){for(var o=[],i=0;i<r;i++)o.push(0);n.push(o)}return n}function o(t,r,n,e){var o;if(t>0){var i=(n[r]-n[t-1])/(r-t+1);o=e[r]-e[t-1]-(r-t+1)*i*i}else o=e[r]-n[r]*n[r]/(r+1);return o<0?0:o}function i(t,r,n,e,a,u,s){if(!(t>r)){var f=Math.floor((t+r)/2);e[n][f]=e[n-1][f-1],a[n][f]=f;var c=n;t>n&&(c=Math.max(c,a[n][t-1]||0)),c=Math.max(c,a[n-1][f]||0);var h=f-1;r<e.length-1&&(h=Math.min(h,a[n][r+1]||0));for(var l,p,v,g,w=h;w>=c&&!((l=o(w,f,u,s))+e[n-1][c-1]>=e[n][f]);--w)p=o(c,f,u,s),v=p+e[n-1][c-1],v<e[n][f]&&(e[n][f]=v,a[n][f]=c),c++,(g=l+e[n-1][w-1])<e[n][f]&&(e[n][f]=g,a[n][f]=w);i(t,f-1,n,e,a,u,s),i(f+1,r,n,e,a,u,s)}}function a(t,r,n){for(var e,a=r[0].length,u=t[Math.floor(a/2)],s=[],f=[],c=0;c<a;++c)e=t[c]-u,0===c?(s.push(e),f.push(e*e)):(s.push(s[c-1]+e),f.push(f[c-1]+e*e)),r[0][c]=o(0,c,s,f),n[0][c]=0;for(var h,l=1;l<r.length;++l)h=l<r.length-1?l:a-1,i(h,a-1,l,r,n,s,f)}function u(t,r){if(r>t.length)throw new Error("cannot generate more classes than there are data values");var n=f(t);if(1===s(n))return[n];var o=e(r,n.length),i=e(r,n.length);a(n,o,i);for(var u=[],c=i[0].length-1,h=i.length-1;h>=0;h--){var l=i[h][c];u[h]=n.slice(l,c+1),h>0&&(c=l-1)}return u}var s=t(67),f=t(38);r.exports=u},{38:38,67:67}],11:[function(t,r,n){"use strict";function e(t,r){var n,o,i,a,u=[];for(n=0;n<t.length;n++)if(1===r)u.push([t[n]]);else for(i=e(t.slice(n+1,t.length),r-1),o=0;o<i.length;o++)a=i[o],a.unshift(t[n]),u.push(a);return u}r.exports=e},{}],12:[function(t,r,n){"use strict";function e(t,r){for(var n=[],o=0;o<t.length;o++)if(1===r)n.push([t[o]]);else for(var i=e(t.slice(o,t.length),r-1),a=0;a<i.length;a++)n.push([t[o]].concat(i[a]));return n}r.exports=e},{}],13:[function(t,r,n){"use strict";function e(t,r,n,e){return(t*r+n*e)/(r+e)}r.exports=e},{}],14:[function(t,r,n){"use strict";function e(t,r,n,e,i,a){var u=o(r,n,i,a);return(n*(t+Math.pow(r-u,2))+a*(e+Math.pow(i-u,2)))/(n+a)}var o=t(13);r.exports=e},{13:13}],15:[function(t,r,n){"use strict";function e(t){var r=Math.abs(t),n=Math.min(Math.round(100*r),o.length-1);return t>=0?o[n]:+(1-o[n]).toFixed(4)}var o=t(60);r.exports=e},{60:60}],16:[function(t,r,n){"use strict";r.exports=1e-4},{}],17:[function(t,r,n){"use strict";function e(t,r){if(t.length<2)return t;for(var n=i(t),e=o(t),a=[n],u=(e-n)/r,s=1;s<r;s++)a.push(a[0]+u*s);return a.push(e),a}var o=t(26),i=t(32);r.exports=e},{26:26,32:32}],18:[function(t,r,n){"use strict";function e(t){var r=1/(1+.5*Math.abs(t)),n=r*Math.exp(-Math.pow(t,2)-1.26551223+1.00002368*r+.37409196*Math.pow(r,2)+.09678418*Math.pow(r,3)-.18628806*Math.pow(r,4)+.27886807*Math.pow(r,5)-1.13520398*Math.pow(r,6)+1.48851587*Math.pow(r,7)-.82215223*Math.pow(r,8)+.17087277*Math.pow(r,9));return t>=0?1-n:n-1}r.exports=e},{}],19:[function(t,r,n){"use strict";function e(t){if(t<0)throw new Error("factorial requires an integer input");if(Math.floor(t)!==t)throw new Error("factorial requires a non-negative value");for(var r=1,n=2;n<=t;n++)r*=n;return r}r.exports=e},{}],20:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("geometricMean requires at least one data point");for(var r=1,n=0;n<t.length;n++){if(t[n]<=0)throw new Error("geometricMean requires only positive numbers as input");r*=t[n]}return Math.pow(r,1/t.length)}r.exports=e},{}],21:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("harmonicMean requires at least one data point");for(var r=0,n=0;n<t.length;n++){if(t[n]<=0)throw new Error("harmonicMean requires only positive numbers as input");r+=1/t[n]}return t.length/r}r.exports=e},{}],22:[function(t,r,n){"use strict";function e(t){var r=o(t,.75),n=o(t,.25);if("number"==typeof r&&"number"==typeof n)return r-n}var o=t(44);r.exports=e},{44:44}],23:[function(t,r,n){"use strict";function e(t){var r=8*(Math.PI-3)/(3*Math.PI*(4-Math.PI)),n=Math.sqrt(Math.sqrt(Math.pow(2/(Math.PI*r)+Math.log(1-t*t)/2,2)-Math.log(1-t*t)/r)-(2/(Math.PI*r)+Math.log(1-t*t)/2));return t>=0?n:-n}r.exports=e},{}],24:[function(t,r,n){"use strict";function e(t){var r,n,e=t.length;if(1===e)r=0,n=t[0][1];else{for(var o,i,a,u=0,s=0,f=0,c=0,h=0;h<e;h++)o=t[h],i=o[0],a=o[1],u+=i,s+=a,f+=i*i,c+=i*a;r=(e*c-u*s)/(e*f-u*u),n=s/e-r*u/e}return{m:r,b:n}}r.exports=e},{}],25:[function(t,r,n){"use strict";function e(t){return function(r){return t.b+t.m*r}}r.exports=e},{}],26:[function(t,r,n){"use strict";function e(t){for(var r,n=0;n<t.length;n++)(void 0===r||t[n]>r)&&(r=t[n]);if(void 0===r)throw new Error("max requires at least one data point");return r}r.exports=e},{}],27:[function(t,r,n){"use strict";function e(t){return t[t.length-1]}r.exports=e},{}],28:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("mean requires at least one data point");return o(t)/t.length}var o=t(62);r.exports=e},{62:62}],29:[function(t,r,n){"use strict";function e(t){return+o(t,.5)}var o=t(44);r.exports=e},{44:44}],30:[function(t,r,n){"use strict";function e(t){for(var r=o(t),n=[],e=0;e<t.length;e++)n.push(Math.abs(t[e]-r));return o(n)}var o=t(29);r.exports=e},{29:29}],31:[function(t,r,n){"use strict";function e(t){return o(t,.5)}var o=t(45);r.exports=e},{45:45}],32:[function(t,r,n){"use strict";function e(t){for(var r,n=0;n<t.length;n++)(void 0===r||t[n]<r)&&(r=t[n]);if(void 0===r)throw new Error("min requires at least one data point");return r}r.exports=e},{}],33:[function(t,r,n){"use strict";function e(t){return t[0]}r.exports=e},{}],34:[function(t,r,n){"use strict";function e(t,r){if(!Object.defineProperty||!Object.defineProperties)throw new Error("without defineProperty, simple-statistics cannot be mixed in");var n,e=["median","standardDeviation","sum","product","sampleSkewness","mean","min","max","quantile","geometricMean","harmonicMean","root_mean_square"];n=r?r.slice():Array.prototype;for(var o=0;o<e.length;o++)Object.defineProperty(n,e[o],{value:function(r){return function(){var n=Array.prototype.slice.apply(arguments);return n.unshift(this),t[r].apply(t,n)}}(e[o]),configurable:!0,enumerable:!1,writable:!0});return n}r.exports=e},{}],35:[function(t,r,n){"use strict";function e(t){return i(o(t))}var o=t(38),i=t(37);r.exports=e},{37:37,38:38}],36:[function(t,r,n){"use strict";function e(t){for(var r,n=new Map,e=0,o=0;o<t.length;o++){var i=n.get(t[o]);void 0===i?i=1:i++,i>e&&(r=t[o],e=i),n.set(t[o],i)}if(0===e)throw new Error("mode requires at last one data point");return r}r.exports=e},{}],37:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("mode requires at least one data point");if(1===t.length)return t[0];for(var r=t[0],n=NaN,e=0,o=1,i=1;i<t.length+1;i++)t[i]!==r?(o>e&&(e=o,n=r),o=1,r=t[i]):o++;return n}r.exports=e},{}],38:[function(t,r,n){"use strict";function e(t){return t.slice().sort(function(t,r){return t-r})}r.exports=e},{}],39:[function(t,r,n){"use strict";function e(){this.weights=[],this.bias=0}e.prototype.predict=function(t){if(t.length!==this.weights.length)return null;for(var r=0,n=0;n<this.weights.length;n++)r+=this.weights[n]*t[n];return r+=this.bias,r>0?1:0},e.prototype.train=function(t,r){if(0!==r&&1!==r)return null;t.length!==this.weights.length&&(this.weights=t,this.bias=1);var n=this.predict(t);if(n!==r){for(var e=r-n,o=0;o<this.weights.length;o++)this.weights[o]+=e*t[o];this.bias+=e}return this},r.exports=e},{}],40:[function(t,r,n){"use strict";function e(t){for(var r=new Array(t.length),n=[t.slice()],e=0;e<t.length;e++)r[e]=0;for(e=0;e<t.length;)if(r[e]<e){var o=0;e%2!=0&&(o=r[e]);var i=t[o];t[o]=t[e],t[e]=i,n.push(t.slice()),r[e]++,e=0}else r[e]=0,e++;return n}r.exports=e},{}],41:[function(t,r,n){"use strict";function e(t){if(!(t<=0)){var r=0,n=0,e={};do{e[r]=Math.pow(Math.E,-t)*Math.pow(t,r)/i(r),n+=e[r],r++}while(n<1-o);return e}}var o=t(16),i=t(19);r.exports=e},{16:16,19:19}],42:[function(t,r,n){"use strict";function e(t){return 0===t?t=o:t>=1&&(t=1-o),Math.sqrt(2)*i(2*t-1)}var o=t(16),i=t(23);r.exports=e},{16:16,23:23}],43:[function(t,r,n){"use strict";function e(t){for(var r=1,n=0;n<t.length;n++)r*=t[n];return r}r.exports=e},{}],44:[function(t,r,n){"use strict";function e(t,r){var n=t.slice();if(Array.isArray(r)){i(n,r);for(var e=[],a=0;a<r.length;a++)e[a]=s(n,r[a]);return e}return o(n,u(n.length,r),0,n.length-1),s(n,r)}function o(t,r,n,e){r%1==0?f(t,r,n,e):(r=Math.floor(r),f(t,r,n,e),f(t,r+1,r+1,e))}function i(t,r){for(var n=[0],e=0;e<r.length;e++)n.push(u(t.length,r[e]));n.push(t.length-1),n.sort(a);for(var i=[0,n.length-1];i.length;){var s=Math.ceil(i.pop()),f=Math.floor(i.pop());if(!(s-f<=1)){var c=Math.floor((f+s)/2);o(t,n[c],n[f],n[s]),i.push(f,c,c,s)}}}function a(t,r){return t-r}function u(t,r){var n=t*r;return 1===r?t-1:0===r?0:n%1!=0?Math.ceil(n)-1:t%2==0?n-.5:n}var s=t(45),f=t(46);r.exports=e},{45:45,46:46}],45:[function(t,r,n){"use strict";function e(t,r){var n=t.length*r;if(0===t.length)throw new Error("quantile requires at least one data point.");if(r<0||r>1)throw new Error("quantiles must be between 0 and 1");return 1===r?t[t.length-1]:0===r?t[0]:n%1!=0?t[Math.ceil(n)-1]:t.length%2==0?(t[n-1]+t[n])/2:t[n]}r.exports=e},{}],46:[function(t,r,n){"use strict";function e(t,r,n,i){for(n=n||0,i=i||t.length-1;i>n;){if(i-n>600){var a=i-n+1,u=r-n+1,s=Math.log(a),f=.5*Math.exp(2*s/3),c=.5*Math.sqrt(s*f*(a-f)/a);u-a/2<0&&(c*=-1);e(t,r,Math.max(n,Math.floor(r-u*f/a+c)),Math.min(i,Math.floor(r+(a-u)*f/a+c)))}var h=t[r],l=n,p=i;for(o(t,n,r),t[i]>h&&o(t,n,i);l<p;){for(o(t,l,p),l++,p--;t[l]<h;)l++;for(;t[p]>h;)p--}t[n]===h?o(t,n,p):(p++,o(t,p,i)),p<=r&&(n=p+1),r<=p&&(i=p-1)}}function o(t,r,n){var e=t[r];t[r]=t[n],t[n]=e}r.exports=e},{}],47:[function(t,r,n){"use strict";function e(t,r){if(t.length<2)return 1;for(var n,e=0,o=0;o<t.length;o++)e+=t[o][1];n=e/t.length;for(var i=0,a=0;a<t.length;a++)i+=Math.pow(n-t[a][1],2);for(var u=0,s=0;s<t.length;s++)u+=Math.pow(t[s][1]-r(t[s][0]),2);return 1-u/i}r.exports=e},{}],48:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("rootMeanSquare requires at least one data point");for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n],2);return Math.sqrt(r/t.length)}r.exports=e},{}],49:[function(t,r,n){"use strict";function e(t,r,n){return o(t,n).slice(0,r)}var o=t(56);r.exports=e},{56:56}],50:[function(t,r,n){"use strict";function e(t,r){return o(t,r)/i(t)/i(r)}var o=t(51),i=t(53);r.exports=e},{51:51,53:53}],51:[function(t,r,n){"use strict";function e(t,r){if(t.length!==r.length)throw new Error("sampleCovariance requires samples with equal lengths");if(t.length<2)throw new Error("sampleCovariance requires at least two data points in each sample");for(var n=o(t),e=o(r),i=0,a=0;a<t.length;a++)i+=(t[a]-n)*(r[a]-e);return i/(t.length-1)}var o=t(28);r.exports=e},{28:28}],52:[function(t,r,n){"use strict";function e(t){var r=i(t);if(t.length<3)throw new Error("sampleSkewness requires at least three data points");var n=t.length,e=Math.pow(r,3);return n*o(t,3)/((n-1)*(n-2)*e)}var o=t(63),i=t(53);r.exports=e},{53:53,63:63}],53:[function(t,r,n){"use strict";function e(t){var r=o(t);return Math.sqrt(r)}var o=t(54);r.exports=e},{54:54}],54:[function(t,r,n){"use strict";function e(t){if(t.length<2)throw new Error("sampleVariance requires at least two data points");return o(t,2)/(t.length-1)}var o=t(63);r.exports=e},{63:63}],55:[function(t,r,n){"use strict";function e(t,r,n){if(0===t.length)return[];n=n||Math.random;for(var e=t.length,o=[],i=0;i<r;i++){var a=Math.floor(n()*e);o.push(t[a])}return o}r.exports=e},{}],56:[function(t,r,n){"use strict";function e(t,r){var n=t.slice();return o(n.slice(),r)}var o=t(57);r.exports=e},{57:57}],57:[function(t,r,n){"use strict";function e(t,r){r=r||Math.random;for(var n,e,o=t.length;o>0;)e=Math.floor(r()*o--),n=t[o],t[o]=t[e],t[e]=n;return t}r.exports=e},{}],58:[function(t,r,n){"use strict";function e(t){if("number"==typeof t)return t<0?-1:0===t?0:1;throw new TypeError("not a number")}r.exports=e},{}],59:[function(t,r,n){"use strict";function e(t){if(1===t.length)return 0;var r=o(t);return Math.sqrt(r)}var o=t(68);r.exports=e},{68:68}],60:[function(t,r,n){"use strict";for(var e=Math.sqrt(2*Math.PI),o=[],i=0;i<=3.09;i+=.01)o.push(function(t){for(var r=t,n=t,o=1;o<15;o++)n*=t*t/(2*o+1),r+=n;return Math.round(1e4*(.5+r/e*Math.exp(-t*t/2)))/1e4}(i));r.exports=o},{}],61:[function(t,r,n){"use strict";function e(t,r,n){return(t*r-n)/(r-1)}r.exports=e},{}],62:[function(t,r,n){"use strict";function e(t){for(var r,n,e=0,o=0,i=0;i<t.length;i++)r=t[i]-o,n=e+r,o=n-e-r,e=n;return e}r.exports=e},{}],63:[function(t,r,n){"use strict";function e(t,r){for(var n=o(t),e=0,i=0;i<t.length;i++)e+=Math.pow(t[i]-n,r);return e}var o=t(28);r.exports=e},{28:28}],64:[function(t,r,n){"use strict";function e(t){for(var r=0,n=0;n<t.length;n++)r+=t[n];return r}r.exports=e},{}],65:[function(t,r,n){"use strict";function e(t,r){return(i(t)-r)/(o(t)/Math.sqrt(t.length))}var o=t(59),i=t(28);r.exports=e},{28:28,59:59}],66:[function(t,r,n){"use strict";function e(t,r,n){var e=t.length,a=r.length;if(!e||!a)return null;n||(n=0);var u=o(t),s=o(r),f=i(t),c=i(r);if("number"==typeof u&&"number"==typeof s&&"number"==typeof f&&"number"==typeof c){var h=((e-1)*f+(a-1)*c)/(e+a-2);return(u-s-n)/Math.sqrt(h*(1/e+1/a))}}var o=t(28),i=t(54);r.exports=e},{28:28,54:54}],67:[function(t,r,n){"use strict";function e(t){for(var r,n=0,e=0;e<t.length;e++)0!==e&&t[e]===r||(r=t[e],n++);return n}r.exports=e},{}],68:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("variance requires at least one data point");return o(t,2)/t.length}var o=t(63);r.exports=e},{63:63}],69:[function(t,r,n){"use strict";function e(t,r,n){return(t-r)/n}r.exports=e},{}]},{},[1])(1)});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r;r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,r.ss=t()}}(function(){return function t(r,n,e){function o(a,u){if(!n[a]){if(!r[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(i)return i(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[a]={exports:{}};r[a][0].call(c.exports,function(t){var n=r[a][1][t];return o(n||t)},c,c.exports,t,r,n,e)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<e.length;a++)o(e[a]);return o}({1:[function(t,r,n){"use strict";var e=r.exports={};e.linearRegression=t(24),e.linearRegressionLine=t(25),e.standardDeviation=t(58),e.rSquared=t(46),e.mode=t(34),e.modeFast=t(35),e.modeSorted=t(36),e.min=t(32),e.max=t(26),e.minSorted=t(33),e.maxSorted=t(27),e.sum=t(61),e.sumSimple=t(63),e.product=t(42),e.quantile=t(43),e.quantileSorted=t(44),e.iqr=e.interquartileRange=t(22),e.medianAbsoluteDeviation=e.mad=t(30),e.chunk=t(9),e.sampleWithReplacement=t(54),e.shuffle=t(55),e.shuffleInPlace=t(56),e.sample=t(48),e.ckmeans=t(10),e.uniqueCountSorted=t(66),e.sumNthPowerDeviations=t(62),e.equalIntervalBreaks=t(17),e.sampleCovariance=t(50),e.sampleCorrelation=t(49),e.sampleVariance=t(53),e.sampleStandardDeviation=t(52),e.sampleSkewness=t(51),e.permutationsHeap=t(39),e.combinations=t(11),e.combinationsReplacement=t(12),e.addToMean=t(2),e.combineMeans=t(13),e.combineVariances=t(14),e.geometricMean=t(20),e.harmonicMean=t(21),e.mean=e.average=t(28),e.median=t(29),e.medianSorted=t(31),e.subtractFromMean=t(60),e.rootMeanSquare=e.rms=t(47),e.variance=t(67),e.tTest=t(64),e.tTestTwoSample=t(65),e.bayesian=t(3),e.perceptron=t(38),e.epsilon=t(16),e.factorial=t(19),e.bernoulliDistribution=t(4),e.binomialDistribution=t(5),e.poissonDistribution=t(40),e.chiSquaredGoodnessOfFit=t(8),e.zScore=t(68),e.cumulativeStdNormalProbability=t(15),e.standardNormalTable=t(59),e.errorFunction=e.erf=t(18),e.inverseErrorFunction=t(23),e.probit=t(41),e.bisect=t(6)},{10:10,11:11,12:12,13:13,14:14,15:15,16:16,17:17,18:18,19:19,2:2,20:20,21:21,22:22,23:23,24:24,25:25,26:26,27:27,28:28,29:29,3:3,30:30,31:31,32:32,33:33,34:34,35:35,36:36,38:38,39:39,4:4,40:40,41:41,42:42,43:43,44:44,46:46,47:47,48:48,49:49,5:5,50:50,51:51,52:52,53:53,54:54,55:55,56:56,58:58,59:59,6:6,60:60,61:61,62:62,63:63,64:64,65:65,66:66,67:67,68:68,8:8,9:9}],2:[function(t,r,n){"use strict";function e(t,r,n){return t+(n-t)/(r+1)}r.exports=e},{}],3:[function(t,r,n){"use strict";function e(){this.totalCount=0,this.data={}}e.prototype.train=function(t,r){this.data[r]||(this.data[r]={});for(var n in t){var e=t[n];void 0===this.data[r][n]&&(this.data[r][n]={}),void 0===this.data[r][n][e]&&(this.data[r][n][e]=0),this.data[r][n][e]++}this.totalCount++},e.prototype.score=function(t){var r,n={};for(var e in t){var o=t[e];for(r in this.data)n[r]={},this.data[r][e]?n[r][e+"_"+o]=(this.data[r][e][o]||0)/this.totalCount:n[r][e+"_"+o]=0}var i={};for(r in n){i[r]=0;for(var a in n[r])i[r]+=n[r][a]}return i},r.exports=e},{}],4:[function(t,r,n){"use strict";function e(t){if(t<0||t>1)throw new Error("bernoulliDistribution requires probability to be between 0 and 1 inclusive");return[1-t,t]}r.exports=e},{}],5:[function(t,r,n){"use strict";function e(t,r){if(!(r<0||r>1||t<=0||t%1!=0)){var n=0,e=0,i=[],a=1;do{i[n]=a*Math.pow(r,n)*Math.pow(1-r,t-n),e+=i[n],n++,a=a*(t-n+1)/n}while(e<1-o);return i}}var o=t(16);r.exports=e},{16:16}],6:[function(t,r,n){"use strict";function e(t,r,n,e,i){if("function"!=typeof t)throw new TypeError("func must be a function");for(var a=0;a<e;a++){var u=(r+n)/2;if(0===t(u)||Math.abs((n-r)/2)<i)return u;o(t(u))===o(t(r))?r=u:n=u}throw new Error("maximum number of iterations exceeded")}var o=t(57);r.exports=e},{57:57}],7:[function(t,r,n){"use strict";var e={1:{.995:0,.99:0,.975:0,.95:0,.9:.02,.5:.45,.1:2.71,.05:3.84,.025:5.02,.01:6.63,.005:7.88},2:{.995:.01,.99:.02,.975:.05,.95:.1,.9:.21,.5:1.39,.1:4.61,.05:5.99,.025:7.38,.01:9.21,.005:10.6},3:{.995:.07,.99:.11,.975:.22,.95:.35,.9:.58,.5:2.37,.1:6.25,.05:7.81,.025:9.35,.01:11.34,.005:12.84},4:{.995:.21,.99:.3,.975:.48,.95:.71,.9:1.06,.5:3.36,.1:7.78,.05:9.49,.025:11.14,.01:13.28,.005:14.86},5:{.995:.41,.99:.55,.975:.83,.95:1.15,.9:1.61,.5:4.35,.1:9.24,.05:11.07,.025:12.83,.01:15.09,.005:16.75},6:{.995:.68,.99:.87,.975:1.24,.95:1.64,.9:2.2,.5:5.35,.1:10.65,.05:12.59,.025:14.45,.01:16.81,.005:18.55},7:{.995:.99,.99:1.25,.975:1.69,.95:2.17,.9:2.83,.5:6.35,.1:12.02,.05:14.07,.025:16.01,.01:18.48,.005:20.28},8:{.995:1.34,.99:1.65,.975:2.18,.95:2.73,.9:3.49,.5:7.34,.1:13.36,.05:15.51,.025:17.53,.01:20.09,.005:21.96},9:{.995:1.73,.99:2.09,.975:2.7,.95:3.33,.9:4.17,.5:8.34,.1:14.68,.05:16.92,.025:19.02,.01:21.67,.005:23.59},10:{.995:2.16,.99:2.56,.975:3.25,.95:3.94,.9:4.87,.5:9.34,.1:15.99,.05:18.31,.025:20.48,.01:23.21,.005:25.19},11:{.995:2.6,.99:3.05,.975:3.82,.95:4.57,.9:5.58,.5:10.34,.1:17.28,.05:19.68,.025:21.92,.01:24.72,.005:26.76},12:{.995:3.07,.99:3.57,.975:4.4,.95:5.23,.9:6.3,.5:11.34,.1:18.55,.05:21.03,.025:23.34,.01:26.22,.005:28.3},13:{.995:3.57,.99:4.11,.975:5.01,.95:5.89,.9:7.04,.5:12.34,.1:19.81,.05:22.36,.025:24.74,.01:27.69,.005:29.82},14:{.995:4.07,.99:4.66,.975:5.63,.95:6.57,.9:7.79,.5:13.34,.1:21.06,.05:23.68,.025:26.12,.01:29.14,.005:31.32},15:{.995:4.6,.99:5.23,.975:6.27,.95:7.26,.9:8.55,.5:14.34,.1:22.31,.05:25,.025:27.49,.01:30.58,.005:32.8},16:{.995:5.14,.99:5.81,.975:6.91,.95:7.96,.9:9.31,.5:15.34,.1:23.54,.05:26.3,.025:28.85,.01:32,.005:34.27},17:{.995:5.7,.99:6.41,.975:7.56,.95:8.67,.9:10.09,.5:16.34,.1:24.77,.05:27.59,.025:30.19,.01:33.41,.005:35.72},18:{.995:6.26,.99:7.01,.975:8.23,.95:9.39,.9:10.87,.5:17.34,.1:25.99,.05:28.87,.025:31.53,.01:34.81,.005:37.16},19:{.995:6.84,.99:7.63,.975:8.91,.95:10.12,.9:11.65,.5:18.34,.1:27.2,.05:30.14,.025:32.85,.01:36.19,.005:38.58},20:{.995:7.43,.99:8.26,.975:9.59,.95:10.85,.9:12.44,.5:19.34,.1:28.41,.05:31.41,.025:34.17,.01:37.57,.005:40},21:{.995:8.03,.99:8.9,.975:10.28,.95:11.59,.9:13.24,.5:20.34,.1:29.62,.05:32.67,.025:35.48,.01:38.93,.005:41.4},22:{.995:8.64,.99:9.54,.975:10.98,.95:12.34,.9:14.04,.5:21.34,.1:30.81,.05:33.92,.025:36.78,.01:40.29,.005:42.8},23:{.995:9.26,.99:10.2,.975:11.69,.95:13.09,.9:14.85,.5:22.34,.1:32.01,.05:35.17,.025:38.08,.01:41.64,.005:44.18},24:{.995:9.89,.99:10.86,.975:12.4,.95:13.85,.9:15.66,.5:23.34,.1:33.2,.05:36.42,.025:39.36,.01:42.98,.005:45.56},25:{.995:10.52,.99:11.52,.975:13.12,.95:14.61,.9:16.47,.5:24.34,.1:34.28,.05:37.65,.025:40.65,.01:44.31,.005:46.93},26:{.995:11.16,.99:12.2,.975:13.84,.95:15.38,.9:17.29,.5:25.34,.1:35.56,.05:38.89,.025:41.92,.01:45.64,.005:48.29},27:{.995:11.81,.99:12.88,.975:14.57,.95:16.15,.9:18.11,.5:26.34,.1:36.74,.05:40.11,.025:43.19,.01:46.96,.005:49.65},28:{.995:12.46,.99:13.57,.975:15.31,.95:16.93,.9:18.94,.5:27.34,.1:37.92,.05:41.34,.025:44.46,.01:48.28,.005:50.99},29:{.995:13.12,.99:14.26,.975:16.05,.95:17.71,.9:19.77,.5:28.34,.1:39.09,.05:42.56,.025:45.72,.01:49.59,.005:52.34},30:{.995:13.79,.99:14.95,.975:16.79,.95:18.49,.9:20.6,.5:29.34,.1:40.26,.05:43.77,.025:46.98,.01:50.89,.005:53.67},40:{.995:20.71,.99:22.16,.975:24.43,.95:26.51,.9:29.05,.5:39.34,.1:51.81,.05:55.76,.025:59.34,.01:63.69,.005:66.77},50:{.995:27.99,.99:29.71,.975:32.36,.95:34.76,.9:37.69,.5:49.33,.1:63.17,.05:67.5,.025:71.42,.01:76.15,.005:79.49},60:{.995:35.53,.99:37.48,.975:40.48,.95:43.19,.9:46.46,.5:59.33,.1:74.4,.05:79.08,.025:83.3,.01:88.38,.005:91.95},70:{.995:43.28,.99:45.44,.975:48.76,.95:51.74,.9:55.33,.5:69.33,.1:85.53,.05:90.53,.025:95.02,.01:100.42,.005:104.22},80:{.995:51.17,.99:53.54,.975:57.15,.95:60.39,.9:64.28,.5:79.33,.1:96.58,.05:101.88,.025:106.63,.01:112.33,.005:116.32},90:{.995:59.2,.99:61.75,.975:65.65,.95:69.13,.9:73.29,.5:89.33,.1:107.57,.05:113.14,.025:118.14,.01:124.12,.005:128.3},100:{.995:67.33,.99:70.06,.975:74.22,.95:77.93,.9:82.36,.5:99.33,.1:118.5,.05:124.34,.025:129.56,.01:135.81,.005:140.17}};r.exports=e},{}],8:[function(t,r,n){"use strict";function e(t,r,n){for(var e,a,u=o(t),s=0,f=r(u),c=[],h=[],l=0;l<t.length;l++)void 0===c[t[l]]&&(c[t[l]]=0),c[t[l]]++;for(l=0;l<c.length;l++)void 0===c[l]&&(c[l]=0);for(a in f)a in c&&(h[+a]=f[a]*t.length);for(a=h.length-1;a>=0;a--)h[a]<3&&(h[a-1]+=h[a],h.pop(),c[a-1]+=c[a],c.pop());for(a=0;a<c.length;a++)s+=Math.pow(c[a]-h[a],2)/h[a];return e=c.length-1-1,i[e][n]<s}var o=t(28),i=t(7);r.exports=e},{28:28,7:7}],9:[function(t,r,n){"use strict";function e(t,r){var n=[];if(r<1)throw new Error("chunk size must be a positive number");if(Math.floor(r)!==r)throw new Error("chunk size must be an integer");for(var e=0;e<t.length;e+=r)n.push(t.slice(e,e+r));return n}r.exports=e},{}],10:[function(t,r,n){"use strict";function e(t,r){for(var n=[],e=0;e<t;e++){for(var o=[],i=0;i<r;i++)o.push(0);n.push(o)}return n}function o(t,r,n,e){var o;if(t>0){var i=(n[r]-n[t-1])/(r-t+1);o=e[r]-e[t-1]-(r-t+1)*i*i}else o=e[r]-n[r]*n[r]/(r+1);return o<0?0:o}function i(t,r,n,e,a,u,s){if(!(t>r)){var f=Math.floor((t+r)/2);e[n][f]=e[n-1][f-1],a[n][f]=f;var c=n;t>n&&(c=Math.max(c,a[n][t-1]||0)),c=Math.max(c,a[n-1][f]||0);var h=f-1;r<e.length-1&&(h=Math.min(h,a[n][r+1]||0));for(var l,p,v,g,w=h;w>=c&&!((l=o(w,f,u,s))+e[n-1][c-1]>=e[n][f]);--w)p=o(c,f,u,s),v=p+e[n-1][c-1],v<e[n][f]&&(e[n][f]=v,a[n][f]=c),c++,(g=l+e[n-1][w-1])<e[n][f]&&(e[n][f]=g,a[n][f]=w);i(t,f-1,n,e,a,u,s),i(f+1,r,n,e,a,u,s)}}function a(t,r,n){for(var e,a=r[0].length,u=t[Math.floor(a/2)],s=[],f=[],c=0;c<a;++c)e=t[c]-u,0===c?(s.push(e),f.push(e*e)):(s.push(s[c-1]+e),f.push(f[c-1]+e*e)),r[0][c]=o(0,c,s,f),n[0][c]=0;for(var h,l=1;l<r.length;++l)h=l<r.length-1?l:a-1,i(h,a-1,l,r,n,s,f)}function u(t,r){if(r>t.length)throw new Error("cannot generate more classes than there are data values");var n=f(t);if(1===s(n))return[n];var o=e(r,n.length),i=e(r,n.length);a(n,o,i);for(var u=[],c=i[0].length-1,h=i.length-1;h>=0;h--){var l=i[h][c];u[h]=n.slice(l,c+1),h>0&&(c=l-1)}return u}var s=t(66),f=t(37);r.exports=u},{37:37,66:66}],11:[function(t,r,n){"use strict";function e(t,r){var n,o,i,a,u=[];for(n=0;n<t.length;n++)if(1===r)u.push([t[n]]);else for(i=e(t.slice(n+1,t.length),r-1),o=0;o<i.length;o++)a=i[o],a.unshift(t[n]),u.push(a);return u}r.exports=e},{}],12:[function(t,r,n){"use strict";function e(t,r){for(var n=[],o=0;o<t.length;o++)if(1===r)n.push([t[o]]);else for(var i=e(t.slice(o,t.length),r-1),a=0;a<i.length;a++)n.push([t[o]].concat(i[a]));return n}r.exports=e},{}],13:[function(t,r,n){"use strict";function e(t,r,n,e){return(t*r+n*e)/(r+e)}r.exports=e},{}],14:[function(t,r,n){"use strict";function e(t,r,n,e,i,a){var u=o(r,n,i,a);return(n*(t+Math.pow(r-u,2))+a*(e+Math.pow(i-u,2)))/(n+a)}var o=t(13);r.exports=e},{13:13}],15:[function(t,r,n){"use strict";function e(t){var r=Math.abs(t),n=Math.min(Math.round(100*r),o.length-1);return t>=0?o[n]:+(1-o[n]).toFixed(4)}var o=t(59);r.exports=e},{59:59}],16:[function(t,r,n){"use strict";r.exports=1e-4},{}],17:[function(t,r,n){"use strict";function e(t,r){if(t.length<2)return t;for(var n=i(t),e=o(t),a=[n],u=(e-n)/r,s=1;s<r;s++)a.push(a[0]+u*s);return a.push(e),a}var o=t(26),i=t(32);r.exports=e},{26:26,32:32}],18:[function(t,r,n){"use strict";function e(t){var r=1/(1+.5*Math.abs(t)),n=r*Math.exp(-Math.pow(t,2)-1.26551223+1.00002368*r+.37409196*Math.pow(r,2)+.09678418*Math.pow(r,3)-.18628806*Math.pow(r,4)+.27886807*Math.pow(r,5)-1.13520398*Math.pow(r,6)+1.48851587*Math.pow(r,7)-.82215223*Math.pow(r,8)+.17087277*Math.pow(r,9));return t>=0?1-n:n-1}r.exports=e},{}],19:[function(t,r,n){"use strict";function e(t){if(t<0)throw new Error("factorial requires a non-negative value");if(Math.floor(t)!==t)throw new Error("factorial requires an integer input");for(var r=1,n=2;n<=t;n++)r*=n;return r}r.exports=e},{}],20:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("geometricMean requires at least one data point");for(var r=1,n=0;n<t.length;n++){if(t[n]<=0)throw new Error("geometricMean requires only positive numbers as input");r*=t[n]}return Math.pow(r,1/t.length)}r.exports=e},{}],21:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("harmonicMean requires at least one data point");for(var r=0,n=0;n<t.length;n++){if(t[n]<=0)throw new Error("harmonicMean requires only positive numbers as input");r+=1/t[n]}return t.length/r}r.exports=e},{}],22:[function(t,r,n){"use strict";function e(t){var r=o(t,.75),n=o(t,.25);if("number"==typeof r&&"number"==typeof n)return r-n}var o=t(43);r.exports=e},{43:43}],23:[function(t,r,n){"use strict";function e(t){var r=8*(Math.PI-3)/(3*Math.PI*(4-Math.PI)),n=Math.sqrt(Math.sqrt(Math.pow(2/(Math.PI*r)+Math.log(1-t*t)/2,2)-Math.log(1-t*t)/r)-(2/(Math.PI*r)+Math.log(1-t*t)/2));return t>=0?n:-n}r.exports=e},{}],24:[function(t,r,n){"use strict";function e(t){var r,n,e=t.length;if(1===e)r=0,n=t[0][1];else{for(var o,i,a,u=0,s=0,f=0,c=0,h=0;h<e;h++)o=t[h],i=o[0],a=o[1],u+=i,s+=a,f+=i*i,c+=i*a;r=(e*c-u*s)/(e*f-u*u),n=s/e-r*u/e}return{m:r,b:n}}r.exports=e},{}],25:[function(t,r,n){"use strict";function e(t){return function(r){return t.b+t.m*r}}r.exports=e},{}],26:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("max requires at least one data point");for(var r=t[0],n=1;n<t.length;n++)t[n]>r&&(r=t[n]);return r}r.exports=e},{}],27:[function(t,r,n){"use strict";function e(t){return t[t.length-1]}r.exports=e},{}],28:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("mean requires at least one data point");return o(t)/t.length}var o=t(61);r.exports=e},{61:61}],29:[function(t,r,n){"use strict";function e(t){return+o(t,.5)}var o=t(43);r.exports=e},{43:43}],30:[function(t,r,n){"use strict";function e(t){for(var r=o(t),n=[],e=0;e<t.length;e++)n.push(Math.abs(t[e]-r));return o(n)}var o=t(29);r.exports=e},{29:29}],31:[function(t,r,n){"use strict";function e(t){return o(t,.5)}var o=t(44);r.exports=e},{44:44}],32:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("min requires at least one data point");for(var r=t[0],n=1;n<t.length;n++)t[n]<r&&(r=t[n]);return r}r.exports=e},{}],33:[function(t,r,n){"use strict";function e(t){return t[0]}r.exports=e},{}],34:[function(t,r,n){"use strict";function e(t){return i(o(t))}var o=t(37),i=t(36);r.exports=e},{36:36,37:37}],35:[function(t,r,n){"use strict";function e(t){for(var r,n=new Map,e=0,o=0;o<t.length;o++){var i=n.get(t[o]);void 0===i?i=1:i++,i>e&&(r=t[o],e=i),n.set(t[o],i)}if(0===e)throw new Error("mode requires at last one data point");return r}r.exports=e},{}],36:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("mode requires at least one data point");if(1===t.length)return t[0];for(var r=t[0],n=NaN,e=0,o=1,i=1;i<t.length+1;i++)t[i]!==r?(o>e&&(e=o,n=r),o=1,r=t[i]):o++;return n}r.exports=e},{}],37:[function(t,r,n){"use strict";function e(t){return t.slice().sort(function(t,r){return t-r})}r.exports=e},{}],38:[function(t,r,n){"use strict";function e(){this.weights=[],this.bias=0}e.prototype.predict=function(t){if(t.length!==this.weights.length)return null;for(var r=0,n=0;n<this.weights.length;n++)r+=this.weights[n]*t[n];return r+=this.bias,r>0?1:0},e.prototype.train=function(t,r){if(0!==r&&1!==r)return null;t.length!==this.weights.length&&(this.weights=t,this.bias=1);var n=this.predict(t);if(n!==r){for(var e=r-n,o=0;o<this.weights.length;o++)this.weights[o]+=e*t[o];this.bias+=e}return this},r.exports=e},{}],39:[function(t,r,n){"use strict";function e(t){for(var r=new Array(t.length),n=[t.slice()],e=0;e<t.length;e++)r[e]=0;for(e=0;e<t.length;)if(r[e]<e){var o=0;e%2!=0&&(o=r[e]);var i=t[o];t[o]=t[e],t[e]=i,n.push(t.slice()),r[e]++,e=0}else r[e]=0,e++;return n}r.exports=e},{}],40:[function(t,r,n){"use strict";function e(t){if(!(t<=0)){var r=0,n=0,e=[],i=1;do{e[r]=Math.exp(-t)*Math.pow(t,r)/i,n+=e[r],r++,i*=r}while(n<1-o);return e}}var o=t(16);r.exports=e},{16:16}],41:[function(t,r,n){"use strict";function e(t){return 0===t?t=o:t>=1&&(t=1-o),Math.sqrt(2)*i(2*t-1)}var o=t(16),i=t(23);r.exports=e},{16:16,23:23}],42:[function(t,r,n){"use strict";function e(t){for(var r=1,n=0;n<t.length;n++)r*=t[n];return r}r.exports=e},{}],43:[function(t,r,n){"use strict";function e(t,r){var n=t.slice();if(Array.isArray(r)){i(n,r);for(var e=[],a=0;a<r.length;a++)e[a]=s(n,r[a]);return e}return o(n,u(n.length,r),0,n.length-1),s(n,r)}function o(t,r,n,e){r%1==0?f(t,r,n,e):(r=Math.floor(r),f(t,r,n,e),f(t,r+1,r+1,e))}function i(t,r){for(var n=[0],e=0;e<r.length;e++)n.push(u(t.length,r[e]));n.push(t.length-1),n.sort(a);for(var i=[0,n.length-1];i.length;){var s=Math.ceil(i.pop()),f=Math.floor(i.pop());if(!(s-f<=1)){var c=Math.floor((f+s)/2);o(t,n[c],n[f],n[s]),i.push(f,c,c,s)}}}function a(t,r){return t-r}function u(t,r){var n=t*r;return 1===r?t-1:0===r?0:n%1!=0?Math.ceil(n)-1:t%2==0?n-.5:n}var s=t(44),f=t(45);r.exports=e},{44:44,45:45}],44:[function(t,r,n){"use strict";function e(t,r){var n=t.length*r;if(0===t.length)throw new Error("quantile requires at least one data point.");if(r<0||r>1)throw new Error("quantiles must be between 0 and 1");return 1===r?t[t.length-1]:0===r?t[0]:n%1!=0?t[Math.ceil(n)-1]:t.length%2==0?(t[n-1]+t[n])/2:t[n]}r.exports=e},{}],45:[function(t,r,n){"use strict";function e(t,r,n,i){for(n=n||0,i=i||t.length-1;i>n;){if(i-n>600){var a=i-n+1,u=r-n+1,s=Math.log(a),f=.5*Math.exp(2*s/3),c=.5*Math.sqrt(s*f*(a-f)/a);u-a/2<0&&(c*=-1);e(t,r,Math.max(n,Math.floor(r-u*f/a+c)),Math.min(i,Math.floor(r+(a-u)*f/a+c)))}var h=t[r],l=n,p=i;for(o(t,n,r),t[i]>h&&o(t,n,i);l<p;){for(o(t,l,p),l++,p--;t[l]<h;)l++;for(;t[p]>h;)p--}t[n]===h?o(t,n,p):(p++,o(t,p,i)),p<=r&&(n=p+1),r<=p&&(i=p-1)}}function o(t,r,n){var e=t[r];t[r]=t[n],t[n]=e}r.exports=e},{}],46:[function(t,r,n){"use strict";function e(t,r){if(t.length<2)return 1;for(var n,e=0,o=0;o<t.length;o++)e+=t[o][1];n=e/t.length;for(var i=0,a=0;a<t.length;a++)i+=Math.pow(n-t[a][1],2);for(var u=0,s=0;s<t.length;s++)u+=Math.pow(t[s][1]-r(t[s][0]),2);return 1-u/i}r.exports=e},{}],47:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("rootMeanSquare requires at least one data point");for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n],2);return Math.sqrt(r/t.length)}r.exports=e},{}],48:[function(t,r,n){"use strict";function e(t,r,n){return o(t,n).slice(0,r)}var o=t(55);r.exports=e},{55:55}],49:[function(t,r,n){"use strict";function e(t,r){return o(t,r)/i(t)/i(r)}var o=t(50),i=t(52);r.exports=e},{50:50,52:52}],50:[function(t,r,n){"use strict";function e(t,r){if(t.length!==r.length)throw new Error("sampleCovariance requires samples with equal lengths");if(t.length<2)throw new Error("sampleCovariance requires at least two data points in each sample");for(var n=o(t),e=o(r),i=0,a=0;a<t.length;a++)i+=(t[a]-n)*(r[a]-e);return i/(t.length-1)}var o=t(28);r.exports=e},{28:28}],51:[function(t,r,n){"use strict";function e(t){if(t.length<3)throw new Error("sampleSkewness requires at least three data points");for(var r,n=o(t),e=0,i=0,a=0;a<t.length;a++)r=t[a]-n,e+=r*r,i+=r*r*r;var u=t.length-1,s=Math.sqrt(e/u),f=t.length;return f*i/((f-1)*(f-2)*Math.pow(s,3))}var o=t(28);r.exports=e},{28:28}],52:[function(t,r,n){"use strict";function e(t){var r=o(t);return Math.sqrt(r)}var o=t(53);r.exports=e},{53:53}],53:[function(t,r,n){"use strict";function e(t){if(t.length<2)throw new Error("sampleVariance requires at least two data points");return o(t,2)/(t.length-1)}var o=t(62);r.exports=e},{62:62}],54:[function(t,r,n){"use strict";function e(t,r,n){if(0===t.length)return[];n=n||Math.random;for(var e=t.length,o=[],i=0;i<r;i++){var a=Math.floor(n()*e);o.push(t[a])}return o}r.exports=e},{}],55:[function(t,r,n){"use strict";function e(t,r){var n=t.slice();return o(n.slice(),r)}var o=t(56);r.exports=e},{56:56}],56:[function(t,r,n){"use strict";function e(t,r){r=r||Math.random;for(var n,e,o=t.length;o>0;)e=Math.floor(r()*o--),n=t[o],t[o]=t[e],t[e]=n;return t}r.exports=e},{}],57:[function(t,r,n){"use strict";function e(t){if("number"==typeof t)return t<0?-1:0===t?0:1;throw new TypeError("not a number")}r.exports=e},{}],58:[function(t,r,n){"use strict";function e(t){if(1===t.length)return 0;var r=o(t);return Math.sqrt(r)}var o=t(67);r.exports=e},{67:67}],59:[function(t,r,n){"use strict";for(var e=Math.sqrt(2*Math.PI),o=[],i=0;i<=3.09;i+=.01)o.push(function(t){for(var r=t,n=t,o=1;o<15;o++)n*=t*t/(2*o+1),r+=n;return Math.round(1e4*(.5+r/e*Math.exp(-t*t/2)))/1e4}(i));r.exports=o},{}],60:[function(t,r,n){"use strict";function e(t,r,n){return(t*r-n)/(r-1)}r.exports=e},{}],61:[function(t,r,n){"use strict";function e(t){if(0===t.length)return 0;for(var r,n=t[0],e=0,o=1;o<t.length;o++)r=n+t[o],Math.abs(n)>=Math.abs(t[o])?e+=n-r+t[o]:e+=t[o]-r+n,n=r;return n+e}r.exports=e},{}],62:[function(t,r,n){"use strict";function e(t,r){var n,e,i=o(t),a=0;if(2===r)for(e=0;e<t.length;e++)n=t[e]-i,a+=n*n;else for(e=0;e<t.length;e++)a+=Math.pow(t[e]-i,r);return a}var o=t(28);r.exports=e},{28:28}],63:[function(t,r,n){"use strict";function e(t){for(var r=0,n=0;n<t.length;n++)r+=t[n];return r}r.exports=e},{}],64:[function(t,r,n){"use strict";function e(t,r){return(i(t)-r)/(o(t)/Math.sqrt(t.length))}var o=t(58),i=t(28);r.exports=e},{28:28,58:58}],65:[function(t,r,n){"use strict";function e(t,r,n){var e=t.length,a=r.length;if(!e||!a)return null;n||(n=0);var u=o(t),s=o(r),f=i(t),c=i(r);if("number"==typeof u&&"number"==typeof s&&"number"==typeof f&&"number"==typeof c){var h=((e-1)*f+(a-1)*c)/(e+a-2);return(u-s-n)/Math.sqrt(h*(1/e+1/a))}}var o=t(28),i=t(53);r.exports=e},{28:28,53:53}],66:[function(t,r,n){"use strict";function e(t){for(var r,n=0,e=0;e<t.length;e++)0!==e&&t[e]===r||(r=t[e],n++);return n}r.exports=e},{}],67:[function(t,r,n){"use strict";function e(t){if(0===t.length)throw new Error("variance requires at least one data point");return o(t,2)/t.length}var o=t(62);r.exports=e},{62:62}],68:[function(t,r,n){"use strict";function e(t,r,n){return(t-r)/n}r.exports=e},{}]},{},[1])(1)});
//# sourceMappingURL=dist/simple-statistics.min.js.map

@@ -87,5 +87,4 @@ /* @flow */

ss.probit = require('./src/probit');
ss.mixin = require('./src/mixin');
// Root-finding methods
ss.bisect = require('./src/bisect');
{
"name": "simple-statistics",
"version": "3.0.0",
"version": "4.0.0",
"description": "Simple Statistics",

@@ -20,10 +20,11 @@ "author": "Tom MacWright <tom@macwright.org> (http://macwright.org/)",

"bundle-collapser": "^1.0.0",
"cz-conventional-changelog": "^1.2.0",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^3.8.1",
"exorcist": "^0.4.0",
"flow-bin": "^0.39.0",
"flow-bin": "^0.44.0",
"jsdoctest": "1.7.0",
"mocha": "3.2.0",
"mocha": "3.3.0",
"random-js": "^1.0.4",
"standard-changelog": "^0.0.1",
"standard-changelog": "^1.0.1",
"standard-version": "^4.0.0",
"tap": "^10.1.1",

@@ -33,2 +34,3 @@ "uglify-js": "^2.6.2"

"scripts": {
"release": "standard-version && sh ./scripts/update_website.sh",
"test": "are-we-flow-yet src && flow check src && eslint index.js src/*.js test/*.js && tap --coverage test/*.js && npm run jsdoctest",

@@ -35,0 +37,0 @@ "test-sauce": "node scripts/browser_test.js",

# Simple Statistics
A JavaScript implementation of descriptive, regression, and inference statistics.
[![Circle CI](https://circleci.com/gh/simple-statistics/simple-statistics/tree/master.svg?style=svg)](https://circleci.com/gh/simple-statistics/simple-statistics/tree/master)
[![Circle CI](https://circleci.com/gh/simple-statistics/simple-statistics/tree/master.svg?style=shield)](https://circleci.com/gh/simple-statistics/simple-statistics/tree/master)
[![codecov.io](https://codecov.io/github/simple-statistics/simple-statistics/coverage.svg?branch=master)](https://codecov.io/github/simple-statistics/simple-statistics?branch=master)
[![npm version](https://badge.fury.io/js/simple-statistics.svg)](http://badge.fury.io/js/simple-statistics)
[![Greenkeeper badge](https://badges.greenkeeper.io/simple-statistics/simple-statistics.svg)](https://greenkeeper.io/)

@@ -25,7 +27,7 @@ Implemented in literate JavaScript with no dependencies, designed to work

* `https://unpkg.com/simple-statistics@3.0.0/dist/simple-statistics.js`
* Minified: `https://unpkg.com/simple-statistics@3.0.0/dist/simple-statistics.min.js`
* `https://unpkg.com/simple-statistics@4.0.0/dist/simple-statistics.js`
* Minified: `https://unpkg.com/simple-statistics@4.0.0/dist/simple-statistics.min.js`
Bower:
* Bower: `https://unpkg.com/simple-statistics@3.0.0/bower.zip`
* Bower: `https://unpkg.com/simple-statistics@4.0.0/bower.zip`
'use strict';
/* @flow */
var binomialDistribution = require('./binomial_distribution');
/**

@@ -18,8 +16,8 @@ * The [Bernoulli distribution](http://en.wikipedia.org/wiki/Bernoulli_distribution)

* @param {number} p input value, between 0 and 1 inclusive
* @returns {number} value of bernoulli distribution at this point
* @returns {number[]} values of bernoulli distribution at this point
* @throws {Error} if p is outside 0 and 1
* @example
* bernoulliDistribution(0.5); // => { '0': 0.5, '1': 0.5 }
* bernoulliDistribution(0.3); // => [0.7, 0.3]
*/
function bernoulliDistribution(p/*: number */) {
function bernoulliDistribution(p/*: number */) /*: number[] */ {
// Check that `p` is a valid probability (0 ≤ p ≤ 1)

@@ -30,5 +28,5 @@ if (p < 0 || p > 1 ) {

return binomialDistribution(1, p);
return [1 - p, p];
}
module.exports = bernoulliDistribution;

@@ -5,3 +5,2 @@ 'use strict';

var epsilon = require('./epsilon');
var factorial = require('./factorial');

@@ -16,7 +15,7 @@ /**

* @param {number} probability
* @returns {Object} output
* @returns {number[]} output
*/
function binomialDistribution(
trials/*: number */,
probability/*: number */)/*: ?Object */ {
probability/*: number */)/*: ?number[] */ {
// Check that `p` is a valid probability (0 ≤ p ≤ 1),

@@ -37,3 +36,4 @@ // that `n` is an integer, strictly positive.

cumulativeProbability = 0,
cells = {};
cells = [],
binomialCoefficient = 1;

@@ -45,7 +45,7 @@ // This algorithm iterates through each potential outcome,

// a [probability mass function](https://en.wikipedia.org/wiki/Probability_mass_function)
cells[x] = factorial(trials) /
(factorial(x) * factorial(trials - x)) *
(Math.pow(probability, x) * Math.pow(1 - probability, trials - x));
cells[x] = binomialCoefficient *
Math.pow(probability, x) * Math.pow(1 - probability, trials - x);
cumulativeProbability += cells[x];
x++;
binomialCoefficient = binomialCoefficient * (trials - x + 1) / x;
// when the cumulativeProbability is nearly 1, we've calculated

@@ -52,0 +52,0 @@ // the useful range of this distribution

@@ -20,7 +20,7 @@ 'use strict';

if (n < 0) {
throw new Error('factorial requires an integer input');
throw new Error('factorial requires a non-negative value');
}
if (Math.floor(n) !== n) {
throw new Error('factorial requires a non-negative value');
throw new Error('factorial requires an integer input');
}

@@ -27,0 +27,0 @@

@@ -17,13 +17,15 @@ 'use strict';

function max(x /*: Array<number> */) /*:number*/ {
var value;
for (var i = 0; i < x.length; i++) {
if (x.length === 0) {
throw new Error('max requires at least one data point');
}
var value = x[0];
for (var i = 1; i < x.length; i++) {
// On the first iteration of this loop, max is
// undefined and is thus made the maximum element in the array
if (value === undefined || x[i] > value) {
if (x[i] > value) {
value = x[i];
}
}
if (value === undefined) {
throw new Error('max requires at least one data point');
}
return value;

@@ -30,0 +32,0 @@ }

@@ -14,13 +14,15 @@ 'use strict';

function min(x /*: Array<number> */)/*:number*/ {
var value;
for (var i = 0; i < x.length; i++) {
if (x.length === 0) {
throw new Error('min requires at least one data point');
}
var value = x[0];
for (var i = 1; i < x.length; i++) {
// On the first iteration of this loop, min is
// undefined and is thus made the minimum element in the array
if (value === undefined || x[i] < value) {
if (x[i] < value) {
value = x[i];
}
}
if (value === undefined) {
throw new Error('min requires at least one data point');
}
return value;

@@ -27,0 +29,0 @@ }

@@ -5,3 +5,2 @@ 'use strict';

var epsilon = require('./epsilon');
var factorial = require('./factorial');

@@ -19,5 +18,5 @@ /**

* @param {number} lambda location poisson distribution
* @returns {number} value of poisson distribution at that point
* @returns {number[]} values of poisson distribution at that point
*/
function poissonDistribution(lambda/*: number */) {
function poissonDistribution(lambda/*: number */) /*: ?number[] */ {
// Check that lambda is strictly positive

@@ -32,3 +31,4 @@ if (lambda <= 0) { return undefined; }

// the calculated cells to be returned
cells = {};
cells = [],
factorialX = 1;

@@ -40,5 +40,6 @@ // This algorithm iterates through each potential outcome,

// a [probability mass function](https://en.wikipedia.org/wiki/Probability_mass_function)
cells[x] = (Math.pow(Math.E, -lambda) * Math.pow(lambda, x)) / factorial(x);
cells[x] = (Math.exp(-lambda) * Math.pow(lambda, x)) / factorialX;
cumulativeProbability += cells[x];
x++;
factorialX *= x;
// when the cumulativeProbability is nearly 1, we've calculated

@@ -45,0 +46,0 @@ // the useful range of this distribution

'use strict';
/* @flow */
var sumNthPowerDeviations = require('./sum_nth_power_deviations');
var sampleStandardDeviation = require('./sample_standard_deviation');
var mean = require('./mean');

@@ -24,4 +23,2 @@ /**

function sampleSkewness(x /*: Array<number> */)/*:number*/ {
// The skewness of less than three arguments is null
var theSampleStandardDeviation = sampleStandardDeviation(x);

@@ -32,5 +29,23 @@ if (x.length < 3) {

var meanValue = mean(x);
var tempValue;
var sumSquaredDeviations = 0;
var sumCubedDeviations = 0;
for (var i = 0; i < x.length; i++) {
tempValue = x[i] - meanValue;
sumSquaredDeviations += tempValue * tempValue;
sumCubedDeviations += tempValue * tempValue * tempValue;
}
// this is Bessels' Correction: an adjustment made to sample statistics
// that allows for the reduced degree of freedom entailed in calculating
// values from samples rather than complete populations.
var besselsCorrection = x.length - 1;
// Find the mean value of that list
var theSampleStandardDeviation = Math.sqrt(sumSquaredDeviations / besselsCorrection);
var n = x.length,
cubedS = Math.pow(theSampleStandardDeviation, 3),
sumCubedDeviations = sumNthPowerDeviations(x, 3);
cubedS = Math.pow(theSampleStandardDeviation, 3);

@@ -37,0 +52,0 @@ return n * sumCubedDeviations / ((n - 1) * (n - 2) * cubedS);

@@ -22,6 +22,18 @@ 'use strict';

var meanValue = mean(x),
sum = 0;
sum = 0,
tempValue,
i;
for (var i = 0; i < x.length; i++) {
sum += Math.pow(x[i] - meanValue, n);
// This is an optimization: when n is 2 (we're computing a number squared),
// multiplying the number by itself is significantly faster than using
// the Math.pow method.
if (n === 2) {
for (i = 0; i < x.length; i++) {
tempValue = x[i] - meanValue;
sum += tempValue * tempValue;
}
} else {
for (i = 0; i < x.length; i++) {
sum += Math.pow(x[i] - meanValue, n);
}
}

@@ -28,0 +40,0 @@

@@ -5,5 +5,7 @@ 'use strict';

/**
* Our default sum is the [Kahan summation algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm) is
* a method for computing the sum of a list of numbers while correcting
* for floating-point errors. Traditionally, sums are calculated as many
* Our default sum is the [Kahan-Babuska algorithm](https://pdfs.semanticscholar.org/1760/7d467cda1d0277ad272deb2113533131dc09.pdf).
* This method is an improvement over the classical
* [Kahan summation algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm).
* It aims at computing the sum of a list of numbers while correcting for
* floating-point errors. Traditionally, sums are calculated as many
* successive additions, each one with its own floating-point roundoff. These

@@ -14,3 +16,3 @@ * losses in precision add up as the number of numbers increases. This alternative

*
* This runs on `O(n)`, linear time in respect to the array
* This runs on `O(n)`, linear time in respect to the array.
*

@@ -24,41 +26,34 @@ * @param {Array<number>} x input

// like the traditional sum algorithm, we keep a running
// count of the current sum.
var sum = 0;
// If the array is empty, we needn't bother computing its sum
if (x.length === 0) {
return 0;
}
// but we also keep three extra variables as bookkeeping:
// most importantly, an error correction value. This will be a very
// small number that is the opposite of the floating point precision loss.
var errorCompensation = 0;
// Initializing the sum as the first number in the array
var sum = x[0];
// this will be each number in the list corrected with the compensation value.
var correctedCurrentValue;
// Keeping track of the floating-point error correction
var correction = 0;
// and this will be the next sum
var nextSum;
var transition;
for (var i = 0; i < x.length; i++) {
// first correct the value that we're going to add to the sum
correctedCurrentValue = x[i] - errorCompensation;
for (var i = 1; i < x.length; i++) {
transition = sum + x[i];
// compute the next sum. sum is likely a much larger number
// than correctedCurrentValue, so we'll lose precision here,
// and measure how much precision is lost in the next step
nextSum = sum + correctedCurrentValue;
// Here we need to update the correction in a different fashion
// if the new absolute value is greater than the absolute sum
if (Math.abs(sum) >= Math.abs(x[i])) {
correction += ((sum - transition) + x[i]);
}
else {
correction += ((x[i] - transition) + sum);
}
// we intentionally didn't assign sum immediately, but stored
// it for now so we can figure out this: is (sum + nextValue) - nextValue
// not equal to 0? ideally it would be, but in practice it won't:
// it will be some very small number. that's what we record
// as errorCompensation.
errorCompensation = nextSum - sum - correctedCurrentValue;
// now that we've computed how much we'll correct for in the next
// loop, start treating the nextSum as the current sum.
sum = nextSum;
sum = transition;
}
return sum;
// Returning the corrected sum
return sum + correction;
}
module.exports = sum;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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