@numero-uno-jpn/rstats 0.0.0-stage → 0.6.1

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 (292) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/LICENSE +21 -0
  3. package/README.ja.md +197 -0
  4. package/README.md +188 -2
  5. package/THIRD_PARTY_NOTICES.md +317 -0
  6. package/dist/chunks/chunk-2JCIB5H2.js +2 -0
  7. package/dist/chunks/chunk-7JVSDGQQ.js +2 -0
  8. package/dist/chunks/chunk-7NK4SA6B.js +2 -0
  9. package/dist/chunks/chunk-AJYQNFXK.js +2 -0
  10. package/dist/chunks/chunk-DRNMIEYH.js +2 -0
  11. package/dist/chunks/chunk-NAYDS7CL.js +2 -0
  12. package/dist/chunks/chunk-NOCEAM44.js +2 -0
  13. package/dist/chunks/chunk-QNAIK4PY.js +2 -0
  14. package/dist/chunks/chunk-TPC6MTYC.js +2 -0
  15. package/dist/chunks/chunk-UGUQYWRQ.js +2 -0
  16. package/dist/chunks/chunk-XM2TVD63.js +2 -0
  17. package/dist/chunks/chunk-Y4IZV7XK.js +2 -0
  18. package/dist/chunks/chunk-ZWJ42QN6.js +2 -0
  19. package/dist/descriptive/basic.d.ts +73 -0
  20. package/dist/descriptive/basic.js +256 -0
  21. package/dist/descriptive/cov.d.ts +39 -0
  22. package/dist/descriptive/cov.js +105 -0
  23. package/dist/descriptive/hist.d.ts +64 -0
  24. package/dist/descriptive/hist.js +304 -0
  25. package/dist/descriptive/moments.d.ts +63 -0
  26. package/dist/descriptive/moments.js +158 -0
  27. package/dist/descriptive/quantile.d.ts +50 -0
  28. package/dist/descriptive/quantile.js +131 -0
  29. package/dist/descriptive/rank.d.ts +23 -0
  30. package/dist/descriptive/rank.js +72 -0
  31. package/dist/descriptive/table.d.ts +54 -0
  32. package/dist/descriptive/table.js +160 -0
  33. package/dist/descriptive.js +2 -0
  34. package/dist/distributions/arcsine.d.ts +24 -0
  35. package/dist/distributions/arcsine.js +73 -0
  36. package/dist/distributions/beta.d.ts +62 -0
  37. package/dist/distributions/beta.js +246 -0
  38. package/dist/distributions/binomial.d.ts +41 -0
  39. package/dist/distributions/binomial.js +136 -0
  40. package/dist/distributions/cauchy.d.ts +34 -0
  41. package/dist/distributions/cauchy.js +139 -0
  42. package/dist/distributions/chisq.d.ts +42 -0
  43. package/dist/distributions/chisq.js +60 -0
  44. package/dist/distributions/exponential.d.ts +34 -0
  45. package/dist/distributions/exponential.js +93 -0
  46. package/dist/distributions/f.d.ts +47 -0
  47. package/dist/distributions/f.js +214 -0
  48. package/dist/distributions/gamma.d.ts +61 -0
  49. package/dist/distributions/gamma.js +188 -0
  50. package/dist/distributions/geometric.d.ts +38 -0
  51. package/dist/distributions/geometric.js +116 -0
  52. package/dist/distributions/hypergeometric.d.ts +38 -0
  53. package/dist/distributions/hypergeometric.js +234 -0
  54. package/dist/distributions/invgamma.d.ts +29 -0
  55. package/dist/distributions/invgamma.js +85 -0
  56. package/dist/distributions/kumaraswamy.d.ts +17 -0
  57. package/dist/distributions/kumaraswamy.js +96 -0
  58. package/dist/distributions/laplace.d.ts +23 -0
  59. package/dist/distributions/laplace.js +69 -0
  60. package/dist/distributions/logistic.d.ts +36 -0
  61. package/dist/distributions/logistic.js +94 -0
  62. package/dist/distributions/lognormal.d.ts +39 -0
  63. package/dist/distributions/lognormal.js +158 -0
  64. package/dist/distributions/multinomial.d.ts +24 -0
  65. package/dist/distributions/multinomial.js +70 -0
  66. package/dist/distributions/nbeta.d.ts +7 -0
  67. package/dist/distributions/nbeta.js +330 -0
  68. package/dist/distributions/nchisq.d.ts +3 -0
  69. package/dist/distributions/nchisq.js +234 -0
  70. package/dist/distributions/negbinomial.d.ts +54 -0
  71. package/dist/distributions/negbinomial.js +325 -0
  72. package/dist/distributions/normal.d.ts +66 -0
  73. package/dist/distributions/normal.js +184 -0
  74. package/dist/distributions/nt.d.ts +3 -0
  75. package/dist/distributions/nt.js +491 -0
  76. package/dist/distributions/pareto.d.ts +23 -0
  77. package/dist/distributions/pareto.js +76 -0
  78. package/dist/distributions/poisson.d.ts +41 -0
  79. package/dist/distributions/poisson.js +104 -0
  80. package/dist/distributions/signrank.d.ts +38 -0
  81. package/dist/distributions/signrank.js +216 -0
  82. package/dist/distributions/summary.d.ts +25 -0
  83. package/dist/distributions/summary.js +289 -0
  84. package/dist/distributions/t.d.ts +49 -0
  85. package/dist/distributions/t.js +235 -0
  86. package/dist/distributions/triangular.d.ts +25 -0
  87. package/dist/distributions/triangular.js +87 -0
  88. package/dist/distributions/tukey.d.ts +43 -0
  89. package/dist/distributions/tukey.js +985 -0
  90. package/dist/distributions/uniform.d.ts +36 -0
  91. package/dist/distributions/uniform.js +90 -0
  92. package/dist/distributions/weibull.d.ts +37 -0
  93. package/dist/distributions/weibull.js +125 -0
  94. package/dist/distributions/wilcox.d.ts +47 -0
  95. package/dist/distributions/wilcox.js +270 -0
  96. package/dist/distributions.js +2 -0
  97. package/dist/entries/descriptive.d.ts +7 -0
  98. package/dist/entries/descriptive.js +8 -0
  99. package/dist/entries/distributions.d.ts +41 -0
  100. package/dist/entries/distributions.js +41 -0
  101. package/dist/entries/linalg.d.ts +11 -0
  102. package/dist/entries/linalg.js +11 -0
  103. package/dist/entries/numerics.d.ts +8 -0
  104. package/dist/entries/numerics.js +6 -0
  105. package/dist/entries/special.d.ts +9 -0
  106. package/dist/entries/special.js +9 -0
  107. package/dist/entries/tests.d.ts +21 -0
  108. package/dist/entries/tests.js +20 -0
  109. package/dist/htest/ansariTest.d.ts +13 -0
  110. package/dist/htest/ansariTest.js +80 -0
  111. package/dist/htest/aov.d.ts +85 -0
  112. package/dist/htest/aov.js +178 -0
  113. package/dist/htest/binomTest.d.ts +36 -0
  114. package/dist/htest/binomTest.js +121 -0
  115. package/dist/htest/chisqTest.d.ts +55 -0
  116. package/dist/htest/chisqTest.js +160 -0
  117. package/dist/htest/cor.d.ts +95 -0
  118. package/dist/htest/cor.js +437 -0
  119. package/dist/htest/core/ansari.d.ts +18 -0
  120. package/dist/htest/core/ansari.js +121 -0
  121. package/dist/htest/core/kolmogorov.d.ts +26 -0
  122. package/dist/htest/core/kolmogorov.js +221 -0
  123. package/dist/htest/core/mantelhaen.d.ts +26 -0
  124. package/dist/htest/core/mantelhaen.js +145 -0
  125. package/dist/htest/core/shapiro.d.ts +24 -0
  126. package/dist/htest/core/shapiro.js +142 -0
  127. package/dist/htest/core/smirnov.d.ts +20 -0
  128. package/dist/htest/core/smirnov.js +75 -0
  129. package/dist/htest/fisherTest.d.ts +48 -0
  130. package/dist/htest/fisherTest.js +482 -0
  131. package/dist/htest/groups.d.ts +20 -0
  132. package/dist/htest/groups.js +62 -0
  133. package/dist/htest/ksTest.d.ts +31 -0
  134. package/dist/htest/ksTest.js +106 -0
  135. package/dist/htest/mantelhaenTest.d.ts +26 -0
  136. package/dist/htest/mantelhaenTest.js +196 -0
  137. package/dist/htest/mcnemarTest.d.ts +26 -0
  138. package/dist/htest/mcnemarTest.js +99 -0
  139. package/dist/htest/onewayTest.d.ts +26 -0
  140. package/dist/htest/onewayTest.js +97 -0
  141. package/dist/htest/pAdjust.d.ts +34 -0
  142. package/dist/htest/pAdjust.js +147 -0
  143. package/dist/htest/pairwise.d.ts +64 -0
  144. package/dist/htest/pairwise.js +152 -0
  145. package/dist/htest/poissonTest.d.ts +35 -0
  146. package/dist/htest/poissonTest.js +170 -0
  147. package/dist/htest/propTest.d.ts +37 -0
  148. package/dist/htest/propTest.js +164 -0
  149. package/dist/htest/rankTests.d.ts +52 -0
  150. package/dist/htest/rankTests.js +234 -0
  151. package/dist/htest/tTest.d.ts +57 -0
  152. package/dist/htest/tTest.js +153 -0
  153. package/dist/htest/types.d.ts +51 -0
  154. package/dist/htest/types.js +26 -0
  155. package/dist/htest/varTest.d.ts +48 -0
  156. package/dist/htest/varTest.js +118 -0
  157. package/dist/htest/wilcoxTest.d.ts +61 -0
  158. package/dist/htest/wilcoxTest.js +433 -0
  159. package/dist/index.d.ts +6 -0
  160. package/dist/index.js +8 -0
  161. package/dist/integrate/quadpack.d.ts +29 -0
  162. package/dist/integrate/quadpack.js +525 -0
  163. package/dist/internal/ddexp.d.ts +19 -0
  164. package/dist/internal/ddexp.js +94 -0
  165. package/dist/internal/discrete.d.ts +14 -0
  166. package/dist/internal/discrete.js +85 -0
  167. package/dist/internal/dpq.d.ts +43 -0
  168. package/dist/internal/dpq.js +54 -0
  169. package/dist/internal/integer.d.ts +4 -0
  170. package/dist/internal/integer.js +17 -0
  171. package/dist/internal/invert.d.ts +36 -0
  172. package/dist/internal/invert.js +124 -0
  173. package/dist/internal/noncentral.d.ts +12 -0
  174. package/dist/internal/noncentral.js +2 -0
  175. package/dist/internal/poissonMixture.d.ts +31 -0
  176. package/dist/internal/poissonMixture.js +401 -0
  177. package/dist/internal/seq.d.ts +5 -0
  178. package/dist/internal/seq.js +14 -0
  179. package/dist/internal/summary.d.ts +21 -0
  180. package/dist/internal/summary.js +125 -0
  181. package/dist/internal/uniroot.d.ts +11 -0
  182. package/dist/internal/uniroot.js +14 -0
  183. package/dist/internal/vectorize.d.ts +12 -0
  184. package/dist/internal/vectorize.js +7 -0
  185. package/dist/linalg/basic.d.ts +95 -0
  186. package/dist/linalg/basic.js +152 -0
  187. package/dist/linalg/chol.d.ts +83 -0
  188. package/dist/linalg/chol.js +200 -0
  189. package/dist/linalg/eigen.d.ts +52 -0
  190. package/dist/linalg/eigen.js +753 -0
  191. package/dist/linalg/kappa.d.ts +51 -0
  192. package/dist/linalg/kappa.js +199 -0
  193. package/dist/linalg/lu.d.ts +45 -0
  194. package/dist/linalg/lu.js +88 -0
  195. package/dist/linalg/matrix.d.ts +29 -0
  196. package/dist/linalg/matrix.js +65 -0
  197. package/dist/linalg/norm.d.ts +32 -0
  198. package/dist/linalg/norm.js +92 -0
  199. package/dist/linalg/ops.d.ts +90 -0
  200. package/dist/linalg/ops.js +320 -0
  201. package/dist/linalg/qr.d.ts +264 -0
  202. package/dist/linalg/qr.js +494 -0
  203. package/dist/linalg/solve.d.ts +123 -0
  204. package/dist/linalg/solve.js +380 -0
  205. package/dist/linalg/svd.d.ts +38 -0
  206. package/dist/linalg/svd.js +275 -0
  207. package/dist/linalg.js +2 -0
  208. package/dist/models/lm.d.ts +98 -0
  209. package/dist/models/lm.js +187 -0
  210. package/dist/numerics/deriv.d.ts +37 -0
  211. package/dist/numerics/deriv.js +150 -0
  212. package/dist/numerics/integrate.d.ts +91 -0
  213. package/dist/numerics/integrate.js +264 -0
  214. package/dist/numerics/interp.d.ts +103 -0
  215. package/dist/numerics/interp.js +581 -0
  216. package/dist/numerics/ode.d.ts +23 -0
  217. package/dist/numerics/ode.js +59 -0
  218. package/dist/numerics.js +2 -0
  219. package/dist/optim/localmin.d.ts +16 -0
  220. package/dist/optim/localmin.js +97 -0
  221. package/dist/random/as241.d.ts +2 -0
  222. package/dist/random/as241.js +58 -0
  223. package/dist/random/beta.d.ts +14 -0
  224. package/dist/random/beta.js +117 -0
  225. package/dist/random/binomial.d.ts +25 -0
  226. package/dist/random/binomial.js +224 -0
  227. package/dist/random/common.d.ts +4 -0
  228. package/dist/random/common.js +35 -0
  229. package/dist/random/continuous.d.ts +91 -0
  230. package/dist/random/continuous.js +138 -0
  231. package/dist/random/extra.d.ts +33 -0
  232. package/dist/random/extra.js +62 -0
  233. package/dist/random/gamma.d.ts +52 -0
  234. package/dist/random/gamma.js +217 -0
  235. package/dist/random/hyper.d.ts +12 -0
  236. package/dist/random/hyper.js +240 -0
  237. package/dist/random/mt.d.ts +16 -0
  238. package/dist/random/mt.js +96 -0
  239. package/dist/random/poisson.d.ts +33 -0
  240. package/dist/random/poisson.js +203 -0
  241. package/dist/random/rank.d.ts +19 -0
  242. package/dist/random/rank.js +62 -0
  243. package/dist/random/rng.d.ts +46 -0
  244. package/dist/random/rng.js +148 -0
  245. package/dist/random/sample.d.ts +45 -0
  246. package/dist/random/sample.js +255 -0
  247. package/dist/rstats.js +2 -0
  248. package/dist/special/besselIK.d.ts +38 -0
  249. package/dist/special/besselIK.js +315 -0
  250. package/dist/special/besselJY.d.ts +32 -0
  251. package/dist/special/besselJY.js +508 -0
  252. package/dist/special/besselSeries.d.ts +8 -0
  253. package/dist/special/besselSeries.js +24 -0
  254. package/dist/special/beta.d.ts +30 -0
  255. package/dist/special/beta.js +169 -0
  256. package/dist/special/choose.d.ts +75 -0
  257. package/dist/special/choose.js +233 -0
  258. package/dist/special/constants.d.ts +16 -0
  259. package/dist/special/constants.js +19 -0
  260. package/dist/special/dd.d.ts +29 -0
  261. package/dist/special/dd.js +693 -0
  262. package/dist/special/erf.d.ts +35 -0
  263. package/dist/special/erf.js +112 -0
  264. package/dist/special/extra.d.ts +47 -0
  265. package/dist/special/extra.js +220 -0
  266. package/dist/special/gamma.d.ts +32 -0
  267. package/dist/special/gamma.js +270 -0
  268. package/dist/special/igam.d.ts +15 -0
  269. package/dist/special/igam.js +346 -0
  270. package/dist/special/igamAsympCoeff.d.ts +4 -0
  271. package/dist/special/igamAsympCoeff.js +233 -0
  272. package/dist/special/igami.d.ts +2 -0
  273. package/dist/special/igami.js +135 -0
  274. package/dist/special/incbet.d.ts +25 -0
  275. package/dist/special/incbet.js +381 -0
  276. package/dist/special/lgammaDiff.d.ts +9 -0
  277. package/dist/special/lgammaDiff.js +47 -0
  278. package/dist/special/loader.d.ts +43 -0
  279. package/dist/special/loader.js +456 -0
  280. package/dist/special/log1pmx.d.ts +2 -0
  281. package/dist/special/log1pmx.js +20 -0
  282. package/dist/special/ndtri.d.ts +4 -0
  283. package/dist/special/ndtri.js +82 -0
  284. package/dist/special/polevl.d.ts +4 -0
  285. package/dist/special/polevl.js +17 -0
  286. package/dist/special/psigamma.d.ts +48 -0
  287. package/dist/special/psigamma.js +318 -0
  288. package/dist/special/rCompatible.d.ts +8 -0
  289. package/dist/special/rCompatible.js +1 -0
  290. package/dist/special.js +2 -0
  291. package/dist/tests.js +2 -0
  292. package/package.json +93 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,144 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
