spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[STDEVPA] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-15 01:51:05
stats
8 file(s) changed, 107 insertions(+), 8 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
tests/SheetFormulaTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index ccd8418..f6b9595 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -1409,6 +1409,15 @@
  6 @returns {number} 
  7 @constructor
  8 ```
  9+
 10+### STDEVPA 
 11+
 12+```
 13+  Calculates the standard deviation of an entire population, including text and boolean values, if possible. If a value cannot be converted to a number, formula will throw a value error. 
 14+@param values - Entire sample. 
 15+@returns {number} 
 16+@constructor
 17+```
 18 ## Text
 19 
 20 
 21diff --git a/TODO.md b/TODO.md
 22index 7458763..dd6c06e 100644
 23--- a/TODO.md
 24+++ b/TODO.md
 25@@ -99,7 +99,6 @@ For example 64 tbs to a qt.
 26 * SLOPE
 27 * SMALL
 28 * STANDARDIZE
 29-* STDEVPA
 30 * STEYX
 31 * T.INV
 32 * T.INV.2T
 33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 34index 14c7aa6..3244e7e 100644
 35--- a/dist/Formulas/AllFormulas.js
 36+++ b/dist/Formulas/AllFormulas.js
 37@@ -125,6 +125,7 @@ exports.PERCENTILE = Statistical_1.PERCENTILE;
 38 exports.STDEV = Statistical_1.STDEV;
 39 exports.STDEVA = Statistical_1.STDEVA;
 40 exports.STDEVP = Statistical_1.STDEVP;
 41+exports.STDEVPA = Statistical_1.STDEVPA;
 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 3fbff6c..ed6e4af 100644
 47--- a/dist/Formulas/Statistical.js
 48+++ b/dist/Formulas/Statistical.js
 49@@ -653,14 +653,44 @@ var STDEVP = function () {
 50     var n = range.length;
 51     var sigma = 0;
 52     var count = 0;
 53-    var mean = AVERAGE(range);
 54+    var m = AVERAGE(range);
 55     for (var i = 0; i < n; i++) {
 56         var value = TypeConverter_1.TypeConverter.firstValue(range[i]);
 57         if (typeof value !== "string") {
 58-            sigma += Math.pow(value - mean, 2);
 59+            sigma += Math.pow(value - m, 2);
 60             count++;
 61         }
 62     }
 63     return Math.sqrt(sigma / count);
 64 };
 65 exports.STDEVP = STDEVP;
 66+/**
 67+ * Calculates the standard deviation of an entire population, including text and boolean values, if possible. If a value
 68+ * cannot be converted to a number, formula will throw a value error.
 69+ * @param values - Entire sample.
 70+ * @returns {number}
 71+ * @constructor
 72+ */
 73+var STDEVPA = function () {
 74+    var values = [];
 75+    for (var _i = 0; _i < arguments.length; _i++) {
 76+        values[_i] = arguments[_i];
 77+    }
 78+    ArgsChecker_1.ArgsChecker.checkAtLeastLength(arguments, 1, "STDEVPA");
 79+    var range = Filter_1.Filter.flattenAndThrow(values).map(function (value) {
 80+        return TypeConverter_1.TypeConverter.firstValueAsNumber(value);
 81+    });
 82+    var n = range.length;
 83+    var sigma = 0;
 84+    var count = 0;
 85+    var m = AVERAGE(range);
 86+    for (var i = 0; i < n; i++) {
 87+        var value = TypeConverter_1.TypeConverter.firstValue(range[i]);
 88+        if (typeof value !== "string") {
 89+            sigma += Math.pow(value - m, 2);
 90+            count++;
 91+        }
 92+    }
 93+    return Math.sqrt(sigma / count);
 94+};
 95+exports.STDEVPA = STDEVPA;
 96diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 97index dc209cb..4e4b67d 100644
 98--- a/src/Formulas/AllFormulas.ts
 99+++ b/src/Formulas/AllFormulas.ts
100@@ -129,7 +129,8 @@ import {
101   PERCENTILE,
102   STDEV,
103   STDEVA,
104-  STDEVP
105+  STDEVP,
106+  STDEVPA
107 } from "./Statistical";
108 import {
109   ARABIC,
110@@ -325,5 +326,6 @@ export {
111   UMINUS,
112   STDEV,
113   STDEVA,
114-  STDEVP
115+  STDEVP,
116+  STDEVPA
117 }
118\ No newline at end of file
119diff --git a/src/Formulas/Statistical.ts b/src/Formulas/Statistical.ts
120index 53f123b..edb8903 100644
121--- a/src/Formulas/Statistical.ts
122+++ b/src/Formulas/Statistical.ts
123@@ -631,11 +631,38 @@ var STDEVP = function (...values) {
124   var n = range.length;
125   var sigma = 0;
126   var count = 0;
127-  var mean = AVERAGE(range);
128+  var m = AVERAGE(range);
129+  for (var i = 0; i < n; i++) {
130+    var value = TypeConverter.firstValue(range[i]);
131+    if (typeof value !== "string") {
132+      sigma += Math.pow(value - m, 2);
133+      count++;
134+    }
135+  }
136+  return Math.sqrt(sigma / count);
137+};
138+
139+
140+/**
141+ * Calculates the standard deviation of an entire population, including text and boolean values, if possible. If a value
142+ * cannot be converted to a number, formula will throw a value error.
143+ * @param values - Entire sample.
144+ * @returns {number}
145+ * @constructor
146+ */
147+var STDEVPA = function (...values) {
148+  ArgsChecker.checkAtLeastLength(arguments, 1, "STDEVPA");
149+  var range = Filter.flattenAndThrow(values).map(function (value) {
150+    return TypeConverter.firstValueAsNumber(value);
151+  });
152+  var n = range.length;
153+  var sigma = 0;
154+  var count = 0;
155+  var m = AVERAGE(range);
156   for (var i = 0; i < n; i++) {
157     var value = TypeConverter.firstValue(range[i]);
158     if (typeof value !== "string") {
159-      sigma += Math.pow(value - mean, 2);
160+      sigma += Math.pow(value - m, 2);
161       count++;
162     }
163   }
164@@ -667,5 +694,6 @@ export {
165   PERCENTILE,
166   STDEV,
167   STDEVA,
168-  STDEVP
169+  STDEVP,
170+  STDEVPA
171 }
172\ No newline at end of file
173diff --git a/tests/Formulas/StatisticalTest.ts b/tests/Formulas/StatisticalTest.ts
174index 2e831fe..35105ca 100644
175--- a/tests/Formulas/StatisticalTest.ts
176+++ b/tests/Formulas/StatisticalTest.ts
177@@ -22,7 +22,8 @@ import {
178   PERCENTILE,
179   STDEV,
180   STDEVA,
181-  STDEVP
182+  STDEVP,
183+  STDEVPA
184 } from "../../src/Formulas/Statistical";
185 import * as ERRORS from "../../src/Errors";
186 import {
187@@ -532,3 +533,23 @@ test("STDEVP", function(){
188     STDEVP([10, 10, [], 10]);
189   }, ERRORS.REF_ERROR);
190 });
191+
192+test("STDEVPA", function() {
193+  assertEquals(STDEVPA(1, 2, 3, 4, 5, 6, 7, 123), 39.39999206852712);
194+  assertEquals(STDEVPA(1, 2, 3, 4, 5, 6, 7, "123"), 39.39999206852712);
195+  assertEquals(STDEVPA(1, 2, 3, 4, 5, 6, 7), 2);
196+  assertEquals(STDEVPA([1, 2, 3, 4, 5, 6, 7]), 2);
197+  assertEquals(STDEVPA(1, 2, 3, [4, 5], 6, 7), 2);
198+  assertEquals(STDEVPA(33, 44), 5.5);
199+  assertEquals(STDEVPA(33, 44, 0, 1, 0, 1), 18.197222010210485);
200+  assertEquals(STDEVPA(33, 44, false, true, false, true), 18.197222010210485);
201+  catchAndAssertEquals(function() {
202+    STDEVPA(1, 2, 3, 4, 5, 6, 7, "string");
203+  }, ERRORS.VALUE_ERROR);
204+  catchAndAssertEquals(function() {
205+    STDEVPA();
206+  }, ERRORS.NA_ERROR);
207+  catchAndAssertEquals(function() {
208+    STDEVPA([10, 10, [], 10]);
209+  }, ERRORS.REF_ERROR);
210+});
211\ No newline at end of file
212diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
213index 1df10f1..26efd6f 100644
214--- a/tests/SheetFormulaTest.ts
215+++ b/tests/SheetFormulaTest.ts
216@@ -287,6 +287,10 @@ test("Sheet STDEVP", function(){
217   assertFormulaEquals('=STDEVP(33, 44)', 5.5);
218 });
219 
220+test("Sheet STDEVPA", function(){
221+  assertFormulaEquals('=STDEVPA(33, 44)', 5.5);
222+});
223+
224 test("Sheet PERCENTILE", function(){
225   assertFormulaEquals('=PERCENTILE([10], 0)', 10);
226 });