@numero-uno-jpn/rstats 0.15.3 → 0.16.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 (285) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/README.ja.md +40 -33
  3. package/README.md +36 -28
  4. package/dist/chunks/chunk-2D2IQWUQ.js +2 -0
  5. package/dist/chunks/chunk-5UQCRBAG.js +2 -0
  6. package/dist/chunks/chunk-6CSTWA5E.js +2 -0
  7. package/dist/chunks/chunk-72Y3HZID.js +2 -0
  8. package/dist/chunks/chunk-BG2KLEHM.js +2 -0
  9. package/dist/chunks/chunk-CMEKBNHQ.js +2 -0
  10. package/dist/chunks/chunk-FLJNSXSW.js +2 -0
  11. package/dist/chunks/chunk-GM53LWSR.js +2 -0
  12. package/dist/chunks/chunk-JBCA56ZS.js +3 -0
  13. package/dist/chunks/chunk-K3RJAD2T.js +2 -0
  14. package/dist/chunks/chunk-KAZRWIB5.js +2 -0
  15. package/dist/chunks/chunk-KBVVIMXX.js +3 -0
  16. package/dist/chunks/chunk-N3SIFCZX.js +2 -0
  17. package/dist/chunks/chunk-QNNL7AZ3.js +2 -0
  18. package/dist/chunks/chunk-SC6CV4Z3.js +2 -0
  19. package/dist/chunks/chunk-SYWOBOTR.js +2 -0
  20. package/dist/chunks/chunk-URIO5LY5.js +2 -0
  21. package/dist/chunks/chunk-VTUGG2SV.js +2 -0
  22. package/dist/chunks/chunk-W26LRYOJ.js +2 -0
  23. package/dist/chunks/chunk-XHETEYVC.js +2 -0
  24. package/dist/chunks/{chunk-VLUL2HFW.js → chunk-YRZWONZB.js} +1 -1
  25. package/dist/chunks/chunk-ZGABZMWX.js +2 -0
  26. package/dist/data/grouping.js +20 -5
  27. package/dist/descriptive/basic.js +90 -8
  28. package/dist/descriptive/cov.js +12 -4
  29. package/dist/descriptive/dataFrames.d.ts +4 -2
  30. package/dist/descriptive/dataFrames.js +56 -18
  31. package/dist/descriptive/factanal.js +16 -7
  32. package/dist/descriptive/hist.d.ts +8 -5
  33. package/dist/descriptive/hist.js +71 -31
  34. package/dist/descriptive/missing.js +3 -1
  35. package/dist/descriptive/moments.js +72 -19
  36. package/dist/descriptive/omega.d.ts +1 -1
  37. package/dist/descriptive/omega.js +68 -9
  38. package/dist/descriptive/pivot.d.ts +21 -9
  39. package/dist/descriptive/pivot.js +161 -35
  40. package/dist/descriptive/quantile.js +2 -1
  41. package/dist/descriptive/rank.js +4 -1
  42. package/dist/descriptive/table.d.ts +3 -2
  43. package/dist/descriptive/table.js +24 -9
  44. package/dist/descriptive.js +2 -2
  45. package/dist/distributions/arcsine.js +19 -2
  46. package/dist/distributions/beta.js +24 -4
  47. package/dist/distributions/binomial.js +37 -14
  48. package/dist/distributions/bvnorm.js +11 -2
  49. package/dist/distributions/cauchy.js +12 -4
  50. package/dist/distributions/chisq.js +7 -3
  51. package/dist/distributions/exponential.js +5 -0
  52. package/dist/distributions/f.js +32 -17
  53. package/dist/distributions/gamma.js +27 -3
  54. package/dist/distributions/geometric.js +49 -13
  55. package/dist/distributions/hypergeometric.d.ts +5 -1
  56. package/dist/distributions/hypergeometric.js +93 -6
  57. package/dist/distributions/invgamma.js +2 -1
  58. package/dist/distributions/laplace.js +27 -6
  59. package/dist/distributions/logistic.js +4 -1
  60. package/dist/distributions/lognormal.js +8 -2
  61. package/dist/distributions/multinomial.js +54 -11
  62. package/dist/distributions/nbeta.js +62 -11
  63. package/dist/distributions/nchisq.js +30 -6
  64. package/dist/distributions/negbinomial.js +94 -17
  65. package/dist/distributions/normal.js +9 -4
  66. package/dist/distributions/nt.js +392 -17
  67. package/dist/distributions/pareto.js +4 -1
  68. package/dist/distributions/poisson.js +28 -3
  69. package/dist/distributions/signrank.js +7 -4
  70. package/dist/distributions/summary.js +450 -60
  71. package/dist/distributions/triangular.js +10 -5
  72. package/dist/distributions/tukey.js +5 -2
  73. package/dist/distributions/weibull.js +10 -0
  74. package/dist/distributions/wilcox.d.ts +9 -3
  75. package/dist/distributions/wilcox.js +155 -26
  76. package/dist/distributions.js +2 -2
  77. package/dist/htest/agreement.d.ts +3 -2
  78. package/dist/htest/agreement.js +76 -14
  79. package/dist/htest/ansariTest.d.ts +6 -1
  80. package/dist/htest/ansariTest.js +75 -8
  81. package/dist/htest/aov.d.ts +1 -1
  82. package/dist/htest/aov.js +48 -34
  83. package/dist/htest/binomTest.d.ts +5 -0
  84. package/dist/htest/binomTest.js +41 -17
  85. package/dist/htest/brunnerMunzelTest.d.ts +4 -3
  86. package/dist/htest/brunnerMunzelTest.js +7 -5
  87. package/dist/htest/chisqTest.d.ts +2 -1
  88. package/dist/htest/chisqTest.js +130 -43
  89. package/dist/htest/cor.d.ts +2 -1
  90. package/dist/htest/cor.js +17 -19
  91. package/dist/htest/core/ansari.d.ts +9 -0
  92. package/dist/htest/core/ansari.js +21 -1
  93. package/dist/htest/core/kolmogorov.d.ts +25 -0
  94. package/dist/htest/core/kolmogorov.js +123 -0
  95. package/dist/htest/core/mantelhaen.js +6 -4
  96. package/dist/htest/core/shapiro.d.ts +1 -1
  97. package/dist/htest/core/shapiro.js +5 -1
  98. package/dist/htest/dunnett.js +14 -5
  99. package/dist/htest/effectSize.d.ts +2 -0
  100. package/dist/htest/effectSize.js +91 -29
  101. package/dist/htest/fisherTest.d.ts +2 -2
  102. package/dist/htest/fisherTest.js +36 -18
  103. package/dist/htest/groups.d.ts +7 -0
  104. package/dist/htest/groups.js +21 -4
  105. package/dist/htest/ksTest.d.ts +3 -1
  106. package/dist/htest/ksTest.js +23 -2
  107. package/dist/htest/leveneTest.js +19 -3
  108. package/dist/htest/mantelhaenTest.js +125 -25
  109. package/dist/htest/mcnemarTest.js +32 -11
  110. package/dist/htest/multipleComparisons.d.ts +8 -1
  111. package/dist/htest/multipleComparisons.js +44 -21
  112. package/dist/htest/normalityTests.js +44 -10
  113. package/dist/htest/onewayTest.js +96 -5
  114. package/dist/htest/pAdjust.d.ts +3 -2
  115. package/dist/htest/pAdjust.js +38 -6
  116. package/dist/htest/pairwise.d.ts +1 -1
  117. package/dist/htest/pairwise.js +17 -15
  118. package/dist/htest/poissonTest.d.ts +1 -1
  119. package/dist/htest/poissonTest.js +111 -59
  120. package/dist/htest/polycor.js +27 -7
  121. package/dist/htest/power.d.ts +11 -1
  122. package/dist/htest/power.js +112 -8
  123. package/dist/htest/propTest.js +21 -4
  124. package/dist/htest/pwr.js +121 -24
  125. package/dist/htest/rankTests.js +29 -5
  126. package/dist/htest/tTest.js +44 -21
  127. package/dist/htest/trendTests.d.ts +7 -3
  128. package/dist/htest/trendTests.js +114 -20
  129. package/dist/htest/types.d.ts +5 -0
  130. package/dist/htest/types.js +7 -0
  131. package/dist/htest/varTest.js +45 -14
  132. package/dist/htest/wilcoxTest.js +114 -21
  133. package/dist/integrate/quadpack.js +27 -5
  134. package/dist/internal/covmat.d.ts +5 -0
  135. package/dist/internal/covmat.js +20 -0
  136. package/dist/internal/ddexp.d.ts +15 -1
  137. package/dist/internal/ddexp.js +59 -6
  138. package/dist/internal/discrete.d.ts +14 -0
  139. package/dist/internal/discrete.js +78 -5
  140. package/dist/internal/extremes.d.ts +9 -0
  141. package/dist/internal/extremes.js +24 -0
  142. package/dist/internal/fround.js +13 -4
  143. package/dist/internal/integer.d.ts +9 -0
  144. package/dist/internal/integer.js +12 -0
  145. package/dist/internal/invert.js +15 -2
  146. package/dist/internal/scaledInverse.d.ts +10 -0
  147. package/dist/internal/scaledInverse.js +22 -0
  148. package/dist/internal/seq.js +15 -2
  149. package/dist/internal/summary.d.ts +90 -0
  150. package/dist/internal/summary.js +458 -39
  151. package/dist/internal/uniroot.d.ts +7 -0
  152. package/dist/internal/uniroot.js +28 -3
  153. package/dist/linalg/basic.d.ts +3 -1
  154. package/dist/linalg/basic.js +51 -7
  155. package/dist/linalg/chol.js +4 -1
  156. package/dist/linalg/dot.d.ts +29 -0
  157. package/dist/linalg/dot.js +132 -0
  158. package/dist/linalg/eigen.d.ts +6 -1
  159. package/dist/linalg/eigen.js +71 -14
  160. package/dist/linalg/expm.d.ts +3 -2
  161. package/dist/linalg/expm.js +109 -15
  162. package/dist/linalg/kappa.js +58 -10
  163. package/dist/linalg/lu.d.ts +2 -1
  164. package/dist/linalg/lu.js +35 -5
  165. package/dist/linalg/matrix.d.ts +14 -0
  166. package/dist/linalg/matrix.js +24 -0
  167. package/dist/linalg/ops.js +60 -13
  168. package/dist/linalg/qr.d.ts +2 -1
  169. package/dist/linalg/qr.js +91 -23
  170. package/dist/linalg/schur.js +11 -3
  171. package/dist/linalg/solve.d.ts +6 -1
  172. package/dist/linalg/solve.js +147 -26
  173. package/dist/linalg/svd.d.ts +9 -2
  174. package/dist/linalg/svd.js +29 -11
  175. package/dist/linalg.js +2 -2
  176. package/dist/mixed.js +4 -4
  177. package/dist/models/anovaSequential.d.ts +16 -1
  178. package/dist/models/anovaSequential.js +124 -25
  179. package/dist/models/aovEz.js +140 -30
  180. package/dist/models/aovStrata.js +55 -22
  181. package/dist/models/carAnova.d.ts +1 -1
  182. package/dist/models/carAnova.js +83 -32
  183. package/dist/models/coxph.js +148 -66
  184. package/dist/models/estimable.d.ts +15 -0
  185. package/dist/models/estimable.js +68 -0
  186. package/dist/models/formula.d.ts +1 -1
  187. package/dist/models/formula.js +26 -8
  188. package/dist/models/glm.d.ts +35 -5
  189. package/dist/models/glm.js +398 -55
  190. package/dist/models/glmAnova.js +84 -13
  191. package/dist/models/glmConfint.d.ts +1 -1
  192. package/dist/models/glmConfint.js +115 -27
  193. package/dist/models/glmFamily.d.ts +10 -0
  194. package/dist/models/glmFamily.js +244 -40
  195. package/dist/models/lm.d.ts +12 -1
  196. package/dist/models/lm.js +235 -36
  197. package/dist/models/lmer.d.ts +20 -1
  198. package/dist/models/lmer.js +109 -27
  199. package/dist/models/lmerAnova.js +37 -4
  200. package/dist/models/lmerHypotheses.d.ts +6 -2
  201. package/dist/models/lmerHypotheses.js +14 -2
  202. package/dist/models/lmerTest.d.ts +9 -2
  203. package/dist/models/lmerTest.js +64 -19
  204. package/dist/models/mauchly.d.ts +4 -1
  205. package/dist/models/mauchly.js +34 -13
  206. package/dist/models/mixedStructure.js +6 -0
  207. package/dist/models/modelFrame.js +8 -2
  208. package/dist/models/modelMatrix.d.ts +3 -1
  209. package/dist/models/modelMatrix.js +40 -15
  210. package/dist/models/scaledTables.d.ts +8 -0
  211. package/dist/models/scaledTables.js +6 -0
  212. package/dist/models/survival.d.ts +6 -1
  213. package/dist/models/survival.js +67 -27
  214. package/dist/models/tiedTimes.d.ts +2 -0
  215. package/dist/models/tiedTimes.js +34 -0
  216. package/dist/numerics/deriv.d.ts +1 -1
  217. package/dist/numerics/deriv.js +64 -8
  218. package/dist/numerics/integrate.d.ts +9 -1
  219. package/dist/numerics/integrate.js +103 -16
  220. package/dist/numerics/interp.d.ts +8 -2
  221. package/dist/numerics/interp.js +352 -50
  222. package/dist/numerics/ode.js +55 -1
  223. package/dist/numerics.js +2 -2
  224. package/dist/optim/localmin.js +4 -0
  225. package/dist/optim/optim.d.ts +3 -1
  226. package/dist/optim/optim.js +80 -8
  227. package/dist/random/beta.js +53 -4
  228. package/dist/random/binomial.d.ts +14 -3
  229. package/dist/random/binomial.js +59 -24
  230. package/dist/random/continuous.js +33 -5
  231. package/dist/random/extra.js +42 -9
  232. package/dist/random/gamma.d.ts +4 -1
  233. package/dist/random/gamma.js +36 -8
  234. package/dist/random/hyper.js +9 -6
  235. package/dist/random/mt.js +17 -2
  236. package/dist/random/poisson.js +26 -3
  237. package/dist/random/r2dtable.d.ts +8 -1
  238. package/dist/random/r2dtable.js +24 -3
  239. package/dist/random/rank.d.ts +2 -0
  240. package/dist/random/rank.js +44 -4
  241. package/dist/random/sample.d.ts +12 -2
  242. package/dist/random/sample.js +57 -20
  243. package/dist/random/streams.js +4 -2
  244. package/dist/rstats.js +14 -14
  245. package/dist/special/besselIK.d.ts +12 -0
  246. package/dist/special/besselIK.js +168 -23
  247. package/dist/special/besselJY.d.ts +11 -1
  248. package/dist/special/besselJY.js +127 -19
  249. package/dist/special/besselSeries.d.ts +27 -0
  250. package/dist/special/besselSeries.js +45 -2
  251. package/dist/special/beta.js +4 -1
  252. package/dist/special/choose.js +17 -8
  253. package/dist/special/dd.js +122 -18
  254. package/dist/special/extra.js +14 -2
  255. package/dist/special/gamma.js +11 -2
  256. package/dist/special/incbet.js +30 -4
  257. package/dist/special/incbetTemme.d.ts +7 -0
  258. package/dist/special/incbetTemme.js +45 -12
  259. package/dist/special/loader.d.ts +1 -1
  260. package/dist/special/loader.js +117 -20
  261. package/dist/special/log1pmx.js +4 -0
  262. package/dist/special.js +2 -2
  263. package/dist/tests.js +11 -11
  264. package/llms.txt +12 -6
  265. package/package.json +1 -1
  266. package/dist/chunks/chunk-3THFTB36.js +0 -2
  267. package/dist/chunks/chunk-3TSWYE5L.js +0 -2
  268. package/dist/chunks/chunk-3WPU6LGK.js +0 -2
  269. package/dist/chunks/chunk-5ITR67MB.js +0 -2
  270. package/dist/chunks/chunk-5NRFU6F6.js +0 -2
  271. package/dist/chunks/chunk-E2LCSVQV.js +0 -2
  272. package/dist/chunks/chunk-FCNVTIPJ.js +0 -2
  273. package/dist/chunks/chunk-FKAKALOZ.js +0 -2
  274. package/dist/chunks/chunk-HD73UKPT.js +0 -2
  275. package/dist/chunks/chunk-IUULP3LE.js +0 -2
  276. package/dist/chunks/chunk-JQG3YQOC.js +0 -2
  277. package/dist/chunks/chunk-KT66SB7R.js +0 -2
  278. package/dist/chunks/chunk-MAUAOQG3.js +0 -2
  279. package/dist/chunks/chunk-MDYE7QP2.js +0 -2
  280. package/dist/chunks/chunk-NM3Z2UBQ.js +0 -2
  281. package/dist/chunks/chunk-PMJI5QO6.js +0 -3
  282. package/dist/chunks/chunk-UF7KOTHF.js +0 -3
  283. package/dist/chunks/chunk-UOE57JGT.js +0 -2
  284. package/dist/chunks/chunk-USPEBXSR.js +0 -2
  285. package/dist/chunks/chunk-ZIX7NYQF.js +0 -2
