@numero-uno-jpn/rstats 0.15.3 → 0.16.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 +166 -0
- package/README.ja.md +40 -33
- package/README.md +36 -28
- package/dist/chunks/chunk-2D2IQWUQ.js +2 -0
- package/dist/chunks/chunk-5UQCRBAG.js +2 -0
- package/dist/chunks/chunk-6CSTWA5E.js +2 -0
- package/dist/chunks/chunk-72Y3HZID.js +2 -0
- package/dist/chunks/chunk-BG2KLEHM.js +2 -0
- package/dist/chunks/chunk-CMEKBNHQ.js +2 -0
- package/dist/chunks/chunk-FLJNSXSW.js +2 -0
- package/dist/chunks/chunk-GM53LWSR.js +2 -0
- package/dist/chunks/chunk-JBCA56ZS.js +3 -0
- package/dist/chunks/chunk-K3RJAD2T.js +2 -0
- package/dist/chunks/chunk-KAZRWIB5.js +2 -0
- package/dist/chunks/chunk-KBVVIMXX.js +3 -0
- package/dist/chunks/chunk-N3SIFCZX.js +2 -0
- package/dist/chunks/chunk-QNNL7AZ3.js +2 -0
- package/dist/chunks/chunk-SC6CV4Z3.js +2 -0
- package/dist/chunks/chunk-SYWOBOTR.js +2 -0
- package/dist/chunks/chunk-URIO5LY5.js +2 -0
- package/dist/chunks/chunk-VTUGG2SV.js +2 -0
- package/dist/chunks/chunk-W26LRYOJ.js +2 -0
- package/dist/chunks/chunk-XHETEYVC.js +2 -0
- package/dist/chunks/{chunk-VLUL2HFW.js → chunk-YRZWONZB.js} +1 -1
- package/dist/chunks/chunk-ZGABZMWX.js +2 -0
- package/dist/data/grouping.js +20 -5
- package/dist/descriptive/basic.js +90 -8
- package/dist/descriptive/cov.js +12 -4
- package/dist/descriptive/dataFrames.d.ts +4 -2
- package/dist/descriptive/dataFrames.js +56 -18
- package/dist/descriptive/factanal.js +16 -7
- package/dist/descriptive/hist.d.ts +8 -5
- package/dist/descriptive/hist.js +71 -31
- package/dist/descriptive/missing.js +3 -1
- package/dist/descriptive/moments.js +72 -19
- package/dist/descriptive/omega.d.ts +1 -1
- package/dist/descriptive/omega.js +68 -9
- package/dist/descriptive/pivot.d.ts +21 -9
- package/dist/descriptive/pivot.js +161 -35
- package/dist/descriptive/quantile.js +2 -1
- package/dist/descriptive/rank.js +4 -1
- package/dist/descriptive/table.d.ts +3 -2
- package/dist/descriptive/table.js +24 -9
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.js +19 -2
- package/dist/distributions/beta.js +24 -4
- package/dist/distributions/binomial.js +37 -14
- package/dist/distributions/bvnorm.js +11 -2
- package/dist/distributions/cauchy.js +12 -4
- package/dist/distributions/chisq.js +7 -3
- package/dist/distributions/exponential.js +5 -0
- package/dist/distributions/f.js +32 -17
- package/dist/distributions/gamma.js +27 -3
- package/dist/distributions/geometric.js +49 -13
- package/dist/distributions/hypergeometric.d.ts +5 -1
- package/dist/distributions/hypergeometric.js +93 -6
- package/dist/distributions/invgamma.js +2 -1
- package/dist/distributions/laplace.js +27 -6
- package/dist/distributions/logistic.js +4 -1
- package/dist/distributions/lognormal.js +8 -2
- package/dist/distributions/multinomial.js +54 -11
- package/dist/distributions/nbeta.js +62 -11
- package/dist/distributions/nchisq.js +30 -6
- package/dist/distributions/negbinomial.js +94 -17
- package/dist/distributions/normal.js +9 -4
- package/dist/distributions/nt.js +392 -17
- package/dist/distributions/pareto.js +4 -1
- package/dist/distributions/poisson.js +28 -3
- package/dist/distributions/signrank.js +7 -4
- package/dist/distributions/summary.js +450 -60
- package/dist/distributions/triangular.js +10 -5
- package/dist/distributions/tukey.js +5 -2
- package/dist/distributions/weibull.js +10 -0
- package/dist/distributions/wilcox.d.ts +9 -3
- package/dist/distributions/wilcox.js +155 -26
- package/dist/distributions.js +2 -2
- package/dist/htest/agreement.d.ts +3 -2
- package/dist/htest/agreement.js +76 -14
- package/dist/htest/ansariTest.d.ts +6 -1
- package/dist/htest/ansariTest.js +75 -8
- package/dist/htest/aov.d.ts +1 -1
- package/dist/htest/aov.js +48 -34
- package/dist/htest/binomTest.d.ts +5 -0
- package/dist/htest/binomTest.js +41 -17
- package/dist/htest/brunnerMunzelTest.d.ts +4 -3
- package/dist/htest/brunnerMunzelTest.js +7 -5
- package/dist/htest/chisqTest.d.ts +2 -1
- package/dist/htest/chisqTest.js +130 -43
- package/dist/htest/cor.d.ts +2 -1
- package/dist/htest/cor.js +17 -19
- package/dist/htest/core/ansari.d.ts +9 -0
- package/dist/htest/core/ansari.js +21 -1
- package/dist/htest/core/kolmogorov.d.ts +25 -0
- package/dist/htest/core/kolmogorov.js +123 -0
- package/dist/htest/core/mantelhaen.js +6 -4
- package/dist/htest/core/shapiro.d.ts +1 -1
- package/dist/htest/core/shapiro.js +5 -1
- package/dist/htest/dunnett.js +14 -5
- package/dist/htest/effectSize.d.ts +2 -0
- package/dist/htest/effectSize.js +91 -29
- package/dist/htest/fisherTest.d.ts +2 -2
- package/dist/htest/fisherTest.js +36 -18
- package/dist/htest/groups.d.ts +7 -0
- package/dist/htest/groups.js +21 -4
- package/dist/htest/ksTest.d.ts +3 -1
- package/dist/htest/ksTest.js +23 -2
- package/dist/htest/leveneTest.js +19 -3
- package/dist/htest/mantelhaenTest.js +125 -25
- package/dist/htest/mcnemarTest.js +32 -11
- package/dist/htest/multipleComparisons.d.ts +8 -1
- package/dist/htest/multipleComparisons.js +44 -21
- package/dist/htest/normalityTests.js +44 -10
- package/dist/htest/onewayTest.js +96 -5
- package/dist/htest/pAdjust.d.ts +3 -2
- package/dist/htest/pAdjust.js +38 -6
- package/dist/htest/pairwise.d.ts +1 -1
- package/dist/htest/pairwise.js +17 -15
- package/dist/htest/poissonTest.d.ts +1 -1
- package/dist/htest/poissonTest.js +111 -59
- package/dist/htest/polycor.js +27 -7
- package/dist/htest/power.d.ts +11 -1
- package/dist/htest/power.js +112 -8
- package/dist/htest/propTest.js +21 -4
- package/dist/htest/pwr.js +121 -24
- package/dist/htest/rankTests.js +29 -5
- package/dist/htest/tTest.js +44 -21
- package/dist/htest/trendTests.d.ts +7 -3
- package/dist/htest/trendTests.js +114 -20
- package/dist/htest/types.d.ts +5 -0
- package/dist/htest/types.js +7 -0
- package/dist/htest/varTest.js +45 -14
- package/dist/htest/wilcoxTest.js +114 -21
- package/dist/integrate/quadpack.js +27 -5
- package/dist/internal/covmat.d.ts +5 -0
- package/dist/internal/covmat.js +20 -0
- package/dist/internal/ddexp.d.ts +15 -1
- package/dist/internal/ddexp.js +59 -6
- package/dist/internal/discrete.d.ts +14 -0
- package/dist/internal/discrete.js +78 -5
- package/dist/internal/extremes.d.ts +9 -0
- package/dist/internal/extremes.js +24 -0
- package/dist/internal/fround.js +13 -4
- package/dist/internal/integer.d.ts +9 -0
- package/dist/internal/integer.js +12 -0
- package/dist/internal/invert.js +15 -2
- package/dist/internal/scaledInverse.d.ts +10 -0
- package/dist/internal/scaledInverse.js +22 -0
- package/dist/internal/seq.js +15 -2
- package/dist/internal/summary.d.ts +90 -0
- package/dist/internal/summary.js +458 -39
- package/dist/internal/uniroot.d.ts +7 -0
- package/dist/internal/uniroot.js +28 -3
- package/dist/linalg/basic.d.ts +3 -1
- package/dist/linalg/basic.js +51 -7
- package/dist/linalg/chol.js +4 -1
- package/dist/linalg/dot.d.ts +29 -0
- package/dist/linalg/dot.js +132 -0
- package/dist/linalg/eigen.d.ts +6 -1
- package/dist/linalg/eigen.js +71 -14
- package/dist/linalg/expm.d.ts +3 -2
- package/dist/linalg/expm.js +109 -15
- package/dist/linalg/kappa.js +58 -10
- package/dist/linalg/lu.d.ts +2 -1
- package/dist/linalg/lu.js +35 -5
- package/dist/linalg/matrix.d.ts +14 -0
- package/dist/linalg/matrix.js +24 -0
- package/dist/linalg/ops.js +60 -13
- package/dist/linalg/qr.d.ts +2 -1
- package/dist/linalg/qr.js +91 -23
- package/dist/linalg/schur.js +11 -3
- package/dist/linalg/solve.d.ts +6 -1
- package/dist/linalg/solve.js +147 -26
- package/dist/linalg/svd.d.ts +9 -2
- package/dist/linalg/svd.js +29 -11
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +4 -4
- package/dist/models/anovaSequential.d.ts +16 -1
- package/dist/models/anovaSequential.js +124 -25
- package/dist/models/aovEz.js +140 -30
- package/dist/models/aovStrata.js +55 -22
- package/dist/models/carAnova.d.ts +1 -1
- package/dist/models/carAnova.js +83 -32
- package/dist/models/coxph.js +148 -66
- package/dist/models/estimable.d.ts +15 -0
- package/dist/models/estimable.js +68 -0
- package/dist/models/formula.d.ts +1 -1
- package/dist/models/formula.js +26 -8
- package/dist/models/glm.d.ts +35 -5
- package/dist/models/glm.js +398 -55
- package/dist/models/glmAnova.js +84 -13
- package/dist/models/glmConfint.d.ts +1 -1
- package/dist/models/glmConfint.js +115 -27
- package/dist/models/glmFamily.d.ts +10 -0
- package/dist/models/glmFamily.js +244 -40
- package/dist/models/lm.d.ts +12 -1
- package/dist/models/lm.js +235 -36
- package/dist/models/lmer.d.ts +20 -1
- package/dist/models/lmer.js +109 -27
- package/dist/models/lmerAnova.js +37 -4
- package/dist/models/lmerHypotheses.d.ts +6 -2
- package/dist/models/lmerHypotheses.js +14 -2
- package/dist/models/lmerTest.d.ts +9 -2
- package/dist/models/lmerTest.js +64 -19
- package/dist/models/mauchly.d.ts +4 -1
- package/dist/models/mauchly.js +34 -13
- package/dist/models/mixedStructure.js +6 -0
- package/dist/models/modelFrame.js +8 -2
- package/dist/models/modelMatrix.d.ts +3 -1
- package/dist/models/modelMatrix.js +40 -15
- package/dist/models/scaledTables.d.ts +8 -0
- package/dist/models/scaledTables.js +6 -0
- package/dist/models/survival.d.ts +6 -1
- package/dist/models/survival.js +67 -27
- package/dist/models/tiedTimes.d.ts +2 -0
- package/dist/models/tiedTimes.js +34 -0
- package/dist/numerics/deriv.d.ts +1 -1
- package/dist/numerics/deriv.js +64 -8
- package/dist/numerics/integrate.d.ts +9 -1
- package/dist/numerics/integrate.js +103 -16
- package/dist/numerics/interp.d.ts +8 -2
- package/dist/numerics/interp.js +352 -50
- package/dist/numerics/ode.js +55 -1
- package/dist/numerics.js +2 -2
- package/dist/optim/localmin.js +4 -0
- package/dist/optim/optim.d.ts +3 -1
- package/dist/optim/optim.js +80 -8
- package/dist/random/beta.js +53 -4
- package/dist/random/binomial.d.ts +14 -3
- package/dist/random/binomial.js +59 -24
- package/dist/random/continuous.js +33 -5
- package/dist/random/extra.js +42 -9
- package/dist/random/gamma.d.ts +4 -1
- package/dist/random/gamma.js +36 -8
- package/dist/random/hyper.js +9 -6
- package/dist/random/mt.js +17 -2
- package/dist/random/poisson.js +26 -3
- package/dist/random/r2dtable.d.ts +8 -1
- package/dist/random/r2dtable.js +24 -3
- package/dist/random/rank.d.ts +2 -0
- package/dist/random/rank.js +44 -4
- package/dist/random/sample.d.ts +12 -2
- package/dist/random/sample.js +57 -20
- package/dist/random/streams.js +4 -2
- package/dist/rstats.js +14 -14
- package/dist/special/besselIK.d.ts +12 -0
- package/dist/special/besselIK.js +168 -23
- package/dist/special/besselJY.d.ts +11 -1
- package/dist/special/besselJY.js +127 -19
- package/dist/special/besselSeries.d.ts +27 -0
- package/dist/special/besselSeries.js +45 -2
- package/dist/special/beta.js +4 -1
- package/dist/special/choose.js +17 -8
- package/dist/special/dd.js +122 -18
- package/dist/special/extra.js +14 -2
- package/dist/special/gamma.js +11 -2
- package/dist/special/incbet.js +30 -4
- package/dist/special/incbetTemme.d.ts +7 -0
- package/dist/special/incbetTemme.js +45 -12
- package/dist/special/loader.d.ts +1 -1
- package/dist/special/loader.js +117 -20
- package/dist/special/log1pmx.js +4 -0
- package/dist/special.js +2 -2
- package/dist/tests.js +11 -11
- package/llms.txt +12 -6
- package/package.json +1 -1
- package/dist/chunks/chunk-3THFTB36.js +0 -2
- package/dist/chunks/chunk-3TSWYE5L.js +0 -2
- package/dist/chunks/chunk-3WPU6LGK.js +0 -2
- package/dist/chunks/chunk-5ITR67MB.js +0 -2
- package/dist/chunks/chunk-5NRFU6F6.js +0 -2
- package/dist/chunks/chunk-E2LCSVQV.js +0 -2
- package/dist/chunks/chunk-FCNVTIPJ.js +0 -2
- package/dist/chunks/chunk-FKAKALOZ.js +0 -2
- package/dist/chunks/chunk-HD73UKPT.js +0 -2
- package/dist/chunks/chunk-IUULP3LE.js +0 -2
- package/dist/chunks/chunk-JQG3YQOC.js +0 -2
- package/dist/chunks/chunk-KT66SB7R.js +0 -2
- package/dist/chunks/chunk-MAUAOQG3.js +0 -2
- package/dist/chunks/chunk-MDYE7QP2.js +0 -2
- package/dist/chunks/chunk-NM3Z2UBQ.js +0 -2
- package/dist/chunks/chunk-PMJI5QO6.js +0 -3
- package/dist/chunks/chunk-UF7KOTHF.js +0 -3
- package/dist/chunks/chunk-UOE57JGT.js +0 -2
- package/dist/chunks/chunk-USPEBXSR.js +0 -2
- package/dist/chunks/chunk-ZIX7NYQF.js +0 -2
|
@@ -169,26 +169,33 @@ function mulLarge(r, x) {
|
|
|
169
169
|
* used (m >= TEMME_MIN_M and |τ| <= TAU_MAX); the caller then uses the series or continued fractions
|
|
170
170
|
*/
|
|
171
171
|
export function betaIncTemme(a, b, xd, xcd, lower, wantLog) {
|
|
172
|
-
|
|
172
|
+
// Where a + b overflows, r x - a, the deviance E and m are formed from the halved shapes and doubled: they are
|
|
173
|
+
// homogeneous of degree 1 in (a, b), while p, q and τ do not change (pbeta(0.5, 1e308, 1e308) was NaN)
|
|
174
|
+
const c = Number.isFinite(a + b) ? 1 : 2;
|
|
175
|
+
const ah = a / c;
|
|
176
|
+
const bh = b / c;
|
|
177
|
+
const rr = twoSum(ah, bh);
|
|
173
178
|
const r = rr[0];
|
|
174
179
|
// (a b overflows beyond 1.8e308: then a (b / r))
|
|
175
|
-
const ab =
|
|
176
|
-
const
|
|
180
|
+
const ab = ah * bh;
|
|
181
|
+
const mh = Number.isFinite(ab) ? ab / r : ah * (bh / r);
|
|
182
|
+
const m = c * mh;
|
|
177
183
|
if (!(m >= TEMME_MIN_M) || !Number.isFinite(r))
|
|
178
184
|
return undefined;
|
|
179
|
-
const p =
|
|
180
|
-
const q =
|
|
181
|
-
const pq =
|
|
185
|
+
const p = ah / r;
|
|
186
|
+
const q = bh / r;
|
|
187
|
+
const pq = mh / r;
|
|
182
188
|
// Cheap filter: |τ| <= 1 needs |w| = |x - p| / pq below about 1.6
|
|
183
189
|
const x = xd[0];
|
|
184
190
|
if (Math.abs(x - p) > 2 * pq)
|
|
185
191
|
return undefined;
|
|
186
192
|
// r x - a exactly enough (sign of x - p, and g_0 in the tail form)
|
|
187
193
|
const rx = mulLarge(rr, xd);
|
|
188
|
-
const dx = ddSub(rx, [
|
|
189
|
-
const d = dx[0] + dx[1];
|
|
194
|
+
const dx = ddSub(rx, [ah, 0]);
|
|
195
|
+
const d = c * (dx[0] + dx[1]);
|
|
190
196
|
// E = bd0(a, r x) + bd0(b, r (1 - x)) in double-double
|
|
191
|
-
const
|
|
197
|
+
const eh = ddAdd(bd0dd(ah, rx), bd0dd(bh, mulLarge(rr, xcd)));
|
|
198
|
+
const e = [c * eh[0], c * eh[1]];
|
|
192
199
|
const E = e[0] + e[1];
|
|
193
200
|
const tau2 = (2 * E) / m;
|
|
194
201
|
if (!(tau2 <= TAU_MAX * TAU_MAX))
|
|
@@ -197,7 +204,8 @@ export function betaIncTemme(a, b, xd, xcd, lower, wantLog) {
|
|
|
197
204
|
const tau = d < 0 ? -absTau : absTau;
|
|
198
205
|
const n = absTau <= 0.5 ? 20 : absTau <= 0.75 ? 24 : NMAX;
|
|
199
206
|
gCoefficients(p, q, n);
|
|
200
|
-
|
|
207
|
+
// (where a + b overflows, its stirlerr, about 1 / (12 (a + b)), is below 1e-309)
|
|
208
|
+
const eD = Math.exp(-(stirlerr(a) + stirlerr(b) - (c === 1 ? stirlerr(r) : 0)));
|
|
201
209
|
const y = Math.sqrt(E);
|
|
202
210
|
// The smaller tail is the lower one when x < p
|
|
203
211
|
const smallIsLower = d < 0;
|
|
@@ -220,9 +228,34 @@ export function betaIncTemme(a, b, xd, xcd, lower, wantLog) {
|
|
|
220
228
|
let small;
|
|
221
229
|
if (e[0] < 700)
|
|
222
230
|
small = Math.exp(-e[0]) * (1 - e[1]) * B;
|
|
231
|
+
// (beyond 1500 the result underflows; 1 - e[1] is then no longer near 1 and could make it -0)
|
|
223
232
|
else
|
|
224
|
-
small = Math.exp(700 - e[0]) * (1 - e[1]) * B * Math.exp(-700);
|
|
233
|
+
small = e[0] < 1500 ? Math.exp(700 - e[0]) * (1 - e[1]) * B * Math.exp(-700) : 0;
|
|
225
234
|
if (lower === smallIsLower)
|
|
226
235
|
return [wantLog ? -e[0] - e[1] + Math.log(B) : NaN, small];
|
|
227
|
-
|
|
236
|
+
// (log1p(-0) would be -0)
|
|
237
|
+
return [wantLog ? (small === 0 ? 0 : Math.log1p(-small)) : NaN, 1 - small];
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Fallback where a + b overflows and the other methods gave NaN (the continued fraction and the prefactor form
|
|
241
|
+
* a + b; pbeta(0.1, 1e308, 1e308) was NaN; #491). The smaller tail is e^-E times a factor whose log is of the order of
|
|
242
|
+
* the logs of the shapes (below about 2000 in size), so where E >= 1e22 its log is -E to double precision and its
|
|
243
|
+
* linear value 0. E in the halved shapes, doubled, as in betaIncTemme. Undefined where a + b is finite or E < 1e22
|
|
244
|
+
*/
|
|
245
|
+
export function betaIncOverflowSum(a, b, xd, xcd, lower, wantLog) {
|
|
246
|
+
if (Number.isFinite(a + b))
|
|
247
|
+
return undefined;
|
|
248
|
+
const ah = a / 2;
|
|
249
|
+
const bh = b / 2;
|
|
250
|
+
const rr = twoSum(ah, bh);
|
|
251
|
+
const rx = mulLarge(rr, xd);
|
|
252
|
+
const dx = ddSub(rx, [ah, 0]);
|
|
253
|
+
const eh = ddAdd(bd0dd(ah, rx), bd0dd(bh, mulLarge(rr, xcd)));
|
|
254
|
+
const E = 2 * (eh[0] + eh[1]);
|
|
255
|
+
if (!(E >= 1e22))
|
|
256
|
+
return undefined;
|
|
257
|
+
// The smaller tail is the lower one when x < p
|
|
258
|
+
if (lower === dx[0] + dx[1] < 0)
|
|
259
|
+
return [wantLog ? -E : NaN, 0];
|
|
260
|
+
return [wantLog ? 0 : NaN, 1];
|
|
228
261
|
}
|
package/dist/special/loader.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare function dbinomRawSplit(x: number, nmx: number, p: number, q: num
|
|
|
28
28
|
* The rounding error of p^x is amplified x times (1e-11 at x = 1e5), so where p is formed as 1 - (smaller side),
|
|
29
29
|
* pass that difference exactly in double-double.
|
|
30
30
|
*/
|
|
31
|
-
export declare function dbinomRawDD(x: number, nmx: number, p: DD, q: DD, log: boolean): number;
|
|
31
|
+
export declare function dbinomRawDD(x: number, nmx: number, p: DD, q: DD, log: boolean, size?: number, shift?: readonly [number, number]): number;
|
|
32
32
|
/**
|
|
33
33
|
* Return the exponent of the core binomial probability (0 < x, 0 < n - x, 0 < p, q) in double-double.
|
|
34
34
|
* Probability = exp(-e) / sqrt(denom). Used when exp should be taken after combining with other factors (beta density).
|
package/dist/special/loader.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// Written from the formulas in the paper. The table of stirlerr at half-integers was computed with Rmpfr (256 bits).
|
|
9
9
|
import { LS2PI } from "./constants.js";
|
|
10
10
|
import { lgamma1p } from "./gamma.js";
|
|
11
|
-
import { ddAdd, ddDiv, ddDivNum, ddLog, ddMul, ddMulNum, ddNeg, ddSub, isDoubleDouble, SPLITTER, twoSum } from "./dd.js";
|
|
11
|
+
import { ddAdd, ddDiv, ddDivNum, ddLog, ddMul, ddMulNum, ddNeg, ddSub, isDoubleDouble, SPLITTER, twoProd, twoSum } from "./dd.js";
|
|
12
12
|
const DBL_MIN = 2.2250738585072014e-308;
|
|
13
13
|
const LN_2PI = 1.837877066409345483560659472811;
|
|
14
14
|
/* stirlerr(k/2), k = 1..30 */
|
|
@@ -70,6 +70,9 @@ const TAIL_IN_DOUBLE = 0.12;
|
|
|
70
70
|
* When x and M are close, it is computed by the series in v = (x - M)/(x + M) (Loader 2000).
|
|
71
71
|
*/
|
|
72
72
|
export function bd0dd(x, M) {
|
|
73
|
+
// the limit at x = 0, as bd0 (log(0) made it NaN)
|
|
74
|
+
if (x === 0)
|
|
75
|
+
return M;
|
|
73
76
|
// bd0 is homogeneous of degree 1: from about 1e300 the splitting in the double-double products overflows (x + M
|
|
74
77
|
// enters them), so scale x and M by 2^-64 (exactly, unless the smaller one would become subnormal; its quotient is
|
|
75
78
|
// then far out and the logarithms are taken separately below) and the result back (pgamma(9.9e299, 1e300) was NaN)
|
|
@@ -401,15 +404,27 @@ function scaleUp(r) {
|
|
|
401
404
|
* 1e-290, down to 0 by underflow, as with tiny shapes: pbeta(5.8e-295, 2.8e-193, 3.5e-153) threw a TypeError), its
|
|
402
405
|
* logarithm is taken as log n + log p
|
|
403
406
|
*/
|
|
404
|
-
function bd0Prod(x, nn, p) {
|
|
407
|
+
function bd0Prod(x, nn, p, k = 0) {
|
|
405
408
|
const s = nn[0] > 1e299 ? 2 ** -64 : 1;
|
|
406
|
-
|
|
407
|
-
|
|
409
|
+
// (p is p 2^k for k > 0, a probability below the doubles: issue #95)
|
|
410
|
+
let M;
|
|
411
|
+
if (k === 0) {
|
|
412
|
+
const ms = ddMul([nn[0] * s, nn[1] * s], p);
|
|
413
|
+
M = [ms[0] / s, ms[1] / s];
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
M = shiftedProduct(nn, p, k);
|
|
417
|
+
}
|
|
408
418
|
if (M[0] >= 1e-290)
|
|
409
419
|
return bd0dd(x, M);
|
|
410
|
-
const lr = ddSub(ddLog([x, 0]), ddAdd(ddLog(nn),
|
|
411
|
-
return ddAdd(ddMulNum(lr, x), twoSum(nn[0] * p[0], -x));
|
|
420
|
+
const lr = ddSub(ddLog([x, 0]), ddAdd(ddLog(nn), logShifted(p, k)));
|
|
421
|
+
return ddAdd(ddMulNum(lr, x), twoSum(k === 0 ? nn[0] * p[0] : M[0], -x));
|
|
412
422
|
}
|
|
423
|
+
/** v 2^e (exact where the result is normal; v 2^e can overflow for v times 2^1100 when e is positive) */
|
|
424
|
+
const pow2 = (v, e) => v * 2 ** Math.trunc(e / 2) * 2 ** (e - Math.trunc(e / 2));
|
|
425
|
+
const LN2_DD = [0.6931471805599453, 2.3190468138462996e-17];
|
|
426
|
+
/** log(p 2^-k) for a double-double p */
|
|
427
|
+
const logShifted = (p, k) => (k === 0 ? ddLog(p) : ddSub(ddLog(p), ddMulNum(LN2_DD, k)));
|
|
413
428
|
/** Double-precision version of bd0 */
|
|
414
429
|
export function bd0(x, M) {
|
|
415
430
|
if (!Number.isFinite(x) || !Number.isFinite(M) || M === 0)
|
|
@@ -447,6 +462,18 @@ function mulLarge(nn, v) {
|
|
|
447
462
|
* exp of a double-double log probability; 0 far below the subnormals, where the low part can exceed 1 and the first
|
|
448
463
|
* order correction would give -0
|
|
449
464
|
*/
|
|
465
|
+
const NO_SHIFT = [0, 0];
|
|
466
|
+
/**
|
|
467
|
+
* n v 2^-k (mulLarge for k = 0). For k > 0, v is up to 2^78 and n v alone could overflow: n is brought to [1, 2) by
|
|
468
|
+
* its power of 2 first (exactly), and the product, far below 1 then, may underflow to 0
|
|
469
|
+
*/
|
|
470
|
+
function shiftedProduct(nn, v, k) {
|
|
471
|
+
if (k === 0)
|
|
472
|
+
return mulLarge(nn, v);
|
|
473
|
+
const e = Math.floor(Math.log2(nn[0]));
|
|
474
|
+
const r = ddMul([pow2(nn[0], -e), pow2(nn[1], -e)], v);
|
|
475
|
+
return [pow2(r[0], e - k), pow2(r[1], e - k)];
|
|
476
|
+
}
|
|
450
477
|
const expLogDD = (l) => (l[0] < -2000 ? 0 : Math.exp(l[0]) * (1 + l[1]));
|
|
451
478
|
/**
|
|
452
479
|
* Binomial probability C(n, x) p^x q^(n-x). x and n need not be integers (used by the beta and F distributions).
|
|
@@ -468,7 +495,10 @@ export function dbinomRawSplit(x, nmx, p, q, log) {
|
|
|
468
495
|
* The rounding error of p^x is amplified x times (1e-11 at x = 1e5), so where p is formed as 1 - (smaller side),
|
|
469
496
|
* pass that difference exactly in double-double.
|
|
470
497
|
*/
|
|
471
|
-
export function dbinomRawDD(x, nmx, p, q, log) {
|
|
498
|
+
export function dbinomRawDD(x, nmx, p, q, log, size, shift = NO_SHIFT) {
|
|
499
|
+
// shift: p and q are given times 2^shift[0] and 2^shift[1] (a probability below the doubles, kept as a normal
|
|
500
|
+
// number: dnbinom(1, 1e-200, { mu: 1e200 }) was 0; issue #95). [0, 0] otherwise
|
|
501
|
+
const [kp, kq] = shift;
|
|
472
502
|
const zero = log ? -Infinity : 0;
|
|
473
503
|
const one = log ? 0 : 1;
|
|
474
504
|
const nn = twoSum(x, nmx); // n in double-double
|
|
@@ -480,29 +510,32 @@ export function dbinomRawDD(x, nmx, p, q, log) {
|
|
|
480
510
|
if (x === 0) {
|
|
481
511
|
if (n === 0)
|
|
482
512
|
return one;
|
|
483
|
-
if (p[0] < 0.1) {
|
|
513
|
+
if (kp > 0 || p[0] < 0.1) {
|
|
484
514
|
// n log q = -bd0(n, n q) - n p
|
|
485
|
-
const e = ddAdd(bd0Prod(n, nn, q),
|
|
515
|
+
const e = ddAdd(bd0Prod(n, nn, q, kq), shiftedProduct(nn, p, kp));
|
|
486
516
|
return log ? -e[0] - e[1] : expLogDD([-e[0], -e[1]]);
|
|
487
517
|
}
|
|
488
|
-
const
|
|
489
|
-
const lc = mulLarge(nn, lq);
|
|
518
|
+
const lc = mulLarge(nn, logShifted(q, kq));
|
|
490
519
|
return log ? lc[0] + lc[1] : expLogDD(lc);
|
|
491
520
|
}
|
|
492
521
|
if (nmx === 0) {
|
|
493
|
-
if (q[0] < 0.1) {
|
|
494
|
-
const e = ddAdd(bd0Prod(n, nn, p),
|
|
522
|
+
if (kq > 0 || q[0] < 0.1) {
|
|
523
|
+
const e = ddAdd(bd0Prod(n, nn, p, kp), shiftedProduct(nn, q, kq));
|
|
495
524
|
return log ? -e[0] - e[1] : expLogDD([-e[0], -e[1]]);
|
|
496
525
|
}
|
|
497
|
-
const lc = mulLarge(nn,
|
|
526
|
+
const lc = mulLarge(nn, logShifted(p, kp));
|
|
498
527
|
return log ? lc[0] + lc[1] : expLogDD(lc);
|
|
499
528
|
}
|
|
500
529
|
if (x < 0 || nmx < 0)
|
|
501
530
|
return zero;
|
|
502
531
|
// E = stirlerr(x) + stirlerr(n-x) - stirlerr(n) + bd0(x, np) + bd0(n-x, nq)
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
532
|
+
// (the given n when n - x was rounded: see exactBinomialExponent)
|
|
533
|
+
const e = size !== undefined && (nn[0] !== size || nn[1] !== 0) ? exactBinomialExponent(x, size, p, q) : binomialExponent(x, nmx, nn, p, q, kp, kq);
|
|
534
|
+
// Denominator 2 pi x (n - x) / n. Beyond 2e307 for x (n - x) / n, 2 pi x overflowed (dbinom(8e307, 1.6e308, 0.5)
|
|
535
|
+
// and dmultinom of such counts were 0; issue #24): as in dpoisRawCore, pi x (n - x) / (8 n) and the value divided by 4
|
|
536
|
+
const big = x * (nmx / n) > 2e307;
|
|
537
|
+
const value = expNegDD(e, log, () => LN_2PI + Math.log(x) + Math.log(nmx) - Math.log(n), big ? () => (Math.PI / 8) * (x * (nmx / n)) : () => 2 * Math.PI * x * (nmx / n));
|
|
538
|
+
return big && !log ? value / 4 : value;
|
|
506
539
|
}
|
|
507
540
|
/**
|
|
508
541
|
* Return the exponent of the core binomial probability (0 < x, 0 < n - x, 0 < p, q) in double-double.
|
|
@@ -517,9 +550,73 @@ export function dbinomExponent(x, nmx, p, q) {
|
|
|
517
550
|
* The exponent E = bd0(x, np) + bd0(n - x, nq) + stirlerr(x) + stirlerr(n - x) - stirlerr(n) in double-double;
|
|
518
551
|
* [Infinity, 0] where a deviance overflows (the double-double sums made it NaN: dbeta(0.998, 55.1, 6.3e307))
|
|
519
552
|
*/
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
553
|
+
/**
|
|
554
|
+
* The exponent of dbinomRawDD for the given n (an integer double) where n - x is not a double (n beyond 2^53): n
|
|
555
|
+
* rebuilt as x + fl(n - x) was up to an ulp off, which at n near 1e308 is 1e137 standard deviations (dbinom(4e307,
|
|
556
|
+
* 1.6e308, 0.25) was 0 for 7.3e-155), and even double-double n q is off by 1e276 there. The deviations are formed
|
|
557
|
+
* exactly instead: with p a double, d1 = x - n p from the exact product, and d2 = (n - x) - n q = -d1 (q = 1 - p
|
|
558
|
+
* exactly); with q a double the roles swap. Otherwise as binomialExponent
|
|
559
|
+
*/
|
|
560
|
+
function exactBinomialExponent(x, n, p, q) {
|
|
561
|
+
const xd = [x, 0];
|
|
562
|
+
const rest = twoSum(n, -x);
|
|
563
|
+
// the exact product n r (n scaled by 2^-64 above 1e299, where the splitting overflows; exact, and back)
|
|
564
|
+
const times = (r) => {
|
|
565
|
+
if (n < 1e299)
|
|
566
|
+
return twoProd(n, r);
|
|
567
|
+
const t = twoProd(n * 2 ** -64, r);
|
|
568
|
+
return [t[0] * 2 ** 64, t[1] * 2 ** 64];
|
|
569
|
+
};
|
|
570
|
+
let d1;
|
|
571
|
+
let d2;
|
|
572
|
+
if (p[1] === 0) {
|
|
573
|
+
d1 = ddSub(xd, times(p[0]));
|
|
574
|
+
d2 = ddNeg(d1);
|
|
575
|
+
}
|
|
576
|
+
else if (q[1] === 0) {
|
|
577
|
+
d2 = ddSub(rest, times(q[0]));
|
|
578
|
+
d1 = ddNeg(d2);
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
return binomialExponent(x, rest[0], twoSum(x, rest[0]), p, q);
|
|
582
|
+
}
|
|
583
|
+
const b1 = bd0FromDeviance(xd, ddSub(xd, d1), d1);
|
|
584
|
+
const b2 = bd0FromDeviance(rest, ddSub(rest, d2), d2);
|
|
585
|
+
if (!Number.isFinite(b1[0] + b2[0]))
|
|
586
|
+
return [Infinity, 0];
|
|
587
|
+
return ddAdd(ddAdd(b1, b2), twoSum(stirlerr(x) + stirlerr(rest[0]), -stirlerr(n)));
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* bd0(x, M) = x log(x/M) + M - x with x, M and d = x - M given in double-double (d exact where M is not): the series of
|
|
591
|
+
* bd0ddOps for a small |d|, else x log(x/M) - d. Homogeneous of degree 1, so computed times 2^-64 above 1e299
|
|
592
|
+
*/
|
|
593
|
+
function bd0FromDeviance(x, M, d) {
|
|
594
|
+
if (Math.max(x[0], M[0]) > 1e299) {
|
|
595
|
+
const s = 2 ** -64;
|
|
596
|
+
return scaleUp(bd0FromDeviance([x[0] * s, x[1] * s], [M[0] * s, M[1] * s], [d[0] * s, d[1] * s]));
|
|
597
|
+
}
|
|
598
|
+
if (Math.abs(d[0]) < 0.1 * (x[0] + M[0])) {
|
|
599
|
+
const v = ddDiv(d, ddAdd(x, M));
|
|
600
|
+
let s = ddMul(d, v);
|
|
601
|
+
let ej = ddMul(v, [2 * x[0], 2 * x[1]]);
|
|
602
|
+
const v2 = ddMul(v, v);
|
|
603
|
+
for (let j = 1; j < 1000; j++) {
|
|
604
|
+
ej = ddMul(ej, v2);
|
|
605
|
+
const t = ddDivNum(ej, 2 * j + 1);
|
|
606
|
+
const s1 = ddAdd(s, t);
|
|
607
|
+
if (Math.abs(t[0]) <= 1e-33 * Math.abs(s1[0]) || (s1[0] === s[0] && s1[1] === s[1]))
|
|
608
|
+
return s1;
|
|
609
|
+
s = s1;
|
|
610
|
+
}
|
|
611
|
+
return s;
|
|
612
|
+
}
|
|
613
|
+
const ratio = x[0] / M[0];
|
|
614
|
+
const lr = ratio > 1e-290 && ratio < 1e290 ? ddLog(ddDiv(x, M)) : ddSub(ddLog(x), ddLog(M));
|
|
615
|
+
return ddSub(ddMul(lr, x), d);
|
|
616
|
+
}
|
|
617
|
+
function binomialExponent(x, nmx, nn, p, q, kp = 0, kq = 0) {
|
|
618
|
+
const d1 = bd0Prod(x, nn, p, kp);
|
|
619
|
+
const d2 = bd0Prod(nmx, nn, q, kq);
|
|
523
620
|
if (!Number.isFinite(d1[0] + d2[0]))
|
|
524
621
|
return [Infinity, 0];
|
|
525
622
|
return ddAdd(ddAdd(d1, d2), twoSum(stirlerr(x) + stirlerr(nmx), -stirlerr(nn[0])));
|
package/dist/special/log1pmx.js
CHANGED
|
@@ -5,6 +5,10 @@ import { MACHEP } from "./constants.js";
|
|
|
5
5
|
/** log(1 + x) - x. Uses a series for small |x| to avoid cancellation */
|
|
6
6
|
export function log1pmx(x) {
|
|
7
7
|
if (Math.abs(x) < 0.5) {
|
|
8
|
+
// (added for rStats.js) x^2 = 0, x = 0 included: every term is 0 and the series gave +0 only after its 498 steps,
|
|
9
|
+
// as the test |term| < eps |res| is then 0 < 0 (issue #106)
|
|
10
|
+
if (x * x === 0)
|
|
11
|
+
return 0;
|
|
8
12
|
let xfac = x;
|
|
9
13
|
let res = 0;
|
|
10
14
|
for (let n = 2; n < 500; n++) {
|
package/dist/special.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
2
|
-
import{a as wt,b as Lt,c as _t,d as Et}from"./chunks/chunk-NM3Z2UBQ.js";import{c as G,d as St,e as jt}from"./chunks/chunk-FKAKALOZ.js";import{A as v,H as ht,M as Dt,N as Ft,b as $,c as qt,h as ft,k as d,l as q,m as U,n as _,o as C,p as Z,q as ct,u as z,v as lt,w as mt,y as ut}from"./chunks/chunk-3TSWYE5L.js";import{b as E,d as j,f as T,g as J,h as at,i as O,k as L}from"./chunks/chunk-KT66SB7R.js";var Mt=22250738585072014e-324;function W(t,e,n){if(t<10)return Math.pow(e/2,t)/q(t+1)*n;let s=e/2,r=z(t,s,!1);if(r>=Mt&&s<700){let a=r*Math.exp(s)*n;if(Math.abs(a)>=Mt)return a}let o=z(t,s,!0)+s+Math.log(Math.abs(n));return Math.sign(n)*Math.exp(o)}var D=Number.EPSILON,H=1e6;function pt(t){return Math.expm1(C(t))}function Tt(t,e){let n=pt(t),s=pt(-t),r=Math.log(e/2),o=Math.exp(t*r),a=-r*t,i=Math.abs(t)<D?1:d(t)/(t*Math.PI),c=Math.abs(a)<D?1:Math.sinh(a)/a,l=Math.abs(t)<D?-.5772156649015329:.5/t*(n-s)*i,f=(2+n+s)*i/2,m=(n+1)/(2*o),u=(1+s)*o/2,M=(Math.cosh(a)*l+c*-r*f)/i,p=m,h=1,S=h*M,k=h*p;for(let I=1;I<H&&(M=(I*M+m+u)/(I*I-t*t),m/=I-t,u/=I+t,p=m-I*M,h*=e*e/(4*I),S+=h*M,k+=h*p,!(Math.abs(h*M)<Math.abs(S)*D));I++);return[S,2*k/e]}function At(t,e){let n=Math.sqrt(Number.MIN_VALUE*4503599627370496),s=n,r=n,o=0;for(let a=1;a<H;a++){let i=2*(t+a)/e;s=i+1/s,o=i+o,s===0&&(s=n),o===0&&(o=n),o=1/o;let c=s*o;if(r*=c,Math.abs(c-1)<=2*D)break}return r}function Jt(t,e){let n=t*t-.25,s=2*(e+1),r=1/s,o=r,a=r,i=0,c=1,l=-n,f=l,m=1+f*a;for(let p=2;p<H;p++){n-=2*(p-1),s+=2,r=1/(s+n*r),a*=s*r-1,o+=a;let h=(i-(s-2)*c)/n;if(i=c,c=h,l*=-n/p,f+=l*h,m+=f*a,h<D&&(l*=h,i/=h,c/=h),Math.abs(f*a)<Math.abs(m)*D)break}let u=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/m;return[M,M*u]}function V(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function bt(t,e){let n=Math.round(t),s=t-n,r,o;if(s===-.5)r=o=Math.sqrt(Math.PI/(2*e));else if(e<=2){let[i,c]=Tt(s,e),l=Math.exp(e);r=i*l,o=c*l}else[r,o]=Jt(s,e);let a=0;for(let i=1;i<=n;i++){let c=2*(s+i)/e,l=Math.log2(Math.abs(o))+Math.log2(c);if(l>900&&Number.isFinite(l)){let m=Math.ceil(l-800);r=V(r,-m),o=V(o,-m),a+=m}let f=c*o+r;r=o,o=f}return{k:r,k1:o,exp2:a}}function Kt(t,e){let n=e*e/4,s=1,r=0;for(let o=1;o<H&&(r+=s,s*=n/o,s/=o+t,!(Math.abs(s)<=D*Math.abs(r)));o++);return W(t,e,r+s)}function Rt(t,e,n){if(t===0||!Number.isFinite(t))return t;let s=t,r=e,o=n>0?700:-700,a=Math.exp(o);for(;Math.abs(n)>700;){n-=o,s*=a;let i=Math.floor(Math.log2(Math.abs(s)));s=V(s,-i),r+=i}return V(s*Math.exp(n),r)}function x(t,e,n){let s=t.ex+n;return s===0?V(t.m,t.e2):Rt(t.m,t.e2,s*e)}function Yt(t,e){if(t===.5)return{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(t>0&&e/t<.25)return{m:Kt(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<D*10&&e>100){let i=4*t*t,c=8*e,l=i-1,f=c,m=1-l/f;return l*=i-9,f*=c*2,m+=l/f,l*=i-25,f*=c*3,m-=l/f,{m:m/Math.sqrt(2*e*Math.PI),e2:0,ex:1}}let{k:s,k1:r,exp2:o}=bt(t,e),a=At(t,e);return{m:1/(e*(s*a+r)),e2:-o,ex:1}}function Nt(t,e){let n=4*t*t,s=8*e,r=(n-1)/s,o=r*(n-9)/(2*s),a=o*(n-25)/(3*s),i=a*(n-49)/(4*s),c=1+r+o+a;if(Math.abs(i)<D*Math.abs(c))return{m:c*Math.sqrt(Math.PI)/Math.sqrt(2*e),e2:0,ex:-1};let{k:l,exp2:f}=bt(t,e);return{m:l,e2:f,ex:-1}}function Ct(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?d(r)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return s?0:1/0;let a=s?-1:0,i=x(Yt(r,t),t,a);if(!o)return i;let c=Nt(r,t);return i+x({...c,m:2/Math.PI*d(r)*c.m},t,a)}function Qt(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e);return t===0?1/0:t===1/0?0:x(Nt(r,t),t,s?1:0)}var y=Number.EPSILON;function A(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function gt(t,e,n,s,r){let o=s,a=r,i=0;for(let c=1;c<=n;c++){let l=2*(t+c)/e,f=Math.log2(Math.abs(a))+Math.log2(l);if(f>900&&Number.isFinite(f)){let u=Math.ceil(f-800);o=A(o,-u),a=A(a,-u),i+=u}let m=l*a-o;o=a,a=m}return{y:o,y1:a,e2:i}}var K=1e6,g=Math.sqrt(22250738585072014e-324),Ut=Number.MAX_VALUE;function It(t){return Math.expm1(C(t))}function Q(t){return d(.5-Math.abs(t%2))}function dt(t,e){let n=-(e/2)*(e/2),s=1,r=0;for(let o=1;o<K&&(r+=s,s*=n/(o*(o+t)),!(Math.abs(s)<=y*Math.abs(r)));o++);return W(t,e,r+s)}function Vt(t,e){let n=Math.log(e/2),s=0,r=t>=170||709.78/t<Math.abs(n),o;if(r){let u=_(t);if(n=t*n,o=u-Math.log(Math.PI)-n,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,s=M}o=-Math.exp(o)}else{let u=q(t);n=Math.pow(e/2,t),Ut*n<u&&(u*=2**-1e3,s=1e3),o=-u/(Math.PI*n)}let a=-(e/2)*(e/2),i=1,c=0;for(let u=1;u<K&&(c+=i,i*=a/(u*(u-t)),!(Math.abs(i)<=y*Math.abs(c)));u++);let l=(c+i)*o,f;if(!r)f=q(-t)*Q(t)*n/Math.PI;else{let u=U(-t);f=Math.exp(u.value+n)*u.sign/Math.PI}i=1;let m=0;for(let u=1;u<K&&(m+=i,i*=a/(u*(u+t)),!(Math.abs(i)<=y*Math.abs(m)));u++);return m+=i,l-=A(f*m,-s),{m:l,e2:s}}function Xt(t,e){let n=1,s=0,r=1,o=8*e,a=1,i=4*t*t,c=1,l=!0;do{c*=(i-a*a)/(r*o),s+=c,r+=1,a+=2;let f=(a*a-i)/(r*o);l=Math.abs(f)<.5,c*=f,n+=c,r+=1,a+=2}while(Math.abs(c)>2*y*n&&l);return l?{p:n,q:s}:void 0}function Bt(t,e){let n=It(t),s=It(-t),r=d(t),o=d(t/2),a=Math.pow(e/2,t),i=Math.log(e/2),c=-i*t,l=Math.abs(c)<y?1:Math.sinh(c)/c,f=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,m=t===0?-.5772156649015329:(n-s)/((1+n)*(1+s)*2*t),u=(2+n+s)/((1+n)*(1+s)*2),M=Math.abs(t)<y?1/Math.PI:t/r,p=(m*Math.cosh(c)-u*i*l)*2*M,h=M/(a*(1+s)),S=M*a/(1+n),k=p+f*S,I=h,F=1,R=F*k,X=F*I,B=t*t,b=-e*e/4;for(let N=1;N<K&&(p=(N*p+h+S)/(N*N-B),h/=N-t,S/=N+t,k=p+f*S,I=h-N*k,F*=b/N,R+=F*k,X+=F*I,!(Math.abs(F*k)<Math.abs(R)*y));N++);return[-R,-2*X/e]}function Ot(t,e){let n=[g,0],s=[g,0],r=[0,0],o=1,a=[e,0];for(let i=1;i<K*100;i++){let c=E(t,i),l=O([2*c[0],2*c[1]],a);n=T(l,O([1,0],n)),r=T(l,r),n[0]===0&&(n=[g,0]),r[0]===0&&(r=[g,0]),r=O([1,0],r);let f=J(n,r);if(s=J(s,f),r[0]<0&&(o=-o),Math.abs(f[0]-1+f[1])<y*y)break}return{fv:-(s[0]+s[1]),sign:o}}function yt(t,e){if(e>30)return Ot(t,e);let n=g,s=g,r=0,o=1;for(let a=1;a<K*100;a++){let i=2*(t+a)/e;n=i-1/n,r=i-r,n===0&&(n=g),r===0&&(r=g),r=1/r;let c=n*r;if(s*=c,r<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-s,sign:o}}function Pt(t,e){let n=-.5/e,s=1,r=n,o=s,a=t*t,i=(.25-a)/e,c=2*e,l=2,f=r*r+1;o=l+i*r/f,r=c+i/f;let m=c,u=l;Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f;let M=r*m-o*u,p=o*m+r*u;f=n,n=f*M-s*p,s=f*p+s*M;for(let h=2;h<K&&(i=h-.5,i*=i,i-=a,l+=2,f=r*r+o*o,r=c+i*r/f,o=l-i*o/f,m=c+i*m,u=l+i*u,Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f,M=r*m-o*u,p=o*m+r*u,f=n,n=f*M-s*p,s=f*p+s*M,!(Math.abs(M-1)+Math.abs(p)<2*y));h++);return{p:n,q:s}}function Zt(t,e){let n=1,s=4*t*t,r=2*e;return r*=r,n+=(s-1)/(2*r),n+=3*(s-1)*(s-9)/(r*r*8),n+=15*(s-1)*(s-9)*(s-25)/(r*r*r*8*6),Math.sqrt(n*2/(Math.PI*e))}function Gt(t,e){let n=4*t*t,s=4*e,r=s*s,o=0;return o+=(n-1)/(2*s),s*=r,o+=(n-1)*(n-25)/(6*s),s*=r,o+=(n-1)*(n*n-114*n+1073)/(5*s),s*=r,o+=(n-1)*(5*n*n*n-1535*n*n+54703*n-375733)/(14*s),o}function Wt(t,e){let n=Zt(t,e),s=Gt(t,e),r=Math.cos(e),o=Math.sin(e),a=Q(t/2+.25),i=d(t/2+.25),c=Math.sin(s),l=Math.cos(s),f=(c*(r*a+o*i)+l*(o*a-r*i))*n;return{j:(l*(r*a+o*i)-c*(o*a-r*i))*n,y:f}}function tt(t,e,n){let s=Math.round(t),r=t-s,o=2/(e*Math.PI);if(!n&&(e<5||t>e*e/4))return{j:dt(t,e),y:{m:NaN,e2:0}};if(e<1&&r!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:dt(t,e),y:Vt(t,e)};if(Math.max(t,1)<e*.011048543456039806){let b=Wt(t,e);return{j:b.j,y:{m:b.y,e2:0}}}if(e>8){let b=Xt(t,e);if(b!==void 0){let N=(t/2+.25)%2,P=Math.sin(e),w=Math.cos(e),Y=d(N),rt=Q(N),st=P*rt-Y*w,ot=w*rt+P*Y,it=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:it*(b.p*ot-b.q*st),y:{m:it*(b.p*st+b.q*ot),e2:0}}}}if(e<=2){let[b,N]=Bt(r,e),P=gt(r,e,s,b,N),{fv:w}=yt(t,e);return{j:A(o/(P.y*w-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let{fv:a,sign:i}=yt(t,e);if(e>=t&&t>2){let{p:b,q:N}=Pt(t,e),P=t/e-a,w=(b-P)/N;w===0&&(w=t*y/e);let Y=i*Math.sqrt(o/(N+w*(b-P)));return{j:Y,y:{m:w*Y,e2:0}}}let c=g,l=a*i*c,f=i*c,m=0;for(let b=s;b>0;b--){let N=2*(r+b)/e;Math.abs(f)>2**900&&(l*=2**-900,f*=2**-900,m+=900);let P=N*f-l;P===0&&(P=l*y/2),l=f,f=P}let u=A(i*c/f,-m),M=l/f,{p,q:h}=Pt(r,e),S=r/e-M,k=(p-S)/h;k===0&&(k=r*y/e);let I=Math.sign(f)*Math.sqrt(o/(h+k*(p-S))),F=I*u,R=k*I,X=R*(r/e-p-h/k);if(!n)return{j:F,y:{m:NaN,e2:0}};let B=gt(r,e,s,R,X);return{j:F,y:{m:B.y,e2:B.e2}}}function Ht(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:s?d(n)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!s){let o=tt(n,t,!1).j;return e<0&&n%2===1?-o:o}let r=tt(n,t,!0);return Q(n)*r.j-A(d(n)*r.y.m,r.y.e2)}function $t(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0;if(t===0){if(!s)return-1/0;let i=Q(n);return i===0?0:i>0?-1/0:1/0}if(t===1/0)return 0;let r=tt(n,t,!0);if(!s)return A(r.y.m,r.y.e2);let o=Q(n),a=d(n);return(a!==0?a*r.j:0)+(o===0?0:A(o*r.y.m,r.y.e2))}function zt(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let n=_(e),s=q(e),r=l=>{let f=v(e,t,l,!1),m=s*f;if(Number.isFinite(s)&&f>kt&&Number.isFinite(m)&&m>kt)return[m,Math.log(m)];let u=n+v(e,t,l,!0);return u<710&&u>-746&&t>0&&(l?t<e:t>e)?vt(t,e,l):[Math.exp(u),u]},[o,a]=r(!0),[i,c]=r(!1);return{lower:o,upper:i,logLower:a,logUpper:c}}var kt=22250738585072014e-324;function vt(t,e,n){let s=j(at(L([t,0]),e),[-t,0]);n?s=j(s,L([mt(e,t)/e,0])):s=j(s,L([ut(e,t),0]));let r=s[0]+s[1];return[s[0]>-708?Math.exp(s[0])*(1+s[1]):Math.exp(r),r]}function et(t){return Number.isNaN(t)||t<0||t>2?NaN:-ft(t/2)*Math.SQRT1_2}function xt(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,n=Math.abs(t);if(n>=.5)return e*et(1-n);if(n<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let s=et(1-n);for(let r=0;r<3;r++){let o=($(s)-n)/(1.1283791670955126*Math.exp(-s*s));if(s-=o,Math.abs(o)<=1e-17*s)break}return e*s}function te(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let n=e===Math.floor(e);return t===Math.floor(t)&&n&&e>t?0:!Number.isFinite(t)||!Number.isFinite(e)?ie(t,e):n&&e<=1e3?ee(t,e):ne(t,e)}function ee(t,e){let n=[1,0];for(let s=0;s<e;s++){let r=E(t,-s),o=n[0]*r[0];if(!Number.isFinite(o)){let a=Math.sign(o);for(let i=s+1;i<e;i++)t-i<0&&(a=-a);return a*(1/0)}n=Math.abs(n[0])>1e290||Math.abs(r[0])>1e290?[(n[0]+n[1])*(r[0]+r[1]),0]:J(n,r)}return n[0]+n[1]}function ne(t,e){let[n,s]=E(t,-e);if(n+1<=0)return re(t,n,s);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let r;if(n>=15){if(e*Math.log(n+1)>720)return 1/0;let o=E(t,-n),a=T(J(o,L([t,0])),ct(n,[t,0]));a=j(a,[Z(t)-Z(n),0]),r=Math.sqrt(t/n)*Math.exp(a[0])*(1+a[1])}else if(t<30)r=q(t+1)/q(n+1);else{if(_(t+1)-_(n+1)>720)return 1/0;let o=T(nt(t+1),L([q(n+1),0]));r=Math.exp(o[0])*(1+o[1])}return s!==0&&Number.isFinite(r)&&r!==0&&(r*=Math.exp(-s*G(n+1))),r}function re(t,e,n){let s=j(E(e,1),[n,0]),r=d(s[0])+d(s[0]+.5)*Math.PI*s[1];if(r===0)return 0;let o=Math.sign(r),a=j(T(L([Math.abs(r),0]),oe),[-n*G(-e),0]);if(_(t+1)+_(-e)+a[0]>720)return o*(1/0);let i=j(j(nt(t+1),nt(-e)),a);return o*Math.exp(i[0])*(1+i[1])}var se=[.9189385332046728,-38782941580672414e-33],oe=[1.1447298858494002,10265951162707826e-33];function nt(t){if(t<15)return L([q(t),0]);let e=T(J(E(t,-.5),L([t,0])),[t,0]);return j(j(e,se),[Z(t),0])}function ie(t,e){let n=U(t+1),s=U(t-e+1);return n.sign*s.sign*Math.exp(n.value-s.value)}function ae(t){return Number.isNaN(t)||t<-1?NaN:t===-1||t===1/0?-1/0:lt(t)}function fe(t){return Number.isNaN(t)||t===-1/0?NaN:t===1/0||t<=-1&&t===Math.floor(t)?1/0:C(t)}function ce(t){return Number.isNaN(t)||t<0?NaN:t===0?-1/0:t===1/0?0:ht(-t)}function le(t){return Number.isNaN(t)?NaN:t<=-37?Math.exp(t):t<=18?Math.log1p(Math.exp(t)):t<=33.3?t+Math.exp(-t):t}export{Ct as besselI,Ht as besselJ,Qt as besselK,$t as besselY,Dt as beta,wt as choose,G as digamma,$ as erf,qt as erfc,et as erfcinv,xt as erfinv,_t as factorial,q as gamma,zt as gammainc,Ft as lbeta,Lt as lchoose,Et as lfactorial,_ as lgamma,fe as lgamma1p,ce as log1mexp,le as log1pexp,ae as log1pmx,te as perm,jt as psigamma,St as trigamma};
|
|
1
|
+
/*! rStats.js 0.16.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 Ut,b as Vt,c as Qt,d as Zt}from"./chunks/chunk-K3RJAD2T.js";import{a as Wt,b as vt,c as xt,d as te}from"./chunks/chunk-URIO5LY5.js";import{d as et,e as Ct,f as Gt}from"./chunks/chunk-6CSTWA5E.js";import{A as x,B as Pt,F as at,H as qt,J as _t,L as tt,O as zt,P as Ht,b as ot,c as Yt,s as it,v as N,w as E,x as H,y as S,z as v}from"./chunks/chunk-SC6CV4Z3.js";import{b as D,d as w,f as T,g as O,h as yt,i as W,k as A}from"./chunks/chunk-GM53LWSR.js";var Et=22250738585072014e-324,ee=Number.EPSILON,St=2**-1021;function K(t){return t>=St?Math.log(t/2):Math.log(t)-Math.LN2}function nt(t,e){return t>=St?Math.pow(t/2,e):Math.pow(t,e)*Math.pow(2,-e)}function rt(t,e,r){if(t<10)return nt(e,t)/E(t+1)*r;let s=e/2,n=at(t,s,!1);if(n>=Et&&s<700){let i=n*Math.exp(s)*r;if(Math.abs(i)>=Et)return i}let o=at(t,s,!0)+s+Math.log(Math.abs(r));return Math.sign(r)*Math.exp(o)}var Y=1e3,ne=Math.log(Number.MAX_VALUE),re=Math.log(Number.MIN_VALUE)-Math.LN2;function C(t,e){let r=t*K(e),s=S(t+1),n=e*e/(4*(t+1));return{lo:r-s,hi:r-s+n,size:Math.abs(r)+Math.abs(s)+n}}function j(t){let e=1+64*ee*t.size;return t.lo-e>ne?1:t.hi+e<re?-1:0}var F=Number.EPSILON,st=1e6,ct=2**-1e3;function Lt(t){return Math.expm1(v(t))}function se(t,e){let r=Lt(t),s=Lt(-t),n=K(e),o=Math.exp(t*n),i=-n*t,a=Math.abs(t)<F?1:N(t)/(t*Math.PI),c=Math.abs(i)<F?1:Math.sinh(i)/i,u=Math.abs(t)<F?-.5772156649015329:.5/t*(r-s)*a,l=(2+r+s)*a/2,h=(r+1)/(2*o),f=(1+s)*o/2,M=(Math.cosh(i)*u+c*-n*l)/a,m=h,b=1,q=b*M,d=b*m;for(let p=1;p<st&&(M=(p*M+h+f)/(p*p-t*t),h/=p-t,f/=p+t,m=h-p*M,b*=e*e/(4*p),q+=b*M,d+=b*m,!(Math.abs(b*M)<Math.abs(q)*F));p++);return[q,2*d/e]}function oe(t,e){if(!Number.isFinite(2*(t+1)/e))return[e/2/(t+1),!0];let r=Math.sqrt(Number.MIN_VALUE*2**52),s=r,n=r,o=0;for(let i=1;i<st;i++){let a=2*(t+i)/e;s=a+1/s,o=a+o,s===0&&(s=r),o===0&&(o=r),o=1/o;let c=s*o;if(n*=c,Math.abs(c-1)<=2*F)return[n,!0]}return[n,!1]}function ie(t,e){let r=t*t-.25,s=2*(e+1),n=1/s,o=n,i=n,a=0,c=1,u=-r,l=u,h=1+l*i;for(let m=2;m<st;m++){r-=2*(m-1),s+=2,n=1/(s+r*n),i*=s*n-1,o+=i;let b=(a-(s-2)*c)/r;if(a=c,c=b,u*=-r/m,l+=u*b,h+=l*i,b<F&&(u*=b,a/=b,c/=b),Math.abs(l*i)<Math.abs(h)*F)break}let f=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/h;return[M,M*f]}function V(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}var ut=2**28;function Rt(t,e,r,s){let n=Math.round(t);if(n>ut)throw new RangeError(`${r}: x = ${e}, nu = ${s} needs a recurrence of about ${n} steps (at most 2^28)`);let o=t-n,i,a;if(o===-.5)i=a=e<ct?Math.sqrt(Math.PI/2)/Math.sqrt(e):Math.sqrt(Math.PI/(2*e));else if(e<=2){let[u,l]=se(o,e),h=Math.exp(e);i=u*h,a=l*h}else[i,a]=ie(o,e);let c=0;for(let u=1;u<=n;u++){let l=2*(o+u)/e,h=Math.log2(Math.abs(a))+Math.log2(l);if(h>900&&Number.isFinite(h)){let M=Math.ceil(h-800);i=V(i,-M),a=V(a,-M),c+=M}let f=l*a+i;i=a,a=f}return{k:i,k1:a,exp2:c}}function ae(t,e){let r=e*e/4,s=1,n=0;for(let o=1;o<st&&(n+=s,s*=r/o,s/=o+t,!(Math.abs(s)<=F*Math.abs(n)));o++);return rt(t,e,n+s)}var ce=2**26;function ft(t,e,r,s){let n=e/t,o=n>1?n*Math.sqrt(1+1/(n*n)):Math.sqrt(1+n*n),i=1/o,a=i*i,c=i*(3-5*a)/24,u=a*(81+a*(-462+a*385))/1152,l=i*a*(30375+a*(-369603+a*(765765-a*425425)))/414720,h=a*a*(4465125+a*(-94121676+a*(349922430+a*(-446185740+a*185910725))))/39813120,f=1/t,M=r==="I"?1:-1,m=1+f*(M*c+f*(u+f*(M*l+f*h))),b=o+n,q=t/b,d=t*Math.log1p((1+1/b)/n),p=Math.sqrt(t)*Math.sqrt(o),_=Math.abs(q)+Math.abs(d);return r==="I"?{m:m/(Math.sqrt(2*Math.PI)*p),e2:0,ex:1,debye:{y:q-d,size:_,what:s}}:{m:m*Math.sqrt(Math.PI/2)/p,e2:0,ex:-1,debye:{y:d-q,size:_,what:s}}}function wt(t,e,r){if(t===0||!Number.isFinite(t))return t;let s=Math.log2(Math.abs(t))+e+r*Math.LOG2E;if(s<-1100)return t*0;if(s>1100)return t*(1/0);let n=t,o=e,i=r>0?700:-700,a=Math.exp(i);for(;Math.abs(r)>700;){r-=i,n*=a;let c=Math.floor(Math.log2(Math.abs(n)));n=V(n,-c),o+=c}return V(n*Math.exp(r),o)}function lt(t,e,r){let s=t.ex+r;if(t.debye){let{y:n,size:o,what:i}=t.debye,a=wt(t.m,t.e2,s*e+n),c=o+Math.abs(s)*e;if(a!==0&&Number.isFinite(a)&&c>ce)throw new RangeError(`${i} has an exponent in Debye's expansion formed from terms of about ${c.toPrecision(3)}, which double precision does not resolve (at most 2^26)`);return a}return s===0?V(t.m,t.e2):wt(t.m,t.e2,s*e)}function fe(t,e,r,s){if(t===.5)return e<ct?{m:Math.sqrt(2/Math.PI)*Math.sqrt(e),e2:0,ex:1}:{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(e<ct||t>0&&e/t<.25)return{m:ae(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<F*10&&e>100){let l=4*t*t,h=8*e,f=l-1,M=h,m=1-f/M;f*=l-9,M*=h*2,m+=f/M,f*=l-25,M*=h*3,m-=f/M;let b=Number.isFinite(2*e*Math.PI)?Math.sqrt(2*e*Math.PI):Math.sqrt(2*Math.PI)*Math.sqrt(e);return{m:m/b,e2:0,ex:1}}if(Math.round(t)>ut)return ft(t,e,"I",`${r}: x = ${e}, nu = ${s}`);let[o,i]=oe(t,e);if(!i&&t>Y)return ft(t,e,"I",`${r}: x = ${e}, nu = ${s}`);let{k:a,k1:c,exp2:u}=Rt(t,e,r,s);return{m:1/(e*(a*o+c)),e2:-u,ex:1}}function $t(t,e,r,s){let n=4*t*t,o=8*e,i=(n-1)/o,a=i*(n-9)/(2*o),c=a*(n-25)/(3*o),u=c*(n-49)/(4*o),l=1+i+a+c;if(Math.abs(u)<F*Math.abs(l))return{m:Number.isFinite(2*e)?l*Math.sqrt(Math.PI)/Math.sqrt(2*e):l*Math.sqrt(Math.PI/2)/Math.sqrt(e),e2:0,ex:-1};if(Math.round(t)>ut)return ft(t,e,"K",`${r}: x = ${e}, nu = ${s}`);let{k:h,exp2:f}=Rt(t,e,r,s);return{m:h,e2:f,ex:-1}}function kt(t,e){let r=C(t-1,e),s=C(t+1,e),n=Math.log(e);return{lo:-r.hi-n-Math.LN2,hi:-s.lo-n,size:r.size+s.size+Math.abs(n)+1}}function U(t,e){return{lo:t.lo+e,hi:t.hi+e,size:t.size+Math.abs(e)}}var Ft=Math.log1p(-Math.exp(-1));function le(t,e,r={}){let s=r.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?N(n)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return s?0:1/0;let i=s?-1:0;if(n>Y){let u=U(C(n,t),i*t),l=j(u);if(o){let h=N(n),f=U(kt(n,t),i*t+Math.log(2/Math.PI*Math.abs(h)));if(l===-1&&j(f)===-1)return 0;if(f.lo-1>u.hi&&j(U(f,Ft))===1)return h>0?1/0:-1/0;if(u.lo-1>f.hi&&j(U(u,Ft))===1)return 1/0}else if(l!==0)return l>0?1/0:0}let a=lt(fe(n,t,"besselI",e),t,i);if(!o)return a;let c=$t(n,t,"besselI",e);return a+lt({...c,m:2/Math.PI*N(n)*c.m},t,i)}function ue(t,e,r={}){let s=r.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e);if(t===0)return 1/0;if(t===1/0)return 0;if(n>Y){let o=j(U(kt(n,t),s?t:0));if(o!==0)return o>0?1/0:0}return lt($t(n,t,"besselK",e),t,s?1:0)}var y=Number.EPSILON;function X(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function At(t,e,r,s,n){let o=s,i=n,a=0;for(let c=1;c<=r;c++){let u=2*(t+c)/e,l=Math.log2(Math.abs(i))+Math.log2(u);if(l>900&&Number.isFinite(l)){let f=Math.ceil(l-800);o=X(o,-f),i=X(i,-f),a+=f}let h=u*i-o;o=i,i=h}return{y:o,y1:i,e2:a}}var B=1e6,I=Math.sqrt(22250738585072014e-324),he=Number.MAX_VALUE;function jt(t){return Math.expm1(v(t))}function G(t){return N(.5-Math.abs(t%2))}function Dt(t,e){let r=-(e/2)*(e/2),s=1,n=0;for(let o=1;o<B&&(n+=s,s*=r/(o*(o+t)),!(Math.abs(s)<=y*Math.abs(n)));o++);return rt(t,e,n+s)}function Me(t,e){let r=K(e),s=0,n=t>=170||709.78/t<Math.abs(r),o;if(n){let f=S(t);if(r=t*r,o=f-Math.log(Math.PI)-r,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,s=M}o=-Math.exp(o)}else{let f=E(t);r=nt(e,t),he*r<f&&(f*=2**-1e3,s=1e3),o=-f/(Math.PI*r)}let i=-(e/2)*(e/2),a=1,c=0;for(let f=1;f<B&&(c+=a,a*=i/(f*(f-t)),!(Math.abs(a)<=y*Math.abs(c)));f++);let u=(c+a)*o,l;if(!n)l=E(-t)*G(t)*r/Math.PI;else{let f=H(-t);l=Math.exp(f.value+r)*f.sign/Math.PI}a=1;let h=0;for(let f=1;f<B&&(h+=a,a*=i/(f*(f+t)),!(Math.abs(a)<=y*Math.abs(h)));f++);return h+=a,u-=X(l*h,-s),{m:u,e2:s}}function me(t,e){let r=1,s=0,n=1,o=8*e,i=1,a=4*t*t,c=1,u=!0;do{c*=(a-i*i)/(n*o),s+=c,n+=1,i+=2;let l=(i*i-a)/(n*o);u=Math.abs(l)<.5,c*=l,r+=c,n+=1,i+=2}while(Math.abs(c)>2*y*r&&u);return u?{p:r,q:s}:void 0}function be(t,e){let r=jt(t),s=jt(-t),n=N(t),o=N(t/2),i=nt(e,t),a=K(e),c=-a*t,u=Math.abs(c)<y?1:Math.sinh(c)/c,l=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,h=t===0?-.5772156649015329:(r-s)/((1+r)*(1+s)*2*t),f=(2+r+s)/((1+r)*(1+s)*2),M=Math.abs(t)<y?1/Math.PI:t/n,m=(h*Math.cosh(c)-f*a*u)*2*M,b=M/(i*(1+s)),q=M*i/(1+r),d=m+l*q,p=b,_=1,R=_*d,z=_*p,Q=t*t,Z=-e*e/4;for(let L=1;L<B&&(m=(L*m+b+q)/(L*L-Q),b/=L-t,q/=L+t,d=m+l*q,p=b-L*d,_*=Z/L,R+=_*d,z+=_*p,!(Math.abs(_*d)<Math.abs(R)*y));L++);return[-R,-2*z/e]}function pe(t,e){let r=[I,0],s=[I,0],n=[0,0],o=1,i=[e,0];for(let a=1;a<B*100;a++){let c=D(t,a),u=W([2*c[0],2*c[1]],i);r=T(u,W([1,0],r)),n=T(u,n),r[0]===0&&(r=[I,0]),n[0]===0&&(n=[I,0]),n=W([1,0],n);let l=O(r,n);if(s=O(s,l),n[0]<0&&(o=-o),Math.abs(l[0]-1+l[1])<y*y)break}return{fv:-(s[0]+s[1]),sign:o}}function Tt(t,e){if(e>30)return pe(t,e);if(!Number.isFinite(2*(t+1)/e))return{fv:e/2/(t+1),sign:1};let r=I,s=I,n=0,o=1;for(let i=1;i<B*100;i++){let a=2*(t+i)/e;r=a-1/r,n=a-n,r===0&&(r=I),n===0&&(n=I),n=1/n;let c=r*n;if(s*=c,n<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-s,sign:o}}function Xt(t,e){let r=-.5/e,s=1,n=r,o=s,i=t*t,a=(.25-i)/e,c=2*e,u=2,l=n*n+1;o=u+a*n/l,n=c+a/l;let h=c,f=u;Math.abs(n)+Math.abs(o)<I&&(n=I),Math.abs(h)+Math.abs(f)<I&&(h=I),l=h*h+f*f,h=h/l,f=-f/l;let M=n*h-o*f,m=o*h+n*f;l=r,r=l*M-s*m,s=l*m+s*M;for(let b=2;b<B&&(a=b-.5,a*=a,a-=i,u+=2,l=n*n+o*o,n=c+a*n/l,o=u-a*o/l,h=c+a*h,f=u+a*f,Math.abs(n)+Math.abs(o)<I&&(n=I),Math.abs(h)+Math.abs(f)<I&&(h=I),l=h*h+f*f,h=h/l,f=-f/l,M=n*h-o*f,m=o*h+n*f,l=r,r=l*M-s*m,s=l*m+s*M,!(Math.abs(M-1)+Math.abs(m)<2*y));b++);return{p:r,q:s}}function ge(t,e){let r=1,s=4*t*t,n=2*e;if(n*=n,r+=(s-1)/(2*n),r+=3*(s-1)*(s-9)/(n*n*8),r+=15*(s-1)*(s-9)*(s-25)/(n*n*n*8*6),!Number.isFinite(r)){let o=t/e,i=u=>o*o-u/(4*e*e),a=i(1),c=i(9);r=1+a/2+3*a*c/8+15*a*c*i(25)/48}return Number.isFinite(Math.PI*e)?Math.sqrt(r*2/(Math.PI*e)):Math.sqrt(r*2/Math.PI)/Math.sqrt(e)}function Ne(t,e){let r=4*t*t,s=4*e,n=s*s,o=0;if(o+=(r-1)/(2*s),s*=n,o+=(r-1)*(r-25)/(6*s),s*=n,o+=(r-1)*(r*r-114*r+1073)/(5*s),s*=n,o+=(r-1)*(5*r*r*r-1535*r*r+54703*r-375733)/(14*s),!Number.isFinite(o)){let i=t/e,a=t*i-1/(4*e),c=i*i/4,u=1/(16*e*e);o=a/2,o+=a*(c-25*u)/6,o+=a*(c*c-114*c*u+1073*u*u)/5,o+=a*(5*c*c*c-1535*c*c*u+54703*c*u*u-375733*u*u*u)/14}return o}function ht(t){return t>=2**52?t%4/2+.25:t/2+.25}var Ie=2**26;function de(t,e,r,s){let n=t*(t/e)/2;if(n>Ie)throw new RangeError(`${r}: x = ${e}, nu = ${s} has a phase correction nu^2 / (2x) of about ${n.toPrecision(3)}, which double precision does not resolve (at most 2^26)`);let o=ge(t,e),i=Ne(t,e),a=Math.cos(e),c=Math.sin(e),u=G(ht(t)),l=N(ht(t)),h=Math.sin(i),f=Math.cos(i),M=(h*(a*u+c*l)+f*(c*u-a*l))*o;return{j:(f*(a*u+c*l)-h*(c*u-a*l))*o,y:M}}var ye=30;function Pe(t,e,r){let s=C(t,e);if(j({lo:-1/0,hi:s.lo,size:s.size})!==-1)return;if(!r)return{j:0,y:{m:NaN,e2:0}};if(!(e<=t-1))return;let n=t*(Math.LN2-Math.log(e)),o=S(t),i=o+n-Math.log(Math.PI)-ye;if(j({lo:i,hi:1/0,size:Math.abs(n)+Math.abs(o)+2})===1)return{j:0,y:{m:-1,e2:1/0}}}var qe=2**25,Jt=2**31,Ot=2**28;function Bt(t,e,r,s,n,o){if(s>qe)throw new RangeError(`${t}: x = ${e}, nu = ${r} needs a continued fraction of about ${Math.round(s)} terms (at most 2^25)`);if(n>o){let i=o===Jt?"2^31":"2^28";throw new RangeError(`${t}: x = ${e}, nu = ${r} needs a recurrence of about ${n} steps (at most ${i})`)}}function Mt(t,e,r,s,n){let o=Math.round(t),i=t-o,a=Number.isFinite(e*Math.PI)?2/(e*Math.PI):2/Math.PI/e;if(t>Y){let g=Pe(t,e,r);if(g!==void 0)return g}if(!r&&(e<5||t>e*e/4))return{j:Dt(t,e),y:{m:NaN,e2:0}};if(e<1&&i!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:Dt(t,e),y:Me(t,e)};if(Math.max(t,1)<e*.011048543456039806){let g=de(t,e,s,n);return{j:g.j,y:{m:g.y,e2:0}}}if(e>8){let g=me(t,e);if(g!==void 0){let $=ht(t)%2,P=Math.sin(e),k=Math.cos(e),J=N($),gt=G($),Nt=P*gt-J*k,It=k*gt+P*J,dt=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:dt*(g.p*It-g.q*Nt),y:{m:dt*(g.p*Nt+g.q*It),e2:0}}}}if(e<=2){Bt(s,e,n,0,o,Ot);let[g,$]=be(i,e),P=At(i,e,o,g,$),{fv:k}=Tt(t,e);return{j:X(a/(P.y*k-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let c=e>=t&&t>2;Bt(s,e,n,e-t,c?0:o,r?Ot:Jt);let{fv:u,sign:l}=Tt(t,e);if(c){let{p:g,q:$}=Xt(t,e),P=t/e-u,k=(g-P)/$;k===0&&(k=t*y/e);let J=l*Math.sqrt(a/($+k*(g-P)));return{j:J,y:{m:k*J,e2:0}}}let h=I,f=u*l*h,M=l*h,m=0;for(let g=o;g>0;g--){let $=2*(i+g)/e;Math.abs(M)>2**900&&(f*=2**-900,M*=2**-900,m+=900);let P=$*M-f;P===0&&(P=f*y/2),f=M,M=P}let b=X(l*h/M,-m),q=f/M,{p:d,q:p}=Xt(i,e),_=i/e-q,R=(d-_)/p;R===0&&(R=i*y/e);let z=Math.sign(M)*Math.sqrt(a/(p+R*(d-_))),Q=z*b,Z=R*z,L=Z*(i/e-d-p/R);if(!r)return{j:Q,y:{m:NaN,e2:0}};let pt=At(i,e,o,Z,L);return{j:Q,y:{m:pt.y,e2:pt.e2}}}function _e(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),s=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:s?N(r)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!s){let o=Mt(r,t,!1,"besselJ",e).j;return e<0&&r%2===1?-o:o}let n=Mt(r,t,!0,"besselJ",e);return G(r)*n.j-X(N(r)*n.y.m,n.y.e2)}function Ee(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),s=e<0;if(t===0){if(!s)return-1/0;let a=G(r);return a===0?0:a>0?-1/0:1/0}if(t===1/0)return 0;let n=Mt(r,t,!0,"besselY",e);if(!s)return X(n.y.m,n.y.e2);let o=G(r),i=N(r);return(i!==0?i*n.j:0)+(o===0?0:X(o*n.y.m,n.y.e2))}function Se(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let r=S(e),s=E(e),n=u=>{if(tt(e,t,u,!0)===-1/0)return[0,-1/0];let h=tt(e,t,u,!1),f=s*h;if(Number.isFinite(s)&&h>Kt&&Number.isFinite(f)&&f>Kt)return[f,Math.log(f)];let M=r+tt(e,t,u,!0);return M<710&&M>-746&&t>0&&(u?t<e:t>e)?Le(t,e,u):[Math.exp(M),M]},[o,i]=n(!0),[a,c]=n(!1);return{lower:o,upper:a,logLower:i,logUpper:c}}var Kt=22250738585072014e-324;function Le(t,e,r){let s=w(yt(A([t,0]),e),[-t,0]);r?s=w(s,A([qt(e,t)/e,0])):s=w(s,A([_t(e,t),0]));let n=s[0]+s[1];return[s[0]>-708?Math.exp(s[0])*(1+s[1]):Math.exp(n),n]}function mt(t){return Number.isNaN(t)||t<0||t>2?NaN:t<2**-1021?-it(Math.log(t)-Math.LN2,{logP:!0})*Math.SQRT1_2:-it(t/2)*Math.SQRT1_2}function we(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,r=Math.abs(t);if(r>=.5)return e*mt(1-r);if(r<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let s=mt(1-r);for(let n=0;n<3;n++){let o=(ot(s)-r)/(1.1283791670955126*Math.exp(-s*s));if(s-=o,Math.abs(o)<=1e-17*s)break}return e*s}function Fe(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let r=e===Math.floor(e);return t===Math.floor(t)&&r&&e>t?0:t===1/0?e===1/0?NaN:e===0?1:1/0:Number.isFinite(e)?r&&e<=1e3?Re(t,e):$e(t,e):De(t,e)}function Re(t,e){let r=[1,0];for(let s=0;s<e;s++){let n=D(t,-s),o=r[0]*n[0];if(!Number.isFinite(o)){let i=Math.sign(o);for(let a=s+1;a<e;a++)t-a<0&&(i=-i);return i*(1/0)}r=Math.abs(r[0])>1e290||Math.abs(n[0])>1e290?[(r[0]+r[1])*(n[0]+n[1]),0]:O(r,n)}return r[0]+r[1]}function $e(t,e){let[r,s]=D(t,-e);if(r+1<=0)return ke(t,r,s);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let n;if(r>=15){if(e*Math.log(r+1)>720)return 1/0;let o=D(t,-r),i=T(O(o,A([t,0])),Pt(r,[t,0]));i=w(i,[x(t)-x(r),0]),n=Math.sqrt(t/r)*Math.exp(i[0])*(1+i[1])}else if(t<30)n=E(t+1)/E(r+1);else{if(S(t+1)-S(r+1)>720)return 1/0;let o=T(bt(t+1),A([E(r+1),0]));n=Math.exp(o[0])*(1+o[1])}return s!==0&&Number.isFinite(n)&&n!==0&&(n*=Math.exp(-s*et(r+1))),n}function ke(t,e,r){let s=w(D(e,1),[r,0]),n=N(s[0])+N(s[0]+.5)*Math.PI*s[1];if(n===0)return 0;let o=Math.sign(n),i=w(T(A([Math.abs(n),0]),je),[-r*et(-e),0]);if(S(t+1)+S(-e)+i[0]>720)return o*(1/0);let a=w(w(bt(t+1),bt(-e)),i);return o*Math.exp(a[0])*(1+a[1])}var Ae=[.9189385332046728,-38782941580672414e-33],je=[1.1447298858494002,10265951162707826e-33];function bt(t){if(t<15)return A([E(t),0]);let e=T(O(D(t,-.5),A([t,0])),[t,0]);return w(w(e,Ae),[x(t),0])}function De(t,e){let r=H(t+1),s=H(t-e+1);return r.sign*s.sign*Math.exp(r.value-s.value)}export{le as besselI,_e as besselJ,ue as besselK,Ee as besselY,zt as beta,Ut as choose,et as digamma,ot as erf,Yt as erfc,mt as erfcinv,we as erfinv,Qt as factorial,E as gamma,Se as gammainc,Ht as lbeta,Vt as lchoose,Zt as lfactorial,S as lgamma,vt as lgamma1p,xt as log1mexp,te as log1pexp,Wt as log1pmx,Fe as perm,Gt as psigamma,Ct as trigamma};
|