spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Added Formula.FISHER
author
Ben Vogt <[email protected]>
date
2017-02-18 18:34:40
stats
2 file(s) changed, 47 insertions(+), 4 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
 1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 2index 2bdd90e..5ad4add 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -87,7 +87,7 @@ import {
 6   Filter,
 7   TypeCaster
 8 } from "./Utils";
 9-import { CellError } from "../Errors"
10+import {CellError, NUM_ERROR} from "../Errors"
11 import * as ERRORS from "../Errors"
12 import {Cell} from "../Cell";
13 
14@@ -128,13 +128,30 @@ var __COMPLEX = {
15   "F.DIST": Formula["FDIST"],
16   "F.INV": Formula["FINV"]
17 };
18-var FISHER = Formula["FISHER"];
19 var FISHERINV = Formula["FISHERINV"];
20 var SUMPRODUCT = Formula["SUMPRODUCT"];
21 var SUMX2MY2 = Formula["SUMX2MY2"];
22 var SUMX2PY2 = Formula["SUMX2PY2"];
23 var YEARFRAC = Formula["YEARFRAC"];
24 
25+
26+/**
27+ * Returns the Fisher transformation of a specified value.
28+ * @param values[0] value - The value for which to calculate the Fisher transformation.
29+ * @returns {number} Fisher transformation
30+ * @constructor
31+ */
32+var FISHER = function (...values) : number {
33+  ArgsChecker.checkLength(values, 1);
34+  var x = TypeCaster.firstValueAsNumber(values[0]);
35+  if (x <= -1 || x >= 1) {
36+    throw new CellError(ERRORS.NUM_ERROR, "Function FISHER parameter 1 value is " + x + ". Valid values are between -1 and 1 exclusive.");
37+  }
38+  return Math.log((1 + x) / (1 - x)) / 2;
39+};
40+
41+
42+
43 export {
44   __COMPLEX,
45 
46diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
47index 5f04d68..8e3eaaf 100644
48--- a/tests/FormulasTest.ts
49+++ b/tests/FormulasTest.ts
50@@ -890,7 +890,30 @@ assertEquals(__COMPLEX["F.DIST"](15.35, 7, 6, true), 0.9980694465675269);
51 
52 assertEquals(__COMPLEX["F.INV"](0.42, 2, 3), 0.6567804059458624);
53 
54+
55+// Test FISHER
56 assertEquals(FISHER(0.962), 1.972066740199461);
57+assertEquals(FISHER([0.962]), 1.972066740199461);
58+assertEquals(FISHER("0.962"), 1.972066740199461);
59+assertEquals(FISHER(0), 0);
60+assertEquals(FISHER(false), 0);
61+assertEquals(FISHER(0.92), 1.589026915173973);
62+catchAndAssertEquals(function() {
63+  FISHER("str");
64+}, ERRORS.VALUE_ERROR);
65+catchAndAssertEquals(function() {
66+  FISHER(1);
67+}, ERRORS.NUM_ERROR);
68+catchAndAssertEquals(function() {
69+  FISHER(-1);
70+}, ERRORS.NUM_ERROR);
71+catchAndAssertEquals(function() {
72+  FISHER();
73+}, ERRORS.NA_ERROR);
74+catchAndAssertEquals(function() {
75+  FISHER(0.55, 0.1);
76+}, ERRORS.NA_ERROR);
77+
78 
79 assertEquals(FISHERINV(0.962), 0.7451676440945232);
80