@ac-kit/math-stats 0.4.0 → 0.6.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.
Files changed (135) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +106 -0
  3. package/dist/_assert-probability.d.ts.map +1 -1
  4. package/dist/_assert-probability.js +2 -1
  5. package/dist/_assert-probability.js.map +1 -1
  6. package/dist/_histogram-rules.d.ts +15 -0
  7. package/dist/_histogram-rules.d.ts.map +1 -0
  8. package/dist/_histogram-rules.js +208 -0
  9. package/dist/_histogram-rules.js.map +1 -0
  10. package/dist/_satterthwaite.d.ts +13 -0
  11. package/dist/_satterthwaite.d.ts.map +1 -0
  12. package/dist/_satterthwaite.js +25 -0
  13. package/dist/_satterthwaite.js.map +1 -0
  14. package/dist/adjust-p-values.d.ts +41 -0
  15. package/dist/adjust-p-values.d.ts.map +1 -0
  16. package/dist/adjust-p-values.js +75 -0
  17. package/dist/adjust-p-values.js.map +1 -0
  18. package/dist/ashman-d.d.ts +25 -0
  19. package/dist/ashman-d.d.ts.map +1 -0
  20. package/dist/ashman-d.js +24 -0
  21. package/dist/ashman-d.js.map +1 -0
  22. package/dist/beta-distribution.d.ts.map +1 -1
  23. package/dist/beta-distribution.js +3 -2
  24. package/dist/beta-distribution.js.map +1 -1
  25. package/dist/bimodality-coefficient.d.ts +32 -0
  26. package/dist/bimodality-coefficient.d.ts.map +1 -0
  27. package/dist/bimodality-coefficient.js +63 -0
  28. package/dist/bimodality-coefficient.js.map +1 -0
  29. package/dist/binomial-distribution.d.ts.map +1 -1
  30. package/dist/binomial-distribution.js +2 -1
  31. package/dist/binomial-distribution.js.map +1 -1
  32. package/dist/chi-squared-distribution.d.ts.map +1 -1
  33. package/dist/chi-squared-distribution.js +2 -1
  34. package/dist/chi-squared-distribution.js.map +1 -1
  35. package/dist/chi-squared-test.js +2 -2
  36. package/dist/chi-squared-test.js.map +1 -1
  37. package/dist/combine-independent-estimates.d.ts +53 -0
  38. package/dist/combine-independent-estimates.d.ts.map +1 -0
  39. package/dist/combine-independent-estimates.js +71 -0
  40. package/dist/combine-independent-estimates.js.map +1 -0
  41. package/dist/confidence-interval.d.ts.map +1 -1
  42. package/dist/confidence-interval.js +2 -1
  43. package/dist/confidence-interval.js.map +1 -1
  44. package/dist/exponential-distribution.d.ts.map +1 -1
  45. package/dist/exponential-distribution.js +2 -1
  46. package/dist/exponential-distribution.js.map +1 -1
  47. package/dist/f-distribution.d.ts.map +1 -1
  48. package/dist/f-distribution.js +3 -2
  49. package/dist/f-distribution.js.map +1 -1
  50. package/dist/gamma-distribution.d.ts.map +1 -1
  51. package/dist/gamma-distribution.js +3 -2
  52. package/dist/gamma-distribution.js.map +1 -1
  53. package/dist/geometric-distribution.d.ts.map +1 -1
  54. package/dist/geometric-distribution.js +2 -1
  55. package/dist/geometric-distribution.js.map +1 -1
  56. package/dist/hartigan-dip.d.ts +65 -0
  57. package/dist/hartigan-dip.d.ts.map +1 -0
  58. package/dist/hartigan-dip.js +273 -0
  59. package/dist/hartigan-dip.js.map +1 -0
  60. package/dist/hierarchical-cluster.d.ts.map +1 -1
  61. package/dist/hierarchical-cluster.js +10 -5
  62. package/dist/hierarchical-cluster.js.map +1 -1
  63. package/dist/histogram-edges.d.ts +92 -0
  64. package/dist/histogram-edges.d.ts.map +1 -0
  65. package/dist/histogram-edges.js +325 -0
  66. package/dist/histogram-edges.js.map +1 -0
  67. package/dist/histogram.d.ts +80 -4
  68. package/dist/histogram.d.ts.map +1 -1
  69. package/dist/histogram.js +86 -9
  70. package/dist/histogram.js.map +1 -1
  71. package/dist/hypergeometric-distribution.js +2 -2
  72. package/dist/hypergeometric-distribution.js.map +1 -1
  73. package/dist/index.d.ts +10 -0
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +10 -0
  76. package/dist/index.js.map +1 -1
  77. package/dist/kmeans.d.ts.map +1 -1
  78. package/dist/kmeans.js +12 -7
  79. package/dist/kmeans.js.map +1 -1
  80. package/dist/kmedoids.js +2 -1
  81. package/dist/kmedoids.js.map +1 -1
  82. package/dist/log-normal-distribution.d.ts.map +1 -1
  83. package/dist/log-normal-distribution.js +2 -1
  84. package/dist/log-normal-distribution.js.map +1 -1
  85. package/dist/negative-binomial-distribution.d.ts.map +1 -1
  86. package/dist/negative-binomial-distribution.js +3 -2
  87. package/dist/negative-binomial-distribution.js.map +1 -1
  88. package/dist/normal-distribution.d.ts.map +1 -1
  89. package/dist/normal-distribution.js +2 -1
  90. package/dist/normal-distribution.js.map +1 -1
  91. package/dist/normal-quantile.d.ts.map +1 -1
  92. package/dist/normal-quantile.js +2 -1
  93. package/dist/normal-quantile.js.map +1 -1
  94. package/dist/poisson-distribution.d.ts.map +1 -1
  95. package/dist/poisson-distribution.js +2 -1
  96. package/dist/poisson-distribution.js.map +1 -1
  97. package/dist/quantile.d.ts +26 -2
  98. package/dist/quantile.d.ts.map +1 -1
  99. package/dist/quantile.js +69 -9
  100. package/dist/quantile.js.map +1 -1
  101. package/dist/random-effects.d.ts +56 -9
  102. package/dist/random-effects.d.ts.map +1 -1
  103. package/dist/random-effects.js +59 -12
  104. package/dist/random-effects.js.map +1 -1
  105. package/dist/regression.d.ts +26 -2
  106. package/dist/regression.d.ts.map +1 -1
  107. package/dist/regression.js +175 -12
  108. package/dist/regression.js.map +1 -1
  109. package/dist/running-statistics.d.ts +103 -0
  110. package/dist/running-statistics.d.ts.map +1 -0
  111. package/dist/running-statistics.js +283 -0
  112. package/dist/running-statistics.js.map +1 -0
  113. package/dist/satterthwaite-degrees-of-freedom.d.ts +44 -0
  114. package/dist/satterthwaite-degrees-of-freedom.d.ts.map +1 -0
  115. package/dist/satterthwaite-degrees-of-freedom.js +41 -0
  116. package/dist/satterthwaite-degrees-of-freedom.js.map +1 -0
  117. package/dist/sliding-median.d.ts +1 -2
  118. package/dist/sliding-median.d.ts.map +1 -1
  119. package/dist/sliding-median.js +28 -24
  120. package/dist/sliding-median.js.map +1 -1
  121. package/dist/student-t-distribution.d.ts.map +1 -1
  122. package/dist/student-t-distribution.js +2 -1
  123. package/dist/student-t-distribution.js.map +1 -1
  124. package/dist/two-cluster-split.d.ts +34 -0
  125. package/dist/two-cluster-split.d.ts.map +1 -0
  126. package/dist/two-cluster-split.js +78 -0
  127. package/dist/two-cluster-split.js.map +1 -0
  128. package/dist/variance-of-sample-median.d.ts +40 -0
  129. package/dist/variance-of-sample-median.d.ts.map +1 -0
  130. package/dist/variance-of-sample-median.js +162 -0
  131. package/dist/variance-of-sample-median.js.map +1 -0
  132. package/dist/welch-t-statistic.d.ts.map +1 -1
  133. package/dist/welch-t-statistic.js +7 -3
  134. package/dist/welch-t-statistic.js.map +1 -1
  135. package/package.json +9 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,234 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0b4fe43: `histogramEdges(values, options)` gives a histogram's bin edges: NumPy's
