@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
package/CHANGELOG.md CHANGED
@@ -7,6 +7,172 @@ While the version is 0.x, a minor release (0.y.0) may contain breaking changes;
7
7
  they are listed under **Breaking** for each release. From 1.0.0 the project follows
8
8
  [Semantic Versioning](https://semver.org/).
9
9
 
10
+ ## 0.16.0 - 2026-11-04
11
+
12
+ Fixes from a numerical review and GitHub issues #8 to #513. Each case is described, with R's value and rStats.js's, in
13
+ [differences from R](docs/differences-from-r.md) and in the review logs (`docs/review-logs/review_fix_log_*.md`).
14
+ Where R itself is wrong, rStats.js now returns the mathematically right value; where R is right, the aim is R's bits.
15
+ The rules behind these changes are listed under "Design rules" in [CONTRIBUTING.md](CONTRIBUTING.md).
16
+
17
+ ### Breaking
18
+
19
+ - More inputs that define no result are errors, also where R returns NaN, NA or a meaningless value (the distribution
20
+ functions keep returning NaN for invalid parameters, as R):
21
+ - Hypothesis tests: a simulation with `B = 0` or a fractional `B` in `chisqTest` and `fisherTest`; `TukeyHSD` and
22
+ `tukeyTest` with 0 or 1 residual degrees of freedom, and `TukeyHSD` with a NaN `confLevel` or one outside [0, 1];
23
+ `pairwiseTTest` (pooled SD) and `onewayTest(varEqual: true)` with a pooled within-group variance of 0, and the
24
+ Welch `onewayTest` with two or more constant groups; `mauchlyTest` with one tested dimension; `propTrendTest` with
25
+ no events or only events, fewer than two distinct scores or an infinite score; an infinite observation in `adTest`,
26
+ `cvmTest`, `lillieTest`, `sfTest` and `pearsonTest`; `flignerTest` with a group whose median is infinite;
27
+ `jonckheereTest` with fewer than 2 nonempty groups; `brunnerMunzelTest` with a sample of fewer than 2 values;
28
+ `cronbachAlpha` with one subject, `kappa2` with fewer than 2 complete pairs, `omega` with fewer than 2 variables;
29
+ `tTest` with a standard error of 0 also when the mean is 0; `powerTTest`, `powerPropTest` and `powerAnovaTest`
30
+ solving for n (or a proportion) where there is no effect.
31
+ - Models: `lm` with an infinite weight; `lmer` with a non-finite response or a non-finite column of a random-effects
32
+ term; `aov` with `Error()` and a non-finite response; `lmerContest` with NaN in `L` or `rhs`; `aovEz` with a factor
33
+ name given twice; `glm` with a two-column binomial response whose total overflows; a formula power beyond the
34
+ integer range (`y ~ (a + b)^1e999` did not return).
35
+ - Numerical methods: `uniroot` with `tol = 0` or an unknown `extendInt`; `optim` and `optimHess` with
36
+ `fnscale = ±Infinity`, a non-finite function value at an evaluated point or a non-finite analytic gradient;
37
+ `grad`, `jacobian` and `hessian` with a step that is not positive and finite, `r` above 512, or (`jacobian`)
38
+ results of differing lengths; `integrate` with `subdivisions` beyond the integer range; `ode` with a non-finite
39
+ time; `approx` with a `rule` other than 1 or 2 or an unknown `method`; `seq` with an infinite `by` pointing away
40
+ from `to`.
41
+ - Linear algebra: `lu` of a matrix with NaN or infinite values; `qr` and `qrSolve` with `tol = Infinity`; `qrX` with
42
+ `ncol` above the dimensions; `rcond` with a `uplo` other than `"U"` or `"L"`; `svd` with a negative or NaN `nu` or
43
+ `nv`.
44
+ - Descriptive statistics and data: `hist` with an infinite or NaN break; `cut` with fewer than 2 breaks; `pretty`
45
+ with invalid `shrinkSml`, `highUBias` or `u5Bias`; `mean` with `trim = NaN`; `tapply`, `split` and `aggregate`
46
+ with 2^31 cells or more; `pivotWider` and `pivotLonger` with tidyr's errors (an id column also selected as names
47
+ or values, an empty `namesFrom` or `valuesFrom`, `colsVary` and `namesVary` other than `"fastest"` or
48
+ `"slowest"`, a `namesPattern` with the wrong number of groups).
49
+ - Computation limits: calls that would allocate more than 2^24 values in one array or run for more than about 10
50
+ seconds throw a RangeError before allocating or computing (exact tests point to `exact: false`). Before, they ran for
51
+ minutes, ran out of memory or did not return.
52
+ - Exact tests: `fisherTest` (2 × 2) and `mantelhaenTest(exact: true)` with a support above 2^24 values (and
53
+ `mantelhaenTest` with a total of 2^53 or more); `ksTest`'s exact one-sample p-value above 2^33 multiply-adds;
54
+ `ansariTest` and `jonckheereTest` above 2^24 values or 2^32 steps; `corTest(method: "kendall")` without ties for
55
+ n above 1290; `pAdjust(method: "hommel")` for n above 65536.
56
+ - Simulations and random numbers: `r2dtable` and the simulated p-values of `chisqTest` and `fisherTest` for tables
57
+ with a total above 2^24; `chisqTest`'s goodness-of-fit simulation above 2^27 draws (`B` times the total);
58
+ `rwilcox` with n above 2^24; `rsignrank` with n of 2^27 or more; weighted `sample` and `sampleInt` with a size of
59
+ 2^31 or more.
60
+ - Distributions and special functions: `dwilcox`, `pwilcox` and `qwilcox` above 2^29 steps; `phyper` above 2^26
61
+ terms and `qhyper` with a standard deviation above 2^21; `besselJ`, `besselY`, `besselI` and `besselK` where the
62
+ series or recurrences would take more than 2^25 to 2^31 steps, or a phase that doubles cannot resolve.
63
+ - Linear algebra: `expm` with the Taylor and Padé methods where order × (n^3 + 64) exceeds 2^31.
64
+ - Values that change in the ordinary range:
65
+ - Welch's degrees of freedom in `tTest`, `cohensD` and `gamesHowellTest`, and `tTest`'s interval ends and Welch
66
+ standard error, take R's (and the packages') forms and now match R's bits (they were 1 to 3 ulp off).
67
+ - `contr.poly` (the polynomial contrasts of `lmer`) with 15 levels or fewer comes from a recurrence that is within
68
+ 5.8e-16 of the exact values; its last bits differ from R's, which were up to 2.8e-13 off.
69
+ - `chisqTest`'s standardized residuals (`stdres`) of a contingency table use exact complements of the margins
70
+ (R's form lost small margins); other tables change in the last bits.
71
+ - `distSummary` of the triangular distribution forms the variance and the skewness from differences without
72
+ cancellation.
73
+ - `Anova` takes a residual sum of squares below 1e-24 times the sum of squares of the response as 0 and returns the
74
+ table (car's behaviour) instead of an error.
75
+ - `pAdjust(method: "hommel")` with n = 2 is Hochberg's method, as R.
76
+ - `ksTest`'s exact two-sided one-sample p-value for D < 1/2 is summed from positive terms where it is below about
77
+ 1e-2 (it had an absolute accuracy of 1e-15 only).
78
+ - `quadeTest` counts only the complete blocks (R counts the dropped ones as well).
79
+ - The Welch `onewayTest` with one constant group returns the limit as its variance tends to 0 (R: NaN).
80
+ - `cor` has NaN on the diagonal where a column's correlation with itself is undefined; group labels that mix
81
+ numbers and strings are strings, as R coerces them; `chisqTest` sorts the levels by code point; the two-sample
82
+ `wilcoxTest` with every value tied has p = 1.
83
+ - The Laplace distribution with `sigma = Infinity` is the limit (as the normal, logistic and Cauchy ones), and
84
+ `df(Infinity, ...)` is 0 (R: NaN); `qbinom` rounds a fractional `size` half to even, as R.
85
+
86
+ - Inputs that define no result are errors (R returns NaN or a meaningless value): `mcnemarTest` on a table without
87
+ discordant pairs, the signed rank `wilcoxTest` with only zero differences, `varTest` with two constant samples,
88
+ `chisqTest`'s simulation with fractional counts, a non-integer `B` or goodness-of-fit counts not summing to an
89
+ integer, `mantelhaenTest(exact: true)` with fractional counts, `dunnettTest`, `tukeyTest` and `glhtDunnett` with a
90
+ pooled within-group variance of 0 (or no residual degrees of freedom), `pAdjust` with `n = Infinity`, `glm` with
91
+ infinite weights ("non-finite weights not allowed"), and `table` with a `useNA` other than `"no"`, `"ifany"` and
92
+ `"always"` (R's match.arg error).
93
+ - `glm` halves an IRLS step that increases the deviance (by `epsilon` relative or more, glm2's rule). R's `glm.fit`
94
+ accepts such steps and can stop at a false convergence: a binomial fit with all weights 1000 returned coefficients
95
+ of 1e15 and a deviance of 144175 (the maximum is 4956), and the glm2 example (binomial, `start = -1.81`) a
96
+ coefficient of 2.25e15 instead of log 3.
97
+ - The links of `glm` are exact beyond R's clamps: logit beyond |η| = 30, log below `exp(η) = eps`, probit, cauchit,
98
+ cloglog and power at the ends (R clamps η or μ to the values at eps and the derivatives to eps), kept within (0, 1)
99
+ by the least double and the largest double below 1; the cloglog link is `log(-log1p(-mu))`. Fits that reach these
100
+ ends (separated data in particular) change. `glm` also warns when the linear predictor still moves at convergence
101
+ ("the data may be separated").
102
+ - `optim(method = "CG")` tries the minimum of the parabola through the start of the line search and the accepted point;
103
+ R's cgmin always tries the midpoint. CG's path, results and counts now differ from R's (a quadratic of 3 variables:
104
+ 8 function evaluations instead of 46).
105
+ - `fisherTest` (2 × 2) and `mantelhaenTest(exact: true)`: the conditional MLE and the confidence limits are the roots to
106
+ full precision (R's uniroot stops up to several percent off, at the end 1/eps for a 99.99% limit).
107
+ - `jonckheereTest`'s normal approximation with ties uses the permutation variance with the ties (Hollander & Wolfe);
108
+ clinfun and DescTools use the variance without ties.
109
+ - `dunnTest`'s step-wise adjustments give tied p-values the same adjusted value (dunn.test's depend on the order of the
110
+ groups); without ties as dunn.test.
111
+ - `glm`'s AIC leaves out the rows of weight 0 (R's gaussian AIC was Inf), and deviance residuals without residual
112
+ degrees of freedom come from each row's contribution (R returns 0, also for a fit that has not converged).
113
+ - `glmSummary` names the statistics "z value" whenever the dispersion is not estimated (as R; a given dispersion was
114
+ named "t value").
115
+
116
+ ### Added
117
+
118
+ - Formula variable names may contain letters outside ASCII (`lm("転帰 ~ 年齢", ...)` was an error).
119
+ - `modelMatrix` accepts a response of any type (it was "the response must be numeric"), as R's `model.matrix`.
120
+ - `aov` accepts `Error()` terms in parentheses (`y ~ treatment + (Error(subject))`), as R.
121
+ - `grad`, `jacobian` and `hessian` accept a negative step `eps`, as numDeriv.
122
+
123
+ ### Changed
124
+
125
+ - `rwilcox` with m + n above 2^24 keeps only the swapped ranks instead of an array of m + n ranks (up to 8 GB), with the
126
+ same values and random stream.
127
+
128
+ ### Fixed
129
+
130
+ - Distributions (#19 to #493): point masses and overflowing shapes of the beta family, `ppois`, `pbinom` and `pnbinom`
131
+ beyond 2^53, `phyper` and `qhyper` beyond 2^53, the discrete quantile search near the largest double, the
132
+ location-scale families near the ends of the range, noncentral distributions, `wilcox` and `signrank` tails,
133
+ `distSummary` where its closed forms overflow or underflow (the beta, gamma, F, Weibull, Kumaraswamy, negative
134
+ binomial and hypergeometric families among others) and of a hypergeometric point mass (populations of 0 or 1 gave
135
+ NaN moments).
136
+ - Special functions (#24 to #492): Bessel functions at subnormal and huge arguments and orders (Debye's expansion for
137
+ orders above 1000, the large-x expansion where its powers overflow), `gamma` near its edges, `choose` near overflow.
138
+ - Random numbers (#30 to #428): R's rounding of integer parameters, NaN for invalid parameters with R's stream kept,
139
+ infinite draws of `rgeom` and `rnbinom`, `r2dtable`'s limits, noncentral `rt` and `rf` with infinite df, and `r`
140
+ functions at infinite parameters that return the limits of their `q` functions.
141
+ - Descriptive statistics (#16 to #473): moments, `sd`, `scale`, `cv` and `prcomp` scaled before centring (no overflow
142
+ where the deviations do), `sum` and `mean` with values in three bands of magnitude that cancel, `weightedMean` with
143
+ products below the normal range, `hist`, `cut`, `ecdf` and `findInterval` with more than 2^31 values or breaks,
144
+ `omega`'s convergence warning.
145
+ - Hypothesis tests (#41 to #507): tail probabilities computed directly (`ksTest`'s exact p-value for D ≥ 1/2: 2.0e-20
146
+ where it was 0), intervals at confidence levels next to 1, `binomTest` and `poissonTest` at large counts and beyond
147
+ 2^53, `quadeTest` and `flignerTest` at any scale, `mcnemarTest` where a pair's counts overflow and its continuity
148
+ correction with fractional counts, `ansariTest`'s interval and estimate at the ends of the range, `wilcoxTest`'s
149
+ signed rank interval at a large `mu`, `survdiff` with a singular variance.
150
+ - Linear models and ANOVA (#8 to #509): standard errors independent of the units of x and of the weights (`lm` with a
151
+ column of 1e-200 or weights below 1e-308), `aov` with `Error()` and large covariates, `anova` and `glmAnova` test
152
+ only nested fits (judged on the rows of positive weight), `aovEz` scaled on the kept subjects only, `predict` with
153
+ the exact inner product where the plain sum overflows, warnings of the fits carried to the tables, `mauchlyTest`
154
+ checks.
155
+ - `glm`: hat values follow the rows of the last QR (a working weight that underflowed shifted them), the null deviance
156
+ with weights of 1e308, `glmPredict`'s standard errors where the squares overflow, Rao's score test with the smaller
157
+ model's intercept (as R), profile intervals of `glmConfint` whose restricted fits cycled in the last bits (NaN
158
+ limits), `glmAnova` warns about a model that has not converged, `glmRstandard` keeps small residuals of a rank-0 fit,
159
+ deviances and AIC of the binomial, Poisson, Gamma and inverse Gaussian families where their terms overflow,
160
+ `glmPredict` with the exact inner product.
161
+ - `lmer` and lmerTest: a response of 1e200 times ordinary data fits (#9), random slopes at any units of x (#11),
162
+ Satterthwaite's degrees of freedom independent of the units of the response and of x (#10; a response times 1e6 made
163
+ the df of x 7.4e8 instead of 31), a response with a large constant added is no longer taken for an exact fit (#12),
164
+ and `lmerAnova` compares the fixed effects of fits as column spaces (#8).
165
+ - `coxph`: a column dropped by the Cholesky factorisation no longer enters the solution (#13), tests in units of each
166
+ covariate's scale, times near 1e308.
167
+ - Linear algebra (#55 to #465): `eigen`, `svd`, `schur`, `qr`, `solve` and `expm` at the ends of the range, triangular
168
+ solves, `determinant`, `matMul`, `crossprod` and `tcrossprod` with the exact inner product where the plain sum
169
+ overflows or falls below the normal range, `rcond`, `qrSolve` and `kappa` on singular matrices.
170
+ - Numerical methods (#13 to #504): `integrate`, `optimize` and `uniroot` on intervals whose width overflows, `seq`,
171
+ `approx` and `spline` near overflow, `barylag` with nodes of any scale (#14), `splinefunH` and `hermiteInterp`
172
+ where differences overflow, `ode`, `optimHess` and `hessian` with large steps or values.
173
+ - Data handling (#35 to #500): `pivotLonger` and `pivotWider` as tidyr (name transforms, separators after zero-width
174
+ matches, repeated columns), `merge` with key columns of different types.
175
+
10
176
  ## 0.15.3 - 2026-10-29
11
177
 
12
178
  ### Fixed
package/README.ja.md CHANGED
@@ -14,9 +14,9 @@ JavaScript とブラウザで使える、R と互換の統計関数のライブ
14
14
  持つオブジェクトで渡します。`pt(q, df, { lowerTail: false })` は R の `pt(q, df, lower.tail = FALSE)` に
15
15
  当たります。結果は素のオブジェクトなので、そのまま `JSON.stringify` できます。
16
16
  - **どこでも動きます。** ESM のみで、依存パッケージはなく、Node 専用の API も使っていません。
17
- tree-shaking が効きます (`pnorm` だけなら gzip で 1.2 KB)。
17
+ tree-shaking が効きます (`pnorm` だけなら gzip で 1.4 KB)。
18
18
 
19
- 状態: **0.15.3。** R の stats パッケージの数値計算の中心
19
+ 状態: **0.16.0。** R の stats パッケージの数値計算の中心
20
20
  (分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
21
21
  [ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
22
22
 
@@ -35,12 +35,12 @@ ES2022 の環境が必要です (現行のブラウザ、Node.js 22 以降、Den
35
35
  ```ts
36
36
  import { pnorm, qnorm, pt, qbeta, dbinom } from "@numero-uno-jpn/rstats";
37
37
 
38
- pnorm(1.96); // 0.9750021048517795
39
- qnorm([0.025, 0.975]); // [-1.9599639845400545, 1.959963984540054]
40
- pt(-40, 3); // 1.7190340394579263e-5
41
- pt(2, 10, { lowerTail: false, logP: true }); // -3.3051415512324533 (log of the upper tail)
42
- qbeta(1e-10, 2, 3); // 4.082494015808333e-6
43
- dbinom(3, 10, 0.2); // 0.20132659200000003
38
+ pnorm(1.96); // ≈ 0.9750021049
39
+ qnorm([0.025, 0.975]); // ≈ [-1.959963985, 1.959963985]
40
+ pt(-40, 3); // ≈ 1.719034039e-5
41
+ pt(2, 10, { lowerTail: false, logP: true }); // ≈ -3.305141551 (上側確率の対数)
42
+ qbeta(1e-10, 2, 3); // ≈ 4.082494016e-6
43
+ dbinom(3, 10, 0.2); // ≈ 0.201326592
44
44
  ```
45
45
 
46
46
  最初の引数には数値・配列・`Float64Array` を渡せます。結果は同じ形で返ります。分布の母数はスカラーです。
@@ -52,7 +52,7 @@ import { setSeed, rnorm, RNGkind, getRandomSeed, setRandomSeed, nextRNGStream, r
52
52
 
53
53
  setSeed(42);
54
54
  rnorm(3); // [1.3709584471466685, -0.5646981713960887, 0.3631284113373392]
55
- // R: set.seed(42); rnorm(3) gives the same numbers (up to the last bit)
55
+ // R の set.seed(42); rnorm(3) と最後のビットまで同じ
56
56
 
57
57
  // R の既定以外の設定: RNGkind("L'Ecuyer-CMRG") と parallel::nextRNGStream、sample.kind = "Rounding"
58
58
  RNGkind({ kind: "L'Ecuyer-CMRG" });
@@ -69,11 +69,11 @@ R で `set.seed(42); rnorm(3)` とすると、最後のビットまで同じ数
69
69
  import { tTest, fisherTest, pAdjust } from "@numero-uno-jpn/rstats";
70
70
 
71
71
  const r = tTest([5.1, 4.9, 6.2, 5.8, 6.0, 5.5], [4.1, 4.5, 5.0, 4.8, 4.3]);
72
- r.pValue; // 0.0035365308877675647 (Welch, the default in R)
73
- r.confInt; // [0.4423253334608047, 1.6443413332058612]
72
+ r.pValue; // ≈ 0.003536530888 (R の既定と同じ Welch の検定)
73
+ r.confInt; // ≈ [0.4423253335, 1.644341333]
74
74
  r.method; // "Welch Two Sample t-test"
75
75
 
76
- fisherTest([[3, 1], [1, 3]]).pValue; // 0.4857142857142857
76
+ fisherTest([[3, 1], [1, 3]]).pValue; // ≈ 0.4857142857
77
77
  pAdjust([0.01, 0.02, 0.03, 0.04], { method: "BH" }); // ≈ [0.04, 0.04, 0.04, 0.04]
78
78
  ```
79
79
 
@@ -90,11 +90,11 @@ const dose = [1, 2, 3, 4, 5, 6];
90
90
  const counts = [[1, 19], [4, 16], [9, 11], [13, 7], [18, 2], [19, 1]];
91
91
  const fit = glm(dose, counts, { family: "binomial" }); // R: glm(cbind(s, f) ~ dose, binomial)
92
92
  fit.coefficients; // ≈ [-3.77413, 1.14807]
93
- glmSummary(fit).pValue; // ≈ [5.357e-8, 3.579e-9] (z tests)
93
+ glmSummary(fit).pValue; // ≈ [5.357e-8, 3.579e-9] (z 検定)
94
94
  glmPredict(fit, { newdata: [3.5], type: "response" }); // { fit: ≈ [0.56073], seFit: ≈ [0.06140] }
95
- glmConfint(fit).lower; // ≈ [-5.27166, 0.80033] (profile likelihood)
95
+ glmConfint(fit).lower; // ≈ [-5.27166, 0.80033] (プロファイル尤度)
96
96
  glmAnova(fit).table[1]; // ≈ [1, 62.978, 4, 0.5196, 2.09e-15]
97
- fit.warnings; // [] (R's warnings, such as non-convergence)
97
+ fit.warnings; // [] (収束しないなどの R の警告)
98
98
  ```
99
99
 
100
100
  ### formula による分散分析
@@ -179,9 +179,9 @@ import { solve, qr, qrCoef, svd, eigen } from "@numero-uno-jpn/rstats";
179
179
 
180
180
  solve([[2, 1], [1, 3]]); // [[0.6, -0.2], [-0.2, 0.4]]
181
181
  const q = qr([[1, 1], [1, 2], [1, 3]]);
182
- qrCoef(q, [1, 3, 4]); // ≈ [-0.333, 1.5] (least squares)
183
- svd([[1, 4], [2, 5], [3, 6]]).d; // [9.50803200069572, 0.7728696356734838]
184
- eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
182
+ qrCoef(q, [1, 3, 4]); // ≈ [-0.333, 1.5] (最小二乗)
183
+ svd([[1, 4], [2, 5], [3, 6]]).d; // ≈ [9.508032001, 0.7728696357]
184
+ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
185
185
  ```
186
186
 
187
187
  ## 含まれるもの
@@ -201,7 +201,7 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
201
201
  | 多重比較 | `dscfAllPairsTest` (Steel-Dwass)、`kwAllPairsDunnTest`、`kwManyOneDunnTest`、`manyOneUTest` (Steel の多対一の順位検定)、`dunnettTest`、`gamesHowellTest`、`tukeyTest` (PMCMRplus)、`dunnTest` (dunn.test)、`glhtDunnett` (multcomp) |
202
202
  | 生存時間解析 | `survdiff` (log-rank)、`survfit` (Kaplan-Meier。信頼区間と中央値)、`coxph` (Cox 回帰。Efron と Breslow のタイの扱い、ケースの重み、層、Wald・尤度比・スコア検定) |
203
203
  | 一致度と信頼性 | `kappa2`、`kappamFleiss`、`icc` (irr)、`cronbachAlpha`、`partialR` (psych)、`polychor`、`polyserial` (polycor)、`pbvnorm`、`factanal`、`omega` (McDonald の ω。psych) |
204
- | データの扱い | `completeCases` (`complete.cases`)、`naOmit` (`na.omit`)、`subset`、`merge`、データフレームの `rbind`・`cbind`、`tapply`、`split`、`aggregate`、`pivotLonger` と `pivotWider` (tidyr)。検定の formula 版 (`tTest("y ~ g", data)`、`kruskalTest`、`friedmanTest("y ~ w \| b", data)`、`corTest("~ x + y", data)` など) |
204
+ | データの扱い | `completeCases` (`complete.cases`)、`naOmit` (`na.omit`)、`subset`、`merge`、データフレームの `rbind`・`cbind`、`tapply`、`split`、`aggregate`、`pivotLonger` と `pivotWider` (tidyr)、`fromRows` と `toRows` (行のオブジェクトの配列とデータフレームの相互の変換)。検定の formula 版 (`tTest("y ~ g", data)`、`kruskalTest`、`friedmanTest("y ~ w \| b", data)`、`corTest("~ x + y", data)` など) |
205
205
  | 線形代数 | `matMul` (`%*%`), `add`, `subtract`, `multiply`, `divide`, `outer`, `t`, `diag`, `cbind`, `rbind`, `matrix`, `kronecker`, `seq`, `crossprod`, `tcrossprod`, `norm`, `backsolve`, `forwardsolve`, `chol`, `chol2inv`, `qr` と `qrQ`, `qrR`, `qrX`, `qrCoef`, `qrQy`, `qrQty`, `qrResid`, `qrFitted`, `qrSolve` (`qr.Q` …), `solve`, `det`, `determinant`, `rcond`, `kappa`, `svd`, `eigen`, `lu`, `prcomp`, `ginv` (MASS)、`schur`、`expm` |
206
206
  | 数値計算 | `integrate`, `optimize`, `optim`, `optimHess`, `uniroot`, `approx`, `spline`, `splinefun`, `splinefunH`, `barylag`, `hermiteInterp`, `ode`, `grad`, `jacobian`, `hessian` |
207
207
 
@@ -233,8 +233,15 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
233
233
  - 添字は 0 から始まります。`sampleInt(n)` は `0..n-1` を返します (R の `sample.int()` から 1 を
234
234
  引いた値で、乱数の列は同じ)。`qr` と `chol` のピボットも 0 から始まります。
235
235
  - 固有ベクトルと特異ベクトルの符号が R と違うことがあります (どちらも正しい答えです)。
236
- - 検定は R の警告を出しません。数値の欄と手法の名前はすべて一致します。`glm` は R の警告を結果の
237
- `warnings` で返します。
236
+ - R の警告を表示することはありません。数値の欄と手法の名前はすべて一致します。モデル (`lm`、`glm`、`lmer`、
237
+ `aov`、`anova`、`Anova`、`aovEz`、`coxph`) と一部の検定・効果量・検出力の計算は、R の警告を結果の `warnings`
238
+ に入れて返します。
239
+ - 結果が定義されない入力はエラーにします。R が NaN や意味のない値を返す場合も同じです (たとえば不一致の
240
+ 組がない表の `mcnemarTest`、NaN を含む行列の `lu`)。分布の関数 (d/p/q/r) は、R と同じく不正な母数に NaN を返します。
241
+ [全般的な違い](docs/ja/differences-from-r.md#全般)を見てください。
242
+ - 1 本の配列に 2^24 個を超える値を確保する計算や、10 秒ほどを超えて走る計算は、始める前に RangeError を
243
+ 投げます。正確な検定では `exact: false` を案内します。R はその多くを、時間がかかっても計算します。
244
+ [上限](docs/ja/performance.md#上限)を見てください。
238
245
  - 分布の母数は、ベクトルとして使い回されません (リサイクルしない)。
239
246
  - `lmer` は基準の厳密な最適点を返します。lme4 の最適化はそこへ許容誤差の範囲でしか近づきません。
240
247
  また、lme4 の収束の警告は出しません。
@@ -248,14 +255,14 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
248
255
 
249
256
  | import するもの | gzip |
250
257
  |---|---|
251
- | `pnorm` | 1.2 KB |
252
- | `setSeed`, `rnorm` | 1.7 KB |
253
- | `solve` / `svd` / `eigen` | 1.7 / 2.0 / 4.5 KB |
254
- | `wilcoxTest` / `fisherTest` / `tTest` | 12.8 / 15.9 / 27.5 KB |
255
- | `qbeta` / `pt` と `qt` | 41.4 / 35.9 KB |
256
- | `glm` と `glmSummary` / `glm` とそのすべての関数 | 30.1 / 42.7 KB |
257
- | `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 16.5 / 62.0 KB |
258
- | すべて (`/mixed` を除く) | 201.9 KB |
258
+ | `pnorm` | 1.4 KB |
259
+ | `setSeed`, `rnorm` | 1.8 KB |
260
+ | `solve` / `svd` / `eigen` | 2.2 / 2.2 / 4.9 KB |
261
+ | `wilcoxTest` / `fisherTest` / `tTest` | 15.6 / 26.9 / 30.5 KB |
262
+ | `qbeta` / `pt` と `qt` | 43.2 / 39.7 KB |
263
+ | `glm` と `glmSummary` / `glm` とそのすべての関数 | 34.3 / 49.9 KB |
264
+ | `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 17.6 / 67.1 KB |
265
+ | すべて (`/mixed` を除く) | 240.4 KB |
259
266
 
260
267
  (`npm run size` で測れます。)
261
268
 
@@ -265,13 +272,13 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
265
272
  できません。メインの入口には含めていません)。
266
273
 
267
274
  バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (`/mixed` 以外のすべての関数を含む
268
- minify 済みの ES モジュール、gzip で 202 KB) を jsDelivr から読み込めます。jsDelivr は、npm のリリースを
275
+ minify 済みの ES モジュール、gzip で 241 KB) を jsDelivr から読み込めます。jsDelivr は、npm のリリースを
269
276
  そのまま配信します。
270
277
 
271
278
  ```html
272
279
  <script type="module">
273
- import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.15.3/dist/rstats.js";
274
- console.log(pnorm(1.96)); // 0.9750021048517795
280
+ import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.16.0/dist/rstats.js";
281
+ console.log(pnorm(1.96)); // ≈ 0.9750021049
275
282
  </script>
276
283
  ```
277
284
 
@@ -286,7 +293,7 @@ minify 済みの ES モジュール、gzip で 202 KB) を jsDelivr から読み
286
293
  `dist/tests.js`、`dist/linalg.js`、`dist/descriptive.js`、`dist/numerics.js`、`dist/special.js`、
287
294
  `dist/mixed.js` は上のサブパスと同じ関数を export し、共通のコードを `dist/chunks/` で共有します。そのため、
288
295
  2 つの分野を読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で
289
- 30 KB (`special`) から 159 KB (`tests`) です。
296
+ 37 KB (`numerics`) から 200 KB (`tests`) です。
290
297
 
291
298
  npm を元にしたほかの CDN も使えます。たとえば `https://esm.sh/@numero-uno-jpn/rstats` です。ビルド結果
292
299
  (`dist/`) は main ブランチにはなく、リリースのタグにも入っていますが、jsDelivr の GitHub 経由の配信
package/README.md CHANGED
@@ -12,9 +12,9 @@ R-compatible statistical functions for JavaScript and the browser, written in Ty
12
12
  with camelCase keys: `pt(q, df, { lowerTail: false })` is R's `pt(q, df, lower.tail = FALSE)`.
13
13
  Results are plain objects that `JSON.stringify` cleanly.
14
14
  - **Runs anywhere.** ESM only, no dependencies, no Node-specific APIs, tree-shakable
15
- (`pnorm` alone is 1.2 KB gzipped).
15
+ (`pnorm` alone is 1.4 KB gzipped).
16
16
 
17
- Status: **0.15.3.** The goal is to cover the numerical core of R's
17
+ Status: **0.16.0.** The goal is to cover the numerical core of R's
18
18
  `stats` package (distributions, descriptive statistics, hypothesis tests, linear models, special
19
19
  functions, numerical methods and the basics of linear algebra) with R-compatible results; see [ROADMAP.md](ROADMAP.md) for what remains. See [CHANGELOG.md](CHANGELOG.md).
20
20
 
@@ -33,12 +33,12 @@ Requires an ES2022 environment (current browsers, Node.js 22 or later, Deno, Bun
33
33
  ```ts
34
34
  import { pnorm, qnorm, pt, qbeta, dbinom } from "@numero-uno-jpn/rstats";
35
35
 
36
- pnorm(1.96); // 0.9750021048517795
37
- qnorm([0.025, 0.975]); // [-1.9599639845400545, 1.959963984540054]
38
- pt(-40, 3); // 1.7190340394579263e-5
39
- pt(2, 10, { lowerTail: false, logP: true }); // -3.3051415512324533 (log of the upper tail)
40
- qbeta(1e-10, 2, 3); // 4.082494015808333e-6
41
- dbinom(3, 10, 0.2); // 0.20132659200000003
36
+ pnorm(1.96); // ≈ 0.9750021049
37
+ qnorm([0.025, 0.975]); // ≈ [-1.959963985, 1.959963985]
38
+ pt(-40, 3); // ≈ 1.719034039e-5
39
+ pt(2, 10, { lowerTail: false, logP: true }); // ≈ -3.305141551 (log of the upper tail)
40
+ qbeta(1e-10, 2, 3); // ≈ 4.082494016e-6
41
+ dbinom(3, 10, 0.2); // ≈ 0.201326592
42
42
  ```
43
43
 
44
44
  The first argument may be a number, an array or a `Float64Array`; the result has the same shape.
@@ -66,11 +66,11 @@ runif(2); // [0.31369782407981056, 0.9280126525616814]
66
66
  import { tTest, fisherTest, pAdjust } from "@numero-uno-jpn/rstats";
67
67
 
68
68
  const r = tTest([5.1, 4.9, 6.2, 5.8, 6.0, 5.5], [4.1, 4.5, 5.0, 4.8, 4.3]);
69
- r.pValue; // 0.0035365308877675647 (Welch, the default in R)
70
- r.confInt; // [0.4423253334608047, 1.6443413332058612]
69
+ r.pValue; // ≈ 0.003536530888 (Welch, the default in R)
70
+ r.confInt; // ≈ [0.4423253335, 1.644341333]
71
71
  r.method; // "Welch Two Sample t-test"
72
72
 
73
- fisherTest([[3, 1], [1, 3]]).pValue; // 0.4857142857142857
73
+ fisherTest([[3, 1], [1, 3]]).pValue; // ≈ 0.4857142857
74
74
  pAdjust([0.01, 0.02, 0.03, 0.04], { method: "BH" }); // ≈ [0.04, 0.04, 0.04, 0.04]
75
75
  ```
76
76
 
@@ -177,8 +177,8 @@ import { solve, qr, qrCoef, svd, eigen } from "@numero-uno-jpn/rstats";
177
177
  solve([[2, 1], [1, 3]]); // [[0.6, -0.2], [-0.2, 0.4]]
178
178
  const q = qr([[1, 1], [1, 2], [1, 3]]);
179
179
  qrCoef(q, [1, 3, 4]); // ≈ [-0.333, 1.5] (least squares)
180
- svd([[1, 4], [2, 5], [3, 6]]).d; // [9.50803200069572, 0.7728696356734838]
181
- eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
180
+ svd([[1, 4], [2, 5], [3, 6]]).d; // ≈ [9.508032001, 0.7728696357]
181
+ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
182
182
  ```
183
183
 
184
184
  ## What is included
@@ -198,7 +198,7 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
198
198
  | Multiple comparisons | `dscfAllPairsTest` (Steel-Dwass), `kwAllPairsDunnTest`, `kwManyOneDunnTest`, `manyOneUTest` (Steel's many-one rank test), `dunnettTest`, `gamesHowellTest`, `tukeyTest` (PMCMRplus), `dunnTest` (dunn.test), `glhtDunnett` (multcomp) |
199
199
  | Survival analysis | `survdiff` (log-rank), `survfit` (Kaplan-Meier with intervals and median), `coxph` (Cox regression: Efron and Breslow ties, case weights, strata, the Wald, likelihood-ratio and score tests) |
200
200
  | Agreement and reliability | `kappa2`, `kappamFleiss`, `icc` (irr), `cronbachAlpha`, `partialR` (psych), `polychor`, `polyserial` (polycor), `pbvnorm`, `factanal`, `omega` (McDonald's ω, psych) |
201
- | Data handling | `completeCases` (`complete.cases`), `naOmit` (`na.omit`), `subset`, `merge`, `rbind` and `cbind` of data frames, `tapply`, `split`, `aggregate`, `pivotLonger` and `pivotWider` (tidyr); formula forms of the tests (`tTest("y ~ g", data)`, `kruskalTest`, `friedmanTest("y ~ w \| b", data)`, `corTest("~ x + y", data)`, ...) |
201
+ | Data handling | `completeCases` (`complete.cases`), `naOmit` (`na.omit`), `subset`, `merge`, `rbind` and `cbind` of data frames, `tapply`, `split`, `aggregate`, `pivotLonger` and `pivotWider` (tidyr), `fromRows` and `toRows` (a data frame from an array of row objects and back); formula forms of the tests (`tTest("y ~ g", data)`, `kruskalTest`, `friedmanTest("y ~ w \| b", data)`, `corTest("~ x + y", data)`, ...) |
202
202
  | Linear algebra | `matMul` (`%*%`), `add`, `subtract`, `multiply`, `divide`, `outer`, `t`, `diag`, `cbind`, `rbind`, `matrix`, `kronecker`, `seq`, `crossprod`, `tcrossprod`, `norm`, `backsolve`, `forwardsolve`, `chol`, `chol2inv`, `qr` with `qrQ`, `qrR`, `qrX`, `qrCoef`, `qrQy`, `qrQty`, `qrResid`, `qrFitted`, `qrSolve` (`qr.Q` …), `solve`, `det`, `determinant`, `rcond`, `kappa`, `svd`, `eigen`, `lu`, `prcomp`, `ginv` (MASS), `schur`, `expm` |
203
203
  | Numerical methods | `integrate`, `optimize`, `optim`, `optimHess`, `uniroot`, `approx`, `spline`, `splinefun`, `splinefunH`, `barylag`, `hermiteInterp`, `ode`, `grad`, `jacobian`, `hessian` |
204
204
 
@@ -229,8 +229,16 @@ everyday use:
229
229
  - Indices are 0-based: `sampleInt(n)` returns `0..n-1` (R's `sample.int()` minus 1, from the
230
230
  same random stream), and pivots of `qr` and `chol` are 0-based.
231
231
  - Signs of eigenvectors and singular vectors may differ from R (both are correct).
232
- - Hypothesis tests do not emit R's warnings; all numeric fields and method names match. `glm` returns
233
- R's warnings in its result (`warnings`).
232
+ - Nothing is printed for R's warnings; all numeric fields and method names match. The models (`lm`, `glm`, `lmer`,
233
+ `aov`, `anova`, `Anova`, `aovEz`, `coxph`) and some tests, effect sizes and power calculations return R's warnings in
234
+ their result (`warnings`).
235
+ - Input for which the result is not defined is an error, also where R returns NaN or a meaningless value (for
236
+ example `mcnemarTest` on a table without discordant pairs, or `lu` of a matrix with NaN). The distribution
237
+ functions (d/p/q/r) return NaN for invalid parameters, as R. See
238
+ [the general differences](docs/differences-from-r.md#general).
239
+ - A computation that would allocate more than 2^24 values in one array or run for more than about 10 seconds throws
240
+ a RangeError before it starts; the exact tests suggest `exact: false`. R computes most of these however long they
241
+ take. See [Limits](docs/performance.md#limits).
234
242
  - Distribution parameters are not recycled as vectors.
235
243
  - `lmer` returns the exact optimum of its criterion, which lme4's optimiser approaches only to its tolerances, and
236
244
  does not emit lme4's convergence warnings.
@@ -244,14 +252,14 @@ removed. Approximate sizes after minification and gzip:
244
252
 
245
253
  | Import | gzip |
246
254
  |---|---|
247
- | `pnorm` | 1.2 KB |
248
- | `setSeed`, `rnorm` | 1.7 KB |
249
- | `solve` / `svd` / `eigen` | 1.7 / 2.0 / 4.5 KB |
250
- | `wilcoxTest` / `fisherTest` / `tTest` | 12.8 / 15.9 / 27.5 KB |
251
- | `qbeta` / `pt` and `qt` | 41.4 / 35.9 KB |
252
- | `glm` and `glmSummary` / `glm` with all its methods | 30.1 / 42.7 KB |
253
- | `lmer` (from `/mixed`) / with `lmerSummary`, `lmerContest`, `lmerAnova` | 16.5 / 62.0 KB |
254
- | everything (except `/mixed`) | 201.9 KB |
255
+ | `pnorm` | 1.4 KB |
256
+ | `setSeed`, `rnorm` | 1.8 KB |
257
+ | `solve` / `svd` / `eigen` | 2.2 / 2.2 / 4.9 KB |
258
+ | `wilcoxTest` / `fisherTest` / `tTest` | 15.6 / 26.9 / 30.5 KB |
259
+ | `qbeta` / `pt` and `qt` | 43.2 / 39.7 KB |
260
+ | `glm` and `glmSummary` / `glm` with all its methods | 34.3 / 49.9 KB |
261
+ | `lmer` (from `/mixed`) / with `lmerSummary`, `lmerContest`, `lmerAnova` | 17.6 / 67.1 KB |
262
+ | everything (except `/mixed`) | 240.4 KB |
255
263
 
256
264
  (`npm run size` measures these.)
257
265
 
@@ -261,12 +269,12 @@ Each area is also a subpath export, for importing one area without the rest:
261
269
  (`lmer` and lmerTest's tests; this area is only available this way, not from the main entry point).
262
270
 
263
271
  Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
264
- function except those of `/mixed`, 202 KB gzipped) from jsDelivr, which serves each npm release:
272
+ function except those of `/mixed`, 241 KB gzipped) from jsDelivr, which serves each npm release:
265
273
 
266
274
  ```html
267
275
  <script type="module">
268
- import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.15.3/dist/rstats.js";
269
- console.log(pnorm(1.96)); // 0.9750021048517795
276
+ import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.16.0/dist/rstats.js";
277
+ console.log(pnorm(1.96)); // ≈ 0.9750021049
270
278
  </script>
271
279
  ```
272
280
 
@@ -281,7 +289,7 @@ A page that needs only some areas can load the per-area bundles instead: `dist/d
281
289
  `dist/tests.js`, `dist/linalg.js`, `dist/descriptive.js`, `dist/numerics.js`, `dist/special.js` and
282
290
  `dist/mixed.js` export the same functions as the subpaths above, and share their common code through
283
291
  `dist/chunks/`, so loading two areas does not load that code twice. With its chunks, one area
284
- transfers 30 KB (`special`) to 159 KB (`tests`) gzipped.
292
+ transfers 37 KB (`numerics`) to 200 KB (`tests`) gzipped.
285
293
 
286
294
  Other npm-based CDNs work as well, for example `https://esm.sh/@numero-uno-jpn/rstats`. Release tags also contain
287
295
  the build output (`dist/`), which is not on the main branch, but jsDelivr's GitHub route
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.16.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{B as $,a as z,c as I,e as g,f as x,h as U,j as R,q as C,u as O,v as j,y as S}from"./chunk-N3SIFCZX.js";import{a as N,c as q}from"./chunk-W26LRYOJ.js";import{s as w}from"./chunk-GM53LWSR.js";function V(f,r={}){let o=I(f),h=o;if(o.data.every(Number.isFinite)){let i=U(o.data),n=i===0?void 0:{...o,data:o.data.map(c=>w(c,-i))};n!==void 0&&n.data.every((c,u)=>c===0?o.data[u]===0:Math.abs(c)>=2**-1022)&&(h=n)}let l=h===o?f:g(h);if(r.exact){let i=r.norm===void 0?"2":P(r.norm);if(i==="2"){let c=O(f,{nu:0,nv:0}).d,u=q(c);return u===0?1/0:N(c)/u}let n;try{n=S(l)}catch(c){if(c instanceof Error&&c.message.startsWith("the system is exactly singular"))return 1/0;throw c}return j(l,{type:i})*j(n,{type:i})}let M=r.norm==="I"?"I":"O";if((r.method??"qr")==="direct"){if(r.triangular)return 1/A(h,(r.uplo??"U")==="U",M);let i=r.norm??"O",n=i.toUpperCase();if(n!=="1"&&n!=="O"&&n!=="I")throw new RangeError(`argument type[1]='${i}' must be one of '1','O', or 'I'`);return 1/$(f,{norm:n==="I"?"I":"O"})}let b=h.nrow<h.ncol?g(x(h)):l;return 1/A(I(C(R(b))),!0,M)}function A(f,r,o){return W(o==="I"?x(f):f,r)}function P(f){let r=f.toUpperCase();if(r==="1"||r==="O")return"O";if(r==="E")return"F";if(r==="I"||r==="F"||r==="M"||r==="2")return r;throw new RangeError(`invalid norm "${f}"`)}function W(f,r){let o=Math.min(f.nrow,f.ncol),h=f.nrow,l=(a,t)=>f.data[a+t*h],M=!r,b=0;for(let a=0;a<o;a++){let[t,m]=M?[a,o-a]:[0,a+1],e=0;for(let s=t;s<t+m;s++)e+=Math.abs(l(s,a));b=Math.max(b,e)}let i=1,n=new Float64Array(o),c=a=>{for(let t=0;t<o;t++)n[t]*=a};for(let a=0;a<o;a++){let t=M?o-1-a:a,m=l(t,t);if(n[t]!==0&&(i=n[t]>0?-Math.abs(i):Math.abs(i)),Math.abs(i-n[t])>Math.abs(m)){let k=Math.abs(m)/Math.abs(i-n[t]);c(k),i*=k}let e=i-n[t],s=-i-n[t],d=Math.abs(e),E=Math.abs(s);if(m!==0?(e/=m,s/=m):(e=1,s=1),a!==o-1){let[k,F]=M?[0,t-1]:[t+1,o-1];for(let p=k;p<=F;p++)E+=Math.abs(n[p]+s*l(t,p)),n[p]+=e*l(t,p),d+=Math.abs(n[p]);if(d<E){let p=s-e;e=s;for(let v=k;v<=F;v++)n[v]+=p*l(t,v)}}n[t]=e}c(1/L(n));let u=1;for(let a=0;a<o;a++){let t=M?a:o-1-a,m=l(t,t);if(Math.abs(n[t])>Math.abs(m)){let e=Math.abs(m)/Math.abs(n[t]);c(e),u*=e}if(m!==0?n[t]/=m:n[t]=1,a<o-1){let e=-n[t];if(M)for(let s=t+1;s<o;s++)n[s]+=e*l(s,t);else for(let s=0;s<t;s++)n[s]+=e*l(s,t)}}let y=1/L(n);return c(y),u*=y,b!==0?u/b:0}function L(f){let r=0;for(let o of f)r+=Math.abs(o);return r}function X(f,r={}){let o=r.tol??Math.sqrt(Number.EPSILON),h=I(f),{d:l,u:M,v:b,s:i}=O(f),n=h.nrow,c=h.ncol,u=z(c,n),y=Math.max(o*(l[0]??0),0),a=[];for(let t=0;t<l.length;t++){if(!(l[t]>y))continue;let m=1/l[t];if(!Number.isFinite(m)){a.push([t,1/w(l[t],600)]);continue}for(let e=0;e<n;e++){let s=M[e][t]*m;for(let d=0;d<c;d++)u.data[d+e*c]+=b[d][t]*s}}i!==0&&(u.data=u.data.map(t=>w(t,-i)));for(let[t,m]of a)for(let e=0;e<n;e++){let s=M[e][t]*m;for(let d=0;d<c;d++)u.data[d+e*c]+=w(b[d][t]*s,600-i)}return g(u)}export{V as a,X as b};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.16.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ var K=2220446049250313e-31,i0=22250738585072014e-324,D=17976931348623157e292,g0=[.06667134430868814,.1494513491505806,.21908636251598204,.26926671930999635,.29552422471475287],h0=[.9956571630258081,.9739065285171717,.9301574913557082,.8650633666889845,.7808177265864169,.6794095682990244,.5627571346686047,.4333953941292472,.2943928627014602,.14887433898163122,0],X=[.011694638867371874,.032558162307964725,.054755896574351995,.07503967481091996,.0931254545836976,.10938715880229764,.12349197626206584,.13470921731147334,.14277593857706009,.14773910490133849,.1494455540029169];function u0(n,o,u,s,t){let c=Math.abs((n-o)*u);return t!==0&&c!==0&&(c=t*Math.min(1,Math.pow(200*c/t,1.5))),s>i0/(50*K)&&(c=Math.max(K*50*s,c)),c}function v0(n,o,u){let s=.5*(o+u),t=.5*(u-o),c=Math.abs(t),p=new Array(10),M=new Array(10),w=n(s),h=0,r=X[10]*w,l=Math.abs(r);for(let b=0;b<5;b++){let a=2*b+1,k=t*h0[a],e=n(s-k),f=n(s+k);p[a]=e,M[a]=f;let g=e+f;h+=g0[b]*g,r+=X[a]*g,l+=X[a]*(Math.abs(e)+Math.abs(f))}for(let b=0;b<5;b++){let a=2*b,k=t*h0[a],e=n(s-k),f=n(s+k);p[a]=e,M[a]=f;let g=e+f;r+=X[a]*g,l+=X[a]*(Math.abs(e)+Math.abs(f))}let A=r*.5,i=X[10]*Math.abs(w-A);for(let b=0;b<10;b++)i+=X[b]*(Math.abs(p[b]-A)+Math.abs(M[b]-A));return l*=c,i*=c,{result:r*t,abserr:u0(r,h,t,l,i),resabs:l,resasc:i}}var M0=[0,.1294849661688697,0,.27970539148927664,0,.3818300505051189,0,.4179591836734694],x0=[.9914553711208126,.9491079123427585,.8648644233597691,.7415311855993945,.5860872354676911,.4058451513773972,.20778495500789848,0],B=[.022935322010529224,.06309209262997856,.10479001032225019,.14065325971552592,.1690047266392679,.19035057806478542,.20443294007529889,.20948214108472782];function y0(n,o,u,s,t){let c=u>1?1:u,p=.5*(s+t),M=.5*(t-s),w=new Array(7),h=new Array(7),r=e=>{let f=o+c*(1-e)/e,g=n(f);return u===2&&(g+=n(-f)),g},l=r(p)/p/p,A=l*M0[7],i=l*B[7],b=Math.abs(i);for(let e=0;e<7;e++){let f=M*x0[e],g=p-f,q=p+f,G=r(g),y=r(q);G=G/g/g,y=y/q/q,w[e]=G,h[e]=y;let F=G+y;A+=M0[e]*F,i+=B[e]*F,b+=B[e]*(Math.abs(G)+Math.abs(y))}let a=i*.5,k=B[7]*Math.abs(l-a);for(let e=0;e<7;e++)k+=B[e]*(Math.abs(w[e]-a)+Math.abs(h[e]-a));return b*=M,k*=M,{result:i*M,abserr:u0(i,A,M,b,k),resabs:b,resasc:k}}function j0(n){let o=n.epstab,u=n.n;n.nres+=1;let s=D,t=o[n.n];if(n.n<2)return s=Math.max(s,5*K*Math.abs(t)),[t,s];let c=49;o[n.n+2]=o[n.n];let p=Math.trunc(n.n/2);o[n.n]=D;let M=n.n;for(let r=0;r<p;r++){let l=M-1,A=M-2,i=o[M+2],b=o[A],a=o[l],k=i,e=Math.abs(a),f=k-a,g=Math.abs(f),q=Math.max(Math.abs(k),e)*K,G=a-b,y=Math.abs(G),F=Math.max(e,Math.abs(b))*K;if(!(g>q||y>F))return t=i,s=g+y,s=Math.max(s,5*K*Math.abs(t)),[t,s];let W=o[M];o[M]=a;let _=a-W,m=Math.abs(_),x=Math.max(e,Math.abs(W))*K;if(m<=x||g<=q||y<=F){n.n=r+r;break}let j=1/_+1/f-1/G;if(!(Math.abs(j*a)>1e-4)){n.n=r+r;break}i=a+1/j,o[M]=i,M-=2;let C=g+Math.abs(i-k)+y;C>s||(s=C,t=i)}n.n===c&&(n.n=2*Math.trunc(c/2));let w=u%2;for(let r=0;r<=p;r++)o[2*r+w]=o[2*r+2+w];if(n.n!==u){let r=u-n.n;for(let l=0;l<=n.n;l++)o[l]=o[r],r++}let h=n.res3la;return n.nres<4?(h[n.nres-1]=t,s=D):(s=Math.abs(t-h[2])+Math.abs(t-h[1])+Math.abs(t-h[0]),h[0]=h[1],h[1]=h[2],h[2]=t),s=Math.max(s,5*K*Math.abs(t)),[t,s]}function K0(n,o,u,s,t,c){if(o<=2){t[0]=0,t[1]=1;let b=t[c];return[b,s[b],c]}let p=s[u];for(;c>0&&p>s[t[c-1]];)t[c]=t[c-1],c-=1;let M=o>Math.trunc(n/2)+2?n-o+2:o-1,w=s[o-1],h=M-1,r=c+1,l=r,A=!1;if(r<=h)for(l=r;l<=h;l++){if(p>=s[t[l]]){A=!0;break}t[l-1]=t[l]}if(!A)t[h]=u,t[M]=o-1;else{t[l-1]=u;let b=h;for(let a=l;a<=h&&!(w<s[t[b]]);a++)t[b+1]=t[b],b--;w<s[t[b]]?t[b+1]=o-1:t[l]=o-1}let i=t[c];return[i,s[i],c]}function k0(n,o,u,s,t,c,p,M){let w=Math.min(c+1,128),h=new Float64Array(w),r=new Float64Array(w),l=new Float64Array(w),A=new Float64Array(w),i=new Int32Array(w),b=d=>{w=Math.min(c+1,Math.max(d,2*w));let L=P=>{let S=new Float64Array(w);return S.set(P),S};h=L(h),r=L(r),l=L(l),A=L(A);let E=new Int32Array(w);E.set(i),i=E},a=0,k=0,e=0,f=0;if(h[0]=o,r[0]=u,s<=0&&t<Math.max(50*K,5e-29))return{result:0,abserr:0,neval:0,ier:6,last:0};let g=n(o,u);e=g.result,f=g.abserr;let q=g.resabs,G=g.resasc,y=Math.abs(e),F=Math.max(s,t*y);if(k=1,l[0]=e,A[0]=f,i[0]=0,f<=100*K*q&&f>F&&(a=2),c===1&&(a=1),a!==0||f<=F&&f!==G||f===0)return{result:e,abserr:f,neval:M(k),ier:a,last:k};let W={epstab:new Float64Array(52),res3la:new Float64Array(3),n:1,nres:0};W.epstab[0]=e;let _=f,m=0,x=e,j=f;f=D;let O=0,C=0,J=!1,s0=!1,Q=0,a0=0,V=0,n0=0,N=0,H=0,R=0,r0=0,w0=y>=(1-50*K)*q?1:-1,o0=!1,v=1;for(v=1;v<c;v++){k=v+1,w<v+2&&b(v+2);let d=h[m],L=.5*(h[m]+r[m]),E=L,P=r[m],S=_,Y=n(d,L),Z=n(E,P),$=Y.result,U=Y.abserr,m0=Y.resasc,t0=Z.result,z=Z.abserr,p0=Z.resasc,e0=$+t0,T=U+z;if(j=j+T-_,x=x+e0-l[m],m0!==U&&p0!==z&&(Math.abs(l[m]-e0)>1e-5*Math.abs(e0)||T<.99*_||(J?V++:a0++),v>9&&T>_&&n0++),l[m]=$,l[v]=t0,F=Math.max(s,t*Math.abs(x)),(a0+V>=10||n0>=20)&&(a=2),V>=5&&(Q=3),k===c&&(a=1),Math.max(Math.abs(d),Math.abs(P))<=(1+100*K)*(Math.abs(E)+1e3*i0)&&(a=4),z>U?(h[m]=E,h[v]=d,r[v]=L,l[m]=t0,l[v]=$,A[m]=z,A[v]=U):(h[v]=E,r[m]=L,r[v]=P,A[m]=U,A[v]=z),[m,_,O]=K0(c,k,m,A,i,O),j<=F){o0=!0;break}if(a!==0)break;if(v===1){N=p,H=j,R=F,W.epstab[1]=x;continue}if(s0)continue;if(H-=S,Math.abs(L-d)>N&&(H+=T),!J){if(Math.abs(r[m]-h[m])>N)continue;J=!0,O=1}if(!(Q===3||H<=R)){let A0=k>2+Math.trunc(c/2)?c+3-k:k,l0=!1;for(let b0=O;b0<A0;b0++){if(m=i[O],_=A[m],Math.abs(r[m]-h[m])>N){l0=!0;break}O++}if(l0)continue}W.n+=1,W.epstab[W.n]=x;let[c0,f0]=j0(W);if(C+=1,C>5&&f<.001*j&&(a=5),f0<f&&(C=0,f=f0,e=c0,r0=H,R=Math.max(s,t*Math.abs(c0)),f<=R)||(W.n===0&&(s0=!0),a===5))break;m=i[0],_=A[m],O=0,J=!1,N*=.5,H=j}let I;if(o0||f===D?I=115:a+Q===0?I=110:(Q===3&&(f+=r0),a===0&&(a=3),e!==0&&x!==0?I=105:f>j?I=115:x===0?I=130:I=110),I===105&&(I=f/Math.abs(e)>j/Math.abs(x)?115:110),I===110)w0===-1&&Math.max(Math.abs(e),Math.abs(x))<=q*.01||(.01>e/x||e/x>100||j>Math.abs(x))&&(a=6);else if(I===115){e=0;for(let d=0;d<=v;d++)e+=l[d];f=j}return a>2&&(a-=1),{result:e,abserr:f,neval:M(k),ier:a,last:k}}function F0(n,o,u,s,t,c){return k0((p,M)=>v0(n,p,M),o,u,s,t,c,Math.abs(u-o)*.375,p=>42*p-21)}function q0(n,o,u,s,t,c){let p=u===2?0:o;return k0((M,w)=>y0(n,p,u,M,w),0,1,s,t,c,.375,M=>(30*M-15)*(u===2?2:1))}export{F0 as a,q0 as b};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.16.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{a as h,t as s,u as p}from"./chunk-SC6CV4Z3.js";function L(t){return Math.abs(t-M(t))>1e-9*Math.max(1,Math.abs(t))}function G(t){let e=M(t);return Math.abs(t-e)<=Math.min(1e-7,1e-9*Math.max(1,Math.abs(t)))?e:Math.floor(t)}function M(t){if(!Number.isFinite(t))return t;let e=Math.round(t);return e-t===.5&&e%2!==0?e-1:e}var y=[.08333333333333333,-.021092796092796094,.007575757575757576,-.004166666666666667,.003968253968253968,-.008333333333333333,.08333333333333333],d=.9955816268920898,w=1569415565/1073741824,O=381566830/1073741824/1073741824,E=9016312093258695e-35,A=[-.002071332116774595,-.04525132144873906,-.28919126444774784,-.6503185377089651,-.3255503118680449,.25479851061131553],S=[-5578984132167551e-22,.0021284987017821146,.054151797245674226,.43593529692665967,1.4606242909763516,2.076711702373047,1];function _(t){let e=t-w;e-=O,e-=E;let r=h(t-1,A)/h(t-1,S);return e*d+e*r}function v(t){let e=0;if(t<1e17){let r=1/(t*t);e=r*h(r,y)}return Math.log(t)-.5/t-e}function k(t){let e=0;if(Number.isNaN(t)||t===1/0)return t;if(t===-1/0)return NaN;if(t===0)return NaN;if(t<0){let r=t-Math.trunc(t);if(r===0)return NaN;e=-Math.PI/Math.tan(Math.PI*r),t=1-t}if(t<=10&&t===Math.floor(t)){let r=t;for(let o=1;o<r;o++)e+=1/o;return e-p}if(t<1)e-=1/t,t+=1;else if(t<10)for(;t>2;)t-=1,e+=1/t;return t>=1&&t<=2?e+_(t):e+v(t)}var N=-.5040830082644554,R=7289763902976895e-32,b;function T(t){b??=Array.from({length:100},(n,a)=>C(a+2,N));let e=R,r=-1,o=t-N;for(let n=1;n<100;n++){r*=-o;let a=r*b[n-1];if(e+=a,Math.abs(a)<Number.EPSILON*Math.abs(e))break}return e}var g=[12,-720,30240,-1209600,47900160,-18924375803183792e-7,74724249600,-2950130727918164e-3,11646782814350067e-2,-4597978722407473,0x284e46fd8153bc0,-7166165256175667e3];function z(t,e){let r=1,o=e,n=1,a=0;for(;e<=1e8&&(a<9||o<=9||o<t);)if(a+=1,o+=1,n=Math.exp(-t*Math.log1p(a/e)),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let u=1,i=0;for(let c=0;c<12;c++){u*=t+i,n/=f;let l=u*n/g[c];if(r+=l,Math.abs(l/r)<s)break;i+=1,u*=t+i,n/=f,i+=1}return r}function C(t,e){let r=Math.pow(e,-t),o=e,n=0,a=0;for(;a<9||o<=9||o<t;)if(a+=1,o+=1,n=Math.pow(o,-t),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let u=1,i=0;for(let c=0;c<12;c++){u*=t+i,n/=f;let l=u*n/g[c];if(r+=l,Math.abs(l/r)<s)break;i+=1,u*=t+i,n/=f,i+=1}return r}function I(t,e){if(e===1/0)return t%2===0?-0:0;let r=1;for(let n=1;n<=t;n++)r*=n/e;let o=r*(z(t+1,e)/e);return t%2===0?-o:o}var m=[];function Z(t){if(m[t]!==void 0)return m[t];let e=[0,1];for(let n=0;n<t;n++){let a=e.slice(1).map((u,i)=>u*(i+1)),f=new Array(a.length+2).fill(0);a.forEach((u,i)=>{f[i]=f[i]-u,f[i+2]=f[i+2]-u}),e=f}let r=(t+1)%2,o=[];for(let n=r;n<e.length;n+=2)o.push(e[n]);return m[t]=o,o}function j(t,e){let r=Z(t),o=e*e,n=r[r.length-1];for(let a=r.length-2;a>=0;a--)n=n*o+r[a];return(t+1)%2===1?n*e:n}function D(t){let e=t-Math.round(t);return Math.sin(Math.PI*(.5-Math.abs(e)))/Math.sin(Math.PI*e)}function P(t,e,r){if(Number.isNaN(e))return NaN;if(e===-1/0)return r&&t%2===1?1/0:NaN;if(e<=0&&e===Math.floor(e))return t%2===1?1/0:NaN;if(e>0)return I(t,e);let o=I(t,1-e);return(t%2===0?o:-o)-Math.pow(Math.PI,t+1)*j(t,D(e))}function H(t){return Math.abs(t-N)<.3?T(t):k(t)}function Y(t,e){return P(1,t,e?.rCompatible??!0)}function B(t,e=0,r){let o=M(e);return Number.isNaN(o)||o<0||o>100?NaN:o===0?H(t):P(o,t,r?.rCompatible??!0)}export{L as a,G as b,M as c,H as d,Y as e,B as f};