@gridsheet/functions 3.0.1 → 3.0.3
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/dist/functions/src/math/sumif.d.ts.map +1 -1
- package/dist/functions/src/math/sumifs.d.ts.map +1 -1
- package/dist/functions/src/statistics/averageif.d.ts.map +1 -1
- package/dist/functions/src/statistics/averageifs.d.ts.map +1 -1
- package/dist/math/index.js +186 -186
- package/dist/math/index.js.map +1 -1
- package/dist/statistics/index.js +179 -179
- package/dist/statistics/index.js.map +1 -1
- package/package.json +8 -4
package/dist/statistics/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { BaseFunction as
|
|
2
|
-
const
|
|
3
|
-
class S extends
|
|
1
|
+
import { BaseFunction as x, conditionArg as T, ensureString as E, eachMatrix as m, stripMatrix as R, isNumeric as A, check as N, ensureNumber as f, FormulaError as d, Sheet as b, createBooleanMask as k } from "@gridsheet/core";
|
|
2
|
+
const v = "Returns the average of a series of cells that meet a condition.";
|
|
3
|
+
class S extends x {
|
|
4
4
|
constructor() {
|
|
5
|
-
super(...arguments), this.example = 'AVERAGEIF(A1:A10,">20")', this.description =
|
|
5
|
+
super(...arguments), this.example = 'AVERAGEIF(A1:A10,">20")', this.description = v, this.defs = [
|
|
6
6
|
{ name: "range", description: "A condition range.", takesMatrix: !0, acceptedTypes: ["matrix"] },
|
|
7
|
-
|
|
7
|
+
T,
|
|
8
8
|
{
|
|
9
9
|
name: "average_range",
|
|
10
10
|
description: "A range to be averaged.",
|
|
@@ -14,37 +14,37 @@ class S extends y {
|
|
|
14
14
|
}
|
|
15
15
|
], this.category = "statistics";
|
|
16
16
|
}
|
|
17
|
-
main(t, n,
|
|
18
|
-
const e =
|
|
17
|
+
main(t, n, a) {
|
|
18
|
+
const e = E(n), r = [], i = [];
|
|
19
19
|
m(
|
|
20
20
|
t,
|
|
21
21
|
(s) => {
|
|
22
|
-
|
|
22
|
+
r.push(s);
|
|
23
23
|
},
|
|
24
24
|
this.at
|
|
25
|
-
),
|
|
26
|
-
|
|
25
|
+
), a && m(
|
|
26
|
+
a,
|
|
27
27
|
(s) => {
|
|
28
28
|
i.push(s);
|
|
29
29
|
},
|
|
30
30
|
this.at
|
|
31
31
|
);
|
|
32
32
|
let c = 0, o = 0;
|
|
33
|
-
if (
|
|
34
|
-
const h =
|
|
35
|
-
|
|
33
|
+
if (r.forEach((s, l) => {
|
|
34
|
+
const h = R((a ? i[l] : s) ?? 0, this.at);
|
|
35
|
+
A(h) && N(s, e) && (c += f(h), o++);
|
|
36
36
|
}), o === 0)
|
|
37
37
|
throw new d("#DIV/0!", "No cells match the condition.");
|
|
38
38
|
return c / o;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
const I = "Returns the average of a range depending on multiple criteria.";
|
|
42
|
-
class V extends
|
|
42
|
+
class V extends x {
|
|
43
43
|
constructor() {
|
|
44
44
|
super(...arguments), this.example = 'AVERAGEIFS(A1:A10, B1:B10, ">20")', this.description = I, this.defs = [
|
|
45
45
|
{ name: "average_range", description: "The range to be averaged.", takesMatrix: !0, acceptedTypes: ["matrix"] },
|
|
46
46
|
{ name: "range1", description: "First condition range.", takesMatrix: !0, acceptedTypes: ["matrix"] },
|
|
47
|
-
{ ...
|
|
47
|
+
{ ...T, name: "condition1" },
|
|
48
48
|
{
|
|
49
49
|
name: "range2",
|
|
50
50
|
description: "Additional condition range.",
|
|
@@ -53,42 +53,42 @@ class V extends y {
|
|
|
53
53
|
optional: !0,
|
|
54
54
|
variadic: !0
|
|
55
55
|
},
|
|
56
|
-
{ ...
|
|
56
|
+
{ ...T, name: "condition2", optional: !0, variadic: !0 }
|
|
57
57
|
], this.category = "statistics";
|
|
58
58
|
}
|
|
59
59
|
validate(t) {
|
|
60
60
|
const n = super.validate(t);
|
|
61
61
|
if ((n.length - 1) % 2 !== 0)
|
|
62
62
|
throw new d("#N/A", "AVERAGEIFS requires average_range and at least one range/condition pair.");
|
|
63
|
-
if (!(n[0] instanceof
|
|
63
|
+
if (!(n[0] instanceof b))
|
|
64
64
|
throw new d("#VALUE!", "First argument of AVERAGEIFS must be a range.");
|
|
65
|
-
const
|
|
65
|
+
const a = n[0].numRows, e = n[0].numCols, r = [], i = [];
|
|
66
66
|
for (let s = 1; s < n.length; s += 2) {
|
|
67
|
-
if (!(n[s] instanceof
|
|
67
|
+
if (!(n[s] instanceof b))
|
|
68
68
|
throw new d("#VALUE!", `Argument ${s + 1} of AVERAGEIFS must be a range.`);
|
|
69
|
-
if (n[s].numRows !==
|
|
69
|
+
if (n[s].numRows !== a || n[s].numCols !== e)
|
|
70
70
|
throw new d("#VALUE!", "Array arguments to AVERAGEIFS are of different size.");
|
|
71
|
-
|
|
71
|
+
r.push(n[s]), i.push(E(n[s + 1]));
|
|
72
72
|
}
|
|
73
|
-
const c = n[0], o =
|
|
73
|
+
const c = n[0], o = k(r, i, this.at);
|
|
74
74
|
return [c, o];
|
|
75
75
|
}
|
|
76
76
|
main(t, n) {
|
|
77
|
-
let
|
|
77
|
+
let a = 0, e = 0;
|
|
78
78
|
return m(
|
|
79
79
|
t,
|
|
80
|
-
(
|
|
80
|
+
(r, i) => {
|
|
81
81
|
if (i && n[i.y][i.x]) {
|
|
82
|
-
const c =
|
|
83
|
-
|
|
82
|
+
const c = R(r ?? 0, this.at);
|
|
83
|
+
A(c) && (a += f(c), e++);
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
this.at
|
|
87
|
-
), e === 0 ? new d("#DIV/0!", "No matching cells found for AVERAGEIFS.") :
|
|
87
|
+
), e === 0 ? new d("#DIV/0!", "No matching cells found for AVERAGEIFS.") : a / e;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
const F = "Returns the median value in a numeric dataset.";
|
|
91
|
-
class C extends
|
|
91
|
+
class C extends x {
|
|
92
92
|
constructor() {
|
|
93
93
|
super(...arguments), this.example = "MEDIAN(A1:A100)", this.description = F, this.defs = [
|
|
94
94
|
{
|
|
@@ -102,11 +102,11 @@ class C extends y {
|
|
|
102
102
|
}
|
|
103
103
|
validate(t) {
|
|
104
104
|
const n = [];
|
|
105
|
-
for (const
|
|
105
|
+
for (const a of t)
|
|
106
106
|
m(
|
|
107
|
-
|
|
107
|
+
a,
|
|
108
108
|
(e) => {
|
|
109
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
109
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
110
110
|
},
|
|
111
111
|
this.at
|
|
112
112
|
);
|
|
@@ -115,13 +115,13 @@ class C extends y {
|
|
|
115
115
|
return [n];
|
|
116
116
|
}
|
|
117
117
|
main(t) {
|
|
118
|
-
t.sort((
|
|
118
|
+
t.sort((a, e) => a - e);
|
|
119
119
|
const n = Math.floor(t.length / 2);
|
|
120
120
|
return t.length % 2 === 0 ? (t[n - 1] + t[n]) / 2 : t[n];
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
const D = "Returns the standard deviation based on a sample.";
|
|
124
|
-
class B extends
|
|
124
|
+
class B extends x {
|
|
125
125
|
constructor() {
|
|
126
126
|
super(...arguments), this.example = "STDEV.S(A1:A100)", this.description = D, this.defs = [
|
|
127
127
|
{
|
|
@@ -135,11 +135,11 @@ class B extends y {
|
|
|
135
135
|
}
|
|
136
136
|
validate(t) {
|
|
137
137
|
const n = [];
|
|
138
|
-
for (const
|
|
138
|
+
for (const a of t)
|
|
139
139
|
m(
|
|
140
|
-
|
|
140
|
+
a,
|
|
141
141
|
(e) => {
|
|
142
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
142
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
143
143
|
},
|
|
144
144
|
this.at
|
|
145
145
|
);
|
|
@@ -148,12 +148,12 @@ class B extends y {
|
|
|
148
148
|
return [n];
|
|
149
149
|
}
|
|
150
150
|
main(t) {
|
|
151
|
-
const n = t.reduce((e,
|
|
152
|
-
return Math.sqrt(
|
|
151
|
+
const n = t.reduce((e, r) => e + r, 0) / t.length, a = t.reduce((e, r) => e + (r - n) ** 2, 0) / (t.length - 1);
|
|
152
|
+
return Math.sqrt(a);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
const P = "Returns the standard deviation based on the entire population.";
|
|
156
|
-
class $ extends
|
|
156
|
+
class $ extends x {
|
|
157
157
|
constructor() {
|
|
158
158
|
super(...arguments), this.example = "STDEV.P(A1:A100)", this.description = P, this.defs = [
|
|
159
159
|
{
|
|
@@ -167,11 +167,11 @@ class $ extends y {
|
|
|
167
167
|
}
|
|
168
168
|
validate(t) {
|
|
169
169
|
const n = [];
|
|
170
|
-
for (const
|
|
170
|
+
for (const a of t)
|
|
171
171
|
m(
|
|
172
|
-
|
|
172
|
+
a,
|
|
173
173
|
(e) => {
|
|
174
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
174
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
175
175
|
},
|
|
176
176
|
this.at
|
|
177
177
|
);
|
|
@@ -180,12 +180,12 @@ class $ extends y {
|
|
|
180
180
|
return [n];
|
|
181
181
|
}
|
|
182
182
|
main(t) {
|
|
183
|
-
const n = t.reduce((e,
|
|
184
|
-
return Math.sqrt(
|
|
183
|
+
const n = t.reduce((e, r) => e + r, 0) / t.length, a = t.reduce((e, r) => e + (r - n) ** 2, 0) / t.length;
|
|
184
|
+
return Math.sqrt(a);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
const U = "Returns the variance based on a sample.";
|
|
188
|
-
class _ extends
|
|
188
|
+
class _ extends x {
|
|
189
189
|
constructor() {
|
|
190
190
|
super(...arguments), this.example = "VAR.S(A1:A100)", this.description = U, this.defs = [
|
|
191
191
|
{
|
|
@@ -199,11 +199,11 @@ class _ extends y {
|
|
|
199
199
|
}
|
|
200
200
|
validate(t) {
|
|
201
201
|
const n = [];
|
|
202
|
-
for (const
|
|
202
|
+
for (const a of t)
|
|
203
203
|
m(
|
|
204
|
-
|
|
204
|
+
a,
|
|
205
205
|
(e) => {
|
|
206
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
206
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
207
207
|
},
|
|
208
208
|
this.at
|
|
209
209
|
);
|
|
@@ -212,12 +212,12 @@ class _ extends y {
|
|
|
212
212
|
return [n];
|
|
213
213
|
}
|
|
214
214
|
main(t) {
|
|
215
|
-
const n = t.reduce((
|
|
216
|
-
return t.reduce((
|
|
215
|
+
const n = t.reduce((a, e) => a + e, 0) / t.length;
|
|
216
|
+
return t.reduce((a, e) => a + (e - n) ** 2, 0) / (t.length - 1);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
const L = "Returns the variance based on the entire population.";
|
|
220
|
-
class Q extends
|
|
220
|
+
class Q extends x {
|
|
221
221
|
constructor() {
|
|
222
222
|
super(...arguments), this.example = "VAR.P(A1:A100)", this.description = L, this.defs = [
|
|
223
223
|
{
|
|
@@ -231,11 +231,11 @@ class Q extends y {
|
|
|
231
231
|
}
|
|
232
232
|
validate(t) {
|
|
233
233
|
const n = [];
|
|
234
|
-
for (const
|
|
234
|
+
for (const a of t)
|
|
235
235
|
m(
|
|
236
|
-
|
|
236
|
+
a,
|
|
237
237
|
(e) => {
|
|
238
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
238
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
239
239
|
},
|
|
240
240
|
this.at
|
|
241
241
|
);
|
|
@@ -244,12 +244,12 @@ class Q extends y {
|
|
|
244
244
|
return [n];
|
|
245
245
|
}
|
|
246
246
|
main(t) {
|
|
247
|
-
const n = t.reduce((
|
|
248
|
-
return t.reduce((
|
|
247
|
+
const n = t.reduce((a, e) => a + e, 0) / t.length;
|
|
248
|
+
return t.reduce((a, e) => a + (e - n) ** 2, 0) / t.length;
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
const G = "Returns the k-th percentile of values in a range, where k is in the range 0 to 1, inclusive.";
|
|
252
|
-
class O extends
|
|
252
|
+
class O extends x {
|
|
253
253
|
constructor() {
|
|
254
254
|
super(...arguments), this.example = "PERCENTILE.INC(A1:A100, 0.9)", this.description = G, this.defs = [
|
|
255
255
|
{
|
|
@@ -265,27 +265,27 @@ class O extends y {
|
|
|
265
265
|
const n = f(t[1]);
|
|
266
266
|
if (n < 0 || n > 1)
|
|
267
267
|
throw new d("#NUM!", "Percentile must be between 0 and 1.");
|
|
268
|
-
const
|
|
268
|
+
const a = [];
|
|
269
269
|
if (m(
|
|
270
270
|
t[0],
|
|
271
271
|
(e) => {
|
|
272
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
272
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
|
|
273
273
|
},
|
|
274
274
|
this.at
|
|
275
|
-
),
|
|
275
|
+
), a.length === 0)
|
|
276
276
|
throw new d("#NUM!", "PERCENTILE.INC requires at least one numeric value.");
|
|
277
|
-
return [
|
|
277
|
+
return [a, n];
|
|
278
278
|
}
|
|
279
279
|
main(t, n) {
|
|
280
280
|
t.sort((i, c) => i - c);
|
|
281
|
-
const
|
|
282
|
-
return t[e] + (t[
|
|
281
|
+
const a = n * (t.length - 1), e = Math.floor(a), r = Math.ceil(a);
|
|
282
|
+
return t[e] + (t[r] - t[e]) * (a - e);
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
-
const
|
|
286
|
-
class
|
|
285
|
+
const X = "Returns the quartile of a dataset, based on percentile values from 0 to 1, inclusive.";
|
|
286
|
+
class Y extends x {
|
|
287
287
|
constructor() {
|
|
288
|
-
super(...arguments), this.example = "QUARTILE.INC(A1:A100, 1)", this.description =
|
|
288
|
+
super(...arguments), this.example = "QUARTILE.INC(A1:A100, 1)", this.description = X, this.defs = [
|
|
289
289
|
{
|
|
290
290
|
name: "data",
|
|
291
291
|
description: "The array or range of data to consider.",
|
|
@@ -303,27 +303,27 @@ class X extends y {
|
|
|
303
303
|
const n = Math.floor(f(t[1]));
|
|
304
304
|
if (n < 0 || n > 4)
|
|
305
305
|
throw new d("#NUM!", "Quartile number must be between 0 and 4.");
|
|
306
|
-
const
|
|
306
|
+
const a = [];
|
|
307
307
|
if (m(
|
|
308
308
|
t[0],
|
|
309
309
|
(e) => {
|
|
310
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
310
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
|
|
311
311
|
},
|
|
312
312
|
this.at
|
|
313
|
-
),
|
|
313
|
+
), a.length === 0)
|
|
314
314
|
throw new d("#NUM!", "QUARTILE.INC requires at least one numeric value.");
|
|
315
|
-
return [
|
|
315
|
+
return [a, n];
|
|
316
316
|
}
|
|
317
317
|
main(t, n) {
|
|
318
318
|
t.sort((c, o) => c - o);
|
|
319
|
-
const e = n / 4 * (t.length - 1),
|
|
320
|
-
return t[
|
|
319
|
+
const e = n / 4 * (t.length - 1), r = Math.floor(e), i = Math.ceil(e);
|
|
320
|
+
return t[r] + (t[i] - t[r]) * (e - r);
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
const
|
|
324
|
-
class
|
|
323
|
+
const K = "Returns the rank of a number in a list of numbers. If more than one value has the same rank, the top rank of that set of values is returned.";
|
|
324
|
+
class W extends x {
|
|
325
325
|
constructor() {
|
|
326
|
-
super(...arguments), this.example = "RANK.EQ(A1, A1:A100)", this.description =
|
|
326
|
+
super(...arguments), this.example = "RANK.EQ(A1, A1:A100)", this.description = K, this.defs = [
|
|
327
327
|
{ name: "value", description: "The value whose rank will be determined.", acceptedTypes: ["number"] },
|
|
328
328
|
{
|
|
329
329
|
name: "data",
|
|
@@ -340,28 +340,28 @@ class K extends y {
|
|
|
340
340
|
], this.category = "statistics";
|
|
341
341
|
}
|
|
342
342
|
validate(t) {
|
|
343
|
-
const n = f(t[0]),
|
|
343
|
+
const n = f(t[0]), a = [];
|
|
344
344
|
if (m(
|
|
345
345
|
t[1],
|
|
346
|
-
(
|
|
347
|
-
|
|
346
|
+
(r) => {
|
|
347
|
+
r == null || r === "" || typeof r == "boolean" || A(r) && a.push(f(r));
|
|
348
348
|
},
|
|
349
349
|
this.at
|
|
350
|
-
),
|
|
350
|
+
), a.length === 0)
|
|
351
351
|
throw new d("#NUM!", "RANK.EQ requires at least one numeric value in data.");
|
|
352
|
-
if (!
|
|
352
|
+
if (!a.includes(n))
|
|
353
353
|
throw new d("#N/A", "Value not found in data range.");
|
|
354
354
|
const e = t[2] ?? !1;
|
|
355
|
-
return [n,
|
|
355
|
+
return [n, a, e];
|
|
356
356
|
}
|
|
357
|
-
main(t, n,
|
|
358
|
-
return n.sort((e,
|
|
357
|
+
main(t, n, a) {
|
|
358
|
+
return n.sort((e, r) => a ? e - r : r - e), n.indexOf(t) + 1;
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
class
|
|
361
|
+
const j = "Returns the correlation coefficient of two datasets.";
|
|
362
|
+
class H extends x {
|
|
363
363
|
constructor() {
|
|
364
|
-
super(...arguments), this.example = "CORREL(A1:A100, B1:B100)", this.description =
|
|
364
|
+
super(...arguments), this.example = "CORREL(A1:A100, B1:B100)", this.description = j, this.defs = [
|
|
365
365
|
{
|
|
366
366
|
name: "data_y",
|
|
367
367
|
description: "The range representing the dependent data.",
|
|
@@ -377,28 +377,28 @@ class j extends y {
|
|
|
377
377
|
], this.category = "statistics";
|
|
378
378
|
}
|
|
379
379
|
validate(t) {
|
|
380
|
-
const n = [],
|
|
380
|
+
const n = [], a = [];
|
|
381
381
|
if (m(
|
|
382
382
|
t[0],
|
|
383
383
|
(e) => {
|
|
384
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
384
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
385
385
|
},
|
|
386
386
|
this.at
|
|
387
387
|
), m(
|
|
388
388
|
t[1],
|
|
389
389
|
(e) => {
|
|
390
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
390
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
|
|
391
391
|
},
|
|
392
392
|
this.at
|
|
393
|
-
), n.length !==
|
|
393
|
+
), n.length !== a.length || n.length < 2)
|
|
394
394
|
throw new d("#N/A", "CORREL requires two ranges of equal length with at least 2 values.");
|
|
395
|
-
return [n,
|
|
395
|
+
return [n, a];
|
|
396
396
|
}
|
|
397
397
|
main(t, n) {
|
|
398
|
-
const
|
|
398
|
+
const a = t.length, e = t.reduce((l, h) => l + h, 0) / a, r = n.reduce((l, h) => l + h, 0) / a;
|
|
399
399
|
let i = 0, c = 0, o = 0;
|
|
400
|
-
for (let l = 0; l <
|
|
401
|
-
const h = t[l] - e, p = n[l] -
|
|
400
|
+
for (let l = 0; l < a; l++) {
|
|
401
|
+
const h = t[l] - e, p = n[l] - r;
|
|
402
402
|
i += h * p, c += h * h, o += p * p;
|
|
403
403
|
}
|
|
404
404
|
const s = Math.sqrt(c * o);
|
|
@@ -407,10 +407,10 @@ class j extends y {
|
|
|
407
407
|
return i / s;
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
|
-
const
|
|
411
|
-
class
|
|
410
|
+
const J = "Returns the sample covariance, the average of the products of deviations for each data point pair in two datasets.";
|
|
411
|
+
class Z extends x {
|
|
412
412
|
constructor() {
|
|
413
|
-
super(...arguments), this.example = "COVARIANCE.S(A1:A100, B1:B100)", this.description =
|
|
413
|
+
super(...arguments), this.example = "COVARIANCE.S(A1:A100, B1:B100)", this.description = J, this.defs = [
|
|
414
414
|
{
|
|
415
415
|
name: "data_y",
|
|
416
416
|
description: "The range representing the first dataset.",
|
|
@@ -426,32 +426,32 @@ class J extends y {
|
|
|
426
426
|
], this.category = "statistics";
|
|
427
427
|
}
|
|
428
428
|
validate(t) {
|
|
429
|
-
const n = [],
|
|
429
|
+
const n = [], a = [];
|
|
430
430
|
if (m(
|
|
431
431
|
t[0],
|
|
432
432
|
(e) => {
|
|
433
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
433
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
434
434
|
},
|
|
435
435
|
this.at
|
|
436
436
|
), m(
|
|
437
437
|
t[1],
|
|
438
438
|
(e) => {
|
|
439
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
439
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
|
|
440
440
|
},
|
|
441
441
|
this.at
|
|
442
|
-
), n.length !==
|
|
442
|
+
), n.length !== a.length || n.length < 2)
|
|
443
443
|
throw new d("#N/A", "COVARIANCE.S requires two ranges of equal length with at least 2 values.");
|
|
444
|
-
return [n,
|
|
444
|
+
return [n, a];
|
|
445
445
|
}
|
|
446
446
|
main(t, n) {
|
|
447
|
-
const
|
|
448
|
-
return t.reduce((i, c, o) => i + (c - e) * (n[o] -
|
|
447
|
+
const a = t.length, e = t.reduce((i, c) => i + c, 0) / a, r = n.reduce((i, c) => i + c, 0) / a;
|
|
448
|
+
return t.reduce((i, c, o) => i + (c - e) * (n[o] - r), 0) / (a - 1);
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
|
-
const
|
|
452
|
-
class
|
|
451
|
+
const z = "Returns the population covariance, the average of the products of deviations for each data point pair in two datasets.";
|
|
452
|
+
class ee extends x {
|
|
453
453
|
constructor() {
|
|
454
|
-
super(...arguments), this.example = "COVARIANCE.P(A1:A100, B1:B100)", this.description =
|
|
454
|
+
super(...arguments), this.example = "COVARIANCE.P(A1:A100, B1:B100)", this.description = z, this.defs = [
|
|
455
455
|
{
|
|
456
456
|
name: "data_y",
|
|
457
457
|
description: "The range representing the first dataset.",
|
|
@@ -467,32 +467,32 @@ class z extends y {
|
|
|
467
467
|
], this.category = "statistics";
|
|
468
468
|
}
|
|
469
469
|
validate(t) {
|
|
470
|
-
const n = [],
|
|
470
|
+
const n = [], a = [];
|
|
471
471
|
if (m(
|
|
472
472
|
t[0],
|
|
473
473
|
(e) => {
|
|
474
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
474
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
475
475
|
},
|
|
476
476
|
this.at
|
|
477
477
|
), m(
|
|
478
478
|
t[1],
|
|
479
479
|
(e) => {
|
|
480
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
480
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
|
|
481
481
|
},
|
|
482
482
|
this.at
|
|
483
|
-
), n.length !==
|
|
483
|
+
), n.length !== a.length || n.length < 1)
|
|
484
484
|
throw new d("#N/A", "COVARIANCE.P requires two ranges of equal length with at least 1 value.");
|
|
485
|
-
return [n,
|
|
485
|
+
return [n, a];
|
|
486
486
|
}
|
|
487
487
|
main(t, n) {
|
|
488
|
-
const
|
|
489
|
-
return t.reduce((i, c, o) => i + (c - e) * (n[o] -
|
|
488
|
+
const a = t.length, e = t.reduce((i, c) => i + c, 0) / a, r = n.reduce((i, c) => i + c, 0) / a;
|
|
489
|
+
return t.reduce((i, c, o) => i + (c - e) * (n[o] - r), 0) / a;
|
|
490
490
|
}
|
|
491
491
|
}
|
|
492
|
-
const
|
|
493
|
-
class
|
|
492
|
+
const te = "Returns the most commonly occurring value in a dataset. If there are multiple modes, the smallest is returned.";
|
|
493
|
+
class ne extends x {
|
|
494
494
|
constructor() {
|
|
495
|
-
super(...arguments), this.example = "MODE.SNGL(A1:A100)", this.description =
|
|
495
|
+
super(...arguments), this.example = "MODE.SNGL(A1:A100)", this.description = te, this.defs = [
|
|
496
496
|
{
|
|
497
497
|
name: "value",
|
|
498
498
|
description: "Numbers or ranges to compute the mode of.",
|
|
@@ -504,11 +504,11 @@ class te extends y {
|
|
|
504
504
|
}
|
|
505
505
|
validate(t) {
|
|
506
506
|
const n = [];
|
|
507
|
-
for (const
|
|
507
|
+
for (const a of t)
|
|
508
508
|
m(
|
|
509
|
-
|
|
509
|
+
a,
|
|
510
510
|
(e) => {
|
|
511
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
511
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
512
512
|
},
|
|
513
513
|
this.at
|
|
514
514
|
);
|
|
@@ -518,19 +518,19 @@ class te extends y {
|
|
|
518
518
|
}
|
|
519
519
|
main(t) {
|
|
520
520
|
const n = /* @__PURE__ */ new Map();
|
|
521
|
-
for (const
|
|
522
|
-
n.set(
|
|
523
|
-
const
|
|
524
|
-
if (
|
|
521
|
+
for (const r of t)
|
|
522
|
+
n.set(r, (n.get(r) ?? 0) + 1);
|
|
523
|
+
const a = Math.max(...n.values());
|
|
524
|
+
if (a < 2)
|
|
525
525
|
throw new d("#N/A", "No value appears more than once.");
|
|
526
|
-
const e = [...n.entries()].filter(([,
|
|
526
|
+
const e = [...n.entries()].filter(([, r]) => r === a).map(([r]) => r);
|
|
527
527
|
return Math.min(...e);
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
|
-
const
|
|
531
|
-
class re extends
|
|
530
|
+
const ae = "Returns the square of the Pearson product-moment correlation coefficient (R²).";
|
|
531
|
+
class re extends x {
|
|
532
532
|
constructor() {
|
|
533
|
-
super(...arguments), this.example = "RSQ(A1:A10, B1:B10)", this.description =
|
|
533
|
+
super(...arguments), this.example = "RSQ(A1:A10, B1:B10)", this.description = ae, this.defs = [
|
|
534
534
|
{
|
|
535
535
|
name: "data_y",
|
|
536
536
|
description: "The range representing the dependent data.",
|
|
@@ -546,30 +546,30 @@ class re extends y {
|
|
|
546
546
|
], this.category = "statistics";
|
|
547
547
|
}
|
|
548
548
|
validate(t) {
|
|
549
|
-
const n = [],
|
|
549
|
+
const n = [], a = [];
|
|
550
550
|
if (m(
|
|
551
551
|
t[0],
|
|
552
552
|
(e) => {
|
|
553
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
553
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
|
|
554
554
|
},
|
|
555
555
|
this.at
|
|
556
556
|
), m(
|
|
557
557
|
t[1],
|
|
558
558
|
(e) => {
|
|
559
|
-
e == null || e === "" || typeof e == "boolean" || (
|
|
559
|
+
e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
|
|
560
560
|
},
|
|
561
561
|
this.at
|
|
562
|
-
), n.length !==
|
|
562
|
+
), n.length !== a.length)
|
|
563
563
|
throw new d("#N/A", "RSQ requires two ranges of equal length.");
|
|
564
564
|
if (n.length < 2)
|
|
565
565
|
throw new d("#N/A", "RSQ requires at least 2 data points.");
|
|
566
|
-
return [n,
|
|
566
|
+
return [n, a];
|
|
567
567
|
}
|
|
568
568
|
main(t, n) {
|
|
569
|
-
const
|
|
569
|
+
const a = t.length, e = t.reduce((h, p) => h + p, 0) / a, r = n.reduce((h, p) => h + p, 0) / a;
|
|
570
570
|
let i = 0, c = 0, o = 0;
|
|
571
|
-
for (let h = 0; h <
|
|
572
|
-
const p = t[h] - e, g = n[h] -
|
|
571
|
+
for (let h = 0; h < a; h++) {
|
|
572
|
+
const p = t[h] - e, g = n[h] - r;
|
|
573
573
|
i += p * g, c += p * p, o += g * g;
|
|
574
574
|
}
|
|
575
575
|
const s = Math.sqrt(c * o);
|
|
@@ -579,20 +579,20 @@ class re extends y {
|
|
|
579
579
|
return l * l;
|
|
580
580
|
}
|
|
581
581
|
}
|
|
582
|
-
const
|
|
582
|
+
const se = `Returns the probability associated with a Student's t-test.
|
|
583
583
|
tails: 1 (one-tailed) or 2 (two-tailed).
|
|
584
584
|
type: 1 (paired), 2 (two-sample equal variance), 3 (two-sample unequal variance).`;
|
|
585
|
-
function
|
|
585
|
+
function q(u, t, n) {
|
|
586
586
|
if (u <= 0)
|
|
587
587
|
return 0;
|
|
588
588
|
if (u >= 1)
|
|
589
589
|
return 1;
|
|
590
590
|
if (u > (t + 1) / (t + n + 2))
|
|
591
|
-
return 1 -
|
|
592
|
-
const
|
|
591
|
+
return 1 - q(1 - u, n, t);
|
|
592
|
+
const a = M(t) + M(n) - M(t + n), e = Math.exp(Math.log(u) * t + Math.log(1 - u) * n - a) / t, r = 200, i = 3e-7;
|
|
593
593
|
let c = 1, o = 1, s = 1 - (t + n) * u / (t + 1);
|
|
594
594
|
Math.abs(s) < 1e-30 && (s = 1e-30), s = 1 / s, c = s;
|
|
595
|
-
for (let l = 1; l <=
|
|
595
|
+
for (let l = 1; l <= r; l++) {
|
|
596
596
|
let h = l * (n - l) * u / ((t + 2 * l - 1) * (t + 2 * l));
|
|
597
597
|
s = 1 + h * s, Math.abs(s) < 1e-30 && (s = 1e-30), o = 1 + h / o, Math.abs(o) < 1e-30 && (o = 1e-30), s = 1 / s, c *= s * o, h = -(t + l) * (t + n + l) * u / ((t + 2 * l) * (t + 2 * l + 1)), s = 1 + h * s, Math.abs(s) < 1e-30 && (s = 1e-30), o = 1 + h / o, Math.abs(o) < 1e-30 && (o = 1e-30), s = 1 / s;
|
|
598
598
|
const p = s * o;
|
|
@@ -601,7 +601,7 @@ function E(u, t, n) {
|
|
|
601
601
|
}
|
|
602
602
|
return e * c;
|
|
603
603
|
}
|
|
604
|
-
function
|
|
604
|
+
function M(u) {
|
|
605
605
|
const n = [
|
|
606
606
|
0.9999999999998099,
|
|
607
607
|
676.5203681218851,
|
|
@@ -614,21 +614,21 @@ function x(u) {
|
|
|
614
614
|
15056327351493116e-23
|
|
615
615
|
];
|
|
616
616
|
if (u < 0.5)
|
|
617
|
-
return Math.log(Math.PI / Math.sin(Math.PI * u)) -
|
|
617
|
+
return Math.log(Math.PI / Math.sin(Math.PI * u)) - M(1 - u);
|
|
618
618
|
u--;
|
|
619
|
-
let
|
|
620
|
-
for (let
|
|
621
|
-
|
|
619
|
+
let a = n[0];
|
|
620
|
+
for (let r = 1; r < 9; r++)
|
|
621
|
+
a += n[r] / (u + r);
|
|
622
622
|
const e = u + 7 + 0.5;
|
|
623
|
-
return 0.5 * Math.log(2 * Math.PI) + (u + 0.5) * Math.log(e) - e + Math.log(
|
|
623
|
+
return 0.5 * Math.log(2 * Math.PI) + (u + 0.5) * Math.log(e) - e + Math.log(a);
|
|
624
624
|
}
|
|
625
|
-
function
|
|
625
|
+
function ie(u, t) {
|
|
626
626
|
const n = t / (t + u * u);
|
|
627
|
-
return
|
|
627
|
+
return q(n, t / 2, 0.5);
|
|
628
628
|
}
|
|
629
|
-
class
|
|
629
|
+
class oe extends x {
|
|
630
630
|
constructor() {
|
|
631
|
-
super(...arguments), this.example = "T.TEST(A1:A100, B1:B100, 2, 2)", this.description =
|
|
631
|
+
super(...arguments), this.example = "T.TEST(A1:A100, B1:B100, 2, 2)", this.description = se, this.defs = [
|
|
632
632
|
{ name: "range1", description: "The first sample of data.", takesMatrix: !0, acceptedTypes: ["matrix"] },
|
|
633
633
|
{ name: "range2", description: "The second sample of data.", takesMatrix: !0, acceptedTypes: ["matrix"] },
|
|
634
634
|
{ name: "tails", description: "The number of distribution tails: 1 or 2.", acceptedTypes: ["number"] },
|
|
@@ -640,12 +640,12 @@ class ie extends y {
|
|
|
640
640
|
], this.category = "statistics";
|
|
641
641
|
}
|
|
642
642
|
validate(t) {
|
|
643
|
-
const n = Math.floor(f(t[2])),
|
|
643
|
+
const n = Math.floor(f(t[2])), a = Math.floor(f(t[3]));
|
|
644
644
|
if (n !== 1 && n !== 2)
|
|
645
645
|
throw new d("#NUM!", "tails must be 1 or 2.");
|
|
646
|
-
if (
|
|
646
|
+
if (a < 1 || a > 3)
|
|
647
647
|
throw new d("#NUM!", "type must be 1, 2, or 3.");
|
|
648
|
-
const e = [],
|
|
648
|
+
const e = [], r = [];
|
|
649
649
|
if (m(
|
|
650
650
|
t[0],
|
|
651
651
|
(i) => {
|
|
@@ -655,33 +655,33 @@ class ie extends y {
|
|
|
655
655
|
), m(
|
|
656
656
|
t[1],
|
|
657
657
|
(i) => {
|
|
658
|
-
i == null || i === "" || typeof i == "boolean" ||
|
|
658
|
+
i == null || i === "" || typeof i == "boolean" || r.push(f(i));
|
|
659
659
|
},
|
|
660
660
|
this.at
|
|
661
|
-
),
|
|
662
|
-
if (e.length !==
|
|
661
|
+
), a === 1) {
|
|
662
|
+
if (e.length !== r.length || e.length < 2)
|
|
663
663
|
throw new d("#N/A", "Paired T.TEST requires equal-length ranges with at least 2 values.");
|
|
664
|
-
} else if (e.length < 2 ||
|
|
665
|
-
throw new d("#DIV/0!", `T.TEST type ${
|
|
666
|
-
return [e,
|
|
664
|
+
} else if (e.length < 2 || r.length < 2)
|
|
665
|
+
throw new d("#DIV/0!", `T.TEST type ${a} requires at least 2 values per range.`);
|
|
666
|
+
return [e, r, n, a];
|
|
667
667
|
}
|
|
668
|
-
main(t, n,
|
|
669
|
-
let
|
|
668
|
+
main(t, n, a, e) {
|
|
669
|
+
let r, i;
|
|
670
670
|
if (e === 1) {
|
|
671
671
|
const o = t.map((p, g) => p - n[g]), s = o.length, l = o.reduce((p, g) => p + g, 0) / s, h = o.reduce((p, g) => p + (g - l) ** 2, 0) / (s - 1);
|
|
672
|
-
|
|
672
|
+
r = l / Math.sqrt(h / s), i = s - 1;
|
|
673
673
|
} else if (e === 2) {
|
|
674
|
-
const o = t.reduce((g,
|
|
675
|
-
|
|
674
|
+
const o = t.reduce((g, w) => g + w, 0) / t.length, s = n.reduce((g, w) => g + w, 0) / n.length, l = t.reduce((g, w) => g + (w - o) ** 2, 0) / (t.length - 1), h = n.reduce((g, w) => g + (w - s) ** 2, 0) / (n.length - 1), p = ((t.length - 1) * l + (n.length - 1) * h) / (t.length + n.length - 2);
|
|
675
|
+
r = (o - s) / Math.sqrt(p * (1 / t.length + 1 / n.length)), i = t.length + n.length - 2;
|
|
676
676
|
} else {
|
|
677
|
-
const o = t.reduce((
|
|
678
|
-
|
|
677
|
+
const o = t.reduce((w, y) => w + y, 0) / t.length, s = n.reduce((w, y) => w + y, 0) / n.length, l = t.reduce((w, y) => w + (y - o) ** 2, 0) / (t.length - 1), h = n.reduce((w, y) => w + (y - s) ** 2, 0) / (n.length - 1), p = l / t.length, g = h / n.length;
|
|
678
|
+
r = (o - s) / Math.sqrt(p + g), i = (p + g) ** 2 / (p ** 2 / (t.length - 1) + g ** 2 / (n.length - 1));
|
|
679
679
|
}
|
|
680
|
-
const c =
|
|
681
|
-
return
|
|
680
|
+
const c = ie(Math.abs(r), i);
|
|
681
|
+
return a === 1 ? c / 2 : c;
|
|
682
682
|
}
|
|
683
683
|
}
|
|
684
|
-
const
|
|
684
|
+
const ue = {
|
|
685
685
|
averageif: S,
|
|
686
686
|
averageifs: V,
|
|
687
687
|
median: C,
|
|
@@ -690,17 +690,17 @@ const ce = {
|
|
|
690
690
|
"var.s": _,
|
|
691
691
|
"var.p": Q,
|
|
692
692
|
"percentile.inc": O,
|
|
693
|
-
"quartile.inc":
|
|
694
|
-
"rank.eq":
|
|
695
|
-
correl:
|
|
696
|
-
"covariance.s":
|
|
697
|
-
"covariance.p":
|
|
698
|
-
"mode.sngl":
|
|
693
|
+
"quartile.inc": Y,
|
|
694
|
+
"rank.eq": W,
|
|
695
|
+
correl: H,
|
|
696
|
+
"covariance.s": Z,
|
|
697
|
+
"covariance.p": ee,
|
|
698
|
+
"mode.sngl": ne,
|
|
699
699
|
rsq: re,
|
|
700
|
-
"t.test":
|
|
700
|
+
"t.test": oe
|
|
701
701
|
};
|
|
702
702
|
export {
|
|
703
|
-
|
|
704
|
-
|
|
703
|
+
ue as default,
|
|
704
|
+
ue as statisticsFunctions
|
|
705
705
|
};
|
|
706
706
|
//# sourceMappingURL=index.js.map
|