@numero-uno-jpn/rstats 0.5.0 → 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 (168) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.ja.md +36 -20
  3. package/README.md +34 -18
  4. package/THIRD_PARTY_NOTICES.md +25 -5
  5. package/dist/chunks/chunk-2JCIB5H2.js +2 -0
  6. package/dist/chunks/chunk-7JVSDGQQ.js +2 -0
  7. package/dist/chunks/chunk-7NK4SA6B.js +2 -0
  8. package/dist/chunks/chunk-AJYQNFXK.js +2 -0
  9. package/dist/chunks/chunk-DRNMIEYH.js +2 -0
  10. package/dist/chunks/chunk-NAYDS7CL.js +2 -0
  11. package/dist/chunks/chunk-NOCEAM44.js +2 -0
  12. package/dist/chunks/chunk-QNAIK4PY.js +2 -0
  13. package/dist/chunks/chunk-TPC6MTYC.js +2 -0
  14. package/dist/chunks/chunk-UGUQYWRQ.js +2 -0
  15. package/dist/chunks/chunk-XM2TVD63.js +2 -0
  16. package/dist/chunks/chunk-Y4IZV7XK.js +2 -0
  17. package/dist/chunks/chunk-ZWJ42QN6.js +2 -0
  18. package/dist/descriptive/basic.d.ts +73 -0
  19. package/dist/descriptive/basic.js +256 -0
  20. package/dist/descriptive/cov.d.ts +39 -0
  21. package/dist/descriptive/cov.js +105 -0
  22. package/dist/descriptive/hist.d.ts +64 -0
  23. package/dist/descriptive/hist.js +304 -0
  24. package/dist/descriptive/moments.d.ts +63 -0
  25. package/dist/descriptive/moments.js +158 -0
  26. package/dist/descriptive/quantile.d.ts +50 -0
  27. package/dist/descriptive/quantile.js +131 -0
  28. package/dist/descriptive/rank.d.ts +23 -0
  29. package/dist/descriptive/rank.js +72 -0
  30. package/dist/descriptive/table.d.ts +54 -0
  31. package/dist/descriptive/table.js +160 -0
  32. package/dist/descriptive.js +2 -0
  33. package/dist/distributions/arcsine.d.ts +24 -0
  34. package/dist/distributions/arcsine.js +73 -0
  35. package/dist/distributions/invgamma.d.ts +29 -0
  36. package/dist/distributions/invgamma.js +85 -0
  37. package/dist/distributions/kumaraswamy.d.ts +17 -0
  38. package/dist/distributions/kumaraswamy.js +96 -0
  39. package/dist/distributions/laplace.d.ts +23 -0
  40. package/dist/distributions/laplace.js +69 -0
  41. package/dist/distributions/multinomial.d.ts +24 -0
  42. package/dist/distributions/multinomial.js +70 -0
  43. package/dist/distributions/nbeta.js +28 -10
  44. package/dist/distributions/nchisq.js +20 -3
  45. package/dist/distributions/pareto.d.ts +23 -0
  46. package/dist/distributions/pareto.js +76 -0
  47. package/dist/distributions/summary.d.ts +25 -0
  48. package/dist/distributions/summary.js +289 -0
  49. package/dist/distributions/triangular.d.ts +25 -0
  50. package/dist/distributions/triangular.js +87 -0
  51. package/dist/distributions.js +2 -0
  52. package/dist/entries/descriptive.d.ts +7 -0
  53. package/dist/entries/descriptive.js +8 -0
  54. package/dist/entries/distributions.d.ts +41 -0
  55. package/dist/entries/distributions.js +41 -0
  56. package/dist/entries/linalg.d.ts +11 -0
  57. package/dist/entries/linalg.js +11 -0
  58. package/dist/entries/numerics.d.ts +8 -0
  59. package/dist/entries/numerics.js +6 -0
  60. package/dist/entries/special.d.ts +9 -0
  61. package/dist/entries/special.js +9 -0
  62. package/dist/entries/tests.d.ts +21 -0
  63. package/dist/entries/tests.js +20 -0
  64. package/dist/htest/ansariTest.d.ts +13 -0
  65. package/dist/htest/ansariTest.js +80 -0
  66. package/dist/htest/aov.d.ts +85 -0
  67. package/dist/htest/aov.js +178 -0
  68. package/dist/htest/binomTest.d.ts +36 -0
  69. package/dist/htest/binomTest.js +121 -0
  70. package/dist/htest/cor.d.ts +14 -0
  71. package/dist/htest/cor.js +4 -3
  72. package/dist/htest/core/ansari.d.ts +18 -0
  73. package/dist/htest/core/ansari.js +121 -0
  74. package/dist/htest/core/kolmogorov.d.ts +26 -0
  75. package/dist/htest/core/kolmogorov.js +221 -0
  76. package/dist/htest/core/mantelhaen.d.ts +26 -0
  77. package/dist/htest/core/mantelhaen.js +145 -0
  78. package/dist/htest/core/shapiro.d.ts +24 -0
  79. package/dist/htest/core/shapiro.js +142 -0
  80. package/dist/htest/core/smirnov.d.ts +20 -0
  81. package/dist/htest/core/smirnov.js +75 -0
  82. package/dist/htest/fisherTest.js +134 -120
  83. package/dist/htest/groups.d.ts +20 -0
  84. package/dist/htest/groups.js +62 -0
  85. package/dist/htest/ksTest.d.ts +31 -0
  86. package/dist/htest/ksTest.js +106 -0
  87. package/dist/htest/mantelhaenTest.d.ts +26 -0
  88. package/dist/htest/mantelhaenTest.js +196 -0
  89. package/dist/htest/mcnemarTest.d.ts +26 -0
  90. package/dist/htest/mcnemarTest.js +99 -0
  91. package/dist/htest/onewayTest.d.ts +26 -0
  92. package/dist/htest/onewayTest.js +97 -0
  93. package/dist/htest/pairwise.d.ts +64 -0
  94. package/dist/htest/pairwise.js +152 -0
  95. package/dist/htest/poissonTest.d.ts +35 -0
  96. package/dist/htest/poissonTest.js +170 -0
  97. package/dist/htest/propTest.d.ts +37 -0
  98. package/dist/htest/propTest.js +164 -0
  99. package/dist/htest/rankTests.d.ts +52 -0
  100. package/dist/htest/rankTests.js +234 -0
  101. package/dist/htest/types.d.ts +2 -0
  102. package/dist/htest/types.js +6 -0
  103. package/dist/htest/varTest.d.ts +48 -0
  104. package/dist/htest/varTest.js +118 -0
  105. package/dist/htest/wilcoxTest.js +136 -174
  106. package/dist/index.d.ts +6 -50
  107. package/dist/index.js +8 -50
  108. package/dist/integrate/quadpack.d.ts +29 -0
  109. package/dist/integrate/quadpack.js +525 -0
  110. package/dist/internal/seq.d.ts +5 -0
  111. package/dist/internal/seq.js +14 -0
  112. package/dist/internal/uniroot.js +10 -71
  113. package/dist/linalg/lu.d.ts +45 -0
  114. package/dist/linalg/lu.js +88 -0
  115. package/dist/linalg/ops.d.ts +90 -0
  116. package/dist/linalg/ops.js +320 -0
  117. package/dist/linalg.js +2 -0
  118. package/dist/models/lm.d.ts +98 -0
  119. package/dist/models/lm.js +187 -0
  120. package/dist/numerics/deriv.d.ts +37 -0
  121. package/dist/numerics/deriv.js +150 -0
  122. package/dist/numerics/integrate.d.ts +91 -0
  123. package/dist/numerics/integrate.js +264 -0
  124. package/dist/numerics/interp.d.ts +103 -0
  125. package/dist/numerics/interp.js +581 -0
  126. package/dist/numerics/ode.d.ts +23 -0
  127. package/dist/numerics/ode.js +59 -0
  128. package/dist/numerics.js +2 -0
  129. package/dist/optim/localmin.d.ts +16 -0
  130. package/dist/optim/localmin.js +97 -0
  131. package/dist/random/beta.js +1 -1
  132. package/dist/random/binomial.js +1 -1
  133. package/dist/random/continuous.js +1 -1
  134. package/dist/random/extra.d.ts +33 -0
  135. package/dist/random/extra.js +62 -0
  136. package/dist/random/gamma.js +1 -1
  137. package/dist/random/hyper.js +1 -1
  138. package/dist/random/mt.js +0 -1
  139. package/dist/random/poisson.js +0 -1
  140. package/dist/random/rank.js +1 -1
  141. package/dist/random/rng.js +1 -1
  142. package/dist/random/sample.js +1 -1
  143. package/dist/rstats.js +2 -2
  144. package/dist/special/besselIK.d.ts +38 -0
  145. package/dist/special/besselIK.js +315 -0
  146. package/dist/special/besselJY.d.ts +32 -0
  147. package/dist/special/besselJY.js +508 -0
  148. package/dist/special/besselSeries.d.ts +8 -0
  149. package/dist/special/besselSeries.js +24 -0
  150. package/dist/special/beta.js +22 -5
  151. package/dist/special/choose.d.ts +75 -0
  152. package/dist/special/choose.js +233 -0
  153. package/dist/special/erf.d.ts +28 -2
  154. package/dist/special/erf.js +37 -10
  155. package/dist/special/extra.d.ts +47 -0
  156. package/dist/special/extra.js +220 -0
  157. package/dist/special/igam.d.ts +4 -0
  158. package/dist/special/igam.js +57 -2
  159. package/dist/special/incbet.js +77 -22
  160. package/dist/special/lgammaDiff.d.ts +7 -0
  161. package/dist/special/lgammaDiff.js +16 -3
  162. package/dist/special/psigamma.d.ts +48 -0
  163. package/dist/special/psigamma.js +318 -0
  164. package/dist/special/rCompatible.d.ts +8 -0
  165. package/dist/special/rCompatible.js +1 -0
  166. package/dist/special.js +2 -0
  167. package/dist/tests.js +2 -0
  168. package/package.json +26 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,107 @@ While the version is 0.x, a minor release (0.y.0) may contain breaking changes;
7
7
  they are listed under **Breaking** for each release. From 1.0.0 the project follows
8
8
  [Semantic Versioning](https://semver.org/).
9
9
 
10
+ ## 0.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
+
10
111
  ## 0.5.0 - 2026-10-21
11
112
 
12
113
  First public version.
package/README.ja.md CHANGED
@@ -5,6 +5,7 @@
5
5
  > この文書は [英語版](README.md) の訳です。内容が食い違うときは英語版が正です。
6
6
 
7
7
  JavaScript とブラウザで使える、R と互換の統計関数のライブラリです。TypeScript で書いています。
8
+ [ブラウザで試す](https://numero-uno-jpn.github.io/rStats.js/demo/) (すべての関数を、R が出す値と並べて試せます)。
8
9
 
9
10
  - **R と同じ数値を返します。** 関数名・既定値・結果は R に合わせています。すべての関数を R 4.5.2 と
10
11
  比べてテストしています (分布関数は相対誤差 1e-14)。R 自身が不正確なところでは、高精度の参照値と
@@ -15,9 +16,9 @@ JavaScript とブラウザで使える、R と互換の統計関数のライブ
15
16
  - **どこでも動きます。** ESM のみで、依存パッケージはなく、Node 専用の API も使っていません。
16
17
  tree-shaking が効きます (`pnorm` だけなら gzip で 1.2 KB)。
17
18
 
18
- 状態: **0.5.0。** R の stats パッケージの数値計算の中心
19
- (分布・検定・特殊関数・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
20
- [ROADMAP.md](ROADMAP.md) (英語)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
19
+ 状態: **0.6.1。** R の stats パッケージの数値計算の中心
20
+ (分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
21
+ [ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
21
22
 
22
23
  ## インストール
23
24
 
@@ -90,11 +91,16 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
90
91
 
91
92
  | 分野 | 関数 (R と名前が違うものは括弧内が R の名前) |
92
93
  |---|---|
93
- | 特殊関数 | `gamma`, `lgamma`, `beta`, `lbeta` |
94
- | 分布 (d/p/q) | 正規、t、カイ二乗、F、ベータ、ガンマ、二項、ポアソン、一様、指数、対数正規、ロジスティック、コーシー、ワイブル、幾何、負の二項、超幾何、Wilcoxon の符号付き順位と順位和、スチューデント化された範囲 (`ptukey`, `qtukey`)、非心カイ二乗・t・F・ベータ (`ncp`) |
95
- | 乱数 | `setSeed` (`set.seed`), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), 20 個の `r*` 関数, `sample`, `sampleInt` (`sample.int`) |
96
- | 検定 | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `cor`, `corTest`, `pAdjust` (`p.adjust`) |
97
- | 線形代数 | `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`, `ginv` (MASS) |
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 の全関数の置き換えがあります。
98
104
 
99
105
  API リファレンスは `npm run docs` (TypeDoc) で作れます (英語)。
100
106
 
@@ -130,32 +136,42 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
130
136
  | `pnorm` | 1.2 KB |
131
137
  | `setSeed`, `rnorm` | 1.7 KB |
132
138
  | `solve` / `svd` / `eigen` | 1.7 / 2.0 / 3.7 KB |
133
- | `wilcoxTest` / `fisherTest` / `tTest` | 7.9 / 13.2 / 16.3 KB |
134
- | `qbeta` / `pt` と `qt` | 17.3 / 25.0 KB |
135
- | すべて | 72.2 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 |
136
142
 
137
143
  (`npm run size` で測れます。)
138
144
 
145
+ 分野ごとにサブパスからも export しているので、1 つの分野だけを import することもできます。
146
+ `@numero-uno-jpn/rstats/distributions`、`/tests` (検定と、`lm`・`confint`・`predict`)、`/linalg`、
147
+ `/descriptive`、`/numerics`、`/special` です。
148
+
139
149
  バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (すべての関数を含む minify 済みの
140
- ES モジュール、gzip で 72 KB) を jsDelivr から読み込めます。jsDelivr は、このリポジトリのリリースの
150
+ ES モジュール、gzip で 112 KB) を jsDelivr から読み込めます。jsDelivr は、このリポジトリのリリースの
141
151
  タグをそのまま配信します。
142
152
 
143
153
  ```html
144
154
  <script type="module">
145
- import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.5.0/dist/rstats.js";
155
+ import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.6.1/dist/rstats.js";
146
156
  console.log(pnorm(1.96)); // 0.9750021048517795
147
157
  </script>
148
158
  ```
149
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
+
150
166
  ビルド結果 (`dist/`) は main ブランチにはなく、リリースのタグにだけ入っています。npm を元にした CDN も
151
167
  使えます。たとえば
152
- `https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.5.0/dist/rstats.js` や
168
+ `https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.6.1/dist/rstats.js` や
153
169
  `https://esm.sh/@numero-uno-jpn/rstats` です。
154
170
 
155
171
  ブラウザ向けのビルドは、headless Chromium でテストしています。バンドラでまとめた場合と、
156
172
  `dist/rstats.js` を ES モジュールとして読み込んだ場合の両方です (`npm run test:browser`)。
157
173
 
158
- **デモ。** [`demo/`](demo) は、`dist/rstats.js` を jsDelivr から読み込んで、すべての関数を試せる
174
+ **デモ:** <https://numero-uno-jpn.github.io/rStats.js/demo/>。[`demo/`](demo) は、`dist/rstats.js` を jsDelivr から読み込んで、すべての関数を試せる
159
175
  静的なページです。確率分布 (グラフ付き)・特殊関数・乱数・検定・線形代数を扱います。各フォームには、
160
176
  入力に対応する R と JavaScript のコードが表示されます。「R との比較」のタブでは、例題の値を R が
161
177
  出力した値と照らし合わせます (`source("examples.R")` で、すべての例題を R で実行できます)。CDN の
@@ -170,12 +186,12 @@ ES モジュール、gzip で 72 KB) を jsDelivr から読み込めます。jsD
170
186
  ## 貢献
171
187
 
172
188
  R との答え合わせの仕組みと、ライセンスの決まり (R や GPL のパッケージのコードは使わない) は
173
- [CONTRIBUTING.md](CONTRIBUTING.md) (英語) にあります。速さと double-double 演算については
174
- [docs/performance.md](docs/performance.md) (英語) にあります。
189
+ [CONTRIBUTING.ja.md](CONTRIBUTING.ja.md) にあります。速さと double-double 演算については
190
+ [docs/ja/performance.md](docs/ja/performance.md) にあります。
175
191
 
176
192
  ## ライセンス
177
193
 
178
- MIT です。数値計算の部品は、SciPy の xsf と scipy.stats (BSD-3)、Boost.Math (BSL-1.0)、
179
- statsmodels (BSD-3)、LAPACK の参照実装 (修正 BSD) から移植しています。パブリックドメインの
180
- LINPACK・EISPACK・Cephes のコードも使っています。詳しくは
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 のコードも使っています。詳しくは
181
197
  [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) (英語) を見てください。
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  English | [日本語](README.ja.md)
4
4
 
5
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).
6
7
 
7
8
  - **Same numbers as R.** Function names, defaults and results follow R. Every function is
8
9
  tested against R 4.5.2 (relative error 1e-14 for distributions), and where R itself is
@@ -13,9 +14,9 @@ R-compatible statistical functions for JavaScript and the browser, written in Ty
13
14
  - **Runs anywhere.** ESM only, no dependencies, no Node-specific APIs, tree-shakable
14
15
  (`pnorm` alone is 1.2 KB gzipped).
15
16
 
16
- Status: **0.5.0.** The goal is to cover the numerical core of R's
17
- `stats` package (distributions, hypothesis tests, special functions and the basics of linear
18
- algebra) with R-compatible results; see [ROADMAP.md](ROADMAP.md) for what remains. See [CHANGELOG.md](CHANGELOG.md).
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).
19
20
 
