@numero-uno-jpn/rstats 0.11.0 → 0.11.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 (269) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.ja.md +5 -4
  3. package/README.md +6 -4
  4. package/dist/chunks/{chunk-YSWGDOWK.js → chunk-2X7JYQBI.js} +2 -2
  5. package/dist/chunks/{chunk-F5EDJFEO.js → chunk-36GVER3O.js} +2 -2
  6. package/dist/chunks/{chunk-7GQMKH3Z.js → chunk-3WUXRSM6.js} +1 -1
  7. package/dist/chunks/{chunk-JWBO5WVN.js → chunk-6I6QKTFK.js} +2 -2
  8. package/dist/chunks/{chunk-EZWBRCJL.js → chunk-ETOEZTGL.js} +1 -1
  9. package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-FVPDVRJQ.js} +2 -2
  10. package/dist/chunks/{chunk-EZAFN5CD.js → chunk-GG4BJMJW.js} +1 -1
  11. package/dist/chunks/{chunk-5WDJPHYY.js → chunk-HITD7CX6.js} +1 -1
  12. package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-KK4GE65D.js} +2 -2
  13. package/dist/chunks/{chunk-AHHS6AC4.js → chunk-LAUYSGV4.js} +2 -2
  14. package/dist/chunks/{chunk-ALM3VHFP.js → chunk-M6GDXKKS.js} +1 -1
  15. package/dist/chunks/{chunk-C5XTWMGB.js → chunk-PHHUHR7T.js} +1 -1
  16. package/dist/chunks/{chunk-TOGXTCZO.js → chunk-WQPFDDIY.js} +2 -2
  17. package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-X2AWQSVS.js} +2 -2
  18. package/dist/chunks/{chunk-Y5CNQ266.js → chunk-ZRJQD7VS.js} +2 -2
  19. package/dist/data/grouping.d.ts +33 -12
  20. package/dist/data/grouping.js +2 -0
  21. package/dist/descriptive/basic.d.ts +130 -17
  22. package/dist/descriptive/basic.js +115 -14
  23. package/dist/descriptive/cov.d.ts +22 -12
  24. package/dist/descriptive/dataFrames.d.ts +39 -11
  25. package/dist/descriptive/dataFrames.js +14 -6
  26. package/dist/descriptive/factanal.d.ts +26 -6
  27. package/dist/descriptive/factanal.js +7 -3
  28. package/dist/descriptive/hist.d.ts +27 -6
  29. package/dist/descriptive/hist.js +9 -3
  30. package/dist/descriptive/missing.d.ts +13 -6
  31. package/dist/descriptive/missing.js +4 -2
  32. package/dist/descriptive/moments.d.ts +91 -13
  33. package/dist/descriptive/moments.js +66 -9
  34. package/dist/descriptive/omega.d.ts +28 -6
  35. package/dist/descriptive/omega.js +16 -4
  36. package/dist/descriptive/pivot.d.ts +22 -6
  37. package/dist/descriptive/pivot.js +7 -3
  38. package/dist/descriptive/quantile.d.ts +33 -5
  39. package/dist/descriptive/quantile.js +20 -2
  40. package/dist/descriptive/rank.d.ts +12 -2
  41. package/dist/descriptive/rank.js +2 -0
  42. package/dist/descriptive/table.d.ts +55 -7
  43. package/dist/descriptive/table.js +38 -4
  44. package/dist/descriptive.js +2 -2
  45. package/dist/distributions/arcsine.d.ts +40 -5
  46. package/dist/distributions/arcsine.js +35 -4
  47. package/dist/distributions/beta.d.ts +12 -0
  48. package/dist/distributions/beta.js +12 -0
  49. package/dist/distributions/binomial.d.ts +18 -0
  50. package/dist/distributions/binomial.js +18 -0
  51. package/dist/distributions/bvnorm.d.ts +4 -1
  52. package/dist/distributions/bvnorm.js +4 -1
  53. package/dist/distributions/cauchy.d.ts +24 -0
  54. package/dist/distributions/cauchy.js +24 -0
  55. package/dist/distributions/chisq.d.ts +18 -0
  56. package/dist/distributions/chisq.js +18 -0
  57. package/dist/distributions/exponential.d.ts +29 -1
  58. package/dist/distributions/exponential.js +24 -0
  59. package/dist/distributions/f.d.ts +18 -0
  60. package/dist/distributions/f.js +18 -0
  61. package/dist/distributions/gamma.d.ts +20 -0
  62. package/dist/distributions/gamma.js +18 -0
  63. package/dist/distributions/geometric.d.ts +24 -0
  64. package/dist/distributions/geometric.js +24 -0
  65. package/dist/distributions/hypergeometric.d.ts +24 -0
  66. package/dist/distributions/hypergeometric.js +24 -0
  67. package/dist/distributions/invgamma.d.ts +32 -4
  68. package/dist/distributions/invgamma.js +27 -3
  69. package/dist/distributions/kumaraswamy.d.ts +31 -3
  70. package/dist/distributions/kumaraswamy.js +31 -3
  71. package/dist/distributions/laplace.d.ts +36 -4
  72. package/dist/distributions/laplace.js +31 -3
  73. package/dist/distributions/logistic.d.ts +29 -1
  74. package/dist/distributions/logistic.js +24 -0
  75. package/dist/distributions/lognormal.d.ts +29 -1
  76. package/dist/distributions/lognormal.js +24 -0
  77. package/dist/distributions/multinomial.d.ts +7 -1
  78. package/dist/distributions/multinomial.js +2 -0
  79. package/dist/distributions/negbinomial.d.ts +29 -1
  80. package/dist/distributions/negbinomial.js +24 -0
  81. package/dist/distributions/normal.d.ts +11 -1
  82. package/dist/distributions/normal.js +6 -0
  83. package/dist/distributions/pareto.d.ts +36 -4
  84. package/dist/distributions/pareto.js +31 -3
  85. package/dist/distributions/poisson.d.ts +18 -0
  86. package/dist/distributions/poisson.js +18 -0
  87. package/dist/distributions/signrank.d.ts +24 -0
  88. package/dist/distributions/signrank.js +24 -0
  89. package/dist/distributions/summary.d.ts +20 -2
  90. package/dist/distributions/summary.js +4 -0
  91. package/dist/distributions/t.d.ts +18 -0
  92. package/dist/distributions/t.js +18 -0
  93. package/dist/distributions/triangular.d.ts +36 -4
  94. package/dist/distributions/triangular.js +31 -3
  95. package/dist/distributions/tukey.d.ts +15 -1
  96. package/dist/distributions/tukey.js +10 -0
  97. package/dist/distributions/uniform.d.ts +29 -1
  98. package/dist/distributions/uniform.js +24 -0
  99. package/dist/distributions/weibull.d.ts +29 -1
  100. package/dist/distributions/weibull.js +24 -0
  101. package/dist/distributions/wilcox.d.ts +24 -0
  102. package/dist/distributions/wilcox.js +24 -0
  103. package/dist/distributions.js +2 -2
  104. package/dist/entries/descriptive.d.ts +1 -1
  105. package/dist/entries/numerics.d.ts +1 -1
  106. package/dist/entries/tests.js +1 -1
  107. package/dist/htest/agreement.d.ts +61 -23
  108. package/dist/htest/agreement.js +19 -9
  109. package/dist/htest/ansariTest.d.ts +8 -2
  110. package/dist/htest/aov.d.ts +43 -10
  111. package/dist/htest/aov.js +17 -3
  112. package/dist/htest/binomTest.d.ts +12 -2
  113. package/dist/htest/binomTest.js +2 -0
  114. package/dist/htest/brunnerMunzelTest.d.ts +9 -3
  115. package/dist/htest/brunnerMunzelTest.js +4 -2
  116. package/dist/htest/chisqTest.d.ts +19 -3
  117. package/dist/htest/cor.d.ts +20 -4
  118. package/dist/htest/effectSize.d.ts +70 -12
  119. package/dist/htest/effectSize.js +40 -7
  120. package/dist/htest/fisherTest.d.ts +9 -1
  121. package/dist/htest/fisherTest.js +2 -0
  122. package/dist/htest/groups.d.ts +5 -1
  123. package/dist/htest/ksTest.d.ts +20 -3
  124. package/dist/htest/leveneTest.d.ts +15 -4
  125. package/dist/htest/leveneTest.js +5 -2
  126. package/dist/htest/mantelhaenTest.d.ts +25 -3
  127. package/dist/htest/mantelhaenTest.js +15 -1
  128. package/dist/htest/mcnemarTest.d.ts +14 -4
  129. package/dist/htest/mcnemarTest.js +4 -2
  130. package/dist/htest/multipleComparisons.d.ts +173 -29
  131. package/dist/htest/multipleComparisons.js +123 -19
  132. package/dist/htest/normalityTests.d.ts +56 -9
  133. package/dist/htest/normalityTests.js +40 -6
  134. package/dist/htest/onewayTest.d.ts +32 -3
  135. package/dist/htest/onewayTest.js +10 -0
  136. package/dist/htest/pAdjust.d.ts +9 -1
  137. package/dist/htest/pAdjust.js +2 -0
  138. package/dist/htest/pairwise.d.ts +50 -5
  139. package/dist/htest/pairwise.js +25 -0
  140. package/dist/htest/poissonTest.d.ts +12 -2
  141. package/dist/htest/poissonTest.js +2 -0
  142. package/dist/htest/polycor.d.ts +29 -10
  143. package/dist/htest/power.d.ts +60 -6
  144. package/dist/htest/power.js +6 -0
  145. package/dist/htest/propTest.d.ts +13 -2
  146. package/dist/htest/propTest.js +2 -0
  147. package/dist/htest/pwr.d.ts +286 -36
  148. package/dist/htest/pwr.js +116 -15
  149. package/dist/htest/rankTests.d.ts +80 -12
  150. package/dist/htest/rankTests.js +11 -2
  151. package/dist/htest/tTest.d.ts +13 -3
  152. package/dist/htest/trendTests.d.ts +29 -8
  153. package/dist/htest/trendTests.js +8 -4
  154. package/dist/htest/types.d.ts +14 -2
  155. package/dist/htest/varTest.d.ts +25 -8
  156. package/dist/htest/wilcoxTest.d.ts +10 -2
  157. package/dist/internal/dpq.d.ts +4 -0
  158. package/dist/internal/noncentral.d.ts +2 -0
  159. package/dist/internal/vectorize.d.ts +4 -0
  160. package/dist/linalg/basic.d.ts +39 -5
  161. package/dist/linalg/basic.js +15 -0
  162. package/dist/linalg/chol.d.ts +26 -5
  163. package/dist/linalg/chol.js +7 -0
  164. package/dist/linalg/eigen.d.ts +16 -7
  165. package/dist/linalg/eigen.js +6 -5
  166. package/dist/linalg/expm.d.ts +15 -5
  167. package/dist/linalg/expm.js +5 -3
  168. package/dist/linalg/kappa.d.ts +21 -1
  169. package/dist/linalg/kappa.js +16 -0
  170. package/dist/linalg/lu.d.ts +30 -6
  171. package/dist/linalg/lu.js +15 -3
  172. package/dist/linalg/matrix.d.ts +4 -0
  173. package/dist/linalg/norm.d.ts +16 -1
  174. package/dist/linalg/norm.js +9 -0
  175. package/dist/linalg/ops.d.ts +156 -35
  176. package/dist/linalg/ops.js +96 -15
  177. package/dist/linalg/qr.d.ts +87 -12
  178. package/dist/linalg/qr.js +31 -0
  179. package/dist/linalg/schur.d.ts +8 -2
  180. package/dist/linalg/schur.js +3 -1
  181. package/dist/linalg/solve.d.ts +42 -6
  182. package/dist/linalg/solve.js +22 -0
  183. package/dist/linalg/svd.d.ts +12 -2
  184. package/dist/linalg/svd.js +2 -0
  185. package/dist/linalg.js +2 -2
  186. package/dist/models/anovaSequential.d.ts +26 -4
  187. package/dist/models/anovaSequential.js +3 -1
  188. package/dist/models/aovEz.d.ts +29 -6
  189. package/dist/models/aovEz.js +5 -2
  190. package/dist/models/aovStrata.d.ts +12 -2
  191. package/dist/models/carAnova.d.ts +9 -3
  192. package/dist/models/carAnova.js +4 -2
  193. package/dist/models/coxph.d.ts +33 -7
  194. package/dist/models/coxph.js +8 -3
  195. package/dist/models/glm.d.ts +128 -21
  196. package/dist/models/glm.js +71 -14
  197. package/dist/models/glmAnova.d.ts +30 -5
  198. package/dist/models/glmAnova.js +15 -2
  199. package/dist/models/glmConfint.d.ts +16 -2
  200. package/dist/models/glmConfint.js +9 -1
  201. package/dist/models/glmFamily.d.ts +27 -5
  202. package/dist/models/lm.d.ts +75 -17
  203. package/dist/models/lm.js +22 -4
  204. package/dist/models/mauchly.d.ts +20 -5
  205. package/dist/models/mauchly.js +7 -3
  206. package/dist/models/modelFrame.d.ts +5 -1
  207. package/dist/models/modelMatrix.d.ts +18 -4
  208. package/dist/models/modelMatrix.js +3 -1
  209. package/dist/models/survival.d.ts +41 -9
  210. package/dist/models/survival.js +10 -4
  211. package/dist/numerics/deriv.d.ts +21 -6
  212. package/dist/numerics/deriv.js +16 -5
  213. package/dist/numerics/integrate.d.ts +37 -7
  214. package/dist/numerics/integrate.js +8 -2
  215. package/dist/numerics/interp.d.ts +63 -12
  216. package/dist/numerics/interp.js +30 -6
  217. package/dist/numerics/ode.d.ts +15 -5
  218. package/dist/numerics/ode.js +5 -3
  219. package/dist/numerics.js +2 -2
  220. package/dist/optim/optim.d.ts +32 -8
  221. package/dist/optim/optim.js +8 -4
  222. package/dist/random/beta.d.ts +8 -0
  223. package/dist/random/beta.js +8 -0
  224. package/dist/random/binomial.d.ts +16 -0
  225. package/dist/random/binomial.js +16 -0
  226. package/dist/random/continuous.d.ts +51 -0
  227. package/dist/random/continuous.js +51 -0
  228. package/dist/random/extra.d.ts +66 -6
  229. package/dist/random/extra.js +66 -6
  230. package/dist/random/gamma.d.ts +33 -0
  231. package/dist/random/gamma.js +33 -0
  232. package/dist/random/hyper.d.ts +8 -0
  233. package/dist/random/hyper.js +8 -0
  234. package/dist/random/poisson.d.ts +25 -0
  235. package/dist/random/poisson.js +25 -0
  236. package/dist/random/r2dtable.d.ts +2 -0
  237. package/dist/random/r2dtable.js +2 -0
  238. package/dist/random/rank.d.ts +16 -0
  239. package/dist/random/rank.js +16 -0
  240. package/dist/random/rng.d.ts +49 -6
  241. package/dist/random/rng.js +29 -2
  242. package/dist/random/sample.d.ts +10 -2
  243. package/dist/random/sample.js +5 -1
  244. package/dist/random/streams.d.ts +13 -0
  245. package/dist/random/streams.js +13 -0
  246. package/dist/rstats.js +1 -1
  247. package/dist/special/besselIK.d.ts +11 -3
  248. package/dist/special/besselIK.js +6 -2
  249. package/dist/special/besselJY.d.ts +6 -2
  250. package/dist/special/besselJY.js +6 -2
  251. package/dist/special/beta.d.ts +16 -2
  252. package/dist/special/beta.js +16 -2
  253. package/dist/special/choose.d.ts +13 -5
  254. package/dist/special/choose.js +13 -5
  255. package/dist/special/erf.d.ts +8 -3
  256. package/dist/special/erf.js +8 -3
  257. package/dist/special/extra.d.ts +30 -10
  258. package/dist/special/extra.js +25 -9
  259. package/dist/special/gamma.d.ts +18 -2
  260. package/dist/special/gamma.js +18 -2
  261. package/dist/special/log1p.d.ts +16 -7
  262. package/dist/special/log1p.js +16 -7
  263. package/dist/special/psigamma.d.ts +9 -3
  264. package/dist/special/psigamma.js +9 -3
  265. package/dist/special/rCompatible.d.ts +5 -1
  266. package/dist/special.js +2 -2
  267. package/dist/tests.js +2 -2
  268. package/llms.txt +2 -0
  269. package/package.json +1 -1
