@numero-uno-jpn/rstats 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.ja.md +18 -9
  3. package/README.md +18 -9
  4. package/dist/chunks/{chunk-MEMYFTYS.js → chunk-4EOKNOXP.js} +1 -1
  5. package/dist/chunks/chunk-4XGKAHD3.js +2 -0
  6. package/dist/chunks/chunk-7GEYDIQC.js +2 -0
  7. package/dist/chunks/{chunk-F44XUHWI.js → chunk-7XHAE2LG.js} +1 -1
  8. package/dist/chunks/{chunk-BSOUJPDF.js → chunk-A3XZUJCP.js} +2 -2
  9. package/dist/chunks/{chunk-SVWU5T7C.js → chunk-AEFWSUZ2.js} +2 -2
  10. package/dist/chunks/chunk-CJ5ETQCK.js +2 -0
  11. package/dist/chunks/{chunk-4GNJEYXR.js → chunk-CMPDE3SZ.js} +2 -2
  12. package/dist/chunks/chunk-GZTLODPK.js +3 -0
  13. package/dist/chunks/{chunk-3AKA4KEL.js → chunk-HNLKOICT.js} +1 -1
  14. package/dist/chunks/{chunk-SLSDFIW2.js → chunk-HS7KIFMR.js} +2 -2
  15. package/dist/chunks/{chunk-CQNVEA22.js → chunk-LU5FHU2O.js} +2 -2
  16. package/dist/chunks/chunk-LVXAWWUX.js +2 -0
  17. package/dist/chunks/{chunk-BJHBYEEU.js → chunk-LWUTCYTZ.js} +1 -1
  18. package/dist/chunks/chunk-NYGWVZOC.js +2 -0
  19. package/dist/chunks/{chunk-4AQNVF3Z.js → chunk-PRDF6IU6.js} +2 -2
  20. package/dist/chunks/{chunk-VG67L3JA.js → chunk-QQIWOGHR.js} +2 -2
  21. package/dist/chunks/chunk-VAPGDPHM.js +2 -0
  22. package/dist/chunks/chunk-VSKWQMSG.js +2 -0
  23. package/dist/chunks/{chunk-JGFUZKLJ.js → chunk-WEWXYHPR.js} +2 -2
  24. package/dist/chunks/{chunk-2IAT6MT2.js → chunk-XMTYTJT6.js} +2 -2
  25. package/dist/descriptive.js +2 -2
  26. package/dist/distributions.js +2 -2
  27. package/dist/entries/mixed.d.ts +3 -1
  28. package/dist/entries/mixed.js +4 -1
  29. package/dist/internal/fround.d.ts +12 -0
  30. package/dist/internal/fround.js +89 -0
  31. package/dist/linalg.js +2 -2
  32. package/dist/mixed.js +4 -3
  33. package/dist/models/glm.js +4 -2
  34. package/dist/models/glmFamily.js +16 -4
  35. package/dist/models/lmer.d.ts +64 -8
  36. package/dist/models/lmer.js +146 -20
  37. package/dist/models/lmerAnova.d.ts +143 -0
  38. package/dist/models/lmerAnova.js +140 -0
  39. package/dist/models/lmerHypotheses.d.ts +106 -0
  40. package/dist/models/lmerHypotheses.js +305 -0
  41. package/dist/models/lmerTest.d.ts +239 -0
  42. package/dist/models/lmerTest.js +311 -0
  43. package/dist/models/mixedDerivatives.d.ts +27 -0
  44. package/dist/models/mixedDerivatives.js +342 -0
  45. package/dist/models/mixedDeviance.d.ts +112 -0
  46. package/dist/models/mixedDeviance.js +216 -86
  47. package/dist/models/mixedStructure.d.ts +5 -3
  48. package/dist/models/mixedStructure.js +30 -14
  49. package/dist/models/modelMatrix.d.ts +10 -3
  50. package/dist/models/modelMatrix.js +23 -2
  51. package/dist/numerics.js +2 -2
  52. package/dist/rstats.js +13 -13
  53. package/dist/special.js +2 -2
  54. package/dist/tests.js +11 -12
  55. package/llms.txt +6 -1
  56. package/package.json +1 -1
  57. package/dist/chunks/chunk-22SXZNR6.js +0 -2
  58. package/dist/chunks/chunk-AGRKZXLG.js +0 -2
  59. package/dist/chunks/chunk-N3FV6H3C.js +0 -2
  60. package/dist/chunks/chunk-NRV3BH7I.js +0 -2
  61. package/dist/chunks/chunk-RTWLZPPG.js +0 -2
  62. package/dist/chunks/chunk-VWGJYRE6.js +0 -2
package/CHANGELOG.md CHANGED
@@ -7,6 +7,53 @@ While the version is 0.x, a minor release (0.y.0) may contain breaking changes;
7
7
  they are listed under **Breaking** for each release. From 1.0.0 the project follows
