@numero-uno-jpn/rstats 0.5.0 → 0.6.1

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.
Files changed (168) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.ja.md +36 -20
  3. package/README.md +34 -18
  4. package/THIRD_PARTY_NOTICES.md +25 -5
  5. package/dist/chunks/chunk-2JCIB5H2.js +2 -0
  6. package/dist/chunks/chunk-7JVSDGQQ.js +2 -0
  7. package/dist/chunks/chunk-7NK4SA6B.js +2 -0
  8. package/dist/chunks/chunk-AJYQNFXK.js +2 -0
  9. package/dist/chunks/chunk-DRNMIEYH.js +2 -0
  10. package/dist/chunks/chunk-NAYDS7CL.js +2 -0
  11. package/dist/chunks/chunk-NOCEAM44.js +2 -0
  12. package/dist/chunks/chunk-QNAIK4PY.js +2 -0
  13. package/dist/chunks/chunk-TPC6MTYC.js +2 -0
  14. package/dist/chunks/chunk-UGUQYWRQ.js +2 -0
  15. package/dist/chunks/chunk-XM2TVD63.js +2 -0
  16. package/dist/chunks/chunk-Y4IZV7XK.js +2 -0
  17. package/dist/chunks/chunk-ZWJ42QN6.js +2 -0
  18. package/dist/descriptive/basic.d.ts +73 -0
  19. package/dist/descriptive/basic.js +256 -0
  20. package/dist/descriptive/cov.d.ts +39 -0
  21. package/dist/descriptive/cov.js +105 -0
  22. package/dist/descriptive/hist.d.ts +64 -0
  23. package/dist/descriptive/hist.js +304 -0
  24. package/dist/descriptive/moments.d.ts +63 -0
  25. package/dist/descriptive/moments.js +158 -0
  26. package/dist/descriptive/quantile.d.ts +50 -0
  27. package/dist/descriptive/quantile.js +131 -0
  28. package/dist/descriptive/rank.d.ts +23 -0
  29. package/dist/descriptive/rank.js +72 -0
  30. package/dist/descriptive/table.d.ts +54 -0
  31. package/dist/descriptive/table.js +160 -0
  32. package/dist/descriptive.js +2 -0
  33. package/dist/distributions/arcsine.d.ts +24 -0
  34. package/dist/distributions/arcsine.js +73 -0
  35. package/dist/distributions/invgamma.d.ts +29 -0
  36. package/dist/distributions/invgamma.js +85 -0
  37. package/dist/distributions/kumaraswamy.d.ts +17 -0
  38. package/dist/distributions/kumaraswamy.js +96 -0
  39. package/dist/distributions/laplace.d.ts +23 -0
  40. package/dist/distributions/laplace.js +69 -0
  41. package/dist/distributions/multinomial.d.ts +24 -0
  42. package/dist/distributions/multinomial.js +70 -0
  43. package/dist/distributions/nbeta.js +28 -10
  44. package/dist/distributions/nchisq.js +20 -3
  45. package/dist/distributions/pareto.d.ts +23 -0
  46. package/dist/distributions/pareto.js +76 -0
  47. package/dist/distributions/summary.d.ts +25 -0
  48. package/dist/distributions/summary.js +289 -0
  49. package/dist/distributions/triangular.d.ts +25 -0
  50. package/dist/distributions/triangular.js +87 -0
  51. package/dist/distributions.js +2 -0
  52. package/dist/entries/descriptive.d.ts +7 -0
  53. package/dist/entries/descriptive.js +8 -0
  54. package/dist/entries/distributions.d.ts +41 -0
  55. package/dist/entries/distributions.js +41 -0
  56. package/dist/entries/linalg.d.ts +11 -0
  57. package/dist/entries/linalg.js +11 -0
  58. package/dist/entries/numerics.d.ts +8 -0
  59. package/dist/entries/numerics.js +6 -0
  60. package/dist/entries/special.d.ts +9 -0
  61. package/dist/entries/special.js +9 -0
  62. package/dist/entries/tests.d.ts +21 -0
  63. package/dist/entries/tests.js +20 -0
  64. package/dist/htest/ansariTest.d.ts +13 -0
  65. package/dist/htest/ansariTest.js +80 -0
  66. package/dist/htest/aov.d.ts +85 -0
  67. package/dist/htest/aov.js +178 -0
  68. package/dist/htest/binomTest.d.ts +36 -0
  69. package/dist/htest/binomTest.js +121 -0
  70. package/dist/htest/cor.d.ts +14 -0
  71. package/dist/htest/cor.js +4 -3
  72. package/dist/htest/core/ansari.d.ts +18 -0
  73. package/dist/htest/core/ansari.js +121 -0
  74. package/dist/htest/core/kolmogorov.d.ts +26 -0
  75. package/dist/htest/core/kolmogorov.js +221 -0
  76. package/dist/htest/core/mantelhaen.d.ts +26 -0
  77. package/dist/htest/core/mantelhaen.js +145 -0
  78. package/dist/htest/core/shapiro.d.ts +24 -0
  79. package/dist/htest/core/shapiro.js +142 -0
  80. package/dist/htest/core/smirnov.d.ts +20 -0
  81. package/dist/htest/core/smirnov.js +75 -0
  82. package/dist/htest/fisherTest.js +134 -120
  83. package/dist/htest/groups.d.ts +20 -0
  84. package/dist/htest/groups.js +62 -0
  85. package/dist/htest/ksTest.d.ts +31 -0
  86. package/dist/htest/ksTest.js +106 -0
  87. package/dist/htest/mantelhaenTest.d.ts +26 -0
  88. package/dist/htest/mantelhaenTest.js +196 -0
  89. package/dist/htest/mcnemarTest.d.ts +26 -0
  90. package/dist/htest/mcnemarTest.js +99 -0
  91. package/dist/htest/onewayTest.d.ts +26 -0
  92. package/dist/htest/onewayTest.js +97 -0
  93. package/dist/htest/pairwise.d.ts +64 -0
  94. package/dist/htest/pairwise.js +152 -0
  95. package/dist/htest/poissonTest.d.ts +35 -0
  96. package/dist/htest/poissonTest.js +170 -0
  97. package/dist/htest/propTest.d.ts +37 -0
  98. package/dist/htest/propTest.js +164 -0
  99. package/dist/htest/rankTests.d.ts +52 -0
  100. package/dist/htest/rankTests.js +234 -0
  101. package/dist/htest/types.d.ts +2 -0
  102. package/dist/htest/types.js +6 -0
  103. package/dist/htest/varTest.d.ts +48 -0
  104. package/dist/htest/varTest.js +118 -0
  105. package/dist/htest/wilcoxTest.js +136 -174
  106. package/dist/index.d.ts +6 -50
  107. package/dist/index.js +8 -50
  108. package/dist/integrate/quadpack.d.ts +29 -0
  109. package/dist/integrate/quadpack.js +525 -0
  110. package/dist/internal/seq.d.ts +5 -0
  111. package/dist/internal/seq.js +14 -0
  112. package/dist/internal/uniroot.js +10 -71
  113. package/dist/linalg/lu.d.ts +45 -0
  114. package/dist/linalg/lu.js +88 -0
  115. package/dist/linalg/ops.d.ts +90 -0
  116. package/dist/linalg/ops.js +320 -0
  117. package/dist/linalg.js +2 -0
  118. package/dist/models/lm.d.ts +98 -0
  119. package/dist/models/lm.js +187 -0
  120. package/dist/numerics/deriv.d.ts +37 -0
  121. package/dist/numerics/deriv.js +150 -0
  122. package/dist/numerics/integrate.d.ts +91 -0
  123. package/dist/numerics/integrate.js +264 -0
  124. package/dist/numerics/interp.d.ts +103 -0
  125. package/dist/numerics/interp.js +581 -0
  126. package/dist/numerics/ode.d.ts +23 -0
  127. package/dist/numerics/ode.js +59 -0
  128. package/dist/numerics.js +2 -0
  129. package/dist/optim/localmin.d.ts +16 -0
  130. package/dist/optim/localmin.js +97 -0
  131. package/dist/random/beta.js +1 -1
  132. package/dist/random/binomial.js +1 -1
  133. package/dist/random/continuous.js +1 -1
  134. package/dist/random/extra.d.ts +33 -0
  135. package/dist/random/extra.js +62 -0
  136. package/dist/random/gamma.js +1 -1
  137. package/dist/random/hyper.js +1 -1
  138. package/dist/random/mt.js +0 -1
  139. package/dist/random/poisson.js +0 -1
  140. package/dist/random/rank.js +1 -1
  141. package/dist/random/rng.js +1 -1
  142. package/dist/random/sample.js +1 -1
  143. package/dist/rstats.js +2 -2
  144. package/dist/special/besselIK.d.ts +38 -0
  145. package/dist/special/besselIK.js +315 -0
  146. package/dist/special/besselJY.d.ts +32 -0
  147. package/dist/special/besselJY.js +508 -0
  148. package/dist/special/besselSeries.d.ts +8 -0
  149. package/dist/special/besselSeries.js +24 -0
  150. package/dist/special/beta.js +22 -5
  151. package/dist/special/choose.d.ts +75 -0
  152. package/dist/special/choose.js +233 -0
  153. package/dist/special/erf.d.ts +28 -2
  154. package/dist/special/erf.js +37 -10
  155. package/dist/special/extra.d.ts +47 -0
  156. package/dist/special/extra.js +220 -0
  157. package/dist/special/igam.d.ts +4 -0
  158. package/dist/special/igam.js +57 -2
  159. package/dist/special/incbet.js +77 -22
  160. package/dist/special/lgammaDiff.d.ts +7 -0
  161. package/dist/special/lgammaDiff.js +16 -3
  162. package/dist/special/psigamma.d.ts +48 -0
  163. package/dist/special/psigamma.js +318 -0
  164. package/dist/special/rCompatible.d.ts +8 -0
  165. package/dist/special/rCompatible.js +1 -0
  166. package/dist/special.js +2 -0
  167. package/dist/tests.js +2 -0
  168. package/package.json +26 -1