8
+ `histogram_bin_edges` equal bins from the low end of the range to the high end,
9
+ or with `nice: true` Vega's round edges, on the multiples of a width of 1, 2 or
10
+ 5 times a power of ten. The width comes from a `rule` (default `"auto"`), a
11
+ `width` or a `count`, with at most `maxCount` bins, over `range` or the extent
12
+ of the finite values; `NaN` and ±Infinity are ignored, an empty sample covers
13
+ `[0, 1]`, a single value is widened by a half (by its own magnitude with
14
+ `nice`), and where a rule finds no width though the values spread (a zero
15
+ interquartile range) Sturges' width stands in instead of NumPy's single bin.
16
+ Edges are finite and strictly ascending, at least two around the values (a
17
+ single value under a `nice` width finer than the doubles there gets the value
18
+ and the next double); the last bin is closed.
19
+
20
+ `HistogramBinRule` and `histogramBinWidth` add NumPy's other rules: `"auto"`,
21
+ `"doane"`, `"rice"`, `"sqrt"` and `"stone"`, checked against NumPy 2.5.
22
+ `histogramBinWidth` and `histogram` accept any `ArrayLike<number>` (a typed
23
+ array is read as is), and `histogram(values, edges, { lastClosed: true })`
24
+ counts a value equal to the last edge in the last bin, as `histogramEdges`' bins
25
+ and NumPy's are.
26
+ - 0b4fe43: `RunningStatistics` accumulates the count, mean, variance, minimum and maximum
27
+ of numbers added one at a time (`add`), by range (`addRange`) or by indexed
28
+ range of a column (`addIndexed`), without copying them. `NaN` is ignored. The
29
+ variance is Welford's single-pass update, so a mean far above the spread loses
30
+ no precision, and `merge` combines partitions exactly as if their numbers had
31
+ been added to one accumulator. `sampleVariance` is `NaN` below two numbers,
32
+ where the function of the same name answers `0`. Its getters read each
33
+ statistic; `writeMean`, `writeMin`, `writeMax` and the variance and standard
34
+ deviation writers put it in an output array (a `Float64Array` or a `number[]`)
35
+ instead, without allocating, even once both kinds have been written.
36
+
37
+ `quantile(sorted, fraction, from, to)` reads the sorted range `[from, to)` in
38
+ place, one group's slice of a shared buffer, and throws a `RangeError` for a
39
+ range outside the array. `writeQuantile(target, index, sorted, fraction, from,
40
+ to)` writes the same quantile into `target[index]` without allocating.
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [0b4fe43]
45
+ - Updated dependencies [0b4fe43]
46
+ - Updated dependencies [0b4fe43]
47
+ - Updated dependencies [0b4fe43]
48
+ - Updated dependencies [0b4fe43]
49
+ - Updated dependencies [0b4fe43]
50
+ - Updated dependencies [0b4fe43]
51
+ - Updated dependencies [0b4fe43]
52
+ - Updated dependencies [0b4fe43]
53
+ - Updated dependencies [0b4fe43]
54
+ - Updated dependencies [0b4fe43]
55
+ - Updated dependencies [0b4fe43]
56
+ - Updated dependencies [0b4fe43]
57
+ - Updated dependencies [0b4fe43]
58
+ - Updated dependencies [0b4fe43]
59
+ - Updated dependencies [0b4fe43]
60
+ - Updated dependencies [0b4fe43]
61
+ - Updated dependencies [0b4fe43]
62
+ - Updated dependencies [0b4fe43]
63
+ - Updated dependencies [0b4fe43]
64
+ - Updated dependencies [0b4fe43]
65
+ - Updated dependencies [0b4fe43]
66
+ - Updated dependencies [0b4fe43]
67
+ - Updated dependencies [0b4fe43]
68
+ - Updated dependencies [0b4fe43]
69
+ - Updated dependencies [0b4fe43]
70
+ - Updated dependencies [0b4fe43]
71
+ - Updated dependencies [0b4fe43]
72
+ - Updated dependencies [0b4fe43]
73
+ - Updated dependencies [0b4fe43]
74
+ - Updated dependencies [0b4fe43]
75
+ - Updated dependencies [0b4fe43]
76
+ - Updated dependencies [0b4fe43]
77
+ - Updated dependencies [0b4fe43]
78
+ - @ac-kit/algo@0.6.0
79
+ - @ac-kit/core@0.13.0
80
+ - @ac-kit/data@0.5.0
81
+ - @ac-kit/math-analysis@0.2.0
82
+ - @ac-kit/math-scalar@0.4.0
83
+ - @ac-kit/math-random@0.4.1
84
+
85
+ ## 0.5.0
86
+
87
+ ### Minor Changes
88
+
89
+ - 34e8cfa: `combineIndependentEstimates(terms)` combines independent estimates linearly
90
+ (`Σ cᵢ θᵢ`, coefficient `1` by default): the estimate, summed exactly rounded,
91
+ its variance `Σ cᵢ² Vᵢ`, its standard error, and the Welch–Satterthwaite
92
+ degrees of freedom, accurate even where the variance leaves the double range.
93
+ Coefficients `1` and `−1` give Welch's difference of two means.
94
+
95
+ `varianceOfSampleMedian(sorted)` estimates the variance of a sample's median
96
+ from the sorted sample: its exact bootstrap variance in closed form, the
97
+ Maritz–Jarrett estimator for an odd sample and Hutson and Ernst's exact
98
+ bootstrap variance of the two middle values' mean for an even one. It needs no
99
+ distributional shape, is exact at every sample size (no switch to a
100
+ large-sample formula), handles ties, and costs O(n) beyond the sort.
101
+ - 34e8cfa: `histogramBinWidth(values, rule)` returns the width of a histogram bin by
102
+ `"sturges"` (`range / (log2 n + 1)`), `"scott"` (`(24√π / n)^(1/3) · σ`, with
103
+ the population standard deviation) or `"freedman-diaconis"`
104
+ (`2 · IQR · n^(-1/3)`, linear-interpolated quartiles), the definitions behind
105
+ NumPy's `histogram_bin_edges`. Only finite values count; the result is `NaN`
106
+ for fewer than two of them, for zero spread, for a width that underflows to
107
+ zero and for an unknown rule. Each spread is measured without overflow or
108
+ underflow over the whole double range, so the width is the representable
109
+ result, rounded; it is `Infinity` only when it exceeds `Number.MAX_VALUE`.
110
+
111
+ `quantile` now accepts any sorted array-like (a `Float64Array` included),
112
+ where it took a `readonly number[]`, and interpolates without overflow between
113
+ neighbours further apart than `Number.MAX_VALUE` (it returned `Infinity`);
114
+ other results are unchanged.
115
+ - 34e8cfa: `bimodalityCoefficient(values)`: Sarle's bimodality coefficient with the SAS
116
+ small-sample corrections (about 1/3 for a normal sample, 5/9 for a uniform or
117
+ exponential one, 1 for two equal point masses) and
118
+ `BIMODALITY_COEFFICIENT_THRESHOLD` (5/9). A screen with known caveats — skewed
119
+ or heavy-tailed unimodal samples can exceed 5/9 and one extreme value pushes it
120
+ towards 1 — documented on the function.
121
+
122
+ `hartiganDip(sorted)`: Hartigan's dip, the distance from a sorted sample's
123
+ distribution function to the nearest unimodal one, with the modal interval, or
124
+ `null` for an empty sample. `dipTestCriticalValue(count, significance)` gives
125
+ the dip above which a sample of at least 10 values is called multimodal at
126
+ significance 0.1, 0.05 or 0.01, from a simulated table of uniform samples (the
127
+ least favourable unimodal case), so the test's false-alarm rate on any unimodal
128
+ sample, however skewed, is at most the significance.
129
+
130
+ `twoClusterSplit(sorted)` splits a sorted sample into the two groups of least
131
+ within-group variance (Otsu's criterion, exact in one dimension, deterministic),
132
+ returning the low group's size and both groups' means and variances, computed
133
+ from each group's own deviations so groups far from zero keep them, or `null`
134
+ when no cut exists. `ashmanD(groups)` is Ashman's D for such a split: how far
135
+ apart two groups are, not whether there are two.
136
+ - 34e8cfa: `poolRandomEffects(groups, level, { method: "hartung-knapp" })` gives the
137
+ Hartung–Knapp–Sidik–Jonkman interval: Student's t on `k − 1` degrees of freedom,
138
+ scaled by the observed scatter of the groups and never narrower than
139
+ DerSimonian–Laird's. It never under-covers with two to nine groups, where the
140
+ default DerSimonian–Laird normal interval is too narrow, at the price of being
141
+ conservative with few or agreeing groups; it needs at least two groups (one
142
+ throws a `RangeError`). The default method is unchanged. Both methods keep a
143
+ finite interval for a level within an ulp of 1. `PooledEstimate`
144
+ gains `standardError` and `degreesOfFreedom` (`Infinity` for the normal
145
+ interval), so a caller can test the estimate against a value. A non-finite group
146
+ estimate or a `NaN` level now throws a `RangeError` instead of producing `NaN`.
147
+
148
+ `adjustPValues(pValues, method)` adjusts a family of p-values for multiple
149
+ comparisons with `"holm"`, `"bonferroni"` or `"benjamini-hochberg"`; the values
150
+ match R's `p.adjust`, and a `NaN` or out-of-range p-value throws.
151
+
152
+ `satterthwaiteDegreesOfFreedom(components)` gives the Welch–Satterthwaite
153
+ effective degrees of freedom of a sum of independent variance estimates,
154
+ accurate for variances anywhere in the double range; invalid components throw a
155
+ `RangeError`. `welchTStatistic` computes its degrees of freedom the same way: its
156
+ results are unchanged, a `NaN` or infinite variance still gives `NaN` degrees of
157
+ freedom rather than a throw, and very large finite variances no longer overflow
158
+ to `NaN`.
159
+
160
+ ### Patch Changes
161
+
162
+ - 34e8cfa: `randomInteger` and `randomBoolean` move from `@ac-kit/algo` to
163
+ `@ac-kit/math-random`, with unchanged behaviour. **Breaking for
164
+ `@ac-kit/algo`:** import them from `@ac-kit/math-random` instead
165
+ (`import { randomBoolean, randomInteger } from "@ac-kit/math-random"`);
166
+ `choice` and `shuffle` stay in `@ac-kit/algo`. `@ac-kit/math-stats` and
167
+ `@ac-kit/model-markup` now depend on `@ac-kit/math-random`.
168
+ - 34e8cfa: An error message that quotes a numeric argument describes it with
169
+ `@ac-kit/core`'s `describeValue`, so building the message can no longer throw
170
+ on a symbol. The text changes: `-0` keeps its sign (`got -0`), a bigint shows
171
+ its digits (a digit-count bound when it is too large to show) and any other
172
+ kind of value is named by its kind. Affected:
173
+ the argument checks of `factorial`, the biquad, window, DCT, FFT size,
174
+ log-frequency map, spectral flux, level meter and novelty peak picker
175
+ functions, every probability distribution's parameters and `quantile`,
176
+ `normalQuantile`, `chiSquaredTest`, `confidenceInterval`, `histogram`,
177
+ `SlidingMedian`, the incomplete beta and gamma functions (and their inverses),
178
+ `trapezoidalRule`, the decimal and rational formatting digit counts and radix,
179
+ the fixed-width integer bit width and shift count, `linspace`, `quantize`,
180
+ `bigIntDigitAt`, `bigIntDigitCount`, `sampleRamp` and `KlActivations`.
181
+ - 34e8cfa: `linearRegressionSlope` answers for finite values of any magnitude instead of
182
+ `NaN` beyond about 1e306 or a lost slope when the terms are far apart in
183
+ magnitude. When every non-zero value lies within 2⁻³⁰⁰ to 2³⁰⁰ (about 1e-90 to
184
+ 1e90), the slope is within four units in the last place of the exact slope of
185
+ the values (a relative error below 2⁻⁵¹ unless the slope is subnormal), however
186
+ much the deviations cancel:
187
+ `linearRegressionSlope([0, 0, 1, -1], [2 ** 100, 2 ** 100, 1, -1])` is `1`,
188
+ where it answered `0`. Beyond that range it is the binary64 nearest the exact
189
+ slope, `±Infinity` only when that is past `Number.MAX_VALUE`.
190
+ - Updated dependencies [34e8cfa]
191
+ - Updated dependencies [34e8cfa]
192
+ - Updated dependencies [34e8cfa]
193
+ - Updated dependencies [34e8cfa]
194
+ - Updated dependencies [34e8cfa]
195
+ - Updated dependencies [34e8cfa]
196
+ - Updated dependencies [34e8cfa]
197
+ - Updated dependencies [34e8cfa]
198
+ - Updated dependencies [34e8cfa]
199
+ - Updated dependencies [34e8cfa]
200
+ - Updated dependencies [34e8cfa]
201
+ - Updated dependencies [34e8cfa]
202
+ - Updated dependencies [34e8cfa]
203
+ - Updated dependencies [34e8cfa]
204
+ - Updated dependencies [34e8cfa]
205
+ - Updated dependencies [34e8cfa]
206
+ - Updated dependencies [34e8cfa]
207
+ - Updated dependencies [34e8cfa]
208
+ - Updated dependencies [34e8cfa]
209
+ - Updated dependencies [34e8cfa]
210
+ - Updated dependencies [34e8cfa]
211
+ - Updated dependencies [34e8cfa]
212
+ - Updated dependencies [34e8cfa]
213
+ - Updated dependencies [34e8cfa]
214
+ - Updated dependencies [34e8cfa]
215
+ - Updated dependencies [34e8cfa]
216
+ - Updated dependencies [34e8cfa]
217
+ - Updated dependencies [34e8cfa]
218
+ - Updated dependencies [34e8cfa]
219
+ - Updated dependencies [34e8cfa]
220
+ - Updated dependencies [34e8cfa]
221
+ - Updated dependencies [34e8cfa]
222
+ - Updated dependencies [34e8cfa]
223
+ - Updated dependencies [34e8cfa]
224
+ - Updated dependencies [34e8cfa]
225
+ - @ac-kit/algo@0.5.0
226
+ - @ac-kit/math-random@0.4.0
227
+ - @ac-kit/core@0.12.0
228
+ - @ac-kit/math-scalar@0.3.0
229
+ - @ac-kit/data@0.4.0
230
+ - @ac-kit/math-analysis@0.1.11
231
+
3
232
  ## 0.4.0
4
233
 
5
234
  ### Minor Changes
package/README.md CHANGED
@@ -46,6 +46,75 @@ on its upper one. Infinities land in the outer bins; `NaN` is not counted.
46
46
  import { histogram } from "@ac-kit/math-stats";
47
47
 
48
48
  histogram([-5, 0, 9, 10, 19, 20, 500], [0, 10, 20]); // [1, 2, 2, 2]
49
+ histogram([-5, 0, 9, 10, 19, 20, 500], [0, 10, 20], { lastClosed: true }); // [1, 2, 3, 1]
50
+ ```
51
+
52
+ `histogramBinWidth(values, rule)` gives the bin width of a rule of thumb, as in
53
+ NumPy's `histogram_bin_edges`: `"auto"` (NumPy's default), `"freedman-diaconis"`,
54
+ `"scott"`, `"sturges"`, `"doane"`, `"rice"`, `"sqrt"` or `"stone"`, over the
55
+ finite values, or `NaN` for fewer than two of them or zero spread. O(n), O(n
56
+ log n) for Freedman–Diaconis and `"auto"`, O(n · max(100, √n)) for Stone.
57
+
58
+ ```ts
59
+ import { histogramBinWidth } from "@ac-kit/math-stats";
60
+
61
+ histogramBinWidth([1, 2, 3, 4, 5, 6, 7, 8], "sturges"); // 1.75
62
+ ```
63
+
64
+ `histogramEdges(values, options)` gives the edges themselves, from a `rule`
65
+ (default `"auto"`), a `width` or a `count`, at most `maxCount` bins, over
66
+ `range` or the extent of the finite values. By default they are NumPy's equal
67
+ bins from the low end to the high end; `nice: true` puts them on the multiples
68
+ of a 1, 2 or 5 width instead, as Vega's `bin` does. `NaN` and the infinities
69
+ are ignored, an empty sample covers `[0, 1]`, a single value is widened, and
70
+ where a rule finds no width (a zero interquartile range) Sturges' stands in.
71
+ Its last bin is closed, as `histogram` counts with `lastClosed`.
72
+
73
+ ```ts
74
+ import { histogram, histogramEdges } from "@ac-kit/math-stats";
75
+
76
+ const values = [0.13, 4.2, 9.7, 5];
77
+ const edges = histogramEdges(values, { count: 4, nice: true }); // [0, 5, 10]
78
+ histogram(values, edges, { lastClosed: true }); // [0, 2, 2, 0]
79
+ ```
80
+
81
+ ## Two groups in a sample
82
+
83
+ `hartiganDip(sorted)` is Hartigan's dip: how far the sample's distribution
84
+ function is from the nearest unimodal one: between `1 / (2n)` and `1/4` for two
85
+ values or more, and 0.5 for a single value. Skew
86
+ and heavy tails do not move it, so it is the test to use when the question is
87
+ "one mode or more": `dipTestCriticalValue(count, significance)` gives the dip a
88
+ sample of that size exceeds with probability 0.1, 0.05 or 0.01 when it is
89
+ uniform, the least favourable unimodal shape, so any unimodal sample is called
90
+ multimodal at most that often.
91
+
92
+ `bimodalityCoefficient(values)` is Sarle's coefficient with the SAS small-sample
93
+ corrections: about 1/3 for a normal sample, 5/9 for a uniform or exponential
94
+ one, 1 for two equal point masses, so a value above
95
+ `BIMODALITY_COEFFICIENT_THRESHOLD` (5/9) suggests more than one mode. It is a
96
+ screen, not a proof: a skewed or heavy-tailed unimodal sample can exceed 5/9 and
97
+ one extreme value pushes it towards 1, so trim outliers first and, for
98
+ multiplicative data such as timings, take the logarithms.
99
+
100
+ `twoClusterSplit(sorted)` cuts a sorted sample into the low and high group of
101
+ least within-group variance (Otsu's criterion, exact in one dimension and
102
+ deterministic, unlike `kmeans`), returning the low group's size and both
103
+ groups' means and variances, or `null` when every value is equal. `ashmanD`
104
+ turns such a split into Ashman's D, `√2·|μ₁ − μ₂| / √(σ₁² + σ₂²)`: above 2 the
105
+ groups are cleanly apart, but a one-sided heavy tail also gives about 2.6, so
106
+ D describes how far apart two groups are, not whether there are two.
107
+
108
+ ```ts
109
+ import {
110
+ dipTestCriticalValue,
111
+ hartiganDip,
112
+ twoClusterSplit,
113
+ } from "@ac-kit/math-stats";
114
+
115
+ const multimodal =
116
+ hartiganDip(sortedTimings)!.dip > dipTestCriticalValue(sortedTimings.length, 0.01);
117
+ const split = twoClusterSplit(sortedTimings); // where the two groups part
49
118
  ```
50
119
 
51
120
  ## Sliding windows
@@ -61,6 +130,26 @@ recent.push(sample);
61
130
  const threshold = recent.median() * 1.5;
62
131
  ```
63
132
 
133
+ ## Running statistics
134
+
135
+ `RunningStatistics` keeps the count, mean, variance, minimum and maximum of
136
+ numbers added one at a time, or by range of a column, without copying them. It
137
+ uses Welford's update, so a mean far above the spread (`1e9 + 0.1`) loses
138
+ nothing, and partitions `merge` as if added to one accumulator.
139
+
140
+ ```ts
141
+ import { RunningStatistics } from "@ac-kit/math-stats";
142
+
143
+ const group = new RunningStatistics().addIndexed(column, rows, from, to);
144
+ group.sampleStandardDeviation;
145
+ ```
146
+
147
+ Its `write…` methods put a statistic in an output array rather than returning
148
+ it, as `writeQuantile(target, index, sorted, fraction, from, to)` does for
149
+ `quantile`: a double returned by a call the engine does not inline is boxed,
150
+ one written to an array is not, so a column of per-group results fills without
151
+ allocating.
152
+
64
153
  ## Distributions
65
154
 
66
155
  Every family is a factory returning a `Distribution` — `density`, `cdf`,
@@ -96,10 +185,27 @@ passing a seeded generator from `@ac-kit/math-random` makes a draw reproducible.
96
185
  | `welchTStatistic(a, b)` | The statistic alone, for callers thresholding on it |
97
186
  | `chiSquaredTest(observed, expected, options)` | Pearson's goodness of fit |
98
187
  | `oneWayAnova(groups)` | Whether several groups share a common mean |
188
+ | `poolRandomEffects(groups, level, { method })` | Random-effects pooling: DerSimonian–Laird or Hartung–Knapp interval |
189
+ | `adjustPValues(pValues, method)` | Holm, Bonferroni or Benjamini–Hochberg adjustment of a family of tests |
190
+ | `satterthwaiteDegreesOfFreedom(components)` | Effective degrees of freedom of a sum of estimated variances |
191
+ | `combineIndependentEstimates(terms)` | `Σ cᵢ θᵢ` of independent estimates, its variance and Welch–Satterthwaite degrees of freedom |
192
+ | `varianceOfSampleMedian(sorted)` | Variance of a sample median: its exact bootstrap variance (Maritz–Jarrett, Hutson–Ernst for an even sample), distribution-free at every size |
99
193
 
100
194
  `tTest` reads its form from its arguments rather than from an option: a number
101
195
  as the second argument is a hypothesised mean, an array is a second sample.
102
196
 
197
+ `poolRandomEffects` defaults to DerSimonian–Laird's normal interval, which is
198
+ too narrow below about ten groups. With few groups (separate processes,
199
+ machines, runs), pass `{ method: "hartung-knapp" }`: the interval then uses
200
+ Student's t on `k − 1` degrees of freedom, scaled by the observed scatter of the
201
+ groups and never narrower than DerSimonian–Laird's. It needs at least two
202
+ groups. That truncation (the "modified" Hartung–Knapp of Röver, Knapp and
203
+ Friede 2015) never lets the interval under-cover, but makes it conservative
204
+ wherever it binds: with groups that agree (τ² = 0) at any count, and with two
205
+ to five groups, a nominal 95 % interval holds the true value 97–100 % of the
206
+ time. Near-nominal coverage is reached with heterogeneous groups from about
207
+ nine up.
208
+
103
209
  ## Usage
104
210
 
105
211
  ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"_assert-probability.d.ts","sourceRoot":"","sources":["../src/_assert-probability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAM7E"}
1
+ {"version":3,"file":"_assert-probability.d.ts","sourceRoot":"","sources":["../src/_assert-probability.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAM7E"}
@@ -1,3 +1,4 @@
1
+ import { describeValue } from "@ac-kit/core";
1
2
  /**
2
3
  * Rejects a probability outside `[0, 1]`, naming the distribution rather than
3
4
  * this module.
@@ -12,7 +13,7 @@
12
13
  */
13
14
  export function assertProbability_(routine, probability) {
14
15
  if (!(probability >= 0 && probability <= 1)) {
15
- throw new RangeError(`${routine}: probability must be in [0, 1], got ${probability}`);
16
+ throw new RangeError(`${routine}: probability must be in [0, 1], got ${describeValue(probability)}`);
16
17
  }
17
18
  }
18
19
  //# sourceMappingURL=_assert-probability.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_assert-probability.js","sourceRoot":"","sources":["../src/_assert-probability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,WAAmB;IACtE,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,UAAU,CACnB,GAAG,OAAO,wCAAwC,WAAW,EAAE,CAC/D,CAAC;IACH,CAAC;AACF,CAAC"}
1
+ {"version":3,"file":"_assert-probability.js","sourceRoot":"","sources":["../src/_assert-probability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,WAAmB;IACtE,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,UAAU,CACnB,GAAG,OAAO,wCAAwC,aAAa,CAAC,WAAW,CAAC,EAAE,CAC9E,CAAC;IACH,CAAC;AACF,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { HistogramBinRule } from "./histogram.js";
2
+ export declare function differenceOver_(high: number, low: number, divisor: number): number;
3
+ /**
4
+ * Edge `index` of `bins` equal bins over `[low, high]`, as NumPy's `linspace`
5
+ * computes it (`index · step + low`, the last edge `high` itself); a span past
6
+ * `Number.MAX_VALUE` is halved first, exactly.
7
+ */
8
+ export declare function linspaceEdge_(low: number, high: number, bins: number, index: number): number;
9
+ /**
10
+ * The width `rule` gives the values of `values` within `[low, high]` (finite
11
+ * bounds), as NumPy's estimator of that name does, or `NaN` where NumPy's is 0
12
+ * (fewer than two values, no spread) and for an unknown rule.
13
+ */
14
+ export declare function ruleWidth_(values: ArrayLike<number>, rule: HistogramBinRule, low: number, high: number): number;
15
+ //# sourceMappingURL=_histogram-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_histogram-rules.d.ts","sourceRoot":"","sources":["../src/_histogram-rules.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAMvD,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GACb,MAAM,CAMR;AAoCD;;;;GAIG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACX,MAAM,CAaR;AAwED;;;;GAIG;AACH,wBAAgB,UAAU,CACzB,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GACV,MAAM,CA+GR"}
@@ -0,0 +1,208 @@
1
+ import { scaleByPowerOfTwo } from "@ac-kit/core";
2
+ import { mean } from "./average.js";
3
+ import { populationStandardDeviation } from "./dispersion.js";
4
+ import { quantile } from "./quantile.js";
5
+ // `(high − low) / divisor`, with `high ≥ low`, rounded once unless the
6
+ // difference overflows; then the halves, exact at that magnitude, are
7
+ // subtracted instead.
8
+ export function differenceOver_(high, low, divisor) {
9
+ const difference = high - low;
10
+ if (difference !== Infinity) {
11
+ return difference / divisor;
12
+ }
13
+ return (high / 2 - low / 2) / (divisor / 2);
14
+ }
15
+ function positiveOrNaN_(width) {
16
+ return width > 0 ? width : Number.NaN;
17
+ }
18
+ // The bin `value` falls in among `bins` equal bins over `[low, high]`, as
19
+ // NumPy's `histogram` finds it: the scaled offset truncated, then corrected
20
+ // against the edges, which it can misjudge by one near an edge; the last bin
21
+ // is closed.
22
+ function uniformBin_(value, low, high, bins) {
23
+ const delta = high - low;
24
+ const scaled = delta === Infinity
25
+ ? ((value / 2 - low / 2) / (high / 2 - low / 2)) * bins
26
+ : ((value - low) / delta) * bins;
27
+ let bin = Math.trunc(scaled);
28
+ if (bin >= bins) {
29
+ bin = bins - 1;
30
+ }
31
+ if (value < linspaceEdge_(low, high, bins, bin)) {
32
+ bin--;
33
+ }
34
+ else if (bin !== bins - 1 &&
35
+ value >= linspaceEdge_(low, high, bins, bin + 1)) {
36
+ bin++;
37
+ }
38
+ return bin;
39
+ }
40
+ /**
41
+ * Edge `index` of `bins` equal bins over `[low, high]`, as NumPy's `linspace`
42
+ * computes it (`index · step + low`, the last edge `high` itself); a span past
43
+ * `Number.MAX_VALUE` is halved first, exactly.
44
+ */
45
+ export function linspaceEdge_(low, high, bins, index) {
46
+ if (index === bins) {
47
+ return high;
48
+ }
49
+ const delta = high - low;
50
+ if (delta === Infinity) {
51
+ return 2 * (index * ((high / 2 - low / 2) / bins) + low / 2);
52
+ }
53
+ const step = delta / bins;
54
+ // A step that underflows to zero: NumPy then divides first.
55
+ return step === 0 && delta !== 0
56
+ ? (index / bins) * delta + low
57
+ : index * step + low;
58
+ }
59
+ // Stone's rule (Stone, 1984), as NumPy's `_hist_bin_stone`: the bin count in
60
+ // 1 … max(100, ⌊√n⌋) minimising the cross-validated estimate of the integrated
61
+ // squared error, `(2 − (n + 1) · Σ pₖ²) / h`, the first on a tie.
62
+ function stoneWidth_(sample, smallest, largest, low, high) {
63
+ const count = sample.length;
64
+ const upper = Math.max(100, Math.floor(Math.sqrt(count)));
65
+ const counts = new Float64Array(upper);
66
+ // `h` is the spread over the count; a spread past the largest double is
67
+ // halved, the same factor for every count, which keeps the scores' order.
68
+ const spread = largest - smallest;
69
+ const scaledSpread = spread === Infinity ? largest / 2 - smallest / 2 : spread;
70
+ let best = 1;
71
+ let bestScore = Infinity;
72
+ for (let bins = 1; bins <= upper; bins++) {
73
+ counts.fill(0, 0, bins);
74
+ for (const value of sample) {
75
+ counts[uniformBin_(value, low, high, bins)]++;
76
+ }
77
+ let squares = 0;
78
+ for (let bin = 0; bin < bins; bin++) {
79
+ const share = counts[bin] / count;
80
+ squares += share * share;
81
+ }
82
+ const score = (2 - (count + 1) * squares) / (scaledSpread / bins);
83
+ if (score < bestScore) {
84
+ bestScore = score;
85
+ best = bins;
86
+ }
87
+ }
88
+ return differenceOver_(largest, smallest, best);
89
+ }
90
+ // The finite sample brought near 1 by a power of two, exactly: the standard
91
+ // deviation overflows on raw values past about 1e154 (its squares) and 1e308
92
+ // (its sum). A value that rounds there moves by under 2⁻¹⁰⁷⁴ of that scale,
93
+ // far below the deviation of any sample whose largest value lies near 1.
94
+ // Returns the exponent, or `undefined` for a sample of zeros.
95
+ function scaleNearOne_(sample) {
96
+ let largest = 0;
97
+ for (const value of sample) {
98
+ largest = Math.max(largest, Math.abs(value));
99
+ }
100
+ if (largest === 0) {
101
+ return undefined;
102
+ }
103
+ const exponent = Math.floor(Math.log2(largest));
104
+ for (let index = 0; index < sample.length; index++) {
105
+ sample[index] = scaleByPowerOfTwo(sample[index], -exponent);
106
+ }
107
+ return exponent;
108
+ }
109
+ function freedmanDiaconis_(sample) {
110
+ const sorted = Float64Array.from(sample).sort();
111
+ return positiveOrNaN_(differenceOver_(quantile(sorted, 0.75), quantile(sorted, 0.25), sample.length ** (1 / 3) / 2));
112
+ }
113
+ /**
114
+ * The width `rule` gives the values of `values` within `[low, high]` (finite
115
+ * bounds), as NumPy's estimator of that name does, or `NaN` where NumPy's is 0
116
+ * (fewer than two values, no spread) and for an unknown rule.
117
+ */
118
+ export function ruleWidth_(values, rule, low, high) {
119
+ let count = 0;
120
+ let smallest = Infinity;
121
+ let largest = -Infinity;
122
+ for (let index = 0; index < values.length; index++) {
123
+ const value = values[index];
124
+ if (value >= low && value <= high) {
125
+ count++;
126
+ smallest = Math.min(smallest, value);
127
+ largest = Math.max(largest, value);
128
+ }
129
+ }
130
+ if (count < 2) {
131
+ return Number.NaN;
132
+ }
133
+ const sample = () => {
134
+ const kept = [];
135
+ for (let index = 0; index < values.length; index++) {
136
+ const value = values[index];
137
+ if (value >= low && value <= high) {
138
+ kept.push(value);
139
+ }
140
+ }
141
+ return kept;
142
+ };
143
+ switch (rule) {
144
+ case "sturges":
145
+ return positiveOrNaN_(differenceOver_(largest, smallest, Math.log2(count) + 1));
146
+ case "rice":
147
+ return positiveOrNaN_(differenceOver_(largest, smallest, 2 * count ** (1 / 3)));
148
+ case "sqrt":
149
+ return positiveOrNaN_(differenceOver_(largest, smallest, Math.sqrt(count)));
150
+ case "scott": {
151
+ const scaled = sample();
152
+ const exponent = scaleNearOne_(scaled);
153
+ if (exponent === undefined) {
154
+ return Number.NaN;
155
+ }
156
+ const width = ((24 * Math.sqrt(Math.PI)) / count) ** (1 / 3) *
157
+ populationStandardDeviation(scaled);
158
+ return positiveOrNaN_(scaleByPowerOfTwo(width, exponent));
159
+ }
160
+ case "doane": {
161
+ if (count < 3) {
162
+ return Number.NaN;
163
+ }
164
+ // The skewness does not change with the scale, so it is measured on
165
+ // the sample brought near 1.
166
+ const scaled = sample();
167
+ if (scaleNearOne_(scaled) === undefined) {
168
+ return Number.NaN;
169
+ }
170
+ const sigma = populationStandardDeviation(scaled);
171
+ if (!(sigma > 0)) {
172
+ return Number.NaN;
173
+ }
174
+ const center = mean(scaled);
175
+ let cubes = 0;
176
+ for (const value of scaled) {
177
+ const standardised = (value - center) / sigma;
178
+ cubes += standardised * standardised * standardised;
179
+ }
180
+ const skewness = cubes / count;
181
+ const skewnessError = Math.sqrt((6 * (count - 2)) / ((count + 1) * (count + 3)));
182
+ return positiveOrNaN_(differenceOver_(largest, smallest, 1 +
183
+ Math.log2(count) +
184
+ Math.log2(1 + Math.abs(skewness) / skewnessError)));
185
+ }
186
+ case "freedman-diaconis":
187
+ return freedmanDiaconis_(sample());
188
+ case "auto": {
189
+ // NumPy's: the Freedman–Diaconis width, but at least half the
190
+ // square-root rule's (so a near-zero interquartile range cannot ask
191
+ // for a great many bins), capped by Sturges'.
192
+ const sturges = differenceOver_(largest, smallest, Math.log2(count) + 1);
193
+ if (!(sturges > 0)) {
194
+ return Number.NaN;
195
+ }
196
+ const freedmanDiaconis = freedmanDiaconis_(sample());
197
+ const sqrtHalf = differenceOver_(largest, smallest, Math.sqrt(count)) / 2;
198
+ return Math.min(Math.max(freedmanDiaconis === freedmanDiaconis ? freedmanDiaconis : 0, sqrtHalf), sturges);
199
+ }
200
+ case "stone":
201
+ return smallest === largest
202
+ ? Number.NaN
203
+ : positiveOrNaN_(stoneWidth_(sample(), smallest, largest, low, high));
204
+ default:
205
+ return Number.NaN;
206
+ }
207
+ }
208
+ //# sourceMappingURL=_histogram-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_histogram-rules.js","sourceRoot":"","sources":["../src/_histogram-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,uEAAuE;AACvE,sEAAsE;AACtE,sBAAsB;AACtB,MAAM,UAAU,eAAe,CAC9B,IAAY,EACZ,GAAW,EACX,OAAe;IAEf,MAAM,UAAU,GAAG,IAAI,GAAG,GAAG,CAAC;IAC9B,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,UAAU,GAAG,OAAO,CAAC;IAC7B,CAAC;IACD,OAAO,CAAC,IAAI,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,cAAc,CAAC,KAAa;IACpC,OAAO,KAAK,GAAG,CAA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,OAAO,MAAM,CAAC,GAAG,CAAC;IACpB,CAAC;AACF,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `(Σ Vᵢ)² / Σ (Vᵢ² / νᵢ)` without validation: a `NaN` or infinite variance
3
+ * gives `NaN`, as does a sum whose variances are all zero.
4
+ *
5
+ * Every variance is divided by the largest before summing and squaring, so the
6
+ * result is finite and accurate across the whole double range — two variances
7
+ * of `1e308` give the same degrees of freedom as two of `1`.
8
+ */
9
+ export declare function satterthwaite_(components: readonly {
10
+ readonly variance: number;
11
+ readonly degreesOfFreedom: number;
12
+ }[]): number;
13
+ //# sourceMappingURL=_satterthwaite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_satterthwaite.d.ts","sourceRoot":"","sources":["../src/_satterthwaite.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC7B,UAAU,EAAE,SAAS;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CAClC,EAAE,GACD,MAAM,CAsBR"}