@numero-uno-jpn/rstats 0.16.0 → 1.0.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 +205 -0
- package/README.ja.md +57 -23
- package/README.md +60 -23
- package/dist/chunks/{chunk-5UQCRBAG.js → chunk-3W5NFFAA.js} +1 -1
- package/dist/chunks/chunk-4F2IALD4.js +3 -0
- package/dist/chunks/{chunk-QNNL7AZ3.js → chunk-4OLDGML4.js} +2 -2
- package/dist/chunks/chunk-63OPBEYO.js +2 -0
- package/dist/chunks/chunk-6XJBCRBV.js +2 -0
- package/dist/chunks/chunk-BQSIBJVX.js +2 -0
- package/dist/chunks/chunk-BWKHYRM6.js +3 -0
- package/dist/chunks/{chunk-W26LRYOJ.js → chunk-CKV4JWW2.js} +1 -1
- package/dist/chunks/chunk-DCAWMF4K.js +2 -0
- package/dist/chunks/chunk-F7YGX7PN.js +2 -0
- package/dist/chunks/chunk-H7I32ZZE.js +2 -0
- package/dist/chunks/chunk-IEOD5GWC.js +3 -0
- package/dist/chunks/chunk-KICBQGFN.js +2 -0
- package/dist/chunks/chunk-LROMWFAK.js +2 -0
- package/dist/chunks/chunk-NSWENS3S.js +2 -0
- package/dist/chunks/chunk-O2SQMGE3.js +2 -0
- package/dist/chunks/chunk-QQX46TCI.js +2 -0
- package/dist/chunks/chunk-QZK3CCBA.js +2 -0
- package/dist/chunks/chunk-UJ66VQIG.js +2 -0
- package/dist/chunks/chunk-UKNDX4BA.js +2 -0
- package/dist/chunks/chunk-WIBKS73G.js +2 -0
- package/dist/chunks/{chunk-URIO5LY5.js → chunk-WQWZ7FND.js} +2 -2
- package/dist/chunks/chunk-WWVMVZUL.js +2 -0
- package/dist/chunks/chunk-YG5S5AVP.js +2 -0
- package/dist/chunks/chunk-YHNMBYSW.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 +9 -0
- package/dist/entries/mixed.js +8 -1
- 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 +5 -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/formula.d.ts +5 -2
- package/dist/models/formula.js +31 -8
- 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/glmer.d.ts +255 -0
- package/dist/models/glmer.js +635 -0
- package/dist/models/glmerAnova.d.ts +81 -0
- package/dist/models/glmerAnova.js +139 -0
- package/dist/models/glmerDeviance.d.ts +98 -0
- package/dist/models/glmerDeviance.js +576 -0
- package/dist/models/glmerFamily.d.ts +57 -0
- package/dist/models/glmerFamily.js +236 -0
- package/dist/models/glmerGradient.d.ts +46 -0
- package/dist/models/glmerGradient.js +301 -0
- package/dist/models/glmerStructure.d.ts +45 -0
- package/dist/models/glmerStructure.js +168 -0
- package/dist/models/glmerSummary.d.ts +102 -0
- package/dist/models/glmerSummary.js +94 -0
- package/dist/models/lm.js +13 -3
- package/dist/models/lmer.d.ts +27 -6
- package/dist/models/lmer.js +75 -321
- package/dist/models/lmerAnova.d.ts +52 -3
- package/dist/models/lmerAnova.js +101 -45
- package/dist/models/lmerTest.d.ts +12 -5
- package/dist/models/lmerTest.js +39 -18
- package/dist/models/mauchly.d.ts +2 -0
- package/dist/models/mauchly.js +7 -2
- package/dist/models/mixedDeviance.d.ts +28 -2
- package/dist/models/mixedDeviance.js +84 -56
- package/dist/models/mixedMinimiser.d.ts +83 -0
- package/dist/models/mixedMinimiser.js +438 -0
- package/dist/models/mixedPredict.d.ts +121 -0
- package/dist/models/mixedPredict.js +530 -0
- package/dist/models/mixedStructure.d.ts +62 -3
- package/dist/models/mixedStructure.js +74 -29
- package/dist/models/modelFrame.js +2 -2
- package/dist/models/modelMatrix.d.ts +8 -1
- package/dist/models/modelMatrix.js +56 -39
- 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 +14 -11
- package/llms.txt +15 -4
- 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-FLJNSXSW.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
|
@@ -11,6 +11,11 @@ import { svd } from "../linalg/svd.js";
|
|
|
11
11
|
import { optim } from "../optim/optim.js";
|
|
12
12
|
import { twoSum } from "../special/dd.js";
|
|
13
13
|
import { cov } from "./cov.js";
|
|
14
|
+
import { unreported } from "../internal/warnings.js";
|
|
15
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
16
|
+
import { checkOptions, nestedOptions } from "../internal/checkOptions.js";
|
|
17
|
+
const FACTANAL_KEYS = ["covmat", "nObs", "rotation", "scores", "control"];
|
|
18
|
+
const FACTANAL_CONTROL_KEYS = ["lower", "start"];
|
|
14
19
|
/** Sum rounded once (R's long double accumulation, here double-double); also used by omega */
|
|
15
20
|
export function sumOnce(xs) {
|
|
16
21
|
let hi = 0;
|
|
@@ -118,6 +123,8 @@ function promax(L) {
|
|
|
118
123
|
* @category Agreement, reliability and factor analysis
|
|
119
124
|
*/
|
|
120
125
|
export function factanal(x, factors, options = {}) {
|
|
126
|
+
checkOptions(options, FACTANAL_KEYS, "factanal"); // generated: option-keys.mjs
|
|
127
|
+
checkOptions(nestedOptions(options, "control"), FACTANAL_CONTROL_KEYS, "factanal", "control"); // generated: option-keys.mjs
|
|
121
128
|
const scores = options.scores ?? "none";
|
|
122
129
|
if (scores !== "none" && scores !== "regression" && scores !== "Bartlett") {
|
|
123
130
|
throw new RangeError("'arg' should be one of “none”, “regression”, “Bartlett”");
|
|
@@ -163,13 +170,13 @@ export function factanal(x, factors, options = {}) {
|
|
|
163
170
|
return (s + v - S[i][i]) / (v * v);
|
|
164
171
|
});
|
|
165
172
|
};
|
|
166
|
-
const fit = optim(start, objective, {
|
|
173
|
+
const fit = unreported(() => optim(start, objective, {
|
|
167
174
|
gr: gradient,
|
|
168
175
|
method: "L-BFGS-B",
|
|
169
176
|
lower,
|
|
170
177
|
upper: 1,
|
|
171
178
|
control: { fnscale: 1, parscale: new Array(p).fill(0.01) },
|
|
172
|
-
});
|
|
179
|
+
}));
|
|
173
180
|
if (fit.convergence !== 0)
|
|
174
181
|
throw new Error("unable to optimize from this starting value");
|
|
175
182
|
const psi = fit.par;
|
|
@@ -199,6 +206,7 @@ export function factanal(x, factors, options = {}) {
|
|
|
199
206
|
converged: true,
|
|
200
207
|
objective: fit.value,
|
|
201
208
|
counts: fit.counts,
|
|
209
|
+
warnings: [],
|
|
202
210
|
};
|
|
203
211
|
if (scores !== "none")
|
|
204
212
|
out.scores = factorScores(x, S, psi, L, scores);
|
package/dist/descriptive/hist.js
CHANGED
|
@@ -13,6 +13,10 @@ import { IQR, quantile } from "./quantile.js";
|
|
|
13
13
|
import { seqLength } from "../internal/seq.js";
|
|
14
14
|
import { midpoint, minOf } from "../internal/extremes.js";
|
|
15
15
|
import { ldexp, scaleToUnit } from "../internal/summary.js";
|
|
16
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
17
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
18
|
+
const HIST_KEYS = ["breaks", "right", "includeLowest"];
|
|
19
|
+
const PRETTY_KEYS = ["n", "minN", "shrinkSml", "highUBias", "u5Bias"];
|
|
16
20
|
/**
|
|
17
21
|
* About n + 1 equally spaced "round" values (1, 2 or 5 times a power of 10) covering the range of `x`. Equivalent to
|
|
18
22
|
* R's `pretty()`.
|
|
@@ -25,6 +29,7 @@ import { ldexp, scaleToUnit } from "../internal/summary.js";
|
|
|
25
29
|
* @category Descriptive statistics
|
|
26
30
|
*/
|
|
27
31
|
export function pretty(x, options = {}) {
|
|
32
|
+
checkOptions(options, PRETTY_KEYS, "pretty"); // generated: option-keys.mjs
|
|
28
33
|
const finite = Array.from(x).filter(Number.isFinite);
|
|
29
34
|
if (finite.length === 0)
|
|
30
35
|
return [];
|
|
@@ -216,6 +221,7 @@ function fuzz(br, lo, hi) {
|
|
|
216
221
|
* @category Descriptive statistics
|
|
217
222
|
*/
|
|
218
223
|
export function hist(x, options = {}) {
|
|
224
|
+
checkOptions(options, HIST_KEYS, "hist"); // generated: option-keys.mjs
|
|
219
225
|
const xs = Array.from(x).filter(Number.isFinite);
|
|
220
226
|
const n = xs.length;
|
|
221
227
|
const right = options.right ?? true;
|
|
@@ -10,6 +10,14 @@ import { values } from "./basic.js";
|
|
|
10
10
|
import { ldexp, meanDD, mean as meanOf, scaleToUnit, variance } from "../internal/summary.js";
|
|
11
11
|
import { median } from "./basic.js";
|
|
12
12
|
import { maxOf } from "../internal/extremes.js";
|
|
13
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
14
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
15
|
+
const SKEWNESS_KEYS = ["type"];
|
|
16
|
+
const KURTOSIS_KEYS = ["type"];
|
|
17
|
+
const GEOMETRIC_MEAN_KEYS = ["naRm"];
|
|
18
|
+
const MEAN_AD_KEYS = ["center"];
|
|
19
|
+
const CV_KEYS = ["unbiased", "naRm"];
|
|
20
|
+
const SCALE_KEYS = ["center", "scale"];
|
|
13
21
|
/**
|
|
14
22
|
* Central sums sum (x - mean)^2, ^3, ^4 of values without NaN, of the data scaled by a power of 2 (exact) first, so
|
|
15
23
|
* that neither the deviations nor their powers overflow or underflow (R returns NaN there). The sums are those of the
|
|
@@ -53,6 +61,7 @@ function checkType(type) {
|
|
|
53
61
|
* @category Descriptive statistics
|
|
54
62
|
*/
|
|
55
63
|
export function skewness(x, options = {}) {
|
|
64
|
+
checkOptions(options, SKEWNESS_KEYS, "skewness"); // generated: option-keys.mjs
|
|
56
65
|
const type = options.type ?? 3;
|
|
57
66
|
checkType(type);
|
|
58
67
|
const xs = values(x, true);
|
|
@@ -81,6 +90,7 @@ export function skewness(x, options = {}) {
|
|
|
81
90
|
* @category Descriptive statistics
|
|
82
91
|
*/
|
|
83
92
|
export function kurtosis(x, options = {}) {
|
|
93
|
+
checkOptions(options, KURTOSIS_KEYS, "kurtosis"); // generated: option-keys.mjs
|
|
84
94
|
const type = options.type ?? 3;
|
|
85
95
|
checkType(type);
|
|
86
96
|
const xs = values(x, true);
|
|
@@ -108,6 +118,7 @@ export function kurtosis(x, options = {}) {
|
|
|
108
118
|
* @category Descriptive statistics
|
|
109
119
|
*/
|
|
110
120
|
export function geometricMean(x, options = {}) {
|
|
121
|
+
checkOptions(options, GEOMETRIC_MEAN_KEYS, "geometricMean"); // generated: option-keys.mjs
|
|
111
122
|
const xs = values(x, options.naRm);
|
|
112
123
|
if (xs === undefined)
|
|
113
124
|
return NaN;
|
|
@@ -154,6 +165,7 @@ export function modes(x) {
|
|
|
154
165
|
* @category Descriptive statistics
|
|
155
166
|
*/
|
|
156
167
|
export function meanAD(x, options = {}) {
|
|
168
|
+
checkOptions(options, MEAN_AD_KEYS, "meanAD"); // generated: option-keys.mjs
|
|
157
169
|
const c = options.center ?? "mean";
|
|
158
170
|
// the deviations of the values (and a given centre) scaled by a power of 2 (exact), so that they cannot overflow;
|
|
159
171
|
// the mean deviation is scaled back
|
|
@@ -173,6 +185,7 @@ export function meanAD(x, options = {}) {
|
|
|
173
185
|
* @category Descriptive statistics
|
|
174
186
|
*/
|
|
175
187
|
export function cv(x, options = {}) {
|
|
188
|
+
checkOptions(options, CV_KEYS, "cv"); // generated: option-keys.mjs
|
|
176
189
|
const xs = values(x, options.naRm);
|
|
177
190
|
if (xs === undefined)
|
|
178
191
|
return NaN;
|
|
@@ -212,6 +225,7 @@ function rootMeanSquare(v) {
|
|
|
212
225
|
* @category Descriptive statistics
|
|
213
226
|
*/
|
|
214
227
|
export function scale(x, options = {}) {
|
|
228
|
+
checkOptions(options, SCALE_KEYS, "scale"); // generated: option-keys.mjs
|
|
215
229
|
const rows = x.length > 0 && Array.isArray(x[0]) ? x.map((r) => [...r]) : Array.from(x, (v) => [v]);
|
|
216
230
|
const nc = rows[0]?.length ?? 0;
|
|
217
231
|
if (rows.some((r) => r.length !== nc))
|
|
@@ -12,6 +12,10 @@ import { optim } from "../optim/optim.js";
|
|
|
12
12
|
import { cor } from "./cov.js";
|
|
13
13
|
import { sumOnce, varimax } from "./factanal.js";
|
|
14
14
|
import { maxOf } from "../internal/extremes.js";
|
|
15
|
+
import { reported, unreported } from "../internal/warnings.js";
|
|
16
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
17
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
18
|
+
const OMEGA_KEYS = ["nfactors", "covmat"];
|
|
15
19
|
const EPS = 2 ** -52;
|
|
16
20
|
const TWO_FACTOR_MESSAGE = "\nThree factors are required for identification -- general factor loadings set to be equal. \nProceed with caution. \nThink about redoing the analysis with alternative values of the 'option' setting.\n\n";
|
|
17
21
|
const matMul = (A, B) => A.map((row) => B[0].map((_, j) => {
|
|
@@ -127,12 +131,12 @@ function minres(S0, q, warnings, messages) {
|
|
|
127
131
|
const lower = 0.005;
|
|
128
132
|
const bounds = { method: "L-BFGS-B", lower, upper: Math.max(maxOf(s), 1) };
|
|
129
133
|
const parscale = new Array(p).fill(0.01);
|
|
130
|
-
let fit = optim(s.map((v) => 1 - v), objective, { gr: gradient, ...bounds, control: { fnscale: 1, parscale } });
|
|
134
|
+
let fit = unreported(() => optim(s.map((v) => 1 - v), objective, { gr: gradient, ...bounds, control: { fnscale: 1, parscale } }));
|
|
131
135
|
// psych's gradient is that of the residual sum of squares with the diagonal (zero where the off-diagonal objective
|
|
132
136
|
// is stationary), so its minimum is the objective's in the interior; with a uniqueness at the lower bound the two
|
|
133
137
|
// part, and the fit stops short of the minimum (#83). Go on from there with the objective's own gradient
|
|
134
138
|
if (fit.par.some((v) => v === lower)) {
|
|
135
|
-
fit = optim(fit.par, objective, { gr: trueGradient, ...bounds, control: { fnscale: 1, parscale, factr: 1e3 } });
|
|
139
|
+
fit = unreported(() => optim(fit.par, objective, { gr: trueGradient, ...bounds, control: { fnscale: 1, parscale, factr: 1e3 } }));
|
|
136
140
|
}
|
|
137
141
|
// psych's fa goes on from the last point without a word when optim does not converge; the loadings, omegas and G6
|
|
138
142
|
// then come from uniquenesses that are not a minimum, so say so (the values are kept, as psych's)
|
|
@@ -260,6 +264,7 @@ function oblimin(A) {
|
|
|
260
264
|
* @category Agreement, reliability and factor analysis
|
|
261
265
|
*/
|
|
262
266
|
export function omega(x, options = {}) {
|
|
267
|
+
checkOptions(options, OMEGA_KEYS, "omega"); // generated: option-keys.mjs
|
|
263
268
|
const q = options.nfactors ?? 3;
|
|
264
269
|
if (!Number.isInteger(q) || q < 1)
|
|
265
270
|
throw new RangeError("'nfactors' must be a positive integer");
|
|
@@ -390,5 +395,5 @@ export function omega(x, options = {}) {
|
|
|
390
395
|
};
|
|
391
396
|
if (phi !== undefined)
|
|
392
397
|
out.phi = phi;
|
|
393
|
-
return out;
|
|
398
|
+
return reported("omega", out);
|
|
394
399
|
}
|
|
@@ -34,7 +34,10 @@ export interface PivotLongerOptions {
|
|
|
34
34
|
* turn. Any other value is an error, as in tidyr.
|
|
35
35
|
*/
|
|
36
36
|
colsVary?: "fastest" | "slowest";
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Called with each of tidyr's warnings, once per distinct warning, in order. Default: the warnings go to the handler
|
|
39
|
+
* of {@link setWarningHandler} (none by default).
|
|
40
|
+
*/
|
|
38
41
|
onWarning?: (message: string) => void;
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
// its `onWarning` option.
|
|
9
9
|
import { formatR } from "../htest/core/simulate.js";
|
|
10
10
|
import { addColumn, compareValues, isMissing, pick, rowCount } from "./dataFrames.js";
|
|
11
|
+
import { reportWarnings } from "../internal/warnings.js";
|
|
12
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
13
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
14
|
+
const PIVOT_LONGER_KEYS = /* @__PURE__ */ new Set([
|
|
15
|
+
"cols", "namesTo", "namesPrefix", "namesSep", "namesPattern", "namesTransform", "valuesTo", "valuesDropNa",
|
|
16
|
+
"colsVary", "onWarning",
|
|
17
|
+
]);
|
|
18
|
+
const PIVOT_WIDER_KEYS = /* @__PURE__ */ new Set([
|
|
19
|
+
"namesFrom", "valuesFrom", "idCols", "namesPrefix", "namesSep", "namesSort", "namesVary", "valuesFill", "valuesFn",
|
|
20
|
+
]);
|
|
11
21
|
const nameList = (v) => (typeof v === "string" ? [v] : [...v]);
|
|
12
22
|
/**
|
|
13
23
|
* colsVary or namesVary, checked as tidyr's arg_match: exactly "fastest" or "slowest" (default "fastest"); anything
|
|
@@ -19,13 +29,13 @@ function varyArg(arg, v) {
|
|
|
19
29
|
if (v === "fastest" || v === "slowest")
|
|
20
30
|
return v;
|
|
21
31
|
if (typeof v !== "string")
|
|
22
|
-
throw new
|
|
23
|
-
throw new
|
|
32
|
+
throw new TypeError(`\`${arg}\` must be a string or character vector.`);
|
|
33
|
+
throw new RangeError(`\`${arg}\` must be one of "fastest" or "slowest", not "${v}".`);
|
|
24
34
|
}
|
|
25
35
|
function requireColumns(data, names) {
|
|
26
36
|
for (const n of names)
|
|
27
37
|
if (!Object.hasOwn(data, n))
|
|
28
|
-
throw new
|
|
38
|
+
throw new RangeError(`Column \`${n}\` doesn't exist.`);
|
|
29
39
|
}
|
|
30
40
|
/** The type of a column; `null` for an array of missing values only (which combines with any type) */
|
|
31
41
|
function columnType(name, col) {
|
|
@@ -65,7 +75,7 @@ function commonType(data, sources) {
|
|
|
65
75
|
function captures(names, pattern, count) {
|
|
66
76
|
const groups = new RegExp(`${pattern}|`).exec("").length - 1;
|
|
67
77
|
if (groups !== count)
|
|
68
|
-
throw new
|
|
78
|
+
throw new TypeError(`\`regex\` should define ${count} groups; ${groups} found.`);
|
|
69
79
|
const re = new RegExp(pattern);
|
|
70
80
|
return names.map((name) => {
|
|
71
81
|
const m = re.exec(name);
|
|
@@ -132,14 +142,14 @@ function nameParts(names, namesTo, options, warnings) {
|
|
|
132
142
|
return names.map(() => []);
|
|
133
143
|
if (namesTo.length === 1) {
|
|
134
144
|
if (namesSep !== undefined)
|
|
135
|
-
throw new
|
|
145
|
+
throw new TypeError("`names_sep` can't be used with a length 1 `names_to`.");
|
|
136
146
|
if (namesPattern === undefined)
|
|
137
147
|
return names.map((n) => [n]);
|
|
138
148
|
// exactly one capture group, as tidyr (no group gave null parts, a second group was ignored, #255)
|
|
139
149
|
return captures(names, namesPattern, 1);
|
|
140
150
|
}
|
|
141
151
|
if ((namesSep === undefined) === (namesPattern === undefined)) {
|
|
142
|
-
throw new
|
|
152
|
+
throw new TypeError("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");
|
|
143
153
|
}
|
|
144
154
|
return namesSep !== undefined
|
|
145
155
|
? separated(names, namesSep, namesTo.length, warnings)
|
|
@@ -161,17 +171,18 @@ function nameParts(names, namesTo, options, warnings) {
|
|
|
161
171
|
* @category Data frames
|
|
162
172
|
*/
|
|
163
173
|
export function pivotLonger(data, options) {
|
|
174
|
+
checkOptions(options, PIVOT_LONGER_KEYS, "pivotLonger"); // generated: option-keys.mjs
|
|
164
175
|
const colsVary = varyArg("cols_vary", options.colsVary);
|
|
165
176
|
const n = rowCount(data);
|
|
166
177
|
const allNames = Object.keys(data);
|
|
167
178
|
const cols = typeof options.cols === "function" ? allNames.filter(options.cols) : [...new Set(options.cols)];
|
|
168
179
|
requireColumns(data, cols);
|
|
169
180
|
if (cols.length === 0)
|
|
170
|
-
throw new
|
|
181
|
+
throw new RangeError("`cols` must select at least one column.");
|
|
171
182
|
const namesTo = nameList(options.namesTo ?? "name");
|
|
172
183
|
const valuePosition = namesTo.indexOf(".value");
|
|
173
184
|
if (namesTo.lastIndexOf(".value") !== valuePosition)
|
|
174
|
-
throw new
|
|
185
|
+
throw new RangeError('`names_to` may contain ".value" only once');
|
|
175
186
|
const warnings = [];
|
|
176
187
|
const prefix = options.namesPrefix === undefined ? null : new RegExp(`^(?:${options.namesPrefix})`);
|
|
177
188
|
const stripped = cols.map((c) => (prefix === null ? c : c.replace(prefix, "")));
|
|
@@ -202,7 +213,7 @@ export function pivotLonger(data, options) {
|
|
|
202
213
|
const part = p[valuePosition] ?? null;
|
|
203
214
|
const transformed = part === null || valueTransform === undefined ? part : valueTransform(part);
|
|
204
215
|
if (transformed !== null && typeof transformed !== "string") {
|
|
205
|
-
throw new
|
|
216
|
+
throw new TypeError(`the transform of \`.value\` must give strings, not ${typeof transformed}`);
|
|
206
217
|
}
|
|
207
218
|
const name = transformed ?? "NA";
|
|
208
219
|
let value = valueIndex.get(name);
|
|
@@ -212,7 +223,7 @@ export function pivotLonger(data, options) {
|
|
|
212
223
|
values.push(value);
|
|
213
224
|
}
|
|
214
225
|
if (value.sources[k] !== null)
|
|
215
|
-
throw new
|
|
226
|
+
throw new RangeError(`the names give the value column '${name}' twice for one key`);
|
|
216
227
|
value.sources[k] = cols[c];
|
|
217
228
|
});
|
|
218
229
|
}
|
|
@@ -267,6 +278,8 @@ export function pivotLonger(data, options) {
|
|
|
267
278
|
if (options.onWarning !== undefined)
|
|
268
279
|
for (const w of new Set(warnings))
|
|
269
280
|
options.onWarning(w);
|
|
281
|
+
else
|
|
282
|
+
reportWarnings("pivotLonger", warnings);
|
|
270
283
|
return out;
|
|
271
284
|
}
|
|
272
285
|
// ---- pivotWider ----
|
|
@@ -347,6 +360,7 @@ function perColumn(option, isSingle, name) {
|
|
|
347
360
|
* @category Data frames
|
|
348
361
|
*/
|
|
349
362
|
export function pivotWider(data, options = {}) {
|
|
363
|
+
checkOptions(options, PIVOT_WIDER_KEYS, "pivotWider"); // generated: option-keys.mjs
|
|
350
364
|
const namesVary = varyArg("names_vary", options.namesVary);
|
|
351
365
|
const n = rowCount(data);
|
|
352
366
|
// As tidyr: names_from, then values_from, each existing and not empty; then id_cols. A name given twice is
|
|
@@ -355,7 +369,7 @@ export function pivotWider(data, options = {}) {
|
|
|
355
369
|
const names = [...new Set(nameList(v))];
|
|
356
370
|
requireColumns(data, names);
|
|
357
371
|
if (names.length === 0)
|
|
358
|
-
throw new
|
|
372
|
+
throw new RangeError(`\`${arg}\` must select at least one column.`);
|
|
359
373
|
return names;
|
|
360
374
|
};
|
|
361
375
|
const namesFrom = selection(options.namesFrom ?? "name", "names_from");
|
|
@@ -367,7 +381,7 @@ export function pivotWider(data, options = {}) {
|
|
|
367
381
|
for (const c of idCols) {
|
|
368
382
|
const by = namesFrom.includes(c) ? "names_from" : valuesFrom.includes(c) ? "values_from" : null;
|
|
369
383
|
if (by !== null) {
|
|
370
|
-
throw new
|
|
384
|
+
throw new RangeError(`\`id_cols\` can't select a column already selected by \`${by}\`. Column \`${c}\` has already been selected.`);
|
|
371
385
|
}
|
|
372
386
|
}
|
|
373
387
|
const prefix = options.namesPrefix ?? "";
|
|
@@ -396,7 +410,7 @@ export function pivotWider(data, options = {}) {
|
|
|
396
410
|
const isFill = (o) => typeof o !== "object" || o === null;
|
|
397
411
|
for (const value of valuesFrom) {
|
|
398
412
|
if (perColumn(options.valuesFn, isSummary, value) === undefined && cellRows.some((rows) => rows.length > 1)) {
|
|
399
|
-
throw new
|
|
413
|
+
throw new RangeError(`values from '${value}' are not uniquely identified; use valuesFn to summarise them`);
|
|
400
414
|
}
|
|
401
415
|
}
|
|
402
416
|
// As tidyr: the filled cells of a value column (after valuesFn, called in order of first appearance of the cell)
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
// Tukey's five-number summary; mad scales by 1.4826 by default.
|
|
10
10
|
import { median, values } from "./basic.js";
|
|
11
11
|
import { midpoint } from "../internal/extremes.js";
|
|
12
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
13
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
14
|
+
const QUANTILE_KEYS = ["type", "naRm"];
|
|
15
|
+
const IQR_KEYS = ["type", "naRm"];
|
|
16
|
+
const MAD_KEYS = ["center", "constant", "low", "high", "naRm"];
|
|
12
17
|
/** Relative fuzz for the positions of types 1 to 6, 8 and 9 */
|
|
13
18
|
const FUZZ = 4 * Number.EPSILON;
|
|
14
19
|
/** (a, b) of the continuous types 4 to 6, 8 and 9 (Hyndman and Fan's p(k) = (k - a) / (n + 1 - a - b)) */
|
|
@@ -64,6 +69,7 @@ function quantileOfSorted(s, p, type) {
|
|
|
64
69
|
return lower;
|
|
65
70
|
}
|
|
66
71
|
export function quantile(x, probs = [0, 0.25, 0.5, 0.75, 1], options = {}) {
|
|
72
|
+
checkOptions(options, QUANTILE_KEYS, "quantile"); // generated: option-keys.mjs
|
|
67
73
|
const type = options.type ?? 7;
|
|
68
74
|
if (!(Number.isInteger(type) && type >= 1 && type <= 9))
|
|
69
75
|
throw new RangeError("'type' must be an integer in 1..9");
|
|
@@ -93,6 +99,7 @@ export function quantile(x, probs = [0, 0.25, 0.5, 0.75, 1], options = {}) {
|
|
|
93
99
|
* @category Descriptive statistics
|
|
94
100
|
*/
|
|
95
101
|
export function IQR(x, options = {}) {
|
|
102
|
+
checkOptions(options, IQR_KEYS, "IQR"); // generated: option-keys.mjs
|
|
96
103
|
const [a, b] = quantile(x, [0.25, 0.75], options);
|
|
97
104
|
return b - a;
|
|
98
105
|
}
|
|
@@ -130,6 +137,7 @@ export function fivenum(x) {
|
|
|
130
137
|
* @category Descriptive statistics
|
|
131
138
|
*/
|
|
132
139
|
export function mad(x, options = {}) {
|
|
140
|
+
checkOptions(options, MAD_KEYS, "mad"); // generated: option-keys.mjs
|
|
133
141
|
// Missing values stay in (and count in n) unless naRm removes them, as in R
|
|
134
142
|
const given = Array.from(x);
|
|
135
143
|
const xs = given.filter((v) => !Number.isNaN(v));
|
package/dist/descriptive/rank.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
// (or before) all the others in their order of appearance. "random" breaks ties with R's uniform random numbers, one
|
|
5
5
|
// per non-missing value, so the result follows setSeed as R's follows set.seed.
|
|
6
6
|
import { runif } from "../random/continuous.js";
|
|
7
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
8
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
9
|
+
const RANK_KEYS = ["tiesMethod", "naLast"];
|
|
7
10
|
/** Ranks of values without NaN */
|
|
8
11
|
function rankValues(x, method) {
|
|
9
12
|
const n = x.length;
|
|
@@ -50,6 +53,7 @@ function rankValues(x, method) {
|
|
|
50
53
|
* @category Descriptive statistics
|
|
51
54
|
*/
|
|
52
55
|
export function rank(x, options = {}) {
|
|
56
|
+
checkOptions(options, RANK_KEYS, "rank"); // generated: option-keys.mjs
|
|
53
57
|
const method = options.tiesMethod ?? "average";
|
|
54
58
|
if (!["average", "first", "last", "random", "max", "min"].includes(method)) {
|
|
55
59
|
throw new RangeError(`invalid tiesMethod "${method}"`);
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type { Sample } from "../htest/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link tabulate}.
|
|
4
|
+
*
|
|
5
|
+
* @category Descriptive statistics
|
|
6
|
+
*/
|
|
7
|
+
export interface TabulateOptions {
|
|
8
|
+
/** Number of bins. Default max(1, bin); truncated towards 0, as R does. */
|
|
9
|
+
nbins?: number;
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
12
|
* Counts of the integers 1..nbins in `bin` (values truncated towards 0; others, NaN, infinite values and values
|
|
4
13
|
* beyond the integer range of R are not counted).
|
|
5
|
-
* Equivalent to R's `tabulate()`. `nbins` defaults to max(1, bin) and is truncated towards 0, as R does
|
|
14
|
+
* Equivalent to R's `tabulate()`. `nbins` defaults to max(1, bin) and is truncated towards 0, as R does; it is the
|
|
15
|
+
* second argument or the option `nbins` (giving both is a RangeError).
|
|
6
16
|
*
|
|
7
17
|
* @example
|
|
8
18
|
* ```ts
|
|
@@ -13,6 +23,15 @@ import type { Sample } from "../htest/types.js";
|
|
|
13
23
|
* @category Descriptive statistics
|
|
14
24
|
*/
|
|
15
25
|
export declare function tabulate(bin: Sample, nbins?: number): number[];
|
|
26
|
+
/**
|
|
27
|
+
* Counts of the integers 1..nbins in `bin`, with the number of bins in the options: `tabulate(bin, { nbins: 3 })`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* tabulate([1, 2, 2, 5], { nbins: 3 }); // [1, 2, 0]
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function tabulate(bin: Sample, options: TabulateOptions): number[];
|
|
16
35
|
/**
|
|
17
36
|
* Options for {@link table}.
|
|
18
37
|
*
|
|
@@ -7,20 +7,17 @@
|
|
|
7
7
|
import { numberLevels } from "../internal/levels.js";
|
|
8
8
|
import { seqLength } from "../internal/seq.js";
|
|
9
9
|
import { maxOf, minOf } from "../internal/extremes.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* @category Descriptive statistics
|
|
22
|
-
*/
|
|
23
|
-
export function tabulate(bin, nbins) {
|
|
10
|
+
import { optionalArgs } from "../internal/optionalArgs.js";
|
|
11
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
12
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
13
|
+
import { optionsIn } from "../internal/optionalArgs.js";
|
|
14
|
+
const TABULATE_KEYS = ["nbins"];
|
|
15
|
+
const TABLE_KEYS = ["useNA"];
|
|
16
|
+
const CUT_KEYS = ["right", "includeLowest"];
|
|
17
|
+
const FIND_INTERVAL_KEYS = ["rightmostClosed", "allInside", "leftOpen"];
|
|
18
|
+
export function tabulate(bin, ...args) {
|
|
19
|
+
checkOptions(optionsIn(args), TABULATE_KEYS, "tabulate"); // generated: option-keys.mjs
|
|
20
|
+
const { nbins } = optionalArgs(["nbins"], args);
|
|
24
21
|
// as R's as.integer: truncated, and NA (here NaN) when infinite or outside the integer range, so such a value is
|
|
25
22
|
// not counted and does not set the default nbins (Infinity was an array of infinite length, 3e9 ran out of memory,
|
|
26
23
|
// #225)
|
|
@@ -56,6 +53,7 @@ export function tabulate(bin, nbins) {
|
|
|
56
53
|
* @category Descriptive statistics
|
|
57
54
|
*/
|
|
58
55
|
export function table(x, options = {}) {
|
|
56
|
+
checkOptions(options, TABLE_KEYS, "table"); // generated: option-keys.mjs
|
|
59
57
|
const useNA = options.useNA ?? "no";
|
|
60
58
|
// (as R's match.arg; any other value was taken as "no", silently dropping the count of missing values; issue #18)
|
|
61
59
|
if (useNA !== "no" && useNA !== "ifany" && useNA !== "always")
|
|
@@ -115,6 +113,7 @@ export function unique(x) {
|
|
|
115
113
|
* @category Descriptive statistics
|
|
116
114
|
*/
|
|
117
115
|
export function cut(x, breaks, options = {}) {
|
|
116
|
+
checkOptions(options, CUT_KEYS, "cut"); // generated: option-keys.mjs
|
|
118
117
|
const right = options.right ?? true;
|
|
119
118
|
const includeLowest = options.includeLowest ?? false;
|
|
120
119
|
const xs = Array.from(x);
|
|
@@ -193,6 +192,7 @@ function binCode(xs, br, right, includeLowest) {
|
|
|
193
192
|
* @category Descriptive statistics
|
|
194
193
|
*/
|
|
195
194
|
export function findInterval(x, vec, options = {}) {
|
|
195
|
+
checkOptions(options, FIND_INTERVAL_KEYS, "findInterval"); // generated: option-keys.mjs
|
|
196
196
|
const n = vec.length;
|
|
197
197
|
for (let i = 1; i < n; i++) {
|
|
198
198
|
if (!(vec[i] >= vec[i - 1]))
|
package/dist/descriptive.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
2
|
-
import{m as Oe,n as Re,o as ke}from"./chunks/chunk-BG2KLEHM.js";import"./chunks/chunk-ZGABZMWX.js";import{A as We,B as Ze,C as Qe,D as Ge,E as Je,F as Xe,a as G,b as B,c as J,d as F,e as ue,f as Fe,g as Te,j as je,k as Ce,l as ce,m as _e,n as Se,o as Ie,p as Le,q as Pe,r as D,s as _,t as S,u as Ue,v as Ve,w as qe,x as ze,y as Be,z as De}from"./chunks/chunk-VTUGG2SV.js";import{a as fe,b as He,c as Ke,d as Ye,e as en,f as nn}from"./chunks/chunk-KAZRWIB5.js";import"./chunks/chunk-SYWOBOTR.js";import{a as se,e as z,f as le}from"./chunks/chunk-FLJNSXSW.js";import"./chunks/chunk-72Y3HZID.js";import{a as ae}from"./chunks/chunk-QNNL7AZ3.js";import{b as q,c as ie}from"./chunks/chunk-YRZWONZB.js";import{b as V,c as oe}from"./chunks/chunk-W26LRYOJ.js";import"./chunks/chunk-SC6CV4Z3.js";import{N as Q,s as P}from"./chunks/chunk-GM53LWSR.js";var X=4*Number.EPSILON,tn={4:[0,1],5:[.5,.5],6:[0,0],8:[1/3,1/3],9:[3/8,3/8]};function rn(e,n,t){let r=e.length,o=a=>e[Math.min(Math.max(a,1),r)-1];if(t===7){let a=1+(r-1)*n,m=Math.floor(a),u=o(m),p=o(Math.ceil(a));if(a>m&&p!==u){let h=a-m;return(1-h)*u+h*p}return u}let i,s;if(t<=3){let a=t===3?r*n-.5:r*n;i=Math.floor(a*(1+X)),t===1?s=a>i?1:0:t===2?s=a>i?1:.5:s=a!==i||Math.abs(i%2)===1?1:0}else{let[a,m]=tn[t],u=a+n*(r+1-a-m);i=Math.floor(u*(1+X)),s=u-i,Math.abs(s)<X&&(s=0)}let l=o(i),f=o(i+1);return s===1?f:s>0&&s<1&&l!==f?(1-s)*l+s*f:l}function W(e,n=[0,.25,.5,.75,1],t={}){let r=t.type??7;if(!(Number.isInteger(r)&&r>=1&&r<=9))throw new RangeError("'type' must be an integer in 1..9");let o=ce(e,t.naRm);if(o===void 0)throw new RangeError("missing values and NaN's not allowed if 'na.rm' is FALSE");let i=o.sort((a,m)=>a-m),s=typeof n=="number"?[n]:Array.from(n),l=100*Number.EPSILON;if(s.some(a=>a<-l||a>1+l))throw new RangeError("'probs' outside [0,1]");let f=s.map(a=>Number.isNaN(a)||i.length===0?NaN:rn(i,Math.min(Math.max(a,0),1),r));return typeof n=="number"?f[0]:f}function H(e,n={}){let[t,r]=W(e,[.25,.75],n);return r-t}function on(e){let n=Array.from(e).filter(i=>!Number.isNaN(i)).sort((i,s)=>i-s),t=n.length;if(t===0)return[NaN,NaN,NaN,NaN,NaN];let r=Math.floor((t+3)/2)/2;return[1,r,(t+1)/2,t+1-r,t].map(i=>V(n[Math.floor(i)-1],n[Math.ceil(i)-1]))}function sn(e,n={}){let t=Array.from(e),r=t.filter(u=>!Number.isNaN(u)),o=n.naRm?r:t,i=n.center??(o.length>r.length?NaN:_(r)),s=n.constant??1.4826,l=n.low??!1,f=n.high??!1,a=o.map(u=>Math.abs(u-i)),m=a.length;if((l||f)&&m%2===0){if(l&&f)throw new RangeError("'low' and 'high' cannot be both TRUE");let u=m/2+(f?1:0),p=a.filter(h=>!Number.isNaN(h)).sort((h,N)=>h-N);if(u===0||p.length<u)throw new RangeError(`'partial' index ${u} outside bounds`);return s*p[u-1]}return s*_(a)}var me=e=>e===null||typeof e=="number"&&Number.isNaN(e),he=e=>Array.isArray(e)||ArrayBuffer.isView(e);function ln(e){if(he(e))return{columns:[e],rows:e.length};if(typeof e!="object"||e===null)throw new TypeError("the arguments must be arrays or data frames");let n=Object.values(e),t=n[0]?.length??0;if(n.some(r=>r.length!==t))throw new RangeError("not all arguments have the same length");return{columns:n,rows:t}}function pe(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(ln),t=n[0].rows;if(n.some(o=>o.rows!==t))throw new RangeError("not all arguments have the same length");let r=n.flatMap(o=>o.columns);return Array.from({length:t},(o,i)=>r.every(s=>!me(s[i])))}function an(e){if(he(e))return Array.from(e).filter(r=>!me(r));let n=pe(e),t={};for(let[r,o]of Object.entries(e)){let i=Array.from(o).filter((s,l)=>n[l]);F(t,r,o instanceof Float64Array?Float64Array.from(i):i)}return t}function ge(e,n={}){let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5;if(Number.isNaN(r)||Math.abs(r)>=2**31||Math.trunc(r)<0)throw new RangeError("invalid 'n' argument");let o=Math.trunc(r),i=n.minN??Math.floor(r/3);if(Number.isNaN(i)||Math.trunc(i)<0||Math.trunc(i)>o)throw new RangeError("invalid 'min.n' argument");let s=Math.trunc(i),l=n.shrinkSml??.75;if(!Number.isFinite(l)||l<=0)throw new RangeError("invalid 'shrink.sml' argument");let f=n.highUBias??1.5;if(!Number.isFinite(f)||f<0)throw new RangeError("invalid 'high.u.bias' argument");let a=n.u5Bias??.5+1.5*f;if(!Number.isFinite(a)||a<0)throw new RangeError("invalid 'u5.bias' argument");let m=1/0,u=-1/0;for(let $ of t)$<m&&(m=$),$>u&&(u=$);let p=u-m,h,N;if(p===0&&u===0)h=1,N=!0;else{h=Math.max(Math.abs(m),Math.abs(u));let M=(1+(a>=1.5*f+.5?1/(1+f):1.5/(1+a)))*Math.max(1,o)*Number.EPSILON;N=p<h*M*3}N?(h>10&&(h=9+h/10),h*=l,s>1&&(h/=s)):(h=o>1?p/o:p,p===1/0&&o>=2&&(h=u/o-m/o));let E=2**-20*un;h<E?h=E:h>Number.MAX_VALUE/1.25&&(h=Number.MAX_VALUE/1.25);let O=10**Math.floor(Math.log10(h)),g=[[2*O,f],[5*O,a],[10*O,f]],y=O;for(let[$,M]of g)if($-h<M*(h-y))y=$;else break;let d=1e-10,w=Math.floor(m/y+d);for(;w*y>m+d*y;)w--;for(;!Number.isFinite(w*y);)w++;let x=Math.ceil(u/y-d);for(;x*y<u-d*y;)x++;for(;!Number.isFinite(x*y);)x--;let c=Math.trunc(.5+x-w);if(c<s){let $=s-c,M=Math.floor($/2),k=$%2;m===0&&w===0&&u!==0?x+=$:u===0&&x===0&&m!==0?w-=$:w>=0?(x+=M,w-=M+k):(w-=M,x+=M+k),c=s}let b=w*y<m?w*y:m,A=x*y>u?x*y:u;if(c<=0)return[b];let R=fe(b,A,c+1),v=A/c-b/c;return R.map($=>Math.abs($)<1e-14*v?0:$)}var un=22250738585072014e-324;function cn(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function fn(e,n){let t=e.length;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let r=l=>[S(l),3.5*D(l)*t**-.3333333333333333],[[o,i],s]=r(e);return Number.isFinite(i-o)&&Number.isFinite(s)||([[o,i],s]=r(Q([e]).groups[0])),s>0?Math.max(1,Math.ceil((i-o)/s)):1}case"fd":case"freedman-diaconis":{let r=(f,a)=>{let m=2*H(a);for(let u=.125;m===0&&u>=.001953125;u/=2){let[p,h]=W(a,[u,1-u]);m=(h-p)/(1-2*u)}return m===0&&(m=3.5*D(f)),[S(f),m]},o=e.map(cn),[[i,s],l]=r(e,o);if(!(Number.isFinite(s-i)&&Number.isFinite(l))){let{k:f}=Q([e]);[[i,s],l]=r(e.map(a=>P(a,-f)),o.map(a=>P(a,-f)))}return l>0?Math.ceil((s-i)/l*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function mn(e,n,t){let r=e.slice(1).map((o,i)=>o-e[i]);return e.length>5?1e-7*_(r):e.length<=3?t-n===1/0?2*(1e-7*(t/2-n/2)):1e-7*(t-n):1e-7*oe(r.filter(o=>o>0))}function hn(e,n={}){let t=Array.from(e).filter(Number.isFinite),r=t.length,o=n.right??!0,i=n.includeLowest??!0,s=n.breaks??"Sturges",l;if(typeof s!="string"&&typeof s!="number"&&s.length>1){if(!s.every(Number.isFinite))throw new RangeError("'breaks' are not finite");if(l=[...s].sort((g,y)=>g-y),l.some((g,y)=>y>0&&!(g>l[y-1])))throw new RangeError("'breaks' are not strictly increasing")}else{i=!0;let g=typeof s=="string"?fn(t,s):typeof s=="number"?s:s[0];if(!Number.isFinite(g)||g<1)throw new RangeError("invalid number of 'breaks'");g=Math.min(g,1e6);let[y,d]=S(t);l=ge([y,d],{n:g,minN:1});for(let w=1;w<l.length;w++)if(!(l[w]-l[w-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let f=l.length,[a,m]=r>0?S(t):[0,0],u=mn(l,a,m),p=l.map((g,y)=>o?y===0&&i?g-u:g+u:y<f-1?g-u:i?g+u:g-u),h=new Array(Math.max(0,f-1)).fill(0),N=0;for(let g of t){let y=gn(g,p,o,i);y>=0&&(h[y]++,N++)}if(N<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let E=h.map((g,y)=>pn(g,r,l[y],l[y+1])),O=h.map((g,y)=>V(l[y+1],l[y]));return{breaks:l,counts:h,density:E,mids:O}}function pn(e,n,t,r){let o=r-t;if(!(n*o===1/0&&Number.isFinite(t)&&Number.isFinite(r)))return e/(n*o);let i=o===1/0?1:0,s=i===1?r/2-t/2:o,l=Math.floor(Math.log2(s));return P(e,-(l+i))/(n*P(s,-l))}function gn(e,n,t,r){let o=n.length-1;if(o<1)return-1;if(t){if(e===n[0]&&r)return 0;if(!(e>n[0]&&e<=n[o]))return-1;let l=1,f=o;for(;l<f;){let a=Math.floor((l+f)/2);e<=n[a]?f=a:l=a+1}return l-1}if(e===n[o]&&r)return o-1;if(!(e>=n[0]&&e<n[o]))return-1;let i=0,s=o-1;for(;i<s;){let l=Math.floor((i+s+1)/2);n[l]<=e?i=l:s=l-1}return i}function dn(e){let n=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,o)=>r-o),t=n.length;if(t<1)throw new RangeError("'x' must have 1 or more non-missing values");return r=>{if(Number.isNaN(r))return NaN;let o=0,i=t;for(;o<i;){let s=Math.floor((o+i)/2);n[s]<=r?o=s+1:i=s}return o/t}}var Z=e=>e===null||typeof e=="number"&&Number.isNaN(e),wn=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?ae(e,n):Number(e)-Number(n),yn=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?q(e):e>0?"Inf":"-Inf";function bn(e,n){let t=ie(n),r=new Set(t.filter(l=>!Z(l)).map(l=>typeof l));if(r.size>1)throw new TypeError(`${e} mixes ${[...r].join(" and ")} labels`);let o=[...r][0];if(o!==void 0&&o!=="number"&&o!=="string"&&o!=="boolean")throw new TypeError(`${e} has labels of an unsupported type`);let i=[...new Set(t.filter(l=>!Z(l)))].sort(wn),s=new Map(i.map((l,f)=>[l,f]));return{levels:i,codes:t.map(l=>Z(l)?-1:s.get(l))}}var I=e=>Array.isArray(e)||e instanceof Float64Array;function be(e){if(e instanceof Float64Array)return[e];if(!Array.isArray(e))throw new TypeError("the group labels must be an array or an array of arrays");if(e.length>0&&e.every(I))return[...e];if(e.some(I))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function K(e,n,t){e.forEach((s,l)=>{if(s.length!==t)throw new RangeError(`${n[l]} must have one label per row (${t}), not ${s.length}`)});let r=e.map((s,l)=>bn(n[l],s)),o=r.reduce((s,l)=>s*l.levels.length,1);if(o>=2**31)throw new RangeError("total number of levels >= 2^31");let i=new Array(t);for(let s=0;s<t;s++){let l=0,f=1;for(let a of r){let m=a.codes[s];if(m<0){l=-1;break}l+=m*f,f*=a.levels.length}i[s]=l}return{factors:r,size:o,cells:i}}function Y(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function Nn(e,n){return e.factors.map(t=>{let r=t.levels.length,o=t.levels[n%r];return n=Math.floor(n/r),o})}var Ne=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function En(e,n,t){let r=Array.from(e),o=be(n),i=K(o,Ne(o.length,"index"),r.length),s=Y(i).map(a=>a.length===0?null:{value:t(a.map(m=>r[m]))}),f=s.every(a=>a===null||typeof a.value=="number")?s.map(a=>a===null?NaN:a.value):s.map(a=>a===null?null:a.value);return{dim:i.factors.map(a=>a.levels.length),dimnames:i.factors.map(a=>[...a.levels]),values:f}}function xn(e,n){let t={};for(let[r,o]of Object.entries(e))F(t,r,o instanceof Float64Array?Float64Array.from(n,i=>o[i]):n.map(i=>o[i]));return t}function $n(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!I(o))throw new TypeError(`column '${r}' must be an array`);if(o.length!==t)throw new RangeError(`the columns of the data frame have different lengths (found for '${r}')`)}return t}function An(e,n,t={}){let r=t.sep??".",o=be(n),i=!I(e);if(i&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let s=i?$n(e):e.length,l=K(o,Ne(o.length,"f"),s),f=i?[]:Array.from(e),a=new Map;return Y(l).forEach((m,u)=>{if(m.length===0&&(t.drop||l.factors.length===1))return;let p=Nn(l,u).map(yn).join(r);if(a.has(p))throw new RangeError(`the group names joined with '${r}' are not unique ('${p}'); use another sep`);a.set(p,i?xn(e,m):m.map(h=>f[h]))}),a}function de(e,n){if(n===void 0)throw new Error(`object '${e}' not found`);if(!I(n))throw new TypeError(`column '${e}' must be an array`);return Array.from(n,t=>{if(t===null)return NaN;if(typeof t!="number")throw new TypeError(`column '${e}' to summarise must be numeric`);return t})}function we(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new Error(`object '${n}' not found`);if(!I(t))throw new TypeError(`column '${n}' must be an array`);return t}function Mn(e,n){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");if(t<0)throw new SyntaxError("invalid formula: missing '~'");let r=e.slice(0,t).trim(),{rhs:o}=se(`~ ${e.slice(t+1)}`),i=/^[A-Za-z.][A-Za-z0-9._]*$/,s;if(r!=="."){let a=/^cbind\s*\((.*)\)$/s.exec(r);if(s=a===null?[r]:a[1].split(",").map(m=>m.trim()),s.some(m=>!i.test(m)||m==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}else if(z(o,[]).length<z(o,["."]).length)throw new SyntaxError("invalid formula: '.' cannot be on both sides");let l=s===void 0?[]:n.filter(a=>!s.includes(a)),f=z(o,l);return le(o,()=>0,l),{values:s??n.filter(a=>!f.includes(a)),groups:f}}function ye(e,n,t,r,o,i){let s=r[0]?.length??n[0]?.length??0;e.forEach((u,p)=>{if(n[p].length!==s)throw new RangeError(`variable lengths differ (found for '${u}')`)});let l=K(r,t,s),f=Y(l).map((u,p)=>({cell:p,rows:u.filter(o)})).filter(u=>u.rows.length>0),a={};t.forEach((u,p)=>{let h=r[p];F(a,u,f.map(N=>{let E=h[N.rows[0]];return E===0?0:E}))});let m=(u,p)=>{if(Object.hasOwn(a,u))throw new RangeError(`duplicate column name '${u}' in the result`);F(a,u,p)};return e.forEach((u,p)=>{let h=n[p],E=f.map(g=>i(g.rows.map(y=>h[y]))).map(g=>{if(typeof g=="number")return{names:void 0,values:[g]};if(Array.isArray(g))return{names:void 0,values:[...g]};let y=g;return{names:Object.keys(y),values:Object.values(y)}}),O=E[0]?.values.length??1;if(E.some(g=>g.values.length!==O))throw new RangeError("fun must return values of the same length for every group");if(O===1&&E[0]?.names===void 0){m(u,E.map(g=>g.values[0]));return}for(let g=0;g<O;g++){let y=E[0].names?.[g]??String(g+1);m(`${u}.${y}`,E.map(d=>d.values[g]))}}),a}function vn(e,n,t){if(typeof n!="object"||n===null)throw new TypeError("the data must be an object of columns");if(typeof e=="string"){let l=n,{values:f,groups:a}=Mn(e,Object.keys(l)),m=N=>Object.prototype.hasOwnProperty.call(l,N),u=f.map(N=>de(N,m(N)?l[N]:void 0)),p=a.map(N=>we(l,N));return ye(f,u,a,p,N=>u.every(E=>!Number.isNaN(E[N]))&&p.every(E=>!Z(E[N])),t)}if(typeof e!="object"||e===null)throw new TypeError("x must be a data frame");let r=Object.keys(e),o=r.map(l=>de(l,e[l])),i=Object.keys(n);if(i.length===0)throw new RangeError("'by' must name at least one grouping column");let s=i.map(l=>we(n,l));return ye(r,o,i,s,()=>!0,t)}var ne=e=>typeof e=="string"?[e]:[...e];function Ae(e,n){if(n==null)return"fastest";if(n==="fastest"||n==="slowest")return n;throw typeof n!="string"?new Error(`\`${e}\` must be a string or character vector.`):new Error(`\`${e}\` must be one of "fastest" or "slowest", not "${n}".`)}function te(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new Error(`Column \`${t}\` doesn't exist.`)}function Me(e,n){if(n instanceof Float64Array)return"double";let t=null;for(let r of n){if(r===null)continue;let o=typeof r=="number"?"double":typeof r=="string"?"character":"logical";if(t!==null&&o!==t)throw new TypeError(`column '${e}' mixes ${t} and ${o} values`);t=o}return t}function On(e,n){let t=null;for(let r of n){let o=Me(r,e[r]);if(o!==null){if(t===null)t={type:o,column:r};else if(t.type!==o){if(t.type==="character"||o==="character")throw new TypeError(`Can't combine \`${t.column}\` <${t.type}> and \`${r}\` <${o}>.`);o==="double"&&(t={type:o,column:r})}}}return t?.type??null}function Ee(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new Error(`\`regex\` should define ${t} groups; ${r} found.`);let o=new RegExp(n);return e.map(i=>{let s=o.exec(i);return Array.from({length:t},(l,f)=>s===null?null:s[f+1]??null)})}function Rn(e,n){let t=e.charCodeAt(n);if(t>=55296&&t<=56319&&n+1<e.length){let r=e.charCodeAt(n+1);if(r>=56320&&r<=57343)return 2}return 1}function kn(e,n,t,r){let o=new RegExp(n,"g"),i=[],s=[],l=e.map((a,m)=>{let u=[],p=0,h=0;for(;;){o.lastIndex=p;let N=o.exec(a);if(N===null||(u.push(a.slice(h,N.index)),h=N.index+N[0].length,p=N[0].length===0?N.index+Rn(a,N.index):h,p>=a.length))break}return u.push(a.slice(h)),u.length>t&&i.push(m+1),u.length<t&&s.push(m+1),Array.from({length:t},(N,E)=>u[E]??null)}),f=a=>`${a.length} rows [${a.join(", ")}]`;return i.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${f(i)}.`),s.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${f(s)}.`),l}function xe(e,n){return e!==void 0&&Object.hasOwn(e,n)?e[n]:void 0}function Fn(e,n,t,r){let{namesSep:o,namesPattern:i}=t;if(n.length===0)return e.map(()=>[]);if(n.length===1){if(o!==void 0)throw new Error("`names_sep` can't be used with a length 1 `names_to`.");return i===void 0?e.map(s=>[s]):Ee(e,i,1)}if(o===void 0==(i===void 0))throw new Error("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?kn(e,o,n.length,r):Ee(e,i,n.length)}function Tn(e,n){let t=Ae("cols_vary",n.colsVary),r=G(e),o=Object.keys(e),i=typeof n.cols=="function"?o.filter(n.cols):[...new Set(n.cols)];if(te(e,i),i.length===0)throw new Error("`cols` must select at least one column.");let s=ne(n.namesTo??"name"),l=s.indexOf(".value");if(s.lastIndexOf(".value")!==l)throw new Error('`names_to` may contain ".value" only once');let f=[],a=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),m=i.map(d=>a===null?d:d.replace(a,"")),u=Fn(m,s,n,f),p=[],h=[];if(l<0)p.push(...u),h.push({name:n.valuesTo??"value",sources:[...i]});else{let d=new Map,w=new Map,x=xe(n.namesTransform,".value");u.forEach((c,b)=>{let A=c.filter((j,C)=>C!==l),R=JSON.stringify(A),v=d.get(R);if(v===void 0){v=p.length,d.set(R,v),p.push(A);for(let j of h)j.sources.push(null)}let $=c[l]??null,M=$===null||x===void 0?$:x($);if(M!==null&&typeof M!="string")throw new Error(`the transform of \`.value\` must give strings, not ${typeof M}`);let k=M??"NA",T=w.get(k);if(T===void 0&&(T={name:k,sources:p.map(()=>null)},w.set(k,T),h.push(T)),T.sources[v]!==null)throw new Error(`the names give the value column '${k}' twice for one key`);T.sources[v]=i[b]})}let N=h.map(d=>On(e,d.sources.filter(w=>w!==null))),E=[];if(t==="slowest")for(let d=0;d<p.length;d++)for(let w=0;w<r;w++)E.push([w,d]);else for(let d=0;d<r;d++)for(let w=0;w<p.length;w++)E.push([d,w]);let O=(d,w,x)=>{let c=d.sources[x];return c==null?null:e[c][w]};n.valuesDropNa===!0&&(E=E.filter(([d,w])=>h.some(x=>!B(O(x,d,w)))));let g={},y=E.map(([d])=>d);for(let d of o)i.includes(d)||F(g,d,J(e[d],y));if(s.forEach((d,w)=>{if(w===l)return;let x=xe(n.namesTransform,d),c=b=>{let A=p[b][w<l||l<0?w:w-1];return A===null||x===void 0?A:x(A)};F(g,d,E.map(([,b])=>c(b)))}),h.forEach((d,w)=>{let x=N[w]==="double";if(x&&d.sources.every(c=>c!==null&&e[c]instanceof Float64Array))F(g,d.name,Float64Array.from(E,([c,b])=>O(d,c,b)));else{let c=E.map(([b,A])=>{let R=O(d,b,A);return x&&typeof R=="boolean"?Number(R):R});F(g,d.name,c)}}),n.onWarning!==void 0)for(let d of new Set(f))n.onWarning(d);return g}var re=e=>typeof e=="number"?"double":typeof e=="string"?"character":"logical";function jn(e,n){if(e===null||n===null)return e;let t=re(e);if(t===n)return e;if(n==="double"&&t==="logical")return Number(e);if(n==="logical"&&t==="double"){let r=e;if(Number.isNaN(r))return null;if(r===0||r===1)return r===1;throw new TypeError("Can't convert from `fill` <double> to <logical> due to loss of precision.")}throw new TypeError(`Can't convert \`fill\` <${t}> to <${n}>.`)}var Cn=e=>B(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function $e(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(i,s)=>{let l=JSON.stringify(e.map(a=>Cn(a[s]))),f=t.get(l);return f===void 0&&(f=r.length,t.set(l,f),r.push(s)),f}),firsts:r}}function _n(e){return B(e)?"NA":typeof e=="number"?Number.isFinite(e)?q(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function ee(e,n,t){if(e!==void 0)return n(e)?e:Object.hasOwn(e,t)?e[t]:void 0}function Sn(e,n={}){let t=Ae("names_vary",n.namesVary),r=G(e),o=(c,b)=>{let A=[...new Set(ne(c))];if(te(e,A),A.length===0)throw new Error(`\`${b}\` must select at least one column.`);return A},i=o(n.namesFrom??"name","names_from"),s=o(n.valuesFrom??"value","values_from"),l=n.idCols===void 0?Object.keys(e).filter(c=>!i.includes(c)&&!s.includes(c)):[...new Set(ne(n.idCols))];te(e,l);for(let c of l){let b=i.includes(c)?"names_from":s.includes(c)?"values_from":null;if(b!==null)throw new Error(`\`id_cols\` can't select a column already selected by \`${b}\`. Column \`${c}\` has already been selected.`)}let f=n.namesPrefix??"",a=n.namesSep??"_",m=$e(l.map(c=>e[c]),r),u=$e(i.map(c=>e[c]),r),p=u.firsts.map((c,b)=>b);n.namesSort===!0&&p.sort((c,b)=>{for(let A of i){let R=ue(e[A][u.firsts[c]],e[A][u.firsts[b]]);if(R!==0)return R}return 0});let h=u.firsts.map(c=>f+i.map(b=>_n(e[b][c])).join(a)),N=u.firsts.length,E=Array.from({length:m.firsts.length*N},()=>[]);for(let c=0;c<r;c++)E[m.codes[c]*N+u.codes[c]].push(c);let O=c=>typeof c=="function",g=c=>typeof c!="object"||c===null;for(let c of s)if(ee(n.valuesFn,O,c)===void 0&&E.some(b=>b.length>1))throw new Error(`values from '${c}' are not uniquely identified; use valuesFn to summarise them`);let y=new Map;for(let c of s){let b=e[c],A=ee(n.valuesFn,O,c),R=new Array(E.length).fill(null),v=null;if(A===void 0)v=Me(c,b),E.forEach((M,k)=>{M.length>0&&(R[k]=b[M[0]])});else{let M=new Uint8Array(E.length),k=0,T=0;for(let j=0;j<r;j++){let C=m.codes[j]*N+u.codes[j];if(M[C]===1)continue;M[C]=1,T++;let U=A(E[C].map(ve=>b[ve]));if(R[C]=U,U==null)continue;let L=re(U);if(v===null||v==="logical"&&L==="double")v=L,k=T;else if(L!==v&&(v==="character"||L==="character"))throw new TypeError(`Can't combine \`x[[${k}]]\` <${v}> and \`x[[${T}]]\` <${L}>.`)}}let $=jn(ee(n.valuesFill,g,c)??null,v);y.set(c,{cells:R,type:v??($===null?null:re($)),fill:$})}let d=(c,b)=>{let A=e[c],{cells:R,type:v,fill:$}=y.get(c),M=m.firsts.map((k,T)=>{let j=T*N+b,C=E[j].length===0?$:R[j];return v==="double"&&typeof C=="boolean"?Number(C):C});return A instanceof Float64Array&&(v==="double"||v===null)?Float64Array.from(M,k=>k===null?NaN:k):M},w={};for(let c of l)F(w,c,J(e[c],m.firsts));let x=(c,b)=>s.length===1?h[b]:`${c}${a}${h[b]}`;if(t==="slowest")for(let c of p)for(let b of s)F(w,x(b,c),d(b,c));else for(let c of s)for(let b of p)F(w,x(c,b),d(c,b));return w}export{H as IQR,vn as aggregate,pe as completeCases,ke as cor,Re as cov,qe as cummax,ze as cummin,Ve as cumprod,Ue as cumsum,en as cut,Je as cv,Be as diff,dn as ecdf,nn as findInterval,on as fivenum,je as fromRows,Ze as geometricMean,hn as hist,We as kurtosis,sn as mad,Ie as mean,Ge as meanAD,_ as median,Fe as merge,Qe as modes,an as naOmit,Tn as pivotLonger,Sn as pivotWider,ge as pretty,Se as prod,W as quantile,S as range,Oe as rank,Xe as scale,D as sd,De as skewness,An as split,Te as subset,_e as sum,Ke as table,He as tabulate,En as tapply,Ce as toRows,Ye as unique,Pe as variance,Le as weightedMean};
|
|
1
|
+
/*! rStats.js 1.0.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{m as ke,n as Fe,o as Te}from"./chunks/chunk-YHNMBYSW.js";import"./chunks/chunk-DCAWMF4K.js";import{A as De,B as Qe,C as Ze,D as Ge,E as Je,F as Xe,a as Z,b as W,c as G,d as F,e as fe,f as Se,g as _e,j as Ie,k as je,l as me,m as Ce,n as Le,o as Pe,p as Ve,q as Ue,r as z,s as j,t as C,u as qe,v as Ye,w as Ke,x as We,y as ze,z as Be}from"./chunks/chunk-QQX46TCI.js";import{a as he,b as He,c as en,d as nn,e as tn,f as rn}from"./chunks/chunk-QZK3CCBA.js";import"./chunks/chunk-UKNDX4BA.js";import"./chunks/chunk-BQSIBJVX.js";import{a as ae,e as K,f as ie}from"./chunks/chunk-LROMWFAK.js";import"./chunks/chunk-YG5S5AVP.js";import{a as ue}from"./chunks/chunk-4OLDGML4.js";import{b as le}from"./chunks/chunk-NSWENS3S.js";import{b as Y,d as ce}from"./chunks/chunk-BWKHYRM6.js";import{b as q,c as se}from"./chunks/chunk-CKV4JWW2.js";import"./chunks/chunk-WWVMVZUL.js";import{P as Q,l as S,u as V}from"./chunks/chunk-63OPBEYO.js";var on=["type","naRm"],sn=["type","naRm"],ln=["center","constant","low","high","naRm"],J=4*Number.EPSILON,an={4:[0,1],5:[.5,.5],6:[0,0],8:[1/3,1/3],9:[3/8,3/8]};function cn(e,n,t){let r=e.length,o=i=>e[Math.min(Math.max(i,1),r)-1];if(t===7){let i=1+(r-1)*n,m=Math.floor(i),c=o(m),p=o(Math.ceil(i));if(i>m&&p!==c){let h=i-m;return(1-h)*c+h*p}return c}let a,s;if(t<=3){let i=t===3?r*n-.5:r*n;a=Math.floor(i*(1+J)),t===1?s=i>a?1:0:t===2?s=i>a?1:.5:s=i!==a||Math.abs(a%2)===1?1:0}else{let[i,m]=an[t],c=i+n*(r+1-i-m);a=Math.floor(c*(1+J)),s=c-a,Math.abs(s)<J&&(s=0)}let l=o(a),f=o(a+1);return s===1?f:s>0&&s<1&&l!==f?(1-s)*l+s*f:l}function B(e,n=[0,.25,.5,.75,1],t={}){S(t,on,"quantile");let r=t.type??7;if(!(Number.isInteger(r)&&r>=1&&r<=9))throw new RangeError("'type' must be an integer in 1..9");let o=me(e,t.naRm);if(o===void 0)throw new RangeError("missing values and NaN's not allowed if 'na.rm' is FALSE");let a=o.sort((i,m)=>i-m),s=typeof n=="number"?[n]:Array.from(n),l=100*Number.EPSILON;if(s.some(i=>i<-l||i>1+l))throw new RangeError("'probs' outside [0,1]");let f=s.map(i=>Number.isNaN(i)||a.length===0?NaN:cn(a,Math.min(Math.max(i,0),1),r));return typeof n=="number"?f[0]:f}function X(e,n={}){S(n,sn,"IQR");let[t,r]=B(e,[.25,.75],n);return r-t}function un(e){let n=Array.from(e).filter(a=>!Number.isNaN(a)).sort((a,s)=>a-s),t=n.length;if(t===0)return[NaN,NaN,NaN,NaN,NaN];let r=Math.floor((t+3)/2)/2;return[1,r,(t+1)/2,t+1-r,t].map(a=>q(n[Math.floor(a)-1],n[Math.ceil(a)-1]))}function fn(e,n={}){S(n,ln,"mad");let t=Array.from(e),r=t.filter(c=>!Number.isNaN(c)),o=n.naRm?r:t,a=n.center??(o.length>r.length?NaN:j(r)),s=n.constant??1.4826,l=n.low??!1,f=n.high??!1,i=o.map(c=>Math.abs(c-a)),m=i.length;if((l||f)&&m%2===0){if(l&&f)throw new RangeError("'low' and 'high' cannot be both TRUE");let c=m/2+(f?1:0),p=i.filter(h=>!Number.isNaN(h)).sort((h,N)=>h-N);if(c===0||p.length<c)throw new RangeError(`'partial' index ${c} outside bounds`);return s*p[c-1]}return s*j(i)}var pe=e=>e===null||typeof e=="number"&&Number.isNaN(e),ge=e=>Array.isArray(e)||ArrayBuffer.isView(e);function mn(e){if(ge(e))return{columns:[e],rows:e.length};if(typeof e!="object"||e===null)throw new TypeError("the arguments must be arrays or data frames");let n=Object.values(e),t=n[0]?.length??0;if(n.some(r=>r.length!==t))throw new RangeError("not all arguments have the same length");return{columns:n,rows:t}}function de(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(mn),t=n[0].rows;if(n.some(o=>o.rows!==t))throw new RangeError("not all arguments have the same length");let r=n.flatMap(o=>o.columns);return Array.from({length:t},(o,a)=>r.every(s=>!pe(s[a])))}function hn(e){if(ge(e))return Array.from(e).filter(r=>!pe(r));let n=de(e),t={};for(let[r,o]of Object.entries(e)){let a=Array.from(o).filter((s,l)=>n[l]);F(t,r,o instanceof Float64Array?Float64Array.from(a):a)}return t}var pn=["breaks","right","includeLowest"],gn=["n","minN","shrinkSml","highUBias","u5Bias"];function we(e,n={}){S(n,gn,"pretty");let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5;if(Number.isNaN(r)||Math.abs(r)>=2**31||Math.trunc(r)<0)throw new RangeError("invalid 'n' argument");let o=Math.trunc(r),a=n.minN??Math.floor(r/3);if(Number.isNaN(a)||Math.trunc(a)<0||Math.trunc(a)>o)throw new RangeError("invalid 'min.n' argument");let s=Math.trunc(a),l=n.shrinkSml??.75;if(!Number.isFinite(l)||l<=0)throw new RangeError("invalid 'shrink.sml' argument");let f=n.highUBias??1.5;if(!Number.isFinite(f)||f<0)throw new RangeError("invalid 'high.u.bias' argument");let i=n.u5Bias??.5+1.5*f;if(!Number.isFinite(i)||i<0)throw new RangeError("invalid 'u5.bias' argument");let m=1/0,c=-1/0;for(let R of t)R<m&&(m=R),R>c&&(c=R);let p=c-m,h,N;if(p===0&&c===0)h=1,N=!0;else{h=Math.max(Math.abs(m),Math.abs(c));let $=(1+(i>=1.5*f+.5?1/(1+f):1.5/(1+i)))*Math.max(1,o)*Number.EPSILON;N=p<h*$*3}N?(h>10&&(h=9+h/10),h*=l,s>1&&(h/=s)):(h=o>1?p/o:p,p===1/0&&o>=2&&(h=c/o-m/o));let E=2**-20*dn;h<E?h=E:h>Number.MAX_VALUE/1.25&&(h=Number.MAX_VALUE/1.25);let M=10**Math.floor(Math.log10(h)),g=[[2*M,f],[5*M,i],[10*M,f]],y=M;for(let[R,$]of g)if(R-h<$*(h-y))y=R;else break;let d=1e-10,w=Math.floor(m/y+d);for(;w*y>m+d*y;)w--;for(;!Number.isFinite(w*y);)w++;let x=Math.ceil(c/y-d);for(;x*y<c-d*y;)x++;for(;!Number.isFinite(x*y);)x--;let u=Math.trunc(.5+x-w);if(u<s){let R=s-u,$=Math.floor(R/2),k=R%2;m===0&&w===0&&c!==0?x+=R:c===0&&x===0&&m!==0?w-=R:w>=0?(x+=$,w-=$+k):(w-=$,x+=$+k),u=s}let b=w*y<m?w*y:m,v=x*y>c?x*y:c;if(u<=0)return[b];let O=he(b,v,u+1),A=v/u-b/u;return O.map(R=>Math.abs(R)<1e-14*A?0:R)}var dn=22250738585072014e-324;function wn(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function yn(e,n){let t=e.length;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let r=l=>[C(l),3.5*z(l)*t**-.3333333333333333],[[o,a],s]=r(e);return Number.isFinite(a-o)&&Number.isFinite(s)||([[o,a],s]=r(Q([e]).groups[0])),s>0?Math.max(1,Math.ceil((a-o)/s)):1}case"fd":case"freedman-diaconis":{let r=(f,i)=>{let m=2*X(i);for(let c=.125;m===0&&c>=.001953125;c/=2){let[p,h]=B(i,[c,1-c]);m=(h-p)/(1-2*c)}return m===0&&(m=3.5*z(f)),[C(f),m]},o=e.map(wn),[[a,s],l]=r(e,o);if(!(Number.isFinite(s-a)&&Number.isFinite(l))){let{k:f}=Q([e]);[[a,s],l]=r(e.map(i=>V(i,-f)),o.map(i=>V(i,-f)))}return l>0?Math.ceil((s-a)/l*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function bn(e,n,t){let r=e.slice(1).map((o,a)=>o-e[a]);return e.length>5?1e-7*j(r):e.length<=3?t-n===1/0?2*(1e-7*(t/2-n/2)):1e-7*(t-n):1e-7*se(r.filter(o=>o>0))}function Nn(e,n={}){S(n,pn,"hist");let t=Array.from(e).filter(Number.isFinite),r=t.length,o=n.right??!0,a=n.includeLowest??!0,s=n.breaks??"Sturges",l;if(typeof s!="string"&&typeof s!="number"&&s.length>1){if(!s.every(Number.isFinite))throw new RangeError("'breaks' are not finite");if(l=[...s].sort((g,y)=>g-y),l.some((g,y)=>y>0&&!(g>l[y-1])))throw new RangeError("'breaks' are not strictly increasing")}else{a=!0;let g=typeof s=="string"?yn(t,s):typeof s=="number"?s:s[0];if(!Number.isFinite(g)||g<1)throw new RangeError("invalid number of 'breaks'");g=Math.min(g,1e6);let[y,d]=C(t);l=we([y,d],{n:g,minN:1});for(let w=1;w<l.length;w++)if(!(l[w]-l[w-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let f=l.length,[i,m]=r>0?C(t):[0,0],c=bn(l,i,m),p=l.map((g,y)=>o?y===0&&a?g-c:g+c:y<f-1?g-c:a?g+c:g-c),h=new Array(Math.max(0,f-1)).fill(0),N=0;for(let g of t){let y=xn(g,p,o,a);y>=0&&(h[y]++,N++)}if(N<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let E=h.map((g,y)=>En(g,r,l[y],l[y+1])),M=h.map((g,y)=>q(l[y+1],l[y]));return{breaks:l,counts:h,density:E,mids:M}}function En(e,n,t,r){let o=r-t;if(!(n*o===1/0&&Number.isFinite(t)&&Number.isFinite(r)))return e/(n*o);let a=o===1/0?1:0,s=a===1?r/2-t/2:o,l=Math.floor(Math.log2(s));return V(e,-(l+a))/(n*V(s,-l))}function xn(e,n,t,r){let o=n.length-1;if(o<1)return-1;if(t){if(e===n[0]&&r)return 0;if(!(e>n[0]&&e<=n[o]))return-1;let l=1,f=o;for(;l<f;){let i=Math.floor((l+f)/2);e<=n[i]?f=i:l=i+1}return l-1}if(e===n[o]&&r)return o-1;if(!(e>=n[0]&&e<n[o]))return-1;let a=0,s=o-1;for(;a<s;){let l=Math.floor((a+s+1)/2);n[l]<=e?a=l:s=l-1}return a}function Rn(e){let n=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,o)=>r-o),t=n.length;if(t<1)throw new RangeError("'x' must have 1 or more non-missing values");return r=>{if(Number.isNaN(r))return NaN;let o=0,a=t;for(;o<a;){let s=Math.floor((o+a)/2);n[s]<=r?o=s+1:a=s}return o/t}}var vn=["drop","sep"],D=e=>e===null||typeof e=="number"&&Number.isNaN(e),$n=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?ue(e,n):Number(e)-Number(n),An=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?Y(e):e>0?"Inf":"-Inf";function Mn(e,n){let t=ce(n),r=new Set(t.filter(l=>!D(l)).map(l=>typeof l));if(r.size>1)throw new TypeError(`${e} mixes ${[...r].join(" and ")} labels`);let o=[...r][0];if(o!==void 0&&o!=="number"&&o!=="string"&&o!=="boolean")throw new TypeError(`${e} has labels of an unsupported type`);let a=[...new Set(t.filter(l=>!D(l)))].sort($n),s=new Map(a.map((l,f)=>[l,f]));return{levels:a,codes:t.map(l=>D(l)?-1:s.get(l))}}var L=e=>Array.isArray(e)||e instanceof Float64Array;function Ee(e){if(e instanceof Float64Array)return[e];if(!Array.isArray(e))throw new TypeError("the group labels must be an array or an array of arrays");if(e.length>0&&e.every(L))return[...e];if(e.some(L))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function H(e,n,t){e.forEach((s,l)=>{if(s.length!==t)throw new RangeError(`${n[l]} must have one label per row (${t}), not ${s.length}`)});let r=e.map((s,l)=>Mn(n[l],s)),o=r.reduce((s,l)=>s*l.levels.length,1);if(o>=2**31)throw new RangeError("total number of levels >= 2^31");let a=new Array(t);for(let s=0;s<t;s++){let l=0,f=1;for(let i of r){let m=i.codes[s];if(m<0){l=-1;break}l+=m*f,f*=i.levels.length}a[s]=l}return{factors:r,size:o,cells:a}}function ee(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function On(e,n){return e.factors.map(t=>{let r=t.levels.length,o=t.levels[n%r];return n=Math.floor(n/r),o})}var xe=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function kn(e,n,t){let r=Array.from(e),o=Ee(n),a=H(o,xe(o.length,"index"),r.length),s=ee(a).map(i=>i.length===0?null:{value:t(i.map(m=>r[m]))}),f=s.every(i=>i===null||typeof i.value=="number")?s.map(i=>i===null?NaN:i.value):s.map(i=>i===null?null:i.value);return{dim:a.factors.map(i=>i.levels.length),dimnames:a.factors.map(i=>[...i.levels]),values:f}}function Fn(e,n){let t={};for(let[r,o]of Object.entries(e))F(t,r,o instanceof Float64Array?Float64Array.from(n,a=>o[a]):n.map(a=>o[a]));return t}function Tn(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!L(o))throw new TypeError(`column '${r}' must be an array`);if(o.length!==t)throw new RangeError(`the columns of the data frame have different lengths (found for '${r}')`)}return t}function Sn(e,n,t={}){S(t,vn,"split");let r=t.sep??".",o=Ee(n),a=!L(e);if(a&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let s=a?Tn(e):e.length,l=H(o,xe(o.length,"f"),s),f=a?[]:Array.from(e),i=new Map;return ee(l).forEach((m,c)=>{if(m.length===0&&(t.drop||l.factors.length===1))return;let p=On(l,c).map(An).join(r);if(i.has(p))throw new RangeError(`the group names joined with '${r}' are not unique ('${p}'); use another sep`);i.set(p,a?Fn(e,m):m.map(h=>f[h]))}),i}function ye(e,n){if(n===void 0)throw new RangeError(`object '${e}' not found`);if(!L(n))throw new TypeError(`column '${e}' must be an array`);return Array.from(n,t=>{if(t===null)return NaN;if(typeof t!="number")throw new TypeError(`column '${e}' to summarise must be numeric`);return t})}function be(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new RangeError(`object '${n}' not found`);if(!L(t))throw new TypeError(`column '${n}' must be an array`);return t}function _n(e,n){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");if(t<0)throw new SyntaxError("invalid formula: missing '~'");let r=e.slice(0,t).trim(),{rhs:o}=ae(`~ ${e.slice(t+1)}`),a=/^[A-Za-z.][A-Za-z0-9._]*$/,s;if(r!=="."){let i=/^cbind\s*\((.*)\)$/s.exec(r);if(s=i===null?[r]:i[1].split(",").map(m=>m.trim()),s.some(m=>!a.test(m)||m==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}else if(K(o,[]).length<K(o,["."]).length)throw new SyntaxError("invalid formula: '.' cannot be on both sides");let l=s===void 0?[]:n.filter(i=>!s.includes(i)),f=K(o,l);return ie(o,()=>0,l),{values:s??n.filter(i=>!f.includes(i)),groups:f}}function Ne(e,n,t,r,o,a){let s=r[0]?.length??n[0]?.length??0;e.forEach((c,p)=>{if(n[p].length!==s)throw new RangeError(`variable lengths differ (found for '${c}')`)});let l=H(r,t,s),f=ee(l).map((c,p)=>({cell:p,rows:c.filter(o)})).filter(c=>c.rows.length>0),i={};t.forEach((c,p)=>{let h=r[p];F(i,c,f.map(N=>{let E=h[N.rows[0]];return E===0?0:E}))});let m=(c,p)=>{if(Object.hasOwn(i,c))throw new RangeError(`duplicate column name '${c}' in the result`);F(i,c,p)};return e.forEach((c,p)=>{let h=n[p],E=f.map(g=>a(g.rows.map(y=>h[y]))).map(g=>{if(typeof g=="number")return{names:void 0,values:[g]};if(Array.isArray(g))return{names:void 0,values:[...g]};let y=g;return{names:Object.keys(y),values:Object.values(y)}}),M=E[0]?.values.length??1;if(E.some(g=>g.values.length!==M))throw new RangeError("fun must return values of the same length for every group");if(M===1&&E[0]?.names===void 0){m(c,E.map(g=>g.values[0]));return}for(let g=0;g<M;g++){let y=E[0].names?.[g]??String(g+1);m(`${c}.${y}`,E.map(d=>d.values[g]))}}),i}function In(e,n,t){if(typeof n!="object"||n===null)throw new TypeError("the data must be an object of columns");if(typeof e=="string"){let l=n,{values:f,groups:i}=_n(e,Object.keys(l)),m=N=>Object.prototype.hasOwnProperty.call(l,N),c=f.map(N=>ye(N,m(N)?l[N]:void 0)),p=i.map(N=>be(l,N));return Ne(f,c,i,p,N=>c.every(E=>!Number.isNaN(E[N]))&&p.every(E=>!D(E[N])),t)}if(typeof e!="object"||e===null)throw new TypeError("x must be a data frame");let r=Object.keys(e),o=r.map(l=>ye(l,e[l])),a=Object.keys(n);if(a.length===0)throw new RangeError("'by' must name at least one grouping column");let s=a.map(l=>be(n,l));return Ne(r,o,a,s,()=>!0,t)}var jn=new Set(["cols","namesTo","namesPrefix","namesSep","namesPattern","namesTransform","valuesTo","valuesDropNa","colsVary","onWarning"]),Cn=new Set(["namesFrom","valuesFrom","idCols","namesPrefix","namesSep","namesSort","namesVary","valuesFill","valuesFn"]),te=e=>typeof e=="string"?[e]:[...e];function Ae(e,n){if(n==null)return"fastest";if(n==="fastest"||n==="slowest")return n;throw typeof n!="string"?new TypeError(`\`${e}\` must be a string or character vector.`):new RangeError(`\`${e}\` must be one of "fastest" or "slowest", not "${n}".`)}function re(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new RangeError(`Column \`${t}\` doesn't exist.`)}function Me(e,n){if(n instanceof Float64Array)return"double";let t=null;for(let r of n){if(r===null)continue;let o=typeof r=="number"?"double":typeof r=="string"?"character":"logical";if(t!==null&&o!==t)throw new TypeError(`column '${e}' mixes ${t} and ${o} values`);t=o}return t}function Ln(e,n){let t=null;for(let r of n){let o=Me(r,e[r]);if(o!==null){if(t===null)t={type:o,column:r};else if(t.type!==o){if(t.type==="character"||o==="character")throw new TypeError(`Can't combine \`${t.column}\` <${t.type}> and \`${r}\` <${o}>.`);o==="double"&&(t={type:o,column:r})}}}return t?.type??null}function Re(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new TypeError(`\`regex\` should define ${t} groups; ${r} found.`);let o=new RegExp(n);return e.map(a=>{let s=o.exec(a);return Array.from({length:t},(l,f)=>s===null?null:s[f+1]??null)})}function Pn(e,n){let t=e.charCodeAt(n);if(t>=55296&&t<=56319&&n+1<e.length){let r=e.charCodeAt(n+1);if(r>=56320&&r<=57343)return 2}return 1}function Vn(e,n,t,r){let o=new RegExp(n,"g"),a=[],s=[],l=e.map((i,m)=>{let c=[],p=0,h=0;for(;;){o.lastIndex=p;let N=o.exec(i);if(N===null||(c.push(i.slice(h,N.index)),h=N.index+N[0].length,p=N[0].length===0?N.index+Pn(i,N.index):h,p>=i.length))break}return c.push(i.slice(h)),c.length>t&&a.push(m+1),c.length<t&&s.push(m+1),Array.from({length:t},(N,E)=>c[E]??null)}),f=i=>`${i.length} rows [${i.join(", ")}]`;return a.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${f(a)}.`),s.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${f(s)}.`),l}function ve(e,n){return e!==void 0&&Object.hasOwn(e,n)?e[n]:void 0}function Un(e,n,t,r){let{namesSep:o,namesPattern:a}=t;if(n.length===0)return e.map(()=>[]);if(n.length===1){if(o!==void 0)throw new TypeError("`names_sep` can't be used with a length 1 `names_to`.");return a===void 0?e.map(s=>[s]):Re(e,a,1)}if(o===void 0==(a===void 0))throw new TypeError("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?Vn(e,o,n.length,r):Re(e,a,n.length)}function qn(e,n){S(n,jn,"pivotLonger");let t=Ae("cols_vary",n.colsVary),r=Z(e),o=Object.keys(e),a=typeof n.cols=="function"?o.filter(n.cols):[...new Set(n.cols)];if(re(e,a),a.length===0)throw new RangeError("`cols` must select at least one column.");let s=te(n.namesTo??"name"),l=s.indexOf(".value");if(s.lastIndexOf(".value")!==l)throw new RangeError('`names_to` may contain ".value" only once');let f=[],i=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),m=a.map(d=>i===null?d:d.replace(i,"")),c=Un(m,s,n,f),p=[],h=[];if(l<0)p.push(...c),h.push({name:n.valuesTo??"value",sources:[...a]});else{let d=new Map,w=new Map,x=ve(n.namesTransform,".value");c.forEach((u,b)=>{let v=u.filter((_,I)=>I!==l),O=JSON.stringify(v),A=d.get(O);if(A===void 0){A=p.length,d.set(O,A),p.push(v);for(let _ of h)_.sources.push(null)}let R=u[l]??null,$=R===null||x===void 0?R:x(R);if($!==null&&typeof $!="string")throw new TypeError(`the transform of \`.value\` must give strings, not ${typeof $}`);let k=$??"NA",T=w.get(k);if(T===void 0&&(T={name:k,sources:p.map(()=>null)},w.set(k,T),h.push(T)),T.sources[A]!==null)throw new RangeError(`the names give the value column '${k}' twice for one key`);T.sources[A]=a[b]})}let N=h.map(d=>Ln(e,d.sources.filter(w=>w!==null))),E=[];if(t==="slowest")for(let d=0;d<p.length;d++)for(let w=0;w<r;w++)E.push([w,d]);else for(let d=0;d<r;d++)for(let w=0;w<p.length;w++)E.push([d,w]);let M=(d,w,x)=>{let u=d.sources[x];return u==null?null:e[u][w]};n.valuesDropNa===!0&&(E=E.filter(([d,w])=>h.some(x=>!W(M(x,d,w)))));let g={},y=E.map(([d])=>d);for(let d of o)a.includes(d)||F(g,d,G(e[d],y));if(s.forEach((d,w)=>{if(w===l)return;let x=ve(n.namesTransform,d),u=b=>{let v=p[b][w<l||l<0?w:w-1];return v===null||x===void 0?v:x(v)};F(g,d,E.map(([,b])=>u(b)))}),h.forEach((d,w)=>{let x=N[w]==="double";if(x&&d.sources.every(u=>u!==null&&e[u]instanceof Float64Array))F(g,d.name,Float64Array.from(E,([u,b])=>M(d,u,b)));else{let u=E.map(([b,v])=>{let O=M(d,b,v);return x&&typeof O=="boolean"?Number(O):O});F(g,d.name,u)}}),n.onWarning!==void 0)for(let d of new Set(f))n.onWarning(d);else le("pivotLonger",f);return g}var oe=e=>typeof e=="number"?"double":typeof e=="string"?"character":"logical";function Yn(e,n){if(e===null||n===null)return e;let t=oe(e);if(t===n)return e;if(n==="double"&&t==="logical")return Number(e);if(n==="logical"&&t==="double"){let r=e;if(Number.isNaN(r))return null;if(r===0||r===1)return r===1;throw new TypeError("Can't convert from `fill` <double> to <logical> due to loss of precision.")}throw new TypeError(`Can't convert \`fill\` <${t}> to <${n}>.`)}var Kn=e=>W(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function $e(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(a,s)=>{let l=JSON.stringify(e.map(i=>Kn(i[s]))),f=t.get(l);return f===void 0&&(f=r.length,t.set(l,f),r.push(s)),f}),firsts:r}}function Wn(e){return W(e)?"NA":typeof e=="number"?Number.isFinite(e)?Y(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function ne(e,n,t){if(e!==void 0)return n(e)?e:Object.hasOwn(e,t)?e[t]:void 0}function zn(e,n={}){S(n,Cn,"pivotWider");let t=Ae("names_vary",n.namesVary),r=Z(e),o=(u,b)=>{let v=[...new Set(te(u))];if(re(e,v),v.length===0)throw new RangeError(`\`${b}\` must select at least one column.`);return v},a=o(n.namesFrom??"name","names_from"),s=o(n.valuesFrom??"value","values_from"),l=n.idCols===void 0?Object.keys(e).filter(u=>!a.includes(u)&&!s.includes(u)):[...new Set(te(n.idCols))];re(e,l);for(let u of l){let b=a.includes(u)?"names_from":s.includes(u)?"values_from":null;if(b!==null)throw new RangeError(`\`id_cols\` can't select a column already selected by \`${b}\`. Column \`${u}\` has already been selected.`)}let f=n.namesPrefix??"",i=n.namesSep??"_",m=$e(l.map(u=>e[u]),r),c=$e(a.map(u=>e[u]),r),p=c.firsts.map((u,b)=>b);n.namesSort===!0&&p.sort((u,b)=>{for(let v of a){let O=fe(e[v][c.firsts[u]],e[v][c.firsts[b]]);if(O!==0)return O}return 0});let h=c.firsts.map(u=>f+a.map(b=>Wn(e[b][u])).join(i)),N=c.firsts.length,E=Array.from({length:m.firsts.length*N},()=>[]);for(let u=0;u<r;u++)E[m.codes[u]*N+c.codes[u]].push(u);let M=u=>typeof u=="function",g=u=>typeof u!="object"||u===null;for(let u of s)if(ne(n.valuesFn,M,u)===void 0&&E.some(b=>b.length>1))throw new RangeError(`values from '${u}' are not uniquely identified; use valuesFn to summarise them`);let y=new Map;for(let u of s){let b=e[u],v=ne(n.valuesFn,M,u),O=new Array(E.length).fill(null),A=null;if(v===void 0)A=Me(u,b),E.forEach(($,k)=>{$.length>0&&(O[k]=b[$[0]])});else{let $=new Uint8Array(E.length),k=0,T=0;for(let _=0;_<r;_++){let I=m.codes[_]*N+c.codes[_];if($[I]===1)continue;$[I]=1,T++;let U=v(E[I].map(Oe=>b[Oe]));if(O[I]=U,U==null)continue;let P=oe(U);if(A===null||A==="logical"&&P==="double")A=P,k=T;else if(P!==A&&(A==="character"||P==="character"))throw new TypeError(`Can't combine \`x[[${k}]]\` <${A}> and \`x[[${T}]]\` <${P}>.`)}}let R=Yn(ne(n.valuesFill,g,u)??null,A);y.set(u,{cells:O,type:A??(R===null?null:oe(R)),fill:R})}let d=(u,b)=>{let v=e[u],{cells:O,type:A,fill:R}=y.get(u),$=m.firsts.map((k,T)=>{let _=T*N+b,I=E[_].length===0?R:O[_];return A==="double"&&typeof I=="boolean"?Number(I):I});return v instanceof Float64Array&&(A==="double"||A===null)?Float64Array.from($,k=>k===null?NaN:k):$},w={};for(let u of l)F(w,u,G(e[u],m.firsts));let x=(u,b)=>s.length===1?h[b]:`${u}${i}${h[b]}`;if(t==="slowest")for(let u of p)for(let b of s)F(w,x(b,u),d(b,u));else for(let u of s)for(let b of p)F(w,x(u,b),d(u,b));return w}export{X as IQR,In as aggregate,de as completeCases,Te as cor,Fe as cov,Ke as cummax,We as cummin,Ye as cumprod,qe as cumsum,tn as cut,Je as cv,ze as diff,Rn as ecdf,rn as findInterval,un as fivenum,Ie as fromRows,Qe as geometricMean,Nn as hist,De as kurtosis,fn as mad,Pe as mean,Ge as meanAD,j as median,Se as merge,Ze as modes,hn as naOmit,qn as pivotLonger,zn as pivotWider,we as pretty,Le as prod,B as quantile,C as range,ke as rank,Xe as scale,z as sd,Be as skewness,Sn as split,_e as subset,Ce as sum,en as table,He as tabulate,kn as tapply,je as toRows,nn as unique,Ue as variance,Ve as weightedMean};
|
|
@@ -11,6 +11,11 @@ import { d0, dt0, dt1, quantileBoundaries } from "../internal/dpq.js";
|
|
|
11
11
|
import { ddAdd, ddLog, ddMulNum, ddSub, twoSum } from "../special/dd.js";
|
|
12
12
|
import { ddExp } from "../internal/ddexp.js";
|
|
13
13
|
import { pbeta1, qbeta1 } from "./beta.js";
|
|
14
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
15
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
16
|
+
const DARCSINE_KEYS = ["a", "b", "log"];
|
|
17
|
+
const PARCSINE_KEYS = ["a", "b", "lowerTail", "logP"];
|
|
18
|
+
const QARCSINE_KEYS = ["a", "b", "lowerTail", "logP"];
|
|
14
19
|
const valid = (a, b) => Number.isFinite(a) && Number.isFinite(b) && a < b;
|
|
15
20
|
export function darcsine1(x, a, b, log) {
|
|
16
21
|
if (Number.isNaN(x) || !valid(a, b))
|
|
@@ -128,6 +133,7 @@ export function qarcsine1(p, a, b, lowerTail, logP) {
|
|
|
128
133
|
* @category Distributions
|
|
129
134
|
*/
|
|
130
135
|
export function darcsine(x, options = {}) {
|
|
136
|
+
checkOptions(options, DARCSINE_KEYS, "darcsine"); // generated: option-keys.mjs
|
|
131
137
|
const { a = 0, b = 1, log = false } = options;
|
|
132
138
|
return vectorize(x, (v) => darcsine1(v, a, b, log));
|
|
133
139
|
}
|
|
@@ -144,6 +150,7 @@ export function darcsine(x, options = {}) {
|
|
|
144
150
|
* @category Distributions
|
|
145
151
|
*/
|
|
146
152
|
export function parcsine(q, options = {}) {
|
|
153
|
+
checkOptions(options, PARCSINE_KEYS, "parcsine"); // generated: option-keys.mjs
|
|
147
154
|
const { a = 0, b = 1, lowerTail = true, logP = false } = options;
|
|
148
155
|
return vectorize(q, (v) => parcsine1(v, a, b, lowerTail, logP));
|
|
149
156
|
}
|
|
@@ -160,6 +167,7 @@ export function parcsine(q, options = {}) {
|
|
|
160
167
|
* @category Distributions
|
|
161
168
|
*/
|
|
162
169
|
export function qarcsine(p, options = {}) {
|
|
170
|
+
checkOptions(options, QARCSINE_KEYS, "qarcsine"); // generated: option-keys.mjs
|
|
163
171
|
const { a = 0, b = 1, lowerTail = true, logP = false } = options;
|
|
164
172
|
return vectorize(p, (v) => qarcsine1(v, a, b, lowerTail, logP));
|
|
165
173
|
}
|