@numero-uno-jpn/rstats 0.16.0 → 0.17.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 +128 -0
- package/README.ja.md +44 -18
- package/README.md +45 -18
- package/dist/chunks/chunk-2C33MXSW.js +3 -0
- package/dist/chunks/chunk-34S5SQY6.js +2 -0
- package/dist/chunks/{chunk-URIO5LY5.js → chunk-4WE3OO62.js} +2 -2
- package/dist/chunks/chunk-5AYHCITP.js +2 -0
- package/dist/chunks/chunk-6JJQL6HL.js +2 -0
- package/dist/chunks/chunk-C7V2FH6L.js +3 -0
- package/dist/chunks/chunk-CZI7KUO3.js +2 -0
- package/dist/chunks/chunk-DXI5N2ET.js +2 -0
- package/dist/chunks/chunk-FY3FVOBM.js +2 -0
- package/dist/chunks/{chunk-QNNL7AZ3.js → chunk-H3WVPZDL.js} +2 -2
- package/dist/chunks/chunk-LHUIJQHY.js +2 -0
- package/dist/chunks/chunk-LV3W2F7N.js +2 -0
- package/dist/chunks/chunk-M4ITG7YR.js +2 -0
- package/dist/chunks/{chunk-FLJNSXSW.js → chunk-NSYZTS26.js} +2 -2
- package/dist/chunks/chunk-ONY5CISH.js +2 -0
- package/dist/chunks/chunk-RFE7MVP7.js +2 -0
- package/dist/chunks/{chunk-W26LRYOJ.js → chunk-SE7V2KLO.js} +1 -1
- package/dist/chunks/chunk-THIGHOKK.js +2 -0
- package/dist/chunks/chunk-TNMJPQPV.js +2 -0
- package/dist/chunks/chunk-WM7VFXTV.js +2 -0
- package/dist/chunks/chunk-WMDYDTVQ.js +2 -0
- package/dist/chunks/chunk-XLSFJTTK.js +2 -0
- package/dist/chunks/{chunk-5UQCRBAG.js → chunk-Z37NELOS.js} +1 -1
- package/dist/chunks/chunk-ZFQWB222.js +2 -0
- package/dist/data/grouping.js +6 -2
- package/dist/descriptive/basic.js +20 -0
- package/dist/descriptive/cov.js +11 -0
- package/dist/descriptive/dataFrames.js +13 -5
- package/dist/descriptive/factanal.d.ts +2 -0
- package/dist/descriptive/factanal.js +10 -2
- package/dist/descriptive/hist.js +6 -0
- package/dist/descriptive/moments.js +14 -0
- package/dist/descriptive/omega.js +8 -3
- package/dist/descriptive/pivot.d.ts +4 -1
- package/dist/descriptive/pivot.js +27 -13
- package/dist/descriptive/quantile.js +8 -0
- package/dist/descriptive/rank.js +4 -0
- package/dist/descriptive/table.d.ts +20 -1
- package/dist/descriptive/table.js +14 -14
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.js +8 -0
- package/dist/distributions/beta.js +9 -0
- package/dist/distributions/binomial.js +9 -0
- package/dist/distributions/cauchy.js +9 -0
- package/dist/distributions/chisq.js +9 -0
- package/dist/distributions/exponential.js +9 -0
- package/dist/distributions/f.js +9 -0
- package/dist/distributions/gamma.js +8 -0
- package/dist/distributions/geometric.js +9 -0
- package/dist/distributions/hypergeometric.js +8 -0
- package/dist/distributions/invgamma.js +8 -0
- package/dist/distributions/kumaraswamy.js +9 -0
- package/dist/distributions/laplace.js +9 -0
- package/dist/distributions/logistic.js +9 -0
- package/dist/distributions/lognormal.js +8 -0
- package/dist/distributions/multinomial.js +4 -0
- package/dist/distributions/negbinomial.js +8 -0
- package/dist/distributions/normal.js +8 -0
- package/dist/distributions/pareto.js +8 -0
- package/dist/distributions/poisson.js +9 -0
- package/dist/distributions/signrank.js +9 -0
- package/dist/distributions/summary.d.ts +2 -1
- package/dist/distributions/summary.js +31 -1
- package/dist/distributions/t.js +9 -0
- package/dist/distributions/triangular.js +9 -0
- package/dist/distributions/tukey.js +6 -0
- package/dist/distributions/uniform.js +8 -0
- package/dist/distributions/weibull.js +8 -0
- package/dist/distributions/wilcox.js +9 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +3 -1
- package/dist/entries/descriptive.js +1 -1
- package/dist/entries/distributions.d.ts +1 -0
- package/dist/entries/distributions.js +2 -0
- package/dist/entries/linalg.d.ts +3 -1
- package/dist/entries/mixed.d.ts +3 -0
- package/dist/entries/mixed.js +2 -0
- package/dist/entries/numerics.d.ts +2 -1
- package/dist/entries/tests.d.ts +8 -5
- package/dist/entries/tests.js +3 -1
- package/dist/htest/agreement.d.ts +13 -0
- package/dist/htest/agreement.js +46 -7
- package/dist/htest/ansariTest.d.ts +2 -1
- package/dist/htest/ansariTest.js +43 -12
- package/dist/htest/aov.d.ts +28 -22
- package/dist/htest/aov.js +42 -13
- package/dist/htest/binomTest.js +6 -0
- package/dist/htest/brunnerMunzelTest.js +5 -0
- package/dist/htest/chisqTest.d.ts +3 -1
- package/dist/htest/chisqTest.js +21 -3
- package/dist/htest/cor.d.ts +7 -1
- package/dist/htest/cor.js +40 -7
- package/dist/htest/core/simulate.d.ts +6 -0
- package/dist/htest/core/simulate.js +20 -0
- package/dist/htest/effectSize.d.ts +3 -0
- package/dist/htest/effectSize.js +28 -8
- package/dist/htest/fisherTest.d.ts +2 -1
- package/dist/htest/fisherTest.js +52 -6
- package/dist/htest/ksTest.d.ts +4 -0
- package/dist/htest/ksTest.js +13 -4
- package/dist/htest/leveneTest.d.ts +2 -0
- package/dist/htest/leveneTest.js +9 -3
- package/dist/htest/mantelhaenTest.js +7 -0
- package/dist/htest/mcnemarTest.js +8 -0
- package/dist/htest/multipleComparisons.d.ts +16 -25
- package/dist/htest/multipleComparisons.js +26 -43
- package/dist/htest/normalityTests.js +10 -4
- package/dist/htest/onewayTest.js +10 -0
- package/dist/htest/pAdjust.js +4 -0
- package/dist/htest/pairwise.d.ts +2 -0
- package/dist/htest/pairwise.js +29 -6
- package/dist/htest/poissonTest.js +6 -0
- package/dist/htest/polycor.js +20 -10
- package/dist/htest/power.d.ts +4 -0
- package/dist/htest/power.js +16 -2
- package/dist/htest/propTest.d.ts +3 -0
- package/dist/htest/propTest.js +23 -2
- package/dist/htest/pwr.d.ts +38 -1
- package/dist/htest/pwr.js +38 -15
- package/dist/htest/rankTests.js +7 -1
- package/dist/htest/tTest.d.ts +2 -0
- package/dist/htest/tTest.js +9 -0
- package/dist/htest/testFormula.js +11 -11
- package/dist/htest/trendTests.d.ts +21 -1
- package/dist/htest/trendTests.js +13 -18
- package/dist/htest/types.d.ts +2 -0
- package/dist/htest/varTest.js +7 -0
- package/dist/htest/wilcoxTest.js +51 -9
- package/dist/internal/checkOptions.d.ts +11 -0
- package/dist/internal/checkOptions.js +31 -0
- package/dist/internal/optionalArgs.d.ts +12 -0
- package/dist/internal/optionalArgs.js +46 -0
- package/dist/internal/warnings.d.ts +66 -0
- package/dist/internal/warnings.js +122 -0
- package/dist/linalg/basic.js +7 -0
- package/dist/linalg/chol.js +6 -0
- package/dist/linalg/eigen.js +4 -0
- package/dist/linalg/expm.js +4 -0
- package/dist/linalg/kappa.js +6 -0
- package/dist/linalg/lu.js +5 -0
- package/dist/linalg/norm.js +4 -0
- package/dist/linalg/ops.d.ts +27 -2
- package/dist/linalg/ops.js +14 -13
- package/dist/linalg/qr.js +14 -0
- package/dist/linalg/solve.js +9 -0
- package/dist/linalg/svd.js +6 -2
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +4 -4
- package/dist/models/anovaSequential.d.ts +16 -1
- package/dist/models/anovaSequential.js +50 -7
- package/dist/models/aovEz.js +16 -11
- package/dist/models/aovStrata.js +15 -4
- package/dist/models/carAnova.js +11 -17
- package/dist/models/coxph.d.ts +6 -0
- package/dist/models/coxph.js +21 -6
- package/dist/models/glm.d.ts +22 -2
- package/dist/models/glm.js +32 -22
- package/dist/models/glmAnova.js +8 -3
- package/dist/models/glmConfint.js +6 -2
- package/dist/models/glmFamily.d.ts +1 -6
- package/dist/models/glmFamily.js +3 -22
- package/dist/models/lm.js +13 -3
- package/dist/models/lmer.d.ts +11 -6
- package/dist/models/lmer.js +20 -15
- package/dist/models/lmerAnova.d.ts +3 -3
- package/dist/models/lmerAnova.js +10 -5
- package/dist/models/lmerTest.d.ts +4 -4
- package/dist/models/lmerTest.js +19 -11
- package/dist/models/mauchly.d.ts +2 -0
- package/dist/models/mauchly.js +7 -2
- package/dist/models/modelFrame.js +2 -2
- package/dist/models/modelMatrix.js +7 -2
- package/dist/models/survival.d.ts +6 -0
- package/dist/models/survival.js +9 -2
- package/dist/numerics/deriv.js +8 -0
- package/dist/numerics/integrate.js +8 -0
- package/dist/numerics/interp.d.ts +32 -7
- package/dist/numerics/interp.js +27 -9
- package/dist/numerics/ode.js +4 -0
- package/dist/numerics.js +2 -2
- package/dist/optim/optim.js +17 -2
- package/dist/random/beta.js +5 -0
- package/dist/random/continuous.js +17 -0
- package/dist/random/extra.js +13 -0
- package/dist/random/gamma.js +11 -0
- package/dist/random/poisson.js +5 -0
- package/dist/random/rng.js +4 -0
- package/dist/random/sample.js +6 -0
- package/dist/rstats.js +17 -14
- package/dist/special/besselIK.js +7 -0
- package/dist/special/choose.js +7 -0
- package/dist/special/psigamma.js +7 -0
- package/dist/special.js +2 -2
- package/dist/tests.js +15 -11
- package/llms.txt +5 -2
- package/package.json +19 -10
- package/dist/chunks/chunk-2D2IQWUQ.js +0 -2
- package/dist/chunks/chunk-6CSTWA5E.js +0 -2
- package/dist/chunks/chunk-72Y3HZID.js +0 -2
- package/dist/chunks/chunk-BG2KLEHM.js +0 -2
- package/dist/chunks/chunk-CMEKBNHQ.js +0 -2
- package/dist/chunks/chunk-GM53LWSR.js +0 -2
- package/dist/chunks/chunk-JBCA56ZS.js +0 -3
- package/dist/chunks/chunk-K3RJAD2T.js +0 -2
- package/dist/chunks/chunk-KAZRWIB5.js +0 -2
- package/dist/chunks/chunk-KBVVIMXX.js +0 -3
- package/dist/chunks/chunk-N3SIFCZX.js +0 -2
- package/dist/chunks/chunk-SC6CV4Z3.js +0 -2
- package/dist/chunks/chunk-SYWOBOTR.js +0 -2
- package/dist/chunks/chunk-VTUGG2SV.js +0 -2
- package/dist/chunks/chunk-XHETEYVC.js +0 -2
- package/dist/chunks/chunk-YRZWONZB.js +0 -3
- package/dist/chunks/chunk-ZGABZMWX.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,134 @@ 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.17.0 - 2026-11-05
|
|
11
|
+
|
|
12
|
+
The API is cleaned up toward 1.0.0, which follows the mixed models of `glmer`: argument errors are a `TypeError` or
|
|
13
|
+
a `RangeError`, a key of an options object that the function does not know is an error, and the results of the tests
|
|
14
|
+
have a required `warnings` with R's warnings, which `setWarningHandler` can also pass to a function.
|
|
15
|
+
|
|
16
|
+
### Breaking
|
|
17
|
+
|
|
18
|
+
- Argument errors that were a plain `Error` are a `TypeError` (wrong type or shape) or a `RangeError` (value out of
|
|
19
|
+
range), as the other functions (the messages are unchanged):
|
|
20
|
+
- `pivotLonger` and `pivotWider`: a `colsVary` or `namesVary` that is not a string, a `namesSep` with one
|
|
21
|
+
`namesTo`, several `namesTo` without `namesSep` or `namesPattern`, a `namesPattern` with the wrong number of
|
|
22
|
+
groups, and a `.value` transform that gives no string are TypeErrors; an unknown `colsVary` or `namesVary`, a
|
|
23
|
+
column that does not exist, an empty `cols`, `namesFrom` or `valuesFrom`, `.value` twice in `namesTo`, a value
|
|
24
|
+
column given twice for one key, `idCols` that overlap `namesFrom` or `valuesFrom`, and values not uniquely
|
|
25
|
+
identified without `valuesFn` are RangeErrors.
|
|
26
|
+
- `merge`: `byX` and `byY` of different lengths are a TypeError, a key that is not a column a RangeError.
|
|
27
|
+
- The formula forms of the tests (`tTest`, `wilcoxTest`, `varTest`, `ansariTest`, `moodTest`, `ksTest`,
|
|
28
|
+
`kruskalTest`, `flignerTest`, `bartlettTest`, `onewayTest`, `friedmanTest`, `quadeTest`, `corTest`): a formula of
|
|
29
|
+
the wrong form for the test is a TypeError. A grouping factor without exactly 2 levels and a block design that is
|
|
30
|
+
not unreplicated and complete stay an `Error` (data whose result is not defined).
|
|
31
|
+
- Data frames and columns: a duplicate column name (`cbind`, `merge` with suffixes that collide, `aggregate`) and a
|
|
32
|
+
`select` of `subset` that is not a column are RangeErrors, and data frames with different names in `rbind` a
|
|
33
|
+
TypeError; a column named in a formula or option that does not exist ("object 'x' not found": `aggregate`, the
|
|
34
|
+
model functions such as `lm` and `glm` and their `weights`, the formula forms of the tests, `aovEz`) is a
|
|
35
|
+
RangeError, and so are a factor given in both `between` and `within` of `aovEz`, a factor name repeated in
|
|
36
|
+
`between` or `within` ("duplicated factor names in 'between': A") and an `observed` variable that is not a factor
|
|
37
|
+
("Observed variable not in data: x"), the same error of `etaSquared`'s `generalized` included.
|
|
38
|
+
- `aov(x, g)` and `aov(samples)` return the fit of the model `y ~ g` (an `LmFormulaResult`, as `aov("y ~ g", data)`)
|
|
39
|
+
instead of the one-way table, as R's `aov` always returns a fit; the table is `aovSummary(aov(x, g))` (rows `g` and
|
|
40
|
+
`Residuals`), and the `AovResult` type is removed. The levels of `g` are the group labels in R's order, or the
|
|
41
|
+
positions of the samples in the list (from 1). F and p agree with the old table to the last bit or within a few ulps
|
|
42
|
+
of rounding (the sums of squares now come from the QR of the fit). Where the residual sum of squares is exactly 0,
|
|
43
|
+
the fit leaves rounding residue as R's does; the table takes it as 0, as the old table: F = Inf and p = 0, and NaN
|
|
44
|
+
when all values are equal (see Changed).
|
|
45
|
+
- `steelTest` is removed. It only reproduced the errors of PMCMRplus 1.9.12's `steelTest`, which fails on every input,
|
|
46
|
+
and never returned a value; Steel's many-to-one rank test is `manyOneUTest` (its normal approximation).
|
|
47
|
+
- A key of an options object that the function does not know is a RangeError, where it was ignored: a misspelt key
|
|
48
|
+
such as `pnorm(q, { lowertail: false })` gave the lower tail without a sign ("unknown option 'lowertail' for pnorm
|
|
49
|
+
(known: mean, sd, lowerTail, logP)"). A key whose value is `undefined` counts. This holds for every exported function
|
|
50
|
+
that takes options, the nested objects with fixed keys included (`optim`'s and `optimHess`' `control`, `glm`'s
|
|
51
|
+
`family` and `link` given as objects, `coxph`'s and `factanal`'s `control`; "unknown option 'control.maxitt' for
|
|
52
|
+
optim", and so for `optimHess`, whose `control` is a position), for the `params` of `distSummary` (the parameters
|
|
53
|
+
of the distribution's d function: `shape`, `rate` and `scale` for `"gamma"`; not `ncp` of `chisq`, `beta`, `t` and
|
|
54
|
+
`f`, which was ignored, giving the summaries of the central distribution) and for the options of the function
|
|
55
|
+
`splinefun` and `splinefunH` return. Objects whose keys are the user's data (data frames, `contrasts`, `levels`) are
|
|
56
|
+
not checked. In `lmer`, `lmerSummary`, `lmerContest` and `lmerAnova` an unknown key was a TypeError with R's
|
|
57
|
+
message ("unused argument (reml)") and is now this RangeError too; an argument of R that they do not support
|
|
58
|
+
(`lmer`'s `weights`, `lmerAnova`'s `ddf`, ...) is still the Error "lmer: argument 'weights' is not supported",
|
|
59
|
+
checked first.
|
|
60
|
+
- `HTest` and the other results of the tests, effect sizes, power and agreement functions, and `factanal`'s, have a
|
|
61
|
+
required `warnings: string[]`: R's warnings, each once, in R's order, an empty array when there are none (not the
|
|
62
|
+
warnings of R's distribution functions about their own precision, nor those about R's argument types; those that
|
|
63
|
+
explain a `NaN` are included). Code that builds such an object itself must add the field. Nothing is printed unless
|
|
64
|
+
a handler is set (`setWarningHandler`, under Added). The functions that had no `warnings` return an empty array,
|
|
65
|
+
except 10 that now give R's warnings where they were silent, and `cohensD` and `hedgesG` give a new one:
|
|
66
|
+
- `wilcoxTest`: "cannot compute exact p-value with ties" or "with zeroes" and the same of the interval, when the
|
|
67
|
+
exact method asked for or chosen by default cannot be used; "requested conf.level not achievable", where the
|
|
68
|
+
interval's confidence level is lowered; "cannot compute confidence interval when all observations are zero or
|
|
69
|
+
tied", where the interval is `NaN`. `pairwiseWilcoxTest` returns those of its comparisons, each once.
|
|
70
|
+
- `ansariTest`: "cannot compute exact p-value with ties" and, with `confInt`, "cannot compute exact confidence
|
|
71
|
+
intervals with ties", where R stops but the normal-approximation interval is returned; "samples differ in
|
|
72
|
+
location: cannot compute confidence set, returning NA", "cannot compute confidence set, returning NA", "cannot
|
|
73
|
+
compute estimate, returning NA" and "cannot compute asymptotic confidence set or estimator", where the interval or
|
|
74
|
+
estimate is `NaN` or left out.
|
|
75
|
+
- `fisherTest`: "'x' has been rounded to integer: Mean relative difference: 0.0625", with the text of R's
|
|
76
|
+
`all.equal` of the counts and the rounded counts.
|
|
77
|
+
- `chisqTest`: "Chi-squared approximation may be incorrect" where an expected count is below 5 and the p-value is
|
|
78
|
+
not simulated, and "cannot compute simulated p-value with zero marginals". `propTest`: "Chi-squared approximation
|
|
79
|
+
may be incorrect"; `pairwisePropTest` returns it once.
|
|
80
|
+
- `ksTest`: "ties should not be present for the one-sample Kolmogorov-Smirnov test", and "p-value will be
|
|
81
|
+
approximate in the presence of ties" for two samples with the asymptotic p-value.
|
|
82
|
+
- `corTest`: "the standard deviation is zero" where x or y is constant, "Cannot compute exact p-value with ties"
|
|
83
|
+
for Kendall and Spearman, and R's "NaNs produced" of Spearman's t approximation for 2 pairs, whose p-value is
|
|
84
|
+
`NaN`.
|
|
85
|
+
- `cohensD` and `hedgesG`: effectsize's "'y' is numeric but has only 2 unique values. ..." where `y` has exactly 2
|
|
86
|
+
distinct values.
|
|
87
|
+
- `cronbachAlpha`: psych's own warnings, "Item = had no variance and was deleted but still is counted in the
|
|
88
|
+
score" for a constant item and "Some items were negatively correlated with the first principal component and
|
|
89
|
+
probably should be reversed. ..." (as psych's `principal`: the eigenvector of the largest eigenvalue of the
|
|
90
|
+
correlations, signed so that its sum is not negative).
|
|
91
|
+
|
|
92
|
+
### Added
|
|
93
|
+
|
|
94
|
+
- The package can be loaded with `require()` (Node 22.12 and later load ES modules with `require`): each subpath of
|
|
95
|
+
`exports` has a `default` condition besides `import`, and `@numero-uno-jpn/rstats/package.json` is exported.
|
|
96
|
+
- Each subpath exports the types its functions use, so they need no import from another subpath: `Sample` and
|
|
97
|
+
`DataFrame` from `/descriptive` and `/linalg`, `Sample` from `/numerics`, `DataFrame` and `ContrastName` from
|
|
98
|
+
`/mixed`, `MatrixInput` and `QR` from `/tests`.
|
|
99
|
+
- Results whose fields keep the names of R or of a package get aliases with the names the other results use, as
|
|
100
|
+
ordinary fields with the same values (the old names stay): `pValue` for `survdiff`'s `pvalue`; `stdError`, `zValue`
|
|
101
|
+
and `pValue` for `coxph`'s `se`, `z` and `p`; `stdError`, `tValue` and `pValue` for `glhtDunnett`'s `se`, `t` and
|
|
102
|
+
`p`; `zValue`, `pValue` and `pAdjusted` for `dunnTest`'s `Z`, `P` and `PAdjusted`; `pAdjusted` for `TukeyHSD`'s
|
|
103
|
+
`pAdj`; `stdError` for the `stdErr` of `tTest` and `survfit`; `fValue` for `icc`'s `Fvalue`.
|
|
104
|
+
- The optional arguments taken by position as in R are also accepted in an options object (an overload), in place of
|
|
105
|
+
the argument or after it: `glmResiduals(fit, { type })`, `cohenES(test, { size })`, `outer(x, y, { fun })`,
|
|
106
|
+
`tabulate(bin, { nbins })`, `propTrendTest(x, n, { score })` and `s(xq, { deriv })` for the function `s` that
|
|
107
|
+
`splinefun` or `splinefunH` returns (its type is the new `SplineFunction`). `optimHess` keeps `gr` and `control` by
|
|
108
|
+
position only, as R (a positional `control` is itself a plain object). Giving one both by position and in the options is a
|
|
109
|
+
RangeError. New types: `GlmResidualsOptions`, `CohenESOptions`, `OuterFun`, `OuterOptions`, `TabulateOptions`,
|
|
110
|
+
`PropTrendTestOptions`, `SplineFunction` and `SplineFunctionOptions`.
|
|
111
|
+
- `setWarningHandler(handler)` passes R's warnings to a function of the user's choice, as R prints them, such as
|
|
112
|
+
`setWarningHandler((message, source) => console.warn(source + ": " + message))`: each call of a test, model or fit
|
|
113
|
+
(and `pivotLonger` without `onWarning`) passes its warnings once it has its result, each distinct warning once, with
|
|
114
|
+
the name of the function called (also the warnings the tests now give, such as `wilcoxTest`'s "cannot compute exact
|
|
115
|
+
p-value with ties"); a function that calls another, such as `pairwiseWilcoxTest`, passes them once under
|
|
116
|
+
its own name. A fit's warnings are passed once, when it is fitted (`lm`, `glm`, `aov`, `lmer`, ...); a function
|
|
117
|
+
given a fit or a table (`anova`, `aovSummary`, `Anova`, `glmSummary`, `etaSquared`, `lmerSummary`, ...) keeps them
|
|
118
|
+
in its result's `warnings` but passes only those it adds. An error thrown by the handler propagates to the caller
|
|
119
|
+
(as R's `options(warn = 2)`). `setWarningHandler(null)`, the default, passes nothing; the previous handler is
|
|
120
|
+
returned. The handler is kept on `globalThis`, one setting for every copy of the library on a page. Exported from
|
|
121
|
+
the root, `rStats.js/distributions`, `rStats.js/tests` and `rStats.js/mixed`, with the type `WarningHandler`.
|
|
122
|
+
|
|
123
|
+
### Changed
|
|
124
|
+
|
|
125
|
+
- `aovSummary` and the sequential table of `anova` take a residual sum of squares at the level of rounding (below
|
|
126
|
+
1e-24 times the weighted sum of squares of the response, as `Anova`'s check of an exact fit) as 0, with the sums of
|
|
127
|
+
squares of the terms at that level: F = Inf and p = 0 for groups without spread (`aov([[1, 1], [2, 2]])` gave F =
|
|
128
|
+
3.4e64 from the residue of the QR, as R), and F = NaN where all values are equal (F = 0.6 or 1 from the residue).
|
|
129
|
+
The same holds in each stratum of a fit with `Error()` (the sum of squares of the whole response as the scale): F =
|
|
130
|
+
Inf or NaN where the Within stratum of `aov("y ~ g + Error(id)", d)` gave F = 2.9e33 from the residue. The tables
|
|
131
|
+
of other fits are unchanged to the bit.
|
|
132
|
+
|
|
133
|
+
### Fixed
|
|
134
|
+
|
|
135
|
+
- The result of `svd` no longer has the internal field `s` (the power-of-2 exponent of the singular values), which is
|
|
136
|
+
not part of `SvdResult`.
|
|
137
|
+
|
|
10
138
|
## 0.16.0 - 2026-11-04
|
|
11
139
|
|
|
12
140
|
Fixes from a numerical review and GitHub issues #8 to #513. Each case is described, with R's value and rStats.js's, in
|
package/README.ja.md
CHANGED
|
@@ -14,9 +14,9 @@ JavaScript とブラウザで使える、R と互換の統計関数のライブ
|
|
|
14
14
|
持つオブジェクトで渡します。`pt(q, df, { lowerTail: false })` は R の `pt(q, df, lower.tail = FALSE)` に
|
|
15
15
|
当たります。結果は素のオブジェクトなので、そのまま `JSON.stringify` できます。
|
|
16
16
|
- **どこでも動きます。** ESM のみで、依存パッケージはなく、Node 専用の API も使っていません。
|
|
17
|
-
tree-shaking が効きます (`pnorm` だけなら gzip で 1.
|
|
17
|
+
tree-shaking が効きます (`pnorm` だけなら gzip で 1.6 KB)。
|
|
18
18
|
|
|
19
|
-
状態: **0.
|
|
19
|
+
状態: **0.17.0。** R の stats パッケージの数値計算の中心
|
|
20
20
|
(分布・記述統計・検定・線形モデル・特殊関数・数値計算・線形代数の基本) を、R と同じ結果でカバーすることを目指しています。残っている作業は
|
|
21
21
|
[ROADMAP.ja.md](ROADMAP.ja.md)、変更履歴は [CHANGELOG.md](CHANGELOG.md) (英語) にあります。
|
|
22
22
|
|
|
@@ -192,7 +192,7 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
|
|
|
192
192
|
| 分布 (d/p/q) | 正規、t、カイ二乗、F、ベータ、ガンマ、二項、ポアソン、一様、指数、対数正規、ロジスティック、コーシー、ワイブル、幾何、負の二項、超幾何、Wilcoxon の符号付き順位と順位和、スチューデント化された範囲 (`ptukey`, `qtukey`)、非心カイ二乗・t・F・ベータ (`ncp`)。多項分布の確率 (`dmultinom`)。逆ガンマ、Kumaraswamy、Pareto、三角、Laplace (extraDistr) と逆正弦。`distSummary` (平均・分散・標準偏差・中央値・最頻値・歪度・尖度) |
|
|
193
193
|
| 乱数 | `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` |
|
|
194
194
|
| 記述統計 | `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` |
|
|
195
|
-
| 検定 | `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` (
|
|
195
|
+
| 検定 | `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` (一元配置。表は当てはめの `aovSummary`), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
|
|
196
196
|
| 分散分析 | formula で呼ぶ `aov` と `aovSummary` (多元、交互作用、共変量、`Error()` の層), `anova` (`anova.lm`。逐次の表とモデルの比較), `Anova` (car の Type II と III), `aovEz` (afex。反復測定と混合計画、Greenhouse-Geisser と Huynh-Feldt の補正、一般化 η² と偏 η²), `mauchlyTest` (`mauchly.test`) |
|
|
197
197
|
| 効果量と検出力 | `cohensD`, `hedgesG` (effectsize。信頼区間は厳密な限界), `etaSquared`, `omegaSquared`, `epsilonSquared` (偏・一般化。`anova` と `Anova` の表から), `powerTTest`, `powerPropTest`, `powerAnovaTest` (`power.*.test`), `pwrTTest`, `pwrT2nTest`, `pwr2pTest`, `pwr2p2nTest`, `pwrPTest`, `pwrNormTest`, `pwrRTest`, `pwrChisqTest`, `pwrAnovaTest`, `pwrF2Test`, `esH`, `esW1`, `esW2`, `cohenES` (pwr) |
|
|
198
198
|
| 線形モデル | `lm` (formula とデータフレーム、または行列で渡す。`summary` の値も返す), `modelMatrix` (`model.matrix`), `confint`, `predict`。`glm` (行列で渡す形。R の `stats` のすべての族とリンク) と `glmSummary` (`summary.glm`)、`glmResiduals` (4 種類)、`glmHatvalues`、`glmRstandard`、`glmCooksDistance`、`glmPredict` (標準誤差つき)、`glmConfint` (プロファイル尤度、厳密な限界)、`glmAnova` (`anova.glm`) |
|
|
@@ -233,9 +233,11 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
233
233
|
- 添字は 0 から始まります。`sampleInt(n)` は `0..n-1` を返します (R の `sample.int()` から 1 を
|
|
234
234
|
引いた値で、乱数の列は同じ)。`qr` と `chol` のピボットも 0 から始まります。
|
|
235
235
|
- 固有ベクトルと特異ベクトルの符号が R と違うことがあります (どちらも正しい答えです)。
|
|
236
|
-
- R
|
|
237
|
-
`
|
|
238
|
-
|
|
236
|
+
- 数値の欄と手法の名前はすべて一致します。R の警告は既定では表示しませんが、検定・モデル・当てはめはすべて、
|
|
237
|
+
結果の `warnings` に入れて返します (R の文言で、同じ警告は 1 回ずつ。なければ `[]`)。R のように表示するには
|
|
238
|
+
handler を設定します。handler は、呼び出しの警告を 1 つずつ、呼んだ関数の名前とともに受け取ります:
|
|
239
|
+
`setWarningHandler((message, source) => console.warn(source + ": " + message))`。handler の中で throw すれば
|
|
240
|
+
R の `options(warn = 2)` の代わりになり、`setWarningHandler(null)` で止まります。
|
|
239
241
|
- 結果が定義されない入力はエラーにします。R が NaN や意味のない値を返す場合も同じです (たとえば不一致の
|
|
240
242
|
組がない表の `mcnemarTest`、NaN を含む行列の `lu`)。分布の関数 (d/p/q/r) は、R と同じく不正な母数に NaN を返します。
|
|
241
243
|
[全般的な違い](docs/ja/differences-from-r.md#全般)を見てください。
|
|
@@ -255,14 +257,14 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
255
257
|
|
|
256
258
|
| import するもの | gzip |
|
|
257
259
|
|---|---|
|
|
258
|
-
| `pnorm` | 1.
|
|
259
|
-
| `setSeed`, `rnorm` |
|
|
260
|
-
| `solve` / `svd` / `eigen` | 2.
|
|
261
|
-
| `wilcoxTest` / `fisherTest` / `tTest` |
|
|
262
|
-
| `qbeta` / `pt` と `qt` | 43.
|
|
263
|
-
| `glm` と `glmSummary` / `glm` とそのすべての関数 |
|
|
264
|
-
| `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 17.
|
|
265
|
-
| すべて (`/mixed` を除く) |
|
|
260
|
+
| `pnorm` | 1.6 KB |
|
|
261
|
+
| `setSeed`, `rnorm` | 2.0 KB |
|
|
262
|
+
| `solve` / `svd` / `eigen` | 2.4 / 2.4 / 5.1 KB |
|
|
263
|
+
| `wilcoxTest` / `fisherTest` / `tTest` | 16.2 / 27.7 / 30.8 KB |
|
|
264
|
+
| `qbeta` / `pt` と `qt` | 43.5 / 40.0 KB |
|
|
265
|
+
| `glm` と `glmSummary` / `glm` とそのすべての関数 | 35.0 / 50.9 KB |
|
|
266
|
+
| `lmer` (`/mixed` から) / `lmerSummary`・`lmerContest`・`lmerAnova` も | 17.9 / 67.5 KB |
|
|
267
|
+
| すべて (`/mixed` を除く) | 248.6 KB |
|
|
266
268
|
|
|
267
269
|
(`npm run size` で測れます。)
|
|
268
270
|
|
|
@@ -272,12 +274,12 @@ double-double 演算で計算しているためです。詳しくは [docs/ja/ac
|
|
|
272
274
|
できません。メインの入口には含めていません)。
|
|
273
275
|
|
|
274
276
|
バンドラを使わない場合は、1 ファイルにまとめたビルド `dist/rstats.js` (`/mixed` 以外のすべての関数を含む
|
|
275
|
-
minify 済みの ES モジュール、gzip で
|
|
277
|
+
minify 済みの ES モジュール、gzip で 249 KB) を jsDelivr から読み込めます。jsDelivr は、npm のリリースを
|
|
276
278
|
そのまま配信します。
|
|
277
279
|
|
|
278
280
|
```html
|
|
279
281
|
<script type="module">
|
|
280
|
-
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.
|
|
282
|
+
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.17.0/dist/rstats.js";
|
|
281
283
|
console.log(pnorm(1.96)); // ≈ 0.9750021049
|
|
282
284
|
</script>
|
|
283
285
|
```
|
|
@@ -293,7 +295,12 @@ minify 済みの ES モジュール、gzip で 241 KB) を jsDelivr から読み
|
|
|
293
295
|
`dist/tests.js`、`dist/linalg.js`、`dist/descriptive.js`、`dist/numerics.js`、`dist/special.js`、
|
|
294
296
|
`dist/mixed.js` は上のサブパスと同じ関数を export し、共通のコードを `dist/chunks/` で共有します。そのため、
|
|
295
297
|
2 つの分野を読み込んでも共通部分は 1 回しか読み込まれません。chunk を含めた 1 分野の転送量は、gzip で
|
|
296
|
-
|
|
298
|
+
38 KB (`special`) から 206 KB (`tests`) です。
|
|
299
|
+
|
|
300
|
+
1 つのページでは、`dist/rstats.js` か分野ごとのバンドルのどちらか一方だけを使ってください。両者は別々の
|
|
301
|
+
モジュールの集まりなので、混ぜると共通のコードが 2 回読み込まれ、乱数の状態も 2 つになります (一方の `setSeed`
|
|
302
|
+
は他方の乱数に効きません)。`dist/rstats.js` と `dist/mixed.js` を一緒に読み込む場合も、`dist/mixed.js` は
|
|
303
|
+
共通のコードを別に持ち込みます。
|
|
297
304
|
|
|
298
305
|
npm を元にしたほかの CDN も使えます。たとえば `https://esm.sh/@numero-uno-jpn/rstats` です。ビルド結果
|
|
299
306
|
(`dist/`) は main ブランチにはなく、リリースのタグにも入っていますが、jsDelivr の GitHub 経由の配信
|
|
@@ -313,7 +320,26 @@ npm を元にしたほかの CDN も使えます。たとえば `https://esm.sh/
|
|
|
313
320
|
## 版の番号
|
|
314
321
|
|
|
315
322
|
版が 0.x の間は、minor の版で互換性のない変更が入ることがあります。その場合は変更履歴に
|
|
316
|
-
書きます。
|
|
323
|
+
書きます。
|
|
324
|
+
|
|
325
|
+
1.0.0 からは Semantic Versioning に従います。公開 API は、パッケージのルートとサブパスが export するもので、
|
|
326
|
+
文書にある名前・引数・オプション・結果のフィールドとそれらの型を含みます。
|
|
327
|
+
|
|
328
|
+
- **major** (互換性のない変更): export・オプション・結果のフィールドの削除や改名、既定値や結果の形の変更、
|
|
329
|
+
値を返していた入力でエラーにすること、エラーの型 (`TypeError`、`RangeError`、`SyntaxError`、`Error`) の変更、
|
|
330
|
+
計算量の上限を厳しくすること、まだサポートされている Node.js の版を外すこと。
|
|
331
|
+
- **minor**: 関数・オプション・オーバーロード・結果のフィールドの追加、エラーだった入力を受け付けること、
|
|
332
|
+
計算量の上限を緩めること、R (または従っているパッケージ) が誤る範囲で正しい値に変えること
|
|
333
|
+
([docs/ja/differences-from-r.md](docs/ja/differences-from-r.md) に記録します)。
|
|
334
|
+
- **patch**: 不具合の修正 (R や厳密な値に近づく値の変化を含みます。最後のビットの変化は互換性のない変更として
|
|
335
|
+
扱いません) と、文書の変更。
|
|
336
|
+
- API に含めないもの: エラーのメッセージ、キーの順、`warnings` と `messages` の中身、列挙できないフィールドや
|
|
337
|
+
文書にないフィールド、`dist/` のうちエントリポイントと `dist/*.js` のバンドル以外のファイル。R の新しい版が
|
|
338
|
+
R 自身の値や乱数の列を変えたときは、rStats.js も minor の版でそれに合わせます。
|
|
339
|
+
- 結果のフィールドで分岐するコードは、フィールドが増えることを前提にしてください。
|
|
340
|
+
- オプションのオブジェクトに関数の知らないキーがあると RangeError になります (`optim` の `control` のような入れ子の
|
|
341
|
+
オブジェクトも同じ)。綴りを誤ったオプションが黙って無視されることはありません。このため、オプションの追加は
|
|
342
|
+
minor の変更です (追加するキーは、それまではエラーでした)。
|
|
317
343
|
|
|
318
344
|
## 貢献
|
|
319
345
|
|
package/README.md
CHANGED
|
@@ -12,9 +12,9 @@ R-compatible statistical functions for JavaScript and the browser, written in Ty
|
|
|
12
12
|
with camelCase keys: `pt(q, df, { lowerTail: false })` is R's `pt(q, df, lower.tail = FALSE)`.
|
|
13
13
|
Results are plain objects that `JSON.stringify` cleanly.
|
|
14
14
|
- **Runs anywhere.** ESM only, no dependencies, no Node-specific APIs, tree-shakable
|
|
15
|
-
(`pnorm` alone is 1.
|
|
15
|
+
(`pnorm` alone is 1.6 KB gzipped).
|
|
16
16
|
|
|
17
|
-
Status: **0.
|
|
17
|
+
Status: **0.17.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
|
|
|
@@ -189,7 +189,7 @@ eigen([[2, 1], [1, 3]]).values; // ≈ [3.618033989, 1.381966011]
|
|
|
189
189
|
| 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) |
|
|
190
190
|
| 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` |
|
|
191
191
|
| 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` |
|
|
192
|
-
| 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`) |
|
|
192
|
+
| 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, a fit whose table is `aovSummary`), `TukeyHSD`, `zTest`, `brunnerMunzelTest`, `pAdjust` (`p.adjust`) |
|
|
193
193
|
| Analysis of variance | `aov` and `aovSummary` with a formula (several factors, interactions, covariates, `Error()` strata), `anova` (`anova.lm`, sequential and model comparison), `Anova` (car: types II and III), `aovEz` (afex: repeated-measures and mixed designs, Greenhouse-Geisser and Huynh-Feldt corrections, generalized and partial eta squared), `mauchlyTest` (`mauchly.test`) |
|
|
194
194
|
| Effect sizes and power | `cohensD`, `hedgesG` (effectsize, with exact confidence limits), `etaSquared`, `omegaSquared`, `epsilonSquared` (partial, generalized, from `anova` and `Anova` tables); `powerTTest`, `powerPropTest`, `powerAnovaTest` (`power.*.test`); `pwrTTest`, `pwrT2nTest`, `pwr2pTest`, `pwr2p2nTest`, `pwrPTest`, `pwrNormTest`, `pwrRTest`, `pwrChisqTest`, `pwrAnovaTest`, `pwrF2Test`, `esH`, `esW1`, `esW2`, `cohenES` (pwr) |
|
|
195
195
|
| Linear models | `lm` (a formula and a data frame, or a matrix, with the `summary` quantities), `modelMatrix` (`model.matrix`), `confint`, `predict`; `glm` (matrix interface, every family and link of R's `stats`) with `glmSummary` (`summary.glm`), `glmResiduals` (the four kinds), `glmHatvalues`, `glmRstandard`, `glmCooksDistance`, `glmPredict` (with standard errors), `glmConfint` (profile likelihood, exact limits), `glmAnova` (`anova.glm`) |
|
|
@@ -229,9 +229,11 @@ everyday use:
|
|
|
229
229
|
- Indices are 0-based: `sampleInt(n)` returns `0..n-1` (R's `sample.int()` minus 1, from the
|
|
230
230
|
same random stream), and pivots of `qr` and `chol` are 0-based.
|
|
231
231
|
- Signs of eigenvectors and singular vectors may differ from R (both are correct).
|
|
232
|
-
-
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
- All numeric fields and method names match. R's warnings are not printed by default, but every test, model and fit
|
|
233
|
+
returns them in its result (`warnings`: R's text, each distinct warning once, `[]` when there are none). To print
|
|
234
|
+
them as R does, set a handler, which receives each warning of a call once with the name of the function called:
|
|
235
|
+
`setWarningHandler((message, source) => console.warn(source + ": " + message))`. A handler that throws plays the
|
|
236
|
+
part of R's `options(warn = 2)`, and `setWarningHandler(null)` stops it.
|
|
235
237
|
- Input for which the result is not defined is an error, also where R returns NaN or a meaningless value (for
|
|
236
238
|
example `mcnemarTest` on a table without discordant pairs, or `lu` of a matrix with NaN). The distribution
|
|
237
239
|
functions (d/p/q/r) return NaN for invalid parameters, as R. See
|
|
@@ -252,14 +254,14 @@ removed. Approximate sizes after minification and gzip:
|
|
|
252
254
|
|
|
253
255
|
| Import | gzip |
|
|
254
256
|
|---|---|
|
|
255
|
-
| `pnorm` | 1.
|
|
256
|
-
| `setSeed`, `rnorm` |
|
|
257
|
-
| `solve` / `svd` / `eigen` | 2.
|
|
258
|
-
| `wilcoxTest` / `fisherTest` / `tTest` |
|
|
259
|
-
| `qbeta` / `pt` and `qt` | 43.
|
|
260
|
-
| `glm` and `glmSummary` / `glm` with all its methods |
|
|
261
|
-
| `lmer` (from `/mixed`) / with `lmerSummary`, `lmerContest`, `lmerAnova` | 17.
|
|
262
|
-
| everything (except `/mixed`) |
|
|
257
|
+
| `pnorm` | 1.6 KB |
|
|
258
|
+
| `setSeed`, `rnorm` | 2.0 KB |
|
|
259
|
+
| `solve` / `svd` / `eigen` | 2.4 / 2.4 / 5.1 KB |
|
|
260
|
+
| `wilcoxTest` / `fisherTest` / `tTest` | 16.2 / 27.7 / 30.8 KB |
|
|
261
|
+
| `qbeta` / `pt` and `qt` | 43.5 / 40.0 KB |
|
|
262
|
+
| `glm` and `glmSummary` / `glm` with all its methods | 35.0 / 50.9 KB |
|
|
263
|
+
| `lmer` (from `/mixed`) / with `lmerSummary`, `lmerContest`, `lmerAnova` | 17.9 / 67.5 KB |
|
|
264
|
+
| everything (except `/mixed`) | 248.6 KB |
|
|
263
265
|
|
|
264
266
|
(`npm run size` measures these.)
|
|
265
267
|
|
|
@@ -269,11 +271,11 @@ Each area is also a subpath export, for importing one area without the rest:
|
|
|
269
271
|
(`lmer` and lmerTest's tests; this area is only available this way, not from the main entry point).
|
|
270
272
|
|
|
271
273
|
Without a bundler, load the single-file build `dist/rstats.js` (one minified ES module with every
|
|
272
|
-
function except those of `/mixed`,
|
|
274
|
+
function except those of `/mixed`, 249 KB gzipped) from jsDelivr, which serves each npm release:
|
|
273
275
|
|
|
274
276
|
```html
|
|
275
277
|
<script type="module">
|
|
276
|
-
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.
|
|
278
|
+
import { pnorm } from "https://cdn.jsdelivr.net/npm/@numero-uno-jpn/rstats@0.17.0/dist/rstats.js";
|
|
277
279
|
console.log(pnorm(1.96)); // ≈ 0.9750021049
|
|
278
280
|
</script>
|
|
279
281
|
```
|
|
@@ -289,7 +291,12 @@ A page that needs only some areas can load the per-area bundles instead: `dist/d
|
|
|
289
291
|
`dist/tests.js`, `dist/linalg.js`, `dist/descriptive.js`, `dist/numerics.js`, `dist/special.js` and
|
|
290
292
|
`dist/mixed.js` export the same functions as the subpaths above, and share their common code through
|
|
291
293
|
`dist/chunks/`, so loading two areas does not load that code twice. With its chunks, one area
|
|
292
|
-
transfers
|
|
294
|
+
transfers 38 KB (`special`) to 206 KB (`tests`) gzipped.
|
|
295
|
+
|
|
296
|
+
Use either `dist/rstats.js` or the per-area bundles on one page, not both: they are separate sets of modules, so a
|
|
297
|
+
page that mixes them loads the common code twice and has two random number states (`setSeed` from one does not seed
|
|
298
|
+
the generators of the other). The same holds for `dist/rstats.js` with `dist/mixed.js`, which brings its own copy
|
|
299
|
+
of the common code.
|
|
293
300
|
|
|
294
301
|
Other npm-based CDNs work as well, for example `https://esm.sh/@numero-uno-jpn/rstats`. Release tags also contain
|
|
295
302
|
the build output (`dist/`), which is not on the main branch, but jsDelivr's GitHub route
|
|
@@ -309,7 +316,27 @@ with a static server (for example `npx serve .`) and open `/demo/?src=local`.
|
|
|
309
316
|
## Versioning
|
|
310
317
|
|
|
311
318
|
While the version is 0.x, a minor release may contain breaking changes; they are listed in the
|
|
312
|
-
changelog.
|
|
319
|
+
changelog.
|
|
320
|
+
|
|
321
|
+
From 1.0.0, rStats.js follows Semantic Versioning. The public API is what the package root and its subpaths export,
|
|
322
|
+
with the documented names, arguments, options, result fields and their types.
|
|
323
|
+
|
|
324
|
+
- **Major** (breaking): removing or renaming an export, an option or a result field; changing a default or the shape
|
|
325
|
+
of a result; throwing for an input that used to return a value, or changing the class of an error
|
|
326
|
+
(`TypeError`, `RangeError`, `SyntaxError`, `Error`); a tighter computation limit; dropping a Node.js version that
|
|
327
|
+
is still supported.
|
|
328
|
+
- **Minor**: new functions, options, overloads or result fields; accepting an input that used to throw; a looser
|
|
329
|
+
computation limit; a value that changes because R (or the package followed) is wrong there and the new value is the
|
|
330
|
+
correct one, recorded in [docs/differences-from-r.md](docs/differences-from-r.md).
|
|
331
|
+
- **Patch**: bug fixes, including values that move toward R or toward the exact result (changes in the last bits
|
|
332
|
+
are not breaking), and changes to documentation.
|
|
333
|
+
- Not part of the API: error messages, the order of keys, the contents of `warnings` and `messages`, non-enumerable
|
|
334
|
+
or undocumented fields, and files under `dist/` other than the entry points and the `dist/*.js` bundles. Where a
|
|
335
|
+
new version of R changes its own values or random streams, rStats.js follows it in a minor version.
|
|
336
|
+
- Code that switches on result fields should allow fields to be added.
|
|
337
|
+
- A key of an options object that the function does not know is a RangeError (also in a nested object such as
|
|
338
|
+
`optim`'s `control`), so a misspelt option cannot be ignored without a sign. A new option is therefore a minor
|
|
339
|
+
change: the key it adds was an error before.
|
|
313
340
|
|
|
314
341
|
## Contributing
|
|
315
342
|
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! rStats.js 0.17.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 Yt,b as Ut}from"./chunk-Z37NELOS.js";import{f as fe,i as ce}from"./chunk-ONY5CISH.js";import{c as Zt}from"./chunk-DXI5N2ET.js";import{l as gt,m as oe,u as ae,v as le}from"./chunk-WM7VFXTV.js";var Ge=Math.pow(Number.EPSILON,.25);function $t(e,t,a,m=Ge){let h=.5*(3-Math.sqrt(5)),s=Math.sqrt(Number.EPSILON),u=t,l=a,c=u+h*(l-u),n=c,i=c,r=0,E=0,o=e(i),M=o,d=o,p=1,F=m/3;for(;;){let v=.5*(u+l),O=s*Math.abs(i)+F,k=2*O;if(Math.abs(i-v)<=k-.5*(l-u))break;let x=!0;if(Math.abs(E)>O){let W=(i-n)*(o-M),G=(i-c)*(o-d),C=(i-c)*G-(i-n)*W;if(G=2*(G-W),G>0?C=-C:G=-G,W=E,E=r,Math.abs(C)<Math.abs(.5*G*W)&&C>G*(u-i)&&C<G*(l-i)){r=C/G;let S=i+r;(S-u<k||l-S<k)&&(r=i<=v?O:-O),x=!1}}x&&(E=i<v?l-i:u-i,r=h*E);let w=Math.abs(r)>=O?i+r:r>=0?i+O:i-O;if(w===i)break;let _=e(w);p++,_<=o?(w<i?l=i:u=i,c=n,M=d,n=i,d=o,i=w,o=_):(w<i?u=w:l=w,_<=d||n===i?(c=n,M=d,n=w,d=_):(_<=M||c===i||c===n)&&(c=w,M=_))}return{x:i,fx:o,evaluations:p}}var _e=["subdivisions","relTol","absTol","stopOnError"],Ce=["maximum","tol"],Ve=["tol","maxiter","extendInt","fLower","fUpper"],he=["OK","maximum number of subdivisions reached","roundoff error was detected","extremely bad integrand behaviour","roundoff error is detected in the extrapolation table","the integral is probably divergent","the input is invalid"],Xt=Number.EPSILON**.25;function ai(e,t,a,m={}){gt(m,_e,"integrate");let h=m.subdivisions??100,s=Math.trunc(h),u=m.relTol??Xt,l=m.absTol??u;if(!(Math.abs(h)<=2147483647)||!Number.isFinite(u)||!Number.isFinite(l)||u<0||l<0)throw new RangeError("invalid parameter values");let c=m.stopOnError??!0;if(Number.isNaN(t)||Number.isNaN(a))throw new RangeError("a limit is NA or NaN");if(s<1||l<=0&&u<Math.max(50*Number.EPSILON,5e-29))throw new RangeError("invalid parameter values");let n=o=>{let M=e(o);if(!Number.isFinite(M))throw new RangeError("non-finite function value");return M};if(t===a&&!Number.isFinite(t))return{value:0,absError:0,subdivisions:0,ier:0,message:he[0]};let i=1;(t===1/0||a===-1/0)&&([t,a]=[a,t],i=-1);let r;if(Number.isFinite(t)&&Number.isFinite(a))if(Number.isFinite(2*Math.max(Math.abs(t),Math.abs(a))))r=Yt(n,t,a,l,u,s);else{let o=l>0?Math.max(l*.5,Number.MIN_VALUE):l*.5,M=Yt(d=>n(2*d),t*.5,a*.5,o,u,s);r={...M,result:2*M.result,abserr:2*M.abserr}}else Number.isFinite(t)?r=Ut(n,t,1,l,u,s):Number.isFinite(a)?r=Ut(n,a,-1,l,u,s):r=Ut(n,0,2,l,u,s);let E=he[r.ier]??"unknown error";if(r.ier===6)throw new RangeError("the input is invalid");if(r.ier!==0&&c)throw new RangeError(E);return{value:i*r.result,absError:r.abserr,subdivisions:r.last,ier:r.ier,message:E}}function me(e,t,a,m={}){gt(m,Ce,"optimize");let h=m.maximum??!1,s=m.tol??Xt;if(!(s>0&&s<1/0))throw new RangeError("'tol' must be a positive finite number");if(!Number.isFinite(t))throw new RangeError("invalid 'xmin' value");if(!Number.isFinite(a))throw new RangeError("invalid 'xmax' value");if(!(t<a))throw new RangeError("'xmin' not less than 'xmax'");let u=c=>{let n=h?-e(c):e(c);return Number.isNaN(n)||n===1/0?Number.MAX_VALUE:n===-1/0?-Number.MAX_VALUE:n},l=Number.isFinite(2*t)&&Number.isFinite(2*a)?$t(u,t,a,s).x:2*$t(c=>u(2*c),t*.5,a*.5,s*.5).x;return{optimum:l,objective:e(l)}}function Be(e){if(e===void 0)return"no";let t=["no","yes","downX","upX"];if(typeof e=="string"&&e.length>0){let a=t.filter(m=>m.startsWith(e));if(a.length===1)return a[0]}throw new RangeError(`'extendInt' should be one of "no", "yes", "downX", "upX"`)}function li(e,t,a,m={}){gt(m,Ve,"uniroot");let h=m.tol??Xt;if(!(h>0&&h<1/0))throw new RangeError("'tol' must be a positive finite number");return We(e,t,a,m)}function We(e,t,a,m={}){let h=m.tol??Xt,s=Math.trunc(m.maxiter??1e3);if(!(h>=0&&h<1/0))throw new RangeError("'tol' must be a non-negative finite number");if(!(s>=1&&s<1/0))throw new RangeError("'maxiter' must be a positive integer");let u=Be(m.extendInt);if(!(t<a))throw new RangeError("lower < upper is not fulfilled");let l=m.fLower??e(t),c=m.fUpper??e(a);if(Number.isNaN(l))throw new RangeError("f.lower = f(lower) is NA");if(Number.isNaN(c))throw new RangeError("f.upper = f(upper) is NA");let n=O=>Math.max(-Number.MAX_VALUE,Math.min(Number.MAX_VALUE,O)),i=O=>.01*Math.max(1e-4,Math.abs(O)),r=u==="downX"?-1:u==="upX"?1:0,E=(O,k)=>Math.sign(O)*Math.sign(k)>0,o=u==="yes"?E(l,c):r!==0&&(r*n(l)>0||r*n(c)<0),M=0,d=()=>{if(++M>s)throw new RangeError(`no sign change found in ${M-1} iterations`)};if(o&&u==="yes"){let O=i(t),k=i(a);for(;E(l,c)&&(Number.isFinite(t)||Number.isFinite(a));){if(d(),Number.isFinite(t)){let x=t-O,w=e(x);Number.isNaN(w)?O/=4:[t,l]=[x,w]}if(Number.isFinite(a)){let x=a+k,w=e(x);Number.isNaN(w)?k/=4:[a,c]=[x,w]}O*=2,k*=2}}else if(o){let O=i(t);for(;r*l>0&&Number.isFinite(t);)d(),t-=O,l=e(t),O*=2;for(O=i(a);r*c<0&&Number.isFinite(a);)d(),a+=O,c=e(a),O*=2}if(!(Math.sign(l)*Math.sign(c)<=0))throw new RangeError(o?"did not succeed extending the interval endpoints for f(lower) * f(upper) <= 0":"f() values at end points not of opposite sign");if(!Number.isFinite(t))throw new RangeError("invalid 'xmin' value");if(!Number.isFinite(a))throw new RangeError("invalid 'xmax' value");let p=!Number.isFinite(a-t),F=p?ue(O=>kt(e(2*O)),t*.5,a*.5,kt(l),kt(c),h*.5,s):ue(O=>kt(e(O)),t,a,kt(l),kt(c),h,s),v=p?{...F,root:2*F.root,estimPrec:2*F.estimPrec}:F;return{root:v.root,fRoot:e(v.root),iter:o?v.iter+M:v.iter,initIt:o?M:NaN,estimPrec:v.estimPrec}}function kt(e){return e===-1/0?-Number.MAX_VALUE:e===1/0||Number.isNaN(e)?Number.MAX_VALUE:e}function ue(e,t,a,m,h,s,u){if(m===0)return{root:t,iter:0,estimPrec:0};if(h===0)return{root:a,iter:0,estimPrec:0};let l=Number.EPSILON,c=t,n=a,i=m,r=h,E=c,o=i,M=n-c,d=M;for(let p=0;p<=u;p++){d=n-c,Math.abs(o)<Math.abs(r)&&(c=n,n=E,E=c,i=r,r=o,o=i);let F=2*l*Math.abs(n)+.5*s,v=.5*(E-n);if(Math.abs(v)<=F||r===0)return{root:n,iter:p,estimPrec:Math.abs(E-n)};if(Math.abs(d)>=F&&Math.abs(i)>Math.abs(r)){let O=r/i,k,x;if(c===E)k=2*v*O,x=1-O;else{x=i/o;let w=r/o;k=O*(2*v*x*(x-w)-(n-c)*(w-1)),x=(x-1)*(w-1)*(O-1)}k>0?x=-x:k=-k,O=d,d=M,2*k>=3*v*x-Math.abs(F*x)||k>=Math.abs(.5*O*x)?(M=v,d=M):M=k/x}else M=v,d=M;c=n,i=r,Math.abs(M)>F?n+=M:v>0?n+=F:n-=F,r=e(n),r*(o/Math.abs(o))>0&&(E=c,o=i,M=n-c,d=M)}return{root:n,iter:u,estimPrec:Math.abs(E-n)}}var de=2220446049250313e-31;function lt(e,t,a,m,h){let s=0;for(let u=0;u<e;u++)s+=t[a+u]*m[h+u];return s}function At(e,t,a,m,h,s){if(!(e<=0||t===0))for(let u=0;u<e;u++)h[s+u]=h[s+u]+t*a[m+u]}function ot(e,t,a,m,h){for(let s=0;s<e;s++)m[h+s]=t[a+s]}function ge(e,t,a,m){for(let h=0;h<e;h++)a[m+h]=t*a[m+h]}function Jt(e,t,a,m){let h=(s,u)=>t+s+(u-1)*a;for(let s=1;s<=m;s++){let u=0;for(let l=1;l<=s-1;l++){let c=e[h(l,s)]-lt(l-1,e,h(1,l),e,h(1,s));c=c/e[h(l,l)],e[h(l,s)]=c,u=u+c*c}if(u=e[h(s,s)]-u,u<=0)return s;e[h(s,s)]=Math.sqrt(u)}return 0}function _t(e,t,a,m,h,s,u){let l=(n,i)=>t+n+(i-1)*a;for(let n=1;n<=m;n++)if(e[l(n,n)]===0)return n;let c=1;if(u%10!==0&&(c=2),Math.trunc(u%100/10)!==0&&(c+=2),c===1){h[s+1]=h[s+1]/e[l(1,1)];for(let n=2;n<=m;n++){let i=-h[s+n-1];At(m-n+1,i,e,l(n,n-1),h,s+n),h[s+n]=h[s+n]/e[l(n,n)]}}else if(c===2){h[s+m]=h[s+m]/e[l(m,m)];for(let n=2;n<=m;n++){let i=m-n+1,r=-h[s+i+1];At(i,r,e,l(1,i+1),h,s+1),h[s+i]=h[s+i]/e[l(i,i)]}}else if(c===3){h[s+m]=h[s+m]/e[l(m,m)];for(let n=2;n<=m;n++){let i=m-n+1;h[s+i]=h[s+i]-lt(n-1,e,l(i+1,i),h,s+i+1),h[s+i]=h[s+i]/e[l(i,i)]}}else{h[s+1]=h[s+1]/e[l(1,1)];for(let n=2;n<=m;n++)h[s+n]=h[s+n]-lt(n-1,e,l(1,n),h,s+1),h[s+n]=h[s+n]/e[l(n,n)]}return 0}function Ne(e,t,a,m,h){let{stx:s,fx:u,dx:l,sty:c,fy:n,dy:i,stp:r}=e,E=a*(l/Math.abs(l)),o;if(t>u){let M=3*(u-t)/(r-s)+l+a,d=Math.max(Math.abs(M),Math.abs(l),Math.abs(a)),p=d*Math.sqrt(M/d*(M/d)-l/d*(a/d));r<s&&(p=-p);let F=p-l+M,v=p-l+p+a,O=F/v,k=s+O*(r-s),x=s+l/((u-t)/(r-s)+l)/2*(r-s);Math.abs(k-s)<Math.abs(x-s)?o=k:o=k+(x-k)/2,e.brackt=!0}else if(E<0){let M=3*(u-t)/(r-s)+l+a,d=Math.max(Math.abs(M),Math.abs(l),Math.abs(a)),p=d*Math.sqrt(M/d*(M/d)-l/d*(a/d));r>s&&(p=-p);let F=p-a+M,v=p-a+p+l,O=F/v,k=r+O*(s-r),x=r+a/(a-l)*(s-r);Math.abs(k-r)>Math.abs(x-r)?o=k:o=x,e.brackt=!0}else if(Math.abs(a)<Math.abs(l)){let M=3*(u-t)/(r-s)+l+a,d=Math.max(Math.abs(M),Math.abs(l),Math.abs(a)),p=d*Math.sqrt(Math.max(0,M/d*(M/d)-l/d*(a/d)));r>s&&(p=-p);let F=p-a+M,v=p+(l-a)+p,O=F/v,k;O<0&&p!==0?k=r+O*(s-r):r>s?k=h:k=m;let x=r+a/(a-l)*(s-r);e.brackt?(Math.abs(k-r)<Math.abs(x-r)?o=k:o=x,r>s?o=Math.min(r+.66*(c-r),o):o=Math.max(r+.66*(c-r),o)):(Math.abs(k-r)>Math.abs(x-r)?o=k:o=x,o=Math.min(h,o),o=Math.max(m,o))}else if(e.brackt){let M=3*(t-n)/(c-r)+i+a,d=Math.max(Math.abs(M),Math.abs(i),Math.abs(a)),p=d*Math.sqrt(M/d*(M/d)-i/d*(a/d));r>c&&(p=-p);let F=p-a+M,v=p-a+p+i,O=F/v;o=r+O*(c-r)}else r>s?o=h:o=m;t>u?(e.sty=r,e.fy=t,e.dy=a):(E<0&&(e.sty=s,e.fy=u,e.dy=l),e.stx=r,e.fx=t,e.dx=a),e.stp=o}var Qt=class{brackt=!1;stage=1;ginit=0;gtest=0;gx=0;gy=0;finit=0;fx=0;fy=0;stx=0;sty=0;stmin=0;stmax=0;width=0;width1=0;call(t,a,m,h,s,u,l,c,n){let i=m,r=n;if(r.startsWith("START"))return i<l&&(r="ERROR: STP .LT. STPMIN"),i>c&&(r="ERROR: STP .GT. STPMAX"),a>=0&&(r="ERROR: INITIAL G .GE. ZERO"),h<0&&(r="ERROR: FTOL .LT. ZERO"),s<0&&(r="ERROR: GTOL .LT. ZERO"),u<0&&(r="ERROR: XTOL .LT. ZERO"),l<0&&(r="ERROR: STPMIN .LT. ZERO"),c<l&&(r="ERROR: STPMAX .LT. STPMIN"),r.startsWith("ERROR")?{stp:i,task:r}:(this.brackt=!1,this.stage=1,this.finit=t,this.ginit=a,this.gtest=h*this.ginit,this.width=c-l,this.width1=this.width/.5,this.stx=0,this.fx=this.finit,this.gx=this.ginit,this.sty=0,this.fy=this.finit,this.gy=this.ginit,this.stmin=0,this.stmax=i+4*i,{stp:i,task:"FG"});let E=this.finit+i*this.gtest;if(this.stage===1&&t<=E&&a>=0&&(this.stage=2),this.brackt&&(i<=this.stmin||i>=this.stmax)&&(r="WARNING: ROUNDING ERRORS PREVENT PROGRESS"),this.brackt&&this.stmax-this.stmin<=u*this.stmax&&(r="WARNING: XTOL TEST SATISFIED"),i===c&&t<=E&&a<=this.gtest&&(r="WARNING: STP = STPMAX"),i===l&&(t>E||a>=this.gtest)&&(r="WARNING: STP = STPMIN"),t<=E&&Math.abs(a)<=s*-this.ginit&&(r="CONVERGENCE"),r.startsWith("WARN")||r.startsWith("CONV"))return{stp:i,task:r};let o={stx:this.stx,fx:this.fx,dx:this.gx,sty:this.sty,fy:this.fy,dy:this.gy,stp:i,brackt:this.brackt};if(this.stage===1&&t<=this.fx&&t>E){let M=t-i*this.gtest;o.fx=this.fx-this.stx*this.gtest,o.fy=this.fy-this.sty*this.gtest;let d=a-this.gtest;o.dx=this.gx-this.gtest,o.dy=this.gy-this.gtest,Ne(o,M,d,this.stmin,this.stmax),this.stx=o.stx,this.sty=o.sty,this.fx=o.fx+o.stx*this.gtest,this.fy=o.fy+o.sty*this.gtest,this.gx=o.dx+this.gtest,this.gy=o.dy+this.gtest}else Ne(o,t,a,this.stmin,this.stmax),this.stx=o.stx,this.sty=o.sty,this.fx=o.fx,this.fy=o.fy,this.gx=o.dx,this.gy=o.dy;return this.brackt=o.brackt,i=o.stp,this.brackt&&(Math.abs(this.sty-this.stx)>=.66*this.width1&&(i=this.stx+.5*(this.sty-this.stx)),this.width1=this.width,this.width=Math.abs(this.sty-this.stx)),this.brackt?(this.stmin=Math.min(this.stx,this.sty),this.stmax=Math.max(this.stx,this.sty)):(this.stmin=i+1.1*(i-this.stx),this.stmax=i+4*(i-this.stx)),i=Math.max(i,l),i=Math.min(i,c),(this.brackt&&(i<=this.stmin||i>=this.stmax)||this.brackt&&this.stmax-this.stmin<=u*this.stmax)&&(i=this.stx),{stp:i,task:"FG"}}};function be(e,t,a,m,h,s,u,l,c,n){let i=f=>new Float64Array(f+1),r=i(e),E=i(e),o=i(e),M=i(e),d=new Int32Array(e+1);for(let f=1;f<=e;f++)r[f]=a[f-1],E[f]=m[f-1],o[f]=h[f-1],d[f]=s[f-1];let p=2*t,F=new Float64Array(e*t+1),v=new Float64Array(e*t+1),O=new Float64Array(t*t+1),k=new Float64Array(t*t+1),x=new Float64Array(t*t+1),w=new Float64Array(p*p+1),_=new Float64Array(p*p+1),W=i(e),G=i(e),C=i(e),S=i(e),g=new Float64Array(8*t+1),P=new Int32Array(e+1),H=new Int32Array(e+1),D=new Int32Array(e+1),q=(f,R)=>f+(R-1)*e,$=(f,R)=>f+(R-1)*t,z=(f,R)=>f+(R-1)*p,Nt=0,A=0,J=1,it=1,mt=0,xt=!1,bt=0,dt=0,Ct=0,ct=e,Et=0,Mt=0,Ft=0,yt=0,wt=0,st=0,Vt=0,pt=0,It=0,at=0,ht=0,ee=0,Bt=0,St=0,Lt=!1,ie=!0,Re=u*de,vt=f=>({x:Array.from(r.subarray(1)),f:Nt,task:f,nfgv:dt}),se=()=>{let f=c(Array.from(r.subarray(1)));Nt=f.f;for(let R=1;R<=e;R++)M[R]=f.g[R-1]},ft="START";e<=0&&(ft="ERROR: N .LE. 0"),t<=0&&(ft="ERROR: M .LE. 0"),u<0&&(ft="ERROR: FACTR .LT. 0");for(let f=1;f<=e;f++)(d[f]<0||d[f]>3)&&(ft="ERROR: INVALID NBD"),d[f]===2&&E[f]>o[f]&&(ft="ERROR: NO FEASIBLE SOLUTION");if(ft.startsWith("ERROR"))return vt(ft);for(let f=1;f<=e;f++)d[f]>0&&(d[f]<=2&&r[f]<=E[f]?r[f]<E[f]&&(r[f]=E[f]):d[f]>=2&&r[f]>=o[f]&&r[f]>o[f]&&(r[f]=o[f]));for(let f=1;f<=e;f++)d[f]!==2&&(ie=!1),d[f]===0?H[f]=-1:(Lt=!0,H[f]=d[f]===2&&o[f]-E[f]<=0?3:0);let ne=()=>{let f=0;for(let R=1;R<=e;R++){let b=M[R];d[R]!==0&&(b<0?d[R]>=2&&(b=Math.max(r[R]-o[R],b)):d[R]<=2&&(b=Math.min(r[R]-E[R],b))),f=Math.max(f,Math.abs(b))}return f},Dt=(f,R,b,T)=>{if(A===0)return 0;b[T+A+1]=f[R+A+1];for(let N=2;N<=A;N++){let I=A+N,y=0;for(let L=1;L<=N-1;L++)y=y+O[$(N,L)]*f[R+L]/O[$(L,L)];b[T+I]=f[R+I]+y}let V=_t(x,0,t,A,b,T+A,11);if(V!==0)return V;for(let N=1;N<=A;N++)b[T+N]=f[R+N]/Math.sqrt(O[$(N,N)]);if(V=_t(x,0,t,A,b,T+A,1),V!==0)return V;for(let N=1;N<=A;N++)b[T+N]=-b[T+N]/Math.sqrt(O[$(N,N)]);for(let N=1;N<=A;N++){let I=0;for(let y=N+1;y<=A;y++)I=I+O[$(y,N)]*b[T+A+y]/O[$(N,N)];b[T+N]=b[T+N]+I}return 0},xe=(f,R)=>{if(R===0)for(let b=2;b<=f;b++){let T=S[b],V=D[b],N=b;for(;N>1;){let I=Math.trunc(N/2);if(T<S[I])S[N]=S[I],D[N]=D[I],N=I;else break}S[N]=T,D[N]=V}if(f>1){let b=1,T=S[1],V=D[1],N=S[f],I=D[f];for(;;){let y=b+b;if(y<=f-1&&(S[y+1]<S[y]&&(y=y+1),S[y]<N)){S[b]=S[y],D[b]=D[y],b=y;continue}break}S[b]=N,D[b]=I,S[f]=T,D[f]=V}},ye=()=>{let R=2*t,b=4*t,T=6*t;if(St<=0)return ot(e,r,1,W,1),0;let V=!0,N=e+1,I=0,y=0,L=0,X=2*A,B=0;for(let j=1;j<=X;j++)g[0+j]=0;let K=0,Q=0;for(let j=1;j<=e;j++){let Y=-M[j];if(H[j]!==3&&H[j]!==-1){d[j]<=2&&(K=r[j]-E[j]),d[j]>=2&&(Q=o[j]-r[j]);let tt=d[j]<=2&&K<=0,et=d[j]>=2&&Q<=0;H[j]=0,tt?Y<=0&&(H[j]=1):et?Y>=0&&(H[j]=2):Math.abs(Y)<=0&&(H[j]=-3)}let rt=J;if(H[j]!==0&&H[j]!==-1)C[j]=0;else{C[j]=Y,B=B-Y*Y;for(let tt=1;tt<=A;tt++)g[0+tt]=g[0+tt]+v[q(j,rt)]*Y,g[0+A+tt]=g[0+A+tt]+F[q(j,rt)]*Y,rt=rt%t+1;d[j]<=2&&d[j]!==0&&Y<0?(I=I+1,D[I]=j,S[I]=K/-Y,(I===1||S[I]<L)&&(L=S[I],y=I)):d[j]>=2&&Y>0?(I=I+1,D[I]=j,S[I]=Q/Y,(I===1||S[I]<L)&&(L=S[I],y=I)):(N=N-1,D[N]=j,Math.abs(Y)>0&&(V=!1))}}if(it!==1&&ge(A,it,g,0+A+1),ot(e,r,1,W,1),I===0&&N===e+1)return 0;for(let j=1;j<=X;j++)g[R+j]=0;let nt=-it*B;if(A>0){let j=Dt(g,0,g,T);if(j!==0)return j;nt=nt-lt(X,g,T+1,g,1)}let U=-B/nt,Z=0;Ct=1;let ut=!1;if(I!==0){let j=I,Y=1,rt=0;for(;;){let tt=rt,et;Y===1?(rt=L,et=D[y]):(Y===2&&y!==I&&(S[y]=S[I],D[y]=D[I]),xe(j,Y-2),rt=S[j],et=D[j]);let Gt=rt-tt;if(U<Gt)break;Z=Z+Gt,j=j-1,Y=Y+1;let Rt=C[et];C[et]=0;let zt;if(Rt>0?(zt=o[et]-r[et],W[et]=o[et],H[et]=2):(zt=E[et]-r[et],W[et]=E[et],H[et]=1),j===0&&I===e){U=Gt,ut=!0;break}Ct=Ct+1;let Kt=Rt*Rt;if(B=B+Gt*nt+Kt-it*Rt*zt,nt=nt-it*Kt,A>0){At(X,Gt,g,1,g,R+1);let Wt=J;for(let qt=1;qt<=A;qt++)g[b+qt]=v[q(et,Wt)],g[b+A+qt]=it*F[q(et,Wt)],Wt=Wt%t+1;let re=Dt(g,b,g,T);if(re!==0)return re;let Le=lt(X,g,R+1,g,T+1),Pe=lt(X,g,1,g,T+1),je=lt(X,g,b+1,g,T+1);At(X,-Rt,g,b+1,g,1),B=B+Rt*Le,nt=nt+2*Rt*Pe-Kt*je}if(j>0){U=-B/nt;continue}else V?(B=0,nt=0,U=0):U=-B/nt;break}}return ut||(U<=0&&(U=0),Z=Z+U,At(e,Z,C,1,W,1)),A>0&&At(X,U,g,1,g,R+1),0},pe=()=>{if(Mt=0,Et=e+1,bt>0&&Lt){for(let b=1;b<=ct;b++){let T=P[b];H[T]>0&&(Et=Et-1,D[Et]=T)}for(let b=1+ct;b<=e;b++){let T=P[b];H[T]<=0&&(Mt=Mt+1,D[Mt]=T)}}let f=Et<e+1||Mt>0||xt;ct=0;let R=e+1;for(let b=1;b<=e;b++)H[b]<=0?(ct=ct+1,P[ct]=b):(R=R-1,P[R]=b);return f},ve=()=>{let f=ct,R;if(xt){if(mt>t)for(let U=1;U<=t-1;U++){let Z=t+U;ot(t-U,_,z(U+1,U+1),_,z(U,U)),ot(t-U,_,z(Z+1,Z+1),_,z(Z,Z)),ot(t-1,_,z(t+2,U+1),_,z(t+1,U))}let N=1,I=f,y=f+1,L=e,X=A,B=t+A,K=J+A-1;K>t&&(K=K-t);let Q=J;for(let U=1;U<=A;U++){let Z=t+U,ut=0,j=0,Y=0;for(let rt=N;rt<=I;rt++){let tt=P[rt];ut=ut+v[q(tt,K)]*v[q(tt,Q)]}for(let rt=y;rt<=L;rt++){let tt=P[rt];j=j+F[q(tt,K)]*F[q(tt,Q)],Y=Y+F[q(tt,K)]*v[q(tt,Q)]}_[z(X,U)]=ut,_[z(B,Z)]=j,_[z(B,U)]=Y,Q=Q%t+1}let nt=A;Q=J+A-1,Q>t&&(Q=Q-t),K=J;for(let U=1;U<=A;U++){let Z=t+U,ut=0;for(let j=N;j<=I;j++){let Y=P[j];ut=ut+F[q(Y,K)]*v[q(Y,Q)]}K=K%t+1,_[z(Z,nt)]=ut}R=A-1}else R=A;let b=J;for(let N=1;N<=R;N++){let I=t+N,y=J;for(let L=1;L<=N;L++){let X=t+L,B=0,K=0,Q=0,nt=0;for(let U=1;U<=Mt;U++){let Z=D[U];B=B+v[q(Z,b)]*v[q(Z,y)],K=K+F[q(Z,b)]*F[q(Z,y)]}for(let U=Et;U<=e;U++){let Z=D[U];Q=Q+v[q(Z,b)]*v[q(Z,y)],nt=nt+F[q(Z,b)]*F[q(Z,y)]}_[z(N,L)]=_[z(N,L)]+B-Q,_[z(I,X)]=_[z(I,X)]-K+nt,y=y%t+1}b=b%t+1}b=J;for(let N=t+1;N<=t+R;N++){let I=J;for(let y=1;y<=R;y++){let L=0,X=0;for(let B=1;B<=Mt;B++){let K=D[B];L=L+F[q(K,b)]*v[q(K,I)]}for(let B=Et;B<=e;B++){let K=D[B];X=X+F[q(K,b)]*v[q(K,I)]}N<=y+t?_[z(N,y)]=_[z(N,y)]+L-X:_[z(N,y)]=_[z(N,y)]-L+X,I=I%t+1}b=b%t+1}for(let N=1;N<=A;N++){let I=A+N,y=t+N;for(let L=1;L<=N;L++){let X=A+L,B=t+L;w[z(L,N)]=_[z(N,L)]/it,w[z(X,I)]=_[z(y,B)]*it}for(let L=1;L<=N-1;L++)w[z(L,I)]=-_[z(y,L)];for(let L=N;L<=A;L++)w[z(L,I)]=_[z(y,L)];w[z(N,N)]=w[z(N,N)]+O[$(N,N)]}let T=Jt(w,0,p,A);if(T!==0)return-1;let V=2*A;for(let N=A+1;N<=V;N++)_t(w,0,p,A,w,z(1,N)-1,11);for(let N=A+1;N<=V;N++)for(let I=N;I<=V;I++)w[z(N,I)]=w[z(N,I)]+lt(A,w,z(1,N),w,z(1,I));return T=Jt(w,A+A*p,p,A),T!==0?-2:0},ke=()=>{if(!Lt&&A>0)for(let f=1;f<=e;f++)G[f]=-M[f];else{for(let b=1;b<=ct;b++){let T=P[b];G[b]=-it*(W[T]-r[T])-M[T]}if(Dt(g,2*t,g,0)!==0)return-8;let R=J;for(let b=1;b<=A;b++){let T=g[b],V=it*g[A+b];for(let N=1;N<=ct;N++){let I=P[N];G[N]=G[N]+v[q(I,R)]*T+F[q(I,R)]*V}R=R%t+1}}return 0},Ae=()=>{let f=ct;if(f<=0)return 0;let R=J;for(let y=1;y<=A;y++){let L=0,X=0;for(let B=1;B<=f;B++){let K=P[B];L=L+v[q(K,R)]*G[B],X=X+F[q(K,R)]*G[B]}g[y]=L,g[A+y]=it*X,R=R%t+1}let b=2*A,T=_t(w,0,p,b,g,0,11);if(T!==0)return T;for(let y=1;y<=A;y++)g[y]=-g[y];if(T=_t(w,0,p,b,g,0,1),T!==0)return T;R=J;for(let y=1;y<=A;y++){let L=A+y;for(let X=1;X<=f;X++){let B=P[X];G[X]=G[X]+v[q(B,R)]*g[y]/it+F[q(B,R)]*g[L]}R=R%t+1}for(let y=1;y<=f;y++)G[y]=G[y]/it;let V=1,N=V,I=0;for(let y=1;y<=f;y++){let L=P[y],X=G[y];if(d[L]!==0){if(X<0&&d[L]<=2){let B=E[L]-W[L];B>=0?N=0:X*V<B&&(N=B/X)}else if(X>0&&d[L]>=2){let B=o[L]-W[L];B<=0?N=0:X*V>B&&(N=B/X)}N<V&&(V=N,I=y)}}if(V<1){let y=G[I],L=P[I];y>0?(W[L]=o[L],G[I]=0):y<0&&(W[L]=E[L],G[I]=0)}for(let y=1;y<=f;y++){let L=P[y];W[L]=W[L]+V*G[y]}return 0},Oe=(f,R)=>{if(mt<=t?(A=mt,Ft=(J+mt-2)%t+1):(Ft=Ft%t+1,J=J%t+1),ot(e,C,1,F,q(1,Ft)),ot(e,G,1,v,q(1,Ft)),it=f/R,mt>t)for(let T=1;T<=A-1;T++)ot(T,k,$(2,T+1),k,$(1,T)),ot(A-T,O,$(T+1,T+1),O,$(T,T));let b=J;for(let T=1;T<=A-1;T++)O[$(A,T)]=lt(e,C,1,v,q(1,b)),k[$(T,A)]=lt(e,F,q(1,b),C,1),b=b%t+1;at===1?k[$(A,A)]=Bt:k[$(A,A)]=at*at*Bt,O[$(A,A)]=R},Te=()=>{for(let f=1;f<=A;f++)x[$(1,f)]=it*k[$(1,f)];for(let f=2;f<=A;f++)for(let R=f;R<=A;R++){let b=Math.min(f,R)-1,T=0;for(let V=1;V<=b;V++)T=T+O[$(f,V)]*O[$(R,V)]/O[$(V,V)];x[$(f,R)]=T+it*k[$(f,R)]}return Jt(x,0,t,A)!==0?-3:0},Fe=new Qt,Pt="START",Ie=()=>{if(Bt=lt(e,C,1,C,1),ee=Math.sqrt(Bt),ht=1e10,Lt)if(bt===0)ht=1;else for(let f=1;f<=e;f++){let R=C[f];if(d[f]!==0){if(R<0&&d[f]<=2){let b=E[f]-r[f];b>=0?ht=0:R*ht<b&&(ht=b/R)}else if(R>0&&d[f]>=2){let b=o[f]-r[f];b<=0?ht=0:R*ht>b&&(ht=b/R)}}}bt===0&&!ie?at=Math.min(1/ee,ht):at=1,ot(e,r,1,S,1),ot(e,M,1,G,1),Vt=Nt,wt=0,yt=0,Pt="START"},Se=()=>{if(pt=lt(e,M,1,C,1),wt===0&&(It=pt,pt>=0))return st=-4,ft;let f=Fe.call(Nt,pt,at,.001,.9,.1,0,ht,Pt);if(at=f.stp,Pt=f.task,!Pt.startsWith("CONV")&&!Pt.startsWith("WARN")){if(wt=wt+1,dt=dt+1,yt=wt-1,at===1)ot(e,W,1,r,1);else for(let R=1;R<=e;R++)r[R]=at*C[R]+S[R];return"FG_LNSRCH"}return"NEW_X"},jt=()=>{st=0,A=0,J=1,it=1,mt=0,xt=!1};if(ft="FG_START",se(),dt=1,St=ne(),St<=l)return vt("CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL");for(;;){let f;if(!Lt&&A>0)ot(e,r,1,W,1),f=xt,Ct=0;else{if(st=ye(),st!==0){jt();continue}f=pe()}if(!(ct===0||A===0)){if(f&&(st=ve()),st!==0){jt();continue}if(st=ke(),st===0&&(st=Ae()),st!==0){jt();continue}}for(let V=1;V<=e;V++)C[V]=W[V]-r[V];for(Ie();ft=Se(),!(st!==0||yt>=20||ft!=="FG_LNSRCH");)se();if(st!==0||yt>=20){if(ot(e,S,1,r,1),ot(e,G,1,M,1),Nt=Vt,A===0)return st===0&&(st=-9,dt=dt-1,wt=wt-1,yt=yt-1),bt=bt+1,vt("ABNORMAL_TERMINATION_IN_LNSRCH");st===0&&(dt=dt-1),jt(),ft="RESTART_FROM_LNSRCH";continue}if(bt=bt+1,St=ne(),n())return vt("NEW_X");if(St<=l)return vt("CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL");let R=Math.max(Math.abs(Vt),Math.abs(Nt),1);if(Vt-Nt<=Re*R)return vt("CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH");for(let V=1;V<=e;V++)G[V]=M[V]-G[V];let b=lt(e,G,1,G,1),T;if(at===1?(T=pt-It,R=-It):(T=(pt-It)*at,ge(e,at,C,1),R=-It*at),T<=de*R){xt=!1;continue}xt=!0,mt=mt+1,Oe(b,T),st=Te(),st!==0&&jt()}}var qe=["gr","method","lower","upper","hessian","control"],Ue=new Set(["maxit","reltol","abstol","parscale","fnscale","ndeps","alpha","beta","gamma","type","lmm","factr","pgtol","temp","tmax"]),Xe=new Set(["maxit","reltol","abstol","parscale","fnscale","ndeps","alpha","beta","gamma","type","lmm","factr","pgtol","temp","tmax"]),Ee=10,He=1e-4,De=.2,ze=1.7,Ke=1e35,Ye=1.7182818;function Ot(e,t,a){if(e===void 0)return new Array(t).fill(a);let m=typeof e=="number"?[e]:e;if(m.length===0)throw new RangeError("argument of length 0");return Array.from({length:t},(h,s)=>m[s%m.length])}function Me(e){for(let t of e)if(!Number.isFinite(t))throw new Error("non-finite value supplied by optim")}var Ht=class{fn;gr;parscale;fnscale;ndeps;n;constructor(t,a,m,h,s){if(this.fn=t,this.gr=a,this.parscale=m,this.fnscale=h,this.ndeps=s,h===1/0||h===-1/0)throw new RangeError("'fnscale' must not be infinite");this.n=m.length}unscale(t){return t.map((a,m)=>a*this.parscale[m])}f(t){return Me(t),this.fn(this.unscale(t))/this.fnscale}g(t,a,m){let{n:h,parscale:s,fnscale:u}=this;if(this.gr!==void 0){Me(t);let n=this.gr(this.unscale(t));if(n.length!==h)throw new RangeError(`gradient in optim evaluated to length ${n.length} not ${h}`);for(let i=0;i<h;i++)if(!Number.isFinite(n[i]))throw new Error(`non-finite value of the gradient [${i+1}] supplied by 'gr'`);return n.map((i,r)=>{let E=i*s[r];return Number.isFinite(E)?E/u:i/u*s[r]})}let l=this.unscale(t),c=new Array(h);for(let n=0;n<h;n++){let i=this.ndeps[n],r=t[n]+i,E=t[n]-i,o;if(a===void 0||m===void 0)o=2*i;else{let p=i,F=i;r>m[n]&&(r=m[n],p=r-t[n]),E<a[n]&&(E=a[n],F=t[n]-E),o=p+F}l[n]=r*s[n];let M=this.fn(l.slice())/u;l[n]=E*s[n];let d=this.fn(l.slice())/u;if(c[n]=(M-d)/o,!Number.isFinite(c[n]))throw new Error(`non-finite finite-difference value [${n+1}]`);l[n]=t[n]*s[n]}return c}},Tt=e=>Number.isFinite(e)?e:Ke,Ze=(e,t)=>Ee+e===Ee+t;function we(e,t,a,m,h,s,u,l){let c=t.length,n=s,i=l,r=0;for(;;){let E=0;for(let o=0;o<c;o++)u[o]=t[o]+n*a[o],Ze(t[o],u[o])&&E++;if(E===c)return{step:n,accepted:!1,value:i,evals:r};if(i=e.f(u),r++,Number.isFinite(i)&&i<=h+m*n*He)return{step:n,accepted:!0,value:i,evals:r};n*=De}}function $e(e,t,a,m,h,s,u,l){let c=t.length;if(l<=0)return{par:t.slice(),value:e.f(t),fnEvals:0,gradEvals:NaN,code:0};let n=e.f(t);if(!Number.isFinite(n))throw new Error("function cannot be evaluated at initial parameters");let i=1,r=u*(Math.abs(n)+u),E=[t.slice()],o=[n],M=0;for(let k of t).1*Math.abs(k)>M&&(M=.1*Math.abs(k));M===0&&(M=.1);let d=0;for(let k=0;k<c;k++){let x=t.slice(),w=M;for(x[k]=t[k]+w;x[k]===t[k];)w*=10,x[k]=t[k]+w;d+=w,E.push(x),o.push(NaN)}let p=d,F=0,v=0,O=new Array(c);do{for(let g=0;g<=c;g++)g!==F&&Number.isNaN(o[g])&&(o[g]=Tt(e.f(E[g])),i++);let k=o[F],x=k,w=F;for(let g=0;g<=c;g++){if(g===F)continue;let P=o[g];P<k&&(F=g,k=P),P>x&&(w=g,x=P)}if(x<=k+r||k<=s)break;let _=E[w];for(let g=0;g<c;g++){let P=-_[g];for(let H of E)P+=H[g];O[g]=P/c}let W=O.map((g,P)=>(1+a)*g-a*_[P]),G=Tt(e.f(W));if(i++,G<k){let g=W.map((D,q)=>h*D+(1-h)*O[q]),P=Tt(e.f(g));i++;let H=P<G;E[w]=H?g:W,o[w]=H?P:G;continue}G<x&&(E[w]=W,o[w]=G);let C=E[w].map((g,P)=>(1-m)*g+m*O[P]),S=Tt(e.f(C));if(i++,S<o[w])E[w]=C,o[w]=S;else if(G>=x){let g=E[F];if(d=0,E.forEach((P,H)=>{if(H!==F){for(let D=0;D<c;D++)P[D]=m*(P[D]-g[D])+g[D],d+=Math.abs(P[D]-g[D]);o[H]=NaN}}),!(d<p)){v=10;break}p=d}}while(i<=l);return v!==10&&i>l&&(v=1),{par:E[F].slice(),value:o[F],fnEvals:i,gradEvals:NaN,code:v}}function Je(e,t,a,m,h){let s=t.length,u=t.slice();if(h<=0)return{par:u,value:e.f(u),fnEvals:0,gradEvals:0,code:0};let l=e.f(u);if(!Number.isFinite(l))throw new Error("initial value in 'vmmin' is not finite");let c=l,n=1,i=1,r=e.g(u),E=i,o=Array.from({length:s},(k,x)=>new Array(x+1).fill(0)),M=(k,x)=>x<=k?o[k][x]:o[x][k],d=new Array(s).fill(0),p=new Array(s).fill(0),F=new Array(s).fill(0),v=!1,O=!1;do{if(E===i)for(let w=0;w<s;w++)o[w].fill(0),o[w][w]=1;for(let w=0;w<s;w++)p[w]=u[w];let k=r.slice(),x=0;for(let w=0;w<s;w++){let _=0;for(let W=0;W<s;W++)_-=M(w,W)*r[W];d[w]=_,x+=_*r[w]}if(x<0){let w=we(e,p,d,x,c,1,u,l);n+=w.evals,l=w.value;let _=w.accepted;if(l>a&&Math.abs(l-c)>m*(Math.abs(c)+m)||(_=!1,c=l),_){c=l,r=e.g(u),i++;let W=k,G=0;for(let C=0;C<s;C++)d[C]=w.step*d[C],W[C]=r[C]-W[C],G+=d[C]*W[C];if(G>0){let C=0;for(let g=0;g<s;g++){let P=0;for(let H=0;H<s;H++)P+=M(g,H)*W[H];F[g]=P,C+=P*W[g]}let S=1+C/G;for(let g=0;g<s;g++)for(let P=0;P<=g;P++)o[g][P]=o[g][P]+(S*d[g]*d[P]-F[g]*d[P]-d[g]*F[P])/G}else E=i;v=!1}else v=E===i,E=i}else v=E===i,E=i;if(i>=h){O=!0;break}i-E>2*s&&(E=i)}while(!v||E!==i);return{par:u,value:c,fnEvals:n,gradEvals:i,code:O?1:0}}function Qe(e,t,a,m,h,s){let u=t.length,l=t.slice();if(s<=0)return{par:l,value:e.f(l),fnEvals:0,gradEvals:0,code:0};if(a!==1&&a!==2&&a!==3)throw new RangeError(`unknown 'type' in "CG" method of 'optim'`);let c=h*u*Math.sqrt(h),n=e.f(l);if(!Number.isFinite(n))throw new Error("function cannot be evaluated at initial parameters");let i=n,r=1,E=0,o=new Array(u),M=new Array(u),d=new Array(u).fill(0),p=!0,F=0,v=0;for(;;){o.fill(0),M.fill(0),F=0;let O=1;p=!0;do{if(F++,E++,E>s)return{par:d.slice(),value:i,fnEvals:r,gradEvals:E,code:1};let k=e.g(l);v=0;let x=0;for(let S=0;S<u;S++){d[S]=l[S];let g=k[S],P=M[S];a===1?(v+=g*g,x+=P*P):a===2?(v+=g*(g-P),x+=P*P):(v+=g*(g-P),x+=o[S]*(g-P)),M[S]=g}if(!(v>c))break;let w=x>0?v/x:1,_=0;for(let S=0;S<u;S++)o[S]=o[S]*w-k[S],_+=o[S]*k[S];let W=i,G=we(e,d,o,_,i,O,l,n);r+=G.evals,n=G.value,p=G.accepted;let C=G.step;if(p){i=n;let S=2*(n-W-_*C);if(S>0){S=-(_*C*C/S);for(let g=0;g<u;g++)l[g]=d[g]+S*o[g];if(i=n,n=e.f(l),r++,n<i)i=n;else for(let g=0;g<u;g++)l[g]=d[g]+C*o[g]}}O=Math.min(1,ze*C)}while(p&&F!==u);if(F===1&&(!p||!(v>c)||i<=m))break}return{par:d.slice(),value:i,fnEvals:r,gradEvals:E,code:0}}function ti(e,t,a,m,h){let s=t.slice();if(a<=0)return{par:s,value:e.f(s),fnEvals:0,gradEvals:NaN,code:0};let u=1/h,l=Tt(e.f(s)),c=l,n=s.slice(),i=1;for(;i<a;){let r=h/Math.log(i+Ye);for(let E=0;E<m&&i<a;E++){let o=s.map(p=>p+u*r*ce()),M=Tt(e.f(o)),d=M-l;(d<=0||fe()<Math.exp(-d/r))&&(s=o,l=M,l<=c&&(n=s.slice(),c=l)),i++}}return{par:n,value:c,fnEvals:a,gradEvals:NaN,code:0}}function bi(e,t,a,m={}){gt(m,Xe,"optimHess","control");let h=e.length,s=new Ht(t,a,Ot(m.parscale,h,1),m.fnscale??1,Ot(m.ndeps,h,.001));return te(s,e)}function te(e,t){let{n:a,parscale:m,fnscale:h,ndeps:s}=e,u=t.map((c,n)=>c/m[n]),l=Array.from({length:a},()=>new Array(a).fill(0));for(let c=0;c<a;c++){let n=s[c]/m[c],i=u[c];u[c]=i+n;let r=e.g(u);u[c]=i-n;let E=e.g(u);u[c]=i;for(let o=0;o<a;o++){let M=h*(r[o]-E[o]),d=2*n*m[c]*m[o],p=M/d;l[c][o]=Number.isFinite(M)&&Number.isFinite(d)&&Number.isFinite(p)?p:ei(h,r[o],E[o],n,m[c],m[o],p)}}for(let c=0;c<a;c++)for(let n=0;n<c;n++){let i=.5*(l[c][n]+l[n][c]);l[c][n]=i,l[n][c]=i}return l}function ei(e,t,a,m,h,s,u){let l=[t/2-a/2,e,m,h,s];if(l.some(i=>i===0||!Number.isFinite(i)))return u;let c=l.map(i=>Math.floor(Math.log2(Math.abs(i)))),n=l.map((i,r)=>ae(i,-c[r]));return le(n[0]*n[1]/(n[2]*n[3]*n[4]),c[0]+c[1]-c[2]-c[3]-c[4])}var ii=["Nelder-Mead","BFGS","CG","L-BFGS-B","SANN","Brent"];function Ei(e,t,a={}){gt(a,qe,"optim"),gt(oe(a,"control"),Ue,"optim","control");let m=e.length,h=a.method??"Nelder-Mead";if(!ii.includes(h))throw new RangeError(`unknown method '${String(h)}'`);let s=a.control??{},u=[],l=Ot(a.lower,m,-1/0),c=Ot(a.upper,m,1/0);(l.some(x=>x>-1/0)||c.some(x=>x<1/0))&&h!=="L-BFGS-B"&&h!=="Brent"&&(u.push("bounds can only be used with method L-BFGS-B (or Brent)"),h="L-BFGS-B");let n=Ot(s.parscale,m,1),i=s.fnscale??1,r=Ot(s.ndeps,m,.001),E=s.maxit??(h==="Nelder-Mead"?500:h==="SANN"?1e4:100);if(!(Math.abs(E)<=2147483647))throw new RangeError("'maxit' is not an integer");let o=Math.trunc(E),M=s.reltol??Math.sqrt(2**-52),d=s.abstol??-1/0;if(!(M>=0&&M<1/0))throw new RangeError("'reltol' must be a non-negative finite number");if(Number.isNaN(d))throw new RangeError("'abstol' must not be NaN");h==="Nelder-Mead"&&m===1&&u.push(`one-dimensional optimization by Nelder-Mead is unreliable:
|
|
3
|
+
use "Brent" or optimize() directly`),h==="L-BFGS-B"&&(s.reltol!==void 0||s.abstol!==void 0)&&u.push("method L-BFGS-B uses 'factr' (and 'pgtol') instead of 'reltol' and 'abstol'");let p=new Ht(t,a.gr,n,i,r),F=e.map((x,w)=>x/n[w]),v,O=null;switch(h){case"Nelder-Mead":v=$e(p,F,s.alpha??1,s.beta??.5,s.gamma??2,d,M,o);break;case"BFGS":v=Je(p,F,d,M,o);break;case"CG":v=Qe(p,F,s.type??1,d,M,o);break;case"SANN":{let x=s.tmax??10;if(!(x>=1))throw new RangeError("'tmax' is not a positive integer");if(!(s.temp===void 0||s.temp>0&&s.temp<1/0))throw new RangeError("'temp' must be a positive finite number");v=ti(p,F,o,Math.trunc(x),s.temp??10);break}case"Brent":{if(m!==1)throw new RangeError('method = "Brent" is only available for one-dimensional optimization');if(!Number.isFinite(l[0])||!Number.isFinite(c[0]))throw new RangeError("'lower' and 'upper' must be finite values");let x=me(_=>t([_])/i,l[0],c[0],{tol:M});v={par:[x.optimum],value:x.objective,fnEvals:NaN,gradEvals:NaN,code:0};let w={par:v.par,value:v.value*i,counts:[NaN,NaN],convergence:0,message:null,warnings:u};return a.hessian&&(w.hessian=te(p,w.par)),Zt("optim",w)}default:{let x=l.map((P,H)=>P/n[H]),w=c.map((P,H)=>P/n[H]),_=s.lmm??5;Math.abs(_)>2147483647&&u.push("NAs introduced by coercion to integer range");let W=Math.abs(_)<=2147483647?Math.max(Math.trunc(_),0):0;if(m===0){v={par:[],value:p.f([]),fnEvals:0,gradEvals:0,code:0},O="NOTHING TO DO";break}let G=x.map((P,H)=>{let D=Number.isFinite(P),q=Number.isFinite(w[H]);return D&&q?2:D?1:q?3:0}),C=0,S=be(m,W,F,x,w,G,s.factr??1e7,s.pgtol??0,P=>{let H=p.f(P);if(!Number.isFinite(H))throw new Error("L-BFGS-B needs finite values of 'fn'");return{f:H,g:p.g(P,x,w)}},()=>++C>o);O=S.task;let g=S.task.startsWith("NEW_X")?1:S.task.startsWith("CONV")?0:S.task.startsWith("WARN")?51:52;v={par:S.x,value:S.f,fnEvals:S.nfgv,gradEvals:S.nfgv,code:g}}}let k={par:p.unscale(v.par),value:v.value*i,counts:[v.fnEvals,v.gradEvals],convergence:v.code,message:O,warnings:u};return a.hessian&&(k.hessian=te(p,k.par)),Zt("optim",k)}export{ai as a,me as b,li as c,We as d,bi as e,Ei as f};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.17.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{c as le}from"./chunk-CZI7KUO3.js";import{a as ne}from"./chunk-RFE7MVP7.js";import{a as ue,g as fe}from"./chunk-NSYZTS26.js";import{x as z}from"./chunk-LV3W2F7N.js";import{b as me,c as V}from"./chunk-H3WVPZDL.js";import{c as R}from"./chunk-DXI5N2ET.js";import{b as re}from"./chunk-C7V2FH6L.js";import{r as L,s as j}from"./chunk-LHUIJQHY.js";import{A as ie,B as ee,J as te,K as q,M as ce,b as oe,c as ae,d as S,f as W,g as F,i as G,l as M}from"./chunk-WM7VFXTV.js";function B(e){if(e.kind==="factor")return me(e);let t=[...new Set(e.values)].sort((o,a)=>o-a),r=[...new Set(t.map(re))],n=new Map(r.map((o,a)=>[o,a]));return{levels:r,codes:e.values.map(o=>n.get(re(o)))}}function A(e,t){if(e.kind!=="numeric")throw new TypeError(`'${t}' must be a numeric column`);return e.values}function C(e,t){let r=ue(e),n=fe(r,Object.keys(t));return{terms:n,rhsVariables:n.variables.slice(n.response===0?1:0)}}function de(e){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");return t<0?void 0:{lhs:e.slice(0,t).trim(),rhs:e.slice(t+1)}}var Oe=/^Pair\s*\(\s*([A-Za-z.][A-Za-z0-9._]*)\s*,\s*([A-Za-z.][A-Za-z0-9._]*)\s*\)$/,$="'formula' missing or incorrect",pe=(e,t)=>t.length===0&&e.terms.length===0&&e.intercept;function De(e,t,r){let n=de(e),o=n===void 0?null:Oe.exec(n.lhs);if(o!==null){let{terms:m,rhsVariables:d}=C(`~${n.rhs}`,t);if(!r||!pe(m,d))throw new TypeError($);let w=V(t,[o[1],o[2]]);return{kind:"paired",x:A(w.variables[0],o[1]),y:A(w.variables[1],o[2])}}let{terms:a,rhsVariables:c}=C(e,t);if(a.response<0)throw new TypeError($);let i=a.variables[0];if(r&&pe(a,c))return{kind:"one",x:A(V(t,[i]).variables[0],i)};if(c.length!==1||a.terms.length!==1)throw new TypeError($);let s=V(t,[i,c[0]],{dropUnusedLevels:!0}),l=A(s.variables[0],i),u=B(s.variables[1]);if(u.levels.length!==2)throw new Error("grouping factor must have exactly 2 levels");return{kind:"two",x:l.filter((m,d)=>u.codes[d]===0),y:l.filter((m,d)=>u.codes[d]===1),levels:[u.levels[0],u.levels[1]]}}function Je(e,t){let r=De(e,t,!1);if(r.kind!=="two")throw new TypeError($);return r}function Qe(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0)throw new TypeError($);if(n.length!==1)throw new TypeError("'formula' should be of the form response ~ group");let o=r.variables[0],a=V(t,[o,n[0]],{dropUnusedLevels:!0});return{values:A(a.variables[0],o),group:B(a.variables[1])}}function et(e,t){let r=t.levels.map(()=>[]);return e.forEach((n,o)=>r[t.codes[o]].push(n)),r}function tt(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0||n.length===0)throw new TypeError($);let o=r.variables[0],a=V(t,[o,...n],{dropUnusedLevels:!0}),c=a.variables.slice(1).map(B),i=a.rows.map((s,l)=>{let u=0,m=1;for(let d of c)u+=d.codes[l]*m,m*=d.levels.length;return u});return{values:A(a.variables[0],o),groups:i}}var he="incorrect specification for 'formula'";function rt(e,t){let r=de(e),n=r?.rhs.split("|");if(r===void 0||r.lhs===""||n.length!==2)throw new TypeError(he);let o=y=>{let{terms:x,rhsVariables:p}=C(y,t);if(p.length!==1||x.terms.length!==1)throw new TypeError(he);return p[0]},{terms:a}=C(`${r.lhs} ~ 1`,t),c=a.variables[0],i=o(`~${n[0]}`),s=o(`~${n[1]}`),l=V(t,[c,i,s],{dropUnusedLevels:!0}),u=A(l.variables[0],c),m=B(l.variables[1]),d=B(l.variables[2]),w=d.levels.map(()=>m.levels.map(()=>NaN)),g=d.levels.map(()=>m.levels.map(()=>0));if(u.forEach((y,x)=>{let p=d.codes[x],N=m.codes[x];g[p][N]++,w[p][N]=y}),g.some(y=>y.some(x=>x!==1)))throw new Error("not an unreplicated complete block design");return w}function we(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response>=0)throw new TypeError("'formula' missing or invalid");if(n.length!==2)throw new TypeError("invalid formula");let o=V(t,n);return{x:A(o.variables[0],n[0]),y:A(o.variables[1],n[1])}}function ge(e){if(e===void 0)return"two.sided";let r=["two.sided","less","greater"].filter(n=>n.startsWith(e));if(e.length===0||r.length!==1)throw new RangeError(`invalid alternative "${e}" (expected "two.sided", "less" or "greater")`);return r[0]}function Ne(e){if(!(Number.isFinite(e)&&e>=0&&e<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function st(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7}function ot(e){if(!(Number.isFinite(e)&&e>0&&e<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var Fe=["alternative","exact","confLevel","continuity","method"],$e=["pearson","kendall","spearman"];function Pe(e){if(e===void 0)return"pearson";let t=$e.filter(r=>r.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function be(e){if(!(e[0]>0))return[Math.sqrt(e[0]),0];let t=Math.sqrt(e[0]),r=W(e,ae(t,t));return oe(t,r[0]/(2*t))}function H(e,t){let r=e.length;if(r<2)return[NaN,0];let n=ee(e)?.d,o=ee(t)?.d;if(n===void 0||o===void 0)return[NaN,0];let a=[0,0],c=[0,0],i=[0,0];for(let l=0;l<r;l++)a=S(a,F(n[l],o[l])),c=S(c,F(n[l],n[l])),i=S(i,F(o[l],o[l]));if(c[0]===0||i[0]===0)return[NaN,0];let s=G(a,F(be(c),be(i)));return s[0]>=1?[1,0]:s[0]<=-1?[-1,0]:s}function ve(e,t){let r=F(W([1,0],e),S([1,0],e));return Math.sqrt(t)*e[0]/Math.sqrt(r[0])}function Ke(e){return Math.abs(e[0])<.5?Math.atanh(e[0]):.5*Math.log(S([1,0],e)[0]/W([1,0],e)[0])}function ye(e,t,r){return r==="less"?z(e,t,!0,!1):r==="greater"?z(e,t,!1,!1):2*Math.min(z(e,t,!0,!1),z(e,t,!1,!1))}function Ie(e,t){return t==="less"?L(e):t==="greater"?L(e,{lowerTail:!1}):2*Math.min(L(e),L(e,{lowerTail:!1}))}function X(e,t){let r=e.length,n=0;for(let u=0;u<r;u++){let m=e[u],d=t[u];for(let w=u+1;w<r;w++){let g=(e[w]>m?1:0)-(e[w]<m?1:0),y=(t[w]>d?1:0)-(t[w]<d?1:0);n+=g*y}}let o=q(e),a=q(t),c=r*(r-1)/2,i=o.reduce((u,m)=>u+m*(m-1)/2,0),s=a.reduce((u,m)=>u+m*(m-1)/2,0),l=r<2||i===c||s===c?NaN:i===0&&s===0?n/c:n/Math.sqrt((c-i)*(c-s));return{s:n,tau:l,ties:o.length>0||a.length>0,tx:o,ty:a}}var Ee=1290;function ke(e,t){let r=e*(e-1)/2;if(t<0)return 0;if(t>=r)return 1;let n=new Float64Array(t+1);n[0]=1;for(let a=2;a<=e;a++){let c=new Float64Array(t+1),i=0;for(let l=0;l<=t;l++)i+=n[l],c[l]=i;let s=new Float64Array(t+1);for(let l=0;l<=t;l++)s[l]=(c[l]-(l>=a?c[l-a]:0))/a;n=s}let o=0;for(let a=t;a>=0;a--)o+=n[a];return Math.min(1,o)}var Te=new Map;function je(e){let t=Te.get(e);if(t!==void 0)return t;let r=e*(e*e-1)/3,n=1<<e,o=new Array(n);o[0]=new Float64Array(r+1),o[0][0]=1;let a=i=>{let s=0;for(;i;i&=i-1)s++;return s};for(let i=0;i<n;i++){let s=o[i];if(s===void 0)continue;let l=a(i);for(let u=0;u<e;u++){if(i&1<<u)continue;let m=(u-l)**2,d=i|1<<u,w=o[d]??=new Float64Array(r+1);for(let g=0;g+m<=r;g++)s[g]&&(w[g+m]+=s[g])}i!==n-1&&(o[i]=void 0)}let c=o[n-1];return Te.set(e,c),c}var T=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function xe(e,t,r){let n=t;n%2!==0&&(n+=1);let o=1/e,a=(6*(n-1)*o/(e*e-1)-1)*Math.sqrt(1/o-1),c=a*a,s=a*o*(T[0]+o*(T[1]+T[2]*o)+c*(-T[3]+o*(T[4]+T[5]*o)-c*o*(T[6]+T[7]*o-c*(T[8]-T[9]*o+c*o*(T[10]-T[11]*c)))))/Math.exp(c/2),l=r?L(a)-s:s+L(a,{lowerTail:!1});return Math.min(1,Math.max(0,l))}function Me(e,t,r){let n=e*(e*e-1)/3;if(e<=9){let o=je(e),a=1;for(let i=2;i<=e;i++)a*=i;let c=0;if(r)for(let i=Math.min(t,n);i>=0;i--)c+=o[i];else for(let i=n;i>=Math.max(t,0);i--)c+=o[i];return c/a}return r?t+1>n?1:t+1<=0?0:xe(e,t+1,!0):t<=0?1:t>n?0:xe(e,t,!1)}function qe(e,t,r={}){if(M(r,Fe,"corTest"),typeof e=="string"){let n=we(e,t);return qe(n.x,n.y,r)}return ze(e,t,r)}function ze(e,t,r){if(e.length!==t.length)throw new TypeError("x and y must have the same length");let n=ge(r.alternative),o=Pe(r.method),a=r.continuity??!1,[c,i]=ce(Array.from(e),Array.from(t)),s=c.length;if(o==="pearson"){let f=r.confLevel??.95;if(Ne(f),s<3)throw new Error("not enough finite observations");let h=H(c,i),E=s-2,v=Number.isNaN(h[0])?NaN:ve(h,E),k={method:"Pearson's product-moment correlation",alternative:n,statistic:v,statisticName:"t",parameter:E,parameterName:"df",pValue:ye(v,E,n),estimate:h[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation",warnings:Number.isNaN(h[0])&&(Se(c)||Se(i))?[se]:[]};if(s>3){let Z=Ke(h),O=1/Math.sqrt(s-3),D=_=>Math.tanh(Z+_),K;if(n==="less")K=[-1,D(O*j(f))];else if(n==="greater")K=[D(-O*j(f)),1];else{let _=(1-f)/2,b=O*(_<1e-8?j(_,{lowerTail:!1}):j((1+f)/2));K=[D(-b),D(b)]}k.confInt=K,k.confLevel=f}return R("corTest",k)}if(s<2)throw new Error("not enough finite observations");if(o==="kendall"){let f=X(c,i),h={method:"Kendall's rank correlation tau",alternative:n,estimate:f.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau",warnings:[]};if(Number.isNaN(f.tau))return R("corTest",{...h,statistic:NaN,statisticName:"T",pValue:NaN,warnings:[se]});let E=r.exact??s<50;if(E&&!f.ties){if(s>Ee)throw new RangeError(`the exact distribution of T for n = ${s} takes too long (at most ${Ee}): use exact: false`);let b=s*(s-1)/2,I=(f.s+b)/2,U=ke(s,I),Y=ke(s,b-I),Ce=n==="less"?U:n==="greater"?Y:Math.min(1,2*Math.min(U,Y));return R("corTest",{...h,statistic:I,statisticName:"T",pValue:Ce})}let v=(b,I)=>I.reduce((U,Y)=>U+b(Y),0),k=b=>b*(b-1),Z=b=>b*(b-1)*(b-2),O=b=>b*(b-1)*(2*b+5),D=(s*(s-1)*(2*s+5)-v(O,f.tx)-v(O,f.ty))/18+(s<3?0:v(Z,f.tx)*v(Z,f.ty)/(9*s*(s-1)*(s-2)))+v(k,f.tx)*v(k,f.ty)/(2*s*(s-1)),_=(a?Math.sign(f.s)*(Math.abs(f.s)-1):f.s)/Math.sqrt(D);return E&&(h.warnings=[Ae]),R("corTest",{...h,statistic:_,statisticName:"z",pValue:Ie(_,n)})}let l=te(c),u=te(i),m=H(l,u),d=s*s*s-s,w=d*(1-m[0])/6,g={method:"Spearman's rank correlation rho",alternative:n,statistic:w,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho",warnings:[]};if(Number.isNaN(m[0]))return R("corTest",{...g,pValue:NaN,warnings:[se]});let y=q(c).length>0||q(i).length>0;if(y&&(r.exact??!0)&&(g.warnings=[Ae]),(r.exact??s<=1290)&&!y&&s<=1290){let f=Math.round(w),h=Me(s,f,!0),E=Me(s,f,!1),v=n==="greater"?h:n==="less"?E:Math.min(1,2*Math.min(h,E));return R("corTest",{...g,pValue:v})}let p=m;if(a){let f=G([6,0],[d,0]);p=G(S(m,f),S([1,0],f)),Math.abs(p[0])>=1&&(p=[Math.sign(p[0]),0])}let N=ve(p,s-2);return s===2&&(g.warnings=[...g.warnings,Be]),R("corTest",{...g,pValue:ye(N,s-2,n)})}var se="the standard deviation is zero",Be="NaNs produced",Ae="Cannot compute exact p-value with ties";function Se(e){return Number.isFinite(e[0])&&e.every(t=>t===e[0])}var Ze=["tiesMethod","naLast"];function Ue(e,t){let r=e.length,n=new Array(r);if(t==="first"||t==="last"||t==="random"){let c=t==="random"?le(r):[],i=Array.from({length:r},(s,l)=>l);return i.sort((s,l)=>{let u=e[s]<e[l]?-1:e[s]>e[l]?1:0;return u!==0?u:t==="first"?s-l:t==="last"?l-s:c[s]-c[l]||s-l}),i.forEach((s,l)=>n[s]=l+1),n}let o=Array.from({length:r},(c,i)=>i).sort((c,i)=>e[c]-e[i]||c-i),a=0;for(;a<r;){let c=a;for(;c+1<r&&e[o[c+1]]===e[o[a]];)c++;let i=t==="average"?(a+c+2)/2:t==="min"?a+1:c+1;for(let s=a;s<=c;s++)n[o[s]]=i;a=c+1}return n}function J(e,t={}){M(t,Ze,"rank");let r=t.tiesMethod??"average";if(!["average","first","last","random","max","min"].includes(r))throw new RangeError(`invalid tiesMethod "${r}"`);let n=t.naLast??"last";if(n!=="last"&&n!=="first"&&n!=="keep")throw new RangeError(`invalid 'naLast': ${String(n)}`);let o=Array.from(e),a=o.filter(m=>!Number.isNaN(m)),c=Ue(a,r),i=o.length-a.length,s=[],l=0,u=0;for(let m of o)Number.isNaN(m)?(u++,s.push(n==="keep"?NaN:n==="last"?a.length+u:u)):s.push(n==="first"?c[l++]+i:c[l++]);return s}var Re=["method","use"],Ve=["method","use"],Ye=["pearson","kendall","spearman"],We=["all.obs","complete.obs","pairwise.complete.obs","everything","na.or.complete"];function _e(e,t,r,n){if(e===void 0)return r;if(t.includes(e))return e;let o=t.filter(a=>a.startsWith(e));if(e.length===0||o.length!==1)throw new RangeError(`invalid '${n}' argument`);return o[0]}function P(e){return e.length>0&&Array.isArray(e[0])}function Le(e){if(!P(e))return[Array.from(e)];let t=e[0].length;if(e.some(r=>!Array.isArray(r)||r.length!==t))throw new TypeError("all rows of the matrix must have the same length");return Array.from({length:t},(r,n)=>e.map(o=>o[n]))}function Q(e,t,r,n){let o=_e(r.method,Ye,"pearson","method"),a=_e(r.use,We,"everything","use");if(t===void 0&&!P(e))throw new TypeError("supply both 'x' and 'y' or a matrix-like 'x'");let c=Le(e),i=t===void 0?c:Le(t),s=c[0]?.length??0;if(i.some(p=>p.length!==s))throw new RangeError("incompatible dimensions");let l=[...c,...i];if(a==="all.obs"&&l.some(p=>p.some(Number.isNaN)))throw new RangeError("missing observations in cov/cor");if(!n&&a==="pairwise.complete.obs"&&o!=="pearson")throw new RangeError("cannot handle 'pairwise.complete.obs'");let u;if((a==="complete.obs"||a==="na.or.complete")&&(u=Array.from({length:s},(p,N)=>l.every(f=>!Number.isNaN(f[N]))),!u.some(Boolean))){if(a==="complete.obs")throw new RangeError("no complete element pairs");return t===void 0||P(e)||P(t)?c.map(()=>i.map(()=>NaN)):NaN}let m=p=>{let N=u===void 0?p:p.filter((f,h)=>u[h]);return o==="spearman"&&a!=="pairwise.complete.obs"?J(N,{naLast:"keep"}):N},d=c.map(m),w=t===void 0?d:i.map(m),g=(p,N)=>{let f=p,h=N;if(a==="pairwise.complete.obs"){let E=p.map((v,k)=>!Number.isNaN(v)&&!Number.isNaN(N[k]));f=p.filter((v,k)=>E[k]),h=N.filter((v,k)=>E[k]),o==="spearman"&&(f=J(f),h=J(h))}else if(f.some(Number.isNaN)||h.some(Number.isNaN))return NaN;return f.length<2?NaN:o==="kendall"?n?X(f,h).tau:2*X(f,h).s:n?H(f,h)[0]:ie(f,h)},y=d.map(p=>w.map(N=>g(p,N))),x=u===void 0?s:u.filter(Boolean).length;return n&&t===void 0&&a!=="pairwise.complete.obs"&&x>=2&&y.forEach((p,N)=>{Number.isNaN(p[N])||(p[N]=1)}),t!==void 0&&!P(e)&&!P(t)?y[0][0]:y}function Tt(e,t,r={}){return ne(t)&&M(t,Re,"cov"),M(r,Re,"cov"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!1):Q(e,t,r,!1)}function xt(e,t,r={}){return ne(t)&&M(t,Ve,"cor"),M(r,Ve,"cor"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!0):Q(e,t,r,!0)}export{De as a,Je as b,Qe as c,et as d,tt as e,rt as f,ge as g,Ne as h,st as i,ot as j,H as k,qe as l,J as m,Tt as n,xt as o};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
2
|
-
import{G as i,l as n,z as t}from"./chunk-
|
|
1
|
+
/*! rStats.js 0.17.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{G as i,l as n,z as t}from"./chunk-LHUIJQHY.js";function o(r){return Number.isNaN(r)||r<-1?NaN:r===-1||r===1/0?-1/0:i(r)}function a(r){return Number.isNaN(r)||r===-1/0?NaN:r===1/0||r<=-1&&r===Math.floor(r)?1/0:t(r)}function m(r){return Number.isNaN(r)||r<0?NaN:r===0?-1/0:r===1/0?0:n(-r)}function p(r){return Number.isNaN(r)?NaN:r<=-37?Math.exp(r):r<=18?Math.log1p(Math.exp(r)):r<=33.3?r+Math.exp(-r):r}export{o as a,a as b,m as c,p as d};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.17.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{B as R,a as S,c as y,e as I,f as O,h as U,j as A,q as K,u as j,v as E,y as P}from"./chunk-XLSFJTTK.js";import{a as q,c as z}from"./chunk-SE7V2KLO.js";import{l as x,u as w}from"./chunk-WM7VFXTV.js";var _=["exact","norm","method","triangular","uplo"],$=["tol"];function Z(f,r={}){x(r,_,"kappa");let o=y(f),h=o;if(o.data.every(Number.isFinite)){let i=U(o.data),n=i===0?void 0:{...o,data:o.data.map(c=>w(c,-i))};n!==void 0&&n.data.every((c,u)=>c===0?o.data[u]===0:Math.abs(c)>=2**-1022)&&(h=n)}let l=h===o?f:I(h);if(r.exact){let i=r.norm===void 0?"2":G(r.norm);if(i==="2"){let c=j(f,{nu:0,nv:0}).d,u=z(c);return u===0?1/0:q(c)/u}let n;try{n=P(l)}catch(c){if(c instanceof Error&&c.message.startsWith("the system is exactly singular"))return 1/0;throw c}return E(l,{type:i})*E(n,{type:i})}let M=r.norm==="I"?"I":"O";if((r.method??"qr")==="direct"){if(r.triangular)return 1/C(h,(r.uplo??"U")==="U",M);let i=r.norm??"O",n=i.toUpperCase();if(n!=="1"&&n!=="O"&&n!=="I")throw new RangeError(`argument type[1]='${i}' must be one of '1','O', or 'I'`);return 1/R(f,{norm:n==="I"?"I":"O"})}let p=h.nrow<h.ncol?I(O(h)):l;return 1/C(y(K(A(p))),!0,M)}function C(f,r,o){return L(o==="I"?O(f):f,r)}function G(f){let r=f.toUpperCase();if(r==="1"||r==="O")return"O";if(r==="E")return"F";if(r==="I"||r==="F"||r==="M"||r==="2")return r;throw new RangeError(`invalid norm "${f}"`)}function L(f,r){let o=Math.min(f.nrow,f.ncol),h=f.nrow,l=(a,t)=>f.data[a+t*h],M=!r,p=0;for(let a=0;a<o;a++){let[t,m]=M?[a,o-a]:[0,a+1],e=0;for(let s=t;s<t+m;s++)e+=Math.abs(l(s,a));p=Math.max(p,e)}let i=1,n=new Float64Array(o),c=a=>{for(let t=0;t<o;t++)n[t]*=a};for(let a=0;a<o;a++){let t=M?o-1-a:a,m=l(t,t);if(n[t]!==0&&(i=n[t]>0?-Math.abs(i):Math.abs(i)),Math.abs(i-n[t])>Math.abs(m)){let k=Math.abs(m)/Math.abs(i-n[t]);c(k),i*=k}let e=i-n[t],s=-i-n[t],d=Math.abs(e),N=Math.abs(s);if(m!==0?(e/=m,s/=m):(e=1,s=1),a!==o-1){let[k,F]=M?[0,t-1]:[t+1,o-1];for(let b=k;b<=F;b++)N+=Math.abs(n[b]+s*l(t,b)),n[b]+=e*l(t,b),d+=Math.abs(n[b]);if(d<N){let b=s-e;e=s;for(let v=k;v<=F;v++)n[v]+=b*l(t,v)}}n[t]=e}c(1/Y(n));let u=1;for(let a=0;a<o;a++){let t=M?a:o-1-a,m=l(t,t);if(Math.abs(n[t])>Math.abs(m)){let e=Math.abs(m)/Math.abs(n[t]);c(e),u*=e}if(m!==0?n[t]/=m:n[t]=1,a<o-1){let e=-n[t];if(M)for(let s=t+1;s<o;s++)n[s]+=e*l(s,t);else for(let s=0;s<t;s++)n[s]+=e*l(s,t)}}let g=1/Y(n);return c(g),u*=g,p!==0?u/p:0}function Y(f){let r=0;for(let o of f)r+=Math.abs(o);return r}function T(f,r={}){x(r,$,"ginv");let o=r.tol??Math.sqrt(Number.EPSILON),h=y(f),{d:l,u:M,v:p,s:i}=j(f),n=h.nrow,c=h.ncol,u=S(c,n),g=Math.max(o*(l[0]??0),0),a=[];for(let t=0;t<l.length;t++){if(!(l[t]>g))continue;let m=1/l[t];if(!Number.isFinite(m)){a.push([t,1/w(l[t],600)]);continue}for(let e=0;e<n;e++){let s=M[e][t]*m;for(let d=0;d<c;d++)u.data[d+e*c]+=p[d][t]*s}}i!==0&&(u.data=u.data.map(t=>w(t,-i)));for(let[t,m]of a)for(let e=0;e<n;e++){let s=M[e][t]*m;for(let d=0;d<c;d++)u.data[d+e*c]+=w(p[d][t]*s,600-i)}return I(u)}export{Z as a,T as b};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.17.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as h,t as s,u as b}from"./chunk-LHUIJQHY.js";import{l as M}from"./chunk-WM7VFXTV.js";function K(t){return Math.abs(t-m(t))>1e-9*Math.max(1,Math.abs(t))}function F(t){let e=m(t);return Math.abs(t-e)<=Math.min(1e-7,1e-9*Math.max(1,Math.abs(t)))?e:Math.floor(t)}function m(t){if(!Number.isFinite(t))return t;let e=Math.round(t);return e-t===.5&&e%2!==0?e-1:e}var A=["rCompatible"],E=["rCompatible"],O=[.08333333333333333,-.021092796092796094,.007575757575757576,-.004166666666666667,.003968253968253968,-.008333333333333333,.08333333333333333],S=.9955816268920898,d=1569415565/1073741824,w=381566830/1073741824/1073741824,_=9016312093258695e-35,k=[-.002071332116774595,-.04525132144873906,-.28919126444774784,-.6503185377089651,-.3255503118680449,.25479851061131553],v=[-5578984132167551e-22,.0021284987017821146,.054151797245674226,.43593529692665967,1.4606242909763516,2.076711702373047,1];function R(t){let e=t-d;e-=w,e-=_;let r=h(t-1,k)/h(t-1,v);return e*S+e*r}function T(t){let e=0;if(t<1e17){let r=1/(t*t);e=r*h(r,O)}return Math.log(t)-.5/t-e}function C(t){let e=0;if(Number.isNaN(t)||t===1/0)return t;if(t===-1/0)return NaN;if(t===0)return NaN;if(t<0){let r=t-Math.trunc(t);if(r===0)return NaN;e=-Math.PI/Math.tan(Math.PI*r),t=1-t}if(t<=10&&t===Math.floor(t)){let r=t;for(let o=1;o<r;o++)e+=1/o;return e-b}if(t<1)e-=1/t,t+=1;else if(t<10)for(;t>2;)t-=1,e+=1/t;return t>=1&&t<=2?e+R(t):e+T(t)}var N=-.5040830082644554,z=7289763902976895e-32,I;function G(t){I??=Array.from({length:100},(n,a)=>j(a+2,N));let e=z,r=-1,o=t-N;for(let n=1;n<100;n++){r*=-o;let a=r*I[n-1];if(e+=a,Math.abs(a)<Number.EPSILON*Math.abs(e))break}return e}var P=[12,-720,30240,-1209600,47900160,-18924375803183792e-7,74724249600,-2950130727918164e-3,11646782814350067e-2,-4597978722407473,0x284e46fd8153bc0,-7166165256175667e3];function Z(t,e){let r=1,o=e,n=1,a=0;for(;e<=1e8&&(a<9||o<=9||o<t);)if(a+=1,o+=1,n=Math.exp(-t*Math.log1p(a/e)),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let c=1,i=0;for(let u=0;u<12;u++){c*=t+i,n/=f;let l=c*n/P[u];if(r+=l,Math.abs(l/r)<s)break;i+=1,c*=t+i,n/=f,i+=1}return r}function j(t,e){let r=Math.pow(e,-t),o=e,n=0,a=0;for(;a<9||o<=9||o<t;)if(a+=1,o+=1,n=Math.pow(o,-t),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let c=1,i=0;for(let u=0;u<12;u++){c*=t+i,n/=f;let l=c*n/P[u];if(r+=l,Math.abs(l/r)<s)break;i+=1,c*=t+i,n/=f,i+=1}return r}function g(t,e){if(e===1/0)return t%2===0?-0:0;let r=1;for(let n=1;n<=t;n++)r*=n/e;let o=r*(Z(t+1,e)/e);return t%2===0?-o:o}var p=[];function D(t){if(p[t]!==void 0)return p[t];let e=[0,1];for(let n=0;n<t;n++){let a=e.slice(1).map((c,i)=>c*(i+1)),f=new Array(a.length+2).fill(0);a.forEach((c,i)=>{f[i]=f[i]-c,f[i+2]=f[i+2]-c}),e=f}let r=(t+1)%2,o=[];for(let n=r;n<e.length;n+=2)o.push(e[n]);return p[t]=o,o}function H(t,e){let r=D(t),o=e*e,n=r[r.length-1];for(let a=r.length-2;a>=0;a--)n=n*o+r[a];return(t+1)%2===1?n*e:n}function L(t){let e=t-Math.round(t);return Math.sin(Math.PI*(.5-Math.abs(e)))/Math.sin(Math.PI*e)}function y(t,e,r){if(Number.isNaN(e))return NaN;if(e===-1/0)return r&&t%2===1?1/0:NaN;if(e<=0&&e===Math.floor(e))return t%2===1?1/0:NaN;if(e>0)return g(t,e);let o=g(t,1-e);return(t%2===0?o:-o)-Math.pow(Math.PI,t+1)*H(t,L(e))}function Y(t){return Math.abs(t-N)<.3?G(t):C(t)}function W(t,e){return M(e,A,"trigamma"),y(1,t,e?.rCompatible??!0)}function X(t,e=0,r){M(r,E,"psigamma");let o=m(e);return Number.isNaN(o)||o<0||o>100?NaN:o===0?Y(t):y(o,t,r?.rCompatible??!0)}export{K as a,F as b,m as c,Y as d,W as e,X as f};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! rStats.js 0.17.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 p(t){return` with simulated p-value
|
|
3
|
+
(based on ${a(t)} replicates)`}function a(t){if(!Number.isFinite(t)||t===0)return String(t);let o=t.toExponential(14).replace(/\.?0+e/,"e"),[r,n]=o.split("e"),s=Number(n),e=`${r}e${s<0?"-":"+"}${String(Math.abs(s)).padStart(2,"0")}`,i=String(Number(t.toPrecision(15)));return i.length<=e.length?i:e}function m(t,o=7){if(!Number.isFinite(t))return Number.isNaN(t)?"NaN":t>0?"Inf":"-Inf";if(t===0)return"0";let[r,n]=t.toExponential(o-1).split("e"),s=r.includes(".")?r.replace(/0+$/,"").replace(/\.$/,""):r,e=Number(n),i=s.replace(/^-/,"").replace(".","").length,u=`${s}e${e<0?"-":"+"}${String(Math.abs(e)).padStart(2,"0")}`,c=Math.max(0,i-1-e);return(t<0?1:0)+(e>=0?e+1:1)+(c>0?c+1:0)>u.length?u:t.toFixed(c)}function f(t){let o=[...new Set(Array.from(t,e=>e===0?0:e))].filter(e=>!Number.isNaN(e)).sort((e,i)=>e-i),r=new Map,n,s=NaN;for(let e of o){let i=a(e);i!==n&&(n=i,s=e),r.set(e,s)}return r}function b(t){let o=Array.from(t),r=f(o.filter(n=>typeof n=="number"));return o.map(n=>typeof n=="number"&&!Number.isNaN(n)?r.get(n):n)}function d(t){return typeof t!="number"?String(t):t===1/0?"Inf":t===-1/0?"-Inf":a(t)}export{p as a,a as b,m as c,b as d,d as e};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.17.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{f as N,i as b,j as a}from"./chunk-ONY5CISH.js";import{f as l}from"./chunk-LHUIJQHY.js";import{d as f,h as m,k as c,l as u}from"./chunk-WM7VFXTV.js";function o(n,t){if(!Number.isFinite(n)||n<0)throw new RangeError("n must be a non-negative finite number");let e=Math.trunc(n),r=new Array(e);for(let i=0;i<e;i++)r[i]=t();return r}function h(n,t){let e=1;if(Number.isNaN(n))return n;if(t!==0){if(!Number.isFinite(n))return Math.pow(n,t);for(t<0&&(t=-t,n=1/n);t&1&&(e*=n),t>>=1,t;)n*=n}return e}var p=["min","max"],d=["mean","sd"],g=["rate"],R=["meanlog","sdlog"],E=["location","scale"],M=["location","scale"],x=["scale"];function y(n,t={}){u(t,p,"runif");let{min:e=0,max:r=1}=t;return o(n,()=>{if(!Number.isFinite(e)||!Number.isFinite(r)||r<e)return NaN;if(e===r)return e;let i=N();return Number.isFinite(r-e)?e+(r-e)*i:e*(1-i)+r*i})}function F(n,t){if(Number.isNaN(n)||!Number.isFinite(t)||t<0)return NaN;if(t===0||!Number.isFinite(n))return n;let e=b(),r=n+t*e;return Number.isFinite(r)?r:2*(n/2+t/2*e)}function L(n,t={}){u(t,d,"rnorm");let{mean:e=0,sd:r=1}=t;return o(n,()=>F(e,r))}function O(n,t={}){u(t,g,"rexp");let e=t.rate??1,r=1/e;return o(n,()=>r===1/0&&e>0?a()/e:!Number.isFinite(r)||r<=0?r===0?0:NaN:r*a())}function A(n,t={}){u(t,R,"rlnorm");let{meanlog:e=0,sdlog:r=1}=t;return o(n,()=>Number.isNaN(e)||!Number.isFinite(r)||r<0?NaN:Math.exp(F(e,r)))}function U(n,t={}){u(t,E,"rlogis");let{location:e=0,scale:r=1}=t;return o(n,()=>{if(Number.isNaN(e)||!Number.isFinite(r))return NaN;if(r<0)return N(),NaN;if(r===0||!Number.isFinite(e))return e;let i=N();return e+r*Math.log(i/(1-i))})}function k(n,t={}){u(t,M,"rcauchy");let{location:e=0,scale:r=1}=t;return o(n,()=>Number.isNaN(e)||!Number.isFinite(r)||r<0?NaN:r===0||!Number.isFinite(e)?e:e+r*Math.tan(Math.PI*N()))}function C(n,t,e={}){u(e,x,"rweibull");let{scale:r=1}=e;return o(n,()=>{if(!(t>0)||!(r>=0))return NaN;if(!Number.isFinite(t)||!Number.isFinite(r)||r===0)return r===0?0:NaN;let i=-Math.log(N()),s=Math.pow(i,1/t);return s!==1/0?r*s:l(f(c([r,0]),m(c([i,0]),1/t)))[0]})}export{o as a,h as b,y as c,F as d,L as e,O as f,A as g,U as h,k as i,C as j};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.17.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 s="@numero-uno-jpn/rstats.warningHandler";function f(){return globalThis[Symbol.for(s)]??null}function p(n){if(n!==null&&typeof n!="function")throw new TypeError("handler must be a function or null");let t=f();return globalThis[Symbol.for(s)]=n,t}var l=0;function a(n,t){if(l>0||t.length===0)return;let r=f();if(r!==null)for(let o of new Set(t))r(o,n)}function d(n,t,...r){let o=new Set(r.flatMap(i=>c(i)));return a(n,(t.warnings??[]).filter(i=>!o.has(i))),t}function c(n){let t=typeof n=="object"&&n!==null?n.warnings:void 0;return Array.isArray(t)?t.filter(r=>typeof r=="string"):[]}function y(n){l++;try{return n()}finally{l--}}var u=class{list=[];add(t){this.list.includes(t)||this.list.push(t)}},e;function h(n,t){let r=e;e=n;try{return t()}finally{e=r}}function w(n){e?.add(n)}export{p as a,a as b,d as c,y as d,u as e,h as f,w as g};
|