@@ -1,30 +1,59 @@
1
1
  import type { Sample } from "../htest/types.js";
2
2
  /**
3
3
  * Counts of the integers 1..nbins in `bin` (values truncated towards 0; others and NaN are not counted).
4
- * Equivalent to R's `tabulate()`; `nbins` defaults to max(1, bin).
4
+ * Equivalent to R's `tabulate()`. `nbins` defaults to max(1, bin).
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * tabulate([1, 2, 2, 5]); // [1, 2, 0, 0, 1]
9
+ * tabulate([1, 2, 2, 5], 3); // [1, 2, 0]
10
+ * ```
11
+ *
12
+ * @category Descriptive statistics
5
13
  */
6
14
  export declare function tabulate(bin: Sample, nbins?: number): number[];
7
- /** Options for {@link table}. */
15
+ /**
16
+ * Options for {@link table}.
17
+ *
18
+ * @category Descriptive statistics
19
+ */
8
20
  export interface TableOptions {
9
21
  /** Count missing values: `"no"` (default), `"ifany"` (when there are some) or `"always"`. */
10
22
  useNA?: "no" | "ifany" | "always";
11
23
  }
12
24
  /**
13
- * Frequency table of the distinct values. Equivalent to R's `table()` for one numeric vector: `values` in increasing
25
+ * Frequency table of the distinct values. Equivalent to R's `table()`. For one numeric vector: `values` in increasing
14
26
  * order (NaN last when counted) with their `counts`.
15
27
  *
16
28
  * @example
17
29
  * ```ts
18
30
  * table([3, 1, 3, 2, 3]); // { values: [1, 2, 3], counts: [1, 1, 3] }
19
31
  * ```
32
+ *
33
+ * @category Descriptive statistics
20
34
  */
21
35
  export declare function table(x: Sample, options?: TableOptions): {
36
+ /** The distinct values, in increasing order (NaN last when missing values are counted); R's names. */
22
37
  values: number[];
38
+ /** How often each value occurs. */
23
39
  counts: number[];
24
40
  };
25
- /** Distinct values in order of first appearance (one NaN at most). Equivalent to R's `unique()`. */
41
+ /**
42
+ * Distinct values in order of first appearance (one NaN at most). Equivalent to R's `unique()`.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * unique([3, 1, 3, 2, 1]); // [3, 1, 2]
47
+ * ```
48
+ *
49
+ * @category Descriptive statistics
50
+ */
26
51
  export declare function unique(x: Sample): number[];
