@numero-uno-jpn/rstats 0.15.3 → 0.17.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 (322) hide show
  1. package/CHANGELOG.md +294 -0
  2. package/README.ja.md +68 -35
  3. package/README.md +65 -30
  4. package/dist/chunks/chunk-2C33MXSW.js +3 -0
  5. package/dist/chunks/chunk-34S5SQY6.js +2 -0
  6. package/dist/chunks/chunk-4WE3OO62.js +2 -0
  7. package/dist/chunks/chunk-5AYHCITP.js +2 -0
  8. package/dist/chunks/chunk-6JJQL6HL.js +2 -0
  9. package/dist/chunks/chunk-C7V2FH6L.js +3 -0
  10. package/dist/chunks/chunk-CZI7KUO3.js +2 -0
  11. package/dist/chunks/chunk-DXI5N2ET.js +2 -0
  12. package/dist/chunks/chunk-FY3FVOBM.js +2 -0
  13. package/dist/chunks/chunk-H3WVPZDL.js +2 -0
  14. package/dist/chunks/chunk-LHUIJQHY.js +2 -0
  15. package/dist/chunks/chunk-LV3W2F7N.js +2 -0
  16. package/dist/chunks/chunk-M4ITG7YR.js +2 -0
  17. package/dist/chunks/chunk-NSYZTS26.js +2 -0
  18. package/dist/chunks/chunk-ONY5CISH.js +2 -0
  19. package/dist/chunks/chunk-RFE7MVP7.js +2 -0
  20. package/dist/chunks/chunk-SE7V2KLO.js +2 -0
  21. package/dist/chunks/chunk-THIGHOKK.js +2 -0
  22. package/dist/chunks/chunk-TNMJPQPV.js +2 -0
  23. package/dist/chunks/chunk-WM7VFXTV.js +2 -0
  24. package/dist/chunks/chunk-WMDYDTVQ.js +2 -0
  25. package/dist/chunks/chunk-XLSFJTTK.js +2 -0
  26. package/dist/chunks/chunk-Z37NELOS.js +2 -0
  27. package/dist/chunks/chunk-ZFQWB222.js +2 -0
  28. package/dist/data/grouping.js +26 -7
  29. package/dist/descriptive/basic.js +110 -8
  30. package/dist/descriptive/cov.js +23 -4
  31. package/dist/descriptive/dataFrames.d.ts +4 -2
  32. package/dist/descriptive/dataFrames.js +69 -23
  33. package/dist/descriptive/factanal.d.ts +2 -0
  34. package/dist/descriptive/factanal.js +26 -9
  35. package/dist/descriptive/hist.d.ts +8 -5
  36. package/dist/descriptive/hist.js +77 -31
  37. package/dist/descriptive/missing.js +3 -1
  38. package/dist/descriptive/moments.js +86 -19
  39. package/dist/descriptive/omega.d.ts +1 -1
  40. package/dist/descriptive/omega.js +74 -10
  41. package/dist/descriptive/pivot.d.ts +25 -10
  42. package/dist/descriptive/pivot.js +182 -42
  43. package/dist/descriptive/quantile.js +10 -1
  44. package/dist/descriptive/rank.js +8 -1
  45. package/dist/descriptive/table.d.ts +23 -3
  46. package/dist/descriptive/table.js +36 -21
  47. package/dist/descriptive.js +2 -2
  48. package/dist/distributions/arcsine.js +27 -2
  49. package/dist/distributions/beta.js +33 -4
  50. package/dist/distributions/binomial.js +46 -14
  51. package/dist/distributions/bvnorm.js +11 -2
  52. package/dist/distributions/cauchy.js +21 -4
  53. package/dist/distributions/chisq.js +16 -3
  54. package/dist/distributions/exponential.js +14 -0
  55. package/dist/distributions/f.js +41 -17
  56. package/dist/distributions/gamma.js +35 -3
  57. package/dist/distributions/geometric.js +58 -13
  58. package/dist/distributions/hypergeometric.d.ts +5 -1
  59. package/dist/distributions/hypergeometric.js +101 -6
  60. package/dist/distributions/invgamma.js +10 -1
  61. package/dist/distributions/kumaraswamy.js +9 -0
  62. package/dist/distributions/laplace.js +36 -6
  63. package/dist/distributions/logistic.js +13 -1
  64. package/dist/distributions/lognormal.js +16 -2
  65. package/dist/distributions/multinomial.js +58 -11
  66. package/dist/distributions/nbeta.js +62 -11
  67. package/dist/distributions/nchisq.js +30 -6
  68. package/dist/distributions/negbinomial.js +102 -17
  69. package/dist/distributions/normal.js +17 -4
  70. package/dist/distributions/nt.js +392 -17
  71. package/dist/distributions/pareto.js +12 -1
  72. package/dist/distributions/poisson.js +37 -3
  73. package/dist/distributions/signrank.js +16 -4
  74. package/dist/distributions/summary.d.ts +2 -1
  75. package/dist/distributions/summary.js +481 -61
  76. package/dist/distributions/t.js +9 -0
  77. package/dist/distributions/triangular.js +19 -5
  78. package/dist/distributions/tukey.js +11 -2
  79. package/dist/distributions/uniform.js +8 -0
  80. package/dist/distributions/weibull.js +18 -0
  81. package/dist/distributions/wilcox.d.ts +9 -3
  82. package/dist/distributions/wilcox.js +164 -26
  83. package/dist/distributions.js +2 -2
  84. package/dist/entries/descriptive.d.ts +3 -1
  85. package/dist/entries/descriptive.js +1 -1
  86. package/dist/entries/distributions.d.ts +1 -0
  87. package/dist/entries/distributions.js +2 -0
  88. package/dist/entries/linalg.d.ts +3 -1
  89. package/dist/entries/mixed.d.ts +3 -0
  90. package/dist/entries/mixed.js +2 -0
  91. package/dist/entries/numerics.d.ts +2 -1
  92. package/dist/entries/tests.d.ts +8 -5
  93. package/dist/entries/tests.js +3 -1
  94. package/dist/htest/agreement.d.ts +16 -2
  95. package/dist/htest/agreement.js +122 -21
  96. package/dist/htest/ansariTest.d.ts +8 -2
  97. package/dist/htest/ansariTest.js +116 -18
  98. package/dist/htest/aov.d.ts +29 -23
  99. package/dist/htest/aov.js +90 -47
  100. package/dist/htest/binomTest.d.ts +5 -0
  101. package/dist/htest/binomTest.js +47 -17
  102. package/dist/htest/brunnerMunzelTest.d.ts +4 -3
  103. package/dist/htest/brunnerMunzelTest.js +12 -5
  104. package/dist/htest/chisqTest.d.ts +5 -2
  105. package/dist/htest/chisqTest.js +151 -46
  106. package/dist/htest/cor.d.ts +9 -2
  107. package/dist/htest/cor.js +57 -26
  108. package/dist/htest/core/ansari.d.ts +9 -0
  109. package/dist/htest/core/ansari.js +21 -1
  110. package/dist/htest/core/kolmogorov.d.ts +25 -0
  111. package/dist/htest/core/kolmogorov.js +123 -0
  112. package/dist/htest/core/mantelhaen.js +6 -4
  113. package/dist/htest/core/shapiro.d.ts +1 -1
  114. package/dist/htest/core/shapiro.js +5 -1
  115. package/dist/htest/core/simulate.d.ts +6 -0
  116. package/dist/htest/core/simulate.js +20 -0
  117. package/dist/htest/dunnett.js +14 -5
  118. package/dist/htest/effectSize.d.ts +5 -0
  119. package/dist/htest/effectSize.js +117 -35
  120. package/dist/htest/fisherTest.d.ts +4 -3
  121. package/dist/htest/fisherTest.js +88 -24
  122. package/dist/htest/groups.d.ts +7 -0
  123. package/dist/htest/groups.js +21 -4
  124. package/dist/htest/ksTest.d.ts +7 -1
  125. package/dist/htest/ksTest.js +36 -6
  126. package/dist/htest/leveneTest.d.ts +2 -0
  127. package/dist/htest/leveneTest.js +28 -6
  128. package/dist/htest/mantelhaenTest.js +132 -25
  129. package/dist/htest/mcnemarTest.js +40 -11
  130. package/dist/htest/multipleComparisons.d.ts +24 -26
  131. package/dist/htest/multipleComparisons.js +70 -64
  132. package/dist/htest/normalityTests.js +54 -14
  133. package/dist/htest/onewayTest.js +106 -5
  134. package/dist/htest/pAdjust.d.ts +3 -2
  135. package/dist/htest/pAdjust.js +42 -6
  136. package/dist/htest/pairwise.d.ts +3 -1
  137. package/dist/htest/pairwise.js +46 -21
  138. package/dist/htest/poissonTest.d.ts +1 -1
  139. package/dist/htest/poissonTest.js +117 -59
  140. package/dist/htest/polycor.js +47 -17
  141. package/dist/htest/power.d.ts +15 -1
  142. package/dist/htest/power.js +128 -10
  143. package/dist/htest/propTest.d.ts +3 -0
  144. package/dist/htest/propTest.js +44 -6
  145. package/dist/htest/pwr.d.ts +38 -1
  146. package/dist/htest/pwr.js +159 -39
  147. package/dist/htest/rankTests.js +36 -6
  148. package/dist/htest/tTest.d.ts +2 -0
  149. package/dist/htest/tTest.js +53 -21
  150. package/dist/htest/testFormula.js +11 -11
  151. package/dist/htest/trendTests.d.ts +28 -4
  152. package/dist/htest/trendTests.js +124 -35
  153. package/dist/htest/types.d.ts +7 -0
  154. package/dist/htest/types.js +7 -0
  155. package/dist/htest/varTest.js +52 -14
  156. package/dist/htest/wilcoxTest.js +164 -29
  157. package/dist/integrate/quadpack.js +27 -5
  158. package/dist/internal/checkOptions.d.ts +11 -0
  159. package/dist/internal/checkOptions.js +31 -0
  160. package/dist/internal/covmat.d.ts +5 -0
  161. package/dist/internal/covmat.js +20 -0
  162. package/dist/internal/ddexp.d.ts +15 -1
  163. package/dist/internal/ddexp.js +59 -6
  164. package/dist/internal/discrete.d.ts +14 -0
  165. package/dist/internal/discrete.js +78 -5
  166. package/dist/internal/extremes.d.ts +9 -0
  167. package/dist/internal/extremes.js +24 -0
  168. package/dist/internal/fround.js +13 -4
  169. package/dist/internal/integer.d.ts +9 -0
  170. package/dist/internal/integer.js +12 -0
  171. package/dist/internal/invert.js +15 -2
  172. package/dist/internal/optionalArgs.d.ts +12 -0
  173. package/dist/internal/optionalArgs.js +46 -0
  174. package/dist/internal/scaledInverse.d.ts +10 -0
  175. package/dist/internal/scaledInverse.js +22 -0
  176. package/dist/internal/seq.js +15 -2
  177. package/dist/internal/summary.d.ts +90 -0
  178. package/dist/internal/summary.js +458 -39
  179. package/dist/internal/uniroot.d.ts +7 -0
  180. package/dist/internal/uniroot.js +28 -3
  181. package/dist/internal/warnings.d.ts +66 -0
  182. package/dist/internal/warnings.js +122 -0
  183. package/dist/linalg/basic.d.ts +3 -1
  184. package/dist/linalg/basic.js +58 -7
  185. package/dist/linalg/chol.js +10 -1
  186. package/dist/linalg/dot.d.ts +29 -0
  187. package/dist/linalg/dot.js +132 -0
  188. package/dist/linalg/eigen.d.ts +6 -1
  189. package/dist/linalg/eigen.js +75 -14
  190. package/dist/linalg/expm.d.ts +3 -2
  191. package/dist/linalg/expm.js +113 -15
  192. package/dist/linalg/kappa.js +64 -10
  193. package/dist/linalg/lu.d.ts +2 -1
  194. package/dist/linalg/lu.js +40 -5
  195. package/dist/linalg/matrix.d.ts +14 -0
  196. package/dist/linalg/matrix.js +24 -0
  197. package/dist/linalg/norm.js +4 -0
  198. package/dist/linalg/ops.d.ts +27 -2
  199. package/dist/linalg/ops.js +74 -26
  200. package/dist/linalg/qr.d.ts +2 -1
  201. package/dist/linalg/qr.js +105 -23
  202. package/dist/linalg/schur.js +11 -3
  203. package/dist/linalg/solve.d.ts +6 -1
  204. package/dist/linalg/solve.js +156 -26
  205. package/dist/linalg/svd.d.ts +9 -2
  206. package/dist/linalg/svd.js +33 -11
  207. package/dist/linalg.js +2 -2
  208. package/dist/mixed.js +4 -4
  209. package/dist/models/anovaSequential.d.ts +32 -2
  210. package/dist/models/anovaSequential.js +170 -28
  211. package/dist/models/aovEz.js +154 -39
  212. package/dist/models/aovStrata.js +68 -24
  213. package/dist/models/carAnova.d.ts +1 -1
  214. package/dist/models/carAnova.js +78 -33
  215. package/dist/models/coxph.d.ts +6 -0
  216. package/dist/models/coxph.js +166 -69
  217. package/dist/models/estimable.d.ts +15 -0
  218. package/dist/models/estimable.js +68 -0
  219. package/dist/models/formula.d.ts +1 -1
  220. package/dist/models/formula.js +26 -8
  221. package/dist/models/glm.d.ts +57 -7
  222. package/dist/models/glm.js +427 -74
  223. package/dist/models/glmAnova.js +90 -14
  224. package/dist/models/glmConfint.d.ts +1 -1
  225. package/dist/models/glmConfint.js +121 -29
  226. package/dist/models/glmFamily.d.ts +11 -6
  227. package/dist/models/glmFamily.js +247 -62
  228. package/dist/models/lm.d.ts +12 -1
  229. package/dist/models/lm.js +246 -37
  230. package/dist/models/lmer.d.ts +31 -7
  231. package/dist/models/lmer.js +129 -42
  232. package/dist/models/lmerAnova.d.ts +3 -3
  233. package/dist/models/lmerAnova.js +47 -9
  234. package/dist/models/lmerHypotheses.d.ts +6 -2
  235. package/dist/models/lmerHypotheses.js +14 -2
  236. package/dist/models/lmerTest.d.ts +13 -6
  237. package/dist/models/lmerTest.js +82 -29
  238. package/dist/models/mauchly.d.ts +6 -1
  239. package/dist/models/mauchly.js +41 -15
  240. package/dist/models/mixedStructure.js +6 -0
  241. package/dist/models/modelFrame.js +10 -4
  242. package/dist/models/modelMatrix.d.ts +3 -1
  243. package/dist/models/modelMatrix.js +47 -17
  244. package/dist/models/scaledTables.d.ts +8 -0
  245. package/dist/models/scaledTables.js +6 -0
  246. package/dist/models/survival.d.ts +12 -1
  247. package/dist/models/survival.js +75 -28
  248. package/dist/models/tiedTimes.d.ts +2 -0
  249. package/dist/models/tiedTimes.js +34 -0
  250. package/dist/numerics/deriv.d.ts +1 -1
  251. package/dist/numerics/deriv.js +72 -8
  252. package/dist/numerics/integrate.d.ts +9 -1
  253. package/dist/numerics/integrate.js +111 -16
  254. package/dist/numerics/interp.d.ts +40 -9
  255. package/dist/numerics/interp.js +375 -55
  256. package/dist/numerics/ode.js +59 -1
  257. package/dist/numerics.js +2 -2
  258. package/dist/optim/localmin.js +4 -0
  259. package/dist/optim/optim.d.ts +3 -1
  260. package/dist/optim/optim.js +97 -10
  261. package/dist/random/beta.js +58 -4
  262. package/dist/random/binomial.d.ts +14 -3
  263. package/dist/random/binomial.js +59 -24
  264. package/dist/random/continuous.js +50 -5
  265. package/dist/random/extra.js +55 -9
  266. package/dist/random/gamma.d.ts +4 -1
  267. package/dist/random/gamma.js +47 -8
  268. package/dist/random/hyper.js +9 -6
  269. package/dist/random/mt.js +17 -2
  270. package/dist/random/poisson.js +31 -3
  271. package/dist/random/r2dtable.d.ts +8 -1
  272. package/dist/random/r2dtable.js +24 -3
  273. package/dist/random/rank.d.ts +2 -0
  274. package/dist/random/rank.js +44 -4
  275. package/dist/random/rng.js +4 -0
  276. package/dist/random/sample.d.ts +12 -2
  277. package/dist/random/sample.js +63 -20
  278. package/dist/random/streams.js +4 -2
  279. package/dist/rstats.js +17 -14
  280. package/dist/special/besselIK.d.ts +12 -0
  281. package/dist/special/besselIK.js +175 -23
  282. package/dist/special/besselJY.d.ts +11 -1
  283. package/dist/special/besselJY.js +127 -19
  284. package/dist/special/besselSeries.d.ts +27 -0
  285. package/dist/special/besselSeries.js +45 -2
  286. package/dist/special/beta.js +4 -1
  287. package/dist/special/choose.js +24 -8
  288. package/dist/special/dd.js +122 -18
  289. package/dist/special/extra.js +14 -2
  290. package/dist/special/gamma.js +11 -2
  291. package/dist/special/incbet.js +30 -4
  292. package/dist/special/incbetTemme.d.ts +7 -0
  293. package/dist/special/incbetTemme.js +45 -12
  294. package/dist/special/loader.d.ts +1 -1
  295. package/dist/special/loader.js +117 -20
  296. package/dist/special/log1pmx.js +4 -0
  297. package/dist/special/psigamma.js +7 -0
  298. package/dist/special.js +2 -2
  299. package/dist/tests.js +15 -11
  300. package/llms.txt +15 -6
  301. package/package.json +19 -10
  302. package/dist/chunks/chunk-3THFTB36.js +0 -2
  303. package/dist/chunks/chunk-3TSWYE5L.js +0 -2
  304. package/dist/chunks/chunk-3WPU6LGK.js +0 -2
  305. package/dist/chunks/chunk-5ITR67MB.js +0 -2
  306. package/dist/chunks/chunk-5NRFU6F6.js +0 -2
  307. package/dist/chunks/chunk-E2LCSVQV.js +0 -2
  308. package/dist/chunks/chunk-FCNVTIPJ.js +0 -2
  309. package/dist/chunks/chunk-FKAKALOZ.js +0 -2
  310. package/dist/chunks/chunk-HD73UKPT.js +0 -2
  311. package/dist/chunks/chunk-IUULP3LE.js +0 -2
  312. package/dist/chunks/chunk-JQG3YQOC.js +0 -2
  313. package/dist/chunks/chunk-KT66SB7R.js +0 -2
  314. package/dist/chunks/chunk-MAUAOQG3.js +0 -2
  315. package/dist/chunks/chunk-MDYE7QP2.js +0 -2
  316. package/dist/chunks/chunk-NM3Z2UBQ.js +0 -2
  317. package/dist/chunks/chunk-PMJI5QO6.js +0 -3
  318. package/dist/chunks/chunk-UF7KOTHF.js +0 -3
  319. package/dist/chunks/chunk-UOE57JGT.js +0 -2
  320. package/dist/chunks/chunk-USPEBXSR.js +0 -2
  321. package/dist/chunks/chunk-VLUL2HFW.js +0 -3
  322. package/dist/chunks/chunk-ZIX7NYQF.js +0 -2
