@numero-uno-jpn/rstats 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +99 -0
- package/README.ja.md +47 -14
- package/README.md +49 -15
- package/THIRD_PARTY_NOTICES.md +35 -0
- package/dist/chunks/chunk-24U4DKRY.js +2 -0
- package/dist/chunks/{chunk-J3SNI7KY.js → chunk-5K4PS7IV.js} +2 -2
- package/dist/chunks/{chunk-MVG5LUZU.js → chunk-BGVMSDVJ.js} +2 -2
- package/dist/chunks/chunk-FC2TLHZC.js +2 -0
- package/dist/chunks/{chunk-ZW52Z3GY.js → chunk-H2AP6TCR.js} +1 -1
- package/dist/chunks/chunk-IVOBWYLV.js +2 -0
- package/dist/chunks/{chunk-UIOAWLAN.js → chunk-JLSTEMSN.js} +1 -1
- package/dist/chunks/chunk-LE7TBHNI.js +2 -0
- package/dist/chunks/{chunk-ZYA4ISAT.js → chunk-LWUSYIQ4.js} +1 -1
- package/dist/chunks/{chunk-AFKYWGKN.js → chunk-MF4VBCHQ.js} +2 -2
- package/dist/chunks/{chunk-SXSJXDD3.js → chunk-MSAUU6PY.js} +2 -2
- package/dist/chunks/{chunk-XYXHHF5L.js → chunk-TOVTN5Y2.js} +1 -1
- package/dist/chunks/{chunk-JCZAB6C5.js → chunk-YC4JWUKG.js} +2 -2
- package/dist/chunks/{chunk-QNQJA6KZ.js → chunk-ZRO446BP.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions/beta.js +21 -5
- package/dist/distributions.js +2 -2
- package/dist/entries/distributions.d.ts +2 -1
- package/dist/entries/distributions.js +2 -1
- package/dist/entries/tests.d.ts +4 -0
- package/dist/entries/tests.js +4 -0
- package/dist/htest/brunnerMunzelTest.d.ts +28 -0
- package/dist/htest/brunnerMunzelTest.js +86 -0
- package/dist/linalg.js +2 -2
- package/dist/models/glm.d.ts +226 -0
- package/dist/models/glm.js +546 -0
- package/dist/models/glmAnova.d.ts +31 -0
- package/dist/models/glmAnova.js +146 -0
- package/dist/models/glmConfint.d.ts +25 -0
- package/dist/models/glmConfint.js +139 -0
- package/dist/models/glmFamily.d.ts +66 -0
- package/dist/models/glmFamily.js +359 -0
- package/dist/numerics.js +2 -2
- package/dist/random/lecuyer.d.ts +20 -0
- package/dist/random/lecuyer.js +71 -0
- package/dist/random/rng.d.ts +78 -11
- package/dist/random/rng.js +128 -26
- package/dist/random/sample.js +24 -7
- package/dist/random/streams.d.ts +34 -0
- package/dist/random/streams.js +75 -0
- package/dist/rstats.js +4 -3
- package/dist/special/igam.d.ts +1 -0
- package/dist/special/igam.js +1 -1
- package/dist/special/incbet.js +487 -6
- package/dist/special/incbetLargeA.d.ts +15 -0
- package/dist/special/incbetLargeA.js +200 -0
- package/dist/special/incbetTemme.d.ts +19 -0
- package/dist/special/incbetTemme.js +216 -0
- package/dist/special/loader.js +151 -118
- package/dist/special.js +2 -2
- package/dist/tests.js +4 -3
- package/package.json +1 -1
- package/dist/chunks/chunk-6R7YDHA2.js +0 -2
- package/dist/chunks/chunk-ANYGLFT4.js +0 -2
- package/dist/chunks/chunk-BI5RSUZ2.js +0 -2
- package/dist/chunks/chunk-PTPPP4TI.js +0 -2
- package/dist/chunks/chunk-YKN6OGJL.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,105 @@ 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.9.0 - 2026-10-25
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `glm` (R's `glm` with a matrix interface): generalized linear models fitted by iteratively
|
|
15
|
+
reweighted least squares, with every family of R's `stats` (`gaussian`, `binomial`,
|
|
16
|
+
`quasibinomial`, `poisson`, `quasipoisson`, `Gamma`, `inverse.gaussian`, `quasi` with its five
|
|
17
|
+
variance functions) and every link each accepts, power links (`{ power: lambda }`), prior weights,
|
|
18
|
+
an offset, starting values, `epsilon`, `maxit` and a model without intercept. A binomial response
|
|
19
|
+
can be rows of (successes, failures). The result has the coefficients (NaN for aliased columns),
|
|
20
|
+
fitted values, deviance, null deviance, AIC, degrees of freedom, iterations, `converged`,
|
|
21
|
+
`boundary`, and R's warnings as strings in `warnings`.
|
|
22
|
+
- `glmSummary` (`summary.glm`): dispersion, coefficient table with z or t tests, unscaled and scaled
|
|
23
|
+
covariance; `glmResiduals` (deviance, Pearson, working, response); `glmHatvalues`,
|
|
24
|
+
`glmRstandard`, `glmCooksDistance`; `glmPredict` on the link or response scale with standard
|
|
25
|
+
errors, for the data or new rows (with their offset).
|
|
26
|
+
- `glmConfint`: profile likelihood confidence intervals (likelihood ratio or Rao score), with the
|
|
27
|
+
exact limits where R's `confint` interpolates a spline (R is up to 4.5e-4 standard errors from
|
|
28
|
+
them); see [docs/differences-from-r.md](docs/differences-from-r.md#generalized-linear-models).
|
|
29
|
+
- `glmAnova` (`anova.glm`): the sequential analysis of deviance of one fit (each column of `x` a
|
|
30
|
+
term) and the comparison of several fits, with the `"Chisq"`/`"LRT"`, `"Rao"`, `"F"` and `"Cp"`
|
|
31
|
+
tests and R 4.4's default test.
|
|
32
|
+
- Together they add 7.8 KB gzipped to everything (122.2 → 130.0 KB); `glm` with `glmSummary` alone
|
|
33
|
+
is 27.2 KB, with all its methods 39.2 KB.
|
|
34
|
+
|
|
35
|
+
## 0.8.0 - 2026-10-25
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
|
|
39
|
+
- `RNGkind({ kind, sampleKind })` (R's `RNGkind()`): the `"L'Ecuyer-CMRG"` generator (L'Ecuyer's
|
|
40
|
+
MRG32k3a) besides R's default Mersenne-Twister, and `sampleKind: "Rounding"`, the `sample` of R
|
|
41
|
+
before 3.6.0 (affects `sample`, `sampleInt` and `rwilcox`), with R's streams after the same seed.
|
|
42
|
+
As in R, changing the kind in the middle of a stream seeds the new generator from the next
|
|
43
|
+
uniform, and the call returns the previous kinds. R's `set.seed(seed, kind, sample.kind)` is
|
|
44
|
+
`RNGkind({ kind, sampleKind })` followed by `setSeed(seed)`.
|
|
45
|
+
- `nextRNGStream` and `nextRNGSubStream` (R's `parallel::nextRNGStream()` and
|
|
46
|
+
`nextRNGSubStream()`): the L'Ecuyer-CMRG state advanced by 2^127 or 2^76 steps, for independent
|
|
47
|
+
streams in parallel work.
|
|
48
|
+
- `getRandomSeed` and `setRandomSeed` handle every supported combination in R's `.Random.seed`
|
|
49
|
+
format (kind code `10403`, `403` with Rounding, `10407` for L'Ecuyer-CMRG with 6 seeds).
|
|
50
|
+
- `brunnerMunzelTest` (`lawstat::brunner.munzel.test()`): the Brunner-Munzel test for the relative
|
|
51
|
+
effect P(X < Y) + P(X = Y)/2 of two samples, with its interval. The interval is set with
|
|
52
|
+
`confLevel` (lawstat's `alpha = 1 - confLevel`); small p-values are computed from the upper tail
|
|
53
|
+
directly, where lawstat's 1 − P loses them. It adds 0.4 KB gzipped to everything (121.8 → 122.2
|
|
54
|
+
KB with the speed-up below).
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- `sampleInt` accepts n up to 4.5e15, as R (before: less than 2^31), when sampling with
|
|
59
|
+
replacement or with a size of at most n / 2 (`sampleInt(1e10, { size: 3 })`); weighted sampling and
|
|
60
|
+
sampling more than half without replacement still need n < 2^31. Uniform integers above 2^47 are
|
|
61
|
+
built from random bits without rounding.
|
|
62
|
+
- Bundle size: `setSeed` with `rnorm` is unchanged (1.7 KB gzipped); `sampleInt` grows from 1.9 to
|
|
63
|
+
2.1 KB and `getRandomSeed` with `setRandomSeed` from 1.0 to 1.5 KB (they read L'Ecuyer-CMRG
|
|
64
|
+
states). The new generator is only included with `RNGkind`, `setRandomSeed` or the stream
|
|
65
|
+
functions. Everything together grows from 119.6 to 120.9 KB.
|
|
66
|
+
|
|
67
|
+
- Speed: the incomplete beta function with both parameters large (ab/(a + b) >= 25, x near the
|
|
68
|
+
mean) uses Temme's uniform asymptotic expansion, in constant time (about 1 µs):
|
|
69
|
+
`pbeta(0.5, 1e6, 1e6)` becomes about 245 times faster and `pbinom(n/2, n, 0.5)` with n = 1e6
|
|
70
|
+
about 170 times. The continued fraction of the incomplete beta function runs without array
|
|
71
|
+
allocations (bit-identical results, about twice as fast), and Loader's deviance, `dbeta` and the
|
|
72
|
+
prefactors leave out double-double steps whose rounding an error bound shows to be negligible.
|
|
73
|
+
On typical inputs (`npm run bench`, Apple M1): `pbeta` 1.6, `dbeta` 2.0, `pt` 1.7, `dbinom` 2.1,
|
|
74
|
+
`pf` 1.7, `qbeta` 1.8 and `qgamma` 1.3 times faster (see [docs/performance.md](docs/performance.md)).
|
|
75
|
+
Accuracy is unchanged: all tests pass with the same tolerances, and new mpmath fixtures cover
|
|
76
|
+
the large-parameter region.
|
|
77
|
+
- Bundle size: the expansion and the allocation-free loop add about 3.6 KB gzipped to everything
|
|
78
|
+
that uses the incomplete beta function (`qbeta` 18.5 → 22.1 KB, `pt` and `qt` 25.5 → 29.4 KB,
|
|
79
|
+
`tTest` 16.7 → 20.3 KB, everything 115.4 → 119.6 KB).
|
|
80
|
+
- Speed: the incomplete beta function with one parameter large and the other small (a >= 15,
|
|
81
|
+
b <= 40, x in the bulk) uses DiDonato and Morris's asymptotic expansion (TOMS 708, eq. 9, in the
|
|
82
|
+
form of Boost.Math's `beta_small_b_large_a_series`) where it used the continued fraction, whose
|
|
83
|
+
length stops growing with a but which took 30 to 170 double-double steps there. This covers `pt`
|
|
84
|
+
and `pf` with large degrees of freedom, `pbeta(x, 1e6, 10)` and `pbinom` with x near 0 or n:
|
|
85
|
+
`pt(1.5, 1e6)` becomes 12 times faster, `pbeta(1 - b/(a + b), 1e10, 0.5)` 31 times,
|
|
86
|
+
`pf(3, 1, 1e5)` 14 times, `pbeta(1 - b/(a + b), 1e6, 10)` 1.4 times, and `pt` over t ~ N(0, 3²)
|
|
87
|
+
takes about the same time for every df from 1e5 to 1e15 (5 to 9 times faster); `qt`, `qbeta`,
|
|
88
|
+
`qf` and `qbinom` there become about 2 times faster (see [docs/performance.md](docs/performance.md)).
|
|
89
|
+
Its cases are within 1.2e-15 of mpmath and Rmpfr references, as the continued fraction was; new
|
|
90
|
+
mpmath fixtures cover a from 15 to 1e10 and b from 0.1 to 40.
|
|
91
|
+
- Bundle size: the expansion adds 0.8 to 1.1 KB gzipped (`pt` and `qt` 29.4 → 30.3 KB, `qbeta`
|
|
92
|
+
22.1 → 23.2 KB, `tTest` 20.3 → 21.4 KB, everything 120.9 → 121.8 KB).
|
|
93
|
+
|
|
94
|
+
### Fixed
|
|
95
|
+
|
|
96
|
+
- Weighted sampling with replacement by Walker's alias method (more than 200 likely candidates)
|
|
97
|
+
compares in the same way as R (t + u against q[t] + t), so that rounding cannot pick a different
|
|
98
|
+
candidate in rare cases.
|
|
99
|
+
- The log of the larger tail of the incomplete beta function for x (or 1 − x) in the subnormal
|
|
100
|
+
range: `pbeta(1e-308, 1, 1e8, lowerTail: false, logP: true)` was off by 4.7e-14, as R's value
|
|
101
|
+
still is (now 1.8e-15).
|
|
102
|
+
- `pt` and `pf` with degrees of freedom above about 1e21 (the continued fraction in the frame of the
|
|
103
|
+
large parameter, now replaced by the expansion for large a): `pt(0.001, 1e22, lowerTail: false)`
|
|
104
|
+
was 1.19 and `pt(0.01, 1e25)` off by 2.6e-4; with degrees of freedom from about 1e153 on, `pt` and
|
|
105
|
+
`pf` returned NaN (`pt(1, 1e160)`, `pf(2, 3, 1e160)`). `pt` now agrees with its normal limit to
|
|
106
|
+
5e-16 for |t| up to 31.6 (beyond, where the tail is below 1e-218, the NaN remains for df from
|
|
107
|
+
1e153 on).
|
|
108
|
+
|
|
10
109
|
## 0.7.0 - 2026-10-25
|
|
11
110
|
|
|
12
111
|
### Added
|
package/README.ja.md
CHANGED
|
@@ -16,7 +16,7 @@ JavaScript とブラウザで使える、R と互換の統計関数のライブ
|
|
|
16
16
|
- **どこでも動きます。** ESM のみで、依存パッケージはなく、Node 専用の API も使っていません。
|
|
17
17
|
tree-shaking が効きます (`pnorm` だけなら gzip で 1.2 KB)。
|
|
18
18
|
|
|
19
|
-
状態: **0.
|
|
19
|
+
状態: **0.9.0。** R の stats パッケージの数値計算の中心
|
|
20
20
|
(分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
|
|
21
21
|
[ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
|
|
22
22
|
|
|
@@ -48,11 +48,17 @@ dbinom(3, 10, 0.2); // 0.20132659200000003
|
|
|
48
48
|
### `set.seed()` と同じ乱数
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
|
-
import { setSeed, rnorm,
|
|
51
|
+
import { setSeed, rnorm, RNGkind, getRandomSeed, setRandomSeed, nextRNGStream, runif } from "@numero-uno-jpn/rstats";
|
|
52
52
|
|
|
53
53
|
setSeed(42);
|
|
54
54
|
rnorm(3); // [1.3709584471466685, -0.5646981713960887, 0.3631284113373392]
|
|
55
55
|
// R: set.seed(42); rnorm(3) gives the same numbers (up to the last bit)
|
|
56
|
+
|
|
57
|
+
// R の既定以外の設定: RNGkind("L'Ecuyer-CMRG") と parallel::nextRNGStream、sample.kind = "Rounding"
|
|
58
|
+
RNGkind({ kind: "L'Ecuyer-CMRG" });
|
|
59
|
+
setSeed(1); // R: set.seed(1, kind = "L'Ecuyer-CMRG")
|
|
60
|
+
setRandomSeed(nextRNGStream(getRandomSeed())); // R: .Random.seed <- nextRNGStream(.Random.seed)
|
|
61
|
+
runif(2); // [0.31369782407981056, 0.9280126525616814]
|
|
56
62
|
```
|
|
57
63
|
|
|
58
64
|
R で `set.seed(42); rnorm(3)` とすると、最後のビットまで同じ数値になります。
|
|
@@ -73,6 +79,24 @@ pAdjust([0.01, 0.02, 0.03, 0.04], { method: "BH" }); // ≈ [0.04, 0.04, 0.04
|
|
|
73
79
|
|
|
74
80
|
`tTest` の既定は、R と同じ Welch の検定です。
|
|
75
81
|
|
|
82
|
+
### 一般化線形モデル
|
|
83
|
+
|
|
84
|
+
説明変数は `lm` と同じく行列 (行の配列) かベクトルで渡します。二項分布の応答は (成功数, 失敗数) の行でも渡せます。
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { glm, glmSummary, glmPredict, glmConfint, glmAnova } from "@numero-uno-jpn/rstats";
|
|
88
|
+
|
|
89
|
+
const dose = [1, 2, 3, 4, 5, 6];
|
|
90
|
+
const counts = [[1, 19], [4, 16], [9, 11], [13, 7], [18, 2], [19, 1]];
|
|
91
|
+
const fit = glm(dose, counts, { family: "binomial" }); // R: glm(cbind(s, f) ~ dose, binomial)
|
|
92
|
+
fit.coefficients; // ≈ [-3.77413, 1.14807]
|
|
93
|
+
glmSummary(fit).pValue; // ≈ [5.357e-8, 3.579e-9] (z tests)
|
|
94
|
+
glmPredict(fit, { newdata: [3.5], type: "response" }); // { fit: ≈ [0.56073], seFit: ≈ [0.06140] }
|
|
95
|
+
glmConfint(fit).lower; // ≈ [-5.27166, 0.80033] (profile likelihood)
|
|
96
|
+
glmAnova(fit).table[1]; // ≈ [1, 62.978, 4, 0.5196, 2.09e-15]
|
|
97
|
+
fit.warnings; // [] (R's warnings, such as non-convergence)
|
|
98
|
+
```
|
|
99
|
+
|
|
76
100
|
### 線形代数
|
|
77
101
|
|
|
78
102
|
行列は行の配列で表します。
|
|
@@ -93,10 +117,10 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
|
|
|
93
117
|
|---|---|
|
|
94
118
|
| 特殊関数 | `gamma`, `lgamma`, `beta`, `lbeta`, `choose`, `lchoose`, `factorial`, `lfactorial`, `digamma`, `trigamma`, `psigamma`, `besselI`, `besselK`, `besselJ`, `besselY`。R にはない `erf`, `erfc`, `erfinv`, `erfcinv`, `gammainc`, `perm` と、R の C API (Rmath.h) の `log1pmx`, `lgamma1p`, `log1mexp`, `log1pexp` も |
|
|
95
119
|
| 分布 (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`), `r2dtable` |
|
|
120
|
+
| 乱数 | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister と L'Ecuyer-CMRG、`sample.kind` の Rejection と Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 個の `r*` 関数, `sample`, `sampleInt` (`sample.int`), `r2dtable` |
|
|
97
121
|
| 記述統計 | `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` |
|
|
122
|
+
| 検定 | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `corTest`, `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`, `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`, `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`, `pairwiseWilcoxTest`, `pairwisePropTest`, `aov`, `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
|
|
123
|
+
| 線形モデル | `lm` (行列で渡す形。`summary` の値も返す), `confint`, `predict`。`glm` (行列で渡す形。R の `stats` のすべての族とリンク) と `glmSummary` (`summary.glm`)、`glmResiduals` (4 種類)、`glmHatvalues`、`glmRstandard`、`glmCooksDistance`、`glmPredict` (標準誤差つき)、`glmConfint` (プロファイル尤度、厳密な限界)、`glmAnova` (`anova.glm`) |
|
|
100
124
|
| 線形代数 | `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
125
|
| 数値計算 | `integrate`, `optimize`, `uniroot`, `approx`, `spline`, `splinefun`, `splinefunH`, `barylag`, `hermiteInterp`, `ode`, `grad`, `jacobian`, `hessian` |
|
|
102
126
|
|
|
@@ -121,7 +145,8 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
121
145
|
- 添字は 0 から始まります。`sampleInt(n)` は `0..n-1` を返します (R の `sample.int()` から 1 を
|
|
122
146
|
引いた値で、乱数の列は同じ)。`qr` と `chol` のピボットも 0 から始まります。
|
|
123
147
|
- 固有ベクトルと特異ベクトルの符号が R と違うことがあります (どちらも正しい答えです)。
|
|
124
|
-
- 検定は R
|
|
148
|
+
- 検定は R の警告を出しません。数値の欄と手法の名前はすべて一致します。`glm` は R の警告を結果の
|
|
149
|
+
`warnings` で返します。
|
|
125
150
|
- 分布の母数は、ベクトルとして使い回されません (リサイクルしない)。
|
|
126
151
|
|
|
127
152
|
すべての違いは [docs/ja/differences-from-r.md](docs/ja/differences-from-r.md) にあります。
|
|
@@ -136,36 +161,44 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
136
161
|
| `pnorm` | 1.2 KB |
|
|
137
162
|
| `setSeed`, `rnorm` | 1.7 KB |
|
|
138
163
|
| `solve` / `svd` / `eigen` | 1.7 / 2.0 / 3.7 KB |
|
|
139
|
-
| `wilcoxTest` / `fisherTest` / `tTest` | 8.6 / 15.
|
|
140
|
-
| `qbeta` / `pt` と `qt` |
|
|
141
|
-
|
|
|
164
|
+
| `wilcoxTest` / `fisherTest` / `tTest` | 8.6 / 15.6 / 21.4 KB |
|
|
165
|
+
| `qbeta` / `pt` と `qt` | 23.2 / 30.3 KB |
|
|
166
|
+
| `glm` と `glmSummary` / `glm` とそのすべての関数 | 27.2 / 39.2 KB |
|
|
167
|
+
| すべて | 130.0 KB |
|
|
142
168
|
|
|
143
169
|
(`npm run size` で測れます。)
|
|
144
170
|
|
|
145
171
|
分野ごとにサブパスからも export しているので、1 つの分野だけを import することもできます。
|
|
146
|
-
`@numero-uno-jpn/rstats/distributions`、`/tests` (
|
|
172
|
+
`@numero-uno-jpn/rstats/distributions`、`/tests` (検定、`lm`・`confint`・`predict`、`glm` とその関数)、`/linalg`、
|
|
147
173
|
`/descriptive`、`/numerics`、`/special` です。
|
|
148
174
|
|
|
149
175
|
バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (すべての関数を含む minify 済みの
|
|
150
|
-
ES モジュール、gzip で
|
|
176
|
+
ES モジュール、gzip で 130 KB) を jsDelivr から読み込めます。jsDelivr は、このリポジトリのリリースの
|
|
151
177
|
タグをそのまま配信します。
|
|
152
178
|
|
|
153
179
|
```html
|
|
154
180
|
<script type="module">
|
|
155
|
-
import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.
|
|
181
|
+
import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.9.0/dist/rstats.js";
|
|
156
182
|
console.log(pnorm(1.96)); // 0.9750021048517795
|
|
157
183
|
</script>
|
|
158
184
|
```
|
|
159
185
|
|
|
186
|
+
関数は R と同じ名前の named export で、`jStat.` や `_.` のような接頭辞はありません。他の名前と区別
|
|
187
|
+
したいときは、名前空間として import してください (上の URL から `import * as rs from` で読み込む)。
|
|
188
|
+
`rs.pnorm(1.96)`、`rs.tTest(x, y)` のように呼べます。バンドラを使う場合
|
|
189
|
+
(`import * as rs from "@numero-uno-jpn/rstats"`) も、使わない関数は取り除かれます。CDN から読み込む
|
|
190
|
+
場合は、どちらの書き方でもファイル全体が読み込まれます。`window` には何も追加しません。他のスクリプトや
|
|
191
|
+
ブラウザのコンソールから使うときは、自分で `window.rs = rs` としてください。
|
|
192
|
+
|
|
160
193
|
一部の分野だけを使うページでは、代わりに分野ごとのバンドルを読み込めます。`dist/distributions.js`、
|
|
161
194
|
`dist/tests.js`、`dist/linalg.js`、`dist/descriptive.js`、`dist/numerics.js`、`dist/special.js` は
|
|
162
195
|
上のサブパスと同じ関数を export し、共通のコードを `dist/chunks/` で共有します。そのため、2 つの分野を
|
|
163
196
|
読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で 18 KB
|
|
164
|
-
(`numerics`) から
|
|
197
|
+
(`numerics`) から 102 KB (`tests`) です。
|
|
165
198
|
|
|
166
199
|
ビルド結果 (`dist/`) は main ブランチにはなく、リリースのタグにだけ入っています。npm を元にした CDN も
|
|
167
200
|
使えます。たとえば
|
|
168
|
-
`https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.
|
|
201
|
+
`https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.9.0/dist/rstats.js` や
|
|
169
202
|
`https://esm.sh/@numero-uno-jpn/rstats` です。
|
|
170
203
|
|
|
171
204
|
ブラウザ向けのビルドは、headless Chromium でテストしています。バンドラでまとめた場合と、
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ R-compatible statistical functions for JavaScript and the browser, written in Ty
|
|
|
14
14
|
- **Runs anywhere.** ESM only, no dependencies, no Node-specific APIs, tree-shakable
|
|
15
15
|
(`pnorm` alone is 1.2 KB gzipped).
|
|
16
16
|
|
|
17
|
-
Status: **0.
|
|
17
|
+
Status: **0.9.0.** The goal is to cover the numerical core of R's
|
|
18
18
|
`stats` package (distributions, descriptive statistics, hypothesis tests, linear models, special
|
|
19
19
|
functions, numerical methods and the basics of linear algebra) with R-compatible results; see [ROADMAP.md](ROADMAP.md) for what remains. See [CHANGELOG.md](CHANGELOG.md).
|
|
20
20
|
|
|
@@ -47,11 +47,17 @@ Distribution parameters are scalars.
|
|
|
47
47
|
### Random numbers that match `set.seed()`
|
|
48
48
|
|
|
49
49
|
```ts
|
|
50
|
-
import { setSeed, rnorm,
|
|
50
|
+
import { setSeed, rnorm, RNGkind, getRandomSeed, setRandomSeed, nextRNGStream, runif } from "@numero-uno-jpn/rstats";
|
|
51
51
|
|
|
52
52
|
setSeed(42);
|
|
53
53
|
rnorm(3); // [1.3709584471466685, -0.5646981713960887, 0.3631284113373392]
|
|
54
54
|
// R: set.seed(42); rnorm(3) gives the same numbers (up to the last bit)
|
|
55
|
+
|
|
56
|
+
// R's other settings: RNGkind("L'Ecuyer-CMRG") with parallel::nextRNGStream, sample.kind = "Rounding"
|
|
57
|
+
RNGkind({ kind: "L'Ecuyer-CMRG" });
|
|
58
|
+
setSeed(1); // R: set.seed(1, kind = "L'Ecuyer-CMRG")
|
|
59
|
+
setRandomSeed(nextRNGStream(getRandomSeed())); // R: .Random.seed <- nextRNGStream(.Random.seed)
|
|
60
|
+
runif(2); // [0.31369782407981056, 0.9280126525616814]
|
|
55
61
|
```
|
|
56
62
|
|
|
57
63
|
### Hypothesis tests
|
|
@@ -68,6 +74,25 @@ fisherTest([[3, 1], [1, 3]]).pValue; // 0.4857142857142857
|
|
|
68
74
|
pAdjust([0.01, 0.02, 0.03, 0.04], { method: "BH" }); // ≈ [0.04, 0.04, 0.04, 0.04]
|
|
69
75
|
```
|
|
70
76
|
|
|
77
|
+
### Generalized linear models
|
|
78
|
+
|
|
79
|
+
The predictors are a matrix (array of rows) or a vector, as for `lm`; a binomial response can be
|
|
80
|
+
rows of (successes, failures).
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { glm, glmSummary, glmPredict, glmConfint, glmAnova } from "@numero-uno-jpn/rstats";
|
|
84
|
+
|
|
85
|
+
const dose = [1, 2, 3, 4, 5, 6];
|
|
86
|
+
const counts = [[1, 19], [4, 16], [9, 11], [13, 7], [18, 2], [19, 1]];
|
|
87
|
+
const fit = glm(dose, counts, { family: "binomial" }); // R: glm(cbind(s, f) ~ dose, binomial)
|
|
88
|
+
fit.coefficients; // ≈ [-3.77413, 1.14807]
|
|
89
|
+
glmSummary(fit).pValue; // ≈ [5.357e-8, 3.579e-9] (z tests)
|
|
90
|
+
glmPredict(fit, { newdata: [3.5], type: "response" }); // { fit: ≈ [0.56073], seFit: ≈ [0.06140] }
|
|
91
|
+
glmConfint(fit).lower; // ≈ [-5.27166, 0.80033] (profile likelihood)
|
|
92
|
+
glmAnova(fit).table[1]; // ≈ [1, 62.978, 4, 0.5196, 2.09e-15]
|
|
93
|
+
fit.warnings; // [] (R's warnings, such as non-convergence)
|
|
94
|
+
```
|
|
95
|
+
|
|
71
96
|
### Linear algebra
|
|
72
97
|
|
|
73
98
|
Matrices are arrays of rows.
|
|
@@ -88,10 +113,10 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
|
|
|
88
113
|
|---|---|
|
|
89
114
|
| 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, and `log1pmx`, `lgamma1p`, `log1mexp`, `log1pexp` from R's C API (Rmath.h) |
|
|
90
115
|
| 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`), `r2dtable` |
|
|
116
|
+
| Random numbers | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister and L'Ecuyer-CMRG, `sample.kind` Rejection and Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 `r*` functions, `sample`, `sampleInt` (`sample.int`), `r2dtable` |
|
|
92
117
|
| 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` |
|
|
118
|
+
| 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`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
|
|
119
|
+
| Linear models | `lm` (matrix interface, with the `summary` quantities), `confint`, `predict`; `glm` (matrix interface, every family and link of R's `stats`) with `glmSummary` (`summary.glm`), `glmResiduals` (the four kinds), `glmHatvalues`, `glmRstandard`, `glmCooksDistance`, `glmPredict` (with standard errors), `glmConfint` (profile likelihood, exact limits), `glmAnova` (`anova.glm`) |
|
|
95
120
|
| 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
121
|
| Numerical methods | `integrate`, `optimize`, `uniroot`, `approx`, `spline`, `splinefun`, `splinefunH`, `barylag`, `hermiteInterp`, `ode`, `grad`, `jacobian`, `hessian` |
|
|
97
122
|
|
|
@@ -115,7 +140,8 @@ everyday use:
|
|
|
115
140
|
- Indices are 0-based: `sampleInt(n)` returns `0..n-1` (R's `sample.int()` minus 1, from the
|
|
116
141
|
same random stream), and pivots of `qr` and `chol` are 0-based.
|
|
117
142
|
- Signs of eigenvectors and singular vectors may differ from R (both are correct).
|
|
118
|
-
- Hypothesis tests do not emit R's warnings; all numeric fields and method names match.
|
|
143
|
+
- Hypothesis tests do not emit R's warnings; all numeric fields and method names match. `glm` returns
|
|
144
|
+
R's warnings in its result (`warnings`).
|
|
119
145
|
- Distribution parameters are not recycled as vectors.
|
|
120
146
|
|
|
121
147
|
Full list: [docs/differences-from-r.md](docs/differences-from-r.md).
|
|
@@ -130,35 +156,43 @@ removed. Approximate sizes after minification and gzip:
|
|
|
130
156
|
| `pnorm` | 1.2 KB |
|
|
131
157
|
| `setSeed`, `rnorm` | 1.7 KB |
|
|
132
158
|
| `solve` / `svd` / `eigen` | 1.7 / 2.0 / 3.7 KB |
|
|
133
|
-
| `wilcoxTest` / `fisherTest` / `tTest` | 8.6 / 15.
|
|
134
|
-
| `qbeta` / `pt` and `qt` |
|
|
135
|
-
|
|
|
159
|
+
| `wilcoxTest` / `fisherTest` / `tTest` | 8.6 / 15.6 / 21.4 KB |
|
|
160
|
+
| `qbeta` / `pt` and `qt` | 23.2 / 30.3 KB |
|
|
161
|
+
| `glm` and `glmSummary` / `glm` with all its methods | 27.2 / 39.2 KB |
|
|
162
|
+
| everything | 130.0 KB |
|
|
136
163
|
|
|
137
164
|
(`npm run size` measures these.)
|
|
138
165
|
|
|
139
166
|
Each area is also a subpath export, for importing one area without the rest:
|
|
140
|
-
`@numero-uno-jpn/rstats/distributions`, `/tests` (hypothesis tests,
|
|
141
|
-
`predict`), `/linalg`, `/descriptive`, `/numerics` and `/special`.
|
|
167
|
+
`@numero-uno-jpn/rstats/distributions`, `/tests` (hypothesis tests, `lm`, `confint` and
|
|
168
|
+
`predict`, and `glm` with its methods), `/linalg`, `/descriptive`, `/numerics` and `/special`.
|
|
142
169
|
|
|
143
170
|
Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
|
|
144
|
-
function,
|
|
171
|
+
function, 130 KB gzipped) from jsDelivr, which serves each release tag of this repository:
|
|
145
172
|
|
|
146
173
|
```html
|
|
147
174
|
<script type="module">
|
|
148
|
-
import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.
|
|
175
|
+
import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.9.0/dist/rstats.js";
|
|
149
176
|
console.log(pnorm(1.96)); // 0.9750021048517795
|
|
150
177
|
</script>
|
|
151
178
|
```
|
|
152
179
|
|
|
180
|
+
The functions are named exports with R's names, without a prefix such as `jStat.` or `_.`. To
|
|
181
|
+
keep them apart from other names, import the module as a namespace (`import * as rs from` the
|
|
182
|
+
URL above) and call `rs.pnorm(1.96)`, `rs.tTest(x, y)`. With a bundler, unused functions are
|
|
183
|
+
still removed (`import * as rs from "@numero-uno-jpn/rstats"`); from a CDN the whole file is
|
|
184
|
+
loaded either way. Nothing is added to `window`: to use the functions from other scripts or the
|
|
185
|
+
browser console, assign `window.rs = rs` yourself.
|
|
186
|
+
|
|
153
187
|
A page that needs only some areas can load the per-area bundles instead: `dist/distributions.js`,
|
|
154
188
|
`dist/tests.js`, `dist/linalg.js`, `dist/descriptive.js`, `dist/numerics.js` and `dist/special.js`
|
|
155
189
|
export the same functions as the subpaths above, and share their common code through
|
|
156
190
|
`dist/chunks/`, so loading two areas does not load that code twice. With its chunks, one area
|
|
157
|
-
transfers 18 KB (`numerics`) to
|
|
191
|
+
transfers 18 KB (`numerics`) to 102 KB (`tests`) gzipped.
|
|
158
192
|
|
|
159
193
|
Release tags contain the build output (`dist/`), which is not on the main branch. npm-based CDNs
|
|
160
194
|
work as well, for example
|
|
161
|
-
`https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.
|
|
195
|
+
`https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.9.0/dist/rstats.js` or
|
|
162
196
|
`https://esm.sh/@numero-uno-jpn/rstats`.
|
|
163
197
|
|
|
164
198
|
The browser build is tested in headless Chromium, both bundled and as `dist/rstats.js` loaded as
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -106,6 +106,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
106
106
|
`detail/bessel_jy.hpp`, `detail/bessel_jy_series.hpp`, `detail/bessel_jy_asym.hpp` and the
|
|
107
107
|
dispatch in `bessel.hpp`, in `src/special/besselIK.ts` and `src/special/besselJY.ts`
|
|
108
108
|
(Copyright (c) 2006 Xiaogang Zhang, (c) 2007 John Maddock, (c) 2024 Matt Borland)
|
|
109
|
+
- Ported (Boost.Math commit 775c9e0): `beta_small_b_large_a_series` in
|
|
110
|
+
`include/boost/math/special_functions/beta.hpp` (DiDonato and Morris's asymptotic expansion for
|
|
111
|
+
large a and small b: the coefficients p_n and the upward recursion of J_n), in
|
|
112
|
+
`src/special/incbetLargeA.ts` ((C) Copyright John Maddock 2006)
|
|
109
113
|
|
|
110
114
|
```
|
|
111
115
|
Boost Software License - Version 1.0 - August 17th, 2003
|
|
@@ -315,3 +319,34 @@ they are listed so that readers can find the originals.
|
|
|
315
319
|
- QUADPACK (Piessens, de Doncker-Kapenga, Überhuber, Kahaner 1983): `dqagse` and `dqagie` (adaptive
|
|
316
320
|
Gauss–Kronrod quadrature with extrapolation), behind `integrate` — `src/integrate/quadpack.ts`,
|
|
317
321
|
ported from SciPy's C translation (see SciPy above)
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Published methods (implemented from the papers, no code copied)
|
|
326
|
+
|
|
327
|
+
Listed for attribution; no license terms apply to the methods themselves.
|
|
328
|
+
|
|
329
|
+
- P. L'Ecuyer, "Good parameters and implementations for combined multiple recursive random number
|
|
330
|
+
generators", Operations Research 47 (1999) 159–164: the MRG32k3a generator and its constants (R's
|
|
331
|
+
`RNGkind("L'Ecuyer-CMRG")`) — `src/random/lecuyer.ts`
|
|
332
|
+
- P. L'Ecuyer, R. Simard, E. J. Chen and W. D. Kelton, "An object-oriented random-number package with
|
|
333
|
+
many long streams and substreams", Operations Research 50 (2002) 1073–1075: the jump-ahead matrices for
|
|
334
|
+
streams (2^127 steps) and substreams (2^76 steps) — `src/random/streams.ts`
|
|
335
|
+
- E. Brunner and U. Munzel, "The nonparametric Behrens-Fisher problem: asymptotic theory and a small-sample
|
|
336
|
+
approximation", Biometrical Journal 42 (2000) 17–25: the Brunner-Munzel test (lawstat's
|
|
337
|
+
`brunner.munzel.test`) — `src/htest/brunnerMunzelTest.ts`
|
|
338
|
+
- P. McCullagh and J. A. Nelder, "Generalized Linear Models", 2nd ed. (Chapman and Hall, 1989): the
|
|
339
|
+
variance functions and deviances of the families (table 2.1), iteratively reweighted least squares
|
|
340
|
+
(section 2.5), the likelihood ratio and score statistics of the intervals and analysis of deviance, with
|
|
341
|
+
R's behaviour taken from oracle/glm-behaviour.md and R's help pages (no R code was read or used) —
|
|
342
|
+
`src/models/glmFamily.ts`, `src/models/glm.ts`, `src/models/glmConfint.ts`, `src/models/glmAnova.ts`
|
|
343
|
+
|
|
344
|
+
- N. M. Temme, "Incomplete Laplace integrals: uniform asymptotic expansion with application to the
|
|
345
|
+
incomplete beta function", SIAM J. Math. Anal. 18 (1987) 1638–1663, and Temme, "Special Functions: An
|
|
346
|
+
Introduction to the Classical Functions of Mathematical Physics" (Wiley, 1996), §11.3.3: the uniform
|
|
347
|
+
asymptotic expansion of the incomplete beta function for large a and b, with coefficients generated at run
|
|
348
|
+
time — `src/special/incbetTemme.ts`
|
|
349
|
+
- A. R. DiDonato and A. H. Morris, "Algorithm 708: Significant digit computation of the incomplete beta
|
|
350
|
+
function ratios", ACM Trans. Math. Software 18 (1992) 360–373, eq. 9 to 9.6 (the formulas only; the
|
|
351
|
+
TOMS 708 code is not used): the asymptotic expansion of the incomplete beta function for large a and
|
|
352
|
+
small b, with the complementary tail from the same expansion summed downwards — `src/special/incbetLargeA.ts`
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.9.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as v,b as y,c as x,d as L,e as q,f as U,g as Q,h as qt,i as Tn,j as Bt,u as z,v as Jn,w as bt}from"./chunk-IVOBWYLV.js";import{a as G,b as D,c as gt,l as zn}from"./chunk-LE7TBHNI.js";import{A as j,D as T,E as Yn,a as tn,e as g,g as pt,h as S,j as rn,l as Zn,n as P,o as Rt,p as Ct,q as St,s as Y,t as at,u as C,z as Pn}from"./chunk-FC2TLHZC.js";import{b as w,c as $,d as F,e as ft,f as $n,g as R,h as nn,i as _,j as dt,k as W}from"./chunk-H2AP6TCR.js";function xe(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-tn(i,r)/tn(i,e);return n<.5?-o:o}function Fe(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 kn(n,t){let r=(n-1)*Math.log(t),e=r*r,i=e*r,o=e*e,u=n*n,s=u*n,a=(n-1)*(1+r),c=(n-1)*(-(e/2)+(n-2)*r+(3*n-5)/2),f=(n-1)*(i/3-(3*n-5)*e/2+(u-6*n+7)*r+(11*u-46*n+47)/6),l=(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),N=t*t,h=N*t,m=N*N;return t+r+a/t+c/N+f/h+l/m}function en(n,t,r){if(n===1)return r>.9?-Math.log1p(-t):-Math.log(r);if(n<1){let M=Zn(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-rn);return d/(1-d/(n+1))}if(n<.3&&p>=.35){let d=Math.exp(-rn-p),I=d*Math.exp(d);return d*Math.exp(I)}if(p>.15||n>=.3){let d=-Math.log(p),I=d-(1-n)*Math.log(d);return d-(1-n)*Math.log(I)-Math.log(1+(1-n)/(1+I))}if(p>.1){let d=-Math.log(p),I=d-(1-n)*Math.log(d);return d-(1-n)*Math.log(I)-Math.log((I*I+2*(3-n)*I+(2-n)*(3-n))/(I*I+(5-n)*I+2))}return kn(n,-Math.log(p))}let e=xe(t,r),i=e*e,o=i*e,u=i*i,s=u*e,a=Math.sqrt(n),c=n+e*a+(i-1)/3;if(c+=(o-7*e)/(36*a),c-=(3*u+7*i-16)/(810*n),c+=(9*s+256*o-433*e)/(38880*n*a),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)+P(n);if(p<-M*2.3)return kn(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 f=c,l=n+1,N=n+2;if(c<.15*l){let M=Math.log(t)+P(l);f=Math.exp((M+c)/n),e=Math.log1p(f/l*(1+f/N)),f=Math.exp((M+f-e)/n),e=Math.log1p(f/l*(1+f/N)),f=Math.exp((M+f-e)/n),e=Math.log1p(f/l*(1+f/N*(1+f/(n+3)))),f=Math.exp((M+f-e)/n)}if(f<=.01*l||f>.7*l)return f;let h=Math.log(Fe(n,f,100,1e-4)),m=Math.log(t)+P(l);return f=Math.exp((m+f-h)/n),f*(1-(n*Math.log(f)-f-m+h)/(n-f))}function on(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 Le(n,t){if(t<1){let r=C(t,n,!0),e=t/n;return r+(Number.isFinite(e)?Math.log(e):Math.log(t)-Math.log(n))}return C(t-1,n,!0)}function ct(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 x(e);if(t===0)return n===0?1/0:x(e);if(n===0)return t<1?1/0:t>1?x(e):e?-Math.log(r):1/r;if(t<1){let o=C(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=C(t-1,n/r,e);return e?i-Math.log(r):i/r}function Ot(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?v(e,i):y(e,i):o<=0?v(e,i):j(t,o,e,i)}function Ee(n,t,r,e){let{lower:i,logTarget:o,linearTarget:u}=q(n,r,e),s=j(t,Number.MIN_VALUE,i,!0);if(i?s>=o:s<=o)return 0;let a;if(t>1&&o<=-700){let c=S(o,{lowerTail:i,logP:!0}),f=1-1/(9*t)+c/Math.sqrt(9*t);a=f>0?t*f*f*f:t*.001}else if(o>-700){let c=Math.exp(o),f=-Math.expm1(o);a=i?en(t,c,f):en(t,f,c)}else if(i)a=Math.exp((o+Rt(t))/t);else{a=-o;for(let c=0;c<3;c++)a=-o-P(t)+(t-1)*Math.log(a)}return U({logTarget:o,...u!==void 0&&{linearTarget:u},lower:i,cdf:(c,f)=>j(t,c,f,!1),cdfLog:(c,f)=>j(t,c,f,!0),cdfBoth:(c,f)=>Pn(t,c,f),pdfLog:c=>Le(c,t),dlogPdf:c=>(t-1)/c-1,x0:a,lo:0,hi:1/0,positive:!0})}function nt(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:Ee(n,t,e,i)*r}function ho(n,t,r={}){let e=on(r),i=r.log??!1;return g(n,o=>ct(o,t,e,i))}function mo(n,t,r={}){let e=on(r),{lowerTail:i=!0,logP:o=!1}=r;return g(n,u=>Ot(u,t,e,i,o))}function Mo(n,t,r={}){let e=on(r),{lowerTail:i=!0,logP:o=!1}=r;return g(n,u=>nt(u,t,e,i,o))}var It=8*Number.EPSILON,tr=2*Number.EPSILON,_e=1e-290;function K(n){let{p:t,lowerTail:r,logP:e,cdf:i,lo:o,hi:u}=n,s;if(e||t<_e){let l;e?l=r?t*(1+tr):t*(1-tr):l=Math.log(t)+Math.log1p(r?-It:It),s=r?N=>i(N,!0,!0)>=l:N=>i(N,!1,!0)<=l}else{let l;if(r?l=t*(1-It):l=1-t>4*It?t*(1+It):t,l>.5){let N=1-l;s=r?h=>i(h,!1,!1)<=N:h=>i(h,!0,!1)>=N}else s=r?N=>i(N,!0,!1)>=l:N=>i(N,!1,!1)<=l}let a=Math.round(n.y0);if(Number.isFinite(a)||(a=o),a=Math.min(Math.max(a,o),u),s(a)){let l=1,N=a-l;for(;N>=o&&s(N);)a=N,l*=2,N=a-l;if(N<o){if(a===o)return o;N=o-1}return nr(N,a,s)}let c=1,f=a+c;for(;f<=u&&!s(f);)a=f,c*=2,f=a+c;return f>u&&(f=u),nr(a,f,s)}function nr(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=G;function Ae(n,t,r){return Number.isNaN(n)||Number.isNaN(t)?NaN:t<0?NaN:Wt(n)?x(r):n<0||!Number.isFinite(n)?x(r):C(Math.round(n),t,r)}function we(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t<0)return NaN;if(n<0)return v(r,e);if(t===0)return y(r,e);if(!Number.isFinite(n))return y(r,e);let i=Math.floor(n+1e-7);return j(i+1,t,!r,e)}function De(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=S(n,{lowerTail:r,logP:e}),s=t+o*(u+(u*u-1)/(6*o));return K({p:n,lowerTail:r,logP:e,cdf:(a,c,f)=>j(a+1,t,!c,f),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=>Ae(i,t,e))}function _o(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return g(n,o=>we(o,t,e,i))}function Ao(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return g(n,o=>De(o,t,e,i))}var Re=1e-17,Ce=Math.log(Re),rr=2e7,sn=500,un=2**sn,yt=2**-sn,Se=2**250,qe=2**-250,fn=sn*Math.LN2,Lt={h:0,l:0,k:0};function Z(n,t,r,e=!1){if(n===0)return Lt;if(!Number.isFinite(n))return{h:n,l:0,k:r};for(;Math.abs(n)>Se;)n*=yt,t*=yt,r++;for(;Math.abs(n)<qe;)n*=un,t*=un,r--;return e?{h:n,l:t,k:r,approx:e}:{h:n,l:t,k:r}}var Be=[346.5735902799727,-22599635089223323e-30];function Gt(n,t){if(n>1e-305||Number.isNaN(n))return Z(n,0,0);let r=t(),[e,i]=typeof r=="number"?[r,0]:r;if(e===-1/0)return Lt;if(Number.isNaN(e))return{h:NaN,l:0,k:0};let o=Math.round(e/fn),u=F([e,i],R(Be,[-o,0])),s=Math.exp(u[0]);return typeof r=="number"?Z(s,0,o,!0):Z(s,s*u[1],o)}function an(n,t){if(n===0)return[-t,0];let r=22250738585072014e-324;if(n<=t*r||t<n*r||!Number.isFinite(n))return F(R(W([t,0]),[n,0]),[-t-Rt(n),0]);let e=F(St(n,[t,0]),[Ct(n),0]);return F([-e[0],-e[1]],[-.5*(Oe+Math.log(n)),0])}var Oe=1.8378770664093456;function J(n,t){return n.approx===!0&&xt(n)>-700?t():n}function rt(n,t){return vt(n,Z(t[0],t[1],0))}function We(n,t){if(n.h===0)return Lt;let r=Z(t[0],t[1],0),e=_([n.h,n.l],[r.h,r.l]);return Z(e[0],e[1],n.k-r.k,n.approx)}function er(n,t,r){let e=rt(n,t.ratio(r));return t.ratioK?{...e,k:e.k+t.ratioK}:e}function ir(n,t,r){let e=We(n,t.ratio(r));return t.ratioK?{...e,k:e.k-t.ratioK}:e}function vt(n,t){if(n.h===0||t.h===0)return Lt;let r=R([n.h,n.l],[t.h,t.l]);return Z(r[0],r[1],n.k+t.k,n.approx===!0||t.approx===!0)}function Ut(n,t,r,e){for(let i=r;i<e&&n!==0;i++)n*=yt,t*=yt;return[n,t]}function or(n,t){if(n.h===0)return t;if(t.h===0)return n;let r=Math.max(n.k,t.k),e=F(Ut(n.h,n.l,n.k,r),Ut(t.h,t.l,t.k,r));return Z(e[0],e[1],r)}function xt(n){return n.h===0?-1/0:Math.log(n.h)+n.l/n.h+n.k*fn}var Ft=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]=Ut(this.s,this.c,this.k,t.k),this.k=t.k);let[r,e]=Ut(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*fn:-1/0}get linear(){let t=this.s+this.c;for(let r=0;r<this.k;r++)t*=un;for(let r=0;r>this.k&&t!==0;r--)t*=yt;return t}value(t){return t?this.log:this.linear}divideBy(t){let r=Z(t,0,0);this.s/=r.h,this.c/=r.h,this.k-=r.k}};function Ue(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 je(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 jt(n,t,r){if(r===-1/0||!(n<t))return!1;let e=n-t;return n+e-Math.log(-Math.expm1(e))<=Ce+r}function et(n,t){return Gt(C(n,t,!1),()=>an(n,t))}function H(n,t){return Gt(n.inc(t,!1),()=>n.incLogDD?n.incLogDD(t):n.inc(t,!0))}function lt(n,t,r,e){return(r?lr(n,t):Nr(n,t)).value(e)}function ur(n,t,r){let e=r?lr(n,t):Nr(n,t);return{lin:e.linear,log:e.log}}function sr(n,t,r,e){return C(r,t,!0)+n.cdf(r,e,!0)}function fr(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 Ge=60;function ar(n,t,r,e){let i=n(t)-Ge;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 cr=3e3;function lr(n,t){let r=Ue(n);if(r>cr){let a=c=>sr(t,n,c,!0);r=ar(a,fr(a,0,r),1,r)}let e=Gt(t.cdf(r,!0,!1),()=>t.cdf(r,!0,!0)),i=et(r,n),o=r>0?H(t,r-1):Lt,u=new Ft,s=-1/0;for(let a=r;a>=0;a--){let c=vt(i,e),f=xt(c);if(u.add(c),jt(f,s,u.log)||(s=f,a===0))break;e=or(e,o),i=J(rt(i,dt([a,0],n)),()=>et(a-1,n)),a>=2&&(o=o.h===0?H(t,a-2):J(ir(o,t,a-1),()=>H(t,a-2)))}return u}function Nr(n,t){let r=je(n),e=!1;for(;;){let i=Gt(t.cdf(r,!1,!1),()=>t.cdf(r,!1,!0)),o=et(r,n),u=H(t,r),s=new Ft,a=-1/0,c=-1;for(let f=r;f<r+rr;f++){let l=vt(o,i),N=xt(l);if(s.add(l),jt(N,a,s.log)||N===-1/0&&f>n+50&&f>r+50)break;if(!e&&f-r>=cr&&N>=a){let h=d=>sr(t,n,d,!1),m=h(f),M=f+1;for(let d=1;h(M)>=m;d*=2)M=f+d;let p=ar(h,fr(h,f,M),-1,f);if(e=!0,p>f){c=p;break}}a=N,i=or(i,u),o=J(rt(o,dt([n,0],f+1)),()=>et(f+1,n)),u=u.h===0?H(t,f+1):J(er(u,t,f+1),()=>H(t,f+1))}if(c<0)return s;r=c}}function Ht(n,t,r,e,i,o){let u=Number.isFinite(e)?Math.max(0,Math.round(e)):0,s=new Ft,a=et(u,n),c=H(t,u),f=a,l=c,N=-1/0;for(let h=u;h<u+rr;h++){let m=rt(vt(f,l),[r(h),0]),M=xt(m);if(s.add(m),jt(M,N,s.log)||M===-1/0&&h>n+50&&h>u+50)break;N=M,f=J(rt(f,dt([n,0],h+1)),()=>et(h+1,n)),l=l.h===0?H(t,h+1):J(er(l,t,h+1),()=>H(t,h+1))}f=a,l=c,N=-1/0;for(let h=u-1;h>=0;h--){f=J(rt(f,dt([h+1,0],n)),()=>et(h,n)),l=l.h===0?H(t,h):J(ir(l,t,h+1),()=>H(t,h));let m=rt(vt(f,l),[r(h),0]),M=xt(m);if(s.add(m),jt(M,N,s.log))break;N=M}return s.divideBy(i),s.value(o)}function He(n){return n<=.5?[[n,0],w(1,-n)]:[w(1,-(1-n)),[1-n,0]]}function pr(n,t,r,e){let[i,o]=He(n),{e:u}=at(t,r,i,o),s=t*r/(t+r);if(!e&&u[0]<700&&n>1e-290&&o[0]>1e-290){let l=Math.exp(-u[0])*(1-u[1])*Math.sqrt(s/(2*Math.PI));if(l>1e-290&&l<1e290){let N=R(i,o);return l/N[0]*(1-N[1]/N[0])}}let a=n>1e-290&&o[0]>1e-290?W(R(i,o)):F(W(i),W(o)),c=s>1e-290&&s<1e290?.5*Math.log(s/(2*Math.PI)):.5*(Math.log(t)+Math.log(r)-Math.log(t+r)-Math.log(2*Math.PI)),f=F(ft(F(u,a)),[c,0]);return e?f[0]+f[1]:Math.exp(f[0])*(1+f[1])}function Qe(n,t,r,e){return pr(n,r,e,!0)}function cn(n,t,r,e){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<0||r<0?NaN:n<0||n>1?x(e):t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)?t===0&&r===0?n===0||n===1?1/0:x(e):t===0||r/t===1/0?n===0?1/0:x(e):r===0||t/r===1/0?n===1?1/0:x(e):n===.5?1/0:x(e):n===0?t>1?x(e):t<1?1/0:e?Math.log(r):r:n===1?r>1?x(e):r<1?1/0:e?Math.log(t):t:pr(n,t,r,e)}function ln(n,t,r,e,i){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<0||r<0?NaN:n>=1?y(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?y(e,i):r===0||t/r===1/0?v(e,i):n<.5?v(e,i):y(e,i):n<=0?v(e,i):Q(t,r,n,1-n,e,i)}function Nn(n,t,r,e){if(!(n>1&&t>1))return;let i=S(e,{logP:!0}),o=r?-i:i,u=1/(2*n-1),s=1/(2*t-1),a=2/(u+s),c=(o*o-3)/6;if(!(a+c>0))return;let f=o*Math.sqrt(a+c)/a-(s-u)*(c+5/6-2/(3*a)),l=n/(n+t*Math.exp(2*f));return l>0&&l<1?l:void 0}function hr(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 a=(e+Math.log(n)+T(n,t))/n;s=Math.exp(Math.max(a,-745)),u=Math.min(s,.25)}if(!(s<.001)){let a=Nn(n,t,r,e);a!==void 0&&a<.5&&(u=a)}return U({logTarget:e,...i!==void 0&&{linearTarget:i},lower:r,cdf:(a,c)=>Q(n,t,a,1-a,c,!1),cdfLog:(a,c)=>Q(n,t,a,1-a,c,!0),cdfBoth:(a,c)=>Bt(n,t,a,1-a,c),pdfLog:a=>Qe(a,1-a,n,t),dlogPdf:a=>(n-1)/a-(t-1)/(1-a),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 l=i?n:Math.log(n),N=e?l:Math.log1p(-Math.exp(l));return N<-Math.LN2?0:N>-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:a}=q(n,e,i),c=Q(t,r,.5,.5,u,!0);return(u?s<=c:s>=c)?hr(t,r,u,s,a):1-hr(r,t,!u,s,a)}function Ko(n,t,r,e={}){let{log:i=!1,ncp:o}=e;return o!==void 0?g(n,u=>mr(u,t,r,o,i)):g(n,u=>cn(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=>Mr(s,t,r,u,i,o)):g(n,s=>ln(s,t,r,i,o))}function Xo(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?g(n,s=>dr(s,t,r,u,i,o)):g(n,s=>Qt(s,t,r,i,o))}function br(n,t){let r=t<1e-250,e=r?t*2**500:t;return{ratioK:r?-1:0,cdf:(i,o,u)=>j(n+i,t,o,u),inc:(i,o)=>{let[u,s]=gr(n,i,t);return o?C(u,t,!0)+s:C(u,t,!1)*(1+s)},ratio:i=>_([e,0],w(n,i)),incLogDD:i=>{let[o,u]=gr(n,i,t);return F(an(o,t),[u,0])}}}function gr(n,t,r){let[e,i]=w(n,t);return[e,i===0?0:i*(Math.log(r)-gt(e+1))]}function Ir(n,t){return n>=0&&t>=0&&Number.isFinite(n)&&Number.isFinite(t)}function yr(n,t,r,e){let i=r/2;if(i*(n/2)>1e18){let s=Ke(n,t,r);return e?{lin:-Math.expm1(s),log:Math.log1p(-Math.exp(s))}:{lin:Math.exp(s),log:s}}let o=br(t/2,Math.max(n/2,Number.MIN_VALUE)),u=ur(i,o,e);if(u.lin>.5){let s;return{lin:u.lin,get log(){return s??=Math.log1p(-lt(i,o,!e,!1)),s}}}return u}function Ke(n,t,r){let e=.5-Math.sqrt(r/n)/2-(t-3)/(4*n);return xr(n,t,r,!0)-Math.log(e)}function hn(n,t,r,e,i){let o=yr(n,t,r,e);return i?o.log:o.lin}function Ve(n,t){let r=NaN,e=!0,i={lin:NaN,log:NaN};return(o,u)=>((o!==r||u!==e)&&(i=yr(o,n,t,u),r=o,e=u),i)}function vr(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?xr(n,t,r,e):Ht(u,br(i,o),a=>i+a,s,n,e)}function xr(n,t,r,e){let i=t/2-1,o=Math.sqrt(r*n),u=4*i*i,s=1,a=1;for(let l=1;l<30&&(s*=-(u-(2*l-1)*(2*l-1))/(8*l*o),a+=s,!(Math.abs(s)<1e-17*Math.abs(a)));l++);let c=Math.sqrt(n)-Math.sqrt(r),f=-Math.LN2-c*c/2+i/2*Math.log(n/r)-.5*Math.log(2*Math.PI*o)+Math.log(a);return e?f:Math.exp(f)}function Fr(n,t,r,e){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:Ir(t,r)?r===0?ct(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:vr(n,t,r,e):NaN}function Lr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!Ir(t,r))return NaN;if(n<0)return v(e,i);if(n===0){if(t>0)return v(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?y(e,i):j(t/2,Math.max(n/2,Number.MIN_VALUE),e,i):n===1/0?y(e,i):hn(n,t,r,e,i)}function Er(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 nt(n,t/2,2,e,i);let{lower:u,logTarget:s,linearTarget:a}=q(n,e,i),c=Ve(t,r),f=hn(Number.MIN_VALUE,t,r,u,!0);if(u?f>=s:f<=s)return 0;let l=(t+2*r)/(t+r),N=(t+r)*(t+r)/(t+2*r),h=l*nt(s,N/2,2,u,!0);(!(h>0)||!Number.isFinite(h))&&(h=t+r);let m=Math.max(h,t+r,1);for(let M=0;M<2e3;M++){let p=hn(m,t,r,u,!0);if(u?p>=s:p<=s)break;m*=2}return U({logTarget:s,...a!==void 0&&{linearTarget:a},lower:u,cdf:(M,p)=>c(M,p).lin,cdfLog:(M,p)=>c(M,p).log,pdfLog:M=>vr(M,t,r,!0),x0:Math.min(h,m),lo:0,hi:m,positive:!0})}function Ar(n,t,r,e){let i=w(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,a,c)=>qt(n+s,t,r,e,a,c),inc:(s,a)=>{let[c,f]=_r(n,t,s,r),l=t/(c+t);return a?Y(c,t,r,e,!0)+Math.log(l)+f:Y(c,t,r,e,!1)*l*(1+f)},ratio:s=>_(R(u,F(i,[s-1,0])),w(n,s)),incLogDD:s=>{let[a,c]=_r(n,t,s,r);if(!(r[0]>1e-305&&e[0]>1e-305)){let N=Xe(a,t,r,e);return typeof N=="number"?N+c:F(N,[c,0])}let{e:f,logDenom:l}=at(a,t,r,e);return F([-f[0],-f[1]],[-.5*l+Math.log(t/(a+t))+c,0])}}}function _r(n,t,r,e){let[i,o]=w(n,r);return o===0?[i,0]:[i,o*(Math.log(e[0])+e[1]/e[0]+gt(i+t)-gt(i+1))]}function Xe(n,t,r,e){if(!(r[0]>0&&e[0]>0))return-1/0;let i=F(nn(W(r),n),nn(W(e),t));return F(F(i,ft(Yn(n,t))),[-Math.log(n),0])}function Mn(n){return n<=.5?[[n,0],w(1,-n)]:[w(1,-(1-n)),[1-n,0]]}function dn(n,t,r,e,i,o,u){let s=Ar(n,t,e,i),a=r/2,c=lt(a,s,o,!1);return u?c>.5?Math.log1p(-lt(a,s,!o,!1)):c>=1e-280?Math.log(c):lt(a,s,o,!0):c}function wr(n,t,r,e,i,o,u){let s=r/2,a=e[0],c=s*a,f=n-1-c,l=(-f+Math.sqrt(Math.max(0,f*f+4*c*(n+t-1))))/2;return Ht(s,Ar(n,t,e,i),N=>n+N,l,o,u)}function pn(n,t,r){return n>0&&t>0&&Number.isFinite(n)&&Number.isFinite(t)&&r>=0&&Number.isFinite(r)}function Dr(n,t,r,e,i){let[o,u]=Mn(n),s=R(o,u);return wr(t,r,e,o,u,s[0]+s[1],i)}function mr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!pn(t,r,e))return NaN;if(e===0)return cn(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:Dr(n,t,r,e,i)}function Mr(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 v(i,o);if(n>=1)return y(i,o);if(!pn(t,r,e))return NaN;if(e===0)return ln(n,t,r,i,o);let[u,s]=Mn(n);return dn(t,r,e,u,s,i,o)}function dr(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(!pn(t,r,e))return NaN;if(e===0)return Qt(n,t,r,i,o);let{lower:s,logTarget:a,linearTarget:c}=q(n,i,o),f=(m,M,p)=>{let[d,I]=Mn(m);return dn(t,r,e,d,I,M,p)},l=f(Number.MIN_VALUE,s,!0);if(s?l>=a:l<=a)return 0;let N=f(1-Number.EPSILON/2,s,!0);if(s?N<a:N>a)return 1;let h=Qt(a,t+e/2,r,s,!0);return h>0&&h<1||(h=.5),U({logTarget:a,...c!==void 0&&{linearTarget:c},lower:s,cdf:(m,M)=>f(m,M,!1),cdfLog:(m,M)=>f(m,M,!0),pdfLog:m=>Dr(m,t,r,e,!0),x0:h,lo:0,hi:1,positive:!0})}function Rr(n,t,r){let e=$(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[w(1,-i),[i,0]]}function Cr(n,t,r,e,i){if(t/r*n<1e-306){let s=t/2,a=-e/2+s*(Math.log(t/r)+Math.log(n))-T(s,r/2)-Math.log(n);return i?a:Math.exp(a)}let[o,u]=Rr(n,t,r);return wr(t/2,r/2,e,o,u,n,i)}function Sr(n,t,r,e,i,o){let u=t/2,s=-e/2+u*(Math.log(t/r)+Math.log(n))-Math.log(u)-T(u,r/2);return i?o?s:Math.exp(s):o?-Math.exp(s):-Math.expm1(s)}function Et(n,t,r,e,i,o){if(t/r*n<1e-306)return Sr(n,t,r,e,i,o);let[u,s]=Rr(n,t,r);return dn(t/2,r/2,e,u,s,i,o)}function qr(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:Kt(n,t,r,i);if(r===1/0){let o=Fr(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?Kt(n,t,r,i):Cr(n,t,r,e,i)}function Br(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?v(i,o):n===1/0?y(i,o):t===1/0?NaN:r===1/0?Lr(n*t,t,e,i,o):t/r*n<1e-306?Sr(n,t,r,e,i,o):e===0?mn(n,t,r,i,o):Et(n,t,r,e,i,o)}function Or(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?Er(n,t,e,i,o)/t:e===0?Vt(n,t,r,i,o):$e(n,t,r,e,i,o)}function $e(n,t,r,e,i,o){let{lower:u,logTarget:s,linearTarget:a}=q(n,i,o),c=Et(Number.MIN_VALUE,t,r,e,u,!0);if(u?c>=s:c<=s)return 0;let f=Et(Number.MAX_VALUE,t,r,e,u,!0);if(u?f<s:f>s)return 1/0;let l=(t+e)*(t+e)/(t+2*e),N=(t+e)/t*Vt(s,l,r,u,!0);return(!(N>0)||!Number.isFinite(N))&&(N=1),U({logTarget:s,...a!==void 0&&{linearTarget:a},lower:u,cdf:(h,m)=>Et(h,t,r,e,m,!1),cdfLog:(h,m)=>Et(h,t,r,e,m,!0),pdfLog:h=>Cr(h,t,r,e,!0),x0:N,lo:0,hi:1/0,positive:!0})}function Wr(n,t,r,e){let i=$(t,n),o,u;if(Number.isFinite(i[0])&&Number.isFinite(i[1])&&Math.abs(i[0])<1e290){let l=F(i,[r,0]);o=_(i,l),u=_([r,0],l)}else u=[r/t/n,0],o=[1,-u[0]];let s=o[0],a=u[0];if(t>=2){let l=t*a/2,N=Y((t-2)/2,r/2,o,u,e);return e?Math.log(l)+N:l*N}let c=t/(r+t*n)*t*r/(2*(t+r)*s),f=Y(t/2,r/2,o,u,e);return e?Math.log(c)+f:c*f}function Kt(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 x(e);if(n===0)return t>2?x(e):t===2?e?0:1:1/0;if(!Number.isFinite(t)&&!Number.isFinite(r))return n===1?1/0:x(e);if(!Number.isFinite(r))return ct(n,t/2,2/t,e);if(!Number.isFinite(t)){let i=ct(1/n,r/2,2/r,e);return e?i-2*Math.log(n):i/(n*n)}return Number.isFinite(n)?Wr(n,t,r,e):t<2?NaN:x(e)}function gn(n,t,r,e,i){let o=$(t,n);if(Number.isFinite(o[0])&&Number.isFinite(o[1])&&Math.abs(o[0])<1e290){let s=F(o,[r,0]);return qt(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 Ze(n,t,r,e){let i=Nn(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 Pe(n,t,r,e){let i=$(t,n);if(Number.isFinite(i[0])&&Number.isFinite(i[1])&&Math.abs(i[0])<1e290){let u=F(i,[r,0]);return Tn(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 mn(n,t,r,e,i){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<=0||r<=0?NaN:n<=0?v(e,i):n===1/0?y(e,i):!Number.isFinite(t)&&!Number.isFinite(r)?n===1?i?-Math.LN2:.5:n<1?v(e,i):y(e,i):Number.isFinite(r)?Number.isFinite(t)?gn(n,t,r,e,i):Ot(r/n,r/2,2,!e,i):Ot(n*t,t/2,2,e,i)}function Vt(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 nt(n,t/2,2,e,i)/t;if(!Number.isFinite(t))return r/nt(n,r/2,2,!e,i);let{lower:u,logTarget:s,linearTarget:a}=q(n,e,i);return u&&(s+Math.log(t/2)+T(t/2,r/2))/(t/2)+Math.log(r/t)<-746?0:!u&&-(s+Math.log(r/2)+T(t/2,r/2))/(r/2)+Math.log(r/t)>709.78?1/0:U({logTarget:s,...a!==void 0&&{linearTarget:a},lower:u,cdf:(c,f)=>gn(c,t,r,f,!1),cdfLog:(c,f)=>gn(c,t,r,f,!0),cdfBoth:(c,f)=>Pe(c,t,r,f),pdfLog:c=>Wr(c,t,r,!0),dlogPdf:c=>(t/2-1)/c-(t+r)/2*(t/(r+t*c)),x0:Ze(t,r,u,s),lo:0,hi:1/0,positive:!0})}function Fu(n,t,r,e={}){let{log:i=!1,ncp:o}=e;return o!==void 0?g(n,u=>qr(u,t,r,o,i)):g(n,u=>Kt(u,t,r,i))}function Lu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?g(n,s=>Br(s,t,r,u,i,o)):g(n,s=>mn(s,t,r,i,o))}function Eu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?g(n,s=>Or(s,t,r,u,i,o)):g(n,s=>Vt(s,t,r,i,o))}function bn(n,t){return Wt(n)||n<0||!Number.isFinite(n)||t<0||t>1}function Ye(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(bn(t,r))return NaN;if(Wt(n)||n<0||!Number.isFinite(n))return x(e);let i=Math.round(n),o=Math.round(t);if(i>o)return x(e);let u=r<=.5?[r,0]:w(1,-(1-r)),s=r<=.5?w(1,-r):[1-r,0];return Y(i,o-i,u,s,e)}function Ur(n,t,r,e,i){return Q(n+1,t-n,r,1-r,!e,i)}function Te(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(bn(t,r))return NaN;let o=Math.round(t);if(n<0)return v(e,i);let u=Math.floor(n+1e-7);return o<=u?y(e,i):r===0?y(e,i):r===1?v(e,i):Ur(u,o,r,e,i)}function ze(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,Je(t),e,i);if(o!==void 0)return o;if(bn(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,a=u*r,c=Math.sqrt(u*r*s),f=(s-r)/c,l=S(n,{lowerTail:e,logP:i}),N=a+c*(l+f*(l*l-1)/6);return K({p:n,lowerTail:e,logP:i,cdf:(h,m,M)=>h>=u?y(m,M):Ur(h,u,r,m,M),y0:Number.isFinite(N)?N:a,lo:0,hi:u})}function Ou(n,t,r,e={}){let i=e.log??!1;return g(n,o=>Ye(o,t,r,i))}function Wu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return g(n,u=>Te(u,t,r,i,o))}function Uu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return g(n,u=>ze(u,t,r,i,o))}function Je(n){let t=Math.round(n);return Math.abs(n%1)===.5&&t%2!==0?t-1:t}var In=1.1447298858494002;function ke(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!(r>0))return NaN;let i=(n-t)/r;if(Number.isNaN(i))return NaN;let o=Math.abs(i);if(o<=1)return e?-(In+Math.log(r))-Math.log1p(i*i):1/(Math.PI*r*(1+i*i));let u=1/o;return e?-(In+Math.log(r))-2*Math.log(o)-Math.log1p(u*u):u/(Math.PI*r)*(u/(1+u*u))}function ti(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!(r>0))return NaN;let o=n-t;if(Number.isNaN(o))return NaN;if(!(Math.abs(o)>r)){let c=o/r,f=.5+Math.atan(e?c:-c)/Math.PI;return i?Math.log(f):f}let u=r/Math.abs(o),s=Math.atan(u)/Math.PI;return e===o<0?i?u<1e-150?Math.log(r)-Math.log(Math.abs(o))-In:Math.log(s):s:i?Math.log1p(-s):1-s}var ni=1e-200,ri=-460;function jr(n,t,r){if(!r)return n/t/Math.PI;let e=Math.exp(-t/2);return e*(n/Math.PI)*e}function Xt(n){return n<=.25?-1/Math.tan(Math.PI*n):-Math.tan(Math.PI*(.5-n))}function ei(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(i?n>0:n<0||n>1)return NaN;if(!(r>0)||!Number.isFinite(r))return r===0?t:NaN;let o;if(i)if(n===0)o=1/0;else if(n===-1/0)o=-1/0;else{if(n<ri)return t+(e?-1:1)*jr(r,n,!0);o=n<-Math.LN2?Xt(Math.exp(n)):-Xt(-Math.expm1(n))}else if(n===0)o=-1/0;else if(n===1)o=1/0;else{if(n<ni)return t+(e?-1:1)*jr(r,n,!1);o=n<=.5?Xt(n):-Xt(1-n)}return zn(t,r,e?o:-o)}function Qu(n,t={}){let{location:r=0,scale:e=1,log:i=!1}=t;return g(n,o=>ke(o,r,e,i))}function Ku(n,t={}){let{location:r=0,scale:e=1,lowerTail:i=!0,logP:o=!1}=t;return g(n,u=>ti(u,r,e,i,o))}function Vu(n,t={}){let{location:r=0,scale:e=1,lowerTail:i=!0,logP:o=!1}=t;return g(n,u=>ei(u,r,e,i,o))}function yn(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(St(i,R([i,0],o)),R([i,0],u)):ft(R([i,0],W(o))),logDenom:0}}return at(n,t,r,e)}function Qr(n,t,r,e){let i=t+r,o=_([e,0],[i,0]),u=_([i-e,0],[i,0]),s=yn(n,t-n,o,u),a=yn(e-n,r-e+n,o,u),c=yn(e,i-e,o,u);return{e:$n(F(s.e,a.e),c.e),logDenom:s.logDenom+a.logDenom-c.logDenom}}function Kr(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 Vr(n){return-n.e[0]-n.e[1]-.5*n.logDenom}function $t(n,t,r){return[Math.max(0,r-t),Math.min(r,n)]}function ii(n,t,r,e,i){if([n,t,r,e].some(Number.isNaN))return NaN;if(![t,r,e].every(Number.isFinite)||G(t)||G(r)||G(e))return NaN;if(t=D(t),r=D(r),e=D(e),t<0||r<0||e<0||e>t+r)return NaN;if(G(n))return x(i);n=D(n);let[o,u]=$t(t,r,e);if(n<o||n>u)return x(i);if(e===0||e===t+r)return i?0:1;let s=Qr(n,t,r,e);return i?Vr(s):Kr(s,1)}function Gr(n,t,r,e){return _($(n,t),$(r,e))}function oi(n,t,r,e,i,o,u){let s=[1,0],a=[1,0],c=n;for(;!(i?c<=o:c>=u);){let f=i?Gr(c,r-e+c,t-c+1,e-c+1):Gr(t-c,e-c,c+1,r-e+c+1);s=R(s,f),a=F(a,s),c+=i?-1:1;let l=f[0];if(l<1&&s[0]*l/(1-l)<a[0]*2**-60)break}return a[0]+a[1]}function Xr(n,t,r,e,i,o){let[u,s]=$t(t,r,e),a=t+r,c=n*a<e*t,f=Hr(n,t,r,e,c,u,s);if(f.value>.5){let l=Hr(n,t,r,e,!c,u,s);l.value<f.value&&(f=l,c=!c)}return c===i?o?f.value>1e-300?Math.log(f.value):Vr(f.form)+Math.log(f.sum):f.value:o?Math.log1p(-f.value):1-f.value}function Hr(n,t,r,e,i,o,u){let s=i?n:n+1,a=Qr(s,t,r,e),c=oi(s,t,r,e,i,o,u);return{form:a,sum:c,value:Kr(a,c)}}function $r(n,t,r){if([n,t,r].every(Number.isFinite)&&(n=D(n),t=D(t),r=D(r),!(n<0||t<0||r<0||r>n+t)))return[n,t,r]}function ui(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;let u=$r(t,r,e);if(u===void 0)return NaN;[t,r,e]=u;let s=Math.floor(n+1e-7),[a,c]=$t(t,r,e);return s<a?v(i,o):s>=c?y(i,o):Xr(s,t,r,e,i,o)}function si(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;let u=$r(t,r,e);if(u===void 0)return NaN;[t,r,e]=u;let[s,a]=$t(t,r,e),c=L(n,s,a,i,o);if(c!==void 0)return c;if(s===a)return s;let f=t+r,l=e*t/f,N=Math.sqrt(e*t/f*(r/f)*(f-e)/Math.max(f-1,1)),h=S(n,{lowerTail:i,logP:o}),m=l+N*h;return K({p:n,lowerTail:i,logP:o,cdf:(M,p,d)=>M<s?v(p,d):M>=a?y(p,d):Xr(M,t,r,e,p,d),y0:Number.isFinite(m)?m:l,lo:s,hi:a})}function ku(n,t,r,e,i={}){let o=i.log??!1;return g(n,u=>ii(u,t,r,e,o))}function ts(n,t,r,e,i={}){let{lowerTail:o=!0,logP:u=!1}=i;return g(n,s=>ui(s,t,r,e,o,u))}function ns(n,t,r,e,i={}){let{lowerTail:o=!0,logP:u=!1}=i;return g(n,s=>si(s,t,r,e,o,u))}var fi=2**900,Zr=-900,it=new Map,ai=2**21,Zt=0,ci=2**25;function li(n,t){if(t+1>ci)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 a=1;a<=i;a++){for(let c=t;c>=a;c--)r[c]+=r[c-a];if(r[Math.min(t,Math.floor(a*(a+1)/4))]>fi){let c=2**Zr;for(let f=0;f<=t;f++)r[f]*=c;e-=Zr}}let o=new Float64Array(t+1),u=0,s=0;for(let a=0;a<=t;a++){let c=r[a]-s,f=u+c;s=f-u-c,u=f,o[a]=u}return{n,len:t+1,count:r,cum:o,scale:e}}function vn(n,t){let r=it.get(n);if(r!==void 0&&r.len>t)return it.delete(n),it.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=li(n,i);r!==void 0&&(it.delete(n),Zt-=r.len),it.set(n,o),Zt+=o.len;for(let[u,s]of it){if(Zt<=ai||u===n)break;it.delete(u),Zt-=s.len}return o}function xn(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 Fn(n){return Number.isFinite(n)?(n=D(n),n<=0?NaN:n):NaN}function Ni(n,t,r){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=Fn(t),Number.isNaN(t))return NaN;if(G(n))return x(r);n=D(n);let e=t*(t+1)/2;if(n<0||n>e)return x(r);let i=Math.min(n,e-n),o=vn(t,i);return xn(o.count[i],o,r)}function Pr(n,t,r,e){let i=t*(t+1)/2,o=n,u=i-n-1,s=r?o:u,a=r?u:o;if(s<=a){let l=vn(t,s);return xn(l.cum[s],l,e)}let c=vn(t,a),f=xn(c.cum[a],c,!1);return e?Math.log1p(-f):1-f}function hi(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=Fn(t),Number.isNaN(t))return NaN;let i=D(n+1e-7),o=t*(t+1)/2;return i<0?v(r,e):i>=o?y(r,e):Pr(i,t,r,e)}function mi(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=Fn(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),a=u+s*S(n,{lowerTail:r,logP:e});return K({p:n,lowerTail:r,logP:e,cdf:(c,f,l)=>c<0?v(f,l):c>=i?y(f,l):Pr(c,t,f,l),y0:Number.isFinite(a)?a:u,lo:0,hi:i})}function fs(n,t,r={}){let e=r.log??!1;return g(n,i=>Ni(i,t,e))}function as(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return g(n,o=>hi(o,t,e,i))}function cs(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return g(n,o=>mi(o,t,e,i))}var Tt=960,Mi=2**25,Pt=134217729,ot=new Map,di=2**21,Yt=0;function pi(n,t,r){if(r+1>Mi)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**Tt;for(let a=1;a<=n;a++){let c=Math.min(r,a*t),f=t+a,l=Pt*a,N=l-(l-a),h=a-N;l=Pt*f;let m=l-(l-f),M=f-m;for(let d=0;d<=c;d++){let I=e[d];if(I===0)continue;let b=I*a;l=Pt*I;let E=l-(l-I),V=I-E,B=E*N-b+E*h+V*N+V*h+i[d]*a,A=b/f,X=A*f;l=Pt*A;let O=l-(l-A),st=A-O,ve=O*m-X+O*M+st*m+st*M,Vn=(b-X-ve+B)/f,Xn=A+Vn;i[d]=Vn-(Xn-A),e[d]=Xn}let p=t+a;for(let d=c;d>=p;d--)Yr(e,i,d,d-p,-1);for(let d=a;d<=c;d++)Yr(e,i,d,d-a,1)}let o=new Float64Array(r+1),u=0,s=0;for(let a=0;a<=r;a++){let c=e[a],f=u+c,l=f-u,N=u-(f-l)+(c-l);N+=s+i[a],u=f+N,s=N-(u-f),o[a]=u}return{m:n,n:t,len:r+1,prob:e,cum:o}}function Yr(n,t,r,e,i){let o=n[r],u=i*n[e],s=o+u,a=s-o,c=o-(s-a)+(u-a);c+=t[r]+i*t[e];let f=s+c;t[r]=c-(f-s),n[r]=f}function Ln(n,t,r){n>t&&([n,t]=[t,n]);let e=`${n},${t}`,i=ot.get(e);if(i!==void 0&&i.len>r)return ot.delete(e),ot.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=pi(n,t,u);i!==void 0&&(ot.delete(e),Yt-=i.len),ot.set(e,s),Yt+=s.len;for(let[a,c]of ot){if(Yt<=di||a===e)break;ot.delete(a),Yt-=c.len}return s}function En(n,t){let r=n*2**-(Tt/2)*2**-(Tt/2);return t?r>=1e-300?Math.log(r):Math.log(n)-Tt*Math.LN2:r}function _n(n,t){if(!(!Number.isFinite(n)||!Number.isFinite(t)))return n=D(n),t=D(t),n<=0||t<=0?void 0:[n,t]}function gi(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let i=_n(t,r);if(i===void 0)return NaN;if([t,r]=i,G(n))return x(e);n=D(n);let o=t*r;if(n<0||n>o)return x(e);let u=Math.min(n,o-n);return En(Ln(t,r,u).prob[u],e)}function Tr(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 En(Ln(t,r,u).cum[u],i);let a=En(Ln(t,r,s).cum[s],!1);return i?Math.log1p(-a):1-a}function bi(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=_n(t,r);if(o===void 0)return NaN;[t,r]=o;let u=Math.floor(n+1e-7);return u<0?v(e,i):u>=t*r?y(e,i):Tr(u,t,r,e,i)}function Ii(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=_n(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 a=u/2,c=Math.sqrt(u*(t+r+1)/12),f=a+c*S(n,{lowerTail:e,logP:i});return K({p:n,lowerTail:e,logP:i,cdf:(l,N,h)=>l<0?v(N,h):l>=u?y(N,h):Tr(l,t,r,N,h),y0:Number.isFinite(f)?f:a,lo:0,hi:u})}function ps(n,t,r,e={}){let i=e.log??!1;return g(n,o=>gi(o,t,r,i))}function gs(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return g(n,u=>bi(u,t,r,i,o))}function bs(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return g(n,u=>Ii(u,t,r,i,o))}var tt=128,On=Number.EPSILON,Wn=Float64Array.from({length:2*tt+1},(n,t)=>Math.cos(Math.PI*t/tt));function yi(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)*Wn[i*r%(2*n)*(tt/n)]*2/(1-i*i);t[r]=(r===0||r===n?.5:1)*2*e/n}return t}var vi=new Map([16,32,64,128].map(n=>[n,yi(n)]));function xi(n,t){let r=vi.get(t),e=tt/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 a=.5*(n[0]+(s%2===0?n[t]:-n[t]));for(let c=1;c<t;c++)a+=n[c]*Wn[s*c%(2*t)*e];a*=2/t,s===t&&(a*=.5),u=Math.max(u,Math.abs(a))}return{integral:i,tail:u,scale:o}}var At=class{f;a;b;c;h;values=new Float64Array(tt+1);have=new Uint8Array(tt+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=tt/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*Wn[u]),this.have[u]=1),e[o]=this.values[u]}let i=xi(e,t);this.N=t,this.integral=i.integral*this.h,this.error=Math.max(i.tail*4/t,4*On*i.scale)*Math.abs(this.h)}};function Jt(n,t,r){let e=[];for(let o=0;o+1<t.length;o++){let u=new At(n,t[o],t[o+1]);u.advance(16),e.push(u)}for(let o=0;o<40;o++){let u=0;for(let f of e)u+=f.integral;let s=r*Math.abs(u)/e.length,a=!0,c=[];for(let f of e){if(f.error<=s||f.error<=4*On*Math.abs(f.integral)){c.push(f);continue}if(a=!1,f.N<tt)f.advance(2*f.N),c.push(f);else{let l=new At(n,f.a,f.c),N=new At(n,f.c,f.b);l.advance(16),N.advance(16),c.push(l,N)}}if(e=c,a)break}let i=0;for(let o of e)i+=o.integral;return i}function Jr(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 kr=2e-15,te=1e-16,Fi={lowerTail:!1},Li={logP:!0},Ei={lowerTail:!1,logP:!0},Dt=.9189385332046728,kt=n=>pt(n),ht=n=>pt(n,Fi),Un=n=>pt(n,Li),jn=n=>pt(n,Ei),_i=.3989422804014327;function mt(n){let t=Math.round(n*16)/16,r=n-t;return _i*Math.exp(-.5*t*t)*Math.exp(-.5*r*(n+t))}var Dn=[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],ne=[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626];function Ai(n,t){let r=n-.5*t,e=.5*t,i=0;for(let o=0;o<4;o++)i+=ne[o]*(mt(r-e*Dn[o])+mt(r+e*Dn[o]));return i*e}function wi(n,t){let r=n-.5*t,e=.5*t,i=0;for(let o=0;o<4;o++){let u=e*Dn[o];i+=ne[o]*(Math.exp(r*u-u*u/2)+Math.exp(-r*u-u*u/2))}return-Dt-r*r/2+Math.log(i*e)}var Gn=(n,t)=>t*Math.max(1,Math.abs(n),Math.abs(n-t))<.5;function Mt(n,t){let r=n-t,e=r-n,i=n-(r-e)+(-t-e);return{ah:r,al:i}}function wt(n,t){return kt(n)+mt(n)*t}function Di(n,t){return ht(n)-mt(n)*t}function re(n,t){if(Gn(n,t))return Ai(n,t);let{ah:r,al:e}=Mt(n,t);return r>=0?Di(r,e)-ht(n):n<=0?kt(n)-wt(r,e):1-wt(r,e)-ht(n)}function Ri(n,t,r){if(n>0&&n-t<0&&!Gn(n,t)){let{ah:i,al:o}=Mt(n,t);return Math.exp(r*Math.log1p(-(wt(i,o)+ht(n))))}let e=re(n,t);return e>0?e**r:0}function Ci(n,t){return n>0?Math.exp(t*Math.log1p(-ht(n))):kt(n)**t}function ee(n,t){let{ah:r,al:e}=Mt(n,t),i=Un(r);return i+e*Math.exp(-Dt-r*r/2-i)}function Si(n,t){let{ah:r,al:e}=Mt(n,t),i=jn(r);return i-e*Math.exp(-Dt-r*r/2-i)}function ie(n,t){if(Gn(n,t))return wi(n,t);if(n-t>=0){let o=Si(n,t);return o+Math.log(-Math.expm1(jn(n)-o))}if(n<=0){let o=Un(n);return o+Math.log(-Math.expm1(ee(n,t)-o))}let{ah:e,al:i}=Mt(n,t);return Math.log1p(-wt(e,i)-ht(n))}var oe=2,An=1e-18;function ue(n,t,r){let e=Jr(t,r,oe),i=e.map(n),o=0;for(let N=1;N<i.length;N++)i[N]>i[o]&&(o=N);let u=i[o];if(!(u>0))return 0;let s=Math.max(o-1,0),a=Math.min(o+1,i.length-1);for(;s>0&&i[s]>u*An;)s--;for(;a<i.length-1&&i[a]>u*An;)a++;let c=u*An,f=e[s],l=e[a];if(i[s]<=c){let N=e[s+1];for(let h=0;h<2;h++){let m=.5*(f+N);n(m)<=c?f=m:N=m}}if(i[a]<=c){let N=e[a-1];for(let h=0;h<2;h++){let m=.5*(l+N);n(m)<=c?l=m:N=m}}return Jt(n,[f,l],te)}function se(n,t,r){let e=Jr(t,r,oe),i=e.map(n),o=0;for(let b=1;b<i.length;b++)i[b]>i[o]&&(o=b);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)],a=(Math.sqrt(5)-1)/2,c=s-a*(s-u),f=u+a*(s-u),l=n(c),N=n(f);for(let b=0;b<80&&s-u>1e-12*Math.max(1,Math.abs(u));b++)l<N?(u=c,c=f,l=N,f=u+a*(s-u),N=n(f)):(s=f,f=c,N=l,c=s-a*(s-u),l=n(c));let h=l>N?c:f,m=Math.max(l,N);i[o]>m&&(h=e[o],m=i[o]);let M=b=>{let E=b<0?t:r,V=Math.max(1e-6,.001*(e[1]-e[0])),B=h;for(;;){let A=h+b*V;if(b<0?A<=E:A>=E)return E;if(n(A)<m-46){let X=A;for(let O=0;O<6;O++){let st=.5*(B+X);n(st)<m-46?X=st:B=st}return X}B=A,V*=2}},p=M(-1),d=M(1),I=[...new Set([p,h,d])].sort((b,E)=>b-E);return m+Math.log(Jt(b=>Math.exp(n(b)-m),I,te))}var Hn=-10,Qn=10;function qi(n,t){return n<=0?0:t*ue(r=>mt(r)*Ri(r,n,t-1),Hn,Qn)}function fe(n,t){if(n<=0)return 1;let r=o=>{let u=kt(o);if(u===0)return 0;let{ah:s,al:a}=Mt(o,n),c=wt(s,a),f=c<.5*u?-Math.expm1((t-1)*Math.log1p(-c/u)):-Math.expm1((t-1)*Math.log(re(o,n)/u));return mt(o)*Ci(o,t-1)*f};if(n>60)return 0;let[e,i]=ae(n);return t*ue(r,e,i)}function ae(n){return n>40?[n/2-15,n/2+15]:[Hn,n+Qn]}function ce(n,t){if(n>100)return-Math.exp(le(n,t));let r=e=>-Dt-e*e/2+(t-1)*ie(e,n);return Math.log(t)+se(r,Hn,Qn)}function le(n,t){if(n>100)return Math.log(t*(t-1))+jn(n/Math.SQRT2);let r=o=>{let u=Un(o),s=ee(o,n)-u,a;return s<-40?a=Math.log(t-1)+s:s<-Math.LN2?a=Math.log(-Math.expm1((t-1)*Math.log1p(-Math.exp(s)))):a=Math.log(-Math.expm1((t-1)*(ie(o,n)-u))),-Dt-o*o/2+(t-1)*u+a},[e,i]=ae(n);return Math.log(t)+se(r,e,i)}function Bi(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=Jt(u=>{let s=n(u);return s>i&&(i=s),Math.exp(s-r)},t,kr);if(Number.isFinite(o)&&i-r<300)return r+Math.log(o);r=i}return NaN}var k=32,Oi=1e-15,Nt=Math.log(.01),Kn=Math.log(20),Ne=Math.log(40),he=Float64Array.from({length:2*k+1},(n,t)=>Math.cos(Math.PI*t/k));function Wi(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]*he[e*o%(2*t)];i*=2/t,(e===0||e===t)&&(i*=.5),r[e]=i}return r}function wn(n,t,r){let e=[],i=[[t,r,0]];for(;i.length>0;){let[o,u,s]=i.pop(),a=.5*(o+u),c=.5*(u-o),f=new Float64Array(k+1),l=1/0;for(let m=0;m<=k;m++)f[m]=n(a+c*he[m]),l=Math.min(l,Math.max(1,Math.abs(f[m])));let N=Wi(f,k),h=0;for(let m=k-3;m<=k;m++)h=Math.max(h,Math.abs(N[m]));h<=Oi*l||s>=14||!f.every(Number.isFinite)?e.push({a:o,b:u,coef:N}):i.push([a,u,s+1],[o,a,s+1])}return e.sort((o,u)=>o.a-u.a)}function Rn(n,t){let r=0,e=n.length-1;for(;r<e;){let f=r+e+1>>1;n[f].a<=t?r=f:e=f-1}let{a:i,b:o,coef:u}=n[r],s=(2*t-i-o)/(o-i),a=0,c=0;for(let f=k;f>=1;f--){let l=2*s*a-c+u[f];c=a,a=l}return s*a-c+u[0]}var _t=new Map,Ui=64,me=Math.log(1e-10);function Me(n){let t=_t.get(n);if(t!==void 0)return t;let r=i=>{let o=qi(i,n);return o>1e-290?Math.log(o):ce(i,n)},e=i=>{let o=Math.exp(i);return fe(o,n)*de(o)};return t={logW:wn(i=>r(Math.exp(i)),Nt,Kn),scaledWc:wn(e,Nt,Ne),smallW:wn(i=>r(Math.exp(i))-(n-1)*i,me,Nt)},_t.size>=Ui&&_t.delete(_t.keys().next().value),_t.set(n,t),t}function de(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 ji(n,t){let r=Math.log(n);if(r>=Kn)return 0;let e=Me(t);return r>=Nt?Rn(e.logW,r):Rn(e.smallW,Math.max(r,me))+(t-1)*r}function Cn(n,t){return Math.log(n)>=Kn?1:Math.exp(ji(n,t))}function Gi(n,t){let r=Math.log(n);return r>=Nt&&r<=Ne?Rn(Me(t).scaledWc,r)/de(n):r<Nt?1-Cn(n,t):fe(n,t)}function zt(n,t,r,e){if(!e){let o=Math.min(Cn(n,t),1);return r===1?o:o**r}let i=Math.min(Gi(n,t),1);return i<=.5?r===1?i:-Math.expm1(r*Math.log1p(-i)):1-Math.min(Cn(n,t),1)**r}function Sn(n,t,r,e){if(!e)return r*ce(n,t);let i=le(n,t);return r===1?i:Math.log(-Math.expm1(r*Math.log1p(-Math.exp(i))))}function qn(n,t,r,e,i){if(r===1/0)return zt(n,t,e,i);let o=r/2,u=Math.log(o),s=Hi(o);return Jt(c=>{let{d:f,s:l}=s(c);return f===0?0:f*zt(n*l,t,e,i)},pe(n,t,r,e,i).map(c=>c-u),kr)}function Hi(n){let t=Ct(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 Qi(n,t,r,e,i){if(r===1/0)return Sn(n,t,e,i);let o=r/2,u=Math.log(o),s=P(o+1);return Bi(c=>{let f=Math.exp(c),l=f>1e-300?C(o,f,!0):o*c-f-s;return u+l+Sn(Math.exp(Math.log(n)+.5*(c-u)),t,e,i)},pe(n,t,r,e,i,!0))}function pe(n,t,r,e,i,o=!1){let u=r/2,s=u,a=Math.log(u);if(i){let b=2*Math.log(n)-Math.log(4*u);a-=b>30?b:Math.log1p(Math.exp(b))}else s=u+(t-1)*e/2,a=Math.log(s);let c=(b,E)=>[b-9/Math.sqrt(E)-41/E,b+9/Math.sqrt(E)+Math.log1p(41/E)],[f,l]=c(Math.log(u),u),[N,h]=c(a,s),m=o?Math.min(f,N):Math.max(Math.min(f,N),-740),M=Math.max(l,h),p=1/Math.sqrt(u),d=1/Math.sqrt(s),I=[m,Math.min(Math.log(u)-4*p,a-4*d),Math.max(Math.log(u)+4*p,a+4*d),M];return[...new Set(I.map(b=>Math.min(Math.max(b,m),M)))].sort((b,E)=>b-E)}function ge(n,t,r){return n>=2&&t>=2&&r>=1&&Number.isFinite(n)&&Number.isFinite(r)&&!Number.isNaN(t)}function Bn(n,t,r,e,i,o){let u;return ut!==void 0&&ut.q===n&&ut.k===t&&ut.df===r&&ut.r===e?u=ut.tail:(u=Ki(n,t,r,e,!i),ut={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 ut;function Ki(n,t,r,e,i){let o=i;r!==1/0&&zt(n,t,e,o)>.5&&(o=!o);let u=qn(n,t,r,e,o);if(u>.5){let s=qn(n,t,r,e,!o);s<u&&(u=s,o=!o)}if(u<1e-290){let s=Qi(n,t,r,e,o);return{upper:o,value:Math.exp(s),log:s}}return{upper:o,value:u,log:Math.log(u)}}function Vi(n,t,r,e,i,o){return[n,t,r,e].some(Number.isNaN)?NaN:ge(t,r,e)?n<=0?v(i,o):n===1/0?y(i,o):Bn(n,t,r,e,i,o):NaN}function Xi(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;if(!ge(t,r,e))return NaN;let u=L(n,0,1/0,i,o);if(u!==void 0)return u;let{lower:s,logTarget:a,linearTarget:c}=q(n,i,o),f=N=>h=>{let m=Math.exp(h);if(c!==void 0&&c>1e-290){let p=N===1/0?qn(m,t,N,e,!s):Bn(m,t,N,e,s,!1);if(p>0)return Math.log(p/c)}return(N===1/0?$i(m,t,e,s):Bn(m,t,N,e,s,!0))-a},l=zr(f(1/0),Math.log(3),s);return Math.exp(r===1/0?l:zr(f(r),l,s))}function $i(n,t,r,e){let i=zt(n,t,r,!e);return i>1e-290?Math.log(i):Sn(n,t,r,!e)}function zr(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,a=n(s);for(let c=0;c<200&&Math.sign(a)===Math.sign(i)&&a!==0;c++)e=s,i=a,u*=2,s=e+o*u,a=n(s);return a===0?s:!Number.isFinite(a)||Math.sign(a)===Math.sign(i)?Number.isFinite(a)?s:e:Zi(n,e,s,i,a)}function Zi(n,t,r,e,i){let o=t,u=e,s=r-t,a=s;for(let c=0;c<100;c++){Math.sign(i)===Math.sign(u)&&(o=t,u=e,s=r-t,a=s),Math.abs(u)<Math.abs(i)&&(t=r,r=o,o=t,e=i,i=u,u=e);let f=2*On*Math.abs(r)+1e-300,l=.5*(o-r);if(Math.abs(l)<=f||i===0)return r;if(Math.abs(a)>=f&&Math.abs(e)>Math.abs(i)){let N=i/e,h,m;if(t===o)h=2*l*N,m=1-N;else{let M=e/u,p=i/u;h=N*(2*l*M*(M-p)-(r-t)*(p-1)),m=(M-1)*(p-1)*(N-1)}h>0?m=-m:h=-h,2*h<Math.min(3*l*m-Math.abs(f*m),Math.abs(a*m))?(a=s,s=h/m):(s=l,a=l)}else s=l,a=l;t=r,e=i,r+=Math.abs(s)>f?s:l>0?f:-f,i=n(r)}return r}function Es(n,t,r,e={}){let{nranges:i=1,lowerTail:o=!0,logP:u=!1}=e;return g(n,s=>Vi(s,t,r,i,o,u))}function _s(n,t,r,e={}){let{nranges:i=1,lowerTail:o=!0,logP:u=!1}=e;return g(n,s=>Xi(s,t,r,i,o,u))}function Ds(n,t={}){return be(n,t).map(r=>r-1)}function be(n,t){if(!Number.isFinite(n)||n<0||n>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");n=Math.trunc(n);let{replace:r=!1,prob:e}=t,i=t.size!==void 0,o=i?t.size:n;if(!Number.isFinite(o)||o<0)throw new RangeError("size must be a non-negative number");let u=Math.trunc(o);if(e!==void 0){if(n>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(e.length!==n)throw new TypeError("prob must have length n");let f=Pi(e,u,r);if(r){let l=0;for(let N=0;N<n;N++)n*f[N]>.1&&l++;return l>200?Ji(f,u):Ti(f,u)}if(u>n)throw new RangeError("cannot take a sample larger than the population when replace is false");return zi(f,u)}if(!r&&u>n)throw new RangeError("cannot take a sample larger than the population when replace is false");if(!r&&n>1e7&&i&&u<=n/2){let f=new Set,l=[];for(;l.length<u;){let N=bt(n);f.has(N)||(f.add(N),l.push(N+1))}return l}let s=new Array(u);if(r||u<2){for(let f=0;f<u;f++)s[f]=bt(n)+1;return s}if(n>=2**31)throw new RangeError("n must be less than 2^31 to sample without replacement with size above n / 2");let a=new Int32Array(n);for(let f=0;f<n;f++)a[f]=f;let c=n;for(let f=0;f<u;f++){let l=bt(c);s[f]=a[l]+1,a[l]=a[--c]}return s}function Rs(n,t={}){return be(n.length,t).map(r=>n[r-1])}function Pi(n,t,r){let e=0,i=0;for(let o of n){if(!Number.isFinite(o))throw new RangeError("prob contains NaN or infinite values");if(o<0)throw new RangeError("prob contains negative values");o>0&&(i++,e+=o)}if(i===0||!r&&t>i)throw new RangeError("too few positive probabilities");return Float64Array.from(n,o=>o/e)}function Yi(n,t){let r=n.length;if(r<=1)return;let e=a=>n[a-1],i=(r>>1)+1,o=r,u,s;for(;;){if(i>1)i=i-1,u=e(i),s=t[i-1];else if(u=e(o),s=t[o-1],n[o-1]=e(1),t[o-1]=t[0],--o===1){n[0]=u,t[0]=s;return}let a=i,c=i<<1;for(;c<=o;)c<o&&e(c)>e(c+1)&&++c,u>e(c)?(n[a-1]=e(c),t[a-1]=t[c-1],a=c,c+=c):c=o+1;n[a-1]=u,t[a-1]=s}}function Ie(n){let t=new Int32Array(n.length);for(let r=0;r<n.length;r++)t[r]=r+1;return Yi(n,t),t}function Ti(n,t){let r=Float64Array.from(n),e=r.length,i=Ie(r);for(let u=1;u<e;u++)r[u]+=r[u-1];let o=new Array(t);for(let u=0;u<t;u++){let s=z(),a=0;for(;a<e-1&&!(s<=r[a]);a++);o[u]=i[a]}return o}function zi(n,t){let r=Float64Array.from(n),e=r.length,i=Ie(r),o=new Array(t),u=1;for(let s=0,a=e-1;s<t;s++,a--){let c=u*z(),f=0,l=0;for(;l<a&&(f+=r[l],!(c<=f));l++);o[s]=i[l],u-=r[l];for(let N=l;N<a;N++)r[N]=r[N+1],i[N]=i[N+1]}return o}function Ji(n,t){let r=n.length,e=new Float64Array(r),i=new Int32Array(r),o=new Int32Array(r),u=-1,s=r;for(let f=0;f<r;f++)e[f]=n[f]*r,e[f]<1?o[++u]=f:o[--s]=f;if(u>=0&&s<r)for(let f=0;f<r-1;f++){let l=o[f],N=o[s];if(i[l]=N,e[N]+=e[l]-1,e[N]<1&&s++,s>=r)break}let a=Jn(),c=new Array(t);for(let f=0;f<t;f++){let l,N;a?(N=z()*r,l=Math.trunc(N)):(l=bt(r),N=l+z()),c[f]=N<e[l]+l?l+1:i[l]+1}return c}function ki(n){let t=new Float64Array(n+1);for(let r=2;r<=n;r++)t[r]=t[r-1]+Math.log(r);return t}function to(n,t,r,e){let i=n.length,o=t.length,u=Array.from(t),s=0;for(let c of n)s+=c;for(let c=0;c<i-1;c++){let f=n[c],l=s;s-=f;let N=0;for(;N<o-1;N++){let h=u[N],m=l;l-=h;let M=m-f,p=M-h;if(m===0){for(let b=N;b<o-1;b++)e[c+b*i]=0;f=0;break}let d=z(),I;t:for(;;){I=Math.floor(f*(h/m)+.5);let b=Math.exp(r[f]+r[M]+r[l]+r[h]-r[m]-r[I]-r[h-I]-r[f-I]-r[p+I]);if(b>=d)break;if(b===0)throw new Error(`r2dtable: probability underflow at cell [${c}, ${N}]`);let E=b,V=b,B=I,A=!1,X=!1;for(;!(A&&X);){if(!A){let O=(h-I)*(f-I);if(O===0)A=!0;else if(I++,b=b*O/(I*(p+I)),E+=b,E>=d)break t}do{let O=B*(p+B);if(O===0){X=!0;break}if(B--,V=V*O/((h-B)*(f-B)),E+=V,E>=d){I=B;break t}}while(A)}d=E*z()}e[c+N*i]=I,f-=I,u[N]=u[N]-I}e[c+(o-1)*i]=f}let a=t[o-1];for(let c=0;c<i-1;c++)a-=e[c+(o-1)*i];for(let c=0;c<o-1;c++)e[i-1+c*i]=u[c];e[i-1+(o-1)*i]=a}function ye(n,t){let r=Array.from(n,e=>Math.trunc(e));if(r.length<=1||r.some(e=>!(e>=0)||e>2147483647))throw new RangeError(`invalid argument '${t}'`);return r}function qs(n,t,r){let e=Math.trunc(n);if(!(e>=0))throw new RangeError("invalid argument 'n'");let i=ye(t,"r"),o=ye(r,"c"),u=i.reduce((f,l)=>f+l,0);if(u!==o.reduce((f,l)=>f+l,0))throw new RangeError("arguments 'r' and 'c' must have the same sums");let s=ki(u),a=new Int32Array(i.length*o.length),c=[];for(let f=0;f<e;f++)to(i,o,s,a),c.push(i.map((l,N)=>o.map((h,m)=>a[N+m*i.length])));return c}export{on as a,ct as b,Ot as c,nt as d,ho as e,mo as f,Mo as g,Fr as h,Lr as i,Er as j,K as k,Wt as l,Ae as m,we as n,De as o,Eo as p,_o as q,Ao as r,mn as s,Vt as t,Fu as u,Lu as v,Eu as w,ln as x,Qt as y,Ko as z,Vo as A,Xo as B,Ye as C,Te as D,Ou as E,Wu as F,Uu as G,ke as H,ti as I,ei as J,Qu as K,Ku as L,Vu as M,ii as N,ui as O,si as P,ku as Q,ts as R,ns as S,hi as T,mi as U,fs as V,as as W,cs as X,bi as Y,Ii as Z,ps as _,gs as $,bs as aa,Es as ba,_s as ca,Ds as da,Rs as ea,ki as fa,to as ga,qs as ha};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
2
|
-
import{a as h,b as c,c as b}from"./chunk-
|
|
1
|
+
/*! rStats.js 0.9.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as h,b as c,c as b}from"./chunk-LE7TBHNI.js";import{D as L,E as C,k as v,l as j,n as M,o as x}from"./chunk-FC2TLHZC.js";import{b as l,d as g,g as y,i as F,k as d}from"./chunk-H2AP6TCR.js";var I=30;function m(t){return t===Math.floor(t)}function D(t,r){if(m(t))return t;if(t>=0)return h(t)?t:c(t);let n=r-1-t;return h(n)?t:r-1-c(n)||-0}function S(t,r){let n=[1,0];for(let i=0;i<r;i++)n=F(y(n,l(t,-i)),[i+1,0]);return n}function p(t,r){return Math.min(t,r)>=1&&Math.max(t,r)<2**52?C(t,r):[L(t,r),0]}function A(t,r){if(t<0){let a=g(d(l(r,-t)),p(-t,r+1));return{log:[-a[0],-a[1]],sign:r%2===0?1:-1}}if(m(t)&&t<r)return;if(t>=r-1){let a=g(d(l(t,1)),p(t-r+1,r+1));return{log:[-a[0],-a[1]],sign:1}}let n=v(t),[i,e]=l(t,1),[o,f]=l(r,-t),s=e===0&&f===0?0:b(i+o),u=(e===0?0:e*(b(i)-s))+(f===0?0:f*(b(o)-s));return{log:g(p(i,o),[Math.log(Math.abs(n)/Math.PI)+u,0]),sign:(r%2===0?-1:1)*Math.sign(n)}}function O(t,r,n){if(Number.isNaN(t)||Number.isNaN(r))return NaN;let i=n?.rCompatible??!0;if(r=c(r),r<0)return 0;if(r===0)return 1;if(!Number.isFinite(r))return i&&t>=0&&t<1/0?0:NaN;if(!Number.isFinite(t))return i&&r>=I?NaN:t>0||r%2===0?1/0:-1/0;if(r<I){let f=i&&!m(t)&&!h(t);if(f&&t>=0&&c(t)<r)return 0;let s=S(t,r),u=s[0]+s[1];if(Number.isFinite(u))return m(t)||f?Math.round(u):u;let N=1;for(let a=0;a<r;a++)N=N*(t-a)/(a+1);return N}if(i&&(t=D(t,r),Object.is(t,-0)))return r%2===0?0:-0;let e=A(t,r);if(e===void 0)return 0;let o=e.sign*Math.exp(e.log[0])*(1+e.log[1]);return m(t)&&Number.isFinite(o)?Math.round(o):o}function P(t,r,n){if(Number.isNaN(t)||Number.isNaN(r))return NaN;let i=n?.rCompatible??!0;if(r=c(r),r<0)return-1/0;if(r===0)return 0;if(!Number.isFinite(r))return i&&t>=0&&t<1/0?-1/0:NaN;if(!Number.isFinite(t))return i&&r>=2?NaN:1/0;if(i&&r>=2&&(t=D(t,r)),r<I){let o=S(t,r),f=Math.abs(o[0]+o[1]);if(f>1e-300&&f<1e300){let u=d(o[0]<0?[-o[0],-o[1]]:o);return u[0]+u[1]}if(f===0)return-1/0;let s=-M(r+1);for(let u=0;u<r;u++)s+=Math.log(Math.abs(t-u));return s}let e=A(t,r);return e===void 0?-1/0:m(t)&&e.log[0]<36?Math.log(Math.round(Math.exp(e.log[0])*(1+e.log[1]))):e.log[0]+e.log[1]}function R(t){return j(t+1)}function _(t){return Math.abs(t)<=.2?x(t):M(t+1)}export{O as a,P as b,R as c,_ as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
2
|
-
import{d as f,f as a,g,j as l}from"./chunk-
|
|
1
|
+
/*! rStats.js 0.9.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{d as f,f as a,g,j as l}from"./chunk-H2AP6TCR.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};
|