@datagrok-libraries/statistics 0.1.0 → 0.1.1
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 +28 -28
- package/README.md +2 -2
- package/package.json +32 -35
- package/src/multiple-tests.ts +234 -234
- package/src/tests.ts +101 -101
- package/tsconfig.json +71 -71
- package/detectors.js +0 -9
- package/webpack.config.js +0 -33
package/.eslintrc.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"browser": true,
|
|
4
|
-
"es2021": true
|
|
5
|
-
},
|
|
6
|
-
"extends": [
|
|
7
|
-
"google"
|
|
8
|
-
],
|
|
9
|
-
"parserOptions": {
|
|
10
|
-
"ecmaVersion": 12,
|
|
11
|
-
"sourceType": "module"
|
|
12
|
-
},
|
|
13
|
-
"rules": {
|
|
14
|
-
"indent": [
|
|
15
|
-
"error",
|
|
16
|
-
2
|
|
17
|
-
],
|
|
18
|
-
"max-len": [
|
|
19
|
-
"error",
|
|
20
|
-
120
|
|
21
|
-
],
|
|
22
|
-
"require-jsdoc": "off",
|
|
23
|
-
"spaced-comment": "off"
|
|
24
|
-
},
|
|
25
|
-
"parser": "@typescript-eslint/parser",
|
|
26
|
-
"plugins": [
|
|
27
|
-
"@typescript-eslint"
|
|
28
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"es2021": true
|
|
5
|
+
},
|
|
6
|
+
"extends": [
|
|
7
|
+
"google"
|
|
8
|
+
],
|
|
9
|
+
"parserOptions": {
|
|
10
|
+
"ecmaVersion": 12,
|
|
11
|
+
"sourceType": "module"
|
|
12
|
+
},
|
|
13
|
+
"rules": {
|
|
14
|
+
"indent": [
|
|
15
|
+
"error",
|
|
16
|
+
2
|
|
17
|
+
],
|
|
18
|
+
"max-len": [
|
|
19
|
+
"error",
|
|
20
|
+
120
|
|
21
|
+
],
|
|
22
|
+
"require-jsdoc": "off",
|
|
23
|
+
"spaced-comment": "off"
|
|
24
|
+
},
|
|
25
|
+
"parser": "@typescript-eslint/parser",
|
|
26
|
+
"plugins": [
|
|
27
|
+
"@typescript-eslint"
|
|
28
|
+
]
|
|
29
29
|
}
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# statistics
|
|
2
|
-
|
|
1
|
+
# statistics
|
|
2
|
+
|
|
3
3
|
statistics is a [package](https://datagrok.ai/help/develop/develop#packages) for the [Datagrok](https://datagrok.ai) platform.
|
package/package.json
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@datagrok-libraries/statistics",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"eslint": "latest"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"lint-fix": "eslint src --ext .ts --fix"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@datagrok-libraries/statistics",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"friendlyName": "statistics",
|
|
7
|
+
"version": "0.1.1",
|
|
8
|
+
"description": "",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"datagrok-api": ">0.95.4",
|
|
11
|
+
"cash-dom": "latest",
|
|
12
|
+
"dayjs": "latest",
|
|
13
|
+
"ts-loader": "latest",
|
|
14
|
+
"typescript": "^4.2.3",
|
|
15
|
+
"jstat": "latest"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"eslint": "latest",
|
|
19
|
+
"eslint-config-google": "latest",
|
|
20
|
+
"@typescript-eslint/eslint-plugin": "latest",
|
|
21
|
+
"@typescript-eslint/parser": "latest"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"link": "npm link",
|
|
25
|
+
"debug-statistics": "grok publish --rebuild",
|
|
26
|
+
"release-statistics": "grok publish --rebuild --release",
|
|
27
|
+
"build-statistics": "tsc",
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"lint": "eslint src --ext .ts",
|
|
30
|
+
"lint-fix": "eslint src --ext .ts --fix"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/multiple-tests.ts
CHANGED
|
@@ -1,234 +1,234 @@
|
|
|
1
|
-
/** @type {*} A dictionary of basic binary operations. */
|
|
2
|
-
const _operations: {[name: string]: Function} = {
|
|
3
|
-
'+': (a: number, b: number) => (a + b),
|
|
4
|
-
'-': (a: number, b: number) => (a - b),
|
|
5
|
-
'*': (a: number, b: number) => (a * b),
|
|
6
|
-
'/': (a: number, b: number) => (a / b),
|
|
7
|
-
'min': (a: number, b: number) => (a < b ? a : b),
|
|
8
|
-
'max': (a: number, b: number) => (a > b ? a : b),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Returns the indices that would sort an array.
|
|
13
|
-
*
|
|
14
|
-
* @param {Float32Array} values Array to sort.
|
|
15
|
-
* @return {Int32Array} Array of indices that sort values along the first axis.
|
|
16
|
-
*/
|
|
17
|
-
function _argsort(values: Float32Array): Int32Array {
|
|
18
|
-
const v = Array.from(values);
|
|
19
|
-
|
|
20
|
-
const argsort = (arr: number[]) => arr
|
|
21
|
-
.map((v, i) => [v, i]) // Decorate with index
|
|
22
|
-
.sort((a, b) => (a[0] == b[0] ? 0 : (a[0] > b[0] ? 1 : -1)))
|
|
23
|
-
.map((v, _) => v[1]); // Undecorate
|
|
24
|
-
|
|
25
|
-
const forder = argsort(v);
|
|
26
|
-
|
|
27
|
-
return Int32Array.from(forder);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Take elements from an array.
|
|
33
|
-
*
|
|
34
|
-
* @param {Int32Array} order The indices of the values to extract.
|
|
35
|
-
* @param {Float32Array} values The source array.
|
|
36
|
-
* @return {Float32Array} The returned array has the same type as values.
|
|
37
|
-
*/
|
|
38
|
-
function _take(order: Int32Array, values: Float32Array): Float32Array {
|
|
39
|
-
// TODO: Implement a general function for TypedArray.
|
|
40
|
-
return Float32Array.from(values).map((_, i) => values[order[i]]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Assign elements of an array following the order given (floating-point version).
|
|
45
|
-
*
|
|
46
|
-
* @param {Float32Array} values The source array.
|
|
47
|
-
* @param {Int32Array} order The order given.
|
|
48
|
-
* @return {Float32Array} The returned array has the same type as values.
|
|
49
|
-
*/
|
|
50
|
-
function _give(values: Float32Array, order: Int32Array): Float32Array {
|
|
51
|
-
const v = Float32Array.from(values);
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < order.length; ++i) {
|
|
54
|
-
v[order[i]] = values[i];
|
|
55
|
-
}
|
|
56
|
-
return v;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Assign elements of an array following the order given (boolean version).
|
|
61
|
-
*
|
|
62
|
-
* @param {Array<boolean>} values The source array.
|
|
63
|
-
* @param {Int32Array} order The order given.
|
|
64
|
-
* @return {Array<boolean>} The returned array has the same type as values.
|
|
65
|
-
*/
|
|
66
|
-
function _giveb(values: Array<boolean>, order: Int32Array): Array<boolean> {
|
|
67
|
-
const v = Array.from(values);
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < order.length; ++i) {
|
|
70
|
-
v[order[i]] = values[i];
|
|
71
|
-
}
|
|
72
|
-
return v;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* No frills empirical cdf used in fdrcorrection.
|
|
77
|
-
*
|
|
78
|
-
* @param {Float32Array} x The source array to take a dimension from.
|
|
79
|
-
* @return {Float32Array} Empirical cdf.
|
|
80
|
-
*/
|
|
81
|
-
function _ecdf(x: Float32Array): Float32Array {
|
|
82
|
-
const nobs = x.length;
|
|
83
|
-
return Float32Array.from(x).map((_, i) => (i+1)/nobs);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* cm = np.sum(1./np.arange(1, len(pvals_sorted)+1))
|
|
88
|
-
*
|
|
89
|
-
* @param {number} n The number given.
|
|
90
|
-
* @return {number} cm value.
|
|
91
|
-
*/
|
|
92
|
-
function _cm(n: number): number {
|
|
93
|
-
let sum = 0;
|
|
94
|
-
for (let i = 0; i < n; ++i) {
|
|
95
|
-
sum += 1 / (i+1);
|
|
96
|
-
}
|
|
97
|
-
return sum;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Basic operation under a vector and a scalar.
|
|
102
|
-
*
|
|
103
|
-
* @param {Float32Array} values The source vector.
|
|
104
|
-
* @param {number} scale The scalar.
|
|
105
|
-
* @param {string} [op='*'] The operation to perform.
|
|
106
|
-
* @return {Float32Array} New vector as a result of the operation.
|
|
107
|
-
*/
|
|
108
|
-
function _factor(values: Float32Array, scale: number, op = '*'): Float32Array {
|
|
109
|
-
return Float32Array.from(values).map((v, _) => _operations[op](v, scale));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Basic operation under two vectors.
|
|
114
|
-
*
|
|
115
|
-
* @param {Float32Array} values The first vector.
|
|
116
|
-
* @param {Float32Array} scale The second vector.
|
|
117
|
-
* @param {string} [op='*'] The operation to perform.
|
|
118
|
-
* @return {Float32Array} New vector as a result of the operation.
|
|
119
|
-
*/
|
|
120
|
-
function _vfactor(values: Float32Array, scale: Float32Array, op = '*'): Float32Array {
|
|
121
|
-
return Float32Array.from(values).map((v, i) => _operations[op](v, scale[i]));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Accumulate the result of applying the min operator to all elements.
|
|
126
|
-
*
|
|
127
|
-
* @param {Float32Array} values The array to act on.
|
|
128
|
-
* @return {Float32Array} The accumulated values.
|
|
129
|
-
*/
|
|
130
|
-
function _minimumAccumulate(values: Float32Array): Float32Array {
|
|
131
|
-
const nItems = values.length;
|
|
132
|
-
const r = Float32Array.from(values);
|
|
133
|
-
|
|
134
|
-
for (let i = 0; i < nItems; ++i) {
|
|
135
|
-
r[i] = values.slice(0, i+1).reduce((a, b, _, __) => (_operations['min'](a, b)));
|
|
136
|
-
}
|
|
137
|
-
return r;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* pvalue correction for false discovery rate
|
|
142
|
-
*
|
|
143
|
-
* @export
|
|
144
|
-
* @param {Float32Array} pvals Set of p-values of the individual tests.
|
|
145
|
-
* @param {number} [alpha=0.05] Family-wise error rate. Defaults to 0.05.
|
|
146
|
-
* @param {string} [method='n'] {'i', 'indep', 'p', 'poscorr', 'n', 'negcorr'}, optional
|
|
147
|
-
* Which method to use for FDR correction.
|
|
148
|
-
* ``{'i', 'indep', 'p', 'poscorr'}`` all refer to ``fdr_bh``
|
|
149
|
-
* (Benjamini/Hochberg for independent or positively
|
|
150
|
-
* correlated tests). ``{'n', 'negcorr'}`` both refer to ``fdr_by``
|
|
151
|
-
* (Benjamini/Yekutieli for general or negatively correlated tests).
|
|
152
|
-
* Defaults to 'n'.
|
|
153
|
-
* @param {boolean} [isSorted=false] If False (default), the p_values will be sorted, but the corrected
|
|
154
|
-
* pvalues are in the original order. If True, then it assumed that the
|
|
155
|
-
* pvalues are already sorted in ascending order.
|
|
156
|
-
* @return {[Array<boolean>, Float32Array]} rejected : ndarray, bool
|
|
157
|
-
* True if a hypothesis is rejected, False if not
|
|
158
|
-
* pvalue-corrected : ndarray
|
|
159
|
-
* pvalues adjusted for multiple hypothesis testing to limit FDR
|
|
160
|
-
* @see
|
|
161
|
-
* If there is prior information on the fraction of true hypothesis, then alpha
|
|
162
|
-
* should be set to ``alpha * m/m_0`` where m is the number of tests,
|
|
163
|
-
* given by the p-values, and m_0 is an estimate of the true hypothesis.
|
|
164
|
-
* (see Benjamini, Krieger and Yekuteli)
|
|
165
|
-
*
|
|
166
|
-
* The two-step method of Benjamini, Krieger and Yekutiel that estimates the number
|
|
167
|
-
* of false hypotheses will be available (soon).
|
|
168
|
-
*
|
|
169
|
-
* Both methods exposed via this function (Benjamini/Hochberg, Benjamini/Yekutieli)
|
|
170
|
-
* are also available in the function ``multipletests``, as ``method="fdr_bh"`` and
|
|
171
|
-
* ``method="fdr_by"``, respectively.
|
|
172
|
-
*/
|
|
173
|
-
export function fdrcorrection(
|
|
174
|
-
pvals: Float32Array,
|
|
175
|
-
alpha: number = 0.05,
|
|
176
|
-
method: string ='n',
|
|
177
|
-
isSorted: boolean = false): [Array<boolean>, Float32Array]
|
|
178
|
-
// eslint-disable-next-line brace-style
|
|
179
|
-
{
|
|
180
|
-
const nItems = pvals.length;
|
|
181
|
-
let pvalsSorted: Float32Array;
|
|
182
|
-
let pvalsSortind: Int32Array;
|
|
183
|
-
let cm = 0;
|
|
184
|
-
|
|
185
|
-
if (!isSorted) {
|
|
186
|
-
pvalsSortind = _argsort(pvals);
|
|
187
|
-
pvalsSorted = _take(pvalsSortind, pvals);
|
|
188
|
-
} else {
|
|
189
|
-
pvalsSortind = new Int32Array(nItems).fill(0).map((_, i) => (i));
|
|
190
|
-
pvalsSorted = pvals; // alias
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
let ecdffactor = _ecdf(pvalsSorted);
|
|
194
|
-
|
|
195
|
-
if (['i', 'indep', 'p', 'poscorr'].includes(method)) {
|
|
196
|
-
;
|
|
197
|
-
} else if (['n', 'negcorr'].includes(method)) {
|
|
198
|
-
cm = _cm(nItems);
|
|
199
|
-
ecdffactor = _factor(ecdffactor, cm, '/');
|
|
200
|
-
} else {
|
|
201
|
-
throw new Error('only indep and negcorr implemented');
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const reject: boolean[] = new Array(nItems).fill(false);
|
|
205
|
-
let rejectmax = -1;
|
|
206
|
-
|
|
207
|
-
for (let i = 0; i < nItems; ++i) {
|
|
208
|
-
if (pvalsSorted[i] <= ecdffactor[i]*alpha) {
|
|
209
|
-
rejectmax = i;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (rejectmax >= 0) {
|
|
214
|
-
for (let i = 0; i < rejectmax; ++i) {
|
|
215
|
-
reject[i] = true;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
let pvalsCorrected = _vfactor(pvalsSorted, ecdffactor, '/');
|
|
220
|
-
pvalsCorrected = _minimumAccumulate(pvalsCorrected.reverse()).reverse();
|
|
221
|
-
|
|
222
|
-
for (let i = 0; i < nItems; ++i) {
|
|
223
|
-
if (pvalsCorrected[i] > 1) {
|
|
224
|
-
pvalsCorrected[i] = 1;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (!isSorted) {
|
|
229
|
-
const pvalsCorrected_ = _give(pvalsCorrected, pvalsSortind);
|
|
230
|
-
const reject_ = _giveb(reject, pvalsSortind);
|
|
231
|
-
return [reject_, pvalsCorrected_];
|
|
232
|
-
}
|
|
233
|
-
return [reject, pvalsCorrected];
|
|
234
|
-
}
|
|
1
|
+
/** @type {*} A dictionary of basic binary operations. */
|
|
2
|
+
const _operations: {[name: string]: Function} = {
|
|
3
|
+
'+': (a: number, b: number) => (a + b),
|
|
4
|
+
'-': (a: number, b: number) => (a - b),
|
|
5
|
+
'*': (a: number, b: number) => (a * b),
|
|
6
|
+
'/': (a: number, b: number) => (a / b),
|
|
7
|
+
'min': (a: number, b: number) => (a < b ? a : b),
|
|
8
|
+
'max': (a: number, b: number) => (a > b ? a : b),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns the indices that would sort an array.
|
|
13
|
+
*
|
|
14
|
+
* @param {Float32Array} values Array to sort.
|
|
15
|
+
* @return {Int32Array} Array of indices that sort values along the first axis.
|
|
16
|
+
*/
|
|
17
|
+
function _argsort(values: Float32Array): Int32Array {
|
|
18
|
+
const v = Array.from(values);
|
|
19
|
+
|
|
20
|
+
const argsort = (arr: number[]) => arr
|
|
21
|
+
.map((v, i) => [v, i]) // Decorate with index
|
|
22
|
+
.sort((a, b) => (a[0] == b[0] ? 0 : (a[0] > b[0] ? 1 : -1)))
|
|
23
|
+
.map((v, _) => v[1]); // Undecorate
|
|
24
|
+
|
|
25
|
+
const forder = argsort(v);
|
|
26
|
+
|
|
27
|
+
return Int32Array.from(forder);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Take elements from an array.
|
|
33
|
+
*
|
|
34
|
+
* @param {Int32Array} order The indices of the values to extract.
|
|
35
|
+
* @param {Float32Array} values The source array.
|
|
36
|
+
* @return {Float32Array} The returned array has the same type as values.
|
|
37
|
+
*/
|
|
38
|
+
function _take(order: Int32Array, values: Float32Array): Float32Array {
|
|
39
|
+
// TODO: Implement a general function for TypedArray.
|
|
40
|
+
return Float32Array.from(values).map((_, i) => values[order[i]]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Assign elements of an array following the order given (floating-point version).
|
|
45
|
+
*
|
|
46
|
+
* @param {Float32Array} values The source array.
|
|
47
|
+
* @param {Int32Array} order The order given.
|
|
48
|
+
* @return {Float32Array} The returned array has the same type as values.
|
|
49
|
+
*/
|
|
50
|
+
function _give(values: Float32Array, order: Int32Array): Float32Array {
|
|
51
|
+
const v = Float32Array.from(values);
|
|
52
|
+
|
|
53
|
+
for (let i = 0; i < order.length; ++i) {
|
|
54
|
+
v[order[i]] = values[i];
|
|
55
|
+
}
|
|
56
|
+
return v;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Assign elements of an array following the order given (boolean version).
|
|
61
|
+
*
|
|
62
|
+
* @param {Array<boolean>} values The source array.
|
|
63
|
+
* @param {Int32Array} order The order given.
|
|
64
|
+
* @return {Array<boolean>} The returned array has the same type as values.
|
|
65
|
+
*/
|
|
66
|
+
function _giveb(values: Array<boolean>, order: Int32Array): Array<boolean> {
|
|
67
|
+
const v = Array.from(values);
|
|
68
|
+
|
|
69
|
+
for (let i = 0; i < order.length; ++i) {
|
|
70
|
+
v[order[i]] = values[i];
|
|
71
|
+
}
|
|
72
|
+
return v;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* No frills empirical cdf used in fdrcorrection.
|
|
77
|
+
*
|
|
78
|
+
* @param {Float32Array} x The source array to take a dimension from.
|
|
79
|
+
* @return {Float32Array} Empirical cdf.
|
|
80
|
+
*/
|
|
81
|
+
function _ecdf(x: Float32Array): Float32Array {
|
|
82
|
+
const nobs = x.length;
|
|
83
|
+
return Float32Array.from(x).map((_, i) => (i+1)/nobs);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* cm = np.sum(1./np.arange(1, len(pvals_sorted)+1))
|
|
88
|
+
*
|
|
89
|
+
* @param {number} n The number given.
|
|
90
|
+
* @return {number} cm value.
|
|
91
|
+
*/
|
|
92
|
+
function _cm(n: number): number {
|
|
93
|
+
let sum = 0;
|
|
94
|
+
for (let i = 0; i < n; ++i) {
|
|
95
|
+
sum += 1 / (i+1);
|
|
96
|
+
}
|
|
97
|
+
return sum;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Basic operation under a vector and a scalar.
|
|
102
|
+
*
|
|
103
|
+
* @param {Float32Array} values The source vector.
|
|
104
|
+
* @param {number} scale The scalar.
|
|
105
|
+
* @param {string} [op='*'] The operation to perform.
|
|
106
|
+
* @return {Float32Array} New vector as a result of the operation.
|
|
107
|
+
*/
|
|
108
|
+
function _factor(values: Float32Array, scale: number, op = '*'): Float32Array {
|
|
109
|
+
return Float32Array.from(values).map((v, _) => _operations[op](v, scale));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Basic operation under two vectors.
|
|
114
|
+
*
|
|
115
|
+
* @param {Float32Array} values The first vector.
|
|
116
|
+
* @param {Float32Array} scale The second vector.
|
|
117
|
+
* @param {string} [op='*'] The operation to perform.
|
|
118
|
+
* @return {Float32Array} New vector as a result of the operation.
|
|
119
|
+
*/
|
|
120
|
+
function _vfactor(values: Float32Array, scale: Float32Array, op = '*'): Float32Array {
|
|
121
|
+
return Float32Array.from(values).map((v, i) => _operations[op](v, scale[i]));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Accumulate the result of applying the min operator to all elements.
|
|
126
|
+
*
|
|
127
|
+
* @param {Float32Array} values The array to act on.
|
|
128
|
+
* @return {Float32Array} The accumulated values.
|
|
129
|
+
*/
|
|
130
|
+
function _minimumAccumulate(values: Float32Array): Float32Array {
|
|
131
|
+
const nItems = values.length;
|
|
132
|
+
const r = Float32Array.from(values);
|
|
133
|
+
|
|
134
|
+
for (let i = 0; i < nItems; ++i) {
|
|
135
|
+
r[i] = values.slice(0, i+1).reduce((a, b, _, __) => (_operations['min'](a, b)));
|
|
136
|
+
}
|
|
137
|
+
return r;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* pvalue correction for false discovery rate
|
|
142
|
+
*
|
|
143
|
+
* @export
|
|
144
|
+
* @param {Float32Array} pvals Set of p-values of the individual tests.
|
|
145
|
+
* @param {number} [alpha=0.05] Family-wise error rate. Defaults to 0.05.
|
|
146
|
+
* @param {string} [method='n'] {'i', 'indep', 'p', 'poscorr', 'n', 'negcorr'}, optional
|
|
147
|
+
* Which method to use for FDR correction.
|
|
148
|
+
* ``{'i', 'indep', 'p', 'poscorr'}`` all refer to ``fdr_bh``
|
|
149
|
+
* (Benjamini/Hochberg for independent or positively
|
|
150
|
+
* correlated tests). ``{'n', 'negcorr'}`` both refer to ``fdr_by``
|
|
151
|
+
* (Benjamini/Yekutieli for general or negatively correlated tests).
|
|
152
|
+
* Defaults to 'n'.
|
|
153
|
+
* @param {boolean} [isSorted=false] If False (default), the p_values will be sorted, but the corrected
|
|
154
|
+
* pvalues are in the original order. If True, then it assumed that the
|
|
155
|
+
* pvalues are already sorted in ascending order.
|
|
156
|
+
* @return {[Array<boolean>, Float32Array]} rejected : ndarray, bool
|
|
157
|
+
* True if a hypothesis is rejected, False if not
|
|
158
|
+
* pvalue-corrected : ndarray
|
|
159
|
+
* pvalues adjusted for multiple hypothesis testing to limit FDR
|
|
160
|
+
* @see
|
|
161
|
+
* If there is prior information on the fraction of true hypothesis, then alpha
|
|
162
|
+
* should be set to ``alpha * m/m_0`` where m is the number of tests,
|
|
163
|
+
* given by the p-values, and m_0 is an estimate of the true hypothesis.
|
|
164
|
+
* (see Benjamini, Krieger and Yekuteli)
|
|
165
|
+
*
|
|
166
|
+
* The two-step method of Benjamini, Krieger and Yekutiel that estimates the number
|
|
167
|
+
* of false hypotheses will be available (soon).
|
|
168
|
+
*
|
|
169
|
+
* Both methods exposed via this function (Benjamini/Hochberg, Benjamini/Yekutieli)
|
|
170
|
+
* are also available in the function ``multipletests``, as ``method="fdr_bh"`` and
|
|
171
|
+
* ``method="fdr_by"``, respectively.
|
|
172
|
+
*/
|
|
173
|
+
export function fdrcorrection(
|
|
174
|
+
pvals: Float32Array,
|
|
175
|
+
alpha: number = 0.05,
|
|
176
|
+
method: string ='n',
|
|
177
|
+
isSorted: boolean = false): [Array<boolean>, Float32Array]
|
|
178
|
+
// eslint-disable-next-line brace-style
|
|
179
|
+
{
|
|
180
|
+
const nItems = pvals.length;
|
|
181
|
+
let pvalsSorted: Float32Array;
|
|
182
|
+
let pvalsSortind: Int32Array;
|
|
183
|
+
let cm = 0;
|
|
184
|
+
|
|
185
|
+
if (!isSorted) {
|
|
186
|
+
pvalsSortind = _argsort(pvals);
|
|
187
|
+
pvalsSorted = _take(pvalsSortind, pvals);
|
|
188
|
+
} else {
|
|
189
|
+
pvalsSortind = new Int32Array(nItems).fill(0).map((_, i) => (i));
|
|
190
|
+
pvalsSorted = pvals; // alias
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let ecdffactor = _ecdf(pvalsSorted);
|
|
194
|
+
|
|
195
|
+
if (['i', 'indep', 'p', 'poscorr'].includes(method)) {
|
|
196
|
+
;
|
|
197
|
+
} else if (['n', 'negcorr'].includes(method)) {
|
|
198
|
+
cm = _cm(nItems);
|
|
199
|
+
ecdffactor = _factor(ecdffactor, cm, '/');
|
|
200
|
+
} else {
|
|
201
|
+
throw new Error('only indep and negcorr implemented');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const reject: boolean[] = new Array(nItems).fill(false);
|
|
205
|
+
let rejectmax = -1;
|
|
206
|
+
|
|
207
|
+
for (let i = 0; i < nItems; ++i) {
|
|
208
|
+
if (pvalsSorted[i] <= ecdffactor[i]*alpha) {
|
|
209
|
+
rejectmax = i;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (rejectmax >= 0) {
|
|
214
|
+
for (let i = 0; i < rejectmax; ++i) {
|
|
215
|
+
reject[i] = true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
let pvalsCorrected = _vfactor(pvalsSorted, ecdffactor, '/');
|
|
220
|
+
pvalsCorrected = _minimumAccumulate(pvalsCorrected.reverse()).reverse();
|
|
221
|
+
|
|
222
|
+
for (let i = 0; i < nItems; ++i) {
|
|
223
|
+
if (pvalsCorrected[i] > 1) {
|
|
224
|
+
pvalsCorrected[i] = 1;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!isSorted) {
|
|
229
|
+
const pvalsCorrected_ = _give(pvalsCorrected, pvalsSortind);
|
|
230
|
+
const reject_ = _giveb(reject, pvalsSortind);
|
|
231
|
+
return [reject_, pvalsCorrected_];
|
|
232
|
+
}
|
|
233
|
+
return [reject, pvalsCorrected];
|
|
234
|
+
}
|
package/src/tests.ts
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
//@ts-ignore: no types
|
|
2
|
-
import * as jStat from 'jstat';
|
|
3
|
-
|
|
4
|
-
type testStats = {
|
|
5
|
-
'p-value': number,
|
|
6
|
-
'Mean difference'?: number,
|
|
7
|
-
'Median difference'?: number,
|
|
8
|
-
'p-value more': number,
|
|
9
|
-
'p-value less': number,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export function tTest(arr1: number[], arr2: number[], devKnown=false, devEqual=false): testStats {
|
|
13
|
-
const m1: number = jStat.mean(arr1);
|
|
14
|
-
const m2: number = jStat.mean(arr2);
|
|
15
|
-
const v1: number = jStat.variance(arr1);
|
|
16
|
-
const v2: number = jStat.variance(arr2);
|
|
17
|
-
const n1 = arr1.length;
|
|
18
|
-
const n2 = arr2.length;
|
|
19
|
-
|
|
20
|
-
let wv1;
|
|
21
|
-
let wv2;
|
|
22
|
-
let wv;
|
|
23
|
-
let Z;
|
|
24
|
-
let K;
|
|
25
|
-
let pMore;
|
|
26
|
-
let pLess;
|
|
27
|
-
let pTot;
|
|
28
|
-
|
|
29
|
-
if (!devKnown) {
|
|
30
|
-
if (!devEqual) {
|
|
31
|
-
wv1 = v1 / n1;
|
|
32
|
-
wv2 = v2 / n2;
|
|
33
|
-
Z = (m1 - m2) / Math.sqrt(wv1 + wv2);
|
|
34
|
-
K = Math.pow((wv1 + wv2), 2) / (wv1 * wv1 / (n1 - 1) + wv2 * wv2 / (n2 - 1));
|
|
35
|
-
|
|
36
|
-
pLess = jStat.studentt.cdf(Z, K);
|
|
37
|
-
pMore = 1 - pLess;
|
|
38
|
-
pTot = 2 * (pLess < pMore ? pLess : pMore);
|
|
39
|
-
} else {
|
|
40
|
-
K = n1 + n2 - 2;
|
|
41
|
-
wv = (v1 * (n1 - 1) + v2 * (n2 - 1)) / K;
|
|
42
|
-
Z = Math.sqrt(n1 * n2 / (n1 + n2)) * (m1 - m2) / wv;
|
|
43
|
-
|
|
44
|
-
pMore = 1 - jStat.studentt.cdf(Z, K);
|
|
45
|
-
pLess = jStat.studentt.cdf(Z, K);
|
|
46
|
-
pTot = 2 * (pLess < pMore ? pLess : pMore);
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
wv1 = v1 / n1;
|
|
50
|
-
wv2 = v2 / n2;
|
|
51
|
-
Z = (m1 - m2) / Math.sqrt(wv1 + wv2);
|
|
52
|
-
|
|
53
|
-
pLess = jStat.normal.pdf(Z, 0, 1);
|
|
54
|
-
pMore = 1 - pLess;
|
|
55
|
-
pTot = 2 * (pLess < pMore ? pLess : pMore);
|
|
56
|
-
}
|
|
57
|
-
return {'p-value': pTot, 'Mean difference': m1 - m2, 'p-value more': pMore, 'p-value less': pLess};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function uTest(x: number[], y: number[], continuity=true): testStats {
|
|
61
|
-
const xy = x.concat(y);
|
|
62
|
-
const n1 = x.length;
|
|
63
|
-
const n2 = y.length;
|
|
64
|
-
const med1 = jStat.median(x);
|
|
65
|
-
const med2 = jStat.median(y);
|
|
66
|
-
|
|
67
|
-
const ranks = jStat.rank(xy);
|
|
68
|
-
|
|
69
|
-
const R1 = jStat.sum(ranks.slice(0, n1));
|
|
70
|
-
const U1 = R1 - n1 * (n1 + 1) / 2;
|
|
71
|
-
const U2 = n1 * n2 - U1;
|
|
72
|
-
const U = U1 > U2 ? U1 : U2;
|
|
73
|
-
|
|
74
|
-
const mu = n1 * n2 / 2;
|
|
75
|
-
const n = n1 + n2;
|
|
76
|
-
|
|
77
|
-
const tieTerm = _tieTerm(ranks);
|
|
78
|
-
const s = Math.sqrt(n1 * n2 / 12 * ((n + 1) - tieTerm / (n* (n - 1))));
|
|
79
|
-
|
|
80
|
-
let numerator = U - mu;
|
|
81
|
-
|
|
82
|
-
if (continuity) {
|
|
83
|
-
numerator -= 0.5;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const z = numerator / s;
|
|
87
|
-
|
|
88
|
-
const p = 2 * (1 - jStat.normal.cdf(z, 0, 1));
|
|
89
|
-
|
|
90
|
-
return {'p-value': p, 'Median difference': med1 - med2, 'p-value more': p, 'p-value less': p};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function _tieTerm(ranks: number[]): number {
|
|
94
|
-
const ties: {[key: number]: number} = {};
|
|
95
|
-
|
|
96
|
-
ranks.forEach((num) => {
|
|
97
|
-
ties[num] = (ties[num] || 0) + 1;
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
return jStat.sum(Object.values(ties));
|
|
101
|
-
}
|
|
1
|
+
//@ts-ignore: no types
|
|
2
|
+
import * as jStat from 'jstat';
|
|
3
|
+
|
|
4
|
+
type testStats = {
|
|
5
|
+
'p-value': number,
|
|
6
|
+
'Mean difference'?: number,
|
|
7
|
+
'Median difference'?: number,
|
|
8
|
+
'p-value more': number,
|
|
9
|
+
'p-value less': number,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function tTest(arr1: number[], arr2: number[], devKnown=false, devEqual=false): testStats {
|
|
13
|
+
const m1: number = jStat.mean(arr1);
|
|
14
|
+
const m2: number = jStat.mean(arr2);
|
|
15
|
+
const v1: number = jStat.variance(arr1);
|
|
16
|
+
const v2: number = jStat.variance(arr2);
|
|
17
|
+
const n1 = arr1.length;
|
|
18
|
+
const n2 = arr2.length;
|
|
19
|
+
|
|
20
|
+
let wv1;
|
|
21
|
+
let wv2;
|
|
22
|
+
let wv;
|
|
23
|
+
let Z;
|
|
24
|
+
let K;
|
|
25
|
+
let pMore;
|
|
26
|
+
let pLess;
|
|
27
|
+
let pTot;
|
|
28
|
+
|
|
29
|
+
if (!devKnown) {
|
|
30
|
+
if (!devEqual) {
|
|
31
|
+
wv1 = v1 / n1;
|
|
32
|
+
wv2 = v2 / n2;
|
|
33
|
+
Z = (m1 - m2) / Math.sqrt(wv1 + wv2);
|
|
34
|
+
K = Math.pow((wv1 + wv2), 2) / (wv1 * wv1 / (n1 - 1) + wv2 * wv2 / (n2 - 1));
|
|
35
|
+
|
|
36
|
+
pLess = jStat.studentt.cdf(Z, K);
|
|
37
|
+
pMore = 1 - pLess;
|
|
38
|
+
pTot = 2 * (pLess < pMore ? pLess : pMore);
|
|
39
|
+
} else {
|
|
40
|
+
K = n1 + n2 - 2;
|
|
41
|
+
wv = (v1 * (n1 - 1) + v2 * (n2 - 1)) / K;
|
|
42
|
+
Z = Math.sqrt(n1 * n2 / (n1 + n2)) * (m1 - m2) / wv;
|
|
43
|
+
|
|
44
|
+
pMore = 1 - jStat.studentt.cdf(Z, K);
|
|
45
|
+
pLess = jStat.studentt.cdf(Z, K);
|
|
46
|
+
pTot = 2 * (pLess < pMore ? pLess : pMore);
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
wv1 = v1 / n1;
|
|
50
|
+
wv2 = v2 / n2;
|
|
51
|
+
Z = (m1 - m2) / Math.sqrt(wv1 + wv2);
|
|
52
|
+
|
|
53
|
+
pLess = jStat.normal.pdf(Z, 0, 1);
|
|
54
|
+
pMore = 1 - pLess;
|
|
55
|
+
pTot = 2 * (pLess < pMore ? pLess : pMore);
|
|
56
|
+
}
|
|
57
|
+
return {'p-value': pTot, 'Mean difference': m1 - m2, 'p-value more': pMore, 'p-value less': pLess};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function uTest(x: number[], y: number[], continuity=true): testStats {
|
|
61
|
+
const xy = x.concat(y);
|
|
62
|
+
const n1 = x.length;
|
|
63
|
+
const n2 = y.length;
|
|
64
|
+
const med1 = jStat.median(x);
|
|
65
|
+
const med2 = jStat.median(y);
|
|
66
|
+
|
|
67
|
+
const ranks = jStat.rank(xy);
|
|
68
|
+
|
|
69
|
+
const R1 = jStat.sum(ranks.slice(0, n1));
|
|
70
|
+
const U1 = R1 - n1 * (n1 + 1) / 2;
|
|
71
|
+
const U2 = n1 * n2 - U1;
|
|
72
|
+
const U = U1 > U2 ? U1 : U2;
|
|
73
|
+
|
|
74
|
+
const mu = n1 * n2 / 2;
|
|
75
|
+
const n = n1 + n2;
|
|
76
|
+
|
|
77
|
+
const tieTerm = _tieTerm(ranks);
|
|
78
|
+
const s = Math.sqrt(n1 * n2 / 12 * ((n + 1) - tieTerm / (n* (n - 1))));
|
|
79
|
+
|
|
80
|
+
let numerator = U - mu;
|
|
81
|
+
|
|
82
|
+
if (continuity) {
|
|
83
|
+
numerator -= 0.5;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const z = numerator / s;
|
|
87
|
+
|
|
88
|
+
const p = 2 * (1 - jStat.normal.cdf(z, 0, 1));
|
|
89
|
+
|
|
90
|
+
return {'p-value': p, 'Median difference': med1 - med2, 'p-value more': p, 'p-value less': p};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function _tieTerm(ranks: number[]): number {
|
|
94
|
+
const ties: {[key: number]: number} = {};
|
|
95
|
+
|
|
96
|
+
ranks.forEach((num) => {
|
|
97
|
+
ties[num] = (ties[num] || 0) + 1;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return jStat.sum(Object.values(ties));
|
|
101
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Basic Options */
|
|
6
|
-
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
-
"target": "
|
|
8
|
-
"module": "es2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
|
-
"lib": ["es2020", "dom"], /* Specify library files to be included in the compilation. */
|
|
10
|
-
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
-
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
-
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
|
13
|
-
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
14
|
-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
-
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
|
-
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
-
// "outDir": "./", /* Redirect output structure to the directory. */
|
|
18
|
-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
|
-
// "composite": true, /* Enable project compilation */
|
|
20
|
-
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
21
|
-
// "removeComments": true, /* Do not emit comments to output. */
|
|
22
|
-
// "noEmit": true, /* Do not emit outputs. */
|
|
23
|
-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
24
|
-
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
25
|
-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
26
|
-
|
|
27
|
-
/* Strict Type-Checking Options */
|
|
28
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
|
-
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
|
-
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
|
-
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
-
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
35
|
-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
36
|
-
|
|
37
|
-
/* Additional Checks */
|
|
38
|
-
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
39
|
-
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
40
|
-
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
|
-
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
|
-
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
43
|
-
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
|
44
|
-
|
|
45
|
-
/* Module Resolution Options */
|
|
46
|
-
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
47
|
-
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
48
|
-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
49
|
-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
50
|
-
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
51
|
-
// "types": [], /* Type declaration files to be included in compilation. */
|
|
52
|
-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
53
|
-
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
54
|
-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
55
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
56
|
-
|
|
57
|
-
/* Source Map Options */
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/* Experimental Options */
|
|
64
|
-
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
65
|
-
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
66
|
-
|
|
67
|
-
/* Advanced Options */
|
|
68
|
-
"skipLibCheck":
|
|
69
|
-
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
70
|
-
}
|
|
71
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Basic Options */
|
|
6
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
+
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
8
|
+
"module": "es2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
|
+
"lib": ["es2020", "dom"], /* Specify library files to be included in the compilation. */
|
|
10
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
|
13
|
+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
14
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
+
// "outDir": "./", /* Redirect output structure to the directory. */
|
|
18
|
+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
|
+
// "composite": true, /* Enable project compilation */
|
|
20
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
21
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
22
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
23
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
24
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
25
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
26
|
+
|
|
27
|
+
/* Strict Type-Checking Options */
|
|
28
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
35
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
36
|
+
|
|
37
|
+
/* Additional Checks */
|
|
38
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
39
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
40
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
43
|
+
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
|
44
|
+
|
|
45
|
+
/* Module Resolution Options */
|
|
46
|
+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
47
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
48
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
49
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
50
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
51
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
52
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
53
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
54
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
55
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
56
|
+
|
|
57
|
+
/* Source Map Options */
|
|
58
|
+
"sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
59
|
+
"mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
60
|
+
"inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
61
|
+
"inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
62
|
+
|
|
63
|
+
/* Experimental Options */
|
|
64
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
65
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
66
|
+
|
|
67
|
+
/* Advanced Options */
|
|
68
|
+
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
69
|
+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
70
|
+
}
|
|
71
|
+
}
|
package/detectors.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The class contains semantic type detectors.
|
|
3
|
-
* Detectors are functions tagged with `DG.FUNC_TYPES.SEM_TYPE_DETECTOR`.
|
|
4
|
-
* See also: https://datagrok.ai/help/develop/how-to/define-semantic-type-detectors
|
|
5
|
-
* The class name is comprised of <PackageName> and the `PackageDetectors` suffix.
|
|
6
|
-
* Follow this naming convention to ensure that your detectors are properly loaded.
|
|
7
|
-
*/
|
|
8
|
-
class StatisticsPackageDetectors extends DG.Package {
|
|
9
|
-
}
|
package/webpack.config.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
mode: 'development',
|
|
5
|
-
entry: {
|
|
6
|
-
package: './src/tests.ts'
|
|
7
|
-
},
|
|
8
|
-
resolve: {
|
|
9
|
-
extensions: ['.wasm', '.mjs', '.js', '.json', '.ts', '.tsx'],
|
|
10
|
-
},
|
|
11
|
-
module: {
|
|
12
|
-
rules: [
|
|
13
|
-
{ test: /\.tsx?$/, loader: 'ts-loader' }
|
|
14
|
-
],
|
|
15
|
-
},
|
|
16
|
-
devtool: 'inline-source-map',
|
|
17
|
-
externals: {
|
|
18
|
-
'datagrok-api/dg': 'DG',
|
|
19
|
-
'datagrok-api/grok': 'grok',
|
|
20
|
-
'datagrok-api/ui': 'ui',
|
|
21
|
-
'openchemlib/full.js': 'OCL',
|
|
22
|
-
'rxjs': 'rxjs',
|
|
23
|
-
'rxjs/operators': 'rxjs.operators',
|
|
24
|
-
'cash-dom': '$',
|
|
25
|
-
'dayjs': 'dayjs',
|
|
26
|
-
},
|
|
27
|
-
output: {
|
|
28
|
-
filename: '[name].js',
|
|
29
|
-
library: 'statistics',
|
|
30
|
-
libraryTarget: 'var',
|
|
31
|
-
path: path.resolve(__dirname, 'dist'),
|
|
32
|
-
},
|
|
33
|
-
};
|