@numero-uno-jpn/rstats 0.16.0 → 1.0.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 (243) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/README.ja.md +57 -23
  3. package/README.md +60 -23
  4. package/dist/chunks/{chunk-5UQCRBAG.js → chunk-3W5NFFAA.js} +1 -1
  5. package/dist/chunks/chunk-4F2IALD4.js +3 -0
  6. package/dist/chunks/{chunk-QNNL7AZ3.js → chunk-4OLDGML4.js} +2 -2
  7. package/dist/chunks/chunk-63OPBEYO.js +2 -0
  8. package/dist/chunks/chunk-6XJBCRBV.js +2 -0
  9. package/dist/chunks/chunk-BQSIBJVX.js +2 -0
  10. package/dist/chunks/chunk-BWKHYRM6.js +3 -0
  11. package/dist/chunks/{chunk-W26LRYOJ.js → chunk-CKV4JWW2.js} +1 -1
  12. package/dist/chunks/chunk-DCAWMF4K.js +2 -0
  13. package/dist/chunks/chunk-F7YGX7PN.js +2 -0
  14. package/dist/chunks/chunk-H7I32ZZE.js +2 -0
  15. package/dist/chunks/chunk-IEOD5GWC.js +3 -0
  16. package/dist/chunks/chunk-KICBQGFN.js +2 -0
  17. package/dist/chunks/chunk-LROMWFAK.js +2 -0
  18. package/dist/chunks/chunk-NSWENS3S.js +2 -0
  19. package/dist/chunks/chunk-O2SQMGE3.js +2 -0
  20. package/dist/chunks/chunk-QQX46TCI.js +2 -0
  21. package/dist/chunks/chunk-QZK3CCBA.js +2 -0
  22. package/dist/chunks/chunk-UJ66VQIG.js +2 -0
  23. package/dist/chunks/chunk-UKNDX4BA.js +2 -0
  24. package/dist/chunks/chunk-WIBKS73G.js +2 -0
  25. package/dist/chunks/{chunk-URIO5LY5.js → chunk-WQWZ7FND.js} +2 -2
  26. package/dist/chunks/chunk-WWVMVZUL.js +2 -0
  27. package/dist/chunks/chunk-YG5S5AVP.js +2 -0
  28. package/dist/chunks/chunk-YHNMBYSW.js +2 -0
  29. package/dist/data/grouping.js +6 -2
  30. package/dist/descriptive/basic.js +20 -0
  31. package/dist/descriptive/cov.js +11 -0
  32. package/dist/descriptive/dataFrames.js +13 -5
  33. package/dist/descriptive/factanal.d.ts +2 -0
  34. package/dist/descriptive/factanal.js +10 -2
  35. package/dist/descriptive/hist.js +6 -0
  36. package/dist/descriptive/moments.js +14 -0
  37. package/dist/descriptive/omega.js +8 -3
  38. package/dist/descriptive/pivot.d.ts +4 -1
  39. package/dist/descriptive/pivot.js +27 -13
  40. package/dist/descriptive/quantile.js +8 -0
  41. package/dist/descriptive/rank.js +4 -0
  42. package/dist/descriptive/table.d.ts +20 -1
  43. package/dist/descriptive/table.js +14 -14
  44. package/dist/descriptive.js +2 -2
  45. package/dist/distributions/arcsine.js +8 -0
  46. package/dist/distributions/beta.js +9 -0
  47. package/dist/distributions/binomial.js +9 -0
  48. package/dist/distributions/cauchy.js +9 -0
  49. package/dist/distributions/chisq.js +9 -0
  50. package/dist/distributions/exponential.js +9 -0
  51. package/dist/distributions/f.js +9 -0
  52. package/dist/distributions/gamma.js +8 -0
  53. package/dist/distributions/geometric.js +9 -0
  54. package/dist/distributions/hypergeometric.js +8 -0
  55. package/dist/distributions/invgamma.js +8 -0
  56. package/dist/distributions/kumaraswamy.js +9 -0
  57. package/dist/distributions/laplace.js +9 -0
  58. package/dist/distributions/logistic.js +9 -0
  59. package/dist/distributions/lognormal.js +8 -0
  60. package/dist/distributions/multinomial.js +4 -0
  61. package/dist/distributions/negbinomial.js +8 -0
  62. package/dist/distributions/normal.js +8 -0
  63. package/dist/distributions/pareto.js +8 -0
  64. package/dist/distributions/poisson.js +9 -0
  65. package/dist/distributions/signrank.js +9 -0
  66. package/dist/distributions/summary.d.ts +2 -1
  67. package/dist/distributions/summary.js +31 -1
  68. package/dist/distributions/t.js +9 -0
  69. package/dist/distributions/triangular.js +9 -0
  70. package/dist/distributions/tukey.js +6 -0
  71. package/dist/distributions/uniform.js +8 -0
  72. package/dist/distributions/weibull.js +8 -0
  73. package/dist/distributions/wilcox.js +9 -0
  74. package/dist/distributions.js +2 -2
  75. package/dist/entries/descriptive.d.ts +3 -1
  76. package/dist/entries/descriptive.js +1 -1
  77. package/dist/entries/distributions.d.ts +1 -0
  78. package/dist/entries/distributions.js +2 -0
  79. package/dist/entries/linalg.d.ts +3 -1
  80. package/dist/entries/mixed.d.ts +9 -0
  81. package/dist/entries/mixed.js +8 -1
  82. package/dist/entries/numerics.d.ts +2 -1
  83. package/dist/entries/tests.d.ts +8 -5
  84. package/dist/entries/tests.js +3 -1
  85. package/dist/htest/agreement.d.ts +13 -0
  86. package/dist/htest/agreement.js +46 -7
  87. package/dist/htest/ansariTest.d.ts +2 -1
  88. package/dist/htest/ansariTest.js +43 -12
  89. package/dist/htest/aov.d.ts +28 -22
  90. package/dist/htest/aov.js +42 -13
  91. package/dist/htest/binomTest.js +6 -0
  92. package/dist/htest/brunnerMunzelTest.js +5 -0
  93. package/dist/htest/chisqTest.d.ts +3 -1
  94. package/dist/htest/chisqTest.js +21 -3
  95. package/dist/htest/cor.d.ts +7 -1
  96. package/dist/htest/cor.js +40 -7
  97. package/dist/htest/core/simulate.d.ts +6 -0
  98. package/dist/htest/core/simulate.js +20 -0
  99. package/dist/htest/effectSize.d.ts +3 -0
  100. package/dist/htest/effectSize.js +28 -8
  101. package/dist/htest/fisherTest.d.ts +2 -1
  102. package/dist/htest/fisherTest.js +52 -6
  103. package/dist/htest/ksTest.d.ts +4 -0
  104. package/dist/htest/ksTest.js +13 -4
  105. package/dist/htest/leveneTest.d.ts +2 -0
  106. package/dist/htest/leveneTest.js +9 -3
  107. package/dist/htest/mantelhaenTest.js +7 -0
  108. package/dist/htest/mcnemarTest.js +8 -0
  109. package/dist/htest/multipleComparisons.d.ts +16 -25
  110. package/dist/htest/multipleComparisons.js +26 -43
  111. package/dist/htest/normalityTests.js +10 -4
  112. package/dist/htest/onewayTest.js +10 -0
  113. package/dist/htest/pAdjust.js +4 -0
  114. package/dist/htest/pairwise.d.ts +2 -0
  115. package/dist/htest/pairwise.js +29 -6
  116. package/dist/htest/poissonTest.js +6 -0
  117. package/dist/htest/polycor.js +20 -10
  118. package/dist/htest/power.d.ts +4 -0
  119. package/dist/htest/power.js +16 -2
  120. package/dist/htest/propTest.d.ts +3 -0
  121. package/dist/htest/propTest.js +23 -2
  122. package/dist/htest/pwr.d.ts +38 -1
  123. package/dist/htest/pwr.js +38 -15
  124. package/dist/htest/rankTests.js +7 -1
  125. package/dist/htest/tTest.d.ts +2 -0
  126. package/dist/htest/tTest.js +9 -0
  127. package/dist/htest/testFormula.js +11 -11
  128. package/dist/htest/trendTests.d.ts +21 -1
  129. package/dist/htest/trendTests.js +13 -18
  130. package/dist/htest/types.d.ts +2 -0
  131. package/dist/htest/varTest.js +7 -0
  132. package/dist/htest/wilcoxTest.js +51 -9
  133. package/dist/internal/checkOptions.d.ts +11 -0
  134. package/dist/internal/checkOptions.js +31 -0
  135. package/dist/internal/optionalArgs.d.ts +12 -0
  136. package/dist/internal/optionalArgs.js +46 -0
  137. package/dist/internal/warnings.d.ts +66 -0
  138. package/dist/internal/warnings.js +122 -0
  139. package/dist/linalg/basic.js +7 -0
  140. package/dist/linalg/chol.js +6 -0
  141. package/dist/linalg/eigen.js +4 -0
  142. package/dist/linalg/expm.js +4 -0
  143. package/dist/linalg/kappa.js +6 -0
  144. package/dist/linalg/lu.js +5 -0
  145. package/dist/linalg/norm.js +4 -0
  146. package/dist/linalg/ops.d.ts +27 -2
  147. package/dist/linalg/ops.js +14 -13
  148. package/dist/linalg/qr.js +14 -0
  149. package/dist/linalg/solve.js +9 -0
  150. package/dist/linalg/svd.js +6 -2
  151. package/dist/linalg.js +2 -2
  152. package/dist/mixed.js +5 -4
  153. package/dist/models/anovaSequential.d.ts +16 -1
  154. package/dist/models/anovaSequential.js +50 -7
  155. package/dist/models/aovEz.js +16 -11
  156. package/dist/models/aovStrata.js +15 -4
  157. package/dist/models/carAnova.js +11 -17
  158. package/dist/models/coxph.d.ts +6 -0
  159. package/dist/models/coxph.js +21 -6
  160. package/dist/models/formula.d.ts +5 -2
  161. package/dist/models/formula.js +31 -8
  162. package/dist/models/glm.d.ts +22 -2
  163. package/dist/models/glm.js +32 -22
  164. package/dist/models/glmAnova.js +8 -3
  165. package/dist/models/glmConfint.js +6 -2
  166. package/dist/models/glmFamily.d.ts +1 -6
  167. package/dist/models/glmFamily.js +3 -22
  168. package/dist/models/glmer.d.ts +255 -0
  169. package/dist/models/glmer.js +635 -0
  170. package/dist/models/glmerAnova.d.ts +81 -0
  171. package/dist/models/glmerAnova.js +139 -0
  172. package/dist/models/glmerDeviance.d.ts +98 -0
  173. package/dist/models/glmerDeviance.js +576 -0
  174. package/dist/models/glmerFamily.d.ts +57 -0
  175. package/dist/models/glmerFamily.js +236 -0
  176. package/dist/models/glmerGradient.d.ts +46 -0
  177. package/dist/models/glmerGradient.js +301 -0
  178. package/dist/models/glmerStructure.d.ts +45 -0
  179. package/dist/models/glmerStructure.js +168 -0
  180. package/dist/models/glmerSummary.d.ts +102 -0
  181. package/dist/models/glmerSummary.js +94 -0
  182. package/dist/models/lm.js +13 -3
  183. package/dist/models/lmer.d.ts +27 -6
  184. package/dist/models/lmer.js +75 -321
  185. package/dist/models/lmerAnova.d.ts +52 -3
  186. package/dist/models/lmerAnova.js +101 -45
  187. package/dist/models/lmerTest.d.ts +12 -5
  188. package/dist/models/lmerTest.js +39 -18
  189. package/dist/models/mauchly.d.ts +2 -0
  190. package/dist/models/mauchly.js +7 -2
  191. package/dist/models/mixedDeviance.d.ts +28 -2
  192. package/dist/models/mixedDeviance.js +84 -56
  193. package/dist/models/mixedMinimiser.d.ts +83 -0
  194. package/dist/models/mixedMinimiser.js +438 -0
  195. package/dist/models/mixedPredict.d.ts +121 -0
  196. package/dist/models/mixedPredict.js +530 -0
  197. package/dist/models/mixedStructure.d.ts +62 -3
  198. package/dist/models/mixedStructure.js +74 -29
  199. package/dist/models/modelFrame.js +2 -2
  200. package/dist/models/modelMatrix.d.ts +8 -1
  201. package/dist/models/modelMatrix.js +56 -39
  202. package/dist/models/survival.d.ts +6 -0
  203. package/dist/models/survival.js +9 -2
  204. package/dist/numerics/deriv.js +8 -0
  205. package/dist/numerics/integrate.js +8 -0
  206. package/dist/numerics/interp.d.ts +32 -7
  207. package/dist/numerics/interp.js +27 -9
  208. package/dist/numerics/ode.js +4 -0
  209. package/dist/numerics.js +2 -2
  210. package/dist/optim/optim.js +17 -2
  211. package/dist/random/beta.js +5 -0
  212. package/dist/random/continuous.js +17 -0
  213. package/dist/random/extra.js +13 -0
  214. package/dist/random/gamma.js +11 -0
  215. package/dist/random/poisson.js +5 -0
  216. package/dist/random/rng.js +4 -0
  217. package/dist/random/sample.js +6 -0
  218. package/dist/rstats.js +17 -14
  219. package/dist/special/besselIK.js +7 -0
  220. package/dist/special/choose.js +7 -0
  221. package/dist/special/psigamma.js +7 -0
  222. package/dist/special.js +2 -2
  223. package/dist/tests.js +14 -11
  224. package/llms.txt +15 -4
  225. package/package.json +19 -10
  226. package/dist/chunks/chunk-2D2IQWUQ.js +0 -2
  227. package/dist/chunks/chunk-6CSTWA5E.js +0 -2
  228. package/dist/chunks/chunk-72Y3HZID.js +0 -2
  229. package/dist/chunks/chunk-BG2KLEHM.js +0 -2
  230. package/dist/chunks/chunk-CMEKBNHQ.js +0 -2
  231. package/dist/chunks/chunk-FLJNSXSW.js +0 -2
  232. package/dist/chunks/chunk-GM53LWSR.js +0 -2
  233. package/dist/chunks/chunk-JBCA56ZS.js +0 -3
  234. package/dist/chunks/chunk-K3RJAD2T.js +0 -2
  235. package/dist/chunks/chunk-KAZRWIB5.js +0 -2
  236. package/dist/chunks/chunk-KBVVIMXX.js +0 -3
  237. package/dist/chunks/chunk-N3SIFCZX.js +0 -2
  238. package/dist/chunks/chunk-SC6CV4Z3.js +0 -2
  239. package/dist/chunks/chunk-SYWOBOTR.js +0 -2
  240. package/dist/chunks/chunk-VTUGG2SV.js +0 -2
  241. package/dist/chunks/chunk-XHETEYVC.js +0 -2
  242. package/dist/chunks/chunk-YRZWONZB.js +0 -3
  243. package/dist/chunks/chunk-ZGABZMWX.js +0 -2
