@numero-uno-jpn/rstats 1.10.0 → 1.12.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 +17 -0
- package/README.ja.md +8 -6
- package/README.md +8 -6
- package/dist/causal/balance.d.ts +106 -0
- package/dist/causal/balance.js +216 -0
- package/dist/causal/match.d.ts +86 -0
- package/dist/causal/match.js +155 -0
- package/dist/causal/scale.d.ts +8 -0
- package/dist/causal/scale.js +26 -0
- package/dist/causal.js +2 -0
- package/dist/chunks/chunk-2P42OXYW.js +2 -0
- package/dist/chunks/{chunk-GYLFMAD6.js → chunk-3QOW56EJ.js} +2 -2
- package/dist/chunks/chunk-3QSYPBUM.js +2 -0
- package/dist/chunks/chunk-4B7NEJCE.js +2 -0
- package/dist/chunks/{chunk-PJ73WRSA.js → chunk-4GRV66HW.js} +2 -2
- package/dist/chunks/chunk-4U65I4J2.js +2 -0
- package/dist/chunks/chunk-52KGBGFL.js +2 -0
- package/dist/chunks/{chunk-Y7SXBQZY.js → chunk-5AR4V7MW.js} +2 -2
- package/dist/chunks/chunk-7FXBOYIH.js +2 -0
- package/dist/chunks/{chunk-ZUHBIFAJ.js → chunk-7K2LMKZR.js} +2 -2
- package/dist/chunks/chunk-7UI4PW32.js +2 -0
- package/dist/chunks/{chunk-IFFGJN5L.js → chunk-CHKBDZC4.js} +2 -2
- package/dist/chunks/chunk-CKBUE4FV.js +2 -0
- package/dist/chunks/chunk-CMTCPLIA.js +2 -0
- package/dist/chunks/chunk-DWVTVOQS.js +2 -0
- package/dist/chunks/chunk-FFMMKXMK.js +2 -0
- package/dist/chunks/chunk-HF3QOIZX.js +2 -0
- package/dist/chunks/chunk-JG26HC2H.js +2 -0
- package/dist/chunks/chunk-L54WIMTZ.js +3 -0
- package/dist/chunks/{chunk-ISNGTKVZ.js → chunk-MAFZ5FGL.js} +2 -2
- package/dist/chunks/{chunk-F3WMBL5R.js → chunk-MJ7IY7AF.js} +2 -2
- package/dist/chunks/chunk-MUYGPZ37.js +3 -0
- package/dist/chunks/chunk-NAACMR7H.js +2 -0
- package/dist/chunks/chunk-NGDBJR3K.js +2 -0
- package/dist/chunks/chunk-NQT7ZWL6.js +2 -0
- package/dist/chunks/{chunk-6U2ICRN3.js → chunk-O6OMXX5U.js} +1 -1
- package/dist/chunks/chunk-PYFASERO.js +2 -0
- package/dist/chunks/chunk-QT32BMYA.js +2 -0
- package/dist/chunks/{chunk-6BDTLUNM.js → chunk-SKQHW2GD.js} +2 -2
- package/dist/chunks/{chunk-EDHAQHB7.js → chunk-SLMS3FQD.js} +1 -1
- package/dist/chunks/{chunk-6Y7OKIIM.js → chunk-SZR5HAMB.js} +2 -2
- package/dist/chunks/chunk-T5TE5KCP.js +2 -0
- package/dist/chunks/chunk-ULQXNAI6.js +2 -0
- package/dist/chunks/chunk-UPFMYDF7.js +2 -0
- package/dist/chunks/{chunk-DC2FP6ZH.js → chunk-WACTNIKS.js} +2 -2
- package/dist/chunks/{chunk-F5K2UXKW.js → chunk-WSDLT4AR.js} +1 -1
- package/dist/chunks/chunk-WUNTM7PJ.js +2 -0
- package/dist/chunks/chunk-XQSYV3IZ.js +2 -0
- package/dist/chunks/chunk-YKCZF4ES.js +2 -0
- package/dist/chunks/{chunk-NNJGXB5K.js → chunk-ZHAT6244.js} +2 -2
- package/dist/chunks/{chunk-OQFZKQVT.js → chunk-ZK7FW5UX.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/causal.d.ts +2 -0
- package/dist/entries/causal.js +3 -0
- package/dist/entries/multivariate.d.ts +4 -0
- package/dist/entries/multivariate.js +4 -0
- package/dist/entries/tests.d.ts +1 -0
- package/dist/entries/tests.js +1 -0
- package/dist/entries/timeseries.d.ts +1 -0
- package/dist/entries/timeseries.js +2 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/clogit.d.ts +80 -0
- package/dist/models/clogit.js +211 -0
- package/dist/models/coxph.d.ts +9 -0
- package/dist/models/coxph.js +3 -3
- package/dist/multivariate/ca.d.ts +120 -0
- package/dist/multivariate/ca.js +230 -0
- package/dist/multivariate/isoMDS.d.ts +55 -0
- package/dist/multivariate/isoMDS.js +409 -0
- package/dist/multivariate/mjca.d.ts +125 -0
- package/dist/multivariate/mjca.js +243 -0
- package/dist/multivariate/sammon.d.ts +66 -0
- package/dist/multivariate/sammon.js +231 -0
- package/dist/multivariate.js +2 -2
- package/dist/numerics.js +2 -2
- package/dist/regression.js +2 -2
- package/dist/rstats.js +18 -18
- package/dist/special.js +2 -2
- package/dist/tests.js +15 -15
- package/dist/timeseries/acf.d.ts +80 -0
- package/dist/timeseries/acf.js +314 -0
- package/dist/timeseries.js +2 -0
- package/llms.txt +51 -2
- package/package.json +11 -1
- package/dist/chunks/chunk-3QUOB47N.js +0 -2
- package/dist/chunks/chunk-5PVS6TF2.js +0 -2
- package/dist/chunks/chunk-AQ7H4RJH.js +0 -2
- package/dist/chunks/chunk-CN5D6ITZ.js +0 -3
- package/dist/chunks/chunk-F232C4SB.js +0 -3
- package/dist/chunks/chunk-JPQEOHZG.js +0 -2
- package/dist/chunks/chunk-JRMISESC.js +0 -2
- package/dist/chunks/chunk-K25FNCFH.js +0 -2
- package/dist/chunks/chunk-KGDCQ2RV.js +0 -2
- package/dist/chunks/chunk-LQWAHXHZ.js +0 -2
- package/dist/chunks/chunk-MBQJWNPX.js +0 -2
- package/dist/chunks/chunk-MULNGWZY.js +0 -2
- package/dist/chunks/chunk-MVIBJA2I.js +0 -2
- package/dist/chunks/chunk-NAUAW5TO.js +0 -2
- package/dist/chunks/chunk-NMVFSSEZ.js +0 -2
- package/dist/chunks/chunk-OXYMJNVJ.js +0 -2
- package/dist/chunks/chunk-R5BXUEH3.js +0 -2
- package/dist/chunks/chunk-RPEFV4FR.js +0 -2
- package/dist/chunks/chunk-T3XFVWOW.js +0 -2
- package/dist/chunks/chunk-Y5M7NEJ5.js +0 -2
- package/dist/chunks/chunk-YCBQQHCB.js +0 -2
- package/dist/chunks/chunk-YGKM6PIJ.js +0 -2
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Nearest-neighbour matching on a scalar score without replacement, after the Matching package's Match(Tr, X,
|
|
2
|
+
// estimand, M, caliper, ties = FALSE, replace = FALSE): the behaviour and the choices are in oracle/match-behaviour.md.
|
|
3
|
+
// Written for rStats.js from the package's documentation and its published output (no ported code).
|
|
4
|
+
import { unifRand } from "../random/rng.js";
|
|
5
|
+
import { ldexp } from "../internal/summary.js";
|
|
6
|
+
import { rescaled } from "./scale.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 MATCH_KEYS = ["estimand", "M", "caliper"];
|
|
10
|
+
/**
|
|
11
|
+
* Nearest-neighbour matching on a scalar score, without replacement and with random tie-breaking. Equivalent to
|
|
12
|
+
* `Matching::Match()` in R. The call followed is
|
|
13
|
+
* `Match(Tr = tr, X = x, estimand, M, caliper, ties = FALSE, replace = FALSE)`, used with the linear predictor
|
|
14
|
+
* `logit(PS)` of a propensity score model.
|
|
15
|
+
*
|
|
16
|
+
* The matched units (the treated for ATT, the controls for ATC, all for ATE) are processed in data order. Each takes
|
|
17
|
+
* its matches from the units of the other group not yet used: every available unit within the M-th smallest distance
|
|
18
|
+
* is a candidate (within the caliper when one is given), and when there are more candidates than M, M of them are
|
|
19
|
+
* drawn at random. A unit with fewer than M available candidates is dropped. Pairs are listed in the order of the
|
|
20
|
+
* matched units, the controls of one treated unit (ATT) in row order.
|
|
21
|
+
*
|
|
22
|
+
* Random draws use rStats.js's generator (`setSeed`): one uniform `u` for each pick, and the candidate at 0-based
|
|
23
|
+
* index `floor(k (1 - u))` among the `k` remaining (in row order) is taken. Without ties no random number is used and
|
|
24
|
+
* the pairs are R's; with sets of two candidates the rule is R's (the second when `u < 0.5`). Known differences from
|
|
25
|
+
* R: larger tie sets are broken differently (R's rule is not documented), and distances count as tied only when
|
|
26
|
+
* exactly equal (R also treats distances within `distance.tolerance = 1e-5` as ties). `M` below 1 is an error (R
|
|
27
|
+
* warns and uses 1).
|
|
28
|
+
* @category Causal inference
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const m = match([1, 0, 1, 0, 0], [0.2, 0.1, 1.5, 1.4, 3]);
|
|
32
|
+
* m.indexTreated; // [1, 3]
|
|
33
|
+
* m.indexControl; // [2, 4]
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function match(tr, x, options = {}) {
|
|
37
|
+
checkOptions(options, MATCH_KEYS, "match"); // generated: option-keys.mjs
|
|
38
|
+
const { estimand = "ATT", M = 1, caliper } = options;
|
|
39
|
+
const n = tr.length;
|
|
40
|
+
if (x.length !== n)
|
|
41
|
+
throw new RangeError("length(Tr) != nrow(X)");
|
|
42
|
+
if (estimand !== "ATT" && estimand !== "ATE" && estimand !== "ATC")
|
|
43
|
+
throw new RangeError(`invalid 'estimand': ${String(estimand)}`);
|
|
44
|
+
if (!Number.isInteger(M) || M < 1)
|
|
45
|
+
throw new RangeError("'M' must be a positive integer");
|
|
46
|
+
if (caliper !== undefined && !(caliper > 0 && Number.isFinite(caliper)))
|
|
47
|
+
throw new RangeError("'caliper' must be a positive number");
|
|
48
|
+
const treated = [];
|
|
49
|
+
for (let i = 0; i < n; i++) {
|
|
50
|
+
const t = tr[i];
|
|
51
|
+
if (t === true || t === 1)
|
|
52
|
+
treated.push(true);
|
|
53
|
+
else if (t === false || t === 0)
|
|
54
|
+
treated.push(false);
|
|
55
|
+
else if (typeof t === "number" && Number.isNaN(t))
|
|
56
|
+
throw new RangeError("Match(): input includes NAs");
|
|
57
|
+
else
|
|
58
|
+
throw new RangeError("Treatment indicator ('Tr') must be a logical variable---i.e., TRUE (1) or FALSE (0)");
|
|
59
|
+
if (!Number.isFinite(x[i]))
|
|
60
|
+
throw new RangeError("Match(): input includes NAs");
|
|
61
|
+
}
|
|
62
|
+
if (!treated.includes(true) || !treated.includes(false)) {
|
|
63
|
+
throw new RangeError("Treatment indicator ('Tr') must contain both treatment and control observations");
|
|
64
|
+
}
|
|
65
|
+
// distances and the caliper in units of 2^e, the power of 2 of the largest |x|: exact (the ties stay ties), and
|
|
66
|
+
// neither overflowing for |x| near 1e308 nor underflowing for |x| near 1e-300
|
|
67
|
+
let top = 0;
|
|
68
|
+
for (const v of x)
|
|
69
|
+
top = Math.max(top, Math.abs(v));
|
|
70
|
+
const unitExp = top > 0 ? Math.floor(Math.log2(top)) : 0;
|
|
71
|
+
const xs = x.map((v) => ldexp(v, -unitExp));
|
|
72
|
+
let ecaliper = null;
|
|
73
|
+
let reach = Infinity; // the caliper in the units of xs
|
|
74
|
+
if (caliper !== undefined) {
|
|
75
|
+
// the SD with divisor n, from the column rescaled exactly (and shifted: a large common offset keeps its digits)
|
|
76
|
+
const { values: r, unitExp: rExp } = rescaled(xs);
|
|
77
|
+
let mean = 0;
|
|
78
|
+
for (const v of r)
|
|
79
|
+
mean += v;
|
|
80
|
+
mean /= n;
|
|
81
|
+
let ss = 0;
|
|
82
|
+
for (const v of r)
|
|
83
|
+
ss += (v - mean) * (v - mean);
|
|
84
|
+
const sd = ldexp(Math.sqrt(ss / n), rExp); // in the units of xs
|
|
85
|
+
reach = caliper * sd;
|
|
86
|
+
ecaliper = ldexp(reach, unitExp);
|
|
87
|
+
}
|
|
88
|
+
// separate pools: the controls still available to treated units, the treated still available to controls
|
|
89
|
+
const used = [new Array(n).fill(false), new Array(n).fill(false)]; // [for treated, for controls]
|
|
90
|
+
const indexTreated = [];
|
|
91
|
+
const indexControl = [];
|
|
92
|
+
const dropped = [];
|
|
93
|
+
const tieSizes = [];
|
|
94
|
+
let wnobs = 0;
|
|
95
|
+
let ndrops = 0;
|
|
96
|
+
for (let i = 0; i < n; i++) {
|
|
97
|
+
const isT = treated[i];
|
|
98
|
+
if (isT ? estimand === "ATC" : estimand === "ATT")
|
|
99
|
+
continue;
|
|
100
|
+
const pool = used[isT ? 0 : 1];
|
|
101
|
+
// available units of the other group within the caliper, with their distances
|
|
102
|
+
const cand = [];
|
|
103
|
+
for (let j = 0; j < n; j++) {
|
|
104
|
+
if (treated[j] === isT)
|
|
105
|
+
continue;
|
|
106
|
+
const d = Math.abs(xs[i] - xs[j]);
|
|
107
|
+
if (d > reach)
|
|
108
|
+
continue;
|
|
109
|
+
if (!pool[j])
|
|
110
|
+
cand.push({ j, d });
|
|
111
|
+
}
|
|
112
|
+
if (cand.length < M) {
|
|
113
|
+
ndrops++;
|
|
114
|
+
dropped.push(i + 1);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// the M-th smallest distance; every candidate within it
|
|
118
|
+
const sorted = cand.map((c) => c.d).sort((a, b) => a - b);
|
|
119
|
+
const dM = sorted[M - 1];
|
|
120
|
+
let set = cand.filter((c) => c.d <= dM).map((c) => c.j); // row order
|
|
121
|
+
let chosen;
|
|
122
|
+
if (set.length === M)
|
|
123
|
+
chosen = set;
|
|
124
|
+
else {
|
|
125
|
+
tieSizes.push(set.length);
|
|
126
|
+
chosen = [];
|
|
127
|
+
set = set.slice();
|
|
128
|
+
for (let p = 0; p < M; p++) {
|
|
129
|
+
const k = set.length;
|
|
130
|
+
const idx = Math.min(k - 1, Math.floor(k * (1 - unifRand())));
|
|
131
|
+
chosen.push(set[idx]);
|
|
132
|
+
set.splice(idx, 1);
|
|
133
|
+
}
|
|
134
|
+
chosen.sort((a, b) => a - b);
|
|
135
|
+
}
|
|
136
|
+
for (const j of chosen) {
|
|
137
|
+
pool[j] = true;
|
|
138
|
+
indexTreated.push((isT ? i : j) + 1);
|
|
139
|
+
indexControl.push((isT ? j : i) + 1);
|
|
140
|
+
}
|
|
141
|
+
wnobs++;
|
|
142
|
+
}
|
|
143
|
+
// R lists (with a caliper) the dropped units that appear in no pair: under ATE a dropped unit may still be the match
|
|
144
|
+
// of another unit
|
|
145
|
+
const inPairs = new Set([...indexTreated, ...indexControl]);
|
|
146
|
+
const listed = ecaliper === null ? [] : dropped.filter((r) => !inPairs.has(r));
|
|
147
|
+
const warnings = [];
|
|
148
|
+
if (indexTreated.length === 0) {
|
|
149
|
+
warnings.push("'Match' object contains no valid matches (probably because of the caliper or the exact option).");
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
indexTreated, indexControl, weights: indexTreated.map(() => 1 / M), indexDropped: listed.length > 0 ? listed : null,
|
|
153
|
+
caliper: caliper ?? null, ecaliper, nobs: n, wnobs, ndrops, estimand, M, tieSizes, warnings,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The column as `(v 2^-e1 - first) 2^-e2`, and the exponent e1 + e2 back to the original units (of spreads, not of
|
|
3
|
+
* locations: a spread s of the result is s 2^(e1 + e2)). A constant column comes back as zeros.
|
|
4
|
+
*/
|
|
5
|
+
export declare function rescaled(values: readonly number[]): {
|
|
6
|
+
values: number[];
|
|
7
|
+
unitExp: number;
|
|
8
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Exact rescaling of a column before its moments: by a power of 2 (no rounding) so that its largest magnitude is near
|
|
2
|
+
// 1, then shifted by its first value (exact for nearby values, Sterbenz) and rescaled again. Standardised differences
|
|
3
|
+
// and variance ratios do not change under v -> (v - a) c, c > 0, while the sums of squares then neither overflow
|
|
4
|
+
// (values near 1e300) nor underflow (near 1e-300) nor lose the digits a large common offset (1e15 + small
|
|
5
|
+
// differences) takes from them. Written for rStats.js.
|
|
6
|
+
import { ldexp } from "../internal/summary.js";
|
|
7
|
+
/** The largest finite magnitude's power of 2 (0 for an all-zero column). */
|
|
8
|
+
function exponentOf(values) {
|
|
9
|
+
let top = 0;
|
|
10
|
+
for (const v of values)
|
|
11
|
+
if (Math.abs(v) > top)
|
|
12
|
+
top = Math.abs(v);
|
|
13
|
+
return top > 0 && Number.isFinite(top) ? Math.floor(Math.log2(top)) : 0;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The column as `(v 2^-e1 - first) 2^-e2`, and the exponent e1 + e2 back to the original units (of spreads, not of
|
|
17
|
+
* locations: a spread s of the result is s 2^(e1 + e2)). A constant column comes back as zeros.
|
|
18
|
+
*/
|
|
19
|
+
export function rescaled(values) {
|
|
20
|
+
const e1 = exponentOf(values);
|
|
21
|
+
const scaled = values.map((v) => ldexp(v, -e1));
|
|
22
|
+
const first = scaled[0] ?? 0;
|
|
23
|
+
const shifted = scaled.map((v) => v - first);
|
|
24
|
+
const e2 = exponentOf(shifted);
|
|
25
|
+
return { values: shifted.map((v) => ldexp(v, -e2)), unitExp: e1 + e2 };
|
|
26
|
+
}
|
package/dist/causal.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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 $}from"./chunks/chunk-2P42OXYW.js";import"./chunks/chunk-4U65I4J2.js";import"./chunks/chunk-XQSYV3IZ.js";import"./chunks/chunk-4B7NEJCE.js";import{g as K}from"./chunks/chunk-DWVTVOQS.js";import"./chunks/chunk-O6OMXX5U.js";import{h as U}from"./chunks/chunk-NAACMR7H.js";import{l as C}from"./chunks/chunk-52KGBGFL.js";function k(r){let n=0;for(let u of r)Math.abs(u)>n&&(n=Math.abs(u));return n>0&&Number.isFinite(n)?Math.floor(Math.log2(n)):0}function B(r){let n=k(r),u=r.map(o=>U(o,-n)),s=u[0]??0,d=u.map(o=>o-s),l=k(d);return{values:d.map(o=>U(o,-l)),unitExp:n+l}}var Y=["estimand","M","caliper"];function z(r,n,u={}){C(u,Y,"match");let{estimand:s="ATT",M:d=1,caliper:l}=u,o=r.length;if(n.length!==o)throw new RangeError("length(Tr) != nrow(X)");if(s!=="ATT"&&s!=="ATE"&&s!=="ATC")throw new RangeError(`invalid 'estimand': ${String(s)}`);if(!Number.isInteger(d)||d<1)throw new RangeError("'M' must be a positive integer");if(l!==void 0&&!(l>0&&Number.isFinite(l)))throw new RangeError("'caliper' must be a positive number");let T=[];for(let a=0;a<o;a++){let g=r[a];if(g===!0||g===1)T.push(!0);else if(g===!1||g===0)T.push(!1);else throw typeof g=="number"&&Number.isNaN(g)?new RangeError("Match(): input includes NAs"):new RangeError("Treatment indicator ('Tr') must be a logical variable---i.e., TRUE (1) or FALSE (0)");if(!Number.isFinite(n[a]))throw new RangeError("Match(): input includes NAs")}if(!T.includes(!0)||!T.includes(!1))throw new RangeError("Treatment indicator ('Tr') must contain both treatment and control observations");let v=0;for(let a of n)v=Math.max(v,Math.abs(a));let i=v>0?Math.floor(Math.log2(v)):0,c=n.map(a=>U(a,-i)),S=null,w=1/0;if(l!==void 0){let{values:a,unitExp:g}=B(c),R=0;for(let M of a)R+=M;R/=o;let y=0;for(let M of a)y+=(M-R)*(M-R);let _=U(Math.sqrt(y/o),g);w=l*_,S=U(w,i)}let A=[new Array(o).fill(!1),new Array(o).fill(!1)],t=[],e=[],m=[],p=[],N=0,h=0;for(let a=0;a<o;a++){let g=T[a];if(g?s==="ATC":s==="ATT")continue;let R=A[g?0:1],y=[];for(let f=0;f<o;f++){if(T[f]===g)continue;let j=Math.abs(c[a]-c[f]);j>w||R[f]||y.push({j:f,d:j})}if(y.length<d){h++,m.push(a+1);continue}let M=y.map(f=>f.d).sort((f,j)=>f-j)[d-1],O=y.filter(f=>f.d<=M).map(f=>f.j),q;if(O.length===d)q=O;else{p.push(O.length),q=[],O=O.slice();for(let f=0;f<d;f++){let j=O.length,F=Math.min(j-1,Math.floor(j*(1-K())));q.push(O[F]),O.splice(F,1)}q.sort((f,j)=>f-j)}for(let f of q)R[f]=!0,t.push((g?a:f)+1),e.push((g?f:a)+1);N++}let E=new Set([...t,...e]),b=S===null?[]:m.filter(a=>!E.has(a)),x=[];return t.length===0&&x.push("'Match' object contains no valid matches (probably because of the caliper or the exact option)."),{indexTreated:t,indexControl:e,weights:t.map(()=>1/d),indexDropped:b.length>0?b:null,caliper:l??null,ecaliper:S,nobs:o,wnobs:N,ndrops:h,estimand:s,M:d,tieSizes:p,warnings:x}}var I=["match","weights","estimand","binary"],W=["factor"];function L(r){let n=new Array(r.nobs).fill(0);return r.indexTreated.forEach((u,s)=>{n[u-1]+=r.weights[s],n[r.indexControl[s]-1]+=r.weights[s]}),n}function H(r,n){if(r===!0||r===1)return!0;if(r===!1||r===0)return!1;throw new RangeError(`'tr' must be 0 or 1 (element ${n+1})`)}function D(r,n,u,s){let d=0,l=0,o=0;for(let i=0;i<r.length;i++){if(u[i]!==s)continue;let c=n===null?1:n[i];d+=c,l+=c*c,o+=c*r[i]}let T=o/d,v=0;for(let i=0;i<r.length;i++){if(u[i]!==s)continue;let c=n===null?1:n[i];v+=c*(r[i]-T)*(r[i]-T)}return[T,v/(d-l/d)]}function P(r,n,u={}){C(u,I,"balTab");let{match:s,binary:d="raw"}=u,l=s===void 0?u.weights:L(s),o=s?.estimand??u.estimand??"ATT",T=new Set(s?.indexDropped??[]),v=s!==void 0&&s.caliper!==null,i=r.length,c=r.map(H);if(!c.includes(!0)||!c.includes(!1))throw new RangeError("'tr' must contain both groups");if(l!==void 0&&l.length!==i)throw new RangeError("'weights' must have the length of 'tr'");let S=Object.keys(n),w={rows:S,type:[],diffUn:[],diffAdj:[],vRatioUn:[],vRatioAdj:[],observations:{rows:["All (ESS)","All (Unweighted)","Matched (ESS)","Matched (Unweighted)","Unmatched",...v?["Discarded"]:[]],control:[],treated:[]}};for(let A of S){let t=n[A];if(t.length!==i)throw new RangeError(`covariate '${A}' must have the length of 'tr'`);if(t.some(M=>!Number.isFinite(M)))throw new RangeError(`covariate '${A}' has missing or infinite values`);let e=new Set(t).size<=2&&t.every(M=>M===0||M===1),m=e?t:B(t).values,[p,N]=D(m,null,c,!0),[h,E]=D(m,null,c,!1),b=e?[p*(1-p),h*(1-h)]:[N,E],x=Math.sqrt(o==="ATT"?b[0]:o==="ATC"?b[1]:(b[0]+b[1])/2),a=e&&d==="raw"?1:x;if(w.type.push(e?"Binary":"Contin."),w.diffUn.push(p===h?0:(p-h)/a),w.vRatioUn.push(e||E===0?NaN:N/E),l===void 0){w.diffAdj.push(NaN),w.vRatioAdj.push(NaN);continue}let[g,R]=D(m,l,c,!0),[y,_]=D(m,l,c,!1);w.diffAdj.push(g===y?0:(g-y)/a),w.vRatioAdj.push(e||_===0?NaN:R/_)}for(let A of[!1,!0]){let t=0,e=0,m=0,p=0,N=0;for(let E=0;E<i;E++){if(c[E]!==A||(t++,T.has(E+1)&&N++,l===void 0))continue;let b=l[E];e+=b,m+=b*b,b>0&&p++}let h=l===void 0?[NaN,NaN,NaN]:[e*e/m,p,t-p-N];v&&h.push(N),(A?w.observations.treated:w.observations.control).push(t,t,...h)}return w}function X(r,n,u={}){C(u,W,"tableOneSmd");let{factor:s=!1}=u;if(r.length!==n.length)throw new RangeError("'x' and 'group' must have the same length");let d=[...new Set(n)].sort((t,e)=>t<e?-1:t>e?1:0);if(d.length!==2)throw new RangeError("'group' must have exactly two levels");let l=t=>t!==null&&!(typeof t=="number"&&Number.isNaN(t)),o=d.map(t=>r.filter((e,m)=>n[m]===t&&l(e)));if(!s){if(o.flat().some(h=>typeof h!="number"))throw new TypeError("'x' must be numeric unless factor: true");let t=B(o.flat()).values,m=[t.slice(0,o[0].length),t.slice(o[0].length)].map(h=>{let E=h.reduce((b,x)=>b+x,0)/h.length;return[E,h.reduce((b,x)=>b+(x-E)*(x-E),0)/(h.length-1)]}),p=m[1][0]-m[0][0],N=Math.sqrt((m[0][1]+m[1][1])/2);return p===0?0:Math.abs(p)/N}let T=[...new Set(o.flat())].sort((t,e)=>typeof t=="number"&&typeof e=="number"?t-e:String(t)<String(e)?-1:String(t)>String(e)?1:0),v=o.map(t=>T.slice(1).map(e=>t.filter(m=>m===e).length/t.length)),i=v[1].map((t,e)=>t-v[0][e]);if(i.every(t=>t===0))return 0;let c=i.length,S=Array.from({length:c},(t,e)=>Array.from({length:c},(m,p)=>{let N=h=>e===p?h[e]*(1-h[e]):-h[e]*h[p];return(N(v[0])+N(v[1]))/2}));if(S.every(t=>t.every(e=>e===0)))return NaN;let w=$(S),A=0;for(let t=0;t<c;t++)for(let e=0;e<c;e++)A+=i[t]*w[t][e]*i[e];return Math.sqrt(A)}export{P as balTab,z as match,L as matchWeights,X as tableOneSmd};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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 E,d as P,g as R}from"./chunk-4U65I4J2.js";import{b as j}from"./chunk-XQSYV3IZ.js";import{a as S,c as y,e as I,f as O,h as U,j as A,s as K}from"./chunk-4B7NEJCE.js";import{a as q,c as z}from"./chunk-O6OMXX5U.js";import{h as w}from"./chunk-NAACMR7H.js";import{l as x}from"./chunk-52KGBGFL.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};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{b as A}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{b as A}from"./chunk-SLMS3FQD.js";var y=t=>new SyntaxError(`invalid formula: ${t}`),L=/^(?:[\p{L}\p{Nl}.]|(?![0-9])\p{Nd})[\p{L}\p{Nl}\p{Nd}\p{M}._]*/u;function R(t,u,i=!1){let a=[],n=0;for(;n<t.length;){let e=t[n];if(/\s/.test(e)){n++;continue}if(/[0-9]/.test(e)||e==="."&&/[0-9]/.test(t[n+1]??"")){let c=/^(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:[eE][+-]?[0-9]+)?/.exec(t.slice(n));a.push({kind:"num",text:c[0]}),n+=c[0].length;continue}let r=L.exec(t.slice(n));if(r!==null){a.push({kind:"name",text:r[0]}),n+=r[0].length;continue}if(t.startsWith("%in%",n)){a.push({kind:"op",text:"%in%"}),n+=4;continue}if(u&&e==="|"){let c=t[n+1]==="|"?"||":"|";a.push({kind:"op",text:c}),n+=c.length;continue}if("~+-*/:^()".includes(e)||i&&e===","){a.push({kind:"op",text:e}),n++;continue}throw y(`unexpected '${e}'`)}return a.push({kind:"end"}),a}var T={"|":.5,"||":.5,"+":1,"-":1,"*":2,"/":2,"%in%":3,":":4,"^":6},C=5;function I(t,u=!1,i=!1,a=!1){if(typeof t!="string")throw new TypeError("the formula must be a string");let n=R(t,i,a),e=0,r=()=>n[e],c=()=>n[e++],f=(o,d)=>o.kind==="op"&&o.text===d;function m(){let o=c();if(o.kind==="name"){if(f(r(),"(")){if(o.text!=="Error"||!u)throw y(`function calls are not supported (${o.text})`);c();let d=g(0);if(!f(c(),")"))throw y("missing ')'");return{type:"Error",arg:d}}if(o.text===".")return{type:"dot"};if(/^\.[0-9]/.test(o.text))throw y(`unexpected '${o.text}'`);return{type:"var",name:o.text}}if(o.kind==="num")return{type:"num",value:Number(o.text),text:o.text};if(o.kind==="op"&&o.text==="("){let d=g(0);if(!f(c(),")"))throw y("missing ')'");return{type:"paren",arg:d}}if(o.kind==="op"&&(o.text==="-"||o.text==="+"))return{type:"unary",op:o.text,arg:g(C)};throw y(o.kind==="end"?"unexpected end of input":`unexpected '${o.kind==="op"?o.text:""}'`)}function g(o){let d=m();for(;;){let x=r();if(x.kind!=="op")break;let h=T[x.text];if(h===void 0||h<=o)break;c();let v=g(x.text==="^"?h-1:h);d=x.text==="|"||x.text==="||"?{type:"bar",double:x.text==="||",lhs:d,group:v}:{type:"binary",op:x.text,left:d,right:v}}return d}let b,l,s=n[0];if(a&&s.kind==="name"&&s.text==="cbind"&&f(n[1],"(")){let o=n[2],d=n[4],x=h=>h.kind==="name"&&h.text!=="."&&!/^\.[0-9]/.test(h.text);if(!(x(o)&&f(n[3],",")&&x(d)&&f(n[5],")")&&f(n[6],"~")))throw y("the response cbind() must have two column names: cbind(successes, failures)");l=[o.text,d.text],b=l[0],e=6}else if(!f(r(),"~")){let o=c();if(o.kind!=="name"||o.text==="."||!f(r(),"~"))throw y("the response must be a variable name followed by '~'");b=o.text}c();let p=g(0);if(r().kind!=="end")throw y("unexpected input after the formula");return l===void 0?{response:b,rhs:p}:{response:b,responseColumns:l,rhs:p}}function V(t){let u=[],i=e=>{if(e.type==="Error"){u.push(e.arg);return}if(e.type==="paren"){let r=i(e.arg);return r===void 0?void 0:{...e,arg:r}}if(e.type==="binary"&&e.op==="+"){let r=i(e.left),c=i(e.right);return r===void 0?c:c===void 0?r:{...e,left:r,right:c}}if(e.type==="binary"&&e.op==="-"){let r=i(e.left);return r===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:r}}return e},a=i(t),n=e=>{if(e.type==="Error")throw y("Error() must be a term of the right-hand side");e.type==="binary"?(n(e.left),n(e.right)):(e.type==="unary"||e.type==="paren")&&n(e.arg)};return a!==void 0&&n(a),u.forEach(n),{treatment:a,errors:u}}function Y(t){let u=[],i=e=>{switch(e.type){case"bar":u.push(e);return;case"paren":{let r=i(e.arg);return r===void 0?void 0:{...e,arg:r}}case"binary":if(e.op==="+"){let r=i(e.left),c=i(e.right);return r===void 0?c:c===void 0?r:{...e,left:r,right:c}}if(e.op==="-"){let r=i(e.left);return r===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:r}}return e;default:return e}},a=i(t),n=e=>{if(e.type==="bar")throw y("a random-effects term (lhs | group) must be a term of the right-hand side");e.type==="binary"?(n(e.left),n(e.right)):(e.type==="unary"||e.type==="paren"||e.type==="Error")&&n(e.arg)};a!==void 0&&n(a);for(let e of u)n(e.lhs),n(e.group);return{fixed:a,bars:u}}var M=new Set(["+","-","*","%in%"]);function w(t){switch(t.type){case"var":return t.name;case"dot":return".";case"num":return A(t.value);case"binary":{let u=w(t.left),i=w(t.right);return M.has(t.op)?`${u} ${t.op} ${i}`:`${u}${t.op}${i}`}case"unary":return`${t.op}${w(t.arg)}`;case"paren":return`(${w(t.arg)})`;case"Error":return`Error(${w(t.arg)})`;case"bar":return`${w(t.lhs)} ${t.double?"||":"|"} ${w(t.group)}`}}function k(t,u,i){if(t!==void 0)switch(t.type){case"var":i.includes(t.name)||i.push(t.name);return;case"dot":for(let a of u)i.includes(a)||i.push(a);return;case"num":return;case"binary":k(t.left,u,i),t.op!=="^"&&k(t.right,u,i);return;case"unary":case"paren":case"Error":k(t.arg,u,i);return;case"bar":k(t.lhs,u,i),k(t.group,u,i)}}function j(t,u){let i=[];return k(t,u,i),i}var N=t=>t.join(",");function E(t){let u=new Set;return t.filter(i=>{let a=N(i);return u.has(a)?!1:(u.add(a),!0)})}var $=(t,u)=>[...new Set([...t,...u])].sort((i,a)=>i-a);function B(t,u,i){let a=!0,n=(r,c)=>{switch(r.type){case"var":return[[u(r.name)]];case"dot":return i.map(f=>[u(f)]);case"num":if(r.value===1)a=!c;else if(r.value===0)a=c;else throw y(`a number (${r.text}) is not a term`);return[];case"paren":return n(r.arg,c);case"Error":throw y("Error() must be a term of the right-hand side");case"bar":throw y("a random-effects term (lhs | group) must be a term of the right-hand side");case"unary":return r.op==="+"?n(r.arg,c):(n(r.arg,!c),[]);case"binary":{if(r.op==="^"){let l=n(r.left,c),s=r.right;for(;s.type==="paren";)s=s.arg;let p=s.type==="num"?Math.trunc(s.value):NaN;if(!(p>=2&&p<=2147483647))throw new Error("invalid power in formula");let o=l;for(let d=1;d<p;d++){let x=[];for(let S of l)for(let O of o)x.push($(S,O));let h=E(x),v=h.length===o.length&&h.every((S,O)=>N(S)===N(o[O]));if(o=h,v)break}return o}if(r.op==="-"){let l=n(r.left,c),s=new Set(n(r.right,!c).map(N));return l.filter(p=>!s.has(N(p)))}let f=n(r.left,c),m=n(r.right,c);if(f.length===0&&r.op!=="+")return[];let g=()=>{let l=[];for(let s of f)for(let p of m)l.push($(s,p));return l},b=l=>l.reduce((s,p)=>$(s,p),[]);switch(r.op){case"+":return E([...f,...m]);case":":return E(g());case"*":return E([...f,...m,...g()]);case"/":{let l=b(f);return E([...f,...m.map(s=>$(s,l))])}case"%in%":{let l=b(m);return E(f.map(s=>$(s,l)))}}}}throw y("unsupported expression")};return{terms:t===void 0?[]:n(t,!1),intercept:a}}function z(t,u,i=t.rhs){let{response:a,responseColumns:n}=t,e=u.filter(s=>s!==a&&!(n?.includes(s)??!1)),r=a===void 0?[]:[a];n!==void 0&&n[1]!==a&&r.push(n[1]),k(t.rhs,e,r);let f=B(i,s=>r.indexOf(s),e),m=f.terms.map((s,p)=>[s,p]).sort((s,p)=>s[0].length-p[0].length||s[1]-p[1]).map(([s])=>s),g=[],b=a===void 0?-1:m.findIndex(s=>s.length===1&&s[0]===0);b>=0&&(g.push("the response appeared on the right-hand side and was dropped"),g.push(`problem with term ${b+1} in model.matrix: no columns are assigned`));let l=r.map(()=>m.map(()=>0));return m.forEach((s,p)=>{for(let o of s){let d=s.filter(h=>h!==o),x=d.length===0||m.slice(0,p).some(h=>d.every(v=>h.includes(v)));l[o][p]=x?1:2}}),{variables:r,response:a===void 0?-1:0,terms:m,termLabels:m.map(s=>s.map(p=>r[p]).join(":")),order:m.map(s=>s.length),intercept:f.intercept,factors:l,responseTerm:b,warnings:g}}export{I as a,V as b,Y as c,w as d,j as e,B as f,z as g};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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 g,b as l,c as d,d as x,s as E}from"./chunk-HF3QOIZX.js";import{a as B,b as q,c as R}from"./chunk-FFMMKXMK.js";import{k as Q,m as L,s as S}from"./chunk-NGDBJR3K.js";import{f as I,n as O,o as A,q as C,t as Y}from"./chunk-ULQXNAI6.js";import{b as _,l as y}from"./chunk-52KGBGFL.js";var P=8*Number.EPSILON,H=2*Number.EPSILON,T=1e-290;function k(n){let{p:r,lowerTail:t,logP:u,lo:i,hi:e}=n,f=!1,N=(c,a,b)=>{let D=n.cdf(c,a,b);return Number.isNaN(D)&&(f=!0),D},o;if(u||r<T){let c;u?c=t?r*(1+H):r*(1-H):c=Math.log(r)+Math.log1p(t?-P:P),o=t?a=>N(a,!0,!0)>=c:a=>N(a,!1,!0)<=c}else{let c;if(t?c=r*(1-P):c=1-r>4*P?r*(1+P):r,c>.5){let a=1-c;o=t?b=>N(b,!1,!1)<=a:b=>N(b,!0,!1)>=a}else o=t?a=>N(a,!0,!1)>=c:a=>N(a,!1,!1)<=c}let s=Math.round(n.y0);Number.isFinite(s)||(s=i),s=Math.min(Math.max(s,i),e);let h=Math.max(1,Math.abs(s)*Number.EPSILON);if(o(s)){let c=h,a=s-c;for(;a>=i&&o(a);)s=a,c*=2,a=s-c;if(f)return NaN;if(a<i){if(s===i)return i;a=i-1}let b=Z(a,s,o,()=>f);return f?NaN:b}if(f)return NaN;let m=h,M=s+m;for(;M<=e&&!o(M);){if(f)return NaN;if(s=M,m*=2,M=s+m,M===1/0&&e===1/0){let c=Number.MAX_VALUE,a=o(c);if(f)return NaN;if(!a)return e;M=c;break}}M>e&&(M=e);let F=Z(s,M,o,()=>f);return f?NaN:F}function Z(n,r,t,u){for(;r-n>1&&!u();){let i=Math.floor(n+(r-n)/2);if(i===n||i===r)break;t(i)?r=i:n=i}return r}function lt(n,r,t){if(r>t||n(r))return r;let u=r,i=1,e=r+1;for(;;){if(e>t){e=t+1;break}if(n(e))break;if(u=e,e===Number.MAX_VALUE)return t+1;i*=2,e=r+i,e===1/0&&(e=Number.MAX_VALUE)}for(;e-u>1;){let f=u+Math.floor((e-u)/2);if(f===u||f===e)break;n(f)?e=f:u=f}return e}function dt(n,r,t){if(r>t||!n(r))return r-1;if(n(t))return t;let u=r,i=t;for(;i-u>1;){let e=u+Math.floor((i-u)/2);if(e===i||e===u)break;n(e)?u=e:i=e}return u}var w=["log"],z=["lowerTail","logP"],tt=["lowerTail","logP"],v=B;function nt(n,r,t){return Number.isNaN(n)||Number.isNaN(r)?NaN:r<0?NaN:v(n)?d(t):n<0||!Number.isFinite(n)?d(t):L(Math.round(n),r,t)}function G(n,r,t,u){if(Number.isNaN(n)||Number.isNaN(r))return NaN;if(r<0)return NaN;if(n<0)return g(t,u);if(r===0)return l(t,u);if(!Number.isFinite(n))return l(t,u);let i=q(n);if(i+1-i===1)return S(i+1,r,!t,u);let e,f;if(u){let N=S(i,r,!t,!0);f=L(i,r,!0),e=t?O(N,f):A(N,f)}else{let N=S(i,r,!t,!1);f=L(i,r,!1),e=t?N+f:N-f}return Number.isNaN(f)?NaN:t||(u?Number.isFinite(e):e>0)?e:S(i+1,r,!t,u)}function rt(n,r,t,u){if(Number.isNaN(n)||Number.isNaN(r))return NaN;if(!Number.isFinite(r)||r<0)return NaN;let i=x(n,0,1/0,t,u);if(i!==void 0)return r===0&&!Number.isNaN(i)?0:i;if(r===0)return 0;let e=Math.sqrt(r),f=Y(n,{lowerTail:t,logP:u}),N=r+e*(f+(f*f-1)/(6*e));return k({p:n,lowerTail:t,logP:u,cdf:(o,s,h)=>G(o,r,s,h),y0:Number.isFinite(N)?N:r,lo:0,hi:1/0})}function xt(n,r,t={}){y(t,w,"dpois");let u=t.log??!1;return I(n,i=>nt(i,r,u))}function Lt(n,r,t={}){y(t,z,"ppois");let{lowerTail:u=!0,logP:i=!1}=t;return I(n,e=>G(e,r,u,i))}function qt(n,r,t={}){y(t,tt,"qpois");let{lowerTail:u=!0,logP:i=!1}=t;return I(n,e=>rt(e,r,u,i))}var et=["log"],it=["lowerTail","logP"],ut=["lowerTail","logP"];function V(n,r){return v(n)||n<0||!Number.isFinite(n)||r<0||r>1}function U(n,r,t,u){if(Number.isNaN(n)||Number.isNaN(r)||Number.isNaN(t))return NaN;if(r===1/0&&t>=0&&t<=1)return t===0&&n===0?u?0:1:d(u);if(V(r,t))return NaN;if(v(n)||n<0||!Number.isFinite(n))return d(u);let i=Math.round(n),e=Math.round(r);if(i>e)return d(u);let f=t<=.5?[t,0]:_(1,-(1-t)),N=t<=.5?_(1,-t):[1-t,0];return Q(i,e-i,f,N,u,e)}function X(n,r,t,u,i){if(n+1-n===1)return E(n+1,r-n,t,1-t,!u,i);let[e,f]=_(r,-n);if(f!==0)return NaN;let N,o;if(i){let s=E(n,e,t,1-t,!u,!0);o=Math.log(e/r)+U(n,r,t,!0),N=u?O(s,o):A(s,o)}else{let s=E(n,e,t,1-t,!u,!1);o=e/r*U(n,r,t,!1),N=u?s+o:s-o}return Number.isNaN(o)?NaN:u||(i?Number.isFinite(N):N>0)?N:E(n+1,e,t,1-t,!u,i)}function ft(n,r,t,u,i){if(Number.isNaN(n)||Number.isNaN(r)||Number.isNaN(t))return NaN;if(V(r,t))return NaN;let e=Math.round(r);if(n<0)return g(u,i);let f=q(n);return e<=f?l(u,i):t===0?l(u,i):t===1?g(u,i):X(f,e,t,u,i)}function Nt(n,r,t,u,i){if(Number.isNaN(n)||Number.isNaN(r)||Number.isNaN(t))return NaN;if(!Number.isFinite(r)||!Number.isFinite(t))return NaN;let e=R(r);if(t<0||t>1||e<0)return NaN;let f=x(n,0,e,u,i);if(f!==void 0)return f;if(t===0||e===0)return 0;if(t===1)return e;let N=1-t,o=e*t,s=Math.sqrt(e*t*N),h=(N-t)/s,m=Y(n,{lowerTail:u,logP:i}),M=o+s*(m+h*(m*m-1)/6);return k({p:n,lowerTail:u,logP:i,cdf:(F,c,a)=>F>=e?l(c,a):X(F,e,t,c,a),y0:Number.isFinite(M)?M:o,lo:0,hi:e})}function Vt(n,r,t,u={}){y(u,et,"dbinom");let i=u.log??!1;return I(n,e=>U(e,r,t,i))}function Xt(n,r,t,u={}){y(u,it,"pbinom");let{lowerTail:i=!0,logP:e=!1}=u;return I(n,f=>ft(f,r,t,i,e))}function jt(n,r,t,u={}){y(u,ut,"qbinom");let{lowerTail:i=!0,logP:e=!1}=u;return I(n,f=>Nt(f,r,t,i,e))}var ot=["location","scale","log"],st=["location","scale","lowerTail","logP"],at=["location","scale","lowerTail","logP"],p=1.1447298858494002,ct=2**-1022;function j(n){let r=n<9332636185032189e-317?600:0,t=Math.floor(Math.log2(n*2**r));return[n*2**r*2**-t,t-r]}function mt(n,r,t,u){if(t<=1)return u?-(p+Math.log(r))-Math.log1p(t*t):1/(Math.PI*(1+t*t))/r;let i=Math.abs(n),e=r/i;if(u)return-p+Math.log(r)-2*Math.log(i)-Math.log1p(e*e);if(i===1/0)return 0;let[f,N]=j(r),[o,s]=j(i),h=N-2*s,m=Math.trunc(h/2);return f/(o*o)/(Math.PI*(1+e*e))*2**m*2**(h-m)}function $(n,r){if(!(Number.isFinite(n-r)||!Number.isFinite(n)||!Number.isFinite(r)))return Math.abs(n/2-r/2)}function ht(n,r,t,u){if(Number.isNaN(n)||Number.isNaN(r)||Number.isNaN(t))return NaN;if(!(t>0))return NaN;let i=(n-r)/t;if(Number.isNaN(i))return NaN;let e=$(n,r);if(e!==void 0){let o=t/e/2;return u?-(p+Math.log(t))-2*(Math.log(e)+Math.LN2-Math.log(t))-Math.log1p(o*o):J(o,t)*(o/(1+o*o))}let f=Math.abs(i);if(t<ct)return mt(n-r,t,f,u);if(f<=1)return u?-(p+Math.log(t))-Math.log1p(i*i):Number.isFinite(Math.PI*t)?1/(Math.PI*t*(1+i*i)):1/Math.PI/t/(1+i*i);let N=1/f;return u?-(p+Math.log(t))-2*Math.log(f)-Math.log1p(N*N):J(N,t)*(N/(1+N*N))}function J(n,r){let t=Math.PI*r;return Number.isFinite(t)?n/t:n/Math.PI/r}function Mt(n,r,t,u,i){if(Number.isNaN(n)||Number.isNaN(r)||Number.isNaN(t))return NaN;if(!(t>0))return NaN;let e=n-r;if(Number.isNaN(e))return NaN;let f=$(n,r);if(f!==void 0){let h=t/f/2,m=Math.atan(h)/Math.PI;return u===e<0?i?h<1e-150?Math.log(t)-Math.log(f)-Math.LN2-p:Math.log(m):m:i?Math.log1p(-m):1-m}if(!(Math.abs(e)>t)){let h=e/t,m=.5+Math.atan(u?h:-h)/Math.PI;return i?Math.log(m):m}let N=t/Math.abs(e),o=Math.atan(N)/Math.PI;return u===e<0?i?N<1e-150?Math.log(t)-Math.log(Math.abs(e))-p:Math.log(o):o:i?Math.log1p(-o):1-o}var It=1e-200,yt=-460;function W(n,r,t){if(!t){let i=n/r;return Number.isFinite(i)?i/Math.PI:n/Math.PI/r}let u=Math.exp(-r/4);return u*n/Math.PI*u*u*u}function K(n){return n<=.25?-1/Math.tan(Math.PI*n):-Math.tan(Math.PI*(.5-n))}function bt(n,r,t,u,i){if(Number.isNaN(n)||Number.isNaN(r)||Number.isNaN(t))return NaN;if(i?n>0:n<0||n>1)return NaN;if(!(t>0))return t===0?r:NaN;let e;if(i)if(n===0)e=1/0;else if(n===-1/0)e=-1/0;else{if(n<yt)return r+(u?-1:1)*W(t,n,!0);e=n<-Math.LN2?K(Math.exp(n)):-K(-Math.expm1(n))}else if(n===0)e=-1/0;else if(n===1)e=1/0;else{if(n<It)return r+(u?-1:1)*W(t,n,!1);e=n<=.5?K(n):-K(1-n)}return C(r,t,u?e:-e)}function wt(n,r={}){y(r,ot,"dcauchy");let{location:t=0,scale:u=1,log:i=!1}=r;return I(n,e=>ht(e,t,u,i))}function zt(n,r={}){y(r,st,"pcauchy");let{location:t=0,scale:u=1,lowerTail:i=!0,logP:e=!1}=r;return I(n,f=>Mt(f,t,u,i,e))}function tn(n,r={}){y(r,at,"qcauchy");let{location:t=0,scale:u=1,lowerTail:i=!0,logP:e=!1}=r;return I(n,f=>bt(f,t,u,i,e))}export{P as a,H as b,k as c,lt as d,dt as e,v as f,nt as g,G as h,rt as i,xt as j,Lt as k,qt as l,U as m,ft as n,Nt as o,Vt as p,Xt as q,jt as r,ht as s,Mt as t,bt as u,wt as v,zt as w,tn as x};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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{h as k}from"./chunk-NAACMR7H.js";import{l as g}from"./chunk-52KGBGFL.js";function x(r,n){return{nrow:r,ncol:n,data:new Float64Array(r*n)}}function R(r){return r.length>0&&typeof r[0]!="number"}function F(r){let n=r.length,t=n===0?0:r[0].length,o=x(n,t);for(let e=0;e<n;e++){let i=r[e];if(i.length!==t)throw new TypeError("all rows of the matrix must have the same length");for(let s=0;s<t;s++)o.data[e+s*n]=i[s]}return o}function S(r){if(R(r))return F(r);let n=r;return{nrow:n.length,ncol:1,data:Float64Array.from(n)}}function y(r){let n=[];for(let t=0;t<r.nrow;t++){let o=new Array(r.ncol);for(let e=0;e<r.ncol;e++)o[e]=r.data[t+e*r.nrow];n.push(o)}return n}function B(r){let n=x(r.ncol,r.nrow);for(let t=0;t<r.ncol;t++)for(let o=0;o<r.nrow;o++)n.data[t+o*r.ncol]=r.data[o+t*r.nrow];return n}function G(r,n="the matrix"){if(r.nrow!==r.ncol)throw new TypeError(`${n} must be square (got ${r.nrow} x ${r.ncol})`)}function N(r){let n=0;for(let t=0;t<r.length;t++)n=Math.max(n,Math.abs(r[t]));return n===0||n>=2**-256&&n<=2**256?0:Math.floor(Math.log2(n))}function $(r,n=256){let t=N(r);return t>0?Math.max(0,t-n):t}var Y=["tol","lapack"],O=["complete","dvec"],W=["complete"],X=["complete","ncol"],C=["k"],z=["tol"];function D(r,n={}){g(n,Y,"qr");let t=F(r);if(n.lapack){let u=t.data.slice(),{tau:a,pivot:l}=T(t);if(u.every(Number.isFinite)&&!(t.data.every(Number.isFinite)&&a.every(Number.isFinite))){let f=$(u);if(f!==0){let d=t.nrow;for(let m=0;m<u.length;m++)t.data[m]=k(u[m],-f);({tau:a,pivot:l}=T(t));for(let m=0;m<t.ncol;m++)for(let w=0;w<=Math.min(m,d-1);w++)t.data[w+m*d]=k(t.data[w+m*d],f)}}let c=Array.from(a);return{qr:y(t),rank:Math.min(t.nrow,t.ncol),qraux:c,pivot:l.map(f=>f-1),useLapack:!0}}for(let u of t.data)if(!Number.isFinite(u))throw new RangeError("the matrix contains NaN or infinite values");let o=n.tol??1e-7;if(!(o>=0&&o<1/0))throw new RangeError("'tol' must be a non-negative finite number");let e=t.data.slice(),{qraux:i,pivot:s,rank:p,transformed:h}=L(t,o);if(!(t.data.every(Number.isFinite)&&i.every(Number.isFinite))){let u=t.nrow,a=Array.from({length:t.ncol},(l,c)=>N(e.subarray(c*u,(c+1)*u)));if(a.some(l=>l!==0)){for(let l=0;l<t.ncol;l++)for(let c=0;c<u;c++)t.data[c+l*u]=k(e[c+l*u],-a[l]);({qraux:i,pivot:s,rank:p,transformed:h}=L(t,o));for(let l=0;l<t.ncol;l++){let c=a[s[l]-1];if(c!==0){for(let f=0;f<=Math.min(l,u-1);f++)t.data[f+l*u]=k(t.data[f+l*u],c);h[l]||(i[l]=k(i[l],c))}}}}return{qr:y(t),rank:p,qraux:Array.from(i),pivot:s.map(u=>u-1),useLapack:!1}}function v(r,n,t){let o=0;for(let i=0;i<t;i++)o=Math.max(o,Math.abs(r[n+i]));if(o===0||!Number.isFinite(o))return o;let e=0;for(let i=0;i<t;i++){let s=r[n+i]/o;e+=s*s}return o*Math.sqrt(e)}function L(r,n){let t=r.nrow,o=r.ncol,e=r.data,i=new Float64Array(o),s=new Float64Array(o),p=new Uint8Array(o),h=Array.from({length:o},(c,f)=>f+1);for(let c=0;c<o;c++)i[c]=v(e,c*t,t),s[c]=i[c]===0?1:i[c];let u=new Float64Array(t),a=Math.min(t,o),l=o;for(let c=0;c<a;c++){for(;c<l&&i[c]<s[c]*n;){u.set(e.subarray(c*t,(c+1)*t));let[m,w,E]=[i[c],s[c],h[c]];e.copyWithin(c*t,(c+1)*t,o*t),e.set(u,(o-1)*t),i.copyWithin(c,c+1),s.copyWithin(c,c+1),h.copyWithin(c,c+1),i[o-1]=m,s[o-1]=w,h[o-1]=E,l--}if(c===t-1)break;let f=c*t,d=v(e,f+c,t-c);if(d!==0){e[f+c]!==0&&(d=Math.sign(e[f+c])*Math.abs(d));for(let m=c;m<t;m++)e[f+m]/=d;e[f+c]=1+e[f+c];for(let m=c+1;m<o;m++){let w=m*t,E=0;for(let M=c;M<t;M++)E-=e[f+M]*e[w+M];E/=e[f+c];for(let M=c;M<t;M++)e[w+M]+=E*e[f+M];if(i[m]===0)continue;let Q=Math.max(1-(Math.abs(e[w+c])/i[m])**2,0);Q<1e-6?i[m]=v(e,w+c+1,t-c-1):i[m]*=Math.sqrt(Q)}i[c]=e[f+c],p[c]=1,e[f+c]=-d}}return{qraux:i,pivot:h,rank:Math.min(l,t),transformed:p}}function T(r){let n=r.nrow,t=r.ncol,o=r.data,e=Math.min(n,t),i=new Float64Array(e),s=Array.from({length:t},(a,l)=>l+1),p=new Float64Array(t),h=new Float64Array(t);for(let a=0;a<t;a++)p[a]=v(o,a*n,n),h[a]=p[a];let u=Math.sqrt(2**-53);for(let a=0;a<e;a++){let l=a;for(let f=a+1;f<t;f++)Math.abs(p[f])>Math.abs(p[l])&&(l=f);if(l!==a){for(let f=0;f<n;f++){let d=o[f+l*n];o[f+l*n]=o[f+a*n],o[f+a*n]=d}[s[l],s[a]]=[s[a],s[l]],p[l]=p[a],h[l]=h[a]}let c=a*n;i[a]=U(o,c+a,n-a),a<t-1&&I(o,c+a,n-a,i[a],r,a,a+1,t-a-1);for(let f=a+1;f<t;f++){if(p[f]===0)continue;let d=1-(Math.abs(o[a+f*n])/p[f])**2;d=Math.max(d,0),d*(p[f]/h[f])**2<=u?a<n-1?(p[f]=v(o,f*n+a+1,n-a-1),h[f]=p[f]):(p[f]=0,h[f]=0):p[f]*=Math.sqrt(d)}}return{tau:i,pivot:s}}function U(r,n,t){if(t<=1)return 0;let o=v(r,n+1,t-1);if(o===0)return 0;let e=r[n],i=-Math.sign(e||1)*Math.hypot(e,o),s=2**-1022/2**-53,p=0;if(Math.abs(i)<s){let a=1/s;do{p++;for(let l=1;l<t;l++)r[n+l]*=a;i*=a,e*=a}while(Math.abs(i)<s&&p<20);o=v(r,n+1,t-1),i=-Math.sign(e||1)*Math.hypot(e,o)}let h=(i-e)/i,u=1/(e-i);for(let a=1;a<t;a++)r[n+a]*=u;for(let a=0;a<p;a++)i*=s;return r[n]=i,h}function tt(r,n,t,o,e,i,s,p){if(o===0)return;let h=e.nrow,u=e.data;for(let a=s;a<s+p;a++){let l=i+a*h,c=0;for(let f=0;f<t;f++)c+=u[l+f]*r[n+f];c*=o;for(let f=0;f<t;f++)u[l+f]-=r[n+f]*c}}function I(r,n,t,o,e,i,s,p){if(o===0)return;let h=t;for(;h>1&&r[n+h-1]===0;)h--;let u=e.nrow,a=e.data;for(let l=s;l<s+p;l++){let c=i+l*u;if(h===1){a[c]*=1-o;continue}let f=0;for(let m=1;m<h;m++)f+=a[c+m]*r[n+m];f+=a[c];let d=-o*f;a[c]+=d;for(let m=1;m<h;m++)a[c+m]+=r[n+m]*d}}function j(r){return{a:F(r.qr),qraux:r.qraux,rank:r.rank,pivot:r.pivot.map(n=>n+1),lapack:r.useLapack}}function _(r,n){let t=S(n);if(t.nrow!==r.a.nrow)throw new TypeError(`qr and y must have the same number of rows (${r.a.nrow} and ${t.nrow})`);return t}function b(r,n){return R(r)?y(n):Array.from(n.data)}function q(r,n,t,o=r.rank){let{a:e,qraux:i}=r,s=e.nrow;if(r.lapack){let u=Math.min(s,e.ncol),a=t?A(0,u):A(0,u).reverse();for(let l of a)I(e.data,l+l*s,s-l,i[l],n,l,0,n.ncol);return}let p=Math.min(o,s-1),h=t?A(0,p):A(0,p).reverse();for(let u of h){if(i[u]===0)continue;let a=u*s,l=e.data[a+u];e.data[a+u]=i[u];for(let c=0;c<n.ncol;c++){let f=c*s,d=0;for(let m=u;m<s;m++)d-=e.data[a+m]*n.data[f+m];d/=e.data[a+u];for(let m=u;m<s;m++)n.data[f+m]+=d*e.data[a+m]}e.data[a+u]=l}}function A(r,n){return Array.from({length:Math.max(0,n-r)},(t,o)=>r+o)}function nt(r,n){let t=j(r),o=_(t,n);return q(t,o,!0),b(n,o)}function ot(r,n){let t=j(r),o=_(t,n);return q(t,o,!1),b(n,o)}function V(r,n){let t=j(r),o=_(t,n),e=t.a.ncol,i=t.a.nrow,s=t.lapack?Math.min(i,e):t.rank;q(t,o,!0);for(let h=0;h<o.ncol;h++){let u=h*i;for(let a=s-1;a>=0;a--){let l=t.a.data[a+a*i];if(l===0)throw new Error("exact singularity in qrCoef");o.data[u+a]/=l;let c=-o.data[u+a];for(let f=0;f<a;f++)o.data[u+f]+=c*t.a.data[f+a*i]}}let p=x(e,o.ncol);p.data.fill(NaN);for(let h=0;h<o.ncol;h++)for(let u=0;u<s;u++)p.data[t.pivot[u]-1+h*e]=o.data[u+h*i];return b(n,p)}function K(r,n,t,o){let e=j(r);if(e.lapack)throw new TypeError("not supported for a QR decomposition computed with lapack: true");let i=o??e.rank;if(!Number.isInteger(i)||i<0||i>e.rank)throw new RangeError(`invalid k (got ${i})`);let s=_(e,n),p=e.a.nrow;if(i===0)return b(n,s);if(p===1)return t||s.data.fill(0),b(n,s);q(e,s,!0,i);for(let h=0;h<s.ncol;h++)t?s.data.fill(0,h*p+i,(h+1)*p):s.data.fill(0,h*p,h*p+i);return q(e,s,!1,i),b(n,s)}function rt(r,n){return K(r,n,!1)}function et(r,n,t={}){return g(t,C,"qrFitted"),K(r,n,!0,t.k)}function at(r,n={}){g(n,O,"qrQ");let t=j(r),o=t.a.nrow,e=n.complete?o:Math.min(o,t.a.ncol),i=n.dvec??new Array(e).fill(1);if(i.length!==e)throw new RangeError(`dvec must have length ${e}`);let s=x(o,e);for(let p=0;p<e;p++)s.data[p+p*o]=i[p];return q(t,s,!1),y(s)}function ct(r,n={}){g(n,W,"qrR");let t=F(r.qr),o=n.complete?t.nrow:Math.min(t.nrow,t.ncol),e=x(o,t.ncol);for(let i=0;i<t.ncol;i++)for(let s=0;s<=Math.min(i,o-1);s++)e.data[s+i*o]=t.data[s+i*t.nrow];return y(e)}function it(r,n={}){g(n,X,"qrX");let t=j(r),o=t.a.nrow,e=t.a.ncol,i=n.complete??!1,s=n.ncol??(i?o:Math.min(o,e));if(!Number.isInteger(s)||s<0)throw new RangeError(`invalid ncol (got ${s})`);if(s>Math.max(o,e))throw new RangeError(`ncol must be at most max(nrow, ncol of x) = ${Math.max(o,e)} (got ${s})`);if(t.pivot.some((l,c)=>l!==c+1)&&s<e)throw new RangeError("ncol must be at least the number of columns because the decomposition is pivoted");let h=x(o,s);for(let l=0;l<s;l++)if(l<e)for(let c=0;c<=Math.min(l,o-1);c++)h.data[c+l*o]=t.a.data[c+l*o];else l<o&&(h.data[l+l*o]=1);q(t,h,!1);let u=Math.min(s,e),a=x(o,s);a.data.set(h.data);for(let l=0;l<u;l++){let c=t.pivot[l]-1;c<u&&a.data.set(h.data.subarray(l*o,(l+1)*o),c*o)}return y(a)}function lt(r,n,t={}){g(t,z,"qrSolve");let o=Array.isArray(r)?D(r,{tol:t.tol??1e-7}):r,e=o.qr.length,i=e===0?0:o.qr[0].length;if(o.rank!==Math.min(e,i))throw new Error("singular matrix in qrSolve");if(o.useLapack){let a=t.tol??1e-7,l=Math.abs(o.qr[0]?.[0]??0);for(let c=0;c<Math.min(e,i);c++)if(!(Math.abs(o.qr[c][c])>a*l))throw new Error("singular matrix in qrSolve")}if(n===void 0&&e!==i)throw new TypeError("only square matrices can be inverted");let s=n??Array.from({length:e},(a,l)=>Array.from({length:e},(c,f)=>l===f?1:0)),p=V(o,s),h=new Set(o.pivot.slice(Math.min(e,i)));if(R(s)){let a=p;for(let l of h)a[l].fill(0);return a}let u=p;for(let a of h)u[a]=0;return u}export{x as a,R as b,F as c,S as d,y as e,B as f,G as g,N as h,$ as i,D as j,U as k,tt as l,nt as m,ot as n,V as o,rt as p,et as q,at as r,ct as s,it as t,lt as u};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{g as h,h as E,i as m}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.12.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 h,h as E,i as m}from"./chunk-DWVTVOQS.js";import{a as b}from"./chunk-O6OMXX5U.js";import{l as g}from"./chunk-52KGBGFL.js";var d=["size","replace","prob"],I=["size","replace","prob"];function j(e,t={}){return g(t,I,"sampleInt"),R(e,t).map(r=>r-1)}function R(e,t){if(!Number.isFinite(e)||e<0||e>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");e=Math.trunc(e);let{replace:r=!1,prob:s}=t,a=t.size!==void 0,o=a?t.size:e;if(!Number.isFinite(o)||o<=-1)throw new RangeError("size must be a non-negative number");let i=Math.trunc(o);if(e===0&&i>0)throw new RangeError("cannot take a sample from an empty population");if(s!==void 0){if(i>=2**31)throw new RangeError("size must be less than 2^31 with prob");if(e>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(s.length!==e)throw new TypeError("prob must have length n");let f=v(s,i,r);if(r){let u=y(f),w=new Array(i);for(let p=0;p<i;p++)w[p]=u();return w}if(i>e)throw new RangeError("cannot take a sample larger than the population when replace is false");return k(f,i)}if(!r&&i>e)throw new RangeError("cannot take a sample larger than the population when replace is false");if(!r&&e>1e7&&a&&i<=e/2){let f=new Set,u=[];for(;u.length<i;){let w=m(e);f.has(w)||(f.add(w),u.push(w+1))}return u}let c=new Array(i);if(r||i<2){for(let f=0;f<i;f++)c[f]=m(e)+1;return c}if(e>=2**31)throw new RangeError("n must be less than 2^31 to sample without replacement with size above n / 2");let n=new Int32Array(e);for(let f=0;f<e;f++)n[f]=f;let l=e;for(let f=0;f<i;f++){let u=m(l);c[f]=n[u]+1,n[u]=n[--l]}return c}function D(e,t){if(!Number.isFinite(e)||e<0||e>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");if(e=Math.trunc(e),e>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(t.length!==e)throw new TypeError("prob must have length n");let r=y(v(t,0,!0));return()=>r()-1}function y(e){let t=e.length,r=0;for(let s=0;s<t;s++)t*e[s]>.1&&r++;return r>200?N(e):F(e)}function L(e,t={}){return g(t,d,"sample"),R(e.length,t).map(r=>e[r-1])}function v(e,t,r){let s=0,a=0;for(let o of e){if(!Number.isFinite(o))throw new RangeError("prob contains NaN or infinite values");if(o<0)throw new RangeError("prob contains negative values");o>0&&(a++,s+=o)}if(a===0||!r&&t>a)throw new RangeError("too few positive probabilities");if(s===1/0){let o=b(e);s=0;for(let i of e)s+=i/o;return Float64Array.from(e,i=>i/o/s)}return Float64Array.from(e,o=>o/s)}function z(e,t){let r=e.length;if(r<=1)return;let s=n=>e[n-1],a=(r>>1)+1,o=r,i,c;for(;;){if(a>1)a=a-1,i=s(a),c=t[a-1];else if(i=s(o),c=t[o-1],e[o-1]=s(1),t[o-1]=t[0],--o===1){e[0]=i,t[0]=c;return}let n=a,l=a<<1;for(;l<=o;)l<o&&s(l)>s(l+1)&&++l,i>s(l)?(e[n-1]=s(l),t[n-1]=t[l-1],n=l,l+=l):l=o+1;e[n-1]=i,t[n-1]=c}}function A(e){let t=new Int32Array(e.length);for(let r=0;r<e.length;r++)t[r]=r+1;return z(e,t),t}function F(e){let t=Float64Array.from(e),r=t.length,s=A(t);for(let a=1;a<r;a++)t[a]+=t[a-1];return()=>{let a=h(),o=0;for(;o<r-1&&!(a<=t[o]);o++);return s[o]}}function k(e,t){let r=Float64Array.from(e),s=r.length,a=A(r),o=new Array(t),i=1;for(let c=0,n=s-1;c<t;c++,n--){let l=i*h(),f=0,u=0;for(;u<n&&(f+=r[u],!(l<=f));u++);o[c]=a[u],i-=r[u];for(let w=u;w<n;w++)r[w]=r[w+1],a[w]=a[w+1]}return o}function N(e){let t=e.length,r=new Float64Array(t),s=new Int32Array(t),a=new Int32Array(t),o=-1,i=t;for(let n=0;n<t;n++)r[n]=e[n]*t,r[n]<1?a[++o]=n:a[--i]=n;if(o>=0&&i<t)for(let n=0;n<t-1;n++){let l=a[n],f=a[i];if(s[l]=f,r[f]+=r[l]-1,r[f]<1&&i++,i>=t)break}let c=E();return()=>{let n,l;return c?(l=h()*t,n=Math.trunc(l)):(n=m(t),l=n+h()),l<r[n]+n?n+1:s[n]+1}}export{j as a,D as b,L as c};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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 Y}from"./chunk-XQSYV3IZ.js";import{a as F,b as A,c as M,d as S,e as E,f as C,g as k,i as x,j as q,s as K}from"./chunk-4B7NEJCE.js";import{h as w}from"./chunk-NAACMR7H.js";import{l as p}from"./chunk-52KGBGFL.js";var V=["type"];function tt(i,r={}){p(r,V,"norm");let a=M(i),e=r.type??"O";if(e.length!==1)throw new RangeError(`type must be a single character (got "${e}")`);switch(e.toUpperCase()){case"O":case"1":return g(a);case"I":return j(a);case"F":case"E":return L(a);case"M":return _(a);case"2":return z(a);default:throw new RangeError(`type must be one of "O", "I", "F", "M" and "2" (got "${e}")`)}}function O(i,r){return Number.isNaN(i)||Number.isNaN(r)?NaN:Math.max(i,r)}function g(i){let r=0;for(let a=0;a<i.ncol;a++){let e=0;for(let n=0;n<i.nrow;n++)e+=Math.abs(i.data[n+a*i.nrow]);r=O(r,e)}return r}function j(i){let r=new Float64Array(i.nrow);for(let e=0;e<i.ncol;e++)for(let n=0;n<i.nrow;n++)r[n]+=Math.abs(i.data[n+e*i.nrow]);let a=0;for(let e of r)a=O(a,e);return a}function _(i){let r=0;for(let a of i.data)r=O(r,Math.abs(a));return r}function L(i){let r=_(i);if(r===0||!Number.isFinite(r))return r;let a=0;for(let e of i.data){let n=e/r;a+=n*n}return r*Math.sqrt(a)}function z(i){if(i.nrow===0||i.ncol===0)return 0;if(i.data.some(Number.isNaN))return NaN;if(i.data.some(r=>!Number.isFinite(r)))throw new RangeError("the matrix contains infinite values");return Y(i)[0]}var B=["tol"],G=["logarithm"],H=["norm","triangular","uplo"];function y(i){let r=i.nrow,a=i.ncol,e=i.data,n=Math.min(r,a),s=new Int32Array(n),c=2**-1022,t=0;for(let o=0;o<n;o++){let f=o*r,u=o,d=Math.abs(e[f+o]);for(let m=o+1;m<r;m++){let l=Math.abs(e[f+m]);l>d&&(d=l,u=m)}if(s[o]=u,e[f+u]!==0){if(u!==o)for(let l=0;l<a;l++){let N=e[o+l*r];e[o+l*r]=e[u+l*r],e[u+l*r]=N}let m=e[f+o];if(Math.abs(m)>=c){let l=1/m;for(let N=o+1;N<r;N++)e[f+N]*=l}else for(let l=o+1;l<r;l++)e[f+l]/=m}else t===0&&(t=o+1);for(let m=o+1;m<a;m++){let l=e[o+m*r];if(l===0)continue;let N=-l;for(let b=o+1;b<r;b++)e[b+m*r]+=e[f+b]*N}}return{ipiv:s,info:t}}function R(i,r,a){let e=i.nrow,n=i.data,s=a.data;for(let c=0;c<a.ncol;c++){let t=c*e;for(let o=0;o<e;o++){let f=r[o];if(f!==o){let u=s[t+o];s[t+o]=s[t+f],s[t+f]=u}}for(let o=0;o<e;o++){let f=s[t+o];if(f!==0)for(let u=o+1;u<e;u++)n[u+o*e]!==0&&(s[t+u]-=f*n[u+o*e])}for(let o=e-1;o>=0;o--)if(s[t+o]!==0){s[t+o]/=n[o+o*e];let f=s[t+o];for(let u=0;u<o;u++)n[u+o*e]!==0&&(s[t+u]-=f*n[u+o*e])}}}function v(i,r,a,e,n){let s=i.nrow,c=i.data;if(a)if(r)for(let t=0;t<s;t++){let o=n[t];for(let f=0;f<t;f++)c[f+t*s]!==0&&(o-=c[f+t*s]*n[f]);e||(o/=c[t+t*s]),n[t]=o}else for(let t=s-1;t>=0;t--){let o=n[t];for(let f=s-1;f>t;f--)c[f+t*s]!==0&&(o-=c[f+t*s]*n[f]);e||(o/=c[t+t*s]),n[t]=o}else if(r){for(let t=s-1;t>=0;t--)if(n[t]!==0){e||(n[t]/=c[t+t*s]);let o=n[t];for(let f=t-1;f>=0;f--)c[f+t*s]!==0&&(n[f]-=o*c[f+t*s])}}else for(let t=0;t<s;t++)if(n[t]!==0){e||(n[t]/=c[t+t*s]);let o=n[t];for(let f=t+1;f<s;f++)c[f+t*s]!==0&&(n[f]-=o*c[f+t*s])}}function J(i,r){let a=new Float64Array(i),e=new Int32Array(i),n=()=>a.reduce((l,N)=>l+Math.abs(N),0),s=()=>{let l=0;for(let N=1;N<i;N++)Math.abs(a[N])>Math.abs(a[l])&&(l=N);return l},c=()=>{for(let l=0;l<i;l++)a[l]=a[l]>=0?1:-1,e[l]=a[l]};if(a.fill(1/i),r(1,a),i===1)return Math.abs(a[0]);let t=n();c(),r(2,a);let o=s(),f=2,u=5;for(;;){a.fill(0),a[o]=1,r(1,a);let l=t;t=n();let N=!1;for(let h=0;h<i;h++)if((a[h]>=0?1:-1)!==e[h]){N=!0;break}if(!N||t<=l)break;c(),r(2,a);let b=o;if(o=s(),a[b]!==Math.abs(a[o])&&f<u){f++;continue}break}let d=1;for(let l=0;l<i;l++)a[l]=d*(1+l/(i-1)),d=-d;r(1,a);let m=2*(n()/(3*i));return m>t?m:t}function D(i){let r=x(i.data);return r===0?void 0:{...i,data:i.data.map(a=>w(a,-r))}}function $(i,r,a){let e=i.nrow;if(e===0)return 1;if(!Number.isFinite(r))throw new RangeError("the matrix contains NaN or infinite values (LAPACK dgecon returned error -5)");if(r===0)return 0;let n=a?1:2;return U(e,s=>1/s/r,r,(s,c)=>{s===n?(v(i,!1,!1,!0,c),v(i,!0,!1,!1,c)):(v(i,!0,!0,!1,c),v(i,!1,!0,!0,c))})}function U(i,r,a,e){let n=o=>{let f=!0,u=J(i,(d,m)=>{if(o!==0)for(let l=0;l<i;l++)m[l]=w(m[l],-o);e(d,m),f&&!m.every(Number.isFinite)&&(f=!1)});return f?u:NaN},s=n(0);if(Number.isFinite(s))return s===0?0:r(s);let c=563-Math.floor(Math.log2(a)),t=n(c);return Number.isFinite(t)&&t!==0?w(r(t),-c):0}function Q(i,r,a){let e=i.nrow,n=new Float64Array(e);for(let c=0;c<e;c++){let[t,o]=r?[0,c]:[c,e-1];for(let f=t;f<=o;f++)n[a?c:f]+=Math.abs(i.data[f+c*e])}let s=0;for(let c of n)s=Number.isNaN(s)||Number.isNaN(c)?NaN:Math.max(s,c);return s}function P(i,r,a){let e=i.nrow;if(e===0)return 1;let n=Q(i,r,a);if(!(n>0))return 0;let s=a?1:2;return U(e,c=>1/n/c,n,(c,t)=>v(i,r,c!==s,!1,t))}function at(i,r,a={}){p(a,B,"solve");let e=M(i);k(e);let n=e.nrow,s;if(r===void 0){s=F(n,n);for(let h=0;h<n;h++)s.data[h+h*n]=1}else if(s=S(r),s.nrow!==n)throw new TypeError(`b (${s.nrow} x ${s.ncol}) is not compatible with a (${n} x ${n})`);let c=e.data.every(Number.isFinite),t=c?D(e):void 0,o=t===void 0?0:x(e.data),f=g(e),u=t===void 0?NaN:g(t),d=t===void 0?void 0:y(t),{ipiv:m,info:l}=y(e);if(l>0)throw new Error(`the system is exactly singular: U[${l}, ${l}] = 0`);let N=a.tol??Number.EPSILON;if(Number.isNaN(N))throw new RangeError("'tol' must not be NaN");if(N>0&&c){let h=t===void 0?$(e,f,!0):d.info>0?0:$(t,u,!0);if(h<N)throw new Error(`the system is computationally singular: reciprocal condition number = ${h.toPrecision(6)}`)}let b=t!==void 0&&d.info===0;if(b&&!e.data.every(Number.isFinite))I(t,d.ipiv,o,s);else{let h=c&&s.data.every(Number.isFinite)?s.data.slice():void 0;R(e,m,s),h!==void 0&&!s.data.every(Number.isFinite)&&e.data.every(Number.isFinite)&&(s.data.set(h),b?I(t,d.ipiv,o,s):I(e,m,0,s))}return r!==void 0&&!A(r)?Array.from(s.data):E(s)}function I(i,r,a,e){let n=i.nrow,s=F(n,1);for(let c=0;c<e.ncol;c++){let t=c*n,o=e.data.subarray(t,t+n);s.data.set(o),R(i,r,s);let f=0;if(!s.data.every(Number.isFinite)&&o.every(Number.isFinite)){let u=0;for(let d of o)u=Math.max(u,Math.abs(d));if(u>0){f=Math.floor(Math.log2(u));for(let d=0;d<n;d++)s.data[d]=w(o[d],-f);R(i,r,s)}}for(let u=0;u<n;u++)o[u]=w(s.data[u],f-a)}}function W(i,r={}){p(r,G,"determinant");let a=r.logarithm??!0,e=M(i);k(e);let n=e.nrow,{ipiv:s,info:c}=y(e);if(c>0)return{modulus:a?-1/0:0,logarithm:a,sign:1};let t=1,o=a?0:1,f=0;for(let u=0;u<n;u++){s[u]!==u&&(t=-t);let d=e.data[u+u*n];if(d<0&&(t=-t),a)o+=Math.log(Math.abs(d));else{let m=Math.abs(d);if(m!==0&&Number.isFinite(m)&&(m>2**500||m<2**-500)){let l=Math.floor(Math.log2(m));m=w(m,-l),f+=l}if(o*=m,o!==0&&Number.isFinite(o)&&(o>2**500||o<2**-500)){let l=Math.floor(Math.log2(o));o=w(o,-l),f+=l}}}return!a&&f!==0&&(o=w(o,f)),{modulus:o,logarithm:a,sign:t}}function ft(i){let{modulus:r,sign:a}=W(i);return a*Math.exp(r)}function ct(i,r={}){p(r,H,"rcond");let a=r.norm??"O";if(!["O","1","I"].includes(a))throw new RangeError(`norm must be "O", "I" or "1" (got "${a}")`);let e=a!=="I",n=M(i);if(n.data.every(Number.isFinite)&&(n=D(n)??n),n.nrow!==n.ncol){let t=n.nrow<n.ncol?C(n):n;return P(M(K(q(E(t)))),!0,e)}if(r.triangular){let t=r.uplo??"U";if(t!=="U"&&t!=="L")throw new RangeError(`'uplo' must be "U" or "L"`);return P(n,t==="U",e)}let s=e?g(n):j(n);n={...n,data:n.data.slice()};let{info:c}=y(n);return c>0?0:$(n,s,e)}export{tt as a,g as b,j as c,at as d,W as e,ft as f,ct as g};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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 Q=!0;function gs(){return Q}function qs(n,t){if(!Q)return[n+t,0];let s=n+t;if(!Number.isFinite(s))return[s,0];let o=s-n,c=n-(s-o)+(t-o);return[s,c]}function A(n,t){let s=Math.trunc(t/2);return n*2**s*2**(t-s)}function Cn(n,t){if(!(Math.abs(n)<2**-900)||!(Math.abs(t)<1)||t===0)return 0;let s=-Math.floor(Math.log2(Math.abs(t)));return Number.isFinite(A(n,s))?s:0}function F(n,t){let s=n===0?0:Math.floor(Math.log2(Math.abs(n))),o=t===0?0:Math.floor(Math.log2(Math.abs(t))),c=A(n,-s),r=A(t,-o),i=c*r,e=134217729*c,b=e-(e-c),l=c-b;e=134217729*r;let f=e-(e-r),h=r-f;return A(b*f-i+b*h+l*f+l*h,s+o)}function ys(n,t){if(!Q)return[n*t,0];let s=n*t;if(!Number.isFinite(s))return[s,0];let o=134217729*n,c=o-(o-n),r=n-c;o=134217729*t;let i=o-(o-t),e=t-i,b=c*i-s+c*e+r*i+r*e;return!Number.isFinite(b)&&Number.isFinite(s)&&(b=F(n,t)),[s,b]}function ks(n,t){if(!Q)return[n[0]+t[0],0];let s=n[0]+t[0];if(!Number.isFinite(s))return[s,0];let o=s-n[0],c=n[0]-(s-o)+(t[0]-o),r=n[1]+t[1],i=r-n[1],e=n[1]-(r-i)+(t[1]-i),b=c+r,l=s+b,h=b-(l-s)+e,R=l+h,L=h-(R-l);return[R,L]}function Ds(n){return[-n[0],-n[1]]}function As(n,t){if(!Q)return[n[0]-t[0],0];let s=-t[0],o=-t[1],c=n[0]+s;if(!Number.isFinite(c))return[c,0];let r=c-n[0],i=n[0]-(c-r)+(s-r),e=n[1]+o,b=e-n[1],l=n[1]-(e-b)+(o-b),f=i+e,h=c+f,L=f-(h-c)+l,C=h+L,_=L-(C-h);return[C,_]}function $s(n,t){if(!Q)return[n[0]*t[0],0];let s=n[0]*t[0];if(!Number.isFinite(s))return[s,0];let o=134217729*n[0],c=o-(o-n[0]),r=n[0]-c,i=134217729*t[0],e=i-(i-t[0]),b=t[0]-e,l=c*e-s+c*b+r*e+r*b;!Number.isFinite(l)&&Number.isFinite(s)&&(l=F(n[0],t[0]));let f=l+(n[0]*t[1]+n[1]*t[0]),h=s+f,R=f-(h-s);return[h,R]}function vs(n,t){if(!Q)return[n[0]*t,0];let s=n[0]*t;if(!Number.isFinite(s))return[s,0];let o=134217729*n[0],c=o-(o-n[0]),r=n[0]-c,i=134217729*t,e=i-(i-t),b=t-e,l=c*e-s+c*b+r*e+r*b;!Number.isFinite(l)&&Number.isFinite(s)&&(l=F(n[0],t));let f=l+n[1]*t,h=s+f,R=f-(h-s);return[h,R]}function Ns(n,t){if(!Q)return[n[0]/t[0],0];let s=Cn(n[0],t[0]);if(s!==0)return Ns([A(n[0],s),A(n[1],s)],[A(t[0],s),A(t[1],s)]);let o=n[0]/t[0];if(!Number.isFinite(o))return[o,0];let c=t[0]*o,r=134217729*t[0],i=r-(r-t[0]),e=t[0]-i,b=134217729*o,l=b-(b-o),f=o-l,h=i*l-c+i*f+e*l+e*f;!Number.isFinite(h)&&Number.isFinite(c)&&(h=F(t[0],o));let R=h+t[1]*o,L=c+R,C=R-(L-c),_=-L,z=-C,w=n[0]+_,i1=w-n[0],S1=n[0]-(w-i1)+(_-i1),x=n[1]+z,F1=x-n[1],R1=n[1]-(x-F1)+(z-F1),a=S1+x,g=w+a,J=a-(g-w)+R1,I=g+J,q=J-(I-g),N=I/t[0],y=t[0]*N,K=134217729*t[0],k=K-(K-t[0]),L1=t[0]-k,U=134217729*N,m=U-(U-N),V=N-m,E=k*m-y+k*V+L1*m+L1*V;!Number.isFinite(E)&&Number.isFinite(y)&&(E=F(t[0],N));let $=E+t[1]*N,W=y+$,r1=$-(W-y),X=-W,Y=-r1,P=I+X,Z=P-I,u1=I-(P-Z)+(X-Z),v=q+Y,t1=v-q,M1=q-(v-t1)+(Y-t1),n1=u1+v,O=P+n1,s1=n1-(O-P)+M1,b1=O+s1,x1=s1-(b1-O),o1=b1/t[0],D=o+N,j=N-(D-o),p=D+o1,P1=p-D,p1=D-(p-P1)+(o1-P1),d=j+0,H=d-j,M=j-(d-H)+(0-H),B=p1+d,G=p+B,c1=B-(G-p)+M,e1=G+c1,l1=c1-(e1-G);return[e1,l1]}function Ss(n,t){if(!Q)return[n[0]/t,0];let s=Cn(n[0],t);if(s!==0)return Ss([A(n[0],s),A(n[1],s)],A(t,s));let o=n[0]/t;if(!Number.isFinite(o))return[o,0];let c=t*o,r=134217729*t,i=r-(r-t),e=t-i,b=134217729*o,l=b-(b-o),f=o-l,h=i*l-c+i*f+e*l+e*f;!Number.isFinite(h)&&Number.isFinite(c)&&(h=F(t,o));let R=h+0*o,L=c+R,C=R-(L-c),_=-L,z=-C,w=n[0]+_,i1=w-n[0],S1=n[0]-(w-i1)+(_-i1),x=n[1]+z,F1=x-n[1],R1=n[1]-(x-F1)+(z-F1),a=S1+x,g=w+a,J=a-(g-w)+R1,I=g+J,q=J-(I-g),N=I/t,y=t*N,K=134217729*t,k=K-(K-t),L1=t-k,U=134217729*N,m=U-(U-N),V=N-m,E=k*m-y+k*V+L1*m+L1*V;!Number.isFinite(E)&&Number.isFinite(y)&&(E=F(t,N));let $=E+0*N,W=y+$,r1=$-(W-y),X=-W,Y=-r1,P=I+X,Z=P-I,u1=I-(P-Z)+(X-Z),v=q+Y,t1=v-q,M1=q-(v-t1)+(Y-t1),n1=u1+v,O=P+n1,s1=n1-(O-P)+M1,b1=O+s1,x1=s1-(b1-O),o1=b1/t,D=o+N,j=N-(D-o),p=D+o1,P1=p-D,p1=D-(p-P1)+(o1-P1),d=j+0,H=d-j,M=j-(d-H)+(0-H),B=p1+d,G=p+B,c1=B-(G-p)+M,e1=G+c1,l1=c1-(e1-G);return[e1,l1]}var w1=[.6931471805599453,23190468138462996e-33],Qn=Math.SQRT2,T=[[1,0],[.3333333333333333,1850371707708594e-32],[.2,-11102230246251566e-33],[.14285714285714285,793016446160826e-32],[.1111111111111111,61679056923619804e-34],[.09090909090909091,-2523234146875356e-33]],Fs=89,Rs=[[-.3633938941874773,-2106844752226605e-32],[-.3522205935893521,-57233316949182485e-34],[-.34117075740276714,19366790062602867e-33],[-.33024168687057687,10828321637483858e-33],[-.3194307707663612,-1354256857264811e-33],[-.3087354816496133,16199186085148102e-33],[-.29815337231907635,1720695867445866e-32],[-.2876820724517809,-2607160616442564e-32],[-.27731928541623435,744528405583513e-32],[-.26706278524904525,732891532732017e-32],[-.2569104137850272,-2502843296152504e-32],[-.24686007793152578,-1361743371748368e-32],[-.2369097470783577,-19682402978398164e-34],[-.22705745063534608,-9551415762738488e-33],[-.2173012756899814,-16168452453763015e-34],[-.2076393647782445,-12053243216686129e-33],[-.1980699137620938,-3742843482461439e-33],[-.18859116980755003,7432164219196925e-33],[-.179201429457711,10785017454858423e-33],[-.16989903679539747,4868008764439071e-34],[-.16068238169047347,3650183553047837e-33],[-.15154989812720093,-51669593684615594e-34],[-.14250006260728304,9926388234225749e-33],[-.13353139262452263,3664457663660085e-33],[-.1246424452072766,5808912678940971e-33],[-.1158318155251217,-4338484369808096e-33],[-.1070981355563671,173705104015906e-32],[-.09844007281325252,4439009633675136e-33],[-.08985632912186105,6273760163689594e-34],[-.0813456394539524,-507707635593117e-32],[-.07290677080808779,6306860257532778e-33],[-.06453852113757118,6470486661692933e-33],[-.05623971832287608,32835149805605613e-34],[-.048009219186360606,-14390903347292205e-34],[-.039845908547199674,3129547680315208e-33],[-.0317486983145803,-30382263084680858e-34],[-.023716526617316044,15774243488668215e-34],[-.015748356968139168,-10021578630528974e-34],[-.007843177461025893,-2764708154124904e-34],[0,0],[.007782140442054949,-12819179123343845e-36],[.015504186535965254,-3278321022892429e-34],[.02316705928153438,-11769544932063305e-34],[.030771658666753687,10431732029005968e-34],[.0383188643021366,-2357996157351286e-33],[.0458095360312942,1902959866474257e-33],[.053244514518812285,-1665575816973663e-33],[.06062462181643484,26424025938726934e-34],[.06795066190850775,-12802141240611733e-34],[.07522342123758753,-5930604196293241e-33],[.08244366921107459,5700437773813987e-33],[.08961215868968714,-54268129336647135e-34],[.09672962645855111,-5597397486289965e-34],[.10379679368164356,547772415726659e-32],[.11081436634029011,1183748342825649e-33],[.11778303565638346,-11971685747593677e-34],[.12470347850095724,-46522609636496624e-34],[.13157635778871926,11123000879729588e-33],[.13840232285911913,4447777301357527e-33],[.1451820098444979,8242418783022475e-33],[.15191604202584197,64838631244022194e-34],[.15860503017663857,11257003872182592e-33],[.16524957289530717,-10094935622322628e-33],[.17185025692665923,-60224538210113705e-34],[.1784076574728183,-12432553788701131e-33],[.184922338494012,30236614153574064e-34],[.19139485299962947,-12129496905792884e-33],[.19782574332991987,12821194372980142e-33],[.2042155414286909,27338281018722773e-34],[.21056476910734964,-4249405314729895e-33],[.21687393830061436,4551026193234283e-33],[.22314355131420976,-9091270597324799e-33],[.22937410106484582,9927671823978025e-33],[.2355660713127669,-23943371495187355e-34],[.24171993688714516,8900990022166643e-33],[.24783616390458127,-12432209578702523e-33],[.25391520998096345,-8048097394424201e-33],[.25995752443692605,2069806938978935e-32],[.26596354849713794,53393802761314314e-34],[.27193371548364176,783319637697442e-33],[.2778684510034563,-916018294909263e-33],[.2837681731306446,-2032665581126656e-32],[.28963329258304266,20535953219858174e-33],[.2954642128938359,-216461086040599e-31],[.3012613305781618,-9048511144048564e-33],[.3070250352949119,-12319916200101964e-33],[.3127557100038969,-1451808353098951e-32],[.3184537311185346,27114779367326236e-33],[.324119468654212,-7958214381893813e-33],[.329753286372468,2122020616196946e-33],[.3353555419211378,1834564437059473e-32],[.3409265869705932,17467136443544747e-33],[.34646676734620857,1028583585496265e-32],[.3519764231571782,-12953893030191963e-33],[.3574558889218038,-25136910072413547e-33]];function Os(n){if(!Q)return[Math.log(n[0]),0];if(!(n[0]>0&&n[0]<1/0))return[Math.log(n[0]),0];let t=n[0],s=n[1],o=0;t<22250738585072014e-324&&(t*=2**600,s*=2**600,o=-600);let c=Math.floor(Math.log2(t));o+=c;let r=2**-c,i=t*r,e=s*r;i>=Qn?(i=i/2,e=e/2,o+=1):i<Qn/2&&(i=i*2,e=e*2,o-=1);let b=Math.round(i*128),l=b/128,f=Rs[b-Fs],h=-l,R=-0,L=i+h,C=L-i,_=i-(L-C)+(h-C),z=e+R,w=z-e,i1=e-(z-w)+(R-w),S1=_+z,x=L+S1,R1=S1-(x-L)+i1,a=x+R1,g=R1-(a-x),E1=i+l,J=E1-i,I=i-(E1-J)+(l-J),q=e+0,N=q-e,y=e-(q-N)+(0-N),K=I+q,k=E1+K,U=K-(k-E1)+y,m=k+U,V=U-(m-k),E=a/m,$=m*E,W=134217729*m,r1=W-(W-m),X=m-r1,Y=134217729*E,P=Y-(Y-E),Z=E-P,u1=r1*P-$+r1*Z+X*P+X*Z;!Number.isFinite(u1)&&Number.isFinite($)&&(u1=F(m,E));let v=u1+V*E,t1=$+v,M1=v-(t1-$),n1=-t1,O=-M1,I1=a+n1,s1=I1-a,b1=a-(I1-s1)+(n1-s1),x1=g+O,o1=x1-g,D=g-(x1-o1)+(O-o1),j=b1+x1,p=I1+j,p1=j-(p-I1)+D,d=p+p1,H=p1-(d-p),M=d/m,B=m*M,G=134217729*m,a1=G-(G-m),c1=m-a1,e1=134217729*M,l1=e1-(e1-M),o0=M-l1,nt=a1*l1-B+a1*o0+c1*l1+c1*o0;!Number.isFinite(nt)&&Number.isFinite(B)&&(nt=F(m,M));let c0=nt+V*M,e0=B+c0,_n=c0-(e0-B),i0=-e0,r0=-_n,q1=d+i0,u0=q1-d,zn=d-(q1-u0)+(i0-u0),st=H+r0,b0=st-H,Hn=H-(st-b0)+(r0-b0),l0=zn+st,ot=q1+l0,T0=l0-(ot-q1)+Hn,f0=ot+T0,Ls=T0-(f0-ot),h0=f0/m,y1=E+M,ct=M-(y1-E),k1=y1+h0,m0=k1-y1,Jn=y1-(k1-m0)+(h0-m0),et=ct+0,N0=et-ct,Kn=ct-(et-N0)+(0-N0),S0=Jn+et,it=k1+S0,F0=S0-(it-k1)+Kn,S=it+F0,rt=F0-(S-it),D1=S*S,R0=134217729*S,ut=R0-(R0-S),E0=S-ut,L0=134217729*S,bt=L0-(L0-S),I0=S-bt,lt=ut*bt-D1+ut*I0+E0*bt+E0*I0;!Number.isFinite(lt)&&Number.isFinite(D1)&&(lt=F(S,S));let P0=lt+(S*rt+rt*S),u=D1+P0,g1=P0-(u-D1),A1=T[5][0]*u,p0=134217729*T[5][0],Tt=p0-(p0-T[5][0]),d0=T[5][0]-Tt,w0=134217729*u,ft=w0-(w0-u),M0=u-ft,ht=Tt*ft-A1+Tt*M0+d0*ft+d0*M0;!Number.isFinite(ht)&&Number.isFinite(A1)&&(ht=F(T[5][0],u));let x0=ht+(T[5][0]*g1+T[5][1]*u),$1=A1+x0,mt=x0-($1-A1),v1=$1+T[4][0],a0=v1-$1,Un=$1-(v1-a0)+(T[4][0]-a0),Nt=mt+T[4][1],g0=Nt-mt,Vn=mt-(Nt-g0)+(T[4][1]-g0),q0=Un+Nt,St=v1+q0,y0=q0-(St-v1)+Vn,T1=St+y0,Wn=y0-(T1-St),O1=T1*u,k0=134217729*T1,Ft=k0-(k0-T1),D0=T1-Ft,A0=134217729*u,Rt=A0-(A0-u),$0=u-Rt,Et=Ft*Rt-O1+Ft*$0+D0*Rt+D0*$0;!Number.isFinite(Et)&&Number.isFinite(O1)&&(Et=F(T1,u));let v0=Et+(T1*g1+Wn*u),j1=O1+v0,Lt=v0-(j1-O1),B1=j1+T[3][0],O0=B1-j1,Xn=j1-(B1-O0)+(T[3][0]-O0),It=Lt+T[3][1],j0=It-Lt,Yn=Lt-(It-j0)+(T[3][1]-j0),B0=Xn+It,Pt=B1+B0,G0=B0-(Pt-B1)+Yn,f1=Pt+G0,Zn=G0-(f1-Pt),G1=f1*u,Q0=134217729*f1,pt=Q0-(Q0-f1),C0=f1-pt,_0=134217729*u,dt=_0-(_0-u),z0=u-dt,wt=pt*dt-G1+pt*z0+C0*dt+C0*z0;!Number.isFinite(wt)&&Number.isFinite(G1)&&(wt=F(f1,u));let H0=wt+(f1*g1+Zn*u),Q1=G1+H0,Mt=H0-(Q1-G1),C1=Q1+T[2][0],J0=C1-Q1,ts=Q1-(C1-J0)+(T[2][0]-J0),xt=Mt+T[2][1],K0=xt-Mt,ns=Mt-(xt-K0)+(T[2][1]-K0),U0=ts+xt,at=C1+U0,V0=U0-(at-C1)+ns,h1=at+V0,ss=V0-(h1-at),_1=h1*u,W0=134217729*h1,gt=W0-(W0-h1),X0=h1-gt,Y0=134217729*u,qt=Y0-(Y0-u),Z0=u-qt,yt=gt*qt-_1+gt*Z0+X0*qt+X0*Z0;!Number.isFinite(yt)&&Number.isFinite(_1)&&(yt=F(h1,u));let tn=yt+(h1*g1+ss*u),z1=_1+tn,kt=tn-(z1-_1),H1=z1+T[1][0],nn=H1-z1,os=z1-(H1-nn)+(T[1][0]-nn),Dt=kt+T[1][1],sn=Dt-kt,cs=kt-(Dt-sn)+(T[1][1]-sn),on=os+Dt,At=H1+on,cn=on-(At-H1)+cs,m1=At+cn,es=cn-(m1-At),J1=m1*u,en=134217729*m1,$t=en-(en-m1),rn=m1-$t,un=134217729*u,vt=un-(un-u),bn=u-vt,Ot=$t*vt-J1+$t*bn+rn*vt+rn*bn;!Number.isFinite(Ot)&&Number.isFinite(J1)&&(Ot=F(m1,u));let ln=Ot+(m1*g1+es*u),K1=J1+ln,jt=ln-(K1-J1),U1=K1+T[0][0],Tn=U1-K1,is=K1-(U1-Tn)+(T[0][0]-Tn),Bt=jt+T[0][1],fn=Bt-jt,rs=jt-(Bt-fn)+(T[0][1]-fn),hn=is+Bt,Gt=U1+hn,mn=hn-(Gt-U1)+rs,N1=Gt+mn,us=mn-(N1-Gt),V1=S*N1,Nn=134217729*S,Qt=Nn-(Nn-S),Sn=S-Qt,Fn=134217729*N1,Ct=Fn-(Fn-N1),Rn=N1-Ct,_t=Qt*Ct-V1+Qt*Rn+Sn*Ct+Sn*Rn;!Number.isFinite(_t)&&Number.isFinite(V1)&&(_t=F(S,N1));let En=_t+(S*us+rt*N1),d1=V1+En,bs=En-(d1-V1),W1=d1*2,Ln=134217729*d1,zt=Ln-(Ln-d1),In=d1-zt,Pn=134217729*2,Ht=Pn-(Pn-2),pn=2-Ht,Jt=zt*Ht-W1+zt*pn+In*Ht+In*pn;!Number.isFinite(Jt)&&Number.isFinite(W1)&&(Jt=F(d1,2));let dn=Jt+bs*2,Kt=W1+dn,wn=dn-(Kt-W1),X1=f[0]+Kt,Mn=X1-f[0],ls=f[0]-(X1-Mn)+(Kt-Mn),Ut=f[1]+wn,xn=Ut-f[1],Ts=f[1]-(Ut-xn)+(wn-xn),an=ls+Ut,Vt=X1+an,gn=an-(Vt-X1)+Ts,Y1=Vt+gn,Wt=gn-(Y1-Vt),Z1=w1[0]*o,qn=134217729*w1[0],Xt=qn-(qn-w1[0]),yn=w1[0]-Xt,kn=134217729*o,Yt=kn-(kn-o),Dn=o-Yt,Zt=Xt*Yt-Z1+Xt*Dn+yn*Yt+yn*Dn;!Number.isFinite(Zt)&&Number.isFinite(Z1)&&(Zt=F(w1[0],o));let An=Zt+w1[1]*o,t0=Z1+An,$n=An-(t0-Z1),tt=Y1+t0,vn=tt-Y1,fs=Y1-(tt-vn)+(t0-vn),n0=Wt+$n,On=n0-Wt,hs=Wt-(n0-On)+($n-On),jn=fs+n0,s0=tt+jn,Bn=jn-(s0-tt)+hs,Gn=s0+Bn,ms=Bn-(Gn-s0);return[Gn,ms]}function Bs(n,t,s,o){if(!(typeof n!="object"||n===null))for(let c in n){if(Array.isArray(t)?t.includes(c):t.has(c))continue;let r=o===void 0?c:`${o}.${c}`;throw new RangeError(`unknown option '${r}' for ${s} (known: ${[...t].join(", ")})`)}}function Gs(n,t){let s=n;for(let o of t.split(".")){if(typeof s!="object"||s===null)return;s=s[o]}return s}export{gs as a,qs as b,ys as c,ks as d,Ds as e,As as f,$s as g,vs as h,Ns as i,Ss as j,Os as k,Bs as l,Gs as m};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{a as b}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.12.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 b}from"./chunk-CHKBDZC4.js";import{d as h,e as f}from"./chunk-SLMS3FQD.js";import{b as c}from"./chunk-O6OMXX5U.js";function w(t){let r=h(t);return r.some(e=>typeof e=="string")?r.map(e=>typeof e=="number"&&!Number.isNaN(e)?f(e):e):r}function N(t,r){return typeof t=="number"&&typeof r=="number"?t-r:b(String(t),String(r))}function d(t,r,e="drop"){if(r===void 0){let n=t;if(n.length>0&&typeof n[0]=="number")throw new TypeError("'g' is required when 'x' is a single sample");let u=n.map(i=>Array.from(i).filter(p=>!Number.isNaN(p)));if(e==="error"&&u.some(i=>i.length===0))throw new RangeError("all groups must contain data");let s=[],a=[];return u.forEach((i,p)=>{i.length!==0&&(s.push(String(p+1)),a.push(i))}),{labels:s,groups:a}}let o=Array.from(t);if(o.length!==r.length)throw new RangeError("'x' and 'g' must have the same length");let l=w(r),m=new Map;for(let n=0;n<o.length;n++){let u=o[n],s=l[n];if(Number.isNaN(u)||typeof s=="number"&&Number.isNaN(s))continue;let a=m.get(s);a===void 0&&m.set(s,a=[]),a.push(u)}let g=Array.from(m.keys()).sort(N);return{labels:g.map(f),groups:g.map(n=>m.get(n))}}function E(t,r,e="drop"){return d(t,r,e).groups}function R(t){let r=[...t].sort((o,l)=>o-l),e=r.length;return e%2===1?r[(e-1)/2]:c(r[e/2-1],r[e/2])}function A(t){if(t.length===0)throw new RangeError("'y' must have at least one row");let r=t[0].length;if(t.some(e=>e.length!==r))throw new RangeError("all rows of 'y' must have the same length");return t.filter(e=>e.every(o=>!Number.isNaN(o))).map(e=>Array.from(e))}export{w as a,N as b,d as c,E as d,R as e,A as f};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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 ue,c as me}from"./chunk-ZHAT6244.js";import{a as ge,b as we,d as re,e as ve,f as be}from"./chunk-L54WIMTZ.js";import{c as ye}from"./chunk-SZR5HAMB.js";import{j as de,n as pe,o as he}from"./chunk-4B7NEJCE.js";import{b as ce}from"./chunk-UPFMYDF7.js";import{c as z,e as T,f as $}from"./chunk-7UI4PW32.js";import{a as ne}from"./chunk-O6OMXX5U.js";import{s as oe}from"./chunk-ULQXNAI6.js";import{C as B,c as fe,d as le,h as E,i as G}from"./chunk-NAACMR7H.js";import{l as P,m as X}from"./chunk-52KGBGFL.js";function Ne(e){let n=e.length,t=new Array(n).fill(0);for(let i=0;i<n;i++){let s=0;for(let a=0;a<=i;a++)s=Math.max(s,Math.abs(e[a][i]));s>0&&Number.isFinite(s)&&(s<2**-400||s>2**400)&&(t[i]=Math.floor(Math.log2(s)))}let r=t.every(i=>i===0)?e.map(i=>i.slice()):e.map(i=>i.map((s,a)=>E(s,-t[a])));return{inv:ye(r),e:t}}var ke=new WeakMap;function ie(e,n){return n!==void 0&&ke.set(e,n),e}function et(e,n){return ke.get(e)??(n.length===0?0:n[n.length-1]+1)}function tt(e,n){for(let t of n)if(Object.hasOwn(e,t))return e[t].length;return Object.values(e)[0]?.length}var Pe=["family","link","weights","offset","start","epsilon","maxit","intercept"],Fe=["family","link","variance"],Me=["power"],We=["dispersion"],De=["type"],Ce=["type","dispersion"],Ge=["dispersion"],ze=["newdata","newoffset","type","dispersion"],L=2**-52;function Le(e){let n=e.map(t=>`"${t}"`);return n.length===1?n[0]:`c(${n.join(", ")})`}function V(e,n,t){return e.map((r,i)=>{let s=0;for(let a=0;a<r.length;a++)s+=r[a]*n[a];return s+t[i]})}function D(e,n,t,r){let i=0;for(let s=0;s<n.length;s++)r[s]!==0&&(i+=e.devContribution(n[s],t[s],r[s]));return i}var Ee=2**-1022,H=e=>e===0||Math.abs(e)>=Ee&&Math.abs(e)<1/0;function xe(e,n,t,r){let i=e.variance(r),s=t**2,a=Math.sqrt(n*s/i);if(a>0&&a<1/0&&H(s)&&s!==0&&H(i)&&i!==0&&H(n*s))return a;if(e.muPower!==void 0&&e.varPower!==void 0&&r>0){let{c:o,a:u}=e.muPower;return Math.sqrt(n)*Math.abs(o)*r**((2*u-e.varPower)/2)}return a}function se(e,n,t,r){let i=(n-t)/r;if(Math.abs(r)>=Ee&&Math.abs(r)<1/0)return i;if(e.muPower!==void 0&&t>0){let{c:s,a}=e.muPower,o=t**(a/2);return(n-t)/s/o/o}return i}function Ye(e,n,t,r){let i=e.variance(t),s=(n-t)*Math.sqrt(r)/Math.sqrt(i);if(Number.isFinite(s)&&H(i)&&i!==0||e.varPower===void 0||!(t>0))return s;let a=t**(e.varPower/4);return(n-t)/a*Math.sqrt(r)/a}var Ke=.1;function qe(e,n){let{x:t,p:r,y:i,w:s,offset:a,fam:o,epsilon:u,maxit:m}=e,p=i.length;if(i.some((c,h)=>s[h]>0&&!Number.isFinite(c)))throw new RangeError("NA/NaN/Inf in 'y'");if(t.some((c,h)=>s[h]>0&&c.some(M=>!Number.isFinite(M))))throw new RangeError("NA/NaN/Inf in 'x'");return $(n,()=>{let c=(R,I)=>R.every(W=>o.etaOk(W))&&I.every(W=>o.muOk(W));if(r===0){let R=a.slice();if(!R.every(_=>o.etaOk(_)))throw new Error("invalid linear predictor values in empty model");let I=R.map(_=>o.linkinv(_));if(!I.every(_=>o.muOk(_)))throw new Error("invalid fitted means in empty model");let W=R.map(_=>o.muEta(_)),j=I.map((_,C)=>xe(o,s[C],W[C],_)**2);return{coefficients:[],eta:R,mu:I,deviance:D(o,i,I,s),iter:0,converged:!0,boundary:!0,rank:0,qr:void 0,used:s.map(_=>_>0),workingWeights:j,workingResiduals:i.map((_,C)=>se(o,_,I[C],W[C]))}}let h,M;if(e.start!==void 0){if(e.start.length!==r)throw new RangeError(`length of 'start' should equal ${r} and correspond to initial coefs for ${Le(e.columnNames)}`);M=e.start.slice(),h=V(t,M,a)}else e.etastart!==void 0?h=e.etastart.slice():h=e.mustart.map(R=>o.link(R));let v=h.map(R=>o.linkinv(R));if(!c(h,v))throw new Error("cannot find valid starting values: please specify some");let A=D(o,i,v,s),y=A,x=!1,q=!1,b=0,l=new Array(r).fill(0),f,g=s.map(()=>!1),k=[],w=[],S=Math.min(1e-7,u/1e3);for(b=1;b<=m;b++){let R=h.map(d=>o.muEta(d));for(let d=0;d<p;d++){if(!(s[d]>0))continue;let N=o.variance(v[d]);if(Number.isNaN(N))throw new Error("NAs in V(mu)");if(N===0&&!(o.varPower!==void 0&&v[d]>0))throw new Error("0s in V(mu)");if(Number.isNaN(R[d]))throw new Error("NAs in d(mu)/d(eta)")}g=s.map((d,N)=>d>0&&R[N]!==0);let I=[];for(let d=0;d<p;d++)g[d]&&I.push(d);if(I.length===0){n.add(`no observations informative at iteration ${b}`),x=!1;break}k=new Array(p).fill(0);let W=[],j=[];for(let d of I){let N=xe(o,s[d],R[d],v[d]);k[d]=N,W.push((h[d]-a[d]+se(o,i[d],v[d],R[d]))*N),j.push(t[d].map(O=>O*N))}f=de(j,{tol:S});let _=he(f,W);if(_.some((d,N)=>f.pivot.indexOf(N)<f.rank&&!Number.isFinite(d))){n.add(`non-finite coefficients at iteration ${b}`),x=!1;break}l=_.map(d=>Number.isNaN(d)?0:d),q=!1;let C=h;if(h=V(t,l,a),v=h.map(d=>o.linkinv(d)),y=D(o,i,v,s),!Number.isFinite(y)){if(M===void 0)throw new Error("no valid set of coefficients has been found: please supply starting values");n.add("step size truncated due to divergence");let d=0;for(;!Number.isFinite(y);){if(d>=m)throw new Error("inner loop 1; cannot correct step size");d++,l=l.map((N,O)=>(N+M[O])/2),h=V(t,l,a),v=h.map(N=>o.linkinv(N)),y=D(o,i,v,s)}q=!0}if(!c(h,v)){if(M===void 0)throw new Error("no valid set of coefficients has been found: please supply starting values");n.add("step size truncated: out of bounds");let d=0;for(;!c(h,v);){if(d>=m)throw new Error("inner loop 2; cannot correct step size");d++,l=l.map((N,O)=>(N+M[O])/2),h=V(t,l,a),v=h.map(N=>o.linkinv(N))}q=!0,y=D(o,i,v,s)}let te=Math.max(u,1e-10);if(M!==void 0&&b>1&&(y-A)/(.1+Math.abs(y))>=te){n.add("step size truncated due to increasing deviance");let d=0;for(;(y-A)/(.1+Math.abs(y))>=te&&d<m;)d++,l=l.map((N,O)=>(N+M[O])/2),h=V(t,l,a),v=h.map(N=>o.linkinv(N)),y=D(o,i,v,s);if((y-A)/(.1+Math.abs(y))>=te){n.add("inner loop 3; cannot correct step size"),x=!1;break}}if(e.untilCoefficients){let d=ne(l.map(Math.abs));if(M!==void 0&&l.every((N,O)=>Math.abs(N-M[O])<=8*L*d)){x=!0;break}if(w.some(N=>N.every((O,Oe)=>O===l[Oe]))){x=!0;break}w.push(l.slice()),w.length>16&&w.shift()}else if(Math.abs(y-A)/(Math.abs(y)+.1)<u){x=!0;let d=0;for(let N=0;N<p;N++)g[N]&&(d=Math.max(d,Math.abs(h[N]-C[N])));d>Ke&&n.add("glm.fit: the linear predictor was still changing at convergence: the data may be separated (no finite maximum likelihood estimates)");break}A=y,M=l.slice()}b>m&&(b=m);let F=r,ee=l.slice();if(f!==void 0){F=f.rank;for(let R=f.rank;R<r;R++)ee[f.pivot[R]]=NaN}let K=h.map(R=>o.muEta(R));return{coefficients:ee,eta:h,mu:v,deviance:y,iter:b,converged:x,boundary:q,rank:F,qr:f,used:g,workingWeights:k.map(R=>R*R),workingResiduals:i.map((R,I)=>se(o,R,v[I],K[I]))}})}function Ae(e){return e.length>0&&typeof e[0]!="number"?e.map(n=>Array.from(n)):Array.from(e,n=>[n])}function Se(e,n,t,r){r||(e.converged||t.add("glm.fit: algorithm did not converge"),e.boundary&&t.add("glm.fit: algorithm stopped at boundary value"),n.family==="binomial"&&e.mu.some(i=>i>1-10*L||i<10*L)&&t.add("glm.fit: fitted probabilities numerically 0 or 1 occurred"),n.family==="poisson"&&e.mu.some(i=>i<10*L)&&t.add("glm.fit: fitted rates numerically 0 occurred"))}function Te(e,n,t,r={}){let i=re(e.familySpec),s="start"in r?r.start:e.start,a=ve(i,e.yGiven,e.priorGiven,s!==void 0||r.etastart!==void 0,t);if(!a.weights.some(p=>p>0))throw new RangeError("all weights are zero");let o=r.extraOffset===void 0?e.offset:e.offset.map((p,c)=>p+r.extraOffset[c]),u=e.x.map(p=>n.map(c=>p[c])),m=qe({x:u,p:n.length,y:a.y,w:a.weights,offset:o,fam:i,epsilon:r.epsilon??e.epsilon,maxit:r.maxit??e.maxit,columnNames:n.map(p=>e.columnNames[p]),start:s,etastart:r.etastart,mustart:a.mustart,untilCoefficients:r.untilCoefficients},t);return Se(m,i,t,n.length===0),{fit:m,fam:i,y:a.y,w:a.weights,size:a.size,offset:o}}function wt(e,n,t={}){P(t,Pe,"glm"),P(X(t,"family"),Fe,"glm","family"),P(X(t,"family.link"),Me,"glm","family.link"),P(X(t,"link"),Me,"glm","link");let r=t.intercept??!0,i=Ae(e);if(i.some(w=>w.length!==i[0].length))throw new TypeError("all rows of x must have the same length");let s=n.length>0&&typeof n[0]!="number",a=s?n.map(w=>Array.from(w)):Array.from(n),o=a.length;if(i.length!==o)throw new RangeError("variable lengths differ (found for 'x1')");let u=t.weights===void 0?void 0:Array.from(t.weights);if(u!==void 0&&u.length!==o)throw new RangeError("variable lengths differ (found for '(weights)')");let m=t.offset===void 0?void 0:Array.from(t.offset);if(m!==void 0&&m.length!==o)throw new RangeError("variable lengths differ (found for '(offset)')");let p=i.map((w,S)=>{let F=a[S];return!(Array.isArray(F)?F.some(K=>Number.isNaN(K)):Number.isNaN(F))&&w.every(K=>!Number.isNaN(K))&&!(u!==void 0&&Number.isNaN(u[S]))&&!(m!==void 0&&Number.isNaN(m[S]))}),c=i.filter((w,S)=>p[S]).map(w=>r?[1,...w]:w),h=a.filter((w,S)=>p[S]),M=h.length;if(M===0)throw new RangeError("0 (non-NA) cases");let v=u===void 0?new Array(M).fill(1):u.filter((w,S)=>p[S]);if(v.some(w=>w<0))throw new RangeError("negative weights not allowed");if(v.some(w=>!Number.isFinite(w)))throw new RangeError("non-finite weights not allowed");let A=m===void 0?new Array(M).fill(0):m.filter((w,S)=>p[S]);if(A.some(w=>!Number.isFinite(w)))throw new RangeError("the offset must be finite");let y=i.length>0?i[0].length:0,x=[...r?["(Intercept)"]:[],...Array.from({length:y},(w,S)=>`x${S+1}`)],q=x.length,b=typeof t.family=="object"?{...t.family}:{family:t.family??"gaussian"};t.link!==void 0&&(b.link=t.link);let l={x:c,columnNames:x,yGiven:h,priorGiven:v,offset:A,hasOffset:m!==void 0,intercept:r,familySpec:b,epsilon:t.epsilon??1e-8,maxit:Math.floor(t.maxit??25),start:t.start===void 0?void 0:Array.from(t.start),rows:p.flatMap((w,S)=>w?[S]:[])};if(!(l.epsilon>0&&l.epsilon<1/0))throw new RangeError("value of 'epsilon' must be > 0 and finite");if(!(l.maxit>0&&l.maxit<1/0))throw new RangeError("maximum number of iterations must be > 0");let f=!s&&$e(b)?B([h]).k:0;if(f===0)return z("glm",ie(Re(l),o));let g=w=>E(w,-f),k=Re({...l,yGiven:h.map(g),offset:A.map(g),start:l.start?.map(g)});return z("glm",ie(Ve(k,f,{...l,yScale:f}),o))}function Re(e){let{x:n,offset:t,intercept:r}=e,i=n.length,s=e.columnNames.length,a=new T,o=Array.from({length:s},(y,x)=>x),{fit:u,fam:m,y:p,w:c,size:h}=Te(e,o,a),M;if(r&&e.hasOffset){let y=new T,x=qe({x:n.map(()=>[1]),p:1,y:p,w:c,offset:t,fam:m,epsilon:e.epsilon,maxit:e.maxit,columnNames:["(Intercept)"],mustart:u.mu},y);Se(x,m,y,!1),y.list.forEach(q=>a.add(q)),M=x.deviance,x.converged||a.add("fitting to calculate the null deviance did not converge -- increase 'maxit'?")}else if(r){let y=Math.floor(Math.log2(ne(c))),x=0,q=0;for(let l=0;l<i;l++){if(!(c[l]>0))continue;let f=E(c[l],-y);x+=f,q+=f*p[l]}let b=q/x;if(!Number.isFinite(b)){let l=0;for(let k=0;k<i;k++)c[k]>0&&(l=Math.max(l,Math.abs(p[k])));let f=Math.floor(Math.log2(l)),g=0;for(let k=0;k<i;k++)c[k]>0&&(g+=E(c[k],-y)*E(p[k],-f));b=E(g/x,f)}M=$(a,()=>D(m,p,p.map(()=>b),c))}else M=$(a,()=>D(m,p,t.map(y=>m.linkinv(y)),c));let v=i-c.filter(y=>y===0).length,A=be(m,p,u.mu,c,h,u.deviance,a)+2*u.rank;return _e(u.used,{coefficients:u.coefficients,fittedValues:u.mu,linearPredictors:u.eta,deviance:u.deviance,nullDeviance:M,aic:A,rank:u.rank,dfResidual:v-u.rank,dfNull:v-(r?1:0),iter:u.iter,converged:u.converged,boundary:u.boundary,y:p,priorWeights:c,weights:u.workingWeights,residuals:u.workingResiduals,family:m.family,link:m.name,warnings:a.list,qr:u.qr,model:e})}function $e(e){return(e.link??"identity")!=="identity"?!1:e.family==="gaussian"||e.family==="quasi"&&(e.variance??"constant")==="constant"}function Ve(e,n,t){let r=s=>E(s,n),i={...e,coefficients:e.coefficients.map(r),fittedValues:e.fittedValues.map(r),linearPredictors:e.linearPredictors.map(r),deviance:E(e.deviance,2*n),nullDeviance:E(e.nullDeviance,2*n),aic:e.aic+2*e.priorWeights.filter(s=>s>0).length*n*Math.LN2,y:e.y.map(r),residuals:e.residuals.map(r),model:t};return Object.defineProperty(i,"scaled",{value:e,enumerable:!1}),_e(J.get(e),i)}var J=new WeakMap;function _e(e,n){return e!==void 0&&J.set(n,e),n}function Y(e){let n=e.scaled;return n===void 0?{fit:e,k:0}:{fit:n,k:e.model.yScale??0}}function U(e){return re(e.model.familySpec)}function yt(e,n){let t=Y(e),r=Q(t.fit,n);return U(e).fixedDispersion?r:E(r,2*t.k)}function Q(e,n){if(U(e).fixedDispersion)return 1;if(e.dfResidual<=0)return NaN;let t=0;for(let r=0;r<e.weights.length;r++)e.weights[r]>0&&(t+=e.weights[r]*e.residuals[r]**2);return e.weights.some(r=>r===0)&&n?.add("observations with zero weight not used for calculating dispersion"),t===1/0?Ue(e):t/e.dfResidual}function Ue(e){let n=[];for(let s=0;s<e.weights.length;s++)e.weights[s]>0&&n.push(s);if(!n.every(s=>Number.isFinite(e.weights[s])&&Number.isFinite(e.residuals[s])))return 1/0;let t=B([n.map(s=>e.residuals[s])]),r=B([n.map((s,a)=>Math.sqrt(e.weights[s])*Math.abs(t.groups[0][a]))]),i=0;for(let s of r.groups[0])i+=s*s;return E(i/e.dfResidual,2*(t.k+r.k))}function Qe(e){return e.qr===void 0||e.rank===0?{inv:[],e:[]}:Ne(e.qr.qr.slice(0,e.rank).map(n=>n.slice(0,e.rank)))}function je(e){if(!(e>=0&&e<1/0))throw new RangeError("'dispersion' must be a non-negative finite number");return e}function Z(e,n){let t=E(je(e),-2*n);if(t===0?e===0:t>=2**-1022&&t<1/0)return{m:t,s:0};let r=Math.floor(Math.floor(Math.log2(e))/2);return{m:E(e,-2*r),s:r-n}}function vt(e,n={}){P(n,We,"glmSummary");let{fit:t,k:r}=Y(e),i=new T,s=U(t),a=n.dispersion===void 0&&!s.fixedDispersion,o=n.dispersion===void 0?void 0:Z(n.dispersion,r),u=o===void 0?Q(t,i):o.m,m=o?.s??0,{inv:p,e:c}=Qe(t),h=p.map((f,g)=>f.map((k,w)=>E(k,-c[g]-c[w]))),v=(t.qr===void 0?[]:t.qr.pivot.slice(0,t.rank)).map(f=>t.coefficients[f]),A=p.map((f,g)=>E(Math.sqrt(f[g]*u),-c[g])),y=m===0?v.map((f,g)=>f/A[g]):v.map((f,g)=>G(f/Math.sqrt(p[g][g]*u),c[g]-m)),x=!a,q=y.map(f=>x?2*oe(-Math.abs(f)):t.dfResidual>0?2*ce(-Math.abs(f),t.dfResidual,!0,!1):NaN);a&&t.dfResidual===0&&(A.fill(NaN),y.fill(NaN));let b=f=>E(f,r),l=f=>E(f,2*r);return z("glmSummary",{dispersion:m===0?l(u):n.dispersion,estimate:v.map(b),stdError:m===0?A.map(b):p.map((f,g)=>G(Math.sqrt(f[g]*u),m+r-c[g])),statistic:y,pValue:q,statisticName:x?"z value":"t value",covUnscaled:h,covScaled:m===0?h.map(f=>f.map(g=>l(g*u))):p.map((f,g)=>f.map((k,w)=>G(k*u,2*(m+r)-c[g]-c[w]))),dfResidual:t.dfResidual,warnings:i.list},e)}function bt(e,...n){P(me(n),De,"glmResiduals");let t=ue(["type"],n).type??"deviance",r=Y(e);return ae(r.fit,t).map(i=>E(i,r.k))}function ae(e,n){let t=U(e),{y:r,fittedValues:i,priorWeights:s}=e;switch(n){case"response":return r.map((a,o)=>a-i[o]);case"working":return e.residuals.slice();case"pearson":return r.map((a,o)=>Ye(t,a,i[o],s[o]));case"deviance":return r.map((a,o)=>s[o]===0?0:Math.sign(a-i[o])*Math.sqrt(Math.max(t.devContribution(a,i[o],s[o]),0)));default:throw new RangeError(`unknown type of residuals "${String(n)}"`)}}function Ie(e){let n=[],t=e.qr,r=[];if(t!==void 0&&e.rank>0){let a=t.qr.length,o=Array.from({length:a},(m,p)=>Array.from({length:e.rank},(c,h)=>p===h?1:0));r=pe(t,o).map(m=>m.reduce((p,c)=>p+c*c,0))}let i=0,s=J.get(e)??e.weights.map(a=>a>0);return e.priorWeights.forEach((a,o)=>{let u=s[o]?r[i++]??0:0;a>0&&n.push(u>1-10*L?1:u)}),n}function Nt(e){let n=[],t=0,r=J.get(e)??e.weights.map(i=>i>0);return e.priorWeights.forEach((i,s)=>{let a=r[s]?t++:-1;i>0&&n.push(a)}),n}function Xe(e){let n=e.slice().sort((r,i)=>r-i),t=n.length>>1;return n.length%2===1?n[t]:(n[t-1]+n[t])/2}function kt(e,n={}){P(n,Ce,"glmRstandard");let t=n.type??"pearson";if(t!=="pearson"&&t!=="deviance")throw new RangeError(`unknown type "${String(t)}" for glmRstandard`);let{fit:r,k:i}=Y(e),s=Ie(r),{m:a,s:o}=n.dispersion===void 0?{m:Q(r),s:0}:Z(n.dispersion,i),u=Math.sqrt(a),m=ae(r,t).filter((c,h)=>r.priorWeights[h]>0),p=r.rank>0?100*L*Xe(m.map(Math.abs)):0;return m.map((c,h)=>{let M=G((Math.abs(c)<p?0:c)/(u*Math.sqrt(1-s[h])),-o);return Number.isFinite(M)?M:NaN})}function Mt(e,n={}){P(n,Ge,"glmCooksDistance");let{fit:t,k:r}=Y(e),i=Ie(t),{m:s,s:a}=n.dispersion===void 0?{m:Q(t),s:0}:Z(n.dispersion,r);return ae(t,"pearson").filter((u,m)=>t.priorWeights[m]>0).map((u,m)=>{let p=i[m]/(s*t.rank),c=(u/(1-i[m]))**2*p;return(!Number.isFinite(c)||p<2**-1022)&&(c=Be(u,i[m],s,t.rank)),a!==0&&(c=G(c,-2*a)),Number.isFinite(c)?c:NaN})}function Be(e,n,t,r){if(!Number.isFinite(e)||!(t>0&&Number.isFinite(t)))return NaN;let i=e===0?0:Math.floor(Math.log2(Math.abs(e))),s=Math.floor(Math.log2(t)),a=E(e,-i)/(1-n);return E(a*a*(n/(E(t,-s)*r)),2*i-s)}function xt(e,n={}){P(n,ze,"glmPredict");let{fit:t,k:r}=Y(e),i=q=>E(q,r),s=U(t),a,o;if(n.newdata===void 0)a=t.model.x,o=t.linearPredictors.slice();else{if(a=Ae(n.newdata).map(l=>t.model.intercept?[1,...l]:l),a.some(l=>l.length!==t.coefficients.length))throw new RangeError("newdata must have one column per predictor of the fit");let q=n.newoffset===void 0?a.map(()=>0):Array.from(n.newoffset,l=>E(l,-r));if(q.length!==a.length)throw new RangeError("newoffset must have one value per row of newdata");let b=t.coefficients.flatMap((l,f)=>Number.isNaN(l)?[]:[f]);o=a.map((l,f)=>{let g=l.reduce((w,S,F)=>Number.isNaN(t.coefficients[F])?w:w+S*t.coefficients[F],0);return(fe(g,0)?le(b.map(w=>l[w]),b.map(w=>t.coefficients[w]),g):g)+q[f]})}let{m:u,s:m}=n.dispersion===void 0?{m:Q(t),s:0}:Z(n.dispersion,r),p=q=>E(q,r+m),c=t.rank,h=t.qr===void 0?[]:t.qr.pivot.slice(0,c),M=t.qr?.qr,v=a.map(q=>{let b=new Array(c).fill(0),l=0;for(let f=0;f<c;f++){let g=q[h[f]];for(let k=0;k<f;k++)g-=M[k][f]*b[k];b[f]=g/M[f][f],l+=b[f]*b[f]}if(!(l>=2**-1022&&l<1/0)){let f=b.reduce((g,k)=>Math.max(g,Math.abs(k)),0);if(f>0&&Number.isFinite(f)){let g=Math.sqrt(b.reduce((w,S)=>w+(S/f)**2,0)),k=f*g*Math.sqrt(u);return Number.isFinite(k)?k:f*(g*Math.sqrt(u))}}return Math.sqrt(l)*Math.sqrt(u)}),A=n.type??"link";if(A!=="link"&&A!=="response")throw new RangeError(`invalid 'type': ${String(A)}`);let y=n.newdata===void 0?[]:we(t.qr,c,a),x=y.length>0?{nonEstimable:y,warnings:[ge]}:{};return A==="link"?z("glmPredict",{fit:o.map(i),seFit:v.map(p),...x},e):z("glmPredict",$(new T,()=>({fit:o.map(q=>i(s.linkinv(q))),seFit:v.map((q,b)=>p(q*Math.abs(s.muEta(o[b])))),...x})),e)}export{Ne as a,ie as b,et as c,tt as d,Te as e,wt as f,Y as g,U as h,yt as i,Z as j,vt as k,bt as l,Ie as m,Nt as n,kt as o,Mt as p,xt as q};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{d as b}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.12.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{d as b}from"./chunk-HF3QOIZX.js";import{f as a,h as f,k as l,l as c,m as g,q as m}from"./chunk-ULQXNAI6.js";import{l as s}from"./chunk-52KGBGFL.js";var d=["location","scale","log"],x=["location","scale","lowerTail","logP"],M=["location","scale","lowerTail","logP"],p=2**-1022;function h(r,o,t,N){if(Number.isNaN(r)||Number.isNaN(o)||Number.isNaN(t))return NaN;if(!(t>0))return NaN;let e=f(r,o,t);if(Number.isNaN(e[0]))return NaN;let n=e[0]<0?[-e[0],-e[1]]:[e[0],e[1]],i=l(n);if(N)return-n[0]-n[1]-Math.log(t)-2*Math.log1p(i);if(i<p)return c(n,t);let u=t*(1+i)*(1+i);return t>=p&&u<1/0?i/u:i/((1+i)*(1+i))/t}function I(r,o,t,N,e){if(Number.isNaN(r)||Number.isNaN(o)||Number.isNaN(t))return NaN;if(!(t>0))return NaN;let n=f(r,o,t);if(Number.isNaN(n[0]))return NaN;let i=n[0]<0?[-n[0],-n[1]]:[n[0],n[1]],u=l(i);return N===n[0]>=0?e?-Math.log1p(u):1/(1+u):e?-i[0]-i[1]-Math.log1p(u):u/(1+u)}function S(r,o){return o?r-g(r):r<.25?Math.log(r/(1-r)):Math.log1p((2*r-1)/(1-r))}function O(r,o,t,N,e){if(Number.isNaN(r)||Number.isNaN(o)||Number.isNaN(t))return NaN;let n=b(r,-1/0,1/0,N,e);if(n!==void 0)return n;if(t<0)return NaN;if(t===0)return o;let i=S(r,e);return m(o,t,N?i:-i)}function w(r,o={}){s(o,d,"dlogis");let{location:t=0,scale:N=1,log:e=!1}=o;return a(r,n=>h(n,t,N,e))}function y(r,o={}){s(o,x,"plogis");let{location:t=0,scale:N=1,lowerTail:e=!0,logP:n=!1}=o;return a(r,i=>I(i,t,N,e,n))}function D(r,o={}){s(o,M,"qlogis");let{location:t=0,scale:N=1,lowerTail:e=!0,logP:n=!1}=o;return a(r,i=>O(i,t,N,e,n))}export{h as a,I as b,w as c,y as d,D as e};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{e as g}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.12.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{e as g}from"./chunk-SLMS3FQD.js";function b(o,f){let r=o[Symbol.iterator](),s=f[Symbol.iterator]();for(;;){let i=r.next(),t=s.next();if(i.done)return t.done?0:-1;if(t.done)return 1;let l=i.value.codePointAt(0)-t.value.codePointAt(0);if(l!==0)return l}}function y(o,f,r){if(f instanceof Float64Array&&r===void 0){let e=Array.from(f);return{v:{kind:"numeric",values:e},missing:e.map(n=>Number.isNaN(n))}}let s=Array.from(f),i=new Set(s.filter(e=>e!==null).map(e=>typeof e));if(i.size>1)throw new TypeError(`column '${o}' mixes ${[...i].join(" and ")} values`);let t=[...i][0]??"number";if(t!=="number"&&t!=="string"&&t!=="boolean")throw new TypeError(`column '${o}' has values of an unsupported type`);if(t==="number"&&r===void 0){let e=s.map(n=>n===null?NaN:n);return{v:{kind:"numeric",values:e},missing:e.map(n=>Number.isNaN(n))}}let l=e=>e===null||typeof e=="number"&&Number.isNaN(e)?null:typeof e=="boolean"?e?"TRUE":"FALSE":g(e),c=s.map(l),u;if(r!==void 0){u=Array.from(r,String);let e=u.findIndex((n,p)=>u.indexOf(n)!==p);if(e>=0)throw new RangeError(`factor level [${e+1}] is duplicated`)}else t==="boolean"?u=["FALSE","TRUE"]:u=[...new Set(c.filter(e=>e!==null))].sort(b);let a=new Map(u.map((e,n)=>[e,n])),m=c.map(e=>e===null?-1:a.get(e)??-1),d=r!==void 0?"given":t==="boolean"?"logical":"values";return{v:{kind:"factor",levels:u,codes:m},missing:m.map(e=>e<0),source:d}}function h(o,f){let r=o.map(()=>!1);for(let t of f)r[t]=!0;let s=new Map;return{levels:o.filter((t,l)=>(r[l]&&s.set(l,s.size),r[l])),codes:f.map(t=>s.get(t))}}function E(o){return h(o.levels,o.codes)}function N(o,f,r={}){if(typeof o!="object"||o===null)throw new TypeError("data must be an object of columns");let s=f.map(e=>{let n=Object.prototype.hasOwnProperty.call(o,e)?o[e]:void 0;if(n===void 0)throw new RangeError(`object '${e}' not found`);if(!Array.isArray(n)&&!(n instanceof Float64Array))throw new TypeError(`column '${e}' must be an array`);return n}),i;if(typeof r.weights=="string"){let e=Object.prototype.hasOwnProperty.call(o,r.weights)?o[r.weights]:void 0;if(e===void 0)throw new RangeError(`object '${r.weights}' not found`);i=e}else r.weights!==void 0&&(i=Array.from(r.weights));let t=s.length>0?s[0].length:i?.length??Object.values(o)[0]?.length??0;if(f.forEach((e,n)=>{if(s[n].length!==t)throw new RangeError(`variable lengths differ (found for '${e}')`)}),i!==void 0&&i.length!==t)throw new RangeError("variable lengths differ (found for '(weights)')");let{levels:l}=r,c=f.map((e,n)=>y(e,s[n],l!==void 0&&Object.hasOwn(l,e)?l[e]:void 0)),u;i!==void 0&&(u=Array.from(i,e=>{if(e===null)return NaN;if(typeof e!="number")throw new TypeError("the weights must be numeric");return e}));let a=[];for(let e=0;e<t;e++)c.some(n=>n.missing[e])||u!==void 0&&Number.isNaN(u[e])||a.push(e);let m=c.map(({v:e,source:n})=>{if(e.kind==="numeric")return{kind:"numeric",values:a.map(w=>e.values[w])};let p=a.map(w=>e.codes[w]);return n==="values"||n==="given"&&r.dropUnusedLevels?{kind:"factor",...h(e.levels,p)}:{kind:"factor",levels:e.levels,codes:p}}),d={rows:a,variables:m};if(u!==void 0&&(d.weights=a.map(e=>u[e]),d.weights.some(e=>e<0)))throw new RangeError("missing or negative weights not allowed");return d}export{b as a,E as b,N as c};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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 t,n as i}from"./chunk-NGDBJR3K.js";import{m as n}from"./chunk-ULQXNAI6.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 1.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as q}from"./chunk-CHKBDZC4.js";import{C as V,a as B,b as en,e as rn,f as on,g as sn,h as G,j as fn,k as U,l as cn,m as un,v as I}from"./chunk-NAACMR7H.js";import{g as tn,l as w}from"./chunk-52KGBGFL.js";var Rn=["by","byX","byY","all","allX","allY","sort","suffixes"],Mn=["select"],On=["columns"];function K(t){let r=Object.values(t),n=r[0]?.length??0;if(r.some(o=>o.length!==n))throw new RangeError("the columns of a data frame must have the same length");return n}var Y=t=>t==null||typeof t=="number"&&Number.isNaN(t),X=(t,r)=>t[r];function P(t,r){if(t.length>0&&t.every(n=>n instanceof Float64Array)){let n=new Float64Array(r.length);return r.forEach((o,e)=>n[e]=o===null?NaN:o[0][o[1]]),n}return r.map(n=>n===null?null:X(n[0],n[1]))}function dn(t,r){return t instanceof Float64Array?Float64Array.from(r,n=>t[n]):r.map(n=>X(t,n))}function $(t,r,n){if(Object.hasOwn(t,r))throw new RangeError(`duplicate column name '${r}'`);Object.defineProperty(t,r,{value:n,enumerable:!0,writable:!0,configurable:!0})}function An(t){if(Number.isNaN(t))return"NA";if(!Number.isFinite(t))return t>0?"Inf":"-Inf";if(t===0)return"0";let[r,n]=Number(t.toPrecision(15)).toExponential().split("e"),o=r.startsWith("-"),e=r.replace("-","").replace(".",""),s=Number(n),i=e.length,u=String(Math.abs(s)).padStart(2,"0"),c=i+(i>1?1:0)+2+u.length,a=s>=0?Math.max(s+1,i)+(i>s+1?1:0):2-s-1+i,y=o?"-":"";return a>c?`${y}${e[0]}${i>1?`.${e.slice(1)}`:""}e${s<0?"-":"+"}${u}`:s<0?`${y}0.${"0".repeat(-s-1)}${e}`:i<=s+1?`${y}${e}${"0".repeat(s+1-i)}`:`${y}${e.slice(0,s+1)}.${e.slice(s+1)}`}function C(t){return Y(t)?"NA":typeof t=="number"?An(t):typeof t=="boolean"?t?"TRUE":"FALSE":t}var an=Symbol("NA"),ln=t=>typeof t=="number"?0:typeof t=="string"?1:2;function _n(t,r){let n=Y(t),o=Y(r);if(n||o)return n===o?0:n?1:-1;let e=t,s=r;return typeof e!=typeof s?ln(e)-ln(s):typeof e=="string"?q(e,s):Number(e)-Number(s)}function Yn(t){let r=t.length,n=[...t],o=t.map((s,i)=>i),e=1;for(;e<=Math.trunc(r/9);)e=3*e+1;for(;e>0;e=Math.trunc(e/3))for(let s=e;s<r;s++){let i=n[s],u=o[s],c=s;for(;c>=e&&n[c-e]>i;)n[c]=n[c-e],o[c]=o[c-e],c-=e;n[c]=i,o[c]=u}return o}function mn(t){let r=[],n=new Map;for(let o of Yn(t)){let e=t[o];if(e===0)r.push(o);else{let s=n.get(e);s===void 0?n.set(e,[o]):s.push(o)}}return{alone:r,groups:n}}var z=t=>typeof t=="string"?[t]:[...t];function hn(t,r){return r.map(n=>{if(!Object.hasOwn(t,n))throw new RangeError("'by' must specify a uniquely valid column");return t[n]})}function Bn(t,r,n={}){w(n,Rn,"merge");let o=Object.keys(t),e=Object.keys(r),s=K(t),i=K(r),u=n.by===void 0?o.filter(f=>e.includes(f)):z(n.by),c=n.byX===void 0?u:z(n.byX),a=n.byY===void 0?u:z(n.byY),y=hn(t,c),M=hn(r,a);if(c.length!==a.length)throw new TypeError("'by.x' and 'by.y' specify different numbers of columns");let O=n.allX??n.all??!1,b=n.allY??n.all??!1,x=n.sort??!0,[h,g]=n.suffixes??[".x",".y"],S=o.filter(f=>!c.includes(f)),L=e.filter(f=>!a.includes(f)),xn=f=>L.includes(f)?f+h:f,En=f=>S.includes(f)||c.includes(f)?f+g:f,R=[];if(c.length===0)for(let f=0;f<i;f++)for(let l=0;l<s;l++)R.push([l,f]);else{let f=y.map((m,N)=>{let _=new Set([...m,...M[N]].filter(d=>!Y(d)).map(d=>typeof d));return _.has("string")?d=>typeof d=="string"?d:C(d):_.has("number")&&_.has("boolean")?d=>typeof d=="boolean"?Number(d):d:d=>d}),l=(m,N,_)=>{let d=X(m[N],_);return Y(d)?an:f[N](d)},p=c.length===1?(m,N)=>l(m,0,N):(m,N)=>JSON.stringify(m.map((_,d)=>{let v=l(m,d,N);return v===an?null:C(v)})),E=Array.from({length:s},(m,N)=>p(y,N)),A=Array.from({length:i},(m,N)=>p(M,N)),k=new Set(A),F=new Map,Q=0;for(let m of E)k.has(m)&&(Q++,F.has(m)||F.set(m,Q));let Z=mn(E.map(m=>F.get(m)??0)),nn=mn(A.map(m=>F.get(m)??0));for(let[m,N]of Z.groups){let _=nn.groups.get(m)??[];for(let d of N)for(let v of _)R.push([d,v])}if(O)for(let m of Z.alone)R.push([m,-1]);if(b)for(let m of nn.alone)R.push([-1,m])}let W=R.some(([f])=>f<0),Sn=R.some(([f])=>f>=0),H=y.map((f,l)=>{let p=M[l],A=P(Sn||!W?W?[f,p]:[f]:[p],R.map(([k,F])=>k>=0?[f,k]:[p,F]));return W?pn(A):A}),D=R.map((f,l)=>l);if(x&&c.length>0){let f=(l,p)=>X(H[p],l);if(c.length>1&&!O&&!b){let l=R.map((p,E)=>c.map((A,k)=>C(f(E,k))).join("\r"));D.sort((p,E)=>q(l[p],l[E]))}else D.sort((l,p)=>{for(let E=0;E<c.length;E++){let A=_n(f(l,E),f(p,E));if(A!==0)return A}return 0})}let J=D.map(f=>R[f]),T={};c.forEach((f,l)=>$(T,f,dn(H[l],D)));for(let f of S){let l=t[f];$(T,xn(f),P([l],J.map(([p])=>p>=0?[l,p]:null)))}for(let f of L){let l=r[f];$(T,En(f),P([l],J.map(([,p])=>p>=0?[l,p]:null)))}return T}function Gn(t,r,n={}){w(n,Mn,"subset");let o=Object.keys(t),e=K(t);if(typeof r!="function"&&r.length!==e)throw new RangeError(`'keep' has ${r.length} values for ${e} rows`);let s=a=>Object.fromEntries(o.map(y=>[y,X(t[y],a)])),i=[];for(let a=0;a<e;a++)(typeof r=="function"?r(s(a)):r[a])===!0&&i.push(a);let u=n.select??o,c={};for(let a of u){if(!Object.hasOwn(t,a))throw new RangeError("undefined columns selected");$(c,a,dn(t[a],i))}return c}function Un(t){if(t.length===0)return{};let r=Object.keys(t[0]);for(let o of t)if(K(o),Object.keys(o).length!==r.length||!r.every(s=>Object.hasOwn(o,s)))throw new TypeError("names do not match previous names");let n={};for(let o of r){let e=t.map(i=>i[o]),s=e.flatMap(i=>Array.from({length:i.length},(u,c)=>[i,c]));$(n,o,pn(P(e,s)))}return n}function pn(t){if(t instanceof Float64Array)return t;let r=new Set(t.filter(n=>!Y(n)).map(n=>typeof n));return r.size<2?t:r.has("string")?t.map(n=>Y(n)?null:typeof n=="string"?n:C(n)):t.map(n=>Y(n)?null:typeof n=="boolean"?n?1:0:n)}function Vn(t){let r={},n=t.map(K),o=n.find(e=>e!==n[0]);if(o!==void 0)throw new RangeError(`arguments imply differing number of rows: ${n[0]}, ${o}`);for(let e of t)for(let[s,i]of Object.entries(e))$(r,s,i instanceof Float64Array?Float64Array.from(i):[...i]);return r}function qn(t,r={}){w(r,On,"fromRows");let n=r.columns;if(n===void 0){let e=new Set;for(let s of t)for(let i of Object.keys(s))e.add(i);n=[...e]}let o={};for(let e of n){let s=new Set,i=t.map((u,c)=>{let a=Object.hasOwn(u,e)?u[e]:void 0;if(a==null)return null;if(typeof a!="number"&&typeof a!="string"&&typeof a!="boolean")throw new TypeError(`row ${c}, column '${e}': values must be numbers, strings, booleans or null`);return s.add(typeof a),a});if(s.size>1)throw new TypeError(`column '${e}' mixes ${[...s].join(" and ")} values`);$(o,e,i)}return o}function zn(t){let r=Object.keys(t),n=K(t);return Array.from({length:n},(o,e)=>Object.fromEntries(r.map(s=>[s,X(t[s],e)])))}var $n=["naRm"],jn=["naRm"],kn=["trim","naRm"],Fn=["naRm"],In=["naRm"],Kn=["naRm"],Xn=["naRm"],Dn=["naRm"],Tn=["lag","differences"];function j(t,r){let n=Array.from(t);return r?n.filter(o=>!Number.isNaN(o)):n.some(Number.isNaN)?void 0:n}function nt(t,r={}){w(r,$n,"sum");let n=j(t,r.naRm);return n===void 0?NaN:I(n)}function tt(t,r={}){w(r,jn,"prod");let n=j(t,r.naRm);if(n===void 0)return NaN;let o=gn();for(let e=0;e<n.length;e++){let s=n[e];if(!Number.isFinite(s)||s===0)return n.slice(e).reduce((i,u)=>i*u,bn(o));yn(o,s)}return Nn(o.p,o.e)}function gn(){return{p:[1,0],e:0}}function yn(t,r){let n=Math.floor(Math.log2(Math.abs(r)));(n>500||n<-500)&&(r=G(r,-n),t.e+=n);let o=tn(t.p,[r,0]);if(n=Math.floor(Math.log2(Math.abs(o[0]))),n>500||n<-500){let e=2**-n;o=[o[0]*e,o[1]*e],t.e+=n}t.p=o}function bn(t){return t.p[0]<0?-1:1}function et(t,r={}){w(r,kn,"mean");let n=j(t,r.naRm),o=r.trim??0;if(Number.isNaN(o)&&(n===void 0||n.length>0))throw new RangeError("'trim' must be numeric of length one");if(n===void 0)return NaN;let e=n.length;if(e===0)return NaN;if(o>0&&e>0){if(o>=.5)return Pn(n);o=Math.max(o,0);let s=Math.floor(e*o),i=[...n].sort((u,c)=>u-c);return U(i.slice(s,e-s))}return U(n)}function rt(t,r,n={}){w(n,Fn,"weightedMean");let o=Array.from(t),e=Array.from(r);if(o.length!==e.length)throw new RangeError("'x' and 'w' must have the same length");if(n.naRm){let h=o.map(g=>!Number.isNaN(g));o=o.filter((g,S)=>h[S]),e=e.filter((g,S)=>h[S])}let s=[],i=!1;for(let h=0;h<o.length;h++){if(e[h]===0)continue;let g=o[h]*e[h];o[h]!==0&&Math.abs(g)<2**-1022&&(i=!0),s.push(g)}let u=I(e),c=I(s)/u;if(Number.isFinite(c)&&Number.isFinite(u)&&!i||!o.every(Number.isFinite)||!e.every(Number.isFinite))return c;let a=vn(o,e);if(a!==void 0)return a;let y=o.filter((h,g)=>e[g]!==0),{groups:[M],k:O}=V([y]),{groups:[b]}=V([e]),x=[];for(let h=0,g=0;h<o.length;h++)e[h]!==0&&x.push(M[g++]*b[h]);return G(I(x)/I(b),O)}function vn(t,r){let n=[],o=[];for(let b=0;b<t.length;b++){if(r[b]===0)continue;let[x,h]=B(r[b]);if(o.push([x,h]),t[b]===0)continue;let[g,S]=B(t[b]);n.push([g*x,S+h])}let e=b=>{let x=0;for(let[,g]of b)x=Math.min(x,g);let h=0n;for(let[g,S]of b)h+=g<<BigInt(S-x);return[h,x]},[s,i]=e(n),[u,c]=e(o);if(u===0n)return;if(s===0n)return 0;u<0n&&(s=-s,u=-u);let a=s<0n,y=a?-s:s,M=Math.max(0,u.toString(2).length-y.toString(2).length+66),O=(y<<BigInt(M))/u;return O*u!==y<<BigInt(M)&&(O|=1n),en(a?-O:O,i-c-M)}function ot(t,r={}){w(r,In,"variance");let n=j(t,r.naRm);return n===void 0?NaN:cn(n)}function st(t,r={}){w(r,Kn,"sd");let n=j(t,r.naRm);return n===void 0?NaN:un(n)}function Pn(t,r={}){w(r,Xn,"median");let n=j(t,r.naRm);if(n===void 0)return NaN;let o=n.length;if(o===0)return NaN;let e=[...n].sort((i,u)=>i-u),s=Math.floor(o/2);return o%2===1?e[s]:fn([e[s-1],e[s]])[0]}function it(t,r={}){w(r,Dn,"range");let n=j(t,r.naRm);if(n===void 0)return[NaN,NaN];let o=1/0,e=-1/0;for(let s of n)s<o&&(o=s),s>e&&(e=s);return[o,e]}function ft(t){let r=Array.from(t),n=[],o=rn(),e;for(let s of r){if(e===void 0&&!Number.isFinite(s)&&(e=0),e!==void 0){e+=s,n.push(e);continue}on(o,s,r.length),n.push(sn(o))}return n}function ct(t){let r=[],n=gn(),o;for(let e of Array.from(t)){if(o===void 0&&(!Number.isFinite(e)||e===0)&&(o=bn(n)),o!==void 0){o*=e,r.push(o);continue}yn(n,e),r.push(Nn(n.p,n.e))}return r}function Nn(t,r){let n=t[0]+t[1];for(;r>0&&Number.isFinite(n);){let o=Math.min(r,1e3);n*=2**o,r-=o}for(;r<0&&n!==0;){let o=Math.max(r,-1e3);n*=2**o,r-=o}return n}function wn(t,r){let n=[],o=NaN,e=!1;for(let s of Array.from(t)){if(e||Number.isNaN(s)){e=!0,n.push(NaN);continue}(n.length===0||r(s,o))&&(o=s),n.push(o)}return n}function ut(t){return wn(t,(r,n)=>r>n)}function at(t){return wn(t,(r,n)=>r<n)}function lt(t,r={}){w(r,Tn,"diff");let n=r.lag??1,o=r.differences??1;if(!(Number.isInteger(n)&&n>=1&&Number.isInteger(o)&&o>=1))throw new RangeError("'lag' and 'differences' must be integers >= 1");let e=Array.from(t);if(n*o>=e.length)return[];for(let s=0;s<o;s++){let i=[];for(let u=n;u<e.length;u++)i.push(e[u]-e[u-n]);e=i}return e}export{K as a,Y as b,dn as c,$ as d,_n as e,Bn as f,Gn as g,Un as h,Vn as i,qn as j,zn as k,j as l,nt as m,tt as n,et as o,rt as p,ot as q,st as r,Pn as s,it as t,ft as u,ct as v,ut as w,at as x,lt as y};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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{l as R}from"./chunk-52KGBGFL.js";var A=23283064365386963e-26,p=2328306437080797e-25,c=class{mt=new Uint32Array(624);mti=625;setSeed(t){let e=t>>>0;for(let n=0;n<50;n++)e=Math.imul(69069,e)+1>>>0;e=Math.imul(69069,e)+1>>>0;for(let n=0;n<624;n++)e=Math.imul(69069,e)+1>>>0,this.mt[n]=e;this.mti=624}sgenrand(t){for(let e=0;e<624;e++)this.mt[e]=t&4294901760,t=Math.imul(69069,t)+1>>>0,this.mt[e]=(this.mt[e]|(t&4294901760)>>>16)>>>0,t=Math.imul(69069,t)+1>>>0;this.mti=624}nextUint32(){let t=this.mt;if(this.mti>=624||this.mti===0){this.mti===625&&this.sgenrand(4357);let n=0,o;for(;n<227;n++)o=t[n]&2147483648|t[n+1]&2147483647,t[n]=t[n+397]^o>>>1^(o&1?2567483615:0);for(;n<623;n++)o=t[n]&2147483648|t[n+1]&2147483647,t[n]=t[n+-227]^o>>>1^(o&1?2567483615:0);o=t[623]&2147483648|t[0]&2147483647,t[623]=t[396]^o>>>1^(o&1?2567483615:0),this.mti=0}let e=t[this.mti++];return e^=e>>>11,e^=e<<7&2636928640,e^=e<<15&4022730752,e^=e>>>18,e>>>0}nextDouble(){let t=this.nextUint32()*A;return t<=0?.5*p:1-t<=0?1-.5*p:t}getRandomSeed(t){let e=new Int32Array(626);e[0]=t,e[1]=this.mti;for(let n=0;n<624;n++)e[n+2]=this.mt[n]|0;return e}setRandomSeed(t){if(t.length!==626)throw new RangeError("the random seed state must have 626 integers");let e=t[1];if(!Number.isInteger(e)||e<0||e>2**31-1)throw new RangeError("the position in the random seed state must be a non-negative 32-bit integer");for(let n=0;n<624;n++){let o=t[n+2];if(!Number.isInteger(o)||o<-(2**31)||o>=2**32)throw new RangeError("the random seed state must hold 32-bit integers")}this.mti=e;for(let n=0;n<624;n++)this.mt[n]=t[n+2]>>>0}};var k=2328306549295728e-25,g=r=>Math.imul(69069,r)+1>>>0,l=class{s=new Float64Array(6);setSeed(t){let e=t>>>0;for(let n=0;n<50;n++)e=g(e);for(let n=0;n<6;n++){do e=g(e);while(e>=4294944443);this.s[n]=e}}nextDouble(){let t=this.s,e=(1403580*t[1]-810728*t[0])%4294967087;e<0&&(e+=4294967087),t[0]=t[1],t[1]=t[2],t[2]=e;let n=(527612*t[5]-1370589*t[3])%4294944443;return n<0&&(n+=4294944443),t[3]=t[4],t[4]=t[5],t[5]=n,(e>n?e-n:e-n+4294967087)*k}};function w(r){if(r.length!==7)throw new RangeError("the random seed state of L'Ecuyer-CMRG must have 7 integers");let t=[];for(let e=1;e<=6;e++){let n=r[e];if(!Number.isInteger(n)||n<-2147483648||n>4294967295)throw new RangeError("the random seed state must hold 32-bit integers");t.push(n>>>0)}if(t[0]===0&&t[1]===0&&t[2]===0||t.slice(0,3).some(e=>e>=4294967087)||t.slice(3).some(e=>e>=4294944443))throw new RangeError("invalid L'Ecuyer-CMRG state: the first three seeds must be below 4294967087 and not all zero, the last three below 4294944443");return t}var I=[3.3871328727963665,133.14166789178438,1971.5909503065513,13731.69376550946,45921.95393154987,67265.7709270087,33430.57558358813,2509.0809287301227],y=[1,42.31333070160091,687.1870074920579,5394.196021424751,21213.794301586597,39307.89580009271,28729.085735721943,5226.495278852854],K=[1.4234371107496835,4.630337846156546,5.769497221460691,3.6478483247632045,1.2704582524523684,.2417807251774506,.022723844989269184,.0007745450142783414],_=[1,2.053191626637759,1.6763848301838038,.6897673349851,.14810397642748008,.015198666563616457,.0005475938084995345,10507500716444169e-25],v=[6.657904643501103,5.463784911164114,1.7848265399172913,.29656057182850487,.026532189526576124,.0012426609473880784,27115555687434876e-21,20103343992922881e-23],L=[1,.599832206555888,.1369298809227358,.014875361290850615,.0007868691311456133,18463183175100548e-21,1421511758316446e-22,20442631033899397e-31];function f(r,t){let e=r[7];for(let n=6;n>=0;n--)e=e*t+r[n];return e}function N(r){let t=r-.5;if(Math.abs(t)<=.425){let o=.180625-t*t;return t*f(I,o)/f(y,o)}let e=t<0?r:1-r;e=Math.sqrt(-Math.log(e));let n;return e<=5?(e-=1.6,n=f(K,e)/f(_,e)):(e-=5,n=f(v,e)/f(L,e)),t<0?-n:n}var G=["kind","sampleKind"],u=new c,i=u,a=!1,h=!1;function m(r){i.setSeed(r),h=!0}function q(){return h}function M(){if(h)return;let r=(Date.now()^Math.floor(Math.random()*2**32))>>>0;typeof globalThis.crypto?.getRandomValues=="function"&&(r=globalThis.crypto.getRandomValues(new Uint32Array(1))[0]),m(r)}function F(r){if(!Number.isFinite(r))throw new RangeError("seed must be a finite number");let t=Math.trunc(r);if(Math.abs(t)>2147483647)throw new RangeError("seed must be a 32-bit integer");m(t)}var P={default:!1,"Mersenne-Twister":!1,"L'Ecuyer-CMRG":!0},T={default:!1,Rejection:!1,Rounding:!0};function x(r,t,e){if(t===void 0)return;let n=r[t];if(typeof n!="boolean")throw new RangeError(`unsupported ${e} "${t}"`);return n}function B(r={}){R(r,G,"RNGkind");let t={kind:i===u?"Mersenne-Twister":"L'Ecuyer-CMRG",normalKind:"Inversion",sampleKind:a?"Rounding":"Rejection"},e=x(P,r.kind,"RNG kind"),n=x(T,r.sampleKind,"sample kind");if((e!==void 0||n!==void 0)&&M(),e!==void 0){let o=Math.trunc(s()*4294967295);i=e?i===u?new l:i:u,m(o)}return n!==void 0&&(a=n),t}var S=()=>(i===u?3:7)+400+(a?0:1e4);function V(){return M(),i===u?u.getRandomSeed(S()):Int32Array.of(S(),...i.s)}function z(r){let t=r[0],e=t%100;if(!Number.isInteger(t)||t<0||t>10407||e!==3&&e!==7||Math.floor(t/100)%100!==4)throw new RangeError(`unsupported RNG kind code ${String(t)} (supported: 10403, 403, 10407, 407)`);if(e===7){let n=new l;n.s.set(w(r)),i=n}else u.setRandomSeed(r),i=u;a=t<1e4,h=!0}function s(){return M(),i.nextDouble()}var Q=()=>a;function U(r){let t=2**Math.max(r-16,0),e=0;for(let n=0;n<=r;n+=16){let o=Math.floor(s()*65536);e=65536*(e%t)+o}return e%2**r}var b=33554432;function Y(r){if(a)return Math.floor(r*(r>2147483647?(Math.floor(b*s())+s())/b:s()));if(r<=0)return 0;let t=Math.ceil(Math.log2(r)),e;do e=U(t);while(r<=e);return e}var E=134217728;function H(){let r=s();return r=Math.trunc(E*r)+s(),N(r/E)}var d=(()=>{let r=[],t=1,e=0;for(let n=1;n<=16;n++)t*=Math.LN2/n,e+=t,r.push(e);return r})();function J(){let r=0,t=s();for(;t<=0||t>=1;)t=s();for(;t+=t,!(t>1);)r+=d[0];if(t-=1,t<=d[0])return r+t;let e=0,n=s(),o=n;do n=s(),o>n&&(o=n),e++;while(t>d[e]);return r+o*d[0]}export{w as a,q as b,F as c,B as d,V as e,z as f,s as g,Q as h,Y as i,H as j,J as k};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 1.12.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 s,b}from"./chunk-NGDBJR3K.js";import{a as h}from"./chunk-ULQXNAI6.js";import{l as M}from"./chunk-52KGBGFL.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};
|