8
8
  [Semantic Versioning](https://semver.org/).
9
9
 
10
+ ## 0.15.0 - 2026-10-27
11
+
12
+ ### Breaking
13
+
14
+ - `lmer`, `lmerSummary`, `lmerContest` and `lmerAnova` check their options: an option of R that is not supported
15
+ (`weights`, `offset`, `subset`, `naAction`, `control`, `start`, ...) and an unknown key are errors (they were
16
+ ignored: `lmer(..., { weights })` fitted without weights, `{ reml: false }` fitted by REML). The logical options
17
+ (`REML`, `joint`, `confint`, `refit`) accept booleans and numbers (0 is false); a string such as `"no"` is the
18
+ error `argument is not interpretable as logical`.
19
+ - `lmer` throws for a response fitted exactly by the fixed effects (a constant response, or as many fixed effects
20
+ as observations) and for a random-effects term without columns (`(0 | g)`), which it fitted before.
21
+
22
+ ### Fixed
23
+
24
+ - `lmer` could stop at a local minimum of the criterion (crossed groups without a fixed intercept, where one term
25
+ takes the place of the intercept), with a higher criterion than the model without that term. The fit now compares
26
+ its result with the boundary points where one term is removed and continues from a lower one. lmerTest's tests and
27
+ the model comparisons follow.
28
+ - The names of `lmer`'s fixed effects follow the formula without the random-effects terms, as lme4's do:
29
+ `y ~ (z | g) + x * z` has `x:z` (it was `z:x`), and the rows of `lmerAnova`'s tables follow.
30
+ - `lmer` failed ("did not converge") for a response with a large mean (1e6 and more): the fit now works with the
31
+ response minus its least-squares fit on the fixed effects, which gives the same model without the cancellation.
32
+ - `lmer(..., { REML: 0 })` reports `REML: false` (it was `0`).
33
+ - `glm`: the warning `NaNs produced` when a step makes a mean negative under a family whose deviance takes the
34
+ logarithm of y/μ (Poisson, quasi-Poisson and Gamma with the inverse link, for example), before `step size truncated
35
+ due to divergence`, as in R; the deviance of `quasi` with variance `"mu^2"` for a negative response follows R's.
36
+
37
+ ## 0.14.0 - 2026-10-27
38
+
39
+ ### Added
40
+
41
+ - **Tests for linear mixed models** (area `@numero-uno-jpn/rstats/mixed`), as lmerTest 3.2.1 and lme4 give them:
42
+ - `lmerSummary(fit)`: the coefficient table with Satterthwaite's degrees of freedom, t values and p-values
43
+ (`summary()` of a `lmerTest::lmer` fit).
44
+ - `lmerContest(fit, L, { joint, rhs, confint, level })`: t-tests of contrasts with confidence intervals, and joint
45
+ F-tests (`lmerTest::contest`).
46
+ - `lmerAnova(fit, { type })`: the Type III (default), II and I ANOVA tables with Satterthwaite's F-tests
47
+ (`anova()` of a lmerTest fit), with lmerTest's hypothesis matrices (and their rounding) and its "Missing cells"
48
+ message.
49
+ - `lmerAnova([fit1, fit2, ...], { refit, names })`: likelihood-ratio comparison of fits (lme4's `anova()`), REML
50
+ fits refitted by maximum likelihood.
51
+ The degrees of freedom use exact (analytic) derivatives at the exact optimum and agree with references computed
52
+ in 128-bit arithmetic to about 1e-13; lmerTest differentiates numerically at lme4's approximate optimum, so its
53
+ values differ in about the 4th to 8th significant digit (see docs/differences-from-r.md). A summary takes about
54
+ 0.05 s for a fit with 5000 groups. Kenward-Roger, `ranova`, `ls_means` and `step` are not included.
55
+ - `lmer` accepts `contr.poly` among the `contrasts` of the fixed effects.
56
+
10
57
  ## 0.13.0 - 2026-10-27
11
58
 
12
59
  ### Breaking
package/README.ja.md CHANGED
@@ -16,7 +16,7 @@ JavaScript とブラウザで使える、R と互換の統計関数のライブ
16
16
  - **どこでも動きます。** ESM のみで、依存パッケージはなく、Node 専用の API も使っていません。
17
17
  tree-shaking が効きます (`pnorm` だけなら gzip で 1.2 KB)。
18
18
 
19
- 状態: **0.13.0。** R の stats パッケージの数値計算の中心
19
+ 状態: **0.15.0。** R の stats パッケージの数値計算の中心
20
20
  (分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
21
21
  [ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
22
22
 
@@ -128,7 +128,7 @@ aovEz(long, { id: "id", dv: "y", within: "W" }).anova.table[0];
128
128
  `@numero-uno-jpn/rstats/mixed` (CDN では `dist/mixed.js`) にあり、1 ファイルにまとめたビルドには含めていません。
129
129
 
130
130
  ```ts
131
- import { lmer } from "@numero-uno-jpn/rstats/mixed";
131
+ import { lmer, lmerSummary, lmerAnova } from "@numero-uno-jpn/rstats/mixed";
132
132
 
133
133
  const d = { subj: ["s1", "s2", "s3", "s4", "s5", "s6"].flatMap((s) => [s, s, s, s]),
134
134
  day: [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3],
@@ -142,10 +142,19 @@ fit.varCorr[0].corr[0][1]; // ≈ 0.6737
142
142
  fit.sigma; // ≈ 4.4385
143
143
  fit.ranef[0].values[1]; // ≈ [-13.118, -1.0038] (s2 の ranef)
144
144
  fit.REMLcrit; // ≈ 158.563
145
+
146
+ // lmerTest の検定 (Satterthwaite の自由度)
147
+ const s = lmerSummary(fit); // R: summary(lmerTest::lmer(rt ~ day + (day | subj), d))
148
+ s.df; // ≈ [5, 5]
149
+ s.pValue; // ≈ [8.6215e-8, 0.00020903]
150
+ lmerAnova(fit).F; // ≈ [91.942] (Type III。R: anova(fit))
145
151
  ```
146
152
 
147
153
  推定値は REML 基準の厳密な最適点です。lme4 の最適化はその手前で止まるので、分散成分は lme4 と
148
154
  有効数字 5〜9 桁程度まで、固定効果と対数尤度はそれ以上の桁まで一致します。
155
+ `lmerSummary`、`lmerContest`、`lmerAnova` は、lmerTest の Satterthwaite の自由度による t 検定と F 検定、
156
+ Type I・II・III の分散分析表を返します (自由度はその最適点で厳密な導関数から求めます。lmerTest は lme4 の
157
+ 最適点で数値微分します)。`lmerAnova([fit1, fit2])` は、lme4 の `anova()` と同じく当てはめを尤度比検定で比べます。
149
158
 
150
159
  ### 効果量と検出力
151
160
 
@@ -187,7 +196,7 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
187
196
  | 分散分析 | formula で呼ぶ `aov` と `aovSummary` (多元、交互作用、共変量、`Error()` の層), `anova` (`anova.lm`。逐次の表とモデルの比較), `Anova` (car の Type II と III), `aovEz` (afex。反復測定と混合計画、Greenhouse-Geisser と Huynh-Feldt の補正、一般化 η² と偏 η²), `mauchlyTest` (`mauchly.test`) |
188
197
  | 効果量と検出力 | `cohensD`, `hedgesG` (effectsize。信頼区間は厳密な限界), `etaSquared`, `omegaSquared`, `epsilonSquared` (偏・一般化。`anova` と `Anova` の表から), `powerTTest`, `powerPropTest`, `powerAnovaTest` (`power.*.test`), `pwrTTest`, `pwrT2nTest`, `pwr2pTest`, `pwr2p2nTest`, `pwrPTest`, `pwrNormTest`, `pwrRTest`, `pwrChisqTest`, `pwrAnovaTest`, `pwrF2Test`, `esH`, `esW1`, `esW2`, `cohenES` (pwr) |
189
198
  | 線形モデル | `lm` (formula とデータフレーム、または行列で渡す。`summary` の値も返す), `modelMatrix` (`model.matrix`), `confint`, `predict`。`glm` (行列で渡す形。R の `stats` のすべての族とリンク) と `glmSummary` (`summary.glm`)、`glmResiduals` (4 種類)、`glmHatvalues`、`glmRstandard`、`glmCooksDistance`、`glmPredict` (標準誤差つき)、`glmConfint` (プロファイル尤度、厳密な限界)、`glmAnova` (`anova.glm`) |
190
- | 混合モデル | `lmer` (lme4: REML と最尤法、相関のある変量効果と相関のない変量効果、交差と入れ子の群。`fixef`、`vcov`、`VarCorr`、`ranef`、`logLik`、`AIC`、`BIC`、`REMLcrit`、`isSingular`)。`@numero-uno-jpn/rstats/mixed` から import する |
199
+ | 混合モデル | `lmer` (lme4: REML と最尤法、相関のある変量効果と相関のない変量効果、交差と入れ子の群。`fixef`、`vcov`、`VarCorr`、`ranef`、`logLik`、`AIC`、`BIC`、`REMLcrit`、`isSingular`)、`lmerSummary`・`lmerContest`・`lmerAnova` (lmerTest: Satterthwaite の t 検定と F 検定、Type I/II/III の分散分析表。当てはめどうしの尤度比検定)。`@numero-uno-jpn/rstats/mixed` から import する |
191
200
  | ほかの検定 | `leveneTest`、`propTrendTest` (`prop.trend.test`)、`jonckheereTest`、`cochranQTest`、`adTest`、`lillieTest`、`cvmTest`、`sfTest`、`pearsonTest` (car、DescTools、clinfun、nortest) |
192
201
  | 多重比較 | `dscfAllPairsTest` (Steel-Dwass)、`kwAllPairsDunnTest`、`kwManyOneDunnTest`、`manyOneUTest` (Steel の多対一の順位検定)、`dunnettTest`、`gamesHowellTest`、`tukeyTest` (PMCMRplus)、`dunnTest` (dunn.test)、`glhtDunnett` (multcomp) |
193
202
  | 生存時間解析 | `survdiff` (log-rank)、`survfit` (Kaplan-Meier。信頼区間と中央値)、`coxph` (Cox 回帰。Efron と Breslow のタイの扱い、ケースの重み、層、Wald・尤度比・スコア検定) |
@@ -244,15 +253,15 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
244
253
  | `solve` / `svd` / `eigen` | 1.7 / 2.0 / 4.5 KB |
245
254
  | `wilcoxTest` / `fisherTest` / `tTest` | 12.5 / 15.7 / 25.3 KB |
246
255
  | `qbeta` / `pt` と `qt` | 23.2 / 30.3 KB |
247
- | `glm` と `glmSummary` / `glm` とそのすべての関数 | 27.4 / 39.5 KB |
248
- | `lmer` (`/mixed` から) | 15.0 KB |
249
- | すべて (`/mixed` を除く) | 187.7 KB |
256
+ | `glm` と `glmSummary` / `glm` とそのすべての関数 | 27.5 / 39.4 KB |
257
+ | `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 16.5 / 58.9 KB |
258
+ | すべて (`/mixed` を除く) | 187.8 KB |
250
259
 
251
260
  (`npm run size` で測れます。)
252
261
 
253
262
  分野ごとにサブパスからも export しているので、1 つの分野だけを import することもできます。
254
263
  `@numero-uno-jpn/rstats/distributions`、`/tests` (検定、`lm`・`confint`・`predict`、`glm` とその関数)、`/linalg`、
255
- `/descriptive`、`/numerics`、`/special`、`/mixed` です (`/mixed` の `lmer` は、この方法でしか import
264
+ `/descriptive`、`/numerics`、`/special`、`/mixed` です (`/mixed` の `lmer` と lmerTest の検定は、この方法でしか import
256
265
  できません。メインの入口には含めていません)。
257
266
 
258
267
  バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (`/mixed` 以外のすべての関数を含む
@@ -261,7 +270,7 @@ minify 済みの ES モジュール、gzip で 188 KB) を jsDelivr から読み
261
270
 
262
271
  ```html
263
272
  <script type="module">
264
- import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.13.0/dist/rstats.js";
273
+ import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.15.0/dist/rstats.js";
265
274
  console.log(pnorm(1.96)); // 0.9750021048517795
266
275
  </script>
267
276
  ```
@@ -277,7 +286,7 @@ minify 済みの ES モジュール、gzip で 188 KB) を jsDelivr から読み
277
286
  `dist/tests.js`、`dist/linalg.js`、`dist/descriptive.js`、`dist/numerics.js`、`dist/special.js`、
278
287
  `dist/mixed.js` は上のサブパスと同じ関数を export し、共通のコードを `dist/chunks/` で共有します。そのため、
279
288
  2 つの分野を読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で
280
- 20 KB (`mixed`) から 158 KB (`tests`) です。
289
+ 30 KB (`special`) から 159 KB (`tests`) です。
281
290
 
282
291
  npm を元にしたほかの CDN も使えます。たとえば `https://esm.sh/@numero-uno-jpn/rstats` です。ビルド結果
283
292
  (`dist/`) は main ブランチにはなく、リリースのタグにも入っていますが、jsDelivr の GitHub 経由の配信
package/README.md CHANGED
@@ -14,7 +14,7 @@ R-compatible statistical functions for JavaScript and the browser, written in Ty
14
14
  - **Runs anywhere.** ESM only, no dependencies, no Node-specific APIs, tree-shakable
15
15
  (`pnorm` alone is 1.2 KB gzipped).
16
16
 
17
- Status: **0.13.0.** The goal is to cover the numerical core of R's
17
+ Status: **0.15.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
 
@@ -124,7 +124,7 @@ aovEz(long, { id: "id", dv: "y", within: "W" }).anova.table[0];
124
124
  `@numero-uno-jpn/rstats/mixed` (`dist/mixed.js` on a CDN), not in the single-file bundle.
125
125
 
126
126
  ```ts
127
- import { lmer } from "@numero-uno-jpn/rstats/mixed";
127
+ import { lmer, lmerSummary, lmerAnova } from "@numero-uno-jpn/rstats/mixed";
128
128
 
129
129
  const d = { subj: ["s1", "s2", "s3", "s4", "s5", "s6"].flatMap((s) => [s, s, s, s]),
130
130
  day: [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3],
@@ -138,10 +138,19 @@ fit.varCorr[0].corr[0][1]; // ≈ 0.6737
138
138
  fit.sigma; // ≈ 4.4385
139
139
  fit.ranef[0].values[1]; // ≈ [-13.118, -1.0038] (ranef for s2)
140
140
  fit.REMLcrit; // ≈ 158.563
141
+
142
+ // lmerTest's tests, with Satterthwaite's degrees of freedom
143
+ const s = lmerSummary(fit); // R: summary(lmerTest::lmer(rt ~ day + (day | subj), d))
144
+ s.df; // ≈ [5, 5]
145
+ s.pValue; // ≈ [8.6215e-8, 0.00020903]
146
+ lmerAnova(fit).F; // ≈ [91.942] (Type III; R: anova(fit))
141
147
  ```
142
148
 
143
149
  The estimates are the exact optimum of the REML criterion; lme4's optimiser stops close to it, so the variance
144
150
  components agree with lme4 to about 5 to 9 significant digits and the fixed effects and log-likelihood to more.
151
+ `lmerSummary`, `lmerContest` and `lmerAnova` give lmerTest's t- and F-tests with Satterthwaite's degrees of freedom
152
+ (computed with exact derivatives at that optimum; lmerTest differentiates numerically at lme4's) and the Type I,
153
+ II and III ANOVA tables; `lmerAnova([fit1, fit2])` compares fits by likelihood-ratio tests, as lme4's `anova()`.
145
154
 
146
155
  ### Effect sizes and power
147
156
 
@@ -184,7 +193,7 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
184
193
  | Analysis of variance | `aov` and `aovSummary` with a formula (several factors, interactions, covariates, `Error()` strata), `anova` (`anova.lm`, sequential and model comparison), `Anova` (car: types II and III), `aovEz` (afex: repeated-measures and mixed designs, Greenhouse-Geisser and Huynh-Feldt corrections, generalized and partial eta squared), `mauchlyTest` (`mauchly.test`) |
185
194
  | Effect sizes and power | `cohensD`, `hedgesG` (effectsize, with exact confidence limits), `etaSquared`, `omegaSquared`, `epsilonSquared` (partial, generalized, from `anova` and `Anova` tables); `powerTTest`, `powerPropTest`, `powerAnovaTest` (`power.*.test`); `pwrTTest`, `pwrT2nTest`, `pwr2pTest`, `pwr2p2nTest`, `pwrPTest`, `pwrNormTest`, `pwrRTest`, `pwrChisqTest`, `pwrAnovaTest`, `pwrF2Test`, `esH`, `esW1`, `esW2`, `cohenES` (pwr) |
186
195
  | 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`) |
187
- | 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`), from `@numero-uno-jpn/rstats/mixed` |
196
+ | Mixed models | `lmer` (lme4: REML and ML, correlated and uncorrelated random effects, crossed and nested grouping factors; `fixef`, `vcov`, `VarCorr`, `ranef`, `logLik`, `AIC`, `BIC`, `REMLcrit`, `isSingular`), `lmerSummary`, `lmerContest` and `lmerAnova` (lmerTest: Satterthwaite's t- and F-tests, Type I/II/III ANOVA tables; likelihood-ratio comparison of fits), from `@numero-uno-jpn/rstats/mixed` |
188
197
  | More tests | `leveneTest`, `propTrendTest` (`prop.trend.test`), `jonckheereTest`, `cochranQTest`, `adTest`, `lillieTest`, `cvmTest`, `sfTest`, `pearsonTest` (car, DescTools, clinfun, nortest) |
189
198
  | Multiple comparisons | `dscfAllPairsTest` (Steel-Dwass), `kwAllPairsDunnTest`, `kwManyOneDunnTest`, `manyOneUTest` (Steel's many-one rank test), `dunnettTest`, `gamesHowellTest`, `tukeyTest` (PMCMRplus), `dunnTest` (dunn.test), `glhtDunnett` (multcomp) |
190
199
  | 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) |
@@ -240,23 +249,23 @@ removed. Approximate sizes after minification and gzip:
240
249
  | `solve` / `svd` / `eigen` | 1.7 / 2.0 / 4.5 KB |
241
250
  | `wilcoxTest` / `fisherTest` / `tTest` | 12.5 / 15.7 / 25.3 KB |
242
251
  | `qbeta` / `pt` and `qt` | 23.2 / 30.3 KB |
243
- | `glm` and `glmSummary` / `glm` with all its methods | 27.4 / 39.5 KB |
244
- | `lmer` (from `/mixed`) | 15.0 KB |
245
- | everything (except `/mixed`) | 187.7 KB |
252
+ | `glm` and `glmSummary` / `glm` with all its methods | 27.5 / 39.4 KB |
253
+ | `lmer` (from `/mixed`) / with `lmerSummary`, `lmerContest`, `lmerAnova` | 16.5 / 58.9 KB |
254
+ | everything (except `/mixed`) | 187.8 KB |
246
255
 
247
256
  (`npm run size` measures these.)
248
257
 
249
258
  Each area is also a subpath export, for importing one area without the rest:
250
259
  `@numero-uno-jpn/rstats/distributions`, `/tests` (hypothesis tests, `lm`, `confint` and
251
260
  `predict`, and `glm` with its methods), `/linalg`, `/descriptive`, `/numerics`, `/special` and `/mixed`
252
- (`lmer`; this area is only available this way, not from the main entry point).
261
+ (`lmer` and lmerTest's tests; this area is only available this way, not from the main entry point).
253
262
 
254
263
  Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
255
264
  function except those of `/mixed`, 188 KB gzipped) from jsDelivr, which serves each npm release:
256
265
 
257
266
  ```html
258
267
  <script type="module">
259
- import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.13.0/dist/rstats.js";
268
+ import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.15.0/dist/rstats.js";
260
269
  console.log(pnorm(1.96)); // 0.9750021048517795
261
270
  </script>
262
271
  ```
@@ -272,7 +281,7 @@ A page that needs only some areas can load the per-area bundles instead: `dist/d
272
281
  `dist/tests.js`, `dist/linalg.js`, `dist/descriptive.js`, `dist/numerics.js`, `dist/special.js` and
273
282
  `dist/mixed.js` export the same functions as the subpaths above, and share their common code through
274
283
  `dist/chunks/`, so loading two areas does not load that code twice. With its chunks, one area
275
- transfers 20 KB (`mixed`) to 158 KB (`tests`) gzipped.
284
+ transfers 30 KB (`special`) to 159 KB (`tests`) gzipped.
276
285
 
277
286
  Other npm-based CDNs work as well, for example `https://esm.sh/@numero-uno-jpn/rstats`. Release tags also contain
278
287
  the build output (`dist/`), which is not on the main branch, but jsDelivr's GitHub route
@@ -1,2 +1,2 @@
1
- /*! rStats.js 0.13.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
1
+ /*! rStats.js 0.15.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
2
  var _=!0;function xt(){return _}function qt(t,s){if(!_)return[t+s,0];let n=t+s,o=n-t,u=t-(n-o)+(s-o);return[n,u]}function Mt(t,s){if(!_)return[t*s,0];let n=t*s,o=134217729*t,u=o-(o-t),T=t-u;o=134217729*s;let c=o-(o-s),e=s-c,l=u*c-n+u*e+T*c+T*e;return[n,l]}function Dt(t,s){if(!_)return[t[0]+s[0],0];let n=t[0]+s[0],o=n-t[0],u=t[0]-(n-o)+(s[0]-o),T=t[1]+s[1],c=T-t[1],e=t[1]-(T-c)+(s[1]-c),l=u+T,E=n+l,S=l-(E-n)+e,P=E+S,i=S-(P-E);return[P,i]}function mt(t){return[-t[0],-t[1]]}function gt(t,s){if(!_)return[t[0]-s[0],0];let n=-s[0],o=-s[1],u=t[0]+n,T=u-t[0],c=t[0]-(u-T)+(n-T),e=t[1]+o,l=e-t[1],E=t[1]-(e-l)+(o-l),L=c+e,S=u+L,i=L-(S-u)+E,m=S+i,j=i-(m-S);return[m,j]}function At(t,s){if(!_)return[t[0]*s[0],0];let n=t[0]*s[0],o=134217729*t[0],u=o-(o-t[0]),T=t[0]-u,c=134217729*s[0],e=c-(c-s[0]),l=s[0]-e,L=u*e-n+u*l+T*e+T*l+(t[0]*s[1]+t[1]*s[0]),S=n+L,P=L-(S-n);return[S,P]}function Nt(t,s){if(!_)return[t[0]*s,0];let n=t[0]*s,o=134217729*t[0],u=o-(o-t[0]),T=t[0]-u,c=134217729*s,e=c-(c-s),l=s-e,L=u*e-n+u*l+T*e+T*l+t[1]*s,S=n+L,P=L-(S-n);return[S,P]}function vt(t,s){if(!_)return[t[0]/s[0],0];let n=t[0]/s[0],o=s[0]*n,u=134217729*s[0],T=u-(u-s[0]),c=s[0]-T,e=134217729*n,l=e-(e-n),E=n-l,S=T*l-o+T*E+c*l+c*E+s[1]*n,P=o+S,i=S-(P-o),m=-P,j=-i,f=t[0]+m,Y=f-t[0],P1=t[0]-(f-Y)+(m-Y),N=t[1]+j,y=N-t[1],d1=t[1]-(N-y)+(j-y),Z=P1+N,d=f+Z,v=Z-(d-f)+d1,p=d+v,z=v-(p-d),h=p/s[0],B=s[0]*h,o1=134217729*s[0],G=o1-(o1-s[0]),F=s[0]-G,u1=134217729*h,O=u1-(u1-h),R=h-O,w=G*O-B+G*R+F*O+F*R+s[1]*h,H=B+w,T1=w-(H-B),J=-H,$=-T1,q=p+J,K=q-p,b1=p-(q-K)+(J-K),a=z+$,s1=a-z,r1=z-(a-s1)+($-s1),c1=b1+a,Q=q+c1,k=c1-(Q-q)+r1,t1=Q+k,F1=k-(t1-Q),U=t1/s[0],M=n+h,V=h-(M-n),D=M+U,W=D-M,q1=M-(D-W)+(U-W),C=V+0,g=C-V,e1=V-(C-g)+(0-g),x=q1+C,A=D+x,X=x-(A-D)+e1,n1=A+X,l1=X-(n1-A);return[n1,l1]}function Bt(t,s){if(!_)return[t[0]/s,0];let n=t[0]/s,o=s*n,u=134217729*s,T=u-(u-s),c=s-T,e=134217729*n,l=e-(e-n),E=n-l,S=T*l-o+T*E+c*l+c*E+0*n,P=o+S,i=S-(P-o),m=-P,j=-i,f=t[0]+m,Y=f-t[0],P1=t[0]-(f-Y)+(m-Y),N=t[1]+j,y=N-t[1],d1=t[1]-(N-y)+(j-y),Z=P1+N,d=f+Z,v=Z-(d-f)+d1,p=d+v,z=v-(p-d),h=p/s,B=s*h,o1=134217729*s,G=o1-(o1-s),F=s-G,u1=134217729*h,O=u1-(u1-h),R=h-O,w=G*O-B+G*R+F*O+F*R+0*h,H=B+w,T1=w-(H-B),J=-H,$=-T1,q=p+J,K=q-p,b1=p-(q-K)+(J-K),a=z+$,s1=a-z,r1=z-(a-s1)+($-s1),c1=b1+a,Q=q+c1,k=c1-(Q-q)+r1,t1=Q+k,F1=k-(t1-Q),U=t1/s,M=n+h,V=h-(M-n),D=M+U,W=D-M,q1=M-(D-W)+(U-W),C=V+0,g=C-V,e1=V-(C-g)+(0-g),x=q1+C,A=D+x,X=x-(A-D)+e1,n1=A+X,l1=X-(n1-A);return[n1,l1]}var f1=[.6931471805599453,23190468138462996e-33],g2=Math.SQRT2,r=[[1,0],[.3333333333333333,1850371707708594e-32],[.2,-11102230246251566e-33],[.14285714285714285,793016446160826e-32],[.1111111111111111,61679056923619804e-34],[.09090909090909091,-2523234146875356e-33]],tt=89,nt=[[-.3633938941874773,-2106844752226605e-32],[-.3522205935893521,-57233316949182485e-34],[-.34117075740276714,19366790062602867e-33],[-.33024168687057687,10828321637483858e-33],[-.3194307707663612,-1354256857264811e-33],[-.3087354816496133,16199186085148102e-33],[-.29815337231907635,1720695867445866e-32],[-.2876820724517809,-2607160616442564e-32],[-.27731928541623435,744528405583513e-32],[-.26706278524904525,732891532732017e-32],[-.2569104137850272,-2502843296152504e-32],[-.24686007793152578,-1361743371748368e-32],[-.2369097470783577,-19682402978398164e-34],[-.22705745063534608,-9551415762738488e-33],[-.2173012756899814,-16168452453763015e-34],[-.2076393647782445,-12053243216686129e-33],[-.1980699137620938,-3742843482461439e-33],[-.18859116980755003,7432164219196925e-33],[-.179201429457711,10785017454858423e-33],[-.16989903679539747,4868008764439071e-34],[-.16068238169047347,3650183553047837e-33],[-.15154989812720093,-51669593684615594e-34],[-.14250006260728304,9926388234225749e-33],[-.13353139262452263,3664457663660085e-33],[-.1246424452072766,5808912678940971e-33],[-.1158318155251217,-4338484369808096e-33],[-.1070981355563671,173705104015906e-32],[-.09844007281325252,4439009633675136e-33],[-.08985632912186105,6273760163689594e-34],[-.0813456394539524,-507707635593117e-32],[-.07290677080808779,6306860257532778e-33],[-.06453852113757118,6470486661692933e-33],[-.05623971832287608,32835149805605613e-34],[-.048009219186360606,-14390903347292205e-34],[-.039845908547199674,3129547680315208e-33],[-.0317486983145803,-30382263084680858e-34],[-.023716526617316044,15774243488668215e-34],[-.015748356968139168,-10021578630528974e-34],[-.007843177461025893,-2764708154124904e-34],[0,0],[.007782140442054949,-12819179123343845e-36],[.015504186535965254,-3278321022892429e-34],[.02316705928153438,-11769544932063305e-34],[.030771658666753687,10431732029005968e-34],[.0383188643021366,-2357996157351286e-33],[.0458095360312942,1902959866474257e-33],[.053244514518812285,-1665575816973663e-33],[.06062462181643484,26424025938726934e-34],[.06795066190850775,-12802141240611733e-34],[.07522342123758753,-5930604196293241e-33],[.08244366921107459,5700437773813987e-33],[.08961215868968714,-54268129336647135e-34],[.09672962645855111,-5597397486289965e-34],[.10379679368164356,547772415726659e-32],[.11081436634029011,1183748342825649e-33],[.11778303565638346,-11971685747593677e-34],[.12470347850095724,-46522609636496624e-34],[.13157635778871926,11123000879729588e-33],[.13840232285911913,4447777301357527e-33],[.1451820098444979,8242418783022475e-33],[.15191604202584197,64838631244022194e-34],[.15860503017663857,11257003872182592e-33],[.16524957289530717,-10094935622322628e-33],[.17185025692665923,-60224538210113705e-34],[.1784076574728183,-12432553788701131e-33],[.184922338494012,30236614153574064e-34],[.19139485299962947,-12129496905792884e-33],[.19782574332991987,12821194372980142e-33],[.2042155414286909,27338281018722773e-34],[.21056476910734964,-4249405314729895e-33],[.21687393830061436,4551026193234283e-33],[.22314355131420976,-9091270597324799e-33],[.22937410106484582,9927671823978025e-33],[.2355660713127669,-23943371495187355e-34],[.24171993688714516,8900990022166643e-33],[.24783616390458127,-12432209578702523e-33],[.25391520998096345,-8048097394424201e-33],[.25995752443692605,2069806938978935e-32],[.26596354849713794,53393802761314314e-34],[.27193371548364176,783319637697442e-33],[.2778684510034563,-916018294909263e-33],[.2837681731306446,-2032665581126656e-32],[.28963329258304266,20535953219858174e-33],[.2954642128938359,-216461086040599e-31],[.3012613305781618,-9048511144048564e-33],[.3070250352949119,-12319916200101964e-33],[.3127557100038969,-1451808353098951e-32],[.3184537311185346,27114779367326236e-33],[.324119468654212,-7958214381893813e-33],[.329753286372468,2122020616196946e-33],[.3353555419211378,1834564437059473e-32],[.3409265869705932,17467136443544747e-33],[.34646676734620857,1028583585496265e-32],[.3519764231571782,-12953893030191963e-33],[.3574558889218038,-25136910072413547e-33]];function Gt(t){if(!_)return[Math.log(t[0]),0];let s=t[0],n=t[1],o=0;s<22250738585072014e-324&&(s*=2**600,n*=2**600,o=-600);let u=Math.floor(Math.log2(s));o+=u;let T=2**-u,c=s*T,e=n*T;c>=g2?(c=c/2,e=e/2,o+=1):c<g2/2&&(c=c*2,e=e*2,o-=1);let l=Math.round(c*128),E=l/128,L=nt[l-tt],S=-E,P=-0,i=c+S,m=i-c,j=c-(i-m)+(S-m),f=e+P,Y=f-e,P1=e-(f-Y)+(P-Y),N=j+f,y=i+N,Z=N-(y-i)+P1,d=y+Z,I1=Z-(d-y),v=c+E,p=v-c,z=c-(v-p)+(E-p),h=e+0,B=h-e,o1=e-(h-B)+(0-B),G=z+h,F=v+G,O=G-(F-v)+o1,R=F+O,w1=O-(R-F),w=d/R,H=R*w,T1=134217729*R,J=T1-(T1-R),$=R-J,q=134217729*w,K=q-(q-w),b1=w-K,s1=J*K-H+J*b1+$*K+$*b1+w1*w,r1=H+s1,c1=s1-(r1-H),Q=-r1,x1=-c1,k=d+Q,t1=k-d,F1=d-(k-t1)+(Q-t1),U=I1+x1,M=U-I1,V=I1-(U-M)+(x1-M),D=F1+U,W=k+D,C=D-(W-k)+V,g=W+C,e1=C-(g-W),x=g/R,A=R*x,M1=134217729*R,X=M1-(M1-R),n1=R-X,l1=134217729*x,H1=l1-(l1-x),K0=x-H1,U0=X*H1-A+X*K0+n1*H1+n1*K0+w1*x,V0=A+U0,A2=U0-(V0-A),W0=-V0,X0=-A2,D1=g+W0,Y0=D1-g,N2=g-(D1-Y0)+(W0-Y0),J1=e1+X0,Z0=J1-e1,v2=e1-(J1-Z0)+(X0-Z0),$0=N2+J1,K1=D1+$0,a0=$0-(K1-D1)+v2,ss=K1+a0,et=a0-(ss-K1),ts=ss/R,m1=w+x,U1=x-(m1-w),g1=m1+ts,ns=g1-m1,B2=m1-(g1-ns)+(ts-ns),V1=U1+0,os=V1-U1,G2=U1-(V1-os)+(0-os),cs=B2+V1,W1=g1+cs,es=cs-(W1-g1)+G2,I=W1+es,X1=es-(I-W1),Y1=I*I,us=134217729*I,Z1=us-(us-I),Ts=I-Z1,bs=134217729*I,$1=bs-(bs-I),rs=I-$1,ls=Z1*$1-Y1+Z1*rs+Ts*$1+Ts*rs+(I*X1+X1*I),b=Y1+ls,p1=ls-(b-Y1),a1=r[5][0]*b,Ss=134217729*r[5][0],s0=Ss-(Ss-r[5][0]),hs=r[5][0]-s0,Ls=134217729*b,t0=Ls-(Ls-b),Rs=b-t0,Es=s0*t0-a1+s0*Rs+hs*t0+hs*Rs+(r[5][0]*p1+r[5][1]*b),A1=a1+Es,n0=Es-(A1-a1),N1=A1+r[4][0],Ps=N1-A1,O2=A1-(N1-Ps)+(r[4][0]-Ps),o0=n0+r[4][1],Is=o0-n0,Q2=n0-(o0-Is)+(r[4][1]-Is),ps=O2+o0,c0=N1+ps,is=ps-(c0-N1)+Q2,S1=c0+is,k2=is-(S1-c0),e0=S1*b,fs=134217729*S1,u0=fs-(fs-S1),ds=S1-u0,ws=134217729*b,T0=ws-(ws-b),xs=b-T0,qs=u0*T0-e0+u0*xs+ds*T0+ds*xs+(S1*p1+k2*b),v1=e0+qs,b0=qs-(v1-e0),B1=v1+r[3][0],Ms=B1-v1,C2=v1-(B1-Ms)+(r[3][0]-Ms),r0=b0+r[3][1],Ds=r0-b0,_2=b0-(r0-Ds)+(r[3][1]-Ds),ms=C2+r0,l0=B1+ms,gs=ms-(l0-B1)+_2,h1=l0+gs,j2=gs-(h1-l0),S0=h1*b,As=134217729*h1,h0=As-(As-h1),Ns=h1-h0,vs=134217729*b,L0=vs-(vs-b),Bs=b-L0,Gs=h0*L0-S0+h0*Bs+Ns*L0+Ns*Bs+(h1*p1+j2*b),G1=S0+Gs,R0=Gs-(G1-S0),O1=G1+r[2][0],Os=O1-G1,y2=G1-(O1-Os)+(r[2][0]-Os),E0=R0+r[2][1],Qs=E0-R0,z2=R0-(E0-Qs)+(r[2][1]-Qs),ks=y2+E0,P0=O1+ks,Cs=ks-(P0-O1)+z2,L1=P0+Cs,F2=Cs-(L1-P0),I0=L1*b,_s=134217729*L1,p0=_s-(_s-L1),js=L1-p0,ys=134217729*b,i0=ys-(ys-b),zs=b-i0,Fs=p0*i0-I0+p0*zs+js*i0+js*zs+(L1*p1+F2*b),Q1=I0+Fs,f0=Fs-(Q1-I0),k1=Q1+r[1][0],Hs=k1-Q1,H2=Q1-(k1-Hs)+(r[1][0]-Hs),d0=f0+r[1][1],Js=d0-f0,J2=f0-(d0-Js)+(r[1][1]-Js),Ks=H2+d0,w0=k1+Ks,Us=Ks-(w0-k1)+J2,R1=w0+Us,K2=Us-(R1-w0),x0=R1*b,Vs=134217729*R1,q0=Vs-(Vs-R1),Ws=R1-q0,Xs=134217729*b,M0=Xs-(Xs-b),Ys=b-M0,Zs=q0*M0-x0+q0*Ys+Ws*M0+Ws*Ys+(R1*p1+K2*b),C1=x0+Zs,D0=Zs-(C1-x0),_1=C1+r[0][0],$s=_1-C1,U2=C1-(_1-$s)+(r[0][0]-$s),m0=D0+r[0][1],as=m0-D0,V2=D0-(m0-as)+(r[0][1]-as),s2=U2+m0,g0=_1+s2,t2=s2-(g0-_1)+V2,E1=g0+t2,W2=t2-(E1-g0),A0=I*E1,n2=134217729*I,N0=n2-(n2-I),o2=I-N0,c2=134217729*E1,v0=c2-(c2-E1),e2=E1-v0,u2=N0*v0-A0+N0*e2+o2*v0+o2*e2+(I*W2+X1*E1),i1=A0+u2,X2=u2-(i1-A0),B0=i1*2,T2=134217729*i1,G0=T2-(T2-i1),b2=i1-G0,r2=134217729*2,O0=r2-(r2-2),l2=2-O0,S2=G0*O0-B0+G0*l2+b2*O0+b2*l2+X2*2,Q0=B0+S2,h2=S2-(Q0-B0),j1=L[0]+Q0,L2=j1-L[0],Y2=L[0]-(j1-L2)+(Q0-L2),k0=L[1]+h2,R2=k0-L[1],Z2=L[1]-(k0-R2)+(h2-R2),E2=Y2+k0,C0=j1+E2,P2=E2-(C0-j1)+Z2,y1=C0+P2,_0=P2-(y1-C0),j0=f1[0]*o,I2=134217729*f1[0],y0=I2-(I2-f1[0]),p2=f1[0]-y0,i2=134217729*o,z0=i2-(i2-o),f2=o-z0,d2=y0*z0-j0+y0*f2+p2*z0+p2*f2+f1[1]*o,F0=j0+d2,w2=d2-(F0-j0),z1=y1+F0,x2=z1-y1,$2=y1-(z1-x2)+(F0-x2),H0=_0+w2,q2=H0-_0,a2=_0-(H0-q2)+(w2-q2),M2=$2+H0,J0=z1+M2,D2=M2-(J0-z1)+a2,m2=J0+D2,st=D2-(m2-J0);return[m2,st]}export{xt as a,qt as b,Mt as c,Dt as d,mt as e,gt as f,At as g,Nt as h,vt as i,Bt as j,Gt as k};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.15.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 o,i as N,j as a}from"./chunk-7XHAE2LG.js";function u(t,e){if(!Number.isFinite(t)||t<0)throw new RangeError("n must be a non-negative finite number");let r=Math.trunc(t),n=new Array(r);for(let i=0;i<r;i++)n[i]=e();return n}function s(t,e){let r=1;if(Number.isNaN(t))return t;if(e!==0){if(!Number.isFinite(t))return Math.pow(t,e);for(e<0&&(e=-e,t=1/t);e&1&&(r*=t),e>>=1,e;)t*=t}return r}function l(t,e={}){let{min:r=0,max:n=1}=e;return u(t,()=>{if(!Number.isFinite(r)||!Number.isFinite(n)||n<r)return NaN;if(r===n)return r;let i=o();return r+(n-r)*i})}function f(t,e){return Number.isNaN(t)||!Number.isFinite(e)||e<0?NaN:e===0||!Number.isFinite(t)?t:t+e*N()}function p(t,e={}){let{mean:r=0,sd:n=1}=e;return u(t,()=>f(r,n))}function F(t,e={}){let r=1/(e.rate??1);return u(t,()=>!Number.isFinite(r)||r<=0?r===0?0:NaN:r*a())}function g(t,e={}){let{meanlog:r=0,sdlog:n=1}=e;return u(t,()=>Number.isNaN(r)||!Number.isFinite(n)||n<0?NaN:Math.exp(f(r,n)))}function h(t,e={}){let{location:r=0,scale:n=1}=e;return u(t,()=>{if(Number.isNaN(r)||!Number.isFinite(n))return NaN;if(n===0||!Number.isFinite(r))return r;let i=o();return r+n*Math.log(i/(1-i))})}function w(t,e={}){let{location:r=0,scale:n=1}=e;return u(t,()=>Number.isNaN(r)||!Number.isFinite(n)||n<0?NaN:n===0||!Number.isFinite(r)?r:r+n*Math.tan(Math.PI*o()))}function M(t,e,r={}){let{scale:n=1}=r;return u(t,()=>!Number.isFinite(e)||!Number.isFinite(n)||e<=0||n<=0?n===0?0:NaN:n*Math.pow(-Math.log(o()),1/e))}export{u as a,s as b,l as c,f as d,p as e,F as f,g,h,w as i,M as j};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.15.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 q,c as p,e as v,f as O,h as U,o as F,r as g,s as j,v as N,y as R}from"./chunk-VAPGDPHM.js";function H(e,n={}){if(n.exact){let i=n.norm===void 0?"2":A(n.norm);if(i==="2"){let l=g(e,{nu:0,nv:0}).d,m=Math.min(...l);return m===0?1/0:Math.max(...l)/m}return j(e,{type:i})*j(N(e),{type:i})}let a=n.norm==="I"?"I":"O";if((n.method??"qr")==="direct"){if(n.triangular)return 1/C(p(e),(n.uplo??"U")==="U",a);let i=n.norm??"O",l=i.toUpperCase();if(l!=="1"&&l!=="O"&&l!=="I")throw new RangeError(`argument type[1]='${i}' must be one of '1','O', or 'I'`);return 1/R(e,{norm:l==="I"?"I":"O"})}let b=p(e),f=b.nrow<b.ncol?v(O(b)):e;return 1/C(p(F(U(f))),!0,a)}function C(e,n,a){return L(a==="I"?O(e):e,n)}function A(e){let n=e.toUpperCase();if(n==="1"||n==="O")return"O";if(n==="E")return"F";if(n==="I"||n==="F"||n==="M"||n==="2")return n;throw new RangeError(`invalid norm "${e}"`)}function L(e,n){let a=Math.min(e.nrow,e.ncol),b=e.nrow,f=(o,t)=>e.data[o+t*b],i=!n,l=0;for(let o=0;o<a;o++){let[t,u]=i?[o,a-o]:[0,o+1],s=0;for(let c=t;c<t+u;c++)s+=Math.abs(f(c,o));l=Math.max(l,s)}let m=1,r=new Float64Array(a),k=o=>{for(let t=0;t<a;t++)r[t]*=o};for(let o=0;o<a;o++){let t=i?a-1-o:o,u=f(t,t);if(r[t]!==0&&(m=r[t]>0?-Math.abs(m):Math.abs(m)),Math.abs(m-r[t])>Math.abs(u)){let d=Math.abs(u)/Math.abs(m-r[t]);k(d),m*=d}let s=m-r[t],c=-m-r[t],x=Math.abs(s),y=Math.abs(c);if(u!==0?(s/=u,c/=u):(s=1,c=1),o!==a-1){let[d,E]=i?[0,t-1]:[t+1,a-1];for(let M=d;M<=E;M++)y+=Math.abs(r[M]+c*f(t,M)),r[M]+=s*f(t,M),x+=Math.abs(r[M]);if(x<y){let M=c-s;s=c;for(let I=d;I<=E;I++)r[I]+=M*f(t,I)}}r[t]=s}k(1/$(r));let w=1;for(let o=0;o<a;o++){let t=i?o:a-1-o,u=f(t,t);if(Math.abs(r[t])>Math.abs(u)){let s=Math.abs(u)/Math.abs(r[t]);k(s),w*=s}if(u!==0?r[t]/=u:r[t]=1,o<a-1){let s=-r[t];if(i)for(let c=t+1;c<a;c++)r[c]+=s*f(c,t);else for(let c=0;c<t;c++)r[c]+=s*f(c,t)}}let h=1/$(r);return k(h),w*=h,l!==0?w/l:0}function $(e){let n=0;for(let a of e)n+=Math.abs(a);return n}function J(e,n={}){let a=n.tol??Math.sqrt(Number.EPSILON),b=p(e),{d:f,u:i,v:l}=g(e),m=b.nrow,r=b.ncol,k=q(r,m),w=Math.max(a*(f[0]??0),0);for(let h=0;h<f.length;h++){if(!(f[h]>w))continue;let o=1/f[h];for(let t=0;t<m;t++){let u=i[t][h]*o;for(let s=0;s<r;s++)k.data[s+t*r]+=l[s][h]*u}}return v(k)}export{H as a,J as b};
@@ -1,2 +1,2 @@
1
- /*! rStats.js 0.13.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
1
+ /*! rStats.js 0.15.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
2
  var E=23283064365386963e-26,M=2328306437080797e-25,c=class{mt=new Uint32Array(624);mti=625;setSeed(t){let e=t>>>0;for(let n=0;n<50;n++)e=Math.imul(69069,e)+1>>>0;e=Math.imul(69069,e)+1>>>0;for(let n=0;n<624;n++)e=Math.imul(69069,e)+1>>>0,this.mt[n]=e;this.mti=624}sgenrand(t){for(let e=0;e<624;e++)this.mt[e]=t&4294901760,t=Math.imul(69069,t)+1>>>0,this.mt[e]=(this.mt[e]|(t&4294901760)>>>16)>>>0,t=Math.imul(69069,t)+1>>>0;this.mti=624}nextUint32(){let t=this.mt;if(this.mti>=624){this.mti===625&&this.sgenrand(4357);let n=0,o;for(;n<227;n++)o=t[n]&2147483648|t[n+1]&2147483647,t[n]=t[n+397]^o>>>1^(o&1?2567483615:0);for(;n<623;n++)o=t[n]&2147483648|t[n+1]&2147483647,t[n]=t[n+-227]^o>>>1^(o&1?2567483615:0);o=t[623]&2147483648|t[0]&2147483647,t[623]=t[396]^o>>>1^(o&1?2567483615:0),this.mti=0}let e=t[this.mti++];return e^=e>>>11,e^=e<<7&2636928640,e^=e<<15&4022730752,e^=e>>>18,e>>>0}nextDouble(){let t=this.nextUint32()*E;return t<=0?.5*M:1-t<=0?1-.5*M:t}getRandomSeed(t){let e=new Int32Array(626);e[0]=t,e[1]=this.mti;for(let n=0;n<624;n++)e[n+2]=this.mt[n]|0;return e}setRandomSeed(t){if(t.length!==626)throw new RangeError("the random seed state must have 626 integers");this.mti=t[1];for(let e=0;e<624;e++)this.mt[e]=t[e+2]>>>0}};var b=2328306549295728e-25,R=r=>Math.imul(69069,r)+1>>>0,a=class{s=new Float64Array(6);setSeed(t){let e=t>>>0;for(let n=0;n<50;n++)e=R(e);for(let n=0;n<6;n++){do e=R(e);while(e>=4294944443);this.s[n]=e}}nextDouble(){let t=this.s,e=(1403580*t[1]-810728*t[0])%4294967087;e<0&&(e+=4294967087),t[0]=t[1],t[1]=t[2],t[2]=e;let n=(527612*t[5]-1370589*t[3])%4294944443;return n<0&&(n+=4294944443),t[3]=t[4],t[4]=t[5],t[5]=n,(e>n?e-n:e-n+4294967087)*b}};function p(r){if(r.length!==7)throw new RangeError("the random seed state of L'Ecuyer-CMRG must have 7 integers");let t=[];for(let e=1;e<=6;e++){let n=r[e];if(!Number.isInteger(n)||n<-2147483648||n>4294967295)throw new RangeError("the random seed state must hold 32-bit integers");t.push(n>>>0)}if(t[0]===0&&t[1]===0&&t[2]===0||t.slice(0,3).some(e=>e>=4294967087)||t.slice(3).some(e=>e>=4294944443))throw new RangeError("invalid L'Ecuyer-CMRG state: the first three seeds must be below 4294967087 and not all zero, the last three below 4294944443");return t}var y=[3.3871328727963665,133.14166789178438,1971.5909503065513,13731.69376550946,45921.95393154987,67265.7709270087,33430.57558358813,2509.0809287301227],_=[1,42.31333070160091,687.1870074920579,5394.196021424751,21213.794301586597,39307.89580009271,28729.085735721943,5226.495278852854],k=[1.4234371107496835,4.630337846156546,5.769497221460691,3.6478483247632045,1.2704582524523684,.2417807251774506,.022723844989269184,.0007745450142783414],I=[1,2.053191626637759,1.6763848301838038,.6897673349851,.14810397642748008,.015198666563616457,.0005475938084995345,10507500716444169e-25],K=[6.657904643501103,5.463784911164114,1.7848265399172913,.29656057182850487,.026532189526576124,.0012426609473880784,27115555687434876e-21,20103343992922881e-23],v=[1,.599832206555888,.1369298809227358,.014875361290850615,.0007868691311456133,18463183175100548e-21,1421511758316446e-22,20442631033899397e-31];function f(r,t){let e=r[7];for(let n=6;n>=0;n--)e=e*t+r[n];return e}function g(r){let t=r-.5;if(Math.abs(t)<=.425){let o=.180625-t*t;return t*f(y,o)/f(_,o)}let e=t<0?r:1-r;e=Math.sqrt(-Math.log(e));let n;return e<=5?(e-=1.6,n=f(k,e)/f(I,e)):(e-=5,n=f(K,e)/f(v,e)),t<0?-n:n}var u=new c,i=u,l=!1,h=!1;function m(r){i.setSeed(r),h=!0}function A(){if(h)return;let r=(Date.now()^Math.floor(Math.random()*2**32))>>>0;typeof globalThis.crypto?.getRandomValues=="function"&&(r=globalThis.crypto.getRandomValues(new Uint32Array(1))[0]),m(r)}function W(r){if(!Number.isFinite(r))throw new RangeError("seed must be a finite number");let t=Math.trunc(r);if(Math.abs(t)>2147483647)throw new RangeError("seed must be a 32-bit integer");m(t)}var L={default:!1,"Mersenne-Twister":!1,"L'Ecuyer-CMRG":!0},P={default:!1,Rejection:!1,Rounding:!0};function w(r,t,e){if(t===void 0)return;let n=r[t];if(typeof n!="boolean")throw new RangeError(`unsupported ${e} "${t}"`);return n}function X(r={}){let t={kind:i===u?"Mersenne-Twister":"L'Ecuyer-CMRG",normalKind:"Inversion",sampleKind:l?"Rounding":"Rejection"},e=w(L,r.kind,"RNG kind"),n=w(P,r.sampleKind,"sample kind");if(e!==void 0){let o=Math.trunc(s()*4294967295);i=e?i===u?new a:i:u,m(o)}return n!==void 0&&(l=n),t}var x=()=>(i===u?3:7)+400+(l?0:1e4);function $(){return A(),i===u?u.getRandomSeed(x()):Int32Array.of(x(),...i.s)}function q(r){let t=r[0],e=t%100;if(!Number.isInteger(t)||t<0||t>10407||e!==3&&e!==7||Math.floor(t/100)%100!==4)throw new RangeError(`unsupported RNG kind code ${String(t)} (supported: 10403, 403, 10407, 407)`);if(e===7){let n=new a;n.s.set(p(r)),i=n}else u.setRandomSeed(r),i=u;l=t<1e4,h=!0}function s(){return A(),i.nextDouble()}var F=()=>l;function T(r){let t=2**Math.max(r-16,0),e=0;for(let n=0;n<=r;n+=16){let o=Math.floor(s()*65536);e=65536*(e%t)+o}return e%2**r}var N=33554432;function B(r){if(l)return Math.floor(r*(r>2147483647?(Math.floor(N*s())+s())/N:s()));if(r<=0)return 0;let t=Math.ceil(Math.log2(r)),e;do e=T(t);while(r<=e);return e}var S=134217728;function V(){let r=s();return r=Math.trunc(S*r)+s(),g(r/S)}var d=(()=>{let r=[],t=1,e=0;for(let n=1;n<=16;n++)t*=Math.LN2/n,e+=t,r.push(e);return r})();function z(){let r=0,t=s();for(;t<=0||t>=1;)t=s();for(;t+=t,!(t>1);)r+=d[0];if(t-=1,t<=d[0])return r+t;let e=0,n=s(),o=n;do n=s(),o>n&&(o=n),e++;while(t>d[e]);return r+o*d[0]}export{p as a,W as b,X as c,$ as d,q as e,s as f,F as g,B as h,V as i,z as j};
@@ -1,2 +1,2 @@
1
- /*! rStats.js 0.13.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{b as A}from"./chunk-3AKA4KEL.js";var h=r=>new SyntaxError(`invalid formula: ${r}`);function N(r,u){let o=[],s=0;for(;s<r.length;){let i=r[s];if(/\s/.test(i)){s++;continue}if(/[0-9]/.test(i)||i==="."&&/[0-9]/.test(r[s+1]??"")){let e=/^(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:[eE][+-]?[0-9]+)?/.exec(r.slice(s));o.push({kind:"num",text:e[0]}),s+=e[0].length;continue}if(/[A-Za-z.]/.test(i)){let e=/^[A-Za-z.][A-Za-z0-9._]*/.exec(r.slice(s));o.push({kind:"name",text:e[0]}),s+=e[0].length;continue}if(r.startsWith("%in%",s)){o.push({kind:"op",text:"%in%"}),s+=4;continue}if(u&&i==="|"){let e=r[s+1]==="|"?"||":"|";o.push({kind:"op",text:e}),s+=e.length;continue}if("~+-*/:^()".includes(i)){o.push({kind:"op",text:i}),s++;continue}throw h(`unexpected '${i}'`)}return o.push({kind:"end"}),o}var O={"|":.5,"||":.5,"+":1,"-":1,"*":2,"/":2,"%in%":3,":":4,"^":6},z=5;function B(r,u=!1,o=!1){if(typeof r!="string")throw new TypeError("the formula must be a string");let s=N(r,o),i=0,e=()=>s[i],n=()=>s[i++],c=(t,a)=>t.kind==="op"&&t.text===a;function f(){let t=n();if(t.kind==="name"){if(c(e(),"(")){if(t.text!=="Error"||!u)throw h(`function calls are not supported (${t.text})`);n();let a=l(0);if(!c(n(),")"))throw h("missing ')'");return{type:"Error",arg:a}}if(t.text===".")return{type:"dot"};if(/^\.[0-9]/.test(t.text))throw h(`unexpected '${t.text}'`);return{type:"var",name:t.text}}if(t.kind==="num")return{type:"num",value:Number(t.text),text:t.text};if(t.kind==="op"&&t.text==="("){let a=l(0);if(!c(n(),")"))throw h("missing ')'");return{type:"paren",arg:a}}if(t.kind==="op"&&(t.text==="-"||t.text==="+"))return{type:"unary",op:t.text,arg:l(z)};throw h(t.kind==="end"?"unexpected end of input":`unexpected '${t.kind==="op"?t.text:""}'`)}function l(t){let a=f();for(;;){let p=e();if(p.kind!=="op")break;let d=O[p.text];if(d===void 0||d<=t)break;n();let y=l(p.text==="^"?d-1:d);a=p.text==="|"||p.text==="||"?{type:"bar",double:p.text==="||",lhs:a,group:y}:{type:"binary",op:p.text,left:a,right:y}}return a}let m;if(!c(e(),"~")){let t=n();if(t.kind!=="name"||t.text==="."||!c(e(),"~"))throw h("the response must be a variable name followed by '~'");m=t.text}n();let x=l(0);if(e().kind!=="end")throw h("unexpected input after the formula");return{response:m,rhs:x}}function C(r){let u=[],o=e=>{if(e.type==="Error"){u.push(e.arg);return}if(e.type==="binary"&&e.op==="+"){let n=o(e.left),c=o(e.right);return n===void 0?c:c===void 0?n:{...e,left:n,right:c}}if(e.type==="binary"&&e.op==="-"){let n=o(e.left);return n===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:n}}return e},s=o(r),i=e=>{if(e.type==="Error")throw h("Error() must be a term of the right-hand side");e.type==="binary"?(i(e.left),i(e.right)):(e.type==="unary"||e.type==="paren")&&i(e.arg)};return s!==void 0&&i(s),u.forEach(i),{treatment:s,errors:u}}function F(r){let u=[],o=e=>{switch(e.type){case"bar":u.push(e);return;case"paren":{let n=o(e.arg);return n===void 0?void 0:{...e,arg:n}}case"binary":if(e.op==="+"){let n=o(e.left),c=o(e.right);return n===void 0?c:c===void 0?n:{...e,left:n,right:c}}if(e.op==="-"){let n=o(e.left);return n===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:n}}return e;default:return e}},s=o(r),i=e=>{if(e.type==="bar")throw h("a random-effects term (lhs | group) must be a term of the right-hand side");e.type==="binary"?(i(e.left),i(e.right)):(e.type==="unary"||e.type==="paren"||e.type==="Error")&&i(e.arg)};s!==void 0&&i(s);for(let e of u)i(e.lhs),i(e.group);return{fixed:s,bars:u}}var R=new Set(["+","-","*","%in%"]);function g(r){switch(r.type){case"var":return r.name;case"dot":return".";case"num":return A(r.value);case"binary":{let u=g(r.left),o=g(r.right);return R.has(r.op)?`${u} ${r.op} ${o}`:`${u}${r.op}${o}`}case"unary":return`${r.op}${g(r.arg)}`;case"paren":return`(${g(r.arg)})`;case"Error":return`Error(${g(r.arg)})`;case"bar":return`${g(r.lhs)} ${r.double?"||":"|"} ${g(r.group)}`}}function b(r,u,o){if(r!==void 0)switch(r.type){case"var":o.includes(r.name)||o.push(r.name);return;case"dot":for(let s of u)o.includes(s)||o.push(s);return;case"num":return;case"binary":b(r.left,u,o),r.op!=="^"&&b(r.right,u,o);return;case"unary":case"paren":case"Error":b(r.arg,u,o);return;case"bar":b(r.lhs,u,o),b(r.group,u,o)}}function I(r,u){let o=[];return b(r,u,o),o}var E=r=>r.join(",");function k(r){let u=new Set;return r.filter(o=>{let s=E(o);return u.has(s)?!1:(u.add(s),!0)})}var $=(r,u)=>[...new Set([...r,...u])].sort((o,s)=>o-s);function T(r,u,o){let s=!0,i=(n,c)=>{switch(n.type){case"var":return[[u(n.name)]];case"dot":return o.map(f=>[u(f)]);case"num":if(n.value===1)s=!c;else if(n.value===0)s=c;else throw h(`a number (${n.text}) is not a term`);return[];case"paren":return i(n.arg,c);case"Error":throw h("Error() must be a term of the right-hand side");case"bar":throw h("a random-effects term (lhs | group) must be a term of the right-hand side");case"unary":return n.op==="+"?i(n.arg,c):(i(n.arg,!c),[]);case"binary":{if(n.op==="^"){let t=i(n.left,c),a=n.right;for(;a.type==="paren";)a=a.arg;let p=a.type==="num"?Math.trunc(a.value):NaN;if(!(p>=2))throw new Error("invalid power in formula");let d=t;for(let y=1;y<p;y++){let w=[];for(let v of t)for(let S of d)w.push($(v,S));d=k(w)}return d}if(n.op==="-"){let t=i(n.left,c),a=new Set(i(n.right,!c).map(E));return t.filter(p=>!a.has(E(p)))}let f=i(n.left,c),l=i(n.right,c);if(f.length===0&&n.op!=="+")return[];let m=()=>{let t=[];for(let a of f)for(let p of l)t.push($(a,p));return t},x=t=>t.reduce((a,p)=>$(a,p),[]);switch(n.op){case"+":return k([...f,...l]);case":":return k(m());case"*":return k([...f,...l,...m()]);case"/":{let t=x(f);return k([...f,...l.map(a=>$(a,t))])}case"%in%":{let t=x(l);return k(f.map(a=>$(a,t)))}}}}throw h("unsupported expression")};return{terms:r===void 0?[]:i(r,!1),intercept:s}}function L(r,u,o=r.rhs){let{response:s}=r,i=u.filter(t=>t!==s),e=s===void 0?[]:[s];b(r.rhs,i,e);let c=T(o,t=>e.indexOf(t),i),f=c.terms.map((t,a)=>[t,a]).sort((t,a)=>t[0].length-a[0].length||t[1]-a[1]).map(([t])=>t),l=[],m=s===void 0?-1:f.findIndex(t=>t.length===1&&t[0]===0);m>=0&&(l.push("the response appeared on the right-hand side and was dropped"),l.push(`problem with term ${m+1} in model.matrix: no columns are assigned`));let x=e.map(()=>f.map(()=>0));return f.forEach((t,a)=>{for(let p of t){let d=t.filter(w=>w!==p),y=d.length===0||f.slice(0,a).some(w=>d.every(v=>w.includes(v)));x[p][a]=y?1:2}}),{variables:e,response:s===void 0?-1:0,terms:f,termLabels:f.map(t=>t.map(a=>e[a]).join(":")),order:f.map(t=>t.length),intercept:c.intercept,factors:x,responseTerm:m,warnings:l}}export{B as a,C as b,F as c,g as d,I as e,T as f,L as g};
1
+ /*! rStats.js 0.15.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{b as A}from"./chunk-HNLKOICT.js";var h=r=>new SyntaxError(`invalid formula: ${r}`);function N(r,u){let o=[],s=0;for(;s<r.length;){let i=r[s];if(/\s/.test(i)){s++;continue}if(/[0-9]/.test(i)||i==="."&&/[0-9]/.test(r[s+1]??"")){let e=/^(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:[eE][+-]?[0-9]+)?/.exec(r.slice(s));o.push({kind:"num",text:e[0]}),s+=e[0].length;continue}if(/[A-Za-z.]/.test(i)){let e=/^[A-Za-z.][A-Za-z0-9._]*/.exec(r.slice(s));o.push({kind:"name",text:e[0]}),s+=e[0].length;continue}if(r.startsWith("%in%",s)){o.push({kind:"op",text:"%in%"}),s+=4;continue}if(u&&i==="|"){let e=r[s+1]==="|"?"||":"|";o.push({kind:"op",text:e}),s+=e.length;continue}if("~+-*/:^()".includes(i)){o.push({kind:"op",text:i}),s++;continue}throw h(`unexpected '${i}'`)}return o.push({kind:"end"}),o}var O={"|":.5,"||":.5,"+":1,"-":1,"*":2,"/":2,"%in%":3,":":4,"^":6},z=5;function B(r,u=!1,o=!1){if(typeof r!="string")throw new TypeError("the formula must be a string");let s=N(r,o),i=0,e=()=>s[i],n=()=>s[i++],c=(t,a)=>t.kind==="op"&&t.text===a;function f(){let t=n();if(t.kind==="name"){if(c(e(),"(")){if(t.text!=="Error"||!u)throw h(`function calls are not supported (${t.text})`);n();let a=l(0);if(!c(n(),")"))throw h("missing ')'");return{type:"Error",arg:a}}if(t.text===".")return{type:"dot"};if(/^\.[0-9]/.test(t.text))throw h(`unexpected '${t.text}'`);return{type:"var",name:t.text}}if(t.kind==="num")return{type:"num",value:Number(t.text),text:t.text};if(t.kind==="op"&&t.text==="("){let a=l(0);if(!c(n(),")"))throw h("missing ')'");return{type:"paren",arg:a}}if(t.kind==="op"&&(t.text==="-"||t.text==="+"))return{type:"unary",op:t.text,arg:l(z)};throw h(t.kind==="end"?"unexpected end of input":`unexpected '${t.kind==="op"?t.text:""}'`)}function l(t){let a=f();for(;;){let p=e();if(p.kind!=="op")break;let d=O[p.text];if(d===void 0||d<=t)break;n();let y=l(p.text==="^"?d-1:d);a=p.text==="|"||p.text==="||"?{type:"bar",double:p.text==="||",lhs:a,group:y}:{type:"binary",op:p.text,left:a,right:y}}return a}let m;if(!c(e(),"~")){let t=n();if(t.kind!=="name"||t.text==="."||!c(e(),"~"))throw h("the response must be a variable name followed by '~'");m=t.text}n();let x=l(0);if(e().kind!=="end")throw h("unexpected input after the formula");return{response:m,rhs:x}}function C(r){let u=[],o=e=>{if(e.type==="Error"){u.push(e.arg);return}if(e.type==="binary"&&e.op==="+"){let n=o(e.left),c=o(e.right);return n===void 0?c:c===void 0?n:{...e,left:n,right:c}}if(e.type==="binary"&&e.op==="-"){let n=o(e.left);return n===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:n}}return e},s=o(r),i=e=>{if(e.type==="Error")throw h("Error() must be a term of the right-hand side");e.type==="binary"?(i(e.left),i(e.right)):(e.type==="unary"||e.type==="paren")&&i(e.arg)};return s!==void 0&&i(s),u.forEach(i),{treatment:s,errors:u}}function F(r){let u=[],o=e=>{switch(e.type){case"bar":u.push(e);return;case"paren":{let n=o(e.arg);return n===void 0?void 0:{...e,arg:n}}case"binary":if(e.op==="+"){let n=o(e.left),c=o(e.right);return n===void 0?c:c===void 0?n:{...e,left:n,right:c}}if(e.op==="-"){let n=o(e.left);return n===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:n}}return e;default:return e}},s=o(r),i=e=>{if(e.type==="bar")throw h("a random-effects term (lhs | group) must be a term of the right-hand side");e.type==="binary"?(i(e.left),i(e.right)):(e.type==="unary"||e.type==="paren"||e.type==="Error")&&i(e.arg)};s!==void 0&&i(s);for(let e of u)i(e.lhs),i(e.group);return{fixed:s,bars:u}}var R=new Set(["+","-","*","%in%"]);function g(r){switch(r.type){case"var":return r.name;case"dot":return".";case"num":return A(r.value);case"binary":{let u=g(r.left),o=g(r.right);return R.has(r.op)?`${u} ${r.op} ${o}`:`${u}${r.op}${o}`}case"unary":return`${r.op}${g(r.arg)}`;case"paren":return`(${g(r.arg)})`;case"Error":return`Error(${g(r.arg)})`;case"bar":return`${g(r.lhs)} ${r.double?"||":"|"} ${g(r.group)}`}}function b(r,u,o){if(r!==void 0)switch(r.type){case"var":o.includes(r.name)||o.push(r.name);return;case"dot":for(let s of u)o.includes(s)||o.push(s);return;case"num":return;case"binary":b(r.left,u,o),r.op!=="^"&&b(r.right,u,o);return;case"unary":case"paren":case"Error":b(r.arg,u,o);return;case"bar":b(r.lhs,u,o),b(r.group,u,o)}}function I(r,u){let o=[];return b(r,u,o),o}var E=r=>r.join(",");function k(r){let u=new Set;return r.filter(o=>{let s=E(o);return u.has(s)?!1:(u.add(s),!0)})}var $=(r,u)=>[...new Set([...r,...u])].sort((o,s)=>o-s);function T(r,u,o){let s=!0,i=(n,c)=>{switch(n.type){case"var":return[[u(n.name)]];case"dot":return o.map(f=>[u(f)]);case"num":if(n.value===1)s=!c;else if(n.value===0)s=c;else throw h(`a number (${n.text}) is not a term`);return[];case"paren":return i(n.arg,c);case"Error":throw h("Error() must be a term of the right-hand side");case"bar":throw h("a random-effects term (lhs | group) must be a term of the right-hand side");case"unary":return n.op==="+"?i(n.arg,c):(i(n.arg,!c),[]);case"binary":{if(n.op==="^"){let t=i(n.left,c),a=n.right;for(;a.type==="paren";)a=a.arg;let p=a.type==="num"?Math.trunc(a.value):NaN;if(!(p>=2))throw new Error("invalid power in formula");let d=t;for(let y=1;y<p;y++){let w=[];for(let v of t)for(let S of d)w.push($(v,S));d=k(w)}return d}if(n.op==="-"){let t=i(n.left,c),a=new Set(i(n.right,!c).map(E));return t.filter(p=>!a.has(E(p)))}let f=i(n.left,c),l=i(n.right,c);if(f.length===0&&n.op!=="+")return[];let m=()=>{let t=[];for(let a of f)for(let p of l)t.push($(a,p));return t},x=t=>t.reduce((a,p)=>$(a,p),[]);switch(n.op){case"+":return k([...f,...l]);case":":return k(m());case"*":return k([...f,...l,...m()]);case"/":{let t=x(f);return k([...f,...l.map(a=>$(a,t))])}case"%in%":{let t=x(l);return k(f.map(a=>$(a,t)))}}}}throw h("unsupported expression")};return{terms:r===void 0?[]:i(r,!1),intercept:s}}function L(r,u,o=r.rhs){let{response:s}=r,i=u.filter(t=>t!==s),e=s===void 0?[]:[s];b(r.rhs,i,e);let c=T(o,t=>e.indexOf(t),i),f=c.terms.map((t,a)=>[t,a]).sort((t,a)=>t[0].length-a[0].length||t[1]-a[1]).map(([t])=>t),l=[],m=s===void 0?-1:f.findIndex(t=>t.length===1&&t[0]===0);m>=0&&(l.push("the response appeared on the right-hand side and was dropped"),l.push(`problem with term ${m+1} in model.matrix: no columns are assigned`));let x=e.map(()=>f.map(()=>0));return f.forEach((t,a)=>{for(let p of t){let d=t.filter(w=>w!==p),y=d.length===0||f.slice(0,a).some(w=>d.every(v=>w.includes(v)));x[p][a]=y?1:2}}),{variables:e,response:s===void 0?-1:0,terms:f,termLabels:f.map(t=>t.map(a=>e[a]).join(":")),order:f.map(t=>t.length),intercept:c.intercept,factors:x,responseTerm:m,warnings:l}}export{B as a,C as b,F as c,g as d,I as e,T as f,L as g};
@@ -1,2 +1,2 @@
1
- /*! rStats.js 0.13.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 z,b as G,c as K,d as U,e as k,f as b,g as S,i as F}from"./chunk-SLSDFIW2.js";import{g as L}from"./chunk-MEMYFTYS.js";import{a as I}from"./chunk-JGFUZKLJ.js";function v(t){let o=Object.values(t),n=o[0]?.length??0;if(o.some(r=>r.length!==n))throw new RangeError("the columns of a data frame must have the same length");return n}var Y=t=>t==null||typeof t=="number"&&Number.isNaN(t),M=(t,o)=>t[o];function _(t,o){if(t.length>0&&t.every(n=>n instanceof Float64Array)){let n=new Float64Array(o.length);return o.forEach((r,e)=>n[e]=r===null?NaN:r[0][r[1]]),n}return o.map(n=>n===null?null:M(n[0],n[1]))}function pn(t,o){return t instanceof Float64Array?Float64Array.from(o,n=>t[n]):o.map(n=>M(t,n))}function j(t,o,n){if(Object.hasOwn(t,o))throw new Error(`duplicate column name '${o}'`);t[o]=n}function dn(t){if(Number.isNaN(t))return"NA";if(!Number.isFinite(t))return t>0?"Inf":"-Inf";if(t===0)return"0";let[o,n]=Number(t.toPrecision(15)).toExponential().split("e"),r=o.startsWith("-"),e=o.replace("-","").replace(".",""),s=Number(n),c=e.length,u=String(Math.abs(s)).padStart(2,"0"),f=c+(c>1?1:0)+2+u.length,a=s>=0?Math.max(s+1,c)+(c>s+1?1:0):2-s-1+c,l=r?"-":"";return a>f?`${l}${e[0]}${c>1?`.${e.slice(1)}`:""}e${s<0?"-":"+"}${u}`:s<0?`${l}0.${"0".repeat(-s-1)}${e}`:c<=s+1?`${l}${e}${"0".repeat(s+1-c)}`:`${l}${e.slice(0,s+1)}.${e.slice(s+1)}`}function B(t){return Y(t)?"NA":typeof t=="number"?dn(t):typeof t=="boolean"?t?"TRUE":"FALSE":t}var gn=Symbol("NA"),H=t=>typeof t=="number"?0:typeof t=="string"?1:2;function yn(t,o){let n=Y(t),r=Y(o);if(n||r)return n===r?0:n?1:-1;let e=t,s=o;return typeof e!=typeof s?H(e)-H(s):typeof e=="string"?I(e,s):Number(e)-Number(s)}function Nn(t){let o=t.length,n=[...t],r=t.map((s,c)=>c),e=1;for(;e<=Math.trunc(o/9);)e=3*e+1;for(;e>0;e=Math.trunc(e/3))for(let s=e;s<o;s++){let c=n[s],u=r[s],f=s;for(;f>=e&&n[f-e]>c;)n[f]=n[f-e],r[f]=r[f-e],f-=e;n[f]=c,r[f]=u}return r}function J(t){let o=[],n=new Map;for(let r of Nn(t)){let e=t[r];if(e===0)o.push(r);else{let s=n.get(e);s===void 0?n.set(e,[r]):s.push(r)}}return{alone:o,groups:n}}var D=t=>typeof t=="string"?[t]:[...t];function Q(t,o){return o.map(n=>{if(!Object.hasOwn(t,n))throw new Error("'by' must specify a uniquely valid column");return t[n]})}function xn(t,o,n={}){let r=Object.keys(t),e=Object.keys(o),s=v(t),c=v(o),u=n.by===void 0?r.filter(i=>e.includes(i)):D(n.by),f=n.byX===void 0?u:D(n.byX),a=n.byY===void 0?u:D(n.byY),l=Q(t,f),w=Q(o,a);if(f.length!==a.length)throw new Error("'by.x' and 'by.y' specify different numbers of columns");let R=n.allX??n.all??!1,A=n.allY??n.all??!1,cn=n.sort??!0,[fn,un]=n.suffixes??[".x",".y"],P=r.filter(i=>!f.includes(i)),C=e.filter(i=>!a.includes(i)),an=i=>C.includes(i)?i+fn:i,ln=i=>P.includes(i)||f.includes(i)?i+un:i,x=[];if(f.length===0)for(let i=0;i<c;i++)for(let m=0;m<s;m++)x.push([m,i]);else{let i=f.length===1?(p,N)=>{let O=M(p[0],N);return Y(O)?gn:O}:(p,N)=>p.map(O=>B(M(O,N))).join("\r"),m=Array.from({length:s},(p,N)=>i(l,N)),h=Array.from({length:c},(p,N)=>i(w,N)),d=new Set(h),g=new Map,E=0;for(let p of m)d.has(p)&&(E++,g.has(p)||g.set(p,E));let V=J(m.map(p=>g.get(p)??0)),W=J(h.map(p=>g.get(p)??0));for(let[p,N]of V.groups){let O=W.groups.get(p)??[];for(let mn of N)for(let hn of O)x.push([mn,hn])}if(R)for(let p of V.alone)x.push([p,-1]);if(A)for(let p of W.alone)x.push([-1,p])}let q=x.map((i,m)=>m);if(cn&&f.length>0){let i=(m,h)=>{let[d,g]=x[m];return d>=0?M(l[h],d):M(w[h],g)};if(f.length>1&&!R&&!A){let m=x.map((h,d)=>f.map((g,E)=>B(i(d,E))).join("\r"));q.sort((h,d)=>I(m[h],m[d]))}else q.sort((m,h)=>{for(let d=0;d<f.length;d++){let g=yn(i(m,d),i(h,d));if(g!==0)return g}return 0})}let X=q.map(i=>x[i]),$={};f.forEach((i,m)=>{let h=l[m],d=w[m];j($,i,_([h,d],X.map(([g,E])=>g>=0?[h,g]:[d,E])))});for(let i of P){let m=t[i];j($,an(i),_([m],X.map(([h])=>h>=0?[m,h]:null)))}for(let i of C){let m=o[i];j($,ln(i),_([m],X.map(([,h])=>h>=0?[m,h]:null)))}return $}function Mn(t,o,n={}){let r=Object.keys(t),e=v(t);if(typeof o!="function"&&o.length!==e)throw new RangeError(`'keep' has ${o.length} values for ${e} rows`);let s=a=>Object.fromEntries(r.map(l=>[l,M(t[l],a)])),c=[];for(let a=0;a<e;a++)(typeof o=="function"?o(s(a)):o[a])===!0&&c.push(a);let u=n.select??r,f={};for(let a of u){if(!Object.hasOwn(t,a))throw new Error("undefined columns selected");j(f,a,pn(t[a],c))}return f}function An(t){if(t.length===0)return{};let o=Object.keys(t[0]);for(let r of t)if(v(r),Object.keys(r).length!==o.length||!o.every(s=>Object.hasOwn(r,s)))throw new Error("names do not match previous names");let n={};for(let r of o){let e=t.map(c=>c[r]),s=e.flatMap(c=>Array.from({length:c.length},(u,f)=>[c,f]));n[r]=_(e,s)}return n}function En(t){let o={},n=t.map(v),r=n.find(e=>e!==n[0]);if(r!==void 0)throw new RangeError(`arguments imply differing number of rows: ${n[0]}, ${r}`);for(let e of t)for(let[s,c]of Object.entries(e))j(o,s,c instanceof Float64Array?Float64Array.from(c):[...c]);return o}function On(t,o={}){let n=o.columns;if(n===void 0){let e=new Set;for(let s of t)for(let c of Object.keys(s))e.add(c);n=[...e]}let r={};for(let e of n){let s=new Set,c=t.map((u,f)=>{let a=Object.hasOwn(u,e)?u[e]:void 0;if(a==null)return null;if(typeof a!="number"&&typeof a!="string"&&typeof a!="boolean")throw new TypeError(`row ${f}, column '${e}': values must be numbers, strings, booleans or null`);return s.add(typeof a),a});if(s.size>1)throw new TypeError(`column '${e}' mixes ${[...s].join(" and ")} values`);j(r,e,c)}return r}function jn(t){let o=Object.keys(t),n=v(t);return Array.from({length:n},(r,e)=>Object.fromEntries(o.map(s=>[s,M(t[s],e)])))}function y(t,o){let n=Array.from(t);return o?n.filter(r=>!Number.isNaN(r)):n.some(Number.isNaN)?void 0:n}function kn(t,o={}){let n=y(t,o.naRm);return n===void 0?NaN:F(n)}function Sn(t,o={}){let n=y(t,o.naRm);if(n===void 0)return NaN;let r=Z();for(let e=0;e<n.length;e++){let s=n[e];if(!Number.isFinite(s)||s===0)return n.slice(e).reduce((c,u)=>c*u,tn(r));nn(r,s)}return en(r.p,r.e)}function Z(){return{p:[1,0],e:0}}function nn(t,o){let n=Math.floor(Math.log2(Math.abs(o)));(n>500||n<-500)&&(o=U(o,-n),t.e+=n);let r=L(t.p,[o,0]);if(n=Math.floor(Math.log2(Math.abs(r[0]))),n>500||n<-500){let e=2**-n;r=[r[0]*e,r[1]*e],t.e+=n}t.p=r}function tn(t){return t.p[0]<0?-1:1}function Fn(t,o={}){let n=y(t,o.naRm);if(n===void 0)return NaN;let r=n.length;if(r===0)return NaN;let e=o.trim??0;if(Number.isNaN(e))throw new RangeError("'trim' must be numeric of length one");if(e>0&&r>0){if(e>=.5)return T(n);e=Math.max(e,0);let s=Math.floor(r*e),c=[...n].sort((u,f)=>u-f);return b(c.slice(s,r-s))}return b(n)}function _n(t,o,n={}){let r=Array.from(t),e=Array.from(o);if(r.length!==e.length)throw new RangeError("'x' and 'w' must have the same length");if(n.naRm){let c=r.map(u=>!Number.isNaN(u));r=r.filter((u,f)=>c[f]),e=e.filter((u,f)=>c[f])}let s=[];for(let c=0;c<r.length;c++)e[c]!==0&&s.push(r[c]*e[c]);return F(s)/F(e)}function bn(t,o={}){let n=y(t,o.naRm);return n===void 0?NaN:S(n)}function Yn(t,o={}){return Math.sqrt(bn(t,o))}function T(t,o={}){let n=y(t,o.naRm);if(n===void 0)return NaN;let r=n.length;if(r===0)return NaN;let e=[...n].sort((c,u)=>c-u),s=Math.floor(r/2);return r%2===1?e[s]:k([e[s-1],e[s]])[0]}function qn(t,o={}){let n=y(t,o.naRm);if(n===void 0)return[NaN,NaN];let r=1/0,e=-1/0;for(let s of n)s<r&&(r=s),s>e&&(e=s);return[r,e]}function Xn(t){let o=Array.from(t),n=[],r=z(),e;for(let s of o){if(e===void 0&&!Number.isFinite(s)&&(e=0),e!==void 0){e+=s,n.push(e);continue}G(r,s,o.length),n.push(K(r))}return n}function In(t){let o=[],n=Z(),r;for(let e of Array.from(t)){if(r===void 0&&(!Number.isFinite(e)||e===0)&&(r=tn(n)),r!==void 0){r*=e,o.push(r);continue}nn(n,e),o.push(en(n.p,n.e))}return o}function en(t,o){let n=t[0]+t[1];for(;o>0&&Number.isFinite(n);){let r=Math.min(o,1e3);n*=2**r,o-=r}for(;o<0&&n!==0;){let r=Math.max(o,-1e3);n*=2**r,o-=r}return n}function rn(t,o){let n=[],r=NaN,e=!1;for(let s of Array.from(t)){if(e||Number.isNaN(s)){e=!0,n.push(NaN);continue}(n.length===0||o(s,r))&&(r=s),n.push(r)}return n}function Dn(t){return rn(t,(o,n)=>o>n)}function Tn(t){return rn(t,(o,n)=>o<n)}function Pn(t,o={}){let n=o.lag??1,r=o.differences??1;if(!(Number.isInteger(n)&&n>=1&&Number.isInteger(r)&&r>=1))throw new RangeError("'lag' and 'differences' must be integers >= 1");let e=Array.from(t);if(n*r>=e.length)return[];for(let s=0;s<r;s++){let c=[];for(let u=n;u<e.length;u++)c.push(e[u]-e[u-n]);e=c}return e}function on(t){let o=k(t),n=0,r=0,e=0;for(let s of t){let c=s-o[0]-o[1],u=c*c;n+=u,r+=u*c,e+=u*u}return[n,r,e]}function sn(t){if(![1,2,3].includes(t))throw new RangeError("Invalid 'type' argument.")}function zn(t,o={}){let n=o.type??3;sn(n);let r=y(t,!0),e=r.length,[s,c]=on(r),u=Math.sqrt(e)*c/s**1.5;if(n===1)return u;if(n===2){if(e<3)throw new RangeError("Need at least 3 complete observations.");return u*Math.sqrt(e*(e-1))/(e-2)}return u*(1-1/e)**1.5}function Gn(t,o={}){let n=o.type??3;sn(n);let r=y(t,!0),e=r.length,[s,,c]=on(r),u=e*c/(s*s);if(n===1)return u-3;if(n===2){if(e<4)throw new RangeError("Need at least 4 complete observations.");return((e+1)*(u-3)+6)*(e-1)/((e-2)*(e-3))}return u*(1-1/e)**2-3}function Kn(t,o={}){let n=y(t,o.naRm);return n===void 0?NaN:n.some(r=>r<0)?NaN:n.includes(0)?0:Math.exp(b(n.map(Math.log)))}function Un(t){let o=y(t,!0),n=new Map;for(let s of o)n.set(s===0?0:s,(n.get(s===0?0:s)??0)+1);let r=0;for(let s of n.values())r=Math.max(r,s);return r<=1?{value:[NaN],frequency:NaN}:{value:[...n.entries()].filter(([,s])=>s===r).map(([s])=>s).sort((s,c)=>s-c),frequency:r}}function Bn(t,o={}){let n=y(t,!0),r=o.center??"mean",e=r==="mean"?b(n):r==="median"?T(n):r;return b(n.map(s=>Math.abs(s-e)))}function Hn(t,o={}){let n=y(t,o.naRm);if(n===void 0)return NaN;let r=n.length,e=Math.sqrt(S(n))/b(n);return o.unbiased&&(e*=1-1/(4*(r-1))+e*e/r+1/(2*(r-1)**2)),e}function Jn(t,o={}){let n=t.length>0&&Array.isArray(t[0])?t.map(f=>[...f]):Array.from(t,f=>[f]),r=n[0]?.length??0,e=f=>n.map(a=>a[f]),s={scaled:n},c=o.center??!0;if(c!==!1){let f=c===!0?Array.from({length:r},(a,l)=>b(e(l).filter(w=>!Number.isNaN(w)))):[...c];if(f.length!==r)throw new RangeError("length of 'center' must equal the number of columns of 'x'");for(let a of n)for(let l=0;l<r;l++)a[l]=a[l]-f[l];s.center=f}let u=o.scale??!0;if(u!==!1){let f=u===!0?Array.from({length:r},(a,l)=>{let w=e(l).filter(A=>!Number.isNaN(A)),R=0;for(let A of w)R+=A*A;return Math.sqrt(R/Math.max(1,w.length-1))}):[...u];if(f.length!==r)throw new RangeError("length of 'scale' must equal the number of columns of 'x'");for(let a of n)for(let l=0;l<r;l++)a[l]=a[l]/f[l];s.scale=f}return s}export{v as a,Y as b,pn as c,j as d,yn as e,xn as f,Mn as g,An as h,En as i,On as j,jn as k,y as l,kn as m,Sn as n,Fn as o,_n as p,bn as q,Yn as r,T as s,qn as t,Xn as u,In as v,Dn as w,Tn as x,Pn as y,zn as z,Gn as A,Kn as B,Un as C,Bn as D,Hn as E,Jn as F};
1
+ /*! rStats.js 0.15.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 z,b as G,c as K,d as U,e as k,f as b,g as S,i as F}from"./chunk-HS7KIFMR.js";import{a as I}from"./chunk-WEWXYHPR.js";import{g as L}from"./chunk-4EOKNOXP.js";function v(t){let o=Object.values(t),n=o[0]?.length??0;if(o.some(r=>r.length!==n))throw new RangeError("the columns of a data frame must have the same length");return n}var Y=t=>t==null||typeof t=="number"&&Number.isNaN(t),M=(t,o)=>t[o];function _(t,o){if(t.length>0&&t.every(n=>n instanceof Float64Array)){let n=new Float64Array(o.length);return o.forEach((r,e)=>n[e]=r===null?NaN:r[0][r[1]]),n}return o.map(n=>n===null?null:M(n[0],n[1]))}function pn(t,o){return t instanceof Float64Array?Float64Array.from(o,n=>t[n]):o.map(n=>M(t,n))}function j(t,o,n){if(Object.hasOwn(t,o))throw new Error(`duplicate column name '${o}'`);t[o]=n}function dn(t){if(Number.isNaN(t))return"NA";if(!Number.isFinite(t))return t>0?"Inf":"-Inf";if(t===0)return"0";let[o,n]=Number(t.toPrecision(15)).toExponential().split("e"),r=o.startsWith("-"),e=o.replace("-","").replace(".",""),s=Number(n),c=e.length,u=String(Math.abs(s)).padStart(2,"0"),f=c+(c>1?1:0)+2+u.length,a=s>=0?Math.max(s+1,c)+(c>s+1?1:0):2-s-1+c,l=r?"-":"";return a>f?`${l}${e[0]}${c>1?`.${e.slice(1)}`:""}e${s<0?"-":"+"}${u}`:s<0?`${l}0.${"0".repeat(-s-1)}${e}`:c<=s+1?`${l}${e}${"0".repeat(s+1-c)}`:`${l}${e.slice(0,s+1)}.${e.slice(s+1)}`}function B(t){return Y(t)?"NA":typeof t=="number"?dn(t):typeof t=="boolean"?t?"TRUE":"FALSE":t}var gn=Symbol("NA"),H=t=>typeof t=="number"?0:typeof t=="string"?1:2;function yn(t,o){let n=Y(t),r=Y(o);if(n||r)return n===r?0:n?1:-1;let e=t,s=o;return typeof e!=typeof s?H(e)-H(s):typeof e=="string"?I(e,s):Number(e)-Number(s)}function Nn(t){let o=t.length,n=[...t],r=t.map((s,c)=>c),e=1;for(;e<=Math.trunc(o/9);)e=3*e+1;for(;e>0;e=Math.trunc(e/3))for(let s=e;s<o;s++){let c=n[s],u=r[s],f=s;for(;f>=e&&n[f-e]>c;)n[f]=n[f-e],r[f]=r[f-e],f-=e;n[f]=c,r[f]=u}return r}function J(t){let o=[],n=new Map;for(let r of Nn(t)){let e=t[r];if(e===0)o.push(r);else{let s=n.get(e);s===void 0?n.set(e,[r]):s.push(r)}}return{alone:o,groups:n}}var D=t=>typeof t=="string"?[t]:[...t];function Q(t,o){return o.map(n=>{if(!Object.hasOwn(t,n))throw new Error("'by' must specify a uniquely valid column");return t[n]})}function xn(t,o,n={}){let r=Object.keys(t),e=Object.keys(o),s=v(t),c=v(o),u=n.by===void 0?r.filter(i=>e.includes(i)):D(n.by),f=n.byX===void 0?u:D(n.byX),a=n.byY===void 0?u:D(n.byY),l=Q(t,f),w=Q(o,a);if(f.length!==a.length)throw new Error("'by.x' and 'by.y' specify different numbers of columns");let R=n.allX??n.all??!1,A=n.allY??n.all??!1,cn=n.sort??!0,[fn,un]=n.suffixes??[".x",".y"],P=r.filter(i=>!f.includes(i)),C=e.filter(i=>!a.includes(i)),an=i=>C.includes(i)?i+fn:i,ln=i=>P.includes(i)||f.includes(i)?i+un:i,x=[];if(f.length===0)for(let i=0;i<c;i++)for(let m=0;m<s;m++)x.push([m,i]);else{let i=f.length===1?(p,N)=>{let O=M(p[0],N);return Y(O)?gn:O}:(p,N)=>p.map(O=>B(M(O,N))).join("\r"),m=Array.from({length:s},(p,N)=>i(l,N)),h=Array.from({length:c},(p,N)=>i(w,N)),d=new Set(h),g=new Map,E=0;for(let p of m)d.has(p)&&(E++,g.has(p)||g.set(p,E));let V=J(m.map(p=>g.get(p)??0)),W=J(h.map(p=>g.get(p)??0));for(let[p,N]of V.groups){let O=W.groups.get(p)??[];for(let mn of N)for(let hn of O)x.push([mn,hn])}if(R)for(let p of V.alone)x.push([p,-1]);if(A)for(let p of W.alone)x.push([-1,p])}let q=x.map((i,m)=>m);if(cn&&f.length>0){let i=(m,h)=>{let[d,g]=x[m];return d>=0?M(l[h],d):M(w[h],g)};if(f.length>1&&!R&&!A){let m=x.map((h,d)=>f.map((g,E)=>B(i(d,E))).join("\r"));q.sort((h,d)=>I(m[h],m[d]))}else q.sort((m,h)=>{for(let d=0;d<f.length;d++){let g=yn(i(m,d),i(h,d));if(g!==0)return g}return 0})}let X=q.map(i=>x[i]),$={};f.forEach((i,m)=>{let h=l[m],d=w[m];j($,i,_([h,d],X.map(([g,E])=>g>=0?[h,g]:[d,E])))});for(let i of P){let m=t[i];j($,an(i),_([m],X.map(([h])=>h>=0?[m,h]:null)))}for(let i of C){let m=o[i];j($,ln(i),_([m],X.map(([,h])=>h>=0?[m,h]:null)))}return $}function Mn(t,o,n={}){let r=Object.keys(t),e=v(t);if(typeof o!="function"&&o.length!==e)throw new RangeError(`'keep' has ${o.length} values for ${e} rows`);let s=a=>Object.fromEntries(r.map(l=>[l,M(t[l],a)])),c=[];for(let a=0;a<e;a++)(typeof o=="function"?o(s(a)):o[a])===!0&&c.push(a);let u=n.select??r,f={};for(let a of u){if(!Object.hasOwn(t,a))throw new Error("undefined columns selected");j(f,a,pn(t[a],c))}return f}function An(t){if(t.length===0)return{};let o=Object.keys(t[0]);for(let r of t)if(v(r),Object.keys(r).length!==o.length||!o.every(s=>Object.hasOwn(r,s)))throw new Error("names do not match previous names");let n={};for(let r of o){let e=t.map(c=>c[r]),s=e.flatMap(c=>Array.from({length:c.length},(u,f)=>[c,f]));n[r]=_(e,s)}return n}function En(t){let o={},n=t.map(v),r=n.find(e=>e!==n[0]);if(r!==void 0)throw new RangeError(`arguments imply differing number of rows: ${n[0]}, ${r}`);for(let e of t)for(let[s,c]of Object.entries(e))j(o,s,c instanceof Float64Array?Float64Array.from(c):[...c]);return o}function On(t,o={}){let n=o.columns;if(n===void 0){let e=new Set;for(let s of t)for(let c of Object.keys(s))e.add(c);n=[...e]}let r={};for(let e of n){let s=new Set,c=t.map((u,f)=>{let a=Object.hasOwn(u,e)?u[e]:void 0;if(a==null)return null;if(typeof a!="number"&&typeof a!="string"&&typeof a!="boolean")throw new TypeError(`row ${f}, column '${e}': values must be numbers, strings, booleans or null`);return s.add(typeof a),a});if(s.size>1)throw new TypeError(`column '${e}' mixes ${[...s].join(" and ")} values`);j(r,e,c)}return r}function jn(t){let o=Object.keys(t),n=v(t);return Array.from({length:n},(r,e)=>Object.fromEntries(o.map(s=>[s,M(t[s],e)])))}function y(t,o){let n=Array.from(t);return o?n.filter(r=>!Number.isNaN(r)):n.some(Number.isNaN)?void 0:n}function kn(t,o={}){let n=y(t,o.naRm);return n===void 0?NaN:F(n)}function Sn(t,o={}){let n=y(t,o.naRm);if(n===void 0)return NaN;let r=Z();for(let e=0;e<n.length;e++){let s=n[e];if(!Number.isFinite(s)||s===0)return n.slice(e).reduce((c,u)=>c*u,tn(r));nn(r,s)}return en(r.p,r.e)}function Z(){return{p:[1,0],e:0}}function nn(t,o){let n=Math.floor(Math.log2(Math.abs(o)));(n>500||n<-500)&&(o=U(o,-n),t.e+=n);let r=L(t.p,[o,0]);if(n=Math.floor(Math.log2(Math.abs(r[0]))),n>500||n<-500){let e=2**-n;r=[r[0]*e,r[1]*e],t.e+=n}t.p=r}function tn(t){return t.p[0]<0?-1:1}function Fn(t,o={}){let n=y(t,o.naRm);if(n===void 0)return NaN;let r=n.length;if(r===0)return NaN;let e=o.trim??0;if(Number.isNaN(e))throw new RangeError("'trim' must be numeric of length one");if(e>0&&r>0){if(e>=.5)return T(n);e=Math.max(e,0);let s=Math.floor(r*e),c=[...n].sort((u,f)=>u-f);return b(c.slice(s,r-s))}return b(n)}function _n(t,o,n={}){let r=Array.from(t),e=Array.from(o);if(r.length!==e.length)throw new RangeError("'x' and 'w' must have the same length");if(n.naRm){let c=r.map(u=>!Number.isNaN(u));r=r.filter((u,f)=>c[f]),e=e.filter((u,f)=>c[f])}let s=[];for(let c=0;c<r.length;c++)e[c]!==0&&s.push(r[c]*e[c]);return F(s)/F(e)}function bn(t,o={}){let n=y(t,o.naRm);return n===void 0?NaN:S(n)}function Yn(t,o={}){return Math.sqrt(bn(t,o))}function T(t,o={}){let n=y(t,o.naRm);if(n===void 0)return NaN;let r=n.length;if(r===0)return NaN;let e=[...n].sort((c,u)=>c-u),s=Math.floor(r/2);return r%2===1?e[s]:k([e[s-1],e[s]])[0]}function qn(t,o={}){let n=y(t,o.naRm);if(n===void 0)return[NaN,NaN];let r=1/0,e=-1/0;for(let s of n)s<r&&(r=s),s>e&&(e=s);return[r,e]}function Xn(t){let o=Array.from(t),n=[],r=z(),e;for(let s of o){if(e===void 0&&!Number.isFinite(s)&&(e=0),e!==void 0){e+=s,n.push(e);continue}G(r,s,o.length),n.push(K(r))}return n}function In(t){let o=[],n=Z(),r;for(let e of Array.from(t)){if(r===void 0&&(!Number.isFinite(e)||e===0)&&(r=tn(n)),r!==void 0){r*=e,o.push(r);continue}nn(n,e),o.push(en(n.p,n.e))}return o}function en(t,o){let n=t[0]+t[1];for(;o>0&&Number.isFinite(n);){let r=Math.min(o,1e3);n*=2**r,o-=r}for(;o<0&&n!==0;){let r=Math.max(o,-1e3);n*=2**r,o-=r}return n}function rn(t,o){let n=[],r=NaN,e=!1;for(let s of Array.from(t)){if(e||Number.isNaN(s)){e=!0,n.push(NaN);continue}(n.length===0||o(s,r))&&(r=s),n.push(r)}return n}function Dn(t){return rn(t,(o,n)=>o>n)}function Tn(t){return rn(t,(o,n)=>o<n)}function Pn(t,o={}){let n=o.lag??1,r=o.differences??1;if(!(Number.isInteger(n)&&n>=1&&Number.isInteger(r)&&r>=1))throw new RangeError("'lag' and 'differences' must be integers >= 1");let e=Array.from(t);if(n*r>=e.length)return[];for(let s=0;s<r;s++){let c=[];for(let u=n;u<e.length;u++)c.push(e[u]-e[u-n]);e=c}return e}function on(t){let o=k(t),n=0,r=0,e=0;for(let s of t){let c=s-o[0]-o[1],u=c*c;n+=u,r+=u*c,e+=u*u}return[n,r,e]}function sn(t){if(![1,2,3].includes(t))throw new RangeError("Invalid 'type' argument.")}function zn(t,o={}){let n=o.type??3;sn(n);let r=y(t,!0),e=r.length,[s,c]=on(r),u=Math.sqrt(e)*c/s**1.5;if(n===1)return u;if(n===2){if(e<3)throw new RangeError("Need at least 3 complete observations.");return u*Math.sqrt(e*(e-1))/(e-2)}return u*(1-1/e)**1.5}function Gn(t,o={}){let n=o.type??3;sn(n);let r=y(t,!0),e=r.length,[s,,c]=on(r),u=e*c/(s*s);if(n===1)return u-3;if(n===2){if(e<4)throw new RangeError("Need at least 4 complete observations.");return((e+1)*(u-3)+6)*(e-1)/((e-2)*(e-3))}return u*(1-1/e)**2-3}function Kn(t,o={}){let n=y(t,o.naRm);return n===void 0?NaN:n.some(r=>r<0)?NaN:n.includes(0)?0:Math.exp(b(n.map(Math.log)))}function Un(t){let o=y(t,!0),n=new Map;for(let s of o)n.set(s===0?0:s,(n.get(s===0?0:s)??0)+1);let r=0;for(let s of n.values())r=Math.max(r,s);return r<=1?{value:[NaN],frequency:NaN}:{value:[...n.entries()].filter(([,s])=>s===r).map(([s])=>s).sort((s,c)=>s-c),frequency:r}}function Bn(t,o={}){let n=y(t,!0),r=o.center??"mean",e=r==="mean"?b(n):r==="median"?T(n):r;return b(n.map(s=>Math.abs(s-e)))}function Hn(t,o={}){let n=y(t,o.naRm);if(n===void 0)return NaN;let r=n.length,e=Math.sqrt(S(n))/b(n);return o.unbiased&&(e*=1-1/(4*(r-1))+e*e/r+1/(2*(r-1)**2)),e}function Jn(t,o={}){let n=t.length>0&&Array.isArray(t[0])?t.map(f=>[...f]):Array.from(t,f=>[f]),r=n[0]?.length??0,e=f=>n.map(a=>a[f]),s={scaled:n},c=o.center??!0;if(c!==!1){let f=c===!0?Array.from({length:r},(a,l)=>b(e(l).filter(w=>!Number.isNaN(w)))):[...c];if(f.length!==r)throw new RangeError("length of 'center' must equal the number of columns of 'x'");for(let a of n)for(let l=0;l<r;l++)a[l]=a[l]-f[l];s.center=f}let u=o.scale??!0;if(u!==!1){let f=u===!0?Array.from({length:r},(a,l)=>{let w=e(l).filter(A=>!Number.isNaN(A)),R=0;for(let A of w)R+=A*A;return Math.sqrt(R/Math.max(1,w.length-1))}):[...u];if(f.length!==r)throw new RangeError("length of 'scale' must equal the number of columns of 'x'");for(let a of n)for(let l=0;l<r;l++)a[l]=a[l]/f[l];s.scale=f}return s}export{v as a,Y as b,pn as c,j as d,yn as e,xn as f,Mn as g,An as h,En as i,On as j,jn as k,y as l,kn as m,Sn as n,Fn as o,_n as p,bn as q,Yn as r,T as s,qn as t,Xn as u,In as v,Dn as w,Tn as x,Pn as y,zn as z,Gn as A,Kn as B,Un as C,Bn as D,Hn as E,Jn as F};
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.15.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 re}from"./chunk-4XGKAHD3.js";import{e as ne,h as se,j as X,k as I,m as oe}from"./chunk-HS7KIFMR.js";import{a as ae,g as ie}from"./chunk-A3XZUJCP.js";import{k as B}from"./chunk-VSKWQMSG.js";import{b as ce,c as S}from"./chunk-WEWXYHPR.js";import{b as Y}from"./chunk-HNLKOICT.js";import{g as D,h as G}from"./chunk-CMPDE3SZ.js";import{b as ee,c as te,d as V,f as q,g as C,i as W}from"./chunk-4EOKNOXP.js";function j(e){if(e.kind==="factor")return ce(e);let t=[...new Set(e.values)].sort((s,o)=>s-o),n=[...new Set(t.map(Y))],r=new Map(n.map((s,o)=>[s,o]));return{levels:n,codes:e.values.map(s=>r.get(Y(s)))}}function A(e,t){if(e.kind!=="numeric")throw new TypeError(`'${t}' must be a numeric column`);return e.values}function R(e,t){let n=ae(e),r=ie(n,Object.keys(t));return{terms:r,rhsVariables:r.variables.slice(r.response===0?1:0)}}function fe(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 Ae=/^Pair\s*\(\s*([A-Za-z.][A-Za-z0-9._]*)\s*,\s*([A-Za-z.][A-Za-z0-9._]*)\s*\)$/,F="'formula' missing or incorrect",le=(e,t)=>t.length===0&&e.terms.length===0&&e.intercept;function Ve(e,t,n){let r=fe(e),s=r===void 0?null:Ae.exec(r.lhs);if(s!==null){let{terms:m,rhsVariables:p}=R(`~${r.rhs}`,t);if(!n||!le(m,p))throw new Error(F);let w=S(t,[s[1],s[2]]);return{kind:"paired",x:A(w.variables[0],s[1]),y:A(w.variables[1],s[2])}}let{terms:o,rhsVariables:c}=R(e,t);if(o.response<0)throw new Error(F);let i=o.variables[0];if(n&&le(o,c))return{kind:"one",x:A(S(t,[i]).variables[0],i)};if(c.length!==1||o.terms.length!==1)throw new Error(F);let a=S(t,[i,c[0]],{dropUnusedLevels:!0}),l=A(a.variables[0],i),u=j(a.variables[1]);if(u.levels.length!==2)throw new Error("grouping factor must have exactly 2 levels");return{kind:"two",x:l.filter((m,p)=>u.codes[p]===0),y:l.filter((m,p)=>u.codes[p]===1),levels:[u.levels[0],u.levels[1]]}}function Ie(e,t){let n=Ve(e,t,!1);if(n.kind!=="two")throw new Error(F);return n}function je(e,t){let{terms:n,rhsVariables:r}=R(e,t);if(n.response<0)throw new Error(F);if(r.length!==1)throw new Error("'formula' should be of the form response ~ group");let s=n.variables[0],o=S(t,[s,r[0]],{dropUnusedLevels:!0});return{values:A(o.variables[0],s),group:j(o.variables[1])}}function ze(e,t){let n=t.levels.map(()=>[]);return e.forEach((r,s)=>n[t.codes[s]].push(r)),n}function Ue(e,t){let{terms:n,rhsVariables:r}=R(e,t);if(n.response<0||r.length===0)throw new Error(F);let s=n.variables[0],o=S(t,[s,...r],{dropUnusedLevels:!0}),c=o.variables.slice(1).map(j),i=o.rows.map((a,l)=>{let u=0,m=1;for(let p of c)u+=p.codes[l]*m,m*=p.levels.length;return u});return{values:A(o.variables[0],s),groups:i}}var ue="incorrect specification for 'formula'";function Ze(e,t){let n=fe(e),r=n?.rhs.split("|");if(n===void 0||n.lhs===""||r.length!==2)throw new Error(ue);let s=y=>{let{terms:E,rhsVariables:h}=R(y,t);if(h.length!==1||E.terms.length!==1)throw new Error(ue);return h[0]},{terms:o}=R(`${n.lhs} ~ 1`,t),c=o.variables[0],i=s(`~${r[0]}`),a=s(`~${r[1]}`),l=S(t,[c,i,a],{dropUnusedLevels:!0}),u=A(l.variables[0],c),m=j(l.variables[1]),p=j(l.variables[2]),w=p.levels.map(()=>m.levels.map(()=>NaN)),N=p.levels.map(()=>m.levels.map(()=>0));if(u.forEach((y,E)=>{let h=p.codes[E],g=m.codes[E];N[h][g]++,w[h][g]=y}),N.some(y=>y.some(E=>E!==1)))throw new Error("not an unreplicated complete block design");return w}function me(e,t){let{terms:n,rhsVariables:r}=R(e,t);if(n.response>=0)throw new Error("'formula' missing or invalid");if(r.length!==2)throw new Error("invalid formula");let s=S(t,r);return{x:A(s.variables[0],r[0]),y:A(s.variables[1],r[1])}}function he(e){if(e===void 0)return"two.sided";let n=["two.sided","less","greater"].filter(r=>r.startsWith(e));if(e.length===0||n.length!==1)throw new RangeError(`invalid alternative "${e}" (expected "two.sided", "less" or "greater")`);return n[0]}function pe(e){if(!(Number.isFinite(e)&&e>=0&&e<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function Ge(e){if(!(Number.isFinite(e)&&e>0&&e<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var Se=["pearson","kendall","spearman"];function Te(e){if(e===void 0)return"pearson";let t=Se.filter(n=>n.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function de(e){if(!(e[0]>0))return[Math.sqrt(e[0]),0];let t=Math.sqrt(e[0]),n=q(e,te(t,t));return ee(t,n[0]/(2*t))}function we(e){let t=ne(e);if(!Number.isFinite(t[0]))return;let n=e.map(o=>q([o,0],t)),r=0;for(let o of n)r=Math.max(r,Math.abs(o[0]));if(r===0)return n;let s=2**-Math.max(-1022,Math.floor(Math.log2(r)));return n.map(o=>[o[0]*s,o[1]*s])}function H(e,t){let n=e.length;if(n<2)return[NaN,0];let r=we(e),s=we(t);if(r===void 0||s===void 0)return[NaN,0];let o=[0,0],c=[0,0],i=[0,0];for(let l=0;l<n;l++)o=V(o,C(r[l],s[l])),c=V(c,C(r[l],r[l])),i=V(i,C(s[l],s[l]));if(c[0]===0||i[0]===0)return[NaN,0];let a=W(o,C(de(c),de(i)));return a[0]>=1?[1,0]:a[0]<=-1?[-1,0]:a}function ge(e,t){let n=C(q([1,0],e),V([1,0],e));return Math.sqrt(t)*e[0]/Math.sqrt(n[0])}function De(e){return Math.abs(e[0])<.5?Math.atanh(e[0]):.5*Math.log(V([1,0],e)[0]/q([1,0],e)[0])}function Ne(e,t,n){return n==="less"?B(e,t,!0,!1):n==="greater"?B(e,t,!1,!1):2*Math.min(B(e,t,!0,!1),B(e,t,!1,!1))}function Re(e,t){return t==="less"?D(e):t==="greater"?D(e,{lowerTail:!1}):2*Math.min(D(e),D(e,{lowerTail:!1}))}function K(e,t){let n=e.length,r=0;for(let u=0;u<n;u++){let m=e[u],p=t[u];for(let w=u+1;w<n;w++){let N=(e[w]>m?1:0)-(e[w]<m?1:0),y=(t[w]>p?1:0)-(t[w]<p?1:0);r+=N*y}}let s=I(e),o=I(t),c=n*(n-1)/2,i=s.reduce((u,m)=>u+m*(m-1)/2,0),a=o.reduce((u,m)=>u+m*(m-1)/2,0),l=n<2||i===c||a===c?NaN:i===0&&a===0?r/c:r/Math.sqrt((c-i)*(c-a));return{s:r,tau:l,ties:s.length>0||o.length>0,tx:s,ty:o}}function be(e,t){let n=e*(e-1)/2;if(t<0)return 0;if(t>=n)return 1;let r=new Float64Array(t+1);r[0]=1;for(let o=2;o<=e;o++){let c=new Float64Array(t+1),i=0;for(let l=0;l<=t;l++)i+=r[l],c[l]=i;let a=new Float64Array(t+1);for(let l=0;l<=t;l++)a[l]=(c[l]-(l>=o?c[l-o]:0))/o;r=a}let s=0;for(let o=t;o>=0;o--)s+=r[o];return Math.min(1,s)}var ve=new Map;function Le(e){let t=ve.get(e);if(t!==void 0)return t;let n=e*(e*e-1)/3,r=1<<e,s=new Array(r);s[0]=new Float64Array(n+1),s[0][0]=1;let o=i=>{let a=0;for(;i;i&=i-1)a++;return a};for(let i=0;i<r;i++){let a=s[i];if(a===void 0)continue;let l=o(i);for(let u=0;u<e;u++){if(i&1<<u)continue;let m=(u-l)**2,p=i|1<<u,w=s[p]??=new Float64Array(n+1);for(let N=0;N+m<=n;N++)a[N]&&(w[N+m]+=a[N])}i!==r-1&&(s[i]=void 0)}let c=s[r-1];return ve.set(e,c),c}var x=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function ye(e,t,n){let r=t;r%2!==0&&(r+=1);let s=1/e,o=(6*(r-1)*s/(e*e-1)-1)*Math.sqrt(1/s-1),c=o*o,a=o*s*(x[0]+s*(x[1]+x[2]*s)+c*(-x[3]+s*(x[4]+x[5]*s)-c*s*(x[6]+x[7]*s-c*(x[8]-x[9]*s+c*s*(x[10]-x[11]*c)))))/Math.exp(c/2),l=n?D(o)-a:a+D(o,{lowerTail:!1});return Math.min(1,Math.max(0,l))}function Me(e,t,n){let r=e*(e*e-1)/3;if(e<=9){let s=Le(e),o=1;for(let i=2;i<=e;i++)o*=i;let c=0;if(n)for(let i=Math.min(t,r);i>=0;i--)c+=s[i];else for(let i=r;i>=Math.max(t,0);i--)c+=s[i];return c/o}return n?t+1>r?1:t+1<=0?0:ye(e,t+1,!0):t<=0?1:t>r?0:ye(e,t,!1)}function _e(e,t,n={}){if(typeof e=="string"){let r=me(e,t);return _e(r.x,r.y,n)}return Ce(e,t,n)}function Ce(e,t,n){if(e.length!==t.length)throw new TypeError("x and y must have the same length");let r=he(n.alternative),s=Te(n.method),o=n.continuity??!1,[c,i]=oe(Array.from(e),Array.from(t)),a=c.length;if(s==="pearson"){let f=n.confLevel??.95;if(pe(f),a<3)throw new Error("not enough finite observations");let d=H(c,i),k=a-2,b=Number.isNaN(d[0])?NaN:ge(d,k),M={method:"Pearson's product-moment correlation",alternative:r,statistic:b,statisticName:"t",parameter:k,parameterName:"df",pValue:Ne(b,k,r),estimate:d[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation"};if(a>3){let z=De(d),L=1/Math.sqrt(a-3),_=T=>Math.tanh(z+T),$;if(r==="less")$=[-1,_(L*G(f))];else if(r==="greater")$=[_(-L*G(f)),1];else{let T=L*G((1+f)/2);$=[_(-T),_(T)]}M.confInt=$,M.confLevel=f}return M}if(a<2)throw new Error("not enough finite observations");if(s==="kendall"){let f=K(c,i),d={method:"Kendall's rank correlation tau",alternative:r,estimate:f.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau"};if(Number.isNaN(f.tau))return{...d,statistic:NaN,statisticName:"T",pValue:NaN};if((n.exact??a<50)&&!f.ties){let v=a*(a-1)/2,P=(f.s+v)/2,U=be(a,P),Z=be(a,v-P),Ee=r==="less"?U:r==="greater"?Z:Math.min(1,2*Math.min(U,Z));return{...d,statistic:P,statisticName:"T",pValue:Ee}}let b=(v,P)=>P.reduce((U,Z)=>U+v(Z),0),M=v=>v*(v-1),z=v=>v*(v-1)*(v-2),L=v=>v*(v-1)*(2*v+5),_=(a*(a-1)*(2*a+5)-b(L,f.tx)-b(L,f.ty))/18+b(z,f.tx)*b(z,f.ty)/(9*a*(a-1)*(a-2))+b(M,f.tx)*b(M,f.ty)/(2*a*(a-1)),T=(o?Math.sign(f.s)*(Math.abs(f.s)-1):f.s)/Math.sqrt(_);return{...d,statistic:T,statisticName:"z",pValue:Re(T,r)}}let l=X(c),u=X(i),m=H(l,u),p=a*a*a-a,w=p*(1-m[0])/6,N={method:"Spearman's rank correlation rho",alternative:r,statistic:w,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho"};if(Number.isNaN(m[0]))return{...N,pValue:NaN};let y=I(c).length>0||I(i).length>0;if((n.exact??a<=1290)&&!y&&a<=1290){let f=Math.round(w),d=Me(a,f,!0),k=Me(a,f,!1),b=r==="greater"?d:r==="less"?k:Math.min(1,2*Math.min(d,k));return{...N,pValue:b}}let h=m;if(o){let f=W([6,0],[p,0]);h=W(V(m,f),V([1,0],f)),Math.abs(h[0])>=1&&(h=[Math.sign(h[0]),0])}let g=ge(h,a-2);return{...N,pValue:Ne(g,a-2,r)}}function Fe(e,t){let n=e.length,r=new Array(n);if(t==="first"||t==="last"||t==="random"){let c=t==="random"?re(n):[],i=Array.from({length:n},(a,l)=>l);return i.sort((a,l)=>{let u=e[a]-e[l];return u!==0?u:t==="first"?a-l:t==="last"?l-a:c[a]-c[l]||a-l}),i.forEach((a,l)=>r[a]=l+1),r}let s=Array.from({length:n},(c,i)=>i).sort((c,i)=>e[c]-e[i]||c-i),o=0;for(;o<n;){let c=o;for(;c+1<n&&e[s[c+1]]===e[s[o]];)c++;let i=t==="average"?(o+c+2)/2:t==="min"?o+1:c+1;for(let a=o;a<=c;a++)r[s[a]]=i;o=c+1}return r}function J(e,t={}){let n=t.tiesMethod??"average";if(!["average","first","last","random","max","min"].includes(n))throw new RangeError(`invalid tiesMethod "${n}"`);let r=t.naLast??"last",s=Array.from(e),o=s.filter(m=>!Number.isNaN(m)),c=Fe(o,n),i=s.length-o.length,a=[],l=0,u=0;for(let m of s)Number.isNaN(m)?(u++,a.push(r==="keep"?NaN:r==="last"?o.length+u:u)):a.push(r==="first"?c[l++]+i:c[l++]);return a}var Oe=["pearson","kendall","spearman"],$e=["all.obs","complete.obs","pairwise.complete.obs","everything","na.or.complete"];function xe(e,t,n,r){if(e===void 0)return n;if(t.includes(e))return e;let s=t.filter(o=>o.startsWith(e));if(e.length===0||s.length!==1)throw new RangeError(`invalid '${r}' argument`);return s[0]}function O(e){return e.length>0&&Array.isArray(e[0])}function ke(e){if(!O(e))return[Array.from(e)];let t=e[0].length;return Array.from({length:t},(n,r)=>e.map(s=>s[r]))}function Q(e,t,n,r){let s=xe(n.method,Oe,"pearson","method"),o=xe(n.use,$e,"everything","use");if(t===void 0&&!O(e))throw new TypeError("supply both 'x' and 'y' or a matrix-like 'x'");let c=ke(e),i=t===void 0?c:ke(t),a=c[0]?.length??0;if(i.some(h=>h.length!==a))throw new RangeError("incompatible dimensions");let l=[...c,...i];if(o==="all.obs"&&l.some(h=>h.some(Number.isNaN)))throw new RangeError("missing observations in cov/cor");if(!r&&o==="pairwise.complete.obs"&&s!=="pearson")throw new RangeError("cannot handle 'pairwise.complete.obs'");let u;if((o==="complete.obs"||o==="na.or.complete")&&(u=Array.from({length:a},(h,g)=>l.every(f=>!Number.isNaN(f[g]))),!u.some(Boolean))){if(o==="complete.obs")throw new RangeError("no complete element pairs");return t===void 0||O(e)||O(t)?c.map(()=>i.map(()=>NaN)):NaN}let m=h=>{let g=u===void 0?h:h.filter((f,d)=>u[d]);return s==="spearman"&&o!=="pairwise.complete.obs"?J(g,{naLast:"keep"}):g},p=c.map(m),w=t===void 0?p:i.map(m),N=(h,g)=>{let f=h,d=g;if(o==="pairwise.complete.obs"){let k=h.map((b,M)=>!Number.isNaN(b)&&!Number.isNaN(g[M]));f=h.filter((b,M)=>k[M]),d=g.filter((b,M)=>k[M]),s==="spearman"&&(f=J(f),d=J(d))}else if(f.some(Number.isNaN)||d.some(Number.isNaN))return NaN;return f.length<2?NaN:s==="kendall"?r?K(f,d).tau:2*K(f,d).s:r?H(f,d)[0]:se(f,d)},y=p.map(h=>w.map(g=>N(h,g))),E=u===void 0?a:u.filter(Boolean).length;return r&&t===void 0&&o!=="pairwise.complete.obs"&&E>=2&&y.forEach((h,g)=>h[g]=1),t!==void 0&&!O(e)&&!O(t)?y[0][0]:y}function it(e,t,n={}){return t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!1):Q(e,t,n,!1)}function ct(e,t,n={}){return t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!0):Q(e,t,n,!0)}export{Ve as a,Ie as b,je as c,ze as d,Ue as e,Ze as f,he as g,pe as h,Ge as i,H as j,_e as k,J as l,it as m,ct as n};