20
21
  ## Install
21
22
 
@@ -85,11 +86,16 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
85
86
 
86
87
  | Area | Functions (R names in parentheses where they differ) |
87
88
  |---|---|
88
- | Special functions | `gamma`, `lgamma`, `beta`, `lbeta` |
89
- | 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`) |
90
- | Random numbers | `setSeed` (`set.seed`), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), 20 `r*` functions, `sample`, `sampleInt` (`sample.int`) |
91
- | Hypothesis tests | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `cor`, `corTest`, `pAdjust` (`p.adjust`) |
92
- | Linear algebra | `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`, `ginv` (MASS) |
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.
93
99
 
94
100
  An API reference can be generated with `npm run docs` (TypeDoc).
95
101
 
@@ -124,31 +130,41 @@ removed. Approximate sizes after minification and gzip:
124
130
  | `pnorm` | 1.2 KB |
125
131
  | `setSeed`, `rnorm` | 1.7 KB |
126
132
  | `solve` / `svd` / `eigen` | 1.7 / 2.0 / 3.7 KB |
127
- | `wilcoxTest` / `fisherTest` / `tTest` | 7.9 / 13.2 / 16.3 KB |
128
- | `qbeta` / `pt` and `qt` | 17.3 / 25.0 KB |
129
- | everything | 72.2 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 |
130
136
 
131
137
  (`npm run size` measures these.)
132
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
+
133
143
  Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
134
- function, 72 KB gzipped) from jsDelivr, which serves each release tag of this repository:
144
+ function, 112 KB gzipped) from jsDelivr, which serves each release tag of this repository:
135
145
 
136
146
  ```html
137
147
  <script type="module">
138
- import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.5.0/dist/rstats.js";
148
+ import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.6.1/dist/rstats.js";
139
149
  console.log(pnorm(1.96)); // 0.9750021048517795
140
150
  </script>
141
151
  ```
142
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
+
143
159
  Release tags contain the build output (`dist/`), which is not on the main branch. npm-based CDNs
144
160
  work as well, for example
145
- `https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.5.0/dist/rstats.js` or
161
+ `https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.6.1/dist/rstats.js` or
146
162
  `https://esm.sh/@numero-uno-jpn/rstats`.
147
163
 
148
164
  The browser build is tested in headless Chromium, both bundled and as `dist/rstats.js` loaded as
149
165
  an ES module (`npm run test:browser`).
150
166
 
151
- **Demo.** [`demo/`](demo) is a static page that loads `dist/rstats.js` from jsDelivr and exercises
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
152
168
  every function: distributions with plots, special functions, random numbers, hypothesis tests and
153
169
  linear algebra. Each form shows the equivalent R and JavaScript code for its inputs, and a "Compare
154
170
  with R" tab checks curated examples against values printed by R (`source("examples.R")` runs them
@@ -168,6 +184,6 @@ rules (no code from R or GPL packages). Notes on speed and the double-double ari
168
184
 
169
185
  ## License
170
186
 
171
- MIT. Numerical kernels are ported from SciPy's xsf and scipy.stats (BSD-3), Boost.Math
172
- (BSL-1.0), statsmodels (BSD-3) and the LAPACK reference implementation (modified BSD), plus
173
- public-domain LINPACK, EISPACK and Cephes code. See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
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).
@@ -8,7 +8,7 @@ listed below. Each ported file names its source at the top.
8
8
  ## xsf
9
9
 
10
10
  - Source: https://github.com/scipy/xsf (commit c6a3afe)
11
- - Used in: `src/special/beta.ts`, `src/special/constants.ts`, `src/special/erf.ts`, `src/special/gamma.ts`, `src/special/igam.ts`, `src/special/igamAsympCoeff.ts`, `src/special/igami.ts`, `src/special/incbet.ts`, `src/special/log1pmx.ts`, `src/special/ndtri.ts`, `src/special/polevl.ts`
11
+ - Used in: `src/special/beta.ts`, `src/special/constants.ts`, `src/special/erf.ts`, `src/special/gamma.ts`, `src/special/igam.ts`, `src/special/igamAsympCoeff.ts`, `src/special/igami.ts`, `src/special/incbet.ts`, `src/special/log1pmx.ts`, `src/special/ndtri.ts`, `src/special/polevl.ts`, `src/special/psigamma.ts`
12
12
  - License: BSD-3-Clause
13
13
  - `include/xsf/ndtri_exp.h` (used in `src/special/ndtri.ts`): Copyright Albert Steppi,
14
14
  distributed under the same license as SciPy (BSD-3-Clause)
@@ -100,6 +100,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100
100
  algorithms — Poisson-mixture summation starting near the mode, and the integral
101
101
  P[T <= t] = E[Φ(tS - δ)] for the non-central t; the TypeScript code was written independently)
102
102
  - License: Boost Software License 1.0
103
+ - Also: the rational approximation of digamma on [1, 2] in `src/special/psigamma.ts`, which xsf's
104
+ `include/xsf/cephes/psi.h` takes from Boost ((C) Copyright John Maddock 2006)
105
+ - Ported (Boost.Math commit 0a0fb4e): `include/boost/math/special_functions/detail/bessel_ik.hpp`,
106
+ `detail/bessel_jy.hpp`, `detail/bessel_jy_series.hpp`, `detail/bessel_jy_asym.hpp` and the
107
+ dispatch in `bessel.hpp`, in `src/special/besselIK.ts` and `src/special/besselJY.ts`
108
+ (Copyright (c) 2006 Xiaogang Zhang, (c) 2007 John Maddock, (c) 2024 Matt Borland)
103
109
 
104
110
  ```
105
111
  Boost Software License - Version 1.0 - August 17th, 2003
@@ -131,16 +137,18 @@ Boost.Math: Copyright John Maddock 2008, Matt Borland 2024 (and other contributo
131
137
 
132
138
  ---
133
139
 
134
- ## SciPy (scipy.stats)
140
+ ## SciPy (scipy.stats, scipy.integrate)
135
141
 
136
142
  - Source: https://github.com/scipy/scipy (commit a087e61)
137
- - `scipy/stats/_stats_py.py` (ttest_1samp / ttest_ind / ttest_rel, chisquare, fisher_exact, pearsonr)
143
+ - `scipy/stats/_stats_py.py` (ttest_1samp / ttest_ind / ttest_rel, chisquare, pearsonr)
138
144
  - `scipy/stats/contingency.py` (chi2_contingency, expected_freq)
139
- - `scipy/stats/_odds_ratio.py` (conditional odds ratio and its confidence interval)
140
145
  - `scipy/stats/_wilcoxon.py`, `scipy/stats/_mannwhitneyu.py`
141
146
  - `scipy/stats/_mstats_basic.py` (kendalltau, `_kendall_p_exact`)
142
- - Used in: `src/htest/tTest.ts`, `src/htest/chisqTest.ts`, `src/htest/fisherTest.ts`, `src/htest/wilcoxTest.ts`, `src/htest/cor.ts`
147
+ - Used in: `src/htest/tTest.ts`, `src/htest/chisqTest.ts`, `src/htest/wilcoxTest.ts`, `src/htest/cor.ts`
143
148
  - License: BSD-3-Clause
149
+ - Ported (SciPy commit 5ccd743): `scipy/integrate/__quadpack.c`, SciPy's C translation of QUADPACK
150
+ (`dqagse`, `dqagie` and their rules), in `src/integrate/quadpack.ts` (Copyright (C) 2024 SciPy
151
+ developers, BSD-3-Clause; QUADPACK itself is in the public domain, see below)
144
152
 
145
153
  ```
146
154
  Copyright (c) 2001-2002 Enthought, Inc. 2003, SciPy Developers.
@@ -295,3 +303,15 @@ they are listed so that readers can find the originals.
295
303
  `src/linalg/qr.ts`, `src/linalg/kappa.ts`
296
304
  - EISPACK / JAMA (NIST and The MathWorks): `svd` (Golub–Reinsch), `tred2`, `tql2`, `orthes`, `hqr2` —
297
305
  `src/linalg/svd.ts`, `src/linalg/eigen.ts`
