@numero-uno-jpn/rstats 0.8.0 → 0.10.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 +88 -0
- package/README.ja.md +89 -13
- package/README.md +90 -13
- package/THIRD_PARTY_NOTICES.md +12 -2
- package/dist/chunks/{chunk-OHPHNE3O.js → chunk-2XKG3DX4.js} +1 -1
- package/dist/chunks/{chunk-3I6EKGB6.js → chunk-4NM37MGA.js} +2 -2
- package/dist/chunks/chunk-7HPVUVZB.js +2 -0
- package/dist/chunks/{chunk-I3LAZE6C.js → chunk-AECGWZHD.js} +2 -2
- package/dist/chunks/chunk-ENL43FNO.js +2 -0
- package/dist/chunks/chunk-EWC6I75B.js +2 -0
- package/dist/chunks/chunk-IT354SHV.js +3 -0
- package/dist/chunks/{chunk-VIPSPG3Y.js → chunk-LIMZKONM.js} +2 -2
- package/dist/chunks/chunk-O6PT7IVU.js +2 -0
- package/dist/chunks/{chunk-YGWPU67I.js → chunk-QFULZNHL.js} +1 -1
- package/dist/chunks/{chunk-XU4BGFZ6.js → chunk-QJJWGNJP.js} +2 -2
- package/dist/chunks/{chunk-32PRRONF.js → chunk-QULPY6YM.js} +1 -1
- package/dist/chunks/chunk-XWTZ4RTR.js +2 -0
- package/dist/chunks/chunk-ZRIM4R4A.js +2 -0
- package/dist/descriptive/factanal.d.ts +56 -0
- package/dist/descriptive/factanal.js +186 -0
- package/dist/descriptive/omega.d.ts +56 -0
- package/dist/descriptive/omega.js +323 -0
- package/dist/descriptive.js +2 -2
- package/dist/distributions/bvnorm.d.ts +15 -0
- package/dist/distributions/bvnorm.js +131 -0
- package/dist/distributions/nbeta.js +34 -1
- package/dist/distributions/nchisq.d.ts +10 -0
- package/dist/distributions/nchisq.js +46 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/distributions.d.ts +1 -0
- package/dist/entries/distributions.js +1 -0
- package/dist/entries/linalg.d.ts +2 -0
- package/dist/entries/linalg.js +2 -0
- package/dist/entries/numerics.d.ts +2 -0
- package/dist/entries/numerics.js +1 -0
- package/dist/entries/tests.d.ts +25 -1
- package/dist/entries/tests.js +22 -1
- package/dist/htest/agreement.d.ts +141 -0
- package/dist/htest/agreement.js +274 -0
- package/dist/htest/aov.d.ts +19 -0
- package/dist/htest/aov.js +22 -15
- package/dist/htest/core/simulate.d.ts +2 -0
- package/dist/htest/core/simulate.js +1 -1
- package/dist/htest/dunnett.d.ts +5 -0
- package/dist/htest/dunnett.js +89 -0
- package/dist/htest/effectSize.d.ts +112 -0
- package/dist/htest/effectSize.js +385 -0
- package/dist/htest/leveneTest.d.ts +30 -0
- package/dist/htest/leveneTest.js +41 -0
- package/dist/htest/multipleComparisons.d.ts +147 -0
- package/dist/htest/multipleComparisons.js +369 -0
- package/dist/htest/normalityTests.d.ts +44 -0
- package/dist/htest/normalityTests.js +164 -0
- package/dist/htest/polycor.d.ts +117 -0
- package/dist/htest/polycor.js +468 -0
- package/dist/htest/power.d.ts +132 -0
- package/dist/htest/power.js +227 -0
- package/dist/htest/pwr.d.ts +263 -0
- package/dist/htest/pwr.js +440 -0
- package/dist/htest/rankTests.d.ts +7 -0
- package/dist/htest/rankTests.js +11 -1
- package/dist/htest/trendTests.d.ts +57 -0
- package/dist/htest/trendTests.js +167 -0
- package/dist/linalg/eigen.d.ts +8 -0
- package/dist/linalg/eigen.js +5 -4
- package/dist/linalg/expm.d.ts +48 -0
- package/dist/linalg/expm.js +472 -0
- package/dist/linalg/schur.d.ts +48 -0
- package/dist/linalg/schur.js +225 -0
- package/dist/linalg.js +2 -2
- package/dist/models/anovaSequential.d.ts +58 -0
- package/dist/models/anovaSequential.js +138 -0
- package/dist/models/aovEz.d.ts +64 -0
- package/dist/models/aovEz.js +332 -0
- package/dist/models/aovStrata.d.ts +32 -0
- package/dist/models/aovStrata.js +104 -0
- package/dist/models/carAnova.d.ts +30 -0
- package/dist/models/carAnova.js +121 -0
- package/dist/models/coxph.d.ts +101 -0
- package/dist/models/coxph.js +502 -0
- package/dist/models/ddLeastSquares.d.ts +30 -0
- package/dist/models/ddLeastSquares.js +90 -0
- package/dist/models/ddMatrix.d.ts +10 -0
- package/dist/models/ddMatrix.js +91 -0
- package/dist/models/formula.d.ts +83 -0
- package/dist/models/formula.js +333 -0
- package/dist/models/glm.d.ts +226 -0
- package/dist/models/glm.js +546 -0
- package/dist/models/glmAnova.d.ts +31 -0
- package/dist/models/glmAnova.js +146 -0
- package/dist/models/glmConfint.d.ts +25 -0
- package/dist/models/glmConfint.js +139 -0
- package/dist/models/glmFamily.d.ts +66 -0
- package/dist/models/glmFamily.js +359 -0
- package/dist/models/lm.d.ts +84 -3
- package/dist/models/lm.js +141 -44
- package/dist/models/mauchly.d.ts +48 -0
- package/dist/models/mauchly.js +123 -0
- package/dist/models/modelFrame.d.ts +40 -0
- package/dist/models/modelFrame.js +131 -0
- package/dist/models/modelMatrix.d.ts +88 -0
- package/dist/models/modelMatrix.js +170 -0
- package/dist/models/survival.d.ts +87 -0
- package/dist/models/survival.js +238 -0
- package/dist/numerics.js +2 -2
- package/dist/optim/lbfgsb.d.ts +20 -0
- package/dist/optim/lbfgsb.js +1240 -0
- package/dist/optim/optim.d.ts +85 -0
- package/dist/optim/optim.js +610 -0
- package/dist/rstats.js +19 -3
- package/dist/special.js +2 -2
- package/dist/tests.js +18 -3
- package/llms.txt +102 -0
- package/package.json +3 -2
- package/dist/chunks/chunk-EJRCDJ76.js +0 -2
- package/dist/chunks/chunk-JERGQKZM.js +0 -2
- package/dist/chunks/chunk-JVYV4633.js +0 -2
- package/dist/chunks/chunk-LXMMKO26.js +0 -2
- package/dist/chunks/chunk-MJQLKEO5.js +0 -2
- package/dist/chunks/chunk-RZ7SBJEG.js +0 -2
- package/dist/chunks/chunk-SPQC445Q.js +0 -2
- package/dist/chunks/chunk-U633VFH3.js +0 -2
package/llms.txt
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# rStats.js
|
|
2
|
+
|
|
3
|
+
> R-compatible statistics for JavaScript and TypeScript: distributions, random numbers that match
|
|
4
|
+
> R's `set.seed()`, descriptive statistics, hypothesis tests, `lm` and `glm`, special functions,
|
|
5
|
+
> numerical methods and linear algebra, with R's function names, defaults and numerical results.
|
|
6
|
+
> Every function is tested against R 4.5.2. ESM only, no dependencies, runs in browsers, Node.js,
|
|
7
|
+
> Deno and Bun.
|
|
8
|
+
|
|
9
|
+
Install with `npm install @numero-uno-jpn/rstats`. All functions are named exports:
|
|
10
|
+
`import { pnorm, tTest } from "@numero-uno-jpn/rstats"`, or `import * as rs from
|
|
11
|
+
"@numero-uno-jpn/rstats"` and call `rs.tTest(x, y)`. Each area is also a subpath export
|
|
12
|
+
(`/distributions`, `/tests`, `/linalg`, `/descriptive`, `/numerics`, `/special`). For use from a
|
|
13
|
+
CDN without a bundler, see the README section "Using it in the browser".
|
|
14
|
+
|
|
15
|
+
## Translating R code
|
|
16
|
+
|
|
17
|
+
- Function names are R's names. A dot in R's name becomes camelCase: `t.test` → `tTest`,
|
|
18
|
+
`chisq.test` → `chisqTest`, `p.adjust` → `pAdjust`, `set.seed` → `setSeed`,
|
|
19
|
+
`sample.int` → `sampleInt`, `weighted.mean` → `weightedMean`, `pairwise.t.test` →
|
|
20
|
+
`pairwiseTTest`. Methods of `glm` carry a prefix: `summary(fit)` → `glmSummary(fit)`,
|
|
21
|
+
`predict` → `glmPredict`, `confint` → `glmConfint`, `anova` → `glmAnova`, `residuals` →
|
|
22
|
+
`glmResiduals`. Other renamed functions: `var` → `variance`, `%*%` → `matMul`,
|
|
23
|
+
`.Random.seed` → `getRandomSeed()` / `setRandomSeed(seed)`, `qr.Q` → `qrQ` (likewise `qrR`,
|
|
24
|
+
`qrCoef`, `qrResid`, ...). Functions from other packages keep their own names (`zTest` from
|
|
25
|
+
BSDA, `brunnerMunzelTest` from lawstat, `ginv` from MASS, `grad` and `hessian` from numDeriv).
|
|
26
|
+
- Required arguments are positional; optional ones go in one options object with camelCase keys:
|
|
27
|
+
`pt(q, df, lower.tail = FALSE, log.p = TRUE)` → `pt(q, df, { lowerTail: false, logP: true })`,
|
|
28
|
+
`t.test(x, y, var.equal = TRUE, conf.level = 0.99)` →
|
|
29
|
+
`tTest(x, y, { varEqual: true, confLevel: 0.99 })`. When an optional second sample is
|
|
30
|
+
omitted, the options take its place: `tTest(x, { mu: 1 })`.
|
|
31
|
+
- Option values are R's strings: `alternative: "less"` (unambiguous abbreviations such as `"l"`
|
|
32
|
+
are accepted, as with R's `match.arg`), `method: "kendall"`, `family: "binomial"`.
|
|
33
|
+
- Results are plain objects with camelCase fields. Hypothesis tests return R's `htest` fields:
|
|
34
|
+
`statistic`, `parameter`, `pValue` (R's `p.value`), `confInt` (`conf.int`) with `confLevel`,
|
|
35
|
+
`estimate`, `nullValue`, `method`, `alternative`. R's names of these values are separate
|
|
36
|
+
fields: `statisticName`, `parameterName`, `estimateNames`, `nullValueName`.
|
|
37
|
+
- Data shapes: a sample is an array of numbers or a `Float64Array`. A matrix or contingency table
|
|
38
|
+
is an array of rows. Grouped data is either an array of samples (`kruskalTest([a, b, c])`) or
|
|
39
|
+
values with a parallel array of group labels (`kruskalTest(x, g)`). The first argument of the
|
|
40
|
+
d/p/q functions may be a number or an array (the result has the same shape); distribution
|
|
41
|
+
parameters are scalars and are not recycled as vectors.
|
|
42
|
+
- Models: `lm` and `aov` take an R formula string and a data frame given as an object of columns:
|
|
43
|
+
`lm("y ~ A * B + x", { y, A, B, x })`, `aov("y ~ W + Error(id/W)", data)`; string columns are
|
|
44
|
+
factors (levels sorted by code point unless `levels: { A: [...] }`), `contrasts: { A: "contr.sum" }`
|
|
45
|
+
sets the coding. Formula functions such as `log(x)` or `I(x^2)` are not supported: compute the
|
|
46
|
+
column first. Tables (`anova(fit)`, `Anova(fit, { type: 3 })` for car's `Anova`, `aovSummary(fit)`)
|
|
47
|
+
are `{ colNames, rowNames, table }` with R's names. afex's `aov_ez(id, dv, data, between, within)`
|
|
48
|
+
is `aovEz(data, { id, dv, between, within })`. `lm(x, y)` also takes a matrix, and `glm(x, y, {
|
|
49
|
+
family })` takes a matrix (array of rows) or a vector of predictors (no formula); the intercept
|
|
50
|
+
is added unless `intercept: false`. A binomial response can be rows of `[successes, failures]`,
|
|
51
|
+
like `cbind(s, f)` in R.
|
|
52
|
+
- Indices are 0-based where R returns indices: `sampleInt(n)` returns `0..n-1` (R's
|
|
53
|
+
`sample.int(n) - 1` from the same random stream), and the pivots of `qr` and `chol`.
|
|
54
|
+
- Hypothesis tests do not emit R's warnings. `glm` returns R's warnings in its result
|
|
55
|
+
(`warnings`).
|
|
56
|
+
- Power calculations take one options object and solve for the quantity given as `null`:
|
|
57
|
+
`power.t.test(delta = 0.5, power = 0.8)` → `powerTTest({ delta: 0.5, power: 0.8 })`, pwr's
|
|
58
|
+
`pwr.anova.test(k = 3, f = 0.25, power = 0.8)` → `pwrAnovaTest({ k: 3, f: 0.25, power: 0.8 })`
|
|
59
|
+
(`sig.level` → `sigLevel`). effectsize's `cohens_d(x, y)` → `cohensD(x, y)` (`{ name, value, ciLow, ciHigh }`),
|
|
60
|
+
`eta_squared(model)` → `etaSquared(anova(fit))` or `etaSquared(Anova(fit, { type: 3 }))`.
|
|
61
|
+
- Cox regression takes the covariates as a matrix (array of rows): `coxph(Surv(time, status) ~ x1 + x2, ties =
|
|
62
|
+
"breslow", weights = w)` → `coxph(time, status, x, { ties: "breslow", weights: w })`, with `strata` as labels.
|
|
63
|
+
psych's `omega(m, nfactors = 3)` → `omega(x, { nfactors: 3 })` (`omega(null, { covmat: R })` for a correlation
|
|
64
|
+
matrix).
|
|
65
|
+
- Random numbers: after `setSeed(42)`, `rnorm`, `runif`, `sample` and the other `r*` functions
|
|
66
|
+
give the same numbers as R after `set.seed(42)`. `RNGkind` supports Mersenne-Twister (R's
|
|
67
|
+
default) and L'Ecuyer-CMRG.
|
|
68
|
+
|
|
69
|
+
## Examples
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { pnorm, pt, setSeed, rnorm, tTest, glm, glmSummary } from "@numero-uno-jpn/rstats";
|
|
73
|
+
|
|
74
|
+
pnorm(1.96); // 0.9750021048517795
|
|
75
|
+
pt(2, 10, { lowerTail: false, logP: true }); // -3.3051415512324533
|
|
76
|
+
|
|
77
|
+
setSeed(42);
|
|
78
|
+
rnorm(3); // [1.3709584471466685, -0.5646981713960887, 0.3631284113373392], as in R
|
|
79
|
+
|
|
80
|
+
const r = tTest([5.1, 4.9, 6.2, 5.8, 6.0, 5.5], [4.1, 4.5, 5.0, 4.8, 4.3]);
|
|
81
|
+
r.pValue; // 0.0035365308877675647 (Welch, R's default)
|
|
82
|
+
r.confInt; // [0.4423253334608047, 1.6443413332058612]
|
|
83
|
+
|
|
84
|
+
// R: glm(cbind(s, f) ~ dose, family = binomial)
|
|
85
|
+
const fit = glm([1, 2, 3, 4, 5, 6], [[1, 19], [4, 16], [9, 11], [13, 7], [18, 2], [19, 1]], { family: "binomial" });
|
|
86
|
+
fit.coefficients; // ≈ [-3.77413, 1.14807]
|
|
87
|
+
glmSummary(fit).pValue; // ≈ [5.357e-8, 3.579e-9]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Docs
|
|
91
|
+
|
|
92
|
+
- [README](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/README.md): install, examples, the full list of functions by area
|
|
93
|
+
- [Differences from R](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/docs/differences-from-r.md): every known difference from R, function by function
|
|
94
|
+
- [Accuracy](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/docs/accuracy.md): how results are checked against R and high-precision references
|
|
95
|
+
- [Migrating from jStat](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/docs/migrating-from-jstat.md): the replacement for every jStat function
|
|
96
|
+
|
|
97
|
+
## Optional
|
|
98
|
+
|
|
99
|
+
- [Performance](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/docs/performance.md): speed and bundle sizes
|
|
100
|
+
- [Roadmap](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/ROADMAP.md): what is planned
|
|
101
|
+
- [Changelog](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/CHANGELOG.md)
|
|
102
|
+
- [Demo](https://numero-uno-jpn.github.io/rStats.js/demo/): every function in the browser, compared with R
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@numero-uno-jpn/rstats",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "R-compatible statistical functions for the browser: distributions, random numbers that match set.seed(), hypothesis tests and linear algebra, tested against R.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"statistics",
|
|
@@ -60,7 +60,8 @@
|
|
|
60
60
|
"files": [
|
|
61
61
|
"dist",
|
|
62
62
|
"THIRD_PARTY_NOTICES.md",
|
|
63
|
-
"CHANGELOG.md"
|
|
63
|
+
"CHANGELOG.md",
|
|
64
|
+
"llms.txt"
|
|
64
65
|
],
|
|
65
66
|
"scripts": {
|
|
66
67
|
"build": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json && node scripts/bundle.mjs",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.8.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 N,b as M,c as x,d as f,f as h,g as a,h as b}from"./chunk-OHPHNE3O.js";var l=[.6931471805599453,23190468138462996e-33];function E(t){let r=t[0];if(!N())return[Math.exp(r),0];if(Number.isNaN(r))return[NaN,0];if(r>709.8)return[1/0,0];if(r<-708)return[Math.exp(r)*(1+t[1]),0];let e=Math.round(r/l[0]),n=h(t,b(l,e)),i=1024;n=[n[0]/i,n[1]/i];let u=n,o=n;for(let s=2;s<20&&(u=a(u,n),u=[u[0]/s,u[1]/s],o=f(o,u),!(Math.abs(u[0])<1e-36));s++);for(let s=0;s<10;s++)o=a(o,f(o,[2,0]));let p=f(o,[1,0]),c=Math.trunc(e/2),d=2**c,m=2**(e-c);return[p[0]*d*m,p[1]*d*m]}function L(t,r,e){let n=t-r;if(!Number.isFinite(n))return[n/e,0];let i=r===0?[t,0]:M(t,-r);if(e===1)return i;let u=i[0]/e;if(!Number.isFinite(u)||u===0)return[u,0];let o=h(i,g(e,u)),p=(o[0]+o[1])/e;return M(u,p)}function g(t,r){let e=t*r;return!Number.isFinite(e)||Math.abs(t)>1e300||Math.abs(r)>1e300?[e,0]:x(t,r)}function D(t){return t[0]>708?Math.exp(700-t[0])*(1-t[1])*Math.exp(-700):Math.exp(-t[0])*(1-t[1])}function S(t){return t>-Math.LN2?Math.log(-Math.expm1(t)):Math.log1p(-Math.exp(t))}function k(t){return t[0]>Math.LN2?Math.log1p(-D(t)):Math.log(-Math.expm1(-(t[0]+t[1])))}function q(t,r,e){let n=g(r,e);if(!Number.isFinite(n[0])||!Number.isFinite(t))return t+n[0];let i=f(n,[t,0]);return i[0]+i[1]}export{E as a,L as b,g as c,D as d,S as e,k as f,q as g};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.8.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 v,b as I,c as x,d as L,e as q,f as U,g as Q,h as qt,i as Yn,j as Bt,u as J,v as Tn,w as bt}from"./chunk-LXMMKO26.js";import{a as H,b as D,c as gt}from"./chunk-MJQLKEO5.js";import{A as j,D as P,E as Zn,a as kt,e as b,g as pt,h as S,j as nn,l as Xn,n as Y,o as Rt,p as Ct,q as St,s as T,t as at,u as C,z as $n}from"./chunk-3I6EKGB6.js";import{b as w,c as $,d as F,e as ft,f as Vn,g as R,h as tn,i as _,j as dt,k as O}from"./chunk-OHPHNE3O.js";function be(n,t){let r=[.213623493715853,4.28342155967104,11.6616720288968,3.31125922108741],e=[.03611708101884203,1.27364489782223,6.40691597760039,6.61053765625462,1],i=n<.5?Math.sqrt(-2*Math.log(n)):Math.sqrt(-2*Math.log(t)),o=i-kt(i,r)/kt(i,e);return n<.5?-o:o}function ye(n,t,r,e){let i=1;if(r>=1){let o=t/(n+1);i+=o;for(let u=2;u<=r&&(o*=t/(n+u),i+=o,!(o<e));++u);}return i}function Pn(n,t){let r=(n-1)*Math.log(t),e=r*r,i=e*r,o=e*e,u=n*n,s=u*n,a=(n-1)*(1+r),c=(n-1)*(-(e/2)+(n-2)*r+(3*n-5)/2),f=(n-1)*(i/3-(3*n-5)*e/2+(u-6*n+7)*r+(11*u-46*n+47)/6),l=(n-1)*(-(o/4)+(11*n-17)*i/6+(-3*u+13*n-13)*e+(2*s-25*u+72*n-61)*r/2+(25*s-195*u+477*n-379)/12),N=t*t,h=N*t,m=N*N;return t+r+a/t+c/N+f/h+l/m}function rn(n,t,r){if(n===1)return r>.9?-Math.log1p(-t):-Math.log(r);if(n<1){let M=Xn(n),p=r*M;if(p>.6||p>=.45&&n>=.3){let d=p*r>1e-8&&r>1e-5?Math.pow(t*M*n,1/n):Math.exp(-r/n-nn);return d/(1-d/(n+1))}if(n<.3&&p>=.35){let d=Math.exp(-nn-p),y=d*Math.exp(d);return d*Math.exp(y)}if(p>.15||n>=.3){let d=-Math.log(p),y=d-(1-n)*Math.log(d);return d-(1-n)*Math.log(y)-Math.log(1+(1-n)/(1+y))}if(p>.1){let d=-Math.log(p),y=d-(1-n)*Math.log(d);return d-(1-n)*Math.log(y)-Math.log((y*y+2*(3-n)*y+(2-n)*(3-n))/(y*y+(5-n)*y+2))}return Pn(n,-Math.log(p))}let e=be(t,r),i=e*e,o=i*e,u=i*i,s=u*e,a=Math.sqrt(n),c=n+e*a+(i-1)/3;if(c+=(o-7*e)/(36*a),c-=(3*u+7*i-16)/(810*n),c+=(9*s+256*o-433*e)/(38880*n*a),n>=500&&Math.abs(1-c/n)<1e-6)return c;if(t>.5){if(c<3*n)return c;let M=Math.max(2,n*(n-1)),p=Math.log(r)+Y(n);if(p<-M*2.3)return Pn(n,-p);let d=-p+(n-1)*Math.log(c)-Math.log(1+(1-n)/(1+c));return-p+(n-1)*Math.log(d)-Math.log(1+(1-n)/(1+d))}let f=c,l=n+1,N=n+2;if(c<.15*l){let M=Math.log(t)+Y(l);f=Math.exp((M+c)/n),e=Math.log1p(f/l*(1+f/N)),f=Math.exp((M+f-e)/n),e=Math.log1p(f/l*(1+f/N)),f=Math.exp((M+f-e)/n),e=Math.log1p(f/l*(1+f/N*(1+f/(n+3)))),f=Math.exp((M+f-e)/n)}if(f<=.01*l||f>.7*l)return f;let h=Math.log(ye(n,f,100,1e-4)),m=Math.log(t)+Y(l);return f=Math.exp((m+f-h)/n),f*(1-(n*Math.log(f)-f-m+h)/(n-f))}function en(n){let{rate:t,scale:r}=n;if(t!==void 0&&r!==void 0){if(Math.abs(t*r-1)>=1e-15)throw new RangeError("rate and scale can both be given only when scale = 1 / rate");return r}return r!==void 0?r:t!==void 0?1/t:1}function Ie(n,t){if(t<1){let r=C(t,n,!0),e=t/n;return r+(Number.isFinite(e)?Math.log(e):Math.log(t)-Math.log(n))}return C(t-1,n,!0)}function ct(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<=0)return NaN;if(n<0)return x(e);if(t===0)return n===0?1/0:x(e);if(n===0)return t<1?1/0:t>1?x(e):e?-Math.log(r):1/r;if(t<1){let o=C(t,n/r,e);if(e){let u=t/n;return o+(Number.isFinite(u)?Math.log(u):Math.log(t)-Math.log(n))}return o*t/n}let i=C(t-1,n/r,e);return e?i-Math.log(r):i/r}function Wt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<=0)return NaN;let o=n/r;return Number.isNaN(o)?o:t===0?o<=0?v(e,i):I(e,i):o<=0?v(e,i):j(t,o,e,i)}function ve(n,t,r,e){let{lower:i,logTarget:o,linearTarget:u}=q(n,r,e),s=j(t,Number.MIN_VALUE,i,!0);if(i?s>=o:s<=o)return 0;let a;if(t>1&&o<=-700){let c=S(o,{lowerTail:i,logP:!0}),f=1-1/(9*t)+c/Math.sqrt(9*t);a=f>0?t*f*f*f:t*.001}else if(o>-700){let c=Math.exp(o),f=-Math.expm1(o);a=i?rn(t,c,f):rn(t,f,c)}else if(i)a=Math.exp((o+Rt(t))/t);else{a=-o;for(let c=0;c<3;c++)a=-o-Y(t)+(t-1)*Math.log(a)}return U({logTarget:o,...u!==void 0&&{linearTarget:u},lower:i,cdf:(c,f)=>j(t,c,f,!1),cdfLog:(c,f)=>j(t,c,f,!0),cdfBoth:(c,f)=>$n(t,c,f),pdfLog:c=>Ie(c,t),dlogPdf:c=>(t-1)/c-1,x0:a,lo:0,hi:1/0,positive:!0})}function nt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=L(n,0,1/0,e,i);return o!==void 0?o:t<0||r<=0?NaN:t===0?0:ve(n,t,e,i)*r}function io(n,t,r={}){let e=en(r),i=r.log??!1;return b(n,o=>ct(o,t,e,i))}function oo(n,t,r={}){let e=en(r),{lowerTail:i=!0,logP:o=!1}=r;return b(n,u=>Wt(u,t,e,i,o))}function uo(n,t,r={}){let e=en(r),{lowerTail:i=!0,logP:o=!1}=r;return b(n,u=>nt(u,t,e,i,o))}var yt=8*Number.EPSILON,Jn=2*Number.EPSILON,xe=1e-290;function K(n){let{p:t,lowerTail:r,logP:e,cdf:i,lo:o,hi:u}=n,s;if(e||t<xe){let l;e?l=r?t*(1+Jn):t*(1-Jn):l=Math.log(t)+Math.log1p(r?-yt:yt),s=r?N=>i(N,!0,!0)>=l:N=>i(N,!1,!0)<=l}else{let l;if(r?l=t*(1-yt):l=1-t>4*yt?t*(1+yt):t,l>.5){let N=1-l;s=r?h=>i(h,!1,!1)<=N:h=>i(h,!0,!1)>=N}else s=r?N=>i(N,!0,!1)>=l:N=>i(N,!1,!1)<=l}let a=Math.round(n.y0);if(Number.isFinite(a)||(a=o),a=Math.min(Math.max(a,o),u),s(a)){let l=1,N=a-l;for(;N>=o&&s(N);)a=N,l*=2,N=a-l;if(N<o){if(a===o)return o;N=o-1}return zn(N,a,s)}let c=1,f=a+c;for(;f<=u&&!s(f);)a=f,c*=2,f=a+c;return f>u&&(f=u),zn(a,f,s)}function zn(n,t,r){for(;t-n>1;){let e=Math.floor(n+(t-n)/2);if(e===n||e===t)break;r(e)?t=e:n=e}return t}var Ot=H;function Fe(n,t,r){return Number.isNaN(n)||Number.isNaN(t)?NaN:t<0?NaN:Ot(n)?x(r):n<0||!Number.isFinite(n)?x(r):C(Math.round(n),t,r)}function Le(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t<0)return NaN;if(n<0)return v(r,e);if(t===0)return I(r,e);if(!Number.isFinite(n))return I(r,e);let i=Math.floor(n+1e-7);return j(i+1,t,!r,e)}function Ee(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(!Number.isFinite(t)||t<0)return NaN;let i=L(n,0,1/0,r,e);if(i!==void 0)return t===0&&!Number.isNaN(i)?0:i;if(t===0)return 0;let o=Math.sqrt(t),u=S(n,{lowerTail:r,logP:e}),s=t+o*(u+(u*u-1)/(6*o));return K({p:n,lowerTail:r,logP:e,cdf:(a,c,f)=>j(a+1,t,!c,f),y0:Number.isFinite(s)?s:t,lo:0,hi:1/0})}function po(n,t,r={}){let e=r.log??!1;return b(n,i=>Fe(i,t,e))}function go(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return b(n,o=>Le(o,t,e,i))}function bo(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return b(n,o=>Ee(o,t,e,i))}var _e=1e-17,Ae=Math.log(_e),kn=2e7,un=500,on=2**un,It=2**-un,we=2**250,De=2**-250,sn=un*Math.LN2,Lt={h:0,l:0,k:0};function Z(n,t,r,e=!1){if(n===0)return Lt;if(!Number.isFinite(n))return{h:n,l:0,k:r};for(;Math.abs(n)>we;)n*=It,t*=It,r++;for(;Math.abs(n)<De;)n*=on,t*=on,r--;return e?{h:n,l:t,k:r,approx:e}:{h:n,l:t,k:r}}var Re=[346.5735902799727,-22599635089223323e-30];function Ht(n,t){if(n>1e-305||Number.isNaN(n))return Z(n,0,0);let r=t(),[e,i]=typeof r=="number"?[r,0]:r;if(e===-1/0)return Lt;if(Number.isNaN(e))return{h:NaN,l:0,k:0};let o=Math.round(e/sn),u=F([e,i],R(Re,[-o,0])),s=Math.exp(u[0]);return typeof r=="number"?Z(s,0,o,!0):Z(s,s*u[1],o)}function fn(n,t){if(n===0)return[-t,0];let r=22250738585072014e-324;if(n<=t*r||t<n*r||!Number.isFinite(n))return F(R(O([t,0]),[n,0]),[-t-Rt(n),0]);let e=F(St(n,[t,0]),[Ct(n),0]);return F([-e[0],-e[1]],[-.5*(Ce+Math.log(n)),0])}var Ce=1.8378770664093456;function z(n,t){return n.approx===!0&&xt(n)>-700?t():n}function rt(n,t){return vt(n,Z(t[0],t[1],0))}function Se(n,t){if(n.h===0)return Lt;let r=Z(t[0],t[1],0),e=_([n.h,n.l],[r.h,r.l]);return Z(e[0],e[1],n.k-r.k,n.approx)}function tr(n,t,r){let e=rt(n,t.ratio(r));return t.ratioK?{...e,k:e.k+t.ratioK}:e}function nr(n,t,r){let e=Se(n,t.ratio(r));return t.ratioK?{...e,k:e.k-t.ratioK}:e}function vt(n,t){if(n.h===0||t.h===0)return Lt;let r=R([n.h,n.l],[t.h,t.l]);return Z(r[0],r[1],n.k+t.k,n.approx===!0||t.approx===!0)}function Ut(n,t,r,e){for(let i=r;i<e&&n!==0;i++)n*=It,t*=It;return[n,t]}function rr(n,t){if(n.h===0)return t;if(t.h===0)return n;let r=Math.max(n.k,t.k),e=F(Ut(n.h,n.l,n.k,r),Ut(t.h,t.l,t.k,r));return Z(e[0],e[1],r)}function xt(n){return n.h===0?-1/0:Math.log(n.h)+n.l/n.h+n.k*sn}var Ft=class{s=0;c=0;k=0;add(t){if(t.h===0)return;if(this.s===0&&this.c===0){this.s=t.h,this.c=t.l,this.k=t.k;return}t.k>this.k&&([this.s,this.c]=Ut(this.s,this.c,this.k,t.k),this.k=t.k);let[r,e]=Ut(t.h,t.l,t.k,this.k);this.addNum(r),this.addNum(e)}addNum(t){let r=this.s+t;Math.abs(this.s)>=Math.abs(t)?this.c+=this.s-r+t:this.c+=t-r+this.s,this.s=r}get log(){let t=this.s+this.c;return Number.isNaN(t)?NaN:t>0?Math.log(t)+this.k*sn:-1/0}get linear(){let t=this.s+this.c;for(let r=0;r<this.k;r++)t*=on;for(let r=0;r>this.k&&t!==0;r--)t*=It;return t}value(t){return t?this.log:this.linear}divideBy(t){let r=Z(t,0,0);this.s/=r.h,this.c/=r.h,this.k-=r.k}};function qe(n){let t=Math.floor(n),r=1;for(;;){if(r*=n/(t+1),r/(1-n/(t+2))<3e-21)return t;t++}}function Be(n){let t=Math.floor(n),r=1;for(;t>0;){if(r*=t/n,r/(1-(t-1)/n)<3e-21)return t;t--}return 0}function jt(n,t,r){if(r===-1/0||!(n<t))return!1;let e=n-t;return n+e-Math.log(-Math.expm1(e))<=Ae+r}function et(n,t){return Ht(C(n,t,!1),()=>fn(n,t))}function G(n,t){return Ht(n.inc(t,!1),()=>n.incLogDD?n.incLogDD(t):n.inc(t,!0))}function lt(n,t,r,e){return(r?fr(n,t):ar(n,t)).value(e)}function er(n,t,r){let e=r?fr(n,t):ar(n,t);return{lin:e.linear,log:e.log}}function ir(n,t,r,e){return C(r,t,!0)+n.cdf(r,e,!0)}function or(n,t,r){for(;r-t>2;){let i=Math.floor(t+(r-t)/3),o=Math.ceil(r-(r-t)/3);n(i)<n(o)?t=i:r=o}let e=t;for(let i=t+1;i<=r;i++)n(i)>n(e)&&(e=i);return e}var We=60;function ur(n,t,r,e){let i=n(t)-We;for(let o=1;;o*=2){let u=t+r*o;if(r>0?u>=e:u<=e)return e;if(n(u)<i)return u}}var sr=3e3;function fr(n,t){let r=qe(n);if(r>sr){let a=c=>ir(t,n,c,!0);r=ur(a,or(a,0,r),1,r)}let e=Ht(t.cdf(r,!0,!1),()=>t.cdf(r,!0,!0)),i=et(r,n),o=r>0?G(t,r-1):Lt,u=new Ft,s=-1/0;for(let a=r;a>=0;a--){let c=vt(i,e),f=xt(c);if(u.add(c),jt(f,s,u.log)||(s=f,a===0))break;e=rr(e,o),i=z(rt(i,dt([a,0],n)),()=>et(a-1,n)),a>=2&&(o=o.h===0?G(t,a-2):z(nr(o,t,a-1),()=>G(t,a-2)))}return u}function ar(n,t){let r=Be(n),e=!1;for(;;){let i=Ht(t.cdf(r,!1,!1),()=>t.cdf(r,!1,!0)),o=et(r,n),u=G(t,r),s=new Ft,a=-1/0,c=-1;for(let f=r;f<r+kn;f++){let l=vt(o,i),N=xt(l);if(s.add(l),jt(N,a,s.log)||N===-1/0&&f>n+50&&f>r+50)break;if(!e&&f-r>=sr&&N>=a){let h=d=>ir(t,n,d,!1),m=h(f),M=f+1;for(let d=1;h(M)>=m;d*=2)M=f+d;let p=ur(h,or(h,f,M),-1,f);if(e=!0,p>f){c=p;break}}a=N,i=rr(i,u),o=z(rt(o,dt([n,0],f+1)),()=>et(f+1,n)),u=u.h===0?G(t,f+1):z(tr(u,t,f+1),()=>G(t,f+1))}if(c<0)return s;r=c}}function Gt(n,t,r,e,i,o){let u=Number.isFinite(e)?Math.max(0,Math.round(e)):0,s=new Ft,a=et(u,n),c=G(t,u),f=a,l=c,N=-1/0;for(let h=u;h<u+kn;h++){let m=rt(vt(f,l),[r(h),0]),M=xt(m);if(s.add(m),jt(M,N,s.log)||M===-1/0&&h>n+50&&h>u+50)break;N=M,f=z(rt(f,dt([n,0],h+1)),()=>et(h+1,n)),l=l.h===0?G(t,h+1):z(tr(l,t,h+1),()=>G(t,h+1))}f=a,l=c,N=-1/0;for(let h=u-1;h>=0;h--){f=z(rt(f,dt([h+1,0],n)),()=>et(h,n)),l=l.h===0?G(t,h):z(nr(l,t,h+1),()=>G(t,h));let m=rt(vt(f,l),[r(h),0]),M=xt(m);if(s.add(m),jt(M,N,s.log))break;N=M}return s.divideBy(i),s.value(o)}function Oe(n){return n<=.5?[[n,0],w(1,-n)]:[w(1,-(1-n)),[1-n,0]]}function mr(n,t,r,e){let[i,o]=Oe(n),{e:u}=at(t,r,i,o),s=t*r/(t+r);if(!e&&u[0]<700&&n>1e-290&&o[0]>1e-290){let l=Math.exp(-u[0])*(1-u[1])*Math.sqrt(s/(2*Math.PI));if(l>1e-290&&l<1e290){let N=R(i,o);return l/N[0]*(1-N[1]/N[0])}}let a=n>1e-290&&o[0]>1e-290?O(R(i,o)):F(O(i),O(o)),c=s>1e-290&&s<1e290?.5*Math.log(s/(2*Math.PI)):.5*(Math.log(t)+Math.log(r)-Math.log(t+r)-Math.log(2*Math.PI)),f=F(ft(F(u,a)),[c,0]);return e?f[0]+f[1]:Math.exp(f[0])*(1+f[1])}function Ue(n,t,r,e){return mr(n,r,e,!0)}function an(n,t,r,e){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<0||r<0?NaN:n<0||n>1?x(e):t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)?t===0&&r===0?n===0||n===1?1/0:x(e):t===0||r/t===1/0?n===0?1/0:x(e):r===0||t/r===1/0?n===1?1/0:x(e):n===.5?1/0:x(e):n===0?t>1?x(e):t<1?1/0:e?Math.log(r):r:n===1?r>1?x(e):r<1?1/0:e?Math.log(t):t:mr(n,t,r,e)}function cn(n,t,r,e,i){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<0||r<0?NaN:n>=1?I(e,i):t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)?t===0&&r===0?i?-Math.LN2:.5:t===0||r/t===1/0?I(e,i):r===0||t/r===1/0?v(e,i):n<.5?v(e,i):I(e,i):n<=0?v(e,i):Q(t,r,n,1-n,e,i)}function ln(n,t,r,e){if(!(n>1&&t>1))return;let i=S(e,{logP:!0}),o=r?-i:i,u=1/(2*n-1),s=1/(2*t-1),a=2/(u+s),c=(o*o-3)/6;if(!(a+c>0))return;let f=o*Math.sqrt(a+c)/a-(s-u)*(c+5/6-2/(3*a)),l=n/(n+t*Math.exp(2*f));return l>0&&l<1?l:void 0}function cr(n,t,r,e,i){let o=Q(n,t,Number.MIN_VALUE,1,r,!0);if(r?o>=e:o<=e)return 0;let u=.25,s=1/0;if(r){let a=(e+Math.log(n)+P(n,t))/n;s=Math.exp(Math.max(a,-745)),u=Math.min(s,.25)}if(!(s<.001)){let a=ln(n,t,r,e);a!==void 0&&a<.5&&(u=a)}return U({logTarget:e,...i!==void 0&&{linearTarget:i},lower:r,cdf:(a,c)=>Q(n,t,a,1-a,c,!1),cdfLog:(a,c)=>Q(n,t,a,1-a,c,!0),cdfBoth:(a,c)=>Bt(n,t,a,1-a,c),pdfLog:a=>Ue(a,1-a,n,t),dlogPdf:a=>(n-1)/a-(t-1)/(1-a),x0:u,lo:0,hi:.5,positive:!0})}function Qt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<0)return NaN;let o=L(n,0,1,e,i);if(o!==void 0)return o;if(t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)){if(t===0&&r===0){let l=i?n:Math.log(n),N=e?l:Math.log1p(-Math.exp(l));return N<-Math.LN2?0:N>-Math.LN2?1:.5}return t===0||r/t===1/0?0:r===0||t/r===1/0?1:.5}let{lower:u,logTarget:s,linearTarget:a}=q(n,e,i),c=Q(t,r,.5,.5,u,!0);return(u?s<=c:s>=c)?cr(t,r,u,s,a):1-cr(r,t,!u,s,a)}function qo(n,t,r,e={}){let{log:i=!1,ncp:o}=e;return o!==void 0?b(n,u=>lr(u,t,r,o,i)):b(n,u=>an(u,t,r,i))}function Bo(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?b(n,s=>Nr(s,t,r,u,i,o)):b(n,s=>cn(s,t,r,i,o))}function Wo(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?b(n,s=>hr(s,t,r,u,i,o)):b(n,s=>Qt(s,t,r,i,o))}function dr(n,t){let r=t<1e-250,e=r?t*2**500:t;return{ratioK:r?-1:0,cdf:(i,o,u)=>j(n+i,t,o,u),inc:(i,o)=>{let[u,s]=Mr(n,i,t);return o?C(u,t,!0)+s:C(u,t,!1)*(1+s)},ratio:i=>_([e,0],w(n,i)),incLogDD:i=>{let[o,u]=Mr(n,i,t);return F(fn(o,t),[u,0])}}}function Mr(n,t,r){let[e,i]=w(n,t);return[e,i===0?0:i*(Math.log(r)-gt(e+1))]}function pr(n,t){return n>=0&&t>=0&&Number.isFinite(n)&&Number.isFinite(t)}function gr(n,t,r,e){let i=r/2;if(i*(n/2)>1e18){let s=je(n,t,r);return e?{lin:-Math.expm1(s),log:Math.log1p(-Math.exp(s))}:{lin:Math.exp(s),log:s}}let o=dr(t/2,Math.max(n/2,Number.MIN_VALUE)),u=er(i,o,e);if(u.lin>.5){let s;return{lin:u.lin,get log(){return s??=Math.log1p(-lt(i,o,!e,!1)),s}}}return u}function je(n,t,r){let e=.5-Math.sqrt(r/n)/2-(t-3)/(4*n);return yr(n,t,r,!0)-Math.log(e)}function Nn(n,t,r,e,i){let o=gr(n,t,r,e);return i?o.log:o.lin}function He(n,t){let r=NaN,e=!0,i={lin:NaN,log:NaN};return(o,u)=>((o!==r||u!==e)&&(i=gr(o,n,t,u),r=o,e=u),i)}function br(n,t,r,e){let i=t/2,o=n/2,u=r/2,s=(-(i-1)+Math.sqrt((i-1)*(i-1)+4*u*o))/2;return u*o>1e18?yr(n,t,r,e):Gt(u,dr(i,o),a=>i+a,s,n,e)}function yr(n,t,r,e){let i=t/2-1,o=Math.sqrt(r*n),u=4*i*i,s=1,a=1;for(let l=1;l<30&&(s*=-(u-(2*l-1)*(2*l-1))/(8*l*o),a+=s,!(Math.abs(s)<1e-17*Math.abs(a)));l++);let c=Math.sqrt(n)-Math.sqrt(r),f=-Math.LN2-c*c/2+i/2*Math.log(n/r)-.5*Math.log(2*Math.PI*o)+Math.log(a);return e?f:Math.exp(f)}function Ir(n,t,r,e){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:pr(t,r)?r===0?ct(n,t/2,2,e):n<0||n===1/0?e?-1/0:0:n===0?t<2?1/0:t===2?e?-r/2-Math.LN2:Math.exp(-r/2)/2:e?-1/0:0:br(n,t,r,e):NaN}function vr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!pr(t,r))return NaN;if(n<0)return v(e,i);if(n===0){if(t>0)return v(e,i);let o=-r/2;return e?i?o:Math.exp(o):i?o<-Math.LN2?Math.log1p(-Math.exp(o)):Math.log(-Math.expm1(o)):-Math.expm1(o)}return r===0?n===1/0?I(e,i):j(t/2,Math.max(n/2,Number.MIN_VALUE),e,i):n===1/0?I(e,i):Nn(n,t,r,e,i)}function xr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!(t>=0&&r>=0&&Number.isFinite(t)))return NaN;let o=L(n,0,1/0,e,i);if(o!==void 0)return o;if(!Number.isFinite(r))return i&&Math.exp(n)===1?e?1/0:0:NaN;if(r===0)return nt(n,t/2,2,e,i);let{lower:u,logTarget:s,linearTarget:a}=q(n,e,i),c=He(t,r),f=Nn(Number.MIN_VALUE,t,r,u,!0);if(u?f>=s:f<=s)return 0;let l=(t+2*r)/(t+r),N=(t+r)*(t+r)/(t+2*r),h=l*nt(s,N/2,2,u,!0);(!(h>0)||!Number.isFinite(h))&&(h=t+r);let m=Math.max(h,t+r,1);for(let M=0;M<2e3;M++){let p=Nn(m,t,r,u,!0);if(u?p>=s:p<=s)break;m*=2}return U({logTarget:s,...a!==void 0&&{linearTarget:a},lower:u,cdf:(M,p)=>c(M,p).lin,cdfLog:(M,p)=>c(M,p).log,pdfLog:M=>br(M,t,r,!0),x0:Math.min(h,m),lo:0,hi:m,positive:!0})}function Lr(n,t,r,e){let i=w(n,t),o=r[0]<1e-250,u=o?[r[0]*2**500,r[1]*2**500]:r;return{ratioK:o?-1:0,cdf:(s,a,c)=>qt(n+s,t,r,e,a,c),inc:(s,a)=>{let[c,f]=Fr(n,t,s,r),l=t/(c+t);return a?T(c,t,r,e,!0)+Math.log(l)+f:T(c,t,r,e,!1)*l*(1+f)},ratio:s=>_(R(u,F(i,[s-1,0])),w(n,s)),incLogDD:s=>{let[a,c]=Fr(n,t,s,r);if(!(r[0]>1e-305&&e[0]>1e-305)){let N=Ge(a,t,r,e);return typeof N=="number"?N+c:F(N,[c,0])}let{e:f,logDenom:l}=at(a,t,r,e);return F([-f[0],-f[1]],[-.5*l+Math.log(t/(a+t))+c,0])}}}function Fr(n,t,r,e){let[i,o]=w(n,r);return o===0?[i,0]:[i,o*(Math.log(e[0])+e[1]/e[0]+gt(i+t)-gt(i+1))]}function Ge(n,t,r,e){if(!(r[0]>0&&e[0]>0))return-1/0;let i=F(tn(O(r),n),tn(O(e),t));return F(F(i,ft(Zn(n,t))),[-Math.log(n),0])}function mn(n){return n<=.5?[[n,0],w(1,-n)]:[w(1,-(1-n)),[1-n,0]]}function Mn(n,t,r,e,i,o,u){let s=Lr(n,t,e,i),a=r/2,c=lt(a,s,o,!1);return u?c>.5?Math.log1p(-lt(a,s,!o,!1)):c>=1e-280?Math.log(c):lt(a,s,o,!0):c}function Er(n,t,r,e,i,o,u){let s=r/2,a=e[0],c=s*a,f=n-1-c,l=(-f+Math.sqrt(Math.max(0,f*f+4*c*(n+t-1))))/2;return Gt(s,Lr(n,t,e,i),N=>n+N,l,o,u)}function dn(n,t,r){return n>0&&t>0&&Number.isFinite(n)&&Number.isFinite(t)&&r>=0&&Number.isFinite(r)}function _r(n,t,r,e,i){let[o,u]=mn(n),s=R(o,u);return Er(t,r,e,o,u,s[0]+s[1],i)}function lr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!dn(t,r,e))return NaN;if(e===0)return an(n,t,r,i);if(n<0||n>1)return i?-1/0:0;let o=e/2;return n===0?t>1?i?-1/0:0:t<1?1/0:i?Math.log(r)-o:r*Math.exp(-o):n===1?r>1?i?-1/0:0:r<1?1/0:i?Math.log(t+o):t+o:_r(n,t,r,e,i)}function Nr(n,t,r,e,i,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(n<=0)return v(i,o);if(n>=1)return I(i,o);if(!dn(t,r,e))return NaN;if(e===0)return cn(n,t,r,i,o);let[u,s]=mn(n);return Mn(t,r,e,u,s,i,o)}function hr(n,t,r,e,i,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!(t>0&&r>0&&e>=0))return NaN;let u=L(n,0,1,i,o);if(u!==void 0)return u;if(!dn(t,r,e))return NaN;if(e===0)return Qt(n,t,r,i,o);let{lower:s,logTarget:a,linearTarget:c}=q(n,i,o),f=(m,M,p)=>{let[d,y]=mn(m);return Mn(t,r,e,d,y,M,p)},l=f(Number.MIN_VALUE,s,!0);if(s?l>=a:l<=a)return 0;let N=f(1-Number.EPSILON/2,s,!0);if(s?N<a:N>a)return 1;let h=Qt(a,t+e/2,r,s,!0);return h>0&&h<1||(h=.5),U({logTarget:a,...c!==void 0&&{linearTarget:c},lower:s,cdf:(m,M)=>f(m,M,!1),cdfLog:(m,M)=>f(m,M,!0),pdfLog:m=>_r(m,t,r,e,!0),x0:h,lo:0,hi:1,positive:!0})}function Ar(n,t,r){let e=$(t,n);if(Number.isFinite(e[0])&&Number.isFinite(e[1])&&Math.abs(e[0])<1e290){let o=F(e,[r,0]);return[_(e,o),_([r,0],o)]}let i=r/t/n;return[w(1,-i),[i,0]]}function wr(n,t,r,e,i){if(t/r*n<1e-306){let s=t/2,a=-e/2+s*(Math.log(t/r)+Math.log(n))-P(s,r/2)-Math.log(n);return i?a:Math.exp(a)}let[o,u]=Ar(n,t,r);return Er(t/2,r/2,e,o,u,n,i)}function Dr(n,t,r,e,i,o){let u=t/2,s=-e/2+u*(Math.log(t/r)+Math.log(n))-Math.log(u)-P(u,r/2);return i?o?s:Math.exp(s):o?-Math.exp(s):-Math.expm1(s)}function Et(n,t,r,e,i,o){if(t/r*n<1e-306)return Dr(n,t,r,e,i,o);let[u,s]=Ar(n,t,r);return Mn(t/2,r/2,e,u,s,i,o)}function Rr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!(t>0&&r>0&&e>=0))return NaN;if(n<0)return i?-1/0:0;if(!Number.isFinite(e))return NaN;if(t===1/0)return r===1/0?n===1?1/0:i?-1/0:0:n===0?NaN:Kt(n,t,r,i);if(r===1/0){let o=Ir(n*t,t,e,i);return i?o+Math.log(t):o*t}return n===1/0?NaN:n===0?t<2?1/0:t>2?i?-1/0:0:i?-e/2:Math.exp(-e/2):e===0?Kt(n,t,r,i):wr(n,t,r,e,i)}function Cr(n,t,r,e,i,o){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e)?NaN:!(t>0&&r>0&&e>=0)||!Number.isFinite(e)?NaN:t===1/0&&r===1/0?NaN:n<=0?v(i,o):n===1/0?I(i,o):t===1/0?NaN:r===1/0?vr(n*t,t,e,i,o):t/r*n<1e-306?Dr(n,t,r,e,i,o):e===0?hn(n,t,r,i,o):Et(n,t,r,e,i,o)}function Sr(n,t,r,e,i,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!(t>0&&r>0&&e>=0)||!Number.isFinite(e))return NaN;let u=L(n,0,1/0,i,o);return u!==void 0?u:t===1/0?NaN:r===1/0?xr(n,t,e,i,o)/t:e===0?Vt(n,t,r,i,o):Qe(n,t,r,e,i,o)}function Qe(n,t,r,e,i,o){let{lower:u,logTarget:s,linearTarget:a}=q(n,i,o),c=Et(Number.MIN_VALUE,t,r,e,u,!0);if(u?c>=s:c<=s)return 0;let f=Et(Number.MAX_VALUE,t,r,e,u,!0);if(u?f<s:f>s)return 1/0;let l=(t+e)*(t+e)/(t+2*e),N=(t+e)/t*Vt(s,l,r,u,!0);return(!(N>0)||!Number.isFinite(N))&&(N=1),U({logTarget:s,...a!==void 0&&{linearTarget:a},lower:u,cdf:(h,m)=>Et(h,t,r,e,m,!1),cdfLog:(h,m)=>Et(h,t,r,e,m,!0),pdfLog:h=>wr(h,t,r,e,!0),x0:N,lo:0,hi:1/0,positive:!0})}function qr(n,t,r,e){let i=$(t,n),o,u;if(Number.isFinite(i[0])&&Number.isFinite(i[1])&&Math.abs(i[0])<1e290){let l=F(i,[r,0]);o=_(i,l),u=_([r,0],l)}else u=[r/t/n,0],o=[1,-u[0]];let s=o[0],a=u[0];if(t>=2){let l=t*a/2,N=T((t-2)/2,r/2,o,u,e);return e?Math.log(l)+N:l*N}let c=t/(r+t*n)*t*r/(2*(t+r)*s),f=T(t/2,r/2,o,u,e);return e?Math.log(c)+f:c*f}function Kt(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<=0||r<=0)return NaN;if(n<0)return x(e);if(n===0)return t>2?x(e):t===2?e?0:1:1/0;if(!Number.isFinite(t)&&!Number.isFinite(r))return n===1?1/0:x(e);if(!Number.isFinite(r))return ct(n,t/2,2/t,e);if(!Number.isFinite(t)){let i=ct(1/n,r/2,2/r,e);return e?i-2*Math.log(n):i/(n*n)}return Number.isFinite(n)?qr(n,t,r,e):t<2?NaN:x(e)}function pn(n,t,r,e,i){let o=$(t,n);if(Number.isFinite(o[0])&&Number.isFinite(o[1])&&Math.abs(o[0])<1e290){let s=F(o,[r,0]);return qt(t/2,r/2,_(o,s),_([r,0],s),e,i)}let u=r/t/n;return Q(t/2,r/2,1-u,u,e,i)}function Ke(n,t,r,e){let i=ln(n/2,t/2,r,e);if(i===void 0)return 1;let o=t*i/(n*(1-i));return o>0&&Number.isFinite(o)?o:1}function Ve(n,t,r,e){let i=$(t,n);if(Number.isFinite(i[0])&&Number.isFinite(i[1])&&Math.abs(i[0])<1e290){let u=F(i,[r,0]);return Yn(t/2,r/2,_(i,u),_([r,0],u),e)}let o=r/t/n;return Bt(t/2,r/2,1-o,o,e)}function hn(n,t,r,e,i){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<=0||r<=0?NaN:n<=0?v(e,i):n===1/0?I(e,i):!Number.isFinite(t)&&!Number.isFinite(r)?n===1?i?-Math.LN2:.5:n<1?v(e,i):I(e,i):Number.isFinite(r)?Number.isFinite(t)?pn(n,t,r,e,i):Wt(r/n,r/2,2,!e,i):Wt(n*t,t/2,2,e,i)}function Vt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<=0||r<=0)return NaN;let o=L(n,0,1/0,e,i);if(o!==void 0)return o;if(!Number.isFinite(t)&&!Number.isFinite(r))return 1;if(!Number.isFinite(r))return nt(n,t/2,2,e,i)/t;if(!Number.isFinite(t))return r/nt(n,r/2,2,!e,i);let{lower:u,logTarget:s,linearTarget:a}=q(n,e,i);return u&&(s+Math.log(t/2)+P(t/2,r/2))/(t/2)+Math.log(r/t)<-746?0:!u&&-(s+Math.log(r/2)+P(t/2,r/2))/(r/2)+Math.log(r/t)>709.78?1/0:U({logTarget:s,...a!==void 0&&{linearTarget:a},lower:u,cdf:(c,f)=>pn(c,t,r,f,!1),cdfLog:(c,f)=>pn(c,t,r,f,!0),cdfBoth:(c,f)=>Ve(c,t,r,f),pdfLog:c=>qr(c,t,r,!0),dlogPdf:c=>(t/2-1)/c-(t+r)/2*(t/(r+t*c)),x0:Ke(t,r,u,s),lo:0,hi:1/0,positive:!0})}function Mu(n,t,r,e={}){let{log:i=!1,ncp:o}=e;return o!==void 0?b(n,u=>Rr(u,t,r,o,i)):b(n,u=>Kt(u,t,r,i))}function du(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?b(n,s=>Cr(s,t,r,u,i,o)):b(n,s=>hn(s,t,r,i,o))}function pu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?b(n,s=>Sr(s,t,r,u,i,o)):b(n,s=>Vt(s,t,r,i,o))}function gn(n,t){return Ot(n)||n<0||!Number.isFinite(n)||t<0||t>1}function Xe(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(gn(t,r))return NaN;if(Ot(n)||n<0||!Number.isFinite(n))return x(e);let i=Math.round(n),o=Math.round(t);if(i>o)return x(e);let u=r<=.5?[r,0]:w(1,-(1-r)),s=r<=.5?w(1,-r):[1-r,0];return T(i,o-i,u,s,e)}function Br(n,t,r,e,i){return Q(n+1,t-n,r,1-r,!e,i)}function $e(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(gn(t,r))return NaN;let o=Math.round(t);if(n<0)return v(e,i);let u=Math.floor(n+1e-7);return o<=u?I(e,i):r===0?I(e,i):r===1?v(e,i):Br(u,o,r,e,i)}function Ze(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!Number.isFinite(t)||!Number.isFinite(r)||r<0||r>1||t<0)return NaN;let o=L(n,0,Ye(t),e,i);if(o!==void 0)return o;if(gn(t,r))return NaN;let u=Math.round(t);if(r===0||u===0)return 0;if(r===1)return u;let s=1-r,a=u*r,c=Math.sqrt(u*r*s),f=(s-r)/c,l=S(n,{lowerTail:e,logP:i}),N=a+c*(l+f*(l*l-1)/6);return K({p:n,lowerTail:e,logP:i,cdf:(h,m,M)=>h>=u?I(m,M):Br(h,u,r,m,M),y0:Number.isFinite(N)?N:a,lo:0,hi:u})}function _u(n,t,r,e={}){let i=e.log??!1;return b(n,o=>Xe(o,t,r,i))}function Au(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return b(n,u=>$e(u,t,r,i,o))}function wu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return b(n,u=>Ze(u,t,r,i,o))}function Ye(n){let t=Math.round(n);return Math.abs(n%1)===.5&&t%2!==0?t-1:t}function bn(n,t,r,e){if(n===0&&t===0)return{e:[0,0],logDenom:0};if(n===0||t===0){let i=n+t,[o,u]=n===0?[e,r]:[r,e];return{e:u[0]<.1?F(St(i,R([i,0],o)),R([i,0],u)):ft(R([i,0],O(o))),logDenom:0}}return at(n,t,r,e)}function Ur(n,t,r,e){let i=t+r,o=_([e,0],[i,0]),u=_([i-e,0],[i,0]),s=bn(n,t-n,o,u),a=bn(e-n,r-e+n,o,u),c=bn(e,i-e,o,u);return{e:Vn(F(s.e,a.e),c.e),logDenom:s.logDenom+a.logDenom-c.logDenom}}function jr(n,t){let[r,e]=n.e,i=t*Math.exp(-.5*n.logDenom);return r<700?Math.exp(-r)*(1-e)*i:Math.exp(700-r)*(1-e)*i*Math.exp(-700)}function Hr(n){return-n.e[0]-n.e[1]-.5*n.logDenom}function Xt(n,t,r){return[Math.max(0,r-t),Math.min(r,n)]}function Te(n,t,r,e,i){if([n,t,r,e].some(Number.isNaN))return NaN;if(![t,r,e].every(Number.isFinite)||H(t)||H(r)||H(e))return NaN;if(t=D(t),r=D(r),e=D(e),t<0||r<0||e<0||e>t+r)return NaN;if(H(n))return x(i);n=D(n);let[o,u]=Xt(t,r,e);if(n<o||n>u)return x(i);if(e===0||e===t+r)return i?0:1;let s=Ur(n,t,r,e);return i?Hr(s):jr(s,1)}function Wr(n,t,r,e){return _($(n,t),$(r,e))}function Pe(n,t,r,e,i,o,u){let s=[1,0],a=[1,0],c=n;for(;!(i?c<=o:c>=u);){let f=i?Wr(c,r-e+c,t-c+1,e-c+1):Wr(t-c,e-c,c+1,r-e+c+1);s=R(s,f),a=F(a,s),c+=i?-1:1;let l=f[0];if(l<1&&s[0]*l/(1-l)<a[0]*2**-60)break}return a[0]+a[1]}function Gr(n,t,r,e,i,o){let[u,s]=Xt(t,r,e),a=t+r,c=n*a<e*t,f=Or(n,t,r,e,c,u,s);if(f.value>.5){let l=Or(n,t,r,e,!c,u,s);l.value<f.value&&(f=l,c=!c)}return c===i?o?f.value>1e-300?Math.log(f.value):Hr(f.form)+Math.log(f.sum):f.value:o?Math.log1p(-f.value):1-f.value}function Or(n,t,r,e,i,o,u){let s=i?n:n+1,a=Ur(s,t,r,e),c=Pe(s,t,r,e,i,o,u);return{form:a,sum:c,value:jr(a,c)}}function Qr(n,t,r){if([n,t,r].every(Number.isFinite)&&(n=D(n),t=D(t),r=D(r),!(n<0||t<0||r<0||r>n+t)))return[n,t,r]}function Je(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;let u=Qr(t,r,e);if(u===void 0)return NaN;[t,r,e]=u;let s=Math.floor(n+1e-7),[a,c]=Xt(t,r,e);return s<a?v(i,o):s>=c?I(i,o):Gr(s,t,r,e,i,o)}function ze(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;let u=Qr(t,r,e);if(u===void 0)return NaN;[t,r,e]=u;let[s,a]=Xt(t,r,e),c=L(n,s,a,i,o);if(c!==void 0)return c;if(s===a)return s;let f=t+r,l=e*t/f,N=Math.sqrt(e*t/f*(r/f)*(f-e)/Math.max(f-1,1)),h=S(n,{lowerTail:i,logP:o}),m=l+N*h;return K({p:n,lowerTail:i,logP:o,cdf:(M,p,d)=>M<s?v(p,d):M>=a?I(p,d):Gr(M,t,r,e,p,d),y0:Number.isFinite(m)?m:l,lo:s,hi:a})}function Uu(n,t,r,e,i={}){let o=i.log??!1;return b(n,u=>Te(u,t,r,e,o))}function ju(n,t,r,e,i={}){let{lowerTail:o=!0,logP:u=!1}=i;return b(n,s=>Je(s,t,r,e,o,u))}function Hu(n,t,r,e,i={}){let{lowerTail:o=!0,logP:u=!1}=i;return b(n,s=>ze(s,t,r,e,o,u))}var ke=2**900,Kr=-900,it=new Map,ti=2**21,$t=0,ni=2**25;function ri(n,t){if(t+1>ni)throw new RangeError(`signrank: n = ${n} needs too large a table (${t+1} entries)`);let r=new Float64Array(t+1);r[0]=1;let e=0,i=Math.min(n,t);for(let a=1;a<=i;a++){for(let c=t;c>=a;c--)r[c]+=r[c-a];if(r[Math.min(t,Math.floor(a*(a+1)/4))]>ke){let c=2**Kr;for(let f=0;f<=t;f++)r[f]*=c;e-=Kr}}let o=new Float64Array(t+1),u=0,s=0;for(let a=0;a<=t;a++){let c=r[a]-s,f=u+c;s=f-u-c,u=f,o[a]=u}return{n,len:t+1,count:r,cum:o,scale:e}}function yn(n,t){let r=it.get(n);if(r!==void 0&&r.len>t)return it.delete(n),it.set(n,r),r;let e=Math.floor(n*(n+1)/4),i=Math.min(e,Math.max(t,r===void 0?0:2*r.len)),o=ri(n,i);r!==void 0&&(it.delete(n),$t-=r.len),it.set(n,o),$t+=o.len;for(let[u,s]of it){if($t<=ti||u===n)break;it.delete(u),$t-=s.len}return o}function In(n,t,r){let e=t.scale-t.n,i=Math.trunc(e/2),o=n*2**i*2**(e-i);return r?o>=1e-300?Math.log(o):Math.log(n)+e*Math.LN2:o}function vn(n){return Number.isFinite(n)?(n=D(n),n<=0?NaN:n):NaN}function ei(n,t,r){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=vn(t),Number.isNaN(t))return NaN;if(H(n))return x(r);n=D(n);let e=t*(t+1)/2;if(n<0||n>e)return x(r);let i=Math.min(n,e-n),o=yn(t,i);return In(o.count[i],o,r)}function Vr(n,t,r,e){let i=t*(t+1)/2,o=n,u=i-n-1,s=r?o:u,a=r?u:o;if(s<=a){let l=yn(t,s);return In(l.cum[s],l,e)}let c=yn(t,a),f=In(c.cum[a],c,!1);return e?Math.log1p(-f):1-f}function ii(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=vn(t),Number.isNaN(t))return NaN;let i=D(n+1e-7),o=t*(t+1)/2;return i<0?v(r,e):i>=o?I(r,e):Vr(i,t,r,e)}function oi(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=vn(t),Number.isNaN(t))return NaN;let i=t*(t+1)/2,o=L(n,0,i,r,e);if(o!==void 0)return o;let u=i/2,s=Math.sqrt(t*(t+1)*(2*t+1)/24),a=u+s*S(n,{lowerTail:r,logP:e});return K({p:n,lowerTail:r,logP:e,cdf:(c,f,l)=>c<0?v(f,l):c>=i?I(f,l):Vr(c,t,f,l),y0:Number.isFinite(a)?a:u,lo:0,hi:i})}function Zu(n,t,r={}){let e=r.log??!1;return b(n,i=>ei(i,t,e))}function Yu(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return b(n,o=>ii(o,t,e,i))}function Tu(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return b(n,o=>oi(o,t,e,i))}var Tt=960,ui=2**25,Zt=134217729,ot=new Map,si=2**21,Yt=0;function fi(n,t,r){if(r+1>ui)throw new RangeError(`wilcox: m = ${n}, n = ${t} needs too large a table (${r+1} entries)`);let e=new Float64Array(r+1),i=new Float64Array(r+1);e[0]=2**Tt;for(let a=1;a<=n;a++){let c=Math.min(r,a*t),f=t+a,l=Zt*a,N=l-(l-a),h=a-N;l=Zt*f;let m=l-(l-f),M=f-m;for(let d=0;d<=c;d++){let y=e[d];if(y===0)continue;let g=y*a;l=Zt*y;let E=l-(l-y),V=y-E,B=E*N-g+E*h+V*N+V*h+i[d]*a,A=g/f,X=A*f;l=Zt*A;let W=l-(l-A),st=A-W,ge=W*m-X+W*M+st*m+st*M,Qn=(g-X-ge+B)/f,Kn=A+Qn;i[d]=Qn-(Kn-A),e[d]=Kn}let p=t+a;for(let d=c;d>=p;d--)Xr(e,i,d,d-p,-1);for(let d=a;d<=c;d++)Xr(e,i,d,d-a,1)}let o=new Float64Array(r+1),u=0,s=0;for(let a=0;a<=r;a++){let c=e[a],f=u+c,l=f-u,N=u-(f-l)+(c-l);N+=s+i[a],u=f+N,s=N-(u-f),o[a]=u}return{m:n,n:t,len:r+1,prob:e,cum:o}}function Xr(n,t,r,e,i){let o=n[r],u=i*n[e],s=o+u,a=s-o,c=o-(s-a)+(u-a);c+=t[r]+i*t[e];let f=s+c;t[r]=c-(f-s),n[r]=f}function xn(n,t,r){n>t&&([n,t]=[t,n]);let e=`${n},${t}`,i=ot.get(e);if(i!==void 0&&i.len>r)return ot.delete(e),ot.set(e,i),i;let o=Math.floor(n*t/2),u=Math.min(o,Math.max(r,i===void 0?0:2*i.len)),s=fi(n,t,u);i!==void 0&&(ot.delete(e),Yt-=i.len),ot.set(e,s),Yt+=s.len;for(let[a,c]of ot){if(Yt<=si||a===e)break;ot.delete(a),Yt-=c.len}return s}function Fn(n,t){let r=n*2**-(Tt/2)*2**-(Tt/2);return t?r>=1e-300?Math.log(r):Math.log(n)-Tt*Math.LN2:r}function Ln(n,t){if(!(!Number.isFinite(n)||!Number.isFinite(t)))return n=D(n),t=D(t),n<=0||t<=0?void 0:[n,t]}function ai(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let i=Ln(t,r);if(i===void 0)return NaN;if([t,r]=i,H(n))return x(e);n=D(n);let o=t*r;if(n<0||n>o)return x(e);let u=Math.min(n,o-n);return Fn(xn(t,r,u).prob[u],e)}function $r(n,t,r,e,i){let o=t*r,u=e?n:o-n-1,s=e?o-n-1:n;if(u<=s)return Fn(xn(t,r,u).cum[u],i);let a=Fn(xn(t,r,s).cum[s],!1);return i?Math.log1p(-a):1-a}function ci(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=Ln(t,r);if(o===void 0)return NaN;[t,r]=o;let u=Math.floor(n+1e-7);return u<0?v(e,i):u>=t*r?I(e,i):$r(u,t,r,e,i)}function li(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=Ln(t,r);if(o===void 0)return NaN;[t,r]=o;let u=t*r,s=L(n,0,u,e,i);if(s!==void 0)return s;let a=u/2,c=Math.sqrt(u*(t+r+1)/12),f=a+c*S(n,{lowerTail:e,logP:i});return K({p:n,lowerTail:e,logP:i,cdf:(l,N,h)=>l<0?v(N,h):l>=u?I(N,h):$r(l,t,r,N,h),y0:Number.isFinite(f)?f:a,lo:0,hi:u})}function rs(n,t,r,e={}){let i=e.log??!1;return b(n,o=>ai(o,t,r,i))}function es(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return b(n,u=>ci(u,t,r,i,o))}function is(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return b(n,u=>li(u,t,r,i,o))}var tt=128,qn=Number.EPSILON,Bn=Float64Array.from({length:2*tt+1},(n,t)=>Math.cos(Math.PI*t/tt));function Ni(n){let t=new Float64Array(n+1);for(let r=0;r<=n;r++){let e=0;for(let i=0;i<=n;i+=2)e+=(i===0||i===n?.5:1)*Bn[i*r%(2*n)*(tt/n)]*2/(1-i*i);t[r]=(r===0||r===n?.5:1)*2*e/n}return t}var hi=new Map([16,32,64,128].map(n=>[n,Ni(n)]));function mi(n,t){let r=hi.get(t),e=tt/t,i=0,o=0;for(let s=0;s<=t;s++)i+=r[s]*n[s],o+=Math.abs(r[s]*n[s]);let u=0;for(let s=t-7;s<=t;s++){let a=.5*(n[0]+(s%2===0?n[t]:-n[t]));for(let c=1;c<t;c++)a+=n[c]*Bn[s*c%(2*t)*e];a*=2/t,s===t&&(a*=.5),u=Math.max(u,Math.abs(a))}return{integral:i,tail:u,scale:o}}var At=class{f;a;b;c;h;values=new Float64Array(tt+1);have=new Uint8Array(tt+1);N=0;integral=0;error=1/0;constructor(t,r,e){this.f=t,this.a=r,this.b=e,this.c=.5*(r+e),this.h=.5*(e-r)}advance(t){let r=tt/t,e=new Float64Array(t+1);for(let o=0;o<=t;o++){let u=o*r;this.have[u]||(this.values[u]=this.f(this.c+this.h*Bn[u]),this.have[u]=1),e[o]=this.values[u]}let i=mi(e,t);this.N=t,this.integral=i.integral*this.h,this.error=Math.max(i.tail*4/t,4*qn*i.scale)*Math.abs(this.h)}};function Jt(n,t,r){let e=[];for(let o=0;o+1<t.length;o++){let u=new At(n,t[o],t[o+1]);u.advance(16),e.push(u)}for(let o=0;o<40;o++){let u=0;for(let f of e)u+=f.integral;let s=r*Math.abs(u)/e.length,a=!0,c=[];for(let f of e){if(f.error<=s||f.error<=4*qn*Math.abs(f.integral)){c.push(f);continue}if(a=!1,f.N<tt)f.advance(2*f.N),c.push(f);else{let l=new At(n,f.a,f.c),N=new At(n,f.c,f.b);l.advance(16),N.advance(16),c.push(l,N)}}if(e=c,a)break}let i=0;for(let o of e)i+=o.integral;return i}function Yr(n,t,r){let e=Math.max(1,Math.ceil((t-n)/r));return Array.from({length:e+1},(i,o)=>o===e?t:n+(t-n)*o/e)}var Tr=2e-15,Pr=1e-16,Mi={lowerTail:!1},di={logP:!0},pi={lowerTail:!1,logP:!0},Dt=.9189385332046728,zt=n=>pt(n),ht=n=>pt(n,Mi),Wn=n=>pt(n,di),On=n=>pt(n,pi),gi=.3989422804014327;function mt(n){let t=Math.round(n*16)/16,r=n-t;return gi*Math.exp(-.5*t*t)*Math.exp(-.5*r*(n+t))}var An=[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],Jr=[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626];function bi(n,t){let r=n-.5*t,e=.5*t,i=0;for(let o=0;o<4;o++)i+=Jr[o]*(mt(r-e*An[o])+mt(r+e*An[o]));return i*e}function yi(n,t){let r=n-.5*t,e=.5*t,i=0;for(let o=0;o<4;o++){let u=e*An[o];i+=Jr[o]*(Math.exp(r*u-u*u/2)+Math.exp(-r*u-u*u/2))}return-Dt-r*r/2+Math.log(i*e)}var Un=(n,t)=>t*Math.max(1,Math.abs(n),Math.abs(n-t))<.5;function Mt(n,t){let r=n-t,e=r-n,i=n-(r-e)+(-t-e);return{ah:r,al:i}}function wt(n,t){return zt(n)+mt(n)*t}function Ii(n,t){return ht(n)-mt(n)*t}function zr(n,t){if(Un(n,t))return bi(n,t);let{ah:r,al:e}=Mt(n,t);return r>=0?Ii(r,e)-ht(n):n<=0?zt(n)-wt(r,e):1-wt(r,e)-ht(n)}function vi(n,t,r){if(n>0&&n-t<0&&!Un(n,t)){let{ah:i,al:o}=Mt(n,t);return Math.exp(r*Math.log1p(-(wt(i,o)+ht(n))))}let e=zr(n,t);return e>0?e**r:0}function xi(n,t){return n>0?Math.exp(t*Math.log1p(-ht(n))):zt(n)**t}function kr(n,t){let{ah:r,al:e}=Mt(n,t),i=Wn(r);return i+e*Math.exp(-Dt-r*r/2-i)}function Fi(n,t){let{ah:r,al:e}=Mt(n,t),i=On(r);return i-e*Math.exp(-Dt-r*r/2-i)}function te(n,t){if(Un(n,t))return yi(n,t);if(n-t>=0){let o=Fi(n,t);return o+Math.log(-Math.expm1(On(n)-o))}if(n<=0){let o=Wn(n);return o+Math.log(-Math.expm1(kr(n,t)-o))}let{ah:e,al:i}=Mt(n,t);return Math.log1p(-wt(e,i)-ht(n))}var ne=2,En=1e-18;function re(n,t,r){let e=Yr(t,r,ne),i=e.map(n),o=0;for(let N=1;N<i.length;N++)i[N]>i[o]&&(o=N);let u=i[o];if(!(u>0))return 0;let s=Math.max(o-1,0),a=Math.min(o+1,i.length-1);for(;s>0&&i[s]>u*En;)s--;for(;a<i.length-1&&i[a]>u*En;)a++;let c=u*En,f=e[s],l=e[a];if(i[s]<=c){let N=e[s+1];for(let h=0;h<2;h++){let m=.5*(f+N);n(m)<=c?f=m:N=m}}if(i[a]<=c){let N=e[a-1];for(let h=0;h<2;h++){let m=.5*(l+N);n(m)<=c?l=m:N=m}}return Jt(n,[f,l],Pr)}function ee(n,t,r){let e=Yr(t,r,ne),i=e.map(n),o=0;for(let g=1;g<i.length;g++)i[g]>i[o]&&(o=g);if(!(i[o]>-1/0))return-1/0;let u=e[Math.max(o-1,0)],s=e[Math.min(o+1,e.length-1)],a=(Math.sqrt(5)-1)/2,c=s-a*(s-u),f=u+a*(s-u),l=n(c),N=n(f);for(let g=0;g<80&&s-u>1e-12*Math.max(1,Math.abs(u));g++)l<N?(u=c,c=f,l=N,f=u+a*(s-u),N=n(f)):(s=f,f=c,N=l,c=s-a*(s-u),l=n(c));let h=l>N?c:f,m=Math.max(l,N);i[o]>m&&(h=e[o],m=i[o]);let M=g=>{let E=g<0?t:r,V=Math.max(1e-6,.001*(e[1]-e[0])),B=h;for(;;){let A=h+g*V;if(g<0?A<=E:A>=E)return E;if(n(A)<m-46){let X=A;for(let W=0;W<6;W++){let st=.5*(B+X);n(st)<m-46?X=st:B=st}return X}B=A,V*=2}},p=M(-1),d=M(1),y=[...new Set([p,h,d])].sort((g,E)=>g-E);return m+Math.log(Jt(g=>Math.exp(n(g)-m),y,Pr))}var jn=-10,Hn=10;function Li(n,t){return n<=0?0:t*re(r=>mt(r)*vi(r,n,t-1),jn,Hn)}function ie(n,t){if(n<=0)return 1;let r=o=>{let u=zt(o);if(u===0)return 0;let{ah:s,al:a}=Mt(o,n),c=wt(s,a),f=c<.5*u?-Math.expm1((t-1)*Math.log1p(-c/u)):-Math.expm1((t-1)*Math.log(zr(o,n)/u));return mt(o)*xi(o,t-1)*f};if(n>60)return 0;let[e,i]=oe(n);return t*re(r,e,i)}function oe(n){return n>40?[n/2-15,n/2+15]:[jn,n+Hn]}function ue(n,t){if(n>100)return-Math.exp(se(n,t));let r=e=>-Dt-e*e/2+(t-1)*te(e,n);return Math.log(t)+ee(r,jn,Hn)}function se(n,t){if(n>100)return Math.log(t*(t-1))+On(n/Math.SQRT2);let r=o=>{let u=Wn(o),s=kr(o,n)-u,a;return s<-40?a=Math.log(t-1)+s:s<-Math.LN2?a=Math.log(-Math.expm1((t-1)*Math.log1p(-Math.exp(s)))):a=Math.log(-Math.expm1((t-1)*(te(o,n)-u))),-Dt-o*o/2+(t-1)*u+a},[e,i]=oe(n);return Math.log(t)+ee(r,e,i)}function Ei(n,t){let r=-1/0;for(let e of t)r=Math.max(r,n(e));for(let e=0;e+1<t.length;e++)r=Math.max(r,n(.5*(t[e]+t[e+1])));if(r===-1/0)return-1/0;for(let e=0;e<4;e++){let i=r,o=Jt(u=>{let s=n(u);return s>i&&(i=s),Math.exp(s-r)},t,Tr);if(Number.isFinite(o)&&i-r<300)return r+Math.log(o);r=i}return NaN}var k=32,_i=1e-15,Nt=Math.log(.01),Gn=Math.log(20),fe=Math.log(40),ae=Float64Array.from({length:2*k+1},(n,t)=>Math.cos(Math.PI*t/k));function Ai(n,t){let r=new Float64Array(t+1);for(let e=0;e<=t;e++){let i=.5*(n[0]+(e%2===0?n[t]:-n[t]));for(let o=1;o<t;o++)i+=n[o]*ae[e*o%(2*t)];i*=2/t,(e===0||e===t)&&(i*=.5),r[e]=i}return r}function _n(n,t,r){let e=[],i=[[t,r,0]];for(;i.length>0;){let[o,u,s]=i.pop(),a=.5*(o+u),c=.5*(u-o),f=new Float64Array(k+1),l=1/0;for(let m=0;m<=k;m++)f[m]=n(a+c*ae[m]),l=Math.min(l,Math.max(1,Math.abs(f[m])));let N=Ai(f,k),h=0;for(let m=k-3;m<=k;m++)h=Math.max(h,Math.abs(N[m]));h<=_i*l||s>=14||!f.every(Number.isFinite)?e.push({a:o,b:u,coef:N}):i.push([a,u,s+1],[o,a,s+1])}return e.sort((o,u)=>o.a-u.a)}function wn(n,t){let r=0,e=n.length-1;for(;r<e;){let f=r+e+1>>1;n[f].a<=t?r=f:e=f-1}let{a:i,b:o,coef:u}=n[r],s=(2*t-i-o)/(o-i),a=0,c=0;for(let f=k;f>=1;f--){let l=2*s*a-c+u[f];c=a,a=l}return s*a-c+u[0]}var _t=new Map,wi=64,ce=Math.log(1e-10);function le(n){let t=_t.get(n);if(t!==void 0)return t;let r=i=>{let o=Li(i,n);return o>1e-290?Math.log(o):ue(i,n)},e=i=>{let o=Math.exp(i);return ie(o,n)*Ne(o)};return t={logW:_n(i=>r(Math.exp(i)),Nt,Gn),scaledWc:_n(e,Nt,fe),smallW:_n(i=>r(Math.exp(i))-(n-1)*i,ce,Nt)},_t.size>=wi&&_t.delete(_t.keys().next().value),_t.set(n,t),t}function Ne(n){let t=n*n,r=134217729*n,e=r-(r-n),i=n-e,o=e*e-t+2*e*i+i*i;return Math.exp(t/4)*(1+o/4)}function Di(n,t){let r=Math.log(n);if(r>=Gn)return 0;let e=le(t);return r>=Nt?wn(e.logW,r):wn(e.smallW,Math.max(r,ce))+(t-1)*r}function Dn(n,t){return Math.log(n)>=Gn?1:Math.exp(Di(n,t))}function Ri(n,t){let r=Math.log(n);return r>=Nt&&r<=fe?wn(le(t).scaledWc,r)/Ne(n):r<Nt?1-Dn(n,t):ie(n,t)}function Pt(n,t,r,e){if(!e){let o=Math.min(Dn(n,t),1);return r===1?o:o**r}let i=Math.min(Ri(n,t),1);return i<=.5?r===1?i:-Math.expm1(r*Math.log1p(-i)):1-Math.min(Dn(n,t),1)**r}function Rn(n,t,r,e){if(!e)return r*ue(n,t);let i=se(n,t);return r===1?i:Math.log(-Math.expm1(r*Math.log1p(-Math.exp(i))))}function Cn(n,t,r,e,i){if(r===1/0)return Pt(n,t,e,i);let o=r/2,u=Math.log(o),s=Ci(o);return Jt(c=>{let{d:f,s:l}=s(c);return f===0?0:f*Pt(n*l,t,e,i)},he(n,t,r,e,i).map(c=>c-u),Tr)}function Ci(n){let t=Ct(n),r=Math.sqrt(n/(2*Math.PI));return e=>{let i;if(Math.abs(e)<.5){let o=e*e/2;i=o;for(let u=3;u<60&&(o*=e/u,i+=o,!(Math.abs(o)<1e-17*i));u++);}else i=Math.expm1(e)-e;return{d:r*Math.exp(-t-n*i),s:Math.exp(.5*e)}}}function Si(n,t,r,e,i){if(r===1/0)return Rn(n,t,e,i);let o=r/2,u=Math.log(o),s=Y(o+1);return Ei(c=>{let f=Math.exp(c),l=f>1e-300?C(o,f,!0):o*c-f-s;return u+l+Rn(Math.exp(Math.log(n)+.5*(c-u)),t,e,i)},he(n,t,r,e,i,!0))}function he(n,t,r,e,i,o=!1){let u=r/2,s=u,a=Math.log(u);if(i){let g=2*Math.log(n)-Math.log(4*u);a-=g>30?g:Math.log1p(Math.exp(g))}else s=u+(t-1)*e/2,a=Math.log(s);let c=(g,E)=>[g-9/Math.sqrt(E)-41/E,g+9/Math.sqrt(E)+Math.log1p(41/E)],[f,l]=c(Math.log(u),u),[N,h]=c(a,s),m=o?Math.min(f,N):Math.max(Math.min(f,N),-740),M=Math.max(l,h),p=1/Math.sqrt(u),d=1/Math.sqrt(s),y=[m,Math.min(Math.log(u)-4*p,a-4*d),Math.max(Math.log(u)+4*p,a+4*d),M];return[...new Set(y.map(g=>Math.min(Math.max(g,m),M)))].sort((g,E)=>g-E)}function me(n,t,r){return n>=2&&t>=2&&r>=1&&Number.isFinite(n)&&Number.isFinite(r)&&!Number.isNaN(t)}function Sn(n,t,r,e,i,o){let u;return ut!==void 0&&ut.q===n&&ut.k===t&&ut.df===r&&ut.r===e?u=ut.tail:(u=qi(n,t,r,e,!i),ut={q:n,k:t,df:r,r:e,tail:u}),u.upper===!i?o?u.log:u.value:o?Math.log1p(-u.value):1-u.value}var ut;function qi(n,t,r,e,i){let o=i;r!==1/0&&Pt(n,t,e,o)>.5&&(o=!o);let u=Cn(n,t,r,e,o);if(u>.5){let s=Cn(n,t,r,e,!o);s<u&&(u=s,o=!o)}if(u<1e-290){let s=Si(n,t,r,e,o);return{upper:o,value:Math.exp(s),log:s}}return{upper:o,value:u,log:Math.log(u)}}function Bi(n,t,r,e,i,o){return[n,t,r,e].some(Number.isNaN)?NaN:me(t,r,e)?n<=0?v(i,o):n===1/0?I(i,o):Sn(n,t,r,e,i,o):NaN}function Wi(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;if(!me(t,r,e))return NaN;let u=L(n,0,1/0,i,o);if(u!==void 0)return u;let{lower:s,logTarget:a,linearTarget:c}=q(n,i,o),f=N=>h=>{let m=Math.exp(h);if(c!==void 0&&c>1e-290){let p=N===1/0?Cn(m,t,N,e,!s):Sn(m,t,N,e,s,!1);if(p>0)return Math.log(p/c)}return(N===1/0?Oi(m,t,e,s):Sn(m,t,N,e,s,!0))-a},l=Zr(f(1/0),Math.log(3),s);return Math.exp(r===1/0?l:Zr(f(r),l,s))}function Oi(n,t,r,e){let i=Pt(n,t,r,!e);return i>1e-290?Math.log(i):Rn(n,t,r,!e)}function Zr(n,t,r){let e=t,i=n(e);if(i===0)return e;let o=i>0===r?-1:1,u=.05,s=e+o*u,a=n(s);for(let c=0;c<200&&Math.sign(a)===Math.sign(i)&&a!==0;c++)e=s,i=a,u*=2,s=e+o*u,a=n(s);return a===0?s:!Number.isFinite(a)||Math.sign(a)===Math.sign(i)?Number.isFinite(a)?s:e:Ui(n,e,s,i,a)}function Ui(n,t,r,e,i){let o=t,u=e,s=r-t,a=s;for(let c=0;c<100;c++){Math.sign(i)===Math.sign(u)&&(o=t,u=e,s=r-t,a=s),Math.abs(u)<Math.abs(i)&&(t=r,r=o,o=t,e=i,i=u,u=e);let f=2*qn*Math.abs(r)+1e-300,l=.5*(o-r);if(Math.abs(l)<=f||i===0)return r;if(Math.abs(a)>=f&&Math.abs(e)>Math.abs(i)){let N=i/e,h,m;if(t===o)h=2*l*N,m=1-N;else{let M=e/u,p=i/u;h=N*(2*l*M*(M-p)-(r-t)*(p-1)),m=(M-1)*(p-1)*(N-1)}h>0?m=-m:h=-h,2*h<Math.min(3*l*m-Math.abs(f*m),Math.abs(a*m))?(a=s,s=h/m):(s=l,a=l)}else s=l,a=l;t=r,e=i,r+=Math.abs(s)>f?s:l>0?f:-f,i=n(r)}return r}function ls(n,t,r,e={}){let{nranges:i=1,lowerTail:o=!0,logP:u=!1}=e;return b(n,s=>Bi(s,t,r,i,o,u))}function Ns(n,t,r,e={}){let{nranges:i=1,lowerTail:o=!0,logP:u=!1}=e;return b(n,s=>Wi(s,t,r,i,o,u))}function Ms(n,t={}){return Me(n,t).map(r=>r-1)}function Me(n,t){if(!Number.isFinite(n)||n<0||n>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");n=Math.trunc(n);let{replace:r=!1,prob:e}=t,i=t.size!==void 0,o=i?t.size:n;if(!Number.isFinite(o)||o<0)throw new RangeError("size must be a non-negative number");let u=Math.trunc(o);if(e!==void 0){if(n>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(e.length!==n)throw new TypeError("prob must have length n");let f=ji(e,u,r);if(r){let l=0;for(let N=0;N<n;N++)n*f[N]>.1&&l++;return l>200?Ki(f,u):Gi(f,u)}if(u>n)throw new RangeError("cannot take a sample larger than the population when replace is false");return Qi(f,u)}if(!r&&u>n)throw new RangeError("cannot take a sample larger than the population when replace is false");if(!r&&n>1e7&&i&&u<=n/2){let f=new Set,l=[];for(;l.length<u;){let N=bt(n);f.has(N)||(f.add(N),l.push(N+1))}return l}let s=new Array(u);if(r||u<2){for(let f=0;f<u;f++)s[f]=bt(n)+1;return s}if(n>=2**31)throw new RangeError("n must be less than 2^31 to sample without replacement with size above n / 2");let a=new Int32Array(n);for(let f=0;f<n;f++)a[f]=f;let c=n;for(let f=0;f<u;f++){let l=bt(c);s[f]=a[l]+1,a[l]=a[--c]}return s}function ds(n,t={}){return Me(n.length,t).map(r=>n[r-1])}function ji(n,t,r){let e=0,i=0;for(let o of n){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&&(i++,e+=o)}if(i===0||!r&&t>i)throw new RangeError("too few positive probabilities");return Float64Array.from(n,o=>o/e)}function Hi(n,t){let r=n.length;if(r<=1)return;let e=a=>n[a-1],i=(r>>1)+1,o=r,u,s;for(;;){if(i>1)i=i-1,u=e(i),s=t[i-1];else if(u=e(o),s=t[o-1],n[o-1]=e(1),t[o-1]=t[0],--o===1){n[0]=u,t[0]=s;return}let a=i,c=i<<1;for(;c<=o;)c<o&&e(c)>e(c+1)&&++c,u>e(c)?(n[a-1]=e(c),t[a-1]=t[c-1],a=c,c+=c):c=o+1;n[a-1]=u,t[a-1]=s}}function de(n){let t=new Int32Array(n.length);for(let r=0;r<n.length;r++)t[r]=r+1;return Hi(n,t),t}function Gi(n,t){let r=Float64Array.from(n),e=r.length,i=de(r);for(let u=1;u<e;u++)r[u]+=r[u-1];let o=new Array(t);for(let u=0;u<t;u++){let s=J(),a=0;for(;a<e-1&&!(s<=r[a]);a++);o[u]=i[a]}return o}function Qi(n,t){let r=Float64Array.from(n),e=r.length,i=de(r),o=new Array(t),u=1;for(let s=0,a=e-1;s<t;s++,a--){let c=u*J(),f=0,l=0;for(;l<a&&(f+=r[l],!(c<=f));l++);o[s]=i[l],u-=r[l];for(let N=l;N<a;N++)r[N]=r[N+1],i[N]=i[N+1]}return o}function Ki(n,t){let r=n.length,e=new Float64Array(r),i=new Int32Array(r),o=new Int32Array(r),u=-1,s=r;for(let f=0;f<r;f++)e[f]=n[f]*r,e[f]<1?o[++u]=f:o[--s]=f;if(u>=0&&s<r)for(let f=0;f<r-1;f++){let l=o[f],N=o[s];if(i[l]=N,e[N]+=e[l]-1,e[N]<1&&s++,s>=r)break}let a=Tn(),c=new Array(t);for(let f=0;f<t;f++){let l,N;a?(N=J()*r,l=Math.trunc(N)):(l=bt(r),N=l+J()),c[f]=N<e[l]+l?l+1:i[l]+1}return c}function Vi(n){let t=new Float64Array(n+1);for(let r=2;r<=n;r++)t[r]=t[r-1]+Math.log(r);return t}function Xi(n,t,r,e){let i=n.length,o=t.length,u=Array.from(t),s=0;for(let c of n)s+=c;for(let c=0;c<i-1;c++){let f=n[c],l=s;s-=f;let N=0;for(;N<o-1;N++){let h=u[N],m=l;l-=h;let M=m-f,p=M-h;if(m===0){for(let g=N;g<o-1;g++)e[c+g*i]=0;f=0;break}let d=J(),y;t:for(;;){y=Math.floor(f*(h/m)+.5);let g=Math.exp(r[f]+r[M]+r[l]+r[h]-r[m]-r[y]-r[h-y]-r[f-y]-r[p+y]);if(g>=d)break;if(g===0)throw new Error(`r2dtable: probability underflow at cell [${c}, ${N}]`);let E=g,V=g,B=y,A=!1,X=!1;for(;!(A&&X);){if(!A){let W=(h-y)*(f-y);if(W===0)A=!0;else if(y++,g=g*W/(y*(p+y)),E+=g,E>=d)break t}do{let W=B*(p+B);if(W===0){X=!0;break}if(B--,V=V*W/((h-B)*(f-B)),E+=V,E>=d){y=B;break t}}while(A)}d=E*J()}e[c+N*i]=y,f-=y,u[N]=u[N]-y}e[c+(o-1)*i]=f}let a=t[o-1];for(let c=0;c<i-1;c++)a-=e[c+(o-1)*i];for(let c=0;c<o-1;c++)e[i-1+c*i]=u[c];e[i-1+(o-1)*i]=a}function pe(n,t){let r=Array.from(n,e=>Math.trunc(e));if(r.length<=1||r.some(e=>!(e>=0)||e>2147483647))throw new RangeError(`invalid argument '${t}'`);return r}function bs(n,t,r){let e=Math.trunc(n);if(!(e>=0))throw new RangeError("invalid argument 'n'");let i=pe(t,"r"),o=pe(r,"c"),u=i.reduce((f,l)=>f+l,0);if(u!==o.reduce((f,l)=>f+l,0))throw new RangeError("arguments 'r' and 'c' must have the same sums");let s=Vi(u),a=new Int32Array(i.length*o.length),c=[];for(let f=0;f<e;f++)Xi(i,o,s,a),c.push(i.map((l,N)=>o.map((h,m)=>a[N+m*i.length])));return c}export{en as a,ct as b,Wt as c,nt as d,io as e,oo as f,uo as g,Ir as h,vr as i,xr as j,K as k,Fe as l,Le as m,Ee as n,po as o,go as p,bo as q,hn as r,Vt as s,Mu as t,du as u,pu as v,cn as w,Qt as x,qo as y,Bo as z,Wo as A,Xe as B,$e as C,_u as D,Au as E,wu as F,Te as G,Je as H,ze as I,Uu as J,ju as K,Hu as L,ii as M,oi as N,Zu as O,Yu as P,Tu as Q,ci as R,li as S,rs as T,es as U,is as V,ls as W,Ns as X,Ms as Y,ds as Z,Vi as _,Xi as $,bs as aa};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.8.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
-
function x(e,n){return{nrow:e,ncol:n,data:new Float64Array(e*n)}}function R(e){return e.length>0&&typeof e[0]!="number"}function q(e){let n=e.length,o=n===0?0:e[0].length,t=x(n,o);for(let r=0;r<n;r++){let a=e[r];if(a.length!==o)throw new TypeError("all rows of the matrix must have the same length");for(let i=0;i<o;i++)t.data[r+i*n]=a[i]}return t}function I(e){if(R(e))return q(e);let n=e;return{nrow:n.length,ncol:1,data:Float64Array.from(n)}}function j(e){let n=[];for(let o=0;o<e.nrow;o++){let t=new Array(e.ncol);for(let r=0;r<e.ncol;r++)t[r]=e.data[o+r*e.nrow];n.push(t)}return n}function S(e){let n=x(e.ncol,e.nrow);for(let o=0;o<e.ncol;o++)for(let t=0;t<e.nrow;t++)n.data[o+t*e.ncol]=e.data[t+o*e.nrow];return n}function _(e,n="the matrix"){if(e.nrow!==e.ncol)throw new TypeError(`${n} must be square (got ${e.nrow} x ${e.ncol})`)}function X(e,n={}){let o=q(e);if(n.lapack){let{tau:i,pivot:s}=st(o),f=Array.from({length:o.ncol},(h,l)=>i[l]??0);return{qr:j(o),rank:Math.min(o.nrow,o.ncol),qraux:f,pivot:s.map(h=>h-1),useLapack:!0}}for(let i of o.data)if(!Number.isFinite(i))throw new RangeError("the matrix contains NaN or infinite values");let{qraux:t,pivot:r,rank:a}=it(o,n.tol??1e-7);return{qr:j(o),rank:a,qraux:Array.from(t),pivot:r.map(i=>i-1),useLapack:!1}}function E(e,n,o){let t=0;for(let a=0;a<o;a++)t=Math.max(t,Math.abs(e[n+a]));if(t===0||!Number.isFinite(t))return t;let r=0;for(let a=0;a<o;a++){let i=e[n+a]/t;r+=i*i}return t*Math.sqrt(r)}function it(e,n){let o=e.nrow,t=e.ncol,r=e.data,a=new Float64Array(t),i=new Float64Array(t),s=new Float64Array(t),f=Array.from({length:t},(c,w)=>w+1);for(let c=0;c<t;c++)a[c]=E(r,c*o,o),i[c]=a[c],s[c]=a[c]===0?1:a[c];let h=new Float64Array(o),l=Math.min(o,t),u=t;for(let c=0;c<l;c++){for(;c<u&&a[c]<s[c]*n;){h.set(r.subarray(c*o,(c+1)*o));let[M,v,d,p]=[a[c],i[c],s[c],f[c]];r.copyWithin(c*o,(c+1)*o,t*o),r.set(h,(t-1)*o),a.copyWithin(c,c+1),i.copyWithin(c,c+1),s.copyWithin(c,c+1),f.copyWithin(c,c+1),a[t-1]=M,i[t-1]=v,s[t-1]=d,f[t-1]=p,u--}if(c===o-1)break;let w=c*o,m=E(r,w+c,o-c);if(m!==0){r[w+c]!==0&&(m=Math.sign(r[w+c])*Math.abs(m));for(let M=c;M<o;M++)r[w+M]/=m;r[w+c]=1+r[w+c];for(let M=c+1;M<t;M++){let v=M*o,d=0;for(let b=c;b<o;b++)d-=r[w+b]*r[v+b];d/=r[w+c];for(let b=c;b<o;b++)r[v+b]+=d*r[w+b];if(a[M]===0)continue;let p=1-(Math.abs(r[v+c])/a[M])**2;p=Math.max(p,0);let g=p;p=1+.05*p*(a[M]/i[M])**2,p!==1?a[M]*=Math.sqrt(g):(a[M]=E(r,v+c+1,o-c-1),i[M]=a[M])}a[c]=r[w+c],r[w+c]=-m}}return{qraux:a,pivot:f,rank:Math.min(u,o)}}function st(e){let n=e.nrow,o=e.ncol,t=e.data,r=Math.min(n,o),a=new Float64Array(r),i=Array.from({length:o},(l,u)=>u+1),s=new Float64Array(o),f=new Float64Array(o);for(let l=0;l<o;l++)s[l]=E(t,l*n,n),f[l]=s[l];let h=Math.sqrt(2**-53);for(let l=0;l<r;l++){let u=l;for(let w=l+1;w<o;w++)Math.abs(s[w])>Math.abs(s[u])&&(u=w);if(u!==l){for(let w=0;w<n;w++){let m=t[w+u*n];t[w+u*n]=t[w+l*n],t[w+l*n]=m}[i[u],i[l]]=[i[l],i[u]],s[u]=s[l],f[u]=f[l]}let c=l*n;if(a[l]=P(t,c+l,n-l),l<o-1){let w=t[c+l];t[c+l]=1,O(t,c+l,n-l,a[l],e,l,l+1,o-l-1),t[c+l]=w}for(let w=l+1;w<o;w++){if(s[w]===0)continue;let m=1-(Math.abs(t[l+w*n])/s[w])**2;m=Math.max(m,0),m*(s[w]/f[w])**2<=h?l<n-1?(s[w]=E(t,w*n+l+1,n-l-1),f[w]=s[w]):(s[w]=0,f[w]=0):s[w]*=Math.sqrt(m)}}return{tau:a,pivot:i}}function P(e,n,o){if(o<=1)return 0;let t=E(e,n+1,o-1);if(t===0)return 0;let r=e[n],a=-Math.sign(r||1)*Math.hypot(r,t),i=2**-1022/2**-53,s=0;if(Math.abs(a)<i){let l=1/i;do{s++;for(let u=1;u<o;u++)e[n+u]*=l;a*=l,r*=l}while(Math.abs(a)<i&&s<20);t=E(e,n+1,o-1),a=-Math.sign(r||1)*Math.hypot(r,t)}let f=(a-r)/a,h=1/(r-a);for(let l=1;l<o;l++)e[n+l]*=h;for(let l=0;l<s;l++)a*=i;return e[n]=a,f}function O(e,n,o,t,r,a,i,s){if(t===0)return;let f=r.nrow,h=r.data;for(let l=i;l<i+s;l++){let u=a+l*f,c=0;for(let w=0;w<o;w++)c+=h[u+w]*e[n+w];c*=t;for(let w=0;w<o;w++)h[u+w]-=e[n+w]*c}}function C(e){return{a:q(e.qr),qraux:e.qraux,rank:e.rank,pivot:e.pivot.map(n=>n+1),lapack:e.useLapack}}function W(e,n){let o=I(n);if(o.nrow!==e.a.nrow)throw new TypeError(`qr and y must have the same number of rows (${e.a.nrow} and ${o.nrow})`);return o}function z(e,n){return R(e)?j(n):Array.from(n.data)}function $(e,n,o,t=e.rank){let{a:r,qraux:a}=e,i=r.nrow;if(e.lapack){let h=Math.min(i,r.ncol),l=o?Q(0,h):Q(0,h).reverse();for(let u of l){let c=r.data[u+u*i];r.data[u+u*i]=1,O(r.data,u+u*i,i-u,a[u],n,u,0,n.ncol),r.data[u+u*i]=c}return}let s=Math.min(t,i-1),f=o?Q(0,s):Q(0,s).reverse();for(let h of f){if(a[h]===0)continue;let l=h*i,u=r.data[l+h];r.data[l+h]=a[h];for(let c=0;c<n.ncol;c++){let w=c*i,m=0;for(let M=h;M<i;M++)m-=r.data[l+M]*n.data[w+M];m/=r.data[l+h];for(let M=h;M<i;M++)n.data[w+M]+=m*r.data[l+M]}r.data[l+h]=u}}function Q(e,n){return Array.from({length:Math.max(0,n-e)},(o,t)=>e+t)}function vt(e,n){let o=C(e),t=W(o,n);return $(o,t,!0),z(n,t)}function yt(e,n){let o=C(e),t=W(o,n);return $(o,t,!1),z(n,t)}function ct(e,n){let o=C(e),t=W(o,n),r=o.a.ncol,a=o.a.nrow,i=o.lapack?Math.min(a,r):o.rank;$(o,t,!0);for(let f=0;f<t.ncol;f++){let h=f*a;for(let l=i-1;l>=0;l--){let u=o.a.data[l+l*a];if(u===0)throw new Error("exact singularity in qrCoef");t.data[h+l]/=u;let c=-t.data[h+l];for(let w=0;w<l;w++)t.data[h+w]+=c*o.a.data[w+l*a]}}let s=x(r,t.ncol);s.data.fill(NaN);for(let f=0;f<t.ncol;f++)for(let h=0;h<i;h++)s.data[o.pivot[h]-1+f*r]=t.data[h+f*a];return z(n,s)}function J(e,n,o,t){let r=C(e);if(r.lapack)throw new TypeError("not supported for a QR decomposition computed with lapack: true");let a=t??r.rank;if(!Number.isInteger(a)||a<0||a>r.rank)throw new RangeError(`invalid k (got ${a})`);let i=W(r,n),s=r.a.nrow;if(a===0)return z(n,i);if(s===1)return o||i.data.fill(0),z(n,i);$(r,i,!0,a);for(let f=0;f<i.ncol;f++)o?i.data.fill(0,f*s+a,(f+1)*s):i.data.fill(0,f*s,f*s+a);return $(r,i,!1,a),z(n,i)}function kt(e,n){return J(e,n,!1)}function Nt(e,n,o={}){return J(e,n,!0,o.k)}function xt(e,n={}){let o=C(e),t=o.a.nrow,r=n.complete?t:Math.min(t,o.a.ncol),a=n.dvec??new Array(r).fill(1);if(a.length!==r)throw new RangeError(`dvec must have length ${r}`);let i=x(t,r);for(let s=0;s<r;s++)i.data[s+s*t]=a[s];return $(o,i,!1),j(i)}function K(e,n={}){let o=q(e.qr),t=n.complete?o.nrow:Math.min(o.nrow,o.ncol),r=x(t,o.ncol);for(let a=0;a<o.ncol;a++)for(let i=0;i<=Math.min(a,t-1);i++)r.data[i+a*t]=o.data[i+a*o.nrow];return j(r)}function jt(e,n={}){let o=C(e),t=o.a.nrow,r=o.a.ncol,a=n.complete??!1,i=n.ncol??(a?t:Math.min(t,r));if(!Number.isInteger(i)||i<0)throw new RangeError(`invalid ncol (got ${i})`);if(o.pivot.some((u,c)=>u!==c+1)&&i<r)throw new RangeError("ncol must be at least the number of columns because the decomposition is pivoted");let f=x(t,i);for(let u=0;u<i;u++)if(u<r)for(let c=0;c<=Math.min(u,t-1);c++)f.data[c+u*t]=o.a.data[c+u*t];else u<t&&(f.data[u+u*t]=1);$(o,f,!1);let h=Math.min(i,r),l=x(t,i);l.data.set(f.data);for(let u=0;u<h;u++){let c=o.pivot[u]-1;c<h&&l.data.set(f.data.subarray(u*t,(u+1)*t),c*t)}return j(l)}function qt(e,n,o={}){let t=Array.isArray(e)?X(e,{tol:o.tol??1e-7}):e,r=t.qr.length,a=r===0?0:t.qr[0].length;if(t.rank!==Math.min(r,a))throw new Error("singular matrix in qrSolve");if(n===void 0&&r!==a)throw new TypeError("only square matrices can be inverted");let i=n??Array.from({length:r},(h,l)=>Array.from({length:r},(u,c)=>l===c?1:0)),s=ct(t,i),f=h=>Number.isNaN(h)?0:h;return R(i)?s.map(h=>h.map(f)):s.map(f)}function $t(e,n={}){let o=q(e);for(let u of o.data)if(!Number.isFinite(u))throw new RangeError("the matrix contains NaN or infinite values");let t=Math.min(o.nrow,o.ncol),r=Math.min(n.nu??t,o.nrow),a=Math.min(n.nv??t,o.ncol);for(let[u,c]of[["nu",r],["nv",a]])if(!Number.isInteger(c)||c<0)throw new RangeError(`${u} must be a non-negative integer`);let i=o.nrow<o.ncol,s=tt(i?S(o):o,i?a:r,i?r:a),f={d:Array.from(s.d)},[h,l]=i?[s.v,s.u]:[s.u,s.v];return r>0&&(f.u=j(Y(h,r))),a>0&&(f.v=j(Y(l,a))),f}function Z(e){return tt(e.nrow<e.ncol?S(e):e,0,0).d}function Y(e,n){return{nrow:e.nrow,ncol:n,data:e.data.slice(0,e.nrow*n)}}function tt(e,n,o){let t=e.nrow,r=e.ncol,a=new Float64Array(r);if(r===0)return{d:a,u:x(t,t),v:x(0,0)};let i={nrow:t,ncol:r,data:e.data.slice()},s=new Float64Array(r),f=new Float64Array(r),h=new Float64Array(r);for(let d=0;d<r;d++){let p=d*t;if(f[d]=P(i.data,p+d,t-d),a[d]=i.data[p+d],d<r-1&&(i.data[p+d]=1,O(i.data,p+d,t-d,f[d],i,d,d+1,r-d-1),i.data[p+d]=a[d]),d<r-1){let g=new Float64Array(r-d-1);for(let y=0;y<g.length;y++)g[y]=i.data[d+(d+1+y)*t];h[d]=P(g,0,g.length),s[d+1]=g[0],g[0]=1;let b=h[d];if(b!==0)for(let y=d+1;y<t;y++){let k=0;for(let N=0;N<g.length;N++)k+=i.data[y+(d+1+N)*t]*g[N];k*=b;for(let N=0;N<g.length;N++)i.data[y+(d+1+N)*t]-=k*g[N]}g[0]=s[d+1];for(let y=0;y<g.length;y++)i.data[d+(d+1+y)*t]=g[y]}}let l=n===0?0:Math.max(n,r),u;if(l>0){u=x(t,l);for(let d=0;d<l;d++)u.data[d+d*t]=1;for(let d=r-1;d>=0;d--){let p=d*t,g=i.data[p+d];i.data[p+d]=1,O(i.data,p+d,t-d,f[d],u,d,0,l),i.data[p+d]=g}}let c;if(o>0){c=x(r,r);for(let p=0;p<r;p++)c.data[p+p*r]=1;let d=new Float64Array(r);for(let p=r-2;p>=0;p--){let g=r-p-1;d[0]=1;for(let b=1;b<g;b++)d[b]=i.data[p+(p+1+b)*t];O(d,0,g,h[p],c,p+1,0,r)}}ft(a,s,u,c);let w=Array.from({length:r},(d,p)=>p).sort((d,p)=>a[p]-a[d]||d-p),m=Float64Array.from(w,d=>a[d]),M=(d,p)=>{if(d===void 0)return;let g={nrow:d.nrow,ncol:d.ncol,data:d.data.slice()};for(let b=0;b<p;b++)g.data.set(d.data.subarray(w[b]*d.nrow,(w[b]+1)*d.nrow),b*d.nrow);return g},v={d:m};return u&&(v.u=M(u,r)),c&&(v.v=M(c,r)),v}function ft(e,n,o,t){let r=e.length,a=Number.EPSILON,i=0;for(let h=0;h<r;h++)i=Math.max(i,Math.abs(e[h])+Math.abs(n[h]));let s=(h,l,u,c)=>{if(!o)return;let w=o.nrow;for(let m=0;m<w;m++){let M=o.data[m+h*w],v=o.data[m+l*w];o.data[m+h*w]=M*u+v*c,o.data[m+l*w]=v*u-M*c}},f=(h,l,u,c)=>{if(t)for(let w=0;w<r;w++){let m=t.data[w+h*r],M=t.data[w+l*r];t.data[w+h*r]=m*u+M*c,t.data[w+l*r]=M*u-m*c}};for(let h=r-1;h>=0;h--)for(let l=0;;l++){let u=h,c=!0;for(;u>=0;u--){if(u===0||Math.abs(n[u])<=a*i){c=!1;break}if(Math.abs(e[u-1])<=a*i)break}if(c){let k=u-1,N=0,F=1;for(let A=u;A<=h;A++){let T=F*n[A];if(n[A]=N*n[A],Math.abs(T)<=a*i)break;let H=e[A],U=Math.hypot(T,H);e[A]=U,N=H/U,F=-T/U,s(k,A,N,F)}}let w=e[h];if(u===h){if(w<0&&(e[h]=-w,t))for(let k=0;k<r;k++)t.data[k+h*r]=-t.data[k+h*r];break}if(l>=75)throw new Error("the singular value decomposition did not converge");let m=e[u],M=h-1,v=e[M],d=n[M],p=n[h],g=((v-w)*(v+w)+(d-p)*(d+p))/(2*p*v);d=Math.hypot(g,1),g=((m-w)*(m+w)+p*(v/(g+(g>=0?Math.abs(d):-Math.abs(d)))-p))/m;let b=1,y=1;for(let k=u;k<=M;k++){let N=k+1;d=n[N],v=e[N],p=y*d,d=b*d;let F=Math.hypot(g,p);n[k]=F,b=g/F,y=p/F,g=m*b+d*y,d=d*b-m*y,p=v*y,v*=b,f(k,N,b,y),F=Math.hypot(g,p),e[k]=F,F!==0&&(b=g/F,y=p/F),g=b*d+y*v,m=b*v-y*d,s(k,N,b,y)}n[u]=0,n[h]=g,e[h]=m}}function Ot(e,n={}){let o=q(e),t=n.type??"O";if(t.length!==1)throw new RangeError(`type must be a single character (got "${t}")`);switch(t.toUpperCase()){case"O":case"1":return V(o);case"I":return D(o);case"F":case"E":return lt(o);case"M":return ot(o);case"2":return ut(o);default:throw new RangeError(`type must be one of "O", "I", "F", "M" and "2" (got "${t}")`)}}function B(e,n){return Number.isNaN(e)||Number.isNaN(n)?NaN:Math.max(e,n)}function V(e){let n=0;for(let o=0;o<e.ncol;o++){let t=0;for(let r=0;r<e.nrow;r++)t+=Math.abs(e.data[r+o*e.nrow]);n=B(n,t)}return n}function D(e){let n=new Float64Array(e.nrow);for(let t=0;t<e.ncol;t++)for(let r=0;r<e.nrow;r++)n[r]+=Math.abs(e.data[r+t*e.nrow]);let o=0;for(let t of n)o=B(o,t);return o}function ot(e){let n=0;for(let o of e.data)n=B(n,Math.abs(o));return n}function lt(e){let n=ot(e);if(n===0||!Number.isFinite(n))return n;let o=0;for(let t of e.data){let r=t/n;o+=r*r}return n*Math.sqrt(o)}function ut(e){if(e.nrow===0||e.ncol===0)return 0;if(e.data.some(Number.isNaN))return NaN;if(e.data.some(n=>!Number.isFinite(n)))throw new RangeError("the matrix contains infinite values");return Z(e)[0]}function G(e){let n=e.nrow,o=e.ncol,t=e.data,r=Math.min(n,o),a=new Int32Array(r),i=2**-1022,s=0;for(let f=0;f<r;f++){let h=f*n,l=f,u=Math.abs(t[h+f]);for(let c=f+1;c<n;c++){let w=Math.abs(t[h+c]);w>u&&(u=w,l=c)}if(a[f]=l,t[h+l]!==0){if(l!==f)for(let w=0;w<o;w++){let m=t[f+w*n];t[f+w*n]=t[l+w*n],t[l+w*n]=m}let c=t[h+f];if(Math.abs(c)>=i){let w=1/c;for(let m=f+1;m<n;m++)t[h+m]*=w}else for(let w=f+1;w<n;w++)t[h+w]/=c}else s===0&&(s=f+1);for(let c=f+1;c<o;c++){let w=t[f+c*n];if(w===0)continue;let m=-w;for(let M=f+1;M<n;M++)t[M+c*n]+=t[h+M]*m}}return{ipiv:a,info:s}}function ht(e,n,o){let t=e.nrow,r=e.data,a=o.data;for(let i=0;i<o.ncol;i++){let s=i*t;for(let f=0;f<t;f++){let h=n[f];if(h!==f){let l=a[s+f];a[s+f]=a[s+h],a[s+h]=l}}for(let f=0;f<t;f++){let h=a[s+f];if(h!==0)for(let l=f+1;l<t;l++)a[s+l]-=h*r[l+f*t]}for(let f=t-1;f>=0;f--)if(a[s+f]!==0){a[s+f]/=r[f+f*t];let h=a[s+f];for(let l=0;l<f;l++)a[s+l]-=h*r[l+f*t]}}}function L(e,n,o,t,r){let a=e.nrow,i=e.data;if(o)if(n)for(let s=0;s<a;s++){let f=r[s];for(let h=0;h<s;h++)f-=i[h+s*a]*r[h];t||(f/=i[s+s*a]),r[s]=f}else for(let s=a-1;s>=0;s--){let f=r[s];for(let h=a-1;h>s;h--)f-=i[h+s*a]*r[h];t||(f/=i[s+s*a]),r[s]=f}else if(n){for(let s=a-1;s>=0;s--)if(r[s]!==0){t||(r[s]/=i[s+s*a]);let f=r[s];for(let h=s-1;h>=0;h--)r[h]-=f*i[h+s*a]}}else for(let s=0;s<a;s++)if(r[s]!==0){t||(r[s]/=i[s+s*a]);let f=r[s];for(let h=s+1;h<a;h++)r[h]-=f*i[h+s*a]}}function nt(e,n){let o=new Float64Array(e),t=new Int32Array(e),r=()=>o.reduce((w,m)=>w+Math.abs(m),0),a=()=>{let w=0;for(let m=1;m<e;m++)Math.abs(o[m])>Math.abs(o[w])&&(w=m);return w},i=()=>{for(let w=0;w<e;w++)o[w]=o[w]>=0?1:-1,t[w]=o[w]};if(o.fill(1/e),n(1,o),e===1)return Math.abs(o[0]);let s=r();i(),n(2,o);let f=a(),h=2,l=5;for(;;){o.fill(0),o[f]=1,n(1,o);let w=s;s=r();let m=!1;for(let v=0;v<e;v++)if((o[v]>=0?1:-1)!==t[v]){m=!0;break}if(!m||s<=w)break;i(),n(2,o);let M=f;if(f=a(),o[M]!==Math.abs(o[f])&&h<l){h++;continue}break}let u=1;for(let w=0;w<e;w++)o[w]=u*(1+w/(e-1)),u=-u;n(1,o);let c=2*(r()/(3*e));return c>s?c:s}function et(e,n,o){let t=e.nrow;if(t===0)return 1;if(!Number.isFinite(n))throw new RangeError("the matrix contains NaN or infinite values (LAPACK dgecon returned error -5)");if(n===0)return 0;let r=o?1:2,a=nt(t,(i,s)=>{i===r?(L(e,!1,!1,!0,s),L(e,!0,!1,!1,s)):(L(e,!0,!0,!1,s),L(e,!1,!0,!0,s))});return Number.isFinite(a)?a===0?0:1/a/n:0}function wt(e,n,o){let t=e.nrow,r=new Float64Array(t);for(let i=0;i<t;i++){let[s,f]=n?[0,i]:[i,t-1];for(let h=s;h<=f;h++)r[o?i:h]+=Math.abs(e.data[h+i*t])}let a=0;for(let i of r)a=Number.isNaN(a)||Number.isNaN(i)?NaN:Math.max(a,i);return a}function rt(e,n,o){let t=e.nrow;if(t===0)return 1;let r=wt(e,n,o);if(!(r>0))return 0;let a=o?1:2,i=nt(t,(s,f)=>L(e,n,s!==a,!1,f));return Number.isFinite(i)?i===0?0:1/r/i:0}function Qt(e,n,o={}){let t=q(e);_(t);let r=t.nrow,a;if(n===void 0){a=x(r,r);for(let l=0;l<r;l++)a.data[l+l*r]=1}else if(a=I(n),a.nrow!==r)throw new TypeError(`b (${a.nrow} x ${a.ncol}) is not compatible with a (${r} x ${r})`);let i=V(t),{ipiv:s,info:f}=G(t);if(f>0)throw new Error(`the system is exactly singular: U[${f}, ${f}] = 0`);let h=o.tol??Number.EPSILON;if(h>0&&Number.isFinite(i)){let l=et(t,i,!0);if(l<h)throw new Error(`the system is computationally singular: reciprocal condition number = ${l.toPrecision(6)}`)}return ht(t,s,a),n!==void 0&&!R(n)?Array.from(a.data):j(a)}function dt(e,n={}){let o=n.logarithm??!0,t=q(e);_(t);let r=t.nrow,{ipiv:a,info:i}=G(t);if(i>0)return{modulus:o?-1/0:0,logarithm:o,sign:1};let s=1,f=o?0:1;for(let h=0;h<r;h++){a[h]!==h&&(s=-s);let l=t.data[h+h*r];l<0&&(s=-s),o?f+=Math.log(Math.abs(l)):f*=Math.abs(l)}return{modulus:f,logarithm:o,sign:s}}function Pt(e){let{modulus:n,sign:o}=dt(e);return o*Math.exp(n)}function Wt(e,n={}){let o=n.norm??"O";if(!["O","1","I"].includes(o))throw new RangeError(`norm must be "O", "I" or "1" (got "${o}")`);let t=o!=="I",r=q(e);if(r.nrow!==r.ncol){let s=r.nrow<r.ncol?j(S(r)):e;return rt(q(K(X(s))),!0,t)}if(n.triangular)return rt(r,(n.uplo??"U")==="U",t);let a=t?V(r):D(r);r={...r,data:r.data.slice()};let{info:i}=G(r);return i>0?0:et(r,a,t)}function Ut(e,n={}){let o=q(e);if(_(o),o.nrow===0)throw new RangeError("the matrix has zero dimension");if(n.pivot){let{pivot:r,rank:a}=pt(o,n.tol??-1);return at(o),{r:j(o),pivot:r.map(i=>i-1),rank:a}}let t=mt(o);if(t>0)throw new Error(`the matrix is not positive definite: the leading minor of order ${t} is not positive`);return at(o),j(o)}function at(e){let n=e.nrow;for(let o=0;o<n;o++)for(let t=o+1;t<n;t++)e.data[t+o*n]=0}function mt(e){let n=e.nrow,o=e.data;for(let t=0;t<n;t++){let r=t*n,a=o[t+r];for(let i=0;i<t;i++)a-=o[i+r]*o[i+r];if(a<=0)return o[t+r]=a,t+1;a=Math.sqrt(a),o[t+r]=a;for(let i=t+1;i<n;i++){let s=i*n,f=o[t+s];for(let h=0;h<t;h++)f-=o[h+r]*o[h+s];o[t+s]=f/a}}return 0}function pt(e,n){let o=e.nrow,t=e.data,r=Array.from({length:o},(u,c)=>c+1),a=(u,c)=>u+c*o,i=(u,c)=>{let w=t[u];t[u]=t[c],t[c]=w},s=0;for(let u=1;u<o;u++)t[a(u,u)]>t[a(s,s)]&&(s=u);let f=t[a(s,s)];if(f<=0||Number.isNaN(f))return{pivot:r,rank:0};let h=n<0?o*Number.EPSILON*f:n,l=new Float64Array(2*o);for(let u=0;u<o;u++){for(let c=u;c<o;c++)u>0&&(l[c]+=t[a(u-1,c)]**2),l[o+c]=t[a(c,c)]-l[c];if(u>0){s=u;for(let c=u+1;c<o;c++)l[o+c]>l[o+s]&&(s=c);if(f=l[o+s],f<=h||Number.isNaN(f))return t[a(u,u)]=f,{pivot:r,rank:u}}if(u!==s){t[a(s,s)]=t[a(u,u)];for(let c=0;c<u;c++)i(a(c,u),a(c,s));for(let c=s+1;c<o;c++)i(a(u,c),a(s,c));for(let c=u+1;c<s;c++)i(a(u,c),a(c,s));[l[u],l[s]]=[l[s],l[u]],[r[u],r[s]]=[r[s],r[u]]}f=Math.sqrt(f),t[a(u,u)]=f;for(let c=u+1;c<o;c++){let w=t[a(u,c)];for(let m=0;m<u;m++)w-=t[a(m,u)]*t[a(m,c)];t[a(u,c)]=w/f}}return{pivot:r,rank:o}}function Xt(e,n={}){let o=I(e),t=n.size??o.ncol;if(!Number.isInteger(t)||t<1)throw new RangeError(`size must be a positive integer (got ${t})`);if(t>o.ncol)throw new RangeError(`size cannot exceed the number of columns (${o.ncol})`);if(t>o.nrow)throw new RangeError(`size cannot exceed the number of rows (${o.nrow})`);let r=x(t,t);for(let a=0;a<t;a++)for(let i=0;i<=a;i++)r.data[i+a*t]=o.data[i+a*o.nrow];Mt(r);for(let a=0;a<t;a++)for(let i=a+1;i<t;i++)r.data[i+a*t]=r.data[a+i*t];return j(r)}function Mt(e){let n=e.nrow,o=e.data;for(let t=0;t<n;t++)if(o[t+t*n]===0)throw new Error(`element (${t+1}, ${t+1}) is zero, so the inverse cannot be computed`);for(let t=0;t<n;t++){let r=t*n;o[t+r]=1/o[t+r];let a=-o[t+r];for(let i=0;i<t;i++){let s=o[i+r];if(s!==0){for(let f=0;f<i;f++)o[f+r]+=s*o[f+i*n];o[i+r]=s*o[i+i*n]}}for(let i=0;i<t;i++)o[i+r]*=a}for(let t=0;t<n;t++){let r=o[t+t*n];if(t<n-1){let a=0;for(let i=t;i<n;i++)a+=o[t+i*n]*o[t+i*n];o[t+t*n]=a;for(let i=0;i<t;i++)o[i+t*n]*=r;for(let i=t+1;i<n;i++){let s=o[t+i*n];if(s!==0)for(let f=0;f<t;f++)o[f+t*n]+=s*o[f+i*n]}}else for(let a=0;a<=t;a++)o[a+t*n]*=r}}export{x as a,R as b,q as c,I as d,j as e,S as f,_ as g,X as h,vt as i,yt as j,ct as k,kt as l,Nt as m,xt as n,K as o,jt as p,qt as q,$t as r,Ot as s,Qt as t,dt as u,Pt as v,Wt as w,Ut as x,Xt as y};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.8.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 Kn,B as Ve,D as Xn,c as As,d as xn,e as xt,g as U,h as qt,i as Rn,o as je,p as ct,q as vn,r as _s,s as We,t as Gn,u as ys,x as Fs}from"./chunk-3I6EKGB6.js";import{a as vs,b as B,c as J,d as I,e as Ue,f as Z,g as P,h as C,i as X,j as Ss,k as W}from"./chunk-OHPHNE3O.js";function Es(n,t){return n?t?-1/0:0:t?0:1}function Ls(n,t){return n?t?0:1:t?-1/0:0}function Ts(n){return n?-1/0:0}function Qn(n,t,e,o,s){if(s){if(n>0)return NaN;if(n===0)return o?e:t;if(n===-1/0)return o?t:e}else{if(n<0||n>1)return NaN;if(n===0)return o?t:e;if(n===1)return o?e:t}}function On(n,t,e){let o=e?n:Math.log(n);if(o<=-Math.LN2)return e?{lower:t,logTarget:o}:{lower:t,logTarget:o,linearTarget:n};let s=e?-Math.expm1(n):1-n;return{lower:!t,logTarget:Math.log(s),linearTarget:s}}function Un(n){let{logTarget:t,lower:e,cdfLog:o,pdfLog:s,linearTarget:r,cdf:i,cdfBoth:c,dlogPdf:u}=n,a=(_,g)=>{if(r!==void 0&&i!==void 0&&g>-700){let l=i(_,e);if(l>0)return Math.log(l/r)}return g-t},d=_=>{if(c===void 0){let N=o(_,e);return[N,a(_,N)]}let[g,l]=c(_,e);return r!==void 0&&g>-700&&l>0?[g,Math.log(l/r)]:[g,g-t]},h=n.positive??!1,m=n.maxIter??200,f=h?Math.exp:_=>_,b=h?Math.log(n.lo):n.lo,p=h?Math.log(n.hi):n.hi,M=h?Math.log(n.x0):n.x0;M>b&&M<p||(M=Ds(b,p,NaN));let k=M,T=1/0;for(let _=0;_<m;_++){let g=f(M),[l,N]=d(g);if(Math.abs(N)<T&&(T=Math.abs(N),k=M),N===0)return g;N<0===e?b=M:p=M;let x=(e?1:-1)*Math.exp(s(g)-l+(h?Math.log(g):0)),v=N/x;if(h&&u!==void 0){let F=x*(1+g*u(g))-x*x,D=2*N*x/(2*x*x-N*F),R=D/v;R>=.5&&R<=2&&(v=D)}let A=M-v,S=A===M&&Number.isFinite(x)&&x!==0;!S&&(!Number.isFinite(A)||A<=b||A>=p)&&(A=Ds(b,p,M));let y=h?Math.abs(A-M)<=2e-16:Math.abs(A-M)<=4e-16*Math.abs(M);if(S||y)return E(f(k));if(b===p)break;M=A}return E(f(k));function E(_){if(!h||!(_>0)||!Number.isFinite(_)||Math.abs(Math.log(_))<=2)return _;let g=_,[l,N]=d(g);for(let x=0;x<4&&N!==0;x++){let v=(e?1:-1)*Math.exp(s(g)-l),A=g-N/v;if(!(A>0)||!Number.isFinite(A)||A===g)break;let[S,y]=d(A);if(!(Math.abs(y)<Math.abs(N)))break;g=A,l=S,N=y}return g}}function Ds(n,t,e){if(Number.isFinite(n)&&Number.isFinite(t))return n+(t-n)/2;if(Number.isFinite(n)){let o=Number.isFinite(e)?Math.max(e,n):n;return o+Math.max(1,Math.abs(o))}if(Number.isFinite(t)){let o=Number.isFinite(e)?Math.min(e,t):t;return o-Math.max(1,Math.abs(o))}return Number.isFinite(e)?e*2+1:0}var Wn=25,qs=1,Vn=30,Xr=12,Qr=1.5,ws=1.772453850905516,Ye=6.283185307179586,Ct=new Float64Array(Vn+2),jn=new Float64Array(Vn+3),Rt=new Float64Array(Vn);function Or(n,t,e){let o=0;for(let s=t-1;s>=0;s--)o=o*e+n[s];return o}function Ur(n,t,e){let o=t-n,s=n*t;Ct[1]=1,jn[1]=0,jn[2]=1;for(let r=3;r<=e+1;r++){let i=2/r*(o*Ct[r-2]-s*jn[r-2]),c=0;for(let u=2;u<=r-2;u++)c+=Ct[u]*Ct[r-u];Ct[r-1]=(i-c)/2,jn[r]=i}Rt[0]=1;for(let r=1;r<e;r++){let i=0;for(let c=1;c<=r;c++)i+=Ct[c+1]*Rt[r-c];Rt[r]=-i}}function Cs(n,t,e,o){let s=e,r=1,i=0;for(let c=0;c<Xr&&s>1;c++){let u;if(o)u=c===0?0:r*Or(Rt,s,n);else{let a=0;for(let d=s-1;d>=1;d--)a=a*n+Rt[d];u=r*a}if(i+=u,c>1&&Math.abs(u)<=1e-17*Math.abs(i))break;for(let a=0;a+2<s;a++)Rt[a]=(a+1)*Rt[a+2];s-=2,r/=t}return i}var Ps=[.9602898564975363,.7966664774136267,.525532409916329,.1834346424956498],jr=[.10122853629037626,.22238103445337448,.31370664587788727,.362683783378362],Wr=.15729920705028513;function Pt(n){if(n<.5||n>=1)return .5*As(n);let t=(1+n)/2,e=(1-n)/2,o=0;for(let s=0;s<4;s++){let r=t+e*Ps[s],i=t-e*Ps[s];o+=jr[s]*(Math.exp(-r*r)+Math.exp(-i*i))}return .5*Wr+e*o/ws}function Vr(n){let t=n*n,e=Math.ceil(4+120/t),o=0;for(let s=e;s>=1;s--)o=-s*(s+.5)/(t+2*s+1.5+o);return-1/(4*ws*n*(t+1.5+o))}function zs(n,t,e,o,s,r){let i=B(n,t),c=i[0],u=n*t/c;if(!(u>=Wn)||!Number.isFinite(c))return;let a=n/c,d=t/c,h=u/c,m=e[0];if(Math.abs(m-a)>2*h)return;let f=P(i,e),b=Z(f,[n,0]),p=b[0]+b[1],M=I(vn(n,f),vn(t,P(i,o))),k=M[0]+M[1],T=2*k/u;if(!(T<=qs*qs))return;let E=Math.sqrt(T),_=p<0?-E:E,g=E<=.5?20:E<=.75?24:Vn;Ur(a,d,g);let l=Math.exp(-(ct(n)+ct(t)-ct(c))),N=Math.sqrt(k),x=p<0;if(N<Qr){let S=Math.exp(-M[0])*(1-M[1])*l*Cs(_,u,g,!1)/Math.sqrt(Ye*u),y=p<0?N:-N,F=(y>=0?Pt(y):1-Pt(-y))-S,D=(y<=0?Pt(-y):1-Pt(y))+S,R=s?F:D;return r?[s===x?Math.log(R):Math.log1p(-(x?F:D)),R]:[NaN,R]}let v=Vr(N)+l*(Math.sqrt(u/Ye)/Math.abs(p)+Cs(_,u,g,!0)/(E*Math.sqrt(Ye*u))),A;return M[0]<700?A=Math.exp(-M[0])*(1-M[1])*v:A=Math.exp(700-M[0])*(1-M[1])*v*Math.exp(-700),s===x?[r?-M[0]-M[1]+Math.log(v):NaN,A]:[r?Math.log1p(-A):NaN,1-A]}var Ks=15,Xs=40,Yr=.3,$r=.1,Hr=500,An=30,Bs=2**-56,$e=new Float64Array(An+1);{let n=1;$e[0]=1;for(let t=1;t<=An;t++)n*=2*t*(2*t+1),$e[t]=1/n}var Sn=new Float64Array(An+1),Jr=1.772453850905516,Zr=[.15915494309189535,-9839338337591243e-33];function tc(n,t,e){if(n===.5){let u=Math.sqrt(t),a=Jr/u*(u>=1?xn(u):2*Math.exp(t)*Pt(u));return a*(1+e*(1-n/t-1/(t*a)))}let o=I(B(t,-n),[e,0]),s=o[0],r=0;for(let u=Math.ceil(100/t+n/2)+10;u>2;u--)r=-u*(u-n)/(s+(2*u+1)+r);let i=[r,0];for(let u=2;u>=1;u--)i=X(C(B(u,-n),-u),I(I(o,[2*u+1,0]),i));let c=X([1,0],I(I(o,[1,0]),i));return c[0]+c[1]}function Gs(n,t){let e=0;for(let o=1;o<=t;o++)e+=(o*n-t)*Sn[t-o]*$e[o];return Sn[t]=e/t}function He(n,t,e,o,s,r){let i=o[0];if(!(i<=Yr))return;let c=-(n+(t-1)/2)*Math.log1p(-i),u=t>=1?t-1/3:Math.pow(.5,1/t),a=c>=u;if(c>Hr||a&&c<$r)return;let d=B(t,-1),h=I([n,0],[d[0]/2,d[1]/2]),m=W(e),f=[-m[0],-m[1]],b=P(h,f),p=b[0]+b[1],M=b[1]-(p-b[0]),k=f[0],T=h[0],E=Z(f,o),_=t*Math.log1p((E[0]+E[1])/i)-(t-1)/2*k,{e:g}=Gn(n,t,e,o),l=P(X(J(n,t),B(n,t)),Zr),N=Math.sqrt(l[0]),x=J(N,N),v=Math.expm1(_-g[1])+(l[0]-x[0]-x[1]+l[1])/(2*l[0]),A=k/2*(k/2),S=4*T*T,y;if(Sn[0]=1,a){let R=tc(t,p,M);y=R;let q=1,G=t,Q=1/0;for(let K=1;K<=An;K++){R=(G*(G+1)*R+q*(p+G+1))/S,q*=A,G+=2;let $=Gs(t,K)*R,ot=Math.abs($);if(ot>Q||(y+=$,ot<=Bs*y))break;Q=ot}}else{let R=0,q=1;for(let K=1;K<=An&&!(Math.abs(Gs(t,K))*q*A<=Bs);K++)q*=A,R=K;let G=t+2*R,Q=q*Fs(G,p)/G;y=Sn[R]*Q;for(let K=R;K>=1;K--)q/=A,G-=2,Q=(S*Q+q*(p+G+1))/(G*(G+1)),y+=Sn[K-1]*Q;y*=1+M*(1-t/p+1/(p*Q))}let F=Math.exp(-g[0])*(N*y),D=F+F*v;if(D>=1e-290)return s===a?[r?Math.log(D):NaN,D]:[r?Math.log1p(-D):NaN,1-D]}var z=4503599627370496,w=2220446049250313e-31;function Us(n,t,e,o){return We(n,t,e,o,!0)+Math.log(n)+Math.log(t)-Math.log(n+t)}function js(n,t,e,o){return We(n,t,e,o,!1)*(n*t/(n+t))}var Ws=22250738585072014e-324*1e3;function Vs(n,t,e,o,s){let{e:r}=Gn(n,t,e,o),i=s*(n*t/(n+t))/Math.sqrt(2*Math.PI*n*(t/(n+t)));if(!(r[0]<1400)||!Number.isFinite(i)||i===0)return;let c=Math.exp(700-r[0])*(1-r[1])*i*Math.exp(-700);return c>0?c:void 0}function nc(n,t,e){let o=(1-t)*e,s=o/(n+1),r=s,i=o,c=2,u=0;for(;(Math.abs(s)>Rn*Math.abs(u+r)||c<4)&&!(c>1e7);)o=(c-t)*e/c,i*=o,s=i/(n+c),u+=s,c+=1;return u+r}function Qs(n,t,e,o){let s=e[0],r=n*(Math.log(s)+e[1]/s)+Ve(n,t)-je(n),i=Math.exp(r),c=-Math.expm1(r)-i*n*nc(n,t,s);return o?Math.log(c):c}function Yn(n,t,e,o,s){let r=e[0],i=1/n,c=(1-t)*r,u=c/(n+1),a=u,d=c,h=2,m=0,f=Rn*i;for(;Math.abs(u)>f;)c=(h-t)*r/h,d*=c,u=d/(n+h),m+=u,h+=1;m+=a,m+=i;let b=oc(e);if(!s){let M=js(n,t,e,o);if(M>Ws)return m*M/Math.exp(t*b);let k=Vs(n,t,e,o,m/Math.exp(t*b));if(k!==void 0)return k}let p=Math.log(m)+Us(n,t,e,o)-t*b;return s?p:Math.exp(p)}var tt=new Float64Array(2);function $n(n,t,e,o){let s=n/e,r=e*s,i=134217729*e,c=i-(i-e),u=e-c,a=134217729*s,d=a-(a-s),h=s-d,f=c*d-r+c*h+u*d+u*h+o*s,b=r+f,p=f-(b-r),M=-b,k=-p,T=n+M,E=T-n,_=n-(T-E)+(M-E),g=t+k,l=g-t,N=t-(g-l)+(k-l),x=_+g,v=T+x,S=x-(v-T)+N,y=v+S,F=S-(y-v),D=y/e,R=e*D,q=134217729*e,G=q-(q-e),Q=e-G,K=134217729*D,$=K-(K-D),ot=D-$,Gt=G*$-R+G*ot+Q*$+Q*ot+o*D,Kt=R+Gt,Xt=Gt-(Kt-R),Qt=-Kt,se=-Xt,ut=y+Qt,st=ut-y,re=y-(ut-st)+(Qt-st),at=F+se,Ot=at-F,Ut=F-(at-Ot)+(se-Ot),jt=re+at,St=ut+jt,Wt=jt-(St-ut)+Ut,ce=St+Wt,ie=Wt-(ce-St),Vt=ce/e,At=s+D,_t=D-(At-s),ft=At+Vt,yt=ft-At,Ln=At-(ft-yt)+(Vt-yt),Ft=_t+0,Et=Ft-_t,Tn=_t-(Ft-Et)+(0-Et),Dn=Ln+Ft,O=ft+Dn,Lt=Dn-(O-ft)+Tn,Yt=O+Lt,$t=Lt-(Yt-O);tt[0]=Yt,tt[1]=$t}function Os(n,t,e,o,s){if(!vs()||Math.max(n,t)>=2**52)return ec(n,t,e,o,s);let r=e[0],i=e[1];s&&($n(e[0],e[1],o[0],o[1]),r=tt[0],i=tt[1]);let c=t+-1,u=c-t,a=t-(c-u)+(-1-u),d=n+t,h=d-n,m=n-(d-h)+(t-h),f=s?c:d,b=s?a:m,p=s?d:c,M=s?m:a,k=n,T=n,E=n+1,_=1,g=n+1,l=n+2,N=s?-1:1,x=-N,v=0,A=0,S=1,y=0,F=1,D=0,R=1,q=0,G=1,Q=0;for(let K=0;K<1e5;K++){let $=r*k,ot=134217729*r,Fn=ot-(ot-r),Gt=r-Fn,Kt=134217729*k,Xt=Kt-(Kt-k),Qt=k-Xt,ut=Fn*Xt-$+Fn*Qt+Gt*Xt+Gt*Qt+i*k,st=$+ut,re=ut-(st-$),at=st*f,Ot=134217729*st,Ut=Ot-(Ot-st),jt=st-Ut,St=134217729*f,En=St-(St-f),Wt=f-En,ie=Ut*En-at+Ut*Wt+jt*En+jt*Wt+(st*b+re*f),Vt=at+ie,At=ie-(Vt-at),_t=T*E,ft=134217729*T,yt=ft-(ft-T),Ln=T-yt,Ft=134217729*E,Et=Ft-(Ft-E),Tn=E-Et,Dn=yt*Et-_t+yt*Tn+Ln*Et+Ln*Tn;$n(Vt,At,_t,Dn);let O=tt[0],ue=tt[1],Lt=v*O,Yt=134217729*v,$t=Yt-(Yt-v),oo=v-$t,so=134217729*O,ae=so-(so-O),ro=O-ae,co=$t*ae-Lt+$t*ro+oo*ae+oo*ro+(v*ue+A*O),io=Lt+co,Nr=co-(io-Lt),uo=-io,ao=-Nr,qn=F+uo,fo=qn-F,br=F-(qn-fo)+(uo-fo),fe=D+ao,lo=fe-D,gr=D-(fe-lo)+(ao-lo),ho=br+fe,le=qn+ho,Mo=ho-(le-qn)+gr,mo=le+Mo,kr=Mo-(mo-le),he=S*O,po=134217729*S,Me=po-(po-S),No=S-Me,bo=134217729*O,me=bo-(bo-O),go=O-me,ko=Me*me-he+Me*go+No*me+No*go+(S*ue+y*O),Io=he+ko,Ir=ko-(Io-he),xo=-Io,Ro=-Ir,Cn=R+xo,vo=Cn-R,xr=R-(Cn-vo)+(xo-vo),de=q+Ro,So=de-q,Rr=q-(de-So)+(Ro-So),Ao=xr+de,pe=Cn+Ao,_o=Ao-(pe-Cn)+Rr,yo=pe+_o,vr=_o-(yo-pe);v=F,A=D,F=mo,D=kr,S=R,y=q,R=yo,q=vr;let Ne=r*_,Fo=134217729*r,be=Fo-(Fo-r),Eo=r-be,Lo=134217729*_,ge=Lo-(Lo-_),To=_-ge,Do=be*ge-Ne+be*To+Eo*ge+Eo*To+i*_,Tt=Ne+Do,Sr=Do-(Tt-Ne),ke=Tt*p,qo=134217729*Tt,Ie=qo-(qo-Tt),Co=Tt-Ie,Po=134217729*p,xe=Po-(Po-p),wo=p-xe,zo=Ie*xe-ke+Ie*wo+Co*xe+Co*wo+(Tt*M+Sr*p),Bo=ke+zo,Ar=zo-(Bo-ke),Go=g*l,Ko=134217729*g,Re=Ko-(Ko-g),Xo=g-Re,Qo=134217729*l,ve=Qo-(Qo-l),Oo=l-ve,_r=Re*ve-Go+Re*Oo+Xo*ve+Xo*Oo;$n(Bo,Ar,Go,_r);let H=tt[0],Uo=tt[1],Se=v*H,jo=134217729*v,Ae=jo-(jo-v),Wo=v-Ae,Vo=134217729*H,_e=Vo-(Vo-H),Yo=H-_e,$o=Ae*_e-Se+Ae*Yo+Wo*_e+Wo*Yo+(v*Uo+A*H),ye=Se+$o,Ho=$o-(ye-Se),Pn=F+ye,Jo=Pn-F,yr=F-(Pn-Jo)+(ye-Jo),Fe=D+Ho,Zo=Fe-D,Fr=D-(Fe-Zo)+(Ho-Zo),ts=yr+Fe,Ee=Pn+ts,ns=ts-(Ee-Pn)+Fr,Ht=Ee+ns,es=ns-(Ht-Ee),Le=S*H,os=134217729*S,Te=os-(os-S),ss=S-Te,rs=134217729*H,De=rs-(rs-H),cs=H-De,is=Te*De-Le+Te*cs+ss*De+ss*cs+(S*Uo+y*H),qe=Le+is,us=is-(qe-Le),wn=R+qe,as=wn-R,Er=R-(wn-as)+(qe-as),Ce=q+us,fs=Ce-q,Lr=q-(Ce-fs)+(us-fs),ls=Er+Ce,Pe=wn+ls,hs=ls-(Pe-wn)+Lr,Dt=Pe+hs,Ms=hs-(Dt-Pe);if(v=F,A=D,F=Ht,D=es,S=R,y=q,R=Dt,q=Ms,Dt!==0){$n(Ht,es,Dt,Ms);let j=tt[0],lt=tt[1],rt=j!==0?Math.abs((G-j)/j):1;if(G=j,Q=lt,rt<Rn&&K>1)break}let zn=f+N,ms=zn-f,Tr=f-(zn-ms)+(N-ms),we=b+0,ds=we-b,Dr=b-(we-ds)+(0-ds),ps=Tr+we,ze=zn+ps,Ns=ps-(ze-zn)+Dr,bs=ze+Ns,qr=Ns-(bs-ze);f=bs,b=qr;let Bn=p+x,gs=Bn-p,Cr=p-(Bn-gs)+(x-gs),Be=M+0,ks=Be-M,Pr=M-(Be-ks)+(0-ks),Is=Cr+Be,Ge=Bn+Is,xs=Is-(Ge-Bn)+Pr,Rs=Ge+xs,wr=xs-(Rs-Ge);if(p=Rs,M=wr,_+=1,k+=1,T+=2,E+=2,g+=2,l+=2,Math.abs(Dt)+Math.abs(Ht)>z){let j=v*w,lt=134217729*v,rt=lt-(lt-v),Jt=v-rt,Zt=134217729*w,ht=Zt-(Zt-w),tn=w-ht,nn=rt*ht-j+rt*tn+Jt*ht+Jt*tn+A*w,en=j+nn,Ke=nn-(en-j);v=en,A=Ke;let Mt=F*w,on=134217729*F,mt=on-(on-F),sn=F-mt,rn=134217729*w,dt=rn-(rn-w),cn=w-dt,un=mt*dt-Mt+mt*cn+sn*dt+sn*cn+D*w,an=Mt+un,Xe=un-(an-Mt);F=an,D=Xe;let pt=S*w,fn=134217729*S,Nt=fn-(fn-S),ln=S-Nt,hn=134217729*w,bt=hn-(hn-w),Mn=w-bt,mn=Nt*bt-pt+Nt*Mn+ln*bt+ln*Mn+y*w,dn=pt+mn,Qe=mn-(dn-pt);S=dn,y=Qe;let gt=R*w,pn=134217729*R,kt=pn-(pn-R),Nn=R-kt,bn=134217729*w,It=bn-(bn-w),gn=w-It,kn=kt*It-gt+kt*gn+Nn*It+Nn*gn+q*w,In=gt+kn,Oe=kn-(In-gt);R=In,q=Oe}if(Math.abs(Dt)<w||Math.abs(Ht)<w){let j=v*z,lt=134217729*v,rt=lt-(lt-v),Jt=v-rt,Zt=134217729*z,ht=Zt-(Zt-z),tn=z-ht,nn=rt*ht-j+rt*tn+Jt*ht+Jt*tn+A*z,en=j+nn,Ke=nn-(en-j);v=en,A=Ke;let Mt=F*z,on=134217729*F,mt=on-(on-F),sn=F-mt,rn=134217729*z,dt=rn-(rn-z),cn=z-dt,un=mt*dt-Mt+mt*cn+sn*dt+sn*cn+D*z,an=Mt+un,Xe=un-(an-Mt);F=an,D=Xe;let pt=S*z,fn=134217729*S,Nt=fn-(fn-S),ln=S-Nt,hn=134217729*z,bt=hn-(hn-z),Mn=z-bt,mn=Nt*bt-pt+Nt*Mn+ln*bt+ln*Mn+y*z,dn=pt+mn,Qe=mn-(dn-pt);S=dn,y=Qe;let gt=R*z,pn=134217729*R,kt=pn-(pn-R),Nn=R-kt,bn=134217729*z,It=bn-(bn-z),gn=z-It,kn=kt*It-gt+kt*gn+Nn*It+Nn*gn+q*z,In=gt+kn,Oe=kn-(In-gt);R=In,q=Oe}}return G+Q}function ec(n,t,e,o,s){let r=s?X(e,o):e,i=Math.max(n,t)>=2**52,c=n,u=s?B(t,-1):B(n,t),a=n,d=n+1,h=1,m=s?B(n,t):B(t,-1),f=n+1,b=n+2,p=[n,0],M=[n,0],k=B(n,1),T=B(n,1),E=B(n,2),_=s?-1:1,g=[0,0],l=[1,0],N=[1,0],x=[1,0],v=[1,0];for(let A=0;A<1e5;A++){let S=i?X(P(P(r,p),u),P(M,k)):X(P(C(r,c),u),J(a,d)),y=Z(N,P(g,S)),F=Z(x,P(l,S));if(g=N,N=y,l=x,x=F,S=X(P(C(r,h),m),i?P(T,E):J(f,b)),y=I(N,P(g,S)),F=I(x,P(l,S)),g=N,N=y,l=x,x=F,F[0]!==0){let R=X(y,F),q=R[0]!==0?Math.abs((v[0]-R[0])/R[0]):1;if(v=R,q<Rn&&A>1)break}u=I(u,[_,0]),m=I(m,[-_,0]),h+=1,i?(p=I(p,[1,0]),M=I(M,[2,0]),k=I(k,[2,0]),T=I(T,[2,0]),E=I(E,[2,0])):(c+=1,a+=2,d+=2,f+=2,b+=2),Math.abs(F[0])+Math.abs(y[0])>z&&(g=C(g,w),N=C(N,w),l=C(l,w),x=C(x,w)),(Math.abs(F[0])<w||Math.abs(y[0])<w)&&(g=C(g,z),N=C(N,z),l=C(l,z),x=C(x,z))}return v[0]+v[1]}function Hn(n,t,e){return t*e<=1&&e<=.95}function Jn(n,t,e){return e<=n/(n+t)}function vt(n,t,e,o,s){let r=e[0],i=o[0],u=r*(n+t-2)-(n-1)<0?Os(n,t,e,o,!1):Os(n,t,e,o,!0)/i;if(!s){let d=js(n,t,e,o);if(d>Ws)return d*(u/n);let h=Vs(n,t,e,o,u/n);if(h!==void 0)return h}let a=Us(n,t,e,o)-Math.log(n)+Math.log(u);return s?a:Math.exp(a)}function s0(n,t,e,o,s,r){if(e<=0)return s?r?-1/0:0:r?0:1;if(o<=0)return s?r?0:1:r?-1/0:0;let i=e<=o?[e,0]:B(1,-o),c=e<=o?B(1,-e):[o,0];return Je(n,t,i,c,s,r)}function Je(n,t,e,o,s,r){let i=Ze(n,t,e,o,s,r);return r?i[0]:i[1]}function Ys(n,t,e,o,s){return Ze(n,t,e,o,s,!0)}function r0(n,t,e,o,s){if(e<=0)return s?[-1/0,0]:[0,1];if(o<=0)return s?[0,1]:[-1/0,0];let r=e<=o?[e,0]:B(1,-o),i=e<=o?B(1,-e):[o,0];return Ze(n,t,r,i,s,!0)}function Ze(n,t,e,o,s,r){if(e[0]<=0)return s?[-1/0,0]:[0,1];if(o[0]<=0)return s?[0,1]:[-1/0,0];let i=22250738585072014e-324;if(e[0]<i||o[0]<i){let l=e[0]<i,[N,x,v]=l?[n,t,e]:[t,n,o],A=I(C(W(v),N),[Ve(N,x)-je(N),0]),S=A[0]+A[1],y=l===s,F=Math.exp(A[0])*(1+A[1]);return y?[S,F]:[r?Math.log1p(-F):NaN,-Math.expm1(S)]}if(n>=Wn&&t>=Wn){let l=zs(n,t,e,o,s,r);if(l!==void 0)return l}let[c,u,a,d]=s?[n,t,e,o]:[t,n,o,e],[h,m,f,b]=s?[t,n,o,e]:[n,t,e,o],p=Math.max(n,t)>=Ks&&Math.min(n,t)<=Xs,M=(l,N)=>{if(p)return n>=t?He(n,t,e,o,l,N):He(t,n,o,e,!l,N)},k=(l,N)=>{if(!r)return[NaN,l];if(l>.5){let x=N();if(x!==void 0)return[Math.log1p(-x),l]}return[Math.log(l),l]},T=()=>{if(Hn(h,m,f[0]))return Yn(h,m,f,b,!1);if(Hn(c,u,a[0])){let l=Qs(c,u,a,!1);return c*Math.abs(Math.log(a[0]))>32*l&&Jn(h,m,f[0])?M(!s,!1)?.[1]??vt(h,m,f,b,!1):l}if(Jn(h,m,f[0]))return M(!s,!1)?.[1]??vt(h,m,f,b,!1)},E=1e-290;if(Hn(c,u,a[0])){let l=Yn(c,u,a,d,!1);return r&&l<E?[Yn(c,u,a,d,!0),l]:k(l,T)}if(Hn(h,m,f[0])){let l=Qs(h,m,f,!1);if(h*Math.abs(Math.log(f[0]))>32*l&&Jn(c,u,a[0])){let N=M(s,r);if(N!==void 0)return N;let x=vt(c,u,a,d,!1);return r&&x<E?[vt(c,u,a,d,!0),x]:k(x,T)}return k(l,()=>Yn(h,m,f,b,!1))}let _=M(s,r);if(_!==void 0)return _;if(Jn(c,u,a[0])){let l=vt(c,u,a,d,!1);return r&&l<E?[vt(c,u,a,d,!0),l]:k(l,T)}let g=vt(h,m,f,b,!1);return[r?Math.log1p(-g):NaN,1-g]}function oc(n){return Math.log1p(-n[0])-n[1]/(1-n[0])}var nt=.9189385332046728,sc=.7978845608028654,$s=[.6931471805599453,23190468138462996e-33];function rc(n){let t=Math.round(n[0]/$s[0]),e=I(n,C($s,-t)),o=[e[0]/256,e[1]/256],s=[1,0],r=[1,0];for(let c=1;c<=12&&(s=P(s,o),s=[s[0]/c,s[1]/c],r=I(r,s),!(Math.abs(s[0])<1e-34));c++);for(let c=0;c<8;c++)r=P(r,r);let i=2**t;return[r[0]*i,r[1]*i]}function cc(n,t){if(Math.abs(n[0])<1e-6){let e=P(n,n),o=C(P(e,n),1/6);return I(I([e[0]/2,e[1]/2],o),[e[0]*e[0]/24,0])}return I(I(t,[-1,0]),[-n[0],-n[1]])}function Js(n){if(Math.abs(n)<.1){let t=n*n/2,e=t;for(let o=3;o<30&&(t*=n/o,e+=t,!(Math.abs(t)<=1e-17*e));o++);return e}return Math.expm1(n)-n}function te(n){return n<0?sc/xn(-n*Math.SQRT1_2):Math.exp(-.5*n*n-nt)/U(n)}function to(n,t){let{a:e,t:o,delta:s}=n,r=Math.exp(t),i=Math.exp(t/2),c=o*i,u=c-s,a=Js(t);if(n.kind==="cdfQ"||n.kind==="cdfP"){let f=e*r,b=n.kind==="cdfQ",p=Kn(e,f,!b,!0),M=e*Math.exp(ys(e,f,!0)-p),k=b?-1:1,T=Math.log(o/2)+t/2-.5*u*u-nt+p,E=.5-u*c/2+k*M,_=-(c*c)/4-u*c/4+k*M*(e-f)-M*M;return[T,E,_]}let d=n.logC-e*a,h=-e*Math.expm1(t),m=-e*r;if(n.kind==="cdf"){let f=te(u);d+=U(u,{logP:!0}),h+=c/2*f,m+=c/4*f-c/2*(c/2)*f*(u+f)}else d+=t/2-.5*u*u-nt,h+=.5-u*c/2,m+=-(c*c)/4-u*c/4;return[d,h,m]}function Zs(n){let t=0,[e,o,s]=to(n,t);for(let i=0;i<200;i++){let c=s<0?-o/s:Math.sign(o);Number.isFinite(c)||(c=Math.sign(o)||0),c=Math.max(-4,Math.min(4,c));let u=t+c,a=to(n,u);for(let h=0;h<60&&!(a[0]>=e);h++)c/=2,u=t+c,a=to(n,u);if(!(a[0]>=e))break;let d=Math.abs(c)<1e-10*Math.max(1,Math.abs(t));if(t=u,[e,o,s]=a,d)break}let r=s<0?Math.min(1/Math.sqrt(-s),10):1;return{w:t,sigma:r,L:e}}function ic(n){let t=n[0],e=n[1]*te(t);if(t>-5)return B(U(t,{logP:!0}),e);let o=P(n,n);return I([-o[0]/2,-o[1]/2],[Math.log(.5*xn(-t*Math.SQRT1_2)),0])}function uc(n,t,e,o=1/0){let{a:s,t:r,delta:i}=n;if(!e&&(n.kind==="cdf"||n.kind==="pdf")){let f=t[0]+t[1],b=Math.exp(f/2),p=s*Js(f),M=r*b,k=M-i,T=Math.exp(n.logC-p);if(n.kind==="cdf"){let E=T*U(k);if((p+te(k)*Math.abs(M))*E<=4*o)return[E,0]}else{let E=T*Math.exp(-.5*k*k-nt)*b;if((p+Math.abs(k*M)+k*k)*E<=4*o)return[E,0]}}let c=rc([t[0]/2,t[1]/2]),u=P(c,c);if(n.kind==="cdfQ"||n.kind==="cdfP"){let f=I(C(c,r),[-i,0]),b=P(f,f),p=s*u[0]+s*u[1],M=n.kind==="cdfP";if(e){let T=Math.log(r/2)+Math.log(c[0])+c[1]/c[0]-nt+Kn(s,p,M,!0);return I([-b[0]/2,-b[1]/2],[T,0])}let k=Kn(s,p,M,!1);return[r/2*(c[0]+c[1])*Math.exp(-.5*b[0]-nt)*(1-b[1]/2)*k,0]}let a=C(cc(t,u),s);if(!(a[0]<1/0))return[e?-1/0:0,0];let d=I(C(c,r),[-i,0]),h=d[0];if(n.kind==="cdf"){if(e)return I([n.logC-a[0],-a[1]],ic(d));let f=d[1]*te(h);return[Math.exp(n.logC-a[0])*(1-a[1])*U(h)*(1+f),0]}let m=P(d,d);return e?I(I([n.logC-a[0],-a[1]],[-m[0]/2,-m[1]/2]),[t[0]/2-nt,t[1]/2]):[Math.exp(n.logC-a[0]-.5*m[0]-nt)*(1-a[1]-m[1]/2)*(c[0]+c[1]),0]}function Hs(n,t,e,o,s,r,i,c){let u=0,a=h=>{let m=Math.exp(-h),f=e/2*(h-Math.expm1(-h)),b=uc(n,B(t,f),s,c),p=e/2*(1+m);return s?Math.exp(b[0]-r)*(1+b[1])*p:b[0]*p},d=i?1:0;i||(u+=a(0));for(let h of[1,-1]){let m=0;for(let f=i?d:1;f<1e5;f+=i?2:1){let b=h*f*o,p=a(b);u+=p;let M=Math.abs(u);if(p>1e-19*M)m=0;else if(m++,m>=3)break;if(Math.abs(b)>40)break}}return u}function wt(n,t){if(n.kind==="cdf"){let e=Zs(n),o=Math.exp(e.w/2),s=Math.min(1/Math.sqrt(n.a*Math.exp(e.w)),10);if(Math.abs(n.t)*o*s/2>2){if(n.t>0){let r=Zn({...n,kind:"cdfQ"},t);return{lin:U(-n.delta)+r.lin,log:t?ac(U(-n.delta,{logP:!0}),r.log):NaN}}return Zn({...n,t:-n.t,delta:-n.delta,kind:"cdfP"},t)}return Zn(n,t,e)}return Zn(n,t)}function ac(n,t){return n===-1/0?t:t===-1/0?n:n>t?n+Math.log1p(Math.exp(t-n)):t+Math.log1p(Math.exp(n-t))}function Zn(n,t,e){let{w:o,sigma:s,L:r}=e??Zs(n);if(!t&&r<-800)return{lin:0,log:NaN};let i=r<-650||r>650,c=i?r:0,u=i?0:Math.exp(r),a=i?Math.max(1e-15,2e-16*Math.abs(r)):1e-15,d=.5,h=Hs(n,o,s,d,i,c,!1,u)*d;for(let f=0;f<6;f++){let b=Hs(n,o,s,d/2,i,c,!0,u)*(d/2),p=h/2+b;d/=2;let M=Math.abs(p-h)<=a*Math.abs(p);if(h=p,M)break}return i?{lin:c>-700?Math.exp(c)*h:Math.exp(c+700)*h*Math.exp(-700),log:c+Math.log(h)}:{lin:h,log:Math.log(h)}}function et(n,t,e,o){return{a:n,t,delta:e,kind:o,logC:.5*Math.log(n)-nt-ct(n)}}function _n(n,t){return 1e10*(Math.abs(t)+10)*Math.sqrt(n+1)}function tr(n,t,e){let o=_n(t,e),s=Math.sign(n),r=Math.min(Math.abs(n),o),i=s>0?et(t,-r,-e,"cdf"):et(t,-r,e,"cdf"),c=wt(i,!0).log;return Math.abs(n)>o?c+2*t*(Math.log(o)-Math.log(Math.abs(n))):c}function nr(n,t,e,o){let s=t/2;if(Math.abs(n)>_n(s,e)){let c=tr(n,s,e);return(n>0?!o:o)?{lin:Math.exp(c),log:c}:{lin:-Math.expm1(c),log:Math.log1p(-Math.exp(c))}}let r=wt(o?et(s,n,e,"cdf"):et(s,-n,-e,"cdf"),!0);if(r.lin<=.5)return r;let i;return{lin:r.lin,get log(){return i??=Math.log1p(-wt(o?et(s,-n,-e,"cdf"):et(s,n,e,"cdf"),!1).lin),i}}}function fc(n,t,e,o,s){if(!s){let i=t/2;if(Math.abs(n)<=_n(i,e))return wt(o?et(i,n,e,"cdf"):et(i,-n,-e,"cdf"),!1).lin}let r=nr(n,t,e,o);return s?r.log:r.lin}function er(n,t,e,o){let s=t/2,r=_n(s,e);if(Math.abs(n)>r){let c=Math.sign(n)*r,u=wt(et(s,c,e,"pdf"),!0).log+(2*s+1)*(Math.log(r)-Math.log(Math.abs(n)));return o?u:Math.exp(u)}let i=wt(et(s,n,e,"pdf"),o);return o?i.log:i.lin}function or(n,t,e,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(e))return NaN;if(t<=0)return NaN;if(!Number.isFinite(n)||!Number.isFinite(e))return o?-1/0:0;if(t===1/0){let s=n-e,r=-.5*s*s-nt;return o?r:Math.exp(r)}return er(n,t,e,o)}function sr(n,t,e,o,s){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(e))return NaN;if(t<=0)return NaN;let r=o?s?-1/0:0:s?0:1,i=o?s?0:1:s?-1/0:0;return n===1/0?i:n===-1/0||e===1/0?r:e===-1/0?i:t===1/0?U(n-e,{lowerTail:o,logP:s}):n===0?U(-e,{lowerTail:o,logP:s}):fc(n,t,e,o,s)}function rr(n,t,e,o,s){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(e))return NaN;if(t<=0)return NaN;let r=Qn(n,-1/0,1/0,o,s);if(r!==void 0)return r;if(t===1/0)return e+qt(n,{lowerTail:o,logP:s});if(!Number.isFinite(e))return NaN;let{lower:i,logTarget:c,linearTarget:u}=On(n,o,s),a=qt(c,{lowerTail:i,logP:!0}),d=e+a*Math.sqrt(1+e*e/(2*t)),h=U(-e,{lowerTail:i,logP:!0}),m=i?c>h:c<h;if(c===h)return 0;let f=m?1:-1,b=f>0?i:!i,p=NaN,M=!0,k={lin:NaN,log:NaN},T=(l,N,x)=>((l!==p||N!==M)&&(k=nr(f*l,t,e,f>0?N:!N),p=l,M=N),x?k.log:k.lin),E=_n(t/2,e),_=1/0;if(!b){let l=tr(f*E,t/2,e);if(c<l){let N=Math.log(E)+(l-c)/t;return N>709.78?f*(1/0):f*Math.exp(N)}_=E}let g=Un({logTarget:c,...u!==void 0&&{linearTarget:u},lower:b,cdf:(l,N)=>T(l,N,!1),cdfLog:(l,N)=>T(l,N,!0),pdfLog:l=>er(f*l,t,e,!0),x0:Math.min(Math.abs(d)>0&&Number.isFinite(d)&&Math.sign(d)===f?Math.abs(d):1,_/2),lo:0,hi:_,positive:!0});return f*g}var cr=.9189385332046728,lc=[-.9189385332046728,38782941580672414e-33];function ir(n,t,e){let o=t/2,s=ct(o+.5)-ct(o)-_s(o,o+.5),r=J(n,n),i=r[0]/t;if(!(i<1e30)){let a=I(C(W([Math.abs(n),0]),2),Ue(W([t,0])));Number.isFinite(i)&&(a=I(a,[Math.log1p(1/i),0]));let d=I(I(Ue(P(a,B(o,.5))),[s,0]),lc);return e?d[0]+d[1]:Math.exp(d[0])*(1+d[1])}let c;if(r[0]>.2*t){let a=W(I([1,0],Ss(r,t)));c=I([s,0],C(a,-o))}else{let a=C(I([t,0],r),.5);c=I(I(vn(o,a),C(r,-.5)),[s,0])}return e?c[0]+c[1]-cr-.5*Math.log1p(i):Math.exp(c[0])*(1+c[1])/Math.sqrt(2*Math.PI*(1+i))}function hc(n,t,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t<=0)return NaN;if(!Number.isFinite(n))return Ts(e);if(!Number.isFinite(t)){let o=-.5*n*n-cr;return e?o:Math.exp(o)}return ir(n,t,e)}function ne(n,t,e){let o=n*n;if(!(t/(t+o)>1e-250)){let u=Z(W([t,0]),C(W([n,0]),2)),a=I(C(u,t/2),[-Math.log(t/2)-Xn(t/2,.5)-Math.LN2,0]);return e?a[0]+a[1]:Math.exp(a[0])*(1+a[1])}let r=J(n,n),i=I(r,[t,0]),c=Je(t/2,.5,X([t,0],i),X(r,i),!0,e);return e?c-Math.LN2:c/2}function Mc(n,t){let e=n*n;if(!(t/(t+e)>1e-250)){let c=Z(W([t,0]),C(W([n,0]),2)),u=I(C(c,t/2),[-Math.log(t/2)-Xn(t/2,.5)-Math.LN2,0]);return[u[0]+u[1],Math.exp(u[0])*(1+u[1])]}let s=J(n,n),r=I(s,[t,0]),i=Ys(t/2,.5,X([t,0],r),X(s,r),!0);return[i[0]-Math.LN2,i[1]/2]}function mc(n,t,e,o){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t<=0)return NaN;if(!Number.isFinite(n))return n<0?Es(e,o):Ls(e,o);if(!Number.isFinite(t))return U(n,{lowerTail:e,logP:o});if(n===0)return o?-Math.LN2:.5;let s=n<0===e,r=Math.abs(n);if(s)return ne(r,t,o);let i=ne(r,t,!1);return o?Math.log1p(-i):1-i}function dc(n,t,e,o){if(Number.isNaN(n)||Number.isNaN(t))return NaN;let s=Qn(n,-1/0,1/0,e,o);if(s!==void 0)return s;if(t<=0)return NaN;if(!Number.isFinite(t))return qt(n,{lowerTail:e,logP:o});let{lower:r,logTarget:i,linearTarget:c}=On(n,e,o);if(i===-Math.LN2&&c===.5)return 0;let u=t,a,d=(.5*u*Math.log(u)-Math.log(u)-Xn(u/2,.5)-i)/u;if(d>709.78)return r?-1/0:1/0;if(i<-30)a=Math.exp(d);else{let m=Math.abs(qt(i,{logP:!0}));if(a=m,u>=3){let f=m*m,b=m*(f+1)/4,p=m*((5*f+16)*f+3)/96,M=m*(((3*f+19)*f+17)*f-15)/384,k=m*((((79*f+776)*f+1482)*f-1920)*f-945)/92160;a=m+(b+(p+(M+k/u)/u)/u)/u}}(!(a>0)||!Number.isFinite(a))&&(a=1);let h=Un({logTarget:i,...c!==void 0&&{linearTarget:c},lower:!1,cdf:m=>ne(m,u,!1),cdfLog:m=>ne(m,u,!0),cdfBoth:m=>Mc(m,u),pdfLog:m=>ir(m,u,!0),dlogPdf:m=>-(u+1)*m/(u+m*m),x0:a,lo:0,hi:1/0,positive:!0});return r?-h:h}function v0(n,t,e={}){let{log:o=!1,ncp:s}=e;return s!==void 0&&s!==0?xt(n,r=>or(r,t,s,o)):xt(n,r=>hc(r,t,o))}function S0(n,t,e={}){let{lowerTail:o=!0,logP:s=!1,ncp:r}=e;return r!==void 0&&r!==0?xt(n,i=>sr(i,t,r,o,s)):xt(n,i=>mc(i,t,o,s))}function A0(n,t,e={}){let{lowerTail:o=!0,logP:s=!1,ncp:r}=e;return r!==void 0&&r!==0?xt(n,i=>rr(i,t,r,o,s)):xt(n,i=>dc(i,t,o,s))}var pc=23283064365386963e-26,ur=2328306437080797e-25,ee=class{mt=new Uint32Array(624);mti=625;setSeed(t){let e=t>>>0;for(let o=0;o<50;o++)e=Math.imul(69069,e)+1>>>0;e=Math.imul(69069,e)+1>>>0;for(let o=0;o<624;o++)e=Math.imul(69069,e)+1>>>0,this.mt[o]=e;this.mti=624}sgenrand(t){for(let e=0;e<624;e++)this.mt[e]=t&4294901760,t=Math.imul(69069,t)+1>>>0,this.mt[e]=(this.mt[e]|(t&4294901760)>>>16)>>>0,t=Math.imul(69069,t)+1>>>0;this.mti=624}nextUint32(){let t=this.mt;if(this.mti>=624){this.mti===625&&this.sgenrand(4357);let o=0,s;for(;o<227;o++)s=t[o]&2147483648|t[o+1]&2147483647,t[o]=t[o+397]^s>>>1^(s&1?2567483615:0);for(;o<623;o++)s=t[o]&2147483648|t[o+1]&2147483647,t[o]=t[o+-227]^s>>>1^(s&1?2567483615:0);s=t[623]&2147483648|t[0]&2147483647,t[623]=t[396]^s>>>1^(s&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()*pc;return t<=0?.5*ur:1-t<=0?1-.5*ur:t}getRandomSeed(t){let e=new Int32Array(626);e[0]=t,e[1]=this.mti;for(let o=0;o<624;o++)e[o+2]=this.mt[o]|0;return e}setRandomSeed(t){if(t.length!==626)throw new RangeError("the random seed state must have 626 integers");this.mti=t[1];for(let e=0;e<624;e++)this.mt[e]=t[e+2]>>>0}};var Nc=2328306549295728e-25,ar=n=>Math.imul(69069,n)+1>>>0,yn=class{s=new Float64Array(6);setSeed(t){let e=t>>>0;for(let o=0;o<50;o++)e=ar(e);for(let o=0;o<6;o++){do e=ar(e);while(e>=4294944443);this.s[o]=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 o=(527612*t[5]-1370589*t[3])%4294944443;return o<0&&(o+=4294944443),t[3]=t[4],t[4]=t[5],t[5]=o,(e>o?e-o:e-o+4294967087)*Nc}};function fr(n){if(n.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 o=n[e];if(!Number.isInteger(o)||o<-2147483648||o>4294967295)throw new RangeError("the random seed state must hold 32-bit integers");t.push(o>>>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 bc=[3.3871328727963665,133.14166789178438,1971.5909503065513,13731.69376550946,45921.95393154987,67265.7709270087,33430.57558358813,2509.0809287301227],gc=[1,42.31333070160091,687.1870074920579,5394.196021424751,21213.794301586597,39307.89580009271,28729.085735721943,5226.495278852854],kc=[1.4234371107496835,4.630337846156546,5.769497221460691,3.6478483247632045,1.2704582524523684,.2417807251774506,.022723844989269184,.0007745450142783414],Ic=[1,2.053191626637759,1.6763848301838038,.6897673349851,.14810397642748008,.015198666563616457,.0005475938084995345,10507500716444169e-25],xc=[6.657904643501103,5.463784911164114,1.7848265399172913,.29656057182850487,.026532189526576124,.0012426609473880784,27115555687434876e-21,20103343992922881e-23],Rc=[1,.599832206555888,.1369298809227358,.014875361290850615,.0007868691311456133,18463183175100548e-21,1421511758316446e-22,20442631033899397e-31];function zt(n,t){let e=n[7];for(let o=6;o>=0;o--)e=e*t+n[o];return e}function lr(n){let t=n-.5;if(Math.abs(t)<=.425){let s=.180625-t*t;return t*zt(bc,s)/zt(gc,s)}let e=t<0?n:1-n;e=Math.sqrt(-Math.log(e));let o;return e<=5?(e-=1.6,o=zt(kc,e)/zt(Ic,e)):(e-=5,o=zt(xc,e)/zt(Rc,e)),t<0?-o:o}var it=new ee,V=it,Bt=!1,no=!1;function eo(n){V.setSeed(n),no=!0}function pr(){if(no)return;let n=(Date.now()^Math.floor(Math.random()*2**32))>>>0;typeof globalThis.crypto?.getRandomValues=="function"&&(n=globalThis.crypto.getRandomValues(new Uint32Array(1))[0]),eo(n)}function q0(n){if(!Number.isFinite(n))throw new RangeError("seed must be a finite number");let t=Math.trunc(n);if(Math.abs(t)>2147483647)throw new RangeError("seed must be a 32-bit integer");eo(t)}var vc={default:!1,"Mersenne-Twister":!1,"L'Ecuyer-CMRG":!0},Sc={default:!1,Rejection:!1,Rounding:!0};function hr(n,t,e){if(t===void 0)return;let o=n[t];if(typeof o!="boolean")throw new RangeError(`unsupported ${e} "${t}"`);return o}function C0(n={}){let t={kind:V===it?"Mersenne-Twister":"L'Ecuyer-CMRG",normalKind:"Inversion",sampleKind:Bt?"Rounding":"Rejection"},e=hr(vc,n.kind,"RNG kind"),o=hr(Sc,n.sampleKind,"sample kind");if(e!==void 0){let s=Math.trunc(Y()*4294967295);V=e?V===it?new yn:V:it,eo(s)}return o!==void 0&&(Bt=o),t}var Mr=()=>(V===it?3:7)+400+(Bt?0:1e4);function P0(){return pr(),V===it?it.getRandomSeed(Mr()):Int32Array.of(Mr(),...V.s)}function w0(n){let t=n[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 o=new yn;o.s.set(fr(n)),V=o}else it.setRandomSeed(n),V=it;Bt=t<1e4,no=!0}function Y(){return pr(),V.nextDouble()}var z0=()=>Bt;function Ac(n){let t=2**Math.max(n-16,0),e=0;for(let o=0;o<=n;o+=16){let s=Math.floor(Y()*65536);e=65536*(e%t)+s}return e%2**n}var mr=33554432;function B0(n){if(Bt)return Math.floor(n*(n>2147483647?(Math.floor(mr*Y())+Y())/mr:Y()));if(n<=0)return 0;let t=Math.ceil(Math.log2(n)),e;do e=Ac(t);while(n<=e);return e}var dr=134217728;function G0(){let n=Y();return n=Math.trunc(dr*n)+Y(),lr(n/dr)}var oe=(()=>{let n=[],t=1,e=0;for(let o=1;o<=16;o++)t*=Math.LN2/o,e+=t,n.push(e);return n})();function K0(){let n=0,t=Y();for(;t<=0||t>=1;)t=Y();for(;t+=t,!(t>1);)n+=oe[0];if(t-=1,t<=oe[0])return n+t;let e=0,o=Y(),s=o;do o=Y(),s>o&&(s=o),e++;while(t>oe[e]);return n+s*oe[0]}export{Es as a,Ls as b,Ts as c,Qn as d,On as e,Un as f,s0 as g,Je as h,Ys as i,r0 as j,mc as k,dc as l,v0 as m,S0 as n,A0 as o,fr as p,q0 as q,C0 as r,P0 as s,w0 as t,Y as u,z0 as v,B0 as w,G0 as x,K0 as y};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.8.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
-
import{a as h,i as s,j as p}from"./chunk-3I6EKGB6.js";function L(t){return Math.abs(t-m(t))>1e-9*Math.max(1,Math.abs(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 y=[.08333333333333333,-.021092796092796094,.007575757575757576,-.004166666666666667,.003968253968253968,-.008333333333333333,.08333333333333333],d=.9955816268920898,w=1569415565/1073741824,O=381566830/1073741824/1073741824,E=9016312093258695e-35,S=[-.002071332116774595,-.04525132144873906,-.28919126444774784,-.6503185377089651,-.3255503118680449,.25479851061131553],_=[-5578984132167551e-22,.0021284987017821146,.054151797245674226,.43593529692665967,1.4606242909763516,2.076711702373047,1];function v(t){let e=t-w;e-=O,e-=E;let r=h(t-1,S)/h(t-1,_);return e*d+e*r}function A(t){let e=0;if(t<1e17){let r=1/(t*t);e=r*h(r,y)}return Math.log(t)-.5/t-e}function k(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-p}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+v(t):e+A(t)}var N=-.5040830082644554,R=7289763902976895e-32,b;function T(t){b??=Array.from({length:100},(n,i)=>C(i+2,N));let e=R,r=-1,o=t-N;for(let n=1;n<100;n++){r*=-o;let i=r*b[n-1];if(e+=i,Math.abs(i)<Number.EPSILON*Math.abs(e))break}return e}var g=[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,i=0;for(;e<=1e8&&(i<9||o<=9||o<t);)if(i+=1,o+=1,n=Math.exp(-t*Math.log1p(i/e)),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let u=1,a=0;for(let c=0;c<12;c++){u*=t+a,n/=f;let l=u*n/g[c];if(r+=l,Math.abs(l/r)<s)break;a+=1,u*=t+a,n/=f,a+=1}return r}function C(t,e){let r=Math.pow(e,-t),o=e,n=0,i=0;for(;i<9||o<=9||o<t;)if(i+=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 u=1,a=0;for(let c=0;c<12;c++){u*=t+a,n/=f;let l=u*n/g[c];if(r+=l,Math.abs(l/r)<s)break;a+=1,u*=t+a,n/=f,a+=1}return r}function I(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 M=[];function Z(t){if(M[t]!==void 0)return M[t];let e=[0,1];for(let n=0;n<t;n++){let i=e.slice(1).map((u,a)=>u*(a+1)),f=new Array(i.length+2).fill(0);i.forEach((u,a)=>{f[a]=f[a]-u,f[a+2]=f[a+2]-u}),e=f}let r=(t+1)%2,o=[];for(let n=r;n<e.length;n+=2)o.push(e[n]);return M[t]=o,o}function j(t,e){let r=Z(t),o=e*e,n=r[r.length-1];for(let i=r.length-2;i>=0;i--)n=n*o+r[i];return(t+1)%2===1?n*e:n}function D(t){let e=t-Math.round(t);return Math.sin(Math.PI*(.5-Math.abs(e)))/Math.sin(Math.PI*e)}function P(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 I(t,e);let o=I(t,1-e);return(t%2===0?o:-o)-Math.pow(Math.PI,t+1)*j(t,D(e))}function H(t){return Math.abs(t-N)<.3?T(t):k(t)}function V(t,e){return P(1,t,e?.rCompatible??!0)}function Y(t,e=0,r){let o=m(e);return Number.isNaN(o)||o<0||o>100?NaN:o===0?H(t):P(o,t,r?.rCompatible??!0)}export{L as a,m as b,H as c,V as d,Y as e};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.8.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{u as o,x as N,y as a}from"./chunk-LXMMKO26.js";function u(t,e){if(!Number.isFinite(t)||t<0)throw new RangeError("n must be a non-negative finite number");let r=Math.trunc(t),n=new Array(r);for(let i=0;i<r;i++)n[i]=e();return n}function s(t,e){let r=1;if(Number.isNaN(t))return t;if(e!==0){if(!Number.isFinite(t))return Math.pow(t,e);for(e<0&&(e=-e,t=1/t);e&1&&(r*=t),e>>=1,e;)t*=t}return r}function l(t,e={}){let{min:r=0,max:n=1}=e;return u(t,()=>{if(!Number.isFinite(r)||!Number.isFinite(n)||n<r)return NaN;if(r===n)return r;let i=o();return r+(n-r)*i})}function f(t,e){return Number.isNaN(t)||!Number.isFinite(e)||e<0?NaN:e===0||!Number.isFinite(t)?t:t+e*N()}function p(t,e={}){let{mean:r=0,sd:n=1}=e;return u(t,()=>f(r,n))}function F(t,e={}){let r=1/(e.rate??1);return u(t,()=>!Number.isFinite(r)||r<=0?r===0?0:NaN:r*a())}function g(t,e={}){let{meanlog:r=0,sdlog:n=1}=e;return u(t,()=>Number.isNaN(r)||!Number.isFinite(n)||n<0?NaN:Math.exp(f(r,n)))}function h(t,e={}){let{location:r=0,scale:n=1}=e;return u(t,()=>{if(Number.isNaN(r)||!Number.isFinite(n))return NaN;if(n===0||!Number.isFinite(r))return r;let i=o();return r+n*Math.log(i/(1-i))})}function w(t,e={}){let{location:r=0,scale:n=1}=e;return u(t,()=>Number.isNaN(r)||!Number.isFinite(n)||n<0?NaN:n===0||!Number.isFinite(r)?r:r+n*Math.tan(Math.PI*o()))}function M(t,e,r={}){let{scale:n=1}=r;return u(t,()=>!Number.isFinite(e)||!Number.isFinite(n)||e<=0||n<=0?n===0?0:NaN:n*Math.pow(-Math.log(o()),1/e))}export{u as a,s as b,l as c,f as d,p as e,F as f,g,h,w as i,M as j};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.8.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 U,b as O}from"./chunk-32PRRONF.js";var y=Math.pow(Number.EPSILON,.25);function q(a,s,o,N=y){let M=.5*(3-Math.sqrt(5)),x=Math.sqrt(Number.EPSILON),n=s,l=o,i=n+M*(l-n),e=i,t=i,r=0,f=0,c=a(t),b=c,m=c,u=1,E=N/3;for(;;){let d=.5*(n+l),h=x*Math.abs(t)+E,w=2*h;if(Math.abs(t-d)<=w-.5*(l-n))break;let g=!0;if(Math.abs(f)>h){let R=(t-e)*(c-b),v=(t-i)*(c-m),I=(t-i)*v-(t-e)*R;if(v=2*(v-R),v>0?I=-I:v=-v,R=f,f=r,Math.abs(I)<Math.abs(.5*v*R)&&I>v*(n-t)&&I<v*(l-t)){r=I/v;let S=t+r;(S-n<w||l-S<w)&&(r=t<=d?h:-h),g=!1}}g&&(f=t<d?l-t:n-t,r=M*f);let L=Math.abs(r)>=h?t+r:r>=0?t+h:t-h,A=a(L);u++,A<=c?(L<t?l=t:n=t,i=e,b=m,e=t,m=c,t=L,c=A):(L<t?n=L:l=L,A<=m||e===t?(i=e,b=m,e=L,m=A):(A<=b||i===t||i===e)&&(i=L,b=A))}return{x:t,fx:c,evaluations:u}}var T=["OK","maximum number of subdivisions reached","roundoff error was detected","extremely bad integrand behaviour","roundoff error is detected in the extrapolation table","the integral is probably divergent","the input is invalid"],F=Number.EPSILON**.25;function k(a,s,o,N={}){let M=N.subdivisions??100,x=N.relTol??F,n=N.absTol??x,l=N.stopOnError??!0;if(Number.isNaN(s)||Number.isNaN(o))throw new RangeError("a limit is NA or NaN");if(M<1||n<=0&&x<Math.max(50*Number.EPSILON,5e-29))throw new RangeError("invalid parameter values");let i=r=>{let f=a(r);if(!Number.isFinite(f))throw new RangeError("non-finite function value");return f},e=Number.isFinite(s)&&Number.isFinite(o)?U(i,s,o,n,x,M):Number.isFinite(s)?O(i,s,1,n,x,M):Number.isFinite(o)?O(i,o,-1,n,x,M):O(i,0,2,n,x,M),t=T[e.ier]??"unknown error";if(e.ier===6)throw new RangeError("the input is invalid");if(e.ier!==0&&l)throw new RangeError(t);return{value:e.result,absError:e.abserr,subdivisions:e.last,ier:e.ier,message:t}}function p(a,s,o,N={}){let M=N.maximum??!1,x=N.tol??F;if(!(s<o))throw new RangeError("'xmin' not less than 'xmax'");let n=q(M?l=>-a(l):a,s,o,x);return{optimum:n.x,objective:a(n.x)}}function j(a,s,o,N={}){let M=N.tol??F,x=N.maxiter??1e3,n=N.extendInt??"no";if(!(s<o))throw new RangeError("lower < upper is not fulfilled");let l=N.fLower??a(s),i=N.fUpper??a(o);if(Number.isNaN(l))throw new RangeError("f.lower = f(lower) is NA");if(Number.isNaN(i))throw new RangeError("f.upper = f(upper) is NA");let e=u=>Math.max(-Number.MAX_VALUE,Math.min(Number.MAX_VALUE,u)),t=u=>.01*Math.max(1e-4,Math.abs(u)),r=n==="downX"?-1:n==="upX"?1:0,f=n==="yes"?e(l)*e(i)>0:r!==0&&(r*e(l)>0||r*e(i)<0),c=0,b=()=>{if(++c>x)throw new RangeError(`no sign change found in ${c-1} iterations`)};if(f&&n==="yes"){let u=t(s),E=t(o);for(;l*i>0&&(Number.isFinite(s)||Number.isFinite(o));){if(b(),Number.isFinite(s)){let d=s-u,h=a(d);Number.isNaN(h)?u/=4:[s,l]=[d,h]}if(Number.isFinite(o)){let d=o+E,h=a(d);Number.isNaN(h)?E/=4:[o,i]=[d,h]}u*=2,E*=2}}else if(f){let u=t(s);for(;r*l>0;)b(),s-=u,l=a(s),u*=2;for(u=t(o);r*i<0;)b(),o+=u,i=a(o),u*=2}if(!(Math.sign(l)*Math.sign(i)<=0))throw new RangeError(f?"did not succeed extending the interval endpoints for f(lower) * f(upper) <= 0":"f() values at end points not of opposite sign");let m=X(u=>P(a(u)),s,o,P(l),P(i),M,x);return{root:m.root,fRoot:a(m.root),iter:f?m.iter+c:m.iter,initIt:f?c:NaN,estimPrec:m.estimPrec}}function P(a){return a===-1/0?-Number.MAX_VALUE:a===1/0||Number.isNaN(a)?Number.MAX_VALUE:a}function X(a,s,o,N,M,x,n){if(N===0)return{root:s,iter:0,estimPrec:0};if(M===0)return{root:o,iter:0,estimPrec:0};let l=Number.EPSILON,i=s,e=o,t=N,r=M,f=i,c=t,b=e-i,m=b;for(let u=0;u<=n;u++){m=e-i,Math.abs(c)<Math.abs(r)&&(i=e,e=f,f=i,t=r,r=c,c=t);let E=2*l*Math.abs(e)+.5*x,d=.5*(f-e);if(Math.abs(d)<=E||r===0)return{root:e,iter:u,estimPrec:Math.abs(f-e)};if(Math.abs(m)>=E&&Math.abs(t)>Math.abs(r)){let h=r/t,w,g;if(i===f)w=2*d*h,g=1-h;else{g=t/c;let L=r/c;w=h*(2*d*g*(g-L)-(e-i)*(L-1)),g=(g-1)*(L-1)*(h-1)}w>0?g=-g:w=-w,h=m,m=b,2*w>=3*d*g-Math.abs(E*g)||w>=Math.abs(.5*h*g)?(b=d,m=b):b=w/g}else b=d,m=b;i=e,t=r,Math.abs(b)>E?e+=b:d>0?e+=E:e-=E,r=a(e),r*(c/Math.abs(c))>0&&(f=i,c=t,b=e-i,m=b)}return{root:e,iter:n,estimPrec:Math.abs(f-e)}}export{k as a,p as b,j as c};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.8.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
-
import{k as D}from"./chunk-LXMMKO26.js";import{a as I,f as $,g as L,i as K}from"./chunk-VIPSPG3Y.js";import{g as v,h as O}from"./chunk-3I6EKGB6.js";import{b as z,c as H,d as w,f as C,g as F,i as j}from"./chunk-OHPHNE3O.js";function Z(t){if(t===void 0)return"two.sided";let o=["two.sided","less","greater"].filter(r=>r.startsWith(t));if(t.length===0||o.length!==1)throw new RangeError(`invalid alternative "${t}" (expected "two.sided", "less" or "greater")`);return o[0]}function B(t){if(!(Number.isFinite(t)&&t>=0&&t<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function ft(t){if(!(Number.isFinite(t)&&t>0&&t<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var ot=["pearson","kendall","spearman"];function st(t){if(t===void 0)return"pearson";let e=ot.filter(o=>o.startsWith(t));if(t.length===0||e.length!==1)throw new RangeError(`invalid method "${t}"`);return e[0]}function G(t){if(!(t[0]>0))return[Math.sqrt(t[0]),0];let e=Math.sqrt(t[0]),o=C(t,H(e,e));return z(e,o[0]/(2*e))}function J(t){let e=I(t);if(!Number.isFinite(e[0]))return;let o=t.map(i=>C([i,0],e)),r=0;for(let i of o)r=Math.max(r,Math.abs(i[0]));if(r===0)return o;let a=2**-Math.max(-1022,Math.floor(Math.log2(r)));return o.map(i=>[i[0]*a,i[1]*a])}function Q(t,e){let o=t.length;if(o<2)return[NaN,0];let r=J(t),a=J(e);if(r===void 0||a===void 0)return[NaN,0];let i=[0,0],c=[0,0],s=[0,0];for(let u=0;u<o;u++)i=w(i,F(r[u],a[u])),c=w(c,F(r[u],r[u])),s=w(s,F(a[u],a[u]));if(c[0]===0||s[0]===0)return[NaN,0];let n=j(i,F(G(c),G(s)));return n[0]>=1?[1,0]:n[0]<=-1?[-1,0]:n}function U(t,e){let o=F(C([1,0],t),w([1,0],t));return Math.sqrt(e)*t[0]/Math.sqrt(o[0])}function at(t){return Math.abs(t[0])<.5?Math.atanh(t[0]):.5*Math.log(w([1,0],t)[0]/C([1,0],t)[0])}function X(t,e,o){return o==="less"?D(t,e,!0,!1):o==="greater"?D(t,e,!1,!1):2*Math.min(D(t,e,!0,!1),D(t,e,!1,!1))}function it(t,e){return e==="less"?v(t):e==="greater"?v(t,{lowerTail:!1}):2*Math.min(v(t),v(t,{lowerTail:!1}))}function ct(t,e){let o=t.length,r=0;for(let f=0;f<o;f++){let m=t[f],x=e[f];for(let p=f+1;p<o;p++){let N=(t[p]>m?1:0)-(t[p]<m?1:0),W=(e[p]>x?1:0)-(e[p]<x?1:0);r+=N*W}}let a=L(t),i=L(e),c=o*(o-1)/2,s=a.reduce((f,m)=>f+m*(m-1)/2,0),n=i.reduce((f,m)=>f+m*(m-1)/2,0),u=o<2||s===c||n===c?NaN:s===0&&n===0?r/c:r/Math.sqrt((c-s)*(c-n));return{s:r,tau:u,ties:a.length>0||i.length>0,tx:a,ty:i}}function Y(t,e){let o=t*(t-1)/2;if(e<0)return 0;if(e>=o)return 1;let r=new Float64Array(e+1);r[0]=1;for(let i=2;i<=t;i++){let c=new Float64Array(e+1),s=0;for(let u=0;u<=e;u++)s+=r[u],c[u]=s;let n=new Float64Array(e+1);for(let u=0;u<=e;u++)n[u]=(c[u]-(u>=i?c[u-i]:0))/i;r=n}let a=0;for(let i=e;i>=0;i--)a+=r[i];return Math.min(1,a)}var _=new Map;function ut(t){let e=_.get(t);if(e!==void 0)return e;let o=t*(t*t-1)/3,r=1<<t,a=new Array(r);a[0]=new Float64Array(o+1),a[0][0]=1;let i=s=>{let n=0;for(;s;s&=s-1)n++;return n};for(let s=0;s<r;s++){let n=a[s];if(n===void 0)continue;let u=i(s);for(let f=0;f<t;f++){if(s&1<<f)continue;let m=(f-u)**2,x=s|1<<f,p=a[x]??=new Float64Array(o+1);for(let N=0;N+m<=o;N++)n[N]&&(p[N+m]+=n[N])}s!==r-1&&(a[s]=void 0)}let c=a[r-1];return _.set(t,c),c}var d=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function tt(t,e,o){let r=e;r%2!==0&&(r+=1);let a=1/t,i=(6*(r-1)*a/(t*t-1)-1)*Math.sqrt(1/a-1),c=i*i,n=i*a*(d[0]+a*(d[1]+d[2]*a)+c*(-d[3]+a*(d[4]+d[5]*a)-c*a*(d[6]+d[7]*a-c*(d[8]-d[9]*a+c*a*(d[10]-d[11]*c)))))/Math.exp(c/2),u=o?v(i)-n:n+v(i,{lowerTail:!1});return Math.min(1,Math.max(0,u))}function et(t,e,o){let r=t*(t*t-1)/3;if(t<=9){let a=ut(t),i=1;for(let s=2;s<=t;s++)i*=s;let c=0;if(o)for(let s=Math.min(e,r);s>=0;s--)c+=a[s];else for(let s=r;s>=Math.max(e,0);s--)c+=a[s];return c/i}return o?e+1>r?1:e+1<=0?0:tt(t,e+1,!0):e<=0?1:e>r?0:tt(t,e,!1)}function Mt(t,e,o={}){if(t.length!==e.length)throw new TypeError("x and y must have the same length");let r=Z(o.alternative),a=st(o.method),i=o.continuity??!1,[c,s]=K(Array.from(t),Array.from(e)),n=c.length;if(a==="pearson"){let l=o.confLevel??.95;if(B(l),n<3)throw new Error("not enough finite observations");let g=Q(c,s),y=n-2,M=Number.isNaN(g[0])?NaN:U(g,y),k={method:"Pearson's product-moment correlation",alternative:r,statistic:M,statisticName:"t",parameter:y,parameterName:"df",pValue:X(M,y,r),estimate:g[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation"};if(n>3){let P=at(g),A=1/Math.sqrt(n-3),V=b=>Math.tanh(P+b),E;if(r==="less")E=[-1,V(A*O(l))];else if(r==="greater")E=[V(-A*O(l)),1];else{let b=A*O((1+l)/2);E=[V(-b),V(b)]}k.confInt=E,k.confLevel=l}return k}if(n<2)throw new Error("not enough finite observations");if(a==="kendall"){let l=ct(c,s),g={method:"Kendall's rank correlation tau",alternative:r,estimate:l.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau"};if(Number.isNaN(l.tau))return{...g,statistic:NaN,statisticName:"T",pValue:NaN};if((o.exact??n<50)&&!l.ties){let h=n*(n-1)/2,S=(l.s+h)/2,q=Y(n,S),R=Y(n,h-S),rt=r==="less"?q:r==="greater"?R:Math.min(1,2*Math.min(q,R));return{...g,statistic:S,statisticName:"T",pValue:rt}}let M=(h,S)=>S.reduce((q,R)=>q+h(R),0),k=h=>h*(h-1),P=h=>h*(h-1)*(h-2),A=h=>h*(h-1)*(2*h+5),V=(n*(n-1)*(2*n+5)-M(A,l.tx)-M(A,l.ty))/18+M(P,l.tx)*M(P,l.ty)/(9*n*(n-1)*(n-2))+M(k,l.tx)*M(k,l.ty)/(2*n*(n-1)),b=(i?Math.sign(l.s)*(Math.abs(l.s)-1):l.s)/Math.sqrt(V);return{...g,statistic:b,statisticName:"z",pValue:it(b,r)}}let u=$(c),f=$(s),m=Q(u,f),x=n*n*n-n,p=x*(1-m[0])/6,N={method:"Spearman's rank correlation rho",alternative:r,statistic:p,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho"};if(Number.isNaN(m[0]))return{...N,pValue:NaN};let W=L(c).length>0||L(s).length>0;if((o.exact??n<=1290)&&!W&&n<=1290){let l=Math.round(p),g=et(n,l,!0),y=et(n,l,!1),M=r==="greater"?g:r==="less"?y:Math.min(1,2*Math.min(g,y));return{...N,pValue:M}}let T=m;if(i){let l=j([6,0],[x,0]);T=j(w(m,l),w([1,0],l)),Math.abs(T[0])>=1&&(T=[Math.sign(T[0]),0])}let nt=U(T,n-2);return{...N,pValue:X(nt,n-2,r)}}export{Z as a,B as b,ft as c,Q as d,ct as e,Mt as f};
|