@ac-kit/math-stats 0.1.0
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/CHANGELOG.md +22 -0
- package/LICENSE +28 -0
- package/README.md +91 -0
- package/dist/_assert-probability.d.ts +14 -0
- package/dist/_assert-probability.d.ts.map +1 -0
- package/dist/_assert-probability.js +18 -0
- package/dist/_assert-probability.js.map +1 -0
- package/dist/_discrete-quantile.d.ts +16 -0
- package/dist/_discrete-quantile.d.ts.map +1 -0
- package/dist/_discrete-quantile.js +43 -0
- package/dist/_discrete-quantile.js.map +1 -0
- package/dist/_inverse-transform-sample.d.ts +17 -0
- package/dist/_inverse-transform-sample.d.ts.map +1 -0
- package/dist/_inverse-transform-sample.js +18 -0
- package/dist/_inverse-transform-sample.js.map +1 -0
- package/dist/_log-binomial.d.ts +16 -0
- package/dist/_log-binomial.d.ts.map +1 -0
- package/dist/_log-binomial.js +19 -0
- package/dist/_log-binomial.js.map +1 -0
- package/dist/average.d.ts +95 -0
- package/dist/average.d.ts.map +1 -0
- package/dist/average.js +113 -0
- package/dist/average.js.map +1 -0
- package/dist/beta-distribution.d.ts +15 -0
- package/dist/beta-distribution.d.ts.map +1 -0
- package/dist/beta-distribution.js +61 -0
- package/dist/beta-distribution.js.map +1 -0
- package/dist/binomial-distribution.d.ts +18 -0
- package/dist/binomial-distribution.d.ts.map +1 -0
- package/dist/binomial-distribution.js +74 -0
- package/dist/binomial-distribution.js.map +1 -0
- package/dist/chi-squared-distribution.d.ts +15 -0
- package/dist/chi-squared-distribution.d.ts.map +1 -0
- package/dist/chi-squared-distribution.js +25 -0
- package/dist/chi-squared-distribution.js.map +1 -0
- package/dist/chi-squared-test.d.ts +39 -0
- package/dist/chi-squared-test.d.ts.map +1 -0
- package/dist/chi-squared-test.js +56 -0
- package/dist/chi-squared-test.js.map +1 -0
- package/dist/confidence-interval.d.ts +62 -0
- package/dist/confidence-interval.d.ts.map +1 -0
- package/dist/confidence-interval.js +93 -0
- package/dist/confidence-interval.js.map +1 -0
- package/dist/dispersion.d.ts +45 -0
- package/dist/dispersion.d.ts.map +1 -0
- package/dist/dispersion.js +80 -0
- package/dist/dispersion.js.map +1 -0
- package/dist/distribution.d.ts +61 -0
- package/dist/distribution.d.ts.map +1 -0
- package/dist/distribution.js +2 -0
- package/dist/distribution.js.map +1 -0
- package/dist/exponential-distribution.d.ts +15 -0
- package/dist/exponential-distribution.d.ts.map +1 -0
- package/dist/exponential-distribution.js +33 -0
- package/dist/exponential-distribution.js.map +1 -0
- package/dist/f-distribution.d.ts +17 -0
- package/dist/f-distribution.d.ts.map +1 -0
- package/dist/f-distribution.js +88 -0
- package/dist/f-distribution.js.map +1 -0
- package/dist/gamma-distribution.d.ts +15 -0
- package/dist/gamma-distribution.d.ts.map +1 -0
- package/dist/gamma-distribution.js +45 -0
- package/dist/gamma-distribution.js.map +1 -0
- package/dist/geometric-distribution.d.ts +19 -0
- package/dist/geometric-distribution.d.ts.map +1 -0
- package/dist/geometric-distribution.js +54 -0
- package/dist/geometric-distribution.js.map +1 -0
- package/dist/hierarchical-cluster.d.ts +35 -0
- package/dist/hierarchical-cluster.d.ts.map +1 -0
- package/dist/hierarchical-cluster.js +97 -0
- package/dist/hierarchical-cluster.js.map +1 -0
- package/dist/hypergeometric-distribution.d.ts +18 -0
- package/dist/hypergeometric-distribution.d.ts.map +1 -0
- package/dist/hypergeometric-distribution.js +92 -0
- package/dist/hypergeometric-distribution.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/kmeans.d.ts +87 -0
- package/dist/kmeans.d.ts.map +1 -0
- package/dist/kmeans.js +126 -0
- package/dist/kmeans.js.map +1 -0
- package/dist/kmedoids.d.ts +27 -0
- package/dist/kmedoids.d.ts.map +1 -0
- package/dist/kmedoids.js +47 -0
- package/dist/kmedoids.js.map +1 -0
- package/dist/log-normal-distribution.d.ts +15 -0
- package/dist/log-normal-distribution.d.ts.map +1 -0
- package/dist/log-normal-distribution.js +44 -0
- package/dist/log-normal-distribution.js.map +1 -0
- package/dist/negative-binomial-distribution.d.ts +18 -0
- package/dist/negative-binomial-distribution.d.ts.map +1 -0
- package/dist/negative-binomial-distribution.js +64 -0
- package/dist/negative-binomial-distribution.js.map +1 -0
- package/dist/normal-distribution.d.ts +16 -0
- package/dist/normal-distribution.d.ts.map +1 -0
- package/dist/normal-distribution.js +41 -0
- package/dist/normal-distribution.js.map +1 -0
- package/dist/normal-quantile.d.ts +19 -0
- package/dist/normal-quantile.d.ts.map +1 -0
- package/dist/normal-quantile.js +115 -0
- package/dist/normal-quantile.js.map +1 -0
- package/dist/one-way-anova.d.ts +31 -0
- package/dist/one-way-anova.d.ts.map +1 -0
- package/dist/one-way-anova.js +69 -0
- package/dist/one-way-anova.js.map +1 -0
- package/dist/outliers.d.ts +20 -0
- package/dist/outliers.d.ts.map +1 -0
- package/dist/outliers.js +49 -0
- package/dist/outliers.js.map +1 -0
- package/dist/poisson-distribution.d.ts +15 -0
- package/dist/poisson-distribution.d.ts.map +1 -0
- package/dist/poisson-distribution.js +44 -0
- package/dist/poisson-distribution.js.map +1 -0
- package/dist/quantile.d.ts +9 -0
- package/dist/quantile.d.ts.map +1 -0
- package/dist/quantile.js +23 -0
- package/dist/quantile.js.map +1 -0
- package/dist/random-effects.d.ts +45 -0
- package/dist/random-effects.d.ts.map +1 -0
- package/dist/random-effects.js +97 -0
- package/dist/random-effects.js.map +1 -0
- package/dist/regression.d.ts +12 -0
- package/dist/regression.d.ts.map +1 -0
- package/dist/regression.js +35 -0
- package/dist/regression.js.map +1 -0
- package/dist/student-t-distribution.d.ts +16 -0
- package/dist/student-t-distribution.d.ts.map +1 -0
- package/dist/student-t-distribution.js +54 -0
- package/dist/student-t-distribution.js.map +1 -0
- package/dist/sum.d.ts +31 -0
- package/dist/sum.d.ts.map +1 -0
- package/dist/sum.js +30 -0
- package/dist/sum.js.map +1 -0
- package/dist/t-test.d.ts +52 -0
- package/dist/t-test.d.ts.map +1 -0
- package/dist/t-test.js +81 -0
- package/dist/t-test.js.map +1 -0
- package/dist/trend.d.ts +55 -0
- package/dist/trend.d.ts.map +1 -0
- package/dist/trend.js +98 -0
- package/dist/trend.js.map +1 -0
- package/dist/uncertainty.d.ts +25 -0
- package/dist/uncertainty.d.ts.map +1 -0
- package/dist/uncertainty.js +26 -0
- package/dist/uncertainty.js.map +1 -0
- package/dist/uniform-distribution.d.ts +11 -0
- package/dist/uniform-distribution.d.ts.map +1 -0
- package/dist/uniform-distribution.js +33 -0
- package/dist/uniform-distribution.js.map +1 -0
- package/dist/welch-t-statistic.d.ts +24 -0
- package/dist/welch-t-statistic.d.ts.map +1 -0
- package/dist/welch-t-statistic.js +33 -0
- package/dist/welch-t-statistic.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Distribution } from "./distribution.js";
|
|
2
|
+
/**
|
|
3
|
+
* Student's t distribution — the reference distribution of a mean estimated
|
|
4
|
+
* from a sample whose variance was estimated from the same sample.
|
|
5
|
+
*
|
|
6
|
+
* The tails go through the incomplete beta on the half of the domain where each
|
|
7
|
+
* is small: `survival(t)` for positive `t` and `cdf(t)` for negative `t` are
|
|
8
|
+
* each computed directly, and the other is their exact complement. Taking both
|
|
9
|
+
* from one branch would reduce a p-value of `1e-16` to zero.
|
|
10
|
+
*
|
|
11
|
+
* @param degreesOfFreedom Positive; need not be an integer.
|
|
12
|
+
* @returns The distribution.
|
|
13
|
+
* @throws {RangeError} When `degreesOfFreedom` is not positive.
|
|
14
|
+
*/
|
|
15
|
+
export declare function studentTDistribution(degreesOfFreedom: number): Distribution;
|
|
16
|
+
//# sourceMappingURL=student-t-distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"student-t-distribution.d.ts","sourceRoot":"","sources":["../src/student-t-distribution.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,GAAG,YAAY,CAuD3E"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { inverseRegularizedIncompleteBeta, logGamma, regularizedIncompleteBeta, } from "@ac-kit/math-analysis";
|
|
2
|
+
import { assertProbability_ } from "./_assert-probability.js";
|
|
3
|
+
import { inverseTransformSample_ } from "./_inverse-transform-sample.js";
|
|
4
|
+
/**
|
|
5
|
+
* Student's t distribution — the reference distribution of a mean estimated
|
|
6
|
+
* from a sample whose variance was estimated from the same sample.
|
|
7
|
+
*
|
|
8
|
+
* The tails go through the incomplete beta on the half of the domain where each
|
|
9
|
+
* is small: `survival(t)` for positive `t` and `cdf(t)` for negative `t` are
|
|
10
|
+
* each computed directly, and the other is their exact complement. Taking both
|
|
11
|
+
* from one branch would reduce a p-value of `1e-16` to zero.
|
|
12
|
+
*
|
|
13
|
+
* @param degreesOfFreedom Positive; need not be an integer.
|
|
14
|
+
* @returns The distribution.
|
|
15
|
+
* @throws {RangeError} When `degreesOfFreedom` is not positive.
|
|
16
|
+
*/
|
|
17
|
+
export function studentTDistribution(degreesOfFreedom) {
|
|
18
|
+
if (!(degreesOfFreedom > 0)) {
|
|
19
|
+
throw new RangeError(`studentTDistribution: degreesOfFreedom must be positive, got ${degreesOfFreedom}`);
|
|
20
|
+
}
|
|
21
|
+
const half = degreesOfFreedom / 2;
|
|
22
|
+
const logNormaliser = logGamma(half + 0.5) -
|
|
23
|
+
logGamma(half) -
|
|
24
|
+
0.5 * Math.log(degreesOfFreedom * Math.PI);
|
|
25
|
+
/** `½·I_{ν/(ν+t²)}(ν/2, ½)` — the mass beyond `|t|`, in either direction. */
|
|
26
|
+
const outerTail = (t) => 0.5 *
|
|
27
|
+
regularizedIncompleteBeta(half, 0.5, degreesOfFreedom / (degreesOfFreedom + t * t));
|
|
28
|
+
const quantile = (probability) => {
|
|
29
|
+
assertProbability_("studentTDistribution", probability);
|
|
30
|
+
if (probability === 0.5) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
// Solved from the tail on whichever side `probability` names, so the beta
|
|
34
|
+
// inverse is handed a small argument rather than one adjacent to 1.
|
|
35
|
+
const tail = Math.min(probability, 1 - probability);
|
|
36
|
+
const inverted = inverseRegularizedIncompleteBeta(half, 0.5, 2 * tail);
|
|
37
|
+
const magnitude = Math.sqrt((degreesOfFreedom * (1 - inverted)) / inverted);
|
|
38
|
+
return probability < 0.5 ? -magnitude : magnitude;
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
density: (t) => Math.exp(logNormaliser - (half + 0.5) * Math.log1p((t * t) / degreesOfFreedom)),
|
|
42
|
+
cdf: (t) => (t <= 0 ? outerTail(t) : 1 - outerTail(t)),
|
|
43
|
+
survival: (t) => (t >= 0 ? outerTail(t) : 1 - outerTail(t)),
|
|
44
|
+
quantile,
|
|
45
|
+
sample: (random) => inverseTransformSample_(quantile, random),
|
|
46
|
+
mean: degreesOfFreedom > 1 ? 0 : Number.NaN,
|
|
47
|
+
variance: degreesOfFreedom > 2
|
|
48
|
+
? degreesOfFreedom / (degreesOfFreedom - 2)
|
|
49
|
+
: degreesOfFreedom > 1
|
|
50
|
+
? Number.POSITIVE_INFINITY
|
|
51
|
+
: Number.NaN,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=student-t-distribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"student-t-distribution.js","sourceRoot":"","sources":["../src/student-t-distribution.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gCAAgC,EAChC,QAAQ,EACR,yBAAyB,GACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGzE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AAC;IACnD,CAAC,CAAC;IAEF,OAAO;QACN,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CACd,IAAI,CAAC,GAAG,CACP,aAAa,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,gBAAgB,CAAC,CACrE;QACF,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QACtD,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QAC3D,QAAQ;QACR,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC7D,IAAI,EAAE,gBAAgB,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG;QAC3C,QAAQ,EACP,gBAAgB,GAAG,CAAC;YACnB,CAAC,CAAC,gBAAgB,GAAG,CAAC,gBAAgB,GAAG,CAAC,CAAC;YAC3C,CAAC,CAAC,gBAAgB,GAAG,CAAC;gBACrB,CAAC,CAAC,MAAM,CAAC,iBAAiB;gBAC1B,CAAC,CAAC,MAAM,CAAC,GAAG;KACf,CAAC;AACH,CAAC"}
|
package/dist/sum.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Callable } from "@ac-kit/core";
|
|
2
|
+
/** How a total is accumulated. */
|
|
3
|
+
export type SumOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to accumulate exactly, so the total is the `number` nearest the
|
|
6
|
+
* true mathematical sum.
|
|
7
|
+
*
|
|
8
|
+
* Defaults to `true`. Turn it off only for a measured hot path whose terms
|
|
9
|
+
* share a sign and a magnitude — the case where a naive running total is
|
|
10
|
+
* already close to exact. Length alone is not a reason; see `sumPrecise`.
|
|
11
|
+
*/
|
|
12
|
+
exact?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Returns the sum of `fn(item)` over all items.
|
|
16
|
+
*
|
|
17
|
+
* @param iterable - The input iterable.
|
|
18
|
+
* @param valueOf - Numeric extractor.
|
|
19
|
+
* @param options - How to accumulate; exact by default.
|
|
20
|
+
* @returns The total sum.
|
|
21
|
+
*/
|
|
22
|
+
export declare function sumBy<T>(iterable: Iterable<T>, valueOf: Callable<[T], number>, options?: SumOptions): number;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the sum of all items.
|
|
25
|
+
*
|
|
26
|
+
* @param iterable - The input iterable.
|
|
27
|
+
* @param options - How to accumulate; exact by default.
|
|
28
|
+
* @returns The total sum.
|
|
29
|
+
*/
|
|
30
|
+
export declare function sum(iterable: Iterable<number>, options?: SumOptions): number;
|
|
31
|
+
//# sourceMappingURL=sum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sum.d.ts","sourceRoot":"","sources":["../src/sum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmB,MAAM,cAAc,CAAC;AAEzD,kCAAkC;AAClC,MAAM,MAAM,UAAU,GAAG;IACxB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACtB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAC9B,OAAO,CAAC,EAAE,UAAU,GAClB,MAAM,CAUR;AAED;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAE5E"}
|
package/dist/sum.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { map, sumPrecise } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the sum of `fn(item)` over all items.
|
|
4
|
+
*
|
|
5
|
+
* @param iterable - The input iterable.
|
|
6
|
+
* @param valueOf - Numeric extractor.
|
|
7
|
+
* @param options - How to accumulate; exact by default.
|
|
8
|
+
* @returns The total sum.
|
|
9
|
+
*/
|
|
10
|
+
export function sumBy(iterable, valueOf, options) {
|
|
11
|
+
if (options?.exact === false) {
|
|
12
|
+
let total = 0;
|
|
13
|
+
for (const item of iterable) {
|
|
14
|
+
total += valueOf(item);
|
|
15
|
+
}
|
|
16
|
+
return total;
|
|
17
|
+
}
|
|
18
|
+
return sumPrecise(map(iterable, valueOf));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns the sum of all items.
|
|
22
|
+
*
|
|
23
|
+
* @param iterable - The input iterable.
|
|
24
|
+
* @param options - How to accumulate; exact by default.
|
|
25
|
+
* @returns The total sum.
|
|
26
|
+
*/
|
|
27
|
+
export function sum(iterable, options) {
|
|
28
|
+
return sumBy(iterable, (x) => x, options);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=sum.js.map
|
package/dist/sum.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sum.js","sourceRoot":"","sources":["../src/sum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,GAAG,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAezD;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CACpB,QAAqB,EACrB,OAA8B,EAC9B,OAAoB;IAEpB,IAAI,OAAO,EAAE,KAAK,KAAK,KAAK,EAAE,CAAC;QAC9B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CAAC,QAA0B,EAAE,OAAoB;IACnE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/t-test.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Which departure from the null hypothesis the p-value is computed against. */
|
|
2
|
+
export type TTestAlternative = "two-sided" | "less" | "greater";
|
|
3
|
+
/** How the samples relate, and what the p-value is measured against. */
|
|
4
|
+
export type TTestOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Treat the two samples as matched by index and test their differences.
|
|
7
|
+
* Ignored when the second argument is a hypothesised mean rather than a
|
|
8
|
+
* sample.
|
|
9
|
+
*/
|
|
10
|
+
paired?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Pool the two variances into one (Student's original form) instead of
|
|
13
|
+
* letting them differ (Welch's).
|
|
14
|
+
*
|
|
15
|
+
* Defaults to `false`, and should usually stay there: pooling is only valid
|
|
16
|
+
* when the variances really are equal, and Welch's form costs almost nothing
|
|
17
|
+
* when they are.
|
|
18
|
+
*/
|
|
19
|
+
pooled?: boolean;
|
|
20
|
+
/** Defaults to `"two-sided"`. */
|
|
21
|
+
alternative?: TTestAlternative;
|
|
22
|
+
};
|
|
23
|
+
/** A t-test's statistic and the evidence against the null hypothesis. */
|
|
24
|
+
export type TTestResult = {
|
|
25
|
+
/** The t-statistic. */
|
|
26
|
+
statistic: number;
|
|
27
|
+
/** Degrees of freedom of the reference distribution. */
|
|
28
|
+
degreesOfFreedom: number;
|
|
29
|
+
/** Probability of a statistic at least this extreme under the null. */
|
|
30
|
+
pValue: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Student's t-test, in whichever of its three forms the arguments describe.
|
|
34
|
+
*
|
|
35
|
+
* Passing a number as `other` runs the one-sample test against it as a
|
|
36
|
+
* hypothesised mean; passing a second sample runs the two-sample test, or the
|
|
37
|
+
* paired test with `options.paired`. The form is read off the arguments rather
|
|
38
|
+
* than named by an option, because an option could contradict them.
|
|
39
|
+
*
|
|
40
|
+
* The p-value comes from the tail of the t distribution computed directly, not
|
|
41
|
+
* from `1 − cdf`, so a result significant at `1e-17` reports that rather than
|
|
42
|
+
* zero.
|
|
43
|
+
*
|
|
44
|
+
* @param sample The sample. Not modified.
|
|
45
|
+
* @param other A second sample, or the hypothesised mean to test against.
|
|
46
|
+
* @param options How the samples relate and which alternative to test.
|
|
47
|
+
* @returns The statistic, its degrees of freedom and the p-value.
|
|
48
|
+
* @throws {RangeError} When a sample is too small, or a paired test is given
|
|
49
|
+
* samples of different lengths.
|
|
50
|
+
*/
|
|
51
|
+
export declare function tTest(sample: readonly number[], other: readonly number[] | number, options?: TTestOptions): TTestResult;
|
|
52
|
+
//# sourceMappingURL=t-test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"t-test.d.ts","sourceRoot":"","sources":["../src/t-test.ts"],"names":[],"mappings":"AAKA,gFAAgF;AAChF,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;AAEhE,wEAAwE;AACxE,MAAM,MAAM,YAAY,GAAG;IAC1B;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,iCAAiC;IACjC,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAC/B,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,WAAW,GAAG;IACzB,uBAAuB;IACvB,SAAS,EAAE,MAAM,CAAC;IAElB,wDAAwD;IACxD,gBAAgB,EAAE,MAAM,CAAC;IAEzB,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CACpB,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EACjC,OAAO,CAAC,EAAE,YAAY,GACpB,WAAW,CAqBb"}
|
package/dist/t-test.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { mean } from "./average.js";
|
|
2
|
+
import { sampleVariance } from "./dispersion.js";
|
|
3
|
+
import { studentTDistribution } from "./student-t-distribution.js";
|
|
4
|
+
import { welchTStatistic } from "./welch-t-statistic.js";
|
|
5
|
+
/**
|
|
6
|
+
* Student's t-test, in whichever of its three forms the arguments describe.
|
|
7
|
+
*
|
|
8
|
+
* Passing a number as `other` runs the one-sample test against it as a
|
|
9
|
+
* hypothesised mean; passing a second sample runs the two-sample test, or the
|
|
10
|
+
* paired test with `options.paired`. The form is read off the arguments rather
|
|
11
|
+
* than named by an option, because an option could contradict them.
|
|
12
|
+
*
|
|
13
|
+
* The p-value comes from the tail of the t distribution computed directly, not
|
|
14
|
+
* from `1 − cdf`, so a result significant at `1e-17` reports that rather than
|
|
15
|
+
* zero.
|
|
16
|
+
*
|
|
17
|
+
* @param sample The sample. Not modified.
|
|
18
|
+
* @param other A second sample, or the hypothesised mean to test against.
|
|
19
|
+
* @param options How the samples relate and which alternative to test.
|
|
20
|
+
* @returns The statistic, its degrees of freedom and the p-value.
|
|
21
|
+
* @throws {RangeError} When a sample is too small, or a paired test is given
|
|
22
|
+
* samples of different lengths.
|
|
23
|
+
*/
|
|
24
|
+
export function tTest(sample, other, options) {
|
|
25
|
+
const alternative = options?.alternative ?? "two-sided";
|
|
26
|
+
const { statistic, degreesOfFreedom } = typeof other === "number"
|
|
27
|
+
? oneSample_(sample, other)
|
|
28
|
+
: options?.paired
|
|
29
|
+
? oneSample_(differences_(sample, other), 0)
|
|
30
|
+
: options?.pooled
|
|
31
|
+
? pooled_(sample, other)
|
|
32
|
+
: welch_(sample, other);
|
|
33
|
+
const reference = studentTDistribution(degreesOfFreedom);
|
|
34
|
+
const pValue = alternative === "two-sided"
|
|
35
|
+
? 2 * reference.survival(Math.abs(statistic))
|
|
36
|
+
: alternative === "greater"
|
|
37
|
+
? reference.survival(statistic)
|
|
38
|
+
: reference.cdf(statistic);
|
|
39
|
+
return { statistic, degreesOfFreedom, pValue };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Welch's statistic, renamed into this module's field names. `welchTStatistic`
|
|
43
|
+
* keeps `t` because its own callers threshold on it directly.
|
|
44
|
+
*/
|
|
45
|
+
function welch_(a, b) {
|
|
46
|
+
const { t, degreesOfFreedom } = welchTStatistic(a, b);
|
|
47
|
+
return { statistic: t, degreesOfFreedom };
|
|
48
|
+
}
|
|
49
|
+
/** The one-sample statistic, which the paired form also reduces to. */
|
|
50
|
+
function oneSample_(sample, hypothesised) {
|
|
51
|
+
if (sample.length < 2) {
|
|
52
|
+
throw new RangeError("tTest: the sample must have at least two values");
|
|
53
|
+
}
|
|
54
|
+
const standardError = Math.sqrt(sampleVariance(sample) / sample.length);
|
|
55
|
+
return {
|
|
56
|
+
statistic: standardError > 0 ? (mean(sample) - hypothesised) / standardError : 0,
|
|
57
|
+
degreesOfFreedom: sample.length - 1,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Student's original equal-variance statistic, with the variances pooled. */
|
|
61
|
+
function pooled_(a, b) {
|
|
62
|
+
if (a.length < 2 || b.length < 2) {
|
|
63
|
+
throw new RangeError("tTest: both samples must have at least two values");
|
|
64
|
+
}
|
|
65
|
+
const degreesOfFreedom = a.length + b.length - 2;
|
|
66
|
+
const variance = ((a.length - 1) * sampleVariance(a) + (b.length - 1) * sampleVariance(b)) /
|
|
67
|
+
degreesOfFreedom;
|
|
68
|
+
const standardError = Math.sqrt(variance * (1 / a.length + 1 / b.length));
|
|
69
|
+
return {
|
|
70
|
+
statistic: standardError > 0 ? (mean(a) - mean(b)) / standardError : 0,
|
|
71
|
+
degreesOfFreedom,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Element-wise differences, which the paired test treats as one sample. */
|
|
75
|
+
function differences_(a, b) {
|
|
76
|
+
if (a.length !== b.length) {
|
|
77
|
+
throw new RangeError("tTest: a paired test needs samples of the same length");
|
|
78
|
+
}
|
|
79
|
+
return a.map((value, index) => value - b[index]);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=t-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"t-test.js","sourceRoot":"","sources":["../src/t-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAwCzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,KAAK,CACpB,MAAyB,EACzB,KAAiC,EACjC,OAAsB;IAEtB,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,WAAW,CAAC;IAExD,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GACpC,OAAO,KAAK,KAAK,QAAQ;QACxB,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC;QAC3B,CAAC,CAAC,OAAO,EAAE,MAAM;YAChB,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;YAC5C,CAAC,CAAC,OAAO,EAAE,MAAM;gBAChB,CAAC,CAAC,OAAO,CAAC,M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@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Mann–Kendall trend statistic and its standardised form. */
|
|
2
|
+
export type MannKendallTrend = {
|
|
3
|
+
/**
|
|
4
|
+
* `S`: the number of increasing ordered pairs minus the number of decreasing
|
|
5
|
+
* ones. Positive means increasing.
|
|
6
|
+
*/
|
|
7
|
+
readonly statistic: number;
|
|
8
|
+
/**
|
|
9
|
+
* `S` standardised to a zero-mean, unit-variance statistic under the no-trend
|
|
10
|
+
* hypothesis, comparable across sample sizes and readable as a standard
|
|
11
|
+
* normal deviate. `0` when the variance is zero.
|
|
12
|
+
*/
|
|
13
|
+
readonly normalised: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Mann–Kendall trend test statistic: whether a series drifts monotonically,
|
|
17
|
+
* with no assumption about the shape of the underlying distribution and no
|
|
18
|
+
* assumption that the drift is linear.
|
|
19
|
+
*
|
|
20
|
+
* A monotone ramp and an oscillation around a fixed level are what this
|
|
21
|
+
* separates — the first accumulates concordant pairs and drives `S` away from
|
|
22
|
+
* zero, while the second cancels them out. It is unaffected by outliers, since
|
|
23
|
+
* only the sign of each pairwise difference counts, never its size.
|
|
24
|
+
*
|
|
25
|
+
* Ties contribute nothing to `S` and are corrected for in the variance.
|
|
26
|
+
*
|
|
27
|
+
* O(n²) — every ordered pair is compared. Intended for the hundreds-of-points
|
|
28
|
+
* series a monitor collects, not for bulk data.
|
|
29
|
+
*
|
|
30
|
+
* @param values The series, in observation order. Not modified.
|
|
31
|
+
* @returns The statistic and its standardised form, both `0` for a series of
|
|
32
|
+
* fewer than two values.
|
|
33
|
+
* @see https://en.wikipedia.org/wiki/Mann%E2%80%93Kendall_test
|
|
34
|
+
*/
|
|
35
|
+
export declare function mannKendallTrend(values: readonly number[]): MannKendallTrend;
|
|
36
|
+
/**
|
|
37
|
+
* Fraction of interior points at which a series changes direction.
|
|
38
|
+
*
|
|
39
|
+
* Where {@link mannKendallTrend} answers "is it drifting", this answers "is it
|
|
40
|
+
* oscillating": a thermal ramp climbs steadily and reverses rarely, while a
|
|
41
|
+
* throttling processor alternates and reverses constantly. The two are
|
|
42
|
+
* complementary, and a series can score low on both by being flat.
|
|
43
|
+
*
|
|
44
|
+
* Flat steps are not reversals and do not break a run: a direction persists
|
|
45
|
+
* across equal values until it actually changes.
|
|
46
|
+
*
|
|
47
|
+
* O(n).
|
|
48
|
+
*
|
|
49
|
+
* @param values The series, in observation order. Not modified.
|
|
50
|
+
* @returns The reversal count divided by `n - 2`, in `[0, 1]` — `0` for a
|
|
51
|
+
* monotone series, `1` for a perfectly alternating one. `0` for a series of
|
|
52
|
+
* fewer than three values, which has no interior point to reverse at.
|
|
53
|
+
*/
|
|
54
|
+
export declare function reversalRate(values: readonly number[]): number;
|
|
55
|
+
//# sourceMappingURL=trend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trend.d.ts","sourceRoot":"","sources":["../src/trend.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,CA6B5E;AAkBD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAoB9D"}
|
package/dist/trend.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mann–Kendall trend test statistic: whether a series drifts monotonically,
|
|
3
|
+
* with no assumption about the shape of the underlying distribution and no
|
|
4
|
+
* assumption that the drift is linear.
|
|
5
|
+
*
|
|
6
|
+
* A monotone ramp and an oscillation around a fixed level are what this
|
|
7
|
+
* separates — the first accumulates concordant pairs and drives `S` away from
|
|
8
|
+
* zero, while the second cancels them out. It is unaffected by outliers, since
|
|
9
|
+
* only the sign of each pairwise difference counts, never its size.
|
|
10
|
+
*
|
|
11
|
+
* Ties contribute nothing to `S` and are corrected for in the variance.
|
|
12
|
+
*
|
|
13
|
+
* O(n²) — every ordered pair is compared. Intended for the hundreds-of-points
|
|
14
|
+
* series a monitor collects, not for bulk data.
|
|
15
|
+
*
|
|
16
|
+
* @param values The series, in observation order. Not modified.
|
|
17
|
+
* @returns The statistic and its standardised form, both `0` for a series of
|
|
18
|
+
* fewer than two values.
|
|
19
|
+
* @see https://en.wikipedia.org/wiki/Mann%E2%80%93Kendall_test
|
|
20
|
+
*/
|
|
21
|
+
export function mannKendallTrend(values) {
|
|
22
|
+
const count = values.length;
|
|
23
|
+
if (count < 2) {
|
|
24
|
+
return { statistic: 0, normalised: 0 };
|
|
25
|
+
}
|
|
26
|
+
let statistic = 0;
|
|
27
|
+
for (let index = 0; index < count - 1; index++) {
|
|
28
|
+
const value = values[index];
|
|
29
|
+
for (let other = index + 1; other < count; other++) {
|
|
30
|
+
statistic += Math.sign(values[other] - value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Variance of S under the no-trend hypothesis, reduced by each group of
|
|
34
|
+
// tied values: a tie is a pair that could never have contributed.
|
|
35
|
+
let variance = (count * (count - 1) * (2 * count + 5)) / 18;
|
|
36
|
+
for (const tied of countTiedGroups(values)) {
|
|
37
|
+
variance -= (tied * (tied - 1) * (2 * tied + 5)) / 18;
|
|
38
|
+
}
|
|
39
|
+
if (variance <= 0) {
|
|
40
|
+
return { statistic, normalised: 0 };
|
|
41
|
+
}
|
|
42
|
+
// The continuity correction pulls S one unit towards zero, so a single
|
|
43
|
+
// concordant pair does not read as a trend.
|
|
44
|
+
const corrected = statistic - Math.sign(statistic);
|
|
45
|
+
return { statistic, normalised: corrected / Math.sqrt(variance) };
|
|
46
|
+
}
|
|
47
|
+
function countTiedGroups(values) {
|
|
48
|
+
const counts = new Map();
|
|
49
|
+
for (let index = 0; index < values.length; index++) {
|
|
50
|
+
const value = values[index];
|
|
51
|
+
counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
52
|
+
}
|
|
53
|
+
const groups = [];
|
|
54
|
+
for (const size of counts.values()) {
|
|
55
|
+
if (size > 1) {
|
|
56
|
+
groups.push(size);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return groups;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Fraction of interior points at which a series changes direction.
|
|
63
|
+
*
|
|
64
|
+
* Where {@link mannKendallTrend} answers "is it drifting", this answers "is it
|
|
65
|
+
* oscillating": a thermal ramp climbs steadily and reverses rarely, while a
|
|
66
|
+
* throttling processor alternates and reverses constantly. The two are
|
|
67
|
+
* complementary, and a series can score low on both by being flat.
|
|
68
|
+
*
|
|
69
|
+
* Flat steps are not reversals and do not break a run: a direction persists
|
|
70
|
+
* across equal values until it actually changes.
|
|
71
|
+
*
|
|
72
|
+
* O(n).
|
|
73
|
+
*
|
|
74
|
+
* @param values The series, in observation order. Not modified.
|
|
75
|
+
* @returns The reversal count divided by `n - 2`, in `[0, 1]` — `0` for a
|
|
76
|
+
* monotone series, `1` for a perfectly alternating one. `0` for a series of
|
|
77
|
+
* fewer than three values, which has no interior point to reverse at.
|
|
78
|
+
*/
|
|
79
|
+
export function reversalRate(values) {
|
|
80
|
+
const count = values.length;
|
|
81
|
+
if (count < 3) {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
let reversals = 0;
|
|
85
|
+
let previousDirection = 0;
|
|
86
|
+
for (let index = 1; index < count; index++) {
|
|
87
|
+
const direction = Math.sign(values[index] - values[index - 1]);
|
|
88
|
+
if (direction === 0) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (previousDirection !== 0 && direction !== previousDirection) {
|
|
92
|
+
reversals++;
|
|
93
|
+
}
|
|
94
|
+
previousDirection = direction;
|
|
95
|
+
}
|
|
96
|
+
return reversals / (count - 2);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=trend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trend.js","sourceRoot":"","sources":["../src/trend.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAyB;IACzD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5B,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACf,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IACxC,CAAC;IAED,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAChD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAE,CAAC;QAC7B,KAAK,IAAI,KAAK,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;YACpD,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAE,GAAG,KAAK,CAAC,CAAC;QAChD,CAAC;IACF,CAAC;IAED,wEAAwE;IACxE,kEAAkE;IAClE,IAAI,QAAQ,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;IAC5D,KAAK,MAAM,IAAI,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5C,QAAQ,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;I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AAC;IAC1B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAE,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAE,CAAC,CAAC;QACjE,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YACrB,SAAS;QACV,CAAC;QACD,IAAI,iBAAiB,KAAK,CAAC,IAAI,SAAS,KAAK,iBAAiB,EAAE,CAAC;YAChE,SAAS,EAAE,CAAC;QACb,CAAC;QACD,iBAAiB,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,OAAO,SAAS,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** A ratio between two measurements, with its propagated uncertainty. */
|
|
2
|
+
export interface RatioWithUncertainty {
|
|
3
|
+
/** `value / baseline`. */
|
|
4
|
+
ratio: number;
|
|
5
|
+
/** Absolute margin on {@link RatioWithUncertainty.ratio}. */
|
|
6
|
+
errorMargin: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Ratio of two independently-measured quantities, with the uncertainty
|
|
10
|
+
* propagated from each operand's own relative uncertainty.
|
|
11
|
+
*
|
|
12
|
+
* Reporting a ratio without an error term invites reading noise as signal: the
|
|
13
|
+
* relative uncertainty of a quotient of two independent quantities is the
|
|
14
|
+
* quadrature sum (root sum of squares) of their own relative uncertainties.
|
|
15
|
+
*
|
|
16
|
+
* @param value Numerator.
|
|
17
|
+
* @param relativeUncertaintyValue `value`'s dispersion as a fraction of `value`
|
|
18
|
+
* (e.g. a relative standard deviation).
|
|
19
|
+
* @param baseline Denominator.
|
|
20
|
+
* @param relativeUncertaintyBaseline `baseline`'s dispersion as a fraction of
|
|
21
|
+
* `baseline`.
|
|
22
|
+
* @returns `NaN` for both fields when `baseline` is `0`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ratioWithUncertainty(value: number, relativeUncertaintyValue: number, baseline: number, relativeUncertaintyBaseline: number): RatioWithUncertainty;
|
|
25
|
+
//# sourceMappingURL=uncertainty.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uncertainty.d.ts","sourceRoot":"","sources":["../src/uncertainty.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,WAAW,oBAAoB;IACpC,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IAEd,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,MAAM,EACb,wBAAwB,EAAE,MAAM,EAChC,QAAQ,EAAE,MAAM,EAChB,2BAA2B,EAAE,MAAM,GACjC,oBAAoB,CAWtB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ratio of two independently-measured quantities, with the uncertainty
|
|
3
|
+
* propagated from each operand's own relative uncertainty.
|
|
4
|
+
*
|
|
5
|
+
* Reporting a ratio without an error term invites reading noise as signal: the
|
|
6
|
+
* relative uncertainty of a quotient of two independent quantities is the
|
|
7
|
+
* quadrature sum (root sum of squares) of their own relative uncertainties.
|
|
8
|
+
*
|
|
9
|
+
* @param value Numerator.
|
|
10
|
+
* @param relativeUncertaintyValue `value`'s dispersion as a fraction of `value`
|
|
11
|
+
* (e.g. a relative standard deviation).
|
|
12
|
+
* @param baseline Denominator.
|
|
13
|
+
* @param relativeUncertaintyBaseline `baseline`'s dispersion as a fraction of
|
|
14
|
+
* `baseline`.
|
|
15
|
+
* @returns `NaN` for both fields when `baseline` is `0`.
|
|
16
|
+
*/
|
|
17
|
+
export function ratioWithUncertainty(value, relativeUncertaintyValue, baseline, relativeUncertaintyBaseline) {
|
|
18
|
+
if (baseline === 0) {
|
|
19
|
+
return { ratio: Number.NaN, errorMargin: Number.NaN };
|
|
20
|
+
}
|
|
21
|
+
const ratio = value / baseline;
|
|
22
|
+
const errorMargin = ratio *
|
|
23
|
+
Math.sqrt(relativeUncertaintyValue ** 2 + relativeUncertaintyBaseline ** 2);
|
|
24
|
+
return { ratio, errorMargin };
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=uncertainty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uncertainty.js","sourceRoot":"","sources":["../src/uncertainty.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB,CACnC,KAAa,EACb,wBAAgC,EAChC,QAAgB,EAChB,2BAAmC;IAEnC,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACpB,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;IACvD,CAAC;IAED,MAAM,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC/B,MAAM,WAAW,GAChB,KAAK;QACL,IAAI,CAAC,IAAI,CAAC,wBAAwB,IAAI,CAAC,GAAG,2BAA2B,IAAI,CAAC,CAAC,CAAC;IAE7E,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Distribution } from "./distribution.js";
|
|
2
|
+
/**
|
|
3
|
+
* The continuous uniform distribution over `[lower, upper]`.
|
|
4
|
+
*
|
|
5
|
+
* @param lower Lower bound of the support.
|
|
6
|
+
* @param upper Upper bound of the support; must exceed `lower`.
|
|
7
|
+
* @returns The distribution.
|
|
8
|
+
* @throws {RangeError} When the bounds do not enclose a positive width.
|
|
9
|
+
*/
|
|
10
|
+
export declare function uniformDistribution(lower?: number, upper?: number): Distribution;
|
|
11
|
+
//# sourceMappingURL=uniform-distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform-distribution.d.ts","sourceRoot":"","sources":["../src/uniform-distribution.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,SAAI,EAAE,KAAK,SAAI,GAAG,YAAY,CAyBtE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { clamp } from "@ac-kit/core";
|
|
2
|
+
import { assertProbability_ } from "./_assert-probability.js";
|
|
3
|
+
import { inverseTransformSample_ } from "./_inverse-transform-sample.js";
|
|
4
|
+
/**
|
|
5
|
+
* The continuous uniform distribution over `[lower, upper]`.
|
|
6
|
+
*
|
|
7
|
+
* @param lower Lower bound of the support.
|
|
8
|
+
* @param upper Upper bound of the support; must exceed `lower`.
|
|
9
|
+
* @returns The distribution.
|
|
10
|
+
* @throws {RangeError} When the bounds do not enclose a positive width.
|
|
11
|
+
*/
|
|
12
|
+
export function uniformDistribution(lower = 0, upper = 1) {
|
|
13
|
+
const width = upper - lower;
|
|
14
|
+
if (!(width > 0)) {
|
|
15
|
+
throw new RangeError(`uniformDistribution: upper must exceed lower, got [${lower}, ${upper}]`);
|
|
16
|
+
}
|
|
17
|
+
const quantile = (probability) => {
|
|
18
|
+
assertProbability_("uniformDistribution", probability);
|
|
19
|
+
return lower + probability * width;
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
density: (x) => (x < lower || x > upper ? 0 : 1 / width),
|
|
23
|
+
cdf: (x) => clamp((x - lower) / width, 0, 1),
|
|
24
|
+
// From the upper bound inward, so a value just short of `upper` keeps its
|
|
25
|
+
// significant digits instead of cancelling against 1.
|
|
26
|
+
survival: (x) => clamp((upper - x) / width, 0, 1),
|
|
27
|
+
quantile,
|
|
28
|
+
sample: (random) => inverseTransformSample_(quantile, random),
|
|
29
|
+
mean: lower + width / 2,
|
|
30
|
+
variance: (width * width) / 12,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=uniform-distribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform-distribution.js","sourceRoot":"","sources":["../src/uniform-distribution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGzE;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC;IACvD,MAAM,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IAC5B,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,UAAU,CACnB,sDAAsD,KAAK,KAAK,KAAK,GAAG,CACxE,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,WAAmB,EAAE,EAAE;QACxC,kBAAkB,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC;QAEvD,OAAO,KAAK,GAAG,WAAW,GAAG,KAAK,CAAC;IACpC,CAAC,CAAC;IAEF,OAAO;QACN,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;QACxD,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QAC5C,0EAA0E;QAC1E,sDAAsD;QACtD,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QACjD,QAAQ;QACR,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC7D,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,CAAC;QACvB,QAAQ,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,EAAE;KAC9B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Welch's t-test result: the statistic and its degrees of freedom. */
|
|
2
|
+
export interface WelchTTestResult {
|
|
3
|
+
/** The t-statistic. Its magnitude is what a caller thresholds on. */
|
|
4
|
+
t: number;
|
|
5
|
+
/** Welch–Satterthwaite degrees of freedom, for reporting alongside `t`. */
|
|
6
|
+
degreesOfFreedom: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Welch's t-statistic for two independent samples, without assuming equal
|
|
10
|
+
* variance.
|
|
11
|
+
*
|
|
12
|
+
* The statistic alone, with no p-value. That is the whole point of it: a caller
|
|
13
|
+
* thresholding on `|t|` — as a dudect-style constant-time check does,
|
|
14
|
+
* conventionally at `4.5` — would pay for an incomplete beta evaluation per
|
|
15
|
+
* call and discard it. Callers wanting the p-value, or the one-sample and
|
|
16
|
+
* paired forms, want `tTest`, which computes this statistic through here.
|
|
17
|
+
*
|
|
18
|
+
* @param a First sample. Not modified.
|
|
19
|
+
* @param b Second sample. Not modified.
|
|
20
|
+
* @returns The t-statistic and its Welch–Satterthwaite degrees of freedom.
|
|
21
|
+
* @throws {RangeError} When either sample has fewer than two values.
|
|
22
|
+
*/
|
|
23
|
+
export declare function welchTStatistic(a: readonly number[], b: readonly number[]): WelchTTestResult;
|
|
24
|
+
//# sourceMappingURL=welch-t-statistic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"welch-t-statistic.d.ts","sourceRoot":"","sources":["../src/welch-t-statistic.ts"],"names":[],"mappings":"AAGA,uEAAuE;AACvE,MAAM,WAAW,gBAAgB;IAChC,qEAAqE;IACrE,CAAC,EAAE,MAAM,CAAC;IAEV,2EAA2E;IAC3E,gBAAgB,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC9B,CAAC,EAAE,SAAS,MAAM,EAAE,EACpB,CAAC,EAAE,SAAS,MAAM,EAAE,GAClB,gBAAgB,CAqBlB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mean } from "./average.js";
|
|
2
|
+
import { sampleVariance } from "./dispersion.js";
|
|
3
|
+
/**
|
|
4
|
+
* Welch's t-statistic for two independent samples, without assuming equal
|
|
5
|
+
* variance.
|
|
6
|
+
*
|
|
7
|
+
* The statistic alone, with no p-value. That is the whole point of it: a caller
|
|
8
|
+
* thresholding on `|t|` — as a dudect-style constant-time check does,
|
|
9
|
+
* conventionally at `4.5` — would pay for an incomplete beta evaluation per
|
|
10
|
+
* call and discard it. Callers wanting the p-value, or the one-sample and
|
|
11
|
+
* paired forms, want `tTest`, which computes this statistic through here.
|
|
12
|
+
*
|
|
13
|
+
* @param a First sample. Not modified.
|
|
14
|
+
* @param b Second sample. Not modified.
|
|
15
|
+
* @returns The t-statistic and its Welch–Satterthwaite degrees of freedom.
|
|
16
|
+
* @throws {RangeError} When either sample has fewer than two values.
|
|
17
|
+
*/
|
|
18
|
+
export function welchTStatistic(a, b) {
|
|
19
|
+
if (a.length < 2 || b.length < 2) {
|
|
20
|
+
throw new RangeError("welchTStatistic: both samples must have at least two values");
|
|
21
|
+
}
|
|
22
|
+
const meanA = mean(a);
|
|
23
|
+
const meanB = mean(b);
|
|
24
|
+
const varianceOverCountA = sampleVariance(a) / a.length;
|
|
25
|
+
const varianceOverCountB = sampleVariance(b) / b.length;
|
|
26
|
+
const standardError = Math.sqrt(varianceOverCountA + varianceOverCountB);
|
|
27
|
+
const t = standardError > 0 ? (meanA - meanB) / standardError : 0;
|
|
28
|
+
const degreesOfFreedom = (varianceOverCountA + varianceOverCountB) ** 2 /
|
|
29
|
+
(varianceOverCountA ** 2 / (a.length - 1) +
|
|
30
|
+
varianceOverCountB ** 2 / (b.length - 1));
|
|
31
|
+
return { t, degreesOfFreedom };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=welch-t-statistic.js.map
|