@numero-uno-jpn/rstats 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/README.ja.md +44 -13
- package/README.md +43 -11
- package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-3VMBBQLV.js} +2 -2
- package/dist/chunks/chunk-4OKAZJJG.js +3 -0
- package/dist/chunks/{chunk-EZAFN5CD.js → chunk-6BH65HGN.js} +1 -1
- package/dist/chunks/chunk-ATC4F4BX.js +2 -0
- package/dist/chunks/{chunk-JWBO5WVN.js → chunk-EDH53DXN.js} +2 -2
- package/dist/chunks/{chunk-Y5CNQ266.js → chunk-EZ2KD5NA.js} +2 -2
- package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-GSPOO2G3.js} +2 -2
- package/dist/chunks/{chunk-F5EDJFEO.js → chunk-K7AZ65H7.js} +2 -2
- package/dist/chunks/{chunk-YSWGDOWK.js → chunk-LEIH4U5X.js} +2 -2
- package/dist/chunks/{chunk-EZWBRCJL.js → chunk-OX3SBG5X.js} +1 -1
- package/dist/chunks/chunk-SGZQDJRR.js +2 -0
- package/dist/chunks/{chunk-C5XTWMGB.js → chunk-UH2N3ZQW.js} +1 -1
- package/dist/chunks/chunk-UV2MZYDQ.js +2 -0
- package/dist/chunks/{chunk-TOGXTCZO.js → chunk-VQHEOBTM.js} +2 -2
- package/dist/chunks/chunk-WJQZZYOI.js +2 -0
- package/dist/chunks/chunk-WKEFHOFR.js +2 -0
- package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-WXC25OPJ.js} +2 -2
- package/dist/chunks/{chunk-5WDJPHYY.js → chunk-XJQKSR52.js} +1 -1
- package/dist/data/grouping.d.ts +39 -15
- package/dist/data/grouping.js +21 -22
- package/dist/descriptive/basic.d.ts +130 -17
- package/dist/descriptive/basic.js +115 -14
- package/dist/descriptive/cov.d.ts +22 -12
- package/dist/descriptive/dataFrames.d.ts +39 -11
- package/dist/descriptive/dataFrames.js +14 -6
- package/dist/descriptive/factanal.d.ts +26 -6
- package/dist/descriptive/factanal.js +7 -3
- package/dist/descriptive/hist.d.ts +27 -6
- package/dist/descriptive/hist.js +9 -3
- package/dist/descriptive/missing.d.ts +13 -6
- package/dist/descriptive/missing.js +4 -2
- package/dist/descriptive/moments.d.ts +91 -13
- package/dist/descriptive/moments.js +66 -9
- package/dist/descriptive/omega.d.ts +28 -6
- package/dist/descriptive/omega.js +16 -4
- package/dist/descriptive/pivot.d.ts +22 -6
- package/dist/descriptive/pivot.js +7 -3
- package/dist/descriptive/quantile.d.ts +33 -5
- package/dist/descriptive/quantile.js +20 -2
- package/dist/descriptive/rank.d.ts +12 -2
- package/dist/descriptive/rank.js +2 -0
- package/dist/descriptive/table.d.ts +55 -7
- package/dist/descriptive/table.js +38 -4
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.d.ts +40 -5
- package/dist/distributions/arcsine.js +35 -4
- package/dist/distributions/beta.d.ts +12 -0
- package/dist/distributions/beta.js +12 -0
- package/dist/distributions/binomial.d.ts +18 -0
- package/dist/distributions/binomial.js +18 -0
- package/dist/distributions/bvnorm.d.ts +4 -1
- package/dist/distributions/bvnorm.js +4 -1
- package/dist/distributions/cauchy.d.ts +24 -0
- package/dist/distributions/cauchy.js +24 -0
- package/dist/distributions/chisq.d.ts +18 -0
- package/dist/distributions/chisq.js +18 -0
- package/dist/distributions/exponential.d.ts +29 -1
- package/dist/distributions/exponential.js +24 -0
- package/dist/distributions/f.d.ts +18 -0
- package/dist/distributions/f.js +18 -0
- package/dist/distributions/gamma.d.ts +20 -0
- package/dist/distributions/gamma.js +18 -0
- package/dist/distributions/geometric.d.ts +24 -0
- package/dist/distributions/geometric.js +24 -0
- package/dist/distributions/hypergeometric.d.ts +24 -0
- package/dist/distributions/hypergeometric.js +24 -0
- package/dist/distributions/invgamma.d.ts +32 -4
- package/dist/distributions/invgamma.js +27 -3
- package/dist/distributions/kumaraswamy.d.ts +31 -3
- package/dist/distributions/kumaraswamy.js +31 -3
- package/dist/distributions/laplace.d.ts +36 -4
- package/dist/distributions/laplace.js +31 -3
- package/dist/distributions/logistic.d.ts +29 -1
- package/dist/distributions/logistic.js +24 -0
- package/dist/distributions/lognormal.d.ts +29 -1
- package/dist/distributions/lognormal.js +24 -0
- package/dist/distributions/multinomial.d.ts +7 -1
- package/dist/distributions/multinomial.js +2 -0
- package/dist/distributions/negbinomial.d.ts +29 -1
- package/dist/distributions/negbinomial.js +24 -0
- package/dist/distributions/normal.d.ts +11 -1
- package/dist/distributions/normal.js +6 -0
- package/dist/distributions/pareto.d.ts +36 -4
- package/dist/distributions/pareto.js +31 -3
- package/dist/distributions/poisson.d.ts +18 -0
- package/dist/distributions/poisson.js +18 -0
- package/dist/distributions/signrank.d.ts +24 -0
- package/dist/distributions/signrank.js +24 -0
- package/dist/distributions/summary.d.ts +20 -2
- package/dist/distributions/summary.js +4 -0
- package/dist/distributions/t.d.ts +18 -0
- package/dist/distributions/t.js +18 -0
- package/dist/distributions/triangular.d.ts +36 -4
- package/dist/distributions/triangular.js +31 -3
- package/dist/distributions/tukey.d.ts +15 -1
- package/dist/distributions/tukey.js +10 -0
- package/dist/distributions/uniform.d.ts +29 -1
- package/dist/distributions/uniform.js +24 -0
- package/dist/distributions/weibull.d.ts +29 -1
- package/dist/distributions/weibull.js +24 -0
- package/dist/distributions/wilcox.d.ts +24 -0
- package/dist/distributions/wilcox.js +24 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +1 -1
- package/dist/entries/mixed.d.ts +1 -0
- package/dist/entries/mixed.js +2 -0
- package/dist/entries/numerics.d.ts +1 -1
- package/dist/entries/tests.js +1 -1
- package/dist/htest/agreement.d.ts +61 -23
- package/dist/htest/agreement.js +19 -9
- package/dist/htest/ansariTest.d.ts +8 -2
- package/dist/htest/aov.d.ts +43 -10
- package/dist/htest/aov.js +17 -3
- package/dist/htest/binomTest.d.ts +12 -2
- package/dist/htest/binomTest.js +2 -0
- package/dist/htest/brunnerMunzelTest.d.ts +9 -3
- package/dist/htest/brunnerMunzelTest.js +4 -2
- package/dist/htest/chisqTest.d.ts +19 -3
- package/dist/htest/cor.d.ts +20 -4
- package/dist/htest/effectSize.d.ts +70 -12
- package/dist/htest/effectSize.js +40 -7
- package/dist/htest/fisherTest.d.ts +9 -1
- package/dist/htest/fisherTest.js +2 -0
- package/dist/htest/groups.d.ts +5 -1
- package/dist/htest/ksTest.d.ts +20 -3
- package/dist/htest/leveneTest.d.ts +15 -4
- package/dist/htest/leveneTest.js +5 -2
- package/dist/htest/mantelhaenTest.d.ts +25 -3
- package/dist/htest/mantelhaenTest.js +15 -1
- package/dist/htest/mcnemarTest.d.ts +14 -4
- package/dist/htest/mcnemarTest.js +4 -2
- package/dist/htest/multipleComparisons.d.ts +173 -29
- package/dist/htest/multipleComparisons.js +123 -19
- package/dist/htest/normalityTests.d.ts +56 -9
- package/dist/htest/normalityTests.js +40 -6
- package/dist/htest/onewayTest.d.ts +32 -3
- package/dist/htest/onewayTest.js +10 -0
- package/dist/htest/pAdjust.d.ts +9 -1
- package/dist/htest/pAdjust.js +2 -0
- package/dist/htest/pairwise.d.ts +50 -5
- package/dist/htest/pairwise.js +25 -0
- package/dist/htest/poissonTest.d.ts +12 -2
- package/dist/htest/poissonTest.js +2 -0
- package/dist/htest/polycor.d.ts +29 -10
- package/dist/htest/power.d.ts +60 -6
- package/dist/htest/power.js +6 -0
- package/dist/htest/propTest.d.ts +13 -2
- package/dist/htest/propTest.js +2 -0
- package/dist/htest/pwr.d.ts +286 -36
- package/dist/htest/pwr.js +116 -15
- package/dist/htest/rankTests.d.ts +80 -12
- package/dist/htest/rankTests.js +11 -2
- package/dist/htest/tTest.d.ts +13 -3
- package/dist/htest/testFormula.js +6 -3
- package/dist/htest/trendTests.d.ts +29 -8
- package/dist/htest/trendTests.js +8 -4
- package/dist/htest/types.d.ts +14 -2
- package/dist/htest/varTest.d.ts +25 -8
- package/dist/htest/wilcoxTest.d.ts +10 -2
- package/dist/internal/dpq.d.ts +4 -0
- package/dist/internal/noncentral.d.ts +2 -0
- package/dist/internal/vectorize.d.ts +4 -0
- package/dist/linalg/basic.d.ts +39 -5
- package/dist/linalg/basic.js +15 -0
- package/dist/linalg/chol.d.ts +26 -5
- package/dist/linalg/chol.js +7 -0
- package/dist/linalg/eigen.d.ts +16 -7
- package/dist/linalg/eigen.js +6 -5
- package/dist/linalg/expm.d.ts +15 -5
- package/dist/linalg/expm.js +5 -3
- package/dist/linalg/kappa.d.ts +21 -1
- package/dist/linalg/kappa.js +16 -0
- package/dist/linalg/lu.d.ts +30 -6
- package/dist/linalg/lu.js +15 -3
- package/dist/linalg/matrix.d.ts +4 -0
- package/dist/linalg/norm.d.ts +16 -1
- package/dist/linalg/norm.js +9 -0
- package/dist/linalg/ops.d.ts +156 -35
- package/dist/linalg/ops.js +96 -15
- package/dist/linalg/qr.d.ts +87 -12
- package/dist/linalg/qr.js +31 -0
- package/dist/linalg/schur.d.ts +8 -2
- package/dist/linalg/schur.js +3 -1
- package/dist/linalg/solve.d.ts +42 -6
- package/dist/linalg/solve.js +22 -0
- package/dist/linalg/svd.d.ts +12 -2
- package/dist/linalg/svd.js +2 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +3 -0
- package/dist/models/anovaSequential.d.ts +26 -4
- package/dist/models/anovaSequential.js +3 -1
- package/dist/models/aovEz.d.ts +29 -6
- package/dist/models/aovEz.js +5 -2
- package/dist/models/aovStrata.d.ts +13 -3
- package/dist/models/aovStrata.js +5 -1
- package/dist/models/carAnova.d.ts +9 -3
- package/dist/models/carAnova.js +4 -2
- package/dist/models/coxph.d.ts +33 -7
- package/dist/models/coxph.js +8 -3
- package/dist/models/formula.d.ts +26 -1
- package/dist/models/formula.js +125 -9
- package/dist/models/glm.d.ts +128 -21
- package/dist/models/glm.js +71 -14
- package/dist/models/glmAnova.d.ts +30 -5
- package/dist/models/glmAnova.js +15 -2
- package/dist/models/glmConfint.d.ts +16 -2
- package/dist/models/glmConfint.js +9 -1
- package/dist/models/glmFamily.d.ts +27 -5
- package/dist/models/lm.d.ts +77 -19
- package/dist/models/lm.js +22 -4
- package/dist/models/lmer.d.ts +162 -0
- package/dist/models/lmer.js +457 -0
- package/dist/models/mauchly.d.ts +20 -5
- package/dist/models/mauchly.js +7 -3
- package/dist/models/mixedDeviance.d.ts +44 -0
- package/dist/models/mixedDeviance.js +872 -0
- package/dist/models/mixedStructure.d.ts +82 -0
- package/dist/models/mixedStructure.js +309 -0
- package/dist/models/modelFrame.d.ts +17 -2
- package/dist/models/modelFrame.js +36 -21
- package/dist/models/modelMatrix.d.ts +33 -8
- package/dist/models/modelMatrix.js +21 -5
- package/dist/models/survival.d.ts +41 -9
- package/dist/models/survival.js +10 -4
- package/dist/numerics/deriv.d.ts +21 -6
- package/dist/numerics/deriv.js +16 -5
- package/dist/numerics/integrate.d.ts +37 -7
- package/dist/numerics/integrate.js +8 -2
- package/dist/numerics/interp.d.ts +63 -12
- package/dist/numerics/interp.js +30 -6
- package/dist/numerics/ode.d.ts +15 -5
- package/dist/numerics/ode.js +5 -3
- package/dist/numerics.js +2 -2
- package/dist/optim/optim.d.ts +32 -8
- package/dist/optim/optim.js +8 -4
- package/dist/random/beta.d.ts +8 -0
- package/dist/random/beta.js +8 -0
- package/dist/random/binomial.d.ts +16 -0
- package/dist/random/binomial.js +16 -0
- package/dist/random/continuous.d.ts +51 -0
- package/dist/random/continuous.js +51 -0
- package/dist/random/extra.d.ts +66 -6
- package/dist/random/extra.js +66 -6
- package/dist/random/gamma.d.ts +33 -0
- package/dist/random/gamma.js +33 -0
- package/dist/random/hyper.d.ts +8 -0
- package/dist/random/hyper.js +8 -0
- package/dist/random/poisson.d.ts +25 -0
- package/dist/random/poisson.js +25 -0
- package/dist/random/r2dtable.d.ts +2 -0
- package/dist/random/r2dtable.js +2 -0
- package/dist/random/rank.d.ts +16 -0
- package/dist/random/rank.js +16 -0
- package/dist/random/rng.d.ts +49 -6
- package/dist/random/rng.js +29 -2
- package/dist/random/sample.d.ts +10 -2
- package/dist/random/sample.js +5 -1
- package/dist/random/streams.d.ts +13 -0
- package/dist/random/streams.js +13 -0
- package/dist/rstats.js +14 -14
- package/dist/special/besselIK.d.ts +11 -3
- package/dist/special/besselIK.js +6 -2
- package/dist/special/besselJY.d.ts +6 -2
- package/dist/special/besselJY.js +6 -2
- package/dist/special/beta.d.ts +16 -2
- package/dist/special/beta.js +16 -2
- package/dist/special/choose.d.ts +13 -5
- package/dist/special/choose.js +13 -5
- package/dist/special/erf.d.ts +8 -3
- package/dist/special/erf.js +8 -3
- package/dist/special/extra.d.ts +30 -10
- package/dist/special/extra.js +25 -9
- package/dist/special/gamma.d.ts +18 -2
- package/dist/special/gamma.js +18 -2
- package/dist/special/log1p.d.ts +16 -7
- package/dist/special/log1p.js +16 -7
- package/dist/special/psigamma.d.ts +9 -3
- package/dist/special/psigamma.js +9 -3
- package/dist/special/rCompatible.d.ts +5 -1
- package/dist/special.js +2 -2
- package/dist/tests.js +12 -12
- package/llms.txt +13 -3
- package/package.json +5 -1
- package/dist/chunks/chunk-7GQMKH3Z.js +0 -2
- package/dist/chunks/chunk-AHHS6AC4.js +0 -3
- package/dist/chunks/chunk-ALM3VHFP.js +0 -2
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Options for {@link besselI} and {@link besselK}.
|
|
3
|
+
*
|
|
4
|
+
* @category Special functions
|
|
5
|
+
*/
|
|
2
6
|
export interface BesselOptions {
|
|
3
7
|
/** If `true`, return `exp(-x) I(x, nu)` (for `besselI`) or `exp(x) K(x, nu)` (for `besselK`). Default `false`. */
|
|
4
8
|
exponScaled?: boolean;
|
|
5
9
|
}
|
|
6
10
|
/**
|
|
7
11
|
* Modified Bessel function of the first kind. Equivalent to R's
|
|
8
|
-
* `besselI(x, nu, expon.scaled = FALSE)
|
|
12
|
+
* `besselI(x, nu, expon.scaled = FALSE)`. Takes single numbers.
|
|
9
13
|
*
|
|
10
14
|
* @param x - Argument, `x >= 0` (`NaN` for negative `x`).
|
|
11
15
|
* @param nu - Order, any real number. For `nu < 0`, `I(x, -nu) = I(x, nu) + 2/pi sin(pi nu) K(x, nu)`
|
|
@@ -18,11 +22,13 @@ export interface BesselOptions {
|
|
|
18
22
|
* besselI(1, 0); // 1.2660658777520086
|
|
19
23
|
* besselI(1000, 2, { exponScaled: true }); // 0.012592018595377398
|
|
20
24
|
* ```
|
|
25
|
+
*
|
|
26
|
+
* @category Special functions
|
|
21
27
|
*/
|
|
22
28
|
export declare function besselI(x: number, nu: number, options?: BesselOptions): number;
|
|
23
29
|
/**
|
|
24
30
|
* Modified Bessel function of the second kind. Equivalent to R's
|
|
25
|
-
* `besselK(x, nu, expon.scaled = FALSE)
|
|
31
|
+
* `besselK(x, nu, expon.scaled = FALSE)`. Takes single numbers.
|
|
26
32
|
*
|
|
27
33
|
* @param x - Argument, `x >= 0` (`NaN` for negative `x`).
|
|
28
34
|
* @param nu - Order, any real number (`K(x, -nu) = K(x, nu)`).
|
|
@@ -34,5 +40,7 @@ export declare function besselI(x: number, nu: number, options?: BesselOptions):
|
|
|
34
40
|
* besselK(1, 0); // 0.4210244382407083
|
|
35
41
|
* besselK(1000, 2, { exponScaled: true }); // 0.03970761786238014
|
|
36
42
|
* ```
|
|
43
|
+
*
|
|
44
|
+
* @category Special functions
|
|
37
45
|
*/
|
|
38
46
|
export declare function besselK(x: number, nu: number, options?: BesselOptions): number;
|
package/dist/special/besselIK.js
CHANGED
|
@@ -252,7 +252,7 @@ function kPos(v, x) {
|
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
254
254
|
* Modified Bessel function of the first kind. Equivalent to R's
|
|
255
|
-
* `besselI(x, nu, expon.scaled = FALSE)
|
|
255
|
+
* `besselI(x, nu, expon.scaled = FALSE)`. Takes single numbers.
|
|
256
256
|
*
|
|
257
257
|
* @param x - Argument, `x >= 0` (`NaN` for negative `x`).
|
|
258
258
|
* @param nu - Order, any real number. For `nu < 0`, `I(x, -nu) = I(x, nu) + 2/pi sin(pi nu) K(x, nu)`
|
|
@@ -265,6 +265,8 @@ function kPos(v, x) {
|
|
|
265
265
|
* besselI(1, 0); // 1.2660658777520086
|
|
266
266
|
* besselI(1000, 2, { exponScaled: true }); // 0.012592018595377398
|
|
267
267
|
* ```
|
|
268
|
+
*
|
|
269
|
+
* @category Special functions
|
|
268
270
|
*/
|
|
269
271
|
export function besselI(x, nu, options = {}) {
|
|
270
272
|
const scaled = options.exponScaled ?? false;
|
|
@@ -289,7 +291,7 @@ export function besselI(x, nu, options = {}) {
|
|
|
289
291
|
}
|
|
290
292
|
/**
|
|
291
293
|
* Modified Bessel function of the second kind. Equivalent to R's
|
|
292
|
-
* `besselK(x, nu, expon.scaled = FALSE)
|
|
294
|
+
* `besselK(x, nu, expon.scaled = FALSE)`. Takes single numbers.
|
|
293
295
|
*
|
|
294
296
|
* @param x - Argument, `x >= 0` (`NaN` for negative `x`).
|
|
295
297
|
* @param nu - Order, any real number (`K(x, -nu) = K(x, nu)`).
|
|
@@ -301,6 +303,8 @@ export function besselI(x, nu, options = {}) {
|
|
|
301
303
|
* besselK(1, 0); // 0.4210244382407083
|
|
302
304
|
* besselK(1000, 2, { exponScaled: true }); // 0.03970761786238014
|
|
303
305
|
* ```
|
|
306
|
+
*
|
|
307
|
+
* @category Special functions
|
|
304
308
|
*/
|
|
305
309
|
export function besselK(x, nu, options = {}) {
|
|
306
310
|
const scaled = options.exponScaled ?? false;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Bessel function of the first kind. Equivalent to R's `besselJ(x, nu)
|
|
2
|
+
* Bessel function of the first kind. Equivalent to R's `besselJ(x, nu)`. Takes single numbers.
|
|
3
3
|
*
|
|
4
4
|
* @param x - Argument, `x >= 0` (`NaN` for negative `x`).
|
|
5
5
|
* @param nu - Order, any real number. For `nu < 0`, `J(x, -nu) = cos(pi nu) J(x, nu) - sin(pi nu) Y(x, nu)`
|
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
* besselJ(1, 0); // 0.7651976865579666
|
|
15
15
|
* besselJ(10, 2.5); // 0.1966584835818184
|
|
16
16
|
* ```
|
|
17
|
+
*
|
|
18
|
+
* @category Special functions
|
|
17
19
|
*/
|
|
18
20
|
export declare function besselJ(x: number, nu: number): number;
|
|
19
21
|
/**
|
|
20
|
-
* Bessel function of the second kind. Equivalent to R's `besselY(x, nu)
|
|
22
|
+
* Bessel function of the second kind. Equivalent to R's `besselY(x, nu)`. Takes single numbers.
|
|
21
23
|
*
|
|
22
24
|
* @param x - Argument, `x >= 0` (`NaN` for negative `x`; `-Infinity` at 0).
|
|
23
25
|
* @param nu - Order, any real number. For `nu < 0`, `Y(x, -nu) = sin(pi nu) J(x, nu) + cos(pi nu) Y(x, nu)`
|
|
@@ -28,5 +30,7 @@ export declare function besselJ(x: number, nu: number): number;
|
|
|
28
30
|
* ```ts
|
|
29
31
|
* besselY(1, 0); // 0.08825696421567694
|
|
30
32
|
* ```
|
|
33
|
+
*
|
|
34
|
+
* @category Special functions
|
|
31
35
|
*/
|
|
32
36
|
export declare function besselY(x: number, nu: number): number;
|
package/dist/special/besselJY.js
CHANGED
|
@@ -432,7 +432,7 @@ function besselJYPos(v, x, needY) {
|
|
|
432
432
|
return { j: jv, y: { m: r.y, e2: r.e2 } };
|
|
433
433
|
}
|
|
434
434
|
/**
|
|
435
|
-
* Bessel function of the first kind. Equivalent to R's `besselJ(x, nu)
|
|
435
|
+
* Bessel function of the first kind. Equivalent to R's `besselJ(x, nu)`. Takes single numbers.
|
|
436
436
|
*
|
|
437
437
|
* @param x - Argument, `x >= 0` (`NaN` for negative `x`).
|
|
438
438
|
* @param nu - Order, any real number. For `nu < 0`, `J(x, -nu) = cos(pi nu) J(x, nu) - sin(pi nu) Y(x, nu)`
|
|
@@ -447,6 +447,8 @@ function besselJYPos(v, x, needY) {
|
|
|
447
447
|
* besselJ(1, 0); // 0.7651976865579666
|
|
448
448
|
* besselJ(10, 2.5); // 0.1966584835818184
|
|
449
449
|
* ```
|
|
450
|
+
*
|
|
451
|
+
* @category Special functions
|
|
450
452
|
*/
|
|
451
453
|
export function besselJ(x, nu) {
|
|
452
454
|
if (Number.isNaN(x) || Number.isNaN(nu) || x < 0 || !Number.isFinite(nu))
|
|
@@ -471,7 +473,7 @@ export function besselJ(x, nu) {
|
|
|
471
473
|
return cospi(v) * r.j - ldexp(sinpi(v) * r.y.m, r.y.e2);
|
|
472
474
|
}
|
|
473
475
|
/**
|
|
474
|
-
* Bessel function of the second kind. Equivalent to R's `besselY(x, nu)
|
|
476
|
+
* Bessel function of the second kind. Equivalent to R's `besselY(x, nu)`. Takes single numbers.
|
|
475
477
|
*
|
|
476
478
|
* @param x - Argument, `x >= 0` (`NaN` for negative `x`; `-Infinity` at 0).
|
|
477
479
|
* @param nu - Order, any real number. For `nu < 0`, `Y(x, -nu) = sin(pi nu) J(x, nu) + cos(pi nu) Y(x, nu)`
|
|
@@ -482,6 +484,8 @@ export function besselJ(x, nu) {
|
|
|
482
484
|
* ```ts
|
|
483
485
|
* besselY(1, 0); // 0.08825696421567694
|
|
484
486
|
* ```
|
|
487
|
+
*
|
|
488
|
+
* @category Special functions
|
|
485
489
|
*/
|
|
486
490
|
export function besselY(x, nu) {
|
|
487
491
|
if (Number.isNaN(x) || Number.isNaN(nu) || x < 0 || !Number.isFinite(nu))
|
package/dist/special/beta.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { type DD } from "./dd.js";
|
|
2
2
|
/**
|
|
3
|
-
* Beta function B(a, b). Equivalent to R's `beta(
|
|
3
|
+
* Beta function B(a, b). Equivalent to R's `beta()`. Takes single numbers.
|
|
4
4
|
*
|
|
5
5
|
* @param a - First argument.
|
|
6
6
|
* @param b - Second argument.
|
|
7
7
|
* @returns B(a, b).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* beta(2, 3); // 0.08333333333333333
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @category Special functions
|
|
8
15
|
*/
|
|
9
16
|
export declare function beta(a: number, b: number): number;
|
|
10
17
|
/**
|
|
11
18
|
* Natural logarithm of the absolute value of the beta function, log|B(a, b)|.
|
|
12
|
-
* Equivalent to R's `lbeta(
|
|
19
|
+
* Equivalent to R's `lbeta()`. Takes single numbers.
|
|
13
20
|
*
|
|
14
21
|
* For a, b > 0 with the larger argument above 15, it is computed as
|
|
15
22
|
* lgamma(small) - [lgamma(large + small) - lgamma(large)] with the bracketed difference
|
|
@@ -18,6 +25,13 @@ export declare function beta(a: number, b: number): number;
|
|
|
18
25
|
* @param a - First argument.
|
|
19
26
|
* @param b - Second argument.
|
|
20
27
|
* @returns log|B(a, b)|.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* lbeta(1000, 1000); // -1388.4826016359023
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @category Special functions
|
|
21
35
|
*/
|
|
22
36
|
export declare function lbeta(a: number, b: number): number;
|
|
23
37
|
/**
|
package/dist/special/beta.js
CHANGED
|
@@ -18,11 +18,18 @@ function lbetaAsymp(a, b) {
|
|
|
18
18
|
return { value: r, sign };
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Beta function B(a, b). Equivalent to R's `beta(
|
|
21
|
+
* Beta function B(a, b). Equivalent to R's `beta()`. Takes single numbers.
|
|
22
22
|
*
|
|
23
23
|
* @param a - First argument.
|
|
24
24
|
* @param b - Second argument.
|
|
25
25
|
* @returns B(a, b).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* beta(2, 3); // 0.08333333333333333
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @category Special functions
|
|
26
33
|
*/
|
|
27
34
|
export function beta(a, b) {
|
|
28
35
|
if (Number.isNaN(a) || Number.isNaN(b))
|
|
@@ -83,7 +90,7 @@ function betaNegint(a, b) {
|
|
|
83
90
|
}
|
|
84
91
|
/**
|
|
85
92
|
* Natural logarithm of the absolute value of the beta function, log|B(a, b)|.
|
|
86
|
-
* Equivalent to R's `lbeta(
|
|
93
|
+
* Equivalent to R's `lbeta()`. Takes single numbers.
|
|
87
94
|
*
|
|
88
95
|
* For a, b > 0 with the larger argument above 15, it is computed as
|
|
89
96
|
* lgamma(small) - [lgamma(large + small) - lgamma(large)] with the bracketed difference
|
|
@@ -92,6 +99,13 @@ function betaNegint(a, b) {
|
|
|
92
99
|
* @param a - First argument.
|
|
93
100
|
* @param b - Second argument.
|
|
94
101
|
* @returns log|B(a, b)|.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* lbeta(1000, 1000); // -1388.4826016359023
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @category Special functions
|
|
95
109
|
*/
|
|
96
110
|
export function lbeta(a, b) {
|
|
97
111
|
if (Number.isNaN(a) || Number.isNaN(b))
|
package/dist/special/choose.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RCompatibleOptions } from "./rCompatible.js";
|
|
2
2
|
/**
|
|
3
|
-
* Binomial coefficient. Equivalent to R's `choose(
|
|
3
|
+
* Binomial coefficient. Equivalent to R's `choose()`. Takes single numbers.
|
|
4
4
|
*
|
|
5
5
|
* `n` may be any real number. `k` is rounded to the nearest integer (as R does, which also warns
|
|
6
6
|
* when `k` is not close to an integer); `choose(n, k)` is 0 for `k < 0` and 1 for `k = 0`.
|
|
@@ -24,11 +24,13 @@ import type { RCompatibleOptions } from "./rCompatible.js";
|
|
|
24
24
|
* choose(0.5, 3); // 0.0625
|
|
25
25
|
* choose(-2, 3); // -4
|
|
26
26
|
* ```
|
|
27
|
+
*
|
|
28
|
+
* @category Special functions
|
|
27
29
|
*/
|
|
28
30
|
export declare function choose(n: number, k: number, options?: RCompatibleOptions): number;
|
|
29
31
|
/**
|
|
30
|
-
* Logarithm of the absolute value of the binomial coefficient. Equivalent to R's `lchoose(
|
|
31
|
-
*
|
|
32
|
+
* Logarithm of the absolute value of the binomial coefficient. Equivalent to R's `lchoose()`.
|
|
33
|
+
* Takes single numbers: `log(abs(choose(n, k)))`, computed without overflow.
|
|
32
34
|
*
|
|
33
35
|
* Edge cases where R differs from the mathematical value, followed by default (`rCompatible: false`
|
|
34
36
|
* returns the mathematical value instead): `n` within 1e-9 max(1, |n|) of an integer is treated as that
|
|
@@ -44,10 +46,12 @@ export declare function choose(n: number, k: number, options?: RCompatibleOption
|
|
|
44
46
|
* ```ts
|
|
45
47
|
* lchoose(1000, 500); // 689.4672615678512
|
|
46
48
|
* ```
|
|
49
|
+
*
|
|
50
|
+
* @category Special functions
|
|
47
51
|
*/
|
|
48
52
|
export declare function lchoose(n: number, k: number, options?: RCompatibleOptions): number;
|
|
49
53
|
/**
|
|
50
|
-
* Factorial. Equivalent to R's `factorial(
|
|
54
|
+
* Factorial. Equivalent to R's `factorial()`. Takes a single number: `gamma(x + 1)`, defined for
|
|
51
55
|
* any real `x` that is not a negative integer.
|
|
52
56
|
*
|
|
53
57
|
* @param x - Argument.
|
|
@@ -58,10 +62,12 @@ export declare function lchoose(n: number, k: number, options?: RCompatibleOptio
|
|
|
58
62
|
* factorial(5); // 120
|
|
59
63
|
* factorial(0.5); // 0.8862269254527579
|
|
60
64
|
* ```
|
|
65
|
+
*
|
|
66
|
+
* @category Special functions
|
|
61
67
|
*/
|
|
62
68
|
export declare function factorial(x: number): number;
|
|
63
69
|
/**
|
|
64
|
-
* Logarithm of the factorial. Equivalent to R's `lfactorial(
|
|
70
|
+
* Logarithm of the factorial. Equivalent to R's `lfactorial()`. Takes a single number:
|
|
65
71
|
* `lgamma(x + 1)`, computed without forming `x + 1` near 0 so that small `x` keep their accuracy.
|
|
66
72
|
*
|
|
67
73
|
* @param x - Argument.
|
|
@@ -71,5 +77,7 @@ export declare function factorial(x: number): number;
|
|
|
71
77
|
* ```ts
|
|
72
78
|
* lfactorial(100); // 363.73937555556347
|
|
73
79
|
* ```
|
|
80
|
+
*
|
|
81
|
+
* @category Special functions
|
|
74
82
|
*/
|
|
75
83
|
export declare function lfactorial(x: number): number;
|
package/dist/special/choose.js
CHANGED
|
@@ -73,7 +73,7 @@ function logChooseLarge(n, k) {
|
|
|
73
73
|
return { log: l, sign: (k % 2 === 0 ? -1 : 1) * Math.sign(s) };
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* Binomial coefficient. Equivalent to R's `choose(
|
|
76
|
+
* Binomial coefficient. Equivalent to R's `choose()`. Takes single numbers.
|
|
77
77
|
*
|
|
78
78
|
* `n` may be any real number. `k` is rounded to the nearest integer (as R does, which also warns
|
|
79
79
|
* when `k` is not close to an integer); `choose(n, k)` is 0 for `k < 0` and 1 for `k = 0`.
|
|
@@ -97,6 +97,8 @@ function logChooseLarge(n, k) {
|
|
|
97
97
|
* choose(0.5, 3); // 0.0625
|
|
98
98
|
* choose(-2, 3); // -4
|
|
99
99
|
* ```
|
|
100
|
+
*
|
|
101
|
+
* @category Special functions
|
|
100
102
|
*/
|
|
101
103
|
export function choose(n, k, options) {
|
|
102
104
|
if (Number.isNaN(n) || Number.isNaN(k))
|
|
@@ -140,8 +142,8 @@ export function choose(n, k, options) {
|
|
|
140
142
|
return isInt(n) && Number.isFinite(v) ? Math.round(v) : v;
|
|
141
143
|
}
|
|
142
144
|
/**
|
|
143
|
-
* Logarithm of the absolute value of the binomial coefficient. Equivalent to R's `lchoose(
|
|
144
|
-
*
|
|
145
|
+
* Logarithm of the absolute value of the binomial coefficient. Equivalent to R's `lchoose()`.
|
|
146
|
+
* Takes single numbers: `log(abs(choose(n, k)))`, computed without overflow.
|
|
145
147
|
*
|
|
146
148
|
* Edge cases where R differs from the mathematical value, followed by default (`rCompatible: false`
|
|
147
149
|
* returns the mathematical value instead): `n` within 1e-9 max(1, |n|) of an integer is treated as that
|
|
@@ -157,6 +159,8 @@ export function choose(n, k, options) {
|
|
|
157
159
|
* ```ts
|
|
158
160
|
* lchoose(1000, 500); // 689.4672615678512
|
|
159
161
|
* ```
|
|
162
|
+
*
|
|
163
|
+
* @category Special functions
|
|
160
164
|
*/
|
|
161
165
|
export function lchoose(n, k, options) {
|
|
162
166
|
if (Number.isNaN(n) || Number.isNaN(k))
|
|
@@ -199,7 +203,7 @@ export function lchoose(n, k, options) {
|
|
|
199
203
|
return r.log[0] + r.log[1];
|
|
200
204
|
}
|
|
201
205
|
/**
|
|
202
|
-
* Factorial. Equivalent to R's `factorial(
|
|
206
|
+
* Factorial. Equivalent to R's `factorial()`. Takes a single number: `gamma(x + 1)`, defined for
|
|
203
207
|
* any real `x` that is not a negative integer.
|
|
204
208
|
*
|
|
205
209
|
* @param x - Argument.
|
|
@@ -210,12 +214,14 @@ export function lchoose(n, k, options) {
|
|
|
210
214
|
* factorial(5); // 120
|
|
211
215
|
* factorial(0.5); // 0.8862269254527579
|
|
212
216
|
* ```
|
|
217
|
+
*
|
|
218
|
+
* @category Special functions
|
|
213
219
|
*/
|
|
214
220
|
export function factorial(x) {
|
|
215
221
|
return gamma(x + 1);
|
|
216
222
|
}
|
|
217
223
|
/**
|
|
218
|
-
* Logarithm of the factorial. Equivalent to R's `lfactorial(
|
|
224
|
+
* Logarithm of the factorial. Equivalent to R's `lfactorial()`. Takes a single number:
|
|
219
225
|
* `lgamma(x + 1)`, computed without forming `x + 1` near 0 so that small `x` keep their accuracy.
|
|
220
226
|
*
|
|
221
227
|
* @param x - Argument.
|
|
@@ -225,6 +231,8 @@ export function factorial(x) {
|
|
|
225
231
|
* ```ts
|
|
226
232
|
* lfactorial(100); // 363.73937555556347
|
|
227
233
|
* ```
|
|
234
|
+
*
|
|
235
|
+
* @category Special functions
|
|
228
236
|
*/
|
|
229
237
|
export function lfactorial(x) {
|
|
230
238
|
if (Math.abs(x) <= 0.2)
|
package/dist/special/erf.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Error function, erf(x) = 2 / sqrt(pi) * integral from 0 to x of exp(-t^2) dt.
|
|
3
|
-
* `2 * pnorm(x * sqrt(2)) - 1`, which loses the relative accuracy of small x
|
|
2
|
+
* Error function, erf(x) = 2 / sqrt(pi) * integral from 0 to x of exp(-t^2) dt.
|
|
3
|
+
* Not an R function. R writes it as `2 * pnorm(x * sqrt(2)) - 1`, which loses the relative accuracy of small x.
|
|
4
4
|
*
|
|
5
5
|
* @param x - Argument.
|
|
6
6
|
* @returns erf(x).
|
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
* erf(0.5); // 0.5204998778130465
|
|
11
11
|
* erf(1e-10); // 1.1283791670955126e-10
|
|
12
12
|
* ```
|
|
13
|
+
*
|
|
14
|
+
* @category Special functions
|
|
13
15
|
*/
|
|
14
16
|
export declare function erf(x: number): number;
|
|
15
17
|
/**
|
|
16
18
|
* Complementary error function, erfc(x) = 1 - erf(x), accurate in the upper tail (down to the subnormal range near
|
|
17
|
-
* x = 27).
|
|
19
|
+
* x = 27).
|
|
20
|
+
* Not an R function. R writes it as `2 * pnorm(x * sqrt(2), lower.tail = FALSE)`.
|
|
18
21
|
*
|
|
19
22
|
* @param a - Argument.
|
|
20
23
|
* @returns erfc(a).
|
|
@@ -26,6 +29,8 @@ export declare function erf(x: number): number;
|
|
|
26
29
|
*
|
|
27
30
|
* Changes from xsf: exp(-x^2) is formed from x^2 = hi + lo exact (the rounding of x^2 is 33 ε relative at x = 5.7),
|
|
28
31
|
* and below the normal range exp(-700) is applied last so that subnormal results (x up to 27.2) are not flushed to 0.
|
|
32
|
+
*
|
|
33
|
+
* @category Special functions
|
|
29
34
|
*/
|
|
30
35
|
export declare function erfc(a: number): number;
|
|
31
36
|
/**
|
package/dist/special/erf.js
CHANGED
|
@@ -39,8 +39,8 @@ const MAXLOG = 7.097827128933839730962063185871e2;
|
|
|
39
39
|
/** 1/sqrt(pi) */
|
|
40
40
|
const INV_SQRT_PI = 0.5641895835477562869;
|
|
41
41
|
/**
|
|
42
|
-
* Error function, erf(x) = 2 / sqrt(pi) * integral from 0 to x of exp(-t^2) dt.
|
|
43
|
-
* `2 * pnorm(x * sqrt(2)) - 1`, which loses the relative accuracy of small x
|
|
42
|
+
* Error function, erf(x) = 2 / sqrt(pi) * integral from 0 to x of exp(-t^2) dt.
|
|
43
|
+
* Not an R function. R writes it as `2 * pnorm(x * sqrt(2)) - 1`, which loses the relative accuracy of small x.
|
|
44
44
|
*
|
|
45
45
|
* @param x - Argument.
|
|
46
46
|
* @returns erf(x).
|
|
@@ -50,6 +50,8 @@ const INV_SQRT_PI = 0.5641895835477562869;
|
|
|
50
50
|
* erf(0.5); // 0.5204998778130465
|
|
51
51
|
* erf(1e-10); // 1.1283791670955126e-10
|
|
52
52
|
* ```
|
|
53
|
+
*
|
|
54
|
+
* @category Special functions
|
|
53
55
|
*/
|
|
54
56
|
export function erf(x) {
|
|
55
57
|
if (Number.isNaN(x))
|
|
@@ -63,7 +65,8 @@ export function erf(x) {
|
|
|
63
65
|
}
|
|
64
66
|
/**
|
|
65
67
|
* Complementary error function, erfc(x) = 1 - erf(x), accurate in the upper tail (down to the subnormal range near
|
|
66
|
-
* x = 27).
|
|
68
|
+
* x = 27).
|
|
69
|
+
* Not an R function. R writes it as `2 * pnorm(x * sqrt(2), lower.tail = FALSE)`.
|
|
67
70
|
*
|
|
68
71
|
* @param a - Argument.
|
|
69
72
|
* @returns erfc(a).
|
|
@@ -75,6 +78,8 @@ export function erf(x) {
|
|
|
75
78
|
*
|
|
76
79
|
* Changes from xsf: exp(-x^2) is formed from x^2 = hi + lo exact (the rounding of x^2 is 33 ε relative at x = 5.7),
|
|
77
80
|
* and below the normal range exp(-700) is applied last so that subnormal results (x up to 27.2) are not flushed to 0.
|
|
81
|
+
*
|
|
82
|
+
* @category Special functions
|
|
78
83
|
*/
|
|
79
84
|
export function erfc(a) {
|
|
80
85
|
if (Number.isNaN(a))
|
package/dist/special/extra.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Result of {@link gammainc}.
|
|
3
|
+
*
|
|
4
|
+
* @category Special functions
|
|
5
|
+
*/
|
|
2
6
|
export interface GammaincResult {
|
|
3
7
|
/** Lower incomplete gamma function gamma(a, x) = integral from 0 to x of t^(a-1) e^-t dt. */
|
|
4
8
|
lower: number;
|
|
@@ -10,38 +14,54 @@ export interface GammaincResult {
|
|
|
10
14
|
logUpper: number;
|
|
11
15
|
}
|
|
12
16
|
/**
|
|
13
|
-
* The non-regularized incomplete gamma functions gamma(a, x) and Gamma(a, x) and their logs.
|
|
14
|
-
* `pracma::gammainc(
|
|
15
|
-
* `pgamma(x, a, lower.tail = FALSE) * gamma(a)`.
|
|
17
|
+
* The non-regularized incomplete gamma functions gamma(a, x) and Gamma(a, x) and their logs.
|
|
18
|
+
* Equivalent to `pracma::gammainc()` in R. `pracma::gammainc(x, a)` returns them as `lowinc` and `uppinc`;
|
|
19
|
+
* in base R they are `pgamma(x, a) * gamma(a)` and `pgamma(x, a, lower.tail = FALSE) * gamma(a)`.
|
|
16
20
|
*
|
|
17
21
|
* @example
|
|
18
22
|
* ```ts
|
|
19
|
-
* gammainc(2, 3).lower; // 0.6466471676338731
|
|
23
|
+
* gammainc(2, 3).lower; // 0.6466471676338731 (2 - 10 e^-2)
|
|
20
24
|
* ```
|
|
25
|
+
*
|
|
26
|
+
* @category Special functions
|
|
21
27
|
*/
|
|
22
28
|
export declare function gammainc(x: number, a: number): GammaincResult;
|
|
23
29
|
/**
|
|
24
|
-
* Inverse of the complementary error function: the x with erfc(x) = z, for 0 <= z <= 2 (NaN outside).
|
|
25
|
-
* `pracma::erfcinv
|
|
30
|
+
* Inverse of the complementary error function: the x with erfc(x) = z, for 0 <= z <= 2 (NaN outside).
|
|
31
|
+
* Equivalent to `pracma::erfcinv()` in R.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* erfcinv(0.5); // 0.4769362762044699
|
|
36
|
+
* erfcinv(1e-20); // 6.601580622355143
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @category Special functions
|
|
26
40
|
*/
|
|
27
41
|
export declare function erfcinv(z: number): number;
|
|
28
42
|
/**
|
|
29
|
-
* Inverse of the error function: the x with erf(x) = y, for -1 <= y <= 1 (NaN outside).
|
|
30
|
-
* accurate for small |y| (pracma's
|
|
43
|
+
* Inverse of the error function: the x with erf(x) = y, for -1 <= y <= 1 (NaN outside).
|
|
44
|
+
* Equivalent to `pracma::erfinv()` in R. Unlike pracma, it is accurate for small |y| (pracma's
|
|
45
|
+
* `qnorm((1 + y) / 2)` loses it: `erfinv(1e-300)` is -0 there).
|
|
31
46
|
*
|
|
32
47
|
* @example
|
|
33
48
|
* ```ts
|
|
34
49
|
* erfinv(0.5); // 0.4769362762044699
|
|
35
50
|
* ```
|
|
51
|
+
*
|
|
52
|
+
* @category Special functions
|
|
36
53
|
*/
|
|
37
54
|
export declare function erfinv(y: number): number;
|
|
38
55
|
/**
|
|
39
56
|
* Number of ordered selections of k items from n: n! / (n - k)!, defined for real n >= 0 as
|
|
40
|
-
* Gamma(n + 1) / Gamma(n - k + 1) (0 for an integer n < k).
|
|
57
|
+
* Gamma(n + 1) / Gamma(n - k + 1) (0 for an integer n < k). Negative arguments give NaN.
|
|
58
|
+
* Not an R function. It is jStat's `permutation`; R has only `choose()` (unordered selections).
|
|
41
59
|
*
|
|
42
60
|
* @example
|
|
43
61
|
* ```ts
|
|
44
62
|
* perm(5, 2); // 20
|
|
45
63
|
* ```
|
|
64
|
+
*
|
|
65
|
+
* @category Special functions
|
|
46
66
|
*/
|
|
47
67
|
export declare function perm(n: number, k: number): number;
|
package/dist/special/extra.js
CHANGED
|
@@ -21,14 +21,16 @@ import { gammaInc, igamcContinuedFractionValue, igamSeriesSum } from "./igam.js"
|
|
|
21
21
|
import { bd0dd, stirlerr } from "./loader.js";
|
|
22
22
|
import { digamma } from "./psigamma.js";
|
|
23
23
|
/**
|
|
24
|
-
* The non-regularized incomplete gamma functions gamma(a, x) and Gamma(a, x) and their logs.
|
|
25
|
-
* `pracma::gammainc(
|
|
26
|
-
* `pgamma(x, a, lower.tail = FALSE) * gamma(a)`.
|
|
24
|
+
* The non-regularized incomplete gamma functions gamma(a, x) and Gamma(a, x) and their logs.
|
|
25
|
+
* Equivalent to `pracma::gammainc()` in R. `pracma::gammainc(x, a)` returns them as `lowinc` and `uppinc`;
|
|
26
|
+
* in base R they are `pgamma(x, a) * gamma(a)` and `pgamma(x, a, lower.tail = FALSE) * gamma(a)`.
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* ```ts
|
|
30
|
-
* gammainc(2, 3).lower; // 0.6466471676338731
|
|
30
|
+
* gammainc(2, 3).lower; // 0.6466471676338731 (2 - 10 e^-2)
|
|
31
31
|
* ```
|
|
32
|
+
*
|
|
33
|
+
* @category Special functions
|
|
32
34
|
*/
|
|
33
35
|
export function gammainc(x, a) {
|
|
34
36
|
if (Number.isNaN(x) || Number.isNaN(a) || x < 0 || !(a > 0))
|
|
@@ -70,8 +72,16 @@ function smallTail(x, a, lower) {
|
|
|
70
72
|
return [v, log];
|
|
71
73
|
}
|
|
72
74
|
/**
|
|
73
|
-
* Inverse of the complementary error function: the x with erfc(x) = z, for 0 <= z <= 2 (NaN outside).
|
|
74
|
-
* `pracma::erfcinv
|
|
75
|
+
* Inverse of the complementary error function: the x with erfc(x) = z, for 0 <= z <= 2 (NaN outside).
|
|
76
|
+
* Equivalent to `pracma::erfcinv()` in R.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* erfcinv(0.5); // 0.4769362762044699
|
|
81
|
+
* erfcinv(1e-20); // 6.601580622355143
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @category Special functions
|
|
75
85
|
*/
|
|
76
86
|
export function erfcinv(z) {
|
|
77
87
|
if (Number.isNaN(z) || z < 0 || z > 2)
|
|
@@ -79,13 +89,16 @@ export function erfcinv(z) {
|
|
|
79
89
|
return -qnorm(z / 2) * Math.SQRT1_2;
|
|
80
90
|
}
|
|
81
91
|
/**
|
|
82
|
-
* Inverse of the error function: the x with erf(x) = y, for -1 <= y <= 1 (NaN outside).
|
|
83
|
-
* accurate for small |y| (pracma's
|
|
92
|
+
* Inverse of the error function: the x with erf(x) = y, for -1 <= y <= 1 (NaN outside).
|
|
93
|
+
* Equivalent to `pracma::erfinv()` in R. Unlike pracma, it is accurate for small |y| (pracma's
|
|
94
|
+
* `qnorm((1 + y) / 2)` loses it: `erfinv(1e-300)` is -0 there).
|
|
84
95
|
*
|
|
85
96
|
* @example
|
|
86
97
|
* ```ts
|
|
87
98
|
* erfinv(0.5); // 0.4769362762044699
|
|
88
99
|
* ```
|
|
100
|
+
*
|
|
101
|
+
* @category Special functions
|
|
89
102
|
*/
|
|
90
103
|
export function erfinv(y) {
|
|
91
104
|
if (Number.isNaN(y) || y < -1 || y > 1)
|
|
@@ -107,12 +120,15 @@ export function erfinv(y) {
|
|
|
107
120
|
}
|
|
108
121
|
/**
|
|
109
122
|
* Number of ordered selections of k items from n: n! / (n - k)!, defined for real n >= 0 as
|
|
110
|
-
* Gamma(n + 1) / Gamma(n - k + 1) (0 for an integer n < k).
|
|
123
|
+
* Gamma(n + 1) / Gamma(n - k + 1) (0 for an integer n < k). Negative arguments give NaN.
|
|
124
|
+
* Not an R function. It is jStat's `permutation`; R has only `choose()` (unordered selections).
|
|
111
125
|
*
|
|
112
126
|
* @example
|
|
113
127
|
* ```ts
|
|
114
128
|
* perm(5, 2); // 20
|
|
115
129
|
* ```
|
|
130
|
+
*
|
|
131
|
+
* @category Special functions
|
|
116
132
|
*/
|
|
117
133
|
export function perm(n, k) {
|
|
118
134
|
if (Number.isNaN(n) || Number.isNaN(k) || n < 0 || k < 0)
|
package/dist/special/gamma.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
/** sin(pi x). Does not lose accuracy to the rounding of pi x even for large x */
|
|
2
2
|
export declare function sinpi(x: number): number;
|
|
3
3
|
/**
|
|
4
|
-
* Gamma function. Equivalent to R's `gamma(
|
|
4
|
+
* Gamma function. Equivalent to R's `gamma()`. Takes a single number.
|
|
5
5
|
*
|
|
6
6
|
* @param x - Argument.
|
|
7
7
|
* @returns Gamma(x). `NaN` at zero and negative integers; `Infinity` on overflow.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* gamma(5); // 24
|
|
12
|
+
* gamma(0.5); // 1.7724538509055159 (sqrt(pi))
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @category Special functions
|
|
8
16
|
*/
|
|
9
17
|
export declare function gamma(x: number): number;
|
|
10
18
|
/** log|Gamma(x)| and the sign of the gamma function. */
|
|
@@ -14,13 +22,21 @@ export declare function lgammaSign(x: number): {
|
|
|
14
22
|
};
|
|
15
23
|
/**
|
|
16
24
|
* Natural logarithm of the absolute value of the gamma function, log|Gamma(x)|.
|
|
17
|
-
* Equivalent to R's `lgamma(
|
|
25
|
+
* Equivalent to R's `lgamma()`. Takes a single number.
|
|
18
26
|
*
|
|
19
27
|
* Near the zeros x = 1 and x = 2 the result keeps full relative accuracy
|
|
20
28
|
* (computed as lgamma(1 + e) = lgamma1p(e) and lgamma(2 + e) = lgamma1p(e) + log1p(e)).
|
|
21
29
|
*
|
|
22
30
|
* @param x - Argument.
|
|
23
31
|
* @returns log|Gamma(x)|.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* lgamma(100); // 359.1342053695754
|
|
36
|
+
* lgamma(-0.5); // 1.2655121234846454
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @category Special functions
|
|
24
40
|
*/
|
|
25
41
|
export declare function lgamma(x: number): number;
|
|
26
42
|
/**
|
package/dist/special/gamma.js
CHANGED
|
@@ -64,10 +64,18 @@ function stirfXsf(x) {
|
|
|
64
64
|
return SQRT2PI * y * w;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
* Gamma function. Equivalent to R's `gamma(
|
|
67
|
+
* Gamma function. Equivalent to R's `gamma()`. Takes a single number.
|
|
68
68
|
*
|
|
69
69
|
* @param x - Argument.
|
|
70
70
|
* @returns Gamma(x). `NaN` at zero and negative integers; `Infinity` on overflow.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* gamma(5); // 24
|
|
75
|
+
* gamma(0.5); // 1.7724538509055159 (sqrt(pi))
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @category Special functions
|
|
71
79
|
*/
|
|
72
80
|
export function gamma(x) {
|
|
73
81
|
if (!Number.isFinite(x))
|
|
@@ -199,13 +207,21 @@ export function lgammaSign(x) {
|
|
|
199
207
|
}
|
|
200
208
|
/**
|
|
201
209
|
* Natural logarithm of the absolute value of the gamma function, log|Gamma(x)|.
|
|
202
|
-
* Equivalent to R's `lgamma(
|
|
210
|
+
* Equivalent to R's `lgamma()`. Takes a single number.
|
|
203
211
|
*
|
|
204
212
|
* Near the zeros x = 1 and x = 2 the result keeps full relative accuracy
|
|
205
213
|
* (computed as lgamma(1 + e) = lgamma1p(e) and lgamma(2 + e) = lgamma1p(e) + log1p(e)).
|
|
206
214
|
*
|
|
207
215
|
* @param x - Argument.
|
|
208
216
|
* @returns log|Gamma(x)|.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* lgamma(100); // 359.1342053695754
|
|
221
|
+
* lgamma(-0.5); // 1.2655121234846454
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* @category Special functions
|
|
209
225
|
*/
|
|
210
226
|
export function lgamma(x) {
|
|
211
227
|
if (Math.abs(x - 1) <= 0.2)
|