@@ -0,0 +1,85 @@
1
+ // Inverse gamma distribution dinvgamma / pinvgamma / qinvgamma, with extraDistr's parameters (alpha shape, beta scale).
2
+ //
3
+ // Written for rStats.js (no ported code). X = 1/Y with Y ~ Gamma(alpha, rate = beta), so with z = beta / x
4
+ // f(x) = f_Gamma(z; alpha, 1) z / x, P[X <= x] = P[Z >= z], q(p) = beta / q_Gamma(1 - p; alpha, 1)
5
+ // which keeps the gamma functions' accuracy in both tails. z is formed in double-double and its low part enters to
6
+ // first order (the density and the tails are steep in z when alpha is large).
7
+ import { vectorize } from "../internal/vectorize.js";
8
+ import { d0, dt0, dt1, quantileBoundaries } from "../internal/dpq.js";
9
+ import { standardizeDD } from "../internal/ddexp.js";
10
+ import { dgamma1, pgamma1, qgamma1 } from "./gamma.js";
11
+ const valid = (alpha, beta) => alpha > 0 && beta > 0 && Number.isFinite(beta);
12
+ // alpha = Inf is taken as the limit (the distribution concentrates at 0), as extraDistr does
13
+ export function dinvgamma1(x, alpha, beta, log) {
14
+ if (Number.isNaN(x) || !valid(alpha, beta))
15
+ return NaN;
16
+ if (x <= 0 || x === Infinity)
17
+ return d0(log);
18
+ if (alpha === Infinity)
19
+ return NaN;
20
+ const [z, zl] = standardizeDD(beta, 0, x);
21
+ if (z === Infinity)
22
+ return d0(log);
23
+ // d/dz log(f_Gamma(z) z) = alpha / z - 1
24
+ const c = Number.isFinite(zl) ? (alpha / z - 1) * zl : 0;
25
+ if (log)
26
+ return dgamma1(z, alpha, 1, true) + Math.log(z) - Math.log(x) + c;
27
+ return ((dgamma1(z, alpha, 1, false) * z) / x) * (1 + c);
28
+ }
29
+ export function pinvgamma1(q, alpha, beta, lowerTail, logP) {
30
+ if (Number.isNaN(q) || !valid(alpha, beta))
31
+ return NaN;
32
+ if (q <= 0)
33
+ return dt0(lowerTail, logP);
34
+ if (q === Infinity || alpha === Infinity)
35
+ return dt1(lowerTail, logP);
36
+ const [z, zl] = standardizeDD(beta, 0, q);
37
+ const v = pgamma1(z, alpha, 1, !lowerTail, logP);
38
+ if (!(zl !== 0 && Number.isFinite(zl) && Number.isFinite(z)))
39
+ return v;
40
+ // P[Z <= z] grows by f(z) zl, P[Z > z] falls by it
41
+ const sign = lowerTail ? -1 : 1;
42
+ if (!logP)
43
+ return v + sign * dgamma1(z, alpha, 1, false) * zl;
44
+ // log P + f(z) zl / P, with f / P from the logs (P may underflow)
45
+ const c = sign * Math.exp(dgamma1(z, alpha, 1, true) - v) * zl;
46
+ return Number.isFinite(c) ? v + c : v;
47
+ }
48
+ export function qinvgamma1(p, alpha, beta, lowerTail, logP) {
49
+ if (Number.isNaN(p) || !valid(alpha, beta))
50
+ return NaN;
51
+ const b = quantileBoundaries(p, 0, Infinity, lowerTail, logP);
52
+ if (b !== undefined)
53
+ return b;
54
+ if (alpha === Infinity)
55
+ return 0;
56
+ return beta / qgamma1(p, alpha, 1, !lowerTail, logP);
57
+ }
58
+ /**
59
+ * Density of the inverse gamma distribution. Equivalent to `extraDistr::dinvgamma(x, alpha, beta = 1, log = FALSE)`:
60
+ * f(x) = beta^alpha x^(-alpha-1) exp(-beta/x) / Gamma(alpha).
61
+ *
62
+ * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
63
+ * @param alpha - Shape parameter.
64
+ * @param options - `beta` (see {@link InvgammaParams}) and `log` (see {@link DensityOptions}).
65
+ */
66
+ export function dinvgamma(x, alpha, options = {}) {
67
+ const { beta = 1, log = false } = options;
68
+ return vectorize(x, (v) => dinvgamma1(v, alpha, beta, log));
69
+ }
70
+ /**
71
+ * Distribution function of the inverse gamma distribution. Equivalent to
72
+ * `extraDistr::pinvgamma(q, alpha, beta = 1, lower.tail = TRUE, log.p = FALSE)`.
73
+ */
74
+ export function pinvgamma(q, alpha, options = {}) {
75
+ const { beta = 1, lowerTail = true, logP = false } = options;
76
+ return vectorize(q, (v) => pinvgamma1(v, alpha, beta, lowerTail, logP));
77
+ }
78
+ /**
79
+ * Quantile function of the inverse gamma distribution. Equivalent to
80
+ * `extraDistr::qinvgamma(p, alpha, beta = 1, lower.tail = TRUE, log.p = FALSE)`.
81
+ */
82
+ export function qinvgamma(p, alpha, options = {}) {
83
+ const { beta = 1, lowerTail = true, logP = false } = options;
84
+ return vectorize(p, (v) => qinvgamma1(v, alpha, beta, lowerTail, logP));
85
+ }
@@ -0,0 +1,17 @@
1
+ import { type Vectorizable, type VectorResult } from "../internal/vectorize.js";
2
+ import { type DensityOptions, type TailOptions } from "../internal/dpq.js";
3
+ export declare function dkumar1(x: number, a: number, b: number, log: boolean): number;
4
+ export declare function pkumar1(q: number, a: number, b: number, lowerTail: boolean, logP: boolean): number;
5
+ export declare function qkumar1(p: number, a: number, b: number, lowerTail: boolean, logP: boolean): number;
6
+ /**
7
+ * Density of the Kumaraswamy distribution. Equivalent to `extraDistr::dkumar(x, a, b, log = FALSE)`.
8
+ *
9
+ * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
10
+ * @param a - First shape parameter.
11
+ * @param b - Second shape parameter.
12
+ */
13
+ export declare function dkumar<T extends Vectorizable>(x: T, a: number, b: number, options?: DensityOptions): VectorResult<T>;
14
+ /** Distribution function of the Kumaraswamy distribution. Equivalent to `extraDistr::pkumar(q, a, b, lower.tail, log.p)`. */
15
+ export declare function pkumar<T extends Vectorizable>(q: T, a: number, b: number, options?: TailOptions): VectorResult<T>;
16
+ /** Quantile function of the Kumaraswamy distribution. Equivalent to `extraDistr::qkumar(p, a, b, lower.tail, log.p)`. */
17
+ export declare function qkumar<T extends Vectorizable>(p: T, a: number, b: number, options?: TailOptions): VectorResult<T>;
@@ -0,0 +1,96 @@
1
+ // Kumaraswamy distribution dkumar / pkumar / qkumar (extraDistr's names).
2
+ //
3
+ // Written for rStats.js (no ported code). On [0, 1] with shapes a, b > 0:
4
+ // f(x) = a b x^(a-1) (1 - x^a)^(b-1), P[X > x] = (1 - x^a)^b, q(p) = (1 - (1 - p)^(1/b))^(1/a)
5
+ // 1 - x^a is formed as -expm1(a log x) when x^a is near 1, and the tails as exp / -expm1 of b log(1 - x^a).
6
+ import { vectorize } from "../internal/vectorize.js";
7
+ import { d0, dt0, dt1, quantileBoundaries } from "../internal/dpq.js";
8
+ import { log1mExp } from "../internal/ddexp.js";
9
+ const valid = (a, b) => a > 0 && b > 0 && Number.isFinite(b);
10
+ // a = Inf is taken as the limit (the distribution concentrates at 1), as extraDistr does
11
+ /** log(1 - x^a) for 0 <= x <= 1 */
12
+ function log1mPow(x, a) {
13
+ const xa = Math.pow(x, a);
14
+ return xa < 0.5 ? Math.log1p(-xa) : Math.log(-Math.expm1(a * Math.log(x)));
15
+ }
16
+ /** (1 - x^a)^e for 0 < x < 1: pow of 1 - x^a with the rounding of the subtraction corrected to first order */
17
+ function powOneMinus(x, a, e) {
18
+ const xa = Math.pow(x, a);
19
+ if (xa >= 0.5)
20
+ return Math.pow(-Math.expm1(a * Math.log(x)), e);
21
+ const hi = 1 - xa;
22
+ const lo = 1 - hi - xa; // exact remainder (Fast2Sum)
23
+ return Math.pow(hi, e) * (1 + (e * lo) / hi);
24
+ }
25
+ /** c log(v), 0 when c is 0 */
26
+ const xlog = (c, v) => (c === 0 ? 0 : c * Math.log(v));
27
+ export function dkumar1(x, a, b, log) {
28
+ if (Number.isNaN(x) || !valid(a, b))
29
+ return NaN;
30
+ if (x < 0 || x > 1)
31
+ return d0(log);
32
+ if (a === Infinity)
33
+ return x === 1 ? Infinity : d0(log);
34
+ const l1 = x === 1 ? -Infinity : log1mPow(x, a);
35
+ const ld = Math.log(a) + Math.log(b) + xlog(a - 1, x) + (b === 1 ? 0 : (b - 1) * l1);
36
+ if (log)
37
+ return ld;
38
+ // the product keeps the relative accuracy that exp(ld) loses for large |ld|; exp(ld) where it under- or overflows
39
+ // x^(a-1) as x^a / x (a - 1 itself may round, which x^(a-1) magnifies by |log x|)
40
+ const xa = Math.pow(x, a);
41
+ const d = a * b * (a === 1 ? 1 : xa > 1e-290 ? xa / x : Math.pow(x, a - 1)) * (b === 1 || x === 0 ? 1 : powOneMinus(x, a, b - 1));
42
+ return d > 2.2250738585072014e-308 && d < Infinity ? d : Math.exp(ld);
43
+ }
44
+ export function pkumar1(q, a, b, lowerTail, logP) {
45
+ if (Number.isNaN(q) || !valid(a, b))
46
+ return NaN;
47
+ if (q <= 0)
48
+ return dt0(lowerTail, logP);
49
+ if (q >= 1)
50
+ return dt1(lowerTail, logP);
51
+ if (a === Infinity)
52
+ return dt0(lowerTail, logP);
53
+ const lu = b * log1mPow(q, a); // log P[X > q]
54
+ if (!lowerTail)
55
+ return logP ? lu : powOneMinus(q, a, b);
56
+ if (!logP)
57
+ return -Math.expm1(lu);
58
+ // for tiny x^a, P[X <= q] = b x^a (1 + O(b x^a)) whose log survives where 1 - exp(lu) underflows
59
+ const xa = Math.pow(q, a);
60
+ if (xa < 1e-20)
61
+ return Math.log(b) + a * Math.log(q) + Math.log1p((-(b - 1) * xa) / 2);
62
+ return lu < -Math.LN2 ? Math.log1p(-powOneMinus(q, a, b)) : log1mExp(lu);
63
+ }
64
+ export function qkumar1(p, a, b, lowerTail, logP) {
65
+ if (Number.isNaN(p) || !valid(a, b))
66
+ return NaN;
67
+ const bd = quantileBoundaries(p, 0, 1, lowerTail, logP);
68
+ if (bd !== undefined)
69
+ return bd;
70
+ if (a === Infinity)
71
+ return 1;
72
+ // log of the upper probability
73
+ const lu = lowerTail ? (logP ? log1mExp(p) : Math.log1p(-p)) : logP ? p : Math.log(p);
74
+ return Math.pow(-Math.expm1(lu / b), 1 / a);
75
+ }
76
+ /**
77
+ * Density of the Kumaraswamy distribution. Equivalent to `extraDistr::dkumar(x, a, b, log = FALSE)`.
78
+ *
79
+ * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
80
+ * @param a - First shape parameter.
81
+ * @param b - Second shape parameter.
82
+ */
83
+ export function dkumar(x, a, b, options = {}) {
84
+ const { log = false } = options;
85
+ return vectorize(x, (v) => dkumar1(v, a, b, log));
86
+ }
87
+ /** Distribution function of the Kumaraswamy distribution. Equivalent to `extraDistr::pkumar(q, a, b, lower.tail, log.p)`. */
88
+ export function pkumar(q, a, b, options = {}) {
89
+ const { lowerTail = true, logP = false } = options;
90
+ return vectorize(q, (v) => pkumar1(v, a, b, lowerTail, logP));
91
+ }
92
+ /** Quantile function of the Kumaraswamy distribution. Equivalent to `extraDistr::qkumar(p, a, b, lower.tail, log.p)`. */
93
+ export function qkumar(p, a, b, options = {}) {
94
+ const { lowerTail = true, logP = false } = options;
95
+ return vectorize(p, (v) => qkumar1(v, a, b, lowerTail, logP));
96
+ }
@@ -0,0 +1,23 @@
1
+ import { type Vectorizable, type VectorResult } from "../internal/vectorize.js";
2
+ import { type DensityOptions, type TailOptions } from "../internal/dpq.js";
3
+ /** Location and scale of the Laplace distribution. */
4
+ export interface LaplaceParams {
5
+ /** Location. Default `0`. */
6
+ mu?: number;
7
+ /** Scale. Default `1`. */
8
+ sigma?: number;
9
+ }
10
+ export declare function dlaplace1(x: number, mu: number, sigma: number, log: boolean): number;
11
+ export declare function plaplace1(q: number, mu: number, sigma: number, lowerTail: boolean, logP: boolean): number;
12
+ export declare function qlaplace1(p: number, mu: number, sigma: number, lowerTail: boolean, logP: boolean): number;
13
+ /**
14
+ * Density of the Laplace distribution. Equivalent to `extraDistr::dlaplace(x, mu = 0, sigma = 1, log = FALSE)`.
15
+ *
16
+ * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
17
+ * @param options - `mu` and `sigma` (see {@link LaplaceParams}) and `log` (see {@link DensityOptions}).
18
+ */
19
+ export declare function dlaplace<T extends Vectorizable>(x: T, options?: LaplaceParams & DensityOptions): VectorResult<T>;
20
+ /** Distribution function of the Laplace distribution. Equivalent to `extraDistr::plaplace(q, mu = 0, sigma = 1, lower.tail, log.p)`. */
21
+ export declare function plaplace<T extends Vectorizable>(q: T, options?: LaplaceParams & TailOptions): VectorResult<T>;
22
+ /** Quantile function of the Laplace distribution. Equivalent to `extraDistr::qlaplace(p, mu = 0, sigma = 1, lower.tail, log.p)`. */
23
+ export declare function qlaplace<T extends Vectorizable>(p: T, options?: LaplaceParams & TailOptions): VectorResult<T>;
@@ -0,0 +1,69 @@
1
+ // Laplace (double exponential) distribution dlaplace / plaplace / qlaplace (extraDistr's names mu, sigma).
2
+ //
3
+ // Written for rStats.js (no ported code). With z = (x - mu) / sigma formed in double-double and a = |z|:
4
+ // f(x) = exp(-a) / (2 sigma), probability of the smaller side exp(-a) / 2, q(p) = mu + sigma log(2p) for p <= 1/2
5
+ // (and the mirror image above 1/2).
6
+ import { vectorize } from "../internal/vectorize.js";
7
+ import { quantileBoundaries, smallerTail } from "../internal/dpq.js";
8
+ import { expNeg, locationScale, standardizeDD } from "../internal/ddexp.js";
9
+ const valid = (mu, sigma) => !Number.isNaN(mu) && sigma > 0 && Number.isFinite(sigma);
10
+ // an infinite mu is taken as the limit (the distribution moves out to that infinity), as extraDistr does
11
+ export function dlaplace1(x, mu, sigma, log) {
12
+ if (Number.isNaN(x) || !valid(mu, sigma))
13
+ return NaN;
14
+ if (!Number.isFinite(mu))
15
+ return log ? -Infinity : 0;
16
+ const z = standardizeDD(x, mu, sigma);
17
+ const a = z[0] < 0 ? [-z[0], -z[1]] : [z[0], z[1]];
18
+ if (log)
19
+ return -a[0] - a[1] - Math.log(2 * sigma);
20
+ return expNeg(a) / (2 * sigma);
21
+ }
22
+ export function plaplace1(q, mu, sigma, lowerTail, logP) {
23
+ if (Number.isNaN(q) || !valid(mu, sigma))
24
+ return NaN;
25
+ if (!Number.isFinite(mu)) {
26
+ const lower = mu === Infinity ? 0 : 1;
27
+ const v = lowerTail ? lower : 1 - lower;
28
+ return logP ? Math.log(v) : v;
29
+ }
30
+ const z = standardizeDD(q, mu, sigma);
31
+ const a = z[0] < 0 ? [-z[0], -z[1]] : [z[0], z[1]];
32
+ const half = expNeg(a) / 2; // probability of the smaller side
33
+ if (lowerTail === z[0] < 0)
34
+ return logP ? -a[0] - a[1] - Math.LN2 : half;
35
+ return logP ? Math.log1p(-half) : 1 - half;
36
+ }
37
+ export function qlaplace1(p, mu, sigma, lowerTail, logP) {
38
+ if (Number.isNaN(p) || !valid(mu, sigma))
39
+ return NaN;
40
+ const bd = quantileBoundaries(p, -Infinity, Infinity, lowerTail, logP);
41
+ if (bd !== undefined)
42
+ return bd;
43
+ if (!Number.isFinite(mu))
44
+ return mu;
45
+ const { lower, logTarget, linearTarget } = smallerTail(p, lowerTail, logP);
46
+ // log(2 t) of the smaller tail t (<= 1/2)
47
+ const l = linearTarget !== undefined ? Math.log(2 * linearTarget) : Math.LN2 + logTarget;
48
+ return locationScale(mu, sigma, lower ? l : -l);
49
+ }
50
+ /**
51
+ * Density of the Laplace distribution. Equivalent to `extraDistr::dlaplace(x, mu = 0, sigma = 1, log = FALSE)`.
52
+ *
53
+ * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
54
+ * @param options - `mu` and `sigma` (see {@link LaplaceParams}) and `log` (see {@link DensityOptions}).
55
+ */
56
+ export function dlaplace(x, options = {}) {
57
+ const { mu = 0, sigma = 1, log = false } = options;
58
+ return vectorize(x, (v) => dlaplace1(v, mu, sigma, log));
59
+ }
60
+ /** Distribution function of the Laplace distribution. Equivalent to `extraDistr::plaplace(q, mu = 0, sigma = 1, lower.tail, log.p)`. */
61
+ export function plaplace(q, options = {}) {
62
+ const { mu = 0, sigma = 1, lowerTail = true, logP = false } = options;
63
+ return vectorize(q, (v) => plaplace1(v, mu, sigma, lowerTail, logP));
64
+ }
65
+ /** Quantile function of the Laplace distribution. Equivalent to `extraDistr::qlaplace(p, mu = 0, sigma = 1, lower.tail, log.p)`. */
66
+ export function qlaplace(p, options = {}) {
67
+ const { mu = 0, sigma = 1, lowerTail = true, logP = false } = options;
68
+ return vectorize(p, (v) => qlaplace1(v, mu, sigma, lowerTail, logP));
69
+ }
@@ -0,0 +1,24 @@
1
+ /** Options for {@link dmultinom}. */
2
+ export interface MultinomialOptions {
3
+ /** Total number of objects; defaults to the sum of `x` (it must equal it, as in R). */
4
+ size?: number;
5
+ /** If `true`, return the log probability. Default `false`. */
6
+ log?: boolean;
7
+ }
8
+ /**
9
+ * Probability function of the multinomial distribution. Equivalent to R's
10
+ * `dmultinom(x, size = NULL, prob, log = FALSE)`.
11
+ *
12
+ * @param x - Counts, a vector of K non-negative integers.
13
+ * @param prob - Category weights, K finite non-negative numbers, not all 0 (divided by their sum).
14
+ * @param options - `size` and `log` (see {@link MultinomialOptions}).
15
+ * @returns The probability `N! / (x_1! ... x_K!) prod p_j^x_j` with `N = sum(x)`, or its log.
16
+ * @throws RangeError if `x` and `prob` differ in length, `x` has a negative or non-integer value, `prob` has a
17
+ * negative or non-finite value or no positive value, or `size` differs from the sum of `x`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * dmultinom([1, 2, 1], [0.2, 0.5, 0.3]); // 0.18000000000000002
22
+ * ```
23
+ */
24
+ export declare function dmultinom(x: readonly number[], prob: readonly number[], options?: MultinomialOptions): number;
@@ -0,0 +1,70 @@
1
+ // Multinomial probability dmultinom.
2
+ //
3
+ // P[X = x] = N! / (x_1! ... x_K!) p_1^x_1 ... p_K^x_K is computed as a product of binomial probabilities,
4
+ // P[X = x] = prod_k b(x_k; n_k, q_k), n_k = x_k + ... + x_K, q_k = p_k / (p_k + ... + p_K),
5
+ // each from Loader's dbinomRawDD with q_k and 1 - q_k = (p_(k+1) + ... + p_K) / (p_k + ... + p_K) formed separately.
6
+ // The sums of the weights are kept in double-double: q_k is raised to the power x_k, so a rounded sum would give an
7
+ // error of x_k ε (1e-9 at x_k = 1e7).
8
+ // Summing lgamma terms instead loses digits to cancellation for large counts.
9
+ import { dbinomRawDD } from "../special/loader.js";
10
+ import { ddAdd, ddDiv } from "../special/dd.js";
11
+ /**
12
+ * Probability function of the multinomial distribution. Equivalent to R's
13
+ * `dmultinom(x, size = NULL, prob, log = FALSE)`.
14
+ *
15
+ * @param x - Counts, a vector of K non-negative integers.
16
+ * @param prob - Category weights, K finite non-negative numbers, not all 0 (divided by their sum).
17
+ * @param options - `size` and `log` (see {@link MultinomialOptions}).
18
+ * @returns The probability `N! / (x_1! ... x_K!) prod p_j^x_j` with `N = sum(x)`, or its log.
19
+ * @throws RangeError if `x` and `prob` differ in length, `x` has a negative or non-integer value, `prob` has a
20
+ * negative or non-finite value or no positive value, or `size` differs from the sum of `x`.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * dmultinom([1, 2, 1], [0.2, 0.5, 0.3]); // 0.18000000000000002
25
+ * ```
26
+ */
27
+ export function dmultinom(x, prob, options = {}) {
28
+ const log = options.log ?? false;
29
+ const K = prob.length;
30
+ if (x.length !== K)
31
+ throw new RangeError("x and prob must have the same length");
32
+ if (prob.some((p) => !Number.isFinite(p) || p < 0))
33
+ throw new RangeError("probabilities must be finite and non-negative");
34
+ if (!prob.some((p) => p > 0))
35
+ throw new RangeError("probabilities must not all be 0");
36
+ if (x.some((v) => !(v >= 0) || !Number.isFinite(v) || v !== Math.round(v)))
37
+ throw new RangeError("x must be non-negative integers");
38
+ const N = x.reduce((a, b) => a + b, 0);
39
+ if (options.size !== undefined && options.size !== N)
40
+ throw new RangeError("size must equal the sum of x");
41
+ // A category with probability 0 and a positive count makes the probability 0
42
+ for (let k = 0; k < K; k++)
43
+ if (prob[k] === 0 && x[k] > 0)
44
+ return log ? -Infinity : 0;
45
+ // Suffix sums of the weights (double-double) and the counts
46
+ const ps = new Array(K + 1).fill([0, 0]);
47
+ const ns = new Array(K + 1).fill(0);
48
+ for (let k = K - 1; k >= 0; k--) {
49
+ ps[k] = ddAdd(ps[k + 1], [prob[k], 0]);
50
+ ns[k] = ns[k + 1] + x[k];
51
+ }
52
+ let logSum = 0;
53
+ let prodLin = 1;
54
+ for (let k = 0; k < K; k++) {
55
+ if (prob[k] === 0)
56
+ continue;
57
+ const rest = ps[k + 1];
58
+ if (rest[0] === 0)
59
+ break; // the remaining counts all fall here: probability 1
60
+ const q = ddDiv([prob[k], 0], ps[k]);
61
+ const qc = ddDiv(rest, ps[k]);
62
+ const xk = x[k];
63
+ const nmx = ns[k + 1];
64
+ if (log)
65
+ logSum += dbinomRawDD(xk, nmx, q, qc, true);
66
+ else
67
+ prodLin *= dbinomRawDD(xk, nmx, q, qc, false);
68
+ }
69
+ return log ? logSum : prodLin;
70
+ }
@@ -17,6 +17,7 @@ import { invertContinuous } from "../internal/invert.js";
17
17
  import { mixtureCdf, mixtureDensity } from "../internal/poissonMixture.js";