package/CHANGELOG.md CHANGED
@@ -7,6 +7,300 @@ 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.17.0 - 2026-11-05
11
+
12
+ The API is cleaned up toward 1.0.0, which follows the mixed models of `glmer`: argument errors are a `TypeError` or
13
+ a `RangeError`, a key of an options object that the function does not know is an error, and the results of the tests
14
+ have a required `warnings` with R's warnings, which `setWarningHandler` can also pass to a function.
15
+
16
+ ### Breaking
17
+
18
+ - Argument errors that were a plain `Error` are a `TypeError` (wrong type or shape) or a `RangeError` (value out of
19
+ range), as the other functions (the messages are unchanged):
20
+ - `pivotLonger` and `pivotWider`: a `colsVary` or `namesVary` that is not a string, a `namesSep` with one
21
+ `namesTo`, several `namesTo` without `namesSep` or `namesPattern`, a `namesPattern` with the wrong number of
22
+ groups, and a `.value` transform that gives no string are TypeErrors; an unknown `colsVary` or `namesVary`, a
23
+ column that does not exist, an empty `cols`, `namesFrom` or `valuesFrom`, `.value` twice in `namesTo`, a value
24
+ column given twice for one key, `idCols` that overlap `namesFrom` or `valuesFrom`, and values not uniquely
25
+ identified without `valuesFn` are RangeErrors.
26
+ - `merge`: `byX` and `byY` of different lengths are a TypeError, a key that is not a column a RangeError.
27
+ - The formula forms of the tests (`tTest`, `wilcoxTest`, `varTest`, `ansariTest`, `moodTest`, `ksTest`,
28
+ `kruskalTest`, `flignerTest`, `bartlettTest`, `onewayTest`, `friedmanTest`, `quadeTest`, `corTest`): a formula of
29
+ the wrong form for the test is a TypeError. A grouping factor without exactly 2 levels and a block design that is
30
+ not unreplicated and complete stay an `Error` (data whose result is not defined).
31
+ - Data frames and columns: a duplicate column name (`cbind`, `merge` with suffixes that collide, `aggregate`) and a
32
+ `select` of `subset` that is not a column are RangeErrors, and data frames with different names in `rbind` a
33
+ TypeError; a column named in a formula or option that does not exist ("object 'x' not found": `aggregate`, the
34
+ model functions such as `lm` and `glm` and their `weights`, the formula forms of the tests, `aovEz`) is a
35
+ RangeError, and so are a factor given in both `between` and `within` of `aovEz`, a factor name repeated in
36
+ `between` or `within` ("duplicated factor names in 'between': A") and an `observed` variable that is not a factor
37
+ ("Observed variable not in data: x"), the same error of `etaSquared`'s `generalized` included.
38
+ - `aov(x, g)` and `aov(samples)` return the fit of the model `y ~ g` (an `LmFormulaResult`, as `aov("y ~ g", data)`)
39
+ instead of the one-way table, as R's `aov` always returns a fit; the table is `aovSummary(aov(x, g))` (rows `g` and
40
+ `Residuals`), and the `AovResult` type is removed. The levels of `g` are the group labels in R's order, or the
41
+ positions of the samples in the list (from 1). F and p agree with the old table to the last bit or within a few ulps
42
+ of rounding (the sums of squares now come from the QR of the fit). Where the residual sum of squares is exactly 0,
43
+ the fit leaves rounding residue as R's does; the table takes it as 0, as the old table: F = Inf and p = 0, and NaN
44
+ when all values are equal (see Changed).
45
+ - `steelTest` is removed. It only reproduced the errors of PMCMRplus 1.9.12's `steelTest`, which fails on every input,
46
+ and never returned a value; Steel's many-to-one rank test is `manyOneUTest` (its normal approximation).
47
+ - A key of an options object that the function does not know is a RangeError, where it was ignored: a misspelt key
48
+ such as `pnorm(q, { lowertail: false })` gave the lower tail without a sign ("unknown option 'lowertail' for pnorm
49
+ (known: mean, sd, lowerTail, logP)"). A key whose value is `undefined` counts. This holds for every exported function
50
+ that takes options, the nested objects with fixed keys included (`optim`'s and `optimHess`' `control`, `glm`'s
51
+ `family` and `link` given as objects, `coxph`'s and `factanal`'s `control`; "unknown option 'control.maxitt' for
52
+ optim", and so for `optimHess`, whose `control` is a position), for the `params` of `distSummary` (the parameters
53
+ of the distribution's d function: `shape`, `rate` and `scale` for `"gamma"`; not `ncp` of `chisq`, `beta`, `t` and
54
+ `f`, which was ignored, giving the summaries of the central distribution) and for the options of the function
55
+ `splinefun` and `splinefunH` return. Objects whose keys are the user's data (data frames, `contrasts`, `levels`) are
56
+ not checked. In `lmer`, `lmerSummary`, `lmerContest` and `lmerAnova` an unknown key was a TypeError with R's
57
+ message ("unused argument (reml)") and is now this RangeError too; an argument of R that they do not support
58
+ (`lmer`'s `weights`, `lmerAnova`'s `ddf`, ...) is still the Error "lmer: argument 'weights' is not supported",
59
+ checked first.
60
+ - `HTest` and the other results of the tests, effect sizes, power and agreement functions, and `factanal`'s, have a
61
+ required `warnings: string[]`: R's warnings, each once, in R's order, an empty array when there are none (not the
62
+ warnings of R's distribution functions about their own precision, nor those about R's argument types; those that
63
+ explain a `NaN` are included). Code that builds such an object itself must add the field. Nothing is printed unless
64
+ a handler is set (`setWarningHandler`, under Added). The functions that had no `warnings` return an empty array,
65
+ except 10 that now give R's warnings where they were silent, and `cohensD` and `hedgesG` give a new one:
66
+ - `wilcoxTest`: "cannot compute exact p-value with ties" or "with zeroes" and the same of the interval, when the
67
+ exact method asked for or chosen by default cannot be used; "requested conf.level not achievable", where the
68
+ interval's confidence level is lowered; "cannot compute confidence interval when all observations are zero or
69
+ tied", where the interval is `NaN`. `pairwiseWilcoxTest` returns those of its comparisons, each once.
70
+ - `ansariTest`: "cannot compute exact p-value with ties" and, with `confInt`, "cannot compute exact confidence
71
+ intervals with ties", where R stops but the normal-approximation interval is returned; "samples differ in
72
+ location: cannot compute confidence set, returning NA", "cannot compute confidence set, returning NA", "cannot
73
+ compute estimate, returning NA" and "cannot compute asymptotic confidence set or estimator", where the interval or
74
+ estimate is `NaN` or left out.
75
+ - `fisherTest`: "'x' has been rounded to integer: Mean relative difference: 0.0625", with the text of R's
76
+ `all.equal` of the counts and the rounded counts.
77
+ - `chisqTest`: "Chi-squared approximation may be incorrect" where an expected count is below 5 and the p-value is
78
+ not simulated, and "cannot compute simulated p-value with zero marginals". `propTest`: "Chi-squared approximation
79
+ may be incorrect"; `pairwisePropTest` returns it once.
80
+ - `ksTest`: "ties should not be present for the one-sample Kolmogorov-Smirnov test", and "p-value will be
81
+ approximate in the presence of ties" for two samples with the asymptotic p-value.
82
+ - `corTest`: "the standard deviation is zero" where x or y is constant, "Cannot compute exact p-value with ties"
83
+ for Kendall and Spearman, and R's "NaNs produced" of Spearman's t approximation for 2 pairs, whose p-value is
84
+ `NaN`.
85
+ - `cohensD` and `hedgesG`: effectsize's "'y' is numeric but has only 2 unique values. ..." where `y` has exactly 2
86
+ distinct values.
87
+ - `cronbachAlpha`: psych's own warnings, "Item = had no variance and was deleted but still is counted in the
88
+ score" for a constant item and "Some items were negatively correlated with the first principal component and
89
+ probably should be reversed. ..." (as psych's `principal`: the eigenvector of the largest eigenvalue of the
90
+ correlations, signed so that its sum is not negative).
91
+
92
+ ### Added
93
+
94
+ - The package can be loaded with `require()` (Node 22.12 and later load ES modules with `require`): each subpath of
95
+ `exports` has a `default` condition besides `import`, and `@numero-uno-jpn/rstats/package.json` is exported.
96
+ - Each subpath exports the types its functions use, so they need no import from another subpath: `Sample` and
97
+ `DataFrame` from `/descriptive` and `/linalg`, `Sample` from `/numerics`, `DataFrame` and `ContrastName` from
98
+ `/mixed`, `MatrixInput` and `QR` from `/tests`.
99
+ - Results whose fields keep the names of R or of a package get aliases with the names the other results use, as
100
+ ordinary fields with the same values (the old names stay): `pValue` for `survdiff`'s `pvalue`; `stdError`, `zValue`
101
+ and `pValue` for `coxph`'s `se`, `z` and `p`; `stdError`, `tValue` and `pValue` for `glhtDunnett`'s `se`, `t` and
102
+ `p`; `zValue`, `pValue` and `pAdjusted` for `dunnTest`'s `Z`, `P` and `PAdjusted`; `pAdjusted` for `TukeyHSD`'s
103
+ `pAdj`; `stdError` for the `stdErr` of `tTest` and `survfit`; `fValue` for `icc`'s `Fvalue`.
104
+ - The optional arguments taken by position as in R are also accepted in an options object (an overload), in place of
105
+ the argument or after it: `glmResiduals(fit, { type })`, `cohenES(test, { size })`, `outer(x, y, { fun })`,
106
+ `tabulate(bin, { nbins })`, `propTrendTest(x, n, { score })` and `s(xq, { deriv })` for the function `s` that
107
+ `splinefun` or `splinefunH` returns (its type is the new `SplineFunction`). `optimHess` keeps `gr` and `control` by
108
+ position only, as R (a positional `control` is itself a plain object). Giving one both by position and in the options is a
109
+ RangeError. New types: `GlmResidualsOptions`, `CohenESOptions`, `OuterFun`, `OuterOptions`, `TabulateOptions`,
110
+ `PropTrendTestOptions`, `SplineFunction` and `SplineFunctionOptions`.
111
+ - `setWarningHandler(handler)` passes R's warnings to a function of the user's choice, as R prints them, such as
112
+ `setWarningHandler((message, source) => console.warn(source + ": " + message))`: each call of a test, model or fit
113
+ (and `pivotLonger` without `onWarning`) passes its warnings once it has its result, each distinct warning once, with
114
+ the name of the function called (also the warnings the tests now give, such as `wilcoxTest`'s "cannot compute exact
115
+ p-value with ties"); a function that calls another, such as `pairwiseWilcoxTest`, passes them once under
116
+ its own name. A fit's warnings are passed once, when it is fitted (`lm`, `glm`, `aov`, `lmer`, ...); a function
117
+ given a fit or a table (`anova`, `aovSummary`, `Anova`, `glmSummary`, `etaSquared`, `lmerSummary`, ...) keeps them
118
+ in its result's `warnings` but passes only those it adds. An error thrown by the handler propagates to the caller
119
+ (as R's `options(warn = 2)`). `setWarningHandler(null)`, the default, passes nothing; the previous handler is
120
+ returned. The handler is kept on `globalThis`, one setting for every copy of the library on a page. Exported from
121
+ the root, `rStats.js/distributions`, `rStats.js/tests` and `rStats.js/mixed`, with the type `WarningHandler`.
122
+
123
+ ### Changed
124
+
125
+ - `aovSummary` and the sequential table of `anova` take a residual sum of squares at the level of rounding (below
126
+ 1e-24 times the weighted sum of squares of the response, as `Anova`'s check of an exact fit) as 0, with the sums of
127
+ squares of the terms at that level: F = Inf and p = 0 for groups without spread (`aov([[1, 1], [2, 2]])` gave F =
128
+ 3.4e64 from the residue of the QR, as R), and F = NaN where all values are equal (F = 0.6 or 1 from the residue).
129
+ The same holds in each stratum of a fit with `Error()` (the sum of squares of the whole response as the scale): F =
130
+ Inf or NaN where the Within stratum of `aov("y ~ g + Error(id)", d)` gave F = 2.9e33 from the residue. The tables
131
+ of other fits are unchanged to the bit.
132
+
133
+ ### Fixed
134
+
135
+ - The result of `svd` no longer has the internal field `s` (the power-of-2 exponent of the singular values), which is
136
+ not part of `SvdResult`.
137
+
138
+ ## 0.16.0 - 2026-11-04
139
+
140
+ Fixes from a numerical review and GitHub issues #8 to #513. Each case is described, with R's value and rStats.js's, in
141
+ [differences from R](docs/differences-from-r.md) and in the review logs (`docs/review-logs/review_fix_log_*.md`).
142
+ Where R itself is wrong, rStats.js now returns the mathematically right value; where R is right, the aim is R's bits.
143
+ The rules behind these changes are listed under "Design rules" in [CONTRIBUTING.md](CONTRIBUTING.md).
144
+
145
+ ### Breaking
146
+
147
+ - More inputs that define no result are errors, also where R returns NaN, NA or a meaningless value (the distribution
148
+ functions keep returning NaN for invalid parameters, as R):
149
+ - Hypothesis tests: a simulation with `B = 0` or a fractional `B` in `chisqTest` and `fisherTest`; `TukeyHSD` and
150
+ `tukeyTest` with 0 or 1 residual degrees of freedom, and `TukeyHSD` with a NaN `confLevel` or one outside [0, 1];
151
+ `pairwiseTTest` (pooled SD) and `onewayTest(varEqual: true)` with a pooled within-group variance of 0, and the
152
+ Welch `onewayTest` with two or more constant groups; `mauchlyTest` with one tested dimension; `propTrendTest` with
153
+ no events or only events, fewer than two distinct scores or an infinite score; an infinite observation in `adTest`,
154
+ `cvmTest`, `lillieTest`, `sfTest` and `pearsonTest`; `flignerTest` with a group whose median is infinite;
155
+ `jonckheereTest` with fewer than 2 nonempty groups; `brunnerMunzelTest` with a sample of fewer than 2 values;
156
+ `cronbachAlpha` with one subject, `kappa2` with fewer than 2 complete pairs, `omega` with fewer than 2 variables;
157
+ `tTest` with a standard error of 0 also when the mean is 0; `powerTTest`, `powerPropTest` and `powerAnovaTest`
158
+ solving for n (or a proportion) where there is no effect.
159
+ - Models: `lm` with an infinite weight; `lmer` with a non-finite response or a non-finite column of a random-effects
160
+ term; `aov` with `Error()` and a non-finite response; `lmerContest` with NaN in `L` or `rhs`; `aovEz` with a factor
161
+ name given twice; `glm` with a two-column binomial response whose total overflows; a formula power beyond the
162
+ integer range (`y ~ (a + b)^1e999` did not return).
163
+ - Numerical methods: `uniroot` with `tol = 0` or an unknown `extendInt`; `optim` and `optimHess` with
164
+ `fnscale = ±Infinity`, a non-finite function value at an evaluated point or a non-finite analytic gradient;
165
+ `grad`, `jacobian` and `hessian` with a step that is not positive and finite, `r` above 512, or (`jacobian`)
166
+ results of differing lengths; `integrate` with `subdivisions` beyond the integer range; `ode` with a non-finite
167
+ time; `approx` with a `rule` other than 1 or 2 or an unknown `method`; `seq` with an infinite `by` pointing away
168
+ from `to`.
169
+ - Linear algebra: `lu` of a matrix with NaN or infinite values; `qr` and `qrSolve` with `tol = Infinity`; `qrX` with
170
+ `ncol` above the dimensions; `rcond` with a `uplo` other than `"U"` or `"L"`; `svd` with a negative or NaN `nu` or
171
+ `nv`.
172
+ - Descriptive statistics and data: `hist` with an infinite or NaN break; `cut` with fewer than 2 breaks; `pretty`
173
+ with invalid `shrinkSml`, `highUBias` or `u5Bias`; `mean` with `trim = NaN`; `tapply`, `split` and `aggregate`
174
+ with 2^31 cells or more; `pivotWider` and `pivotLonger` with tidyr's errors (an id column also selected as names
175
+ or values, an empty `namesFrom` or `valuesFrom`, `colsVary` and `namesVary` other than `"fastest"` or
176
+ `"slowest"`, a `namesPattern` with the wrong number of groups).
177
+ - Computation limits: calls that would allocate more than 2^24 values in one array or run for more than about 10
178
+ seconds throw a RangeError before allocating or computing (exact tests point to `exact: false`). Before, they ran for
179
+ minutes, ran out of memory or did not return.
180
+ - Exact tests: `fisherTest` (2 × 2) and `mantelhaenTest(exact: true)` with a support above 2^24 values (and
181
+ `mantelhaenTest` with a total of 2^53 or more); `ksTest`'s exact one-sample p-value above 2^33 multiply-adds;
182
+ `ansariTest` and `jonckheereTest` above 2^24 values or 2^32 steps; `corTest(method: "kendall")` without ties for
183
+ n above 1290; `pAdjust(method: "hommel")` for n above 65536.
184
+ - Simulations and random numbers: `r2dtable` and the simulated p-values of `chisqTest` and `fisherTest` for tables
185
+ with a total above 2^24; `chisqTest`'s goodness-of-fit simulation above 2^27 draws (`B` times the total);
186
+ `rwilcox` with n above 2^24; `rsignrank` with n of 2^27 or more; weighted `sample` and `sampleInt` with a size of
187
+ 2^31 or more.
188
+ - Distributions and special functions: `dwilcox`, `pwilcox` and `qwilcox` above 2^29 steps; `phyper` above 2^26
189
+ terms and `qhyper` with a standard deviation above 2^21; `besselJ`, `besselY`, `besselI` and `besselK` where the
190
+ series or recurrences would take more than 2^25 to 2^31 steps, or a phase that doubles cannot resolve.
191
+ - Linear algebra: `expm` with the Taylor and Padé methods where order × (n^3 + 64) exceeds 2^31.
192
+ - Values that change in the ordinary range:
193
+ - Welch's degrees of freedom in `tTest`, `cohensD` and `gamesHowellTest`, and `tTest`'s interval ends and Welch
194
+ standard error, take R's (and the packages') forms and now match R's bits (they were 1 to 3 ulp off).
195
+ - `contr.poly` (the polynomial contrasts of `lmer`) with 15 levels or fewer comes from a recurrence that is within
196
+ 5.8e-16 of the exact values; its last bits differ from R's, which were up to 2.8e-13 off.
197
+ - `chisqTest`'s standardized residuals (`stdres`) of a contingency table use exact complements of the margins
198
+ (R's form lost small margins); other tables change in the last bits.
199
+ - `distSummary` of the triangular distribution forms the variance and the skewness from differences without
200
+ cancellation.
201
+ - `Anova` takes a residual sum of squares below 1e-24 times the sum of squares of the response as 0 and returns the
202
+ table (car's behaviour) instead of an error.
203
+ - `pAdjust(method: "hommel")` with n = 2 is Hochberg's method, as R.
204
+ - `ksTest`'s exact two-sided one-sample p-value for D < 1/2 is summed from positive terms where it is below about
205
+ 1e-2 (it had an absolute accuracy of 1e-15 only).
206
+ - `quadeTest` counts only the complete blocks (R counts the dropped ones as well).
207
+ - The Welch `onewayTest` with one constant group returns the limit as its variance tends to 0 (R: NaN).
208
+ - `cor` has NaN on the diagonal where a column's correlation with itself is undefined; group labels that mix
209
+ numbers and strings are strings, as R coerces them; `chisqTest` sorts the levels by code point; the two-sample
210
+ `wilcoxTest` with every value tied has p = 1.
211
+ - The Laplace distribution with `sigma = Infinity` is the limit (as the normal, logistic and Cauchy ones), and
212
+ `df(Infinity, ...)` is 0 (R: NaN); `qbinom` rounds a fractional `size` half to even, as R.
213
+
214
+ - Inputs that define no result are errors (R returns NaN or a meaningless value): `mcnemarTest` on a table without
215
+ discordant pairs, the signed rank `wilcoxTest` with only zero differences, `varTest` with two constant samples,
216
+ `chisqTest`'s simulation with fractional counts, a non-integer `B` or goodness-of-fit counts not summing to an
217
+ integer, `mantelhaenTest(exact: true)` with fractional counts, `dunnettTest`, `tukeyTest` and `glhtDunnett` with a
218
+ pooled within-group variance of 0 (or no residual degrees of freedom), `pAdjust` with `n = Infinity`, `glm` with
219
+ infinite weights ("non-finite weights not allowed"), and `table` with a `useNA` other than `"no"`, `"ifany"` and
220
+ `"always"` (R's match.arg error).
221
+ - `glm` halves an IRLS step that increases the deviance (by `epsilon` relative or more, glm2's rule). R's `glm.fit`
222
+ accepts such steps and can stop at a false convergence: a binomial fit with all weights 1000 returned coefficients
223
+ of 1e15 and a deviance of 144175 (the maximum is 4956), and the glm2 example (binomial, `start = -1.81`) a
224
+ coefficient of 2.25e15 instead of log 3.
225
+ - The links of `glm` are exact beyond R's clamps: logit beyond |η| = 30, log below `exp(η) = eps`, probit, cauchit,
226
+ cloglog and power at the ends (R clamps η or μ to the values at eps and the derivatives to eps), kept within (0, 1)
227
+ by the least double and the largest double below 1; the cloglog link is `log(-log1p(-mu))`. Fits that reach these
228
+ ends (separated data in particular) change. `glm` also warns when the linear predictor still moves at convergence
229
+ ("the data may be separated").
230
+ - `optim(method = "CG")` tries the minimum of the parabola through the start of the line search and the accepted point;
231
+ R's cgmin always tries the midpoint. CG's path, results and counts now differ from R's (a quadratic of 3 variables:
232
+ 8 function evaluations instead of 46).
233
+ - `fisherTest` (2 × 2) and `mantelhaenTest(exact: true)`: the conditional MLE and the confidence limits are the roots to
234
+ full precision (R's uniroot stops up to several percent off, at the end 1/eps for a 99.99% limit).
235
+ - `jonckheereTest`'s normal approximation with ties uses the permutation variance with the ties (Hollander & Wolfe);
236
+ clinfun and DescTools use the variance without ties.
237
+ - `dunnTest`'s step-wise adjustments give tied p-values the same adjusted value (dunn.test's depend on the order of the
238
+ groups); without ties as dunn.test.
239
+ - `glm`'s AIC leaves out the rows of weight 0 (R's gaussian AIC was Inf), and deviance residuals without residual
240
+ degrees of freedom come from each row's contribution (R returns 0, also for a fit that has not converged).
241
+ - `glmSummary` names the statistics "z value" whenever the dispersion is not estimated (as R; a given dispersion was
242
+ named "t value").
243
+
244
+ ### Added
245
+
246
+ - Formula variable names may contain letters outside ASCII (`lm("転帰 ~ 年齢", ...)` was an error).
247
+ - `modelMatrix` accepts a response of any type (it was "the response must be numeric"), as R's `model.matrix`.
248
+ - `aov` accepts `Error()` terms in parentheses (`y ~ treatment + (Error(subject))`), as R.
249
+ - `grad`, `jacobian` and `hessian` accept a negative step `eps`, as numDeriv.
250
+
251
+ ### Changed
252
+
253
+ - `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
254
+ same values and random stream.
255
+
256
+ ### Fixed
257
+
258
+ - Distributions (#19 to #493): point masses and overflowing shapes of the beta family, `ppois`, `pbinom` and `pnbinom`
259
+ beyond 2^53, `phyper` and `qhyper` beyond 2^53, the discrete quantile search near the largest double, the
260
+ location-scale families near the ends of the range, noncentral distributions, `wilcox` and `signrank` tails,
261
+ `distSummary` where its closed forms overflow or underflow (the beta, gamma, F, Weibull, Kumaraswamy, negative
262
+ binomial and hypergeometric families among others) and of a hypergeometric point mass (populations of 0 or 1 gave
263
+ NaN moments).
264
+ - Special functions (#24 to #492): Bessel functions at subnormal and huge arguments and orders (Debye's expansion for
265
+ orders above 1000, the large-x expansion where its powers overflow), `gamma` near its edges, `choose` near overflow.
266
+ - Random numbers (#30 to #428): R's rounding of integer parameters, NaN for invalid parameters with R's stream kept,
267
+ infinite draws of `rgeom` and `rnbinom`, `r2dtable`'s limits, noncentral `rt` and `rf` with infinite df, and `r`
268
+ functions at infinite parameters that return the limits of their `q` functions.
269
+ - Descriptive statistics (#16 to #473): moments, `sd`, `scale`, `cv` and `prcomp` scaled before centring (no overflow
270
+ where the deviations do), `sum` and `mean` with values in three bands of magnitude that cancel, `weightedMean` with
271
+ products below the normal range, `hist`, `cut`, `ecdf` and `findInterval` with more than 2^31 values or breaks,
272
+ `omega`'s convergence warning.
273
+ - Hypothesis tests (#41 to #507): tail probabilities computed directly (`ksTest`'s exact p-value for D ≥ 1/2: 2.0e-20
274
+ where it was 0), intervals at confidence levels next to 1, `binomTest` and `poissonTest` at large counts and beyond
275
+ 2^53, `quadeTest` and `flignerTest` at any scale, `mcnemarTest` where a pair's counts overflow and its continuity
276
+ correction with fractional counts, `ansariTest`'s interval and estimate at the ends of the range, `wilcoxTest`'s
277
+ signed rank interval at a large `mu`, `survdiff` with a singular variance.
278
+ - Linear models and ANOVA (#8 to #509): standard errors independent of the units of x and of the weights (`lm` with a
279
+ column of 1e-200 or weights below 1e-308), `aov` with `Error()` and large covariates, `anova` and `glmAnova` test
280
+ only nested fits (judged on the rows of positive weight), `aovEz` scaled on the kept subjects only, `predict` with
281
+ the exact inner product where the plain sum overflows, warnings of the fits carried to the tables, `mauchlyTest`
282
+ checks.
283
+ - `glm`: hat values follow the rows of the last QR (a working weight that underflowed shifted them), the null deviance
284
+ with weights of 1e308, `glmPredict`'s standard errors where the squares overflow, Rao's score test with the smaller
285
+ model's intercept (as R), profile intervals of `glmConfint` whose restricted fits cycled in the last bits (NaN
286
+ limits), `glmAnova` warns about a model that has not converged, `glmRstandard` keeps small residuals of a rank-0 fit,
287
+ deviances and AIC of the binomial, Poisson, Gamma and inverse Gaussian families where their terms overflow,
288
+ `glmPredict` with the exact inner product.
289
+ - `lmer` and lmerTest: a response of 1e200 times ordinary data fits (#9), random slopes at any units of x (#11),
290
+ Satterthwaite's degrees of freedom independent of the units of the response and of x (#10; a response times 1e6 made
291
+ 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),
292
+ and `lmerAnova` compares the fixed effects of fits as column spaces (#8).
293
+ - `coxph`: a column dropped by the Cholesky factorisation no longer enters the solution (#13), tests in units of each
294
+ covariate's scale, times near 1e308.
295
+ - Linear algebra (#55 to #465): `eigen`, `svd`, `schur`, `qr`, `solve` and `expm` at the ends of the range, triangular
296
+ solves, `determinant`, `matMul`, `crossprod` and `tcrossprod` with the exact inner product where the plain sum
297
+ overflows or falls below the normal range, `rcond`, `qrSolve` and `kappa` on singular matrices.
298
+ - Numerical methods (#13 to #504): `integrate`, `optimize` and `uniroot` on intervals whose width overflows, `seq`,
299
+ `approx` and `spline` near overflow, `barylag` with nodes of any scale (#14), `splinefunH` and `hermiteInterp`
300
+ where differences overflow, `ode`, `optimHess` and `hessian` with large steps or values.
301
+ - Data handling (#35 to #500): `pivotLonger` and `pivotWider` as tidyr (name transforms, separators after zero-width
302
+ matches, repeated columns), `merge` with key columns of different types.
303
+
10
304
  ## 0.15.3 - 2026-10-29
11
305
 
12
306
  ### 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.6 KB)。
18
18
 
19
- 状態: **0.15.3。** R の stats パッケージの数値計算の中心
19
+ 状態: **0.17.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
  ## 含まれるもの
@@ -192,7 +192,7 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
192
192
  | 分布 (d/p/q) | 正規、t、カイ二乗、F、ベータ、ガンマ、二項、ポアソン、一様、指数、対数正規、ロジスティック、コーシー、ワイブル、幾何、負の二項、超幾何、Wilcoxon の符号付き順位と順位和、スチューデント化された範囲 (`ptukey`, `qtukey`)、非心カイ二乗・t・F・ベータ (`ncp`)。多項分布の確率 (`dmultinom`)。逆ガンマ、Kumaraswamy、Pareto、三角、Laplace (extraDistr) と逆正弦。`distSummary` (平均・分散・標準偏差・中央値・最頻値・歪度・尖度) |
193
193
  | 乱数 | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister と L'Ecuyer-CMRG、`sample.kind` の Rejection と Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 個の `r*` 関数, `sample`, `sampleInt` (`sample.int`), `r2dtable` |
194
194
  | 記述統計 | `sum`, `prod`, `mean`, `weightedMean` (`weighted.mean`), `variance` (`var`), `sd`, `median`, `range`, `cumsum`, `cumprod`, `cummax`, `cummin`, `diff`, `quantile`, `IQR`, `fivenum`, `mad`, `rank`, `cov`, `cor`, `tabulate`, `table`, `unique`, `cut`, `findInterval`, `pretty`, `hist`, `ecdf`, `scale`, `skewness`, `kurtosis`, `geometricMean`, `modes`, `meanAD`, `cv` |
195
- | 検定 | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `corTest`, `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`, `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`, `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`, `pairwiseWilcoxTest`, `pairwisePropTest`, `aov` (一元配置), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
195
+ | 検定 | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `corTest`, `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`, `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`, `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`, `pairwiseWilcoxTest`, `pairwisePropTest`, `aov` (一元配置。表は当てはめの `aovSummary`), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
196
196
  | 分散分析 | formula で呼ぶ `aov` と `aovSummary` (多元、交互作用、共変量、`Error()` の層), `anova` (`anova.lm`。逐次の表とモデルの比較), `Anova` (car の Type II と III), `aovEz` (afex。反復測定と混合計画、Greenhouse-Geisser と Huynh-Feldt の補正、一般化 η² と偏 η²), `mauchlyTest` (`mauchly.test`) |
197
197
  | 効果量と検出力 | `cohensD`, `hedgesG` (effectsize。信頼区間は厳密な限界), `etaSquared`, `omegaSquared`, `epsilonSquared` (偏・一般化。`anova` と `Anova` の表から), `powerTTest`, `powerPropTest`, `powerAnovaTest` (`power.*.test`), `pwrTTest`, `pwrT2nTest`, `pwr2pTest`, `pwr2p2nTest`, `pwrPTest`, `pwrNormTest`, `pwrRTest`, `pwrChisqTest`, `pwrAnovaTest`, `pwrF2Test`, `esH`, `esW1`, `esW2`, `cohenES` (pwr) |
198
198
  | 線形モデル | `lm` (formula とデータフレーム、または行列で渡す。`summary` の値も返す), `modelMatrix` (`model.matrix`), `confint`, `predict`。`glm` (行列で渡す形。R の `stats` のすべての族とリンク) と `glmSummary` (`summary.glm`)、`glmResiduals` (4 種類)、`glmHatvalues`、`glmRstandard`、`glmCooksDistance`、`glmPredict` (標準誤差つき)、`glmConfint` (プロファイル尤度、厳密な限界)、`glmAnova` (`anova.glm`) |
@@ -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,17 @@ 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 の警告は既定では表示しませんが、検定・モデル・当てはめはすべて、
237
+ 結果の `warnings` に入れて返します (R の文言で、同じ警告は 1 回ずつ。なければ `[]`)。R のように表示するには
238
+ handler を設定します。handler は、呼び出しの警告を 1 つずつ、呼んだ関数の名前とともに受け取ります:
239
+ `setWarningHandler((message, source) => console.warn(source + ": " + message))`。handler の中で throw すれば
240
+ R の `options(warn = 2)` の代わりになり、`setWarningHandler(null)` で止まります。
241
+ - 結果が定義されない入力はエラーにします。R が NaN や意味のない値を返す場合も同じです (たとえば不一致の
242
+ 組がない表の `mcnemarTest`、NaN を含む行列の `lu`)。分布の関数 (d/p/q/r) は、R と同じく不正な母数に NaN を返します。
243
+ [全般的な違い](docs/ja/differences-from-r.md#全般)を見てください。
244
+ - 1 本の配列に 2^24 個を超える値を確保する計算や、10 秒ほどを超えて走る計算は、始める前に RangeError を
245
+ 投げます。正確な検定では `exact: false` を案内します。R はその多くを、時間がかかっても計算します。
246
+ [上限](docs/ja/performance.md#上限)を見てください。
238
247
  - 分布の母数は、ベクトルとして使い回されません (リサイクルしない)。
239
248
  - `lmer` は基準の厳密な最適点を返します。lme4 の最適化はそこへ許容誤差の範囲でしか近づきません。
240
249
  また、lme4 の収束の警告は出しません。
@@ -248,14 +257,14 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
248
257
 
249
258
  | import するもの | gzip |
250
259
  |---|---|
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 |
260
+ | `pnorm` | 1.6 KB |
261
+ | `setSeed`, `rnorm` | 2.0 KB |
262
+ | `solve` / `svd` / `eigen` | 2.4 / 2.4 / 5.1 KB |
263
+ | `wilcoxTest` / `fisherTest` / `tTest` | 16.2 / 27.7 / 30.8 KB |
264
+ | `qbeta` / `pt` と `qt` | 43.5 / 40.0 KB |
265
+ | `glm` と `glmSummary` / `glm` とそのすべての関数 | 35.0 / 50.9 KB |
266
+ | `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 17.9 / 67.5 KB |
267
+ | すべて (`/mixed` を除く) | 248.6 KB |
259
268
 
260
269
  (`npm run size` で測れます。)
261
270
 
@@ -265,13 +274,13 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
265
274
  できません。メインの入口には含めていません)。
266
275
 
267
276
  バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (`/mixed` 以外のすべての関数を含む
268
- minify 済みの ES モジュール、gzip で 202 KB) を jsDelivr から読み込めます。jsDelivr は、npm のリリースを
277
+ minify 済みの ES モジュール、gzip で 249 KB) を jsDelivr から読み込めます。jsDelivr は、npm のリリースを
269
278
  そのまま配信します。
270
279
 
271
280
  ```html
272
281
  <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
282
+ import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.17.0/dist/rstats.js";
283
+ console.log(pnorm(1.96)); // ≈ 0.9750021049
275
284
  </script>
276
285
  ```
277
286
 
@@ -286,7 +295,12 @@ minify 済みの ES モジュール、gzip で 202 KB) を jsDelivr から読み
286
295
  `dist/tests.js`、`dist/linalg.js`、`dist/descriptive.js`、`dist/numerics.js`、`dist/special.js`、
