@numero-uno-jpn/rstats 0.9.0 → 0.11.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 +87 -0
- package/README.ja.md +64 -12
- package/README.md +63 -11
- package/THIRD_PARTY_NOTICES.md +7 -2
- package/dist/chunks/chunk-5WDJPHYY.js +2 -0
- package/dist/chunks/chunk-7GQMKH3Z.js +2 -0
- package/dist/chunks/chunk-AHHS6AC4.js +3 -0
- package/dist/chunks/chunk-ALM3VHFP.js +2 -0
- package/dist/chunks/{chunk-TOVTN5Y2.js → chunk-C5XTWMGB.js} +1 -1
- package/dist/chunks/chunk-CGBNKHNZ.js +2 -0
- package/dist/chunks/{chunk-LWUSYIQ4.js → chunk-EZAFN5CD.js} +1 -1
- package/dist/chunks/{chunk-H2AP6TCR.js → chunk-EZWBRCJL.js} +1 -1
- package/dist/chunks/chunk-F5EDJFEO.js +2 -0
- package/dist/chunks/{chunk-FC2TLHZC.js → chunk-JWBO5WVN.js} +2 -2
- package/dist/chunks/{chunk-LE7TBHNI.js → chunk-TOGXTCZO.js} +2 -2
- package/dist/chunks/chunk-VJ4BDBMU.js +3 -0
- package/dist/chunks/chunk-Y5CNQ266.js +2 -0
- package/dist/chunks/{chunk-BGVMSDVJ.js → chunk-Y5PYRAYP.js} +2 -2
- package/dist/chunks/{chunk-5K4PS7IV.js → chunk-YSWGDOWK.js} +2 -2
- package/dist/data/grouping.d.ts +79 -0
- package/dist/data/grouping.js +262 -0
- package/dist/descriptive/dataFrames.d.ts +110 -0
- package/dist/descriptive/dataFrames.js +392 -0
- package/dist/descriptive/factanal.d.ts +56 -0
- package/dist/descriptive/factanal.js +186 -0
- package/dist/descriptive/missing.d.ts +35 -0
- package/dist/descriptive/missing.js +50 -0
- package/dist/descriptive/omega.d.ts +56 -0
- package/dist/descriptive/omega.js +323 -0
- package/dist/descriptive/pivot.d.ts +89 -0
- package/dist/descriptive/pivot.js +343 -0
- package/dist/descriptive.js +2 -2
- package/dist/distributions/bvnorm.d.ts +15 -0
- package/dist/distributions/bvnorm.js +131 -0
- package/dist/distributions/nbeta.js +34 -1
- package/dist/distributions/nchisq.d.ts +10 -0
- package/dist/distributions/nchisq.js +46 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +4 -0
- package/dist/entries/descriptive.js +4 -0
- package/dist/entries/distributions.d.ts +1 -0
- package/dist/entries/distributions.js +1 -0
- package/dist/entries/linalg.d.ts +2 -0
- package/dist/entries/linalg.js +2 -0
- package/dist/entries/numerics.d.ts +2 -0
- package/dist/entries/numerics.js +1 -0
- package/dist/entries/tests.d.ts +22 -1
- package/dist/entries/tests.js +19 -1
- package/dist/htest/agreement.d.ts +141 -0
- package/dist/htest/agreement.js +274 -0
- package/dist/htest/ansariTest.d.ts +12 -0
- package/dist/htest/ansariTest.js +5 -17
- package/dist/htest/aov.d.ts +19 -0
- package/dist/htest/aov.js +22 -15
- package/dist/htest/cor.d.ts +12 -0
- package/dist/htest/cor.js +9 -27
- package/dist/htest/core/simulate.d.ts +2 -0
- package/dist/htest/core/simulate.js +1 -1
- package/dist/htest/dunnett.d.ts +5 -0
- package/dist/htest/dunnett.js +89 -0
- package/dist/htest/effectSize.d.ts +112 -0
- package/dist/htest/effectSize.js +385 -0
- package/dist/htest/ksTest.d.ts +13 -0
- package/dist/htest/ksTest.js +5 -8
- package/dist/htest/leveneTest.d.ts +30 -0
- package/dist/htest/leveneTest.js +41 -0
- package/dist/htest/multipleComparisons.d.ts +147 -0
- package/dist/htest/multipleComparisons.js +369 -0
- package/dist/htest/normalityTests.d.ts +44 -0
- package/dist/htest/normalityTests.js +164 -0
- package/dist/htest/onewayTest.d.ts +14 -0
- package/dist/htest/onewayTest.js +5 -7
- package/dist/htest/polycor.d.ts +117 -0
- package/dist/htest/polycor.js +468 -0
- package/dist/htest/power.d.ts +132 -0
- package/dist/htest/power.js +227 -0
- package/dist/htest/pwr.d.ts +263 -0
- package/dist/htest/pwr.js +440 -0
- package/dist/htest/rankTests.d.ts +64 -0
- package/dist/htest/rankTests.js +27 -29
- package/dist/htest/tTest.d.ts +20 -0
- package/dist/htest/tTest.js +19 -24
- package/dist/htest/testFormula.d.ts +57 -0
- package/dist/htest/testFormula.js +171 -0
- package/dist/htest/trendTests.d.ts +57 -0
- package/dist/htest/trendTests.js +167 -0
- package/dist/htest/varTest.d.ts +23 -0
- package/dist/htest/varTest.js +11 -21
- package/dist/htest/wilcoxTest.d.ts +14 -0
- package/dist/htest/wilcoxTest.js +9 -24
- package/dist/linalg/eigen.d.ts +8 -0
- package/dist/linalg/eigen.js +5 -4
- package/dist/linalg/expm.d.ts +48 -0
- package/dist/linalg/expm.js +472 -0
- package/dist/linalg/ops.d.ts +13 -2
- package/dist/linalg/ops.js +20 -5
- package/dist/linalg/schur.d.ts +48 -0
- package/dist/linalg/schur.js +225 -0
- package/dist/linalg.js +2 -2
- package/dist/models/anovaSequential.d.ts +58 -0
- package/dist/models/anovaSequential.js +138 -0
- package/dist/models/aovEz.d.ts +64 -0
- package/dist/models/aovEz.js +332 -0
- package/dist/models/aovStrata.d.ts +32 -0
- package/dist/models/aovStrata.js +104 -0
- package/dist/models/carAnova.d.ts +30 -0
- package/dist/models/carAnova.js +121 -0
- package/dist/models/coxph.d.ts +101 -0
- package/dist/models/coxph.js +502 -0
- package/dist/models/ddLeastSquares.d.ts +30 -0
- package/dist/models/ddLeastSquares.js +90 -0
- package/dist/models/ddMatrix.d.ts +10 -0
- package/dist/models/ddMatrix.js +91 -0
- package/dist/models/formula.d.ts +83 -0
- package/dist/models/formula.js +333 -0
- package/dist/models/lm.d.ts +84 -3
- package/dist/models/lm.js +141 -44
- package/dist/models/mauchly.d.ts +48 -0
- package/dist/models/mauchly.js +123 -0
- package/dist/models/modelFrame.d.ts +40 -0
- package/dist/models/modelFrame.js +131 -0
- package/dist/models/modelMatrix.d.ts +88 -0
- package/dist/models/modelMatrix.js +170 -0
- package/dist/models/survival.d.ts +87 -0
- package/dist/models/survival.js +238 -0
- package/dist/numerics.js +2 -2
- package/dist/optim/lbfgsb.d.ts +20 -0
- package/dist/optim/lbfgsb.js +1240 -0
- package/dist/optim/optim.d.ts +85 -0
- package/dist/optim/optim.js +610 -0
- package/dist/rstats.js +19 -4
- package/dist/special.js +2 -2
- package/dist/tests.js +17 -4
- package/llms.txt +114 -0
- package/package.json +3 -2
- package/dist/chunks/chunk-24U4DKRY.js +0 -2
- package/dist/chunks/chunk-IVOBWYLV.js +0 -2
- package/dist/chunks/chunk-JLSTEMSN.js +0 -2
- package/dist/chunks/chunk-MF4VBCHQ.js +0 -2
- package/dist/chunks/chunk-MSAUU6PY.js +0 -2
- package/dist/chunks/chunk-YC4JWUKG.js +0 -2
- package/dist/chunks/chunk-ZRO446BP.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,93 @@ 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.11.0 - 2026-10-26
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Data handling, for "missing values → groups → test" without hand work:
|
|
15
|
+
- formula forms of the tests: `tTest("y ~ g", data)` (also `"y ~ 1"` and `"Pair(a, b) ~ 1"`), `wilcoxTest`,
|
|
16
|
+
`varTest`, `ansariTest`, `moodTest`, `ksTest`, `kruskalTest`, `flignerTest`, `bartlettTest`, `onewayTest`
|
|
17
|
+
(several factors as their interaction), `friedmanTest` and `quadeTest` (`"y ~ w | b"`), `corTest("~ x + y",
|
|
18
|
+
data)`, with R's handling of missing values, levels and messages;
|
|
19
|
+
- `completeCases` (`complete.cases`) and `naOmit` (`na.omit`);
|
|
20
|
+
- `tapply`, `split` (a `Map` in R's order) and `aggregate` (formula and data-frame forms);
|
|
21
|
+
- `merge` (R's row order, including its order of duplicated keys), `subset`, and `rbind` / `cbind` of data
|
|
22
|
+
frames (the matrix forms are unchanged);
|
|
23
|
+
- `fromRows` and `toRows`: data frames from arrays of row objects (JSON, parsed CSV) and back;
|
|
24
|
+
- `pivotLonger` and `pivotWider` (tidyr's `pivot_longer` and `pivot_wider`): wide and long formats, with
|
|
25
|
+
`.value`, `namesSep`, `namesPattern`, `valuesFill` and `valuesFn`.
|
|
26
|
+
- [docs/guide-for-js-developers.md](docs/guide-for-js-developers.md) (and its Japanese translation): R's way of
|
|
27
|
+
writing an analysis explained for JavaScript developers, with a worked example that the tests run.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- The tests with a formula form import the formula and model-frame code: `tTest` alone is 24.9 KB gzipped (was
|
|
32
|
+
21.4 KB), `wilcoxTest` 12.1 KB (was 8.6 KB). Everything together is 185.8 KB.
|
|
33
|
+
|
|
34
|
+
## 0.10.0 - 2026-10-26
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
|
|
38
|
+
- Model formulas: `lm(formula, data)` and `aov(formula, data)` take an R formula string and a data frame (an
|
|
39
|
+
object of columns; strings and booleans are factors), besides the existing matrix and group forms. Formulas
|
|
40
|
+
support `+`, `-`, `*`, `/`, `:`, `%in%`, `^`, `.`, `0`/`1` and parentheses, with R's term order, labels and
|
|
41
|
+
coding (contrasts or indicators by R's rule, the first factor coded by indicators without an intercept), the
|
|
42
|
+
contrasts `contr.treatment`, `contr.sum` and `contr.helmert`, a `levels` option and weights. `modelMatrix`
|
|
43
|
+
returns R's `model.matrix` with the attributes of `terms()`.
|
|
44
|
+
- `anova` (`anova.lm`): the sequential table of a fit and the comparison of several fits; `aovSummary`
|
|
45
|
+
(`summary(aov(...))`).
|
|
46
|
+
- `aov` with an `Error()` term: the error strata and their tables, as R's multistratum `aov`.
|
|
47
|
+
- `Anova` (`car::Anova` for linear models): type II and type III tests.
|
|
48
|
+
- `aovEz` (`afex::aov_ez`): repeated-measures, between-subjects and mixed designs from long data, with car's
|
|
49
|
+
univariate tests, the Greenhouse-Geisser and Huynh-Feldt corrections, Mauchly's tests, generalized and partial
|
|
50
|
+
eta squared (`es`, `observed`), types II and III, and afex's aggregation and checks.
|
|
51
|
+
- `mauchlyTest` (`mauchly.test`) for the responses of several measurements per subject, with `group`, `M`, `X`
|
|
52
|
+
and `idata`.
|
|
53
|
+
- The fits are computed in double-double where R's QR decomposition loses digits (a mean of 1e6: R's
|
|
54
|
+
coefficients are off by up to 1.5e-11); every table agrees with R to 1e-12 or with exact rational values.
|
|
55
|
+
- Effect sizes (effectsize): `cohensD` and `hedgesG` (one sample, two samples pooled or not, paired), and
|
|
56
|
+
`etaSquared` (partial, non-partial, generalized), `omegaSquared` and `epsilonSquared` of `anova` and `Anova`
|
|
57
|
+
tables, with confidence intervals. The limits are the exact solutions; effectsize's optimiser leaves them about
|
|
58
|
+
1e-9 (up to 3e-3) off.
|
|
59
|
+
- Power calculations: `powerTTest`, `powerPropTest`, `powerAnovaTest` (R's `power.*.test`) and pwr's `pwrTTest`,
|
|
60
|
+
`pwrT2nTest`, `pwr2pTest`, `pwr2p2nTest`, `pwrPTest`, `pwrNormTest`, `pwrRTest`, `pwrChisqTest`, `pwrAnovaTest`,
|
|
61
|
+
`pwrF2Test` with `esH`, `esW1`, `esW2` and `cohenES`. Give the quantity to solve for as `null`; it is found with R's
|
|
62
|
+
own `uniroot` calls, with accurate noncentral distributions (R's noncentral t and F are not: computed powers
|
|
63
|
+
differ from R's by up to 3e-8).
|
|
64
|
+
|
|
65
|
+
- More tests: `leveneTest` (car), `propTrendTest` (`prop.trend.test`), `jonckheereTest` (DescTools' and clinfun's
|
|
66
|
+
variants), `cochranQTest` (DescTools), and nortest's `adTest`, `lillieTest`, `cvmTest`, `sfTest`, `pearsonTest`.
|
|
67
|
+
- Effect sizes of repeated-measures designs: `etaSquared`, `omegaSquared`, `epsilonSquared` of `aov` fits with
|
|
68
|
+
`Error()` and of `aovEz` results, with exact intervals.
|
|
69
|
+
- Multiple comparisons: PMCMRplus's `dscfAllPairsTest` (Steel-Dwass), `kwAllPairsDunnTest`, `kwManyOneDunnTest`, `manyOneUTest` (Steel's many-one rank test),
|
|
70
|
+
`dunnettTest`, `gamesHowellTest`, `tukeyTest` and `steelTest` (its errors); dunn.test's `dunnTest`; multcomp's
|
|
71
|
+
Dunnett comparisons (`glhtDunnett`). Dunnett-type probabilities are computed exactly by a one-dimensional integral
|
|
72
|
+
(R's mvtnorm integration is randomised and about 1e-3 accurate); studentized-range p-values are R's to full
|
|
73
|
+
precision (R's `ptukey` has about 8 digits).
|
|
74
|
+
- Survival analysis: `survdiff` (log-rank, G-rho family) and `survfit` (Kaplan-Meier with its intervals and median).
|
|
75
|
+
- `coxph` (Cox regression, survival's `coxph` for right-censored data with a covariate matrix): Efron and Breslow
|
|
76
|
+
ties, case weights, strata, starting values, R's Newton-Raphson iterations and warnings, and the summary's
|
|
77
|
+
coefficient table, intervals and the likelihood-ratio, score and Wald tests.
|
|
78
|
+
- Agreement and reliability: `kappa2`, `kappamFleiss`, `icc` (irr), `cronbachAlpha`, `partialR` (psych).
|
|
79
|
+
- `schur` (real Schur decomposition, `Matrix::Schur`) and `expm` (the matrix exponential, expm's `Higham08.b`,
|
|
80
|
+
`Higham08`, `Pade`, `Taylor`, `PadeO` and `TaylorO` with `order`).
|
|
81
|
+
- `factanal` (maximum-likelihood factor analysis with varimax and promax rotations), on `optim`'s L-BFGS-B.
|
|
82
|
+
- `omega` (McDonald's ω, psych's `omega`): minres factor analysis, varimax and oblimin rotations, the
|
|
83
|
+
Schmid-Leiman transformation, ω_h, ω_t, ω_lim, α, G6, ECV and the group omegas.
|
|
84
|
+
- `polychor` and `polyserial` (polycor's two-step estimates) and `pbvnorm` (bivariate normal rectangle
|
|
85
|
+
probabilities, Genz's method). With `{ ML, stdErr }`, the maximum-likelihood estimates (correlation and
|
|
86
|
+
thresholds) and the standard errors with polycor's chi-squared statistics, at the exact maximum of the likelihood
|
|
87
|
+
(R's optimisers stop up to 1e-3 short of it, and fail on some strongly associated tables).
|
|
88
|
+
- `optim` with Nelder-Mead, BFGS, CG, L-BFGS-B (a port of the Netlib code), SANN and Brent, following R's iterations
|
|
89
|
+
(the same evaluation counts), and `optimHess`.
|
|
90
|
+
|
|
91
|
+
### Fixed
|
|
92
|
+
|
|
93
|
+
- `pchisq` and `pf` with a huge noncentrality (above about 1e12) far from the quantile returned wrong values or NaN;
|
|
94
|
+
a Chernoff bound now returns 0 and 1 there.
|
|
95
|
+
|
|
96
|
+
|
|
10
97
|
## 0.9.0 - 2026-10-25
|
|
11
98
|
|
|
12
99
|
### Added
|
package/README.ja.md
CHANGED
|
@@ -16,7 +16,7 @@ JavaScript とブラウザで使える、R と互換の統計関数のライブ
|
|
|
16
16
|
- **どこでも動きます。** ESM のみで、依存パッケージはなく、Node 専用の API も使っていません。
|
|
17
17
|
tree-shaking が効きます (`pnorm` だけなら gzip で 1.2 KB)。
|
|
18
18
|
|
|
19
|
-
状態: **0.
|
|
19
|
+
状態: **0.11.0。** R の stats パッケージの数値計算の中心
|
|
20
20
|
(分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
|
|
21
21
|
[ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
|
|
22
22
|
|
|
@@ -97,6 +97,45 @@ glmAnova(fit).table[1]; // ≈ [1, 62.978, 4, 0.5196,
|
|
|
97
97
|
fit.warnings; // [] (R's warnings, such as non-convergence)
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
### formula による分散分析
|
|
101
|
+
|
|
102
|
+
`lm` と `aov` は、R の formula とデータフレーム (列のオブジェクト。文字列の列は因子) でも呼べます。`anova` は R の
|
|
103
|
+
逐次の表、`Anova` は car の Type II と III の検定、`aovEz` は afex の反復測定の分散分析 (Greenhouse-Geisser の補正と
|
|
104
|
+
一般化 η² つき) です。
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { lm, anova, Anova, aovEz } from "@numero-uno-jpn/rstats";
|
|
108
|
+
|
|
109
|
+
const d = { y: [12.1, 14.3, 13.8, 17.2, 19.5, 22.4, 11.6, 13.9, 15.7, 18.8, 21.1, 25.3],
|
|
110
|
+
A: ["a", "a", "b", "b", "c", "c", "a", "a", "b", "b", "c", "c"],
|
|
111
|
+
B: ["p", "q", "p", "q", "p", "q", "p", "q", "p", "q", "p", "q"] };
|
|
112
|
+
const fit = lm("y ~ A * B", d, { contrasts: { A: "contr.sum", B: "contr.sum" } });
|
|
113
|
+
anova(fit).rowNames; // ["A", "B", "A:B", "Residuals"]
|
|
114
|
+
anova(fit).table[0]; // ≈ [2, 169.147, 84.573, 57.828, 0.00011997] (Df, Sum Sq, Mean Sq, F, p)
|
|
115
|
+
Anova(fit, { type: 3 }).table[1]; // ≈ [169.147, 2, 57.828, 0.00011997] (car::Anova(fit, type = 3))
|
|
116
|
+
|
|
117
|
+
// 反復測定 (R: afex::aov_ez("id", "y", long, within = "W"))
|
|
118
|
+
const long = { id: ["s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3", "s4", "s4", "s4", "s5", "s5", "s5"],
|
|
119
|
+
W: ["pre", "mid", "post", "pre", "mid", "post", "pre", "mid", "post", "pre", "mid", "post", "pre", "mid", "post"],
|
|
120
|
+
y: [5.1, 6.3, 7.2, 4.8, 5.9, 7.5, 6.0, 6.1, 8.3, 5.5, 6.8, 7.1, 4.9, 6.6, 7.8] };
|
|
121
|
+
aovEz(long, { id: "id", dv: "y", within: "W" }).anova.table[0];
|
|
122
|
+
// ≈ [1.735, 6.940, 0.21653, 35.876, 0.84607, 0.00026363] (num Df, den Df, MSE, F, ges, p。GG で補正)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 効果量と検出力
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { cohensD, etaSquared, Anova, powerTTest, pwrAnovaTest } from "@numero-uno-jpn/rstats";
|
|
129
|
+
|
|
130
|
+
cohensD([5.1, 4.9, 6.2, 5.8, 6.0, 5.5], [4.1, 4.5, 5.0, 4.8, 4.3]);
|
|
131
|
+
// ≈ { name: "Cohens_d", value: 2.30726, ci: 0.95, ciLow: 0.68824, ciHigh: 3.85666 } (effectsize::cohens_d)
|
|
132
|
+
etaSquared(Anova(fit, { type: 3 })).table[0]; // ≈ [0.95068, 0.95, 0.82023, 1] (fit は上の例のもの。偏 η²、片側の信頼区間)
|
|
133
|
+
powerTTest({ delta: 0.5, power: 0.8 }).n; // ≈ 63.766 (1 群あたり、power.t.test)
|
|
134
|
+
pwrAnovaTest({ k: 3, f: 0.25, power: 0.8 }).n; // ≈ 52.397 (pwr::pwr.anova.test)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
信頼区間の限界は厳密な解です。effectsize は最適化で求めるので、1e-9 程度 (ときに 3e-3) ずれます。
|
|
138
|
+
|
|
100
139
|
### 線形代数
|
|
101
140
|
|
|
102
141
|
行列は行の配列で表します。
|
|
@@ -119,15 +158,28 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
|
|
|
119
158
|
| 分布 (d/p/q) | 正規、t、カイ二乗、F、ベータ、ガンマ、二項、ポアソン、一様、指数、対数正規、ロジスティック、コーシー、ワイブル、幾何、負の二項、超幾何、Wilcoxon の符号付き順位と順位和、スチューデント化された範囲 (`ptukey`, `qtukey`)、非心カイ二乗・t・F・ベータ (`ncp`)。多項分布の確率 (`dmultinom`)。逆ガンマ、Kumaraswamy、Pareto、三角、Laplace (extraDistr) と逆正弦。`distSummary` (平均・分散・標準偏差・中央値・最頻値・歪度・尖度) |
|
|
120
159
|
| 乱数 | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister と L'Ecuyer-CMRG、`sample.kind` の Rejection と Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 個の `r*` 関数, `sample`, `sampleInt` (`sample.int`), `r2dtable` |
|
|
121
160
|
| 記述統計 | `sum`, `prod`, `mean`, `weightedMean` (`weighted.mean`), `variance` (`var`), `sd`, `median`, `range`, `cumsum`, `cumprod`, `cummax`, `cummin`, `diff`, `quantile`, `IQR`, `fivenum`, `mad`, `rank`, `cov`, `cor`, `tabulate`, `table`, `unique`, `cut`, `findInterval`, `pretty`, `hist`, `ecdf`, `scale`, `skewness`, `kurtosis`, `geometricMean`, `modes`, `meanAD`, `cv` |
|
|
122
|
-
| 検定 | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `corTest`, `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`, `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`, `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`, `pairwiseWilcoxTest`, `pairwisePropTest`, `aov
|
|
123
|
-
|
|
|
124
|
-
|
|
|
125
|
-
|
|
|
161
|
+
| 検定 | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `corTest`, `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`, `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`, `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`, `pairwiseWilcoxTest`, `pairwisePropTest`, `aov` (一元配置), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
|
|
162
|
+
| 分散分析 | formula で呼ぶ `aov` と `aovSummary` (多元、交互作用、共変量、`Error()` の層), `anova` (`anova.lm`。逐次の表とモデルの比較), `Anova` (car の Type II と III), `aovEz` (afex。反復測定と混合計画、Greenhouse-Geisser と Huynh-Feldt の補正、一般化 η² と偏 η²), `mauchlyTest` (`mauchly.test`) |
|
|
163
|
+
| 効果量と検出力 | `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) |
|
|
164
|
+
| 線形モデル | `lm` (formula とデータフレーム、または行列で渡す。`summary` の値も返す), `modelMatrix` (`model.matrix`), `confint`, `predict`。`glm` (行列で渡す形。R の `stats` のすべての族とリンク) と `glmSummary` (`summary.glm`)、`glmResiduals` (4 種類)、`glmHatvalues`、`glmRstandard`、`glmCooksDistance`、`glmPredict` (標準誤差つき)、`glmConfint` (プロファイル尤度、厳密な限界)、`glmAnova` (`anova.glm`) |
|
|
165
|
+
| ほかの検定 | `leveneTest`、`propTrendTest` (`prop.trend.test`)、`jonckheereTest`、`cochranQTest`、`adTest`、`lillieTest`、`cvmTest`、`sfTest`、`pearsonTest` (car、DescTools、clinfun、nortest) |
|
|
166
|
+
| 多重比較 | `dscfAllPairsTest` (Steel-Dwass)、`kwAllPairsDunnTest`、`kwManyOneDunnTest`、`manyOneUTest` (Steel の多対一の順位検定)、`dunnettTest`、`gamesHowellTest`、`tukeyTest` (PMCMRplus)、`dunnTest` (dunn.test)、`glhtDunnett` (multcomp) |
|
|
167
|
+
| 生存時間解析 | `survdiff` (log-rank)、`survfit` (Kaplan-Meier。信頼区間と中央値)、`coxph` (Cox 回帰。Efron と Breslow のタイの扱い、ケースの重み、層、Wald・尤度比・スコア検定) |
|
|
168
|
+
| 一致度と信頼性 | `kappa2`、`kappamFleiss`、`icc` (irr)、`cronbachAlpha`、`partialR` (psych)、`polychor`、`polyserial` (polycor)、`pbvnorm`、`factanal`、`omega` (McDonald の ω。psych) |
|
|
169
|
+
| データの扱い | `completeCases` (`complete.cases`)、`naOmit` (`na.omit`)、`subset`、`merge`、データフレームの `rbind`・`cbind`、`tapply`、`split`、`aggregate`、`pivotLonger` と `pivotWider` (tidyr)。検定の formula 版 (`tTest("y ~ g", data)`、`kruskalTest`、`friedmanTest("y ~ w \| b", data)`、`corTest("~ x + y", data)` など) |
|
|
170
|
+
| 線形代数 | `matMul` (`%*%`), `add`, `subtract`, `multiply`, `divide`, `outer`, `t`, `diag`, `cbind`, `rbind`, `matrix`, `kronecker`, `seq`, `crossprod`, `tcrossprod`, `norm`, `backsolve`, `forwardsolve`, `chol`, `chol2inv`, `qr` と `qrQ`, `qrR`, `qrX`, `qrCoef`, `qrQy`, `qrQty`, `qrResid`, `qrFitted`, `qrSolve` (`qr.Q` …), `solve`, `det`, `determinant`, `rcond`, `kappa`, `svd`, `eigen`, `lu`, `prcomp`, `ginv` (MASS)、`schur`、`expm` |
|
|
171
|
+
| 数値計算 | `integrate`, `optimize`, `optim`, `optimHess`, `uniroot`, `approx`, `spline`, `splinefun`, `splinefunH`, `barylag`, `hermiteInterp`, `ode`, `grad`, `jacobian`, `hessian` |
|
|
172
|
+
|
|
173
|
+
R の分析の書き方 (データフレーム、formula、因子) に慣れていない場合は、[docs/ja/guide-for-js-developers.md](docs/ja/guide-for-js-developers.md) が JavaScript の開発者の立場から例を使って説明しています。
|
|
126
174
|
|
|
127
175
|
jStat から移るときは [docs/ja/migrating-from-jstat.md](docs/ja/migrating-from-jstat.md) に jStat の全関数の置き換えがあります。
|
|
128
176
|
|
|
129
177
|
API リファレンスは `npm run docs` (TypeDoc) で作れます (英語)。
|
|
130
178
|
|
|
179
|
+
AI のコーディング支援向けに、R のコードを rStats.js の呼び出しに書き換える方法を [llms.txt](llms.txt)
|
|
180
|
+
にまとめています (英語。npm のパッケージにも入っていて、<https://numero-uno-jpn.github.io/rStats.js/llms.txt>
|
|
181
|
+
でも読めます)。
|
|
182
|
+
|
|
131
183
|
## 精度
|
|
132
184
|
|
|
133
185
|
正解の値は [`oracle/`](oracle) の R のスクリプトで作り、[`test/fixtures/`](test/fixtures) に
|
|
@@ -161,10 +213,10 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
161
213
|
| `pnorm` | 1.2 KB |
|
|
162
214
|
| `setSeed`, `rnorm` | 1.7 KB |
|
|
163
215
|
| `solve` / `svd` / `eigen` | 1.7 / 2.0 / 3.7 KB |
|
|
164
|
-
| `wilcoxTest` / `fisherTest` / `tTest` |
|
|
216
|
+
| `wilcoxTest` / `fisherTest` / `tTest` | 12.1 / 15.6 / 24.9 KB |
|
|
165
217
|
| `qbeta` / `pt` と `qt` | 23.2 / 30.3 KB |
|
|
166
218
|
| `glm` と `glmSummary` / `glm` とそのすべての関数 | 27.2 / 39.2 KB |
|
|
167
|
-
| すべて |
|
|
219
|
+
| すべて | 185.8 KB |
|
|
168
220
|
|
|
169
221
|
(`npm run size` で測れます。)
|
|
170
222
|
|
|
@@ -173,12 +225,12 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
173
225
|
`/descriptive`、`/numerics`、`/special` です。
|
|
174
226
|
|
|
175
227
|
バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (すべての関数を含む minify 済みの
|
|
176
|
-
ES モジュール、gzip で
|
|
228
|
+
ES モジュール、gzip で 186 KB) を jsDelivr から読み込めます。jsDelivr は、このリポジトリのリリースの
|
|
177
229
|
タグをそのまま配信します。
|
|
178
230
|
|
|
179
231
|
```html
|
|
180
232
|
<script type="module">
|
|
181
|
-
import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.
|
|
233
|
+
import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.11.0/dist/rstats.js";
|
|
182
234
|
console.log(pnorm(1.96)); // 0.9750021048517795
|
|
183
235
|
</script>
|
|
184
236
|
```
|
|
@@ -193,12 +245,12 @@ ES モジュール、gzip で 130 KB) を jsDelivr から読み込めます。js
|
|
|
193
245
|
一部の分野だけを使うページでは、代わりに分野ごとのバンドルを読み込めます。`dist/distributions.js`、
|
|
194
246
|
`dist/tests.js`、`dist/linalg.js`、`dist/descriptive.js`、`dist/numerics.js`、`dist/special.js` は
|
|
195
247
|
上のサブパスと同じ関数を export し、共通のコードを `dist/chunks/` で共有します。そのため、2 つの分野を
|
|
196
|
-
読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で
|
|
197
|
-
(`numerics`) から
|
|
248
|
+
読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で 29 KB
|
|
249
|
+
(`numerics`) から 153 KB (`tests`) です。
|
|
198
250
|
|
|
199
251
|
ビルド結果 (`dist/`) は main ブランチにはなく、リリースのタグにだけ入っています。npm を元にした CDN も
|
|
200
252
|
使えます。たとえば
|
|
201
|
-
`https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.
|
|
253
|
+
`https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.11.0/dist/rstats.js` や
|
|
202
254
|
`https://esm.sh/@numero-uno-jpn/rstats` です。
|
|
203
255
|
|
|
204
256
|
ブラウザ向けのビルドは、headless Chromium でテストしています。バンドラでまとめた場合と、
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ R-compatible statistical functions for JavaScript and the browser, written in Ty
|
|
|
14
14
|
- **Runs anywhere.** ESM only, no dependencies, no Node-specific APIs, tree-shakable
|
|
15
15
|
(`pnorm` alone is 1.2 KB gzipped).
|
|
16
16
|
|
|
17
|
-
Status: **0.
|
|
17
|
+
Status: **0.11.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
|
|
|
@@ -93,6 +93,46 @@ glmAnova(fit).table[1]; // ≈ [1, 62.978, 4, 0.5196,
|
|
|
93
93
|
fit.warnings; // [] (R's warnings, such as non-convergence)
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
+
### Analysis of variance with formulas
|
|
97
|
+
|
|
98
|
+
`lm` and `aov` also take an R formula and a data frame (an object of columns; strings are factors). `anova` gives
|
|
99
|
+
R's sequential table, `Anova` car's type II and III tests, `aovEz` afex's repeated-measures ANOVA with the
|
|
100
|
+
Greenhouse-Geisser correction and generalized eta squared.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { lm, anova, Anova, aovEz } from "@numero-uno-jpn/rstats";
|
|
104
|
+
|
|
105
|
+
const d = { y: [12.1, 14.3, 13.8, 17.2, 19.5, 22.4, 11.6, 13.9, 15.7, 18.8, 21.1, 25.3],
|
|
106
|
+
A: ["a", "a", "b", "b", "c", "c", "a", "a", "b", "b", "c", "c"],
|
|
107
|
+
B: ["p", "q", "p", "q", "p", "q", "p", "q", "p", "q", "p", "q"] };
|
|
108
|
+
const fit = lm("y ~ A * B", d, { contrasts: { A: "contr.sum", B: "contr.sum" } });
|
|
109
|
+
anova(fit).rowNames; // ["A", "B", "A:B", "Residuals"]
|
|
110
|
+
anova(fit).table[0]; // ≈ [2, 169.147, 84.573, 57.828, 0.00011997] (Df, Sum Sq, Mean Sq, F, p)
|
|
111
|
+
Anova(fit, { type: 3 }).table[1]; // ≈ [169.147, 2, 57.828, 0.00011997] (car::Anova(fit, type = 3))
|
|
112
|
+
|
|
113
|
+
// repeated measures (R: afex::aov_ez("id", "y", long, within = "W"))
|
|
114
|
+
const long = { id: ["s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3", "s4", "s4", "s4", "s5", "s5", "s5"],
|
|
115
|
+
W: ["pre", "mid", "post", "pre", "mid", "post", "pre", "mid", "post", "pre", "mid", "post", "pre", "mid", "post"],
|
|
116
|
+
y: [5.1, 6.3, 7.2, 4.8, 5.9, 7.5, 6.0, 6.1, 8.3, 5.5, 6.8, 7.1, 4.9, 6.6, 7.8] };
|
|
117
|
+
aovEz(long, { id: "id", dv: "y", within: "W" }).anova.table[0];
|
|
118
|
+
// ≈ [1.735, 6.940, 0.21653, 35.876, 0.84607, 0.00026363] (num Df, den Df, MSE, F, ges, p; GG-corrected)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Effect sizes and power
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { cohensD, etaSquared, Anova, powerTTest, pwrAnovaTest } from "@numero-uno-jpn/rstats";
|
|
125
|
+
|
|
126
|
+
cohensD([5.1, 4.9, 6.2, 5.8, 6.0, 5.5], [4.1, 4.5, 5.0, 4.8, 4.3]);
|
|
127
|
+
// ≈ { name: "Cohens_d", value: 2.30726, ci: 0.95, ciLow: 0.68824, ciHigh: 3.85666 } (effectsize::cohens_d)
|
|
128
|
+
etaSquared(Anova(fit, { type: 3 })).table[0]; // ≈ [0.95068, 0.95, 0.82023, 1] (fit from the example above; partial eta², one-sided CI)
|
|
129
|
+
powerTTest({ delta: 0.5, power: 0.8 }).n; // ≈ 63.766 per group (power.t.test)
|
|
130
|
+
pwrAnovaTest({ k: 3, f: 0.25, power: 0.8 }).n; // ≈ 52.397 (pwr::pwr.anova.test)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The confidence limits are the exact solutions; effectsize finds them with an optimiser and is up to
|
|
134
|
+
about 1e-9 (sometimes 3e-3) off.
|
|
135
|
+
|
|
96
136
|
### Linear algebra
|
|
97
137
|
|
|
98
138
|
Matrices are arrays of rows.
|
|
@@ -115,15 +155,27 @@ eigen([[2, 1], [1, 3]]).values; // [3.618033988749895, 1.381966011250105]
|
|
|
115
155
|
| Distributions (d/p/q) | normal, t, chi-squared, F, beta, gamma, binomial, Poisson, uniform, exponential, log-normal, logistic, Cauchy, Weibull, geometric, negative binomial, hypergeometric, Wilcoxon signed rank and rank sum, studentized range (`ptukey`, `qtukey`), non-central chi-squared, t, F and beta (`ncp`); the multinomial probability (`dmultinom`); inverse gamma, Kumaraswamy, Pareto, triangular, Laplace (extraDistr) and arcsine; `distSummary` (mean, variance, sd, median, mode, skewness, kurtosis) |
|
|
116
156
|
| Random numbers | `setSeed` (`set.seed`), `RNGkind` (Mersenne-Twister and L'Ecuyer-CMRG, `sample.kind` Rejection and Rounding), `getRandomSeed`/`setRandomSeed` (`.Random.seed`), `nextRNGStream`/`nextRNGSubStream` (`parallel`), 26 `r*` functions, `sample`, `sampleInt` (`sample.int`), `r2dtable` |
|
|
117
157
|
| Descriptive statistics | `sum`, `prod`, `mean`, `weightedMean` (`weighted.mean`), `variance` (`var`), `sd`, `median`, `range`, `cumsum`, `cumprod`, `cummax`, `cummin`, `diff`, `quantile`, `IQR`, `fivenum`, `mad`, `rank`, `cov`, `cor`, `tabulate`, `table`, `unique`, `cut`, `findInterval`, `pretty`, `hist`, `ecdf`, `scale`, `skewness`, `kurtosis`, `geometricMean`, `modes`, `meanAD`, `cv` |
|
|
118
|
-
| Hypothesis tests | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `corTest`, `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`, `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`, `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`, `pairwiseWilcoxTest`, `pairwisePropTest`, `aov
|
|
119
|
-
|
|
|
120
|
-
|
|
|
121
|
-
|
|
|
158
|
+
| Hypothesis tests | `tTest`, `chisqTest`, `fisherTest`, `wilcoxTest`, `corTest`, `binomTest`, `poissonTest`, `propTest`, `mcnemarTest`, `varTest`, `bartlettTest`, `kruskalTest`, `friedmanTest`, `quadeTest`, `flignerTest`, `moodTest`, `onewayTest`, `shapiroTest`, `mantelhaenTest`, `ansariTest`, `ksTest`, `pairwiseTTest`, `pairwiseWilcoxTest`, `pairwisePropTest`, `aov` (one way), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
|
|
159
|
+
| 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`) |
|
|
160
|
+
| 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) |
|
|
161
|
+
| 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`) |
|
|
162
|
+
| More tests | `leveneTest`, `propTrendTest` (`prop.trend.test`), `jonckheereTest`, `cochranQTest`, `adTest`, `lillieTest`, `cvmTest`, `sfTest`, `pearsonTest` (car, DescTools, clinfun, nortest) |
|
|
163
|
+
| Multiple comparisons | `dscfAllPairsTest` (Steel-Dwass), `kwAllPairsDunnTest`, `kwManyOneDunnTest`, `manyOneUTest` (Steel's many-one rank test), `dunnettTest`, `gamesHowellTest`, `tukeyTest` (PMCMRplus), `dunnTest` (dunn.test), `glhtDunnett` (multcomp) |
|
|
164
|
+
| 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) |
|
|
165
|
+
| Agreement and reliability | `kappa2`, `kappamFleiss`, `icc` (irr), `cronbachAlpha`, `partialR` (psych), `polychor`, `polyserial` (polycor), `pbvnorm`, `factanal`, `omega` (McDonald's ω, psych) |
|
|
166
|
+
| Data handling | `completeCases` (`complete.cases`), `naOmit` (`na.omit`), `subset`, `merge`, `rbind` and `cbind` of data frames, `tapply`, `split`, `aggregate`, `pivotLonger` and `pivotWider` (tidyr); formula forms of the tests (`tTest("y ~ g", data)`, `kruskalTest`, `friedmanTest("y ~ w \| b", data)`, `corTest("~ x + y", data)`, ...) |
|
|
167
|
+
| Linear algebra | `matMul` (`%*%`), `add`, `subtract`, `multiply`, `divide`, `outer`, `t`, `diag`, `cbind`, `rbind`, `matrix`, `kronecker`, `seq`, `crossprod`, `tcrossprod`, `norm`, `backsolve`, `forwardsolve`, `chol`, `chol2inv`, `qr` with `qrQ`, `qrR`, `qrX`, `qrCoef`, `qrQy`, `qrQty`, `qrResid`, `qrFitted`, `qrSolve` (`qr.Q` …), `solve`, `det`, `determinant`, `rcond`, `kappa`, `svd`, `eigen`, `lu`, `prcomp`, `ginv` (MASS), `schur`, `expm` |
|
|
168
|
+
| Numerical methods | `integrate`, `optimize`, `optim`, `optimHess`, `uniroot`, `approx`, `spline`, `splinefun`, `splinefunH`, `barylag`, `hermiteInterp`, `ode`, `grad`, `jacobian`, `hessian` |
|
|
169
|
+
|
|
170
|
+
New to R's way of writing an analysis (data frames, formulas, factors)? [docs/guide-for-js-developers.md](docs/guide-for-js-developers.md) explains it from a JavaScript developer's point of view, with a worked example.
|
|
122
171
|
|
|
123
172
|
Coming from jStat? [docs/migrating-from-jstat.md](docs/migrating-from-jstat.md) lists the replacement for every jStat function.
|
|
124
173
|
|
|
125
174
|
An API reference can be generated with `npm run docs` (TypeDoc).
|
|
126
175
|
|
|
176
|
+
For AI coding assistants, [llms.txt](llms.txt) summarises how R code translates to rStats.js
|
|
177
|
+
calls (also in the npm package and at <https://numero-uno-jpn.github.io/rStats.js/llms.txt>).
|
|
178
|
+
|
|
127
179
|
## Accuracy
|
|
128
180
|
|
|
129
181
|
Expected values are produced by R scripts in [`oracle/`](oracle) and stored in
|
|
@@ -156,10 +208,10 @@ removed. Approximate sizes after minification and gzip:
|
|
|
156
208
|
| `pnorm` | 1.2 KB |
|
|
157
209
|
| `setSeed`, `rnorm` | 1.7 KB |
|
|
158
210
|
| `solve` / `svd` / `eigen` | 1.7 / 2.0 / 3.7 KB |
|
|
159
|
-
| `wilcoxTest` / `fisherTest` / `tTest` |
|
|
211
|
+
| `wilcoxTest` / `fisherTest` / `tTest` | 12.1 / 15.6 / 24.9 KB |
|
|
160
212
|
| `qbeta` / `pt` and `qt` | 23.2 / 30.3 KB |
|
|
161
213
|
| `glm` and `glmSummary` / `glm` with all its methods | 27.2 / 39.2 KB |
|
|
162
|
-
| everything |
|
|
214
|
+
| everything | 185.8 KB |
|
|
163
215
|
|
|
164
216
|
(`npm run size` measures these.)
|
|
165
217
|
|
|
@@ -168,11 +220,11 @@ Each area is also a subpath export, for importing one area without the rest:
|
|
|
168
220
|
`predict`, and `glm` with its methods), `/linalg`, `/descriptive`, `/numerics` and `/special`.
|
|
169
221
|
|
|
170
222
|
Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
|
|
171
|
-
function,
|
|
223
|
+
function, 186 KB gzipped) from jsDelivr, which serves each release tag of this repository:
|
|
172
224
|
|
|
173
225
|
```html
|
|
174
226
|
<script type="module">
|
|
175
|
-
import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.
|
|
227
|
+
import { pnorm } from "https://cdn.jsdelivr.net/gh/numero-uno-jpn/rStats.js@v0.11.0/dist/rstats.js";
|
|
176
228
|
console.log(pnorm(1.96)); // 0.9750021048517795
|
|
177
229
|
</script>
|
|
178
230
|
```
|
|
@@ -188,11 +240,11 @@ A page that needs only some areas can load the per-area bundles instead: `dist/d
|
|
|
188
240
|
`dist/tests.js`, `dist/linalg.js`, `dist/descriptive.js`, `dist/numerics.js` and `dist/special.js`
|
|
189
241
|
export the same functions as the subpaths above, and share their common code through
|
|
190
242
|
`dist/chunks/`, so loading two areas does not load that code twice. With its chunks, one area
|
|
191
|
-
transfers
|
|
243
|
+
transfers 29 KB (`numerics`) to 153 KB (`tests`) gzipped.
|
|
192
244
|
|
|
193
245
|
Release tags contain the build output (`dist/`), which is not on the main branch. npm-based CDNs
|
|
194
246
|
work as well, for example
|
|
195
|
-
`https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.
|
|
247
|
+
`https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.11.0/dist/rstats.js` or
|
|
196
248
|
`https://esm.sh/@numero-uno-jpn/rstats`.
|
|
197
249
|
|
|
198
250
|
The browser build is tested in headless Chromium, both bundled and as `dist/rstats.js` loaded as
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -240,8 +240,8 @@ DAMAGE.
|
|
|
240
240
|
- Source: https://github.com/Reference-LAPACK/lapack (tag v3.12.0)
|
|
241
241
|
- `BLAS/SRC/dtrsm.f`, `SRC/dlange.f`, `SRC/dpotf2.f`, `SRC/dpstf2.f`, `SRC/dpotri.f` (`dtrti2.f`, `dlauu2.f`),
|
|
242
242
|
`SRC/dgeqp3.f` (`dlaqp2.f`, `dlarfg.f`, `dlarf.f`), `SRC/dorm2r.f`, `SRC/dgetf2.f`, `SRC/dgetrs.f`,
|
|
243
|
-
`SRC/dgecon.f`, `SRC/dtrcon.f`, `SRC/dlacn2.f`
|
|
244
|
-
- 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`
|
|
243
|
+
`SRC/dgecon.f`, `SRC/dtrcon.f`, `SRC/dlacn2.f`, `SRC/dgebal.f`, `SRC/dlanv2.f`
|
|
244
|
+
- 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/expm.ts`, `src/linalg/schur.ts`
|
|
245
245
|
- License: modified BSD
|
|
246
246
|
|
|
247
247
|
```
|
|
@@ -316,6 +316,11 @@ they are listed so that readers can find the originals.
|
|
|
316
316
|
- netlib fmm (https://netlib.org/fmm/fmin.f; Brent, "Algorithms for Minimization without Derivatives",
|
|
317
317
|
1973, chapter 5): `fmin` (Brent's localmin, golden-section search with parabolic interpolation),
|
|
318
318
|
the minimiser of `optimize` — `src/optim/localmin.ts`
|
|
319
|
+
- L-BFGS-B version 2.1 (C. Zhu, R. H. Byrd, P. Lu-Chen and J. Nocedal; netlib
|
|
320
|
+
https://www.netlib.org/opt/lbfgs_bcm.shar, `routines.f`, distributed without a copyright notice): `setulb`/`mainlb`
|
|
321
|
+
and their subroutines (generalized Cauchy point, subspace minimisation, limited-memory BFGS matrices), with the
|
|
322
|
+
MINPACK-2 line search `dcsrch`/`dcstep` (Moré and Thuente) and the LINPACK/BLAS routines it ships with, the method
|
|
323
|
+
"L-BFGS-B" of `optim` — `src/optim/lbfgsb.ts`
|
|
319
324
|
- QUADPACK (Piessens, de Doncker-Kapenga, Überhuber, Kahaner 1983): `dqagse` and `dqagie` (adaptive
|
|
320
325
|
Gauss–Kronrod quadrature with extrapolation), behind `integrate` — `src/integrate/quadpack.ts`,
|
|
321
326
|
ported from SciPy's C translation (see SciPy above)
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.11.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
|
+
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};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.11.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
|
+
function A(l,s){return{nrow:l,ncol:s,data:new Float64Array(l*s)}}function _(l){return l.length>0&&typeof l[0]!="number"}function R(l){let s=l.length,r=s===0?0:l[0].length,n=A(s,r);for(let a=0;a<s;a++){let i=l[a];if(i.length!==r)throw new TypeError("all rows of the matrix must have the same length");for(let t=0;t<r;t++)n.data[a+t*s]=i[t]}return n}function C(l){if(_(l))return R(l);let s=l;return{nrow:s.length,ncol:1,data:Float64Array.from(s)}}function $(l){let s=[];for(let r=0;r<l.nrow;r++){let n=new Array(l.ncol);for(let a=0;a<l.ncol;a++)n[a]=l.data[r+a*l.nrow];s.push(n)}return s}function W(l){let s=A(l.ncol,l.nrow);for(let r=0;r<l.ncol;r++)for(let n=0;n<l.nrow;n++)s.data[r+n*l.ncol]=l.data[n+r*l.nrow];return s}function O(l,s="the matrix"){if(l.nrow!==l.ncol)throw new TypeError(`${s} must be square (got ${l.nrow} x ${l.ncol})`)}function H(l,s={}){let r=R(l);if(s.lapack){let{tau:t,pivot:c}=ut(r),e=Array.from({length:r.ncol},(o,u)=>t[u]??0);return{qr:$(r),rank:Math.min(r.nrow,r.ncol),qraux:e,pivot:c.map(o=>o-1),useLapack:!0}}for(let t of r.data)if(!Number.isFinite(t))throw new RangeError("the matrix contains NaN or infinite values");let{qraux:n,pivot:a,rank:i}=ct(r,s.tol??1e-7);return{qr:$(r),rank:i,qraux:Array.from(n),pivot:a.map(t=>t-1),useLapack:!1}}function S(l,s,r){let n=0;for(let i=0;i<r;i++)n=Math.max(n,Math.abs(l[s+i]));if(n===0||!Number.isFinite(n))return n;let a=0;for(let i=0;i<r;i++){let t=l[s+i]/n;a+=t*t}return n*Math.sqrt(a)}function ct(l,s){let r=l.nrow,n=l.ncol,a=l.data,i=new Float64Array(n),t=new Float64Array(n),c=new Float64Array(n),e=Array.from({length:n},(f,h)=>h+1);for(let f=0;f<n;f++)i[f]=S(a,f*r,r),t[f]=i[f],c[f]=i[f]===0?1:i[f];let o=new Float64Array(r),u=Math.min(r,n),w=n;for(let f=0;f<u;f++){for(;f<w&&i[f]<c[f]*s;){o.set(a.subarray(f*r,(f+1)*r));let[d,v,m,b]=[i[f],t[f],c[f],e[f]];a.copyWithin(f*r,(f+1)*r,n*r),a.set(o,(n-1)*r),i.copyWithin(f,f+1),t.copyWithin(f,f+1),c.copyWithin(f,f+1),e.copyWithin(f,f+1),i[n-1]=d,t[n-1]=v,c[n-1]=m,e[n-1]=b,w--}if(f===r-1)break;let h=f*r,p=S(a,h+f,r-f);if(p!==0){a[h+f]!==0&&(p=Math.sign(a[h+f])*Math.abs(p));for(let d=f;d<r;d++)a[h+d]/=p;a[h+f]=1+a[h+f];for(let d=f+1;d<n;d++){let v=d*r,m=0;for(let j=f;j<r;j++)m-=a[h+j]*a[v+j];m/=a[h+f];for(let j=f;j<r;j++)a[v+j]+=m*a[h+j];if(i[d]===0)continue;let b=1-(Math.abs(a[v+f])/i[d])**2;b=Math.max(b,0);let N=b;b=1+.05*b*(i[d]/t[d])**2,b!==1?i[d]*=Math.sqrt(N):(i[d]=S(a,v+f+1,r-f-1),t[d]=i[d])}i[f]=a[h+f],a[h+f]=-p}}return{qraux:i,pivot:e,rank:Math.min(w,r)}}function ut(l){let s=l.nrow,r=l.ncol,n=l.data,a=Math.min(s,r),i=new Float64Array(a),t=Array.from({length:r},(u,w)=>w+1),c=new Float64Array(r),e=new Float64Array(r);for(let u=0;u<r;u++)c[u]=S(n,u*s,s),e[u]=c[u];let o=Math.sqrt(2**-53);for(let u=0;u<a;u++){let w=u;for(let h=u+1;h<r;h++)Math.abs(c[h])>Math.abs(c[w])&&(w=h);if(w!==u){for(let h=0;h<s;h++){let p=n[h+w*s];n[h+w*s]=n[h+u*s],n[h+u*s]=p}[t[w],t[u]]=[t[u],t[w]],c[w]=c[u],e[w]=e[u]}let f=u*s;if(i[u]=X(n,f+u,s-u),u<r-1){let h=n[f+u];n[f+u]=1,V(n,f+u,s-u,i[u],l,u,u+1,r-u-1),n[f+u]=h}for(let h=u+1;h<r;h++){if(c[h]===0)continue;let p=1-(Math.abs(n[u+h*s])/c[h])**2;p=Math.max(p,0),p*(c[h]/e[h])**2<=o?u<s-1?(c[h]=S(n,h*s+u+1,s-u-1),e[h]=c[h]):(c[h]=0,e[h]=0):c[h]*=Math.sqrt(p)}}return{tau:i,pivot:t}}function X(l,s,r){if(r<=1)return 0;let n=S(l,s+1,r-1);if(n===0)return 0;let a=l[s],i=-Math.sign(a||1)*Math.hypot(a,n),t=2**-1022/2**-53,c=0;if(Math.abs(i)<t){let u=1/t;do{c++;for(let w=1;w<r;w++)l[s+w]*=u;i*=u,a*=u}while(Math.abs(i)<t&&c<20);n=S(l,s+1,r-1),i=-Math.sign(a||1)*Math.hypot(a,n)}let e=(i-a)/i,o=1/(a-i);for(let u=1;u<r;u++)l[s+u]*=o;for(let u=0;u<c;u++)i*=t;return l[s]=i,e}function V(l,s,r,n,a,i,t,c){if(n===0)return;let e=a.nrow,o=a.data;for(let u=t;u<t+c;u++){let w=i+u*e,f=0;for(let h=0;h<r;h++)f+=o[w+h]*l[s+h];f*=n;for(let h=0;h<r;h++)o[w+h]-=l[s+h]*f}}function Q(l){return{a:R(l.qr),qraux:l.qraux,rank:l.rank,pivot:l.pivot.map(s=>s+1),lapack:l.useLapack}}function B(l,s){let r=C(s);if(r.nrow!==l.a.nrow)throw new TypeError(`qr and y must have the same number of rows (${l.a.nrow} and ${r.nrow})`);return r}function P(l,s){return _(l)?$(s):Array.from(s.data)}function L(l,s,r,n=l.rank){let{a,qraux:i}=l,t=a.nrow;if(l.lapack){let o=Math.min(t,a.ncol),u=r?U(0,o):U(0,o).reverse();for(let w of u){let f=a.data[w+w*t];a.data[w+w*t]=1,V(a.data,w+w*t,t-w,i[w],s,w,0,s.ncol),a.data[w+w*t]=f}return}let c=Math.min(n,t-1),e=r?U(0,c):U(0,c).reverse();for(let o of e){if(i[o]===0)continue;let u=o*t,w=a.data[u+o];a.data[u+o]=i[o];for(let f=0;f<s.ncol;f++){let h=f*t,p=0;for(let d=o;d<t;d++)p-=a.data[u+d]*s.data[h+d];p/=a.data[u+o];for(let d=o;d<t;d++)s.data[h+d]+=p*a.data[u+d]}a.data[u+o]=w}}function U(l,s){return Array.from({length:Math.max(0,s-l)},(r,n)=>l+n)}function It(l,s){let r=Q(l),n=B(r,s);return L(r,n,!0),P(s,n)}function zt(l,s){let r=Q(l),n=B(r,s);return L(r,n,!1),P(s,n)}function ht(l,s){let r=Q(l),n=B(r,s),a=r.a.ncol,i=r.a.nrow,t=r.lapack?Math.min(i,a):r.rank;L(r,n,!0);for(let e=0;e<n.ncol;e++){let o=e*i;for(let u=t-1;u>=0;u--){let w=r.a.data[u+u*i];if(w===0)throw new Error("exact singularity in qrCoef");n.data[o+u]/=w;let f=-n.data[o+u];for(let h=0;h<u;h++)n.data[o+h]+=f*r.a.data[h+u*i]}}let c=A(a,n.ncol);c.data.fill(NaN);for(let e=0;e<n.ncol;e++)for(let o=0;o<t;o++)c.data[r.pivot[o]-1+e*a]=n.data[o+e*i];return P(s,c)}function tt(l,s,r,n){let a=Q(l);if(a.lapack)throw new TypeError("not supported for a QR decomposition computed with lapack: true");let i=n??a.rank;if(!Number.isInteger(i)||i<0||i>a.rank)throw new RangeError(`invalid k (got ${i})`);let t=B(a,s),c=a.a.nrow;if(i===0)return P(s,t);if(c===1)return r||t.data.fill(0),P(s,t);L(a,t,!0,i);for(let e=0;e<t.ncol;e++)r?t.data.fill(0,e*c+i,(e+1)*c):t.data.fill(0,e*c,e*c+i);return L(a,t,!1,i),P(s,t)}function Ot(l,s){return tt(l,s,!1)}function St(l,s,r={}){return tt(l,s,!0,r.k)}function Lt(l,s={}){let r=Q(l),n=r.a.nrow,a=s.complete?n:Math.min(n,r.a.ncol),i=s.dvec??new Array(a).fill(1);if(i.length!==a)throw new RangeError(`dvec must have length ${a}`);let t=A(n,a);for(let c=0;c<a;c++)t.data[c+c*n]=i[c];return L(r,t,!1),$(t)}function ot(l,s={}){let r=R(l.qr),n=s.complete?r.nrow:Math.min(r.nrow,r.ncol),a=A(n,r.ncol);for(let i=0;i<r.ncol;i++)for(let t=0;t<=Math.min(i,n-1);t++)a.data[t+i*n]=r.data[t+i*r.nrow];return $(a)}function _t(l,s={}){let r=Q(l),n=r.a.nrow,a=r.a.ncol,i=s.complete??!1,t=s.ncol??(i?n:Math.min(n,a));if(!Number.isInteger(t)||t<0)throw new RangeError(`invalid ncol (got ${t})`);if(r.pivot.some((w,f)=>w!==f+1)&&t<a)throw new RangeError("ncol must be at least the number of columns because the decomposition is pivoted");let e=A(n,t);for(let w=0;w<t;w++)if(w<a)for(let f=0;f<=Math.min(w,n-1);f++)e.data[f+w*n]=r.a.data[f+w*n];else w<n&&(e.data[w+w*n]=1);L(r,e,!1);let o=Math.min(t,a),u=A(n,t);u.data.set(e.data);for(let w=0;w<o;w++){let f=r.pivot[w]-1;f<o&&u.data.set(e.data.subarray(w*n,(w+1)*n),f*n)}return $(u)}function Ct(l,s,r={}){let n=Array.isArray(l)?H(l,{tol:r.tol??1e-7}):l,a=n.qr.length,i=a===0?0:n.qr[0].length;if(n.rank!==Math.min(a,i))throw new Error("singular matrix in qrSolve");if(s===void 0&&a!==i)throw new TypeError("only square matrices can be inverted");let t=s??Array.from({length:a},(o,u)=>Array.from({length:a},(w,f)=>u===f?1:0)),c=ht(n,t),e=o=>Number.isNaN(o)?0:o;return _(t)?c.map(o=>o.map(e)):c.map(e)}function Wt(l,s={}){let r=R(l);for(let w of r.data)if(!Number.isFinite(w))throw new RangeError("the matrix contains NaN or infinite values");let n=Math.min(r.nrow,r.ncol),a=Math.min(s.nu??n,r.nrow),i=Math.min(s.nv??n,r.ncol);for(let[w,f]of[["nu",a],["nv",i]])if(!Number.isInteger(f)||f<0)throw new RangeError(`${w} must be a non-negative integer`);let t=r.nrow<r.ncol,c=et(t?W(r):r,t?i:a,t?a:i),e={d:Array.from(c.d)},[o,u]=t?[c.v,c.u]:[c.u,c.v];return a>0&&(e.u=$(rt(o,a))),i>0&&(e.v=$(rt(u,i))),e}function nt(l){return et(l.nrow<l.ncol?W(l):l,0,0).d}function rt(l,s){return{nrow:l.nrow,ncol:s,data:l.data.slice(0,l.nrow*s)}}function et(l,s,r){let n=l.nrow,a=l.ncol,i=new Float64Array(a);if(a===0)return{d:i,u:A(n,n),v:A(0,0)};let t={nrow:n,ncol:a,data:l.data.slice()},c=new Float64Array(a),e=new Float64Array(a),o=new Float64Array(a);for(let m=0;m<a;m++){let b=m*n;if(e[m]=X(t.data,b+m,n-m),i[m]=t.data[b+m],m<a-1&&(t.data[b+m]=1,V(t.data,b+m,n-m,e[m],t,m,m+1,a-m-1),t.data[b+m]=i[m]),m<a-1){let N=new Float64Array(a-m-1);for(let y=0;y<N.length;y++)N[y]=t.data[m+(m+1+y)*n];o[m]=X(N,0,N.length),c[m+1]=N[0],N[0]=1;let j=o[m];if(j!==0)for(let y=m+1;y<n;y++){let q=0;for(let x=0;x<N.length;x++)q+=t.data[y+(m+1+x)*n]*N[x];q*=j;for(let x=0;x<N.length;x++)t.data[y+(m+1+x)*n]-=q*N[x]}N[0]=c[m+1];for(let y=0;y<N.length;y++)t.data[m+(m+1+y)*n]=N[y]}}let u=s===0?0:Math.max(s,a),w;if(u>0){w=A(n,u);for(let m=0;m<u;m++)w.data[m+m*n]=1;for(let m=a-1;m>=0;m--){let b=m*n,N=t.data[b+m];t.data[b+m]=1,V(t.data,b+m,n-m,e[m],w,m,0,u),t.data[b+m]=N}}let f;if(r>0){f=A(a,a);for(let b=0;b<a;b++)f.data[b+b*a]=1;let m=new Float64Array(a);for(let b=a-2;b>=0;b--){let N=a-b-1;m[0]=1;for(let j=1;j<N;j++)m[j]=t.data[b+(b+1+j)*n];V(m,0,N,o[b],f,b+1,0,a)}}wt(i,c,w,f);let h=Array.from({length:a},(m,b)=>b).sort((m,b)=>i[b]-i[m]||m-b),p=Float64Array.from(h,m=>i[m]),d=(m,b)=>{if(m===void 0)return;let N={nrow:m.nrow,ncol:m.ncol,data:m.data.slice()};for(let j=0;j<b;j++)N.data.set(m.data.subarray(h[j]*m.nrow,(h[j]+1)*m.nrow),j*m.nrow);return N},v={d:p};return w&&(v.u=d(w,a)),f&&(v.v=d(f,a)),v}function wt(l,s,r,n){let a=l.length,i=Number.EPSILON,t=0;for(let o=0;o<a;o++)t=Math.max(t,Math.abs(l[o])+Math.abs(s[o]));let c=(o,u,w,f)=>{if(!r)return;let h=r.nrow;for(let p=0;p<h;p++){let d=r.data[p+o*h],v=r.data[p+u*h];r.data[p+o*h]=d*w+v*f,r.data[p+u*h]=v*w-d*f}},e=(o,u,w,f)=>{if(n)for(let h=0;h<a;h++){let p=n.data[h+o*a],d=n.data[h+u*a];n.data[h+o*a]=p*w+d*f,n.data[h+u*a]=d*w-p*f}};for(let o=a-1;o>=0;o--)for(let u=0;;u++){let w=o,f=!0;for(;w>=0;w--){if(w===0||Math.abs(s[w])<=i*t){f=!1;break}if(Math.abs(l[w-1])<=i*t)break}if(f){let q=w-1,x=0,F=1;for(let z=w;z<=o;z++){let E=F*s[z];if(s[z]=x*s[z],Math.abs(E)<=i*t)break;let M=l[z],g=Math.hypot(E,M);l[z]=g,x=M/g,F=-E/g,c(q,z,x,F)}}let h=l[o];if(w===o){if(h<0&&(l[o]=-h,n))for(let q=0;q<a;q++)n.data[q+o*a]=-n.data[q+o*a];break}if(u>=75)throw new Error("the singular value decomposition did not converge");let p=l[w],d=o-1,v=l[d],m=s[d],b=s[o],N=((v-h)*(v+h)+(m-b)*(m+b))/(2*b*v);m=Math.hypot(N,1),N=((p-h)*(p+h)+b*(v/(N+(N>=0?Math.abs(m):-Math.abs(m)))-b))/p;let j=1,y=1;for(let q=w;q<=d;q++){let x=q+1;m=s[x],v=l[x],b=y*m,m=j*m;let F=Math.hypot(N,b);s[q]=F,j=N/F,y=b/F,N=p*j+m*y,m=m*j-p*y,b=v*y,v*=j,e(q,x,j,y),F=Math.hypot(N,b),l[q]=F,F!==0&&(j=N/F,y=b/F),N=j*m+y*v,p=j*v-y*m,c(q,x,j,y)}s[w]=0,s[o]=N,l[o]=p}}function Bt(l,s={}){let r=R(l),n=s.type??"O";if(n.length!==1)throw new RangeError(`type must be a single character (got "${n}")`);switch(n.toUpperCase()){case"O":case"1":return D(r);case"I":return K(r);case"F":case"E":return mt(r);case"M":return at(r);case"2":return dt(r);default:throw new RangeError(`type must be one of "O", "I", "F", "M" and "2" (got "${n}")`)}}function J(l,s){return Number.isNaN(l)||Number.isNaN(s)?NaN:Math.max(l,s)}function D(l){let s=0;for(let r=0;r<l.ncol;r++){let n=0;for(let a=0;a<l.nrow;a++)n+=Math.abs(l.data[a+r*l.nrow]);s=J(s,n)}return s}function K(l){let s=new Float64Array(l.nrow);for(let n=0;n<l.ncol;n++)for(let a=0;a<l.nrow;a++)s[a]+=Math.abs(l.data[a+n*l.nrow]);let r=0;for(let n of s)r=J(r,n);return r}function at(l){let s=0;for(let r of l.data)s=J(s,Math.abs(r));return s}function mt(l){let s=at(l);if(s===0||!Number.isFinite(s))return s;let r=0;for(let n of l.data){let a=n/s;r+=a*a}return s*Math.sqrt(r)}function dt(l){if(l.nrow===0||l.ncol===0)return 0;if(l.data.some(Number.isNaN))return NaN;if(l.data.some(s=>!Number.isFinite(s)))throw new RangeError("the matrix contains infinite values");return nt(l)[0]}function Y(l){let s=l.nrow,r=l.ncol,n=l.data,a=Math.min(s,r),i=new Int32Array(a),t=2**-1022,c=0;for(let e=0;e<a;e++){let o=e*s,u=e,w=Math.abs(n[o+e]);for(let f=e+1;f<s;f++){let h=Math.abs(n[o+f]);h>w&&(w=h,u=f)}if(i[e]=u,n[o+u]!==0){if(u!==e)for(let h=0;h<r;h++){let p=n[e+h*s];n[e+h*s]=n[u+h*s],n[u+h*s]=p}let f=n[o+e];if(Math.abs(f)>=t){let h=1/f;for(let p=e+1;p<s;p++)n[o+p]*=h}else for(let h=e+1;h<s;h++)n[o+h]/=f}else c===0&&(c=e+1);for(let f=e+1;f<r;f++){let h=n[e+f*s];if(h===0)continue;let p=-h;for(let d=e+1;d<s;d++)n[d+f*s]+=n[o+d]*p}}return{ipiv:i,info:c}}function pt(l,s,r){let n=l.nrow,a=l.data,i=r.data;for(let t=0;t<r.ncol;t++){let c=t*n;for(let e=0;e<n;e++){let o=s[e];if(o!==e){let u=i[c+e];i[c+e]=i[c+o],i[c+o]=u}}for(let e=0;e<n;e++){let o=i[c+e];if(o!==0)for(let u=e+1;u<n;u++)i[c+u]-=o*a[u+e*n]}for(let e=n-1;e>=0;e--)if(i[c+e]!==0){i[c+e]/=a[e+e*n];let o=i[c+e];for(let u=0;u<e;u++)i[c+u]-=o*a[u+e*n]}}}function T(l,s,r,n,a){let i=l.nrow,t=l.data;if(r)if(s)for(let c=0;c<i;c++){let e=a[c];for(let o=0;o<c;o++)e-=t[o+c*i]*a[o];n||(e/=t[c+c*i]),a[c]=e}else for(let c=i-1;c>=0;c--){let e=a[c];for(let o=i-1;o>c;o--)e-=t[o+c*i]*a[o];n||(e/=t[c+c*i]),a[c]=e}else if(s){for(let c=i-1;c>=0;c--)if(a[c]!==0){n||(a[c]/=t[c+c*i]);let e=a[c];for(let o=c-1;o>=0;o--)a[o]-=e*t[o+c*i]}}else for(let c=0;c<i;c++)if(a[c]!==0){n||(a[c]/=t[c+c*i]);let e=a[c];for(let o=c+1;o<i;o++)a[o]-=e*t[o+c*i]}}function it(l,s){let r=new Float64Array(l),n=new Int32Array(l),a=()=>r.reduce((h,p)=>h+Math.abs(p),0),i=()=>{let h=0;for(let p=1;p<l;p++)Math.abs(r[p])>Math.abs(r[h])&&(h=p);return h},t=()=>{for(let h=0;h<l;h++)r[h]=r[h]>=0?1:-1,n[h]=r[h]};if(r.fill(1/l),s(1,r),l===1)return Math.abs(r[0]);let c=a();t(),s(2,r);let e=i(),o=2,u=5;for(;;){r.fill(0),r[e]=1,s(1,r);let h=c;c=a();let p=!1;for(let v=0;v<l;v++)if((r[v]>=0?1:-1)!==n[v]){p=!0;break}if(!p||c<=h)break;t(),s(2,r);let d=e;if(e=i(),r[d]!==Math.abs(r[e])&&o<u){o++;continue}break}let w=1;for(let h=0;h<l;h++)r[h]=w*(1+h/(l-1)),w=-w;s(1,r);let f=2*(a()/(3*l));return f>c?f:c}function ft(l,s,r){let n=l.nrow;if(n===0)return 1;if(!Number.isFinite(s))throw new RangeError("the matrix contains NaN or infinite values (LAPACK dgecon returned error -5)");if(s===0)return 0;let a=r?1:2,i=it(n,(t,c)=>{t===a?(T(l,!1,!1,!0,c),T(l,!0,!1,!1,c)):(T(l,!0,!0,!1,c),T(l,!1,!0,!0,c))});return Number.isFinite(i)?i===0?0:1/i/s:0}function Mt(l,s,r){let n=l.nrow,a=new Float64Array(n);for(let t=0;t<n;t++){let[c,e]=s?[0,t]:[t,n-1];for(let o=c;o<=e;o++)a[r?t:o]+=Math.abs(l.data[o+t*n])}let i=0;for(let t of a)i=Number.isNaN(i)||Number.isNaN(t)?NaN:Math.max(i,t);return i}function st(l,s,r){let n=l.nrow;if(n===0)return 1;let a=Mt(l,s,r);if(!(a>0))return 0;let i=r?1:2,t=it(n,(c,e)=>T(l,s,c!==i,!1,e));return Number.isFinite(t)?t===0?0:1/a/t:0}function Kt(l,s,r={}){let n=R(l);O(n);let a=n.nrow,i;if(s===void 0){i=A(a,a);for(let u=0;u<a;u++)i.data[u+u*a]=1}else if(i=C(s),i.nrow!==a)throw new TypeError(`b (${i.nrow} x ${i.ncol}) is not compatible with a (${a} x ${a})`);let t=D(n),{ipiv:c,info:e}=Y(n);if(e>0)throw new Error(`the system is exactly singular: U[${e}, ${e}] = 0`);let o=r.tol??Number.EPSILON;if(o>0&&Number.isFinite(t)){let u=ft(n,t,!0);if(u<o)throw new Error(`the system is computationally singular: reciprocal condition number = ${u.toPrecision(6)}`)}return pt(n,c,i),s!==void 0&&!_(s)?Array.from(i.data):$(i)}function bt(l,s={}){let r=s.logarithm??!0,n=R(l);O(n);let a=n.nrow,{ipiv:i,info:t}=Y(n);if(t>0)return{modulus:r?-1/0:0,logarithm:r,sign:1};let c=1,e=r?0:1;for(let o=0;o<a;o++){i[o]!==o&&(c=-c);let u=n.data[o+o*a];u<0&&(c=-c),r?e+=Math.log(Math.abs(u)):e*=Math.abs(u)}return{modulus:e,logarithm:r,sign:c}}function Yt(l){let{modulus:s,sign:r}=bt(l);return r*Math.exp(s)}function Zt(l,s={}){let r=s.norm??"O";if(!["O","1","I"].includes(r))throw new RangeError(`norm must be "O", "I" or "1" (got "${r}")`);let n=r!=="I",a=R(l);if(a.nrow!==a.ncol){let c=a.nrow<a.ncol?$(W(a)):l;return st(R(ot(H(c))),!0,n)}if(s.triangular)return st(a,(s.uplo??"U")==="U",n);let i=n?D(a):K(a);a={...a,data:a.data.slice()};let{info:t}=Y(a);return t>0?0:ft(a,i,n)}function ro(l,s={}){let r=R(l);if(O(r),r.nrow===0)throw new RangeError("the matrix has zero dimension");if(s.pivot){let{pivot:a,rank:i}=vt(r,s.tol??-1);return lt(r),{r:$(r),pivot:a.map(t=>t-1),rank:i}}let n=gt(r);if(n>0)throw new Error(`the matrix is not positive definite: the leading minor of order ${n} is not positive`);return lt(r),$(r)}function lt(l){let s=l.nrow;for(let r=0;r<s;r++)for(let n=r+1;n<s;n++)l.data[n+r*s]=0}function gt(l){let s=l.nrow,r=l.data;for(let n=0;n<s;n++){let a=n*s,i=r[n+a];for(let t=0;t<n;t++)i-=r[t+a]*r[t+a];if(i<=0)return r[n+a]=i,n+1;i=Math.sqrt(i),r[n+a]=i;for(let t=n+1;t<s;t++){let c=t*s,e=r[n+c];for(let o=0;o<n;o++)e-=r[o+a]*r[o+c];r[n+c]=e/i}}return 0}function vt(l,s){let r=l.nrow,n=l.data,a=Array.from({length:r},(w,f)=>f+1),i=(w,f)=>w+f*r,t=(w,f)=>{let h=n[w];n[w]=n[f],n[f]=h},c=0;for(let w=1;w<r;w++)n[i(w,w)]>n[i(c,c)]&&(c=w);let e=n[i(c,c)];if(e<=0||Number.isNaN(e))return{pivot:a,rank:0};let o=s<0?r*Number.EPSILON*e:s,u=new Float64Array(2*r);for(let w=0;w<r;w++){for(let f=w;f<r;f++)w>0&&(u[f]+=n[i(w-1,f)]**2),u[r+f]=n[i(f,f)]-u[f];if(w>0){c=w;for(let f=w+1;f<r;f++)u[r+f]>u[r+c]&&(c=f);if(e=u[r+c],e<=o||Number.isNaN(e))return n[i(w,w)]=e,{pivot:a,rank:w}}if(w!==c){n[i(c,c)]=n[i(w,w)];for(let f=0;f<w;f++)t(i(f,w),i(f,c));for(let f=c+1;f<r;f++)t(i(w,f),i(c,f));for(let f=w+1;f<c;f++)t(i(w,f),i(f,c));[u[w],u[c]]=[u[c],u[w]],[a[w],a[c]]=[a[c],a[w]]}e=Math.sqrt(e),n[i(w,w)]=e;for(let f=w+1;f<r;f++){let h=n[i(w,f)];for(let p=0;p<w;p++)h-=n[i(p,w)]*n[i(p,f)];n[i(w,f)]=h/e}}return{pivot:a,rank:r}}function no(l,s={}){let r=C(l),n=s.size??r.ncol;if(!Number.isInteger(n)||n<1)throw new RangeError(`size must be a positive integer (got ${n})`);if(n>r.ncol)throw new RangeError(`size cannot exceed the number of columns (${r.ncol})`);if(n>r.nrow)throw new RangeError(`size cannot exceed the number of rows (${r.nrow})`);let a=A(n,n);for(let i=0;i<n;i++)for(let t=0;t<=i;t++)a.data[t+i*n]=r.data[t+i*r.nrow];yt(a);for(let i=0;i<n;i++)for(let t=i+1;t<n;t++)a.data[t+i*n]=a.data[i+t*n];return $(a)}function yt(l){let s=l.nrow,r=l.data;for(let n=0;n<s;n++)if(r[n+n*s]===0)throw new Error(`element (${n+1}, ${n+1}) is zero, so the inverse cannot be computed`);for(let n=0;n<s;n++){let a=n*s;r[n+a]=1/r[n+a];let i=-r[n+a];for(let t=0;t<n;t++){let c=r[t+a];if(c!==0){for(let e=0;e<t;e++)r[e+a]+=c*r[e+t*s];r[t+a]=c*r[t+t*s]}}for(let t=0;t<n;t++)r[t+a]*=i}for(let n=0;n<s;n++){let a=r[n+n*s];if(n<s-1){let i=0;for(let t=n;t<s;t++)i+=r[n+t*s]*r[n+t*s];r[n+n*s]=i;for(let t=0;t<n;t++)r[t+n*s]*=a;for(let t=n+1;t<s;t++){let c=r[n+t*s];if(c!==0)for(let e=0;e<n;e++)r[e+n*s]+=c*r[e+t*s]}}else for(let i=0;i<=n;i++)r[i+n*s]*=a}}function so(l,s={}){let r=R(l);if(O(r),r.nrow===0)throw new RangeError("the matrix has zero dimension");for(let i of r.data)if(!Number.isFinite(i))throw new RangeError("the matrix contains NaN or infinite values");let n=s.symmetric??jt(r),a=!(s.onlyValues??!1);return n?kt(r,a):qt(r,a)}function jt(l){let s=l.nrow,r=0,n=0;for(let e=0;e<s;e++)for(let o=0;o<s;o++)r+=Math.abs(l.data[o+e*s]-l.data[e+o*s]),n+=Math.abs(l.data[o+e*s]);let a=100*Number.EPSILON,i=s*s,t=n/i,c=r/i;return(Number.isFinite(t)&&t>a?c/t:c)<=a}function kt(l,s){let r=l.nrow,n=A(r,r);for(let e=0;e<r;e++)for(let o=e;o<r;o++)n.data[o+e*r]=l.data[o+e*r],n.data[e+o*r]=l.data[o+e*r];let a=new Float64Array(r),i=new Float64Array(r);Nt(n,a,i),xt(n,a,i);let t=Array.from(a).reverse();if(!s)return{values:t};let c=A(r,r);for(let e=0;e<r;e++)c.data.set(n.data.subarray((r-1-e)*r,(r-e)*r),e*r);return{values:t,vectors:$(c)}}function Nt(l,s,r){let n=l.nrow,a=l.data,i=(t,c)=>t+c*n;for(let t=0;t<n;t++)s[t]=a[i(n-1,t)];for(let t=n-1;t>0;t--){let c=0,e=0;for(let o=0;o<t;o++)c+=Math.abs(s[o]);if(c===0){r[t]=s[t-1];for(let o=0;o<t;o++)s[o]=a[i(t-1,o)],a[i(t,o)]=0,a[i(o,t)]=0}else{for(let f=0;f<t;f++)s[f]/=c,e+=s[f]*s[f];let o=s[t-1],u=Math.sqrt(e);o>0&&(u=-u),r[t]=c*u,e-=o*u,s[t-1]=o-u;for(let f=0;f<t;f++)r[f]=0;for(let f=0;f<t;f++){o=s[f],a[i(f,t)]=o,u=r[f]+a[i(f,f)]*o;for(let h=f+1;h<=t-1;h++)u+=a[i(h,f)]*s[h],r[h]+=a[i(h,f)]*o;r[f]=u}o=0;for(let f=0;f<t;f++)r[f]/=e,o+=r[f]*s[f];let w=o/(e+e);for(let f=0;f<t;f++)r[f]-=w*s[f];for(let f=0;f<t;f++){o=s[f],u=r[f];for(let h=f;h<=t-1;h++)a[i(h,f)]-=o*r[h]+u*s[h];s[f]=a[i(t-1,f)],a[i(t,f)]=0}}s[t]=e}for(let t=0;t<n-1;t++){a[i(n-1,t)]=a[i(t,t)],a[i(t,t)]=1;let c=s[t+1];if(c!==0){for(let e=0;e<=t;e++)s[e]=a[i(e,t+1)]/c;for(let e=0;e<=t;e++){let o=0;for(let u=0;u<=t;u++)o+=a[i(u,t+1)]*a[i(u,e)];for(let u=0;u<=t;u++)a[i(u,e)]-=o*s[u]}}for(let e=0;e<=t;e++)a[i(e,t+1)]=0}for(let t=0;t<n;t++)s[t]=a[i(n-1,t)],a[i(n-1,t)]=0;a[i(n-1,n-1)]=1,r[0]=0}function xt(l,s,r){let n=l.nrow,a=l.data,i=(o,u)=>o+u*n;for(let o=1;o<n;o++)r[o-1]=r[o];r[n-1]=0;let t=0,c=0,e=Number.EPSILON;for(let o=0;o<n;o++){c=Math.max(c,Math.abs(s[o])+Math.abs(r[o]));let u=o;for(;u<n-1&&Math.abs(r[u])>e*c;)u++;if(u>o){let w=0;do{if(++w>100)throw new Error("the eigendecomposition did not converge");let f=s[o],h=(s[o+1]-f)/(2*r[o]),p=Math.hypot(h,1);h<0&&(p=-p),s[o]=r[o]/(h+p),s[o+1]=r[o]*(h+p);let d=s[o+1],v=f-s[o];for(let x=o+2;x<n;x++)s[x]-=v;t+=v,h=s[u];let m=1,b=m,N=m,j=r[o+1],y=0,q=0;for(let x=u-1;x>=o;x--){N=b,b=m,q=y,f=m*r[x],v=m*h,p=Math.hypot(h,r[x]),r[x+1]=y*p,y=r[x]/p,m=h/p,h=m*s[x]-y*f,s[x+1]=v+y*(m*f+y*s[x]);for(let F=0;F<n;F++)v=a[i(F,x+1)],a[i(F,x+1)]=y*a[i(F,x)]+m*v,a[i(F,x)]=m*a[i(F,x)]-y*v}h=-y*q*N*j*r[o]/d,r[o]=y*h,s[o]=m*h}while(Math.abs(r[o])>e*c)}s[o]=s[o]+t,r[o]=0}for(let o=0;o<n-1;o++){let u=o,w=s[o];for(let f=o+1;f<n;f++)s[f]<w&&(u=f,w=s[f]);if(u!==o){s[u]=s[o],s[o]=w;for(let f=0;f<n;f++){let h=a[i(f,o)];a[i(f,o)]=a[i(f,u)],a[i(f,u)]=h}}}}function qt(l,s){let r=l.nrow,n={nrow:r,ncol:r,data:l.data.slice()},a=A(r,r),i=new Float64Array(r),t=new Float64Array(r);Ft(n,a),At(n,a,i,t);let c=Array.from(i,(d,v)=>Math.hypot(d,t[v])),e=Array.from({length:r},(d,v)=>v).sort((d,v)=>c[v]-c[d]||d-v),o=t.some(d=>d!==0),u={values:e.map(d=>i[d])};if(o&&(u.valuesIm=e.map(d=>t[d])),!s)return u;let w=A(r,r),f=A(r,r);for(let d=0;d<r;d++){let v=a.data.subarray(d*r,(d+1)*r);if(t[d]===0)w.data.set(v,d*r);else if(t[d]>0){let m=a.data.subarray((d+1)*r,(d+2)*r);w.data.set(v,d*r),f.data.set(m,d*r),w.data.set(v,(d+1)*r);for(let b=0;b<r;b++)f.data[b+(d+1)*r]=-m[b]}}Et(w,f);let h=A(r,r),p=A(r,r);return e.forEach((d,v)=>{h.data.set(w.data.subarray(d*r,(d+1)*r),v*r),p.data.set(f.data.subarray(d*r,(d+1)*r),v*r)}),u.vectors=$(h),o&&(u.vectorsIm=$(p)),u}function Et(l,s){let r=l.nrow;for(let n=0;n<r;n++){let a=n*r,i=0,t=0,c=-1;for(let w=0;w<r;w++){let f=Math.hypot(l.data[a+w],s.data[a+w]);i+=f*f,f>c&&(c=f,t=w)}let e=Math.sqrt(i);if(e===0)continue;let o=l.data[a+t]/c/e,u=-s.data[a+t]/c/e;for(let w=0;w<r;w++){let f=l.data[a+w],h=s.data[a+w];l.data[a+w]=f*o-h*u,s.data[a+w]=f*u+h*o}s.data[a+t]=0}}function Ft(l,s){let r=l.nrow,n=l.data,a=s.data,i=(o,u)=>o+u*r,t=new Float64Array(r),c=0,e=r-1;for(let o=c+1;o<=e-1;o++){let u=0;for(let h=o;h<=e;h++)u+=Math.abs(n[i(h,o-1)]);if(u===0)continue;let w=0;for(let h=e;h>=o;h--)t[h]=n[i(h,o-1)]/u,w+=t[h]*t[h];let f=Math.sqrt(w);t[o]>0&&(f=-f),w-=t[o]*f,t[o]=t[o]-f;for(let h=o;h<r;h++){let p=0;for(let d=e;d>=o;d--)p+=t[d]*n[i(d,h)];p/=w;for(let d=o;d<=e;d++)n[i(d,h)]-=p*t[d]}for(let h=0;h<=e;h++){let p=0;for(let d=e;d>=o;d--)p+=t[d]*n[i(h,d)];p/=w;for(let d=o;d<=e;d++)n[i(h,d)]-=p*t[d]}t[o]=u*t[o],n[i(o,o-1)]=u*f}for(let o=0;o<r;o++)for(let u=0;u<r;u++)a[i(o,u)]=o===u?1:0;for(let o=e-1;o>=c+1;o--)if(n[i(o,o-1)]!==0){for(let u=o+1;u<=e;u++)t[u]=n[i(u,o-1)];for(let u=o;u<=e;u++){let w=0;for(let f=o;f<=e;f++)w+=t[f]*a[i(f,u)];w=w/t[o]/n[i(o,o-1)];for(let f=o;f<=e;f++)a[i(f,u)]+=w*t[f]}}}function G(l,s,r,n){if(Math.abs(r)>Math.abs(n)){let t=n/r,c=r+t*n;return[(l+t*s)/c,(s-t*l)/c]}let a=r/n,i=n+a*r;return[(a*l+s)/i,(a*s-l)/i]}function At(l,s,r,n,a=!1){let i=l.nrow,t=l.data,c=s.data,e=(E,M)=>E+M*i,o=i-1,u=0,w=i-1,f=Number.EPSILON,h=0,p=0,d=0,v=0,m=0,b=0,N,j,y,q,x=0;for(let E=0;E<i;E++)for(let M=Math.max(E-1,0);M<i;M++)x+=Math.abs(t[e(E,M)]);let F=0,z=0;for(;o>=u;){let E=o;for(;E>u&&(m=Math.abs(t[e(E-1,E-1)])+Math.abs(t[e(E,E)]),m===0&&(m=x),!(Math.abs(t[e(E,E-1)])<f*m));)E--;if(E===o)t[e(o,o)]=t[e(o,o)]+h,r[o]=t[e(o,o)],n[o]=0,o--,F=0;else if(E===o-1){if(j=t[e(o,o-1)]*t[e(o-1,o)],p=(t[e(o-1,o-1)]-t[e(o,o)])/2,d=p*p+j,b=Math.sqrt(Math.abs(d)),t[e(o,o)]=t[e(o,o)]+h,t[e(o-1,o-1)]=t[e(o-1,o-1)]+h,y=t[e(o,o)],d>=0){b=p>=0?p+b:p-b,r[o-1]=y+b,r[o]=r[o-1],b!==0&&(r[o]=y-j/b),n[o-1]=0,n[o]=0,y=t[e(o,o-1)],m=Math.abs(y)+Math.abs(b),p=y/m,d=b/m,v=Math.sqrt(p*p+d*d),p/=v,d/=v;for(let M=o-1;M<i;M++)b=t[e(o-1,M)],t[e(o-1,M)]=d*b+p*t[e(o,M)],t[e(o,M)]=d*t[e(o,M)]-p*b;for(let M=0;M<=o;M++)b=t[e(M,o-1)],t[e(M,o-1)]=d*b+p*t[e(M,o)],t[e(M,o)]=d*t[e(M,o)]-p*b;for(let M=u;M<=w;M++)b=c[e(M,o-1)],c[e(M,o-1)]=d*b+p*c[e(M,o)],c[e(M,o)]=d*c[e(M,o)]-p*b}else r[o-1]=y+p,r[o]=y+p,n[o-1]=b,n[o]=-b;o-=2,F=0}else{if(y=t[e(o,o)],q=0,j=0,E<o&&(q=t[e(o-1,o-1)],j=t[e(o,o-1)]*t[e(o-1,o)]),F===10){h+=y;for(let g=u;g<=o;g++)t[e(g,g)]-=y;m=Math.abs(t[e(o,o-1)])+Math.abs(t[e(o-1,o-2)]),y=q=.75*m,j=-.4375*m*m}if(F===30&&(m=(q-y)/2,m=m*m+j,m>0)){m=Math.sqrt(m),q<y&&(m=-m),m=y-j/((q-y)/2+m);for(let g=u;g<=o;g++)t[e(g,g)]-=m;h+=m,y=q=j=.964}if(F++,++z>100*i)throw new Error("the eigendecomposition did not converge");let M=o-2;for(;M>=E&&(b=t[e(M,M)],v=y-b,m=q-b,p=(v*m-j)/t[e(M+1,M)]+t[e(M,M+1)],d=t[e(M+1,M+1)]-b-v-m,v=t[e(M+2,M+1)],m=Math.abs(p)+Math.abs(d)+Math.abs(v),p/=m,d/=m,v/=m,!(M===E||Math.abs(t[e(M,M-1)])*(Math.abs(d)+Math.abs(v))<f*(Math.abs(p)*(Math.abs(t[e(M-1,M-1)])+Math.abs(b)+Math.abs(t[e(M+1,M+1)])))));)M--;for(let g=M+2;g<=o;g++)t[e(g,g-2)]=0,g>M+2&&(t[e(g,g-3)]=0);for(let g=M;g<=o-1;g++){let I=g!==o-1;if(g!==M){if(p=t[e(g,g-1)],d=t[e(g+1,g-1)],v=I?t[e(g+2,g-1)]:0,y=Math.abs(p)+Math.abs(d)+Math.abs(v),y===0)continue;p/=y,d/=y,v/=y}if(m=Math.sqrt(p*p+d*d+v*v),p<0&&(m=-m),m!==0){g!==M?t[e(g,g-1)]=-m*y:E!==M&&(t[e(g,g-1)]=-t[e(g,g-1)]),p+=m,y=p/m,q=d/m,b=v/m,d/=p,v/=p;for(let k=g;k<i;k++)p=t[e(g,k)]+d*t[e(g+1,k)],I&&(p+=v*t[e(g+2,k)],t[e(g+2,k)]=t[e(g+2,k)]-p*b),t[e(g,k)]=t[e(g,k)]-p*y,t[e(g+1,k)]=t[e(g+1,k)]-p*q;for(let k=0;k<=Math.min(o,g+3);k++)p=y*t[e(k,g)]+q*t[e(k,g+1)],I&&(p+=b*t[e(k,g+2)],t[e(k,g+2)]=t[e(k,g+2)]-p*v),t[e(k,g)]=t[e(k,g)]-p,t[e(k,g+1)]=t[e(k,g+1)]-p*d;for(let k=u;k<=w;k++)p=y*c[e(k,g)]+q*c[e(k,g+1)],I&&(p+=b*c[e(k,g+2)],c[e(k,g+2)]=c[e(k,g+2)]-p*v),c[e(k,g)]=c[e(k,g)]-p,c[e(k,g+1)]=c[e(k,g+1)]-p*d}}}}if(!(x===0||a)){for(o=i-1;o>=0;o--)if(p=r[o],d=n[o],d===0){let E=o;t[e(o,o)]=1;for(let M=o-1;M>=0;M--){j=t[e(M,M)]-p,v=0;for(let g=E;g<=o;g++)v+=t[e(M,g)]*t[e(g,o)];if(n[M]<0)b=j,m=v;else if(E=M,n[M]===0?t[e(M,o)]=j!==0?-v/j:-v/(f*x):(y=t[e(M,M+1)],q=t[e(M+1,M)],d=(r[M]-p)*(r[M]-p)+n[M]*n[M],N=(y*m-b*v)/d,t[e(M,o)]=N,t[e(M+1,o)]=Math.abs(y)>Math.abs(b)?(-v-j*N)/y:(-m-q*N)/b),N=Math.abs(t[e(M,o)]),f*N*N>1)for(let g=M;g<=o;g++)t[e(g,o)]=t[e(g,o)]/N}}else if(d<0){let E=o-1;Math.abs(t[e(o,o-1)])>Math.abs(t[e(o-1,o)])?(t[e(o-1,o-1)]=d/t[e(o,o-1)],t[e(o-1,o)]=-(t[e(o,o)]-p)/t[e(o,o-1)]):[t[e(o-1,o-1)],t[e(o-1,o)]]=G(0,-t[e(o-1,o)],t[e(o-1,o-1)]-p,d),t[e(o,o-1)]=0,t[e(o,o)]=1;for(let M=o-2;M>=0;M--){let g=0,I=0;for(let k=E;k<=o;k++)g+=t[e(M,k)]*t[e(k,o-1)],I+=t[e(M,k)]*t[e(k,o)];if(j=t[e(M,M)]-p,n[M]<0)b=j,v=g,m=I;else{if(E=M,n[M]===0)[t[e(M,o-1)],t[e(M,o)]]=G(-g,-I,j,d);else{y=t[e(M,M+1)],q=t[e(M+1,M)];let k=(r[M]-p)*(r[M]-p)+n[M]*n[M]-d*d,Z=(r[M]-p)*2*d;k===0&&Z===0&&(k=f*x*(Math.abs(j)+Math.abs(d)+Math.abs(y)+Math.abs(q)+Math.abs(b))),[t[e(M,o-1)],t[e(M,o)]]=G(y*v-b*g+d*I,y*m-b*I-d*g,k,Z),Math.abs(y)>Math.abs(b)+Math.abs(d)?(t[e(M+1,o-1)]=(-g-j*t[e(M,o-1)]+d*t[e(M,o)])/y,t[e(M+1,o)]=(-I-j*t[e(M,o)]-d*t[e(M,o-1)])/y):[t[e(M+1,o-1)],t[e(M+1,o)]]=G(-v-q*t[e(M,o-1)],-m-q*t[e(M,o)],b,d)}if(N=Math.max(Math.abs(t[e(M,o-1)]),Math.abs(t[e(M,o)])),f*N*N>1)for(let k=M;k<=o;k++)t[e(k,o-1)]=t[e(k,o-1)]/N,t[e(k,o)]=t[e(k,o)]/N}}}for(let E=i-1;E>=u;E--)for(let M=u;M<=w;M++){b=0;for(let g=u;g<=Math.min(E,w);g++)b+=c[e(M,g)]*t[e(g,E)];c[e(M,E)]=b}}}export{A as a,_ as b,R as c,C as d,$ as e,W as f,O as g,H as h,It as i,zt as j,ht as k,Ot as l,St as m,Lt as n,ot as o,_t as p,Ct as q,Wt as r,Bt as s,D as t,K as u,Kt as v,bt as w,Yt as x,Zt as y,ro as z,no as A,so as B,Ft as C,At as D};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! rStats.js 0.11.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{k as j,r as ae}from"./chunk-Y5CNQ266.js";import{b as V}from"./chunk-ALM3VHFP.js";import{a as ce,d as ue,f as ne,g as q,i as le}from"./chunk-Y5PYRAYP.js";import{g as T,h as Y}from"./chunk-JWBO5WVN.js";import{b as oe,c as ie,d as S,f as Z,g as O,i as K}from"./chunk-EZWBRCJL.js";var k=e=>new SyntaxError(`invalid formula: ${e}`);function Te(e){let t=[],r=0;for(;r<e.length;){let n=e[r];if(/\s/.test(n)){r++;continue}if(/[0-9]/.test(n)||n==="."&&/[0-9]/.test(e[r+1]??"")){let o=/^(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:[eE][+-]?[0-9]+)?/.exec(e.slice(r));t.push({kind:"num",text:o[0]}),r+=o[0].length;continue}if(/[A-Za-z.]/.test(n)){let o=/^[A-Za-z.][A-Za-z0-9._]*/.exec(e.slice(r));t.push({kind:"name",text:o[0]}),r+=o[0].length;continue}if(e.startsWith("%in%",r)){t.push({kind:"op",text:"%in%"}),r+=4;continue}if("~+-*/:^()".includes(n)){t.push({kind:"op",text:n}),r++;continue}throw k(`unexpected '${n}'`)}return t.push({kind:"end"}),t}var $e={"+":1,"-":1,"*":2,"/":2,"%in%":3,":":4,"^":6},De=5;function fe(e,t=!1){if(typeof e!="string")throw new TypeError("the formula must be a string");let r=Te(e),n=0,o=()=>r[n],s=()=>r[n++],i=(u,l)=>u.kind==="op"&&u.text===l;function c(){let u=s();if(u.kind==="name"){if(i(o(),"(")){if(u.text!=="Error"||!t)throw k(`function calls are not supported (${u.text})`);s();let l=a(0);if(!i(s(),")"))throw k("missing ')'");return{type:"Error",arg:l}}if(u.text===".")return{type:"dot"};if(/^\.[0-9]/.test(u.text))throw k(`unexpected '${u.text}'`);return{type:"var",name:u.text}}if(u.kind==="num")return{type:"num",value:Number(u.text),text:u.text};if(u.kind==="op"&&u.text==="("){let l=a(0);if(!i(s(),")"))throw k("missing ')'");return{type:"paren",arg:l}}if(u.kind==="op"&&(u.text==="-"||u.text==="+"))return{type:"unary",op:u.text,arg:a(De)};throw k(u.kind==="end"?"unexpected end of input":`unexpected '${u.kind==="op"?u.text:""}'`)}function a(u){let l=c();for(;;){let p=o();if(p.kind!=="op")break;let d=$e[p.text];if(d===void 0||d<=u)break;s();let b=a(p.text==="^"?d-1:d);l={type:"binary",op:p.text,left:l,right:b}}return l}let f;if(!i(o(),"~")){let u=s();if(u.kind!=="name"||u.text==="."||!i(o(),"~"))throw k("the response must be a variable name followed by '~'");f=u.text}s();let m=a(0);if(o().kind!=="end")throw k("unexpected input after the formula");return{response:f,rhs:m}}function We(e){let t=[],r=s=>{if(s.type==="Error"){t.push(s.arg);return}if(s.type==="binary"&&s.op==="+"){let i=r(s.left),c=r(s.right);return i===void 0?c:c===void 0?i:{...s,left:i,right:c}}if(s.type==="binary"&&s.op==="-"){let i=r(s.left);return i===void 0?{type:"unary",op:"-",arg:s.right}:{...s,left:i}}return s},n=r(e),o=s=>{if(s.type==="Error")throw k("Error() must be a term of the right-hand side");s.type==="binary"?(o(s.left),o(s.right)):(s.type==="unary"||s.type==="paren")&&o(s.arg)};return n!==void 0&&o(n),t.forEach(o),{treatment:n,errors:t}}function J(e,t,r){if(e!==void 0)switch(e.type){case"var":r.includes(e.name)||r.push(e.name);return;case"dot":for(let n of t)r.includes(n)||r.push(n);return;case"num":return;case"binary":J(e.left,t,r),e.op!=="^"&&J(e.right,t,r);return;case"unary":case"paren":case"Error":J(e.arg,t,r)}}var se=e=>e.join(",");function _(e){let t=new Set;return e.filter(r=>{let n=se(r);return t.has(n)?!1:(t.add(n),!0)})}var B=(e,t)=>[...new Set([...e,...t])].sort((r,n)=>r-n);function Le(e,t,r){let n=!0,o=(i,c)=>{switch(i.type){case"var":return[[t(i.name)]];case"dot":return r.map(a=>[t(a)]);case"num":if(i.value===1)n=!c;else if(i.value===0)n=c;else throw k(`a number (${i.text}) is not a term`);return[];case"paren":return o(i.arg,c);case"Error":throw k("Error() must be a term of the right-hand side");case"unary":return i.op==="+"?o(i.arg,c):(o(i.arg,!c),[]);case"binary":{if(i.op==="^"){let l=o(i.left,c),p=i.right;for(;p.type==="paren";)p=p.arg;let d=p.type==="num"?p.value:NaN;if(!Number.isInteger(d)||d<2)throw new Error("invalid power in formula");let b=l;for(let g=1;g<d;g++){let w=[];for(let x of l)for(let h of b)w.push(B(x,h));b=_(w)}return b}if(i.op==="-"){let l=o(i.left,c),p=new Set(o(i.right,!c).map(se));return l.filter(d=>!p.has(se(d)))}let a=o(i.left,c),f=o(i.right,c),m=()=>{let l=[];for(let p of a)for(let d of f)l.push(B(p,d));return l},u=l=>l.reduce((p,d)=>B(p,d),[]);switch(i.op){case"+":return _([...a,...f]);case":":return _(m());case"*":return _([...a,...f,...m()]);case"/":{let l=u(a);return _([...a,...f.map(p=>B(p,l))])}case"%in%":{let l=u(f);return _(a.map(p=>B(p,l)))}}}}throw k("unsupported expression")};return{terms:e===void 0?[]:o(e,!1),intercept:n}}function pe(e,t,r=e.rhs){let{response:n}=e,o=t.filter(l=>l!==n),s=n===void 0?[]:[n];J(e.rhs,o,s);let c=Le(r,l=>s.indexOf(l),o),a=c.terms.map((l,p)=>[l,p]).sort((l,p)=>l[0].length-p[0].length||l[1]-p[1]).map(([l])=>l),f=[],m=n===void 0?-1:a.findIndex(l=>l.length===1&&l[0]===0);m>=0&&(f.push("the response appeared on the right-hand side and was dropped"),f.push(`problem with term ${m+1} in model.matrix: no columns are assigned`));let u=s.map(()=>a.map(()=>0));return a.forEach((l,p)=>{for(let d of l){let b=l.filter(w=>w!==d),g=b.length===0||a.slice(0,p).some(w=>b.every(x=>w.includes(x)));u[d][p]=g?1:2}}),{variables:s,response:n===void 0?-1:0,terms:a,termLabels:a.map(l=>l.map(p=>s[p]).join(":")),order:a.map(l=>l.length),intercept:c.intercept,factors:u,responseTerm:m,warnings:f}}function He(e){return` with simulated p-value
|
|
3
|
+
(based on ${Q(e)} replicates)`}function Q(e){if(!Number.isFinite(e)||e===0)return String(e);let t=e.toExponential(14).replace(/\.?0+e/,"e"),[r,n]=t.split("e"),o=Number(n),s=`${r}e${o<0?"-":"+"}${String(Math.abs(o)).padStart(2,"0")}`,i=String(Number(e.toPrecision(15)));return i.length<=s.length?i:s}function U(e){if(e.kind==="factor")return{levels:e.levels,codes:e.codes};let t=[...new Set(e.values)].sort((o,s)=>o-s),r=[...new Set(t.map(Q))],n=new Map(r.map((o,s)=>[o,s]));return{levels:r,codes:e.values.map(o=>n.get(Q(o)))}}function A(e,t){if(e.kind!=="numeric")throw new TypeError(`'${t}' must be a numeric column`);return e.values}function $(e,t){let r=fe(e),n=pe(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 Fe=/^Pair\s*\(\s*([A-Za-z.][A-Za-z0-9._]*)\s*,\s*([A-Za-z.][A-Za-z0-9._]*)\s*\)$/,C="'formula' missing or incorrect",me=(e,t)=>t.length===0&&e.terms.length===0&&e.intercept;function Oe(e,t,r){let n=de(e),o=n===void 0?null:Fe.exec(n.lhs);if(o!==null){let{terms:u,rhsVariables:l}=$(`~${n.rhs}`,t);if(!r||!me(u,l))throw new Error(C);let p=V(t,[o[1],o[2]]);return{kind:"paired",x:A(p.variables[0],o[1]),y:A(p.variables[1],o[2])}}let{terms:s,rhsVariables:i}=$(e,t);if(s.response<0)throw new Error(C);let c=s.variables[0];if(r&&me(s,i))return{kind:"one",x:A(V(t,[c]).variables[0],c)};if(i.length!==1||s.terms.length!==1)throw new Error(C);let a=V(t,[c,i[0]],{dropUnusedLevels:!0}),f=A(a.variables[0],c),m=U(a.variables[1]);if(m.levels.length!==2)throw new Error("grouping factor must have exactly 2 levels");return{kind:"two",x:f.filter((u,l)=>m.codes[l]===0),y:f.filter((u,l)=>m.codes[l]===1),levels:[m.levels[0],m.levels[1]]}}function Xe(e,t){let r=Oe(e,t,!1);if(r.kind!=="two")throw new Error(C);return r}function et(e,t){let{terms:r,rhsVariables:n}=$(e,t);if(r.response<0)throw new Error(C);if(n.length!==1)throw new Error("'formula' should be of the form response ~ group");let o=r.variables[0],s=V(t,[o,n[0]],{dropUnusedLevels:!0});return{values:A(s.variables[0],o),group:U(s.variables[1])}}function tt(e,t){let r=t.levels.map(()=>[]);return e.forEach((n,o)=>r[t.codes[o]].push(n)),r}function rt(e,t){let{terms:r,rhsVariables:n}=$(e,t);if(r.response<0||n.length===0)throw new Error(C);let o=r.variables[0],s=V(t,[o,...n],{dropUnusedLevels:!0}),i=s.variables.slice(1).map(U),c=s.rows.map((a,f)=>{let m=0,u=1;for(let l of i)m+=l.codes[f]*u,u*=l.levels.length;return m});return{values:A(s.variables[0],o),groups:c}}var he="incorrect specification for 'formula'";function nt(e,t){let r=de(e),n=r?.rhs.split("|");if(r===void 0||r.lhs===""||n.length!==2)throw new Error(he);let o=b=>{let{terms:g,rhsVariables:w}=$(b,t);if(w.length!==1||g.terms.length!==1)throw new Error(he);return w[0]},{terms:s}=$(`${r.lhs} ~ 1`,t),i=s.variables[0],c=o(`~${n[0]}`),a=o(`~${n[1]}`),f=V(t,[i,c,a],{dropUnusedLevels:!0}),m=A(f.variables[0],i),u=U(f.variables[1]),l=U(f.variables[2]),p=l.levels.map(()=>u.levels.map(()=>NaN)),d=l.levels.map(()=>u.levels.map(()=>0));if(m.forEach((b,g)=>{let w=l.codes[g],x=u.codes[g];d[w][x]++,p[w][x]=b}),d.some(b=>b.some(g=>g!==1)))throw new Error("not an unreplicated complete block design");return p}function we(e,t){let{terms:r,rhsVariables:n}=$(e,t);if(r.response>=0)throw new Error("'formula' missing or invalid");if(n.length!==2)throw new Error("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 be(e){if(!(Number.isFinite(e)&&e>=0&&e<=1))throw new RangeError("confLevel must be a number between 0 and 1")}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 _e=["pearson","kendall","spearman"];function Ce(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 xe(e){if(!(e[0]>0))return[Math.sqrt(e[0]),0];let t=Math.sqrt(e[0]),r=Z(e,ie(t,t));return oe(t,r[0]/(2*t))}function Ne(e){let t=ce(e);if(!Number.isFinite(t[0]))return;let r=e.map(s=>Z([s,0],t)),n=0;for(let s of r)n=Math.max(n,Math.abs(s[0]));if(n===0)return r;let o=2**-Math.max(-1022,Math.floor(Math.log2(n)));return r.map(s=>[s[0]*o,s[1]*o])}function X(e,t){let r=e.length;if(r<2)return[NaN,0];let n=Ne(e),o=Ne(t);if(n===void 0||o===void 0)return[NaN,0];let s=[0,0],i=[0,0],c=[0,0];for(let f=0;f<r;f++)s=S(s,O(n[f],o[f])),i=S(i,O(n[f],n[f])),c=S(c,O(o[f],o[f]));if(i[0]===0||c[0]===0)return[NaN,0];let a=K(s,O(xe(i),xe(c)));return a[0]>=1?[1,0]:a[0]<=-1?[-1,0]:a}function ve(e,t){let r=O(Z([1,0],e),S([1,0],e));return Math.sqrt(t)*e[0]/Math.sqrt(r[0])}function Pe(e){return Math.abs(e[0])<.5?Math.atanh(e[0]):.5*Math.log(S([1,0],e)[0]/Z([1,0],e)[0])}function ye(e,t,r){return r==="less"?j(e,t,!0,!1):r==="greater"?j(e,t,!1,!1):2*Math.min(j(e,t,!0,!1),j(e,t,!1,!1))}function ze(e,t){return t==="less"?T(e):t==="greater"?T(e,{lowerTail:!1}):2*Math.min(T(e),T(e,{lowerTail:!1}))}function ee(e,t){let r=e.length,n=0;for(let m=0;m<r;m++){let u=e[m],l=t[m];for(let p=m+1;p<r;p++){let d=(e[p]>u?1:0)-(e[p]<u?1:0),b=(t[p]>l?1:0)-(t[p]<l?1:0);n+=d*b}}let o=q(e),s=q(t),i=r*(r-1)/2,c=o.reduce((m,u)=>m+u*(u-1)/2,0),a=s.reduce((m,u)=>m+u*(u-1)/2,0),f=r<2||c===i||a===i?NaN:c===0&&a===0?n/i:n/Math.sqrt((i-c)*(i-a));return{s:n,tau:f,ties:o.length>0||s.length>0,tx:o,ty:s}}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 s=2;s<=e;s++){let i=new Float64Array(t+1),c=0;for(let f=0;f<=t;f++)c+=n[f],i[f]=c;let a=new Float64Array(t+1);for(let f=0;f<=t;f++)a[f]=(i[f]-(f>=s?i[f-s]:0))/s;n=a}let o=0;for(let s=t;s>=0;s--)o+=n[s];return Math.min(1,o)}var Ee=new Map;function Ie(e){let t=Ee.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 s=c=>{let a=0;for(;c;c&=c-1)a++;return a};for(let c=0;c<n;c++){let a=o[c];if(a===void 0)continue;let f=s(c);for(let m=0;m<e;m++){if(c&1<<m)continue;let u=(m-f)**2,l=c|1<<m,p=o[l]??=new Float64Array(r+1);for(let d=0;d+u<=r;d++)a[d]&&(p[d+u]+=a[d])}c!==n-1&&(o[c]=void 0)}let i=o[n-1];return Ee.set(e,i),i}var E=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function Me(e,t,r){let n=t;n%2!==0&&(n+=1);let o=1/e,s=(6*(n-1)*o/(e*e-1)-1)*Math.sqrt(1/o-1),i=s*s,a=s*o*(E[0]+o*(E[1]+E[2]*o)+i*(-E[3]+o*(E[4]+E[5]*o)-i*o*(E[6]+E[7]*o-i*(E[8]-E[9]*o+i*o*(E[10]-E[11]*i)))))/Math.exp(i/2),f=r?T(s)-a:a+T(s,{lowerTail:!1});return Math.min(1,Math.max(0,f))}function Ae(e,t,r){let n=e*(e*e-1)/3;if(e<=9){let o=Ie(e),s=1;for(let c=2;c<=e;c++)s*=c;let i=0;if(r)for(let c=Math.min(t,n);c>=0;c--)i+=o[c];else for(let c=n;c>=Math.max(t,0);c--)i+=o[c];return i/s}return r?t+1>n?1:t+1<=0?0:Me(e,t+1,!0):t<=0?1:t>n?0:Me(e,t,!1)}function Ze(e,t,r={}){if(typeof e=="string"){let n=we(e,t);return Ze(n.x,n.y,r)}return je(e,t,r)}function je(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=Ce(r.method),s=r.continuity??!1,[i,c]=le(Array.from(e),Array.from(t)),a=i.length;if(o==="pearson"){let h=r.confLevel??.95;if(be(h),a<3)throw new Error("not enough finite observations");let y=X(i,c),M=a-2,N=Number.isNaN(y[0])?NaN:ve(y,M),D={method:"Pearson's product-moment correlation",alternative:n,statistic:N,statisticName:"t",parameter:M,parameterName:"df",pValue:ye(N,M,n),estimate:y[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation"};if(a>3){let W=Pe(y),L=1/Math.sqrt(a-3),F=R=>Math.tanh(W+R),z;if(n==="less")z=[-1,F(L*Y(h))];else if(n==="greater")z=[F(-L*Y(h)),1];else{let R=L*Y((1+h)/2);z=[F(-R),F(R)]}D.confInt=z,D.confLevel=h}return D}if(a<2)throw new Error("not enough finite observations");if(o==="kendall"){let h=ee(i,c),y={method:"Kendall's rank correlation tau",alternative:n,estimate:h.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau"};if(Number.isNaN(h.tau))return{...y,statistic:NaN,statisticName:"T",pValue:NaN};if((r.exact??a<50)&&!h.ties){let v=a*(a-1)/2,I=(h.s+v)/2,G=ke(a,I),H=ke(a,v-I),Re=n==="less"?G:n==="greater"?H:Math.min(1,2*Math.min(G,H));return{...y,statistic:I,statisticName:"T",pValue:Re}}let N=(v,I)=>I.reduce((G,H)=>G+v(H),0),D=v=>v*(v-1),W=v=>v*(v-1)*(v-2),L=v=>v*(v-1)*(2*v+5),F=(a*(a-1)*(2*a+5)-N(L,h.tx)-N(L,h.ty))/18+N(W,h.tx)*N(W,h.ty)/(9*a*(a-1)*(a-2))+N(D,h.tx)*N(D,h.ty)/(2*a*(a-1)),R=(s?Math.sign(h.s)*(Math.abs(h.s)-1):h.s)/Math.sqrt(F);return{...y,statistic:R,statisticName:"z",pValue:ze(R,n)}}let f=ne(i),m=ne(c),u=X(f,m),l=a*a*a-a,p=l*(1-u[0])/6,d={method:"Spearman's rank correlation rho",alternative:n,statistic:p,statisticName:"S",estimate:u[0],estimateNames:"rho",nullValue:0,nullValueName:"rho"};if(Number.isNaN(u[0]))return{...d,pValue:NaN};let b=q(i).length>0||q(c).length>0;if((r.exact??a<=1290)&&!b&&a<=1290){let h=Math.round(p),y=Ae(a,h,!0),M=Ae(a,h,!1),N=n==="greater"?y:n==="less"?M:Math.min(1,2*Math.min(y,M));return{...d,pValue:N}}let w=u;if(s){let h=K([6,0],[l,0]);w=K(S(u,h),S([1,0],h)),Math.abs(w[0])>=1&&(w=[Math.sign(w[0]),0])}let x=ve(w,a-2);return{...d,pValue:ye(x,a-2,n)}}function qe(e,t){let r=e.length,n=new Array(r);if(t==="first"||t==="last"||t==="random"){let i=t==="random"?ae(r):[],c=Array.from({length:r},(a,f)=>f);return c.sort((a,f)=>{let m=e[a]-e[f];return m!==0?m:t==="first"?a-f:t==="last"?f-a:i[a]-i[f]||a-f}),c.forEach((a,f)=>n[a]=f+1),n}let o=Array.from({length:r},(i,c)=>c).sort((i,c)=>e[i]-e[c]||i-c),s=0;for(;s<r;){let i=s;for(;i+1<r&&e[o[i+1]]===e[o[s]];)i++;let c=t==="average"?(s+i+2)/2:t==="min"?s+1:i+1;for(let a=s;a<=i;a++)n[o[a]]=c;s=i+1}return n}function te(e,t={}){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",o=Array.from(e),s=o.filter(u=>!Number.isNaN(u)),i=qe(s,r),c=o.length-s.length,a=[],f=0,m=0;for(let u of o)Number.isNaN(u)?(m++,a.push(n==="keep"?NaN:n==="last"?s.length+m:m)):a.push(n==="first"?i[f++]+c:i[f++]);return a}var Be=["pearson","kendall","spearman"],Ue=["all.obs","complete.obs","pairwise.complete.obs","everything","na.or.complete"];function Se(e,t,r,n){if(e===void 0)return r;if(t.includes(e))return e;let o=t.filter(s=>s.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 Ve(e){if(!P(e))return[Array.from(e)];let t=e[0].length;return Array.from({length:t},(r,n)=>e.map(o=>o[n]))}function re(e,t,r,n){let o=Se(r.method,Be,"pearson","method"),s=Se(r.use,Ue,"everything","use");if(t===void 0&&!P(e))throw new TypeError("supply both 'x' and 'y' or a matrix-like 'x'");let i=Ve(e),c=t===void 0?i:Ve(t),a=i[0]?.length??0;if(c.some(g=>g.length!==a))throw new RangeError("incompatible dimensions");let f=[...i,...c];if(s==="all.obs"&&f.some(g=>g.some(Number.isNaN)))throw new RangeError("missing observations in cov/cor");if(!n&&s==="pairwise.complete.obs"&&o!=="pearson")throw new RangeError("cannot handle 'pairwise.complete.obs'");let m;if((s==="complete.obs"||s==="na.or.complete")&&(m=Array.from({length:a},(g,w)=>f.every(x=>!Number.isNaN(x[w]))),!m.some(Boolean))){if(s==="complete.obs")throw new RangeError("no complete element pairs");return t===void 0||P(e)||P(t)?i.map(()=>c.map(()=>NaN)):NaN}let u=g=>{let w=m===void 0?g:g.filter((x,h)=>m[h]);return o==="spearman"&&s!=="pairwise.complete.obs"?te(w,{naLast:"keep"}):w},l=i.map(u),p=t===void 0?l:c.map(u),d=(g,w)=>{let x=g,h=w;if(s==="pairwise.complete.obs"){let y=g.map((M,N)=>!Number.isNaN(M)&&!Number.isNaN(w[N]));x=g.filter((M,N)=>y[N]),h=w.filter((M,N)=>y[N]),o==="spearman"&&(x=te(x),h=te(h))}else if(x.some(Number.isNaN)||h.some(Number.isNaN))return NaN;return o==="kendall"?n?ee(x,h).tau:2*ee(x,h).s:n?X(x,h)[0]:ue(x,h)},b=l.map(g=>p.map(w=>d(g,w)));return n&&t===void 0&&s!=="pairwise.complete.obs"&&b.forEach((g,w)=>g[w]=1),t!==void 0&&!P(e)&&!P(t)?b[0][0]:b}function xt(e,t,r={}){return t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?re(e,void 0,t,!1):re(e,t,r,!1)}function Nt(e,t,r={}){return t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?re(e,void 0,t,!0):re(e,t,r,!0)}export{fe as a,We as b,pe as c,He as d,Q as e,Oe as f,Xe as g,et as h,tt as i,rt as j,nt as k,ge as l,be as m,ot as n,X as o,Ze as p,te as q,xt as r,Nt as s};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.11.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
|
+
function b(i,f){let r=i[Symbol.iterator](),u=f[Symbol.iterator]();for(;;){let t=r.next(),o=u.next();if(t.done)return o.done?0:-1;if(o.done)return 1;let a=t.value.codePointAt(0)-o.value.codePointAt(0);if(a!==0)return a}}function y(i,f,r){if(f instanceof Float64Array&&r===void 0){let e=Array.from(f);return{v:{kind:"numeric",values:e},missing:e.map(n=>Number.isNaN(n))}}let u=Array.from(f),t=new Set(u.filter(e=>e!==null).map(e=>typeof e));if(t.size>1)throw new TypeError(`column '${i}' mixes ${[...t].join(" and ")} values`);let o=[...t][0]??"number";if(o!=="number"&&o!=="string"&&o!=="boolean")throw new TypeError(`column '${i}' has values of an unsupported type`);if(o==="number"&&r===void 0){let e=u.map(n=>n===null?NaN:n);return{v:{kind:"numeric",values:e},missing:e.map(n=>Number.isNaN(n))}}let a=e=>e===null||typeof e=="number"&&Number.isNaN(e)?null:typeof e=="boolean"?e?"TRUE":"FALSE":String(e),l=u.map(a),s;r!==void 0?s=Array.from(r,String):o==="boolean"?s=["FALSE","TRUE"]:s=[...new Set(l.filter(e=>e!==null))].sort(b);let p=new Map(s.map((e,n)=>[e,n])),m=l.map(e=>e===null?-1:p.get(e)??-1);return{v:{kind:"factor",levels:s,codes:m},missing:m.map(e=>e<0)}}function N(i,f,r={}){if(typeof i!="object"||i===null)throw new TypeError("data must be an object of columns");let u=f.map(e=>{let n=Object.prototype.hasOwnProperty.call(i,e)?i[e]:void 0;if(n===void 0)throw new Error(`object '${e}' not found`);if(!Array.isArray(n)&&!(n instanceof Float64Array))throw new TypeError(`column '${e}' must be an array`);return n}),t;if(typeof r.weights=="string"){let e=Object.prototype.hasOwnProperty.call(i,r.weights)?i[r.weights]:void 0;if(e===void 0)throw new Error(`object '${r.weights}' not found`);t=e}else r.weights!==void 0&&(t=Array.from(r.weights));let o=u.length>0?u[0].length:t?.length??Object.values(i)[0]?.length??0;if(f.forEach((e,n)=>{if(u[n].length!==o)throw new RangeError(`variable lengths differ (found for '${e}')`)}),t!==void 0&&t.length!==o)throw new RangeError("variable lengths differ (found for '(weights)')");let a=f.map((e,n)=>y(e,u[n],r.levels?.[e])),l;t!==void 0&&(l=Array.from(t,e=>{if(e===null)return NaN;if(typeof e!="number")throw new TypeError("the weights must be numeric");return e}));let s=[];for(let e=0;e<o;e++)a.some(n=>n.missing[e])||l!==void 0&&Number.isNaN(l[e])||s.push(e);let p=a.map(({v:e})=>{if(e.kind==="numeric")return{kind:"numeric",values:s.map(c=>e.values[c])};let n=s.map(c=>e.codes[c]),d=e.levels;if(r.dropUnusedLevels){let c=d.map(()=>!1);for(let w of n)c[w]=!0;let h=new Map;d=d.filter((w,g)=>(c[g]&&h.set(g,h.size),c[g])),n=n.map(w=>h.get(w))}return{kind:"factor",levels:d,codes:n}}),m={rows:s,variables:p};if(l!==void 0&&(m.weights=s.map(e=>l[e]),m.weights.some(e=>e<0)))throw new RangeError("missing or negative weights not allowed");return m}export{b as a,N as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
1
|
+
/*! rStats.js 0.11.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
|
function h(f,t,a){let n=Math.ceil(a);if(n===1)return[f];let i=(t-f)/(n-1),o=Array.from({length:n},(s,r)=>f+r*i);return n>0&&(o[n-1]=t),o}function g(f,t){let a=Array.from(f).map(o=>Math.trunc(o)),n=t??Math.max(1,...a.filter(o=>!Number.isNaN(o))),i=new Array(Math.max(0,n)).fill(0);for(let o of a)o>=1&&o<=n&&i[o-1]++;return i}function y(f,t={}){let a=t.useNA??"no",n=Array.from(f),i=new Map,o=0;for(let e of n)Number.isNaN(e)?o++:i.set(e===0?0:e,(i.get(e===0?0:e)??0)+1);let s=Array.from(i.keys()).sort((e,l)=>e-l),r=s.map(e=>i.get(e));return(a==="always"||a==="ifany"&&o>0)&&(s.push(NaN),r.push(o)),{values:s,counts:r}}function b(f){let t=new Set,a=[];for(let n of Array.from(f)){let i=n===0?0:n;t.has(i)||(t.add(i),a.push(n))}return a}function x(f,t,a={}){let n=a.right??!0,i=a.includeLowest??!1,o=Array.from(f),s;if(typeof t=="number"||t.length===1){let r=typeof t=="number"?t:t[0];if(!(r>=2))throw new RangeError("invalid number of intervals");let e=Math.trunc(r+1),l=o.filter(N=>!Number.isNaN(N)),u=Math.min(...l),c=Math.max(...l),m=c-u;m===0?(m=u!==0?Math.abs(u):1,s=h(u-m/1e3,c+m/1e3,e)):(s=h(u,c,e),s[0]=u-m/1e3,s[e-1]=c+m/1e3)}else s=[...t].sort((r,e)=>r-e);if(new Set(s).size<s.length)throw new RangeError("'breaks' are not unique");return d(o,s,n,i)}function d(f,t,a,n){let i=t.length;return f.map(o=>{if(Number.isNaN(o))return NaN;let s=0,r=i;for(;s<r;){let l=s+r>>1;(a?t[l]<o:t[l]<=o)?s=l+1:r=l}let e=s;return n&&(a&&o===t[0]&&(e=1),!a&&o===t[i-1]&&(e=i-1)),e>=1&&e<=i-1?e:NaN})}function A(f,t,a={}){let n=t.length;for(let r=1;r<n;r++)if(!(t[r]>=t[r-1]))throw new RangeError("'vec' must be sorted non-decreasingly and not contain NAs");if(t.some(Number.isNaN))throw new RangeError("'vec' must be sorted non-decreasingly and not contain NAs");let{rightmostClosed:i=!1,allInside:o=!1,leftOpen:s=!1}=a;return Array.from(f).map(r=>{if(Number.isNaN(r))return NaN;let e=0,l=n;for(;e<l;){let c=e+l>>1;(s?t[c]<r:t[c]<=r)?e=c+1:l=c}let u=e;return i&&n>0&&(!s&&u===n&&r===t[n-1]&&(u=n-1),s&&u===0&&r===t[0]&&(u=1)),o&&(u=Math.min(Math.max(u,1),n-1)),u})}export{h as a,g as b,y as c,b as d,x as e,A as f};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.11.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 D}from"./chunk-ALM3VHFP.js";import{a as k,b,c as F}from"./chunk-Y5PYRAYP.js";import{d as X,g as I}from"./chunk-EZWBRCJL.js";function j(n){let o=Object.values(n),t=o[0]?.length??0;if(o.some(r=>r.length!==t))throw new RangeError("the columns of a data frame must have the same length");return t}var Y=n=>n==null||typeof n=="number"&&Number.isNaN(n),M=(n,o)=>n[o];function _(n,o){if(n.length>0&&n.every(t=>t instanceof Float64Array)){let t=new Float64Array(o.length);return o.forEach((r,e)=>t[e]=r===null?NaN:r[0][r[1]]),t}return o.map(t=>t===null?null:M(t[0],t[1]))}function ft(n,o){return n instanceof Float64Array?Float64Array.from(o,t=>n[t]):o.map(t=>M(n,t))}function O(n,o,t){if(Object.hasOwn(n,o))throw new Error(`duplicate column name '${o}'`);n[o]=t}function ut(n){if(Number.isNaN(n))return"NA";if(!Number.isFinite(n))return n>0?"Inf":"-Inf";if(n===0)return"0";let[o,t]=Number(n.toPrecision(15)).toExponential().split("e"),r=o.startsWith("-"),e=o.replace("-","").replace(".",""),s=Number(t),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 K(n){return Y(n)?"NA":typeof n=="number"?ut(n):typeof n=="boolean"?n?"TRUE":"FALSE":n}var it=Symbol("NA"),U=n=>typeof n=="number"?0:typeof n=="string"?1:2;function at(n,o){let t=Y(n),r=Y(o);if(t||r)return t===r?0:t?1:-1;let e=n,s=o;return typeof e!=typeof s?U(e)-U(s):typeof e=="string"?D(e,s):Number(e)-Number(s)}function lt(n){let o=n.length,t=[...n],r=n.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=t[s],u=r[s],f=s;for(;f>=e&&t[f-e]>c;)t[f]=t[f-e],r[f]=r[f-e],f-=e;t[f]=c,r[f]=u}return r}function B(n){let o=[],t=new Map;for(let r of lt(n)){let e=n[r];if(e===0)o.push(r);else{let s=t.get(e);s===void 0?t.set(e,[r]):s.push(r)}}return{alone:o,groups:t}}var T=n=>typeof n=="string"?[n]:[...n];function H(n,o){return o.map(t=>{if(!Object.hasOwn(n,t))throw new Error("'by' must specify a uniquely valid column");return n[t]})}function pt(n,o,t={}){let r=Object.keys(n),e=Object.keys(o),s=j(n),c=j(o),u=t.by===void 0?r.filter(i=>e.includes(i)):T(t.by),f=t.byX===void 0?u:T(t.byX),a=t.byY===void 0?u:T(t.byY),l=H(n,f),w=H(o,a);if(f.length!==a.length)throw new Error("'by.x' and 'by.y' specify different numbers of columns");let R=t.allX??t.all??!1,v=t.allY??t.all??!1,tt=t.sort??!0,[nt,et]=t.suffixes??[".x",".y"],L=r.filter(i=>!f.includes(i)),V=e.filter(i=>!a.includes(i)),rt=i=>V.includes(i)?i+nt:i,ot=i=>L.includes(i)||f.includes(i)?i+et: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,y)=>{let E=M(p[0],y);return Y(E)?it:E}:(p,y)=>p.map(E=>K(M(E,y))).join("\r"),m=Array.from({length:s},(p,y)=>i(l,y)),h=Array.from({length:c},(p,y)=>i(w,y)),d=new Set(h),g=new Map,A=0;for(let p of m)d.has(p)&&(A++,g.has(p)||g.set(p,A));let z=B(m.map(p=>g.get(p)??0)),G=B(h.map(p=>g.get(p)??0));for(let[p,y]of z.groups){let E=G.groups.get(p)??[];for(let st of y)for(let ct of E)x.push([st,ct])}if(R)for(let p of z.alone)x.push([p,-1]);if(v)for(let p of G.alone)x.push([-1,p])}let S=x.map((i,m)=>m);if(tt&&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&&!v){let m=x.map((h,d)=>f.map((g,A)=>K(i(d,A))).join("\r"));S.sort((h,d)=>D(m[h],m[d]))}else S.sort((m,h)=>{for(let d=0;d<f.length;d++){let g=at(i(m,d),i(h,d));if(g!==0)return g}return 0})}let q=S.map(i=>x[i]),$={};f.forEach((i,m)=>{let h=l[m],d=w[m];O($,i,_([h,d],q.map(([g,A])=>g>=0?[h,g]:[d,A])))});for(let i of L){let m=n[i];O($,rt(i),_([m],q.map(([h])=>h>=0?[m,h]:null)))}for(let i of V){let m=o[i];O($,ot(i),_([m],q.map(([,h])=>h>=0?[m,h]:null)))}return $}function dt(n,o,t={}){let r=Object.keys(n),e=j(n);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(n[l],a)])),c=[];for(let a=0;a<e;a++)(typeof o=="function"?o(s(a)):o[a])===!0&&c.push(a);let u=t.select??r,f={};for(let a of u){if(!Object.hasOwn(n,a))throw new Error("undefined columns selected");O(f,a,ft(n[a],c))}return f}function gt(n){if(n.length===0)return{};let o=Object.keys(n[0]);for(let r of n)if(j(r),Object.keys(r).length!==o.length||!o.every(s=>Object.hasOwn(r,s)))throw new Error("names do not match previous names");let t={};for(let r of o){let e=n.map(c=>c[r]),s=e.flatMap(c=>Array.from({length:c.length},(u,f)=>[c,f]));t[r]=_(e,s)}return t}function Nt(n){let o={},t=n.map(j),r=t.find(e=>e!==t[0]);if(r!==void 0)throw new RangeError(`arguments imply differing number of rows: ${t[0]}, ${r}`);for(let e of n)for(let[s,c]of Object.entries(e))O(o,s,c instanceof Float64Array?Float64Array.from(c):[...c]);return o}function yt(n,o={}){let t=o.columns;if(t===void 0){let e=new Set;for(let s of n)for(let c of Object.keys(s))e.add(c);t=[...e]}let r={};for(let e of t){let s=new Set,c=n.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`);O(r,e,c)}return r}function bt(n){let o=Object.keys(n),t=j(n);return Array.from({length:t},(r,e)=>Object.fromEntries(o.map(s=>[s,M(n[s],e)])))}function N(n,o){let t=Array.from(n);return o?t.filter(r=>!Number.isNaN(r)):t.some(Number.isNaN)?void 0:t}function C(n){if(!n.every(Number.isFinite))return n.reduce((t,r)=>t+r,0);let o=[0,0];for(let t of n)o=X(o,[t,0]);return o[0]+o[1]}function vt(n,o={}){let t=N(n,o.naRm);return t===void 0?NaN:C(t)}function At(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;if(!t.every(Number.isFinite)||t.includes(0))return t.reduce((s,c)=>s*c,1);let r=[1,0],e=0;for(let s of t){r=I(r,[s,0]);let c=Math.floor(Math.log2(Math.abs(r[0])));if(c>500||c<-500){let u=2**-c;r=[r[0]*u,r[1]*u],e+=c}}return P(r,e)}function Et(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;let r=t.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 W(t);e=Math.max(e,0);let s=Math.floor(r*e),c=[...t].sort((u,f)=>u-f);return b(c.slice(s,r-s))}return b(t)}function Ot(n,o,t={}){let r=Array.from(n),e=Array.from(o);if(r.length!==e.length)throw new RangeError("'x' and 'w' must have the same length");if(t.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 C(s)/C(e)}function mt(n,o={}){let t=N(n,o.naRm);return t===void 0?NaN:F(t)}function jt(n,o={}){return Math.sqrt(mt(n,o))}function W(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;let r=t.length;if(r===0)return NaN;let e=[...t].sort((c,u)=>c-u),s=Math.floor(r/2);return r%2===1?e[s]:k([e[s-1],e[s]])[0]}function Rt(n,o={}){let t=N(n,o.naRm);if(t===void 0)return[NaN,NaN];let r=1/0,e=-1/0;for(let s of t)s<r&&(r=s),s>e&&(e=s);return[r,e]}function $t(n){let o=[],t=[0,0],r=0,e=!0;for(let s of Array.from(n))r+=s,e&&Number.isFinite(s)?(t=X(t,[s,0]),o.push(t[0]+t[1])):(e=!1,o.push(Number.isNaN(s)||Number.isNaN(r)?NaN:r));return o}function kt(n){let o=[],t=[1,0],r=0,e;for(let s of Array.from(n)){if(e===void 0&&(!Number.isFinite(s)||s===0)&&(e=P(t,r)),e!==void 0){e*=s,o.push(e);continue}t=I(t,[s,0]);let c=Math.floor(Math.log2(Math.abs(t[0])));(c>500||c<-500)&&(t=[t[0]*2**-c,t[1]*2**-c],r+=c),o.push(P(t,r))}return o}function P(n,o){let t=n[0]+n[1];for(;o>0&&Number.isFinite(t);){let r=Math.min(o,1e3);t*=2**r,o-=r}for(;o<0&&t!==0;){let r=Math.max(o,-1e3);t*=2**r,o-=r}return t}function J(n,o){let t=[],r=NaN,e=!1;for(let s of Array.from(n)){if(e||Number.isNaN(s)){e=!0,t.push(NaN);continue}(t.length===0||o(s,r))&&(r=s),t.push(r)}return t}function Ft(n){return J(n,(o,t)=>o>t)}function _t(n){return J(n,(o,t)=>o<t)}function Yt(n,o={}){let t=o.lag??1,r=o.differences??1;if(!(Number.isInteger(t)&&t>=1&&Number.isInteger(r)&&r>=1))throw new RangeError("'lag' and 'differences' must be integers >= 1");let e=Array.from(n);if(t*r>=e.length)return[];for(let s=0;s<r;s++){let c=[];for(let u=t;u<e.length;u++)c.push(e[u]-e[u-t]);e=c}return e}function Q(n){let o=k(n),t=0,r=0,e=0;for(let s of n){let c=s-o[0]-o[1],u=c*c;t+=u,r+=u*c,e+=u*u}return[t,r,e]}function Z(n){if(![1,2,3].includes(n))throw new RangeError("Invalid 'type' argument.")}function Dt(n,o={}){let t=o.type??3;Z(t);let r=N(n,!0),e=r.length,[s,c]=Q(r),u=Math.sqrt(e)*c/s**1.5;if(t===1)return u;if(t===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 Tt(n,o={}){let t=o.type??3;Z(t);let r=N(n,!0),e=r.length,[s,,c]=Q(r),u=e*c/(s*s);if(t===1)return u-3;if(t===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 Ct(n,o={}){let t=N(n,o.naRm);return t===void 0?NaN:t.some(r=>r<0)?NaN:t.includes(0)?0:Math.exp(b(t.map(Math.log)))}function Pt(n){let o=N(n,!0),t=new Map;for(let s of o)t.set(s===0?0:s,(t.get(s===0?0:s)??0)+1);let r=0;for(let s of t.values())r=Math.max(r,s);return r<=1?{value:[NaN],frequency:NaN}:{value:[...t.entries()].filter(([,s])=>s===r).map(([s])=>s).sort((s,c)=>s-c),frequency:r}}function Wt(n,o={}){let t=N(n,!0),r=o.center??"mean",e=r==="mean"?b(t):r==="median"?W(t):r;return b(t.map(s=>Math.abs(s-e)))}function Lt(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;let r=t.length,e=Math.sqrt(F(t))/b(t);return o.unbiased&&(e*=1-1/(4*(r-1))+e*e/r+1/(2*(r-1)**2)),e}function Vt(n,o={}){let t=n.length>0&&Array.isArray(n[0])?n.map(f=>[...f]):Array.from(n,f=>[f]),r=t[0]?.length??0,e=f=>t.map(a=>a[f]),s={scaled:t},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 t)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(v=>!Number.isNaN(v)),R=0;for(let v of w)R+=v*v;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 t)for(let l=0;l<r;l++)a[l]=a[l]/f[l];s.scale=f}return s}export{j as a,Y as b,ft as c,O as d,at as e,pt as f,dt as g,gt as h,Nt as i,yt as j,bt as k,N as l,vt as m,At as n,Et as o,Ot as p,mt as q,jt as r,W as s,Rt as t,$t as u,kt as v,Ft as w,_t as x,Yt as y,Dt as z,Tt as A,Ct as B,Pt as C,Wt as D,Lt as E,Vt as F};
|