@ac-kit/math-stats 0.3.0 → 0.5.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 +163 -0
- package/README.md +80 -0
- package/dist/_assert-probability.d.ts.map +1 -1
- package/dist/_assert-probability.js +2 -1
- package/dist/_assert-probability.js.map +1 -1
- package/dist/_satterthwaite.d.ts +13 -0
- package/dist/_satterthwaite.d.ts.map +1 -0
- package/dist/_satterthwaite.js +25 -0
- package/dist/_satterthwaite.js.map +1 -0
- package/dist/adjust-p-values.d.ts +41 -0
- package/dist/adjust-p-values.d.ts.map +1 -0
- package/dist/adjust-p-values.js +75 -0
- package/dist/adjust-p-values.js.map +1 -0
- package/dist/ashman-d.d.ts +25 -0
- package/dist/ashman-d.d.ts.map +1 -0
- package/dist/ashman-d.js +24 -0
- package/dist/ashman-d.js.map +1 -0
- package/dist/beta-distribution.d.ts.map +1 -1
- package/dist/beta-distribution.js +3 -2
- package/dist/beta-distribution.js.map +1 -1
- package/dist/bimodality-coefficient.d.ts +32 -0
- package/dist/bimodality-coefficient.d.ts.map +1 -0
- package/dist/bimodality-coefficient.js +63 -0
- package/dist/bimodality-coefficient.js.map +1 -0
- package/dist/binomial-distribution.d.ts.map +1 -1
- package/dist/binomial-distribution.js +2 -1
- package/dist/binomial-distribution.js.map +1 -1
- package/dist/chi-squared-distribution.d.ts.map +1 -1
- package/dist/chi-squared-distribution.js +2 -1
- package/dist/chi-squared-distribution.js.map +1 -1
- package/dist/chi-squared-test.js +2 -2
- package/dist/chi-squared-test.js.map +1 -1
- package/dist/combine-independent-estimates.d.ts +53 -0
- package/dist/combine-independent-estimates.d.ts.map +1 -0
- package/dist/combine-independent-estimates.js +71 -0
- package/dist/combine-independent-estimates.js.map +1 -0
- package/dist/confidence-interval.d.ts.map +1 -1
- package/dist/confidence-interval.js +2 -1
- package/dist/confidence-interval.js.map +1 -1
- package/dist/exponential-distribution.d.ts.map +1 -1
- package/dist/exponential-distribution.js +2 -1
- package/dist/exponential-distribution.js.map +1 -1
- package/dist/f-distribution.d.ts.map +1 -1
- package/dist/f-distribution.js +3 -2
- package/dist/f-distribution.js.map +1 -1
- package/dist/gamma-distribution.d.ts.map +1 -1
- package/dist/gamma-distribution.js +3 -2
- package/dist/gamma-distribution.js.map +1 -1
- package/dist/geometric-distribution.d.ts.map +1 -1
- package/dist/geometric-distribution.js +2 -1
- package/dist/geometric-distribution.js.map +1 -1
- package/dist/hartigan-dip.d.ts +65 -0
- package/dist/hartigan-dip.d.ts.map +1 -0
- package/dist/hartigan-dip.js +273 -0
- package/dist/hartigan-dip.js.map +1 -0
- package/dist/histogram.d.ts +61 -0
- package/dist/histogram.d.ts.map +1 -0
- package/dist/histogram.js +144 -0
- package/dist/histogram.js.map +1 -0
- package/dist/hypergeometric-distribution.js +2 -2
- package/dist/hypergeometric-distribution.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/kmeans.d.ts.map +1 -1
- package/dist/kmeans.js +1 -1
- package/dist/kmeans.js.map +1 -1
- package/dist/log-normal-distribution.d.ts.map +1 -1
- package/dist/log-normal-distribution.js +2 -1
- package/dist/log-normal-distribution.js.map +1 -1
- package/dist/negative-binomial-distribution.d.ts.map +1 -1
- package/dist/negative-binomial-distribution.js +3 -2
- package/dist/negative-binomial-distribution.js.map +1 -1
- package/dist/normal-distribution.d.ts.map +1 -1
- package/dist/normal-distribution.js +2 -1
- package/dist/normal-distribution.js.map +1 -1
- package/dist/normal-quantile.d.ts.map +1 -1
- package/dist/normal-quantile.js +2 -1
- package/dist/normal-quantile.js.map +1 -1
- package/dist/poisson-distribution.d.ts.map +1 -1
- package/dist/poisson-distribution.js +2 -1
- package/dist/poisson-distribution.js.map +1 -1
- package/dist/quantile.d.ts +6 -2
- package/dist/quantile.d.ts.map +1 -1
- package/dist/quantile.js +17 -2
- package/dist/quantile.js.map +1 -1
- package/dist/random-effects.d.ts +56 -9
- package/dist/random-effects.d.ts.map +1 -1
- package/dist/random-effects.js +59 -12
- package/dist/random-effects.js.map +1 -1
- package/dist/regression.d.ts +26 -2
- package/dist/regression.d.ts.map +1 -1
- package/dist/regression.js +175 -12
- package/dist/regression.js.map +1 -1
- package/dist/satterthwaite-degrees-of-freedom.d.ts +44 -0
- package/dist/satterthwaite-degrees-of-freedom.d.ts.map +1 -0
- package/dist/satterthwaite-degrees-of-freedom.js +41 -0
- package/dist/satterthwaite-degrees-of-freedom.js.map +1 -0
- package/dist/sliding-median.d.ts +1 -2
- package/dist/sliding-median.d.ts.map +1 -1
- package/dist/sliding-median.js +28 -24
- package/dist/sliding-median.js.map +1 -1
- package/dist/student-t-distribution.d.ts.map +1 -1
- package/dist/student-t-distribution.js +2 -1
- package/dist/student-t-distribution.js.map +1 -1
- package/dist/two-cluster-split.d.ts +34 -0
- package/dist/two-cluster-split.d.ts.map +1 -0
- package/dist/two-cluster-split.js +78 -0
- package/dist/two-cluster-split.js.map +1 -0
- package/dist/variance-of-sample-median.d.ts +40 -0
- package/dist/variance-of-sample-median.d.ts.map +1 -0
- package/dist/variance-of-sample-median.js +162 -0
- package/dist/variance-of-sample-median.js.map +1 -0
- package/dist/welch-t-statistic.d.ts.map +1 -1
- package/dist/welch-t-statistic.js +7 -3
- package/dist/welch-t-statistic.js.map +1 -1
- package/package.json +9 -7
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variance of a sample's median, estimated from the sample itself: the exact
|
|
3
|
+
* bootstrap variance of the median, computed in closed form rather than by
|
|
4
|
+
* resampling.
|
|
5
|
+
*
|
|
6
|
+
* - Odd `n` is the Maritz–Jarrett estimator: the median is the order statistic
|
|
7
|
+
* `X₍ₖ₎`, `k = (n + 1) / 2`, and a resample's `k`-th value is `x₍ᵢ₎` with
|
|
8
|
+
* probability `wᵢ = I_{i/n}(k, n − k + 1) − I_{(i−1)/n}(k, n − k + 1)`, so
|
|
9
|
+
* the variance is `Σ wᵢ (x₍ᵢ₎ − Σ wⱼ x₍ⱼ₎)²` (Maritz & Jarrett 1978; Wilcox,
|
|
10
|
+
* _Introduction to Robust Estimation and Hypothesis Testing_, who applies it
|
|
11
|
+
* to the lower middle value of an even sample).
|
|
12
|
+
* - Even `n`, `k = n / 2`, is the exact bootstrap variance of the mean of the two
|
|
13
|
+
* middle values (Hutson & Ernst 2000, for any L-estimator), not of one of
|
|
14
|
+
* them: the joint law of `X₍ₖ₎` and `X₍ₖ₊₁₎` adds their covariance, which a
|
|
15
|
+
* suffix recurrence brings to O(n).
|
|
16
|
+
*
|
|
17
|
+
* Exact at every `n`, so there is no switch to the large-sample normal-theory
|
|
18
|
+
* `(π / 2) σ² / n`: that formula overstates a small sample's variance (by 57 %
|
|
19
|
+
* at `n = 1`) and assumes a normal shape, while this one needs no shape, agrees
|
|
20
|
+
* with it on large normal samples, and costs O(n) beyond the sort. Ties are
|
|
21
|
+
* exact: the bootstrap resamples positions.
|
|
22
|
+
*
|
|
23
|
+
* O(n) regularized incomplete beta evaluations and O(n) arithmetic; O(n)
|
|
24
|
+
* memory.
|
|
25
|
+
*
|
|
26
|
+
* @param sorted The sample in ascending order, at least one value, all finite.
|
|
27
|
+
* Not modified.
|
|
28
|
+
* @returns The variance, in the square of the values' unit; `0` for one value
|
|
29
|
+
* or equal values.
|
|
30
|
+
* @throws {RangeError} When `sorted` is empty, holds a value that is not
|
|
31
|
+
* finite, or is not in ascending order.
|
|
32
|
+
* @see Maritz, J. S., & Jarrett, R. G. (1978). A note on estimating the
|
|
33
|
+
* variance of the sample median. _Journal of the American Statistical
|
|
34
|
+
* Association_, 73(361), 194–196.
|
|
35
|
+
* @see Hutson, A. D., & Ernst, M. D. (2000). The exact bootstrap mean and
|
|
36
|
+
* variance of an L-estimator. _Journal of the Royal Statistical Society:
|
|
37
|
+
* Series B_, 62(1), 89–94.
|
|
38
|
+
*/
|
|
39
|
+
export declare function varianceOfSampleMedian(sorted: ArrayLike<number>): number;
|
|
40
|
+
//# sourceMappingURL=variance-of-sample-median.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variance-of-sample-median.d.ts","sourceRoot":"","sources":["../src/variance-of-sample-median.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAgBxE"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { describeValue, PreciseSum } from "@ac-kit/core";
|
|
2
|
+
import { regularizedIncompleteBeta } from "@ac-kit/math-analysis";
|
|
3
|
+
import { logBinomial_ } from "./_log-binomial.js";
|
|
4
|
+
/**
|
|
5
|
+
* Variance of a sample's median, estimated from the sample itself: the exact
|
|
6
|
+
* bootstrap variance of the median, computed in closed form rather than by
|
|
7
|
+
* resampling.
|
|
8
|
+
*
|
|
9
|
+
* - Odd `n` is the Maritz–Jarrett estimator: the median is the order statistic
|
|
10
|
+
* `X₍ₖ₎`, `k = (n + 1) / 2`, and a resample's `k`-th value is `x₍ᵢ₎` with
|
|
11
|
+
* probability `wᵢ = I_{i/n}(k, n − k + 1) − I_{(i−1)/n}(k, n − k + 1)`, so
|
|
12
|
+
* the variance is `Σ wᵢ (x₍ᵢ₎ − Σ wⱼ x₍ⱼ₎)²` (Maritz & Jarrett 1978; Wilcox,
|
|
13
|
+
* _Introduction to Robust Estimation and Hypothesis Testing_, who applies it
|
|
14
|
+
* to the lower middle value of an even sample).
|
|
15
|
+
* - Even `n`, `k = n / 2`, is the exact bootstrap variance of the mean of the two
|
|
16
|
+
* middle values (Hutson & Ernst 2000, for any L-estimator), not of one of
|
|
17
|
+
* them: the joint law of `X₍ₖ₎` and `X₍ₖ₊₁₎` adds their covariance, which a
|
|
18
|
+
* suffix recurrence brings to O(n).
|
|
19
|
+
*
|
|
20
|
+
* Exact at every `n`, so there is no switch to the large-sample normal-theory
|
|
21
|
+
* `(π / 2) σ² / n`: that formula overstates a small sample's variance (by 57 %
|
|
22
|
+
* at `n = 1`) and assumes a normal shape, while this one needs no shape, agrees
|
|
23
|
+
* with it on large normal samples, and costs O(n) beyond the sort. Ties are
|
|
24
|
+
* exact: the bootstrap resamples positions.
|
|
25
|
+
*
|
|
26
|
+
* O(n) regularized incomplete beta evaluations and O(n) arithmetic; O(n)
|
|
27
|
+
* memory.
|
|
28
|
+
*
|
|
29
|
+
* @param sorted The sample in ascending order, at least one value, all finite.
|
|
30
|
+
* Not modified.
|
|
31
|
+
* @returns The variance, in the square of the values' unit; `0` for one value
|
|
32
|
+
* or equal values.
|
|
33
|
+
* @throws {RangeError} When `sorted` is empty, holds a value that is not
|
|
34
|
+
* finite, or is not in ascending order.
|
|
35
|
+
* @see Maritz, J. S., & Jarrett, R. G. (1978). A note on estimating the
|
|
36
|
+
* variance of the sample median. _Journal of the American Statistical
|
|
37
|
+
* Association_, 73(361), 194–196.
|
|
38
|
+
* @see Hutson, A. D., & Ernst, M. D. (2000). The exact bootstrap mean and
|
|
39
|
+
* variance of an L-estimator. _Journal of the Royal Statistical Society:
|
|
40
|
+
* Series B_, 62(1), 89–94.
|
|
41
|
+
*/
|
|
42
|
+
export function varianceOfSampleMedian(sorted) {
|
|
43
|
+
validateSorted_(sorted);
|
|
44
|
+
const n = sorted.length;
|
|
45
|
+
if (n === 1) {
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
if (n % 2 === 1) {
|
|
49
|
+
const weights = orderStatisticWeights_(n, (n + 1) / 2);
|
|
50
|
+
return weightedVariance_(sorted, weights, weightedMean_(sorted, weights));
|
|
51
|
+
}
|
|
52
|
+
return evenMedianVariance_(sorted);
|
|
53
|
+
}
|
|
54
|
+
function validateSorted_(sorted) {
|
|
55
|
+
if (sorted.length === 0) {
|
|
56
|
+
throw new RangeError("varianceOfSampleMedian: the sample is empty");
|
|
57
|
+
}
|
|
58
|
+
for (let index = 0; index < sorted.length; index++) {
|
|
59
|
+
const value = sorted[index];
|
|
60
|
+
if (!Number.isFinite(value)) {
|
|
61
|
+
throw new RangeError(`varianceOfSampleMedian: every value must be finite, got ${describeValue(value)}`);
|
|
62
|
+
}
|
|
63
|
+
if (index > 0 && value < sorted[index - 1]) {
|
|
64
|
+
throw new RangeError(`varianceOfSampleMedian: the sample must be in ascending order, got ${describeValue(value)} after ${describeValue(sorted[index - 1])}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* `P(X*₍ᵣ₎ = x₍ᵢ₎)` for a resample of `n` positions, `i = 1 … n` at index `i −
|
|
70
|
+
* 1`. `P(X*₍ᵣ₎ ≤ x₍ᵢ₎) = P(Bin(n, i/n) ≥ r) = I_{i/n}(r, n − r + 1)`; above `i
|
|
71
|
+
* = r` the complement `I_{(n−i)/n}(n − r + 1, r)` is differenced instead, so
|
|
72
|
+
* each weight keeps its digits in both tails.
|
|
73
|
+
*/
|
|
74
|
+
function orderStatisticWeights_(n, r) {
|
|
75
|
+
const weights = new Float64Array(n);
|
|
76
|
+
const atLeast = (i) => i >= n ? 1 : i <= 0 ? 0 : regularizedIncompleteBeta(r, n - r + 1, i / n);
|
|
77
|
+
const below = (i) => i >= n
|
|
78
|
+
? 0
|
|
79
|
+
: i <= 0
|
|
80
|
+
? 1
|
|
81
|
+
: regularizedIncompleteBeta(n - r + 1, r, (n - i) / n);
|
|
82
|
+
let previous = 0;
|
|
83
|
+
for (let i = 1; i <= r; i++) {
|
|
84
|
+
const current = atLeast(i);
|
|
85
|
+
weights[i - 1] = Math.max(0, current - previous);
|
|
86
|
+
previous = current;
|
|
87
|
+
}
|
|
88
|
+
previous = below(r);
|
|
89
|
+
for (let i = r + 1; i <= n; i++) {
|
|
90
|
+
const current = below(i);
|
|
91
|
+
weights[i - 1] = Math.max(0, previous - current);
|
|
92
|
+
previous = current;
|
|
93
|
+
}
|
|
94
|
+
return weights;
|
|
95
|
+
}
|
|
96
|
+
function weightedMean_(sorted, weights) {
|
|
97
|
+
const total = new PreciseSum();
|
|
98
|
+
for (let index = 0; index < weights.length; index++) {
|
|
99
|
+
total.add(weights[index] * sorted[index]);
|
|
100
|
+
}
|
|
101
|
+
return total.value;
|
|
102
|
+
}
|
|
103
|
+
function weightedVariance_(sorted, weights, center) {
|
|
104
|
+
const total = new PreciseSum();
|
|
105
|
+
for (let index = 0; index < weights.length; index++) {
|
|
106
|
+
const deviation = sorted[index] - center;
|
|
107
|
+
total.add(weights[index] * deviation * deviation);
|
|
108
|
+
}
|
|
109
|
+
return Math.max(0, total.value);
|
|
110
|
+
}
|
|
111
|
+
/** `P(Bin(n, p) = k)`, through logs so neither factor overflows. */
|
|
112
|
+
function binomialMass_(n, k, p) {
|
|
113
|
+
if (p <= 0) {
|
|
114
|
+
return k === 0 ? 1 : 0;
|
|
115
|
+
}
|
|
116
|
+
if (p >= 1) {
|
|
117
|
+
return k === n ? 1 : 0;
|
|
118
|
+
}
|
|
119
|
+
return Math.exp(logBinomial_(n, k) + k * Math.log(p) + (n - k) * Math.log1p(-p));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The exact bootstrap variance of `(X₍ₖ₎ + X₍ₖ₊₁₎) / 2`, `k = n / 2`.
|
|
123
|
+
*
|
|
124
|
+
* With `yᵢ = x₍ᵢ₎ − c` for `c` the bootstrap mean of the median, it is `(E
|
|
125
|
+
* Y₍ₖ₎² + E Y₍ₖ₊₁₎² + 2 E Y₍ₖ₎Y₍ₖ₊₁₎) / 4`. For the cross moment, `Aᵢ = P(X*₍ₖ₎
|
|
126
|
+
* = x₍ᵢ₎ < X*₍ₖ₊₁₎)` is `P(Nᵢ = k) − P(Nᵢ₋₁ = k) ρᵢ`, with `Nᵢ ~ Bin(n, i/n)`
|
|
127
|
+
* counting the resample at or below position `i` and `ρᵢ = ((n − i) / (n − i +
|
|
128
|
+
* 1))ⁿ⁻ᵏ`; given it, the `n − k` other draws are uniform above `i`, so `X*₍ₖ₊₁₎
|
|
129
|
+
* = x₍ⱼ₎` with probability `qᵢⱼ = ((n − j + 1) / (n − i))ⁿ⁻ᵏ − ((n − j) / (n −
|
|
130
|
+
* i))ⁿ⁻ᵏ`, and both equal `x₍ᵢ₎` with probability `wᵢ − Aᵢ`. The sums `Uᵢ =
|
|
131
|
+
* Σ_{j>i} qᵢⱼ yⱼ` obey `Uᵢ₋₁ = ρᵢ Uᵢ + (1 − ρᵢ) yᵢ`, every factor in `[0, 1]`,
|
|
132
|
+
* so the cross moment costs O(n) instead of O(n²).
|
|
133
|
+
*/
|
|
134
|
+
function evenMedianVariance_(sorted) {
|
|
135
|
+
const n = sorted.length;
|
|
136
|
+
const k = n / 2;
|
|
137
|
+
const lower = orderStatisticWeights_(n, k);
|
|
138
|
+
const upper = orderStatisticWeights_(n, k + 1);
|
|
139
|
+
const center = (weightedMean_(sorted, lower) + weightedMean_(sorted, upper)) / 2;
|
|
140
|
+
const remaining = n - k;
|
|
141
|
+
const total = new PreciseSum();
|
|
142
|
+
let suffix = 0;
|
|
143
|
+
let massAtOrBelow = binomialMass_(n, k, 1);
|
|
144
|
+
for (let i = n; i >= 1; i--) {
|
|
145
|
+
const y = sorted[i - 1] - center;
|
|
146
|
+
// log1p and expm1 keep ρ and 1 − ρ exact where 1 / (n − i + 1) is small.
|
|
147
|
+
const exponent = remaining * Math.log1p(-1 / (n - i + 1));
|
|
148
|
+
const rho = Math.exp(exponent);
|
|
149
|
+
const massBefore = binomialMass_(n, k, (i - 1) / n);
|
|
150
|
+
const weight = lower[i - 1];
|
|
151
|
+
const strictlyBelowNext = Math.min(weight, Math.max(0, massAtOrBelow - massBefore * rho));
|
|
152
|
+
const square = y * y;
|
|
153
|
+
total.add(weight * square);
|
|
154
|
+
total.add(upper[i - 1] * square);
|
|
155
|
+
total.add(2 * (weight - strictlyBelowNext) * square);
|
|
156
|
+
total.add(2 * strictlyBelowNext * y * suffix);
|
|
157
|
+
suffix = rho * suffix - Math.expm1(exponent) * y;
|
|
158
|
+
massAtOrBelow = massBefore;
|
|
159
|
+
}
|
|
160
|
+
return Math.max(0, total.value / 4);
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=variance-of-sample-median.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variance-of-sample-median.js","sourceRoot":"","sources":["../src/variance-of-sample-median.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAyB;IAC/D,eAAe,CAAC,MAAM,CAAC,CAAC;IAExB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IAExB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACb,OAAO,CAAC,CAAC;IACV,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAEvD,OAAO,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,eAAe,CAAC,MAAyB;IACjD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,UAAU,CAAC,6CAA6C,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAA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,GAAG,CAAC,MAAM,GAAG,iBAAiB,CAAC,GAAG,MAAM,CAAC,CAAC;QACrD,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,iBAAiB,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;QAE9C,MAAM,GAAG,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACjD,aAAa,GAAG,UAAU,CAAC;IAC5B,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"welch-t-statistic.d.ts","sourceRoot":"","sources":["../src/welch-t-statistic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"welch-t-statistic.d.ts","sourceRoot":"","sources":["../src/welch-t-statistic.ts"],"names":[],"mappings":"AAIA,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,CAuBlB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { satterthwaite_ } from "./_satterthwaite.js";
|
|
1
2
|
import { mean } from "./average.js";
|
|
2
3
|
import { sampleVariance } from "./dispersion.js";
|
|
3
4
|
/**
|
|
@@ -25,9 +26,12 @@ export function welchTStatistic(a, b) {
|
|
|
25
26
|
const varianceOverCountB = sampleVariance(b) / b.length;
|
|
26
27
|
const standardError = Math.sqrt(varianceOverCountA + varianceOverCountB);
|
|
27
28
|
const t = standardError > 0 ? (meanA - meanB) / standardError : 0;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// Unchecked: a NaN or overflowing variance gives NaN degrees of freedom
|
|
30
|
+
// rather than a throw, as this function always has.
|
|
31
|
+
const degreesOfFreedom = satterthwaite_([
|
|
32
|
+
{ variance: varianceOverCountA, degreesOfFreedom: a.length - 1 },
|
|
33
|
+
{ variance: varianceOverCountB, degreesOfFreedom: b.length - 1 },
|
|
34
|
+
]);
|
|
31
35
|
return { t, degreesOfFreedom };
|
|
32
36
|
}
|
|
33
37
|
//# sourceMappingURL=welch-t-statistic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"welch-t-statistic.js","sourceRoot":"","sources":["../src/welch-t-statistic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAWjD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAC9B,CAAoB,EACpB,CAAoB;IAEpB,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,UAAU,CACnB,6DAA6D,CAC7D,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,MAAM,kBAAkB,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACxD,MAAM,kBAAkB,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACxD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC,CAAC;IAEzE,MAAM,CAAC,GAAG,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,aAAa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AM,GAAG,CAAC,EAAE;KAChE,CAAC,CAAC;IAEH,OAAO,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/math-stats",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Descriptive statistics, probability distributions and statistical inference over samples of number.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"distribution",
|
|
@@ -44,17 +44,19 @@
|
|
|
44
44
|
"prepack": "yarn build"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@ac-kit/algo": "^0.
|
|
48
|
-
"@ac-kit/core": "^0.
|
|
49
|
-
"@ac-kit/
|
|
50
|
-
"@ac-kit/math-
|
|
47
|
+
"@ac-kit/algo": "^0.5.0",
|
|
48
|
+
"@ac-kit/core": "^0.12.0",
|
|
49
|
+
"@ac-kit/data": "^0.4.0",
|
|
50
|
+
"@ac-kit/math-analysis": "^0.1.11",
|
|
51
|
+
"@ac-kit/math-random": "^0.4.0",
|
|
52
|
+
"@ac-kit/math-scalar": "^0.3.0",
|
|
51
53
|
"@types/web": "^0.0.367"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
54
|
-
"@ac-kit/test-util": "0.
|
|
56
|
+
"@ac-kit/test-util": "0.4.0",
|
|
55
57
|
"@ac-kit/tsconfig": "0.1.0",
|
|
56
58
|
"@ac-kit/typedoc-config": "0.1.0",
|
|
57
|
-
"@ac-kit/vitest-config": "0.
|
|
59
|
+
"@ac-kit/vitest-config": "0.2.0",
|
|
58
60
|
"@typescript/native": "typescript@7.0.2",
|
|
59
61
|
"rimraf": "6.1.4",
|
|
60
62
|
"typedoc": "0.28.20",
|