287
296
  `dist/mixed.js` は上のサブパスと同じ関数を export し、共通のコードを `dist/chunks/` で共有します。そのため、
288
297
  2 つの分野を読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で
289
- 30 KB (`special`) から 159 KB (`tests`) です。
298
+ 38 KB (`special`) から 206 KB (`tests`) です。
299
+
300
+ 1 つのページでは、`dist/rstats.js` か分野ごとのバンドルのどちらか一方だけを使ってください。両者は別々の
301
+ モジュールの集まりなので、混ぜると共通のコードが 2 回読み込まれ、乱数の状態も 2 つになります (一方の `setSeed`
302
+ は他方の乱数に効きません)。`dist/rstats.js` と `dist/mixed.js` を一緒に読み込む場合も、`dist/mixed.js` は
303
+ 共通のコードを別に持ち込みます。
290
304
 
291
305
  npm を元にしたほかの CDN も使えます。たとえば `https://esm.sh/@numero-uno-jpn/rstats` です。ビルド結果
292
306
  (`dist/`) は main ブランチにはなく、リリースのタグにも入っていますが、jsDelivr の GitHub 経由の配信
@@ -306,7 +320,26 @@ npm を元にしたほかの CDN も使えます。たとえば `https://esm.sh/
306
320
  ## 版の番号
307
321
 
308
322
  版が 0.x の間は、minor の版で互換性のない変更が入ることがあります。その場合は変更履歴に
309
- 書きます。1.0.0 からは Semantic Versioning に従います。
323
+ 書きます。
324
+
325
+ 1.0.0 からは Semantic Versioning に従います。公開 API は、パッケージのルートとサブパスが export するもので、
326
+ 文書にある名前・引数・オプション・結果のフィールドとそれらの型を含みます。
327
+
328
+ - **major** (互換性のない変更): export・オプション・結果のフィールドの削除や改名、既定値や結果の形の変更、
329
+ 値を返していた入力でエラーにすること、エラーの型 (`TypeError`、`RangeError`、`SyntaxError`、`Error`) の変更、
330
+ 計算量の上限を厳しくすること、まだサポートされている Node.js の版を外すこと。
331
+ - **minor**: 関数・オプション・オーバーロード・結果のフィールドの追加、エラーだった入力を受け付けること、
332
+ 計算量の上限を緩めること、R (または従っているパッケージ) が誤る範囲で正しい値に変えること
333
+ ([docs/ja/differences-from-r.md](docs/ja/differences-from-r.md) に記録します)。
334
+ - **patch**: 不具合の修正 (R や厳密な値に近づく値の変化を含みます。最後のビットの変化は互換性のない変更として
335
+ 扱いません) と、文書の変更。
336
+ - API に含めないもの: エラーのメッセージ、キーの順、`warnings` と `messages` の中身、列挙できないフィールドや
337
+ 文書にないフィールド、`dist/` のうちエントリポイントと `dist/*.js` のバンドル以外のファイル。R の新しい版が
338
+ R 自身の値や乱数の列を変えたときは、rStats.js も minor の版でそれに合わせます。
339
+ - 結果のフィールドで分岐するコードは、フィールドが増えることを前提にしてください。
340
+ - オプションのオブジェクトに関数の知らないキーがあると RangeError になります (`optim` の `control` のような入れ子の
341
+ オブジェクトも同じ)。綴りを誤ったオプションが黙って無視されることはありません。このため、オプションの追加は
342
+ minor の変更です (追加するキーは、それまではエラーでした)。
310
343
 
311
344
  ## 貢献
312
345