27
- /** Options for {@link cut}. */
52
+ /**
53
+ * Options for {@link cut}.
54
+ *
55
+ * @category Descriptive statistics
56
+ */
28
57
  export interface CutOptions {
29
58
  /** Intervals closed on the right, (a, b] (default `true`); otherwise [a, b). */
30
59
  right?: boolean;
@@ -36,9 +65,21 @@ export interface CutOptions {
36
65
  *
37
66
  * @param breaks The break points, or a number of intervals (at least 2): then equal intervals over the range of `x`,
38
67
  * widened by 1/1000 of the range at each end, as R does.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * cut([1, 2.5, 4, 6], [0, 2, 4, 6]); // [1, 2, 2, 3]
72
+ * cut([1, 2.5, 4, 6], [0, 2, 4, 6], { right: false }); // [1, 2, 3, NaN]
73
+ * ```
74
+ *
75
+ * @category Descriptive statistics
39
76
  */
40
77
  export declare function cut(x: Sample, breaks: number | readonly number[], options?: CutOptions): number[];
41
- /** Options for {@link findInterval}. */
78
+ /**
79
+ * Options for {@link findInterval}.
80
+ *
81
+ * @category Descriptive statistics
82
+ */
42
83
  export interface FindIntervalOptions {
43
84
  /** Treat the last interval as closed on the right (with `leftOpen`, the first as closed on the left). */
44
85
  rightmostClosed?: boolean;
@@ -49,6 +90,13 @@ export interface FindIntervalOptions {
49
90
  }
50
91
  /**
51
92
  * For each value, the number of break points at or below it (the interval index). Equivalent to R's
52
- * `findInterval()`; `vec` must be non-decreasing.
93
+ * `findInterval()`. `vec` must be non-decreasing.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * findInterval([0, 1.5, 3, 5], [1, 2, 3]); // [0, 1, 3, 3]
98
+ * ```
99
+ *
100
+ * @category Descriptive statistics
53
101
  */
54
102
  export declare function findInterval(x: Sample, vec: readonly number[], options?: FindIntervalOptions): number[];
@@ -6,7 +6,15 @@
6
6
  import { seqLength } from "../internal/seq.js";
7
7
  /**
8
8
  * Counts of the integers 1..nbins in `bin` (values truncated towards 0; others and NaN are not counted).
9
- * Equivalent to R's `tabulate()`; `nbins` defaults to max(1, bin).
9
+ * Equivalent to R's `tabulate()`. `nbins` defaults to max(1, bin).
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * tabulate([1, 2, 2, 5]); // [1, 2, 0, 0, 1]
14
+ * tabulate([1, 2, 2, 5], 3); // [1, 2, 0]
15
+ * ```
16
+ *
17
+ * @category Descriptive statistics
10
18
  */
11
19
  export function tabulate(bin, nbins) {
12
20
  const b = Array.from(bin).map((v) => Math.trunc(v));
@@ -18,13 +26,15 @@ export function tabulate(bin, nbins) {
18
26
  return out;
19
27
  }
20
28
  /**
21
- * Frequency table of the distinct values. Equivalent to R's `table()` for one numeric vector: `values` in increasing
29
+ * Frequency table of the distinct values. Equivalent to R's `table()`. For one numeric vector: `values` in increasing
22
30
  * order (NaN last when counted) with their `counts`.
23
31
  *
24
32
  * @example
25
33
  * ```ts
26
34
  * table([3, 1, 3, 2, 3]); // { values: [1, 2, 3], counts: [1, 1, 3] }
27
35
  * ```
36
+ *
37
+ * @category Descriptive statistics
28
38
  */
29
39
  export function table(x, options = {}) {
30
40
  const useNA = options.useNA ?? "no";
@@ -45,7 +55,16 @@ export function table(x, options = {}) {
45
55
  }
46
56
  return { values, counts };
47
57
  }
48
- /** Distinct values in order of first appearance (one NaN at most). Equivalent to R's `unique()`. */
58
+ /**
59
+ * Distinct values in order of first appearance (one NaN at most). Equivalent to R's `unique()`.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * unique([3, 1, 3, 2, 1]); // [3, 1, 2]
64
+ * ```
65
+ *
66
+ * @category Descriptive statistics
67
+ */
49
68
  export function unique(x) {
50
69
  const seen = new Set();
51
70
  const out = [];
@@ -63,6 +82,14 @@ export function unique(x) {
63
82
  *
64
83
  * @param breaks The break points, or a number of intervals (at least 2): then equal intervals over the range of `x`,
65
84
  * widened by 1/1000 of the range at each end, as R does.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * cut([1, 2.5, 4, 6], [0, 2, 4, 6]); // [1, 2, 2, 3]
89
+ * cut([1, 2.5, 4, 6], [0, 2, 4, 6], { right: false }); // [1, 2, 3, NaN]
90
+ * ```
91
+ *
92
+ * @category Descriptive statistics
66
93
  */
67
94
  export function cut(x, breaks, options = {}) {
68
95
  const right = options.right ?? true;
@@ -122,7 +149,14 @@ function binCode(xs, br, right, includeLowest) {
122
149
  }
123
150
  /**
124
151
  * For each value, the number of break points at or below it (the interval index). Equivalent to R's
125
- * `findInterval()`; `vec` must be non-decreasing.
152
+ * `findInterval()`. `vec` must be non-decreasing.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * findInterval([0, 1.5, 3, 5], [1, 2, 3]); // [0, 1, 3, 3]
157
+ * ```
158
+ *
159
+ * @category Descriptive statistics
126
160
  */
127
161
  export function findInterval(x, vec, options = {}) {
128
162
  const n = vec.length;
@@ -1,2 +1,2 @@
1
- /*! rStats.js 0.11.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 J,e as S,q as fe,r as ue,s as me}from"./chunks/chunk-AHHS6AC4.js";import"./chunks/chunk-Y5CNQ266.js";import{A as ke,B as Re,C as Fe,D as je,E as Se,F as Te,a as q,b as T,c as z,d as k,e as G,f as he,g as pe,j as ge,k as ye,l as V,m as de,n as we,o as be,p as Ne,q as Ee,r as _,s as R,t as j,u as Ae,v as xe,w as Me,x as $e,y as ve,z as Oe}from"./chunks/chunk-CGBNKHNZ.js";import{a as X}from"./chunks/chunk-ALM3VHFP.js";import{a as H,b as _e,c as Ce,d as Ie,e as Le,f as Pe}from"./chunks/chunk-C5XTWMGB.js";import"./chunks/chunk-5WDJPHYY.js";import"./chunks/chunk-Y5PYRAYP.js";import"./chunks/chunk-JWBO5WVN.js";import"./chunks/chunk-EZWBRCJL.js";var B=4*Number.EPSILON,Ue={4:[0,1],5:[.5,.5],6:[0,0],8:[1/3,1/3],9:[3/8,3/8]};function qe(e,n,t){let r=e.length,o=a=>e[Math.min(Math.max(a,1),r)-1];if(t===7){let a=1+(r-1)*n,g=Math.floor(a),m=o(g),y=o(Math.ceil(a));if(a>g&&y!==m){let b=a-g;return(1-b)*m+b*y}return m}let i,l;if(t<=3){let a=t===3?r*n-.5:r*n;i=Math.floor(a*(1+B)),t===1?l=a>i?1:0:t===2?l=a>i?1:.5:l=a!==i||Math.abs(i%2)===1?1:0}else{let[a,g]=Ue[t],m=a+n*(r+1-a-g);i=Math.floor(m*(1+B)),l=m-i,Math.abs(l)<B&&(l=0)}let s=o(i),u=o(i+1);return l===1?u:l>0&&l<1&&s!==u?(1-l)*s+l*u:s}function C(e,n=[0,.25,.5,.75,1],t={}){let r=t.type??7;if(!(Number.isInteger(r)&&r>=1&&r<=9))throw new RangeError("'type' must be an integer in 1..9");let o=V(e,t.naRm);if(o===void 0)throw new RangeError("missing values and NaN's not allowed if 'na.rm' is FALSE");let i=o.sort((a,g)=>a-g),l=typeof n=="number"?[n]:Array.from(n),s=100*Number.EPSILON;if(l.some(a=>a<-s||a>1+s))throw new RangeError("'probs' outside [0,1]");let u=l.map(a=>Number.isNaN(a)||i.length===0?NaN:qe(i,Math.min(Math.max(a,0),1),r));return typeof n=="number"?u[0]:u}function W(e,n={}){let[t,r]=C(e,[.25,.75],n);return r-t}function ze(e){let n=Array.from(e).filter(i=>!Number.isNaN(i)).sort((i,l)=>i-l),t=n.length;if(t===0)return[NaN,NaN,NaN,NaN,NaN];let r=Math.floor((t+3)/2)/2;return[1,r,(t+1)/2,t+1-r,t].map(i=>.5*(n[Math.floor(i)-1]+n[Math.ceil(i)-1]))}function Ve(e,n={}){let t=V(e,n.naRm);if(t===void 0)return NaN;let r=n.center??R(t),o=n.constant??1.4826,i=n.low??!1,l=n.high??!1,s=t.map(a=>Math.abs(a-r)),u=s.length;if((i||l)&&u%2===0){if(i&&l)throw new RangeError("'low' and 'high' cannot be both TRUE");let a=u/2+(l?1:0),g=s.sort((m,y)=>m-y);return o*g[a-1]}return o*R(s)}var K=e=>e===null||typeof e=="number"&&Number.isNaN(e),Y=e=>Array.isArray(e)||ArrayBuffer.isView(e);function Be(e){if(Y(e))return{columns:[e],rows:e.length};if(typeof e!="object"||e===null)throw new TypeError("the arguments must be arrays or data frames");let n=Object.values(e),t=n[0]?.length??0;if(n.some(r=>r.length!==t))throw new RangeError("not all arguments have the same length");return{columns:n,rows:t}}function ee(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(Be),t=n[0].rows;if(n.some(o=>o.rows!==t))throw new RangeError("not all arguments have the same length");let r=n.flatMap(o=>o.columns);return Array.from({length:t},(o,i)=>r.every(l=>!K(l[i])))}function We(e){if(Y(e))return Array.from(e).filter(r=>!K(r));let n=ee(e),t={};for(let[r,o]of Object.entries(e)){let i=Array.from(o).filter((l,s)=>n[s]);t[r]=o instanceof Float64Array?Float64Array.from(i):i}return t}function ne(e,n={}){let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5,o=n.minN??Math.floor(r/3),i=n.shrinkSml??.75,l=n.highUBias??1.5,s=n.u5Bias??.5+1.5*l,u=1/0,a=-1/0;for(let w of t)w<u&&(u=w),w>a&&(a=w);let g=a-u,m,y;if(g===0&&a===0)m=1,y=!0;else{m=Math.max(Math.abs(u),Math.abs(a));let M=(1+(s>=1.5*l+.5?1/(1+l):1.5/(1+s)))*Math.max(1,r)*Number.EPSILON;y=g<m*M*3}y?(m>10&&(m=9+m/10),m*=i,o>1&&(m/=o)):(m=r>1?g/r:g,g===1/0&&r>=2&&(m=a/r-u/r));let b=2**-20*Ze;m<b?m=b:m>Number.MAX_VALUE/1.25&&(m=Number.MAX_VALUE/1.25);let d=10**Math.floor(Math.log10(m)),x=[[2*d,l],[5*d,s],[10*d,l]],N=d;for(let[w,M]of x)if(w-m<M*(m-N))N=w;else break;let h=1e-10,f=Math.floor(u/N+h);for(;f*N>u+h*N;)f--;for(;!Number.isFinite(f*N);)f++;let c=Math.ceil(a/N-h);for(;c*N<a-h*N;)c++;for(;!Number.isFinite(c*N);)c--;let p=Math.trunc(.5+c-f);if(p<o){let w=o-p,M=Math.floor(w/2),O=w%2;u===0&&f===0&&a!==0?c+=w:a===0&&c===0&&u!==0?f-=w:f>=0?(c+=M,f-=M+O):(f-=M,c+=M+O),p=o}let E=f*N<u?f*N:u,A=c*N>a?c*N:a;if(p<=0)return[E];let $;if(Number.isFinite(A-E))$=H(E,A,p+1);else{let w=A/p-E/p;$=Array.from({length:p+1},(M,O)=>E+O*w),$[p]=A}let v=A/p-E/p;return $.map(w=>Math.abs(w)<1e-14*v?0:w)}var Ze=22250738585072014e-324;function De(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function Qe(e,n){let t=e.length,[r,o]=j(e),i=o-r;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let l=3.5*_(e)*t**-.3333333333333333;return l>0?Math.max(1,Math.ceil(i/l)):1}case"fd":case"freedman-diaconis":{let l=e.map(De),s=2*W(l);for(let u=1/8;s===0&&u>=1/512;u/=2){let[a,g]=C(l,[u,1-u]);s=(g-a)/(1-2*u)}return s===0&&(s=3.5*_(e)),s>0?Math.ceil(i/s*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function Je(e,n){let t=e.slice(1).map((r,o)=>r-e[o]);return e.length>5?R(t):e.length<=3?n:Math.min(...t.filter(r=>r>0))}function Xe(e,n={}){let t=Array.from(e).filter(Number.isFinite),r=t.length,o=n.right??!0,i=n.includeLowest??!0,l=n.breaks??"Sturges",s;if(typeof l!="string"&&typeof l!="number"&&l.length>1)s=[...l].sort((h,f)=>h-f);else{i=!0;let h=typeof l=="string"?Qe(t,l):typeof l=="number"?l:l[0];if(!Number.isFinite(h)||h<1)throw new RangeError("invalid number of 'breaks'");h=Math.min(h,1e6);let[f,c]=j(t);s=ne([f,c],{n:h,minN:1});for(let p=1;p<s.length;p++)if(!(s[p]-s[p-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let u=s.length,[a,g]=r>0?j(t):[0,0],m=1e-7*Je(s,g-a),y=s.map((h,f)=>o?f===0&&i?h-m:h+m:f<u-1?h-m:i?h+m:h-m),b=new Array(Math.max(0,u-1)).fill(0),d=0;for(let h of t){let f=Ge(h,y,o,i);f>=0&&(b[f]++,d++)}if(d<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let x=b.map((h,f)=>h/(r*(s[f+1]-s[f]))),N=b.map((h,f)=>.5*(s[f+1]+s[f]));return{breaks:s,counts:b,density:x,mids:N}}function Ge(e,n,t,r){let o=n.length-1;if(o<1)return-1;if(t){if(e===n[0]&&r)return 0;if(!(e>n[0]&&e<=n[o]))return-1;let s=1,u=o;for(;s<u;){let a=s+u>>1;e<=n[a]?u=a:s=a+1}return s-1}if(e===n[o]&&r)return o-1;if(!(e>=n[0]&&e<n[o]))return-1;let i=0,l=o-1;for(;i<l;){let s=i+l+1>>1;n[s]<=e?i=s:l=s-1}return i}function He(e){let n=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,o)=>r-o),t=n.length;if(t<1)throw new RangeError("'x' must have 1 or more non-missing values");return r=>{if(Number.isNaN(r))return NaN;let o=0,i=t;for(;o<i;){let l=o+i>>1;n[l]<=r?o=l+1:i=l}return o/t}}var I=e=>e===null||typeof e=="number"&&Number.isNaN(e),Ke=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?X(e,n):Number(e)-Number(n),Ye=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?S(e):e>0?"Inf":"-Inf";function en(e,n){let t=Array.from(n,s=>s===0?0:s),r=new Set(t.filter(s=>!I(s)).map(s=>typeof s));if(r.size>1)throw new TypeError(`${e} mixes ${[...r].join(" and ")} labels`);let o=[...r][0];if(o!==void 0&&o!=="number"&&o!=="string"&&o!=="boolean")throw new TypeError(`${e} has labels of an unsupported type`);let i=[...new Set(t.filter(s=>!I(s)))].sort(Ke),l=new Map(i.map((s,u)=>[s,u]));return{levels:i,codes:t.map(s=>I(s)?-1:l.get(s))}}var F=e=>Array.isArray(e)||e instanceof Float64Array;function se(e){if(e instanceof Float64Array)return[e];if(!Array.isArray(e))throw new TypeError("the group labels must be an array or an array of arrays");if(e.length>0&&e.every(F))return[...e];if(e.some(F))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function Z(e,n,t){e.forEach((l,s)=>{if(l.length!==t)throw new RangeError(`${n[s]} must have one label per row (${t}), not ${l.length}`)});let r=e.map((l,s)=>en(n[s],l)),o=r.reduce((l,s)=>l*s.levels.length,1),i=new Array(t);for(let l=0;l<t;l++){let s=0,u=1;for(let a of r){let g=a.codes[l];if(g<0){s=-1;break}s+=g*u,u*=a.levels.length}i[l]=s}return{factors:r,size:o,cells:i}}function D(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function le(e,n){return e.factors.map(t=>{let r=t.levels.length,o=t.levels[n%r];return n=Math.floor(n/r),o})}var ae=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function nn(e,n,t){let r=Array.from(e),o=se(n),i=Z(o,ae(o.length,"index"),r.length),l=D(i).map(a=>a.length===0?null:{value:t(a.map(g=>r[g]))}),u=l.every(a=>a===null||typeof a.value=="number")?l.map(a=>a===null?NaN:a.value):l.map(a=>a===null?null:a.value);return{dim:i.factors.map(a=>a.levels.length),dimnames:i.factors.map(a=>[...a.levels]),values:u}}function tn(e,n){let t={};for(let[r,o]of Object.entries(e))t[r]=o instanceof Float64Array?Float64Array.from(n,i=>o[i]):n.map(i=>o[i]);return t}function rn(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!F(o))throw new TypeError(`column '${r}' must be an array`);if(o.length!==t)throw new RangeError(`the columns of the data frame have different lengths (found for '${r}')`)}return t}function on(e,n,t={}){let r=t.sep??".",o=se(n),i=!F(e);if(i&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let l=i?rn(e):e.length,s=Z(o,ae(o.length,"f"),l),u=i?[]:Array.from(e),a=new Map;return D(s).forEach((g,m)=>{if(g.length===0&&(t.drop||s.factors.length===1))return;let y=le(s,m).map(Ye).join(r);a.set(y,i?tn(e,g):g.map(b=>u[b]))}),a}function te(e,n){if(n===void 0)throw new Error(`object '${e}' not found`);if(!F(n))throw new TypeError(`column '${e}' must be an array`);return Array.from(n,t=>{if(t===null)return NaN;if(typeof t!="number")throw new TypeError(`column '${e}' to summarise must be numeric`);return t})}function re(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new Error(`object '${n}' not found`);if(!F(t))throw new TypeError(`column '${n}' must be an array`);return t}function L(e,n){if(e.type==="var")n.push(e.name);else if(e.type==="binary"&&e.op==="+")L(e.left,n),L(e.right,n);else if(e.type==="paren")L(e.arg,n);else throw new SyntaxError("invalid formula: the right-hand side must be grouping variables joined by '+'");return n}function sn(e,n){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");if(t<0)throw new SyntaxError("invalid formula: missing '~'");let r=e.slice(0,t).trim(),o=L(J(`~ ${e.slice(t+1)}`).rhs,[]),i=/^[A-Za-z.][A-Za-z0-9._]*$/,l;if(r===".")l=n.filter(s=>!o.includes(s));else{let s=/^cbind\s*\((.*)\)$/s.exec(r);if(l=s===null?[r]:s[1].split(",").map(u=>u.trim()),l.some(u=>!i.test(u)||u==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}return{values:l,groups:o}}function oe(e,n,t,r,o,i){let l=r[0]?.length??0;e.forEach((m,y)=>{if(n[y].length!==l)throw new RangeError(`variable lengths differ (found for '${m}')`)});let s=Z(r,t,l),u=D(s).map((m,y)=>({cell:y,rows:m.filter(o)})).filter(m=>m.rows.length>0),a={},g=u.map(m=>le(s,m.cell));return t.forEach((m,y)=>{a[m]=g.map(b=>b[y])}),e.forEach((m,y)=>{let b=n[y],x=u.map(h=>i(h.rows.map(f=>b[f]))).map(h=>{if(typeof h=="number")return{names:void 0,values:[h]};if(Array.isArray(h))return{names:void 0,values:[...h]};let f=h;return{names:Object.keys(f),values:Object.values(f)}}),N=x[0]?.values.length??1;if(x.some(h=>h.values.length!==N))throw new RangeError("fun must return values of the same length for every group");if(N===1&&x[0]?.names===void 0){a[m]=x.map(h=>h.values[0]);return}for(let h=0;h<N;h++){let f=x[0].names?.[h]??String(h+1);a[`${m}.${f}`]=x.map(c=>c.values[h])}}),a}function ln(e,n,t){if(typeof n!="object"||n===null)throw new TypeError("the data must be an object of columns");if(typeof e=="string"){let s=n,{values:u,groups:a}=sn(e,Object.keys(s)),g=d=>Object.prototype.hasOwnProperty.call(s,d),m=u.map(d=>te(d,g(d)?s[d]:void 0)),y=a.map(d=>re(s,d));return oe(u,m,a,y,d=>m.every(x=>!Number.isNaN(x[d]))&&y.every(x=>!I(x[d])),t)}if(typeof e!="object"||e===null)throw new TypeError("x must be a data frame");let r=Object.keys(e),o=r.map(s=>te(s,e[s])),i=Object.keys(n);if(i.length===0)throw new RangeError("'by' must name at least one grouping column");let l=i.map(s=>re(n,s));return oe(r,o,i,l,()=>!0,t)}var P=e=>typeof e=="string"?[e]:[...e];function ce(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new Error(`Column \`${t}\` doesn't exist.`)}function an(e,n){if(n instanceof Float64Array)return"double";let t=null;for(let r of n){if(r===null)continue;let o=typeof r=="number"?"double":typeof r=="string"?"character":"logical";if(t!==null&&o!==t)throw new TypeError(`column '${e}' mixes ${t} and ${o} values`);t=o}return t}function cn(e,n){let t=null;for(let r of n){let o=an(r,e[r]);if(o!==null){if(t===null)t={type:o,column:r};else if(t.type!==o){if(t.type==="character"||o==="character")throw new TypeError(`Can't combine \`${t.column}\` <${t.type}> and \`${r}\` <${o}>.`);o==="double"&&(t={type:o,column:r})}}}return t?.type??null}function fn(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new Error(`\`regex\` should define ${t} groups; ${r} found.`);let o=new RegExp(n);return e.map(i=>{let l=o.exec(i);return Array.from({length:t},(s,u)=>l===null?null:l[u+1]??null)})}function un(e,n,t,r){let o=new RegExp(n,"g"),i=[],l=[],s=e.map((a,g)=>{let m=[],y=0;for(let b of a.matchAll(o))b[0].length!==0&&(m.push(a.slice(y,b.index)),y=b.index+b[0].length);return m.push(a.slice(y)),m.length>t&&i.push(g+1),m.length<t&&l.push(g+1),Array.from({length:t},(b,d)=>m[d]??null)}),u=a=>`${a.length} rows [${a.join(", ")}]`;return i.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${u(i)}.`),l.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${u(l)}.`),s}function mn(e,n,t,r){let{namesSep:o,namesPattern:i}=t;if(n.length===1){if(o!==void 0)throw new Error("`names_sep` can't be used with a length 1 `names_to`.");if(i===void 0)return e.map(s=>[s]);let l=new RegExp(i);return e.map(s=>[l.exec(s)?.[1]??null])}if(o===void 0==(i===void 0))throw new Error("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?un(e,o,n.length,r):fn(e,i,n.length)}function hn(e,n){let t=q(e),r=Object.keys(e),o=typeof n.cols=="function"?r.filter(n.cols):[...new Set(n.cols)];if(ce(e,o),o.length===0)throw new Error("`cols` must select at least one column.");let i=P(n.namesTo??"name"),l=i.indexOf(".value");if(i.lastIndexOf(".value")!==l)throw new Error('`names_to` may contain ".value" only once');let s=[],u=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),a=o.map(f=>u===null?f:f.replace(u,"")),g=mn(a,i,n,s),m=[],y=[];if(l<0)m.push(...g),y.push({name:n.valuesTo??"value",sources:[...o]});else{let f=new Map,c=new Map;g.forEach((p,E)=>{let A=p.filter((O,U)=>U!==l),$=JSON.stringify(A),v=f.get($);if(v===void 0){v=m.length,f.set($,v),m.push(A);for(let O of y)O.sources.push(null)}let w=p[l]??"NA",M=c.get(w);if(M===void 0&&(M={name:w,sources:m.map(()=>null)},c.set(w,M),y.push(M)),M.sources[v]!==null)throw new Error(`the names give the value column '${w}' twice for one key`);M.sources[v]=o[E]})}let b=y.map(f=>cn(e,f.sources.filter(c=>c!==null))),d=[];if(n.colsVary==="slowest")for(let f=0;f<m.length;f++)for(let c=0;c<t;c++)d.push([c,f]);else for(let f=0;f<t;f++)for(let c=0;c<m.length;c++)d.push([f,c]);let x=(f,c,p)=>{let E=f.sources[p];return E==null?null:e[E][c]};n.valuesDropNa===!0&&(d=d.filter(([f,c])=>y.some(p=>!T(x(p,f,c)))));let N={},h=d.map(([f])=>f);for(let f of r)o.includes(f)||k(N,f,z(e[f],h));if(i.forEach((f,c)=>{if(c===l)return;let p=n.namesTransform?.[f],E=A=>{let $=m[A][c<l||l<0?c:c-1];return $===null||p===void 0?$:p($)};k(N,f,d.map(([,A])=>E(A)))}),y.forEach((f,c)=>{let p=b[c]==="double";if(p&&f.sources.every(E=>E!==null&&e[E]instanceof Float64Array))k(N,f.name,Float64Array.from(d,([E,A])=>x(f,E,A)));else{let E=d.map(([A,$])=>{let v=x(f,A,$);return p&&typeof v=="boolean"?Number(v):v});k(N,f.name,E)}}),n.onWarning!==void 0)for(let f of new Set(s))n.onWarning(f);return N}var pn=e=>T(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function ie(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(i,l)=>{let s=JSON.stringify(e.map(a=>pn(a[l]))),u=t.get(s);return u===void 0&&(u=r.length,t.set(s,u),r.push(l)),u}),firsts:r}}function gn(e){return T(e)?"NA":typeof e=="number"?Number.isFinite(e)?S(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function Q(e,n,t){if(e!==void 0)return n(e)?e:e[t]}function yn(e,n={}){let t=q(e),r=P(n.namesFrom??"name"),o=P(n.valuesFrom??"value"),i=n.idCols===void 0?Object.keys(e).filter(c=>!r.includes(c)&&!o.includes(c)):P(n.idCols);ce(e,[...i,...r,...o]);let l=n.namesPrefix??"",s=n.namesSep??"_",u=ie(i.map(c=>e[c]),t),a=ie(r.map(c=>e[c]),t),g=a.firsts.map((c,p)=>p);n.namesSort===!0&&g.sort((c,p)=>{for(let E of r){let A=G(e[E][a.firsts[c]],e[E][a.firsts[p]]);if(A!==0)return A}return 0});let m=a.firsts.map(c=>l+r.map(p=>gn(e[p][c])).join(s)),y=a.firsts.length,b=Array.from({length:u.firsts.length*y},()=>[]);for(let c=0;c<t;c++)b[u.codes[c]*y+a.codes[c]].push(c);let d=c=>typeof c=="function",x=c=>typeof c!="object"||c===null,N=(c,p)=>{let E=e[c],A=Q(n.valuesFn,d,c),$=Q(n.valuesFill,x,c)??null,v=u.firsts.map((w,M)=>{let O=b[M*y+p];return O.length===0?$:A!==void 0?A(O.map(U=>E[U])):E[O[0]]});return E instanceof Float64Array&&v.every(w=>w===null||typeof w=="number")?Float64Array.from(v,w=>w===null?NaN:w):v};for(let c of o)if(Q(n.valuesFn,d,c)===void 0&&b.some(p=>p.length>1))throw new Error(`values from '${c}' are not uniquely identified; use valuesFn to summarise them`);let h={};for(let c of i)k(h,c,z(e[c],u.firsts));let f=(c,p)=>o.length===1?m[p]:`${c}${s}${m[p]}`;if(n.namesVary==="slowest")for(let c of g)for(let p of o)k(h,f(p,c),N(p,c));else for(let c of o)for(let p of g)k(h,f(c,p),N(c,p));return h}export{W as IQR,ln as aggregate,ee as completeCases,me as cor,ue as cov,Me as cummax,$e as cummin,xe as cumprod,Ae as cumsum,Le as cut,Se as cv,ve as diff,He as ecdf,Pe as findInterval,ze as fivenum,ge as fromRows,Re as geometricMean,Xe as hist,ke as kurtosis,Ve as mad,be as mean,je as meanAD,R as median,he as merge,Fe as modes,We as naOmit,hn as pivotLonger,yn as pivotWider,ne as pretty,we as prod,C as quantile,j as range,fe as rank,Te as scale,_ as sd,Oe as skewness,on as split,pe as subset,de as sum,Ce as table,_e as tabulate,nn as tapply,ye as toRows,Ie as unique,Ee as variance,Ne as weightedMean};
1
+ /*! rStats.js 0.11.1 | 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 J,e as S,q as fe,r as ue,s as me}from"./chunks/chunk-LAUYSGV4.js";import"./chunks/chunk-ZRJQD7VS.js";import{A as ke,B as Re,C as Fe,D as je,E as Se,F as Te,a as q,b as T,c as z,d as k,e as G,f as he,g as pe,j as ge,k as ye,l as V,m as de,n as we,o as be,p as Ne,q as Ee,r as _,s as R,t as j,u as Ae,v as xe,w as Me,x as $e,y as ve,z as Oe}from"./chunks/chunk-X2AWQSVS.js";import{a as X}from"./chunks/chunk-M6GDXKKS.js";import{a as H,b as _e,c as Ce,d as Ie,e as Le,f as Pe}from"./chunks/chunk-PHHUHR7T.js";import"./chunks/chunk-HITD7CX6.js";import"./chunks/chunk-KK4GE65D.js";import"./chunks/chunk-6I6QKTFK.js";import"./chunks/chunk-ETOEZTGL.js";var B=4*Number.EPSILON,Ue={4:[0,1],5:[.5,.5],6:[0,0],8:[1/3,1/3],9:[3/8,3/8]};function qe(e,n,t){let r=e.length,o=a=>e[Math.min(Math.max(a,1),r)-1];if(t===7){let a=1+(r-1)*n,g=Math.floor(a),m=o(g),y=o(Math.ceil(a));if(a>g&&y!==m){let b=a-g;return(1-b)*m+b*y}return m}let i,l;if(t<=3){let a=t===3?r*n-.5:r*n;i=Math.floor(a*(1+B)),t===1?l=a>i?1:0:t===2?l=a>i?1:.5:l=a!==i||Math.abs(i%2)===1?1:0}else{let[a,g]=Ue[t],m=a+n*(r+1-a-g);i=Math.floor(m*(1+B)),l=m-i,Math.abs(l)<B&&(l=0)}let s=o(i),u=o(i+1);return l===1?u:l>0&&l<1&&s!==u?(1-l)*s+l*u:s}function C(e,n=[0,.25,.5,.75,1],t={}){let r=t.type??7;if(!(Number.isInteger(r)&&r>=1&&r<=9))throw new RangeError("'type' must be an integer in 1..9");let o=V(e,t.naRm);if(o===void 0)throw new RangeError("missing values and NaN's not allowed if 'na.rm' is FALSE");let i=o.sort((a,g)=>a-g),l=typeof n=="number"?[n]:Array.from(n),s=100*Number.EPSILON;if(l.some(a=>a<-s||a>1+s))throw new RangeError("'probs' outside [0,1]");let u=l.map(a=>Number.isNaN(a)||i.length===0?NaN:qe(i,Math.min(Math.max(a,0),1),r));return typeof n=="number"?u[0]:u}function W(e,n={}){let[t,r]=C(e,[.25,.75],n);return r-t}function ze(e){let n=Array.from(e).filter(i=>!Number.isNaN(i)).sort((i,l)=>i-l),t=n.length;if(t===0)return[NaN,NaN,NaN,NaN,NaN];let r=Math.floor((t+3)/2)/2;return[1,r,(t+1)/2,t+1-r,t].map(i=>.5*(n[Math.floor(i)-1]+n[Math.ceil(i)-1]))}function Ve(e,n={}){let t=V(e,n.naRm);if(t===void 0)return NaN;let r=n.center??R(t),o=n.constant??1.4826,i=n.low??!1,l=n.high??!1,s=t.map(a=>Math.abs(a-r)),u=s.length;if((i||l)&&u%2===0){if(i&&l)throw new RangeError("'low' and 'high' cannot be both TRUE");let a=u/2+(l?1:0),g=s.sort((m,y)=>m-y);return o*g[a-1]}return o*R(s)}var K=e=>e===null||typeof e=="number"&&Number.isNaN(e),Y=e=>Array.isArray(e)||ArrayBuffer.isView(e);function Be(e){if(Y(e))return{columns:[e],rows:e.length};if(typeof e!="object"||e===null)throw new TypeError("the arguments must be arrays or data frames");let n=Object.values(e),t=n[0]?.length??0;if(n.some(r=>r.length!==t))throw new RangeError("not all arguments have the same length");return{columns:n,rows:t}}function ee(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(Be),t=n[0].rows;if(n.some(o=>o.rows!==t))throw new RangeError("not all arguments have the same length");let r=n.flatMap(o=>o.columns);return Array.from({length:t},(o,i)=>r.every(l=>!K(l[i])))}function We(e){if(Y(e))return Array.from(e).filter(r=>!K(r));let n=ee(e),t={};for(let[r,o]of Object.entries(e)){let i=Array.from(o).filter((l,s)=>n[s]);t[r]=o instanceof Float64Array?Float64Array.from(i):i}return t}function ne(e,n={}){let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5,o=n.minN??Math.floor(r/3),i=n.shrinkSml??.75,l=n.highUBias??1.5,s=n.u5Bias??.5+1.5*l,u=1/0,a=-1/0;for(let w of t)w<u&&(u=w),w>a&&(a=w);let g=a-u,m,y;if(g===0&&a===0)m=1,y=!0;else{m=Math.max(Math.abs(u),Math.abs(a));let M=(1+(s>=1.5*l+.5?1/(1+l):1.5/(1+s)))*Math.max(1,r)*Number.EPSILON;y=g<m*M*3}y?(m>10&&(m=9+m/10),m*=i,o>1&&(m/=o)):(m=r>1?g/r:g,g===1/0&&r>=2&&(m=a/r-u/r));let b=2**-20*Ze;m<b?m=b:m>Number.MAX_VALUE/1.25&&(m=Number.MAX_VALUE/1.25);let d=10**Math.floor(Math.log10(m)),x=[[2*d,l],[5*d,s],[10*d,l]],N=d;for(let[w,M]of x)if(w-m<M*(m-N))N=w;else break;let h=1e-10,f=Math.floor(u/N+h);for(;f*N>u+h*N;)f--;for(;!Number.isFinite(f*N);)f++;let c=Math.ceil(a/N-h);for(;c*N<a-h*N;)c++;for(;!Number.isFinite(c*N);)c--;let p=Math.trunc(.5+c-f);if(p<o){let w=o-p,M=Math.floor(w/2),O=w%2;u===0&&f===0&&a!==0?c+=w:a===0&&c===0&&u!==0?f-=w:f>=0?(c+=M,f-=M+O):(f-=M,c+=M+O),p=o}let E=f*N<u?f*N:u,A=c*N>a?c*N:a;if(p<=0)return[E];let $;if(Number.isFinite(A-E))$=H(E,A,p+1);else{let w=A/p-E/p;$=Array.from({length:p+1},(M,O)=>E+O*w),$[p]=A}let v=A/p-E/p;return $.map(w=>Math.abs(w)<1e-14*v?0:w)}var Ze=22250738585072014e-324;function De(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function Qe(e,n){let t=e.length,[r,o]=j(e),i=o-r;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let l=3.5*_(e)*t**-.3333333333333333;return l>0?Math.max(1,Math.ceil(i/l)):1}case"fd":case"freedman-diaconis":{let l=e.map(De),s=2*W(l);for(let u=1/8;s===0&&u>=1/512;u/=2){let[a,g]=C(l,[u,1-u]);s=(g-a)/(1-2*u)}return s===0&&(s=3.5*_(e)),s>0?Math.ceil(i/s*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function Je(e,n){let t=e.slice(1).map((r,o)=>r-e[o]);return e.length>5?R(t):e.length<=3?n:Math.min(...t.filter(r=>r>0))}function Xe(e,n={}){let t=Array.from(e).filter(Number.isFinite),r=t.length,o=n.right??!0,i=n.includeLowest??!0,l=n.breaks??"Sturges",s;if(typeof l!="string"&&typeof l!="number"&&l.length>1)s=[...l].sort((h,f)=>h-f);else{i=!0;let h=typeof l=="string"?Qe(t,l):typeof l=="number"?l:l[0];if(!Number.isFinite(h)||h<1)throw new RangeError("invalid number of 'breaks'");h=Math.min(h,1e6);let[f,c]=j(t);s=ne([f,c],{n:h,minN:1});for(let p=1;p<s.length;p++)if(!(s[p]-s[p-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let u=s.length,[a,g]=r>0?j(t):[0,0],m=1e-7*Je(s,g-a),y=s.map((h,f)=>o?f===0&&i?h-m:h+m:f<u-1?h-m:i?h+m:h-m),b=new Array(Math.max(0,u-1)).fill(0),d=0;for(let h of t){let f=Ge(h,y,o,i);f>=0&&(b[f]++,d++)}if(d<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let x=b.map((h,f)=>h/(r*(s[f+1]-s[f]))),N=b.map((h,f)=>.5*(s[f+1]+s[f]));return{breaks:s,counts:b,density:x,mids:N}}function Ge(e,n,t,r){let o=n.length-1;if(o<1)return-1;if(t){if(e===n[0]&&r)return 0;if(!(e>n[0]&&e<=n[o]))return-1;let s=1,u=o;for(;s<u;){let a=s+u>>1;e<=n[a]?u=a:s=a+1}return s-1}if(e===n[o]&&r)return o-1;if(!(e>=n[0]&&e<n[o]))return-1;let i=0,l=o-1;for(;i<l;){let s=i+l+1>>1;n[s]<=e?i=s:l=s-1}return i}function He(e){let n=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,o)=>r-o),t=n.length;if(t<1)throw new RangeError("'x' must have 1 or more non-missing values");return r=>{if(Number.isNaN(r))return NaN;let o=0,i=t;for(;o<i;){let l=o+i>>1;n[l]<=r?o=l+1:i=l}return o/t}}var I=e=>e===null||typeof e=="number"&&Number.isNaN(e),Ke=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?X(e,n):Number(e)-Number(n),Ye=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?S(e):e>0?"Inf":"-Inf";function en(e,n){let t=Array.from(n,s=>s===0?0:s),r=new Set(t.filter(s=>!I(s)).map(s=>typeof s));if(r.size>1)throw new TypeError(`${e} mixes ${[...r].join(" and ")} labels`);let o=[...r][0];if(o!==void 0&&o!=="number"&&o!=="string"&&o!=="boolean")throw new TypeError(`${e} has labels of an unsupported type`);let i=[...new Set(t.filter(s=>!I(s)))].sort(Ke),l=new Map(i.map((s,u)=>[s,u]));return{levels:i,codes:t.map(s=>I(s)?-1:l.get(s))}}var F=e=>Array.isArray(e)||e instanceof Float64Array;function se(e){if(e instanceof Float64Array)return[e];if(!Array.isArray(e))throw new TypeError("the group labels must be an array or an array of arrays");if(e.length>0&&e.every(F))return[...e];if(e.some(F))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function Z(e,n,t){e.forEach((l,s)=>{if(l.length!==t)throw new RangeError(`${n[s]} must have one label per row (${t}), not ${l.length}`)});let r=e.map((l,s)=>en(n[s],l)),o=r.reduce((l,s)=>l*s.levels.length,1),i=new Array(t);for(let l=0;l<t;l++){let s=0,u=1;for(let a of r){let g=a.codes[l];if(g<0){s=-1;break}s+=g*u,u*=a.levels.length}i[l]=s}return{factors:r,size:o,cells:i}}function D(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function le(e,n){return e.factors.map(t=>{let r=t.levels.length,o=t.levels[n%r];return n=Math.floor(n/r),o})}var ae=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function nn(e,n,t){let r=Array.from(e),o=se(n),i=Z(o,ae(o.length,"index"),r.length),l=D(i).map(a=>a.length===0?null:{value:t(a.map(g=>r[g]))}),u=l.every(a=>a===null||typeof a.value=="number")?l.map(a=>a===null?NaN:a.value):l.map(a=>a===null?null:a.value);return{dim:i.factors.map(a=>a.levels.length),dimnames:i.factors.map(a=>[...a.levels]),values:u}}function tn(e,n){let t={};for(let[r,o]of Object.entries(e))t[r]=o instanceof Float64Array?Float64Array.from(n,i=>o[i]):n.map(i=>o[i]);return t}function rn(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!F(o))throw new TypeError(`column '${r}' must be an array`);if(o.length!==t)throw new RangeError(`the columns of the data frame have different lengths (found for '${r}')`)}return t}function on(e,n,t={}){let r=t.sep??".",o=se(n),i=!F(e);if(i&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let l=i?rn(e):e.length,s=Z(o,ae(o.length,"f"),l),u=i?[]:Array.from(e),a=new Map;return D(s).forEach((g,m)=>{if(g.length===0&&(t.drop||s.factors.length===1))return;let y=le(s,m).map(Ye).join(r);a.set(y,i?tn(e,g):g.map(b=>u[b]))}),a}function te(e,n){if(n===void 0)throw new Error(`object '${e}' not found`);if(!F(n))throw new TypeError(`column '${e}' must be an array`);return Array.from(n,t=>{if(t===null)return NaN;if(typeof t!="number")throw new TypeError(`column '${e}' to summarise must be numeric`);return t})}function re(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new Error(`object '${n}' not found`);if(!F(t))throw new TypeError(`column '${n}' must be an array`);return t}function L(e,n){if(e.type==="var")n.push(e.name);else if(e.type==="binary"&&e.op==="+")L(e.left,n),L(e.right,n);else if(e.type==="paren")L(e.arg,n);else throw new SyntaxError("invalid formula: the right-hand side must be grouping variables joined by '+'");return n}function sn(e,n){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");if(t<0)throw new SyntaxError("invalid formula: missing '~'");let r=e.slice(0,t).trim(),o=L(J(`~ ${e.slice(t+1)}`).rhs,[]),i=/^[A-Za-z.][A-Za-z0-9._]*$/,l;if(r===".")l=n.filter(s=>!o.includes(s));else{let s=/^cbind\s*\((.*)\)$/s.exec(r);if(l=s===null?[r]:s[1].split(",").map(u=>u.trim()),l.some(u=>!i.test(u)||u==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}return{values:l,groups:o}}function oe(e,n,t,r,o,i){let l=r[0]?.length??0;e.forEach((m,y)=>{if(n[y].length!==l)throw new RangeError(`variable lengths differ (found for '${m}')`)});let s=Z(r,t,l),u=D(s).map((m,y)=>({cell:y,rows:m.filter(o)})).filter(m=>m.rows.length>0),a={},g=u.map(m=>le(s,m.cell));return t.forEach((m,y)=>{a[m]=g.map(b=>b[y])}),e.forEach((m,y)=>{let b=n[y],x=u.map(h=>i(h.rows.map(f=>b[f]))).map(h=>{if(typeof h=="number")return{names:void 0,values:[h]};if(Array.isArray(h))return{names:void 0,values:[...h]};let f=h;return{names:Object.keys(f),values:Object.values(f)}}),N=x[0]?.values.length??1;if(x.some(h=>h.values.length!==N))throw new RangeError("fun must return values of the same length for every group");if(N===1&&x[0]?.names===void 0){a[m]=x.map(h=>h.values[0]);return}for(let h=0;h<N;h++){let f=x[0].names?.[h]??String(h+1);a[`${m}.${f}`]=x.map(c=>c.values[h])}}),a}function ln(e,n,t){if(typeof n!="object"||n===null)throw new TypeError("the data must be an object of columns");if(typeof e=="string"){let s=n,{values:u,groups:a}=sn(e,Object.keys(s)),g=d=>Object.prototype.hasOwnProperty.call(s,d),m=u.map(d=>te(d,g(d)?s[d]:void 0)),y=a.map(d=>re(s,d));return oe(u,m,a,y,d=>m.every(x=>!Number.isNaN(x[d]))&&y.every(x=>!I(x[d])),t)}if(typeof e!="object"||e===null)throw new TypeError("x must be a data frame");let r=Object.keys(e),o=r.map(s=>te(s,e[s])),i=Object.keys(n);if(i.length===0)throw new RangeError("'by' must name at least one grouping column");let l=i.map(s=>re(n,s));return oe(r,o,i,l,()=>!0,t)}var P=e=>typeof e=="string"?[e]:[...e];function ce(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new Error(`Column \`${t}\` doesn't exist.`)}function an(e,n){if(n instanceof Float64Array)return"double";let t=null;for(let r of n){if(r===null)continue;let o=typeof r=="number"?"double":typeof r=="string"?"character":"logical";if(t!==null&&o!==t)throw new TypeError(`column '${e}' mixes ${t} and ${o} values`);t=o}return t}function cn(e,n){let t=null;for(let r of n){let o=an(r,e[r]);if(o!==null){if(t===null)t={type:o,column:r};else if(t.type!==o){if(t.type==="character"||o==="character")throw new TypeError(`Can't combine \`${t.column}\` <${t.type}> and \`${r}\` <${o}>.`);o==="double"&&(t={type:o,column:r})}}}return t?.type??null}function fn(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new Error(`\`regex\` should define ${t} groups; ${r} found.`);let o=new RegExp(n);return e.map(i=>{let l=o.exec(i);return Array.from({length:t},(s,u)=>l===null?null:l[u+1]??null)})}function un(e,n,t,r){let o=new RegExp(n,"g"),i=[],l=[],s=e.map((a,g)=>{let m=[],y=0;for(let b of a.matchAll(o))b[0].length!==0&&(m.push(a.slice(y,b.index)),y=b.index+b[0].length);return m.push(a.slice(y)),m.length>t&&i.push(g+1),m.length<t&&l.push(g+1),Array.from({length:t},(b,d)=>m[d]??null)}),u=a=>`${a.length} rows [${a.join(", ")}]`;return i.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${u(i)}.`),l.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${u(l)}.`),s}function mn(e,n,t,r){let{namesSep:o,namesPattern:i}=t;if(n.length===1){if(o!==void 0)throw new Error("`names_sep` can't be used with a length 1 `names_to`.");if(i===void 0)return e.map(s=>[s]);let l=new RegExp(i);return e.map(s=>[l.exec(s)?.[1]??null])}if(o===void 0==(i===void 0))throw new Error("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?un(e,o,n.length,r):fn(e,i,n.length)}function hn(e,n){let t=q(e),r=Object.keys(e),o=typeof n.cols=="function"?r.filter(n.cols):[...new Set(n.cols)];if(ce(e,o),o.length===0)throw new Error("`cols` must select at least one column.");let i=P(n.namesTo??"name"),l=i.indexOf(".value");if(i.lastIndexOf(".value")!==l)throw new Error('`names_to` may contain ".value" only once');let s=[],u=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),a=o.map(f=>u===null?f:f.replace(u,"")),g=mn(a,i,n,s),m=[],y=[];if(l<0)m.push(...g),y.push({name:n.valuesTo??"value",sources:[...o]});else{let f=new Map,c=new Map;g.forEach((p,E)=>{let A=p.filter((O,U)=>U!==l),$=JSON.stringify(A),v=f.get($);if(v===void 0){v=m.length,f.set($,v),m.push(A);for(let O of y)O.sources.push(null)}let w=p[l]??"NA",M=c.get(w);if(M===void 0&&(M={name:w,sources:m.map(()=>null)},c.set(w,M),y.push(M)),M.sources[v]!==null)throw new Error(`the names give the value column '${w}' twice for one key`);M.sources[v]=o[E]})}let b=y.map(f=>cn(e,f.sources.filter(c=>c!==null))),d=[];if(n.colsVary==="slowest")for(let f=0;f<m.length;f++)for(let c=0;c<t;c++)d.push([c,f]);else for(let f=0;f<t;f++)for(let c=0;c<m.length;c++)d.push([f,c]);let x=(f,c,p)=>{let E=f.sources[p];return E==null?null:e[E][c]};n.valuesDropNa===!0&&(d=d.filter(([f,c])=>y.some(p=>!T(x(p,f,c)))));let N={},h=d.map(([f])=>f);for(let f of r)o.includes(f)||k(N,f,z(e[f],h));if(i.forEach((f,c)=>{if(c===l)return;let p=n.namesTransform?.[f],E=A=>{let $=m[A][c<l||l<0?c:c-1];return $===null||p===void 0?$:p($)};k(N,f,d.map(([,A])=>E(A)))}),y.forEach((f,c)=>{let p=b[c]==="double";if(p&&f.sources.every(E=>E!==null&&e[E]instanceof Float64Array))k(N,f.name,Float64Array.from(d,([E,A])=>x(f,E,A)));else{let E=d.map(([A,$])=>{let v=x(f,A,$);return p&&typeof v=="boolean"?Number(v):v});k(N,f.name,E)}}),n.onWarning!==void 0)for(let f of new Set(s))n.onWarning(f);return N}var pn=e=>T(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function ie(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(i,l)=>{let s=JSON.stringify(e.map(a=>pn(a[l]))),u=t.get(s);return u===void 0&&(u=r.length,t.set(s,u),r.push(l)),u}),firsts:r}}function gn(e){return T(e)?"NA":typeof e=="number"?Number.isFinite(e)?S(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function Q(e,n,t){if(e!==void 0)return n(e)?e:e[t]}function yn(e,n={}){let t=q(e),r=P(n.namesFrom??"name"),o=P(n.valuesFrom??"value"),i=n.idCols===void 0?Object.keys(e).filter(c=>!r.includes(c)&&!o.includes(c)):P(n.idCols);ce(e,[...i,...r,...o]);let l=n.namesPrefix??"",s=n.namesSep??"_",u=ie(i.map(c=>e[c]),t),a=ie(r.map(c=>e[c]),t),g=a.firsts.map((c,p)=>p);n.namesSort===!0&&g.sort((c,p)=>{for(let E of r){let A=G(e[E][a.firsts[c]],e[E][a.firsts[p]]);if(A!==0)return A}return 0});let m=a.firsts.map(c=>l+r.map(p=>gn(e[p][c])).join(s)),y=a.firsts.length,b=Array.from({length:u.firsts.length*y},()=>[]);for(let c=0;c<t;c++)b[u.codes[c]*y+a.codes[c]].push(c);let d=c=>typeof c=="function",x=c=>typeof c!="object"||c===null,N=(c,p)=>{let E=e[c],A=Q(n.valuesFn,d,c),$=Q(n.valuesFill,x,c)??null,v=u.firsts.map((w,M)=>{let O=b[M*y+p];return O.length===0?$:A!==void 0?A(O.map(U=>E[U])):E[O[0]]});return E instanceof Float64Array&&v.every(w=>w===null||typeof w=="number")?Float64Array.from(v,w=>w===null?NaN:w):v};for(let c of o)if(Q(n.valuesFn,d,c)===void 0&&b.some(p=>p.length>1))throw new Error(`values from '${c}' are not uniquely identified; use valuesFn to summarise them`);let h={};for(let c of i)k(h,c,z(e[c],u.firsts));let f=(c,p)=>o.length===1?m[p]:`${c}${s}${m[p]}`;if(n.namesVary==="slowest")for(let c of g)for(let p of o)k(h,f(p,c),N(p,c));else for(let c of o)for(let p of g)k(h,f(c,p),N(c,p));return h}export{W as IQR,ln as aggregate,ee as completeCases,me as cor,ue as cov,Me as cummax,$e as cummin,xe as cumprod,Ae as cumsum,Le as cut,Se as cv,ve as diff,He as ecdf,Pe as findInterval,ze as fivenum,ge as fromRows,Re as geometricMean,Xe as hist,ke as kurtosis,Ve as mad,be as mean,je as meanAD,R as median,he as merge,Fe as modes,We as naOmit,hn as pivotLonger,yn as pivotWider,ne as pretty,we as prod,C as quantile,j as range,fe as rank,Te as scale,_ as sd,Oe as skewness,on as split,pe as subset,de as sum,Ce as table,_e as tabulate,nn as tapply,ye as toRows,Ie as unique,Ee as variance,Ne as weightedMean};
@@ -1,6 +1,10 @@
1
1
  import { type Vectorizable, type VectorResult } from "../internal/vectorize.js";
2
2
  import { type DensityOptions, type TailOptions } from "../internal/dpq.js";
3
- /** Limits of the arcsine distribution. */
3
+ /**
4
+ * Limits of the arcsine distribution.
5
+ *
6
+ * @category Distributions
7
+ */
4
8
  export interface ArcsineParams {
5
9
  /** Lower limit. Default `0`. */
6
10
  a?: number;
@@ -11,14 +15,45 @@ export declare function darcsine1(x: number, a: number, b: number, log: boolean)
11
15
  export declare function parcsine1(q: number, a: number, b: number, lowerTail: boolean, logP: boolean): number;
12
16
  export declare function qarcsine1(p: number, a: number, b: number, lowerTail: boolean, logP: boolean): number;
13
17
  /**
14
- * Density of the arcsine distribution on (a, b), f(x) = 1 / (pi sqrt((x - a)(b - x))). R has no arcsine
15
- * distribution; this equals `dbeta((x - a) / (b - a), 0.5, 0.5) / (b - a)`.
18
+ * Density of the arcsine distribution on (a, b), f(x) = 1 / (pi sqrt((x - a)(b - x))).
19
+ * Not an R function. Neither base R nor extraDistr has the arcsine distribution; this equals
20
+ * `dbeta((x - a) / (b - a), 0.5, 0.5) / (b - a)`.
16
21
  *
17
22
  * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
18
23
  * @param options - `a` and `b` (see {@link ArcsineParams}) and `log` (see {@link DensityOptions}).
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * darcsine(0.5); // 0.6366197723675813
28
+ * darcsine(1, { a: 0, b: 4 }); // 0.1837762984739307
29
+ * ```
30
+ *
31
+ * @category Distributions
19
32
  */
20
33
  export declare function darcsine<T extends Vectorizable>(x: T, options?: ArcsineParams & DensityOptions): VectorResult<T>;
21
- /** Distribution function of the arcsine distribution on (a, b): `pbeta((q - a) / (b - a), 0.5, 0.5)`. */
34
+ /**
35
+ * Distribution function of the arcsine distribution on (a, b): `pbeta((q - a) / (b - a), 0.5, 0.5)`.
36
+ * Not an R function. Neither base R nor extraDistr has the arcsine distribution.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * parcsine(0.25); // 0.3333333333333333
41
+ * parcsine(1, { a: 0, b: 4 }); // 0.3333333333333333
42
+ * ```
43
+ *
44
+ * @category Distributions
45
+ */
22
46
  export declare function parcsine<T extends Vectorizable>(q: T, options?: ArcsineParams & TailOptions): VectorResult<T>;
23
- /** Quantile function of the arcsine distribution on (a, b): `a + (b - a) qbeta(p, 0.5, 0.5)`. */
47
+ /**
48
+ * Quantile function of the arcsine distribution on (a, b): `a + (b - a) qbeta(p, 0.5, 0.5)`.
49
+ * Not an R function. Neither base R nor extraDistr has the arcsine distribution.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * qarcsine(0.5); // 0.5
54
+ * qarcsine(0.25, { a: 0, b: 4 }); // 0.5857864376269049
55
+ * ```
56
+ *
57
+ * @category Distributions
58
+ */
24
59
  export declare function qarcsine<T extends Vectorizable>(p: T, options?: ArcsineParams & TailOptions): VectorResult<T>;
@@ -51,22 +51,53 @@ export function qarcsine1(p, a, b, lowerTail, logP) {
51
51
  return b - (b - a) * qbeta1(p, 0.5, 0.5, !lowerTail, logP);
52
52
  }
53
53
  /**
54
- * Density of the arcsine distribution on (a, b), f(x) = 1 / (pi sqrt((x - a)(b - x))). R has no arcsine
55
- * distribution; this equals `dbeta((x - a) / (b - a), 0.5, 0.5) / (b - a)`.
54
+ * Density of the arcsine distribution on (a, b), f(x) = 1 / (pi sqrt((x - a)(b - x))).
55
+ * Not an R function. Neither base R nor extraDistr has the arcsine distribution; this equals
56
+ * `dbeta((x - a) / (b - a), 0.5, 0.5) / (b - a)`.
56
57
  *
57
58
  * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
58
59
  * @param options - `a` and `b` (see {@link ArcsineParams}) and `log` (see {@link DensityOptions}).
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * darcsine(0.5); // 0.6366197723675813
64
+ * darcsine(1, { a: 0, b: 4 }); // 0.1837762984739307
65
+ * ```
66
+ *
67
+ * @category Distributions
59
68
  */
60
69
  export function darcsine(x, options = {}) {
61
70
  const { a = 0, b = 1, log = false } = options;
62
71
  return vectorize(x, (v) => darcsine1(v, a, b, log));
63
72
  }
64
- /** Distribution function of the arcsine distribution on (a, b): `pbeta((q - a) / (b - a), 0.5, 0.5)`. */
73
+ /**
74
+ * Distribution function of the arcsine distribution on (a, b): `pbeta((q - a) / (b - a), 0.5, 0.5)`.
75
+ * Not an R function. Neither base R nor extraDistr has the arcsine distribution.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * parcsine(0.25); // 0.3333333333333333
80
+ * parcsine(1, { a: 0, b: 4 }); // 0.3333333333333333
81
+ * ```
82
+ *
83
+ * @category Distributions
84
+ */
65
85
  export function parcsine(q, options = {}) {
66
86
  const { a = 0, b = 1, lowerTail = true, logP = false } = options;
67
87
  return vectorize(q, (v) => parcsine1(v, a, b, lowerTail, logP));
68
88
  }
69
- /** Quantile function of the arcsine distribution on (a, b): `a + (b - a) qbeta(p, 0.5, 0.5)`. */
89
+ /**
90
+ * Quantile function of the arcsine distribution on (a, b): `a + (b - a) qbeta(p, 0.5, 0.5)`.
91
+ * Not an R function. Neither base R nor extraDistr has the arcsine distribution.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * qarcsine(0.5); // 0.5
96
+ * qarcsine(0.25, { a: 0, b: 4 }); // 0.5857864376269049
97
+ * ```
98
+ *
99
+ * @category Distributions
100
+ */
70
101
  export function qarcsine(p, options = {}) {
71
102
  const { a = 0, b = 1, lowerTail = true, logP = false } = options;
72
103
  return vectorize(p, (v) => qarcsine1(v, a, b, lowerTail, logP));
@@ -23,6 +23,14 @@ export declare function qbeta1(p: number, a: number, b: number, lowerTail: boole
23
23
  * @param shape2 - Second shape parameter (b).
24
24
  * @param options - `ncp` (see {@link NoncentralOption}) and `log` (see {@link DensityOptions}).
25
25
  * @returns The density (or log density).
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * dbeta(0.5, 2, 3); // 1.5
30
+ * dbeta([0.25, 0.75], 2, 3); // [1.6875, 0.5625]
31
+ * ```
32
+ *
33
+ * @category Distributions
26
34
  */
27
35
  export declare function dbeta<T extends Vectorizable>(x: T, shape1: number, shape2: number, options?: DensityOptions & NoncentralOption): VectorResult<T>;
28
36
  /**
@@ -40,6 +48,8 @@ export declare function dbeta<T extends Vectorizable>(x: T, shape1: number, shap
40
48
  * ```ts
41
49
  * pbeta(0.5, 2, 3); // 0.6875 (up to rounding)
42
50
  * ```
51
+ *
52
+ * @category Distributions
43
53
  */
44
54
  export declare function pbeta<T extends Vectorizable>(q: T, shape1: number, shape2: number, options?: TailOptions & NoncentralOption): VectorResult<T>;
45
55
  /**
@@ -58,5 +68,7 @@ export declare function pbeta<T extends Vectorizable>(q: T, shape1: number, shap
58
68
  * qbeta(0.025, 3, 7); // 0.07485463141969181
59
69
  * qbeta([0.025, 0.975], 3, 7); // [0.07485463141969181, 0.6000935737163121]
60
70
  * ```
71
+ *
72
+ * @category Distributions
61
73
  */
62
74
  export declare function qbeta<T extends Vectorizable>(p: T, shape1: number, shape2: number, options?: TailOptions & NoncentralOption): VectorResult<T>;
@@ -208,6 +208,14 @@ export function qbeta1(p, a, b, lowerTail, logP) {
208
208
  * @param shape2 - Second shape parameter (b).
209
209
  * @param options - `ncp` (see {@link NoncentralOption}) and `log` (see {@link DensityOptions}).
210
210
  * @returns The density (or log density).
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * dbeta(0.5, 2, 3); // 1.5
215
+ * dbeta([0.25, 0.75], 2, 3); // [1.6875, 0.5625]
216
+ * ```
217
+ *
218
+ * @category Distributions
211
219
  */
212
220
  export function dbeta(x, shape1, shape2, options = {}) {
213
221
  const { log = false, ncp } = options;
@@ -230,6 +238,8 @@ export function dbeta(x, shape1, shape2, options = {}) {
230
238
  * ```ts
231
239
  * pbeta(0.5, 2, 3); // 0.6875 (up to rounding)
232
240
  * ```
241
+ *
242
+ * @category Distributions
233
243
  */
234
244
  export function pbeta(q, shape1, shape2, options = {}) {
235
245
  const { lowerTail = true, logP = false, ncp } = options;
@@ -253,6 +263,8 @@ export function pbeta(q, shape1, shape2, options = {}) {
253
263
  * qbeta(0.025, 3, 7); // 0.07485463141969181
254
264
  * qbeta([0.025, 0.975], 3, 7); // [0.07485463141969181, 0.6000935737163121]
255
265
  * ```
266
+ *
267
+ * @category Distributions
256
268
  */
257
269
  export function qbeta(p, shape1, shape2, options = {}) {
258
270
  const { lowerTail = true, logP = false, ncp } = options;
@@ -11,6 +11,14 @@ export declare function qbinom1(p: number, size: number, prob: number, lowerTail
11
11
  * @param prob - Probability of success on each trial.
12
12
  * @param options - `log` (see {@link DensityOptions}).
13
13
  * @returns The probability (or log probability).
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * dbinom(3, 10, 0.5); // 0.1171875
18
+ * dbinom([0, 5], 10, 0.5); // [0.0009765625, 0.24609375]
19
+ * ```
20
+ *
21
+ * @category Distributions
14
22
  */
15
23
  export declare function dbinom<T extends Vectorizable>(x: T, size: number, prob: number, options?: DensityOptions): VectorResult<T>;
16
24
  /**
@@ -27,6 +35,8 @@ export declare function dbinom<T extends Vectorizable>(x: T, size: number, prob:
27
35
  * pbinom(3, 10, 0.5); // 0.171875
28
36
  * pbinom([3, 5], 10, 0.5); // [0.171875, 0.623046875]
29
37
  * ```
38
+ *
39
+ * @category Distributions
30
40
  */
31
41
  export declare function pbinom<T extends Vectorizable>(q: T, size: number, prob: number, options?: TailOptions): VectorResult<T>;
32
42
  /**
@@ -37,5 +47,13 @@ export declare function pbinom<T extends Vectorizable>(q: T, size: number, prob:
37
47
  * @param prob - Probability of success on each trial.
38
48
  * @param options - `lowerTail` and `logP` (see {@link TailOptions}).
39
49
  * @returns The quantile(s).
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * qbinom(0.5, 10, 0.3); // 3
54
+ * qbinom([0.025, 0.975], 10, 0.3); // [0, 6]
55
+ * ```
56
+ *
57
+ * @category Distributions
40
58
  */
41
59
  export declare function qbinom<T extends Vectorizable>(p: T, size: number, prob: number, options?: TailOptions): VectorResult<T>;
@@ -92,6 +92,14 @@ export function qbinom1(p, size, prob, lowerTail, logP) {
92
92
  * @param prob - Probability of success on each trial.
93
93
  * @param options - `log` (see {@link DensityOptions}).
94
94
  * @returns The probability (or log probability).
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * dbinom(3, 10, 0.5); // 0.1171875
99
+ * dbinom([0, 5], 10, 0.5); // [0.0009765625, 0.24609375]
100
+ * ```
101
+ *
102
+ * @category Distributions
95
103
  */
96
104
  export function dbinom(x, size, prob, options = {}) {
97
105
  const log = options.log ?? false;
@@ -111,6 +119,8 @@ export function dbinom(x, size, prob, options = {}) {
111
119
  * pbinom(3, 10, 0.5); // 0.171875
112
120
  * pbinom([3, 5], 10, 0.5); // [0.171875, 0.623046875]
113
121
  * ```
122
+ *
123
+ * @category Distributions
114
124
  */
115
125
  export function pbinom(q, size, prob, options = {}) {
116
126
  const { lowerTail = true, logP = false } = options;
@@ -124,6 +134,14 @@ export function pbinom(q, size, prob, options = {}) {
124
134
  * @param prob - Probability of success on each trial.
125
135
  * @param options - `lowerTail` and `logP` (see {@link TailOptions}).
126
136
  * @returns The quantile(s).
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * qbinom(0.5, 10, 0.3); // 3
141
+ * qbinom([0.025, 0.975], 10, 0.3); // [0, 6]
142
+ * ```
143
+ *
144
+ * @category Distributions
127
145
  */
128
146
  export function qbinom(p, size, prob, options = {}) {
129
147
  const { lowerTail = true, logP = false } = options;
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Probability that a standard bivariate normal pair (X, Y) with correlation `rho` lies in the rectangle
3
- * `lower ≤ (X, Y) ≤ upper`. Equivalent to mvtnorm's `pmvnorm(lower, upper, corr = matrix(c(1, rho, rho, 1), 2))`.
3
+ * `lower ≤ (X, Y) ≤ upper`. Equivalent to `mvtnorm::pmvnorm()` in R. The same as
4
+ * `pmvnorm(lower, upper, corr = matrix(c(1, rho, rho, 1), 2))`.
4
5
  * Bounds may be infinite. Accurate to about 1e-15 absolute.
5
6
  *
6
7
  * @param lower - Lower bounds `[a1, a2]`.
@@ -11,5 +12,7 @@
11
12
  * ```ts
12
13
  * pbvnorm([-Infinity, -Infinity], [0, 0], 0.5); // 0.3333333333333333
13
14
  * ```
15
+ *
16
+ * @category Distributions
14
17
  */
15
18
  export declare function pbvnorm(lower: readonly [number, number] | readonly number[], upper: readonly [number, number] | readonly number[], rho: number): number;
@@ -100,7 +100,8 @@ function orthant(h, k, r) {
100
100
  }
101
101
  /**
102
102
  * Probability that a standard bivariate normal pair (X, Y) with correlation `rho` lies in the rectangle
103
- * `lower ≤ (X, Y) ≤ upper`. Equivalent to mvtnorm's `pmvnorm(lower, upper, corr = matrix(c(1, rho, rho, 1), 2))`.
103
+ * `lower ≤ (X, Y) ≤ upper`. Equivalent to `mvtnorm::pmvnorm()` in R. The same as
104
+ * `pmvnorm(lower, upper, corr = matrix(c(1, rho, rho, 1), 2))`.
104
105
  * Bounds may be infinite. Accurate to about 1e-15 absolute.
105
106
  *
106
107
  * @param lower - Lower bounds `[a1, a2]`.
@@ -111,6 +112,8 @@ function orthant(h, k, r) {
111
112
  * ```ts
112
113
  * pbvnorm([-Infinity, -Infinity], [0, 0], 0.5); // 0.3333333333333333
113
114
  * ```
115
+ *
116
+ * @category Distributions
114
117
  */
115
118
  export function pbvnorm(lower, upper, rho) {
116
119
  if (lower.length !== 2 || upper.length !== 2)
@@ -14,6 +14,14 @@ export declare function qcauchy1(p: number, location: number, scale: number, low
14
14
  * @param x - Value(s) at which to evaluate: a number, `number[]` or `Float64Array`. The result has the same shape.
15
15
  * @param options - `location` and `scale` (see {@link LocationScaleParams}) and `log` (see {@link DensityOptions}).
16
16
  * @returns The density (or log density).
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * dcauchy(0); // 0.3183098861837907
21
+ * dcauchy(1, { location: 1, scale: 2 }); // 0.15915494309189535
22
+ * ```
23
+ *
24
+ * @category Distributions
17
25
  */
18
26
  export declare function dcauchy<T extends Vectorizable>(x: T, options?: LocationScaleParams & DensityOptions): VectorResult<T>;
19
27
  /**
@@ -22,6 +30,14 @@ export declare function dcauchy<T extends Vectorizable>(x: T, options?: Location
22
30
  * @param q - Quantile(s): a number, `number[]` or `Float64Array`. The result has the same shape.
23
31
  * @param options - `location` and `scale` (see {@link LocationScaleParams}), `lowerTail` and `logP` (see {@link TailOptions}).
24
32
  * @returns The probability (or log probability).
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * pcauchy(1); // 0.75
37
+ * pcauchy(3, { location: 1, scale: 2 }); // 0.75
38
+ * ```
39
+ *
40
+ * @category Distributions
25
41
  */
26
42
  export declare function pcauchy<T extends Vectorizable>(q: T, options?: LocationScaleParams & TailOptions): VectorResult<T>;
27
43
  /**
@@ -30,5 +46,13 @@ export declare function pcauchy<T extends Vectorizable>(q: T, options?: Location
30
46
  * @param p - Probability (or log probability with `logP`): a number, `number[]` or `Float64Array`. The result has the same shape.
31
47
  * @param options - `location` and `scale` (see {@link LocationScaleParams}), `lowerTail` and `logP` (see {@link TailOptions}).
32
48
  * @returns The quantile(s).
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * qcauchy(0.75); // 1.0000000000000002
53
+ * qcauchy(0.975, { scale: 2 }); // 25.41240947234939
54
+ * ```
55
+ *
56
+ * @category Distributions
33
57
  */
34
58
  export declare function qcauchy<T extends Vectorizable>(p: T, options?: LocationScaleParams & TailOptions): VectorResult<T>;