18
18
  import { ddAdd, ddDiv, ddLog, ddMul, ddMulNum, ddNeg, twoProd, twoSum } from "../special/dd.js";
19
19
  import { lbeta, lbetaDD } from "../special/beta.js";
20
+ import { digamma } from "../special/psigamma.js";
20
21
  import { betaIncDD } from "../special/incbet.js";
21
22
  import { dbinomExponent, dbinomRawDD } from "../special/loader.js";
22
23
  import { dbeta1, pbeta1, qbeta1 } from "./beta.js";
@@ -31,29 +32,46 @@ function betaKernel(a, b, xd, xcd) {
31
32
  ratioK: tiny ? -1 : 0,
32
33
  cdf: (j, lower, log) => betaIncDD(a + j, b, xd, xcd, lower, log),
33
34
  inc: (j, log) => {
34
- const c = b / (a + b + j);
35
- return log ? dbinomRawDD(a + j, b, xd, xcd, true) + Math.log(c) : dbinomRawDD(a + j, b, xd, xcd, false) * c;
35
+ const [s, corr] = incCorrection(a, b, j, xd);
36
+ const c = b / (s + b);
37
+ return log
38
+ ? dbinomRawDD(s, b, xd, xcd, true) + Math.log(c) + corr
39
+ : dbinomRawDD(s, b, xd, xcd, false) * c * (1 + corr);
36
40
  },
37
41
  // e_j / e_{j-1} = x (a + b + j - 1) / (a + j)
38
42
  ratio: (j) => ddDiv(ddMul(xs, ddAdd(ab, [j - 1, 0])), twoSum(a, j)),
39
43
  incLogDD: (j) => {
40
44
  // log e_j = log dbinom(a + j; a + b + j, x) + log(b / (a + b + j))
41
45
  // Near subnormal x the binomial-probability helpers break down, so build it from the log of the beta function
42
- if (!(xd[0] > 1e-305 && xcd[0] > 1e-305))
43
- return betaKernelIncLog(a, b, xd, xcd, j);
44
- const { e, logDenom } = dbinomExponent(a + j, b, xd, xcd);
45
- return ddAdd([-e[0], -e[1]], [-0.5 * logDenom + Math.log(b / (a + b + j)), 0]);
46
+ const [s, corr] = incCorrection(a, b, j, xd);
47
+ if (!(xd[0] > 1e-305 && xcd[0] > 1e-305)) {
48
+ const l = betaKernelIncLog(s, b, xd, xcd);
49
+ return typeof l === "number" ? l + corr : ddAdd(l, [corr, 0]);
50
+ }
51
+ const { e, logDenom } = dbinomExponent(s, b, xd, xcd);
52
+ return ddAdd([-e[0], -e[1]], [-0.5 * logDenom + Math.log(b / (s + b)) + corr, 0]);
46
53
  },
47
54
  };
