spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[KURT] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-25 17:25:23
stats
7 file(s) changed, 88 insertions(+), 5 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Statistical.js
src/Formulas/AllFormulas.ts
src/Formulas/Statistical.ts
tests/Formulas/StatisticalTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index ad837e3..11ee145 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -1545,6 +1545,15 @@
  6 @param n - N in 'Nth'. 
  7 @constructor
  8 ```
  9+
 10+### KURT 
 11+
 12+```
 13+  Returns the kurtosis of a data set or range. Ignores text values. 
 14+@param values - data set or range to calculate. Must be at least 4 values. 
 15+@returns {number} 
 16+@constructor
 17+```
 18 ## Text
 19 
 20 
 21diff --git a/TODO.md b/TODO.md
 22index ebb86f6..ee0ea41 100644
 23--- a/TODO.md
 24+++ b/TODO.md
 25@@ -69,7 +69,6 @@ For example 64 tbs to a qt.
 26 * HARMEAN
 27 * HYPGEOMDIST
 28 * INTERCEPT
 29-* KURT
 30 * LOGINV
 31 * LOGNORMDIST
 32 * MODE
 33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 34index 953b403..c95b202 100644
 35--- a/dist/Formulas/AllFormulas.js
 36+++ b/dist/Formulas/AllFormulas.js
 37@@ -140,6 +140,7 @@ exports.SLOPE = Statistical_1.SLOPE;
 38 exports.STANDARDIZE = Statistical_1.STANDARDIZE;
 39 exports.SMALL = Statistical_1.SMALL;
 40 exports.LARGE = Statistical_1.LARGE;
 41+exports.KURT = Statistical_1.KURT;
 42 var Text_1 = require("./Text");
 43 exports.ARABIC = Text_1.ARABIC;
 44 exports.CHAR = Text_1.CHAR;
 45diff --git a/dist/Formulas/Statistical.js b/dist/Formulas/Statistical.js
 46index bc9ef79..c44d47d 100644
 47--- a/dist/Formulas/Statistical.js
 48+++ b/dist/Formulas/Statistical.js
 49@@ -820,3 +820,33 @@ var LARGE = function (range, n) {
 50     return data[n - 1];
 51 };
 52 exports.LARGE = LARGE;
 53+/**
 54+ * Returns the kurtosis of a data set or range. Ignores text values.
 55+ * @param values - data set or range to calculate. Must be at least 4 values.
 56+ * @returns {number}
 57+ * @constructor
 58+ */
 59+var KURT = function () {
 60+    var values = [];
 61+    for (var _i = 0; _i < arguments.length; _i++) {
 62+        values[_i] = arguments[_i];
 63+    }
 64+    ArgsChecker_1.ArgsChecker.checkAtLeastLength(values, 4, "KURT");
 65+    var range = Filter_1.Filter.flattenAndThrow(values).filter(function (value) {
 66+        return typeof value !== "string";
 67+    }).map(function (value) {
 68+        return TypeConverter_1.TypeConverter.valueToNumber(value);
 69+    });
 70+    if (range.length < 4) {
 71+        throw new Errors_1.DivZeroError("KURT requires more values in range. Expected: 4, found: " + range.length + ".");
 72+    }
 73+    var m = MathHelpers_1.mean(range);
 74+    var n = range.length;
 75+    var sigma = 0;
 76+    for (var i = 0; i < n; i++) {
 77+        sigma += Math.pow(range[i] - m, 4);
 78+    }
 79+    sigma = sigma / Math.pow(MathHelpers_1.stdev(range, true), 4);
 80+    return ((n * (n + 1)) / ((n - 1) * (n - 2) * (n - 3))) * sigma - 3 * (n - 1) * (n - 1) / ((n - 2) * (n - 3));
 81+};
 82+exports.KURT = KURT;
 83diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 84index be65348..88de407 100644
 85--- a/src/Formulas/AllFormulas.ts
 86+++ b/src/Formulas/AllFormulas.ts
 87@@ -145,7 +145,8 @@ import {
 88   SLOPE,
 89   STANDARDIZE,
 90   SMALL,
 91-  LARGE
 92+  LARGE,
 93+  KURT
 94 } from "./Statistical";
 95 import {
 96   ARABIC,
 97@@ -359,5 +360,6 @@ export {
 98   UPPER,
 99   STANDARDIZE,
100   SMALL,
101-  LARGE
102+  LARGE,
103+  KURT
104 }
105\ No newline at end of file
106diff --git a/src/Formulas/Statistical.ts b/src/Formulas/Statistical.ts
107index 2ee9500..3a27215 100644
108--- a/src/Formulas/Statistical.ts
109+++ b/src/Formulas/Statistical.ts
110@@ -804,6 +804,33 @@ var LARGE =  function (range, n) {
111 };
112 
113 
114+/**
115+ * Returns the kurtosis of a data set or range. Ignores text values.
116+ * @param values - data set or range to calculate. Must be at least 4 values.
117+ * @returns {number}
118+ * @constructor
119+ */
120+var KURT = function (...values) {
121+  ArgsChecker.checkAtLeastLength(values, 4, "KURT");
122+  var range = Filter.flattenAndThrow(values).filter(function (value) {
123+    return typeof value !== "string";
124+  }).map(function (value) {
125+    return TypeConverter.valueToNumber(value);
126+  });
127+  if (range.length < 4) {
128+    throw new DivZeroError("KURT requires more values in range. Expected: 4, found: " + range.length + ".");
129+  }
130+  var m = mean(range);
131+  var n = range.length;
132+  var sigma = 0;
133+  for (var i = 0; i < n; i++) {
134+    sigma += Math.pow(range[i] - m, 4);
135+  }
136+  sigma = sigma / Math.pow(stdev(range, true), 4);
137+  return ((n * (n + 1)) / ((n - 1) * (n - 2) * (n - 3))) * sigma - 3 * (n - 1) * (n - 1) / ((n - 2) * (n - 3));
138+};
139+
140+
141 export {
142   AVERAGE,
143   AVERAGEA,
144@@ -834,5 +861,6 @@ export {
145   SLOPE,
146   STANDARDIZE,
147   SMALL,
148-  LARGE
149+  LARGE,
150+  KURT
151 }
152\ No newline at end of file
153diff --git a/tests/Formulas/StatisticalTest.ts b/tests/Formulas/StatisticalTest.ts
154index f05a438..ca78622 100644
155--- a/tests/Formulas/StatisticalTest.ts
156+++ b/tests/Formulas/StatisticalTest.ts
157@@ -28,7 +28,8 @@ import {
158   SLOPE,
159   STANDARDIZE,
160   SMALL,
161-  LARGE
162+  LARGE,
163+  KURT
164 } from "../../src/Formulas/Statistical";
165 import * as ERRORS from "../../src/Errors";
166 import {
167@@ -639,4 +640,16 @@ test("LARGE", function() {
168   catchAndAssertEquals(function() {
169     LARGE.apply(this, [[44, 2.1], 3, 4]);
170   }, ERRORS.NA_ERROR);
171+});
172+
173+test("KURT", function() {
174+  assertEquals(KURT(3, 4, 5, 6, 9, 11, 15), -0.23508087990005144);
175+  assertEquals(KURT(3, 4, 5, 6, 9, 11, 15, "ignore"), -0.23508087990005144);
176+  assertEquals(KURT(11, 15, 11, 1), 2.602498034762867);
177+  catchAndAssertEquals(function() {
178+    KURT(1, 2, 3);
179+  }, ERRORS.NA_ERROR);
180+  catchAndAssertEquals(function() {
181+    KURT(1, 2, 3, "ignore");
182+  }, ERRORS.DIV_ZERO_ERROR);
183 });
184\ No newline at end of file