@zukhruf/statistics 0.8.153 → 0.8.155
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/README.md +22 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/multiple-testing/holm.d.ts +5 -0
- package/dist/multiple-testing/holm.d.ts.map +1 -0
- package/dist/multiple-testing/holm.js +22 -0
- package/dist/multiple-testing/holm.js.map +1 -0
- package/dist/multiple-testing/multiple-test-correction.d.ts +4 -0
- package/dist/multiple-testing/multiple-test-correction.d.ts.map +1 -0
- package/dist/multiple-testing/multiple-test-correction.js +2 -0
- package/dist/multiple-testing/multiple-test-correction.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @zukhruf/statistics
|
|
2
2
|
|
|
3
|
-
The percentile bootstrap, the quantile methods of NumPy, and `numpy.sum`, `numpy.mean`, `numpy.nanmean` and `numpy.std` in JavaScript, to the last bit. Use it when a TypeScript eval must give the same interval as a Python program, such as the summary of a benchmark or the comparison of two models.
|
|
3
|
+
The percentile bootstrap, the quantile methods of NumPy, the Holm correction of statsmodels, and `numpy.sum`, `numpy.mean`, `numpy.nanmean` and `numpy.std` in JavaScript, to the last bit. Use it when a TypeScript eval must give the same interval as a Python program, such as the summary of a benchmark or the comparison of two models.
|
|
4
4
|
|
|
5
5
|
The package is public on npm. Until 2026-11-07 it was private and reached through a workspace path (ADR 0001); it became public with `@zukhruf/evals`, which depends on it (backlog #3888).
|
|
6
6
|
|
|
@@ -75,6 +75,18 @@ std([1, 2, 3, 4]); // 1.118033988749895, as numpy.std(a)
|
|
|
75
75
|
std([1, 2, 3, 4], { ddof: 1 }); // 1.2909944487358056, as numpy.std(a, ddof=1)
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
## Adjust the p-values of many tests
|
|
79
|
+
|
|
80
|
+
When one run tests many hypotheses, such as each score of a comparison of two models, some test passes a level by chance alone. A `MultipleTestCorrection` adjusts the p-values of the family, so that each test can read its adjusted p-value against the level (Strategy, ADR 0003). `Holm` gives the values of `multipletests(p, method="holm")[1]` of statsmodels 0.15.0, to the last bit, in the order of the p-values that you give it:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { Holm } from '@zukhruf/statistics';
|
|
84
|
+
|
|
85
|
+
new Holm().adjust([0.04, 0.001, 0.03, 0.2, 0.01]); // [0.09, 0.005, 0.09, 0.2, 0.04]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Holm's step-down correction multiplies the k-th smallest of n p-values by n − k + 1, keeps a running maximum in that order, and caps each value at 1 (Holm 1979). A test is significant at a level when its adjusted p-value is at most that level. R names the same rule `p.adjust(p, method = "holm")`.
|
|
89
|
+
|
|
78
90
|
## Errors
|
|
79
91
|
|
|
80
92
|
Each error is a `RangeError`. Its message says which input is out of range.
|
|
@@ -136,6 +148,15 @@ class PercentileInterval implements ConfidenceIntervalMethod {
|
|
|
136
148
|
of(distribution: readonly number[]): ConfidenceInterval;
|
|
137
149
|
}
|
|
138
150
|
|
|
151
|
+
// The method of statsmodels' multipletests and R's p.adjust. Exported as a type only.
|
|
152
|
+
interface MultipleTestCorrection {
|
|
153
|
+
adjust(pValues: readonly number[]): number[];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
class Holm implements MultipleTestCorrection {
|
|
157
|
+
adjust(pValues: readonly number[]): number[];
|
|
158
|
+
}
|
|
159
|
+
|
|
139
160
|
class IidBootstrap {
|
|
140
161
|
constructor(options: {
|
|
141
162
|
readonly nResamples: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export { ConfidenceInterval } from './interval/confidence-interval.ts';
|
|
|
3
3
|
export type { ConfidenceIntervalMethod } from './interval/confidence-interval-method.ts';
|
|
4
4
|
export { DifferenceInterval } from './interval/difference-interval.ts';
|
|
5
5
|
export { PercentileInterval } from './interval/percentile-interval.ts';
|
|
6
|
+
export { Holm } from './multiple-testing/holm.ts';
|
|
7
|
+
export type { MultipleTestCorrection } from './multiple-testing/multiple-test-correction.ts';
|
|
6
8
|
export { Higher } from './quantile/higher.ts';
|
|
7
9
|
export { InvertedCdf } from './quantile/inverted-cdf.ts';
|
|
8
10
|
export { Linear } from './quantile/linear.ts';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,YAAY,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,YAAY,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,YAAY,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AAC7F,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { IidBootstrap } from './bootstrap/iid-bootstrap.js';
|
|
|
2
2
|
export { ConfidenceInterval } from './interval/confidence-interval.js';
|
|
3
3
|
export { DifferenceInterval } from './interval/difference-interval.js';
|
|
4
4
|
export { PercentileInterval } from './interval/percentile-interval.js';
|
|
5
|
+
export { Holm } from './multiple-testing/holm.js';
|
|
5
6
|
export { Higher } from './quantile/higher.js';
|
|
6
7
|
export { InvertedCdf } from './quantile/inverted-cdf.js';
|
|
7
8
|
export { Linear } from './quantile/linear.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE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,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holm.d.ts","sourceRoot":"","sources":["../../src/multiple-testing/holm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAS5E,qBAAa,IAAK,YAAW,sBAAsB;IACjD,MAAM,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAW3C;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The Holm adjusted p-values (Holm 1979) of several tests, in the order of
|
|
2
|
+
// the p-values. The step-down correction multiplies the k-th smallest of n
|
|
3
|
+
// p-values by n - k + 1, takes the running maximum in that order, so an
|
|
4
|
+
// adjusted value is never below the one before it, and caps each value at 1.
|
|
5
|
+
// A test is significant at level alpha when its adjusted value is at most
|
|
6
|
+
// alpha. These are the values of statsmodels 0.15.0
|
|
7
|
+
// multipletests(pValues, method="holm")[1], to the last bit (ADR 0003).
|
|
8
|
+
export class Holm {
|
|
9
|
+
adjust(pValues) {
|
|
10
|
+
const order = pValues
|
|
11
|
+
.map((value, index) => ({ value, index }))
|
|
12
|
+
.toSorted((a, b) => a.value - b.value);
|
|
13
|
+
const adjusted = Array.from({ length: pValues.length });
|
|
14
|
+
let running = Number.NEGATIVE_INFINITY;
|
|
15
|
+
for (const [rank, { value, index }] of order.entries()) {
|
|
16
|
+
running = Math.max(running, value * (order.length - rank));
|
|
17
|
+
adjusted[index] = Math.min(running, 1);
|
|
18
|
+
}
|
|
19
|
+
return adjusted;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=holm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holm.js","sourceRoot":"","sources":["../../src/multiple-testing/holm.ts"],"names":[],"mappings":"AAEA,2EAA2E;AAC3E,2EAA2E;AAC3E,wEAAwE;AACxE,6EAA6E;AAC7E,0EAA0E;AAC1E,oDAAoD;AACpD,wEAAwE;AACxE,MAAM,OAAO,IAAI;IACf,MAAM,CAAC,OAA0B;QAC/B,MAAM,KAAK,GAAG,OAAO;aAClB,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;aACzC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,QAAQ,GAAa,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAClE,IAAI,OAAO,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACvC,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YACvD,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;YAC3D,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiple-test-correction.d.ts","sourceRoot":"","sources":["../../src/multiple-testing/multiple-test-correction.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;CAC9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiple-test-correction.js","sourceRoot":"","sources":["../../src/multiple-testing/multiple-test-correction.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/statistics",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.155",
|
|
4
4
|
"description": "The percentile bootstrap, NumPy's quantile methods, and the sum, mean, nanmean and std of NumPy in JavaScript, to the last bit: resamples with a random generator that the caller gives, the percentile interval of their statistic, and NumPy's pairwise sum.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
"@stdlib/blas-ext-base-gsumpw": "^0.3.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@zukhruf/parameterized-test": "^0.8.
|
|
46
|
+
"@zukhruf/parameterized-test": "^0.8.155"
|
|
47
47
|
}
|
|
48
48
|
}
|