package/CHANGELOG.md CHANGED
@@ -7,6 +7,211 @@ 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
+ ## 1.0.0 - 2026-11-05
11
+
12
+ The first stable version: from 1.0.0 the public API follows Semantic Versioning (see Versioning in the README), so
13
+ breaking changes come only with a new major version. It adds the generalized linear mixed models of lme4's `glmer`,
14
+ with `glmerSummary`, `glmerAnova` and predictions for both mixed models (`glmerPredict`, `lmerPredict`), in the area
15
+ `@numero-uno-jpn/rstats/mixed`, which stays out of the root export and of `dist/rstats.js`; and fixes `lmer` and
16
+ `lmerSummary` for predictors on extreme scales.
17
+
18
+ ### Added
19
+
20
+ - **Generalized linear mixed models:** `glmer`, lme4's `glmer()`, in the area `@numero-uno-jpn/rstats/mixed`, by the
21
+ Laplace approximation (`nAGQ = 1`, default) or with the fixed effects from the penalised IRLS (`nAGQ = 0`), for the
22
+ families binomial, poisson, Gamma, inverse.gaussian and gaussian (not with the identity link, which is `lmer`) with
23
+ their links and lme4's own inverse links and variance functions. A binomial response may be 0/1, booleans, strings
24
+ (the first level failure), proportions with `weights`, or `cbind(successes, failures)` with two column names;
25
+ `weights` and `offset` are arrays or column names; `start` (`theta`, `fixef`) as R's. The result has the quantities
26
+ of `fixef`, `coef(summary())` (estimates, standard errors, z values; p-values come with `glmerSummary`), `vcov`,
27
+ `sigma`, `VarCorr`, `ranef`, `fitted`, `predict`, the deviance, Pearson, working and response residuals,
28
+ `deviance`, `logLik`, `AIC`, `BIC` and `isSingular`, with lme4's checks, messages and warnings (not those of its
29
+ optimiser). The estimate is the exact minimiser of the Laplace deviance at the exact conditional mode, found with
30
+ the analytic gradient of the deviance (implicit differentiation through the conditional mode; lme4 has none), so
31
+ that thousands of rows with ten fixed effects fit in a second or two and 100000 rows in about 12 s (references at
32
+ the optimum in 110-bit arithmetic matched within 1e-9, the log-likelihood within 1e-12, standard errors within
33
+ 1e-9), which lme4 approaches to its own tolerances: its estimates differ in about the 4th to 6th significant digit
34
+ and its standard errors, from a finite-difference Hessian of its approximate deviance, by up to about 1% (much more
35
+ for a small dispersion). Predictors shifted (years), rescaled (by up to 1e±300) or nearly collinear, large counts,
36
+ prior weights from 2^-20 to 2^30, offsets far from the data (`log(exposure)`, constants) and Gamma responses beyond
37
+ 1e154 or, with the log link, below lme4's bound 2^-52 of the mean give the same fit transformed, also where lme4
38
+ fails. Non-integer poisson counts are a RangeError for `nAGQ` 0 and 1 (the log-likelihood is −Inf everywhere; R
39
+ returns its starting values); `nAGQ` is truncated before its sign is checked (−0.5 is 0, as R). A response scale
40
+ that lme4's Laplace criterion cannot resolve (poisson counts beyond about 1e11, inverse.gaussian or gaussian with
41
+ the log link far from 1) is a RangeError saying so, instead of a PIRLS message or a θ of 0 that is no estimate.
42
+ Adaptive Gauss-Hermite quadrature (`nAGQ` from 2 to 100) for a single scalar random-effects term such as `(1 | g)`
43
+ (R's two errors otherwise), with the rule computed to rounding error, the binomial and poisson families only (for
44
+ Gamma, inverse.gaussian and gaussian a RangeError: lme4 holds the dispersion at 1 there, so its estimates would not
45
+ be maximum likelihood); its `logLik`, `AIC` and `BIC` are those of the log-likelihood, which R's leave out the
46
+ constant of the saturated model for `nAGQ > 1` (they differ from R's by that constant), and its estimates match the
47
+ exact optimum as for the Laplace approximation (lme4's AGQ fits are close: standard errors within about 4e-5).
48
+ Prediction for new data: `glmerPredict`.
49
+ - **`glmerSummary`**, lme4's `summary()` of a glmer fit: the coefficient table with p-values from the normal
50
+ distribution for every family (as lme4's, although it names the statistic `t value` for the families with a
51
+ dispersion), the correlation of the fixed effects, the quartiles of the scaled Pearson residuals, `AIC`, `BIC`,
52
+ `logLik`, −2 logLik (R's `-2*log(L)`), `df.resid`, the variance components, the numbers of groups and the fit's
53
+ messages and vcov warning.
54
+ - **`glmerAnova`**, lme4's `anova()` for glmer fits: for one fit the table of the fixed-effects terms (`npar`,
55
+ sequential Wald sums of squares from R_X, mean squares and F = mean square / σ², no p-values, as lme4's); for an
56
+ array of fits the likelihood-ratio comparison of glmer, lmer and glm fits together (lmer REML fits refitted by ML),
57
+ with `lmerAnova`'s checks (same data object, rows and response; a glm fit: the same number of observations and
58
+ response values), the same prior weights, and the test only where the smaller fit is nested in the larger (same
59
+ family, link and offset, its fixed-effects columns and random-effects terms within the larger fit's, compared on
60
+ the rows of positive weight; R tests any pair). For `nAGQ > 1` the log-likelihood of the fit includes the saturated model's constant, so fits with different
61
+ `nAGQ` and glm fits are commensurate (R's differ by that constant; R refuses glm fits with `nAGQ > 1`).
62
+ - **`glmerPredict` and `lmerPredict`**, lme4's `predict()` of glmer and lmer fits: at the fit's rows or at
63
+ `newdata` (the fixed part built as the fit built X: its terms, contrasts, factor levels and dropped columns), with all
64
+ (default), some (`reForm: "~ (1 | g)"`, also a term with fewer columns than the fit's) or none (`reForm: false`) of
65
+ the random-effects terms, `randomOnly`, `allowNewLevels` (a new level or a missing grouping value adds 0 for its
66
+ term), `type` `"link"` or `"response"` (glmer), and `seFit`: the standard errors from the conditional covariance of
67
+ (b, β) at θ̂, computed correctly where lme4's are wrong (crossed grouping factors whose sparse factor is permuted,
68
+ `reForm` subsets) or fail, and finite where only their sum of squares overflows (R: Infinity). glmer's offset: an offset given as a column name is read from `newdata`, one given as an
69
+ array is replaced by `newoffset` (default 0, as R ignores glmer's `offset` argument in prediction). A missing value
70
+ gives NaN for its row; a new level of a factor of the fixed part is the error `factor <name> has new level <value>`
71
+ (R: `non-conformable arguments`), and a missing value there NaN (R: the same error). Without `newdata`, the rows of
72
+ the fit (R fails there when the fit dropped a row with a missing grouping value). Matched to the predictions at the
73
+ exact fit within 1e-8 (lmer within 1e-14).
74
+
75
+ ### Fixed
76
+
77
+ - **`lmer` and `lmerSummary` with predictors beyond 2^±500** (times 1e-160): the standard errors were Infinity in the
78
+ fit and NaN (with NaN degrees of freedom and p-values) in `lmerSummary`, since the inverse of R_X'R_X overflowed. They
79
+ are now computed with those columns of X divided by their powers of 2 (an entry of `vcov` may still overflow, as
80
+ R's would, where the standard error does not); fits on ordinary scales are unchanged, bit for bit.
81
+ - **`lmer` with predictors beyond 2^±500**: times 1e160 (and 1e-160 with REML) the fit threw a TypeError inside the
82
+ minimiser (X'X overflowed to NaN), and times 1e-160 it was accurate to about 1e-6 only (X'X subnormal). Such columns
83
+ of X are now divided by their powers of 2 for the fit (exact), so that the result is the unscaled fit transformed
84
+ back (the REML criterion with log det R_X'R_X of the given X); a Hessian with NaN in the minimiser is its failure,
85
+ not a TypeError. Fits on ordinary scales are unchanged, bit for bit.
86
+
87
+ ## 0.17.0 - 2026-11-05
88
+
89
+ The API is cleaned up toward 1.0.0, which follows the mixed models of `glmer`: argument errors are a `TypeError` or
90
+ a `RangeError`, a key of an options object that the function does not know is an error, and the results of the tests
91
+ have a required `warnings` with R's warnings, which `setWarningHandler` can also pass to a function.
92
+
93
+ ### Breaking
94
+
95
+ - Argument errors that were a plain `Error` are a `TypeError` (wrong type or shape) or a `RangeError` (value out of
96
+ range), as the other functions (the messages are unchanged):
97
+ - `pivotLonger` and `pivotWider`: a `colsVary` or `namesVary` that is not a string, a `namesSep` with one
98
+ `namesTo`, several `namesTo` without `namesSep` or `namesPattern`, a `namesPattern` with the wrong number of
99
+ groups, and a `.value` transform that gives no string are TypeErrors; an unknown `colsVary` or `namesVary`, a
100
+ column that does not exist, an empty `cols`, `namesFrom` or `valuesFrom`, `.value` twice in `namesTo`, a value
101
+ column given twice for one key, `idCols` that overlap `namesFrom` or `valuesFrom`, and values not uniquely
102
+ identified without `valuesFn` are RangeErrors.
103
+ - `merge`: `byX` and `byY` of different lengths are a TypeError, a key that is not a column a RangeError.
104
+ - The formula forms of the tests (`tTest`, `wilcoxTest`, `varTest`, `ansariTest`, `moodTest`, `ksTest`,
105
+ `kruskalTest`, `flignerTest`, `bartlettTest`, `onewayTest`, `friedmanTest`, `quadeTest`, `corTest`): a formula of
106
+ the wrong form for the test is a TypeError. A grouping factor without exactly 2 levels and a block design that is
107
+ not unreplicated and complete stay an `Error` (data whose result is not defined).
108
+ - Data frames and columns: a duplicate column name (`cbind`, `merge` with suffixes that collide, `aggregate`) and a
109
+ `select` of `subset` that is not a column are RangeErrors, and data frames with different names in `rbind` a
110
+ TypeError; a column named in a formula or option that does not exist ("object 'x' not found": `aggregate`, the
111
+ model functions such as `lm` and `glm` and their `weights`, the formula forms of the tests, `aovEz`) is a
112
+ RangeError, and so are a factor given in both `between` and `within` of `aovEz`, a factor name repeated in
113
+ `between` or `within` ("duplicated factor names in 'between': A") and an `observed` variable that is not a factor
114
+ ("Observed variable not in data: x"), the same error of `etaSquared`'s `generalized` included.
115
+ - `aov(x, g)` and `aov(samples)` return the fit of the model `y ~ g` (an `LmFormulaResult`, as `aov("y ~ g", data)`)
116
+ instead of the one-way table, as R's `aov` always returns a fit; the table is `aovSummary(aov(x, g))` (rows `g` and
117
+ `Residuals`), and the `AovResult` type is removed. The levels of `g` are the group labels in R's order, or the
118
+ 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
119
+ of rounding (the sums of squares now come from the QR of the fit). Where the residual sum of squares is exactly 0,
120
+ 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
121
+ when all values are equal (see Changed).
122
+ - `steelTest` is removed. It only reproduced the errors of PMCMRplus 1.9.12's `steelTest`, which fails on every input,
123
+ and never returned a value; Steel's many-to-one rank test is `manyOneUTest` (its normal approximation).
124
+ - A key of an options object that the function does not know is a RangeError, where it was ignored: a misspelt key
125
+ such as `pnorm(q, { lowertail: false })` gave the lower tail without a sign ("unknown option 'lowertail' for pnorm
126
+ (known: mean, sd, lowerTail, logP)"). A key whose value is `undefined` counts. This holds for every exported function
127
+ that takes options, the nested objects with fixed keys included (`optim`'s and `optimHess`' `control`, `glm`'s
128
+ `family` and `link` given as objects, `coxph`'s and `factanal`'s `control`; "unknown option 'control.maxitt' for
129
+ optim", and so for `optimHess`, whose `control` is a position), for the `params` of `distSummary` (the parameters
130
+ of the distribution's d function: `shape`, `rate` and `scale` for `"gamma"`; not `ncp` of `chisq`, `beta`, `t` and
131
+ `f`, which was ignored, giving the summaries of the central distribution) and for the options of the function
132
+ `splinefun` and `splinefunH` return. Objects whose keys are the user's data (data frames, `contrasts`, `levels`) are
133
+ not checked. In `lmer`, `lmerSummary`, `lmerContest` and `lmerAnova` an unknown key was a TypeError with R's
134
+ message ("unused argument (reml)") and is now this RangeError too; an argument of R that they do not support
135
+ (`lmer`'s `weights`, `lmerAnova`'s `ddf`, ...) is still the Error "lmer: argument 'weights' is not supported",
136
+ checked first.
137
+ - `HTest` and the other results of the tests, effect sizes, power and agreement functions, and `factanal`'s, have a
138
+ required `warnings: string[]`: R's warnings, each once, in R's order, an empty array when there are none (not the
139
+ warnings of R's distribution functions about their own precision, nor those about R's argument types; those that
140
+ explain a `NaN` are included). Code that builds such an object itself must add the field. Nothing is printed unless
141
+ a handler is set (`setWarningHandler`, under Added). The functions that had no `warnings` return an empty array,
142
+ except 10 that now give R's warnings where they were silent, and `cohensD` and `hedgesG` give a new one:
143
+ - `wilcoxTest`: "cannot compute exact p-value with ties" or "with zeroes" and the same of the interval, when the
144
+ exact method asked for or chosen by default cannot be used; "requested conf.level not achievable", where the
145
+ interval's confidence level is lowered; "cannot compute confidence interval when all observations are zero or
146
+ tied", where the interval is `NaN`. `pairwiseWilcoxTest` returns those of its comparisons, each once.
147
+ - `ansariTest`: "cannot compute exact p-value with ties" and, with `confInt`, "cannot compute exact confidence
148
+ intervals with ties", where R stops but the normal-approximation interval is returned; "samples differ in
149
+ location: cannot compute confidence set, returning NA", "cannot compute confidence set, returning NA", "cannot
150
+ compute estimate, returning NA" and "cannot compute asymptotic confidence set or estimator", where the interval or
151
+ estimate is `NaN` or left out.
152
+ - `fisherTest`: "'x' has been rounded to integer: Mean relative difference: 0.0625", with the text of R's
153
+ `all.equal` of the counts and the rounded counts.
154
+ - `chisqTest`: "Chi-squared approximation may be incorrect" where an expected count is below 5 and the p-value is
155
+ not simulated, and "cannot compute simulated p-value with zero marginals". `propTest`: "Chi-squared approximation
156
+ may be incorrect"; `pairwisePropTest` returns it once.
157
+ - `ksTest`: "ties should not be present for the one-sample Kolmogorov-Smirnov test", and "p-value will be
158
+ approximate in the presence of ties" for two samples with the asymptotic p-value.
159
+ - `corTest`: "the standard deviation is zero" where x or y is constant, "Cannot compute exact p-value with ties"
160
+ for Kendall and Spearman, and R's "NaNs produced" of Spearman's t approximation for 2 pairs, whose p-value is
161
+ `NaN`.
162
+ - `cohensD` and `hedgesG`: effectsize's "'y' is numeric but has only 2 unique values. ..." where `y` has exactly 2
163
+ distinct values.
164
+ - `cronbachAlpha`: psych's own warnings, "Item = had no variance and was deleted but still is counted in the
165
+ score" for a constant item and "Some items were negatively correlated with the first principal component and
166
+ probably should be reversed. ..." (as psych's `principal`: the eigenvector of the largest eigenvalue of the
167
+ correlations, signed so that its sum is not negative).
168
+
169
+ ### Added
170
+
171
+ - The package can be loaded with `require()` (Node 22.12 and later load ES modules with `require`): each subpath of
172
+ `exports` has a `default` condition besides `import`, and `@numero-uno-jpn/rstats/package.json` is exported.
173
+ - Each subpath exports the types its functions use, so they need no import from another subpath: `Sample` and
174
+ `DataFrame` from `/descriptive` and `/linalg`, `Sample` from `/numerics`, `DataFrame` and `ContrastName` from
175
+ `/mixed`, `MatrixInput` and `QR` from `/tests`.
176
+ - Results whose fields keep the names of R or of a package get aliases with the names the other results use, as
177
+ ordinary fields with the same values (the old names stay): `pValue` for `survdiff`'s `pvalue`; `stdError`, `zValue`
178
+ and `pValue` for `coxph`'s `se`, `z` and `p`; `stdError`, `tValue` and `pValue` for `glhtDunnett`'s `se`, `t` and
179
+ `p`; `zValue`, `pValue` and `pAdjusted` for `dunnTest`'s `Z`, `P` and `PAdjusted`; `pAdjusted` for `TukeyHSD`'s
180
+ `pAdj`; `stdError` for the `stdErr` of `tTest` and `survfit`; `fValue` for `icc`'s `Fvalue`.
181
+ - The optional arguments taken by position as in R are also accepted in an options object (an overload), in place of
182
+ the argument or after it: `glmResiduals(fit, { type })`, `cohenES(test, { size })`, `outer(x, y, { fun })`,
183
+ `tabulate(bin, { nbins })`, `propTrendTest(x, n, { score })` and `s(xq, { deriv })` for the function `s` that
184
+ `splinefun` or `splinefunH` returns (its type is the new `SplineFunction`). `optimHess` keeps `gr` and `control` by
185
+ position only, as R (a positional `control` is itself a plain object). Giving one both by position and in the options is a
186
+ RangeError. New types: `GlmResidualsOptions`, `CohenESOptions`, `OuterFun`, `OuterOptions`, `TabulateOptions`,
187
+ `PropTrendTestOptions`, `SplineFunction` and `SplineFunctionOptions`.
188
+ - `setWarningHandler(handler)` passes R's warnings to a function of the user's choice, as R prints them, such as
189
+ `setWarningHandler((message, source) => console.warn(source + ": " + message))`: each call of a test, model or fit
190
+ (and `pivotLonger` without `onWarning`) passes its warnings once it has its result, each distinct warning once, with
191
+ the name of the function called (also the warnings the tests now give, such as `wilcoxTest`'s "cannot compute exact
192
+ p-value with ties"); a function that calls another, such as `pairwiseWilcoxTest`, passes them once under
193
+ its own name. A fit's warnings are passed once, when it is fitted (`lm`, `glm`, `aov`, `lmer`, ...); a function
194
+ given a fit or a table (`anova`, `aovSummary`, `Anova`, `glmSummary`, `etaSquared`, `lmerSummary`, ...) keeps them
195
+ in its result's `warnings` but passes only those it adds. An error thrown by the handler propagates to the caller
196
+ (as R's `options(warn = 2)`). `setWarningHandler(null)`, the default, passes nothing; the previous handler is
197
+ returned. The handler is kept on `globalThis`, one setting for every copy of the library on a page. Exported from
198
+ the root, `rStats.js/distributions`, `rStats.js/tests` and `rStats.js/mixed`, with the type `WarningHandler`.
199
+
200
+ ### Changed
201
+
202
+ - `aovSummary` and the sequential table of `anova` take a residual sum of squares at the level of rounding (below
203
+ 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
204
+ squares of the terms at that level: F = Inf and p = 0 for groups without spread (`aov([[1, 1], [2, 2]])` gave F =
205
+ 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).
206
+ The same holds in each stratum of a fit with `Error()` (the sum of squares of the whole response as the scale): F =
207
+ Inf or NaN where the Within stratum of `aov("y ~ g + Error(id)", d)` gave F = 2.9e33 from the residue. The tables
208
+ of other fits are unchanged to the bit.
209
+
210
+ ### Fixed
211
+
212
+ - The result of `svd` no longer has the internal field `s` (the power-of-2 exponent of the singular values), which is
213
+ not part of `SvdResult`.
214
+
10
215
  ## 0.16.0 - 2026-11-04
11
216
 
12
217
  Fixes from a numerical review and GitHub issues #8 to #513. Each case is described, with R's value and rStats.js's, in
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.4 KB)。
17
+ tree-shaking が効きます (`pnorm` だけなら gzip で 1.6 KB)。
18
18
 
19
- 状態: **0.16.0。** R の stats パッケージの数値計算の中心
19
+ 状態: **1.0.0。** R の stats パッケージの数値計算の中心
20
20
  (分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
21
21
  [ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
22
22
 
@@ -122,7 +122,7 @@ aovEz(long, { id: "id", dv: "y", within: "W" }).anova.table[0];
122
122
  // ≈ [1.735, 6.940, 0.21653, 35.876, 0.84607, 0.00026363] (num Df, den Df, MSE, F, ges, p。GG で補正)
123
123
  ```
124
124
 
125
- ### 線形混合モデル
125
+ ### 混合モデル
126
126
 
127
127
  `lmer` は、lme4 の線形混合モデルを REML または最尤法で当てはめます。独立した分野
128
128
  `@numero-uno-jpn/rstats/mixed` (CDN では `dist/mixed.js`) にあり、1 ファイルにまとめたビルドには含めていません。
@@ -156,6 +156,13 @@ lmerAnova(fit).F; // ≈ [91.942] (Type III。R: anova(fit))
156
156
  Type I・II・III の分散分析表を返します (自由度はその最適点で厳密な導関数から求めます。lmerTest は lme4 の
157
157
  最適点で数値微分します)。`lmerAnova([fit1, fit2])` は、lme4 の `anova()` と同じく当てはめを尤度比検定で比べます。
158
158
 
159
+ `glmer` は、lme4 の一般化線形混合モデル (二項、ポアソン、Gamma、inverse.gaussian、gaussian の族とそのリンク) を、
160
+ ラプラス近似で、またスカラーの変量効果の項が 1 つなら適応的 Gauss-Hermite 求積 (`nAGQ` 2〜100) で当てはめます:
161
+ `glmer("y ~ x + (1 | g)", d, { family: "poisson" })`。`glmerSummary` は p 値つきの係数表、`glmerAnova` は分散分析表
162
+ または glmer・lmer・glm の当てはめの尤度比検定による比較、`glmerPredict` と `lmerPredict` は予測 (新しいデータ、
163
+ 一部または全部を除いた変量効果、標準誤差つきも可) を返します。`lmer` と同じく推定値は厳密な最適点です。標準誤差と
164
+ `nAGQ > 1` については[違い](docs/ja/differences-from-r.md#混合モデル)を見てください。
165
+
159
166
  ### 効果量と検出力
160
167
 
161
168
  ```ts
@@ -192,11 +199,11 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
192
199
  | 分布 (d/p/q) | 正規、t、カイ二乗、F、ベータ、ガンマ、二項、ポアソン、一様、指数、対数正規、ロジスティック、コーシー、ワイブル、幾何、負の二項、超幾何、Wilcoxon の符号付き順位と順位和、スチューデント化された範囲 (`ptukey`, `qtukey`)、非心カイ二乗・t・F・ベータ (`ncp`)。多項分布の確率 (`dmultinom`)。逆ガンマ、Kumaraswamy、Pareto、三角、Laplace (extraDistr) と逆正弦。`distSummary` (平均・分散・標準偏差・中央値・最頻値・歪度・尖度) |
193
200
  | 乱数 | `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
201
  | 記述統計 | `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`) |
202
+ | 検定 | `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
203
  | 分散分析 | formula で呼ぶ `aov` と `aovSummary` (多元、交互作用、共変量、`Error()` の層), `anova` (`anova.lm`。逐次の表とモデルの比較), `Anova` (car の Type II と III), `aovEz` (afex。反復測定と混合計画、Greenhouse-Geisser と Huynh-Feldt の補正、一般化 η² と偏 η²), `mauchlyTest` (`mauchly.test`) |
197
204
  | 効果量と検出力 | `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
205
  | 線形モデル | `lm` (formula とデータフレーム、または行列で渡す。`summary` の値も返す), `modelMatrix` (`model.matrix`), `confint`, `predict`。`glm` (行列で渡す形。R の `stats` のすべての族とリンク) と `glmSummary` (`summary.glm`)、`glmResiduals` (4 種類)、`glmHatvalues`、`glmRstandard`、`glmCooksDistance`、`glmPredict` (標準誤差つき)、`glmConfint` (プロファイル尤度、厳密な限界)、`glmAnova` (`anova.glm`) |
199
- | 混合モデル | `lmer` (lme4: REML と最尤法、相関のある変量効果と相関のない変量効果、交差と入れ子の群。`fixef`、`vcov`、`VarCorr`、`ranef`、`logLik`、`AIC`、`BIC`、`REMLcrit`、`isSingular`)、`lmerSummary`・`lmerContest`・`lmerAnova` (lmerTest: Satterthwaite の t 検定と F 検定、Type I/II/III の分散分析表。当てはめどうしの尤度比検定)。`@numero-uno-jpn/rstats/mixed` から import する |
206
+ | 混合モデル | `lmer` (lme4: REML と最尤法、相関のある変量効果と相関のない変量効果、交差と入れ子の群。`fixef`、`vcov`、`VarCorr`、`ranef`、`logLik`、`AIC`、`BIC`、`REMLcrit`、`isSingular`)、`lmerSummary`・`lmerContest`・`lmerAnova` (lmerTest: Satterthwaite の t 検定と F 検定、Type I/II/III の分散分析表。当てはめどうしの尤度比検定)、`glmer` (lme4: glm のすべての族、ラプラス近似と適応的 Gauss-Hermite 求積)、`glmerSummary`・`glmerAnova`・`glmerPredict`・`lmerPredict`。`@numero-uno-jpn/rstats/mixed` から import する |
200
207
  | ほかの検定 | `leveneTest`、`propTrendTest` (`prop.trend.test`)、`jonckheereTest`、`cochranQTest`、`adTest`、`lillieTest`、`cvmTest`、`sfTest`、`pearsonTest` (car、DescTools、clinfun、nortest) |
201
208
  | 多重比較 | `dscfAllPairsTest` (Steel-Dwass)、`kwAllPairsDunnTest`、`kwManyOneDunnTest`、`manyOneUTest` (Steel の多対一の順位検定)、`dunnettTest`、`gamesHowellTest`、`tukeyTest` (PMCMRplus)、`dunnTest` (dunn.test)、`glhtDunnett` (multcomp) |
202
209
  | 生存時間解析 | `survdiff` (log-rank)、`survfit` (Kaplan-Meier。信頼区間と中央値)、`coxph` (Cox 回帰。Efron と Breslow のタイの扱い、ケースの重み、層、Wald・尤度比・スコア検定) |
@@ -233,9 +240,11 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
233
240
  - 添字は 0 から始まります。`sampleInt(n)` は `0..n-1` を返します (R の `sample.int()` から 1 を
234
241
  引いた値で、乱数の列は同じ)。`qr` と `chol` のピボットも 0 から始まります。
235
242
  - 固有ベクトルと特異ベクトルの符号が R と違うことがあります (どちらも正しい答えです)。
236
- - R の警告を表示することはありません。数値の欄と手法の名前はすべて一致します。モデル (`lm`、`glm`、`lmer`、
237
- `aov`、`anova`、`Anova`、`aovEz`、`coxph`) と一部の検定・効果量・検出力の計算は、R の警告を結果の `warnings`
238
- に入れて返します。
243
+ - 数値の欄と手法の名前はすべて一致します。R の警告は既定では表示しませんが、検定・モデル・当てはめはすべて、
244
+ 結果の `warnings` に入れて返します (R の文言で、同じ警告は 1 回ずつ。なければ `[]`)。R のように表示するには
245
+ handler を設定します。handler は、呼び出しの警告を 1 つずつ、呼んだ関数の名前とともに受け取ります:
246
+ `setWarningHandler((message, source) => console.warn(source + ": " + message))`。handler の中で throw すれば
247
+ R の `options(warn = 2)` の代わりになり、`setWarningHandler(null)` で止まります。
239
248
  - 結果が定義されない入力はエラーにします。R が NaN や意味のない値を返す場合も同じです (たとえば不一致の
240
249
  組がない表の `mcnemarTest`、NaN を含む行列の `lu`)。分布の関数 (d/p/q/r) は、R と同じく不正な母数に NaN を返します。
241
250
  [全般的な違い](docs/ja/differences-from-r.md#全般)を見てください。
@@ -243,8 +252,8 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
243
252
  投げます。正確な検定では `exact: false` を案内します。R はその多くを、時間がかかっても計算します。
244
253
  [上限](docs/ja/performance.md#上限)を見てください。
245
254
  - 分布の母数は、ベクトルとして使い回されません (リサイクルしない)。
246
- - `lmer` は基準の厳密な最適点を返します。lme4 の最適化はそこへ許容誤差の範囲でしか近づきません。
247
- また、lme4 の収束の警告は出しません。
255
+ - `lmer` と `glmer` は基準の厳密な最適点を返します。lme4 の最適化はそこへ許容誤差の範囲でしか近づきません。
256
+ また、lme4 の収束の警告は出しません。`nAGQ > 1` の `glmer` の対数尤度は真の値です (lme4 は定数を落とします)。
248
257
 
249
258
  すべての違いは [docs/ja/differences-from-r.md](docs/ja/differences-from-r.md) にあります。
250
259
 
@@ -255,29 +264,30 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
255
264
 
256
265
  | import するもの | gzip |
257
266
  |---|---|
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 |
267
+ | `pnorm` | 1.6 KB |
268
+ | `setSeed`, `rnorm` | 2.0 KB |
269
+ | `solve` / `svd` / `eigen` | 2.4 / 2.4 / 5.1 KB |
270
+ | `wilcoxTest` / `fisherTest` / `tTest` | 16.4 / 27.7 / 31.0 KB |
271
+ | `qbeta` / `pt` と `qt` | 43.5 / 40.0 KB |
272
+ | `glm` と `glmSummary` / `glm` とそのすべての関数 | 35.0 / 50.9 KB |
273
+ | `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 19.4 / 69.5 KB |
274
+ | `glmer` (`/mixed` から) / `glmerSummary`・`glmerAnova`・`glmerPredict` も | 47.1 / 65.6 KB |
275
+ | すべて (`/mixed` を除く) | 248.9 KB |
266
276
 
267
277
  (`npm run size` で測れます。)
268
278
 
269
279
  分野ごとにサブパスからも export しているので、1 つの分野だけを import することもできます。
270
280
  `@numero-uno-jpn/rstats/distributions`、`/tests` (検定、`lm`・`confint`・`predict`、`glm` とその関数)、`/linalg`、
271
- `/descriptive`、`/numerics`、`/special`、`/mixed` です (`/mixed` の `lmer` と lmerTest の検定は、この方法でしか import
281
+ `/descriptive`、`/numerics`、`/special`、`/mixed` です (`/mixed` の `lmer`・`glmer` とその関数は、この方法でしか import
272
282
  できません。メインの入口には含めていません)。
273
283
 
274
284
  バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (`/mixed` 以外のすべての関数を含む
275
- minify 済みの ES モジュール、gzip で 241 KB) を jsDelivr から読み込めます。jsDelivr は、npm のリリースを
285
+ minify 済みの ES モジュール、gzip で 249 KB) を jsDelivr から読み込めます。jsDelivr は、npm のリリースを
276
286
  そのまま配信します。
277
287
 
278
288
  ```html
279
289
  <script type="module">
280
- import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.16.0/dist/rstats.js";
290
+ import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.0.0/dist/rstats.js";
281
291
  console.log(pnorm(1.96)); // ≈ 0.9750021049
282
292
  </script>
283
293
  ```
@@ -293,7 +303,12 @@ minify 済みの ES モジュール、gzip で 241 KB) を jsDelivr から読み
293
303
  `dist/tests.js`、`dist/linalg.js`、`dist/descriptive.js`、`dist/numerics.js`、`dist/special.js`、
294
304
  `dist/mixed.js` は上のサブパスと同じ関数を export し、共通のコードを `dist/chunks/` で共有します。そのため、
295
305
  2 つの分野を読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で
296
- 37 KB (`numerics`) から 200 KB (`tests`) です。
306
+ 38 KB (`special`) から 206 KB (`tests`) です。
307
+
308
+ 1 つのページでは、`dist/rstats.js` か分野ごとのバンドルのどちらか一方だけを使ってください。両者は別々の
309
+ モジュールの集まりなので、混ぜると共通のコードが 2 回読み込まれ、乱数の状態も 2 つになります (一方の `setSeed`
310
+ は他方の乱数に効きません)。`dist/rstats.js` と `dist/mixed.js` を一緒に読み込む場合も、`dist/mixed.js` は
311
+ 共通のコードを別に持ち込みます。
297
312
 
298
313
  npm を元にしたほかの CDN も使えます。たとえば `https://esm.sh/@numero-uno-jpn/rstats` です。ビルド結果
299
314
  (`dist/`) は main ブランチにはなく、リリースのタグにも入っていますが、jsDelivr の GitHub 経由の配信
@@ -313,7 +328,26 @@ npm を元にしたほかの CDN も使えます。たとえば `https://esm.sh/
313
328
  ## 版の番号
314
329
 
315
330
  版が 0.x の間は、minor の版で互換性のない変更が入ることがあります。その場合は変更履歴に
316
- 書きます。1.0.0 からは Semantic Versioning に従います。
331
+ 書きます。
332
+
333
+ 1.0.0 からは Semantic Versioning に従います。公開 API は、パッケージのルートとサブパスが export するもので、
334
+ 文書にある名前・引数・オプション・結果のフィールドとそれらの型を含みます。
335
+
336
+ - **major** (互換性のない変更): export・オプション・結果のフィールドの削除や改名、既定値や結果の形の変更、
337
+ 値を返していた入力でエラーにすること、エラーの型 (`TypeError`、`RangeError`、`SyntaxError`、`Error`) の変更、
338
+ 計算量の上限を厳しくすること、まだサポートされている Node.js の版を外すこと。
339
+ - **minor**: 関数・オプション・オーバーロード・結果のフィールドの追加、エラーだった入力を受け付けること、
340
+ 計算量の上限を緩めること、R (または従っているパッケージ) が誤る範囲で正しい値に変えること
341
+ ([docs/ja/differences-from-r.md](docs/ja/differences-from-r.md) に記録します)。
342
+ - **patch**: 不具合の修正 (R や厳密な値に近づく値の変化を含みます。最後のビットの変化は互換性のない変更として
343
+ 扱いません) と、文書の変更。
344
+ - API に含めないもの: エラーのメッセージ、キーの順、`warnings` と `messages` の中身、列挙できないフィールドや
345
+ 文書にないフィールド、`dist/` のうちエントリポイントと `dist/*.js` のバンドル以外のファイル。R の新しい版が
346
+ R 自身の値や乱数の列を変えたときは、rStats.js も minor の版でそれに合わせます。
347
+ - 結果のフィールドで分岐するコードは、フィールドが増えることを前提にしてください。
348
+ - オプションのオブジェクトに関数の知らないキーがあると RangeError になります (`optim` の `control` のような入れ子の
349
+ オブジェクトも同じ)。綴りを誤ったオプションが黙って無視されることはありません。このため、オプションの追加は
350
+ minor の変更です (追加するキーは、それまではエラーでした)。
317
351
 
318
352
  ## 貢献
319
353
 
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.4 KB gzipped).
15
+ (`pnorm` alone is 1.6 KB gzipped).
16
16
 
17
- Status: **0.16.0.** The goal is to cover the numerical core of R's
17
+ Status: **1.0.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
 
@@ -118,7 +118,7 @@ aovEz(long, { id: "id", dv: "y", within: "W" }).anova.table[0];
118
118
  // ≈ [1.735, 6.940, 0.21653, 35.876, 0.84607, 0.00026363] (num Df, den Df, MSE, F, ges, p; GG-corrected)
119
119
  ```
120
120
 
121
- ### Linear mixed models
121
+ ### Mixed models
122
122
 
123
123
  `lmer` fits lme4's linear mixed models by REML or maximum likelihood. It is in its own area,
124
124
  `@numero-uno-jpn/rstats/mixed` (`dist/mixed.js` on a CDN), not in the single-file bundle.
@@ -152,6 +152,14 @@ components agree with lme4 to about 5 to 9 significant digits and the fixed effe
152
152
  (computed with exact derivatives at that optimum; lmerTest differentiates numerically at lme4's) and the Type I,
153
153
  II and III ANOVA tables; `lmerAnova([fit1, fit2])` compares fits by likelihood-ratio tests, as lme4's `anova()`.
154
154
 
155
+ `glmer` fits lme4's generalized linear mixed models (binomial, poisson, Gamma, inverse.gaussian and gaussian families
156
+ with their links) by the Laplace approximation, or by adaptive Gauss-Hermite quadrature (`nAGQ` 2 to 100) for a
157
+ single scalar random-effects term: `glmer("y ~ x + (1 | g)", d, { family: "poisson" })`. `glmerSummary` gives the
158
+ coefficient table with p-values, `glmerAnova` the ANOVA table or the likelihood-ratio comparison of glmer, lmer and
159
+ glm fits, and `glmerPredict` and `lmerPredict` the predictions (at new data, with some or none of the random
160
+ effects, with standard errors). As for `lmer`, the estimates are the exact optimum; see the
161
+ [differences](docs/differences-from-r.md#mixed-models) for the standard errors and `nAGQ > 1`.
162
+
155
163
  ### Effect sizes and power
156
164
 
157
165
  ```ts
@@ -189,11 +197,11 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
189
197
  | Distributions (d/p/q) | normal, t, chi-squared, F, beta, gamma, binomial, Poisson, uniform, exponential, log-normal, logistic, Cauchy, Weibull, geometric, negative binomial, hypergeometric, Wilcoxon signed rank and rank sum, studentized range (`ptukey`, `qtukey`), non-central chi-squared, t, F and beta (`ncp`); the multinomial probability (`dmultinom`); inverse gamma, Kumaraswamy, Pareto, triangular, Laplace (extraDistr) and arcsine; `distSummary` (mean, variance, sd, median, mode, skewness, kurtosis) |
190
198
  | Random numbers | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister and L'Ecuyer-CMRG, `sample.kind` Rejection and Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 `r*` functions, `sample`, `sampleInt` (`sample.int`), `r2dtable` |
191
199
  | Descriptive statistics | `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` |
192
- | Hypothesis tests | `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` (one way), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
200
+ | Hypothesis tests | `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` (one way, a fit whose table is `aovSummary`), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
193
201
  | Analysis of variance | `aov` and `aovSummary` with a formula (several factors, interactions, covariates, `Error()` strata), `anova` (`anova.lm`, sequential and model comparison), `Anova` (car: types II and III), `aovEz` (afex: repeated-measures and mixed designs, Greenhouse-Geisser and Huynh-Feldt corrections, generalized and partial eta squared), `mauchlyTest` (`mauchly.test`) |
194
202
  | Effect sizes and power | `cohensD`, `hedgesG` (effectsize, with exact confidence limits), `etaSquared`, `omegaSquared`, `epsilonSquared` (partial, generalized, from `anova` and `Anova` tables); `powerTTest`, `powerPropTest`, `powerAnovaTest` (`power.*.test`); `pwrTTest`, `pwrT2nTest`, `pwr2pTest`, `pwr2p2nTest`, `pwrPTest`, `pwrNormTest`, `pwrRTest`, `pwrChisqTest`, `pwrAnovaTest`, `pwrF2Test`, `esH`, `esW1`, `esW2`, `cohenES` (pwr) |
195
203
  | Linear models | `lm` (a formula and a data frame, or a matrix, with the `summary` quantities), `modelMatrix` (`model.matrix`), `confint`, `predict`; `glm` (matrix interface, every family and link of R's `stats`) with `glmSummary` (`summary.glm`), `glmResiduals` (the four kinds), `glmHatvalues`, `glmRstandard`, `glmCooksDistance`, `glmPredict` (with standard errors), `glmConfint` (profile likelihood, exact limits), `glmAnova` (`anova.glm`) |
196
- | Mixed models | `lmer` (lme4: REML and ML, correlated and uncorrelated random effects, crossed and nested grouping factors; `fixef`, `vcov`, `VarCorr`, `ranef`, `logLik`, `AIC`, `BIC`, `REMLcrit`, `isSingular`), `lmerSummary`, `lmerContest` and `lmerAnova` (lmerTest: Satterthwaite's t- and F-tests, Type I/II/III ANOVA tables; likelihood-ratio comparison of fits), from `@numero-uno-jpn/rstats/mixed` |
204
+ | Mixed models | `lmer` (lme4: REML and ML, correlated and uncorrelated random effects, crossed and nested grouping factors; `fixef`, `vcov`, `VarCorr`, `ranef`, `logLik`, `AIC`, `BIC`, `REMLcrit`, `isSingular`), `lmerSummary`, `lmerContest` and `lmerAnova` (lmerTest: Satterthwaite's t- and F-tests, Type I/II/III ANOVA tables; likelihood-ratio comparison of fits), `glmer` (lme4: all glm families, Laplace approximation and adaptive Gauss-Hermite quadrature), `glmerSummary`, `glmerAnova`, `glmerPredict` and `lmerPredict`, from `@numero-uno-jpn/rstats/mixed` |
197
205
  | More tests | `leveneTest`, `propTrendTest` (`prop.trend.test`), `jonckheereTest`, `cochranQTest`, `adTest`, `lillieTest`, `cvmTest`, `sfTest`, `pearsonTest` (car, DescTools, clinfun, nortest) |
198
206
  | Multiple comparisons | `dscfAllPairsTest` (Steel-Dwass), `kwAllPairsDunnTest`, `kwManyOneDunnTest`, `manyOneUTest` (Steel's many-one rank test), `dunnettTest`, `gamesHowellTest`, `tukeyTest` (PMCMRplus), `dunnTest` (dunn.test), `glhtDunnett` (multcomp) |
199
207
  | 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) |
@@ -229,9 +237,11 @@ everyday use:
229
237
  - Indices are 0-based: `sampleInt(n)` returns `0..n-1` (R's `sample.int()` minus 1, from the
230
238
  same random stream), and pivots of `qr` and `chol` are 0-based.
231
239
  - Signs of eigenvectors and singular vectors may differ from R (both are correct).
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`).
240
+ - All numeric fields and method names match. R's warnings are not printed by default, but every test, model and fit
241
+ returns them in its result (`warnings`: R's text, each distinct warning once, `[]` when there are none). To print
242
+ them as R does, set a handler, which receives each warning of a call once with the name of the function called:
243
+ `setWarningHandler((message, source) => console.warn(source + ": " + message))`. A handler that throws plays the
244
+ part of R's `options(warn = 2)`, and `setWarningHandler(null)` stops it.
235
245
  - Input for which the result is not defined is an error, also where R returns NaN or a meaningless value (for
236
246
  example `mcnemarTest` on a table without discordant pairs, or `lu` of a matrix with NaN). The distribution
237
247
  functions (d/p/q/r) return NaN for invalid parameters, as R. See
@@ -240,8 +250,9 @@ everyday use:
240
250
  a RangeError before it starts; the exact tests suggest `exact: false`. R computes most of these however long they
241
251
  take. See [Limits](docs/performance.md#limits).
242
252
  - Distribution parameters are not recycled as vectors.
243
- - `lmer` returns the exact optimum of its criterion, which lme4's optimiser approaches only to its tolerances, and
244
- does not emit lme4's convergence warnings.
253
+ - `lmer` and `glmer` return the exact optimum of their criterion, which lme4's optimiser approaches only to its
254
+ tolerances, and do not emit lme4's convergence warnings. For `nAGQ > 1`, `glmer`'s log-likelihood is the true one
255
+ (lme4 leaves out a constant).
245
256
 
246
257
  Full list: [docs/differences-from-r.md](docs/differences-from-r.md).
247
258
 
@@ -252,28 +263,29 @@ removed. Approximate sizes after minification and gzip:
252
263
 
253
264
  | Import | gzip |
254
265
  |---|---|
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 |
266
+ | `pnorm` | 1.6 KB |
267
+ | `setSeed`, `rnorm` | 2.0 KB |
268
+ | `solve` / `svd` / `eigen` | 2.4 / 2.4 / 5.1 KB |
269
+ | `wilcoxTest` / `fisherTest` / `tTest` | 16.4 / 27.7 / 31.0 KB |
270
+ | `qbeta` / `pt` and `qt` | 43.5 / 40.0 KB |
271
+ | `glm` and `glmSummary` / `glm` with all its methods | 35.0 / 50.9 KB |
272
+ | `lmer` (from `/mixed`) / with `lmerSummary`, `lmerContest`, `lmerAnova` | 19.4 / 69.5 KB |
273
+ | `glmer` (from `/mixed`) / with `glmerSummary`, `glmerAnova`, `glmerPredict` | 47.1 / 65.6 KB |
274
+ | everything (except `/mixed`) | 248.9 KB |
263
275
 
264
276
  (`npm run size` measures these.)
265
277
 
266
278
  Each area is also a subpath export, for importing one area without the rest:
267
279
  `@numero-uno-jpn/rstats/distributions`, `/tests` (hypothesis tests, `lm`, `confint` and
268
280
  `predict`, and `glm` with its methods), `/linalg`, `/descriptive`, `/numerics`, `/special` and `/mixed`
269
- (`lmer` and lmerTest's tests; this area is only available this way, not from the main entry point).
281
+ (`lmer`, `glmer` and their methods; this area is only available this way, not from the main entry point).
270
282
 
271
283
  Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
272
- function except those of `/mixed`, 241 KB gzipped) from jsDelivr, which serves each npm release:
284
+ function except those of `/mixed`, 249 KB gzipped) from jsDelivr, which serves each npm release:
273
285
 
274
286
  ```html
275
287
  <script type="module">
276
- import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.16.0/dist/rstats.js";
288
+ import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.0.0/dist/rstats.js";
277
289
  console.log(pnorm(1.96)); // ≈ 0.9750021049
278
290
  </script>
279
291
  ```
@@ -289,7 +301,12 @@ A page that needs only some areas can load the per-area bundles instead: `dist/d
289
301
  `dist/tests.js`, `dist/linalg.js`, `dist/descriptive.js`, `dist/numerics.js`, `dist/special.js` and
290
302
  `dist/mixed.js` export the same functions as the subpaths above, and share their common code through
291
303
  `dist/chunks/`, so loading two areas does not load that code twice. With its chunks, one area
292
- transfers 37 KB (`numerics`) to 200 KB (`tests`) gzipped.
304
+ transfers 38 KB (`special`) to 206 KB (`tests`) gzipped.
305
+
306
+ Use either `dist/rstats.js` or the per-area bundles on one page, not both: they are separate sets of modules, so a
307
+ page that mixes them loads the common code twice and has two random number states (`setSeed` from one does not seed
308
+ the generators of the other). The same holds for `dist/rstats.js` with `dist/mixed.js`, which brings its own copy
309
+ of the common code.
293
310
 
294
311
  Other npm-based CDNs work as well, for example `https://esm.sh/@numero-uno-jpn/rstats`. Release tags also contain
295
312
  the build output (`dist/`), which is not on the main branch, but jsDelivr's GitHub route
@@ -309,7 +326,27 @@ with a static server (for example `npx serve .`) and open `/demo/?src=local`.
309
326
  ## Versioning
310
327
 
311
328
  While the version is 0.x, a minor release may contain breaking changes; they are listed in the
312
- changelog. From 1.0.0 the project follows Semantic Versioning.
329
+ changelog.
330
+
331
+ From 1.0.0, rStats.js follows Semantic Versioning. The public API is what the package root and its subpaths export,
332
+ with the documented names, arguments, options, result fields and their types.
333
+
334
+ - **Major** (breaking): removing or renaming an export, an option or a result field; changing a default or the shape
335
+ of a result; throwing for an input that used to return a value, or changing the class of an error
336
+ (`TypeError`, `RangeError`, `SyntaxError`, `Error`); a tighter computation limit; dropping a Node.js version that
337
+ is still supported.
338
+ - **Minor**: new functions, options, overloads or result fields; accepting an input that used to throw; a looser
339
+ computation limit; a value that changes because R (or the package followed) is wrong there and the new value is the
340
+ correct one, recorded in [docs/differences-from-r.md](docs/differences-from-r.md).
341
+ - **Patch**: bug fixes, including values that move toward R or toward the exact result (changes in the last bits
342
+ are not breaking), and changes to documentation.
343
+ - Not part of the API: error messages, the order of keys, the contents of `warnings` and `messages`, non-enumerable
344
+ or undocumented fields, and files under `dist/` other than the entry points and the `dist/*.js` bundles. Where a
345
+ new version of R changes its own values or random streams, rStats.js follows it in a minor version.
346
+ - Code that switches on result fields should allow fields to be added.
347
+ - A key of an options object that the function does not know is a RangeError (also in a nested object such as
348
+ `optim`'s `control`), so a misspelt option cannot be ignored without a sign. A new option is therefore a minor
349
+ change: the key it adds was an error before.
313
350
 
314
351
  ## Contributing
315
352
 
@@ -1,2 +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 */
1
+ /*! rStats.js 1.0.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
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};