commit
message
[STANDARDIZE] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-24 00:02:16
stats
8 file(s) changed,
77 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
tests/SheetFormulaTest.ts
1diff --git a/DOCS.md b/DOCS.md
2index 5cff1f3..adf5a9d 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -1516,6 +1516,17 @@
6 @param rangeX - The range or array representing the independent data.
7 @constructor
8 ```
9+
10+### ANDARDIZE
11+
12+```
13+ Returns the normalized equivalent of a random variable given mean and standard deviation of the distribution.
14+@param value - Value to be standardized.
15+@param meanValue - Arithmetic mean of the distribution
16+@param std - The standard deviation of the distribution or range.
17+@returns {number}
18+@constructor
19+```
20 ## Text
21
22
23diff --git a/TODO.md b/TODO.md
24index 0f50539..31b3d31 100644
25--- a/TODO.md
26+++ b/TODO.md
27@@ -91,7 +91,6 @@ For example 64 tbs to a qt.
28 * RSQ
29 * SKEW
30 * SMALL
31-* STANDARDIZE
32 * STEYX
33 * T.INV
34 * T.INV.2T
35diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
36index c4fac8f..1f7851d 100644
37--- a/dist/Formulas/AllFormulas.js
38+++ b/dist/Formulas/AllFormulas.js
39@@ -137,6 +137,7 @@ exports.STDEVP = Statistical_1.STDEVP;
40 exports.STDEVPA = Statistical_1.STDEVPA;
41 exports.TRIMMEAN = Statistical_1.TRIMMEAN;
42 exports.SLOPE = Statistical_1.SLOPE;
43+exports.STANDARDIZE = Statistical_1.STANDARDIZE;
44 var Text_1 = require("./Text");
45 exports.ARABIC = Text_1.ARABIC;
46 exports.CHAR = Text_1.CHAR;
47diff --git a/dist/Formulas/Statistical.js b/dist/Formulas/Statistical.js
48index 8cd1552..cd07590 100644
49--- a/dist/Formulas/Statistical.js
50+++ b/dist/Formulas/Statistical.js
51@@ -759,3 +759,21 @@ var SLOPE = function (rangeY, rangeX) {
52 return num / den;
53 };
54 exports.SLOPE = SLOPE;
55+/**
56+ * Returns the normalized equivalent of a random variable given mean and standard deviation of the distribution.
57+ * @param value - Value to be standardized.
58+ * @param meanValue - Arithmetic mean of the distribution
59+ * @param std - The standard deviation of the distribution or range.
60+ * @returns {number}
61+ * @constructor
62+ */
63+var STANDARDIZE = function (value, meanValue, std) {
64+ value = TypeConverter_1.TypeConverter.firstValueAsNumber(value);
65+ meanValue = TypeConverter_1.TypeConverter.firstValueAsNumber(meanValue);
66+ std = TypeConverter_1.TypeConverter.firstValueAsNumber(std);
67+ if (std <= 0) {
68+ throw new Errors_1.NumError("Function STANDARDIZE parameter 3 value is " + std + ". It should be greater than 0.");
69+ }
70+ return (value - meanValue) / std;
71+};
72+exports.STANDARDIZE = STANDARDIZE;
73diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
74index 2e80054..1fb3e28 100644
75--- a/src/Formulas/AllFormulas.ts
76+++ b/src/Formulas/AllFormulas.ts
77@@ -142,7 +142,8 @@ import {
78 STDEVP,
79 STDEVPA,
80 TRIMMEAN,
81- SLOPE
82+ SLOPE,
83+ STANDARDIZE
84 } from "./Statistical";
85 import {
86 ARABIC,
87@@ -353,5 +354,6 @@ export {
88 TRIMMEAN,
89 SLOPE,
90 LOWER,
91- UPPER
92+ UPPER,
93+ STANDARDIZE
94 }
95\ No newline at end of file
96diff --git a/src/Formulas/Statistical.ts b/src/Formulas/Statistical.ts
97index c400066..04c6208 100644
98--- a/src/Formulas/Statistical.ts
99+++ b/src/Formulas/Statistical.ts
100@@ -740,6 +740,25 @@ var SLOPE = function (rangeY, rangeX) {
101 };
102
103
104+/**
105+ * Returns the normalized equivalent of a random variable given mean and standard deviation of the distribution.
106+ * @param value - Value to be standardized.
107+ * @param meanValue - Arithmetic mean of the distribution
108+ * @param std - The standard deviation of the distribution or range.
109+ * @returns {number}
110+ * @constructor
111+ */
112+var STANDARDIZE = function (value, meanValue, std) {
113+ value = TypeConverter.firstValueAsNumber(value);
114+ meanValue = TypeConverter.firstValueAsNumber(meanValue);
115+ std = TypeConverter.firstValueAsNumber(std);
116+ if (std <= 0) {
117+ throw new NumError("Function STANDARDIZE parameter 3 value is " + std + ". It should be greater than 0.");
118+ }
119+ return (value - meanValue) / std;
120+};
121+
122+
123 export {
124 AVERAGE,
125 AVERAGEA,
126@@ -767,5 +786,6 @@ export {
127 STDEVP,
128 STDEVPA,
129 TRIMMEAN,
130- SLOPE
131+ SLOPE,
132+ STANDARDIZE
133 }
134\ No newline at end of file
135diff --git a/tests/Formulas/StatisticalTest.ts b/tests/Formulas/StatisticalTest.ts
136index cebdb11..62ca8bf 100644
137--- a/tests/Formulas/StatisticalTest.ts
138+++ b/tests/Formulas/StatisticalTest.ts
139@@ -25,7 +25,8 @@ import {
140 STDEVP,
141 STDEVPA,
142 TRIMMEAN,
143- SLOPE
144+ SLOPE,
145+ STANDARDIZE
146 } from "../../src/Formulas/Statistical";
147 import * as ERRORS from "../../src/Errors";
148 import {
149@@ -586,4 +587,18 @@ test("SLOPE", function() {
150 catchAndAssertEquals(function() {
151 SLOPE([1, 3], [1]);
152 }, ERRORS.NA_ERROR);
153+});
154+
155+test("STANDARDIZE", function() {
156+ assertEquals(STANDARDIZE(10, 2, 1), 8);
157+ assertEquals(STANDARDIZE(44, 2.1, 99), 0.42323232323232324);
158+ assertEquals(STANDARDIZE(10, 2, [1, []]), 8);
159+ assertEquals(STANDARDIZE(44, 0, 10), 4.4);
160+ assertEquals(STANDARDIZE(0, 0, 1), 0);
161+ catchAndAssertEquals(function() {
162+ STANDARDIZE(44, 2.1, 0);
163+ }, ERRORS.NUM_ERROR);
164+ catchAndAssertEquals(function() {
165+ STANDARDIZE(44, 2.1, -10);
166+ }, ERRORS.NUM_ERROR);
167 });
168\ No newline at end of file
169diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
170index f275ae4..ca7569f 100644
171--- a/tests/SheetFormulaTest.ts
172+++ b/tests/SheetFormulaTest.ts
173@@ -703,6 +703,10 @@ test("Sheet UPPER", function(){
174 assertFormulaEquals('=UPPER("str")', "STR");
175 });
176
177+test("Sheet STANDARDIZE", function(){
178+ assertFormulaEquals('=STANDARDIZE(10, 2, 1)', 8);
179+});
180+
181 test("Sheet *", function(){
182 assertFormulaEquals('= 10 * 10', 100);
183 assertFormulaEquals('= 10 * 0', 0);