+
6
+ While the version is 0.x, a minor release (0.y.0) may contain breaking changes;
7
+ they are listed under **Breaking** for each release. From 1.0.0 the project follows
8
+ [Semantic Versioning](https://semver.org/).
9
+
10
+ ## 0.6.1 - 2026-10-24
11
+
12
+ The first release of the 0.6 series on npm. A `v0.6.0` tag was pushed to GitHub earlier the same
13
+ day but never published to npm and has been withdrawn; use 0.6.1.
14
+
15
+ ### Added
16
+
17
+ - Everything jStat offers, with R's names and defaults, and a migration guide
18
+ ([docs/migrating-from-jstat.md](docs/migrating-from-jstat.md)) whose replacements are checked
19
+ against jStat itself (`test/jstat-replacement.test.ts`):
20
+ - descriptive statistics (`@numero-uno-jpn/rstats/descriptive`): `sum`, `prod`, `mean` (with `trim`),
21
+ `weightedMean`, `variance` (R's `var`), `sd`, `median`, `range`, `cumsum`, `cumprod`, `cummax`,
22
+ `cummin`, `diff`, `quantile` (all nine types), `IQR`, `fivenum`, `mad`, `rank`, `cov` and `cor`
23
+ for vectors and matrices (Pearson, Kendall, Spearman, with `use`), `tabulate`, `table`, `unique`,
24
+ `cut`, `findInterval`, `pretty`, `hist`, `ecdf`, `scale`, and `skewness`, `kurtosis` (e1071),
25
+ `geometricMean`, `modes`, `meanAD`, `cv` (DescTools); sums in double-double;
26
+ - matrix arithmetic: `matMul`, `add`, `subtract`, `multiply`, `divide`, `outer`, `t`, `diag`,
27
+ `cbind`, `rbind`, `matrix`, `kronecker`, `seq`, and `lu` (`Matrix::lu`) and `prcomp`;
28
+ - hypothesis tests: `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`,
29
+ `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`,
30
+ `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`,
31
+ `pairwiseWilcoxTest`, `pairwisePropTest`, `aov` (one way), `TukeyHSD` and `zTest` (BSDA);
32
+ - linear models: `lm` with a matrix interface and the quantities of `summary.lm`, `confint`,
33
+ `predict`;
34
+ - numerical methods (`@numero-uno-jpn/rstats/numerics`): `integrate`, `optimize`, `uniroot` (with
35
+ `extendInt`), `approx`, `spline`, `splinefun`, `splinefunH`, `barylag` (pracma),
36
+ `hermiteInterp`, `ode` (fixed-step, deSolve), `grad`, `jacobian`, `hessian` (numDeriv);
37
+ - distributions outside base R with extraDistr's names: `invgamma`, `kumar`, `pareto`, `triang`,
38
+ `laplace`, and `arcsine` (d/p/q/r), and `distSummary` (mean, variance, sd, median, mode,
39
+ skewness, kurtosis) for 23 distributions (all but signrank, wilcox and tukey);
40
+ - special functions: `gammainc`, `erfinv`, `erfcinv`, `perm`.
41
+ - Subpath exports and per-area CDN files: `@numero-uno-jpn/rstats/distributions`, `/tests`, `/linalg`,
42
+ `/descriptive`, `/numerics`, `/special` (`dist/<area>.js`, with shared code split out).
43
+ - `choose`, `lchoose`, `factorial` and `lfactorial`, for any real `n` (and `x`).
44
+ - `digamma`, `trigamma` and `psigamma` (derivatives up to 100, negative arguments by
45
+ reflection; unlike R, also for x < 0 with deriv ≥ 6).
46
+ - `besselI`, `besselK` (with `exponScaled`, R's `expon.scaled`), `besselJ` and `besselY` for any
47
+ real order, ported from Boost.Math.
48
+ - The option `rCompatible` of `choose`, `lchoose`, `trigamma` and `psigamma` (type
49
+ `RCompatibleOptions`): by default they follow R at its edge cases (n near an integer in
50
+ `choose`, infinite arguments); `rCompatible: false` returns the mathematical values there.
51
+ - `erf` and `erfc`, which R lacks (checked against mpmath). `erfc` is now accurate in the far tail:
52
+ it forms exp(-x^2) from an exact x^2 and no longer flushes subnormal results to 0.
53
+ - `dmultinom`, as a product of binomial probabilities (accurate for large counts).
54
+ - The new functions are checked against R 4.5.2, and against mpmath (100 to 800 digits) where R
55
+ is inaccurate or fails (docs/differences-from-r.md).
56
+
57
+ ### Changed
58
+
59
+ - Code that followed the GPL sources of R (and of BSDA, for `zTest`) too closely was re-implemented independently, so that the
60
+ package stays MIT licensed: `propTest`, the two-sided p-values of `poissonTest` and `binomTest`,
61
+ the exact 2 × 2 parts of `mantelhaenTest` and `fisherTest`, the intervals of `wilcoxTest`,
62
+ `zTest`, `approx`, `spline`, `splinefun`, `splinefunH`, `uniroot`, `seq`, `pretty`, `hist` and
63
+ `quantile`.
64
+ - `uniroot`'s zero finder is now a port of netlib's `zeroin.f` (public domain).
65
+ - **Type change:** `fStatistic` and `fPValue` of `lm`'s result are optional; they are absent for a
66
+ model with nothing beyond the intercept, as `summary.lm` has no `fstatistic` there.
67
+ - The error messages of `grad`, `jacobian`, `hessian` and `zTest` are worded differently.
68
+
69
+ ### Fixed
70
+
71
+ - `lbeta` and `beta` with an argument of 2^52 or more: `lbeta(1e17, 31)` was off by 20 and
72
+ `lbeta(1e100, 31)` returned 0.92 instead of -7063.
73
+
74
+ - Accuracy of the incomplete beta function behind `pbeta`, `pt`, `pf`, `pbinom` and `pnbinom`
75
+ (checked against mpmath). The 15 `pnbinom` cases that were excluded as known accuracy
76
+ problems now pass:
77
+ - results near 1e-308 kept their exponent only to double precision (up to 1.2e-13 relative);
78
+ - the continued fraction rounded a + b, losing the digits of a small b (up to 6e-11 relative,
79
+ e.g. `pnbinom(1e8, 0.01, mu = 1e4)`).
80
+ - With parameters of 2^52 or more the continued fraction stopped advancing its coefficients, and
81
+ a result could pass through a subnormal intermediate: `pnbinom` with q around 1e17 was off by
82
+ up to 1e-3 relative, and returned NaN in some cases.
83
+ - `pgamma` and `ppois` with a shape (or lambda) above about 1e6, 5 to 40 standard deviations below
84
+ the mean (lower tail of `pgamma`, upper tail of `ppois`): off by up to 2e-14 relative, now 2.7e-15.
85
+ The series is summed in double-double there, which makes those calls about 9 times slower.
86
+ - `pchisq` and `pbeta` with `ncp` around 1000 in the far tails: off by up to 1.4e-13 relative, now
87
+ below 5e-15 (the terms of the Poisson mixture are corrected to the exact shape a + j).
88
+ - Fixed since the withdrawn `v0.6.0` tag:
89
+ - `propTest` with missing groups and with `p`; `pairwisePropTest` with missing groups (dropped and
90
+ the rest renumbered, as in R);
91
+ - `uniroot` when `f` returns a non-finite value;
92
+ - default number of points and range of `spline`, now taken from the regularized x;
93
+ - the third derivative of `splinefunH` and of `splinefun` with `method: "monoH.FC"` is now the
94
+ exact one; R returns h times it on an interval of width h (see docs/differences-from-r.md);
95
+ - `lm` with weights of 0 (those rows are left out of the fit, all zero is an error) and with an
96
+ intercept-only model (R² = 0 and no F test, as in R);
97
+ - `optimize` with `lower >= upper` is now an error, as in R;
98
+ - a non-integer `deriv` (`splinefun`, `splinefunH`) is truncated and non-integer lengths (`n`)
99
+ are rounded up, as in R;
100
+ - `barylag` with duplicate nodes; `lu` forms its multipliers as LAPACK does;
101
+ - `TukeyHSD` comparison names (labels, or positions in the list; groups without data left out);
102
+ - `kruskalTest` and `flignerTest` with an empty group, `mcnemarTest` with different numbers of
103
+ levels in x and y, `bartlettTest` with infinite values, `poissonTest` with zero counts and
104
+ zero `T` or `r`, all now as in R;
105
+ - accuracy of `besselK` and `besselI` for orders near 2.5, the arcsine distribution near its
106
+ upper end, `gammainc` for large a, `perm` (overflow and non-integer k), the `distSummary` kurtosis of
107
+ `lnorm` for small sdlog, `psigamma` for large x, `beta` for huge a, and `choose` for
108
+ non-integer n;
109
+ - `pretty` no longer overflows for huge ranges.
110
+
111
+ ## 0.5.0 - 2026-10-21
112
+
113
+ First public version.
114
+
115
+ ### Included
116
+
117
+ - Special functions: `gamma`, `lgamma`, `beta`, `lbeta`.
118
+ - d/p/q functions with `lowerTail` and `logP` for the normal, t, chi-squared, F, beta, gamma,
119
+ binomial, Poisson, uniform, exponential, log-normal, logistic, Cauchy, Weibull, geometric,
120
+ negative binomial, hypergeometric, Wilcoxon signed rank and rank sum, and studentized range
121
+ distributions, and the non-central chi-squared, t, F and beta (`ncp`).
122
+ - Random numbers that reproduce R's `set.seed()` streams: `setSeed`, `getRandomSeed`,
123
+ `setRandomSeed`, 20 `r*` functions, `sample` and `sampleInt`.
124
+ - Hypothesis tests returning R's `htest` fields as plain objects: `tTest`, `chisqTest`,
125
+ `fisherTest` (including r × c tables), `wilcoxTest` (exact and normal approximation, with
126
+ confidence intervals), `cor`, `corTest` and `pAdjust`.
127
+ - Linear algebra on matrices given as arrays of rows: `crossprod`, `tcrossprod`, `norm`,
128
+ `backsolve`, `forwardsolve`, `chol`, `chol2inv`, `qr` (R's default limited pivoting and the
129
+ LAPACK variant) with `qrQ`, `qrR`, `qrX`, `qrCoef`, `qrQy`, `qrQty`, `qrResid`, `qrFitted`,
130
+ `qrSolve`, `solve`, `det`, `determinant`, `rcond`, `kappa`, `svd`, `eigen` (symmetric and
131
+ general, including complex eigenvalues) and `ginv`.
132
+
133
+ ### Conventions
134
+
135
+ - Indices are 0-based, matching JavaScript arrays: `sampleInt(n)` returns integers in `0..n-1`
136
+ (R's `sample.int()` minus 1, from the same random stream), and the `pivot` of `qr()` and of
137
+ `chol(x, { pivot: true })` is 0-based.
138
+ - Errors are thrown with English messages, and the class tells the kind of problem: `TypeError`
139
+ for wrong types or shapes, `RangeError` for values out of range, and `Error` for numerical
140
+ failures (singular matrix, not positive definite, no convergence, data essentially constant).
141
+ - A single-file minified ES module, `dist/rstats.js`, for loading from a CDN; release tags contain
142
+ the build output so that jsDelivr can serve it from GitHub.
143
+ - ESM only, no dependencies, tree-shakable. Requires Node.js 22 or later (or another ES2022
144
+ environment).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 numero-uno-jpn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.ja.md ADDED
@@ -0,0 +1,197 @@
1
+ # rStats.js
2
+
3
+ [English](README.md) | 日本語
4
+
5
+ > この文書は [英語版](README.md) の訳です。内容が食い違うときは英語版が正です。
6
+
7
+ JavaScript とブラウザで使える、R と互換の統計関数のライブラリです。TypeScript で書いています。
8
+ [ブラウザで試す](https://numero-uno-jpn.github.io/rStats.js/demo/) (すべての関数を、R が出す値と並べて試せます)。
9
+
10
+ - **R と同じ数値を返します。** 関数名・既定値・結果は R に合わせています。すべての関数を R 4.5.2 と
11
+ 比べてテストしています (分布関数は相対誤差 1e-14)。R 自身が不正確なところでは、高精度の参照値と
12
+ 比べています。
13
+ - **JavaScript らしい呼び出し方です。** 必須の引数は位置で渡し、省略できる引数は camelCase のキーを
14
+ 持つオブジェクトで渡します。`pt(q, df, { lowerTail: false })` は R の `pt(q, df, lower.tail = FALSE)` に
15
+ 当たります。結果は素のオブジェクトなので、そのまま `JSON.stringify` できます。
16
+ - **どこでも動きます。** ESM のみで、依存パッケージはなく、Node 専用の API も使っていません。
17
+ tree-shaking が効きます (`pnorm` だけなら gzip で 1.2 KB)。
18
+
19
+ 状態: **0.6.1。** R の stats パッケージの数値計算の中心
20
+ (分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
21
+ [ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
22
+
23
+ ## インストール
24
+
25
+ ```sh
26
+ npm install @numero-uno-jpn/rstats
27
+ ```
28
+
29
+ ES2022 の環境が必要です (現行のブラウザ、Node.js 22 以降、Deno、Bun)。
30
+
31
+ ## 使い方の例
32
+
33
+ ### 分布
34
+
35
+ ```ts
36
+ import { pnorm, qnorm, pt, qbeta, dbinom } from "@numero-uno-jpn/rstats";
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
44
+ ```
45
+
46
+ 最初の引数には数値・配列・`Float64Array` を渡せます。結果は同じ形で返ります。分布の母数はスカラーです。
47
+
48
+ ### `set.seed()` と同じ乱数
49
+
50
+ ```ts
51
+ import { setSeed, rnorm, sample } from "@numero-uno-jpn/rstats";
52
+
53
+ setSeed(42);
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)
56
+ ```
57
+
58
+ R で `set.seed(42); rnorm(3)` とすると、最後のビットまで同じ数値になります。
59
+
60
+ ### 検定
61
+
62
+ ```ts
63
+ import { tTest, fisherTest, pAdjust } from "@numero-uno-jpn/rstats";
64
+
65
+ 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]);
66
+ r.pValue; // 0.0035365308877675647 (Welch, the default in R)
67
+ r.confInt; // [0.4423253334608047, 1.6443413332058612]
68
+ r.method; // "Welch Two Sample t-test"
69
+
70
+ fisherTest([[3, 1], [1, 3]]).pValue; // 0.4857142857142857
71
+ pAdjust([0.01, 0.02, 0.03, 0.04], { method: "BH" }); // ≈ [0.04, 0.04, 0.04, 0.04]
72
+ ```
73
+
74
+ `tTest` の既定は、R と同じ Welch の検定です。
75
+
76
+ ### 線形代数
77
+
78
+ 行列は行の配列で表します。
79
+
80
+ ```ts
81
+ import { solve, qr, qrCoef, svd, eigen } from "@numero-uno-jpn/rstats";
82
+
83
+ solve([[2, 1], [1, 3]]); // [[0.6, -0.2], [-0.2, 0.4]]
84
+ const q = qr([[1, 1], [1, 2], [1, 3]]);
85
+ qrCoef(q, [1, 3, 4]); // ≈ [-0.333, 1.5] (least squares)
86
+ svd([[1, 4], [2, 5], [3, 6]]).d; // [9.50803200069572, 0.7728696356734838]
87
+ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
88
+ ```
89
+
90
+ ## 含まれるもの
91
+
92
+ | 分野 | 関数 (R と名前が違うものは括弧内が R の名前) |
93
+ |---|---|
94
+ | 特殊関数 | `gamma`, `lgamma`, `beta`, `lbeta`, `choose`, `lchoose`, `factorial`, `lfactorial`, `digamma`, `trigamma`, `psigamma`, `besselI`, `besselK`, `besselJ`, `besselY`。R にはない `erf`, `erfc`, `erfinv`, `erfcinv`, `gammainc`, `perm` も |
95
+ | 分布 (d/p/q) | 正規、t、カイ二乗、F、ベータ、ガンマ、二項、ポアソン、一様、指数、対数正規、ロジスティック、コーシー、ワイブル、幾何、負の二項、超幾何、Wilcoxon の符号付き順位と順位和、スチューデント化された範囲 (`ptukey`, `qtukey`)、非心カイ二乗・t・F・ベータ (`ncp`)。多項分布の確率 (`dmultinom`)。逆ガンマ、Kumaraswamy、Pareto、三角、Laplace (extraDistr) と逆正弦。`distSummary` (平均・分散・標準偏差・中央値・最頻値・歪度・尖度) |
96
+ | 乱数 | `setSeed` (`set.seed`), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), 26 個の `r*` 関数, `sample`, `sampleInt` (`sample.int`) |
97
+ | 記述統計 | `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` |
98
+ | 検定 | `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`, `pAdjust` (`p.adjust`) |
99
+ | 線形モデル | `lm` (行列で渡す形。`summary` の値も返す), `confint`, `predict` |
100
+ | 線形代数 | `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) |
101
+ | 数値計算 | `integrate`, `optimize`, `uniroot`, `approx`, `spline`, `splinefun`, `splinefunH`, `barylag`, `hermiteInterp`, `ode`, `grad`, `jacobian`, `hessian` |
102
+
103
+ jStat から移るときは [docs/ja/migrating-from-jstat.md](docs/ja/migrating-from-jstat.md) に jStat の全関数の置き換えがあります。
104
+
105
+ API リファレンスは `npm run docs` (TypeDoc) で作れます (英語)。
106
+
107
+ ## 精度
108
+
109
+ 正解の値は [`oracle/`](oracle) の R のスクリプトで作り、[`test/fixtures/`](test/fixtures) に
110
+ 保存してあります。そのため、テストは R がなくても動きます。各ケースは、R と一致するか、R が
111
+ 間違っているところでは Rmpfr や gmp で計算した高精度の値と一致すれば合格です。分布の裾の深い
112
+ ところや母数の大きいところでは、rStats.js のほうが R より正確なことがよくあります。指数部を
113
+ double-double 演算で計算しているためです。詳しくは [docs/ja/accuracy.md](docs/ja/accuracy.md) を
114
+ 見てください。
115
+
116
+ ## R との違い
117
+
118
+ 違いの多くは、R の精度が落ちるか、R が失敗するケースです。ふだんの使い方に関わる意図的な違いは
119
+ 次のとおりです。
120
+
121
+ - 添字は 0 から始まります。`sampleInt(n)` は `0..n-1` を返します (R の `sample.int()` から 1 を
122
+ 引いた値で、乱数の列は同じ)。`qr` と `chol` のピボットも 0 から始まります。
123
+ - 固有ベクトルと特異ベクトルの符号が R と違うことがあります (どちらも正しい答えです)。
124
+ - 検定は R の警告を出しません。数値の欄と手法の名前はすべて一致します。
125
+ - 分布の母数は、ベクトルとして使い回されません (リサイクルしない)。
126
+
127
+ すべての違いは [docs/ja/differences-from-r.md](docs/ja/differences-from-r.md) にあります。
128
+
129
+ ## ブラウザで使う
130
+
131
+ バンドラ (Vite、esbuild、webpack、Rollup) を使う場合は、関数を名前で import してください。
132
+ 使わない関数は取り除かれます。minify と gzip をした後のおおよその大きさは次のとおりです。
133
+
134
+ | import するもの | gzip |
135
+ |---|---|
136
+ | `pnorm` | 1.2 KB |
137
+ | `setSeed`, `rnorm` | 1.7 KB |
138
+ | `solve` / `svd` / `eigen` | 1.7 / 2.0 / 3.7 KB |
139
+ | `wilcoxTest` / `fisherTest` / `tTest` | 8.6 / 13.8 / 16.7 KB |
140
+ | `qbeta` / `pt` と `qt` | 18.5 / 25.5 KB |
141
+ | すべて | 112.4 KB |
142
+
143
+ (`npm run size` で測れます。)
144
+
145
+ 分野ごとにサブパスからも export しているので、1 つの分野だけを import することもできます。
146
+ `@numero-uno-jpn/rstats/distributions`、`/tests` (検定と、`lm`・`confint`・`predict`)、`/linalg`、
147
+ `/descriptive`、`/numerics`、`/special` です。
148
+
149
+ バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (すべての関数を含む minify 済みの
150
+ ES モジュール、gzip で 112 KB) を jsDelivr から読み込めます。jsDelivr は、このリポジトリのリリースの
151
+ タグをそのまま配信します。
152
+
153
+ ```html
154
+ <script type="module">
155
+ import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.6.1/dist/rstats.js";
156
+ console.log(pnorm(1.96)); // 0.9750021048517795
157
+ </script>
158
+ ```
159
+
160
+ 一部の分野だけを使うページでは、代わりに分野ごとのバンドルを読み込めます。`dist/distributions.js`、
161
+ `dist/tests.js`、`dist/linalg.js`、`dist/descriptive.js`、`dist/numerics.js`、`dist/special.js` は
162
+ 上のサブパスと同じ関数を export し、共通のコードを `dist/chunks/` で共有します。そのため、2 つの分野を
163
+ 読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で 18 KB
164
+ (`numerics`) から 80 KB (`tests`) です。
165
+
166
+ ビルド結果 (`dist/`) は main ブランチにはなく、リリースのタグにだけ入っています。npm を元にした CDN も
167
+ 使えます。たとえば
168
+ `https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.6.1/dist/rstats.js` や
169
+ `https://esm.sh/@numero-uno-jpn/rstats` です。
170
+
171
+ ブラウザ向けのビルドは、headless Chromium でテストしています。バンドラでまとめた場合と、
172
+ `dist/rstats.js` を ES モジュールとして読み込んだ場合の両方です (`npm run test:browser`)。
173
+
174
+ **デモ:** <https://numero-uno-jpn.github.io/rStats.js/demo/>。[`demo/`](demo) は、`dist/rstats.js` を jsDelivr から読み込んで、すべての関数を試せる
175
+ 静的なページです。確率分布 (グラフ付き)・特殊関数・乱数・検定・線形代数を扱います。各フォームには、
176
+ 入力に対応する R と JavaScript のコードが表示されます。「R との比較」のタブでは、例題の値を R が
177
+ 出力した値と照らし合わせます (`source("examples.R")` で、すべての例題を R で実行できます)。CDN の
178
+ 代わりに手元のビルドを使うには、`npm run build` をしてから、リポジトリのルートを静的サーバー
179
+ (たとえば `npx serve .`) で配信し、`/demo/?src=local` を開いてください。
180
+
181
+ ## 版の番号
182
+
183
+ 版が 0.x の間は、minor の版で互換性のない変更が入ることがあります。その場合は変更履歴に
184
+ 書きます。1.0.0 からは Semantic Versioning に従います。
185
+
186
+ ## 貢献
187
+
188
+ R との答え合わせの仕組みと、ライセンスの決まり (R や GPL のパッケージのコードは使わない) は
189
+ [CONTRIBUTING.ja.md](CONTRIBUTING.ja.md) にあります。速さと double-double 演算については
190
+ [docs/ja/performance.md](docs/ja/performance.md) にあります。
191
+
192
+ ## ライセンス
193
+
194
+ MIT です。数値計算の部品は、SciPy の xsf・scipy.stats・QUADPACK の C 訳 (BSD-3)、Boost.Math
195
+ (BSL-1.0)、statsmodels (BSD-3)、LAPACK の参照実装 (修正 BSD) から移植しています。パブリックドメインの
196
+ LINPACK・EISPACK・Cephes・QUADPACK・netlib のコードも使っています。詳しくは
197
+ [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) (英語) を見てください。
package/README.md CHANGED
@@ -1,3 +1,189 @@
1
- # Temporary Holding Version
1
+ # rStats.js
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ English | [日本語](README.ja.md)
4
+
5
+ R-compatible statistical functions for JavaScript and the browser, written in TypeScript.
6
+ [Try it in the browser](https://numero-uno-jpn.github.io/rStats.js/demo/) (every function, with the values R gives).
7
+
8
+ - **Same numbers as R.** Function names, defaults and results follow R. Every function is
9
+ tested against R 4.5.2 (relative error 1e-14 for distributions), and where R itself is
10
+ inaccurate, against high-precision reference values.
11
+ - **JavaScript-style calls.** Required arguments are positional, optional ones go in an object
12
+ with camelCase keys: `pt(q, df, { lowerTail: false })` is R's `pt(q, df, lower.tail = FALSE)`.
13
+ Results are plain objects that `JSON.stringify` cleanly.
14
+ - **Runs anywhere.** ESM only, no dependencies, no Node-specific APIs, tree-shakable
15
+ (`pnorm` alone is 1.2 KB gzipped).
16
+
17
+ Status: **0.6.1.** The goal is to cover the numerical core of R's
18
+ `stats` package (distributions, descriptive statistics, hypothesis tests, linear models, special
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
+
21
+ ## Install
22
+
23
+ ```sh
24
+ npm install @numero-uno-jpn/rstats
25
+ ```
26
+
27
+ Requires an ES2022 environment (current browsers, Node.js 22 or later, Deno, Bun).
28
+
29
+ ## Examples
30
+
31
+ ### Distributions
32
+
33
+ ```ts
34
+ import { pnorm, qnorm, pt, qbeta, dbinom } from "@numero-uno-jpn/rstats";
35
+
36
+ pnorm(1.96); // 0.9750021048517795
37
+ qnorm([0.025, 0.975]); // [-1.9599639845400545, 1.959963984540054]
38
+ pt(-40, 3); // 1.7190340394579263e-5
39
+ pt(2, 10, { lowerTail: false, logP: true }); // -3.3051415512324533 (log of the upper tail)
40
+ qbeta(1e-10, 2, 3); // 4.082494015808333e-6
41
+ dbinom(3, 10, 0.2); // 0.20132659200000003
42
+ ```
43
+
44
+ The first argument may be a number, an array or a `Float64Array`; the result has the same shape.
45
+ Distribution parameters are scalars.
46
+
47
+ ### Random numbers that match `set.seed()`
48
+
49
+ ```ts
50
+ import { setSeed, rnorm, sample } from "@numero-uno-jpn/rstats";
51
+
52
+ setSeed(42);
53
+ rnorm(3); // [1.3709584471466685, -0.5646981713960887, 0.3631284113373392]
54
+ // R: set.seed(42); rnorm(3) gives the same numbers (up to the last bit)
55
+ ```
56
+
57
+ ### Hypothesis tests
58
+
59
+ ```ts
60
+ import { tTest, fisherTest, pAdjust } from "@numero-uno-jpn/rstats";
61
+
62
+ 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]);
63
+ r.pValue; // 0.0035365308877675647 (Welch, the default in R)
64
+ r.confInt; // [0.4423253334608047, 1.6443413332058612]
65
+ r.method; // "Welch Two Sample t-test"
66
+
67
+ fisherTest([[3, 1], [1, 3]]).pValue; // 0.4857142857142857
68
+ pAdjust([0.01, 0.02, 0.03, 0.04], { method: "BH" }); // ≈ [0.04, 0.04, 0.04, 0.04]
69
+ ```
70
+
71
+ ### Linear algebra
72
+
73
+ Matrices are arrays of rows.
74
+
75
+ ```ts
76
+ import { solve, qr, qrCoef, svd, eigen } from "@numero-uno-jpn/rstats";
77
+
78
+ solve([[2, 1], [1, 3]]); // [[0.6, -0.2], [-0.2, 0.4]]
79
+ const q = qr([[1, 1], [1, 2], [1, 3]]);
80
+ qrCoef(q, [1, 3, 4]); // ≈ [-0.333, 1.5] (least squares)
81
+ svd([[1, 4], [2, 5], [3, 6]]).d; // [9.50803200069572, 0.7728696356734838]
82
+ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
83
+ ```
84
+
85
+ ## What is included
86
+
87
+ | Area | Functions (R names in parentheses where they differ) |
88
+ |---|---|
89
+ | Special functions | `gamma`, `lgamma`, `beta`, `lbeta`, `choose`, `lchoose`, `factorial`, `lfactorial`, `digamma`, `trigamma`, `psigamma`, `besselI`, `besselK`, `besselJ`, `besselY`; also `erf`, `erfc`, `erfinv`, `erfcinv`, `gammainc` and `perm`, which R lacks |
90
+ | 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) |
91
+ | Random numbers | `setSeed` (`set.seed`), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), 26 `r*` functions, `sample`, `sampleInt` (`sample.int`) |
92
+ | 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` |
93
+ | 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`, `TukeyHSD`, `zTest`, `pAdjust` (`p.adjust`) |
94
+ | Linear models | `lm` (matrix interface, with the `summary` quantities), `confint`, `predict` |
95
+ | Linear algebra | `matMul` (`%*%`), `add`, `subtract`, `multiply`, `divide`, `outer`, `t`, `diag`, `cbind`, `rbind`, `matrix`, `kronecker`, `seq`, `crossprod`, `tcrossprod`, `norm`, `backsolve`, `forwardsolve`, `chol`, `chol2inv`, `qr` with `qrQ`, `qrR`, `qrX`, `qrCoef`, `qrQy`, `qrQty`, `qrResid`, `qrFitted`, `qrSolve` (`qr.Q` …), `solve`, `det`, `determinant`, `rcond`, `kappa`, `svd`, `eigen`, `lu`, `prcomp`, `ginv` (MASS) |
96
+ | Numerical methods | `integrate`, `optimize`, `uniroot`, `approx`, `spline`, `splinefun`, `splinefunH`, `barylag`, `hermiteInterp`, `ode`, `grad`, `jacobian`, `hessian` |
97
+
98
+ Coming from jStat? [docs/migrating-from-jstat.md](docs/migrating-from-jstat.md) lists the replacement for every jStat function.
99
+
100
+ An API reference can be generated with `npm run docs` (TypeDoc).
101
+
102
+ ## Accuracy
103
+
104
+ Expected values are produced by R scripts in [`oracle/`](oracle) and stored in
105
+ [`test/fixtures/`](test/fixtures), so the test suite runs without R. A case passes if it matches
106
+ R, or if R is wrong there and rStats.js matches a high-precision value computed with Rmpfr or
107
+ gmp. In the far tails and for large parameters rStats.js is often more accurate than R, because
108
+ it computes exponents in double-double arithmetic. Details: [docs/accuracy.md](docs/accuracy.md).
109
+
110
+ ## Differences from R
111
+
112
+ Most differences are cases where R loses accuracy or fails. The deliberate ones that affect
113
+ everyday use:
114
+
115
+ - Indices are 0-based: `sampleInt(n)` returns `0..n-1` (R's `sample.int()` minus 1, from the
116
+ same random stream), and pivots of `qr` and `chol` are 0-based.
117
+ - Signs of eigenvectors and singular vectors may differ from R (both are correct).
118
+ - Hypothesis tests do not emit R's warnings; all numeric fields and method names match.
119
+ - Distribution parameters are not recycled as vectors.
120
+
121
+ Full list: [docs/differences-from-r.md](docs/differences-from-r.md).
122
+
123
+ ## Using it in the browser
124
+
125
+ With a bundler (Vite, esbuild, webpack, Rollup), import named functions; unused functions are
126
+ removed. Approximate sizes after minification and gzip:
127
+
128
+ | Import | gzip |
129
+ |---|---|
130
+ | `pnorm` | 1.2 KB |
131
+ | `setSeed`, `rnorm` | 1.7 KB |
132
+ | `solve` / `svd` / `eigen` | 1.7 / 2.0 / 3.7 KB |
133
+ | `wilcoxTest` / `fisherTest` / `tTest` | 8.6 / 13.8 / 16.7 KB |
134
+ | `qbeta` / `pt` and `qt` | 18.5 / 25.5 KB |
135
+ | everything | 112.4 KB |
136
+
137
+ (`npm run size` measures these.)
138
+
139
+ Each area is also a subpath export, for importing one area without the rest:
140
+ `@numero-uno-jpn/rstats/distributions`, `/tests` (hypothesis tests, and `lm`, `confint` and
141
+ `predict`), `/linalg`, `/descriptive`, `/numerics` and `/special`.
142
+
143
+ Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
144
+ function, 112 KB gzipped) from jsDelivr, which serves each release tag of this repository:
145
+
146
+ ```html
147
+ <script type="module">
148
+ import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.6.1/dist/rstats.js";
149
+ console.log(pnorm(1.96)); // 0.9750021048517795
150
+ </script>
151
+ ```
152
+
153
+ A page that needs only some areas can load the per-area bundles instead: `dist/distributions.js`,
154
+ `dist/tests.js`, `dist/linalg.js`, `dist/descriptive.js`, `dist/numerics.js` and `dist/special.js`
155
+ export the same functions as the subpaths above, and share their common code through
156
+ `dist/chunks/`, so loading two areas does not load that code twice. With its chunks, one area
157
+ transfers 18 KB (`numerics`) to 80 KB (`tests`) gzipped.
158
+
159
+ Release tags contain the build output (`dist/`), which is not on the main branch. npm-based CDNs
160
+ work as well, for example
161
+ `https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.6.1/dist/rstats.js` or
162
+ `https://esm.sh/@numero-uno-jpn/rstats`.
163
+
164
+ The browser build is tested in headless Chromium, both bundled and as `dist/rstats.js` loaded as
165
+ an ES module (`npm run test:browser`).
166
+
167
+ **Demo:** <https://numero-uno-jpn.github.io/rStats.js/demo/>. [`demo/`](demo) is a static page that loads `dist/rstats.js` from jsDelivr and exercises
168
+ every function: distributions with plots, special functions, random numbers, hypothesis tests and
169
+ linear algebra. Each form shows the equivalent R and JavaScript code for its inputs, and a "Compare
170
+ with R" tab checks curated examples against values printed by R (`source("examples.R")` runs them
171
+ all in R). To use your own build instead of the CDN, run `npm run build`, serve the repository root
172
+ with a static server (for example `npx serve .`) and open `/demo/?src=local`.
173
+
174
+ ## Versioning
175
+
176
+ While the version is 0.x, a minor release may contain breaking changes; they are listed in the
177
+ changelog. From 1.0.0 the project follows Semantic Versioning.
178
+
179
+ ## Contributing
180
+
181
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for how the comparison with R works and the licensing
182
+ rules (no code from R or GPL packages). Notes on speed and the double-double arithmetic are in
183
+ [docs/performance.md](docs/performance.md).
184
+
185
+ ## License
186
+
187
+ MIT. Numerical kernels are ported from SciPy's xsf, scipy.stats and C translation of QUADPACK
188
+ (BSD-3), Boost.Math (BSL-1.0), statsmodels (BSD-3) and the LAPACK reference implementation
189
+ (modified BSD), plus public-domain LINPACK, EISPACK, Cephes, QUADPACK and netlib code. See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).