@syncfusion/ej2-calculate 35.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +263 -0
- package/README.md +132 -0
- package/base.d.ts +4 -0
- package/base.js +4 -0
- package/common.d.ts +4 -0
- package/common.js +4 -0
- package/dist/ej2-calculate.umd.min.js +11 -0
- package/dist/ej2-calculate.umd.min.js.map +1 -0
- package/dist/es6/ej2-calculate.es2015.js +24801 -0
- package/dist/es6/ej2-calculate.es2015.js.map +1 -0
- package/dist/es6/ej2-calculate.es5.js +27229 -0
- package/dist/es6/ej2-calculate.es5.js.map +1 -0
- package/dist/global/ej2-calculate.min.js +11 -0
- package/dist/global/ej2-calculate.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/formulas.d.ts +4 -0
- package/formulas.js +4 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -0
- package/src/base/calculate-model.d.ts +4 -0
- package/src/base/calculate-model.js +0 -0
- package/src/base/calculate.d.ts +1105 -0
- package/src/base/calculate.js +4720 -0
- package/src/base/index.d.ts +8 -0
- package/src/base/index.js +7 -0
- package/src/base/parser.d.ts +208 -0
- package/src/base/parser.js +1512 -0
- package/src/common/address.d.ts +59 -0
- package/src/common/address.js +96 -0
- package/src/common/cell-ref.d.ts +32 -0
- package/src/common/cell-ref.js +112 -0
- package/src/common/common.d.ts +44 -0
- package/src/common/common.js +134 -0
- package/src/common/enum.d.ts +94 -0
- package/src/common/enum.js +97 -0
- package/src/common/index.d.ts +9 -0
- package/src/common/index.js +8 -0
- package/src/common/interface.d.ts +122 -0
- package/src/common/interface.js +0 -0
- package/src/common/l10n.d.ts +24 -0
- package/src/common/l10n.js +54 -0
- package/src/common/number-date.d.ts +26 -0
- package/src/common/number-date.js +38 -0
- package/src/common/sheet-info.d.ts +10 -0
- package/src/common/sheet-info.js +17 -0
- package/src/common/sort.d.ts +17 -0
- package/src/common/sort.js +44 -0
- package/src/formulas/array.d.ts +47 -0
- package/src/formulas/array.js +718 -0
- package/src/formulas/basic.d.ts +47 -0
- package/src/formulas/basic.js +181 -0
- package/src/formulas/complex-numbers.d.ts +207 -0
- package/src/formulas/complex-numbers.js +549 -0
- package/src/formulas/database.d.ts +152 -0
- package/src/formulas/database.js +579 -0
- package/src/formulas/date-time-extra.d.ts +97 -0
- package/src/formulas/date-time-extra.js +415 -0
- package/src/formulas/date-time-intl.d.ts +57 -0
- package/src/formulas/date-time-intl.js +309 -0
- package/src/formulas/date-time.d.ts +164 -0
- package/src/formulas/date-time.js +1021 -0
- package/src/formulas/engineering-base.d.ts +150 -0
- package/src/formulas/engineering-base.js +404 -0
- package/src/formulas/engineering-bessel.d.ts +65 -0
- package/src/formulas/engineering-bessel.js +167 -0
- package/src/formulas/engineering-convert.d.ts +35 -0
- package/src/formulas/engineering-convert.js +120 -0
- package/src/formulas/engineering-misc.d.ts +64 -0
- package/src/formulas/engineering-misc.js +168 -0
- package/src/formulas/financial-amortization-ecma.d.ts +87 -0
- package/src/formulas/financial-amortization-ecma.js +288 -0
- package/src/formulas/financial-annuity.d.ts +104 -0
- package/src/formulas/financial-annuity.js +419 -0
- package/src/formulas/financial-bond-helpers.d.ts +106 -0
- package/src/formulas/financial-bond-helpers.js +190 -0
- package/src/formulas/financial-cashflow.d.ts +47 -0
- package/src/formulas/financial-cashflow.js +203 -0
- package/src/formulas/financial-coupons.d.ts +227 -0
- package/src/formulas/financial-coupons.js +810 -0
- package/src/formulas/financial-depreciation.d.ts +64 -0
- package/src/formulas/financial-depreciation.js +247 -0
- package/src/formulas/financial-rates.d.ts +54 -0
- package/src/formulas/financial-rates.js +140 -0
- package/src/formulas/financial-securities.d.ts +126 -0
- package/src/formulas/financial-securities.js +488 -0
- package/src/formulas/formula-math-helpers.d.ts +212 -0
- package/src/formulas/formula-math-helpers.js +599 -0
- package/src/formulas/formula-module-base.d.ts +54 -0
- package/src/formulas/formula-module-base.js +125 -0
- package/src/formulas/formula-owner.d.ts +17 -0
- package/src/formulas/formula-owner.js +0 -0
- package/src/formulas/index.d.ts +68 -0
- package/src/formulas/index.js +67 -0
- package/src/formulas/information-advanced.d.ts +44 -0
- package/src/formulas/information-advanced.js +157 -0
- package/src/formulas/information-ecma.d.ts +33 -0
- package/src/formulas/information-ecma.js +88 -0
- package/src/formulas/information-extra.d.ts +146 -0
- package/src/formulas/information-extra.js +351 -0
- package/src/formulas/information.d.ts +34 -0
- package/src/formulas/information.js +78 -0
- package/src/formulas/logical-extra.d.ts +75 -0
- package/src/formulas/logical-extra.js +217 -0
- package/src/formulas/logical.d.ts +83 -0
- package/src/formulas/logical.js +296 -0
- package/src/formulas/lookup-array.d.ts +98 -0
- package/src/formulas/lookup-array.js +364 -0
- package/src/formulas/lookup-ref-extra.d.ts +64 -0
- package/src/formulas/lookup-ref-extra.js +180 -0
- package/src/formulas/lookup-ref.d.ts +84 -0
- package/src/formulas/lookup-ref.js +263 -0
- package/src/formulas/lookup.d.ts +114 -0
- package/src/formulas/lookup.js +881 -0
- package/src/formulas/math-aggregate.d.ts +74 -0
- package/src/formulas/math-aggregate.js +376 -0
- package/src/formulas/math-ceiling-ecma.d.ts +42 -0
- package/src/formulas/math-ceiling-ecma.js +123 -0
- package/src/formulas/math-combinatorics.d.ts +75 -0
- package/src/formulas/math-combinatorics.js +290 -0
- package/src/formulas/math-misc.d.ts +164 -0
- package/src/formulas/math-misc.js +889 -0
- package/src/formulas/math-number.d.ts +76 -0
- package/src/formulas/math-number.js +261 -0
- package/src/formulas/math-rounding.d.ts +115 -0
- package/src/formulas/math-rounding.js +728 -0
- package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
- package/src/formulas/math-trig-hyperbolic.js +113 -0
- package/src/formulas/math-trig.d.ts +165 -0
- package/src/formulas/math-trig.js +334 -0
- package/src/formulas/matrix-base.d.ts +13 -0
- package/src/formulas/matrix-base.js +169 -0
- package/src/formulas/matrix.d.ts +64 -0
- package/src/formulas/matrix.js +161 -0
- package/src/formulas/regression-ecma.d.ts +66 -0
- package/src/formulas/regression-ecma.js +234 -0
- package/src/formulas/statistical-advanced.d.ts +125 -0
- package/src/formulas/statistical-advanced.js +756 -0
- package/src/formulas/statistical-correlation.d.ts +75 -0
- package/src/formulas/statistical-correlation.js +198 -0
- package/src/formulas/statistical-dispersion.d.ts +108 -0
- package/src/formulas/statistical-dispersion.js +337 -0
- package/src/formulas/statistical-distribution-extended.d.ts +176 -0
- package/src/formulas/statistical-distribution-extended.js +668 -0
- package/src/formulas/statistical-distribution.d.ts +104 -0
- package/src/formulas/statistical-distribution.js +368 -0
- package/src/formulas/statistical-ecma.d.ts +95 -0
- package/src/formulas/statistical-ecma.js +392 -0
- package/src/formulas/statistical-extended.d.ts +136 -0
- package/src/formulas/statistical-extended.js +340 -0
- package/src/formulas/statistical-ifs.d.ts +46 -0
- package/src/formulas/statistical-ifs.js +180 -0
- package/src/formulas/statistical-moments.d.ts +84 -0
- package/src/formulas/statistical-moments.js +269 -0
- package/src/formulas/statistical-percentile.d.ts +56 -0
- package/src/formulas/statistical-percentile.js +195 -0
- package/src/formulas/statistical-sample-base.d.ts +14 -0
- package/src/formulas/statistical-sample-base.js +124 -0
- package/src/formulas/statistical.d.ts +135 -0
- package/src/formulas/statistical.js +542 -0
- package/src/formulas/text-advanced.d.ts +64 -0
- package/src/formulas/text-advanced.js +222 -0
- package/src/formulas/text-ecma.d.ts +54 -0
- package/src/formulas/text-ecma.js +106 -0
- package/src/formulas/text-extra.d.ts +216 -0
- package/src/formulas/text-extra.js +657 -0
- package/src/formulas/text.d.ts +125 -0
- package/src/formulas/text.js +628 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +14 -0
- package/tslint.json +111 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { FormulasErrorsStrings, CommonErrors } from '../common/index';
|
|
15
|
+
import { isNullOrUndefined } from '@syncfusion/ej2-base';
|
|
16
|
+
import { StatisticalSampleBase } from './statistical-sample-base';
|
|
17
|
+
import { betaDist, betaInv, tCDF, tInv, fCDF } from './formula-math-helpers';
|
|
18
|
+
/**
|
|
19
|
+
* ECMA-376 statistical distribution and hypothesis-test functions (beta, t, F, frequency).
|
|
20
|
+
*
|
|
21
|
+
* Registered functions: BETADIST, BETAINV, TDIST, TINV, TTEST, FTEST, FREQUENCY.
|
|
22
|
+
*
|
|
23
|
+
* @hidden
|
|
24
|
+
*/
|
|
25
|
+
var StatisticalEcmaFormulas = /** @class */ (function (_super) {
|
|
26
|
+
__extends(StatisticalEcmaFormulas, _super);
|
|
27
|
+
/**
|
|
28
|
+
* @hidden
|
|
29
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
30
|
+
*/
|
|
31
|
+
function StatisticalEcmaFormulas(owner) {
|
|
32
|
+
var _this = _super.call(this, owner) || this;
|
|
33
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
34
|
+
_this.formulas = [
|
|
35
|
+
{ formulaName: 'BETADIST', category: 'Statistical', description: 'Returns the beta cumulative distribution function.' },
|
|
36
|
+
{ formulaName: 'BETAINV', category: 'Statistical', description: 'Returns the inverse of the beta cumulative distribution function.' },
|
|
37
|
+
{ formulaName: 'TDIST', category: 'Statistical', description: 'Returns the Student t-distribution.' },
|
|
38
|
+
{ formulaName: 'TINV', category: 'Statistical', description: 'Returns the inverse of the Student t-distribution.' },
|
|
39
|
+
{ formulaName: 'TTEST', category: 'Statistical', description: 'Returns the probability associated with a Student t-test.' },
|
|
40
|
+
{ formulaName: 'FTEST', category: 'Statistical', description: 'Returns the result of an F-test.' },
|
|
41
|
+
{ formulaName: 'FREQUENCY', category: 'Statistical', description: 'Returns the frequency distribution of a range of values.' }
|
|
42
|
+
];
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the beta cumulative distribution function.
|
|
47
|
+
*
|
|
48
|
+
* Excel: `BETADIST(...)`.
|
|
49
|
+
*
|
|
50
|
+
* @hidden
|
|
51
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
52
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* engine.computeFormula('=BETADIST(1)');
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
StatisticalEcmaFormulas.prototype.ComputeBETADIST = function () {
|
|
60
|
+
var args = [];
|
|
61
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
62
|
+
args[_i] = arguments[_i];
|
|
63
|
+
}
|
|
64
|
+
var errCollection = this.parent.getErrorStrings();
|
|
65
|
+
if (isNullOrUndefined(args) || args.length < 3 || args.length > 5) {
|
|
66
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
67
|
+
}
|
|
68
|
+
var x = this.resolveNumberArg(args[0]);
|
|
69
|
+
var alpha = this.resolveNumberArg(args[1]);
|
|
70
|
+
var betaParam = this.resolveNumberArg(args[2]);
|
|
71
|
+
if (typeof x === 'string') {
|
|
72
|
+
return x;
|
|
73
|
+
}
|
|
74
|
+
if (typeof alpha === 'string') {
|
|
75
|
+
return alpha;
|
|
76
|
+
}
|
|
77
|
+
if (typeof betaParam === 'string') {
|
|
78
|
+
return betaParam;
|
|
79
|
+
}
|
|
80
|
+
var a = 0;
|
|
81
|
+
var b = 1;
|
|
82
|
+
if (args.length >= 4 && args[3] !== '') {
|
|
83
|
+
var av = this.resolveNumberArg(args[3]);
|
|
84
|
+
if (typeof av === 'string') {
|
|
85
|
+
return av;
|
|
86
|
+
}
|
|
87
|
+
a = av;
|
|
88
|
+
}
|
|
89
|
+
if (args.length >= 5 && args[4] !== '') {
|
|
90
|
+
var bv = this.resolveNumberArg(args[4]);
|
|
91
|
+
if (typeof bv === 'string') {
|
|
92
|
+
return bv;
|
|
93
|
+
}
|
|
94
|
+
b = bv;
|
|
95
|
+
}
|
|
96
|
+
if (x < a || x > b || alpha <= 0 || betaParam <= 0 || a >= b) {
|
|
97
|
+
return errCollection[CommonErrors.Num];
|
|
98
|
+
}
|
|
99
|
+
var scaled = (x - a) / (b - a);
|
|
100
|
+
var result = betaDist(scaled, alpha, betaParam);
|
|
101
|
+
if (isNaN(result)) {
|
|
102
|
+
return errCollection[CommonErrors.Num];
|
|
103
|
+
}
|
|
104
|
+
return result.toString();
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Returns the inverse of the beta cumulative distribution function.
|
|
108
|
+
*
|
|
109
|
+
* Excel: `BETAINV(...)`.
|
|
110
|
+
*
|
|
111
|
+
* @hidden
|
|
112
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
113
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
114
|
+
*/
|
|
115
|
+
StatisticalEcmaFormulas.prototype.ComputeBETAINV = function () {
|
|
116
|
+
var args = [];
|
|
117
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
118
|
+
args[_i] = arguments[_i];
|
|
119
|
+
}
|
|
120
|
+
var errCollection = this.parent.getErrorStrings();
|
|
121
|
+
if (isNullOrUndefined(args) || args.length < 3 || args.length > 5) {
|
|
122
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
123
|
+
}
|
|
124
|
+
var p = this.resolveNumberArg(args[0]);
|
|
125
|
+
var alpha = this.resolveNumberArg(args[1]);
|
|
126
|
+
var betaParam = this.resolveNumberArg(args[2]);
|
|
127
|
+
if (typeof p === 'string') {
|
|
128
|
+
return p;
|
|
129
|
+
}
|
|
130
|
+
if (typeof alpha === 'string') {
|
|
131
|
+
return alpha;
|
|
132
|
+
}
|
|
133
|
+
if (typeof betaParam === 'string') {
|
|
134
|
+
return betaParam;
|
|
135
|
+
}
|
|
136
|
+
var a = 0;
|
|
137
|
+
var b = 1;
|
|
138
|
+
if (args.length >= 4 && args[3] !== '') {
|
|
139
|
+
var av = this.resolveNumberArg(args[3]);
|
|
140
|
+
if (typeof av === 'string') {
|
|
141
|
+
return av;
|
|
142
|
+
}
|
|
143
|
+
a = av;
|
|
144
|
+
}
|
|
145
|
+
if (args.length >= 5 && args[4] !== '') {
|
|
146
|
+
var bv = this.resolveNumberArg(args[4]);
|
|
147
|
+
if (typeof bv === 'string') {
|
|
148
|
+
return bv;
|
|
149
|
+
}
|
|
150
|
+
b = bv;
|
|
151
|
+
}
|
|
152
|
+
var scaled = betaInv(p, alpha, betaParam);
|
|
153
|
+
if (isNaN(scaled)) {
|
|
154
|
+
return errCollection[CommonErrors.Num];
|
|
155
|
+
}
|
|
156
|
+
return (a + scaled * (b - a)).toString();
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Returns the Student t-distribution.
|
|
160
|
+
*
|
|
161
|
+
* Excel: `TDIST(...)`.
|
|
162
|
+
*
|
|
163
|
+
* @hidden
|
|
164
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
165
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
166
|
+
*/
|
|
167
|
+
StatisticalEcmaFormulas.prototype.ComputeTDIST = function () {
|
|
168
|
+
var args = [];
|
|
169
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
170
|
+
args[_i] = arguments[_i];
|
|
171
|
+
}
|
|
172
|
+
if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
|
|
173
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
174
|
+
}
|
|
175
|
+
var x = this.resolveNumberArg(args[0]);
|
|
176
|
+
var df = this.resolveNumberArg(args[1]);
|
|
177
|
+
if (typeof x === 'string') {
|
|
178
|
+
return x;
|
|
179
|
+
}
|
|
180
|
+
if (typeof df === 'string') {
|
|
181
|
+
return df;
|
|
182
|
+
}
|
|
183
|
+
var tails = 1;
|
|
184
|
+
if (args.length === 3 && args[2] !== '') {
|
|
185
|
+
var t = this.resolveNumberArg(args[2]);
|
|
186
|
+
if (typeof t === 'string') {
|
|
187
|
+
return t;
|
|
188
|
+
}
|
|
189
|
+
tails = Math.floor(t);
|
|
190
|
+
}
|
|
191
|
+
var cdf = tCDF(Math.abs(x), df);
|
|
192
|
+
var p = tails === 1 ? 1 - cdf : 2 * (1 - cdf);
|
|
193
|
+
return p.toString();
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Returns the inverse of the Student t-distribution.
|
|
197
|
+
*
|
|
198
|
+
* Excel: `TINV(...)`.
|
|
199
|
+
*
|
|
200
|
+
* @hidden
|
|
201
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
202
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
203
|
+
*/
|
|
204
|
+
StatisticalEcmaFormulas.prototype.ComputeTINV = function () {
|
|
205
|
+
var args = [];
|
|
206
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
207
|
+
args[_i] = arguments[_i];
|
|
208
|
+
}
|
|
209
|
+
var errCollection = this.parent.getErrorStrings();
|
|
210
|
+
if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
|
|
211
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
212
|
+
}
|
|
213
|
+
var p = this.resolveNumberArg(args[0]);
|
|
214
|
+
var df = this.resolveNumberArg(args[1]);
|
|
215
|
+
if (typeof p === 'string') {
|
|
216
|
+
return p;
|
|
217
|
+
}
|
|
218
|
+
if (typeof df === 'string') {
|
|
219
|
+
return df;
|
|
220
|
+
}
|
|
221
|
+
var tails = 2;
|
|
222
|
+
if (args.length === 3 && args[2] !== '') {
|
|
223
|
+
var t = this.resolveNumberArg(args[2]);
|
|
224
|
+
if (typeof t === 'string') {
|
|
225
|
+
return t;
|
|
226
|
+
}
|
|
227
|
+
tails = Math.floor(t);
|
|
228
|
+
}
|
|
229
|
+
var prob = tails === 1 ? 1 - p : 1 - p / 2;
|
|
230
|
+
var result = tInv(prob, df);
|
|
231
|
+
if (isNaN(result)) {
|
|
232
|
+
return errCollection[CommonErrors.Num];
|
|
233
|
+
}
|
|
234
|
+
return result.toString();
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Returns the probability associated with a Student t-test.
|
|
238
|
+
*
|
|
239
|
+
* Excel: `TTEST(...)`.
|
|
240
|
+
*
|
|
241
|
+
* @hidden
|
|
242
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
243
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
244
|
+
*/
|
|
245
|
+
StatisticalEcmaFormulas.prototype.ComputeTTEST = function () {
|
|
246
|
+
var args = [];
|
|
247
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
248
|
+
args[_i] = arguments[_i];
|
|
249
|
+
}
|
|
250
|
+
var errCollection = this.parent.getErrorStrings();
|
|
251
|
+
if (isNullOrUndefined(args) || args.length < 3 || args.length > 4) {
|
|
252
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
253
|
+
}
|
|
254
|
+
var a = this.collectSample([args[0]], false);
|
|
255
|
+
var b = this.collectSample([args[1]], false);
|
|
256
|
+
if (typeof a === 'string') {
|
|
257
|
+
return a;
|
|
258
|
+
}
|
|
259
|
+
if (typeof b === 'string') {
|
|
260
|
+
return b;
|
|
261
|
+
}
|
|
262
|
+
if (a.length < 2 || b.length < 2) {
|
|
263
|
+
return errCollection[CommonErrors.DivZero];
|
|
264
|
+
}
|
|
265
|
+
var meanA = this.mean(a);
|
|
266
|
+
var meanB = this.mean(b);
|
|
267
|
+
var varA = 0;
|
|
268
|
+
var varB = 0;
|
|
269
|
+
for (var i = 0; i < a.length; i++) {
|
|
270
|
+
varA += Math.pow(a[i] - meanA, 2);
|
|
271
|
+
}
|
|
272
|
+
for (var i = 0; i < b.length; i++) {
|
|
273
|
+
varB += Math.pow(b[i] - meanB, 2);
|
|
274
|
+
}
|
|
275
|
+
varA /= (a.length - 1);
|
|
276
|
+
varB /= (b.length - 1);
|
|
277
|
+
var se = Math.sqrt(varA / a.length + varB / b.length);
|
|
278
|
+
if (se === 0) {
|
|
279
|
+
return errCollection[CommonErrors.DivZero];
|
|
280
|
+
}
|
|
281
|
+
var t = Math.abs(meanA - meanB) / se;
|
|
282
|
+
var df = a.length + b.length - 2;
|
|
283
|
+
var tails = 2;
|
|
284
|
+
if (args.length === 4 && args[3] !== '') {
|
|
285
|
+
var tt = this.resolveNumberArg(args[3]);
|
|
286
|
+
if (typeof tt === 'string') {
|
|
287
|
+
return tt;
|
|
288
|
+
}
|
|
289
|
+
tails = Math.floor(tt);
|
|
290
|
+
}
|
|
291
|
+
var cdf = tCDF(t, df);
|
|
292
|
+
var p = tails === 1 ? 1 - cdf : 2 * (1 - cdf);
|
|
293
|
+
return p.toString();
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Returns the result of an F-test.
|
|
297
|
+
*
|
|
298
|
+
* Excel: `FTEST(...)`.
|
|
299
|
+
*
|
|
300
|
+
* @hidden
|
|
301
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
302
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
303
|
+
*/
|
|
304
|
+
StatisticalEcmaFormulas.prototype.ComputeFTEST = function () {
|
|
305
|
+
var args = [];
|
|
306
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
307
|
+
args[_i] = arguments[_i];
|
|
308
|
+
}
|
|
309
|
+
var errCollection = this.parent.getErrorStrings();
|
|
310
|
+
if (isNullOrUndefined(args) || args.length !== 2) {
|
|
311
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
312
|
+
}
|
|
313
|
+
var a = this.collectSample([args[0]], false);
|
|
314
|
+
var b = this.collectSample([args[1]], false);
|
|
315
|
+
if (typeof a === 'string') {
|
|
316
|
+
return a;
|
|
317
|
+
}
|
|
318
|
+
if (typeof b === 'string') {
|
|
319
|
+
return b;
|
|
320
|
+
}
|
|
321
|
+
if (a.length < 2 || b.length < 2) {
|
|
322
|
+
return errCollection[CommonErrors.DivZero];
|
|
323
|
+
}
|
|
324
|
+
var varA = this.sampleVar(a);
|
|
325
|
+
var varB = this.sampleVar(b);
|
|
326
|
+
if (varB === 0) {
|
|
327
|
+
return errCollection[CommonErrors.DivZero];
|
|
328
|
+
}
|
|
329
|
+
var f = varA / varB;
|
|
330
|
+
var d1 = a.length - 1;
|
|
331
|
+
var d2 = b.length - 1;
|
|
332
|
+
return (2 * Math.min(fCDF(f, d1, d2), fCDF(1 / f, d2, d1))).toString();
|
|
333
|
+
};
|
|
334
|
+
StatisticalEcmaFormulas.prototype.sampleVar = function (nums) {
|
|
335
|
+
var m = this.mean(nums);
|
|
336
|
+
var sum = 0;
|
|
337
|
+
for (var i = 0; i < nums.length; i++) {
|
|
338
|
+
sum += Math.pow(nums[i] - m, 2);
|
|
339
|
+
}
|
|
340
|
+
return sum / (nums.length - 1);
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Returns a frequency distribution as a vertical array (first bin when spill unavailable).
|
|
344
|
+
*
|
|
345
|
+
* Excel: `FREQUENCY(...)`.
|
|
346
|
+
*
|
|
347
|
+
* @hidden
|
|
348
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
349
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
350
|
+
*/
|
|
351
|
+
StatisticalEcmaFormulas.prototype.ComputeFREQUENCY = function () {
|
|
352
|
+
var args = [];
|
|
353
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
354
|
+
args[_i] = arguments[_i];
|
|
355
|
+
}
|
|
356
|
+
var errCollection = this.parent.getErrorStrings();
|
|
357
|
+
if (isNullOrUndefined(args) || args.length !== 2) {
|
|
358
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
359
|
+
}
|
|
360
|
+
var data = this.collectSample([args[0]], false);
|
|
361
|
+
var bins = this.collectSample([args[1]], false);
|
|
362
|
+
if (typeof data === 'string') {
|
|
363
|
+
return data;
|
|
364
|
+
}
|
|
365
|
+
if (typeof bins === 'string') {
|
|
366
|
+
return bins;
|
|
367
|
+
}
|
|
368
|
+
if (bins.length === 0) {
|
|
369
|
+
return errCollection[CommonErrors.Num];
|
|
370
|
+
}
|
|
371
|
+
var sortedBins = bins.slice().sort(function (x, y) { return x - y; });
|
|
372
|
+
var counts = new Array(sortedBins.length + 1).fill(0);
|
|
373
|
+
for (var i = 0; i < data.length; i++) {
|
|
374
|
+
var v = data[i];
|
|
375
|
+
var placed = false;
|
|
376
|
+
for (var b = 0; b < sortedBins.length; b++) {
|
|
377
|
+
if (v <= sortedBins[b]) {
|
|
378
|
+
counts[b]++;
|
|
379
|
+
placed = true;
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (!placed) {
|
|
384
|
+
counts[counts.length - 1]++;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
var sep = this.parent.getParseArgumentSeparator();
|
|
388
|
+
return counts.join(sep);
|
|
389
|
+
};
|
|
390
|
+
return StatisticalEcmaFormulas;
|
|
391
|
+
}(StatisticalSampleBase));
|
|
392
|
+
export { StatisticalEcmaFormulas };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { StatisticalSampleBase } from './statistical-sample-base';
|
|
4
|
+
/**
|
|
5
|
+
* Large-sample and array statistical helpers beyond basic descriptive functions.
|
|
6
|
+
*
|
|
7
|
+
* Registers 11 functions including STDEVA, STDEVPA, VARA, VARPA, TRIMMEAN, and others.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class StatisticalExtendedFormulas extends StatisticalSampleBase {
|
|
12
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
13
|
+
formulas: IBasicFormula[];
|
|
14
|
+
/**
|
|
15
|
+
* @hidden
|
|
16
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
17
|
+
*/
|
|
18
|
+
constructor(owner: FormulaOwner);
|
|
19
|
+
private stdevVarA;
|
|
20
|
+
/**
|
|
21
|
+
* Estimates standard deviation based on a sample, including text and logicals.
|
|
22
|
+
*
|
|
23
|
+
* Excel: `STDEVA(...)`.
|
|
24
|
+
*
|
|
25
|
+
* @hidden
|
|
26
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
27
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* engine.computeFormula('=STDEVA(1)');
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
ComputeSTDEVA(...args: string[]): string | number;
|
|
35
|
+
/**
|
|
36
|
+
* Calculates standard deviation based on the entire population, including text and logicals.
|
|
37
|
+
*
|
|
38
|
+
* Excel: `STDEVPA(...)`.
|
|
39
|
+
*
|
|
40
|
+
* @hidden
|
|
41
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
42
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
43
|
+
*/
|
|
44
|
+
ComputeSTDEVPA(...args: string[]): string | number;
|
|
45
|
+
/**
|
|
46
|
+
* Estimates variance based on a sample, including text and logicals.
|
|
47
|
+
*
|
|
48
|
+
* Excel: `VARA(...)`.
|
|
49
|
+
*
|
|
50
|
+
* @hidden
|
|
51
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
52
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
53
|
+
*/
|
|
54
|
+
ComputeVARA(...args: string[]): string | number;
|
|
55
|
+
/**
|
|
56
|
+
* Calculates variance based on the entire population, including text and logicals.
|
|
57
|
+
*
|
|
58
|
+
* Excel: `VARPA(...)`.
|
|
59
|
+
*
|
|
60
|
+
* @hidden
|
|
61
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
62
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
63
|
+
*/
|
|
64
|
+
ComputeVARPA(...args: string[]): string | number;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the mean of the interior of a data set.
|
|
67
|
+
*
|
|
68
|
+
* Excel: `TRIMMEAN(...)`.
|
|
69
|
+
*
|
|
70
|
+
* @hidden
|
|
71
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
72
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
73
|
+
*/
|
|
74
|
+
ComputeTRIMMEAN(...args: string[]): string | number;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the Fisher transformation.
|
|
77
|
+
*
|
|
78
|
+
* Excel: `FISHER(...)`.
|
|
79
|
+
*
|
|
80
|
+
* @hidden
|
|
81
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
82
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
83
|
+
*/
|
|
84
|
+
ComputeFISHER(...args: string[]): string | number;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the inverse of the Fisher transformation.
|
|
87
|
+
*
|
|
88
|
+
* Excel: `FISHERINV(...)`.
|
|
89
|
+
*
|
|
90
|
+
* @hidden
|
|
91
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
92
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
93
|
+
*/
|
|
94
|
+
ComputeFISHERINV(...args: string[]): string | number;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the natural logarithm of the gamma function.
|
|
97
|
+
*
|
|
98
|
+
* Excel: `GAMMALN(...)`.
|
|
99
|
+
*
|
|
100
|
+
* @hidden
|
|
101
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
102
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
103
|
+
*/
|
|
104
|
+
ComputeGAMMALN(...args: string[]): string | number;
|
|
105
|
+
private sumSquaresPair;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the sum of the difference of squares of corresponding values in two arrays.
|
|
108
|
+
*
|
|
109
|
+
* Excel: `SUMX2MY2(...)`.
|
|
110
|
+
*
|
|
111
|
+
* @hidden
|
|
112
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
113
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
114
|
+
*/
|
|
115
|
+
ComputeSUMX2MY2(...args: string[]): string | number;
|
|
116
|
+
/**
|
|
117
|
+
* Returns the sum of the sum of squares of corresponding values in two arrays.
|
|
118
|
+
*
|
|
119
|
+
* Excel: `SUMX2PY2(...)`.
|
|
120
|
+
*
|
|
121
|
+
* @hidden
|
|
122
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
123
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
124
|
+
*/
|
|
125
|
+
ComputeSUMX2PY2(...args: string[]): string | number;
|
|
126
|
+
/**
|
|
127
|
+
* Returns the sum of squares of differences of corresponding values in two arrays.
|
|
128
|
+
*
|
|
129
|
+
* Excel: `SUMXMY2(...)`.
|
|
130
|
+
*
|
|
131
|
+
* @hidden
|
|
132
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
133
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
134
|
+
*/
|
|
135
|
+
ComputeSUMXMY2(...args: string[]): string | number;
|
|
136
|
+
}
|