@numero-uno-jpn/rstats 1.0.0 → 1.2.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 +101 -0
- package/README.ja.md +12 -11
- package/README.md +12 -11
- package/THIRD_PARTY_NOTICES.md +3 -2
- package/dist/chunks/{chunk-UJ66VQIG.js → chunk-2NNBUYHJ.js} +2 -2
- package/dist/chunks/{chunk-YHNMBYSW.js → chunk-47IIPUFN.js} +2 -2
- package/dist/chunks/{chunk-WIBKS73G.js → chunk-4AOTAT3O.js} +2 -2
- package/dist/chunks/{chunk-4F2IALD4.js → chunk-5SGTWSCB.js} +3 -3
- package/dist/chunks/{chunk-F7YGX7PN.js → chunk-6FZHTD5G.js} +2 -2
- package/dist/chunks/{chunk-NSWENS3S.js → chunk-73LNRWU3.js} +1 -1
- package/dist/chunks/{chunk-BQSIBJVX.js → chunk-7INBXTVV.js} +2 -2
- package/dist/chunks/chunk-7WG7X2UI.js +2 -0
- package/dist/chunks/{chunk-H7I32ZZE.js → chunk-A66M3ZEA.js} +2 -2
- package/dist/chunks/{chunk-BWKHYRM6.js → chunk-BI7NYJWP.js} +1 -1
- package/dist/chunks/{chunk-QZK3CCBA.js → chunk-BKV3FINA.js} +2 -2
- package/dist/chunks/{chunk-QQX46TCI.js → chunk-CQB4BJBR.js} +2 -2
- package/dist/chunks/{chunk-3W5NFFAA.js → chunk-EEU7D4RU.js} +1 -1
- package/dist/chunks/{chunk-DCAWMF4K.js → chunk-F3EQLL4F.js} +2 -2
- package/dist/chunks/{chunk-IEOD5GWC.js → chunk-HBHMEPGY.js} +2 -2
- package/dist/chunks/{chunk-4OLDGML4.js → chunk-IAWXF73N.js} +2 -2
- package/dist/chunks/{chunk-CKV4JWW2.js → chunk-IMPRIQE5.js} +1 -1
- package/dist/chunks/chunk-JWBSEL3V.js +2 -0
- package/dist/chunks/{chunk-LROMWFAK.js → chunk-L23RSC2N.js} +2 -2
- package/dist/chunks/{chunk-UKNDX4BA.js → chunk-NSU6U3ET.js} +2 -2
- package/dist/chunks/{chunk-WQWZ7FND.js → chunk-ORE5ZRCY.js} +2 -2
- package/dist/chunks/{chunk-YG5S5AVP.js → chunk-RRO4LMCB.js} +2 -2
- package/dist/chunks/{chunk-6XJBCRBV.js → chunk-T5DRIITM.js} +2 -2
- package/dist/chunks/{chunk-63OPBEYO.js → chunk-TNETWBF5.js} +1 -1
- package/dist/chunks/{chunk-O2SQMGE3.js → chunk-VERBXW6E.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions/signrank.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/tests.d.ts +6 -1
- package/dist/entries/tests.js +5 -0
- package/dist/htest/ansariTest.js +32 -34
- package/dist/htest/binomCI.d.ts +116 -0
- package/dist/htest/binomCI.js +252 -0
- package/dist/htest/boschlooTest.d.ts +65 -0
- package/dist/htest/boschlooTest.js +394 -0
- package/dist/htest/chisqTest.d.ts +19 -0
- package/dist/htest/chisqTest.js +30 -2
- package/dist/htest/cor.d.ts +2 -2
- package/dist/htest/cor.js +2 -1
- package/dist/htest/core/scoreDistribution.d.ts +39 -0
- package/dist/htest/core/scoreDistribution.js +151 -0
- package/dist/htest/core/twoProportions.d.ts +48 -0
- package/dist/htest/core/twoProportions.js +476 -0
- package/dist/htest/equivalence.d.ts +172 -0
- package/dist/htest/equivalence.js +189 -0
- package/dist/htest/fisherTest.d.ts +49 -0
- package/dist/htest/fisherTest.js +136 -13
- package/dist/htest/tableTests.d.ts +216 -0
- package/dist/htest/tableTests.js +650 -0
- package/dist/htest/twoByTwo.d.ts +203 -0
- package/dist/htest/twoByTwo.js +385 -0
- package/dist/htest/wilcoxTest.d.ts +23 -8
- package/dist/htest/wilcoxTest.js +521 -199
- package/dist/linalg/chol.d.ts +3 -3
- package/dist/linalg/chol.js +10 -2
- package/dist/linalg/qr.js +39 -15
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/anovaSequential.d.ts +16 -1
- package/dist/models/anovaSequential.js +40 -5
- package/dist/models/aovStrata.js +21 -4
- package/dist/models/glm.d.ts +15 -4
- package/dist/models/glm.js +13 -6
- package/dist/models/survival.d.ts +4 -1
- package/dist/models/survival.js +7 -1
- package/dist/numerics.js +2 -2
- package/dist/rstats.js +16 -16
- package/dist/special/igam.js +140 -23
- package/dist/special/loader.js +8 -0
- package/dist/special.js +2 -2
- package/dist/tests.js +13 -13
- package/llms.txt +9 -1
- package/package.json +1 -1
- package/dist/chunks/chunk-KICBQGFN.js +0 -2
- package/dist/chunks/chunk-WWVMVZUL.js +0 -2
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
|
+
## 1.2.0 - 2026-11-07
|
|
11
|
+
|
|
12
|
+
Contingency tables and proportions (item 1 of the roadmap): intervals for a proportion and for the risk difference,
|
|
13
|
+
risk ratio and odds ratio of a 2 × 2 table, the mid-p version of Fisher's exact test, Boschloo's test, the G-test,
|
|
14
|
+
the Stuart-Maxwell test, Goodman and Kruskal's gamma, the linear-by-linear association test, the 'N − 1' chi-squared
|
|
15
|
+
test, Freeman-Tukey residuals and equivalence tests, checked against DescTools, epitools, epiR, exact2x2, Exact, coin
|
|
16
|
+
and equivalence (R 4.6.2); where these packages' root searches or maxima are inexact, the true values. `pgamma` (and
|
|
17
|
+
`pchisq`, `ppois`, ...) is more accurate for small shapes and near x = a.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- **Proportions and odds ratios** (one case per call): `binomCI(x, n, { method, confLevel, sides })`, DescTools'
|
|
22
|
+
`BinomCI()`, with the methods `wilson` (default), `wald`, `wilsoncc`, `agresti-coull`, `jeffreys`,
|
|
23
|
+
`clopper-pearson` and `midp`; `binomDiffCI(x1, n1, x2, n2, ...)`, DescTools' `BinomDiffCI()`, with `ac` (default),
|
|
24
|
+
`wald`, `score` (Newcombe's hybrid), `mn` (Miettinen-Nurminen) and `mee` (Farrington-Manning); `binomRatioCI(x1, n1,
|
|
25
|
+
x2, n2, ...)`, DescTools' `BinomRatioCI()`, with `katz.log` (default) and `koopman`; `oddsRatio(table, { method,
|
|
26
|
+
confLevel })`, epitools' `oddsratio()`, with `midp` (default: the median-unbiased estimate and the mid-p exact
|
|
27
|
+
interval), `fisher`, `wald` and `score` (epiR's score interval), and epitools' three p-values. The mid-p and score
|
|
28
|
+
limits are the roots of their equations to the precision of the doubles (the packages stop their searches at 1e-7
|
|
29
|
+
to 1e-3 and fail for zero cells or odds ratios beyond 1000); `binomRatioCI` applies `sides` to the limits; input
|
|
30
|
+
without a defined result is an error (docs/differences-from-r.md). epiR's `epi.2by2` numbers for one stratum are
|
|
31
|
+
reached through these functions.
|
|
32
|
+
- **Mid-p Fisher's exact test**: `fisherTest(x, { midp: true })`, exact2x2's `fisher.exact(midp = TRUE)`, for 2 × 2
|
|
33
|
+
tables: the mid-p p-value (two-sided: the central test) and the mid-p confidence limits as the roots of the mid-p
|
|
34
|
+
tails (exact2x2's search stops up to 1% from them, at 1/eps for large limits); the estimate stays the conditional
|
|
35
|
+
MLE.
|
|
36
|
+
- **Boschloo's test**: `boschlooTest(table, { alternative, tsmethod })`, Exact's `exact.test(method = "boschloo")`,
|
|
37
|
+
for a 2 × 2 table with the groups in the rows: `"square"` (default) or `"central"` two-sided, `alternative` in
|
|
38
|
+
Exact's orientation. The p-value is the true supremum over the nuisance parameter (Exact's is up to 6e-9 below it,
|
|
39
|
+
and its two-sided square region can contain tables that do not belong to it); 200 against 200 takes under 10 ms.
|
|
40
|
+
Tables with more than 2^24 possible outcomes, or a grid that would take more than about 8 s, are a RangeError.
|
|
41
|
+
- **Tests and measures of r × c tables**: `gTest(x, { correct, p, rescaleP })`, DescTools' `GTest()` (independence
|
|
42
|
+
and goodness of fit; corrections `none`, `williams` and `yates` as DescTools; the p-value is the upper tail, where
|
|
43
|
+
DescTools' is 0 below 1.1e-16, and G is summed without cancellation); `stuartMaxwellTest(table)`, DescTools'
|
|
44
|
+
`StuartMaxwellTest()`, with K - 1 degrees of freedom after removing the categories without off-diagonal counts;
|
|
45
|
+
`goodmanKruskalGamma(table, { confLevel })`, DescTools' `GoodmanKruskalGamma()`, with the asymptotic standard error
|
|
46
|
+
ASE1 and the Wald interval; `lblTest(table, { alternative, rowScores, colScores })`, coin's asymptotic `lbl_test()`,
|
|
47
|
+
with scores 1..k for every factor (coin turns the sign for a two-level factor and refuses 2 × 2 tables).
|
|
48
|
+
- **'N - 1' chi-squared test**: `chisqTest(x, { nMinus1: true })` (Campbell 2007; not in R), Pearson's statistic
|
|
49
|
+
without continuity correction times (N - 1)/N, for 2 × 2 and r × c tables.
|
|
50
|
+
- **Freeman-Tukey deviates**: the results of `chisqTest` and `gTest` have `ftResiduals`, `sqrt(O) + sqrt(O + 1) -
|
|
51
|
+
sqrt(4E + 1)` (Bishop, Fienberg and Holland 1975).
|
|
52
|
+
- **Equivalence tests**: `tost(x, y, { epsilon, paired, varEqual, confLevel, alpha })`, equivalence's `tost()`: two
|
|
53
|
+
one-sided t tests (Welch's, pooled or paired, from `tTest`) with the larger p-value and the 1 - 2 alpha interval;
|
|
54
|
+
`binomDiffEquivalenceTest(x1, n1, x2, n2, { margin, method, alpha })` (not in R): equivalence of two proportions on
|
|
55
|
+
counts with the score statistic at -margin and +margin (Miettinen-Nurminen by default, Farrington-Manning `"mee"`,
|
|
56
|
+
`"wald"`), both one-sided p-values, the larger as the p-value, and the dual 1 - 2 alpha interval of `binomDiffCI`.
|
|
57
|
+
|
|
58
|
+
### Fixed
|
|
59
|
+
|
|
60
|
+
- `pgamma` and `pchisq`: the upper tail for small shapes (a < 4, so df < 8) and 1.1 < x < 64 (in the standardized
|
|
61
|
+
scale) is within a few eps of the true value; it was up to about 120 eps off from the rounding errors of the
|
|
62
|
+
continued fraction, which now runs in double-double there (`pchisq(2.3569217160548437, 1, lowerTail: false)` was
|
|
63
|
+
45 eps off). The values that depend on it can change in the last bits (for example the p-value of
|
|
64
|
+
`propTrendTest([15, 10, 8, 4], [30, 30, 30, 30])` by one ulp, now correctly rounded). Such calls take up to about
|
|
65
|
+
8 µs instead of 1 µs.
|
|
66
|
+
- `pgamma` and the functions built on it (`pchisq`, `ppois`, ...) near x = a (20 < a, within Temme's expansion's
|
|
67
|
+
region): within about 4 eps, from up to about 35 eps (`pgamma(256.71, 199, lowerTail: false)` was 22 eps off);
|
|
68
|
+
and with a tiny shape (below 0.01): within a few eps, from up to about 50 eps (`pgamma(100, 1e-100, lowerTail:
|
|
69
|
+
false)`). Values there can change in the last bits.
|
|
70
|
+
|
|
71
|
+
## 1.1.0 - 2026-11-06
|
|
72
|
+
|
|
73
|
+
The reference is now R 4.6.2 (until 1.0.0, R 4.5.2): every fixture was regenerated with `oracle/Dockerfile.r46`
|
|
74
|
+
(R 4.6.2, the same dated package snapshot, Ubuntu 26.04 with OpenBLAS 0.3.32), and the functions whose results R 4.6
|
|
75
|
+
changed follow it, except where R 4.6.2 is wrong (docs/differences-from-r.md). The fixture of `fisherTest` is still R 4.5.2's
|
|
76
|
+
(`fisher.test` is unchanged in R 4.6; its oracle needs nearly all of the Docker VM's memory).
|
|
77
|
+
|
|
78
|
+
### Changed
|
|
79
|
+
|
|
80
|
+
- `glmRstandard` follows R 4.6: standardized Pearson residuals by default (R 4.6's default type of `rstandard()`), the
|
|
81
|
+
deviance residuals with the new option `type: "deviance"`, divided by sigma sqrt(1 - h).
|
|
82
|
+
- `ansariTest` follows R 4.6: the normal approximation with ties is centred and scaled with the mean and variance of
|
|
83
|
+
the observed scores (p-values, intervals and estimates change; without ties as before), and the warning reads
|
|
84
|
+
"cannot compute exact confidence interval with ties".
|
|
85
|
+
- `moodTest` with ties agrees with R 4.6, which fixed its tie correction of the variance (the values here, the exact
|
|
86
|
+
permutation variance of the averaged scores, are unchanged; the entry in differences-from-r is removed).
|
|
87
|
+
- `corTest` follows R 4.6's text of the Kendall and Spearman warning: "cannot compute exact p-value with ties" (lower
|
|
88
|
+
case).
|
|
89
|
+
- `aovSummary` follows R 4.6's `summary.aov`: the warning "essentially perfect fit for ‘1’: summary may be unreliable"
|
|
90
|
+
where the residual variance is below 1e-30 times mean(f)^2 + var(f) of the fitted values f (also for each stratum of
|
|
91
|
+
a fit with `Error()`).
|
|
92
|
+
- `survfit` follows survival 3.8-12 (with R 4.6): with `confType: "log-log"`, the limits are 1 and 1 (not `NaN`) at the
|
|
93
|
+
times where the estimate is 1.
|
|
94
|
+
- `chol` with `pivot: true` follows R 4.6: when the decomposition stops early (rank deficiency), the trailing submatrix
|
|
95
|
+
of the factor is zeroed, so that `x[pivot, pivot] = t(R) R` holds for positive semi-definite `x`.
|
|
96
|
+
- `qr` with `lapack: true` follows LAPACK 3.12.1 (as R 4.6.2 with OpenBLAS 0.3.32): the reflections are applied in
|
|
97
|
+
3.12.1's order (dlarf1f), which changes the last bits and the choice among columns tied for the pivot.
|
|
98
|
+
- `wilcoxTest` follows R 4.6: with ties or zero differences the exact test (default for n < 50, zeros counted) is the
|
|
99
|
+
conditional test given the mid-ranks, the signed rank test ranking the zeros with the data (Pratt), instead of the
|
|
100
|
+
normal approximation, and the exact-test warnings are gone; exact intervals report the achieved confidence level
|
|
101
|
+
((-Inf, Inf) at level 1 where none is reached); the two-sided exact two-sample p-value takes both tails; `correct`
|
|
102
|
+
also takes 0..3 (Edgeworth terms in the normal p-value); the normal interval of the signed rank test is searched on
|
|
103
|
+
the observations, values equal to `mu` included. Two values differ from R 4.6.2, where it is wrong
|
|
104
|
+
(docs/differences-from-r.md): the one-sample conditional interval's lower end (R's is one Walsh average too high)
|
|
105
|
+
and its level, the level of a conditional interval (one or two samples) with an end at the first or last Walsh
|
|
106
|
+
average or difference (R reports tail 0 there), and two-sided normal p-values below 1/64 from the upper tail itself (R's 2 (1 - F) gives 0 for
|
|
107
|
+
`1:300`). The conditional distribution has time and memory limits (RangeError suggesting `exact: false`).
|
|
108
|
+
- `pairwiseWilcoxTest` follows R 4.6's `wilcox.test` through `wilcoxTest`: exact p-values with ties and zeros, no
|
|
109
|
+
ties warnings, and `correct` 0..3.
|
|
110
|
+
|
|
10
111
|
## 1.0.0 - 2026-11-05
|
|
11
112
|
|
|
12
113
|
The first stable version: from 1.0.0 the public API follows Semantic Versioning (see Versioning in the README), so
|
package/README.ja.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
JavaScript とブラウザで使える、R と互換の統計関数のライブラリです。TypeScript で書いています。
|
|
8
8
|
[ブラウザで試す](https://numero-uno-jpn.github.io/rStats.js/demo/) (すべての関数を、R が出す値と並べて試せます)。
|
|
9
9
|
|
|
10
|
-
- **R と同じ数値を返します。** 関数名・既定値・結果は R に合わせています。すべての関数を R 4.
|
|
10
|
+
- **R と同じ数値を返します。** 関数名・既定値・結果は R に合わせています。すべての関数を R 4.6.2 と
|
|
11
11
|
比べてテストしています (分布関数は相対誤差 1e-14)。R 自身が不正確なところでは、高精度の参照値と
|
|
12
12
|
比べています。
|
|
13
13
|
- **JavaScript らしい呼び出し方です。** 必須の引数は位置で渡し、省略できる引数は camelCase のキーを
|
|
@@ -16,7 +16,7 @@ JavaScript とブラウザで使える、R と互換の統計関数のライブ
|
|
|
16
16
|
- **どこでも動きます。** ESM のみで、依存パッケージはなく、Node 専用の API も使っていません。
|
|
17
17
|
tree-shaking が効きます (`pnorm` だけなら gzip で 1.6 KB)。
|
|
18
18
|
|
|
19
|
-
状態: **1.
|
|
19
|
+
状態: **1.2.0。** R の stats パッケージの数値計算の中心
|
|
20
20
|
(分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
|
|
21
21
|
[ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
|
|
22
22
|
|
|
@@ -205,6 +205,7 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
|
|
|
205
205
|
| 線形モデル | `lm` (formula とデータフレーム、または行列で渡す。`summary` の値も返す), `modelMatrix` (`model.matrix`), `confint`, `predict`。`glm` (行列で渡す形。R の `stats` のすべての族とリンク) と `glmSummary` (`summary.glm`)、`glmResiduals` (4 種類)、`glmHatvalues`、`glmRstandard`、`glmCooksDistance`、`glmPredict` (標準誤差つき)、`glmConfint` (プロファイル尤度、厳密な限界)、`glmAnova` (`anova.glm`) |
|
|
206
206
|
| 混合モデル | `lmer` (lme4: REML と最尤法、相関のある変量効果と相関のない変量効果、交差と入れ子の群。`fixef`、`vcov`、`VarCorr`、`ranef`、`logLik`、`AIC`、`BIC`、`REMLcrit`、`isSingular`)、`lmerSummary`・`lmerContest`・`lmerAnova` (lmerTest: Satterthwaite の t 検定と F 検定、Type I/II/III の分散分析表。当てはめどうしの尤度比検定)、`glmer` (lme4: glm のすべての族、ラプラス近似と適応的 Gauss-Hermite 求積)、`glmerSummary`・`glmerAnova`・`glmerPredict`・`lmerPredict`。`@numero-uno-jpn/rstats/mixed` から import する |
|
|
207
207
|
| ほかの検定 | `leveneTest`、`propTrendTest` (`prop.trend.test`)、`jonckheereTest`、`cochranQTest`、`adTest`、`lillieTest`、`cvmTest`、`sfTest`、`pearsonTest` (car、DescTools、clinfun、nortest) |
|
|
208
|
+
| 分割表と比率 | `binomCI`、`binomDiffCI`、`binomRatioCI` (DescTools の `BinomCI`、`BinomDiffCI`、`BinomRatioCI`)、`oddsRatio` (epitools と epiR のスコア区間)、`fisherTest(x, { midp: true })` (exact2x2)、`boschlooTest` (Exact)、`gTest`、`stuartMaxwellTest`、`goodmanKruskalGamma` (DescTools)、`lblTest` (coin)、`chisqTest(x, { nMinus1: true })` (Campbell の N − 1 検定) と Freeman-Tukey 残差、`tost` (equivalence)、`binomDiffEquivalenceTest` (2 つの比率のスコア法の TOST) |
|
|
208
209
|
| 多重比較 | `dscfAllPairsTest` (Steel-Dwass)、`kwAllPairsDunnTest`、`kwManyOneDunnTest`、`manyOneUTest` (Steel の多対一の順位検定)、`dunnettTest`、`gamesHowellTest`、`tukeyTest` (PMCMRplus)、`dunnTest` (dunn.test)、`glhtDunnett` (multcomp) |
|
|
209
210
|
| 生存時間解析 | `survdiff` (log-rank)、`survfit` (Kaplan-Meier。信頼区間と中央値)、`coxph` (Cox 回帰。Efron と Breslow のタイの扱い、ケースの重み、層、Wald・尤度比・スコア検定) |
|
|
210
211
|
| 一致度と信頼性 | `kappa2`、`kappamFleiss`、`icc` (irr)、`cronbachAlpha`、`partialR` (psych)、`polychor`、`polyserial` (polycor)、`pbvnorm`、`factanal`、`omega` (McDonald の ω。psych) |
|
|
@@ -267,12 +268,12 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
267
268
|
| `pnorm` | 1.6 KB |
|
|
268
269
|
| `setSeed`, `rnorm` | 2.0 KB |
|
|
269
270
|
| `solve` / `svd` / `eigen` | 2.4 / 2.4 / 5.1 KB |
|
|
270
|
-
| `wilcoxTest` / `fisherTest` / `tTest` |
|
|
271
|
-
| `qbeta` / `pt` と `qt` | 43.
|
|
272
|
-
| `glm` と `glmSummary` / `glm` とそのすべての関数 | 35.0 /
|
|
273
|
-
| `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 19.4 /
|
|
274
|
-
| `glmer` (`/mixed` から) / `glmerSummary`・`glmerAnova`・`glmerPredict` も | 47.
|
|
275
|
-
| すべて (`/mixed` を除く) |
|
|
271
|
+
| `wilcoxTest` / `fisherTest` / `tTest` | 18.9 / 27.9 / 31.0 KB |
|
|
272
|
+
| `qbeta` / `pt` と `qt` | 43.9 / 40.4 KB |
|
|
273
|
+
| `glm` と `glmSummary` / `glm` とそのすべての関数 | 35.0 / 51.4 KB |
|
|
274
|
+
| `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 19.4 / 70.0 KB |
|
|
275
|
+
| `glmer` (`/mixed` から) / `glmerSummary`・`glmerAnova`・`glmerPredict` も | 47.2 / 66.1 KB |
|
|
276
|
+
| すべて (`/mixed` を除く) | 263.5 KB |
|
|
276
277
|
|
|
277
278
|
(`npm run size` で測れます。)
|
|
278
279
|
|
|
@@ -282,12 +283,12 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
282
283
|
できません。メインの入口には含めていません)。
|
|
283
284
|
|
|
284
285
|
バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (`/mixed` 以外のすべての関数を含む
|
|
285
|
-
minify 済みの ES モジュール、gzip で
|
|
286
|
+
minify 済みの ES モジュール、gzip で 264 KB) を jsDelivr から読み込めます。jsDelivr は、npm のリリースを
|
|
286
287
|
そのまま配信します。
|
|
287
288
|
|
|
288
289
|
```html
|
|
289
290
|
<script type="module">
|
|
290
|
-
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.
|
|
291
|
+
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.2.0/dist/rstats.js";
|
|
291
292
|
console.log(pnorm(1.96)); // ≈ 0.9750021049
|
|
292
293
|
</script>
|
|
293
294
|
```
|
|
@@ -303,7 +304,7 @@ minify 済みの ES モジュール、gzip で 249 KB) を jsDelivr から読み
|
|
|
303
304
|
`dist/tests.js`、`dist/linalg.js`、`dist/descriptive.js`、`dist/numerics.js`、`dist/special.js`、
|
|
304
305
|
`dist/mixed.js` は上のサブパスと同じ関数を export し、共通のコードを `dist/chunks/` で共有します。そのため、
|
|
305
306
|
2 つの分野を読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で
|
|
306
|
-
|
|
307
|
+
39 KB (`special`) から 221 KB (`tests`) です。
|
|
307
308
|
|
|
308
309
|
1 つのページでは、`dist/rstats.js` か分野ごとのバンドルのどちらか一方だけを使ってください。両者は別々の
|
|
309
310
|
モジュールの集まりなので、混ぜると共通のコードが 2 回読み込まれ、乱数の状態も 2 つになります (一方の `setSeed`
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ R-compatible statistical functions for JavaScript and the browser, written in Ty
|
|
|
6
6
|
[Try it in the browser](https://numero-uno-jpn.github.io/rStats.js/demo/) (every function, with the values R gives).
|
|
7
7
|
|
|
8
8
|
- **Same numbers as R.** Function names, defaults and results follow R. Every function is
|
|
9
|
-
tested against R 4.
|
|
9
|
+
tested against R 4.6.2 (relative error 1e-14 for distributions), and where R itself is
|
|
10
10
|
inaccurate, against high-precision reference values.
|
|
11
11
|
- **JavaScript-style calls.** Required arguments are positional, optional ones go in an object
|
|
12
12
|
with camelCase keys: `pt(q, df, { lowerTail: false })` is R's `pt(q, df, lower.tail = FALSE)`.
|
|
@@ -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.6 KB gzipped).
|
|
16
16
|
|
|
17
|
-
Status: **1.
|
|
17
|
+
Status: **1.2.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
|
|
|
@@ -203,6 +203,7 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
|
|
|
203
203
|
| Linear models | `lm` (a formula and a data frame, or a matrix, with the `summary` quantities), `modelMatrix` (`model.matrix`), `confint`, `predict`; `glm` (matrix interface, every family and link of R's `stats`) with `glmSummary` (`summary.glm`), `glmResiduals` (the four kinds), `glmHatvalues`, `glmRstandard`, `glmCooksDistance`, `glmPredict` (with standard errors), `glmConfint` (profile likelihood, exact limits), `glmAnova` (`anova.glm`) |
|
|
204
204
|
| Mixed models | `lmer` (lme4: REML and ML, correlated and uncorrelated random effects, crossed and nested grouping factors; `fixef`, `vcov`, `VarCorr`, `ranef`, `logLik`, `AIC`, `BIC`, `REMLcrit`, `isSingular`), `lmerSummary`, `lmerContest` and `lmerAnova` (lmerTest: Satterthwaite's t- and F-tests, Type I/II/III ANOVA tables; likelihood-ratio comparison of fits), `glmer` (lme4: all glm families, Laplace approximation and adaptive Gauss-Hermite quadrature), `glmerSummary`, `glmerAnova`, `glmerPredict` and `lmerPredict`, from `@numero-uno-jpn/rstats/mixed` |
|
|
205
205
|
| More tests | `leveneTest`, `propTrendTest` (`prop.trend.test`), `jonckheereTest`, `cochranQTest`, `adTest`, `lillieTest`, `cvmTest`, `sfTest`, `pearsonTest` (car, DescTools, clinfun, nortest) |
|
|
206
|
+
| Contingency tables and proportions | `binomCI`, `binomDiffCI`, `binomRatioCI` (DescTools' `BinomCI`, `BinomDiffCI`, `BinomRatioCI`), `oddsRatio` (epitools, and epiR's score interval), `fisherTest(x, { midp: true })` (exact2x2), `boschlooTest` (Exact), `gTest`, `stuartMaxwellTest`, `goodmanKruskalGamma` (DescTools), `lblTest` (coin), `chisqTest(x, { nMinus1: true })` (Campbell's 'N − 1' test) and Freeman-Tukey residuals, `tost` (equivalence), `binomDiffEquivalenceTest` (score TOST of two proportions) |
|
|
206
207
|
| Multiple comparisons | `dscfAllPairsTest` (Steel-Dwass), `kwAllPairsDunnTest`, `kwManyOneDunnTest`, `manyOneUTest` (Steel's many-one rank test), `dunnettTest`, `gamesHowellTest`, `tukeyTest` (PMCMRplus), `dunnTest` (dunn.test), `glhtDunnett` (multcomp) |
|
|
207
208
|
| Survival analysis | `survdiff` (log-rank), `survfit` (Kaplan-Meier with intervals and median), `coxph` (Cox regression: Efron and Breslow ties, case weights, strata, the Wald, likelihood-ratio and score tests) |
|
|
208
209
|
| Agreement and reliability | `kappa2`, `kappamFleiss`, `icc` (irr), `cronbachAlpha`, `partialR` (psych), `polychor`, `polyserial` (polycor), `pbvnorm`, `factanal`, `omega` (McDonald's ω, psych) |
|
|
@@ -266,12 +267,12 @@ removed. Approximate sizes after minification and gzip:
|
|
|
266
267
|
| `pnorm` | 1.6 KB |
|
|
267
268
|
| `setSeed`, `rnorm` | 2.0 KB |
|
|
268
269
|
| `solve` / `svd` / `eigen` | 2.4 / 2.4 / 5.1 KB |
|
|
269
|
-
| `wilcoxTest` / `fisherTest` / `tTest` |
|
|
270
|
-
| `qbeta` / `pt` and `qt` | 43.
|
|
271
|
-
| `glm` and `glmSummary` / `glm` with all its methods | 35.0 /
|
|
272
|
-
| `lmer` (from `/mixed`) / with `lmerSummary`, `lmerContest`, `lmerAnova` | 19.4 /
|
|
273
|
-
| `glmer` (from `/mixed`) / with `glmerSummary`, `glmerAnova`, `glmerPredict` | 47.
|
|
274
|
-
| everything (except `/mixed`) |
|
|
270
|
+
| `wilcoxTest` / `fisherTest` / `tTest` | 18.9 / 27.9 / 31.0 KB |
|
|
271
|
+
| `qbeta` / `pt` and `qt` | 43.9 / 40.4 KB |
|
|
272
|
+
| `glm` and `glmSummary` / `glm` with all its methods | 35.0 / 51.4 KB |
|
|
273
|
+
| `lmer` (from `/mixed`) / with `lmerSummary`, `lmerContest`, `lmerAnova` | 19.4 / 70.0 KB |
|
|
274
|
+
| `glmer` (from `/mixed`) / with `glmerSummary`, `glmerAnova`, `glmerPredict` | 47.2 / 66.1 KB |
|
|
275
|
+
| everything (except `/mixed`) | 263.5 KB |
|
|
275
276
|
|
|
276
277
|
(`npm run size` measures these.)
|
|
277
278
|
|
|
@@ -281,11 +282,11 @@ Each area is also a subpath export, for importing one area without the rest:
|
|
|
281
282
|
(`lmer`, `glmer` and their methods; this area is only available this way, not from the main entry point).
|
|
282
283
|
|
|
283
284
|
Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
|
|
284
|
-
function except those of `/mixed`,
|
|
285
|
+
function except those of `/mixed`, 264 KB gzipped) from jsDelivr, which serves each npm release:
|
|
285
286
|
|
|
286
287
|
```html
|
|
287
288
|
<script type="module">
|
|
288
|
-
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.
|
|
289
|
+
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@1.2.0/dist/rstats.js";
|
|
289
290
|
console.log(pnorm(1.96)); // ≈ 0.9750021049
|
|
290
291
|
</script>
|
|
291
292
|
```
|
|
@@ -301,7 +302,7 @@ A page that needs only some areas can load the per-area bundles instead: `dist/d
|
|
|
301
302
|
`dist/tests.js`, `dist/linalg.js`, `dist/descriptive.js`, `dist/numerics.js`, `dist/special.js` and
|
|
302
303
|
`dist/mixed.js` export the same functions as the subpaths above, and share their common code through
|
|
303
304
|
`dist/chunks/`, so loading two areas does not load that code twice. With its chunks, one area
|
|
304
|
-
transfers
|
|
305
|
+
transfers 39 KB (`special`) to 221 KB (`tests`) gzipped.
|
|
305
306
|
|
|
306
307
|
Use either `dist/rstats.js` or the per-area bundles on one page, not both: they are separate sets of modules, so a
|
|
307
308
|
page that mixes them loads the common code twice and has two random number states (`setSeed` from one does not seed
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -237,9 +237,10 @@ DAMAGE.
|
|
|
237
237
|
|
|
238
238
|
## LAPACK
|
|
239
239
|
|
|
240
|
-
- Source: https://github.com/Reference-LAPACK/lapack (tag v3.12.0)
|
|
240
|
+
- Source: https://github.com/Reference-LAPACK/lapack (tag v3.12.0; tag v3.12.1 where noted)
|
|
241
241
|
- `BLAS/SRC/dtrsm.f`, `SRC/dlange.f`, `SRC/dpotf2.f`, `SRC/dpstf2.f`, `SRC/dpotri.f` (`dtrti2.f`, `dlauu2.f`),
|
|
242
|
-
`SRC/dgeqp3.f` (`dlaqp2.f`, `dlarfg.f`, `dlarf.f
|
|
242
|
+
`SRC/dgeqp3.f` (`dlaqp2.f`, `dlarfg.f`, `dlarf.f`; v3.12.1: `dlaqp2.f` with `dlarf1f.f`), `SRC/dorm2r.f`
|
|
243
|
+
(v3.12.1, with `dlarf1f.f`), `SRC/dgetf2.f`, `SRC/dgetrs.f`,
|
|
243
244
|
`SRC/dgecon.f`, `SRC/dtrcon.f`, `SRC/dlacn2.f`, `SRC/dgebal.f`, `SRC/dgebak.f`, `SRC/dlanv2.f`
|
|
244
245
|
- Used in: `src/linalg/basic.ts`, `src/linalg/norm.ts`, `src/linalg/chol.ts`, `src/linalg/qr.ts`, `src/linalg/solve.ts`, `src/linalg/svd.ts`, `src/linalg/balance.ts`, `src/linalg/schur.ts`
|
|
245
246
|
- License: modified BSD
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{a as h,t as s,u as b}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.2.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,t as s,u as b}from"./chunk-7WG7X2UI.js";import{l as M}from"./chunk-TNETWBF5.js";function K(t){return Math.abs(t-m(t))>1e-9*Math.max(1,Math.abs(t))}function F(t){let e=m(t);return Math.abs(t-e)<=Math.min(1e-7,1e-9*Math.max(1,Math.abs(t)))?e:Math.floor(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 A=["rCompatible"],E=["rCompatible"],O=[.08333333333333333,-.021092796092796094,.007575757575757576,-.004166666666666667,.003968253968253968,-.008333333333333333,.08333333333333333],S=.9955816268920898,d=1569415565/1073741824,w=381566830/1073741824/1073741824,_=9016312093258695e-35,k=[-.002071332116774595,-.04525132144873906,-.28919126444774784,-.6503185377089651,-.3255503118680449,.25479851061131553],v=[-5578984132167551e-22,.0021284987017821146,.054151797245674226,.43593529692665967,1.4606242909763516,2.076711702373047,1];function R(t){let e=t-d;e-=w,e-=_;let r=h(t-1,k)/h(t-1,v);return e*S+e*r}function T(t){let e=0;if(t<1e17){let r=1/(t*t);e=r*h(r,O)}return Math.log(t)-.5/t-e}function C(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-b}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+R(t):e+T(t)}var N=-.5040830082644554,z=7289763902976895e-32,I;function G(t){I??=Array.from({length:100},(n,a)=>j(a+2,N));let e=z,r=-1,o=t-N;for(let n=1;n<100;n++){r*=-o;let a=r*I[n-1];if(e+=a,Math.abs(a)<Number.EPSILON*Math.abs(e))break}return e}var P=[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,a=0;for(;e<=1e8&&(a<9||o<=9||o<t);)if(a+=1,o+=1,n=Math.exp(-t*Math.log1p(a/e)),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let c=1,i=0;for(let u=0;u<12;u++){c*=t+i,n/=f;let l=c*n/P[u];if(r+=l,Math.abs(l/r)<s)break;i+=1,c*=t+i,n/=f,i+=1}return r}function j(t,e){let r=Math.pow(e,-t),o=e,n=0,a=0;for(;a<9||o<=9||o<t;)if(a+=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 c=1,i=0;for(let u=0;u<12;u++){c*=t+i,n/=f;let l=c*n/P[u];if(r+=l,Math.abs(l/r)<s)break;i+=1,c*=t+i,n/=f,i+=1}return r}function g(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 p=[];function D(t){if(p[t]!==void 0)return p[t];let e=[0,1];for(let n=0;n<t;n++){let a=e.slice(1).map((c,i)=>c*(i+1)),f=new Array(a.length+2).fill(0);a.forEach((c,i)=>{f[i]=f[i]-c,f[i+2]=f[i+2]-c}),e=f}let r=(t+1)%2,o=[];for(let n=r;n<e.length;n+=2)o.push(e[n]);return p[t]=o,o}function H(t,e){let r=D(t),o=e*e,n=r[r.length-1];for(let a=r.length-2;a>=0;a--)n=n*o+r[a];return(t+1)%2===1?n*e:n}function L(t){let e=t-Math.round(t);return Math.sin(Math.PI*(.5-Math.abs(e)))/Math.sin(Math.PI*e)}function y(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 g(t,e);let o=g(t,1-e);return(t%2===0?o:-o)-Math.pow(Math.PI,t+1)*H(t,L(e))}function Y(t){return Math.abs(t-N)<.3?G(t):C(t)}function W(t,e){return M(e,A,"trigamma"),y(1,t,e?.rCompatible??!0)}function X(t,e=0,r){M(r,E,"psigamma");let o=m(e);return Number.isNaN(o)||o<0||o>100?NaN:o===0?Y(t):y(o,t,r?.rCompatible??!0)}export{K as a,F as b,m as c,Y as d,W as e,X as f};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{c as le}from"./chunk-DCAWMF4K.js";import{a as ne}from"./chunk-BQSIBJVX.js";import{a as ue,g as fe}from"./chunk-LROMWFAK.js";import{x as z}from"./chunk-YG5S5AVP.js";import{b as me,c as V}from"./chunk-4OLDGML4.js";import{c as R}from"./chunk-NSWENS3S.js";import{b as re}from"./chunk-BWKHYRM6.js";import{r as L,s as j}from"./chunk-WWVMVZUL.js";import{A as ie,B as ee,J as te,K as q,M as ce,b as oe,c as ae,d as S,f as W,g as F,i as G,l as M}from"./chunk-63OPBEYO.js";function B(e){if(e.kind==="factor")return me(e);let t=[...new Set(e.values)].sort((o,a)=>o-a),r=[...new Set(t.map(re))],n=new Map(r.map((o,a)=>[o,a]));return{levels:r,codes:e.values.map(o=>n.get(re(o)))}}function A(e,t){if(e.kind!=="numeric")throw new TypeError(`'${t}' must be a numeric column`);return e.values}function C(e,t){let r=ue(e),n=fe(r,Object.keys(t));return{terms:n,rhsVariables:n.variables.slice(n.response===0?1:0)}}function de(e){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");return t<0?void 0:{lhs:e.slice(0,t).trim(),rhs:e.slice(t+1)}}var Oe=/^Pair\s*\(\s*([A-Za-z.][A-Za-z0-9._]*)\s*,\s*([A-Za-z.][A-Za-z0-9._]*)\s*\)$/,$="'formula' missing or incorrect",pe=(e,t)=>t.length===0&&e.terms.length===0&&e.intercept;function De(e,t,r){let n=de(e),o=n===void 0?null:Oe.exec(n.lhs);if(o!==null){let{terms:m,rhsVariables:d}=C(`~${n.rhs}`,t);if(!r||!pe(m,d))throw new TypeError($);let w=V(t,[o[1],o[2]]);return{kind:"paired",x:A(w.variables[0],o[1]),y:A(w.variables[1],o[2])}}let{terms:a,rhsVariables:c}=C(e,t);if(a.response<0)throw new TypeError($);let i=a.variables[0];if(r&&pe(a,c))return{kind:"one",x:A(V(t,[i]).variables[0],i)};if(c.length!==1||a.terms.length!==1)throw new TypeError($);let s=V(t,[i,c[0]],{dropUnusedLevels:!0}),l=A(s.variables[0],i),u=B(s.variables[1]);if(u.levels.length!==2)throw new Error("grouping factor must have exactly 2 levels");return{kind:"two",x:l.filter((m,d)=>u.codes[d]===0),y:l.filter((m,d)=>u.codes[d]===1),levels:[u.levels[0],u.levels[1]]}}function Je(e,t){let r=De(e,t,!1);if(r.kind!=="two")throw new TypeError($);return r}function Qe(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0)throw new TypeError($);if(n.length!==1)throw new TypeError("'formula' should be of the form response ~ group");let o=r.variables[0],a=V(t,[o,n[0]],{dropUnusedLevels:!0});return{values:A(a.variables[0],o),group:B(a.variables[1])}}function et(e,t){let r=t.levels.map(()=>[]);return e.forEach((n,o)=>r[t.codes[o]].push(n)),r}function tt(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0||n.length===0)throw new TypeError($);let o=r.variables[0],a=V(t,[o,...n],{dropUnusedLevels:!0}),c=a.variables.slice(1).map(B),i=a.rows.map((s,l)=>{let u=0,m=1;for(let d of c)u+=d.codes[l]*m,m*=d.levels.length;return u});return{values:A(a.variables[0],o),groups:i}}var he="incorrect specification for 'formula'";function rt(e,t){let r=de(e),n=r?.rhs.split("|");if(r===void 0||r.lhs===""||n.length!==2)throw new TypeError(he);let o=y=>{let{terms:x,rhsVariables:p}=C(y,t);if(p.length!==1||x.terms.length!==1)throw new TypeError(he);return p[0]},{terms:a}=C(`${r.lhs} ~ 1`,t),c=a.variables[0],i=o(`~${n[0]}`),s=o(`~${n[1]}`),l=V(t,[c,i,s],{dropUnusedLevels:!0}),u=A(l.variables[0],c),m=B(l.variables[1]),d=B(l.variables[2]),w=d.levels.map(()=>m.levels.map(()=>NaN)),g=d.levels.map(()=>m.levels.map(()=>0));if(u.forEach((y,x)=>{let p=d.codes[x],N=m.codes[x];g[p][N]++,w[p][N]=y}),g.some(y=>y.some(x=>x!==1)))throw new Error("not an unreplicated complete block design");return w}function we(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response>=0)throw new TypeError("'formula' missing or invalid");if(n.length!==2)throw new TypeError("invalid formula");let o=V(t,n);return{x:A(o.variables[0],n[0]),y:A(o.variables[1],n[1])}}function ge(e){if(e===void 0)return"two.sided";let r=["two.sided","less","greater"].filter(n=>n.startsWith(e));if(e.length===0||r.length!==1)throw new RangeError(`invalid alternative "${e}" (expected "two.sided", "less" or "greater")`);return r[0]}function Ne(e){if(!(Number.isFinite(e)&&e>=0&&e<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function st(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7}function ot(e){if(!(Number.isFinite(e)&&e>0&&e<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var Fe=["alternative","exact","confLevel","continuity","method"],$e=["pearson","kendall","spearman"];function Pe(e){if(e===void 0)return"pearson";let t=$e.filter(r=>r.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function be(e){if(!(e[0]>0))return[Math.sqrt(e[0]),0];let t=Math.sqrt(e[0]),r=W(e,ae(t,t));return oe(t,r[0]/(2*t))}function H(e,t){let r=e.length;if(r<2)return[NaN,0];let n=ee(e)?.d,o=ee(t)?.d;if(n===void 0||o===void 0)return[NaN,0];let a=[0,0],c=[0,0],i=[0,0];for(let l=0;l<r;l++)a=S(a,F(n[l],o[l])),c=S(c,F(n[l],n[l])),i=S(i,F(o[l],o[l]));if(c[0]===0||i[0]===0)return[NaN,0];let s=G(a,F(be(c),be(i)));return s[0]>=1?[1,0]:s[0]<=-1?[-1,0]:s}function ve(e,t){let r=F(W([1,0],e),S([1,0],e));return Math.sqrt(t)*e[0]/Math.sqrt(r[0])}function Ke(e){return Math.abs(e[0])<.5?Math.atanh(e[0]):.5*Math.log(S([1,0],e)[0]/W([1,0],e)[0])}function ye(e,t,r){return r==="less"?z(e,t,!0,!1):r==="greater"?z(e,t,!1,!1):2*Math.min(z(e,t,!0,!1),z(e,t,!1,!1))}function Ie(e,t){return t==="less"?L(e):t==="greater"?L(e,{lowerTail:!1}):2*Math.min(L(e),L(e,{lowerTail:!1}))}function X(e,t){let r=e.length,n=0;for(let u=0;u<r;u++){let m=e[u],d=t[u];for(let w=u+1;w<r;w++){let g=(e[w]>m?1:0)-(e[w]<m?1:0),y=(t[w]>d?1:0)-(t[w]<d?1:0);n+=g*y}}let o=q(e),a=q(t),c=r*(r-1)/2,i=o.reduce((u,m)=>u+m*(m-1)/2,0),s=a.reduce((u,m)=>u+m*(m-1)/2,0),l=r<2||i===c||s===c?NaN:i===0&&s===0?n/c:n/Math.sqrt((c-i)*(c-s));return{s:n,tau:l,ties:o.length>0||a.length>0,tx:o,ty:a}}var Ee=1290;function ke(e,t){let r=e*(e-1)/2;if(t<0)return 0;if(t>=r)return 1;let n=new Float64Array(t+1);n[0]=1;for(let a=2;a<=e;a++){let c=new Float64Array(t+1),i=0;for(let l=0;l<=t;l++)i+=n[l],c[l]=i;let s=new Float64Array(t+1);for(let l=0;l<=t;l++)s[l]=(c[l]-(l>=a?c[l-a]:0))/a;n=s}let o=0;for(let a=t;a>=0;a--)o+=n[a];return Math.min(1,o)}var Te=new Map;function je(e){let t=Te.get(e);if(t!==void 0)return t;let r=e*(e*e-1)/3,n=1<<e,o=new Array(n);o[0]=new Float64Array(r+1),o[0][0]=1;let a=i=>{let s=0;for(;i;i&=i-1)s++;return s};for(let i=0;i<n;i++){let s=o[i];if(s===void 0)continue;let l=a(i);for(let u=0;u<e;u++){if(i&1<<u)continue;let m=(u-l)**2,d=i|1<<u,w=o[d]??=new Float64Array(r+1);for(let g=0;g+m<=r;g++)s[g]&&(w[g+m]+=s[g])}i!==n-1&&(o[i]=void 0)}let c=o[n-1];return Te.set(e,c),c}var T=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function xe(e,t,r){let n=t;n%2!==0&&(n+=1);let o=1/e,a=(6*(n-1)*o/(e*e-1)-1)*Math.sqrt(1/o-1),c=a*a,s=a*o*(T[0]+o*(T[1]+T[2]*o)+c*(-T[3]+o*(T[4]+T[5]*o)-c*o*(T[6]+T[7]*o-c*(T[8]-T[9]*o+c*o*(T[10]-T[11]*c)))))/Math.exp(c/2),l=r?L(a)-s:s+L(a,{lowerTail:!1});return Math.min(1,Math.max(0,l))}function Me(e,t,r){let n=e*(e*e-1)/3;if(e<=9){let o=je(e),a=1;for(let i=2;i<=e;i++)a*=i;let c=0;if(r)for(let i=Math.min(t,n);i>=0;i--)c+=o[i];else for(let i=n;i>=Math.max(t,0);i--)c+=o[i];return c/a}return r?t+1>n?1:t+1<=0?0:xe(e,t+1,!0):t<=0?1:t>n?0:xe(e,t,!1)}function qe(e,t,r={}){if(M(r,Fe,"corTest"),typeof e=="string"){let n=we(e,t);return qe(n.x,n.y,r)}return ze(e,t,r)}function ze(e,t,r){if(e.length!==t.length)throw new TypeError("x and y must have the same length");let n=ge(r.alternative),o=Pe(r.method),a=r.continuity??!1,[c,i]=ce(Array.from(e),Array.from(t)),s=c.length;if(o==="pearson"){let f=r.confLevel??.95;if(Ne(f),s<3)throw new Error("not enough finite observations");let h=H(c,i),E=s-2,v=Number.isNaN(h[0])?NaN:ve(h,E),k={method:"Pearson's product-moment correlation",alternative:n,statistic:v,statisticName:"t",parameter:E,parameterName:"df",pValue:ye(v,E,n),estimate:h[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation",warnings:Number.isNaN(h[0])&&(Se(c)||Se(i))?[se]:[]};if(s>3){let Z=Ke(h),O=1/Math.sqrt(s-3),D=_=>Math.tanh(Z+_),K;if(n==="less")K=[-1,D(O*j(f))];else if(n==="greater")K=[D(-O*j(f)),1];else{let _=(1-f)/2,b=O*(_<1e-8?j(_,{lowerTail:!1}):j((1+f)/2));K=[D(-b),D(b)]}k.confInt=K,k.confLevel=f}return R("corTest",k)}if(s<2)throw new Error("not enough finite observations");if(o==="kendall"){let f=X(c,i),h={method:"Kendall's rank correlation tau",alternative:n,estimate:f.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau",warnings:[]};if(Number.isNaN(f.tau))return R("corTest",{...h,statistic:NaN,statisticName:"T",pValue:NaN,warnings:[se]});let E=r.exact??s<50;if(E&&!f.ties){if(s>Ee)throw new RangeError(`the exact distribution of T for n = ${s} takes too long (at most ${Ee}): use exact: false`);let b=s*(s-1)/2,I=(f.s+b)/2,U=ke(s,I),Y=ke(s,b-I),Ce=n==="less"?U:n==="greater"?Y:Math.min(1,2*Math.min(U,Y));return R("corTest",{...h,statistic:I,statisticName:"T",pValue:Ce})}let v=(b,I)=>I.reduce((U,Y)=>U+b(Y),0),k=b=>b*(b-1),Z=b=>b*(b-1)*(b-2),O=b=>b*(b-1)*(2*b+5),D=(s*(s-1)*(2*s+5)-v(O,f.tx)-v(O,f.ty))/18+(s<3?0:v(Z,f.tx)*v(Z,f.ty)/(9*s*(s-1)*(s-2)))+v(k,f.tx)*v(k,f.ty)/(2*s*(s-1)),_=(a?Math.sign(f.s)*(Math.abs(f.s)-1):f.s)/Math.sqrt(D);return E&&(h.warnings=[Ae]),R("corTest",{...h,statistic:_,statisticName:"z",pValue:Ie(_,n)})}let l=te(c),u=te(i),m=H(l,u),d=s*s*s-s,w=d*(1-m[0])/6,g={method:"Spearman's rank correlation rho",alternative:n,statistic:w,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho",warnings:[]};if(Number.isNaN(m[0]))return R("corTest",{...g,pValue:NaN,warnings:[se]});let y=q(c).length>0||q(i).length>0;if(y&&(r.exact??!0)&&(g.warnings=[Ae]),(r.exact??s<=1290)&&!y&&s<=1290){let f=Math.round(w),h=Me(s,f,!0),E=Me(s,f,!1),v=n==="greater"?h:n==="less"?E:Math.min(1,2*Math.min(h,E));return R("corTest",{...g,pValue:v})}let p=m;if(a){let f=G([6,0],[d,0]);p=G(S(m,f),S([1,0],f)),Math.abs(p[0])>=1&&(p=[Math.sign(p[0]),0])}let N=ve(p,s-2);return s===2&&(g.warnings=[...g.warnings,Be]),R("corTest",{...g,pValue:ye(N,s-2,n)})}var se="the standard deviation is zero",Be="NaNs produced",Ae="Cannot compute exact p-value with ties";function Se(e){return Number.isFinite(e[0])&&e.every(t=>t===e[0])}var Ze=["tiesMethod","naLast"];function Ue(e,t){let r=e.length,n=new Array(r);if(t==="first"||t==="last"||t==="random"){let c=t==="random"?le(r):[],i=Array.from({length:r},(s,l)=>l);return i.sort((s,l)=>{let u=e[s]<e[l]?-1:e[s]>e[l]?1:0;return u!==0?u:t==="first"?s-l:t==="last"?l-s:c[s]-c[l]||s-l}),i.forEach((s,l)=>n[s]=l+1),n}let o=Array.from({length:r},(c,i)=>i).sort((c,i)=>e[c]-e[i]||c-i),a=0;for(;a<r;){let c=a;for(;c+1<r&&e[o[c+1]]===e[o[a]];)c++;let i=t==="average"?(a+c+2)/2:t==="min"?a+1:c+1;for(let s=a;s<=c;s++)n[o[s]]=i;a=c+1}return n}function J(e,t={}){M(t,Ze,"rank");let r=t.tiesMethod??"average";if(!["average","first","last","random","max","min"].includes(r))throw new RangeError(`invalid tiesMethod "${r}"`);let n=t.naLast??"last";if(n!=="last"&&n!=="first"&&n!=="keep")throw new RangeError(`invalid 'naLast': ${String(n)}`);let o=Array.from(e),a=o.filter(m=>!Number.isNaN(m)),c=Ue(a,r),i=o.length-a.length,s=[],l=0,u=0;for(let m of o)Number.isNaN(m)?(u++,s.push(n==="keep"?NaN:n==="last"?a.length+u:u)):s.push(n==="first"?c[l++]+i:c[l++]);return s}var Re=["method","use"],Ve=["method","use"],Ye=["pearson","kendall","spearman"],We=["all.obs","complete.obs","pairwise.complete.obs","everything","na.or.complete"];function _e(e,t,r,n){if(e===void 0)return r;if(t.includes(e))return e;let o=t.filter(a=>a.startsWith(e));if(e.length===0||o.length!==1)throw new RangeError(`invalid '${n}' argument`);return o[0]}function P(e){return e.length>0&&Array.isArray(e[0])}function Le(e){if(!P(e))return[Array.from(e)];let t=e[0].length;if(e.some(r=>!Array.isArray(r)||r.length!==t))throw new TypeError("all rows of the matrix must have the same length");return Array.from({length:t},(r,n)=>e.map(o=>o[n]))}function Q(e,t,r,n){let o=_e(r.method,Ye,"pearson","method"),a=_e(r.use,We,"everything","use");if(t===void 0&&!P(e))throw new TypeError("supply both 'x' and 'y' or a matrix-like 'x'");let c=Le(e),i=t===void 0?c:Le(t),s=c[0]?.length??0;if(i.some(p=>p.length!==s))throw new RangeError("incompatible dimensions");let l=[...c,...i];if(a==="all.obs"&&l.some(p=>p.some(Number.isNaN)))throw new RangeError("missing observations in cov/cor");if(!n&&a==="pairwise.complete.obs"&&o!=="pearson")throw new RangeError("cannot handle 'pairwise.complete.obs'");let u;if((a==="complete.obs"||a==="na.or.complete")&&(u=Array.from({length:s},(p,N)=>l.every(f=>!Number.isNaN(f[N]))),!u.some(Boolean))){if(a==="complete.obs")throw new RangeError("no complete element pairs");return t===void 0||P(e)||P(t)?c.map(()=>i.map(()=>NaN)):NaN}let m=p=>{let N=u===void 0?p:p.filter((f,h)=>u[h]);return o==="spearman"&&a!=="pairwise.complete.obs"?J(N,{naLast:"keep"}):N},d=c.map(m),w=t===void 0?d:i.map(m),g=(p,N)=>{let f=p,h=N;if(a==="pairwise.complete.obs"){let E=p.map((v,k)=>!Number.isNaN(v)&&!Number.isNaN(N[k]));f=p.filter((v,k)=>E[k]),h=N.filter((v,k)=>E[k]),o==="spearman"&&(f=J(f),h=J(h))}else if(f.some(Number.isNaN)||h.some(Number.isNaN))return NaN;return f.length<2?NaN:o==="kendall"?n?X(f,h).tau:2*X(f,h).s:n?H(f,h)[0]:ie(f,h)},y=d.map(p=>w.map(N=>g(p,N))),x=u===void 0?s:u.filter(Boolean).length;return n&&t===void 0&&a!=="pairwise.complete.obs"&&x>=2&&y.forEach((p,N)=>{Number.isNaN(p[N])||(p[N]=1)}),t!==void 0&&!P(e)&&!P(t)?y[0][0]:y}function Tt(e,t,r={}){return ne(t)&&M(t,Re,"cov"),M(r,Re,"cov"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!1):Q(e,t,r,!1)}function xt(e,t,r={}){return ne(t)&&M(t,Ve,"cor"),M(r,Ve,"cor"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!0):Q(e,t,r,!0)}export{De as a,Je as b,Qe as c,et as d,tt as e,rt as f,ge as g,Ne as h,st as i,ot as j,H as k,qe as l,J as m,Tt as n,xt as o};
|
|
1
|
+
/*! rStats.js 1.2.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{c as le}from"./chunk-F3EQLL4F.js";import{a as ne}from"./chunk-7INBXTVV.js";import{a as ue,g as fe}from"./chunk-L23RSC2N.js";import{x as z}from"./chunk-RRO4LMCB.js";import{b as me,c as V}from"./chunk-IAWXF73N.js";import{c as R}from"./chunk-73LNRWU3.js";import{b as re}from"./chunk-BI7NYJWP.js";import{r as L,s as j}from"./chunk-7WG7X2UI.js";import{A as ie,B as ee,J as te,K as q,M as ce,b as oe,c as ae,d as S,f as W,g as F,i as G,l as M}from"./chunk-TNETWBF5.js";function B(e){if(e.kind==="factor")return me(e);let t=[...new Set(e.values)].sort((o,a)=>o-a),r=[...new Set(t.map(re))],n=new Map(r.map((o,a)=>[o,a]));return{levels:r,codes:e.values.map(o=>n.get(re(o)))}}function A(e,t){if(e.kind!=="numeric")throw new TypeError(`'${t}' must be a numeric column`);return e.values}function C(e,t){let r=ue(e),n=fe(r,Object.keys(t));return{terms:n,rhsVariables:n.variables.slice(n.response===0?1:0)}}function de(e){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");return t<0?void 0:{lhs:e.slice(0,t).trim(),rhs:e.slice(t+1)}}var Oe=/^Pair\s*\(\s*([A-Za-z.][A-Za-z0-9._]*)\s*,\s*([A-Za-z.][A-Za-z0-9._]*)\s*\)$/,$="'formula' missing or incorrect",pe=(e,t)=>t.length===0&&e.terms.length===0&&e.intercept;function De(e,t,r){let n=de(e),o=n===void 0?null:Oe.exec(n.lhs);if(o!==null){let{terms:m,rhsVariables:d}=C(`~${n.rhs}`,t);if(!r||!pe(m,d))throw new TypeError($);let w=V(t,[o[1],o[2]]);return{kind:"paired",x:A(w.variables[0],o[1]),y:A(w.variables[1],o[2])}}let{terms:a,rhsVariables:c}=C(e,t);if(a.response<0)throw new TypeError($);let i=a.variables[0];if(r&&pe(a,c))return{kind:"one",x:A(V(t,[i]).variables[0],i)};if(c.length!==1||a.terms.length!==1)throw new TypeError($);let s=V(t,[i,c[0]],{dropUnusedLevels:!0}),l=A(s.variables[0],i),u=B(s.variables[1]);if(u.levels.length!==2)throw new Error("grouping factor must have exactly 2 levels");return{kind:"two",x:l.filter((m,d)=>u.codes[d]===0),y:l.filter((m,d)=>u.codes[d]===1),levels:[u.levels[0],u.levels[1]]}}function Je(e,t){let r=De(e,t,!1);if(r.kind!=="two")throw new TypeError($);return r}function Qe(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0)throw new TypeError($);if(n.length!==1)throw new TypeError("'formula' should be of the form response ~ group");let o=r.variables[0],a=V(t,[o,n[0]],{dropUnusedLevels:!0});return{values:A(a.variables[0],o),group:B(a.variables[1])}}function et(e,t){let r=t.levels.map(()=>[]);return e.forEach((n,o)=>r[t.codes[o]].push(n)),r}function tt(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0||n.length===0)throw new TypeError($);let o=r.variables[0],a=V(t,[o,...n],{dropUnusedLevels:!0}),c=a.variables.slice(1).map(B),i=a.rows.map((s,l)=>{let u=0,m=1;for(let d of c)u+=d.codes[l]*m,m*=d.levels.length;return u});return{values:A(a.variables[0],o),groups:i}}var he="incorrect specification for 'formula'";function rt(e,t){let r=de(e),n=r?.rhs.split("|");if(r===void 0||r.lhs===""||n.length!==2)throw new TypeError(he);let o=y=>{let{terms:x,rhsVariables:p}=C(y,t);if(p.length!==1||x.terms.length!==1)throw new TypeError(he);return p[0]},{terms:a}=C(`${r.lhs} ~ 1`,t),c=a.variables[0],i=o(`~${n[0]}`),s=o(`~${n[1]}`),l=V(t,[c,i,s],{dropUnusedLevels:!0}),u=A(l.variables[0],c),m=B(l.variables[1]),d=B(l.variables[2]),w=d.levels.map(()=>m.levels.map(()=>NaN)),g=d.levels.map(()=>m.levels.map(()=>0));if(u.forEach((y,x)=>{let p=d.codes[x],N=m.codes[x];g[p][N]++,w[p][N]=y}),g.some(y=>y.some(x=>x!==1)))throw new Error("not an unreplicated complete block design");return w}function we(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response>=0)throw new TypeError("'formula' missing or invalid");if(n.length!==2)throw new TypeError("invalid formula");let o=V(t,n);return{x:A(o.variables[0],n[0]),y:A(o.variables[1],n[1])}}function ge(e){if(e===void 0)return"two.sided";let r=["two.sided","less","greater"].filter(n=>n.startsWith(e));if(e.length===0||r.length!==1)throw new RangeError(`invalid alternative "${e}" (expected "two.sided", "less" or "greater")`);return r[0]}function Ne(e){if(!(Number.isFinite(e)&&e>=0&&e<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function st(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7}function ot(e){if(!(Number.isFinite(e)&&e>0&&e<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var Fe=["alternative","exact","confLevel","continuity","method"],$e=["pearson","kendall","spearman"];function Pe(e){if(e===void 0)return"pearson";let t=$e.filter(r=>r.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function be(e){if(!(e[0]>0))return[Math.sqrt(e[0]),0];let t=Math.sqrt(e[0]),r=W(e,ae(t,t));return oe(t,r[0]/(2*t))}function H(e,t){let r=e.length;if(r<2)return[NaN,0];let n=ee(e)?.d,o=ee(t)?.d;if(n===void 0||o===void 0)return[NaN,0];let a=[0,0],c=[0,0],i=[0,0];for(let l=0;l<r;l++)a=S(a,F(n[l],o[l])),c=S(c,F(n[l],n[l])),i=S(i,F(o[l],o[l]));if(c[0]===0||i[0]===0)return[NaN,0];let s=G(a,F(be(c),be(i)));return s[0]>=1?[1,0]:s[0]<=-1?[-1,0]:s}function ve(e,t){let r=F(W([1,0],e),S([1,0],e));return Math.sqrt(t)*e[0]/Math.sqrt(r[0])}function Ke(e){return Math.abs(e[0])<.5?Math.atanh(e[0]):.5*Math.log(S([1,0],e)[0]/W([1,0],e)[0])}function ye(e,t,r){return r==="less"?z(e,t,!0,!1):r==="greater"?z(e,t,!1,!1):2*Math.min(z(e,t,!0,!1),z(e,t,!1,!1))}function Ie(e,t){return t==="less"?L(e):t==="greater"?L(e,{lowerTail:!1}):2*Math.min(L(e),L(e,{lowerTail:!1}))}function X(e,t){let r=e.length,n=0;for(let u=0;u<r;u++){let m=e[u],d=t[u];for(let w=u+1;w<r;w++){let g=(e[w]>m?1:0)-(e[w]<m?1:0),y=(t[w]>d?1:0)-(t[w]<d?1:0);n+=g*y}}let o=q(e),a=q(t),c=r*(r-1)/2,i=o.reduce((u,m)=>u+m*(m-1)/2,0),s=a.reduce((u,m)=>u+m*(m-1)/2,0),l=r<2||i===c||s===c?NaN:i===0&&s===0?n/c:n/Math.sqrt((c-i)*(c-s));return{s:n,tau:l,ties:o.length>0||a.length>0,tx:o,ty:a}}var Ee=1290;function ke(e,t){let r=e*(e-1)/2;if(t<0)return 0;if(t>=r)return 1;let n=new Float64Array(t+1);n[0]=1;for(let a=2;a<=e;a++){let c=new Float64Array(t+1),i=0;for(let l=0;l<=t;l++)i+=n[l],c[l]=i;let s=new Float64Array(t+1);for(let l=0;l<=t;l++)s[l]=(c[l]-(l>=a?c[l-a]:0))/a;n=s}let o=0;for(let a=t;a>=0;a--)o+=n[a];return Math.min(1,o)}var Te=new Map;function je(e){let t=Te.get(e);if(t!==void 0)return t;let r=e*(e*e-1)/3,n=1<<e,o=new Array(n);o[0]=new Float64Array(r+1),o[0][0]=1;let a=i=>{let s=0;for(;i;i&=i-1)s++;return s};for(let i=0;i<n;i++){let s=o[i];if(s===void 0)continue;let l=a(i);for(let u=0;u<e;u++){if(i&1<<u)continue;let m=(u-l)**2,d=i|1<<u,w=o[d]??=new Float64Array(r+1);for(let g=0;g+m<=r;g++)s[g]&&(w[g+m]+=s[g])}i!==n-1&&(o[i]=void 0)}let c=o[n-1];return Te.set(e,c),c}var T=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function xe(e,t,r){let n=t;n%2!==0&&(n+=1);let o=1/e,a=(6*(n-1)*o/(e*e-1)-1)*Math.sqrt(1/o-1),c=a*a,s=a*o*(T[0]+o*(T[1]+T[2]*o)+c*(-T[3]+o*(T[4]+T[5]*o)-c*o*(T[6]+T[7]*o-c*(T[8]-T[9]*o+c*o*(T[10]-T[11]*c)))))/Math.exp(c/2),l=r?L(a)-s:s+L(a,{lowerTail:!1});return Math.min(1,Math.max(0,l))}function Me(e,t,r){let n=e*(e*e-1)/3;if(e<=9){let o=je(e),a=1;for(let i=2;i<=e;i++)a*=i;let c=0;if(r)for(let i=Math.min(t,n);i>=0;i--)c+=o[i];else for(let i=n;i>=Math.max(t,0);i--)c+=o[i];return c/a}return r?t+1>n?1:t+1<=0?0:xe(e,t+1,!0):t<=0?1:t>n?0:xe(e,t,!1)}function qe(e,t,r={}){if(M(r,Fe,"corTest"),typeof e=="string"){let n=we(e,t);return qe(n.x,n.y,r)}return ze(e,t,r)}function ze(e,t,r){if(e.length!==t.length)throw new TypeError("x and y must have the same length");let n=ge(r.alternative),o=Pe(r.method),a=r.continuity??!1,[c,i]=ce(Array.from(e),Array.from(t)),s=c.length;if(o==="pearson"){let f=r.confLevel??.95;if(Ne(f),s<3)throw new Error("not enough finite observations");let h=H(c,i),E=s-2,v=Number.isNaN(h[0])?NaN:ve(h,E),k={method:"Pearson's product-moment correlation",alternative:n,statistic:v,statisticName:"t",parameter:E,parameterName:"df",pValue:ye(v,E,n),estimate:h[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation",warnings:Number.isNaN(h[0])&&(Se(c)||Se(i))?[se]:[]};if(s>3){let Z=Ke(h),O=1/Math.sqrt(s-3),D=_=>Math.tanh(Z+_),K;if(n==="less")K=[-1,D(O*j(f))];else if(n==="greater")K=[D(-O*j(f)),1];else{let _=(1-f)/2,b=O*(_<1e-8?j(_,{lowerTail:!1}):j((1+f)/2));K=[D(-b),D(b)]}k.confInt=K,k.confLevel=f}return R("corTest",k)}if(s<2)throw new Error("not enough finite observations");if(o==="kendall"){let f=X(c,i),h={method:"Kendall's rank correlation tau",alternative:n,estimate:f.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau",warnings:[]};if(Number.isNaN(f.tau))return R("corTest",{...h,statistic:NaN,statisticName:"T",pValue:NaN,warnings:[se]});let E=r.exact??s<50;if(E&&!f.ties){if(s>Ee)throw new RangeError(`the exact distribution of T for n = ${s} takes too long (at most ${Ee}): use exact: false`);let b=s*(s-1)/2,I=(f.s+b)/2,U=ke(s,I),Y=ke(s,b-I),Ce=n==="less"?U:n==="greater"?Y:Math.min(1,2*Math.min(U,Y));return R("corTest",{...h,statistic:I,statisticName:"T",pValue:Ce})}let v=(b,I)=>I.reduce((U,Y)=>U+b(Y),0),k=b=>b*(b-1),Z=b=>b*(b-1)*(b-2),O=b=>b*(b-1)*(2*b+5),D=(s*(s-1)*(2*s+5)-v(O,f.tx)-v(O,f.ty))/18+(s<3?0:v(Z,f.tx)*v(Z,f.ty)/(9*s*(s-1)*(s-2)))+v(k,f.tx)*v(k,f.ty)/(2*s*(s-1)),_=(a?Math.sign(f.s)*(Math.abs(f.s)-1):f.s)/Math.sqrt(D);return E&&(h.warnings=[Ae]),R("corTest",{...h,statistic:_,statisticName:"z",pValue:Ie(_,n)})}let l=te(c),u=te(i),m=H(l,u),d=s*s*s-s,w=d*(1-m[0])/6,g={method:"Spearman's rank correlation rho",alternative:n,statistic:w,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho",warnings:[]};if(Number.isNaN(m[0]))return R("corTest",{...g,pValue:NaN,warnings:[se]});let y=q(c).length>0||q(i).length>0;if(y&&(r.exact??!0)&&(g.warnings=[Ae]),(r.exact??s<=1290)&&!y&&s<=1290){let f=Math.round(w),h=Me(s,f,!0),E=Me(s,f,!1),v=n==="greater"?h:n==="less"?E:Math.min(1,2*Math.min(h,E));return R("corTest",{...g,pValue:v})}let p=m;if(a){let f=G([6,0],[d,0]);p=G(S(m,f),S([1,0],f)),Math.abs(p[0])>=1&&(p=[Math.sign(p[0]),0])}let N=ve(p,s-2);return s===2&&(g.warnings=[...g.warnings,Be]),R("corTest",{...g,pValue:ye(N,s-2,n)})}var se="the standard deviation is zero",Be="NaNs produced",Ae="cannot compute exact p-value with ties";function Se(e){return Number.isFinite(e[0])&&e.every(t=>t===e[0])}var Ze=["tiesMethod","naLast"];function Ue(e,t){let r=e.length,n=new Array(r);if(t==="first"||t==="last"||t==="random"){let c=t==="random"?le(r):[],i=Array.from({length:r},(s,l)=>l);return i.sort((s,l)=>{let u=e[s]<e[l]?-1:e[s]>e[l]?1:0;return u!==0?u:t==="first"?s-l:t==="last"?l-s:c[s]-c[l]||s-l}),i.forEach((s,l)=>n[s]=l+1),n}let o=Array.from({length:r},(c,i)=>i).sort((c,i)=>e[c]-e[i]||c-i),a=0;for(;a<r;){let c=a;for(;c+1<r&&e[o[c+1]]===e[o[a]];)c++;let i=t==="average"?(a+c+2)/2:t==="min"?a+1:c+1;for(let s=a;s<=c;s++)n[o[s]]=i;a=c+1}return n}function J(e,t={}){M(t,Ze,"rank");let r=t.tiesMethod??"average";if(!["average","first","last","random","max","min"].includes(r))throw new RangeError(`invalid tiesMethod "${r}"`);let n=t.naLast??"last";if(n!=="last"&&n!=="first"&&n!=="keep")throw new RangeError(`invalid 'naLast': ${String(n)}`);let o=Array.from(e),a=o.filter(m=>!Number.isNaN(m)),c=Ue(a,r),i=o.length-a.length,s=[],l=0,u=0;for(let m of o)Number.isNaN(m)?(u++,s.push(n==="keep"?NaN:n==="last"?a.length+u:u)):s.push(n==="first"?c[l++]+i:c[l++]);return s}var Re=["method","use"],Ve=["method","use"],Ye=["pearson","kendall","spearman"],We=["all.obs","complete.obs","pairwise.complete.obs","everything","na.or.complete"];function _e(e,t,r,n){if(e===void 0)return r;if(t.includes(e))return e;let o=t.filter(a=>a.startsWith(e));if(e.length===0||o.length!==1)throw new RangeError(`invalid '${n}' argument`);return o[0]}function P(e){return e.length>0&&Array.isArray(e[0])}function Le(e){if(!P(e))return[Array.from(e)];let t=e[0].length;if(e.some(r=>!Array.isArray(r)||r.length!==t))throw new TypeError("all rows of the matrix must have the same length");return Array.from({length:t},(r,n)=>e.map(o=>o[n]))}function Q(e,t,r,n){let o=_e(r.method,Ye,"pearson","method"),a=_e(r.use,We,"everything","use");if(t===void 0&&!P(e))throw new TypeError("supply both 'x' and 'y' or a matrix-like 'x'");let c=Le(e),i=t===void 0?c:Le(t),s=c[0]?.length??0;if(i.some(p=>p.length!==s))throw new RangeError("incompatible dimensions");let l=[...c,...i];if(a==="all.obs"&&l.some(p=>p.some(Number.isNaN)))throw new RangeError("missing observations in cov/cor");if(!n&&a==="pairwise.complete.obs"&&o!=="pearson")throw new RangeError("cannot handle 'pairwise.complete.obs'");let u;if((a==="complete.obs"||a==="na.or.complete")&&(u=Array.from({length:s},(p,N)=>l.every(f=>!Number.isNaN(f[N]))),!u.some(Boolean))){if(a==="complete.obs")throw new RangeError("no complete element pairs");return t===void 0||P(e)||P(t)?c.map(()=>i.map(()=>NaN)):NaN}let m=p=>{let N=u===void 0?p:p.filter((f,h)=>u[h]);return o==="spearman"&&a!=="pairwise.complete.obs"?J(N,{naLast:"keep"}):N},d=c.map(m),w=t===void 0?d:i.map(m),g=(p,N)=>{let f=p,h=N;if(a==="pairwise.complete.obs"){let E=p.map((v,k)=>!Number.isNaN(v)&&!Number.isNaN(N[k]));f=p.filter((v,k)=>E[k]),h=N.filter((v,k)=>E[k]),o==="spearman"&&(f=J(f),h=J(h))}else if(f.some(Number.isNaN)||h.some(Number.isNaN))return NaN;return f.length<2?NaN:o==="kendall"?n?X(f,h).tau:2*X(f,h).s:n?H(f,h)[0]:ie(f,h)},y=d.map(p=>w.map(N=>g(p,N))),x=u===void 0?s:u.filter(Boolean).length;return n&&t===void 0&&a!=="pairwise.complete.obs"&&x>=2&&y.forEach((p,N)=>{Number.isNaN(p[N])||(p[N]=1)}),t!==void 0&&!P(e)&&!P(t)?y[0][0]:y}function Tt(e,t,r={}){return ne(t)&&M(t,Re,"cov"),M(r,Re,"cov"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!1):Q(e,t,r,!1)}function xt(e,t,r={}){return ne(t)&&M(t,Ve,"cor"),M(r,Ve,"cor"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!0):Q(e,t,r,!0)}export{De as a,Je as b,Qe as c,et as d,tt as e,rt as f,ge as g,Ne as h,st as i,ot as j,H as k,qe as l,J as m,Tt as n,xt as o};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{f as q,g as he,h as J}from"./chunk-UKNDX4BA.js";import{A as ue,B as le,a as ie,b as ae,c as se,f as j,z as ce}from"./chunk-H7I32ZZE.js";import{a as S,b as T,c as C,d as L,e as Jt,h as ne,i as re,l as oe}from"./chunk-YG5S5AVP.js";import{a as fe}from"./chunk-CKV4JWW2.js";import{a as F,b as Q,c as v}from"./chunk-UJ66VQIG.js";import{A as kt,B as te,E as ee,e as E,r as R,s as B}from"./chunk-WWVMVZUL.js";import{b as Ut,c as Nt,d as ot,e as Vt,f as Zt,g as z,i as it,k as zt,l as y}from"./chunk-63OPBEYO.js";var gn=["log","ncp"],dn=["lowerTail","logP","ncp"],Nn=["lowerTail","logP","ncp"];function Dr(t,e,n={}){y(n,gn,"dchisq");let{log:r=!1,ncp:o}=n;if(o!==void 0)return E(t,a=>ie(a,e,o,r));let i=e<0?NaN:e/2;return E(t,a=>ne(a,i,2,r))}function Yr(t,e,n={}){y(n,dn,"pchisq");let{lowerTail:r=!0,logP:o=!1,ncp:i}=n;if(i!==void 0)return E(t,s=>ae(s,e,i,r,o));let a=e<0?NaN:e/2;return E(t,s=>re(s,a,2,r,o))}function Kr(t,e,n={}){y(n,Nn,"qchisq");let{lowerTail:r=!0,logP:o=!1,ncp:i}=n;if(i!==void 0)return E(t,s=>se(s,e,i,r,o));let a=e<0?NaN:e/2;return E(t,s=>oe(s,a,2,r,o))}var bn=["log"],wn=["lowerTail","logP"],xn=["lowerTail","logP"];function bt(t,e,n,r){if(t===0&&e===0)return{e:[0,0],logDenom:0};if(t===0||e===0){let o=t+e,[i,a]=t===0?[r,n]:[n,r];return{e:a[0]<.1?ot(te(o,z([o,0],i)),z([o,0],a)):Vt(z([o,0],zt(i))),logDenom:0}}return ee(t,e,n,r)}function ge(t,e,n,r){let o=e+n,i=it([r,0],[o,0]),a=it([o-r,0],[o,0]),s=bt(t,e-t,i,a),c=bt(r-t,n-r+t,i,a),u=bt(r,o-r,i,a);return{e:Zt(ot(s.e,c.e),u.e),logDenom:s.logDenom+c.logDenom-u.logDenom}}function de(t,e){let[n,r]=t.e,o=e*Math.exp(-.5*t.logDenom);return n<700?Math.exp(-n)*(1-r)*o:Math.exp(700-n)*(1-r)*o*Math.exp(-700)}function Ne(t){return-t.e[0]-t.e[1]-.5*t.logDenom}function wt(t,e){return Ut(t,e)[1]===0}function at(t,e,n){return[Math.max(0,n-e),Math.min(n,t)]}function En(t,e,n,r,o){if([t,e,n,r].some(Number.isNaN))return NaN;if(![e,n,r].every(Number.isFinite)||F(e)||F(n)||F(r))return NaN;if(e=v(e),n=v(n),r=v(r),e<0||n<0||r<0||r>e+n)return NaN;if(Et(e,n,r))return ce(t,r,xt(e,n),o);if(F(t))return C(o);t=v(t);let[i,a]=at(e,n,r);if(t<i||t>a)return C(o);if(r===0)return o?0:1;if(!wt(e,n))return NaN;if(r===e+n)return o?0:1;let s=ge(t,e,n,r);return o?Ne(s):de(s,1)}function Me(t,e,n,r){return it(Nt(t,e),Nt(n,r))}function yn(t,e,n,r,o,i,a){let s=[1,0],c=[1,0],u=t;for(;!(o?u<=i:u>=a);){let l=o?Me(u,n-r+u,e-u+1,r-u+1):Me(e-u,r-u,u+1,n-r+u+1);s=z(s,l),c=ot(c,s),u+=o?-1:1;let h=l[0];if(h<1&&s[0]*h/(1-h)<c[0]*2**-60)break}return c[0]+c[1]}function be(t,e,n,r,o,i){let[a,s]=at(e,n,r),c=e+n,u=t*c<r*e,l=pe(t,e,n,r,u,a,s);if(l.value>.5){let h=pe(t,e,n,r,!u,a,s);h.value<l.value&&(l=h,u=!u)}return u===o?i?l.value>1e-300?Math.log(l.value):Ne(l.form)+Math.log(l.sum):l.value:i?Math.log1p(-l.value):1-l.value}function pe(t,e,n,r,o,i,a){let s=o?t:t+1,c=ge(s,e,n,r),u=yn(s,e,n,r,o,i,a);return{form:c,sum:u,value:de(c,u)}}function xt(t,e){return t>=e?1/(1+e/t):e/t===1/0?0:t/e/(1+t/e)}function Et(t,e,n){return n>0&&n<t*2**-60+e*2**-60}function we(t,e,n){if([t,e,n].every(Number.isFinite)&&(t=v(t),e=v(e),n=v(n),!(t<0||e<0||n<0||n>t+e)))return[t,e,n]}function In(t,e,n,r,o,i){if([t,e,n,r].some(Number.isNaN))return NaN;let a=we(e,n,r);if(a===void 0)return NaN;if([e,n,r]=a,Et(e,n,r))return ue(t,r,xt(e,n),o,i);let s=Q(t),[c,u]=at(e,n,r);if(s<c)return S(o,i);if(s>=u)return T(o,i);if(u>Ee||!wt(e,n))return NaN;let l=vn(s,e,n,r,c,u);if(l>_n)throw new RangeError(`phyper: m = ${e}, n = ${n}, k = ${r} needs about ${Math.round(l)} terms at q = ${t} (at most 2^26)`);return be(s,e,n,r,o,i)}function xe(t,e,n,r){return n*t/r*(e/r)*(r-n)/Math.max(r-1,1)}function me(t,e,n,r,o,i){let a=e?n-t:t-n,s=Math.sqrt(a*a+83*r);return Math.min(a>=0?83*r/(s+a):s-a,e?t-o:i-t)}function vn(t,e,n,r,o,i){let a=e+n,s=r*e/a,c=xe(e,n,r,a),u=t*a<r*e,l=u?t:t+1,h=me(l,u,s,c,o,i);return Math.abs(l-s)>=1?h:h+me(u?t+1:t,!u,s,c,o,i)}var _n=2**26,An=2**21,Ee=2**53;function Rn(t,e,n,r,o,i,a=!0){if([t,e,n,r].some(Number.isNaN))return NaN;let s=we(e,n,r);if(s===void 0)return NaN;if([e,n,r]=s,Et(e,n,r))return le(t,r,xt(e,n),o,i);let[c,u]=at(e,n,r),l=L(t,c,u,o,i);if(l!==void 0)return l;if(c===u)return c;if(u>Ee||!wt(e,n))return NaN;let h=e+n,f=r*e/h,p=Math.sqrt(xe(e,n,r,h));if(a&&p>An)throw new RangeError(`qhyper: m = ${e}, n = ${n}, k = ${r} has a standard deviation of about ${p.toPrecision(3)} (at most 2^21)`);let M=B(t,{lowerTail:o,logP:i}),N=f+p*M;return j({p:t,lowerTail:o,logP:i,cdf:(g,I,d)=>g<c?S(I,d):g>=u?T(I,d):be(g,e,n,r,I,d),y0:Number.isFinite(N)?N:f,lo:c,hi:u})}function Jr(t,e,n,r,o={}){y(o,bn,"dhyper");let i=o.log??!1;return E(t,a=>En(a,e,n,r,i))}function kr(t,e,n,r,o={}){y(o,wn,"phyper");let{lowerTail:i=!0,logP:a=!1}=o;return E(t,s=>In(s,e,n,r,i,a))}function to(t,e,n,r,o={}){y(o,xn,"qhyper");let{lowerTail:i=!0,logP:a=!1}=o;return E(t,s=>Rn(s,e,n,r,i,a))}var Sn=["log"],Tn=["lowerTail","logP"],Pn=["lowerTail","logP"],Cn=2**900,ye=-900,W=new Map,Fn=2**21,st=0,Ln=2**25;function ve(t,e){if(e+1>Ln)throw new RangeError(`signrank: n = ${t} needs too large a table (${e+1} entries)`);let n=new Float64Array(e+1);n[0]=1;let r=0,o=-1/0,i=Math.min(t,e);for(let u=1;u<=i;u++){for(let l=e;l>=u;l--)n[l]+=n[l-u];if(n[Math.min(e,Math.floor(u*(u+1)/4))]>Cn){let l=2**ye;for(let h=0;h<=e;h++)n[h]*=l;r-=ye,o=Math.max(o,r-1015+i-u)}}let a=new Float64Array(e+1),s=0,c=0;for(let u=0;u<=e;u++){let l=n[u]-c,h=s+l;c=h-s-l,s=h,a[u]=s}return{n:t,len:e+1,count:n,cum:a,scale:r,minTrusted:2**(o-r)}}function Ie(t,e,n=!1){let r=n?-t:t,o=W.get(r);if(o!==void 0&&o.len>e)return W.delete(r),W.set(r,o),o;let i=Math.floor(t*(t+1)/4),a=Math.min(i,Math.max(e,o===void 0?0:2*o.len));return _e(r,ve(t,a),o)}function _e(t,e,n){n!==void 0&&(W.delete(t),st-=n.len),W.set(t,e),st+=e.len;for(let[r,o]of W){if(st<=Fn||r===t)break;W.delete(r),st-=o.len}return e}function yt(t,e,n){let r=(a,s)=>e===a.len-1||s>=(n?(e+1)*a.minTrusted:a.minTrusted),o=Ie(t,e),i=(n?o.cum:o.count)[e];return r(o,i)?[i,o]:(o=Ie(t,e,!0),i=(n?o.cum:o.count)[e],r(o,i)?[i,o]:(o=_e(-t,ve(t,e),W.get(-t)),[(n?o.cum:o.count)[e],o]))}function It(t,e,n){let r=e.scale-e.n,o=Math.trunc(r/2),i=t*2**o*2**(r-o);if(!n)return i;if(i>=1e-300)return Math.log(i);let a=Math.floor(Math.log2(t)),s=Math.trunc(a/2),c=t*2**-s*2**-(a-s);return c>=2?(c/=2,a++):c<1&&(c*=2,a--),Math.log(c)+(a+r)*Math.LN2}function vt(t){return Number.isFinite(t)?(t=v(t),t<=0||t>=2**27?NaN:t):NaN}function qn(t,e,n){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;if(F(t))return C(n);t=v(t);let r=e*(e+1)/2;if(t<0||t>r)return C(n);let o=Math.min(t,r-t),[i,a]=yt(e,o,!1);return It(i,a,n)}function Ae(t,e,n,r){let o=e*(e+1)/2,i=t,a=o-t-1,s=n?i:a,c=n?a:i;if(s<=c){let[f,p]=yt(e,s,!0);return It(f,p,r)}let[u,l]=yt(e,c,!0),h=It(u,l,!1);return r?Math.log1p(-h):1-h}function Wn(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;let o=Q(t),i=e*(e+1)/2;return o<0?S(n,r):o>=i?T(n,r):Ae(o,e,n,r)}function $n(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;let o=e*(e+1)/2,i=L(t,0,o,n,r);if(i!==void 0)return i;let a=o/2,s=Math.sqrt(e*(e+1)*(2*e+1)/24),c=a+s*B(t,{lowerTail:n,logP:r});return j({p:t,lowerTail:n,logP:r,cdf:(u,l,h)=>u<0?S(l,h):u>=o?T(l,h):Ae(u,e,l,h),y0:Number.isFinite(c)?c:a,lo:0,hi:o})}function co(t,e,n={}){y(n,Sn,"dsignrank");let r=n.log??!1;return E(t,o=>qn(o,e,r))}function uo(t,e,n={}){y(n,Tn,"psignrank");let{lowerTail:r=!0,logP:o=!1}=n;return E(t,i=>Wn(i,e,r,o))}function lo(t,e,n={}){y(n,Pn,"qsignrank");let{lowerTail:r=!0,logP:o=!1}=n;return E(t,i=>$n(i,e,r,o))}var On=["log"],Dn=["lowerTail","logP"],Yn=["lowerTail","logP"],Re=960,Se=2**996,Kn=2**25,Fe=2**29,Hn=2**760,Te=200,Xn=2**-969,ct=134217729,$=new Map,Bn=2**21,ut=0;function Le(t,e,n){if(n+1>Kn)throw new RangeError(`wilcox: m = ${t}, n = ${e} needs too large a table (${n+1} entries)`);if(t*(n+1)>Fe)throw new RangeError(`wilcox: m = ${t}, n = ${e} needs ${t*(n+1)} steps for a table of ${n+1} entries (at most 2^29)`);let r=new Float64Array(n+1),o=new Float64Array(n+1);r[0]=2**Re;let i=Re,a=NaN,s=n+1;for(let f=1;f<=t;f++){let p=Math.min(s-1,f*e),M=e+f,N=ct*f,g=N-(N-f),I=f-g;N=ct*M;let d=N-(N-M),m=M-d;for(let b=0;b<=p;b++){let x=r[b];if(x===0)continue;if(!(Math.abs(x)<=Se)){s=b,p=b-1;break}let P=x*f;N=ct*x;let A=N-(N-x),H=x-A,pn=A*g-P+A*I+H*g+H*I+o[b]*f,X=P/M,Qt=X*M;N=ct*X;let gt=N-(N-X),jt=X-gt,mn=gt*d-Qt+gt*m+jt*d+jt*m,Gt=(P-Qt-mn+pn)/M,dt=X+Gt;o[b]=Gt-(dt-X),r[b]=dt,Math.abs(dt)<Xn&&Number.isNaN(a)&&(a=i)}let w=e+f;for(let b=p;b>=w;b--)Pe(r,o,b,b-w,-1);for(let b=f;b<=p;b++)Pe(r,o,b,b-f,1);let _=Math.min(p,Math.floor(f*e/2));for(;_>=0&&r[_]>0&&r[_]<Hn;){let b=2**Te;for(let x=0;x<=p;x++)r[x]*=b,o[x]*=b;i+=Te}}let c=new Float64Array(n+1),u=0,l=0;for(let f=0;f<s;f++){let p=r[f];if(!(Math.abs(p)<=Se)){s=f;break}let M=u+p,N=M-u,g=u-(M-N)+(p-N);g+=l+o[f],u=M+g,l=g-(u-M),c[f]=u}let h=Number.isNaN(a)?0:2**Math.min(1023,-909+Math.ceil(Math.log2(t*(n+1)))+i-a);return{m:t,n:e,len:n+1,prob:r,cum:c,scale:i,minTrusted:h,valid:s}}function Pe(t,e,n,r,o){let i=t[n],a=o*t[r],s=i+a,c=s-i,u=i-(s-c)+(a-c);u+=e[n]+o*e[r];let l=s+u;e[n]=u-(l-s),t[n]=l}function Ce(t,e,n,r=!1){let o=`${t},${e}${r?",low":""}`,i=$.get(o);if(i!==void 0&&i.len>n)return $.delete(o),$.set(o,i),i;let a=Math.floor(t*e/2),s=i===void 0?0:Math.min(2*i.len,Math.floor(Fe/t)-1),c=Math.min(a,Math.max(n,s));return qe(o,Le(t,e,c),i)}function qe(t,e,n){n!==void 0&&($.delete(t),ut-=n.len),$.set(t,e),ut+=e.len;for(let[r,o]of $){if(ut<=Bn||r===t)break;$.delete(r),ut-=o.len}return e}function _t(t,e,n,r){t>e&&([t,e]=[e,t]);let o=u=>{if(n>=u.valid)throw new RangeError(`wilcox: the exact distribution for m = ${t}, n = ${e} cannot be computed accurately at ${n} (from ${u.valid} on, near the center of large samples)`);return(r?u.cum:u.prob)[n]},i=(u,l)=>n===u.len-1||l>=(r?(n+1)*u.minTrusted:u.minTrusted),a=Ce(t,e,n),s=o(a);if(i(a,s))return[s,a];if(a=Ce(t,e,n,!0),s=o(a),i(a,s))return[s,a];let c=`${t},${e},low`;return a=qe(c,Le(t,e,n),$.get(c)),[o(a),a]}var Qn=.6931471803691238,jn=19082149292705877e-26;function At(t,e,n){let r=-e.scale,o=Math.trunc(r/2),i=t*2**o*2**(r-o);if(!n)return i;if(i>=1e-300)return Math.log(i);let a=Math.floor(Math.log2(t)),s=Math.trunc(a/2),c=t*2**-s*2**-(a-s);return c>=2?(c/=2,a++):c<1&&(c*=2,a--),(a+r)*Qn+(Math.log(c)+(a+r)*jn)}function Rt(t,e){if(!(!Number.isFinite(t)||!Number.isFinite(e))&&(t=v(t),e=v(e),!(t<=0||e<=0||t*e>2**53)))return t*e===2**53&&BigInt(t)*BigInt(e)!==2n**53n?void 0:[t,e]}function Gn(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let o=Rt(e,n);if(o===void 0)return NaN;if([e,n]=o,F(t))return C(r);t=v(t);let i=e*n;if(t<0||t>i)return C(r);let a=Math.min(t,i-t),[s,c]=_t(e,n,a,!1);return At(s,c,r)}function We(t,e,n,r,o){let i=e*n,a=r?t:i-t-1,s=r?i-t-1:t;if(a<=s){let[h,f]=_t(e,n,a,!0);return At(h,f,o)}let[c,u]=_t(e,n,s,!0),l=At(c,u,!1);return o?Math.log1p(-l):1-l}function Un(t,e,n,r,o){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let i=Rt(e,n);if(i===void 0)return NaN;[e,n]=i;let a=Q(t);return a<0?S(r,o):a>=e*n?T(r,o):We(a,e,n,r,o)}function Vn(t,e,n,r,o){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let i=Rt(e,n);if(i===void 0)return NaN;[e,n]=i;let a=e*n,s=L(t,0,a,r,o);if(s!==void 0)return s;let c=a/2,u=Math.sqrt(a*(e+n+1)/12),l=c+u*B(t,{lowerTail:r,logP:o});return j({p:t,lowerTail:r,logP:o,cdf:(h,f,p)=>h<0?S(f,p):h>=a?T(f,p):We(h,e,n,f,p),y0:Number.isFinite(l)?l:c,lo:0,hi:a})}function bo(t,e,n,r={}){y(r,On,"dwilcox");let o=r.log??!1;return E(t,i=>Gn(i,e,n,o))}function wo(t,e,n,r={}){y(r,Dn,"pwilcox");let{lowerTail:o=!0,logP:i=!1}=r;return E(t,a=>Un(a,e,n,o,i))}function xo(t,e,n,r={}){y(r,Yn,"qwilcox");let{lowerTail:o=!0,logP:i=!1}=r;return E(t,a=>Vn(a,e,n,o,i))}var Zn=["nranges","lowerTail","logP"],zn=["nranges","lowerTail","logP"],D=128,et=Number.EPSILON,Jn=256,$t=Float64Array.from({length:2*D+1},(t,e)=>Math.cos(Math.PI*e/D));function kn(t){let e=new Float64Array(t+1);for(let n=0;n<=t;n++){let r=0;for(let o=0;o<=t;o+=2)r+=(o===0||o===t?.5:1)*$t[o*n%(2*t)*(D/t)]*2/(1-o*o);e[n]=(n===0||n===t?.5:1)*2*r/t}return e}var tr=new Map([16,32,64,128].map(t=>[t,kn(t)]));function er(t,e){let n=tr.get(e),r=D/e,o=0,i=0;for(let s=0;s<=e;s++)o+=n[s]*t[s],i+=Math.abs(n[s]*t[s]);let a=0;for(let s=e-7;s<=e;s++){let c=.5*(t[0]+(s%2===0?t[e]:-t[e]));for(let u=1;u<e;u++)c+=t[u]*$t[s*u%(2*e)*r];c*=2/e,s===e&&(c*=.5),a=Math.max(a,Math.abs(c))}return{integral:o,tail:a,scale:i}}var tt=class{f;a;b;noise;c;h;values=new Float64Array(D+1);have=new Uint8Array(D+1);N=0;integral=0;error=1/0;constructor(e,n,r,o){this.f=e,this.a=n,this.b=r,this.noise=o,this.c=.5*(n+r),this.h=.5*(r-n)}advance(e){let n=D/e,r=new Float64Array(e+1);for(let i=0;i<=e;i++){let a=i*n;this.have[a]||(this.values[a]=this.f(this.c+this.h*$t[a]),this.have[a]=1),r[i]=this.values[a]}let o=er(r,e);this.N=e,this.integral=o.integral*this.h,this.error=Math.max(o.tail*4/e,this.noise*o.scale)*Math.abs(this.h)}};function ht(t,e,n,r=4*et){let o=[];for(let a=0;a+1<e.length;a++){let s=new tt(t,e[a],e[a+1],r);s.advance(16),o.push(s)}for(let a=0;a<40;a++){let s=0;for(let f of o)s+=f.integral;let c=n*Math.abs(s)/o.length,u=!0,l=o.length,h=[];for(let f of o){if(f.error<=c||f.error<=r*Math.abs(f.integral)){h.push(f);continue}if(u=!1,f.N<D)f.advance(2*f.N),h.push(f);else if(l>=Jn)h.push(f);else{l++;let p=new tt(t,f.a,f.c,r),M=new tt(t,f.c,f.b,r);p.advance(16),M.advance(16),h.push(p,M)}}if(o=h,u)break}let i=0;for(let a of o)i+=a.integral;return i}function De(t,e,n){let r=Math.max(1,Math.ceil((e-t)/n));return Array.from({length:r+1},(o,i)=>i===r?e:t+(e-t)*i/r)}var Ye=2e-15,Ke=1e-16,nr={lowerTail:!1},rr={logP:!0},or={lowerTail:!1,logP:!0},rt=.9189385332046728,Mt=t=>R(t),U=t=>R(t,nr),Ot=t=>R(t,rr),Dt=t=>R(t,or),ir=.3989422804014327;function V(t){let e=Math.round(t*16)/16,n=t-e;return ir*Math.exp(-.5*e*e)*Math.exp(-.5*n*(t+e))}var Pt=[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],He=[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626];function ar(t,e){let n=t-.5*e,r=.5*e,o=0;for(let i=0;i<4;i++)o+=He[i]*(V(n-r*Pt[i])+V(n+r*Pt[i]));return o*r}function sr(t,e){let n=t-.5*e,r=.5*e,o=0;for(let i=0;i<4;i++){let a=r*Pt[i];o+=He[i]*(Math.exp(n*a-a*a/2)+Math.exp(-n*a-a*a/2))}return-rt-n*n/2+Math.log(o*r)}var Yt=(t,e)=>e*Math.max(1,Math.abs(t),Math.abs(t-e))<.5;function Z(t,e){let n=t-e,r=n-t,o=t-(n-r)+(-e-r);return{ah:n,al:o}}function nt(t,e){return Mt(t)+V(t)*e}function cr(t,e){return U(t)-V(t)*e}function Xe(t,e){if(Yt(t,e))return ar(t,e);let{ah:n,al:r}=Z(t,e);return n>=0?cr(n,r)-U(t):t<=0?Mt(t)-nt(n,r):1-nt(n,r)-U(t)}function ur(t,e,n){if(t>0&&t-e<0&&!Yt(t,e)){let{ah:o,al:i}=Z(t,e);return Math.exp(n*Math.log1p(-(nt(o,i)+U(t))))}let r=Xe(t,e);return r>0?r**n:0}function lr(t,e){return t>0?Math.exp(e*Math.log1p(-U(t))):Mt(t)**e}function Be(t,e){let{ah:n,al:r}=Z(t,e),o=Ot(n);return o+r*Math.exp(-rt-n*n/2-o)}function fr(t,e){let{ah:n,al:r}=Z(t,e),o=Dt(n);return o-r*Math.exp(-rt-n*n/2-o)}function Qe(t,e){if(Yt(t,e))return sr(t,e);if(t-e>=0){let i=fr(t,e);return i+Math.log(-Math.expm1(Dt(t)-i))}if(t<=0){let i=Ot(t);return i+Math.log(-Math.expm1(Be(t,e)-i))}let{ah:r,al:o}=Z(t,e);return Math.log1p(-nt(r,o)-U(t))}var je=2,St=1e-18;function Ge(t,e,n){let r=De(e,n,je),o=r.map(t),i=0;for(let f=1;f<o.length;f++)o[f]>o[i]&&(i=f);let a=o[i];if(!(a>0))return 0;let s=Math.max(i-1,0),c=Math.min(i+1,o.length-1);for(;s>0&&o[s]>a*St;)s--;for(;c<o.length-1&&o[c]>a*St;)c++;let u=a*St,l=r[s],h=r[c];if(o[s]<=u){let f=r[s+1];for(let p=0;p<2;p++){let M=.5*(l+f);t(M)<=u?l=M:f=M}}if(o[c]<=u){let f=r[c-1];for(let p=0;p<2;p++){let M=.5*(h+f);t(M)<=u?h=M:f=M}}return ht(t,[l,h],Ke)}function Ue(t,e,n){let r=De(e,n,je),o=r.map(t),i=0;for(let m=1;m<o.length;m++)o[m]>o[i]&&(i=m);if(!(o[i]>-1/0))return-1/0;let a=r[Math.max(i-1,0)],s=r[Math.min(i+1,r.length-1)],c=(Math.sqrt(5)-1)/2,u=s-c*(s-a),l=a+c*(s-a),h=t(u),f=t(l);for(let m=0;m<80&&s-a>1e-12*Math.max(1,Math.abs(a));m++)h<f?(a=u,u=l,h=f,l=a+c*(s-a),f=t(l)):(s=l,l=u,f=h,u=s-c*(s-a),h=t(u));let p=h>f?u:l,M=Math.max(h,f);o[i]>M&&(p=r[i],M=o[i]);let N=m=>{let w=m<0?e:n,_=Math.max(1e-6,.001*(r[1]-r[0])),b=p;for(;;){let x=p+m*_;if(m<0?x<=w:x>=w)return w;if(t(x)<M-46){let P=x;for(let A=0;A<6;A++){let H=.5*(b+P);t(H)<M-46?P=H:b=H}return P}b=x,_*=2}},g=N(-1),I=N(1),d=[...new Set([g,p,I])].sort((m,w)=>m-w);return M+Math.log(ht(m=>Math.exp(t(m)-M),d,Ke,4*et*Math.max(1,Math.abs(M))))}var Kt=-10,Ht=10;function hr(t,e){return t<=0?0:e*Ge(n=>V(n)*ur(n,t,e-1),Kt,Ht)}function Ve(t,e){if(t<=0)return 1;let n=i=>{let a=Mt(i);if(a===0)return 0;let{ah:s,al:c}=Z(i,t),u=nt(s,c),l=u<.5*a?-Math.expm1((e-1)*Math.log1p(-u/a)):-Math.expm1((e-1)*Math.log(Xe(i,t)/a));return V(i)*lr(i,e-1)*l};if(t>60)return 0;let[r,o]=Ze(t);return e*Ge(n,r,o)}function Ze(t){return t>40?[t/2-15,t/2+15]:[Kt,t+Ht]}function Mr(t,e){if(t>100)return-Math.exp(ze(t,e));let n=r=>-rt-r*r/2+(e-1)*Qe(r,t);return Math.log(e)+Ue(n,Kt,Ht)}function ze(t,e){if(t>100){let i=e*(e-1);return(Number.isFinite(i)?Math.log(i):Math.log(e)+Math.log(e-1))+Dt(t/Math.SQRT2)}let n=i=>{let a=Ot(i),s=Be(i,t)-a,c;return s<-40?c=Math.log(e-1)+s:s<-Math.LN2?c=Math.log(-Math.expm1((e-1)*Math.log1p(-Math.exp(s)))):c=Math.log(-Math.expm1((e-1)*(Qe(i,t)-a))),-rt-i*i/2+(e-1)*a+c},[r,o]=Ze(t);return Math.log(e)+Ue(n,r,o)}function pr(t,e){let n=-1/0;for(let r of e)n=Math.max(n,t(r));for(let r=0;r+1<e.length;r++)n=Math.max(n,t(.5*(e[r]+e[r+1])));if(n===-1/0)return-1/0;if(et*Math.abs(n)>1)return n;for(let r=0;r<4;r++){let o=n,i=ht(a=>{let s=t(a);return s>o&&(o=s),Math.exp(s-n)},e,Ye,8*et*Math.max(1,Math.abs(n)));if(Number.isFinite(i)&&o-n<300)return n+Math.log(i);n=o}return NaN}var O=32,mr=1e-15,G=Math.log(.01),pt=Math.log(20),Je=Math.log(40),ke=Float64Array.from({length:2*O+1},(t,e)=>Math.cos(Math.PI*e/O));function gr(t,e){let n=new Float64Array(e+1);for(let r=0;r<=e;r++){let o=.5*(t[0]+(r%2===0?t[e]:-t[e]));for(let i=1;i<e;i++)o+=t[i]*ke[r*i%(2*e)];o*=2/e,(r===0||r===e)&&(o*=.5),n[r]=o}return n}function Tt(t,e,n){let r=[],o=[[e,n,0]];for(;o.length>0;){let[i,a,s]=o.pop(),c=.5*(i+a),u=.5*(a-i),l=new Float64Array(O+1),h=1/0;for(let M=0;M<=O;M++)l[M]=t(c+u*ke[M]),h=Math.min(h,Math.max(1,Math.abs(l[M])));let f=gr(l,O),p=0;for(let M=O-3;M<=O;M++)p=Math.max(p,Math.abs(f[M]));p<=mr*h||s>=14||!l.every(Number.isFinite)?r.push({a:i,b:a,coef:f}):o.push([c,a,s+1],[i,c,s+1])}return r.sort((i,a)=>i.a-a.a)}function Ct(t,e){let n=0,r=t.length-1;for(;n<r;){let l=n+r+1>>1;t[l].a<=e?n=l:r=l-1}let{a:o,b:i,coef:a}=t[n],s=(2*e-o-i)/(i-o),c=0,u=0;for(let l=O;l>=1;l--){let h=2*s*c-u+a[l];u=c,c=h}return s*c-u+a[0]}var k=new Map,dr=64,tn=Math.log(1e-10);function en(t){let e=k.get(t);if(e!==void 0)return e;let n=o=>{let i=hr(o,t);return i>1e-290?Math.log(i):Mr(o,t)},r=o=>{let i=Math.exp(o);return Ve(i,t)*nn(i)};return e={logW:Tt(o=>n(Math.exp(o)),G,pt),scaledWc:Tt(r,G,Je),smallW:Tt(o=>n(Math.exp(o))-(t-1)*o,tn,G)},k.size>=dr&&k.delete(k.keys().next().value),k.set(t,e),e}function nn(t){let e=t*t,n=134217729*t,r=n-(n-t),o=t-r,i=r*r-e+2*r*o+o*o;return Math.exp(e/4)*(1+i/4)}function rn(t,e){let n=Math.log(t);if(n>=pt)return 0;let r=en(e);return n>=G?Ct(r.logW,n):Ct(r.smallW,Math.max(n,tn))+(e-1)*n}function Ft(t,e){return Math.log(t)>=pt?1:Math.exp(rn(t,e))}function Lt(t,e){let n=Math.log(t);return n>=G&&n<=Je?Ct(en(e).scaledWc,n)/nn(t):n<G?1-Ft(t,e):Ve(t,e)}function lt(t,e,n,r){if(!r){let i=Math.min(Ft(t,e),1);return n===1?i:i**n}let o=Math.min(Lt(t,e),1);return o<=.5?n===1?o:-Math.expm1(n*Math.log1p(-o)):1-Math.min(Ft(t,e),1)**n}function qt(t,e,n,r){if(!r)return n*(Math.log(t)<pt?rn(t,e):Math.log1p(-Math.min(Lt(t,e),1)));let o=Math.min(Lt(t,e),1),i=o>1e-290?Math.log(o):ze(t,e);return n===1?i:i<-700?Math.log(n)+i:Math.log(-Math.expm1(n*Math.log1p(-Math.exp(i))))}function Wt(t,e,n,r,o){if(n===1/0||an(t,e,n,r))return lt(t,e,r,o);let i=n/2,a=on(i);return ht(c=>{let u=Math.exp(a(c));return u===0?0:u*lt(t*Math.exp(.5*c),e,r,o)},sn(t,e,n,r,o),Ye)}function on(t){let e=.5*Math.log(t/(2*Math.PI))-kt(t);return n=>{let r;if(Math.abs(n)<.5){let o=n*n/2;r=o;for(let i=3;i<60&&(o*=n/i,r+=o,!(Math.abs(o)<1e-17*r));i++);}else r=Math.expm1(n)-n;return e-t*r}}function an(t,e,n,r){let o=Math.max((e-1)*r,t*t,1);return o*o<1e-17*n}function Nr(t,e,n,r,o){if(n===1/0||an(t,e,n,r))return qt(t,e,r,o);let i=on(n/2),a=Math.log(t);return pr(c=>i(c)+qt(Math.exp(a+.5*c),e,r,o),sn(t,e,n,r,o,!0))}function sn(t,e,n,r,o,i=!1){let a=n/2,s=a,c;if(o){let m=2*Math.log(t)-Math.log(4*a);c=-(m>30?m:Math.log1p(Math.exp(m)))}else s=a+(e-1)*r/2,c=Math.log1p((e-1)*r/(2*a));let u=(m,w)=>[m-9/Math.sqrt(w)-41/w,m+9/Math.sqrt(w)+Math.log1p(41/w)],[l,h]=u(0,a),[f,p]=u(c,s),M=i?Math.min(l,f):Math.max(Math.min(l,f),-740-Math.log(a)),N=Math.max(h,p),g=1/Math.sqrt(a),I=1/Math.sqrt(s),d=[M,Math.min(-4*g,c-4*I),Math.max(4*g,c+4*I),N];return[...new Set(d.map(m=>Math.min(Math.max(m,M),N)))].sort((m,w)=>m-w)}function cn(t,e,n){return t>=2&&e>=2&&n>=1&&Number.isFinite(t)&&Number.isFinite(n)&&!Number.isNaN(e)}function ft(t,e,n,r,o,i){if(t<$e){let s=ft($e,e,n,r,!0,!0)+(e-1)*r*Math.log(t*10715086071862673e285);return o?i?s:Math.exp(s):i?-Math.exp(s):-Math.expm1(s)}let a;return K!==void 0&&K.q===t&&K.k===e&&K.df===n&&K.r===r?a=K.tail:(a=br(t,e,n,r,!o),K={q:t,k:e,df:n,r,tail:a}),a.upper===!o?i?a.log:a.value:i?Math.log1p(-a.value):1-a.value}var K,$e=2**-1e3;function br(t,e,n,r,o){let i=o;n!==1/0&<(t,e,r,i)>.5&&(i=!i);let a=Wt(t,e,n,r,i);if(a>.5){let s=Wt(t,e,n,r,!i);s<a&&(a=s,i=!i)}if(a<1e-290){let s=Nr(t,e,n,r,i);return{upper:i,value:Math.exp(s),log:s}}return{upper:i,value:a,log:Math.log(a)}}function wr(t,e,n,r,o,i){return[t,e,n,r].some(Number.isNaN)?NaN:cn(e,n,r)?t<=0?S(o,i):t===1/0?T(o,i):ft(t,e,n,r,o,i):NaN}function xr(t,e,n,r,o,i){if([t,e,n,r].some(Number.isNaN))return NaN;if(!cn(e,n,r))return NaN;let a=L(t,0,1/0,o,i);if(a!==void 0)return a;let{lower:s,logTarget:c,linearTarget:u}=Jt(t,o,i),l=f=>p=>{let M=Math.exp(p);if(u!==void 0&&u>1e-290){let g=f===1/0?Wt(M,e,f,r,!s):ft(M,e,f,r,s,!1);if(g>0)return Math.log(g/u)}return(f===1/0?Er(M,e,r,s):ft(M,e,f,r,s,!0))-c},h=Oe(l(1/0),Math.log(3),s);return Math.exp(n===1/0?h:Oe(l(n),h,s))}function Er(t,e,n,r){let o=lt(t,e,n,!r);return o>1e-290?Math.log(o):qt(t,e,n,!r)}function Oe(t,e,n){let r=e,o=t(r);if(o===0)return r;let i=o>0===n?-1:1,a=.05,s=r+i*a,c=t(s),u=NaN;for(let l=0;l<200&&Math.sign(c)===Math.sign(o)&&c!==0;l++){if(Math.abs(u-s)<.001)return s;for(r=s,o=c,a*=2,s=(r+i*a-u)*i>=0?.5*(r+u):r+i*a,c=t(s);!Number.isFinite(c);){if(u=s,Math.abs(u-r)<.001)return r;s=.5*(r+u),c=t(s)}}return c===0?s:!Number.isFinite(c)||Math.sign(c)===Math.sign(o)?Number.isFinite(c)?s:r:yr(t,r,s,o,c)}function yr(t,e,n,r,o){let i=e,a=r,s=n-e,c=s;for(let u=0;u<100;u++){Math.sign(o)===Math.sign(a)&&(i=e,a=r,s=n-e,c=s),Math.abs(a)<Math.abs(o)&&(e=n,n=i,i=e,r=o,o=a,a=r);let l=2*et*Math.abs(n)+1e-300,h=.5*(i-n);if(Math.abs(h)<=l||o===0)return n;if(Math.abs(c)>=l&&Math.abs(r)>Math.abs(o)){let f=o/r,p,M;if(e===i)p=2*h*f,M=1-f;else{let N=r/a,g=o/a;p=f*(2*h*N*(N-g)-(n-e)*(g-1)),M=(N-1)*(g-1)*(f-1)}p>0?M=-M:p=-p,2*p<Math.min(3*h*M-Math.abs(l*M),Math.abs(c*M))?(c=s,s=p/M):(s=h,c=h)}else s=h,c=h;e=n,r=o,n+=Math.abs(s)>l?s:h>0?l:-l,o=t(n)}return n}function Ro(t,e,n,r={}){y(r,Zn,"ptukey");let{nranges:o=1,lowerTail:i=!0,logP:a=!1}=r;return E(t,s=>wr(s,e,n,o,i,a))}function So(t,e,n,r={}){y(r,zn,"qtukey");let{nranges:o=1,lowerTail:i=!0,logP:a=!1}=r;return E(t,s=>xr(s,e,n,o,i,a))}function Xt(t){let e=[],n=[];for(let r=1;r<=t/2;r++){let o=Math.cos(Math.PI*(r-.25)/(t+.5)),i=0;for(let a=0;a<100;a++){let s=1,c=o;for(let l=2;l<=t;l++)[s,c]=[c,((2*l-1)*o*c-(l-1)*s)/l];i=t*(o*c-s)/(o*o-1);let u=c/i;if(o-=u,Math.abs(u)<=1e-17)break}e.push(o),n.push(2/((1-o*o)*i*i))}return{x:e,w:n}}var Ir=[Xt(6),Xt(12),Xt(20)],Bt=2*Math.PI,Y=t=>R(t,{lowerTail:!1});function vr(t,e,n){if(n===1)return Y(Math.max(t,e));if(n===-1)return t>=-e?0:t>=0?Y(t)-Y(-e):R(-e)-R(t);let{x:r,w:o}=Ir[Math.abs(n)<.3?0:Math.abs(n)<.75?1:2],i=t*e;if(Math.abs(n)<.925){let g=(t*t+e*e)/2,I=Math.asin(n),d=0;for(let m=0;m<r.length;m++)for(let w of[1-r[m],1+r[m]]){let _=Math.sin(I*w/2);d+=o[m]*Math.exp((_*i-g)/(1-_*_))}return d*I/(2*Bt)+Y(t)*Y(e)}let a=n<0?-e:e,s=n<0?-i:i,c=(1-n)*(1+n),u=Math.sqrt(c),l=(t-a)**2,h=(4-s)/8,f=(12-s)/16,p=u*Math.exp(-(l/c+s)/2)*(1-h*(l-c)*(1-f*l/5)/3+h*f*c*c/5);if(s>-160){let g=Math.sqrt(l);p-=Math.exp(-s/2)*Math.sqrt(Bt)*R(-g/u)*g*(1-h*l*(1-f*l/5)/3)}let M=u/2;for(let g=0;g<r.length;g++)for(let I of[1-r[g],1+r[g]]){let d=(M*I)**2,m=Math.sqrt(1-d);p+=M*o[g]*(Math.exp(-l/(2*d)-s/(1+m))/m-Math.exp(-(l/d+s)/2)*(1+h*d*(1+f*d)))}let N=-p/Bt;return n>0?N+Y(Math.max(t,a)):-N+(a>t?R(a)-R(t):0)}function mt(t,e,n){return t===1/0||e===1/0?0:t===-1/0?e===-1/0?1:Y(e):e===-1/0?Y(t):vr(t,e,n)}function Co(t,e,n){if(t.length!==2||e.length!==2)throw new TypeError("'lower' and 'upper' must have length 2");if(!(n>=-1&&n<=1))throw new RangeError("'rho' must be in [-1, 1]");let[r,o]=t,[i,a]=e;if([r,o,i,a].some(Number.isNaN))return NaN;if([r,o,i,a]=[r,o,i,a].map(c=>c>40?1/0:c<-40?-1/0:c),!(r<i&&o<a))return 0;r+i+o+a<0&&([r,o,i,a]=[-i,-a,-r,-o]);let s=mt(r,o,n)-mt(r,a,n)-mt(i,o,n)+mt(i,a,n);return Math.max(0,s)}var _r=["size","replace","prob"],Ar=["size","replace","prob"];function $o(t,e={}){return y(e,Ar,"sampleInt"),un(t,e).map(n=>n-1)}function un(t,e){if(!Number.isFinite(t)||t<0||t>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");t=Math.trunc(t);let{replace:n=!1,prob:r}=e,o=e.size!==void 0,i=o?e.size:t;if(!Number.isFinite(i)||i<=-1)throw new RangeError("size must be a non-negative number");let a=Math.trunc(i);if(t===0&&a>0)throw new RangeError("cannot take a sample from an empty population");if(r!==void 0){if(a>=2**31)throw new RangeError("size must be less than 2^31 with prob");if(t>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(r.length!==t)throw new TypeError("prob must have length n");let l=fn(r,a,n);if(n){let h=ln(l),f=new Array(a);for(let p=0;p<a;p++)f[p]=h();return f}if(a>t)throw new RangeError("cannot take a sample larger than the population when replace is false");return Tr(l,a)}if(!n&&a>t)throw new RangeError("cannot take a sample larger than the population when replace is false");if(!n&&t>1e7&&o&&a<=t/2){let l=new Set,h=[];for(;h.length<a;){let f=J(t);l.has(f)||(l.add(f),h.push(f+1))}return h}let s=new Array(a);if(n||a<2){for(let l=0;l<a;l++)s[l]=J(t)+1;return s}if(t>=2**31)throw new RangeError("n must be less than 2^31 to sample without replacement with size above n / 2");let c=new Int32Array(t);for(let l=0;l<t;l++)c[l]=l;let u=t;for(let l=0;l<a;l++){let h=J(u);s[l]=c[h]+1,c[h]=c[--u]}return s}function Oo(t,e){if(!Number.isFinite(t)||t<0||t>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");if(t=Math.trunc(t),t>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(e.length!==t)throw new TypeError("prob must have length n");let n=ln(fn(e,0,!0));return()=>n()-1}function ln(t){let e=t.length,n=0;for(let r=0;r<e;r++)e*t[r]>.1&&n++;return n>200?Pr(t):Sr(t)}function Do(t,e={}){return y(e,_r,"sample"),un(t.length,e).map(n=>t[n-1])}function fn(t,e,n){let r=0,o=0;for(let i of t){if(!Number.isFinite(i))throw new RangeError("prob contains NaN or infinite values");if(i<0)throw new RangeError("prob contains negative values");i>0&&(o++,r+=i)}if(o===0||!n&&e>o)throw new RangeError("too few positive probabilities");if(r===1/0){let i=fe(t);r=0;for(let a of t)r+=a/i;return Float64Array.from(t,a=>a/i/r)}return Float64Array.from(t,i=>i/r)}function Rr(t,e){let n=t.length;if(n<=1)return;let r=c=>t[c-1],o=(n>>1)+1,i=n,a,s;for(;;){if(o>1)o=o-1,a=r(o),s=e[o-1];else if(a=r(i),s=e[i-1],t[i-1]=r(1),e[i-1]=e[0],--i===1){t[0]=a,e[0]=s;return}let c=o,u=o<<1;for(;u<=i;)u<i&&r(u)>r(u+1)&&++u,a>r(u)?(t[c-1]=r(u),e[c-1]=e[u-1],c=u,u+=u):u=i+1;t[c-1]=a,e[c-1]=s}}function hn(t){let e=new Int32Array(t.length);for(let n=0;n<t.length;n++)e[n]=n+1;return Rr(t,e),e}function Sr(t){let e=Float64Array.from(t),n=e.length,r=hn(e);for(let o=1;o<n;o++)e[o]+=e[o-1];return()=>{let o=q(),i=0;for(;i<n-1&&!(o<=e[i]);i++);return r[i]}}function Tr(t,e){let n=Float64Array.from(t),r=n.length,o=hn(n),i=new Array(e),a=1;for(let s=0,c=r-1;s<e;s++,c--){let u=a*q(),l=0,h=0;for(;h<c&&(l+=n[h],!(u<=l));h++);i[s]=o[h],a-=n[h];for(let f=h;f<c;f++)n[f]=n[f+1],o[f]=o[f+1]}return i}function Pr(t){let e=t.length,n=new Float64Array(e),r=new Int32Array(e),o=new Int32Array(e),i=-1,a=e;for(let c=0;c<e;c++)n[c]=t[c]*e,n[c]<1?o[++i]=c:o[--a]=c;if(i>=0&&a<e)for(let c=0;c<e-1;c++){let u=o[c],l=o[a];if(r[u]=l,n[l]+=n[u]-1,n[l]<1&&a++,a>=e)break}let s=he();return()=>{let c,u;return s?(u=q()*e,c=Math.trunc(u)):(c=J(e),u=c+q()),u<n[c]+c?c+1:r[c]+1}}var Cr=2**24;function Fr(t){let e=new Float64Array(t+1);for(let n=2;n<=t;n++)e[n]=e[n-1]+Math.log(n);return e}function Lr(t,e,n,r){let o=t.length,i=e.length,a=Array.from(e),s=0;for(let u of t)s+=u;for(let u=0;u<o-1;u++){let l=t[u],h=s;s-=l;let f=0;for(;f<i-1;f++){let p=a[f],M=h;h-=p;let N=M-l,g=N-p;if(M===0){for(let m=f;m<i-1;m++)r[u+m*o]=0;l=0;break}let I=q(),d;t:for(;;){d=Math.floor(l*(p/M)+.5);let m=Math.exp(n[l]+n[N]+n[h]+n[p]-n[M]-n[d]-n[p-d]-n[l-d]-n[g+d]);if(m>=I)break;if(m===0)throw new Error(`r2dtable: probability underflow at cell [${u}, ${f}]`);let w=m,_=m,b=d,x=!1,P=!1;for(;!(x&&P);){if(!x){let A=(p-d)*(l-d);if(A===0)x=!0;else if(d++,m=m*A/(d*(g+d)),w+=m,w>=I)break t}do{let A=b*(g+b);if(A===0){P=!0;break}if(b--,_=_*A/((p-b)*(l-b)),w+=_,w>=I){d=b;break t}}while(x)}I=w*q()}r[u+f*o]=d,l-=d,a[f]=a[f]-d}r[u+(i-1)*o]=l}let c=e[i-1];for(let u=0;u<o-1;u++)c-=r[u+(i-1)*o];for(let u=0;u<i-1;u++)r[o-1+u*o]=a[u];r[o-1+(i-1)*o]=c}function Mn(t,e){let n=Array.from(t,r=>Math.trunc(r));if(n.length<=1||n.some(r=>!(r>=0)||r>2147483647))throw new RangeError(`invalid argument '${e}'`);return n}function Ho(t,e,n){if(!(Number.isFinite(t)&&t>-1&&t<2**31))throw new RangeError("invalid argument 'n'");let r=Math.trunc(t),o=Mn(e,"r"),i=Mn(n,"c"),a=o.reduce((l,h)=>l+h,0);if(a!==i.reduce((l,h)=>l+h,0))throw new RangeError("arguments 'r' and 'c' must have the same sums");if(a>2147483647)throw new RangeError("the sum of 'r' must be at most 2147483647");if(r===0)return[];if(a>Cr)throw new RangeError("the sum of 'r' must be at most 16777216 (2^24) to generate tables");let s=Fr(a),c=new Int32Array(o.length*i.length),u=[];for(let l=0;l<r;l++)Lr(o,i,s,c),u.push(o.map((h,f)=>i.map((p,M)=>c[f+M*o.length])));return u}export{Dr as a,Yr as b,Kr as c,En as d,xt as e,In as f,Rn as g,Jr as h,kr as i,to as j,Wn as k,$n as l,co as m,uo as n,lo as o,Gn as p,Un as q,Vn as r,bo as s,wo as t,xo as u,Ro as v,So as w,Co as x,$o as y,Oo as z,Do as A,Cr as B,Fr as C,Lr as D,Ho as E};
|
|
1
|
+
/*! rStats.js 1.2.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{f as q,g as he,h as J}from"./chunk-NSU6U3ET.js";import{A as ue,B as le,a as ie,b as ae,c as se,f as j,z as ce}from"./chunk-A66M3ZEA.js";import{a as S,b as T,c as C,d as L,e as Jt,h as ne,i as re,l as oe}from"./chunk-RRO4LMCB.js";import{a as fe}from"./chunk-IMPRIQE5.js";import{a as F,b as Q,c as v}from"./chunk-2NNBUYHJ.js";import{A as kt,B as te,E as ee,e as E,r as R,s as B}from"./chunk-7WG7X2UI.js";import{b as Ut,c as Nt,d as ot,e as Vt,f as Zt,g as z,i as it,k as zt,l as y}from"./chunk-TNETWBF5.js";var gn=["log","ncp"],dn=["lowerTail","logP","ncp"],Nn=["lowerTail","logP","ncp"];function Dr(t,e,n={}){y(n,gn,"dchisq");let{log:r=!1,ncp:o}=n;if(o!==void 0)return E(t,a=>ie(a,e,o,r));let i=e<0?NaN:e/2;return E(t,a=>ne(a,i,2,r))}function Yr(t,e,n={}){y(n,dn,"pchisq");let{lowerTail:r=!0,logP:o=!1,ncp:i}=n;if(i!==void 0)return E(t,s=>ae(s,e,i,r,o));let a=e<0?NaN:e/2;return E(t,s=>re(s,a,2,r,o))}function Kr(t,e,n={}){y(n,Nn,"qchisq");let{lowerTail:r=!0,logP:o=!1,ncp:i}=n;if(i!==void 0)return E(t,s=>se(s,e,i,r,o));let a=e<0?NaN:e/2;return E(t,s=>oe(s,a,2,r,o))}var bn=["log"],wn=["lowerTail","logP"],xn=["lowerTail","logP"];function bt(t,e,n,r){if(t===0&&e===0)return{e:[0,0],logDenom:0};if(t===0||e===0){let o=t+e,[i,a]=t===0?[r,n]:[n,r];return{e:a[0]<.1?ot(te(o,z([o,0],i)),z([o,0],a)):Vt(z([o,0],zt(i))),logDenom:0}}return ee(t,e,n,r)}function ge(t,e,n,r){let o=e+n,i=it([r,0],[o,0]),a=it([o-r,0],[o,0]),s=bt(t,e-t,i,a),c=bt(r-t,n-r+t,i,a),u=bt(r,o-r,i,a);return{e:Zt(ot(s.e,c.e),u.e),logDenom:s.logDenom+c.logDenom-u.logDenom}}function de(t,e){let[n,r]=t.e,o=e*Math.exp(-.5*t.logDenom);return n<700?Math.exp(-n)*(1-r)*o:Math.exp(700-n)*(1-r)*o*Math.exp(-700)}function Ne(t){return-t.e[0]-t.e[1]-.5*t.logDenom}function wt(t,e){return Ut(t,e)[1]===0}function at(t,e,n){return[Math.max(0,n-e),Math.min(n,t)]}function En(t,e,n,r,o){if([t,e,n,r].some(Number.isNaN))return NaN;if(![e,n,r].every(Number.isFinite)||F(e)||F(n)||F(r))return NaN;if(e=v(e),n=v(n),r=v(r),e<0||n<0||r<0||r>e+n)return NaN;if(Et(e,n,r))return ce(t,r,xt(e,n),o);if(F(t))return C(o);t=v(t);let[i,a]=at(e,n,r);if(t<i||t>a)return C(o);if(r===0)return o?0:1;if(!wt(e,n))return NaN;if(r===e+n)return o?0:1;let s=ge(t,e,n,r);return o?Ne(s):de(s,1)}function Me(t,e,n,r){return it(Nt(t,e),Nt(n,r))}function yn(t,e,n,r,o,i,a){let s=[1,0],c=[1,0],u=t;for(;!(o?u<=i:u>=a);){let l=o?Me(u,n-r+u,e-u+1,r-u+1):Me(e-u,r-u,u+1,n-r+u+1);s=z(s,l),c=ot(c,s),u+=o?-1:1;let h=l[0];if(h<1&&s[0]*h/(1-h)<c[0]*2**-60)break}return c[0]+c[1]}function be(t,e,n,r,o,i){let[a,s]=at(e,n,r),c=e+n,u=t*c<r*e,l=pe(t,e,n,r,u,a,s);if(l.value>.5){let h=pe(t,e,n,r,!u,a,s);h.value<l.value&&(l=h,u=!u)}return u===o?i?l.value>1e-300?Math.log(l.value):Ne(l.form)+Math.log(l.sum):l.value:i?Math.log1p(-l.value):1-l.value}function pe(t,e,n,r,o,i,a){let s=o?t:t+1,c=ge(s,e,n,r),u=yn(s,e,n,r,o,i,a);return{form:c,sum:u,value:de(c,u)}}function xt(t,e){return t>=e?1/(1+e/t):e/t===1/0?0:t/e/(1+t/e)}function Et(t,e,n){return n>0&&n<t*2**-60+e*2**-60}function we(t,e,n){if([t,e,n].every(Number.isFinite)&&(t=v(t),e=v(e),n=v(n),!(t<0||e<0||n<0||n>t+e)))return[t,e,n]}function In(t,e,n,r,o,i){if([t,e,n,r].some(Number.isNaN))return NaN;let a=we(e,n,r);if(a===void 0)return NaN;if([e,n,r]=a,Et(e,n,r))return ue(t,r,xt(e,n),o,i);let s=Q(t),[c,u]=at(e,n,r);if(s<c)return S(o,i);if(s>=u)return T(o,i);if(u>Ee||!wt(e,n))return NaN;let l=vn(s,e,n,r,c,u);if(l>_n)throw new RangeError(`phyper: m = ${e}, n = ${n}, k = ${r} needs about ${Math.round(l)} terms at q = ${t} (at most 2^26)`);return be(s,e,n,r,o,i)}function xe(t,e,n,r){return n*t/r*(e/r)*(r-n)/Math.max(r-1,1)}function me(t,e,n,r,o,i){let a=e?n-t:t-n,s=Math.sqrt(a*a+83*r);return Math.min(a>=0?83*r/(s+a):s-a,e?t-o:i-t)}function vn(t,e,n,r,o,i){let a=e+n,s=r*e/a,c=xe(e,n,r,a),u=t*a<r*e,l=u?t:t+1,h=me(l,u,s,c,o,i);return Math.abs(l-s)>=1?h:h+me(u?t+1:t,!u,s,c,o,i)}var _n=2**26,An=2**21,Ee=2**53;function Rn(t,e,n,r,o,i,a=!0){if([t,e,n,r].some(Number.isNaN))return NaN;let s=we(e,n,r);if(s===void 0)return NaN;if([e,n,r]=s,Et(e,n,r))return le(t,r,xt(e,n),o,i);let[c,u]=at(e,n,r),l=L(t,c,u,o,i);if(l!==void 0)return l;if(c===u)return c;if(u>Ee||!wt(e,n))return NaN;let h=e+n,f=r*e/h,p=Math.sqrt(xe(e,n,r,h));if(a&&p>An)throw new RangeError(`qhyper: m = ${e}, n = ${n}, k = ${r} has a standard deviation of about ${p.toPrecision(3)} (at most 2^21)`);let M=B(t,{lowerTail:o,logP:i}),N=f+p*M;return j({p:t,lowerTail:o,logP:i,cdf:(g,I,d)=>g<c?S(I,d):g>=u?T(I,d):be(g,e,n,r,I,d),y0:Number.isFinite(N)?N:f,lo:c,hi:u})}function Jr(t,e,n,r,o={}){y(o,bn,"dhyper");let i=o.log??!1;return E(t,a=>En(a,e,n,r,i))}function kr(t,e,n,r,o={}){y(o,wn,"phyper");let{lowerTail:i=!0,logP:a=!1}=o;return E(t,s=>In(s,e,n,r,i,a))}function to(t,e,n,r,o={}){y(o,xn,"qhyper");let{lowerTail:i=!0,logP:a=!1}=o;return E(t,s=>Rn(s,e,n,r,i,a))}var Sn=["log"],Tn=["lowerTail","logP"],Pn=["lowerTail","logP"],Cn=2**900,ye=-900,W=new Map,Fn=2**21,st=0,Ln=2**25;function ve(t,e){if(e+1>Ln)throw new RangeError(`signrank: n = ${t} needs too large a table (${e+1} entries)`);let n=new Float64Array(e+1);n[0]=1;let r=0,o=-1/0,i=Math.min(t,e);for(let u=1;u<=i;u++){for(let l=e;l>=u;l--)n[l]+=n[l-u];if(n[Math.min(e,Math.floor(u*(u+1)/4))]>Cn){let l=2**ye;for(let h=0;h<=e;h++)n[h]*=l;r-=ye,o=Math.max(o,r-1015+i-u)}}let a=new Float64Array(e+1),s=0,c=0;for(let u=0;u<=e;u++){let l=n[u]-c,h=s+l;c=h-s-l,s=h,a[u]=s}return{n:t,len:e+1,count:n,cum:a,scale:r,minTrusted:2**(o-r)}}function Ie(t,e,n=!1){let r=n?-t:t,o=W.get(r);if(o!==void 0&&o.len>e)return W.delete(r),W.set(r,o),o;let i=Math.floor(t*(t+1)/4),a=Math.min(i,Math.max(e,o===void 0?0:2*o.len));return _e(r,ve(t,a),o)}function _e(t,e,n){n!==void 0&&(W.delete(t),st-=n.len),W.set(t,e),st+=e.len;for(let[r,o]of W){if(st<=Fn||r===t)break;W.delete(r),st-=o.len}return e}function yt(t,e,n){let r=(a,s)=>e===a.len-1||s>=(n?(e+1)*a.minTrusted:a.minTrusted),o=Ie(t,e),i=(n?o.cum:o.count)[e];return r(o,i)?[i,o]:(o=Ie(t,e,!0),i=(n?o.cum:o.count)[e],r(o,i)?[i,o]:(o=_e(-t,ve(t,e),W.get(-t)),[(n?o.cum:o.count)[e],o]))}function It(t,e,n){let r=e.scale-e.n,o=Math.trunc(r/2),i=t*2**o*2**(r-o);if(!n)return i;if(i>=1e-300)return Math.log(i);let a=Math.floor(Math.log2(t)),s=Math.trunc(a/2),c=t*2**-s*2**-(a-s);return c>=2?(c/=2,a++):c<1&&(c*=2,a--),Math.log(c)+(a+r)*Math.LN2}function vt(t){return Number.isFinite(t)?(t=v(t),t<=0||t>=2**27?NaN:t):NaN}function qn(t,e,n){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;if(F(t))return C(n);t=v(t);let r=e*(e+1)/2;if(t<0||t>r)return C(n);let o=Math.min(t,r-t),[i,a]=yt(e,o,!1);return It(i,a,n)}function Ae(t,e,n,r){let o=e*(e+1)/2,i=t,a=o-t-1,s=n?i:a,c=n?a:i;if(s<=c){let[f,p]=yt(e,s,!0);return It(f,p,r)}let[u,l]=yt(e,c,!0),h=It(u,l,!1);return r?Math.log1p(-h):1-h}function Wn(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;let o=Q(t),i=e*(e+1)/2;return o<0?S(n,r):o>=i?T(n,r):Ae(o,e,n,r)}function $n(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;let o=e*(e+1)/2,i=L(t,0,o,n,r);if(i!==void 0)return i;let a=o/2,s=Math.sqrt(e*(e+1)*(2*e+1)/24),c=a+s*B(t,{lowerTail:n,logP:r});return j({p:t,lowerTail:n,logP:r,cdf:(u,l,h)=>u<0?S(l,h):u>=o?T(l,h):Ae(u,e,l,h),y0:Number.isFinite(c)?c:a,lo:0,hi:o})}function co(t,e,n={}){y(n,Sn,"dsignrank");let r=n.log??!1;return E(t,o=>qn(o,e,r))}function uo(t,e,n={}){y(n,Tn,"psignrank");let{lowerTail:r=!0,logP:o=!1}=n;return E(t,i=>Wn(i,e,r,o))}function lo(t,e,n={}){y(n,Pn,"qsignrank");let{lowerTail:r=!0,logP:o=!1}=n;return E(t,i=>$n(i,e,r,o))}var On=["log"],Dn=["lowerTail","logP"],Yn=["lowerTail","logP"],Re=960,Se=2**996,Kn=2**25,Fe=2**29,Hn=2**760,Te=200,Xn=2**-969,ct=134217729,$=new Map,Bn=2**21,ut=0;function Le(t,e,n){if(n+1>Kn)throw new RangeError(`wilcox: m = ${t}, n = ${e} needs too large a table (${n+1} entries)`);if(t*(n+1)>Fe)throw new RangeError(`wilcox: m = ${t}, n = ${e} needs ${t*(n+1)} steps for a table of ${n+1} entries (at most 2^29)`);let r=new Float64Array(n+1),o=new Float64Array(n+1);r[0]=2**Re;let i=Re,a=NaN,s=n+1;for(let f=1;f<=t;f++){let p=Math.min(s-1,f*e),M=e+f,N=ct*f,g=N-(N-f),I=f-g;N=ct*M;let d=N-(N-M),m=M-d;for(let b=0;b<=p;b++){let x=r[b];if(x===0)continue;if(!(Math.abs(x)<=Se)){s=b,p=b-1;break}let P=x*f;N=ct*x;let A=N-(N-x),H=x-A,pn=A*g-P+A*I+H*g+H*I+o[b]*f,X=P/M,Qt=X*M;N=ct*X;let gt=N-(N-X),jt=X-gt,mn=gt*d-Qt+gt*m+jt*d+jt*m,Gt=(P-Qt-mn+pn)/M,dt=X+Gt;o[b]=Gt-(dt-X),r[b]=dt,Math.abs(dt)<Xn&&Number.isNaN(a)&&(a=i)}let w=e+f;for(let b=p;b>=w;b--)Pe(r,o,b,b-w,-1);for(let b=f;b<=p;b++)Pe(r,o,b,b-f,1);let _=Math.min(p,Math.floor(f*e/2));for(;_>=0&&r[_]>0&&r[_]<Hn;){let b=2**Te;for(let x=0;x<=p;x++)r[x]*=b,o[x]*=b;i+=Te}}let c=new Float64Array(n+1),u=0,l=0;for(let f=0;f<s;f++){let p=r[f];if(!(Math.abs(p)<=Se)){s=f;break}let M=u+p,N=M-u,g=u-(M-N)+(p-N);g+=l+o[f],u=M+g,l=g-(u-M),c[f]=u}let h=Number.isNaN(a)?0:2**Math.min(1023,-909+Math.ceil(Math.log2(t*(n+1)))+i-a);return{m:t,n:e,len:n+1,prob:r,cum:c,scale:i,minTrusted:h,valid:s}}function Pe(t,e,n,r,o){let i=t[n],a=o*t[r],s=i+a,c=s-i,u=i-(s-c)+(a-c);u+=e[n]+o*e[r];let l=s+u;e[n]=u-(l-s),t[n]=l}function Ce(t,e,n,r=!1){let o=`${t},${e}${r?",low":""}`,i=$.get(o);if(i!==void 0&&i.len>n)return $.delete(o),$.set(o,i),i;let a=Math.floor(t*e/2),s=i===void 0?0:Math.min(2*i.len,Math.floor(Fe/t)-1),c=Math.min(a,Math.max(n,s));return qe(o,Le(t,e,c),i)}function qe(t,e,n){n!==void 0&&($.delete(t),ut-=n.len),$.set(t,e),ut+=e.len;for(let[r,o]of $){if(ut<=Bn||r===t)break;$.delete(r),ut-=o.len}return e}function _t(t,e,n,r){t>e&&([t,e]=[e,t]);let o=u=>{if(n>=u.valid)throw new RangeError(`wilcox: the exact distribution for m = ${t}, n = ${e} cannot be computed accurately at ${n} (from ${u.valid} on, near the center of large samples)`);return(r?u.cum:u.prob)[n]},i=(u,l)=>n===u.len-1||l>=(r?(n+1)*u.minTrusted:u.minTrusted),a=Ce(t,e,n),s=o(a);if(i(a,s))return[s,a];if(a=Ce(t,e,n,!0),s=o(a),i(a,s))return[s,a];let c=`${t},${e},low`;return a=qe(c,Le(t,e,n),$.get(c)),[o(a),a]}var Qn=.6931471803691238,jn=19082149292705877e-26;function At(t,e,n){let r=-e.scale,o=Math.trunc(r/2),i=t*2**o*2**(r-o);if(!n)return i;if(i>=1e-300)return Math.log(i);let a=Math.floor(Math.log2(t)),s=Math.trunc(a/2),c=t*2**-s*2**-(a-s);return c>=2?(c/=2,a++):c<1&&(c*=2,a--),(a+r)*Qn+(Math.log(c)+(a+r)*jn)}function Rt(t,e){if(!(!Number.isFinite(t)||!Number.isFinite(e))&&(t=v(t),e=v(e),!(t<=0||e<=0||t*e>2**53)))return t*e===2**53&&BigInt(t)*BigInt(e)!==2n**53n?void 0:[t,e]}function Gn(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let o=Rt(e,n);if(o===void 0)return NaN;if([e,n]=o,F(t))return C(r);t=v(t);let i=e*n;if(t<0||t>i)return C(r);let a=Math.min(t,i-t),[s,c]=_t(e,n,a,!1);return At(s,c,r)}function We(t,e,n,r,o){let i=e*n,a=r?t:i-t-1,s=r?i-t-1:t;if(a<=s){let[h,f]=_t(e,n,a,!0);return At(h,f,o)}let[c,u]=_t(e,n,s,!0),l=At(c,u,!1);return o?Math.log1p(-l):1-l}function Un(t,e,n,r,o){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let i=Rt(e,n);if(i===void 0)return NaN;[e,n]=i;let a=Q(t);return a<0?S(r,o):a>=e*n?T(r,o):We(a,e,n,r,o)}function Vn(t,e,n,r,o){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let i=Rt(e,n);if(i===void 0)return NaN;[e,n]=i;let a=e*n,s=L(t,0,a,r,o);if(s!==void 0)return s;let c=a/2,u=Math.sqrt(a*(e+n+1)/12),l=c+u*B(t,{lowerTail:r,logP:o});return j({p:t,lowerTail:r,logP:o,cdf:(h,f,p)=>h<0?S(f,p):h>=a?T(f,p):We(h,e,n,f,p),y0:Number.isFinite(l)?l:c,lo:0,hi:a})}function bo(t,e,n,r={}){y(r,On,"dwilcox");let o=r.log??!1;return E(t,i=>Gn(i,e,n,o))}function wo(t,e,n,r={}){y(r,Dn,"pwilcox");let{lowerTail:o=!0,logP:i=!1}=r;return E(t,a=>Un(a,e,n,o,i))}function xo(t,e,n,r={}){y(r,Yn,"qwilcox");let{lowerTail:o=!0,logP:i=!1}=r;return E(t,a=>Vn(a,e,n,o,i))}var Zn=["nranges","lowerTail","logP"],zn=["nranges","lowerTail","logP"],D=128,et=Number.EPSILON,Jn=256,$t=Float64Array.from({length:2*D+1},(t,e)=>Math.cos(Math.PI*e/D));function kn(t){let e=new Float64Array(t+1);for(let n=0;n<=t;n++){let r=0;for(let o=0;o<=t;o+=2)r+=(o===0||o===t?.5:1)*$t[o*n%(2*t)*(D/t)]*2/(1-o*o);e[n]=(n===0||n===t?.5:1)*2*r/t}return e}var tr=new Map([16,32,64,128].map(t=>[t,kn(t)]));function er(t,e){let n=tr.get(e),r=D/e,o=0,i=0;for(let s=0;s<=e;s++)o+=n[s]*t[s],i+=Math.abs(n[s]*t[s]);let a=0;for(let s=e-7;s<=e;s++){let c=.5*(t[0]+(s%2===0?t[e]:-t[e]));for(let u=1;u<e;u++)c+=t[u]*$t[s*u%(2*e)*r];c*=2/e,s===e&&(c*=.5),a=Math.max(a,Math.abs(c))}return{integral:o,tail:a,scale:i}}var tt=class{f;a;b;noise;c;h;values=new Float64Array(D+1);have=new Uint8Array(D+1);N=0;integral=0;error=1/0;constructor(e,n,r,o){this.f=e,this.a=n,this.b=r,this.noise=o,this.c=.5*(n+r),this.h=.5*(r-n)}advance(e){let n=D/e,r=new Float64Array(e+1);for(let i=0;i<=e;i++){let a=i*n;this.have[a]||(this.values[a]=this.f(this.c+this.h*$t[a]),this.have[a]=1),r[i]=this.values[a]}let o=er(r,e);this.N=e,this.integral=o.integral*this.h,this.error=Math.max(o.tail*4/e,this.noise*o.scale)*Math.abs(this.h)}};function ht(t,e,n,r=4*et){let o=[];for(let a=0;a+1<e.length;a++){let s=new tt(t,e[a],e[a+1],r);s.advance(16),o.push(s)}for(let a=0;a<40;a++){let s=0;for(let f of o)s+=f.integral;let c=n*Math.abs(s)/o.length,u=!0,l=o.length,h=[];for(let f of o){if(f.error<=c||f.error<=r*Math.abs(f.integral)){h.push(f);continue}if(u=!1,f.N<D)f.advance(2*f.N),h.push(f);else if(l>=Jn)h.push(f);else{l++;let p=new tt(t,f.a,f.c,r),M=new tt(t,f.c,f.b,r);p.advance(16),M.advance(16),h.push(p,M)}}if(o=h,u)break}let i=0;for(let a of o)i+=a.integral;return i}function De(t,e,n){let r=Math.max(1,Math.ceil((e-t)/n));return Array.from({length:r+1},(o,i)=>i===r?e:t+(e-t)*i/r)}var Ye=2e-15,Ke=1e-16,nr={lowerTail:!1},rr={logP:!0},or={lowerTail:!1,logP:!0},rt=.9189385332046728,Mt=t=>R(t),U=t=>R(t,nr),Ot=t=>R(t,rr),Dt=t=>R(t,or),ir=.3989422804014327;function V(t){let e=Math.round(t*16)/16,n=t-e;return ir*Math.exp(-.5*e*e)*Math.exp(-.5*n*(t+e))}var Pt=[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],He=[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626];function ar(t,e){let n=t-.5*e,r=.5*e,o=0;for(let i=0;i<4;i++)o+=He[i]*(V(n-r*Pt[i])+V(n+r*Pt[i]));return o*r}function sr(t,e){let n=t-.5*e,r=.5*e,o=0;for(let i=0;i<4;i++){let a=r*Pt[i];o+=He[i]*(Math.exp(n*a-a*a/2)+Math.exp(-n*a-a*a/2))}return-rt-n*n/2+Math.log(o*r)}var Yt=(t,e)=>e*Math.max(1,Math.abs(t),Math.abs(t-e))<.5;function Z(t,e){let n=t-e,r=n-t,o=t-(n-r)+(-e-r);return{ah:n,al:o}}function nt(t,e){return Mt(t)+V(t)*e}function cr(t,e){return U(t)-V(t)*e}function Xe(t,e){if(Yt(t,e))return ar(t,e);let{ah:n,al:r}=Z(t,e);return n>=0?cr(n,r)-U(t):t<=0?Mt(t)-nt(n,r):1-nt(n,r)-U(t)}function ur(t,e,n){if(t>0&&t-e<0&&!Yt(t,e)){let{ah:o,al:i}=Z(t,e);return Math.exp(n*Math.log1p(-(nt(o,i)+U(t))))}let r=Xe(t,e);return r>0?r**n:0}function lr(t,e){return t>0?Math.exp(e*Math.log1p(-U(t))):Mt(t)**e}function Be(t,e){let{ah:n,al:r}=Z(t,e),o=Ot(n);return o+r*Math.exp(-rt-n*n/2-o)}function fr(t,e){let{ah:n,al:r}=Z(t,e),o=Dt(n);return o-r*Math.exp(-rt-n*n/2-o)}function Qe(t,e){if(Yt(t,e))return sr(t,e);if(t-e>=0){let i=fr(t,e);return i+Math.log(-Math.expm1(Dt(t)-i))}if(t<=0){let i=Ot(t);return i+Math.log(-Math.expm1(Be(t,e)-i))}let{ah:r,al:o}=Z(t,e);return Math.log1p(-nt(r,o)-U(t))}var je=2,St=1e-18;function Ge(t,e,n){let r=De(e,n,je),o=r.map(t),i=0;for(let f=1;f<o.length;f++)o[f]>o[i]&&(i=f);let a=o[i];if(!(a>0))return 0;let s=Math.max(i-1,0),c=Math.min(i+1,o.length-1);for(;s>0&&o[s]>a*St;)s--;for(;c<o.length-1&&o[c]>a*St;)c++;let u=a*St,l=r[s],h=r[c];if(o[s]<=u){let f=r[s+1];for(let p=0;p<2;p++){let M=.5*(l+f);t(M)<=u?l=M:f=M}}if(o[c]<=u){let f=r[c-1];for(let p=0;p<2;p++){let M=.5*(h+f);t(M)<=u?h=M:f=M}}return ht(t,[l,h],Ke)}function Ue(t,e,n){let r=De(e,n,je),o=r.map(t),i=0;for(let m=1;m<o.length;m++)o[m]>o[i]&&(i=m);if(!(o[i]>-1/0))return-1/0;let a=r[Math.max(i-1,0)],s=r[Math.min(i+1,r.length-1)],c=(Math.sqrt(5)-1)/2,u=s-c*(s-a),l=a+c*(s-a),h=t(u),f=t(l);for(let m=0;m<80&&s-a>1e-12*Math.max(1,Math.abs(a));m++)h<f?(a=u,u=l,h=f,l=a+c*(s-a),f=t(l)):(s=l,l=u,f=h,u=s-c*(s-a),h=t(u));let p=h>f?u:l,M=Math.max(h,f);o[i]>M&&(p=r[i],M=o[i]);let N=m=>{let w=m<0?e:n,_=Math.max(1e-6,.001*(r[1]-r[0])),b=p;for(;;){let x=p+m*_;if(m<0?x<=w:x>=w)return w;if(t(x)<M-46){let P=x;for(let A=0;A<6;A++){let H=.5*(b+P);t(H)<M-46?P=H:b=H}return P}b=x,_*=2}},g=N(-1),I=N(1),d=[...new Set([g,p,I])].sort((m,w)=>m-w);return M+Math.log(ht(m=>Math.exp(t(m)-M),d,Ke,4*et*Math.max(1,Math.abs(M))))}var Kt=-10,Ht=10;function hr(t,e){return t<=0?0:e*Ge(n=>V(n)*ur(n,t,e-1),Kt,Ht)}function Ve(t,e){if(t<=0)return 1;let n=i=>{let a=Mt(i);if(a===0)return 0;let{ah:s,al:c}=Z(i,t),u=nt(s,c),l=u<.5*a?-Math.expm1((e-1)*Math.log1p(-u/a)):-Math.expm1((e-1)*Math.log(Xe(i,t)/a));return V(i)*lr(i,e-1)*l};if(t>60)return 0;let[r,o]=Ze(t);return e*Ge(n,r,o)}function Ze(t){return t>40?[t/2-15,t/2+15]:[Kt,t+Ht]}function Mr(t,e){if(t>100)return-Math.exp(ze(t,e));let n=r=>-rt-r*r/2+(e-1)*Qe(r,t);return Math.log(e)+Ue(n,Kt,Ht)}function ze(t,e){if(t>100){let i=e*(e-1);return(Number.isFinite(i)?Math.log(i):Math.log(e)+Math.log(e-1))+Dt(t/Math.SQRT2)}let n=i=>{let a=Ot(i),s=Be(i,t)-a,c;return s<-40?c=Math.log(e-1)+s:s<-Math.LN2?c=Math.log(-Math.expm1((e-1)*Math.log1p(-Math.exp(s)))):c=Math.log(-Math.expm1((e-1)*(Qe(i,t)-a))),-rt-i*i/2+(e-1)*a+c},[r,o]=Ze(t);return Math.log(e)+Ue(n,r,o)}function pr(t,e){let n=-1/0;for(let r of e)n=Math.max(n,t(r));for(let r=0;r+1<e.length;r++)n=Math.max(n,t(.5*(e[r]+e[r+1])));if(n===-1/0)return-1/0;if(et*Math.abs(n)>1)return n;for(let r=0;r<4;r++){let o=n,i=ht(a=>{let s=t(a);return s>o&&(o=s),Math.exp(s-n)},e,Ye,8*et*Math.max(1,Math.abs(n)));if(Number.isFinite(i)&&o-n<300)return n+Math.log(i);n=o}return NaN}var O=32,mr=1e-15,G=Math.log(.01),pt=Math.log(20),Je=Math.log(40),ke=Float64Array.from({length:2*O+1},(t,e)=>Math.cos(Math.PI*e/O));function gr(t,e){let n=new Float64Array(e+1);for(let r=0;r<=e;r++){let o=.5*(t[0]+(r%2===0?t[e]:-t[e]));for(let i=1;i<e;i++)o+=t[i]*ke[r*i%(2*e)];o*=2/e,(r===0||r===e)&&(o*=.5),n[r]=o}return n}function Tt(t,e,n){let r=[],o=[[e,n,0]];for(;o.length>0;){let[i,a,s]=o.pop(),c=.5*(i+a),u=.5*(a-i),l=new Float64Array(O+1),h=1/0;for(let M=0;M<=O;M++)l[M]=t(c+u*ke[M]),h=Math.min(h,Math.max(1,Math.abs(l[M])));let f=gr(l,O),p=0;for(let M=O-3;M<=O;M++)p=Math.max(p,Math.abs(f[M]));p<=mr*h||s>=14||!l.every(Number.isFinite)?r.push({a:i,b:a,coef:f}):o.push([c,a,s+1],[i,c,s+1])}return r.sort((i,a)=>i.a-a.a)}function Ct(t,e){let n=0,r=t.length-1;for(;n<r;){let l=n+r+1>>1;t[l].a<=e?n=l:r=l-1}let{a:o,b:i,coef:a}=t[n],s=(2*e-o-i)/(i-o),c=0,u=0;for(let l=O;l>=1;l--){let h=2*s*c-u+a[l];u=c,c=h}return s*c-u+a[0]}var k=new Map,dr=64,tn=Math.log(1e-10);function en(t){let e=k.get(t);if(e!==void 0)return e;let n=o=>{let i=hr(o,t);return i>1e-290?Math.log(i):Mr(o,t)},r=o=>{let i=Math.exp(o);return Ve(i,t)*nn(i)};return e={logW:Tt(o=>n(Math.exp(o)),G,pt),scaledWc:Tt(r,G,Je),smallW:Tt(o=>n(Math.exp(o))-(t-1)*o,tn,G)},k.size>=dr&&k.delete(k.keys().next().value),k.set(t,e),e}function nn(t){let e=t*t,n=134217729*t,r=n-(n-t),o=t-r,i=r*r-e+2*r*o+o*o;return Math.exp(e/4)*(1+i/4)}function rn(t,e){let n=Math.log(t);if(n>=pt)return 0;let r=en(e);return n>=G?Ct(r.logW,n):Ct(r.smallW,Math.max(n,tn))+(e-1)*n}function Ft(t,e){return Math.log(t)>=pt?1:Math.exp(rn(t,e))}function Lt(t,e){let n=Math.log(t);return n>=G&&n<=Je?Ct(en(e).scaledWc,n)/nn(t):n<G?1-Ft(t,e):Ve(t,e)}function lt(t,e,n,r){if(!r){let i=Math.min(Ft(t,e),1);return n===1?i:i**n}let o=Math.min(Lt(t,e),1);return o<=.5?n===1?o:-Math.expm1(n*Math.log1p(-o)):1-Math.min(Ft(t,e),1)**n}function qt(t,e,n,r){if(!r)return n*(Math.log(t)<pt?rn(t,e):Math.log1p(-Math.min(Lt(t,e),1)));let o=Math.min(Lt(t,e),1),i=o>1e-290?Math.log(o):ze(t,e);return n===1?i:i<-700?Math.log(n)+i:Math.log(-Math.expm1(n*Math.log1p(-Math.exp(i))))}function Wt(t,e,n,r,o){if(n===1/0||an(t,e,n,r))return lt(t,e,r,o);let i=n/2,a=on(i);return ht(c=>{let u=Math.exp(a(c));return u===0?0:u*lt(t*Math.exp(.5*c),e,r,o)},sn(t,e,n,r,o),Ye)}function on(t){let e=.5*Math.log(t/(2*Math.PI))-kt(t);return n=>{let r;if(Math.abs(n)<.5){let o=n*n/2;r=o;for(let i=3;i<60&&(o*=n/i,r+=o,!(Math.abs(o)<1e-17*r));i++);}else r=Math.expm1(n)-n;return e-t*r}}function an(t,e,n,r){let o=Math.max((e-1)*r,t*t,1);return o*o<1e-17*n}function Nr(t,e,n,r,o){if(n===1/0||an(t,e,n,r))return qt(t,e,r,o);let i=on(n/2),a=Math.log(t);return pr(c=>i(c)+qt(Math.exp(a+.5*c),e,r,o),sn(t,e,n,r,o,!0))}function sn(t,e,n,r,o,i=!1){let a=n/2,s=a,c;if(o){let m=2*Math.log(t)-Math.log(4*a);c=-(m>30?m:Math.log1p(Math.exp(m)))}else s=a+(e-1)*r/2,c=Math.log1p((e-1)*r/(2*a));let u=(m,w)=>[m-9/Math.sqrt(w)-41/w,m+9/Math.sqrt(w)+Math.log1p(41/w)],[l,h]=u(0,a),[f,p]=u(c,s),M=i?Math.min(l,f):Math.max(Math.min(l,f),-740-Math.log(a)),N=Math.max(h,p),g=1/Math.sqrt(a),I=1/Math.sqrt(s),d=[M,Math.min(-4*g,c-4*I),Math.max(4*g,c+4*I),N];return[...new Set(d.map(m=>Math.min(Math.max(m,M),N)))].sort((m,w)=>m-w)}function cn(t,e,n){return t>=2&&e>=2&&n>=1&&Number.isFinite(t)&&Number.isFinite(n)&&!Number.isNaN(e)}function ft(t,e,n,r,o,i){if(t<$e){let s=ft($e,e,n,r,!0,!0)+(e-1)*r*Math.log(t*10715086071862673e285);return o?i?s:Math.exp(s):i?-Math.exp(s):-Math.expm1(s)}let a;return K!==void 0&&K.q===t&&K.k===e&&K.df===n&&K.r===r?a=K.tail:(a=br(t,e,n,r,!o),K={q:t,k:e,df:n,r,tail:a}),a.upper===!o?i?a.log:a.value:i?Math.log1p(-a.value):1-a.value}var K,$e=2**-1e3;function br(t,e,n,r,o){let i=o;n!==1/0&<(t,e,r,i)>.5&&(i=!i);let a=Wt(t,e,n,r,i);if(a>.5){let s=Wt(t,e,n,r,!i);s<a&&(a=s,i=!i)}if(a<1e-290){let s=Nr(t,e,n,r,i);return{upper:i,value:Math.exp(s),log:s}}return{upper:i,value:a,log:Math.log(a)}}function wr(t,e,n,r,o,i){return[t,e,n,r].some(Number.isNaN)?NaN:cn(e,n,r)?t<=0?S(o,i):t===1/0?T(o,i):ft(t,e,n,r,o,i):NaN}function xr(t,e,n,r,o,i){if([t,e,n,r].some(Number.isNaN))return NaN;if(!cn(e,n,r))return NaN;let a=L(t,0,1/0,o,i);if(a!==void 0)return a;let{lower:s,logTarget:c,linearTarget:u}=Jt(t,o,i),l=f=>p=>{let M=Math.exp(p);if(u!==void 0&&u>1e-290){let g=f===1/0?Wt(M,e,f,r,!s):ft(M,e,f,r,s,!1);if(g>0)return Math.log(g/u)}return(f===1/0?Er(M,e,r,s):ft(M,e,f,r,s,!0))-c},h=Oe(l(1/0),Math.log(3),s);return Math.exp(n===1/0?h:Oe(l(n),h,s))}function Er(t,e,n,r){let o=lt(t,e,n,!r);return o>1e-290?Math.log(o):qt(t,e,n,!r)}function Oe(t,e,n){let r=e,o=t(r);if(o===0)return r;let i=o>0===n?-1:1,a=.05,s=r+i*a,c=t(s),u=NaN;for(let l=0;l<200&&Math.sign(c)===Math.sign(o)&&c!==0;l++){if(Math.abs(u-s)<.001)return s;for(r=s,o=c,a*=2,s=(r+i*a-u)*i>=0?.5*(r+u):r+i*a,c=t(s);!Number.isFinite(c);){if(u=s,Math.abs(u-r)<.001)return r;s=.5*(r+u),c=t(s)}}return c===0?s:!Number.isFinite(c)||Math.sign(c)===Math.sign(o)?Number.isFinite(c)?s:r:yr(t,r,s,o,c)}function yr(t,e,n,r,o){let i=e,a=r,s=n-e,c=s;for(let u=0;u<100;u++){Math.sign(o)===Math.sign(a)&&(i=e,a=r,s=n-e,c=s),Math.abs(a)<Math.abs(o)&&(e=n,n=i,i=e,r=o,o=a,a=r);let l=2*et*Math.abs(n)+1e-300,h=.5*(i-n);if(Math.abs(h)<=l||o===0)return n;if(Math.abs(c)>=l&&Math.abs(r)>Math.abs(o)){let f=o/r,p,M;if(e===i)p=2*h*f,M=1-f;else{let N=r/a,g=o/a;p=f*(2*h*N*(N-g)-(n-e)*(g-1)),M=(N-1)*(g-1)*(f-1)}p>0?M=-M:p=-p,2*p<Math.min(3*h*M-Math.abs(l*M),Math.abs(c*M))?(c=s,s=p/M):(s=h,c=h)}else s=h,c=h;e=n,r=o,n+=Math.abs(s)>l?s:h>0?l:-l,o=t(n)}return n}function Ro(t,e,n,r={}){y(r,Zn,"ptukey");let{nranges:o=1,lowerTail:i=!0,logP:a=!1}=r;return E(t,s=>wr(s,e,n,o,i,a))}function So(t,e,n,r={}){y(r,zn,"qtukey");let{nranges:o=1,lowerTail:i=!0,logP:a=!1}=r;return E(t,s=>xr(s,e,n,o,i,a))}function Xt(t){let e=[],n=[];for(let r=1;r<=t/2;r++){let o=Math.cos(Math.PI*(r-.25)/(t+.5)),i=0;for(let a=0;a<100;a++){let s=1,c=o;for(let l=2;l<=t;l++)[s,c]=[c,((2*l-1)*o*c-(l-1)*s)/l];i=t*(o*c-s)/(o*o-1);let u=c/i;if(o-=u,Math.abs(u)<=1e-17)break}e.push(o),n.push(2/((1-o*o)*i*i))}return{x:e,w:n}}var Ir=[Xt(6),Xt(12),Xt(20)],Bt=2*Math.PI,Y=t=>R(t,{lowerTail:!1});function vr(t,e,n){if(n===1)return Y(Math.max(t,e));if(n===-1)return t>=-e?0:t>=0?Y(t)-Y(-e):R(-e)-R(t);let{x:r,w:o}=Ir[Math.abs(n)<.3?0:Math.abs(n)<.75?1:2],i=t*e;if(Math.abs(n)<.925){let g=(t*t+e*e)/2,I=Math.asin(n),d=0;for(let m=0;m<r.length;m++)for(let w of[1-r[m],1+r[m]]){let _=Math.sin(I*w/2);d+=o[m]*Math.exp((_*i-g)/(1-_*_))}return d*I/(2*Bt)+Y(t)*Y(e)}let a=n<0?-e:e,s=n<0?-i:i,c=(1-n)*(1+n),u=Math.sqrt(c),l=(t-a)**2,h=(4-s)/8,f=(12-s)/16,p=u*Math.exp(-(l/c+s)/2)*(1-h*(l-c)*(1-f*l/5)/3+h*f*c*c/5);if(s>-160){let g=Math.sqrt(l);p-=Math.exp(-s/2)*Math.sqrt(Bt)*R(-g/u)*g*(1-h*l*(1-f*l/5)/3)}let M=u/2;for(let g=0;g<r.length;g++)for(let I of[1-r[g],1+r[g]]){let d=(M*I)**2,m=Math.sqrt(1-d);p+=M*o[g]*(Math.exp(-l/(2*d)-s/(1+m))/m-Math.exp(-(l/d+s)/2)*(1+h*d*(1+f*d)))}let N=-p/Bt;return n>0?N+Y(Math.max(t,a)):-N+(a>t?R(a)-R(t):0)}function mt(t,e,n){return t===1/0||e===1/0?0:t===-1/0?e===-1/0?1:Y(e):e===-1/0?Y(t):vr(t,e,n)}function Co(t,e,n){if(t.length!==2||e.length!==2)throw new TypeError("'lower' and 'upper' must have length 2");if(!(n>=-1&&n<=1))throw new RangeError("'rho' must be in [-1, 1]");let[r,o]=t,[i,a]=e;if([r,o,i,a].some(Number.isNaN))return NaN;if([r,o,i,a]=[r,o,i,a].map(c=>c>40?1/0:c<-40?-1/0:c),!(r<i&&o<a))return 0;r+i+o+a<0&&([r,o,i,a]=[-i,-a,-r,-o]);let s=mt(r,o,n)-mt(r,a,n)-mt(i,o,n)+mt(i,a,n);return Math.max(0,s)}var _r=["size","replace","prob"],Ar=["size","replace","prob"];function $o(t,e={}){return y(e,Ar,"sampleInt"),un(t,e).map(n=>n-1)}function un(t,e){if(!Number.isFinite(t)||t<0||t>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");t=Math.trunc(t);let{replace:n=!1,prob:r}=e,o=e.size!==void 0,i=o?e.size:t;if(!Number.isFinite(i)||i<=-1)throw new RangeError("size must be a non-negative number");let a=Math.trunc(i);if(t===0&&a>0)throw new RangeError("cannot take a sample from an empty population");if(r!==void 0){if(a>=2**31)throw new RangeError("size must be less than 2^31 with prob");if(t>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(r.length!==t)throw new TypeError("prob must have length n");let l=fn(r,a,n);if(n){let h=ln(l),f=new Array(a);for(let p=0;p<a;p++)f[p]=h();return f}if(a>t)throw new RangeError("cannot take a sample larger than the population when replace is false");return Tr(l,a)}if(!n&&a>t)throw new RangeError("cannot take a sample larger than the population when replace is false");if(!n&&t>1e7&&o&&a<=t/2){let l=new Set,h=[];for(;h.length<a;){let f=J(t);l.has(f)||(l.add(f),h.push(f+1))}return h}let s=new Array(a);if(n||a<2){for(let l=0;l<a;l++)s[l]=J(t)+1;return s}if(t>=2**31)throw new RangeError("n must be less than 2^31 to sample without replacement with size above n / 2");let c=new Int32Array(t);for(let l=0;l<t;l++)c[l]=l;let u=t;for(let l=0;l<a;l++){let h=J(u);s[l]=c[h]+1,c[h]=c[--u]}return s}function Oo(t,e){if(!Number.isFinite(t)||t<0||t>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");if(t=Math.trunc(t),t>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(e.length!==t)throw new TypeError("prob must have length n");let n=ln(fn(e,0,!0));return()=>n()-1}function ln(t){let e=t.length,n=0;for(let r=0;r<e;r++)e*t[r]>.1&&n++;return n>200?Pr(t):Sr(t)}function Do(t,e={}){return y(e,_r,"sample"),un(t.length,e).map(n=>t[n-1])}function fn(t,e,n){let r=0,o=0;for(let i of t){if(!Number.isFinite(i))throw new RangeError("prob contains NaN or infinite values");if(i<0)throw new RangeError("prob contains negative values");i>0&&(o++,r+=i)}if(o===0||!n&&e>o)throw new RangeError("too few positive probabilities");if(r===1/0){let i=fe(t);r=0;for(let a of t)r+=a/i;return Float64Array.from(t,a=>a/i/r)}return Float64Array.from(t,i=>i/r)}function Rr(t,e){let n=t.length;if(n<=1)return;let r=c=>t[c-1],o=(n>>1)+1,i=n,a,s;for(;;){if(o>1)o=o-1,a=r(o),s=e[o-1];else if(a=r(i),s=e[i-1],t[i-1]=r(1),e[i-1]=e[0],--i===1){t[0]=a,e[0]=s;return}let c=o,u=o<<1;for(;u<=i;)u<i&&r(u)>r(u+1)&&++u,a>r(u)?(t[c-1]=r(u),e[c-1]=e[u-1],c=u,u+=u):u=i+1;t[c-1]=a,e[c-1]=s}}function hn(t){let e=new Int32Array(t.length);for(let n=0;n<t.length;n++)e[n]=n+1;return Rr(t,e),e}function Sr(t){let e=Float64Array.from(t),n=e.length,r=hn(e);for(let o=1;o<n;o++)e[o]+=e[o-1];return()=>{let o=q(),i=0;for(;i<n-1&&!(o<=e[i]);i++);return r[i]}}function Tr(t,e){let n=Float64Array.from(t),r=n.length,o=hn(n),i=new Array(e),a=1;for(let s=0,c=r-1;s<e;s++,c--){let u=a*q(),l=0,h=0;for(;h<c&&(l+=n[h],!(u<=l));h++);i[s]=o[h],a-=n[h];for(let f=h;f<c;f++)n[f]=n[f+1],o[f]=o[f+1]}return i}function Pr(t){let e=t.length,n=new Float64Array(e),r=new Int32Array(e),o=new Int32Array(e),i=-1,a=e;for(let c=0;c<e;c++)n[c]=t[c]*e,n[c]<1?o[++i]=c:o[--a]=c;if(i>=0&&a<e)for(let c=0;c<e-1;c++){let u=o[c],l=o[a];if(r[u]=l,n[l]+=n[u]-1,n[l]<1&&a++,a>=e)break}let s=he();return()=>{let c,u;return s?(u=q()*e,c=Math.trunc(u)):(c=J(e),u=c+q()),u<n[c]+c?c+1:r[c]+1}}var Cr=2**24;function Fr(t){let e=new Float64Array(t+1);for(let n=2;n<=t;n++)e[n]=e[n-1]+Math.log(n);return e}function Lr(t,e,n,r){let o=t.length,i=e.length,a=Array.from(e),s=0;for(let u of t)s+=u;for(let u=0;u<o-1;u++){let l=t[u],h=s;s-=l;let f=0;for(;f<i-1;f++){let p=a[f],M=h;h-=p;let N=M-l,g=N-p;if(M===0){for(let m=f;m<i-1;m++)r[u+m*o]=0;l=0;break}let I=q(),d;t:for(;;){d=Math.floor(l*(p/M)+.5);let m=Math.exp(n[l]+n[N]+n[h]+n[p]-n[M]-n[d]-n[p-d]-n[l-d]-n[g+d]);if(m>=I)break;if(m===0)throw new Error(`r2dtable: probability underflow at cell [${u}, ${f}]`);let w=m,_=m,b=d,x=!1,P=!1;for(;!(x&&P);){if(!x){let A=(p-d)*(l-d);if(A===0)x=!0;else if(d++,m=m*A/(d*(g+d)),w+=m,w>=I)break t}do{let A=b*(g+b);if(A===0){P=!0;break}if(b--,_=_*A/((p-b)*(l-b)),w+=_,w>=I){d=b;break t}}while(x)}I=w*q()}r[u+f*o]=d,l-=d,a[f]=a[f]-d}r[u+(i-1)*o]=l}let c=e[i-1];for(let u=0;u<o-1;u++)c-=r[u+(i-1)*o];for(let u=0;u<i-1;u++)r[o-1+u*o]=a[u];r[o-1+(i-1)*o]=c}function Mn(t,e){let n=Array.from(t,r=>Math.trunc(r));if(n.length<=1||n.some(r=>!(r>=0)||r>2147483647))throw new RangeError(`invalid argument '${e}'`);return n}function Ho(t,e,n){if(!(Number.isFinite(t)&&t>-1&&t<2**31))throw new RangeError("invalid argument 'n'");let r=Math.trunc(t),o=Mn(e,"r"),i=Mn(n,"c"),a=o.reduce((l,h)=>l+h,0);if(a!==i.reduce((l,h)=>l+h,0))throw new RangeError("arguments 'r' and 'c' must have the same sums");if(a>2147483647)throw new RangeError("the sum of 'r' must be at most 2147483647");if(r===0)return[];if(a>Cr)throw new RangeError("the sum of 'r' must be at most 16777216 (2^24) to generate tables");let s=Fr(a),c=new Int32Array(o.length*i.length),u=[];for(let l=0;l<r;l++)Lr(o,i,s,c),u.push(o.map((h,f)=>i.map((p,M)=>c[f+M*o.length])));return u}export{Dr as a,Yr as b,Kr as c,En as d,xt as e,In as f,Rn as g,Jr as h,kr as i,to as j,Wn as k,$n as l,co as m,uo as n,lo as o,Gn as p,Un as q,Vn as r,bo as s,wo as t,xo as u,Ro as v,So as w,Co as x,$o as y,Oo as z,Do as A,Cr as B,Fr as C,Lr as D,Ho as E};
|