48
55
  }
49
56
  /**
50
- * log e_j in double-double when x (or 1 - x) is near subnormal:
51
- * log e_j = -log B(a + j, b) - log(a + j) + (a + j) log x + b log(1 - x)
57
+ * The shape a + j rounded to double, s, and the first-order change in log e_j from s to the exact a + j:
58
+ * δ ∂log e/∂s with δ the rounding and ∂log e_j/∂s = log x + ψ(s + b) - ψ(s + 1) (e_j = x^s (1 - x)^b / (s B(s, b))).
59
+ * Far in a tail this derivative is large, and the recurrences carry e_j to every other term, so the rounding of s
60
+ * would otherwise reach the result in full (as in nchisq.ts)
52
61
  */
53
- function betaKernelIncLog(a, b, xd, xcd, j) {
62
+ function incCorrection(a, b, j, xd) {
63
+ const [s, delta] = twoSum(a, j);
64
+ if (delta === 0)
65
+ return [s, 0];
66
+ return [s, delta * (Math.log(xd[0]) + xd[1] / xd[0] + digamma(s + b) - digamma(s + 1))];
67
+ }
68
+ /**
69
+ * log e_j in double-double when x (or 1 - x) is near subnormal, for the shape s = a + j:
70
+ * log e_j = -log B(s, b) - log(s) + s log x + b log(1 - x)
71
+ */
72
+ function betaKernelIncLog(s, b, xd, xcd) {
54
73
  if (!(xd[0] > 0 && xcd[0] > 0))
55
74
  return -Infinity;
56
- const s = a + j;
57
75
  const l = ddAdd(ddMulNum(ddLog(xd), s), ddMulNum(ddLog(xcd), b));
58
76
  return ddAdd(ddAdd(l, ddNeg(lbetaDD(s, b))), [-Math.log(s), 0]);
59
77
  }
@@ -13,7 +13,8 @@ import { invertContinuous } from "../internal/invert.js";
13
13
  import { dpoisLogDD, mixtureCdf, mixtureCdfBoth, mixtureDensity } from "../internal/poissonMixture.js";
14
14
  import { gammaInc } from "../special/igam.js";
15
15
  import { dpoisRaw } from "../special/loader.js";
16
- import { ddDiv, twoSum } from "../special/dd.js";
16
+ import { ddAdd, ddDiv, twoSum } from "../special/dd.js";
17
+ import { digamma } from "../special/psigamma.js";
17
18
  import { dgamma1, qgamma1 } from "./gamma.js";
18
19
  function gammaKernel(a, y) {
19
20
  // For very small y the ratio y/(a+j) underflows, so keep it scaled by 2^500
@@ -22,12 +23,28 @@ function gammaKernel(a, y) {
22
23
  return {
23
24
  ratioK: tiny ? -1 : 0,
24
25
  cdf: (j, lower, log) => gammaInc(a + j, y, lower, log),
25
- inc: (j, log) => dpoisRaw(a + j, y, log),
26
+ inc: (j, log) => {
27
+ const [s, corr] = incCorrection(a, j, y);
28
+ return log ? dpoisRaw(s, y, true) + corr : dpoisRaw(s, y, false) * (1 + corr);
29
+ },
26
30
  // d_j / d_{j-1} = y / (a + j)
27
31
  ratio: (j) => ddDiv([ys, 0], twoSum(a, j)),
28
- incLogDD: (j) => dpoisLogDD(a + j, y),
32
+ incLogDD: (j) => {
33
+ const [s, corr] = incCorrection(a, j, y);
34
+ return ddAdd(dpoisLogDD(s, y), [corr, 0]);
35
+ },
29
36
  };
30
37
  }
38
+ /**
39
+ * The shape a + j rounded to double, s, and the first-order change in log d_j from s to the exact a + j:
40
+ * δ ∂log d/∂s with δ the rounding and ∂log dpois(s; y)/∂s = log y - ψ(s + 1). Far in a tail |log y - ψ(s + 1)| is
41
+ * large (above 1 at s = 1130, y = 331), and since the recurrences carry d_j to every other term, the rounding of
42
+ * s (1e-13 there) would otherwise reach the result in full
43
+ */
44
+ function incCorrection(a, j, y) {
45
+ const [s, delta] = twoSum(a, j);
46
+ return [s, delta === 0 ? 0 : delta * (Math.log(y) - digamma(s + 1))];
47
+ }
31
48
  /** Whether the parameters are valid for the noncentral χ² (R gives NaN for df = Inf or ncp = Inf) */
32
49
  function validParams(df, ncp) {
33
50
  return df >= 0 && ncp >= 0 && Number.isFinite(df) && Number.isFinite(ncp);
@@ -0,0 +1,23 @@
1
+ import { type Vectorizable, type VectorResult } from "../internal/vectorize.js";
2
+ import { type DensityOptions, type TailOptions } from "../internal/dpq.js";
3
+ /** Shape and scale of the Pareto distribution. */
4
+ export interface ParetoParams {
5
+ /** Shape. Default `1`. */
6
+ a?: number;
7
+ /** Scale (the lower limit of the support). Default `1`. */
8
+ b?: number;
9
+ }
10
+ export declare function dpareto1(x: number, a: number, b: number, log: boolean): number;
11
+ export declare function ppareto1(q: number, a: number, b: number, lowerTail: boolean, logP: boolean): number;
12
+ export declare function qpareto1(p: number, a: number, b: number, lowerTail: boolean, logP: boolean): number;
13
+ /**
14
+ * Density of the Pareto distribution. Equivalent to `extraDistr::dpareto(x, a = 1, b = 1, log = FALSE)`.
15
+ *
16
+ * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
17
+ * @param options - `a` and `b` (see {@link ParetoParams}) and `log` (see {@link DensityOptions}).
18
+ */
19
+ export declare function dpareto<T extends Vectorizable>(x: T, options?: ParetoParams & DensityOptions): VectorResult<T>;
20
+ /** Distribution function of the Pareto distribution. Equivalent to `extraDistr::ppareto(q, a = 1, b = 1, lower.tail, log.p)`. */
21
+ export declare function ppareto<T extends Vectorizable>(q: T, options?: ParetoParams & TailOptions): VectorResult<T>;
22
+ /** Quantile function of the Pareto distribution. Equivalent to `extraDistr::qpareto(p, a = 1, b = 1, lower.tail, log.p)`. */
23
+ export declare function qpareto<T extends Vectorizable>(p: T, options?: ParetoParams & TailOptions): VectorResult<T>;
@@ -0,0 +1,76 @@
1
+ // Pareto distribution dpareto / ppareto / qpareto, with extraDistr's parameters (a shape, b scale).
2
+ //
3
+ // Written for rStats.js (no ported code). For x >= b:
4
+ // f(x) = (a / b) (b / x)^(a+1), P[X > x] = (b / x)^a, q(p) = b (1 - p)^(-1/a)
5
+ // r = x / b is formed in double-double and the powers taken with pow, whose rounding does not grow with a (the low
6
+ // part of r enters to first order).
7
+ import { vectorize } from "../internal/vectorize.js";
8
+ import { d0, dt0, dt1, quantileBoundaries } from "../internal/dpq.js";
9
+ import { log1mExp, standardizeDD } from "../internal/ddexp.js";
10
+ const valid = (a, b) => a > 0 && b > 0 && Number.isFinite(b);
11
+ // a = Inf is taken as the limit (the distribution concentrates at b), as extraDistr does
12
+ export function dpareto1(x, a, b, log) {
13
+ if (Number.isNaN(x) || !valid(a, b))
14
+ return NaN;
15
+ if (x < b || x === Infinity)
16
+ return d0(log);
17
+ if (a === Infinity)
18
+ return x === b ? Infinity : d0(log);
19
+ const [r, rl] = standardizeDD(x, 0, b);
20
+ const e = Number.isFinite(rl) ? rl / r : 0;
21
+ if (log)
22
+ return Math.log(a / b) - (a + 1) * (Math.log(r) + e);
23
+ const d = ((a / b) * Math.pow(r, -a)) / r;
24
+ return d > 0 && d < Infinity ? d * (1 - (a + 1) * e) : Math.exp(Math.log(a / b) - (a + 1) * (Math.log(r) + e));
25
+ }
26
+ export function ppareto1(q, a, b, lowerTail, logP) {
27
+ if (Number.isNaN(q) || !valid(a, b))
28
+ return NaN;
29
+ if (q <= b)
30
+ return dt0(lowerTail, logP);
31
+ if (q === Infinity || a === Infinity)
32
+ return dt1(lowerTail, logP);
33
+ const [r, rl] = standardizeDD(q, 0, b);
34
+ const e = Number.isFinite(rl) ? rl / r : 0;
35
+ const lu = -a * (Math.log(r) + e); // log P[X > q]
36
+ if (!lowerTail) {
37
+ if (logP)
38
+ return lu;
39
+ const u = Math.pow(r, -a);
40
+ return u > 0 ? u * (1 - a * e) : Math.exp(lu);
41
+ }
42
+ if (!logP)
43
+ return -Math.expm1(lu);
44
+ return lu < -Math.LN2 ? Math.log1p(-Math.pow(r, -a) * (1 - a * e)) : log1mExp(lu);
45
+ }
46
+ export function qpareto1(p, a, b, lowerTail, logP) {
47
+ if (Number.isNaN(p) || !valid(a, b))
48
+ return NaN;
49
+ const bd = quantileBoundaries(p, b, Infinity, lowerTail, logP);
50
+ if (bd !== undefined)
51
+ return bd;
52
+ if (a === Infinity)
53
+ return b;
54
+ const lu = lowerTail ? (logP ? log1mExp(p) : Math.log1p(-p)) : logP ? p : Math.log(p);
55
+ return b * Math.exp(-lu / a);
56
+ }
57
+ /**
58
+ * Density of the Pareto distribution. Equivalent to `extraDistr::dpareto(x, a = 1, b = 1, log = FALSE)`.
59
+ *
60
+ * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
61
+ * @param options - `a` and `b` (see {@link ParetoParams}) and `log` (see {@link DensityOptions}).
62
+ */
63
+ export function dpareto(x, options = {}) {
64
+ const { a = 1, b = 1, log = false } = options;
65
+ return vectorize(x, (v) => dpareto1(v, a, b, log));
66
+ }
67
+ /** Distribution function of the Pareto distribution. Equivalent to `extraDistr::ppareto(q, a = 1, b = 1, lower.tail, log.p)`. */
68
+ export function ppareto(q, options = {}) {
69
+ const { a = 1, b = 1, lowerTail = true, logP = false } = options;
70
+ return vectorize(q, (v) => ppareto1(v, a, b, lowerTail, logP));
71
+ }
72
+ /** Quantile function of the Pareto distribution. Equivalent to `extraDistr::qpareto(p, a = 1, b = 1, lower.tail, log.p)`. */
73
+ export function qpareto(p, options = {}) {
74
+ const { a = 1, b = 1, lowerTail = true, logP = false } = options;
75
+ return vectorize(p, (v) => qpareto1(v, a, b, lowerTail, logP));
76
+ }
@@ -0,0 +1,25 @@
1
+ /** Result of {@link distSummary}. */
2
+ export interface DistSummary {
3
+ mean: number;
4
+ variance: number;
5
+ sd: number;
6
+ median: number;
7
+ mode: number;
8
+ skewness: number;
9
+ /** Excess kurtosis (0 for the normal distribution). */
10
+ kurtosis: number;
11
+ }
12
+ /** Distributions known to {@link distSummary} (the names of their d/p/q/r functions). */
13
+ export type DistName = "norm" | "lnorm" | "unif" | "exp" | "gamma" | "chisq" | "beta" | "t" | "f" | "cauchy" | "weibull" | "logis" | "binom" | "pois" | "geom" | "nbinom" | "hyper" | "invgamma" | "kumar" | "pareto" | "triang" | "laplace" | "arcsine";
14
+ /**
15
+ * Mean, variance, standard deviation, median, mode, skewness and excess kurtosis of a distribution, given by the
16
+ * name of its d/p/q/r functions and their parameters (with the same names and defaults; `gamma` takes `rate` or
17
+ * `scale`, `nbinom` takes `prob` or `mu`). Invalid parameters give NaN throughout.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * distSummary("gamma", { shape: 2.5, rate: 2 }); // { mean: 1.25, variance: 0.625, ..., mode: 0.75, kurtosis: 2.4 }
22
+ * distSummary("binom", { size: 9, prob: 0.5 }).mode; // 5 (4 and 5 are equally likely: the larger)
23
+ * ```
24
+ */
25
+ export declare function distSummary(distribution: DistName, params?: Record<string, number | undefined>): DistSummary;