306
+ - FMM (Forsythe, Malcolm, Moler, "Computer Methods for Mathematical Computations", 1977; netlib
307
+ https://netlib.org/fmm/spline.f): `spline` (cubic spline coefficients with end third derivatives from
308
+ divided differences), the "fmm" method — `src/numerics/interp.ts`
309
+ - netlib go (https://netlib.org/go/zeroin.f; Brent, "Algorithms for Minimization without Derivatives",
310
+ 1973, chapter 4): `zeroin` (Brent's root finder by bisection, secant and inverse quadratic
311
+ interpolation), the zero finder of `uniroot` — `src/numerics/integrate.ts`
312
+ - netlib fmm (https://netlib.org/fmm/fmin.f; Brent, "Algorithms for Minimization without Derivatives",
313
+ 1973, chapter 5): `fmin` (Brent's localmin, golden-section search with parabolic interpolation),
314
+ the minimiser of `optimize` — `src/optim/localmin.ts`
315
+ - QUADPACK (Piessens, de Doncker-Kapenga, Überhuber, Kahaner 1983): `dqagse` and `dqagie` (adaptive
316
+ Gauss–Kronrod quadrature with extrapolation), behind `integrate` — `src/integrate/quadpack.ts`,
317
+ ported from SciPy's C translation (see SciPy above)
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.6.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{a as h,i as s,j as p}from"./chunk-QNAIK4PY.js";function L(t){return Math.abs(t-m(t))>1e-9*Math.max(1,Math.abs(t))}function m(t){if(!Number.isFinite(t))return t;let e=Math.round(t);return e-t===.5&&e%2!==0?e-1:e}var y=[.08333333333333333,-.021092796092796094,.007575757575757576,-.004166666666666667,.003968253968253968,-.008333333333333333,.08333333333333333],d=.9955816268920898,w=1569415565/1073741824,O=381566830/1073741824/1073741824,E=9016312093258695e-35,S=[-.002071332116774595,-.04525132144873906,-.28919126444774784,-.6503185377089651,-.3255503118680449,.25479851061131553],_=[-5578984132167551e-22,.0021284987017821146,.054151797245674226,.43593529692665967,1.4606242909763516,2.076711702373047,1];function v(t){let e=t-w;e-=O,e-=E;let r=h(t-1,S)/h(t-1,_);return e*d+e*r}function A(t){let e=0;if(t<1e17){let r=1/(t*t);e=r*h(r,y)}return Math.log(t)-.5/t-e}function k(t){let e=0;if(Number.isNaN(t)||t===1/0)return t;if(t===-1/0)return NaN;if(t===0)return NaN;if(t<0){let r=t-Math.trunc(t);if(r===0)return NaN;e=-Math.PI/Math.tan(Math.PI*r),t=1-t}if(t<=10&&t===Math.floor(t)){let r=t;for(let o=1;o<r;o++)e+=1/o;return e-p}if(t<1)e-=1/t,t+=1;else if(t<10)for(;t>2;)t-=1,e+=1/t;return t>=1&&t<=2?e+v(t):e+A(t)}var N=-.5040830082644554,R=7289763902976895e-32,b;function T(t){b??=Array.from({length:100},(n,i)=>C(i+2,N));let e=R,r=-1,o=t-N;for(let n=1;n<100;n++){r*=-o;let i=r*b[n-1];if(e+=i,Math.abs(i)<Number.EPSILON*Math.abs(e))break}return e}var g=[12,-720,30240,-1209600,47900160,-18924375803183792e-7,74724249600,-2950130727918164e-3,11646782814350067e-2,-4597978722407473,0x284e46fd8153bc0,-7166165256175667e3];function z(t,e){let r=1,o=e,n=1,i=0;for(;e<=1e8&&(i<9||o<=9||o<t);)if(i+=1,o+=1,n=Math.exp(-t*Math.log1p(i/e)),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let u=1,a=0;for(let c=0;c<12;c++){u*=t+a,n/=f;let l=u*n/g[c];if(r+=l,Math.abs(l/r)<s)break;a+=1,u*=t+a,n/=f,a+=1}return r}function C(t,e){let r=Math.pow(e,-t),o=e,n=0,i=0;for(;i<9||o<=9||o<t;)if(i+=1,o+=1,n=Math.pow(o,-t),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let u=1,a=0;for(let c=0;c<12;c++){u*=t+a,n/=f;let l=u*n/g[c];if(r+=l,Math.abs(l/r)<s)break;a+=1,u*=t+a,n/=f,a+=1}return r}function I(t,e){if(e===1/0)return t%2===0?-0:0;let r=1;for(let n=1;n<=t;n++)r*=n/e;let o=r*(z(t+1,e)/e);return t%2===0?-o:o}var M=[];function Z(t){if(M[t]!==void 0)return M[t];let e=[0,1];for(let n=0;n<t;n++){let i=e.slice(1).map((u,a)=>u*(a+1)),f=new Array(i.length+2).fill(0);i.forEach((u,a)=>{f[a]=f[a]-u,f[a+2]=f[a+2]-u}),e=f}let r=(t+1)%2,o=[];for(let n=r;n<e.length;n+=2)o.push(e[n]);return M[t]=o,o}function j(t,e){let r=Z(t),o=e*e,n=r[r.length-1];for(let i=r.length-2;i>=0;i--)n=n*o+r[i];return(t+1)%2===1?n*e:n}function D(t){let e=t-Math.round(t);return Math.sin(Math.PI*(.5-Math.abs(e)))/Math.sin(Math.PI*e)}function P(t,e,r){if(Number.isNaN(e))return NaN;if(e===-1/0)return r&&t%2===1?1/0:NaN;if(e<=0&&e===Math.floor(e))return t%2===1?1/0:NaN;if(e>0)return I(t,e);let o=I(t,1-e);return(t%2===0?o:-o)-Math.pow(Math.PI,t+1)*j(t,D(e))}function H(t){return Math.abs(t-N)<.3?T(t):k(t)}function V(t,e){return P(1,t,e?.rCompatible??!0)}function Y(t,e=0,r){let o=m(e);return Number.isNaN(o)||o<0||o>100?NaN:o===0?H(t):P(o,t,r?.rCompatible??!0)}export{L as a,m as b,H as c,V as d,Y as e};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.6.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{a as I,b,c as y,d as L,e as S,f as W,g as Q,h as St,i as Zn,j as Bt}from"./chunk-XM2TVD63.js";import{a as U,b as C,c as pt}from"./chunk-2JCIB5H2.js";import{B as Z,C as wn,a as Jt,e as g,g as dt,h as R,j as kt,l as Vn,n as X,o as Ct,p as At,q as Rt,s as w,t as ut,u as A,x as Xn,y as O}from"./chunk-QNAIK4PY.js";import{b as E,c as K,d as F,e as P,f as Kn,g as q,h as zt,i as _,j as Mt,k as G}from"./chunk-UGUQYWRQ.js";function le(n,t){let r=[.213623493715853,4.28342155967104,11.6616720288968,3.31125922108741],e=[.03611708101884203,1.27364489782223,6.40691597760039,6.61053765625462,1],i=n<.5?Math.sqrt(-2*Math.log(n)):Math.sqrt(-2*Math.log(t)),o=i-Jt(i,r)/Jt(i,e);return n<.5?-o:o}function me(n,t,r,e){let i=1;if(r>=1){let o=t/(n+1);i+=o;for(let u=2;u<=r&&(o*=t/(n+u),i+=o,!(o<e));++u);}return i}function $n(n,t){let r=(n-1)*Math.log(t),e=r*r,i=e*r,o=e*e,u=n*n,s=u*n,f=(n-1)*(1+r),c=(n-1)*(-(e/2)+(n-2)*r+(3*n-5)/2),a=(n-1)*(i/3-(3*n-5)*e/2+(u-6*n+7)*r+(11*u-46*n+47)/6),N=(n-1)*(-(o/4)+(11*n-17)*i/6+(-3*u+13*n-13)*e+(2*s-25*u+72*n-61)*r/2+(25*s-195*u+477*n-379)/12),h=t*t,l=h*t,m=h*h;return t+r+f/t+c/h+a/l+N/m}function tn(n,t,r){if(n===1)return r>.9?-Math.log1p(-t):-Math.log(r);if(n<1){let M=Vn(n),p=r*M;if(p>.6||p>=.45&&n>=.3){let d=p*r>1e-8&&r>1e-5?Math.pow(t*M*n,1/n):Math.exp(-r/n-kt);return d/(1-d/(n+1))}if(n<.3&&p>=.35){let d=Math.exp(-kt-p),x=d*Math.exp(d);return d*Math.exp(x)}if(p>.15||n>=.3){let d=-Math.log(p),x=d-(1-n)*Math.log(d);return d-(1-n)*Math.log(x)-Math.log(1+(1-n)/(1+x))}if(p>.1){let d=-Math.log(p),x=d-(1-n)*Math.log(d);return d-(1-n)*Math.log(x)-Math.log((x*x+2*(3-n)*x+(2-n)*(3-n))/(x*x+(5-n)*x+2))}return $n(n,-Math.log(p))}let e=le(t,r),i=e*e,o=i*e,u=i*i,s=u*e,f=Math.sqrt(n),c=n+e*f+(i-1)/3;if(c+=(o-7*e)/(36*f),c-=(3*u+7*i-16)/(810*n),c+=(9*s+256*o-433*e)/(38880*n*f),n>=500&&Math.abs(1-c/n)<1e-6)return c;if(t>.5){if(c<3*n)return c;let M=Math.max(2,n*(n-1)),p=Math.log(r)+X(n);if(p<-M*2.3)return $n(n,-p);let d=-p+(n-1)*Math.log(c)-Math.log(1+(1-n)/(1+c));return-p+(n-1)*Math.log(d)-Math.log(1+(1-n)/(1+d))}let a=c,N=n+1,h=n+2;if(c<.15*N){let M=Math.log(t)+X(N);a=Math.exp((M+c)/n),e=Math.log1p(a/N*(1+a/h)),a=Math.exp((M+a-e)/n),e=Math.log1p(a/N*(1+a/h)),a=Math.exp((M+a-e)/n),e=Math.log1p(a/N*(1+a/h*(1+a/(n+3)))),a=Math.exp((M+a-e)/n)}if(a<=.01*N||a>.7*N)return a;let l=Math.log(me(n,a,100,1e-4)),m=Math.log(t)+X(N);return a=Math.exp((m+a-l)/n),a*(1-(n*Math.log(a)-a-m+l)/(n-a))}function nn(n){let{rate:t,scale:r}=n;if(t!==void 0&&r!==void 0){if(Math.abs(t*r-1)>=1e-15)throw new RangeError("rate and scale can both be given only when scale = 1 / rate");return r}return r!==void 0?r:t!==void 0?1/t:1}function Me(n,t){if(t<1){let r=A(t,n,!0),e=t/n;return r+(Number.isFinite(e)?Math.log(e):Math.log(t)-Math.log(n))}return A(t-1,n,!0)}function st(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<=0)return NaN;if(n<0)return y(e);if(t===0)return n===0?1/0:y(e);if(n===0)return t<1?1/0:t>1?y(e):e?-Math.log(r):1/r;if(t<1){let o=A(t,n/r,e);if(e){let u=t/n;return o+(Number.isFinite(u)?Math.log(u):Math.log(t)-Math.log(n))}return o*t/n}let i=A(t-1,n/r,e);return e?i-Math.log(r):i/r}function qt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<=0)return NaN;let o=n/r;return Number.isNaN(o)?o:t===0?o<=0?I(e,i):b(e,i):o<=0?I(e,i):O(t,o,e,i)}function de(n,t,r,e){let{lower:i,logTarget:o,linearTarget:u}=S(n,r,e),s=O(t,Number.MIN_VALUE,i,!0);if(i?s>=o:s<=o)return 0;let f;if(t>1&&o<=-700){let c=R(o,{lowerTail:i,logP:!0}),a=1-1/(9*t)+c/Math.sqrt(9*t);f=a>0?t*a*a*a:t*.001}else if(o>-700){let c=Math.exp(o),a=-Math.expm1(o);f=i?tn(t,c,a):tn(t,a,c)}else if(i)f=Math.exp((o+Ct(t))/t);else{f=-o;for(let c=0;c<3;c++)f=-o-X(t)+(t-1)*Math.log(f)}return W({logTarget:o,...u!==void 0&&{linearTarget:u},lower:i,cdf:(c,a)=>O(t,c,a,!1),cdfLog:(c,a)=>O(t,c,a,!0),cdfBoth:(c,a)=>Xn(t,c,a),pdfLog:c=>Me(c,t),dlogPdf:c=>(t-1)/c-1,x0:f,lo:0,hi:1/0,positive:!0})}function J(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=L(n,0,1/0,e,i);return o!==void 0?o:t<0||r<=0?NaN:t===0?0:de(n,t,e,i)*r}function wi(n,t,r={}){let e=nn(r),i=r.log??!1;return g(n,o=>st(o,t,e,i))}function Zi(n,t,r={}){let e=nn(r),{lowerTail:i=!0,logP:o=!1}=r;return g(n,u=>qt(u,t,e,i,o))}function $i(n,t,r={}){let e=nn(r),{lowerTail:i=!0,logP:o=!1}=r;return g(n,u=>J(u,t,e,i,o))}var gt=8*Number.EPSILON,Yn=2*Number.EPSILON,pe=1e-290;function j(n){let{p:t,lowerTail:r,logP:e,cdf:i,lo:o,hi:u}=n,s;if(e||t<pe){let N;e?N=r?t*(1+Yn):t*(1-Yn):N=Math.log(t)+Math.log1p(r?-gt:gt),s=r?h=>i(h,!0,!0)>=N:h=>i(h,!1,!0)<=N}else{let N;if(r?N=t*(1-gt):N=1-t>4*gt?t*(1+gt):t,N>.5){let h=1-N;s=r?l=>i(l,!1,!1)<=h:l=>i(l,!0,!1)>=h}else s=r?h=>i(h,!0,!1)>=N:h=>i(h,!1,!1)<=N}let f=Math.round(n.y0);if(Number.isFinite(f)||(f=o),f=Math.min(Math.max(f,o),u),s(f)){let N=1,h=f-N;for(;h>=o&&s(h);)f=h,N*=2,h=f-N;if(h<o){if(f===o)return o;h=o-1}return Tn(h,f,s)}let c=1,a=f+c;for(;a<=u&&!s(a);)f=a,c*=2,a=f+c;return a>u&&(a=u),Tn(f,a,s)}function Tn(n,t,r){for(;t-n>1;){let e=Math.floor(n+(t-n)/2);if(e===n||e===t)break;r(e)?t=e:n=e}return t}var Wt=U;function ge(n,t,r){return Number.isNaN(n)||Number.isNaN(t)?NaN:t<0?NaN:Wt(n)?y(r):n<0||!Number.isFinite(n)?y(r):A(Math.round(n),t,r)}function be(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t<0)return NaN;if(n<0)return I(r,e);if(t===0)return b(r,e);if(!Number.isFinite(n))return b(r,e);let i=Math.floor(n+1e-7);return O(i+1,t,!r,e)}function Ie(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(!Number.isFinite(t)||t<0)return NaN;let i=L(n,0,1/0,r,e);if(i!==void 0)return t===0&&!Number.isNaN(i)?0:i;if(t===0)return 0;let o=Math.sqrt(t),u=R(n,{lowerTail:r,logP:e}),s=t+o*(u+(u*u-1)/(6*o));return j({p:n,lowerTail:r,logP:e,cdf:(f,c,a)=>O(f+1,t,!c,a),y0:Number.isFinite(s)?s:t,lo:0,hi:1/0})}function eo(n,t,r={}){let e=r.log??!1;return g(n,i=>ge(i,t,e))}function io(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return g(n,o=>be(o,t,e,i))}function oo(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return g(n,o=>Ie(o,t,e,i))}var ye=1e-17,ve=Math.log(ye),Pn=2e7,en=500,rn=2**en,bt=2**-en,Fe=2**250,xe=2**-250,on=en*Math.LN2,Ft={h:0,l:0,k:0};function V(n,t,r,e=!1){if(n===0)return Ft;if(!Number.isFinite(n))return{h:n,l:0,k:r};for(;Math.abs(n)>Fe;)n*=bt,t*=bt,r++;for(;Math.abs(n)<xe;)n*=rn,t*=rn,r--;return e?{h:n,l:t,k:r,approx:e}:{h:n,l:t,k:r}}var Le=[346.5735902799727,-22599635089223323e-30];function Ht(n,t){if(n>1e-305||Number.isNaN(n))return V(n,0,0);let r=t(),[e,i]=typeof r=="number"?[r,0]:r;if(e===-1/0)return Ft;if(Number.isNaN(e))return{h:NaN,l:0,k:0};let o=Math.round(e/on),u=F([e,i],q(Le,[-o,0])),s=Math.exp(u[0]);return typeof r=="number"?V(s,0,o,!0):V(s,s*u[1],o)}function un(n,t){if(n===0)return[-t,0];let r=22250738585072014e-324;if(n<=t*r||t<n*r||!Number.isFinite(n))return F(q(G([t,0]),[n,0]),[-t-Ct(n),0]);let e=F(Rt(n,[t,0]),[At(n),0]);return F([-e[0],-e[1]],[-.5*(_e+Math.log(n)),0])}var _e=1.8378770664093456;function $(n,t){return n.approx===!0&&yt(n)>-700?t():n}function z(n,t){return It(n,V(t[0],t[1],0))}function De(n,t){if(n.h===0)return Ft;let r=V(t[0],t[1],0),e=_([n.h,n.l],[r.h,r.l]);return V(e[0],e[1],n.k-r.k,n.approx)}function Jn(n,t,r){let e=z(n,t.ratio(r));return t.ratioK?{...e,k:e.k+t.ratioK}:e}function zn(n,t,r){let e=De(n,t.ratio(r));return t.ratioK?{...e,k:e.k-t.ratioK}:e}function It(n,t){if(n.h===0||t.h===0)return Ft;let r=q([n.h,n.l],[t.h,t.l]);return V(r[0],r[1],n.k+t.k,n.approx===!0||t.approx===!0)}function Ot(n,t,r,e){for(let i=r;i<e&&n!==0;i++)n*=bt,t*=bt;return[n,t]}function kn(n,t){if(n.h===0)return t;if(t.h===0)return n;let r=Math.max(n.k,t.k),e=F(Ot(n.h,n.l,n.k,r),Ot(t.h,t.l,t.k,r));return V(e[0],e[1],r)}function yt(n){return n.h===0?-1/0:Math.log(n.h)+n.l/n.h+n.k*on}var vt=class{s=0;c=0;k=0;add(t){if(t.h===0)return;if(this.s===0&&this.c===0){this.s=t.h,this.c=t.l,this.k=t.k;return}t.k>this.k&&([this.s,this.c]=Ot(this.s,this.c,this.k,t.k),this.k=t.k);let[r,e]=Ot(t.h,t.l,t.k,this.k);this.addNum(r),this.addNum(e)}addNum(t){let r=this.s+t;Math.abs(this.s)>=Math.abs(t)?this.c+=this.s-r+t:this.c+=t-r+this.s,this.s=r}get log(){let t=this.s+this.c;return Number.isNaN(t)?NaN:t>0?Math.log(t)+this.k*on:-1/0}get linear(){let t=this.s+this.c;for(let r=0;r<this.k;r++)t*=rn;for(let r=0;r>this.k&&t!==0;r--)t*=bt;return t}value(t){return t?this.log:this.linear}divideBy(t){let r=V(t,0,0);this.s/=r.h,this.c/=r.h,this.k-=r.k}};function Ee(n){let t=Math.floor(n),r=1;for(;;){if(r*=n/(t+1),r/(1-n/(t+2))<3e-21)return t;t++}}function Ce(n){let t=Math.floor(n),r=1;for(;t>0;){if(r*=t/n,r/(1-(t-1)/n)<3e-21)return t;t--}return 0}function Ut(n,t,r){if(r===-1/0||!(n<t))return!1;let e=n-t;return n+e-Math.log(-Math.expm1(e))<=ve+r}function k(n,t){return Ht(A(n,t,!1),()=>un(n,t))}function H(n,t){return Ht(n.inc(t,!1),()=>n.incLogDD?n.incLogDD(t):n.inc(t,!0))}function ft(n,t,r,e){return(r?or(n,t):ur(n,t)).value(e)}function tr(n,t,r){let e=r?or(n,t):ur(n,t);return{lin:e.linear,log:e.log}}function nr(n,t,r,e){return A(r,t,!0)+n.cdf(r,e,!0)}function rr(n,t,r){for(;r-t>2;){let i=Math.floor(t+(r-t)/3),o=Math.ceil(r-(r-t)/3);n(i)<n(o)?t=i:r=o}let e=t;for(let i=t+1;i<=r;i++)n(i)>n(e)&&(e=i);return e}var Ae=60;function er(n,t,r,e){let i=n(t)-Ae;for(let o=1;;o*=2){let u=t+r*o;if(r>0?u>=e:u<=e)return e;if(n(u)<i)return u}}var ir=3e3;function or(n,t){let r=Ee(n);if(r>ir){let f=c=>nr(t,n,c,!0);r=er(f,rr(f,0,r),1,r)}let e=Ht(t.cdf(r,!0,!1),()=>t.cdf(r,!0,!0)),i=k(r,n),o=r>0?H(t,r-1):Ft,u=new vt,s=-1/0;for(let f=r;f>=0;f--){let c=It(i,e),a=yt(c);if(u.add(c),Ut(a,s,u.log)||(s=a,f===0))break;e=kn(e,o),i=$(z(i,Mt([f,0],n)),()=>k(f-1,n)),f>=2&&(o=o.h===0?H(t,f-2):$(zn(o,t,f-1),()=>H(t,f-2)))}return u}function ur(n,t){let r=Ce(n),e=!1;for(;;){let i=Ht(t.cdf(r,!1,!1),()=>t.cdf(r,!1,!0)),o=k(r,n),u=H(t,r),s=new vt,f=-1/0,c=-1;for(let a=r;a<r+Pn;a++){let N=It(o,i),h=yt(N);if(s.add(N),Ut(h,f,s.log)||h===-1/0&&a>n+50&&a>r+50)break;if(!e&&a-r>=ir&&h>=f){let l=d=>nr(t,n,d,!1),m=l(a),M=a+1;for(let d=1;l(M)>=m;d*=2)M=a+d;let p=er(l,rr(l,a,M),-1,a);if(e=!0,p>a){c=p;break}}f=h,i=kn(i,u),o=$(z(o,Mt([n,0],a+1)),()=>k(a+1,n)),u=u.h===0?H(t,a+1):$(Jn(u,t,a+1),()=>H(t,a+1))}if(c<0)return s;r=c}}function Gt(n,t,r,e,i,o){let u=Number.isFinite(e)?Math.max(0,Math.round(e)):0,s=new vt,f=k(u,n),c=H(t,u),a=f,N=c,h=-1/0;for(let l=u;l<u+Pn;l++){let m=z(It(a,N),[r(l),0]),M=yt(m);if(s.add(m),Ut(M,h,s.log)||M===-1/0&&l>n+50&&l>u+50)break;h=M,a=$(z(a,Mt([n,0],l+1)),()=>k(l+1,n)),N=N.h===0?H(t,l+1):$(Jn(N,t,l+1),()=>H(t,l+1))}a=f,N=c,h=-1/0;for(let l=u-1;l>=0;l--){a=$(z(a,Mt([l+1,0],n)),()=>k(l,n)),N=N.h===0?H(t,l):$(zn(N,t,l+1),()=>H(t,l));let m=z(It(a,N),[r(l),0]),M=yt(m);if(s.add(m),Ut(M,h,s.log))break;h=M}return s.divideBy(i),s.value(o)}function Re(n){return n<=.5?[[n,0],E(1,-n)]:[E(1,-(1-n)),[1-n,0]]}function Nr(n,t,r,e){let[i,o]=Re(n),{e:u,logDenom:s}=ut(t,r,i,o),f=F(P(F(G(i),G(o))),[Math.log(t*r/(t+r))-.5*s,0]),c=F(P(u),f);return e?c[0]+c[1]:Math.exp(c[0])*(1+c[1])}function Se(n,t,r,e){return Nr(n,r,e,!0)}function sn(n,t,r,e){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<0||r<0?NaN:n<0||n>1?y(e):t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)?t===0&&r===0?n===0||n===1?1/0:y(e):t===0||r/t===1/0?n===0?1/0:y(e):r===0||t/r===1/0?n===1?1/0:y(e):n===.5?1/0:y(e):n===0?t>1?y(e):t<1?1/0:e?Math.log(r):r:n===1?r>1?y(e):r<1?1/0:e?Math.log(t):t:Nr(n,t,r,e)}function fn(n,t,r,e,i){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<0||r<0?NaN:n>=1?b(e,i):t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)?t===0&&r===0?i?-Math.LN2:.5:t===0||r/t===1/0?b(e,i):r===0||t/r===1/0?I(e,i):n<.5?I(e,i):b(e,i):n<=0?I(e,i):Q(t,r,n,1-n,e,i)}function an(n,t,r,e){if(!(n>1&&t>1))return;let i=R(e,{logP:!0}),o=r?-i:i,u=1/(2*n-1),s=1/(2*t-1),f=2/(u+s),c=(o*o-3)/6;if(!(f+c>0))return;let a=o*Math.sqrt(f+c)/f-(s-u)*(c+5/6-2/(3*f)),N=n/(n+t*Math.exp(2*a));return N>0&&N<1?N:void 0}function sr(n,t,r,e,i){let o=Q(n,t,Number.MIN_VALUE,1,r,!0);if(r?o>=e:o<=e)return 0;let u=.25,s=1/0;if(r){let f=(e+Math.log(n)+Z(n,t))/n;s=Math.exp(Math.max(f,-745)),u=Math.min(s,.25)}if(!(s<.001)){let f=an(n,t,r,e);f!==void 0&&f<.5&&(u=f)}return W({logTarget:e,...i!==void 0&&{linearTarget:i},lower:r,cdf:(f,c)=>Q(n,t,f,1-f,c,!1),cdfLog:(f,c)=>Q(n,t,f,1-f,c,!0),cdfBoth:(f,c)=>Bt(n,t,f,1-f,c),pdfLog:f=>Se(f,1-f,n,t),dlogPdf:f=>(n-1)/f-(t-1)/(1-f),x0:u,lo:0,hi:.5,positive:!0})}function Qt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<0)return NaN;let o=L(n,0,1,e,i);if(o!==void 0)return o;if(t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)){if(t===0&&r===0){let N=i?n:Math.log(n),h=e?N:Math.log1p(-Math.exp(N));return h<-Math.LN2?0:h>-Math.LN2?1:.5}return t===0||r/t===1/0?0:r===0||t/r===1/0?1:.5}let{lower:u,logTarget:s,linearTarget:f}=S(n,e,i),c=Q(t,r,.5,.5,u,!0);return(u?s<=c:s>=c)?sr(t,r,u,s,f):1-sr(r,t,!u,s,f)}function yo(n,t,r,e={}){let{log:i=!1,ncp:o}=e;return o!==void 0?g(n,u=>fr(u,t,r,o,i)):g(n,u=>sn(u,t,r,i))}function vo(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?g(n,s=>ar(s,t,r,u,i,o)):g(n,s=>fn(s,t,r,i,o))}function Fo(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?g(n,s=>cr(s,t,r,u,i,o)):g(n,s=>Qt(s,t,r,i,o))}function lr(n,t){let r=t<1e-250,e=r?t*2**500:t;return{ratioK:r?-1:0,cdf:(i,o,u)=>O(n+i,t,o,u),inc:(i,o)=>{let[u,s]=hr(n,i,t);return o?A(u,t,!0)+s:A(u,t,!1)*(1+s)},ratio:i=>_([e,0],E(n,i)),incLogDD:i=>{let[o,u]=hr(n,i,t);return F(un(o,t),[u,0])}}}function hr(n,t,r){let[e,i]=E(n,t);return[e,i===0?0:i*(Math.log(r)-pt(e+1))]}function mr(n,t){return n>=0&&t>=0&&Number.isFinite(n)&&Number.isFinite(t)}function Mr(n,t,r,e){let i=r/2;if(i*(n/2)>1e18){let s=Be(n,t,r);return e?{lin:-Math.expm1(s),log:Math.log1p(-Math.exp(s))}:{lin:Math.exp(s),log:s}}let o=lr(t/2,Math.max(n/2,Number.MIN_VALUE)),u=tr(i,o,e);if(u.lin>.5){let s;return{lin:u.lin,get log(){return s??=Math.log1p(-ft(i,o,!e,!1)),s}}}return u}function Be(n,t,r){let e=.5-Math.sqrt(r/n)/2-(t-3)/(4*n);return pr(n,t,r,!0)-Math.log(e)}function cn(n,t,r,e,i){let o=Mr(n,t,r,e);return i?o.log:o.lin}function qe(n,t){let r=NaN,e=!0,i={lin:NaN,log:NaN};return(o,u)=>((o!==r||u!==e)&&(i=Mr(o,n,t,u),r=o,e=u),i)}function dr(n,t,r,e){let i=t/2,o=n/2,u=r/2,s=(-(i-1)+Math.sqrt((i-1)*(i-1)+4*u*o))/2;return u*o>1e18?pr(n,t,r,e):Gt(u,lr(i,o),f=>i+f,s,n,e)}function pr(n,t,r,e){let i=t/2-1,o=Math.sqrt(r*n),u=4*i*i,s=1,f=1;for(let N=1;N<30&&(s*=-(u-(2*N-1)*(2*N-1))/(8*N*o),f+=s,!(Math.abs(s)<1e-17*Math.abs(f)));N++);let c=Math.sqrt(n)-Math.sqrt(r),a=-Math.LN2-c*c/2+i/2*Math.log(n/r)-.5*Math.log(2*Math.PI*o)+Math.log(f);return e?a:Math.exp(a)}function gr(n,t,r,e){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:mr(t,r)?r===0?st(n,t/2,2,e):n<0||n===1/0?e?-1/0:0:n===0?t<2?1/0:t===2?e?-r/2-Math.LN2:Math.exp(-r/2)/2:e?-1/0:0:dr(n,t,r,e):NaN}function br(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!mr(t,r))return NaN;if(n<0)return I(e,i);if(n===0){if(t>0)return I(e,i);let o=-r/2;return e?i?o:Math.exp(o):i?o<-Math.LN2?Math.log1p(-Math.exp(o)):Math.log(-Math.expm1(o)):-Math.expm1(o)}return r===0?n===1/0?b(e,i):O(t/2,Math.max(n/2,Number.MIN_VALUE),e,i):n===1/0?b(e,i):cn(n,t,r,e,i)}function Ir(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!(t>=0&&r>=0&&Number.isFinite(t)))return NaN;let o=L(n,0,1/0,e,i);if(o!==void 0)return o;if(!Number.isFinite(r))return i&&Math.exp(n)===1?e?1/0:0:NaN;if(r===0)return J(n,t/2,2,e,i);let{lower:u,logTarget:s,linearTarget:f}=S(n,e,i),c=qe(t,r),a=cn(Number.MIN_VALUE,t,r,u,!0);if(u?a>=s:a<=s)return 0;let N=(t+2*r)/(t+r),h=(t+r)*(t+r)/(t+2*r),l=N*J(s,h/2,2,u,!0);(!(l>0)||!Number.isFinite(l))&&(l=t+r);let m=Math.max(l,t+r,1);for(let M=0;M<2e3;M++){let p=cn(m,t,r,u,!0);if(u?p>=s:p<=s)break;m*=2}return W({logTarget:s,...f!==void 0&&{linearTarget:f},lower:u,cdf:(M,p)=>c(M,p).lin,cdfLog:(M,p)=>c(M,p).log,pdfLog:M=>dr(M,t,r,!0),x0:Math.min(l,m),lo:0,hi:m,positive:!0})}function vr(n,t,r,e){let i=E(n,t),o=r[0]<1e-250,u=o?[r[0]*2**500,r[1]*2**500]:r;return{ratioK:o?-1:0,cdf:(s,f,c)=>St(n+s,t,r,e,f,c),inc:(s,f)=>{let[c,a]=yr(n,t,s,r),N=t/(c+t);return f?w(c,t,r,e,!0)+Math.log(N)+a:w(c,t,r,e,!1)*N*(1+a)},ratio:s=>_(q(u,F(i,[s-1,0])),E(n,s)),incLogDD:s=>{let[f,c]=yr(n,t,s,r);if(!(r[0]>1e-305&&e[0]>1e-305)){let h=We(f,t,r,e);return typeof h=="number"?h+c:F(h,[c,0])}let{e:a,logDenom:N}=ut(f,t,r,e);return F([-a[0],-a[1]],[-.5*N+Math.log(t/(f+t))+c,0])}}}function yr(n,t,r,e){let[i,o]=E(n,r);return o===0?[i,0]:[i,o*(Math.log(e[0])+e[1]/e[0]+pt(i+t)-pt(i+1))]}function We(n,t,r,e){if(!(r[0]>0&&e[0]>0))return-1/0;let i=F(zt(G(r),n),zt(G(e),t));return F(F(i,P(wn(n,t))),[-Math.log(n),0])}function hn(n){return n<=.5?[[n,0],E(1,-n)]:[E(1,-(1-n)),[1-n,0]]}function ln(n,t,r,e,i,o,u){let s=vr(n,t,e,i),f=r/2,c=ft(f,s,o,!1);return u?c>.5?Math.log1p(-ft(f,s,!o,!1)):c>=1e-280?Math.log(c):ft(f,s,o,!0):c}function Fr(n,t,r,e,i,o,u){let s=r/2,f=e[0],c=s*f,a=n-1-c,N=(-a+Math.sqrt(Math.max(0,a*a+4*c*(n+t-1))))/2;return Gt(s,vr(n,t,e,i),h=>n+h,N,o,u)}function mn(n,t,r){return n>0&&t>0&&Number.isFinite(n)&&Number.isFinite(t)&&r>=0&&Number.isFinite(r)}function xr(n,t,r,e,i){let[o,u]=hn(n),s=q(o,u);return Fr(t,r,e,o,u,s[0]+s[1],i)}function fr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!mn(t,r,e))return NaN;if(e===0)return sn(n,t,r,i);if(n<0||n>1)return i?-1/0:0;let o=e/2;return n===0?t>1?i?-1/0:0:t<1?1/0:i?Math.log(r)-o:r*Math.exp(-o):n===1?r>1?i?-1/0:0:r<1?1/0:i?Math.log(t+o):t+o:xr(n,t,r,e,i)}function ar(n,t,r,e,i,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(n<=0)return I(i,o);if(n>=1)return b(i,o);if(!mn(t,r,e))return NaN;if(e===0)return fn(n,t,r,i,o);let[u,s]=hn(n);return ln(t,r,e,u,s,i,o)}function cr(n,t,r,e,i,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!(t>0&&r>0&&e>=0))return NaN;let u=L(n,0,1,i,o);if(u!==void 0)return u;if(!mn(t,r,e))return NaN;if(e===0)return Qt(n,t,r,i,o);let{lower:s,logTarget:f,linearTarget:c}=S(n,i,o),a=(m,M,p)=>{let[d,x]=hn(m);return ln(t,r,e,d,x,M,p)},N=a(Number.MIN_VALUE,s,!0);if(s?N>=f:N<=f)return 0;let h=a(1-Number.EPSILON/2,s,!0);if(s?h<f:h>f)return 1;let l=Qt(f,t+e/2,r,s,!0);return l>0&&l<1||(l=.5),W({logTarget:f,...c!==void 0&&{linearTarget:c},lower:s,cdf:(m,M)=>a(m,M,!1),cdfLog:(m,M)=>a(m,M,!0),pdfLog:m=>xr(m,t,r,e,!0),x0:l,lo:0,hi:1,positive:!0})}function Lr(n,t,r){let e=K(t,n);if(Number.isFinite(e[0])&&Number.isFinite(e[1])&&Math.abs(e[0])<1e290){let o=F(e,[r,0]);return[_(e,o),_([r,0],o)]}let i=r/t/n;return[E(1,-i),[i,0]]}function _r(n,t,r,e,i){if(t/r*n<1e-306){let s=t/2,f=-e/2+s*(Math.log(t/r)+Math.log(n))-Z(s,r/2)-Math.log(n);return i?f:Math.exp(f)}let[o,u]=Lr(n,t,r);return Fr(t/2,r/2,e,o,u,n,i)}function Dr(n,t,r,e,i,o){let u=t/2,s=-e/2+u*(Math.log(t/r)+Math.log(n))-Math.log(u)-Z(u,r/2);return i?o?s:Math.exp(s):o?-Math.exp(s):-Math.expm1(s)}function xt(n,t,r,e,i,o){if(t/r*n<1e-306)return Dr(n,t,r,e,i,o);let[u,s]=Lr(n,t,r);return ln(t/2,r/2,e,u,s,i,o)}function Er(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!(t>0&&r>0&&e>=0))return NaN;if(n<0)return i?-1/0:0;if(!Number.isFinite(e))return NaN;if(t===1/0)return r===1/0?n===1?1/0:i?-1/0:0:n===0?NaN:jt(n,t,r,i);if(r===1/0){let o=gr(n*t,t,e,i);return i?o+Math.log(t):o*t}return n===1/0?NaN:n===0?t<2?1/0:t>2?i?-1/0:0:i?-e/2:Math.exp(-e/2):e===0?jt(n,t,r,i):_r(n,t,r,e,i)}function Cr(n,t,r,e,i,o){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e)?NaN:!(t>0&&r>0&&e>=0)||!Number.isFinite(e)?NaN:t===1/0&&r===1/0?NaN:n<=0?I(i,o):n===1/0?b(i,o):t===1/0?NaN:r===1/0?br(n*t,t,e,i,o):t/r*n<1e-306?Dr(n,t,r,e,i,o):e===0?Nn(n,t,r,i,o):xt(n,t,r,e,i,o)}function Ar(n,t,r,e,i,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!(t>0&&r>0&&e>=0)||!Number.isFinite(e))return NaN;let u=L(n,0,1/0,i,o);return u!==void 0?u:t===1/0?NaN:r===1/0?Ir(n,t,e,i,o)/t:e===0?Kt(n,t,r,i,o):Oe(n,t,r,e,i,o)}function Oe(n,t,r,e,i,o){let{lower:u,logTarget:s,linearTarget:f}=S(n,i,o),c=xt(Number.MIN_VALUE,t,r,e,u,!0);if(u?c>=s:c<=s)return 0;let a=xt(Number.MAX_VALUE,t,r,e,u,!0);if(u?a<s:a>s)return 1/0;let N=(t+e)*(t+e)/(t+2*e),h=(t+e)/t*Kt(s,N,r,u,!0);return(!(h>0)||!Number.isFinite(h))&&(h=1),W({logTarget:s,...f!==void 0&&{linearTarget:f},lower:u,cdf:(l,m)=>xt(l,t,r,e,m,!1),cdfLog:(l,m)=>xt(l,t,r,e,m,!0),pdfLog:l=>_r(l,t,r,e,!0),x0:h,lo:0,hi:1/0,positive:!0})}function Rr(n,t,r,e){let i=K(t,n),o,u;if(Number.isFinite(i[0])&&Number.isFinite(i[1])&&Math.abs(i[0])<1e290){let N=F(i,[r,0]);o=_(i,N),u=_([r,0],N)}else u=[r/t/n,0],o=[1,-u[0]];let s=o[0],f=u[0];if(t>=2){let N=t*f/2,h=w((t-2)/2,r/2,o,u,e);return e?Math.log(N)+h:N*h}let c=t/(r+t*n)*t*r/(2*(t+r)*s),a=w(t/2,r/2,o,u,e);return e?Math.log(c)+a:c*a}function jt(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<=0||r<=0)return NaN;if(n<0)return y(e);if(n===0)return t>2?y(e):t===2?e?0:1:1/0;if(!Number.isFinite(t)&&!Number.isFinite(r))return n===1?1/0:y(e);if(!Number.isFinite(r))return st(n,t/2,2/t,e);if(!Number.isFinite(t)){let i=st(1/n,r/2,2/r,e);return e?i-2*Math.log(n):i/(n*n)}return Number.isFinite(n)?Rr(n,t,r,e):t<2?NaN:y(e)}function Mn(n,t,r,e,i){let o=K(t,n);if(Number.isFinite(o[0])&&Number.isFinite(o[1])&&Math.abs(o[0])<1e290){let s=F(o,[r,0]);return St(t/2,r/2,_(o,s),_([r,0],s),e,i)}let u=r/t/n;return Q(t/2,r/2,1-u,u,e,i)}function Ue(n,t,r,e){let i=an(n/2,t/2,r,e);if(i===void 0)return 1;let o=t*i/(n*(1-i));return o>0&&Number.isFinite(o)?o:1}function He(n,t,r,e){let i=K(t,n);if(Number.isFinite(i[0])&&Number.isFinite(i[1])&&Math.abs(i[0])<1e290){let u=F(i,[r,0]);return Zn(t/2,r/2,_(i,u),_([r,0],u),e)}let o=r/t/n;return Bt(t/2,r/2,1-o,o,e)}function Nn(n,t,r,e,i){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<=0||r<=0?NaN:n<=0?I(e,i):n===1/0?b(e,i):!Number.isFinite(t)&&!Number.isFinite(r)?n===1?i?-Math.LN2:.5:n<1?I(e,i):b(e,i):Number.isFinite(r)?Number.isFinite(t)?Mn(n,t,r,e,i):qt(r/n,r/2,2,!e,i):qt(n*t,t/2,2,e,i)}function Kt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<=0||r<=0)return NaN;let o=L(n,0,1/0,e,i);if(o!==void 0)return o;if(!Number.isFinite(t)&&!Number.isFinite(r))return 1;if(!Number.isFinite(r))return J(n,t/2,2,e,i)/t;if(!Number.isFinite(t))return r/J(n,r/2,2,!e,i);let{lower:u,logTarget:s,linearTarget:f}=S(n,e,i);return u&&(s+Math.log(t/2)+Z(t/2,r/2))/(t/2)+Math.log(r/t)<-746?0:!u&&-(s+Math.log(r/2)+Z(t/2,r/2))/(r/2)+Math.log(r/t)>709.78?1/0:W({logTarget:s,...f!==void 0&&{linearTarget:f},lower:u,cdf:(c,a)=>Mn(c,t,r,a,!1),cdfLog:(c,a)=>Mn(c,t,r,a,!0),cdfBoth:(c,a)=>He(c,t,r,a),pdfLog:c=>Rr(c,t,r,!0),dlogPdf:c=>(t/2-1)/c-(t+r)/2*(t/(r+t*c)),x0:Ue(t,r,u,s),lo:0,hi:1/0,positive:!0})}function ru(n,t,r,e={}){let{log:i=!1,ncp:o}=e;return o!==void 0?g(n,u=>Er(u,t,r,o,i)):g(n,u=>jt(u,t,r,i))}function eu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?g(n,s=>Cr(s,t,r,u,i,o)):g(n,s=>Nn(s,t,r,i,o))}function iu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?g(n,s=>Ar(s,t,r,u,i,o)):g(n,s=>Kt(s,t,r,i,o))}function dn(n,t){return Wt(n)||n<0||!Number.isFinite(n)||t<0||t>1}function Ge(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(dn(t,r))return NaN;if(Wt(n)||n<0||!Number.isFinite(n))return y(e);let i=Math.round(n),o=Math.round(t);if(i>o)return y(e);let u=r<=.5?[r,0]:E(1,-(1-r)),s=r<=.5?E(1,-r):[1-r,0];return w(i,o-i,u,s,e)}function Sr(n,t,r,e,i){return Q(n+1,t-n,r,1-r,!e,i)}function Qe(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(dn(t,r))return NaN;let o=Math.round(t);if(n<0)return I(e,i);let u=Math.floor(n+1e-7);return o<=u?b(e,i):r===0?b(e,i):r===1?I(e,i):Sr(u,o,r,e,i)}function je(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!Number.isFinite(t)||!Number.isFinite(r)||r<0||r>1||t<0)return NaN;let o=L(n,0,Ke(t),e,i);if(o!==void 0)return o;if(dn(t,r))return NaN;let u=Math.round(t);if(r===0||u===0)return 0;if(r===1)return u;let s=1-r,f=u*r,c=Math.sqrt(u*r*s),a=(s-r)/c,N=R(n,{lowerTail:e,logP:i}),h=f+c*(N+a*(N*N-1)/6);return j({p:n,lowerTail:e,logP:i,cdf:(l,m,M)=>l>=u?b(m,M):Sr(l,u,r,m,M),y0:Number.isFinite(h)?h:f,lo:0,hi:u})}function mu(n,t,r,e={}){let i=e.log??!1;return g(n,o=>Ge(o,t,r,i))}function Mu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return g(n,u=>Qe(u,t,r,i,o))}function du(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return g(n,u=>je(u,t,r,i,o))}function Ke(n){let t=Math.round(n);return Math.abs(n%1)===.5&&t%2!==0?t-1:t}function pn(n,t,r,e){if(n===0&&t===0)return{e:[0,0],logDenom:0};if(n===0||t===0){let i=n+t,[o,u]=n===0?[e,r]:[r,e];return{e:u[0]<.1?F(Rt(i,q([i,0],o)),q([i,0],u)):P(q([i,0],G(o))),logDenom:0}}return ut(n,t,r,e)}function Wr(n,t,r,e){let i=t+r,o=_([e,0],[i,0]),u=_([i-e,0],[i,0]),s=pn(n,t-n,o,u),f=pn(e-n,r-e+n,o,u),c=pn(e,i-e,o,u);return{e:Kn(F(s.e,f.e),c.e),logDenom:s.logDenom+f.logDenom-c.logDenom}}function Or(n,t){let[r,e]=n.e,i=t*Math.exp(-.5*n.logDenom);return r<700?Math.exp(-r)*(1-e)*i:Math.exp(700-r)*(1-e)*i*Math.exp(-700)}function Ur(n){return-n.e[0]-n.e[1]-.5*n.logDenom}function Vt(n,t,r){return[Math.max(0,r-t),Math.min(r,n)]}function Ve(n,t,r,e,i){if([n,t,r,e].some(Number.isNaN))return NaN;if(![t,r,e].every(Number.isFinite)||U(t)||U(r)||U(e))return NaN;if(t=C(t),r=C(r),e=C(e),t<0||r<0||e<0||e>t+r)return NaN;if(U(n))return y(i);n=C(n);let[o,u]=Vt(t,r,e);if(n<o||n>u)return y(i);if(e===0||e===t+r)return i?0:1;let s=Wr(n,t,r,e);return i?Ur(s):Or(s,1)}function Br(n,t,r,e){return _(K(n,t),K(r,e))}function Xe(n,t,r,e,i,o,u){let s=[1,0],f=[1,0],c=n;for(;!(i?c<=o:c>=u);){let a=i?Br(c,r-e+c,t-c+1,e-c+1):Br(t-c,e-c,c+1,r-e+c+1);s=q(s,a),f=F(f,s),c+=i?-1:1;let N=a[0];if(N<1&&s[0]*N/(1-N)<f[0]*2**-60)break}return f[0]+f[1]}function Hr(n,t,r,e,i,o){let[u,s]=Vt(t,r,e),f=t+r,c=n*f<e*t,a=qr(n,t,r,e,c,u,s);if(a.value>.5){let N=qr(n,t,r,e,!c,u,s);N.value<a.value&&(a=N,c=!c)}return c===i?o?a.value>1e-300?Math.log(a.value):Ur(a.form)+Math.log(a.sum):a.value:o?Math.log1p(-a.value):1-a.value}function qr(n,t,r,e,i,o,u){let s=i?n:n+1,f=Wr(s,t,r,e),c=Xe(s,t,r,e,i,o,u);return{form:f,sum:c,value:Or(f,c)}}function Gr(n,t,r){if([n,t,r].every(Number.isFinite)&&(n=C(n),t=C(t),r=C(r),!(n<0||t<0||r<0||r>n+t)))return[n,t,r]}function we(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;let u=Gr(t,r,e);if(u===void 0)return NaN;[t,r,e]=u;let s=Math.floor(n+1e-7),[f,c]=Vt(t,r,e);return s<f?I(i,o):s>=c?b(i,o):Hr(s,t,r,e,i,o)}function Ze(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;let u=Gr(t,r,e);if(u===void 0)return NaN;[t,r,e]=u;let[s,f]=Vt(t,r,e),c=L(n,s,f,i,o);if(c!==void 0)return c;if(s===f)return s;let a=t+r,N=e*t/a,h=Math.sqrt(e*t/a*(r/a)*(a-e)/Math.max(a-1,1)),l=R(n,{lowerTail:i,logP:o}),m=N+h*l;return j({p:n,lowerTail:i,logP:o,cdf:(M,p,d)=>M<s?I(p,d):M>=f?b(p,d):Hr(M,t,r,e,p,d),y0:Number.isFinite(m)?m:N,lo:s,hi:f})}function Lu(n,t,r,e,i={}){let o=i.log??!1;return g(n,u=>Ve(u,t,r,e,o))}function _u(n,t,r,e,i={}){let{lowerTail:o=!0,logP:u=!1}=i;return g(n,s=>we(s,t,r,e,o,u))}function Du(n,t,r,e,i={}){let{lowerTail:o=!0,logP:u=!1}=i;return g(n,s=>Ze(s,t,r,e,o,u))}var $e=2**900,Qr=-900,tt=new Map,Ye=2**21,Xt=0,Te=2**25;function Pe(n,t){if(t+1>Te)throw new RangeError(`signrank: n = ${n} needs too large a table (${t+1} entries)`);let r=new Float64Array(t+1);r[0]=1;let e=0,i=Math.min(n,t);for(let f=1;f<=i;f++){for(let c=t;c>=f;c--)r[c]+=r[c-f];if(r[Math.min(t,Math.floor(f*(f+1)/4))]>$e){let c=2**Qr;for(let a=0;a<=t;a++)r[a]*=c;e-=Qr}}let o=new Float64Array(t+1),u=0,s=0;for(let f=0;f<=t;f++){let c=r[f]-s,a=u+c;s=a-u-c,u=a,o[f]=u}return{n,len:t+1,count:r,cum:o,scale:e}}function gn(n,t){let r=tt.get(n);if(r!==void 0&&r.len>t)return tt.delete(n),tt.set(n,r),r;let e=Math.floor(n*(n+1)/4),i=Math.min(e,Math.max(t,r===void 0?0:2*r.len)),o=Pe(n,i);r!==void 0&&(tt.delete(n),Xt-=r.len),tt.set(n,o),Xt+=o.len;for(let[u,s]of tt){if(Xt<=Ye||u===n)break;tt.delete(u),Xt-=s.len}return o}function bn(n,t,r){let e=t.scale-t.n,i=Math.trunc(e/2),o=n*2**i*2**(e-i);return r?o>=1e-300?Math.log(o):Math.log(n)+e*Math.LN2:o}function In(n){return Number.isFinite(n)?(n=C(n),n<=0?NaN:n):NaN}function Je(n,t,r){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=In(t),Number.isNaN(t))return NaN;if(U(n))return y(r);n=C(n);let e=t*(t+1)/2;if(n<0||n>e)return y(r);let i=Math.min(n,e-n),o=gn(t,i);return bn(o.count[i],o,r)}function jr(n,t,r,e){let i=t*(t+1)/2,o=n,u=i-n-1,s=r?o:u,f=r?u:o;if(s<=f){let N=gn(t,s);return bn(N.cum[s],N,e)}let c=gn(t,f),a=bn(c.cum[f],c,!1);return e?Math.log1p(-a):1-a}function ze(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=In(t),Number.isNaN(t))return NaN;let i=C(n+1e-7),o=t*(t+1)/2;return i<0?I(r,e):i>=o?b(r,e):jr(i,t,r,e)}function ke(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=In(t),Number.isNaN(t))return NaN;let i=t*(t+1)/2,o=L(n,0,i,r,e);if(o!==void 0)return o;let u=i/2,s=Math.sqrt(t*(t+1)*(2*t+1)/24),f=u+s*R(n,{lowerTail:r,logP:e});return j({p:n,lowerTail:r,logP:e,cdf:(c,a,N)=>c<0?I(a,N):c>=i?b(a,N):jr(c,t,a,N),y0:Number.isFinite(f)?f:u,lo:0,hi:i})}function qu(n,t,r={}){let e=r.log??!1;return g(n,i=>Je(i,t,e))}function Wu(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return g(n,o=>ze(o,t,e,i))}function Ou(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return g(n,o=>ke(o,t,e,i))}var $t=960,ti=2**25,wt=134217729,nt=new Map,ni=2**21,Zt=0;function ri(n,t,r){if(r+1>ti)throw new RangeError(`wilcox: m = ${n}, n = ${t} needs too large a table (${r+1} entries)`);let e=new Float64Array(r+1),i=new Float64Array(r+1);e[0]=2**$t;for(let f=1;f<=n;f++){let c=Math.min(r,f*t),a=t+f,N=wt*f,h=N-(N-f),l=f-h;N=wt*a;let m=N-(N-a),M=a-m;for(let d=0;d<=c;d++){let x=e[d];if(x===0)continue;let v=x*f;N=wt*x;let D=N-(N-x),lt=x-D,mt=D*h-v+D*l+lt*h+lt*l+i[d]*f,B=v/a,et=B*a;N=wt*B;let it=N-(N-B),ot=B-it,he=it*m-et+it*M+ot*m+ot*M,Qn=(v-et-he+mt)/a,jn=B+Qn;i[d]=Qn-(jn-B),e[d]=jn}let p=t+f;for(let d=c;d>=p;d--)Kr(e,i,d,d-p,-1);for(let d=f;d<=c;d++)Kr(e,i,d,d-f,1)}let o=new Float64Array(r+1),u=0,s=0;for(let f=0;f<=r;f++){let c=e[f],a=u+c,N=a-u,h=u-(a-N)+(c-N);h+=s+i[f],u=a+h,s=h-(u-a),o[f]=u}return{m:n,n:t,len:r+1,prob:e,cum:o}}function Kr(n,t,r,e,i){let o=n[r],u=i*n[e],s=o+u,f=s-o,c=o-(s-f)+(u-f);c+=t[r]+i*t[e];let a=s+c;t[r]=c-(a-s),n[r]=a}function yn(n,t,r){n>t&&([n,t]=[t,n]);let e=`${n},${t}`,i=nt.get(e);if(i!==void 0&&i.len>r)return nt.delete(e),nt.set(e,i),i;let o=Math.floor(n*t/2),u=Math.min(o,Math.max(r,i===void 0?0:2*i.len)),s=ri(n,t,u);i!==void 0&&(nt.delete(e),Zt-=i.len),nt.set(e,s),Zt+=s.len;for(let[f,c]of nt){if(Zt<=ni||f===e)break;nt.delete(f),Zt-=c.len}return s}function vn(n,t){let r=n*2**-($t/2)*2**-($t/2);return t?r>=1e-300?Math.log(r):Math.log(n)-$t*Math.LN2:r}function Fn(n,t){if(!(!Number.isFinite(n)||!Number.isFinite(t)))return n=C(n),t=C(t),n<=0||t<=0?void 0:[n,t]}function ei(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let i=Fn(t,r);if(i===void 0)return NaN;if([t,r]=i,U(n))return y(e);n=C(n);let o=t*r;if(n<0||n>o)return y(e);let u=Math.min(n,o-n);return vn(yn(t,r,u).prob[u],e)}function Vr(n,t,r,e,i){let o=t*r,u=e?n:o-n-1,s=e?o-n-1:n;if(u<=s)return vn(yn(t,r,u).cum[u],i);let f=vn(yn(t,r,s).cum[s],!1);return i?Math.log1p(-f):1-f}function ii(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=Fn(t,r);if(o===void 0)return NaN;[t,r]=o;let u=Math.floor(n+1e-7);return u<0?I(e,i):u>=t*r?b(e,i):Vr(u,t,r,e,i)}function oi(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=Fn(t,r);if(o===void 0)return NaN;[t,r]=o;let u=t*r,s=L(n,0,u,e,i);if(s!==void 0)return s;let f=u/2,c=Math.sqrt(u*(t+r+1)/12),a=f+c*R(n,{lowerTail:e,logP:i});return j({p:n,lowerTail:e,logP:i,cdf:(N,h,l)=>N<0?I(h,l):N>=u?b(h,l):Vr(N,t,r,h,l),y0:Number.isFinite(a)?a:f,lo:0,hi:u})}function Vu(n,t,r,e={}){let i=e.log??!1;return g(n,o=>ei(o,t,r,i))}function Xu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return g(n,u=>ii(u,t,r,i,o))}function wu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return g(n,u=>oi(u,t,r,i,o))}var T=128,Sn=Number.EPSILON,Bn=Float64Array.from({length:2*T+1},(n,t)=>Math.cos(Math.PI*t/T));function ui(n){let t=new Float64Array(n+1);for(let r=0;r<=n;r++){let e=0;for(let i=0;i<=n;i+=2)e+=(i===0||i===n?.5:1)*Bn[i*r%(2*n)*(T/n)]*2/(1-i*i);t[r]=(r===0||r===n?.5:1)*2*e/n}return t}var si=new Map([16,32,64,128].map(n=>[n,ui(n)]));function fi(n,t){let r=si.get(t),e=T/t,i=0,o=0;for(let s=0;s<=t;s++)i+=r[s]*n[s],o+=Math.abs(r[s]*n[s]);let u=0;for(let s=t-7;s<=t;s++){let f=.5*(n[0]+(s%2===0?n[t]:-n[t]));for(let c=1;c<t;c++)f+=n[c]*Bn[s*c%(2*t)*e];f*=2/t,s===t&&(f*=.5),u=Math.max(u,Math.abs(f))}return{integral:i,tail:u,scale:o}}var _t=class{f;a;b;c;h;values=new Float64Array(T+1);have=new Uint8Array(T+1);N=0;integral=0;error=1/0;constructor(t,r,e){this.f=t,this.a=r,this.b=e,this.c=.5*(r+e),this.h=.5*(e-r)}advance(t){let r=T/t,e=new Float64Array(t+1);for(let o=0;o<=t;o++){let u=o*r;this.have[u]||(this.values[u]=this.f(this.c+this.h*Bn[u]),this.have[u]=1),e[o]=this.values[u]}let i=fi(e,t);this.N=t,this.integral=i.integral*this.h,this.error=Math.max(i.tail*4/t,4*Sn*i.scale)*Math.abs(this.h)}};function Tt(n,t,r){let e=[];for(let o=0;o+1<t.length;o++){let u=new _t(n,t[o],t[o+1]);u.advance(16),e.push(u)}for(let o=0;o<40;o++){let u=0;for(let a of e)u+=a.integral;let s=r*Math.abs(u)/e.length,f=!0,c=[];for(let a of e){if(a.error<=s||a.error<=4*Sn*Math.abs(a.integral)){c.push(a);continue}if(f=!1,a.N<T)a.advance(2*a.N),c.push(a);else{let N=new _t(n,a.a,a.c),h=new _t(n,a.c,a.b);N.advance(16),h.advance(16),c.push(N,h)}}if(e=c,f)break}let i=0;for(let o of e)i+=o.integral;return i}function wr(n,t,r){let e=Math.max(1,Math.ceil((t-n)/r));return Array.from({length:e+1},(i,o)=>o===e?t:n+(t-n)*o/e)}var Zr=2e-15,$r=1e-16,ai={lowerTail:!1},ci={logP:!0},Ni={lowerTail:!1,logP:!0},Et=.9189385332046728,Pt=n=>dt(n),ct=n=>dt(n,ai),qn=n=>dt(n,ci),Wn=n=>dt(n,Ni),hi=.3989422804014327;function Nt(n){let t=Math.round(n*16)/16,r=n-t;return hi*Math.exp(-.5*t*t)*Math.exp(-.5*r*(n+t))}var _n=[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],Yr=[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626];function li(n,t){let r=n-.5*t,e=.5*t,i=0;for(let o=0;o<4;o++)i+=Yr[o]*(Nt(r-e*_n[o])+Nt(r+e*_n[o]));return i*e}function mi(n,t){let r=n-.5*t,e=.5*t,i=0;for(let o=0;o<4;o++){let u=e*_n[o];i+=Yr[o]*(Math.exp(r*u-u*u/2)+Math.exp(-r*u-u*u/2))}return-Et-r*r/2+Math.log(i*e)}var On=(n,t)=>t*Math.max(1,Math.abs(n),Math.abs(n-t))<.5;function ht(n,t){let r=n-t,e=r-n,i=n-(r-e)+(-t-e);return{ah:r,al:i}}function Dt(n,t){return Pt(n)+Nt(n)*t}function Mi(n,t){return ct(n)-Nt(n)*t}function Tr(n,t){if(On(n,t))return li(n,t);let{ah:r,al:e}=ht(n,t);return r>=0?Mi(r,e)-ct(n):n<=0?Pt(n)-Dt(r,e):1-Dt(r,e)-ct(n)}function di(n,t,r){if(n>0&&n-t<0&&!On(n,t)){let{ah:i,al:o}=ht(n,t);return Math.exp(r*Math.log1p(-(Dt(i,o)+ct(n))))}let e=Tr(n,t);return e>0?e**r:0}function pi(n,t){return n>0?Math.exp(t*Math.log1p(-ct(n))):Pt(n)**t}function Pr(n,t){let{ah:r,al:e}=ht(n,t),i=qn(r);return i+e*Math.exp(-Et-r*r/2-i)}function gi(n,t){let{ah:r,al:e}=ht(n,t),i=Wn(r);return i-e*Math.exp(-Et-r*r/2-i)}function Jr(n,t){if(On(n,t))return mi(n,t);if(n-t>=0){let o=gi(n,t);return o+Math.log(-Math.expm1(Wn(n)-o))}if(n<=0){let o=qn(n);return o+Math.log(-Math.expm1(Pr(n,t)-o))}let{ah:e,al:i}=ht(n,t);return Math.log1p(-Dt(e,i)-ct(n))}var zr=2,xn=1e-18;function kr(n,t,r){let e=wr(t,r,zr),i=e.map(n),o=0;for(let h=1;h<i.length;h++)i[h]>i[o]&&(o=h);let u=i[o];if(!(u>0))return 0;let s=Math.max(o-1,0),f=Math.min(o+1,i.length-1);for(;s>0&&i[s]>u*xn;)s--;for(;f<i.length-1&&i[f]>u*xn;)f++;let c=u*xn,a=e[s],N=e[f];if(i[s]<=c){let h=e[s+1];for(let l=0;l<2;l++){let m=.5*(a+h);n(m)<=c?a=m:h=m}}if(i[f]<=c){let h=e[f-1];for(let l=0;l<2;l++){let m=.5*(N+h);n(m)<=c?N=m:h=m}}return Tt(n,[a,N],$r)}function te(n,t,r){let e=wr(t,r,zr),i=e.map(n),o=0;for(let v=1;v<i.length;v++)i[v]>i[o]&&(o=v);if(!(i[o]>-1/0))return-1/0;let u=e[Math.max(o-1,0)],s=e[Math.min(o+1,e.length-1)],f=(Math.sqrt(5)-1)/2,c=s-f*(s-u),a=u+f*(s-u),N=n(c),h=n(a);for(let v=0;v<80&&s-u>1e-12*Math.max(1,Math.abs(u));v++)N<h?(u=c,c=a,N=h,a=u+f*(s-u),h=n(a)):(s=a,a=c,h=N,c=s-f*(s-u),N=n(c));let l=N>h?c:a,m=Math.max(N,h);i[o]>m&&(l=e[o],m=i[o]);let M=v=>{let D=v<0?t:r,lt=Math.max(1e-6,.001*(e[1]-e[0])),mt=l;for(;;){let B=l+v*lt;if(v<0?B<=D:B>=D)return D;if(n(B)<m-46){let et=B;for(let it=0;it<6;it++){let ot=.5*(mt+et);n(ot)<m-46?et=ot:mt=ot}return et}mt=B,lt*=2}},p=M(-1),d=M(1),x=[...new Set([p,l,d])].sort((v,D)=>v-D);return m+Math.log(Tt(v=>Math.exp(n(v)-m),x,$r))}var Un=-10,Hn=10;function bi(n,t){return n<=0?0:t*kr(r=>Nt(r)*di(r,n,t-1),Un,Hn)}function ne(n,t){if(n<=0)return 1;let r=o=>{let u=Pt(o);if(u===0)return 0;let{ah:s,al:f}=ht(o,n),c=Dt(s,f),a=c<.5*u?-Math.expm1((t-1)*Math.log1p(-c/u)):-Math.expm1((t-1)*Math.log(Tr(o,n)/u));return Nt(o)*pi(o,t-1)*a};if(n>60)return 0;let[e,i]=re(n);return t*kr(r,e,i)}function re(n){return n>40?[n/2-15,n/2+15]:[Un,n+Hn]}function ee(n,t){if(n>100)return-Math.exp(ie(n,t));let r=e=>-Et-e*e/2+(t-1)*Jr(e,n);return Math.log(t)+te(r,Un,Hn)}function ie(n,t){if(n>100)return Math.log(t*(t-1))+Wn(n/Math.SQRT2);let r=o=>{let u=qn(o),s=Pr(o,n)-u,f;return s<-40?f=Math.log(t-1)+s:s<-Math.LN2?f=Math.log(-Math.expm1((t-1)*Math.log1p(-Math.exp(s)))):f=Math.log(-Math.expm1((t-1)*(Jr(o,n)-u))),-Et-o*o/2+(t-1)*u+f},[e,i]=re(n);return Math.log(t)+te(r,e,i)}function Ii(n,t){let r=-1/0;for(let e of t)r=Math.max(r,n(e));for(let e=0;e+1<t.length;e++)r=Math.max(r,n(.5*(t[e]+t[e+1])));if(r===-1/0)return-1/0;for(let e=0;e<4;e++){let i=r,o=Tt(u=>{let s=n(u);return s>i&&(i=s),Math.exp(s-r)},t,Zr);if(Number.isFinite(o)&&i-r<300)return r+Math.log(o);r=i}return NaN}var Y=32,yi=1e-15,at=Math.log(.01),Gn=Math.log(20),oe=Math.log(40),ue=Float64Array.from({length:2*Y+1},(n,t)=>Math.cos(Math.PI*t/Y));function vi(n,t){let r=new Float64Array(t+1);for(let e=0;e<=t;e++){let i=.5*(n[0]+(e%2===0?n[t]:-n[t]));for(let o=1;o<t;o++)i+=n[o]*ue[e*o%(2*t)];i*=2/t,(e===0||e===t)&&(i*=.5),r[e]=i}return r}function Ln(n,t,r){let e=[],i=[[t,r,0]];for(;i.length>0;){let[o,u,s]=i.pop(),f=.5*(o+u),c=.5*(u-o),a=new Float64Array(Y+1),N=1/0;for(let m=0;m<=Y;m++)a[m]=n(f+c*ue[m]),N=Math.min(N,Math.max(1,Math.abs(a[m])));let h=vi(a,Y),l=0;for(let m=Y-3;m<=Y;m++)l=Math.max(l,Math.abs(h[m]));l<=yi*N||s>=14||!a.every(Number.isFinite)?e.push({a:o,b:u,coef:h}):i.push([f,u,s+1],[o,f,s+1])}return e.sort((o,u)=>o.a-u.a)}function Dn(n,t){let r=0,e=n.length-1;for(;r<e;){let a=r+e+1>>1;n[a].a<=t?r=a:e=a-1}let{a:i,b:o,coef:u}=n[r],s=(2*t-i-o)/(o-i),f=0,c=0;for(let a=Y;a>=1;a--){let N=2*s*f-c+u[a];c=f,f=N}return s*f-c+u[0]}var Lt=new Map,Fi=64,se=Math.log(1e-10);function fe(n){let t=Lt.get(n);if(t!==void 0)return t;let r=i=>{let o=bi(i,n);return o>1e-290?Math.log(o):ee(i,n)},e=i=>{let o=Math.exp(i);return ne(o,n)*ae(o)};return t={logW:Ln(i=>r(Math.exp(i)),at,Gn),scaledWc:Ln(e,at,oe),smallW:Ln(i=>r(Math.exp(i))-(n-1)*i,se,at)},Lt.size>=Fi&&Lt.delete(Lt.keys().next().value),Lt.set(n,t),t}function ae(n){let t=n*n,r=134217729*n,e=r-(r-n),i=n-e,o=e*e-t+2*e*i+i*i;return Math.exp(t/4)*(1+o/4)}function xi(n,t){let r=Math.log(n);if(r>=Gn)return 0;let e=fe(t);return r>=at?Dn(e.logW,r):Dn(e.smallW,Math.max(r,se))+(t-1)*r}function En(n,t){return Math.log(n)>=Gn?1:Math.exp(xi(n,t))}function Li(n,t){let r=Math.log(n);return r>=at&&r<=oe?Dn(fe(t).scaledWc,r)/ae(n):r<at?1-En(n,t):ne(n,t)}function Yt(n,t,r,e){if(!e){let o=Math.min(En(n,t),1);return r===1?o:o**r}let i=Math.min(Li(n,t),1);return i<=.5?r===1?i:-Math.expm1(r*Math.log1p(-i)):1-Math.min(En(n,t),1)**r}function Cn(n,t,r,e){if(!e)return r*ee(n,t);let i=ie(n,t);return r===1?i:Math.log(-Math.expm1(r*Math.log1p(-Math.exp(i))))}function An(n,t,r,e,i){if(r===1/0)return Yt(n,t,e,i);let o=r/2,u=Math.log(o),s=_i(o);return Tt(c=>{let{d:a,s:N}=s(c);return a===0?0:a*Yt(n*N,t,e,i)},ce(n,t,r,e,i).map(c=>c-u),Zr)}function _i(n){let t=At(n),r=Math.sqrt(n/(2*Math.PI));return e=>{let i;if(Math.abs(e)<.5){let o=e*e/2;i=o;for(let u=3;u<60&&(o*=e/u,i+=o,!(Math.abs(o)<1e-17*i));u++);}else i=Math.expm1(e)-e;return{d:r*Math.exp(-t-n*i),s:Math.exp(.5*e)}}}function Di(n,t,r,e,i){if(r===1/0)return Cn(n,t,e,i);let o=r/2,u=Math.log(o),s=X(o+1);return Ii(c=>{let a=Math.exp(c),N=a>1e-300?A(o,a,!0):o*c-a-s;return u+N+Cn(Math.exp(Math.log(n)+.5*(c-u)),t,e,i)},ce(n,t,r,e,i,!0))}function ce(n,t,r,e,i,o=!1){let u=r/2,s=u,f=Math.log(u);if(i){let v=2*Math.log(n)-Math.log(4*u);f-=v>30?v:Math.log1p(Math.exp(v))}else s=u+(t-1)*e/2,f=Math.log(s);let c=(v,D)=>[v-9/Math.sqrt(D)-41/D,v+9/Math.sqrt(D)+Math.log1p(41/D)],[a,N]=c(Math.log(u),u),[h,l]=c(f,s),m=o?Math.min(a,h):Math.max(Math.min(a,h),-740),M=Math.max(N,l),p=1/Math.sqrt(u),d=1/Math.sqrt(s),x=[m,Math.min(Math.log(u)-4*p,f-4*d),Math.max(Math.log(u)+4*p,f+4*d),M];return[...new Set(x.map(v=>Math.min(Math.max(v,m),M)))].sort((v,D)=>v-D)}function Ne(n,t,r){return n>=2&&t>=2&&r>=1&&Number.isFinite(n)&&Number.isFinite(r)&&!Number.isNaN(t)}function Rn(n,t,r,e,i,o){let u;return rt!==void 0&&rt.q===n&&rt.k===t&&rt.df===r&&rt.r===e?u=rt.tail:(u=Ei(n,t,r,e,!i),rt={q:n,k:t,df:r,r:e,tail:u}),u.upper===!i?o?u.log:u.value:o?Math.log1p(-u.value):1-u.value}var rt;function Ei(n,t,r,e,i){let o=i;r!==1/0&&Yt(n,t,e,o)>.5&&(o=!o);let u=An(n,t,r,e,o);if(u>.5){let s=An(n,t,r,e,!o);s<u&&(u=s,o=!o)}if(u<1e-290){let s=Di(n,t,r,e,o);return{upper:o,value:Math.exp(s),log:s}}return{upper:o,value:u,log:Math.log(u)}}function Ci(n,t,r,e,i,o){return[n,t,r,e].some(Number.isNaN)?NaN:Ne(t,r,e)?n<=0?I(i,o):n===1/0?b(i,o):Rn(n,t,r,e,i,o):NaN}function Ai(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;if(!Ne(t,r,e))return NaN;let u=L(n,0,1/0,i,o);if(u!==void 0)return u;let{lower:s,logTarget:f,linearTarget:c}=S(n,i,o),a=h=>l=>{let m=Math.exp(l);if(c!==void 0&&c>1e-290){let p=h===1/0?An(m,t,h,e,!s):Rn(m,t,h,e,s,!1);if(p>0)return Math.log(p/c)}return(h===1/0?Ri(m,t,e,s):Rn(m,t,h,e,s,!0))-f},N=Xr(a(1/0),Math.log(3),s);return Math.exp(r===1/0?N:Xr(a(r),N,s))}function Ri(n,t,r,e){let i=Yt(n,t,r,!e);return i>1e-290?Math.log(i):Cn(n,t,r,!e)}function Xr(n,t,r){let e=t,i=n(e);if(i===0)return e;let o=i>0===r?-1:1,u=.05,s=e+o*u,f=n(s);for(let c=0;c<200&&Math.sign(f)===Math.sign(i)&&f!==0;c++)e=s,i=f,u*=2,s=e+o*u,f=n(s);return f===0?s:!Number.isFinite(f)||Math.sign(f)===Math.sign(i)?Number.isFinite(f)?s:e:Si(n,e,s,i,f)}function Si(n,t,r,e,i){let o=t,u=e,s=r-t,f=s;for(let c=0;c<100;c++){Math.sign(i)===Math.sign(u)&&(o=t,u=e,s=r-t,f=s),Math.abs(u)<Math.abs(i)&&(t=r,r=o,o=t,e=i,i=u,u=e);let a=2*Sn*Math.abs(r)+1e-300,N=.5*(o-r);if(Math.abs(N)<=a||i===0)return r;if(Math.abs(f)>=a&&Math.abs(e)>Math.abs(i)){let h=i/e,l,m;if(t===o)l=2*N*h,m=1-h;else{let M=e/u,p=i/u;l=h*(2*N*M*(M-p)-(r-t)*(p-1)),m=(M-1)*(p-1)*(h-1)}l>0?m=-m:l=-l,2*l<Math.min(3*N*m-Math.abs(a*m),Math.abs(f*m))?(f=s,s=l/m):(s=N,f=N)}else s=N,f=N;t=r,e=i,r+=Math.abs(s)>a?s:N>0?a:-a,i=n(r)}return r}function zu(n,t,r,e={}){let{nranges:i=1,lowerTail:o=!0,logP:u=!1}=e;return g(n,s=>Ci(s,t,r,i,o,u))}function ku(n,t,r,e={}){let{nranges:i=1,lowerTail:o=!0,logP:u=!1}=e;return g(n,s=>Ai(s,t,r,i,o,u))}export{nn as a,st as b,qt as c,J as d,wi as e,Zi as f,$i as g,gr as h,br as i,Ir as j,j as k,ge as l,be as m,Ie as n,eo as o,io as p,oo as q,Nn as r,Kt as s,ru as t,eu as u,iu as v,fn as w,Qt as x,yo as y,vo as z,Fo as A,Ge as B,Qe as C,mu as D,Mu as E,du as F,Ve as G,we as H,Ze as I,Lu as J,_u as K,Du as L,ze as M,ke as N,qu as O,Wu as P,Ou as Q,ii as R,oi as S,Vu as T,Xu as U,wu as V,zu as W,ku as X};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.6.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{d as f,f as a,g,j as l}from"./chunk-UGUQYWRQ.js";function m(t){let n=t.length;if(!t.every(Number.isFinite))return[t.reduce((o,s)=>o+s,0)/n,0];let r=[0,0];for(let o of t)r=f(r,[o,0]);let i=l(r,n);if(!Number.isFinite(i[0]))return[r[0]/n,0];let e=[0,0];for(let o of t)e=f(e,a([o,0],i));return f(i,l(e,n))}function y(t){return t.length===0?NaN:m(t)[0]}function A(t){return M(t,t)}function M(t,n){let r=t.length;if(r<2)return NaN;let i=m(t),e=t===n?i:m(n);if(!Number.isFinite(i[0])||!Number.isFinite(e[0]))return NaN;let o=t.map(u=>a([u,0],i)),s=t===n?o:n.map(u=>a([u,0],e)),c=v(o),N=t===n?c:v(s),p=2**-c,d=2**-N,h=[0,0];for(let u=0;u<r;u++){let b=[o[u][0]*p,o[u][1]*p],w=[s[u][0]*d,s[u][1]*d];h=f(h,g(b,w))}return l(h,r-1)[0]*2**c*2**N}function v(t){let n=0;for(let r of t)n=Math.max(n,Math.abs(r[0]));return n===0||!Number.isFinite(n)?0:Math.max(-1022,Math.floor(Math.log2(n)))}function D(t){let n=[0,0];for(let r of t)n=f(n,[r,0]);return n[0]}function j(t){let n=t.length,r=Array.from({length:n},(o,s)=>s);r.sort((o,s)=>t[o]-t[s]||o-s);let i=new Array(n),e=0;for(;e<n;){let o=e;for(;o+1<n&&t[r[o+1]]===t[r[e]];)o++;let s=(e+o+2)/2;for(let c=e;c<=o;c++)i[r[c]]=s;e=o+1}return i}function E(t){let n=[...t].sort((e,o)=>e-o),r=[],i=0;for(;i<n.length;){let e=i;for(;e+1<n.length&&n[e+1]===n[i];)e++;e>i&&r.push(e-i+1),i=e+1}return r}function C(t){return t.filter(n=>!Number.isNaN(n))}function P(t,n){if(t.length!==n.length)throw new TypeError("x and y must have the same length");let r=[],i=[];for(let e=0;e<t.length;e++)!Number.isNaN(t[e])&&!Number.isNaN(n[e])&&(r.push(t[e]),i.push(n[e]));return[r,i]}export{m as a,y as b,A as c,M as d,D as e,j as f,E as g,C as h,P as i};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.6.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{k as D}from"./chunk-XM2TVD63.js";import{a as I,f as $,g as L,i as K}from"./chunk-7NK4SA6B.js";import{g as v,h as O}from"./chunk-QNAIK4PY.js";import{b as z,c as H,d as w,f as C,g as F,i as j}from"./chunk-UGUQYWRQ.js";function Z(t){if(t===void 0)return"two.sided";let o=["two.sided","less","greater"].filter(r=>r.startsWith(t));if(t.length===0||o.length!==1)throw new RangeError(`invalid alternative "${t}" (expected "two.sided", "less" or "greater")`);return o[0]}function B(t){if(!(Number.isFinite(t)&&t>=0&&t<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function ft(t){if(!(Number.isFinite(t)&&t>0&&t<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var ot=["pearson","kendall","spearman"];function st(t){if(t===void 0)return"pearson";let e=ot.filter(o=>o.startsWith(t));if(t.length===0||e.length!==1)throw new RangeError(`invalid method "${t}"`);return e[0]}function G(t){if(!(t[0]>0))return[Math.sqrt(t[0]),0];let e=Math.sqrt(t[0]),o=C(t,H(e,e));return z(e,o[0]/(2*e))}function J(t){let e=I(t);if(!Number.isFinite(e[0]))return;let o=t.map(i=>C([i,0],e)),r=0;for(let i of o)r=Math.max(r,Math.abs(i[0]));if(r===0)return o;let a=2**-Math.max(-1022,Math.floor(Math.log2(r)));return o.map(i=>[i[0]*a,i[1]*a])}function Q(t,e){let o=t.length;if(o<2)return[NaN,0];let r=J(t),a=J(e);if(r===void 0||a===void 0)return[NaN,0];let i=[0,0],c=[0,0],s=[0,0];for(let u=0;u<o;u++)i=w(i,F(r[u],a[u])),c=w(c,F(r[u],r[u])),s=w(s,F(a[u],a[u]));if(c[0]===0||s[0]===0)return[NaN,0];let n=j(i,F(G(c),G(s)));return n[0]>=1?[1,0]:n[0]<=-1?[-1,0]:n}function U(t,e){let o=F(C([1,0],t),w([1,0],t));return Math.sqrt(e)*t[0]/Math.sqrt(o[0])}function at(t){return Math.abs(t[0])<.5?Math.atanh(t[0]):.5*Math.log(w([1,0],t)[0]/C([1,0],t)[0])}function X(t,e,o){return o==="less"?D(t,e,!0,!1):o==="greater"?D(t,e,!1,!1):2*Math.min(D(t,e,!0,!1),D(t,e,!1,!1))}function it(t,e){return e==="less"?v(t):e==="greater"?v(t,{lowerTail:!1}):2*Math.min(v(t),v(t,{lowerTail:!1}))}function ct(t,e){let o=t.length,r=0;for(let f=0;f<o;f++){let m=t[f],x=e[f];for(let p=f+1;p<o;p++){let N=(t[p]>m?1:0)-(t[p]<m?1:0),W=(e[p]>x?1:0)-(e[p]<x?1:0);r+=N*W}}let a=L(t),i=L(e),c=o*(o-1)/2,s=a.reduce((f,m)=>f+m*(m-1)/2,0),n=i.reduce((f,m)=>f+m*(m-1)/2,0),u=o<2||s===c||n===c?NaN:s===0&&n===0?r/c:r/Math.sqrt((c-s)*(c-n));return{s:r,tau:u,ties:a.length>0||i.length>0,tx:a,ty:i}}function Y(t,e){let o=t*(t-1)/2;if(e<0)return 0;if(e>=o)return 1;let r=new Float64Array(e+1);r[0]=1;for(let i=2;i<=t;i++){let c=new Float64Array(e+1),s=0;for(let u=0;u<=e;u++)s+=r[u],c[u]=s;let n=new Float64Array(e+1);for(let u=0;u<=e;u++)n[u]=(c[u]-(u>=i?c[u-i]:0))/i;r=n}let a=0;for(let i=e;i>=0;i--)a+=r[i];return Math.min(1,a)}var _=new Map;function ut(t){let e=_.get(t);if(e!==void 0)return e;let o=t*(t*t-1)/3,r=1<<t,a=new Array(r);a[0]=new Float64Array(o+1),a[0][0]=1;let i=s=>{let n=0;for(;s;s&=s-1)n++;return n};for(let s=0;s<r;s++){let n=a[s];if(n===void 0)continue;let u=i(s);for(let f=0;f<t;f++){if(s&1<<f)continue;let m=(f-u)**2,x=s|1<<f,p=a[x]??=new Float64Array(o+1);for(let N=0;N+m<=o;N++)n[N]&&(p[N+m]+=n[N])}s!==r-1&&(a[s]=void 0)}let c=a[r-1];return _.set(t,c),c}var d=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function tt(t,e,o){let r=e;r%2!==0&&(r+=1);let a=1/t,i=(6*(r-1)*a/(t*t-1)-1)*Math.sqrt(1/a-1),c=i*i,n=i*a*(d[0]+a*(d[1]+d[2]*a)+c*(-d[3]+a*(d[4]+d[5]*a)-c*a*(d[6]+d[7]*a-c*(d[8]-d[9]*a+c*a*(d[10]-d[11]*c)))))/Math.exp(c/2),u=o?v(i)-n:n+v(i,{lowerTail:!1});return Math.min(1,Math.max(0,u))}function et(t,e,o){let r=t*(t*t-1)/3;if(t<=9){let a=ut(t),i=1;for(let s=2;s<=t;s++)i*=s;let c=0;if(o)for(let s=Math.min(e,r);s>=0;s--)c+=a[s];else for(let s=r;s>=Math.max(e,0);s--)c+=a[s];return c/i}return o?e+1>r?1:e+1<=0?0:tt(t,e+1,!0):e<=0?1:e>r?0:tt(t,e,!1)}function Mt(t,e,o={}){if(t.length!==e.length)throw new TypeError("x and y must have the same length");let r=Z(o.alternative),a=st(o.method),i=o.continuity??!1,[c,s]=K(Array.from(t),Array.from(e)),n=c.length;if(a==="pearson"){let l=o.confLevel??.95;if(B(l),n<3)throw new Error("not enough finite observations");let g=Q(c,s),y=n-2,M=Number.isNaN(g[0])?NaN:U(g,y),k={method:"Pearson's product-moment correlation",alternative:r,statistic:M,statisticName:"t",parameter:y,parameterName:"df",pValue:X(M,y,r),estimate:g[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation"};if(n>3){let P=at(g),A=1/Math.sqrt(n-3),V=b=>Math.tanh(P+b),E;if(r==="less")E=[-1,V(A*O(l))];else if(r==="greater")E=[V(-A*O(l)),1];else{let b=A*O((1+l)/2);E=[V(-b),V(b)]}k.confInt=E,k.confLevel=l}return k}if(n<2)throw new Error("not enough finite observations");if(a==="kendall"){let l=ct(c,s),g={method:"Kendall's rank correlation tau",alternative:r,estimate:l.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau"};if(Number.isNaN(l.tau))return{...g,statistic:NaN,statisticName:"T",pValue:NaN};if((o.exact??n<50)&&!l.ties){let h=n*(n-1)/2,S=(l.s+h)/2,q=Y(n,S),R=Y(n,h-S),rt=r==="less"?q:r==="greater"?R:Math.min(1,2*Math.min(q,R));return{...g,statistic:S,statisticName:"T",pValue:rt}}let M=(h,S)=>S.reduce((q,R)=>q+h(R),0),k=h=>h*(h-1),P=h=>h*(h-1)*(h-2),A=h=>h*(h-1)*(2*h+5),V=(n*(n-1)*(2*n+5)-M(A,l.tx)-M(A,l.ty))/18+M(P,l.tx)*M(P,l.ty)/(9*n*(n-1)*(n-2))+M(k,l.tx)*M(k,l.ty)/(2*n*(n-1)),b=(i?Math.sign(l.s)*(Math.abs(l.s)-1):l.s)/Math.sqrt(V);return{...g,statistic:b,statisticName:"z",pValue:it(b,r)}}let u=$(c),f=$(s),m=Q(u,f),x=n*n*n-n,p=x*(1-m[0])/6,N={method:"Spearman's rank correlation rho",alternative:r,statistic:p,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho"};if(Number.isNaN(m[0]))return{...N,pValue:NaN};let W=L(c).length>0||L(s).length>0;if((o.exact??n<=1290)&&!W&&n<=1290){let l=Math.round(p),g=et(n,l,!0),y=et(n,l,!1),M=r==="greater"?g:r==="less"?y:Math.min(1,2*Math.min(g,y));return{...N,pValue:M}}let T=m;if(i){let l=j([6,0],[x,0]);T=j(w(m,l),w([1,0],l)),Math.abs(T[0])>=1&&(T=[Math.sign(T[0]),0])}let nt=U(T,n-2);return{...N,pValue:X(nt,n-2,r)}}export{Z as a,B as b,ft as c,Q as d,ct as e,Mt as f};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.6.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ var q=2220446049250313e-31,b0=22250738585072014e-324,z=17976931348623157e292,v0=[.06667134430868814,.1494513491505806,.21908636251598204,.26926671930999635,.29552422471475287],f0=[.9956571630258081,.9739065285171717,.9301574913557082,.8650633666889845,.7808177265864169,.6794095682990244,.5627571346686047,.4333953941292472,.2943928627014602,.14887433898163122,0],I=[.011694638867371874,.032558162307964725,.054755896574351995,.07503967481091996,.0931254545836976,.10938715880229764,.12349197626206584,.13470921731147334,.14277593857706009,.14773910490133849,.1494455540029169];function h0(a,o,i,s,t){let r=Math.abs((a-o)*i);return t!==0&&r!==0&&(r=t*Math.min(1,Math.pow(200*r/t,1.5))),s>b0/(50*q)&&(r=Math.max(q*50*s,r)),r}function g0(a,o,i){let s=.5*(o+i),t=.5*(i-o),r=Math.abs(t),w=new Array(10),u=new Array(10),p=a(s),M=0,c=I[10]*p,b=Math.abs(c);for(let e=0;e<5;e++){let n=2*e+1,l=t*f0[n],h=a(s-l),v=a(s+l);w[n]=h,u[n]=v;let g=h+v;M+=v0[e]*g,c+=I[n]*g,b+=I[n]*(Math.abs(h)+Math.abs(v))}for(let e=0;e<5;e++){let n=2*e,l=t*f0[n],h=a(s-l),v=a(s+l);w[n]=h,u[n]=v;let g=h+v;c+=I[n]*g,b+=I[n]*(Math.abs(h)+Math.abs(v))}let A=c*.5,f=I[10]*Math.abs(p-A);for(let e=0;e<10;e++)f+=I[e]*(Math.abs(w[e]-A)+Math.abs(u[e]-A));return b*=r,f*=r,{result:c*t,abserr:h0(c,M,t,b,f),resabs:b,resasc:f}}var l0=[0,.1294849661688697,0,.27970539148927664,0,.3818300505051189,0,.4179591836734694],x0=[.9914553711208126,.9491079123427585,.8648644233597691,.7415311855993945,.5860872354676911,.4058451513773972,.20778495500789848,0],U=[.022935322010529224,.06309209262997856,.10479001032225019,.14065325971552592,.1690047266392679,.19035057806478542,.20443294007529889,.20948214108472782];function A0(a,o,i,s,t){let r=i>1?1:i,w=.5*(s+t),u=.5*(t-s),p=new Array(7),M=new Array(7),c=h=>{let v=o+r*(1-h)/h,g=a(v);return i===2&&(g+=a(-v)),g},b=c(w)/w/w,A=b*l0[7],f=b*U[7],e=Math.abs(f);for(let h=0;h<7;h++){let v=u*x0[h],g=w-v,W=w+v,m=c(g),x=c(W);m=m/g/g,x=x/W/W,p[h]=m,M[h]=x;let K=m+x;A+=l0[h]*K,f+=U[h]*K,e+=U[h]*(Math.abs(m)+Math.abs(x))}let n=f*.5,l=U[7]*Math.abs(b-n);for(let h=0;h<7;h++)l+=U[h]*(Math.abs(p[h]-n)+Math.abs(M[h]-n));return e*=u,l*=u,{result:f*u,abserr:h0(f,A,u,e,l),resabs:e,resasc:l}}function j0(a){let o=a.epstab,i=a.n;a.nres+=1;let s=z,t=o[a.n];if(a.n<2)return s=Math.max(s,5*q*Math.abs(t)),[t,s];let r=49;o[a.n+2]=o[a.n];let w=Math.trunc(a.n/2);o[a.n]=z;let u=a.n;for(let c=0;c<w;c++){let b=u-1,A=u-2,f=o[u+2],e=o[A],n=o[b],l=f,h=Math.abs(n),v=l-n,g=Math.abs(v),W=Math.max(Math.abs(l),h)*q,m=n-e,x=Math.abs(m),K=Math.max(h,Math.abs(e))*q;if(!(g>W||x>K))return t=f,s=g+x,s=Math.max(s,5*q*Math.abs(t)),[t,s];let k=o[u];o[u]=n;let j=n-k,F=Math.abs(j),_=Math.max(h,Math.abs(k))*q;if(F<=_||g<=W||x<=K){a.n=c+c;break}let L=1/j+1/v-1/m;if(!(Math.abs(L*n)>1e-4)){a.n=c+c;break}f=n+1/L,o[u]=f,u-=2;let X=g+Math.abs(f-l)+x;X>s||(s=X,t=f)}a.n===r&&(a.n=2*Math.trunc(r/2));let p=i%2;for(let c=0;c<=w;c++)o[2*c+p]=o[2*c+2+p];if(a.n!==i){let c=i-a.n;for(let b=0;b<=a.n;b++)o[b]=o[c],c++}let M=a.res3la;return a.nres<4?(M[a.nres-1]=t,s=z):(s=Math.abs(t-M[2])+Math.abs(t-M[1])+Math.abs(t-M[0]),M[0]=M[1],M[1]=M[2],M[2]=t),s=Math.max(s,5*q*Math.abs(t)),[t,s]}function y0(a,o,i,s,t,r){if(o<=2){t[0]=0,t[1]=1;let e=t[r];return[e,s[e],r]}let w=s[i];for(;r>0&&w>s[t[r-1]];)t[r]=t[r-1],r-=1;let u=o>Math.trunc(a/2)+2?a-o+2:o-1,p=s[o-1],M=u-1,c=r+1,b=c,A=!1;if(c<=M)for(b=c;b<=M;b++){if(w>=s[t[b]]){A=!0;break}t[b-1]=t[b]}if(!A)t[M]=i,t[u]=o-1;else{t[b-1]=i;let e=M;for(let n=b;n<=M&&!(p<s[t[e]]);n++)t[e+1]=t[e],e--;p<s[t[e]]?t[e+1]=o-1:t[b]=o-1}let f=t[r];return[f,s[f],r]}function M0(a,o,i,s,t,r,w,u){let p=new Float64Array(r+1),M=new Float64Array(r+1),c=new Float64Array(r+1),b=new Float64Array(r+1),A=new Int32Array(r+1),f=0,e=0,n=0,l=0;if(p[0]=o,M[0]=i,s<=0&&t<Math.max(50*q,5e-29))return{result:0,abserr:0,neval:0,ier:6,last:0};let h=a(o,i);n=h.result,l=h.abserr;let v=h.resabs,g=h.resasc,W=Math.abs(n),m=Math.max(s,t*W);if(e=1,c[0]=n,b[0]=l,A[0]=0,l<=100*q*v&&l>m&&(f=2),r===1&&(f=1),f!==0||l<=m&&l!==g||l===0)return{result:n,abserr:l,neval:u(e),ier:f,last:e};let x={epstab:new Float64Array(52),res3la:new Float64Array(3),n:1,nres:0};x.epstab[0]=n;let K=l,k=0,j=n,F=l;l=z;let _=0,L=0,E=!1,X=!1,B=0,t0=0,R=0,s0=0,C=0,O=0,D=0,e0=0,u0=W>=(1-50*q)*v?1:-1,a0=!1,y=1;for(y=1;y<r;y++){e=y+1;let d=p[k],H=.5*(p[k]+M[k]),J=H,S=M[k],i0=K,T=a(d,H),V=a(J,S),Y=T.result,N=T.abserr,k0=T.resasc,Z=V.result,P=V.abserr,w0=V.resasc,$=Y+Z,Q=N+P;if(F=F+Q-K,j=j+$-c[k],k0!==N&&w0!==P&&(Math.abs(c[k]-$)>1e-5*Math.abs($)||Q<.99*K||(E?R++:t0++),y>9&&Q>K&&s0++),c[k]=Y,c[y]=Z,m=Math.max(s,t*Math.abs(j)),(t0+R>=10||s0>=20)&&(f=2),R>=5&&(B=3),e===r&&(f=1),Math.max(Math.abs(d),Math.abs(S))<=(1+100*q)*(Math.abs(J)+1e3*b0)&&(f=4),P>N?(p[k]=J,p[y]=d,M[y]=H,c[k]=Z,c[y]=Y,b[k]=P,b[y]=N):(p[y]=J,M[k]=H,M[y]=S,b[k]=N,b[y]=P),[k,K,_]=y0(r,e,k,b,A,_),F<=m){a0=!0;break}if(f!==0)break;if(y===1){C=w,O=F,D=m,x.epstab[1]=j;continue}if(X)continue;if(O-=i0,Math.abs(H-d)>C&&(O+=Q),!E){if(Math.abs(M[k]-p[k])>C)continue;E=!0,_=1}if(!(B===3||O<=D)){let p0=e>2+Math.trunc(r/2)?r+3-e:e,o0=!1;for(let c0=_;c0<p0;c0++){if(k=A[_],K=b[k],Math.abs(M[k]-p[k])>C){o0=!0;break}_++}if(o0)continue}x.n+=1,x.epstab[x.n]=j;let[n0,r0]=j0(x);if(L+=1,L>5&&l<.001*F&&(f=5),r0<l&&(L=0,l=r0,n=n0,e0=O,D=Math.max(s,t*Math.abs(n0)),l<=D)||(x.n===0&&(X=!0),f===5))break;k=A[0],K=b[k],_=0,E=!1,C*=.5,O=F}let G;if(a0||l===z?G=115:f+B===0?G=110:(B===3&&(l+=e0),f===0&&(f=3),n!==0&&j!==0?G=105:l>F?G=115:j===0?G=130:G=110),G===105&&(G=l/Math.abs(n)>F/Math.abs(j)?115:110),G===110)u0===-1&&Math.max(Math.abs(n),Math.abs(j))<=v*.01||(.01>n/j||n/j>100||F>Math.abs(j))&&(f=6);else if(G===115){n=0;for(let d=0;d<=y;d++)n+=c[d];l=F}return f>2&&(f-=1),{result:n,abserr:l,neval:u(e),ier:f,last:e}}function m0(a,o,i,s,t,r){return M0((w,u)=>g0(a,w,u),o,i,s,t,r,Math.abs(i-o)*.375,w=>42*w-21)}function K0(a,o,i,s,t,r){let w=i===2?0:o;return M0((u,p)=>A0(a,w,i,u,p),0,1,s,t,r,.375,u=>(30*u-15)*(i===2?2:1))}export{m0 as a,K0 as b};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.6.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ var x=23283064365386963e-26,N=2328306437080797e-25,a=class{mt=new Uint32Array(624);mti=625;setSeed(t){let e=t>>>0;for(let r=0;r<50;r++)e=Math.imul(69069,e)+1>>>0;e=Math.imul(69069,e)+1>>>0;for(let r=0;r<624;r++)e=Math.imul(69069,e)+1>>>0,this.mt[r]=e;this.mti=624}sgenrand(t){for(let e=0;e<624;e++)this.mt[e]=t&4294901760,t=Math.imul(69069,t)+1>>>0,this.mt[e]=(this.mt[e]|(t&4294901760)>>>16)>>>0,t=Math.imul(69069,t)+1>>>0;this.mti=624}nextUint32(){let t=this.mt;if(this.mti>=624){this.mti===625&&this.sgenrand(4357);let r=0,i;for(;r<227;r++)i=t[r]&2147483648|t[r+1]&2147483647,t[r]=t[r+397]^i>>>1^(i&1?2567483615:0);for(;r<623;r++)i=t[r]&2147483648|t[r+1]&2147483647,t[r]=t[r+-227]^i>>>1^(i&1?2567483615:0);i=t[623]&2147483648|t[0]&2147483647,t[623]=t[396]^i>>>1^(i&1?2567483615:0),this.mti=0}let e=t[this.mti++];return e^=e>>>11,e^=e<<7&2636928640,e^=e<<15&4022730752,e^=e>>>18,e>>>0}nextDouble(){let t=this.nextUint32()*x;return t<=0?.5*N:1-t<=0?1-.5*N:t}getRandomSeed(t){let e=new Int32Array(626);e[0]=t,e[1]=this.mti;for(let r=0;r<624;r++)e[r+2]=this.mt[r]|0;return e}setRandomSeed(t){if(t.length!==626)throw new RangeError("the random seed state must have 626 integers");this.mti=t[1];for(let e=0;e<624;e++)this.mt[e]=t[e+2]>>>0}};var g=[3.3871328727963665,133.14166789178438,1971.5909503065513,13731.69376550946,45921.95393154987,67265.7709270087,33430.57558358813,2509.0809287301227],w=[1,42.31333070160091,687.1870074920579,5394.196021424751,21213.794301586597,39307.89580009271,28729.085735721943,5226.495278852854],A=[1.4234371107496835,4.630337846156546,5.769497221460691,3.6478483247632045,1.2704582524523684,.2417807251774506,.022723844989269184,.0007745450142783414],S=[1,2.053191626637759,1.6763848301838038,.6897673349851,.14810397642748008,.015198666563616457,.0005475938084995345,10507500716444169e-25],F=[6.657904643501103,5.463784911164114,1.7848265399172913,.29656057182850487,.026532189526576124,.0012426609473880784,27115555687434876e-21,20103343992922881e-23],E=[1,.599832206555888,.1369298809227358,.014875361290850615,.0007868691311456133,18463183175100548e-21,1421511758316446e-22,20442631033899397e-31];function s(n,t){let e=n[7];for(let r=6;r>=0;r--)e=e*t+n[r];return e}function h(n){let t=n-.5;if(Math.abs(t)<=.425){let i=.180625-t*t;return t*s(g,i)/s(w,i)}let e=t<0?n:1-n;e=Math.sqrt(-Math.log(e));let r;return e<=5?(e-=1.6,r=s(A,e)/s(S,e)):(e-=5,r=s(F,e)/s(E,e)),t<0?-r:r}var l=10403,f=new a,c=!1;function p(){if(c)return;let n=(Date.now()^Math.floor(Math.random()*2**32))>>>0;typeof globalThis.crypto?.getRandomValues=="function"&&(n=globalThis.crypto.getRandomValues(new Uint32Array(1))[0]),f.setSeed(n),c=!0}function U(n){if(!Number.isFinite(n))throw new RangeError("seed must be a finite number");let t=Math.trunc(n);if(Math.abs(t)>2147483647)throw new RangeError("seed must be a 32-bit integer");f.setSeed(t|0),c=!0}function v(){return p(),f.getRandomSeed(l)}function T(n){if(n[0]!==l)throw new RangeError(`only the default RNG kind (${l}) is supported`);f.setRandomSeed(n),c=!0}function o(){return p(),f.nextDouble()}function _(n){let t=0;for(let e=0;e<=n;e+=16){let r=Math.floor(o()*65536);t=65536*t+r}return t%2**n}function k(n){if(n<=0)return 0;let t=Math.ceil(Math.log2(n)),e;do e=_(t);while(n<=e);return e}var M=134217728;function b(){let n=o();return n=Math.trunc(M*n)+o(),h(n/M)}var m=(()=>{let n=[],t=1,e=0;for(let r=1;r<=16;r++)t*=Math.LN2/r,e+=t,n.push(e);return n})();function d(){let n=0,t=o();for(;t<=0||t>=1;)t=o();for(;t+=t,!(t>1);)n+=m[0];if(t-=1,t<=m[0])return n+t;let e=0,r=o(),i=r;do r=o(),i>r&&(i=r),e++;while(t>m[e]);return n+i*m[0]}function u(n,t){if(!Number.isFinite(n)||n<0)throw new RangeError("n must be a non-negative finite number");let e=Math.trunc(n),r=new Array(e);for(let i=0;i<e;i++)r[i]=t();return r}function L(n,t){let e=1;if(Number.isNaN(n))return n;if(t!==0){if(!Number.isFinite(n))return Math.pow(n,t);for(t<0&&(t=-t,n=1/n);t&1&&(e*=n),t>>=1,t;)n*=n}return e}function q(n,t={}){let{min:e=0,max:r=1}=t;return u(n,()=>{if(!Number.isFinite(e)||!Number.isFinite(r)||r<e)return NaN;if(e===r)return e;let i=o();return e+(r-e)*i})}function R(n,t){return Number.isNaN(n)||!Number.isFinite(t)||t<0?NaN:t===0||!Number.isFinite(n)?n:n+t*b()}function j(n,t={}){let{mean:e=0,sd:r=1}=t;return u(n,()=>R(e,r))}function B(n,t={}){let e=1/(t.rate??1);return u(n,()=>!Number.isFinite(e)||e<=0?e===0?0:NaN:e*d())}function G(n,t={}){let{meanlog:e=0,sdlog:r=1}=t;return u(n,()=>Number.isNaN(e)||!Number.isFinite(r)||r<0?NaN:Math.exp(R(e,r)))}function V(n,t={}){let{location:e=0,scale:r=1}=t;return u(n,()=>{if(Number.isNaN(e)||!Number.isFinite(r))return NaN;if(r===0||!Number.isFinite(e))return e;let i=o();return e+r*Math.log(i/(1-i))})}function $(n,t={}){let{location:e=0,scale:r=1}=t;return u(n,()=>Number.isNaN(e)||!Number.isFinite(r)||r<0?NaN:r===0||!Number.isFinite(e)?e:e+r*Math.tan(Math.PI*o()))}function C(n,t,e={}){let{scale:r=1}=e;return u(n,()=>!Number.isFinite(t)||!Number.isFinite(r)||t<=0||r<=0?r===0?0:NaN:r*Math.pow(-Math.log(o()),1/t))}export{U as a,v as b,T as c,o as d,k as e,b as f,d as g,u as h,L as i,q as j,R as k,j as l,B as m,G as n,V as o,$ as p,C as q};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.6.1 | 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
+ function h(f,t,a){let n=Math.ceil(a);if(n===1)return[f];let i=(t-f)/(n-1),o=Array.from({length:n},(s,r)=>f+r*i);return n>0&&(o[n-1]=t),o}function g(f,t){let a=Array.from(f).map(o=>Math.trunc(o)),n=t??Math.max(1,...a.filter(o=>!Number.isNaN(o))),i=new Array(Math.max(0,n)).fill(0);for(let o of a)o>=1&&o<=n&&i[o-1]++;return i}function y(f,t={}){let a=t.useNA??"no",n=Array.from(f),i=new Map,o=0;for(let e of n)Number.isNaN(e)?o++:i.set(e===0?0:e,(i.get(e===0?0:e)??0)+1);let s=Array.from(i.keys()).sort((e,l)=>e-l),r=s.map(e=>i.get(e));return(a==="always"||a==="ifany"&&o>0)&&(s.push(NaN),r.push(o)),{values:s,counts:r}}function b(f){let t=new Set,a=[];for(let n of Array.from(f)){let i=n===0?0:n;t.has(i)||(t.add(i),a.push(n))}return a}function x(f,t,a={}){let n=a.right??!0,i=a.includeLowest??!1,o=Array.from(f),s;if(typeof t=="number"||t.length===1){let r=typeof t=="number"?t:t[0];if(!(r>=2))throw new RangeError("invalid number of intervals");let e=Math.trunc(r+1),l=o.filter(N=>!Number.isNaN(N)),u=Math.min(...l),c=Math.max(...l),m=c-u;m===0?(m=u!==0?Math.abs(u):1,s=h(u-m/1e3,c+m/1e3,e)):(s=h(u,c,e),s[0]=u-m/1e3,s[e-1]=c+m/1e3)}else s=[...t].sort((r,e)=>r-e);if(new Set(s).size<s.length)throw new RangeError("'breaks' are not unique");return d(o,s,n,i)}function d(f,t,a,n){let i=t.length;return f.map(o=>{if(Number.isNaN(o))return NaN;let s=0,r=i;for(;s<r;){let l=s+r>>1;(a?t[l]<o:t[l]<=o)?s=l+1:r=l}let e=s;return n&&(a&&o===t[0]&&(e=1),!a&&o===t[i-1]&&(e=i-1)),e>=1&&e<=i-1?e:NaN})}function A(f,t,a={}){let n=t.length;for(let r=1;r<n;r++)if(!(t[r]>=t[r-1]))throw new RangeError("'vec' must be sorted non-decreasingly and not contain NAs");if(t.some(Number.isNaN))throw new RangeError("'vec' must be sorted non-decreasingly and not contain NAs");let{rightmostClosed:i=!1,allInside:o=!1,leftOpen:s=!1}=a;return Array.from(f).map(r=>{if(Number.isNaN(r))return NaN;let e=0,l=n;for(;e<l;){let c=e+l>>1;(s?t[c]<r:t[c]<=r)?e=c+1:l=c}let u=e;return i&&n>0&&(!s&&u===n&&r===t[n-1]&&(u=n-1),s&&u===0&&r===t[0]&&(u=1)),o&&(u=Math.min(Math.max(u,1),n-1)),u})}export{h as a,g as b,y as c,b as d,x as e,A as f};