simple-statistics
Advanced tools
Comparing version 2.5.0 to 3.0.0
@@ -0,1 +1,18 @@ | ||
<a name="3.0.0"></a> | ||
# [3.0.0](https://github.com/simple-statistics/simple-statistics/compare/v2.5.0...v3.0.0) (2017-04-06) | ||
**Breaking change**: before this release, simple-statistics would return `NaN` | ||
when provided with invalid input. After 3.0.0, simple-statistics will throw | ||
exceptions when provided with invalid input. If you previously used `isNaN` to | ||
test for these error cases, switch to using `try` and `catch`, or make sure | ||
that valid input is given to simple-statistics. | ||
### Features | ||
* **mean:** combineMeans, a method for combining calculated means ([d9e3ebc](https://github.com/simple-statistics/simple-statistics/commit/d9e3ebc)) | ||
* **mean:** subtractFromMean, a method to remove a value from the mean ([afe76e9](https://github.com/simple-statistics/simple-statistics/commit/afe76e9)) | ||
* **variance:** combineVariances, a method for combining pre-calculated variances of two dataset ([68133f7](https://github.com/simple-statistics/simple-statistics/commit/68133f7)) | ||
<a name="2.5.0"></a> | ||
@@ -2,0 +19,0 @@ # [2.5.0](https://github.com/simple-statistics/simple-statistics/compare/v2.4.0...v2.5.0) (2017-02-24) |
@@ -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(u,a){if(!n[u]){if(!r[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[u]={exports:{}};r[u][0].call(c.exports,function(t){var n=r[u][1][t];return o(n?n:t)},c,c.exports,t,r,n,e)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<e.length;u++)o(e[u]);return o}({1:[function(t,r,n){"use strict";var e=r.exports={};e.linearRegression=t(22),e.linearRegressionLine=t(23),e.standardDeviation=t(57),e.rSquared=t(45),e.mode=t(33),e.modeFast=t(34),e.modeSorted=t(35),e.min=t(30),e.max=t(24),e.minSorted=t(31),e.maxSorted=t(25),e.sum=t(59),e.sumSimple=t(61),e.product=t(41),e.quantile=t(42),e.quantileSorted=t(43),e.iqr=e.interquartileRange=t(20),e.medianAbsoluteDeviation=e.mad=t(28),e.chunk=t(9),e.sampleWithReplacement=t(53),e.shuffle=t(54),e.shuffleInPlace=t(55),e.sample=t(47),e.ckmeans=t(10),e.uniqueCountSorted=t(64),e.sumNthPowerDeviations=t(60),e.equalIntervalBreaks=t(15),e.sampleCovariance=t(49),e.sampleCorrelation=t(48),e.sampleVariance=t(52),e.sampleStandardDeviation=t(51),e.sampleSkewness=t(50),e.permutationsHeap=t(38),e.combinations=t(11),e.combinationsReplacement=t(12),e.addToMean=t(2),e.geometricMean=t(18),e.harmonicMean=t(19),e.mean=e.average=t(26),e.median=t(27),e.medianSorted=t(29),e.rootMeanSquare=e.rms=t(46),e.variance=t(65),e.tTest=t(62),e.tTestTwoSample=t(63),e.bayesian=t(3),e.perceptron=t(37),e.epsilon=t(14),e.factorial=t(17),e.bernoulliDistribution=t(4),e.binomialDistribution=t(5),e.poissonDistribution=t(39),e.chiSquaredGoodnessOfFit=t(8),e.zScore=t(66),e.cumulativeStdNormalProbability=t(13),e.standardNormalTable=t(58),e.errorFunction=e.erf=t(16),e.inverseErrorFunction=t(21),e.probit=t(40),e.mixin=t(32),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,37:37,38:38,39:39,4:4,40:40,41:41,42:42,43:43,45:45,46:46,47:47,48:48,49:49,5:5,50:50,51:51,52:52,53:53,54:54,55:55,57:57,58:58,59:59,6:6,60:60,61:61,62:62,63:63,64:64,65:65,66:66,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 u in n[r])i[r]+=n[r][u]}return i},r.exports=e},{}],4:[function(t,r,n){"use strict";function e(t){return t<0||t>1?NaN: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,u={};do u[n]=i(t)/(i(n)*i(t-n))*(Math.pow(r,n)*Math.pow(1-r,t-n)),e+=u[n],n++;while(e<1-o);return u}}var o=t(14),i=t(17);r.exports=e},{14:14,17:17}],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 u=0;u<e;u++){var a=(r+n)/2;if(0===t(a)||Math.abs((n-r)/2)<i)return a;o(t(a))===o(t(r))?r=a:n=a}throw new Error("maximum number of iterations exceeded")}var o=t(56);r.exports=e},{56:56}],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,u,a=o(t),s=0,f=1,c=r(a),h=[],l=[],p=0;p<t.length;p++)void 0===h[t[p]]&&(h[t[p]]=0),h[t[p]]++;for(p=0;p<h.length;p++)void 0===h[p]&&(h[p]=0);for(u in c)u in h&&(l[+u]=c[u]*t.length);for(u=l.length-1;u>=0;u--)l[u]<3&&(l[u-1]+=l[u],l.pop(),h[u-1]+=h[u],h.pop());for(u=0;u<h.length;u++)s+=Math.pow(h[u]-l[u],2)/l[u];return e=h.length-f-1,i[e][n]<s}var o=t(26),i=t(7);r.exports=e},{26:26,7:7}],9:[function(t,r,n){"use strict";function e(t,r){var n=[];if(r<=0)throw new Error("chunk size must be a positive 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,u,a,s){if(!(t>r)){var f=Math.floor((t+r)/2);e[n][f]=e[n-1][f-1],u[n][f]=f;var c=n;t>n&&(c=Math.max(c,u[n][t-1]||0)),c=Math.max(c,u[n-1][f]||0);var h=f-1;r<e.length-1&&(h=Math.min(h,u[n][r+1]||0));for(var l,p,v,g,d=h;d>=c&&(l=o(d,f,a,s),!(l+e[n-1][c-1]>=e[n][f]));--d)p=o(c,f,a,s),v=p+e[n-1][c-1],v<e[n][f]&&(e[n][f]=v,u[n][f]=c),c++,g=l+e[n-1][d-1],g<e[n][f]&&(e[n][f]=g,u[n][f]=d);i(t,f-1,n,e,u,a,s),i(f+1,r,n,e,u,a,s)}}function u(t,r,n){for(var e,u=r[0].length,a=t[Math.floor(u/2)],s=[],f=[],c=0;c<u;++c)e=t[c]-a,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:u-1,i(h,u-1,l,r,n,s,f)}function a(t,r){if(r>t.length)throw new Error("Cannot generate more classes than there are data values");var n=f(t),o=s(n);if(1===o)return[n];var i=e(r,n.length),a=e(r,n.length);u(n,i,a);for(var c=[],h=a[0].length-1,l=a.length-1;l>=0;l--){var p=a[l][h];c[l]=n.slice(p,h+1),l>0&&(h=p-1)}return c}var s=t(64),f=t(36);r.exports=a},{36:36,64:64}],11:[function(t,r,n){"use strict";function e(t,r){var n,o,i,u,a=[];for(n=0;n<t.length;n++)if(1===r)a.push([t[n]]);else for(i=e(t.slice(n+1,t.length),r-1),o=0;o<i.length;o++)u=i[o],u.unshift(t[n]),a.push(u);return a}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),u=0;u<i.length;u++)n.push([t[o]].concat(i[u]));return n}r.exports=e},{}],13:[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(58);r.exports=e},{58:58}],14:[function(t,r,n){"use strict";var e=1e-4;r.exports=e},{}],15:[function(t,r,n){"use strict";function e(t,r){if(t.length<=1)return t;for(var n=i(t),e=o(t),u=[n],a=(e-n)/r,s=1;s<r;s++)u.push(u[0]+a*s);return u.push(e),u}var o=t(24),i=t(30);r.exports=e},{24:24,30:30}],16:[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},{}],17:[function(t,r,n){"use strict";function e(t){if(t<0)return NaN;for(var r=1,n=2;n<=t;n++)r*=n;return r}r.exports=e},{}],18:[function(t,r,n){"use strict";function e(t){if(0!==t.length){for(var r=1,n=0;n<t.length;n++){if(t[n]<=0)return;r*=t[n]}return Math.pow(r,1/t.length)}}r.exports=e},{}],19:[function(t,r,n){"use strict";function e(t){if(0!==t.length){for(var r=0,n=0;n<t.length;n++){if(t[n]<=0)return;r+=1/t[n]}return t.length/r}}r.exports=e},{}],20:[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(42);r.exports=e},{42:42}],21:[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},{}],22:[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,u,a=0,s=0,f=0,c=0,h=0;h<e;h++)o=t[h],i=o[0],u=o[1],a+=i,s+=u,f+=i*i,c+=i*u;r=(e*c-a*s)/(e*f-a*a),n=s/e-r*a/e}return{m:r,b:n}}r.exports=e},{}],23:[function(t,r,n){"use strict";function e(t){return function(r){return t.b+t.m*r}}r.exports=e},{}],24:[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]);return void 0===r?NaN:r}r.exports=e},{}],25:[function(t,r,n){"use strict";function e(t){return t[t.length-1]}r.exports=e},{}],26:[function(t,r,n){"use strict";function e(t){return 0===t.length?NaN:o(t)/t.length}var o=t(59);r.exports=e},{59:59}],27:[function(t,r,n){"use strict";function e(t){return+o(t,.5)}var o=t(42);r.exports=e},{42:42}],28:[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(27);r.exports=e},{27:27}],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,n=0;n<t.length;n++)(void 0===r||t[n]<r)&&(r=t[n]);return void 0===r?NaN:r}r.exports=e},{}],31:[function(t,r,n){"use strict";function e(t){return t[0]}r.exports=e},{}],32:[function(t,r,n){"use strict";function e(t,r){function n(r){return function(){var n=Array.prototype.slice.apply(arguments);return n.unshift(this),t[r].apply(t,n)}}var e=!(!Object.defineProperty||!Object.defineProperties);if(!e)throw new Error("without defineProperty, simple-statistics cannot be mixed in");var o,i=["median","standardDeviation","sum","product","sampleSkewness","mean","min","max","quantile","geometricMean","harmonicMean","root_mean_square"];o=r?r.slice():Array.prototype;for(var u=0;u<i.length;u++)Object.defineProperty(o,i[u],{value:n(i[u]),configurable:!0,enumerable:!1,writable:!0});return o}r.exports=e},{}],33:[function(t,r,n){"use strict";function e(t){return i(o(t))}var o=t(36),i=t(35);r.exports=e},{35:35,36:36}],34:[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)}return r}r.exports=e},{}],35:[function(t,r,n){"use strict";function e(t){if(0===t.length)return NaN;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},{}],36:[function(t,r,n){"use strict";function e(t){return t.slice().sort(function(t,r){return t-r})}r.exports=e},{}],37:[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},{}],38:[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},{}],39:[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(14),i=t(17);r.exports=e},{14:14,17:17}],40:[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(14),i=t(21);r.exports=e},{14:14,21:21}],41:[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},{}],42:[function(t,r,n){"use strict";function e(t,r){var n=t.slice();if(Array.isArray(r)){i(n,r);for(var e=[],u=0;u<r.length;u++)e[u]=s(n,r[u]);return e}var f=a(n.length,r);return o(n,f,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(a(t.length,r[e]));n.push(t.length-1),n.sort(u);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 u(t,r){return t-r}function a(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(43),f=t(44);r.exports=e},{43:43,44:44}],43:[function(t,r,n){"use strict";function e(t,r){var n=t.length*r;return r<0||r>1?NaN: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},{}],44:[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 u=i-n+1,a=r-n+1,s=Math.log(u),f=.5*Math.exp(2*s/3),c=.5*Math.sqrt(s*f*(u-f)/u);a-u/2<0&&(c*=-1);var h=Math.max(n,Math.floor(r-a*f/u+c)),l=Math.min(i,Math.floor(r+(u-a)*f/u+c));e(t,r,h,l)}var p=t[r],v=n,g=i;for(o(t,n,r),t[i]>p&&o(t,n,i);v<g;){for(o(t,v,g),v++,g--;t[v]<p;)v++;for(;t[g]>p;)g--}t[n]===p?o(t,n,g):(g++,o(t,g,i)),g<=r&&(n=g+1),r<=g&&(i=g-1)}}function o(t,r,n){var e=t[r];t[r]=t[n],t[n]=e}r.exports=e},{}],45:[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,u=0;u<t.length;u++)i+=Math.pow(n-t[u][1],2);for(var a=0,s=0;s<t.length;s++)a+=Math.pow(t[s][1]-r(t[s][0]),2);return 1-a/i}r.exports=e},{}],46:[function(t,r,n){"use strict";function e(t){if(0===t.length)return NaN;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},{}],47:[function(t,r,n){"use strict";function e(t,r,n){var e=o(t,n);return e.slice(0,r)}var o=t(54);r.exports=e},{54:54}],48:[function(t,r,n){"use strict";function e(t,r){var n=o(t,r),e=i(t),u=i(r);return n/e/u}var o=t(49),i=t(51);r.exports=e},{49:49,51:51}],49:[function(t,r,n){"use strict";function e(t,r){if(t.length<=1||t.length!==r.length)return NaN;for(var n=o(t),e=o(r),i=0,u=0;u<t.length;u++)i+=(t[u]-n)*(r[u]-e);var a=t.length-1;return i/a}var o=t(26);r.exports=e},{26:26}],50:[function(t,r,n){"use strict";function e(t){var r=i(t);if(isNaN(r)||t.length<3)return NaN;var n=t.length,e=Math.pow(r,3),u=o(t,3);return n*u/((n-1)*(n-2)*e)}var o=t(60),i=t(51);r.exports=e},{51:51,60:60}],51:[function(t,r,n){"use strict";function e(t){var r=o(t);return isNaN(r)?NaN:Math.sqrt(r)}var o=t(52);r.exports=e},{52:52}],52:[function(t,r,n){"use strict";function e(t){if(t.length<=1)return NaN;var r=o(t,2),n=t.length-1;return r/n}var o=t(60);r.exports=e},{60:60}],53:[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 u=Math.floor(n()*e);o.push(t[u])}return o}r.exports=e},{}],54:[function(t,r,n){"use strict";function e(t,r){return t=t.slice(),o(t.slice(),r)}var o=t(55);r.exports=e},{55:55}],55:[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},{}],56:[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},{}],57:[function(t,r,n){"use strict";function e(t){var r=o(t);return isNaN(r)?0:Math.sqrt(r)}var o=t(65);r.exports=e},{65:65}],58:[function(t,r,n){"use strict";function e(t){for(var r=t,n=t,e=1;e<15;e++)n*=t*t/(2*e+1),r+=n;return Math.round(1e4*(.5+r/o*Math.exp(-t*t/2)))/1e4}for(var o=Math.sqrt(2*Math.PI),i=[],u=0;u<=3.09;u+=.01)i.push(e(u));r.exports=i},{}],59:[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},{}],60:[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(26);r.exports=e},{26:26}],61:[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},{}],62:[function(t,r,n){"use strict";function e(t,r){var n=i(t),e=o(t),u=Math.sqrt(t.length);return(n-r)/(e/u)}var o=t(57),i=t(26);r.exports=e},{26:26,57:57}],63:[function(t,r,n){"use strict";function e(t,r,n){var e=t.length,u=r.length;if(!e||!u)return null;n||(n=0);var a=o(t),s=o(r),f=i(t),c=i(r);if("number"==typeof a&&"number"==typeof s&&"number"==typeof f&&"number"==typeof c){var h=((e-1)*f+(u-1)*c)/(e+u-2);return(a-s-n)/Math.sqrt(h*(1/e+1/u))}}var o=t(26),i=t(52);r.exports=e},{26:26,52:52}],64:[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},{}],65:[function(t,r,n){"use strict";function e(t){return 0===t.length?NaN:o(t,2)/t.length}var o=t(60);r.exports=e},{60:60}],66:[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(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)}); | ||
//# sourceMappingURL=dist/simple-statistics.min.js.map |
@@ -53,2 +53,4 @@ /* @flow */ | ||
ss.addToMean = require('./src/add_to_mean'); | ||
ss.combineMeans = require('./src/combine_means'); | ||
ss.combineVariances = require('./src/combine_variances'); | ||
ss.geometricMean = require('./src/geometric_mean'); | ||
@@ -59,2 +61,3 @@ ss.harmonicMean = require('./src/harmonic_mean'); | ||
ss.medianSorted = require('./src/median_sorted'); | ||
ss.subtractFromMean = require('./src/subtract_from_mean'); | ||
@@ -61,0 +64,0 @@ ss.rootMeanSquare = ss.rms = require('./src/root_mean_square'); |
{ | ||
"name": "simple-statistics", | ||
"version": "2.5.0", | ||
"version": "3.0.0", | ||
"description": "Simple Statistics", | ||
@@ -5,0 +5,0 @@ "author": "Tom MacWright <tom@macwright.org> (http://macwright.org/)", |
@@ -12,3 +12,5 @@ # Simple Statistics | ||
## :green_book: [API Documentation](http://simplestatistics.org/docs/) | ||
* :green_book: [API Documentation](http://simplestatistics.org/docs/) | ||
* :chart_with_upwards_trend: [Benchmarks](./benchmarks/) | ||
* :kissing: [A list of other statistics libraries](./SEEALSO.md) | ||
@@ -24,17 +26,7 @@ ## Installation | ||
* `https://unpkg.com/simple-statistics@2.5.0/dist/simple-statistics.js` | ||
* Minified: `https://unpkg.com/simple-statistics@2.5.0/dist/simple-statistics.min.js` | ||
* `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` | ||
Bower: | ||
* Bower: `https://unpkg.com/simple-statistics@2.5.0/bower.zip` | ||
## Ports | ||
* Python: [simplestatistics](https://github.com/sheriferson/simplestatistics) is an idiomatic implementation of basic statistical algorithms. | ||
## Examples | ||
* [Linear regression with simple-statistics and d3js](http://bl.ocks.org/3931800) | ||
* [Jenks Natural Breaks with a choropleth map with d3js](http://bl.ocks.org/tmcw/4969184) | ||
* Embedded statistics in a spreadsheet with nxsheet: [regression](https://nxsheet.com/sheets/56d0a87264e47ee60a95f652) and [stddev](https://nxsheet.com/sheets/56d55ca7743aea68490764ba) | ||
* Bower: `https://unpkg.com/simple-statistics@3.0.0/bower.zip` |
@@ -19,2 +19,3 @@ 'use strict'; | ||
* @returns {number} value of bernoulli distribution at this point | ||
* @throws {Error} if p is outside 0 and 1 | ||
* @example | ||
@@ -25,3 +26,5 @@ * bernoulliDistribution(0.5); // => { '0': 0.5, '1': 0.5 } | ||
// Check that `p` is a valid probability (0 ≤ p ≤ 1) | ||
if (p < 0 || p > 1 ) { return NaN; } | ||
if (p < 0 || p > 1 ) { | ||
throw new Error('bernoulliDistribution requires probability to be between 0 and 1 inclusive'); | ||
} | ||
@@ -28,0 +31,0 @@ return binomialDistribution(1, p); |
@@ -10,8 +10,9 @@ 'use strict'; | ||
* | ||
* `sample` is expected to be an array, and `chunkSize` a number. | ||
* The `sample` array can contain any kind of data. | ||
* `x` is expected to be an array, and `chunkSize` a number. | ||
* The `x` array can contain any kind of data. | ||
* | ||
* @param {Array} sample any array of values | ||
* @param {number} chunkSize size of each output array | ||
* @param {Array} x a sample | ||
* @param {number} chunkSize size of each output array. must be a positive integer | ||
* @returns {Array<Array>} a chunked array | ||
* @throws {Error} if chunk size is less than 1 or not an integer | ||
* @example | ||
@@ -21,3 +22,3 @@ * chunk([1, 2, 3, 4, 5, 6], 2); | ||
*/ | ||
function chunk(sample/*:Array<any>*/, chunkSize/*:number*/)/*:?Array<Array<any>>*/ { | ||
function chunk(x/*:Array<any>*/, chunkSize/*:number*/)/*:?Array<Array<any>>*/ { | ||
@@ -31,9 +32,13 @@ // a list of result chunks, as arrays in an array | ||
// invalid input. | ||
if (chunkSize <= 0) { | ||
throw new Error('chunk size must be a positive integer'); | ||
if (chunkSize < 1) { | ||
throw new Error('chunk size must be a positive number'); | ||
} | ||
if (Math.floor(chunkSize) !== chunkSize) { | ||
throw new Error('chunk size must be an integer'); | ||
} | ||
// `start` is the index at which `.slice` will start selecting | ||
// new array elements | ||
for (var start = 0; start < sample.length; start += chunkSize) { | ||
for (var start = 0; start < x.length; start += chunkSize) { | ||
@@ -43,3 +48,3 @@ // for each chunk, slice that part of the array and add it | ||
// the original array. | ||
output.push(sample.slice(start, start + chunkSize)); | ||
output.push(x.slice(start, start + chunkSize)); | ||
} | ||
@@ -46,0 +51,0 @@ return output; |
@@ -207,6 +207,7 @@ 'use strict'; | ||
* from The R Journal Vol. 3/2, December 2011 | ||
* @param {Array<number>} data input data, as an array of number values | ||
* @param {Array<number>} x input data, as an array of number values | ||
* @param {number} nClusters number of desired classes. This cannot be | ||
* greater than the number of values in the data array. | ||
* @returns {Array<Array<number>>} clustered input | ||
* @throws {Error} if the number of requested clusters is higher than the size of the data | ||
* @example | ||
@@ -217,9 +218,9 @@ * ckmeans([-1, 2, -1, 2, 4, 5, 6, -1, 2, -1], 3); | ||
*/ | ||
function ckmeans(data/*: Array<number> */, nClusters/*: number */)/*: Array<Array<number>> */ { | ||
function ckmeans(x/*: Array<number> */, nClusters/*: number */)/*: Array<Array<number>> */ { | ||
if (nClusters > data.length) { | ||
throw new Error('Cannot generate more classes than there are data values'); | ||
if (nClusters > x.length) { | ||
throw new Error('cannot generate more classes than there are data values'); | ||
} | ||
var sorted = numericSort(data), | ||
var sorted = numericSort(x), | ||
// we'll use this as the maximum number of clusters | ||
@@ -226,0 +227,0 @@ uniqueCount = uniqueCountSorted(sorted); |
@@ -6,7 +6,7 @@ /* @flow */ | ||
* Implementation of [Combinations](https://en.wikipedia.org/wiki/Combination) with replacement | ||
* Combinations are unique subsets of a collection - in this case, k elements from a collection at a time. | ||
* Combinations are unique subsets of a collection - in this case, k x from a collection at a time. | ||
* 'With replacement' means that a given element can be chosen multiple times. | ||
* Unlike permutation, order doesn't matter for combinations. | ||
* | ||
* @param {Array} elements any type of data | ||
* @param {Array} x any type of data | ||
* @param {int} k the number of objects in each group (without replacement) | ||
@@ -18,3 +18,3 @@ * @returns {Array<Array>} array of permutations | ||
function combinationsReplacement( | ||
elements /*: Array<any> */, | ||
x /*: Array<any> */, | ||
k /*: number */) { | ||
@@ -24,7 +24,7 @@ | ||
for (var i = 0; i < elements.length; i++) { | ||
for (var i = 0; i < x.length; i++) { | ||
if (k === 1) { | ||
// If we're requested to find only one element, we don't need | ||
// to recurse: just push `elements[i]` onto the list of combinations. | ||
combinationList.push([elements[i]]) | ||
// to recurse: just push `x[i]` onto the list of combinations. | ||
combinationList.push([x[i]]) | ||
} else { | ||
@@ -34,3 +34,3 @@ // Otherwise, recursively find combinations, given `k - 1`. Note that | ||
// requesting k=2. This -1 gets reversed in the for loop right after this | ||
// code, since we concatenate `elements[i]` onto the selected combinations, | ||
// code, since we concatenate `x[i]` onto the selected combinations, | ||
// bringing `k` back up to your requested level. | ||
@@ -40,7 +40,7 @@ // This recursion may go many levels deep, since it only stops once | ||
var subsetCombinations = combinationsReplacement( | ||
elements.slice(i, elements.length), | ||
x.slice(i, x.length), | ||
k - 1); | ||
for (var j = 0; j < subsetCombinations.length; j++) { | ||
combinationList.push([elements[i]] | ||
combinationList.push([x[i]] | ||
.concat(subsetCombinations[j])); | ||
@@ -47,0 +47,0 @@ } |
@@ -5,5 +5,5 @@ /* @flow */ | ||
* Implementation of Combinations | ||
* Combinations are unique subsets of a collection - in this case, k elements from a collection at a time. | ||
* Combinations are unique subsets of a collection - in this case, k x from a collection at a time. | ||
* https://en.wikipedia.org/wiki/Combination | ||
* @param {Array} elements any type of data | ||
* @param {Array} x any type of data | ||
* @param {int} k the number of objects in each group (without replacement) | ||
@@ -15,3 +15,3 @@ * @returns {Array<Array>} array of permutations | ||
function combinations(elements /*: Array<any> */, k/*: number */) { | ||
function combinations(x /*: Array<any> */, k/*: number */) { | ||
var i; | ||
@@ -23,10 +23,10 @@ var subI; | ||
for (i = 0; i < elements.length; i++) { | ||
for (i = 0; i < x.length; i++) { | ||
if (k === 1) { | ||
combinationList.push([elements[i]]) | ||
combinationList.push([x[i]]) | ||
} else { | ||
subsetCombinations = combinations(elements.slice( i + 1, elements.length ), k - 1); | ||
subsetCombinations = combinations(x.slice( i + 1, x.length ), k - 1); | ||
for (subI = 0; subI < subsetCombinations.length; subI++) { | ||
next = subsetCombinations[subI]; | ||
next.unshift(elements[i]); | ||
next.unshift(x[i]); | ||
combinationList.push(next); | ||
@@ -33,0 +33,0 @@ } |
@@ -8,9 +8,9 @@ 'use strict'; | ||
/** | ||
* Given an array of data, this will find the extent of the | ||
* data and return an array of breaks that can be used | ||
* to categorize the data into a number of classes. The | ||
* Given an array of x, this will find the extent of the | ||
* x and return an array of breaks that can be used | ||
* to categorize the x into a number of classes. The | ||
* returned array will always be 1 longer than the number of | ||
* classes because it includes the minimum value. | ||
* | ||
* @param {Array<number>} data input data, as an array of number values | ||
* @param {Array<number>} x an array of number values | ||
* @param {number} nClasses number of desired classes | ||
@@ -21,16 +21,16 @@ * @returns {Array<number>} array of class break positions | ||
*/ | ||
function equalIntervalBreaks(data/*: Array<number> */, nClasses/*:number*/)/*: Array<number> */ { | ||
function equalIntervalBreaks(x/*: Array<number> */, nClasses/*:number*/)/*: Array<number> */ { | ||
if (data.length <= 1) { | ||
return data; | ||
if (x.length < 2) { | ||
return x; | ||
} | ||
var theMin = min(data), | ||
theMax = max(data); | ||
var theMin = min(x), | ||
theMax = max(x); | ||
// the first break will always be the minimum value | ||
// in the dataset | ||
// in the xset | ||
var breaks = [theMin]; | ||
// The size of each break is the full range of the data | ||
// The size of each break is the full range of the x | ||
// divided by the number of classes requested | ||
@@ -37,0 +37,0 @@ var breakSize = (theMax - theMin) / nClasses; |
@@ -10,4 +10,5 @@ 'use strict'; | ||
* | ||
* @param {number} n input | ||
* @param {number} n input, must be an integer number 1 or greater | ||
* @returns {number} factorial: n! | ||
* @throws {Error} if n is less than 0 or not an integer | ||
* @example | ||
@@ -19,4 +20,10 @@ * factorial(5); // => 120 | ||
// factorial is mathematically undefined for negative numbers | ||
if (n < 0) { return NaN; } | ||
if (n < 0) { | ||
throw new Error('factorial requires an integer input'); | ||
} | ||
if (Math.floor(n) !== n) { | ||
throw new Error('factorial requires a non-negative value'); | ||
} | ||
// typically you'll expand the factorial function going down, like | ||
@@ -23,0 +30,0 @@ // 5! = 5 * 4 * 3 * 2 * 1. This is going in the opposite direction, |
@@ -20,4 +20,6 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x input array | ||
* @param {Array<number>} x sample of one or more data points | ||
* @returns {number} geometric mean | ||
* @throws {Error} if x is empty | ||
* @throws {Error} if x contains a negative number | ||
* @example | ||
@@ -39,3 +41,5 @@ * var growthRates = [1.80, 1.166666, 1.428571]; | ||
// The mean of no numbers is null | ||
if (x.length === 0) { return undefined; } | ||
if (x.length === 0) { | ||
throw new Error('geometricMean requires at least one data point'); | ||
} | ||
@@ -47,3 +51,5 @@ // the starting value. | ||
// the geometric mean is only valid for positive numbers | ||
if (x[i] <= 0) { return undefined; } | ||
if (x[i] <= 0) { | ||
throw new Error('geometricMean requires only positive numbers as input'); | ||
} | ||
@@ -50,0 +56,0 @@ // repeatedly multiply the value by each number |
@@ -15,4 +15,6 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x input | ||
* @param {Array<number>} x sample of one or more data points | ||
* @returns {number} harmonic mean | ||
* @throws {Error} if x is empty | ||
* @throws {Error} if x contains a negative number | ||
* @example | ||
@@ -23,3 +25,5 @@ * harmonicMean([2, 3]).toFixed(2) // => '2.40' | ||
// The mean of no numbers is null | ||
if (x.length === 0) { return undefined; } | ||
if (x.length === 0) { | ||
throw new Error('harmonicMean requires at least one data point'); | ||
} | ||
@@ -30,3 +34,5 @@ var reciprocalSum = 0; | ||
// the harmonic mean is only valid for positive numbers | ||
if (x[i] <= 0) { return undefined; } | ||
if (x[i] <= 0) { | ||
throw new Error('harmonicMean requires only positive numbers as input'); | ||
} | ||
@@ -33,0 +39,0 @@ reciprocalSum += 1 / x[i]; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} sample | ||
* @param {Array<number>} x sample of one or more numbers | ||
* @returns {number} interquartile range: the span between lower and upper quartile, | ||
@@ -19,7 +19,7 @@ * 0.25 and 0.75 | ||
*/ | ||
function interquartileRange(sample/*: Array<number> */) { | ||
function interquartileRange(x/*: Array<number> */) { | ||
// Interquartile range is the span between the upper quartile, | ||
// at `0.75`, and lower quartile, `0.25` | ||
var q1 = quantile(sample, 0.75), | ||
q2 = quantile(sample, 0.25); | ||
var q1 = quantile(x, 0.75), | ||
q2 = quantile(x, 0.25); | ||
@@ -26,0 +26,0 @@ if (typeof q1 === 'number' && typeof q2 === 'number') { |
@@ -9,4 +9,5 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x input | ||
* @param {Array<number>} x sample of one or more data points | ||
* @returns {number} maximum value | ||
* @throws {Error} if the the length of x is less than one | ||
* @example | ||
@@ -26,3 +27,3 @@ * max([1, 2, 3, 4]); | ||
if (value === undefined) { | ||
return NaN; | ||
throw new Error('max requires at least one data point'); | ||
} | ||
@@ -29,0 +30,0 @@ return value; |
@@ -14,3 +14,4 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x input values | ||
* @param {Array<number>} x sample of one or more data points | ||
* @throws {Error} if the the length of x is less than one | ||
* @returns {number} mean | ||
@@ -22,3 +23,5 @@ * @example | ||
// The mean of no numbers is null | ||
if (x.length === 0) { return NaN; } | ||
if (x.length === 0) { | ||
throw new Error('mean requires at least one data point'); | ||
} | ||
@@ -25,0 +28,0 @@ return sum(x) / x.length; |
@@ -7,3 +7,4 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x input | ||
* @param {Array<number>} x sample of one or more data points | ||
* @throws {Error} if the the length of x is less than one | ||
* @returns {number} minimum value | ||
@@ -23,3 +24,3 @@ * @example | ||
if (value === undefined) { | ||
return NaN; | ||
throw new Error('min requires at least one data point'); | ||
} | ||
@@ -26,0 +27,0 @@ return value; |
@@ -14,2 +14,3 @@ 'use strict'; | ||
* by changing the global `Array.prototype`. | ||
* @throws {Error} if the JavaScript environment doesn't support Object.defineProperty | ||
* @returns {*} the extended Array, or Array.prototype if no object | ||
@@ -16,0 +17,0 @@ * is given. |
@@ -20,5 +20,6 @@ 'use strict'; | ||
* | ||
* @param {Array<*>} x input | ||
* @param {Array<*>} x a sample of one or more data points | ||
* @returns {?*} mode | ||
* @throws {ReferenceError} if the JavaScript environment doesn't support Map | ||
* @throws {Error} if x is empty | ||
* @example | ||
@@ -52,2 +53,6 @@ * modeFast(['rabbits', 'rabbits', 'squirrels']); // => 'rabbits' | ||
if (modeCount === 0) { | ||
throw new Error('mode requires at last one data point'); | ||
} | ||
return mode; | ||
@@ -54,0 +59,0 @@ } |
@@ -14,4 +14,5 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} sorted input | ||
* @param {Array<number>} sorted a sample of one or more data points | ||
* @returns {number} mode | ||
* @throws {Error} if sorted is empty | ||
* @example | ||
@@ -23,5 +24,8 @@ * modeSorted([0, 0, 1]); // => 0 | ||
// Handle edge cases: | ||
// The mode of an empty list is NaN | ||
if (sorted.length === 0) { return NaN; } | ||
else if (sorted.length === 1) { return sorted[0]; } | ||
// The mode of an empty list is undefined | ||
if (sorted.length === 0) { | ||
throw new Error('mode requires at least one data point'); | ||
} else if (sorted.length === 1) { | ||
return sorted[0]; | ||
} | ||
@@ -28,0 +32,0 @@ // This assumes it is dealing with an array of size > 1, since size |
@@ -15,3 +15,3 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} array input array | ||
* @param {Array<number>} x input array | ||
* @return {Array<number>} sorted array | ||
@@ -22,4 +22,4 @@ * @private | ||
*/ | ||
function numericSort(array /*: Array<number> */) /*: Array<number> */ { | ||
return array | ||
function numericSort(x /*: Array<number> */) /*: Array<number> */ { | ||
return x | ||
// ensure the array is not changed in-place | ||
@@ -26,0 +26,0 @@ .slice() |
@@ -9,29 +9,33 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} sample input data | ||
* @param {Array<number>} x sample of one or more data points | ||
* @param {number} p desired quantile: a number between 0 to 1, inclusive | ||
* @returns {number} quantile value | ||
* @throws {Error} if p ix outside of the range from 0 to 1 | ||
* @throws {Error} if x is empty | ||
* @example | ||
* quantileSorted([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], 0.5); // => 9 | ||
*/ | ||
function quantileSorted(sample /*: Array<number> */, p /*: number */)/*:number*/ { | ||
var idx = sample.length * p; | ||
if (p < 0 || p > 1) { | ||
return NaN; | ||
function quantileSorted(x /*: Array<number> */, p /*: number */)/*:number*/ { | ||
var idx = x.length * p; | ||
if (x.length === 0) { | ||
throw new Error('quantile requires at least one data point.'); | ||
} else if (p < 0 || p > 1) { | ||
throw new Error('quantiles must be between 0 and 1'); | ||
} else if (p === 1) { | ||
// If p is 1, directly return the last element | ||
return sample[sample.length - 1]; | ||
return x[x.length - 1]; | ||
} else if (p === 0) { | ||
// If p is 0, directly return the first element | ||
return sample[0]; | ||
return x[0]; | ||
} else if (idx % 1 !== 0) { | ||
// If p is not integer, return the next element in array | ||
return sample[Math.ceil(idx) - 1]; | ||
} else if (sample.length % 2 === 0) { | ||
return x[Math.ceil(idx) - 1]; | ||
} else if (x.length % 2 === 0) { | ||
// If the list has even-length, we'll take the average of this number | ||
// and the next value, if there is one | ||
return (sample[idx - 1] + sample[idx]) / 2; | ||
return (x[idx - 1] + x[idx]) / 2; | ||
} else { | ||
// Finally, in the simple case of an integer value | ||
// with an odd-length list, return the sample value at the index. | ||
return sample[idx]; | ||
// with an odd-length list, return the x value at the index. | ||
return x[idx]; | ||
} | ||
@@ -38,0 +42,0 @@ } |
@@ -22,3 +22,3 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} sample a sample from the population | ||
* @param {Array<number>} x sample of one or more numbers | ||
* @param {number} p the desired quantile, as a number between 0 and 1 | ||
@@ -29,4 +29,4 @@ * @returns {number} quantile | ||
*/ | ||
function quantile(sample /*: Array<number> */, p /*: Array<number> | number */) { | ||
var copy = sample.slice(); | ||
function quantile(x /*: Array<number> */, p /*: Array<number> | number */) { | ||
var copy = x.slice(); | ||
@@ -33,0 +33,0 @@ if (Array.isArray(p)) { |
@@ -10,3 +10,3 @@ 'use strict'; | ||
* | ||
* @param {Array<Array<number>>} data input data: this should be doubly-nested | ||
* @param {Array<Array<number>>} x input data: this should be doubly-nested | ||
* @param {Function} func function called on `[i][0]` values within the dataset | ||
@@ -19,4 +19,4 @@ * @returns {number} r-squared value | ||
*/ | ||
function rSquared(data /*: Array<Array<number>> */, func /*: Function */) /*: number */ { | ||
if (data.length < 2) { return 1; } | ||
function rSquared(x /*: Array<Array<number>> */, func /*: Function */) /*: number */ { | ||
if (x.length < 2) { return 1; } | ||
@@ -27,6 +27,6 @@ // Compute the average y value for the actual | ||
var sum = 0, average; | ||
for (var i = 0; i < data.length; i++) { | ||
sum += data[i][1]; | ||
for (var i = 0; i < x.length; i++) { | ||
sum += x[i][1]; | ||
} | ||
average = sum / data.length; | ||
average = sum / x.length; | ||
@@ -37,4 +37,4 @@ // Compute the total sum of squares - the | ||
var sumOfSquares = 0; | ||
for (var j = 0; j < data.length; j++) { | ||
sumOfSquares += Math.pow(average - data[j][1], 2); | ||
for (var j = 0; j < x.length; j++) { | ||
sumOfSquares += Math.pow(average - x[j][1], 2); | ||
} | ||
@@ -46,4 +46,4 @@ | ||
var err = 0; | ||
for (var k = 0; k < data.length; k++) { | ||
err += Math.pow(data[k][1] - func(data[k][0]), 2); | ||
for (var k = 0; k < x.length; k++) { | ||
err += Math.pow(x[k][1] - func(x[k][0]), 2); | ||
} | ||
@@ -50,0 +50,0 @@ |
@@ -12,4 +12,5 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x input | ||
* @param {Array<number>} x a sample of one or more data points | ||
* @returns {number} root mean square | ||
* @throws {Error} if x is empty | ||
* @example | ||
@@ -19,3 +20,5 @@ * rootMeanSquare([-1, 1, -1, 1]); // => 1 | ||
function rootMeanSquare(x /*: Array<number> */)/*:number*/ { | ||
if (x.length === 0) { return NaN; } | ||
if (x.length === 0) { | ||
throw new Error('rootMeanSquare requires at least one data point'); | ||
} | ||
@@ -22,0 +25,0 @@ var sumOfSquares = 0; |
@@ -11,4 +11,6 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x first input | ||
* @param {Array<number>} y second input | ||
* @param {Array<number>} x a sample of two or more data points | ||
* @param {Array<number>} y a sample of two or more data points | ||
* @throws {Error} if x and y do not have equal lengths | ||
* @throws {Error} if x or y have length of one or less | ||
* @returns {number} sample covariance | ||
@@ -21,6 +23,10 @@ * @example | ||
// The two datasets must have the same length which must be more than 1 | ||
if (x.length <= 1 || x.length !== y.length) { | ||
return NaN; | ||
if (x.length !== y.length) { | ||
throw new Error('sampleCovariance requires samples with equal lengths'); | ||
} | ||
if (x.length < 2) { | ||
throw new Error('sampleCovariance requires at least two data points in each sample'); | ||
} | ||
// determine the mean of each dataset so that we can judge each | ||
@@ -27,0 +33,0 @@ // value of the dataset fairly as the difference from the mean. this |
@@ -17,4 +17,5 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x input | ||
* @param {Array<number>} x a sample of 3 or more data points | ||
* @returns {number} sample skewness | ||
* @throws {Error} if x has length of 3 or less | ||
* @example | ||
@@ -27,4 +28,4 @@ * sampleSkewness([2, 4, 6, 3, 1]); // => 0.590128656384365 | ||
if (isNaN(theSampleStandardDeviation) || x.length < 3) { | ||
return NaN; | ||
if (x.length < 3) { | ||
throw new Error('sampleSkewness requires at least three data points'); | ||
} | ||
@@ -31,0 +32,0 @@ |
@@ -19,3 +19,2 @@ 'use strict'; | ||
var sampleVarianceX = sampleVariance(x); | ||
if (isNaN(sampleVarianceX)) { return NaN; } | ||
return Math.sqrt(sampleVarianceX); | ||
@@ -22,0 +21,0 @@ } |
@@ -17,3 +17,4 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x input array | ||
* @param {Array<number>} x a sample of two or more data points | ||
* @throws {Error} if the length of x is less than 2 | ||
* @return {number} sample variance | ||
@@ -25,3 +26,5 @@ * @example | ||
// The variance of no numbers is null | ||
if (x.length <= 1) { return NaN; } | ||
if (x.length < 2) { | ||
throw new Error('sampleVariance requires at least two data points'); | ||
} | ||
@@ -28,0 +31,0 @@ var sumSquaredDeviationsValue = sumNthPowerDeviations(x, 2); |
@@ -8,3 +8,3 @@ 'use strict'; | ||
* | ||
* @param {Array} population an array of any kind of element | ||
* @param {Array<*>} x an array of any kind of value | ||
* @param {number} n count of how many elements to take | ||
@@ -18,7 +18,7 @@ * @param {Function} [randomSource=Math.random] an optional entropy source that | ||
*/ | ||
function sampleWithReplacement/*::<T>*/(population/*:Array<T>*/, | ||
function sampleWithReplacement/*::<T>*/(x/*:Array<T>*/, | ||
n /*: number */, | ||
randomSource/*:Function*/) { | ||
if (population.length === 0) { | ||
if (x.length === 0) { | ||
return []; | ||
@@ -32,3 +32,3 @@ } | ||
var length = population.length; | ||
var length = x.length; | ||
var sample = []; | ||
@@ -39,3 +39,3 @@ | ||
sample.push(population[index]); | ||
sample.push(x[index]); | ||
} | ||
@@ -42,0 +42,0 @@ |
@@ -13,3 +13,3 @@ 'use strict'; | ||
* | ||
* @param {Array} array input array. can contain any type | ||
* @param {Array<any>} x input array. can contain any type | ||
* @param {number} n count of how many elements to take | ||
@@ -24,7 +24,7 @@ * @param {Function} [randomSource=Math.random] an optional entropy source that | ||
function sample/*:: <T> */( | ||
array /*: Array<T> */, | ||
x /*: Array<T> */, | ||
n /*: number */, | ||
randomSource /*: Function */) /*: Array<T> */ { | ||
// shuffle the original array using a fisher-yates shuffle | ||
var shuffled = shuffle(array, randomSource); | ||
var shuffled = shuffle(x, randomSource); | ||
@@ -31,0 +31,0 @@ // and then return a subset of it - the first `n` elements. |
@@ -12,14 +12,13 @@ 'use strict'; | ||
* | ||
* @param {Array} sample input array | ||
* @param {Array} x sample of one or more numbers | ||
* @param {Function} [randomSource=Math.random] an optional entropy source that | ||
* returns numbers between 0 inclusive and 1 exclusive: the range [0, 1) | ||
* @returns {Array} sample | ||
* @returns {Array} x | ||
* @example | ||
* var sample = [1, 2, 3, 4]; | ||
* shuffleInPlace(sample); | ||
* // sample is shuffled to a value like [2, 1, 4, 3] | ||
* var x = [1, 2, 3, 4]; | ||
* shuffleInPlace(x); | ||
* // x is shuffled to a value like [2, 1, 4, 3] | ||
*/ | ||
function shuffleInPlace(sample/*:Array<any>*/, randomSource/*:Function*/)/*:Array<any>*/ { | ||
function shuffleInPlace(x/*:Array<any>*/, randomSource/*:Function*/)/*:Array<any>*/ { | ||
// a custom random number source can be provided if you want to use | ||
@@ -30,5 +29,5 @@ // a fixed seed or another random number generator, like | ||
// store the current length of the sample to determine | ||
// store the current length of the x to determine | ||
// when no elements remain to shuffle. | ||
var length = sample.length; | ||
var length = x.length; | ||
@@ -49,12 +48,12 @@ // temporary is used to hold an item when it is being | ||
// store the value that we'll move temporarily | ||
temporary = sample[length]; | ||
temporary = x[length]; | ||
// swap the value at `sample[length]` with `sample[index]` | ||
sample[length] = sample[index]; | ||
sample[index] = temporary; | ||
// swap the value at `x[length]` with `x[index]` | ||
x[length] = x[index]; | ||
x[index] = temporary; | ||
} | ||
return sample; | ||
return x; | ||
} | ||
module.exports = shuffleInPlace; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
* | ||
* @param {Array} sample an array of any kind of element | ||
* @param {Array} x sample of 0 or more numbers | ||
* @param {Function} [randomSource=Math.random] an optional entropy source that | ||
@@ -21,5 +21,5 @@ * returns numbers between 0 inclusive and 1 exclusive: the range [0, 1) | ||
*/ | ||
function shuffle/*::<T>*/(sample/*:Array<T>*/, randomSource/*:Function*/) { | ||
function shuffle/*::<T>*/(x/*:Array<T>*/, randomSource/*:Function*/) { | ||
// slice the original array so that it is not modified | ||
sample = sample.slice(); | ||
var sample = x.slice(); | ||
@@ -26,0 +26,0 @@ // and then shuffle that shallow-copied array, in place |
@@ -8,3 +8,4 @@ 'use strict'; | ||
* The [standard deviation](http://en.wikipedia.org/wiki/Standard_deviation) | ||
* is the square root of the variance. It's useful for measuring the amount | ||
* is the square root of the variance. This is also known as the population | ||
* standard deviation. It's useful for measuring the amount | ||
* of variation or dispersion in a set of values. | ||
@@ -23,5 +24,6 @@ * | ||
function standardDeviation(x /*: Array<number> */)/*:number*/ { | ||
// The standard deviation of no numbers is null | ||
if (x.length === 1) { | ||
return 0; | ||
} | ||
var v = variance(x); | ||
if (isNaN(v)) { return 0; } | ||
return Math.sqrt(v); | ||
@@ -28,0 +30,0 @@ } |
@@ -18,4 +18,4 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} sample an array of numbers as input | ||
* @param {number} x expected value of the population mean | ||
* @param {Array<number>} x sample of one or more numbers | ||
* @param {number} expectedValue expected value of the population mean | ||
* @returns {number} value | ||
@@ -25,16 +25,16 @@ * @example | ||
*/ | ||
function tTest(sample/*: Array<number> */, x/*: number */)/*:number*/ { | ||
function tTest(x/*: Array<number> */, expectedValue/*: number */)/*:number*/ { | ||
// The mean of the sample | ||
var sampleMean = mean(sample); | ||
var sampleMean = mean(x); | ||
// The standard deviation of the sample | ||
var sd = standardDeviation(sample); | ||
var sd = standardDeviation(x); | ||
// Square root the length of the sample | ||
var rootN = Math.sqrt(sample.length); | ||
var rootN = Math.sqrt(x.length); | ||
// returning the t value | ||
return (sampleMean - x) / (sd / rootN); | ||
return (sampleMean - expectedValue) / (sd / rootN); | ||
} | ||
module.exports = tTest; |
@@ -12,3 +12,3 @@ 'use strict'; | ||
* | ||
* @param {Array} input an array of primitive values. | ||
* @param {Array<*>} x an array of any kind of value | ||
* @returns {number} count of unique values | ||
@@ -19,8 +19,8 @@ * @example | ||
*/ | ||
function uniqueCountSorted(input/*: Array<any>*/)/*: number */ { | ||
function uniqueCountSorted(x/*: Array<any>*/)/*: number */ { | ||
var uniqueValueCount = 0, | ||
lastSeenValue; | ||
for (var i = 0; i < input.length; i++) { | ||
if (i === 0 || input[i] !== lastSeenValue) { | ||
lastSeenValue = input[i]; | ||
for (var i = 0; i < x.length; i++) { | ||
if (i === 0 || x[i] !== lastSeenValue) { | ||
lastSeenValue = x[i]; | ||
uniqueValueCount++; | ||
@@ -27,0 +27,0 @@ } |
@@ -13,5 +13,6 @@ 'use strict'; | ||
* | ||
* @param {Array<number>} x a population | ||
* @param {Array<number>} x a population of one or more data points | ||
* @returns {number} variance: a value greater than or equal to zero. | ||
* zero indicates that all values are identical. | ||
* @throws {Error} if x's length is 0 | ||
* @example | ||
@@ -22,3 +23,5 @@ * variance([1, 2, 3, 4, 5, 6]); // => 2.9166666666666665 | ||
// The variance of no numbers is null | ||
if (x.length === 0) { return NaN; } | ||
if (x.length === 0) { | ||
throw new Error('variance requires at least one data point'); | ||
} | ||
@@ -25,0 +28,0 @@ // Find the mean of squared deviations between the |
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
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
569703
78
6802
31