@@ -145,8 +145,11 @@ export function invertContinuous(problem) {
145
145
  }
146
146
  if (!(xl > 0 && xh > xl && Number.isFinite(xh)))
147
147
  return x0;
148
- for (let k = 0; k < 64; k++) {
149
- const mid = xl + (xh - xl) / 2;
148
+ // halved on the bit patterns of the doubles (positive x: ordered as integers), so that any bracket shrinks to
149
+ // adjacent doubles within 64 steps; halving the values took 64 steps per factor 2^64 of width, and a bracket 1e55
150
+ // times wider than the answer ended far from it (qgamma(0.75, 1e145) was 151 ulps below the right 1e145)
151
+ for (let k = 0; k < 70; k++) {
152
+ const mid = bitMidpoint(xl, xh);
150
153
  if (mid <= xl || mid >= xh)
151
154
  break;
152
155
  const r = evaluate(mid)[1];
@@ -162,6 +165,16 @@ export function invertContinuous(problem) {
162
165
  return Math.abs(evaluate(xl)[1]) < Math.abs(evaluate(xh)[1]) ? xl : xh;
163
166
  }
164
167
  }
168
+ const bitView = new DataView(new ArrayBuffer(8));
169
+ /** The double halfway between positive finite a < b in the order of the doubles (the mean of their bit patterns) */
170
+ function bitMidpoint(a, b) {
171
+ bitView.setFloat64(0, a);
172
+ const ia = bitView.getBigUint64(0);
173
+ bitView.setFloat64(0, b);
174
+ const ib = bitView.getBigUint64(0);
175
+ bitView.setBigUint64(0, (ia + ib) / 2n);
176
+ return bitView.getFloat64(0);
177
+ }
165
178
  /** Midpoint of the bracketing interval. If an end is infinite, expand outward from the current value */
166
179
  function midpoint(lo, hi, x) {
167
180
  if (Number.isFinite(lo) && Number.isFinite(hi))
@@ -0,0 +1,10 @@
1
+ /**
2
+ * (R'R)^-1 of an upper triangular R as inv_jk 2^(-e_j - e_k): the columns of R divided by 2^e_j first (exact). The
3
+ * inverse of R itself overflowed for columns of 1e-200 (and underflowed for 1e200), so standard errors were Infinity
4
+ * or 0 though they scale with the column (R's too). e_j is the exponent of the largest |R_ij| of a column outside
5
+ * [2^-400, 2^400], else 0, which leaves the computation as before
6
+ */
7
+ export declare function chol2invColumns(R: readonly (readonly number[])[]): {
8
+ inv: number[][];
9
+ e: number[];
10
+ };
@@ -0,0 +1,22 @@
1
+ // (R'R)^-1 of a triangular factor whose columns may be far from 1 (review 64).
2
+ import { chol2inv } from "../linalg/chol.js";
3
+ import { ldexp } from "./summary.js";
4
+ /**
5
+ * (R'R)^-1 of an upper triangular R as inv_jk 2^(-e_j - e_k): the columns of R divided by 2^e_j first (exact). The
6
+ * inverse of R itself overflowed for columns of 1e-200 (and underflowed for 1e200), so standard errors were Infinity
7
+ * or 0 though they scale with the column (R's too). e_j is the exponent of the largest |R_ij| of a column outside
8
+ * [2^-400, 2^400], else 0, which leaves the computation as before
9
+ */
10
+ export function chol2invColumns(R) {
11
+ const p = R.length;
12
+ const e = new Array(p).fill(0);
13
+ for (let j = 0; j < p; j++) {
14
+ let top = 0;
15
+ for (let i = 0; i <= j; i++)
16
+ top = Math.max(top, Math.abs(R[i][j]));
17
+ if (top > 0 && Number.isFinite(top) && (top < 2 ** -400 || top > 2 ** 400))
18
+ e[j] = Math.floor(Math.log2(top));
19
+ }
20
+ const Rs = e.every((v) => v === 0) ? R.map((r) => r.slice()) : R.map((r) => r.map((v, j) => ldexp(v, -e[j])));
21
+ return { inv: chol2inv(Rs), e };
22
+ }
@@ -4,10 +4,23 @@
4
4
  */
5
5
  export function seqLength(from, to, n) {
6
6
  const len = Math.ceil(n);
7
+ // (a length that is not finite or rounds up to a negative number was an empty array; issue #98)
8
+ if (!Number.isFinite(n) || len < 0)
9
+ throw new RangeError("'length.out' must be a non-negative number");
7
10
  if (len === 1)
8
11
  return [from];
9
- const by = (to - from) / (len - 1);
10
- const out = Array.from({ length: len }, (_, i) => from + i * by);
12
+ let out;
13
+ if (Number.isFinite(to - from) || !Number.isFinite(from) || !Number.isFinite(to)) {
14
+ const by = (to - from) / (len - 1);
15
+ out = Array.from({ length: len }, (_, i) => from + i * by);
16
+ }
17
+ else {
18
+ // finite ends whose difference overflows: in half coordinates, doubled (seqLength(-1e308, 1e308, 3) was NaN,
19
+ // Infinity, 1e308; R's seq gives -1e308, 0, 1e308)
20
+ const h = from / 2;
21
+ const by = (to / 2 - h) / (len - 1);
22
+ out = Array.from({ length: len }, (_, i) => 2 * (h + i * by));
23
+ }
11
24
  if (len > 0)
12
25
  out[len - 1] = to;
13
26
  return out;
@@ -14,13 +14,77 @@ export declare function wideSumAdd(acc: WideSum, v: number, n: number): void;
14
14
  export declare function wideSumValue(acc: WideSum): number;
15
15
  /** v 2^k for an integer k, in two steps so that 2^k itself does not overflow or underflow */
16
16
  export declare function ldexp(v: number, k: number): number;
17
+ /** v 2^k for any integer k (beyond the +-2046 of ldexp), in steps of at most 2^1000 */
18
+ export declare function ldexpWide(v: number, k: number): number;
17
19
  /** Mean as double-double. x contains no NaN and has length >= 1 */
18
20
  export declare function meanDD(x: readonly number[]): DD;
19
21
  export declare function mean(x: readonly number[]): number;
20
22
  /** Unbiased variance. NaN for length below 2 (R's var gives NA) */
21
23
  export declare function variance(x: readonly number[]): number;
24
+ /**
25
+ * Sample standard deviation from the scaled deviations: sqrt(sum d^2 / (n - 1)) in the coordinates 2^-k, times 2^k.
26
+ * The same bits as sqrt(variance(x)) where the variance is a normal number (the square root of 4^k y is 2^k sqrt(y)),
27
+ * and the right value where it overflows or underflows (sd of c(-1e308, -1e308, -1e308, -1e308, 1.5e308) is 1.118e308
28
+ * while its variance is 1.25e616). x contains no NaN
29
+ */
30
+ export declare function standardDeviation(x: readonly number[]): number;
22
31
  /** Unbiased covariance. x and y have the same length and contain no NaN */
23
32
  export declare function covariance(x: readonly number[], y: readonly number[]): number;
33
+ /**
34
+ * The deviations from the mean of x scaled by 2^-k (the scaling first, see the rules above), in double-double, with k
35
+ * and the scaled mean. undefined when x has an infinite value (the mean is not finite)
36
+ */
37
+ export declare function centered(x: readonly number[]): {
38
+ d: DD[];
39
+ k: number;
40
+ mean: DD;
41
+ } | undefined;
42
+ /**
43
+ * (x - mean) / sd, from the scaled deviations (no overflow or underflow at any scale). NaN values when the standard
44
+ * deviation is 0 or x has fewer than 2 values or an infinite one
45
+ */
46
+ export declare function standardize(x: readonly number[]): number[];
47
+ /**
48
+ * Moments of groups on one common scale 2^-k (see the rules above): per group the size, mean, within sum of squares
49
+ * and variance (NaN below 2 values), the grand mean, the between and pooled within sums of squares (accumulated in
50
+ * double-double), and the scaled values. Means are scaled back by 2^k, sums of squares and variances by 2^2k
51
+ */
52
+ export interface GroupMoments {
53
+ k: number;
54
+ groups: number[][];
55
+ n: number[];
56
+ mean: number[];
57
+ ss: number[];
58
+ variance: number[];
59
+ grandMean: number;
60
+ ssBetween: number;
61
+ ssWithin: number;
62
+ }
63
+ export declare function groupMoments(groups: readonly (readonly number[])[]): GroupMoments;
64
+ /** x - y for paired values, both scaled by one 2^-k first (so the differences cannot overflow), with k */
65
+ export declare function pairedDifferences(x: readonly number[], y: readonly number[]): {
66
+ d: number[];
67
+ k: number;
68
+ };
69
+ /**
70
+ * Satterthwaite's degrees of freedom (sum w)^2 / sum(w^2 / df) of a sum of independent variance estimates w with
71
+ * degrees of freedom df. The w are scaled by a power of 2 first (no rounding), so the squares neither overflow nor
72
+ * underflow when the w do not; the ratio does not depend on the units of the data. The form of irr's icc (the same
73
+ * order of operations); tTest, cohensD and gamesHowellTest use R's forms below and this only where those are not finite
74
+ */
75
+ export declare function satterthwaiteDf(w: readonly number[], df: readonly number[]): number;
76
+ /**
77
+ * Welch's degrees of freedom in the form of R's t.test and effectsize: se^4 / sum(se_i^4 / df_i) with se_i = sqrt(w_i)
78
+ * and se = sqrt(sum se_i^2), on the w scaled by an even power of 2 (exact, also through sqrt, so the same bits as R
79
+ * wherever R's terms are in range, and no overflow). {@link satterthwaiteDf} where that is not finite and positive
80
+ * (revision of review 2)
81
+ */
82
+ export declare function satterthwaiteDfSe(w: readonly number[], df: readonly number[]): number;
83
+ /**
84
+ * Welch's degrees of freedom in the form of PMCMRplus's gamesHowellTest: A^2 / sum(s2_i^2 / (n_i^2 (n_i - 1))) with
85
+ * A = sum s2_i / n_i, for the group variances s2 and sizes n, scaled as {@link satterthwaiteDfSe} (revision of review 2)
86
+ */
87
+ export declare function satterthwaiteDfPM(s2: readonly number[], n: readonly number[]): number;
24
88
  /**
25
89
  * Sum (accumulated in double-double without overflow, then rounded; ±Infinity beyond the double range). With
26
90
  * infinite or NaN values, as in double arithmetic
@@ -37,3 +101,29 @@ export declare function tieCounts(x: readonly number[]): number[];
37
101
  export declare function dropNaN(x: readonly number[]): number[];
38
102
  /** Keep only the pairs where neither x nor y is NaN (R's complete.cases) */
39
103
  export declare function completePairs(x: readonly number[], y: readonly number[]): [number[], number[]];
104
+ /**
105
+ * d^2 / e, as for a Pearson chi-squared term. When d^2 overflows (or loses precision below the normal range) although
106
+ * the quotient is representable, it is formed as (d / sqrt(e))^2 instead
107
+ */
108
+ export declare function squareOver(d: number, e: number): number;
109
+ /**
110
+ * a b / n, as for an expected count from two margins. When the product overflows, underflows or is subnormal (with a
111
+ * and b not 0), the three are scaled to [1, 2) by powers of 2 and the exponents added back at the end
112
+ */
113
+ export declare function productOver(a: number, b: number, n: number): number;
114
+ /**
115
+ * Data scaled by a power of 2, 2^-k, so that the largest finite absolute value is in [1, 2) (k = 0 when there is
116
+ * none). The scaling adds no rounding error, so statistics that do not depend on the units (t, F, chi-squared,
117
+ * ratios of variances, degrees of freedom) come out as from the original data, but their squares and variances
118
+ * can no longer overflow or underflow. Quantities with units are multiplied back by 2^k (see ldexp)
119
+ */
120
+ export declare function scaleToUnit(groups: readonly (readonly number[])[]): {
121
+ groups: number[][];
122
+ k: number;
123
+ };
124
+ /**
125
+ * Euclidean norm sqrt(sum x_i^2): the plain sum where it is in range (so the value is unchanged there), otherwise from
126
+ * the values divided by the largest |x_i| (as BLAS's dnrm2), so that squares of values around 1e200 or 1e-200 neither
127
+ * overflow nor underflow
128
+ */
129
+ export declare function norm2(x: readonly number[]): number;