@numero-uno-jpn/rstats 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.ja.md +44 -13
  3. package/README.md +43 -11
  4. package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-3VMBBQLV.js} +2 -2
  5. package/dist/chunks/chunk-4OKAZJJG.js +3 -0
  6. package/dist/chunks/{chunk-EZAFN5CD.js → chunk-6BH65HGN.js} +1 -1
  7. package/dist/chunks/chunk-ATC4F4BX.js +2 -0
  8. package/dist/chunks/{chunk-JWBO5WVN.js → chunk-EDH53DXN.js} +2 -2
  9. package/dist/chunks/{chunk-Y5CNQ266.js → chunk-EZ2KD5NA.js} +2 -2
  10. package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-GSPOO2G3.js} +2 -2
  11. package/dist/chunks/{chunk-F5EDJFEO.js → chunk-K7AZ65H7.js} +2 -2
  12. package/dist/chunks/{chunk-YSWGDOWK.js → chunk-LEIH4U5X.js} +2 -2
  13. package/dist/chunks/{chunk-EZWBRCJL.js → chunk-OX3SBG5X.js} +1 -1
  14. package/dist/chunks/chunk-SGZQDJRR.js +2 -0
  15. package/dist/chunks/{chunk-C5XTWMGB.js → chunk-UH2N3ZQW.js} +1 -1
  16. package/dist/chunks/chunk-UV2MZYDQ.js +2 -0
  17. package/dist/chunks/{chunk-TOGXTCZO.js → chunk-VQHEOBTM.js} +2 -2
  18. package/dist/chunks/chunk-WJQZZYOI.js +2 -0
  19. package/dist/chunks/chunk-WKEFHOFR.js +2 -0
  20. package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-WXC25OPJ.js} +2 -2
  21. package/dist/chunks/{chunk-5WDJPHYY.js → chunk-XJQKSR52.js} +1 -1
  22. package/dist/data/grouping.d.ts +39 -15
  23. package/dist/data/grouping.js +21 -22
  24. package/dist/descriptive/basic.d.ts +130 -17
  25. package/dist/descriptive/basic.js +115 -14
  26. package/dist/descriptive/cov.d.ts +22 -12
  27. package/dist/descriptive/dataFrames.d.ts +39 -11
  28. package/dist/descriptive/dataFrames.js +14 -6
  29. package/dist/descriptive/factanal.d.ts +26 -6
  30. package/dist/descriptive/factanal.js +7 -3
  31. package/dist/descriptive/hist.d.ts +27 -6
  32. package/dist/descriptive/hist.js +9 -3
  33. package/dist/descriptive/missing.d.ts +13 -6
  34. package/dist/descriptive/missing.js +4 -2
  35. package/dist/descriptive/moments.d.ts +91 -13
  36. package/dist/descriptive/moments.js +66 -9
  37. package/dist/descriptive/omega.d.ts +28 -6
  38. package/dist/descriptive/omega.js +16 -4
  39. package/dist/descriptive/pivot.d.ts +22 -6
  40. package/dist/descriptive/pivot.js +7 -3
  41. package/dist/descriptive/quantile.d.ts +33 -5
  42. package/dist/descriptive/quantile.js +20 -2
  43. package/dist/descriptive/rank.d.ts +12 -2
  44. package/dist/descriptive/rank.js +2 -0
  45. package/dist/descriptive/table.d.ts +55 -7
  46. package/dist/descriptive/table.js +38 -4
  47. package/dist/descriptive.js +2 -2
  48. package/dist/distributions/arcsine.d.ts +40 -5
  49. package/dist/distributions/arcsine.js +35 -4
  50. package/dist/distributions/beta.d.ts +12 -0
  51. package/dist/distributions/beta.js +12 -0
  52. package/dist/distributions/binomial.d.ts +18 -0
  53. package/dist/distributions/binomial.js +18 -0
  54. package/dist/distributions/bvnorm.d.ts +4 -1
  55. package/dist/distributions/bvnorm.js +4 -1
  56. package/dist/distributions/cauchy.d.ts +24 -0
  57. package/dist/distributions/cauchy.js +24 -0
  58. package/dist/distributions/chisq.d.ts +18 -0
  59. package/dist/distributions/chisq.js +18 -0
  60. package/dist/distributions/exponential.d.ts +29 -1
  61. package/dist/distributions/exponential.js +24 -0
  62. package/dist/distributions/f.d.ts +18 -0
  63. package/dist/distributions/f.js +18 -0
  64. package/dist/distributions/gamma.d.ts +20 -0
  65. package/dist/distributions/gamma.js +18 -0
  66. package/dist/distributions/geometric.d.ts +24 -0
  67. package/dist/distributions/geometric.js +24 -0
  68. package/dist/distributions/hypergeometric.d.ts +24 -0
  69. package/dist/distributions/hypergeometric.js +24 -0
  70. package/dist/distributions/invgamma.d.ts +32 -4
  71. package/dist/distributions/invgamma.js +27 -3
  72. package/dist/distributions/kumaraswamy.d.ts +31 -3
  73. package/dist/distributions/kumaraswamy.js +31 -3
  74. package/dist/distributions/laplace.d.ts +36 -4
  75. package/dist/distributions/laplace.js +31 -3
  76. package/dist/distributions/logistic.d.ts +29 -1
  77. package/dist/distributions/logistic.js +24 -0
  78. package/dist/distributions/lognormal.d.ts +29 -1
  79. package/dist/distributions/lognormal.js +24 -0
  80. package/dist/distributions/multinomial.d.ts +7 -1
  81. package/dist/distributions/multinomial.js +2 -0
  82. package/dist/distributions/negbinomial.d.ts +29 -1
  83. package/dist/distributions/negbinomial.js +24 -0
  84. package/dist/distributions/normal.d.ts +11 -1
  85. package/dist/distributions/normal.js +6 -0
  86. package/dist/distributions/pareto.d.ts +36 -4
  87. package/dist/distributions/pareto.js +31 -3
  88. package/dist/distributions/poisson.d.ts +18 -0
  89. package/dist/distributions/poisson.js +18 -0
  90. package/dist/distributions/signrank.d.ts +24 -0
  91. package/dist/distributions/signrank.js +24 -0
  92. package/dist/distributions/summary.d.ts +20 -2
  93. package/dist/distributions/summary.js +4 -0
  94. package/dist/distributions/t.d.ts +18 -0
  95. package/dist/distributions/t.js +18 -0
  96. package/dist/distributions/triangular.d.ts +36 -4
  97. package/dist/distributions/triangular.js +31 -3
  98. package/dist/distributions/tukey.d.ts +15 -1
  99. package/dist/distributions/tukey.js +10 -0
  100. package/dist/distributions/uniform.d.ts +29 -1
  101. package/dist/distributions/uniform.js +24 -0
  102. package/dist/distributions/weibull.d.ts +29 -1
  103. package/dist/distributions/weibull.js +24 -0
  104. package/dist/distributions/wilcox.d.ts +24 -0
  105. package/dist/distributions/wilcox.js +24 -0
  106. package/dist/distributions.js +2 -2
  107. package/dist/entries/descriptive.d.ts +1 -1
  108. package/dist/entries/mixed.d.ts +1 -0
  109. package/dist/entries/mixed.js +2 -0
  110. package/dist/entries/numerics.d.ts +1 -1
  111. package/dist/entries/tests.js +1 -1
  112. package/dist/htest/agreement.d.ts +61 -23
  113. package/dist/htest/agreement.js +19 -9
  114. package/dist/htest/ansariTest.d.ts +8 -2
  115. package/dist/htest/aov.d.ts +43 -10
  116. package/dist/htest/aov.js +17 -3
  117. package/dist/htest/binomTest.d.ts +12 -2
  118. package/dist/htest/binomTest.js +2 -0
  119. package/dist/htest/brunnerMunzelTest.d.ts +9 -3
  120. package/dist/htest/brunnerMunzelTest.js +4 -2
  121. package/dist/htest/chisqTest.d.ts +19 -3
  122. package/dist/htest/cor.d.ts +20 -4
  123. package/dist/htest/effectSize.d.ts +70 -12
  124. package/dist/htest/effectSize.js +40 -7
  125. package/dist/htest/fisherTest.d.ts +9 -1
  126. package/dist/htest/fisherTest.js +2 -0
  127. package/dist/htest/groups.d.ts +5 -1
  128. package/dist/htest/ksTest.d.ts +20 -3
  129. package/dist/htest/leveneTest.d.ts +15 -4
  130. package/dist/htest/leveneTest.js +5 -2
  131. package/dist/htest/mantelhaenTest.d.ts +25 -3
  132. package/dist/htest/mantelhaenTest.js +15 -1
  133. package/dist/htest/mcnemarTest.d.ts +14 -4
  134. package/dist/htest/mcnemarTest.js +4 -2
  135. package/dist/htest/multipleComparisons.d.ts +173 -29
  136. package/dist/htest/multipleComparisons.js +123 -19
  137. package/dist/htest/normalityTests.d.ts +56 -9
  138. package/dist/htest/normalityTests.js +40 -6
  139. package/dist/htest/onewayTest.d.ts +32 -3
  140. package/dist/htest/onewayTest.js +10 -0
  141. package/dist/htest/pAdjust.d.ts +9 -1
  142. package/dist/htest/pAdjust.js +2 -0
  143. package/dist/htest/pairwise.d.ts +50 -5
  144. package/dist/htest/pairwise.js +25 -0
  145. package/dist/htest/poissonTest.d.ts +12 -2
  146. package/dist/htest/poissonTest.js +2 -0
  147. package/dist/htest/polycor.d.ts +29 -10
  148. package/dist/htest/power.d.ts +60 -6
  149. package/dist/htest/power.js +6 -0
  150. package/dist/htest/propTest.d.ts +13 -2
  151. package/dist/htest/propTest.js +2 -0
  152. package/dist/htest/pwr.d.ts +286 -36
  153. package/dist/htest/pwr.js +116 -15
  154. package/dist/htest/rankTests.d.ts +80 -12
  155. package/dist/htest/rankTests.js +11 -2
  156. package/dist/htest/tTest.d.ts +13 -3
  157. package/dist/htest/testFormula.js +6 -3
  158. package/dist/htest/trendTests.d.ts +29 -8
  159. package/dist/htest/trendTests.js +8 -4
  160. package/dist/htest/types.d.ts +14 -2
  161. package/dist/htest/varTest.d.ts +25 -8
  162. package/dist/htest/wilcoxTest.d.ts +10 -2
  163. package/dist/internal/dpq.d.ts +4 -0
  164. package/dist/internal/noncentral.d.ts +2 -0
  165. package/dist/internal/vectorize.d.ts +4 -0
  166. package/dist/linalg/basic.d.ts +39 -5
  167. package/dist/linalg/basic.js +15 -0
  168. package/dist/linalg/chol.d.ts +26 -5
  169. package/dist/linalg/chol.js +7 -0
  170. package/dist/linalg/eigen.d.ts +16 -7
  171. package/dist/linalg/eigen.js +6 -5
  172. package/dist/linalg/expm.d.ts +15 -5
  173. package/dist/linalg/expm.js +5 -3
  174. package/dist/linalg/kappa.d.ts +21 -1
  175. package/dist/linalg/kappa.js +16 -0
  176. package/dist/linalg/lu.d.ts +30 -6
  177. package/dist/linalg/lu.js +15 -3
  178. package/dist/linalg/matrix.d.ts +4 -0
  179. package/dist/linalg/norm.d.ts +16 -1
  180. package/dist/linalg/norm.js +9 -0
  181. package/dist/linalg/ops.d.ts +156 -35
  182. package/dist/linalg/ops.js +96 -15
  183. package/dist/linalg/qr.d.ts +87 -12
  184. package/dist/linalg/qr.js +31 -0
  185. package/dist/linalg/schur.d.ts +8 -2
  186. package/dist/linalg/schur.js +3 -1
  187. package/dist/linalg/solve.d.ts +42 -6
  188. package/dist/linalg/solve.js +22 -0
  189. package/dist/linalg/svd.d.ts +12 -2
  190. package/dist/linalg/svd.js +2 -0
  191. package/dist/linalg.js +2 -2
  192. package/dist/mixed.js +3 -0
  193. package/dist/models/anovaSequential.d.ts +26 -4
  194. package/dist/models/anovaSequential.js +3 -1
  195. package/dist/models/aovEz.d.ts +29 -6
  196. package/dist/models/aovEz.js +5 -2
  197. package/dist/models/aovStrata.d.ts +13 -3
  198. package/dist/models/aovStrata.js +5 -1
  199. package/dist/models/carAnova.d.ts +9 -3
  200. package/dist/models/carAnova.js +4 -2
  201. package/dist/models/coxph.d.ts +33 -7
  202. package/dist/models/coxph.js +8 -3
  203. package/dist/models/formula.d.ts +26 -1
  204. package/dist/models/formula.js +125 -9
  205. package/dist/models/glm.d.ts +128 -21
  206. package/dist/models/glm.js +71 -14
  207. package/dist/models/glmAnova.d.ts +30 -5
  208. package/dist/models/glmAnova.js +15 -2
  209. package/dist/models/glmConfint.d.ts +16 -2
  210. package/dist/models/glmConfint.js +9 -1
  211. package/dist/models/glmFamily.d.ts +27 -5
  212. package/dist/models/lm.d.ts +77 -19
  213. package/dist/models/lm.js +22 -4
  214. package/dist/models/lmer.d.ts +162 -0
  215. package/dist/models/lmer.js +457 -0
  216. package/dist/models/mauchly.d.ts +20 -5
  217. package/dist/models/mauchly.js +7 -3
  218. package/dist/models/mixedDeviance.d.ts +44 -0
  219. package/dist/models/mixedDeviance.js +872 -0
  220. package/dist/models/mixedStructure.d.ts +82 -0
  221. package/dist/models/mixedStructure.js +309 -0
  222. package/dist/models/modelFrame.d.ts +17 -2
  223. package/dist/models/modelFrame.js +36 -21
  224. package/dist/models/modelMatrix.d.ts +33 -8
  225. package/dist/models/modelMatrix.js +21 -5
  226. package/dist/models/survival.d.ts +41 -9
  227. package/dist/models/survival.js +10 -4
  228. package/dist/numerics/deriv.d.ts +21 -6
  229. package/dist/numerics/deriv.js +16 -5
  230. package/dist/numerics/integrate.d.ts +37 -7
  231. package/dist/numerics/integrate.js +8 -2
  232. package/dist/numerics/interp.d.ts +63 -12
  233. package/dist/numerics/interp.js +30 -6
  234. package/dist/numerics/ode.d.ts +15 -5
  235. package/dist/numerics/ode.js +5 -3
  236. package/dist/numerics.js +2 -2
  237. package/dist/optim/optim.d.ts +32 -8
  238. package/dist/optim/optim.js +8 -4
  239. package/dist/random/beta.d.ts +8 -0
  240. package/dist/random/beta.js +8 -0
  241. package/dist/random/binomial.d.ts +16 -0
  242. package/dist/random/binomial.js +16 -0
  243. package/dist/random/continuous.d.ts +51 -0
  244. package/dist/random/continuous.js +51 -0
  245. package/dist/random/extra.d.ts +66 -6
  246. package/dist/random/extra.js +66 -6
  247. package/dist/random/gamma.d.ts +33 -0
  248. package/dist/random/gamma.js +33 -0
  249. package/dist/random/hyper.d.ts +8 -0
  250. package/dist/random/hyper.js +8 -0
  251. package/dist/random/poisson.d.ts +25 -0
  252. package/dist/random/poisson.js +25 -0
  253. package/dist/random/r2dtable.d.ts +2 -0
  254. package/dist/random/r2dtable.js +2 -0
  255. package/dist/random/rank.d.ts +16 -0
  256. package/dist/random/rank.js +16 -0
  257. package/dist/random/rng.d.ts +49 -6
  258. package/dist/random/rng.js +29 -2
  259. package/dist/random/sample.d.ts +10 -2
  260. package/dist/random/sample.js +5 -1
  261. package/dist/random/streams.d.ts +13 -0
  262. package/dist/random/streams.js +13 -0
  263. package/dist/rstats.js +14 -14
  264. package/dist/special/besselIK.d.ts +11 -3
  265. package/dist/special/besselIK.js +6 -2
  266. package/dist/special/besselJY.d.ts +6 -2
  267. package/dist/special/besselJY.js +6 -2
  268. package/dist/special/beta.d.ts +16 -2
  269. package/dist/special/beta.js +16 -2
  270. package/dist/special/choose.d.ts +13 -5
  271. package/dist/special/choose.js +13 -5
  272. package/dist/special/erf.d.ts +8 -3
  273. package/dist/special/erf.js +8 -3
  274. package/dist/special/extra.d.ts +30 -10
  275. package/dist/special/extra.js +25 -9
  276. package/dist/special/gamma.d.ts +18 -2
  277. package/dist/special/gamma.js +18 -2
  278. package/dist/special/log1p.d.ts +16 -7
  279. package/dist/special/log1p.js +16 -7
  280. package/dist/special/psigamma.d.ts +9 -3
  281. package/dist/special/psigamma.js +9 -3
  282. package/dist/special/rCompatible.d.ts +5 -1
  283. package/dist/special.js +2 -2
  284. package/dist/tests.js +12 -12
  285. package/llms.txt +13 -3
  286. package/package.json +5 -1
  287. package/dist/chunks/chunk-7GQMKH3Z.js +0 -2
  288. package/dist/chunks/chunk-AHHS6AC4.js +0 -3
  289. package/dist/chunks/chunk-ALM3VHFP.js +0 -2
@@ -1,6 +1,10 @@
1
1
  import type { DataFrame } from "../models/modelFrame.js";
2
2
  import { type DataValue } from "./dataFrames.js";
3
- /** Options for {@link pivotLonger} (tidyr's arguments in camelCase). */
3
+ /**
4
+ * Options for {@link pivotLonger} (tidyr's arguments in camelCase).
5
+ *
6
+ * @category Data frames
7
+ */
4
8
  export interface PivotLongerOptions {
5
9
  /** The columns to pivot: their names, in this order, or a test of the name (selecting in the data's order). */
6
10
  cols: readonly string[] | ((name: string) => boolean);
@@ -29,9 +33,17 @@ export interface PivotLongerOptions {
29
33
  /** Called with each of tidyr's warnings, once per distinct warning, in order. Default: the warnings are dropped. */
30
34
  onWarning?: (message: string) => void;
31
35
  }
32
- /** A summary of the values of one cell (in data order), for `valuesFn` of {@link pivotWider}. */
36
+ /**
37
+ * A summary of the values of one cell (in data order), for `valuesFn` of {@link pivotWider}.
38
+ *
39
+ * @category Data frames
40
+ */
33
41
  export type PivotSummary = (values: DataValue[]) => DataValue;
34
- /** Options for {@link pivotWider} (tidyr's arguments in camelCase). */
42
+ /**
43
+ * Options for {@link pivotWider} (tidyr's arguments in camelCase).
44
+ *
45
+ * @category Data frames
46
+ */
35
47
  export interface PivotWiderOptions {
36
48
  /** The column (or columns) whose values name the new columns. Default `"name"`. */
37
49
  namesFrom?: string | readonly string[];
@@ -59,8 +71,8 @@ export interface PivotWiderOptions {
59
71
  valuesFn?: PivotSummary | Readonly<Record<string, PivotSummary>>;
60
72
  }
61
73
  /**
62
- * Reshapes a data frame from wide to long: the selected columns become rows. Equivalent to tidyr's `pivot_longer()`:
63
- * the result has the columns not selected, a column per part of the selected names (`namesTo`), and the value
74
+ * Reshapes a data frame from wide to long: the selected columns become rows. Equivalent to `tidyr::pivot_longer()` in
75
+ * R. The result has the columns not selected, a column per part of the selected names (`namesTo`), and the value
64
76
  * column (`valuesTo`), or with `".value"` in `namesTo` one value column per value of that part. The values of the
65
77
  * selected columns are combined into one type: numbers with booleans give numbers; strings with either are an error.
66
78
  *
@@ -70,11 +82,13 @@ export interface PivotWiderOptions {
70
82
  * pivotLonger(wide, { cols: ["t1", "t2"], namesTo: "time", valuesTo: "score" });
71
83
  * // { id: ["s1", "s1", "s2", "s2"], time: ["t1", "t2", "t1", "t2"], score: [5.1, 6.3, 4.8, 7.2] }
72
84
  * ```
85
+ *
86
+ * @category Data frames
73
87
  */
74
88
  export declare function pivotLonger(data: DataFrame, options: PivotLongerOptions): DataFrame;
75
89
  /**
76
90
  * Reshapes a data frame from long to wide: the values of `namesFrom` become columns, filled from `valuesFrom`.
77
- * Equivalent to tidyr's `pivot_wider()`: one row per combination of the id columns (in order of first appearance),
91
+ * Equivalent to `tidyr::pivot_wider()` in R. One row per combination of the id columns (in order of first appearance),
78
92
  * the new columns in order of first appearance of their names (unless `namesSort`). A cell that no row fills is
79
93
  * `valuesFill` (default missing). A cell that several rows fill is an error unless `valuesFn` summarises the values
80
94
  * (tidyr makes a list column there, which a data frame here cannot hold).
@@ -85,5 +99,7 @@ export declare function pivotLonger(data: DataFrame, options: PivotLongerOptions
85
99
  * pivotWider(long, { namesFrom: "time", valuesFrom: "score" });
86
100
  * // { id: ["s1", "s2"], t1: [5.1, 4.8], t2: [6.3, null] }
87
101
  * ```
102
+ *
103
+ * @category Data frames
88
104
  */
89
105
  export declare function pivotWider(data: DataFrame, options?: PivotWiderOptions): DataFrame;
@@ -106,8 +106,8 @@ function nameParts(names, namesTo, options, warnings) {
106
106
  : captures(names, namesPattern, namesTo.length);
107
107
  }
108
108
  /**
109
- * Reshapes a data frame from wide to long: the selected columns become rows. Equivalent to tidyr's `pivot_longer()`:
110
- * the result has the columns not selected, a column per part of the selected names (`namesTo`), and the value
109
+ * Reshapes a data frame from wide to long: the selected columns become rows. Equivalent to `tidyr::pivot_longer()` in
110
+ * R. The result has the columns not selected, a column per part of the selected names (`namesTo`), and the value
111
111
  * column (`valuesTo`), or with `".value"` in `namesTo` one value column per value of that part. The values of the
112
112
  * selected columns are combined into one type: numbers with booleans give numbers; strings with either are an error.
113
113
  *
@@ -117,6 +117,8 @@ function nameParts(names, namesTo, options, warnings) {
117
117
  * pivotLonger(wide, { cols: ["t1", "t2"], namesTo: "time", valuesTo: "score" });
118
118
  * // { id: ["s1", "s1", "s2", "s2"], time: ["t1", "t2", "t1", "t2"], score: [5.1, 6.3, 4.8, 7.2] }
119
119
  * ```
120
+ *
121
+ * @category Data frames
120
122
  */
121
123
  export function pivotLonger(data, options) {
122
124
  const n = rowCount(data);
@@ -259,7 +261,7 @@ function perColumn(option, isSingle, name) {
259
261
  }
260
262
  /**
261
263
  * Reshapes a data frame from long to wide: the values of `namesFrom` become columns, filled from `valuesFrom`.
262
- * Equivalent to tidyr's `pivot_wider()`: one row per combination of the id columns (in order of first appearance),
264
+ * Equivalent to `tidyr::pivot_wider()` in R. One row per combination of the id columns (in order of first appearance),
263
265
  * the new columns in order of first appearance of their names (unless `namesSort`). A cell that no row fills is
264
266
  * `valuesFill` (default missing). A cell that several rows fill is an error unless `valuesFn` summarises the values
265
267
  * (tidyr makes a list column there, which a data frame here cannot hold).
@@ -270,6 +272,8 @@ function perColumn(option, isSingle, name) {
270
272
  * pivotWider(long, { namesFrom: "time", valuesFrom: "score" });
271
273
  * // { id: ["s1", "s2"], t1: [5.1, 4.8], t2: [6.3, null] }
272
274
  * ```
275
+ *
276
+ * @category Data frames
273
277
  */
274
278
  export function pivotWider(data, options = {}) {
275
279
  const n = rowCount(data);
@@ -1,12 +1,16 @@
1
1
  import { type NaRmOptions } from "./basic.js";
2
2
  import type { Sample } from "../htest/types.js";
3
- /** Options for {@link quantile}. */
3
+ /**
4
+ * Options for {@link quantile}.
5
+ *
6
+ * @category Descriptive statistics
7
+ */
4
8
  export interface QuantileOptions extends NaRmOptions {
5
9
  /** Hyndman and Fan's definition, 1 to 9. Default `7`. */
6
10
  type?: number;
7
11
  }
8
12
  /**
9
- * Sample quantiles. Equivalent to R's `quantile()` (with `names = FALSE`).
13
+ * Sample quantiles. Equivalent to R's `quantile()`. Without names (R's `names = FALSE`).
10
14
  *
11
15
  * @param x The data.
12
16
  * @param probs Probabilities in [0, 1]. Default `[0, 0.25, 0.5, 0.75, 1]`. A single number gives a single number.
@@ -17,17 +21,39 @@ export interface QuantileOptions extends NaRmOptions {
17
21
  * quantile([1, 2, 3, 4, 5, 6], 0.25); // 2.25 (type 7)
18
22
  * quantile([1, 2, 3, 4, 5, 6], 0.25, { type: 9 }); // 1.9375 (jStat's quantiles)
19
23
  * ```
24
+ *
25
+ * @category Descriptive statistics
20
26
  */
21
27
  export declare function quantile(x: Sample, probs: number, options?: QuantileOptions): number;
22
28
  export declare function quantile(x: Sample, probs?: readonly number[], options?: QuantileOptions): number[];
23
- /** Interquartile range, the difference of the 0.75 and 0.25 quantiles. Equivalent to R's `IQR()`. */
29
+ /**
30
+ * Interquartile range, the difference of the 0.75 and 0.25 quantiles. Equivalent to R's `IQR()`.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * IQR([1, 2, 3, 4, 5, 6]); // 2.5
35
+ * ```
36
+ *
37
+ * @category Descriptive statistics
38
+ */
24
39
  export declare function IQR(x: Sample, options?: QuantileOptions): number;
25
40
  /**
26
- * Tukey's five-number summary (minimum, lower hinge, median, upper hinge, maximum). Equivalent to R's `fivenum()`;
41
+ * Tukey's five-number summary (minimum, lower hinge, median, upper hinge, maximum). Equivalent to R's `fivenum()`.
27
42
  * `NaN` values are dropped.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * fivenum([1, 2, 3, 4, 5, 6]); // [1, 2, 3.5, 5, 6]
47
+ * ```
48
+ *
49
+ * @category Descriptive statistics
28
50
  */
29
51
  export declare function fivenum(x: Sample): [number, number, number, number, number];
30
- /** Options for {@link mad}. */
52
+ /**
53
+ * Options for {@link mad}.
54
+ *
55
+ * @category Descriptive statistics
56
+ */
31
57
  export interface MadOptions extends NaRmOptions {
32
58
  /** Centre. Default: the median. */
33
59
  center?: number;
@@ -46,5 +72,7 @@ export interface MadOptions extends NaRmOptions {
46
72
  * mad([1, 2, 3, 4, 100]); // 1.4826
47
73
  * mad([1, 2, 3, 4, 100], { constant: 1 }); // 1 (jStat's meddev)
48
74
  * ```
75
+ *
76
+ * @category Descriptive statistics
49
77
  */
50
78
  export declare function mad(x: Sample, options?: MadOptions): number;
@@ -81,14 +81,30 @@ export function quantile(x, probs = [0, 0.25, 0.5, 0.75, 1], options = {}) {
81
81
  });
82
82
  return typeof probs === "number" ? out[0] : out;
83
83
  }
84
- /** Interquartile range, the difference of the 0.75 and 0.25 quantiles. Equivalent to R's `IQR()`. */
84
+ /**
85
+ * Interquartile range, the difference of the 0.75 and 0.25 quantiles. Equivalent to R's `IQR()`.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * IQR([1, 2, 3, 4, 5, 6]); // 2.5
90
+ * ```
91
+ *
92
+ * @category Descriptive statistics
93
+ */
85
94
  export function IQR(x, options = {}) {
86
95
  const [a, b] = quantile(x, [0.25, 0.75], options);
87
96
  return b - a;
88
97
  }
89
98
  /**
90
- * Tukey's five-number summary (minimum, lower hinge, median, upper hinge, maximum). Equivalent to R's `fivenum()`;
99
+ * Tukey's five-number summary (minimum, lower hinge, median, upper hinge, maximum). Equivalent to R's `fivenum()`.
91
100
  * `NaN` values are dropped.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * fivenum([1, 2, 3, 4, 5, 6]); // [1, 2, 3.5, 5, 6]
105
+ * ```
106
+ *
107
+ * @category Descriptive statistics
92
108
  */
93
109
  export function fivenum(x) {
94
110
  const s = Array.from(x)
@@ -109,6 +125,8 @@ export function fivenum(x) {
109
125
  * mad([1, 2, 3, 4, 100]); // 1.4826
110
126
  * mad([1, 2, 3, 4, 100], { constant: 1 }); // 1 (jStat's meddev)
111
127
  * ```
128
+ *
129
+ * @category Descriptive statistics
112
130
  */
113
131
  export function mad(x, options = {}) {
114
132
  const xs = values(x, options.naRm);
@@ -1,7 +1,15 @@
1
1
  import type { Sample } from "../htest/types.js";
2
- /** How ties are ranked, as R's `ties.method`. */
2
+ /**
3
+ * How ties are ranked, as R's `ties.method`.
4
+ *
5
+ * @category Descriptive statistics
6
+ */
3
7
  export type TiesMethod = "average" | "first" | "last" | "random" | "max" | "min";
4
- /** Options for {@link rank}. */
8
+ /**
9
+ * Options for {@link rank}.
10
+ *
11
+ * @category Descriptive statistics
12
+ */
5
13
  export interface RankOptions {
6
14
  /** Ranks of tied values. Default `"average"`. */
7
15
  tiesMethod?: TiesMethod;
@@ -19,5 +27,7 @@ export interface RankOptions {
19
27
  * rank([10, 20, 20, 30]); // [1, 2.5, 2.5, 4]
20
28
  * rank([10, 20, 20, 30], { tiesMethod: "min" }); // [1, 2, 2, 4]
21
29
  * ```
30
+ *
31
+ * @category Descriptive statistics
22
32
  */
23
33
  export declare function rank(x: Sample, options?: RankOptions): number[];
@@ -45,6 +45,8 @@ function rankValues(x, method) {
45
45
  * rank([10, 20, 20, 30]); // [1, 2.5, 2.5, 4]
46
46
  * rank([10, 20, 20, 30], { tiesMethod: "min" }); // [1, 2, 2, 4]
47
47
  * ```
48
+ *
49
+ * @category Descriptive statistics
48
50
  */
49
51
  export function rank(x, options = {}) {
50
52
  const method = options.tiesMethod ?? "average";
@@ -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.12.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{l as fe,m as me,n as he}from"./chunks/chunk-SGZQDJRR.js";import"./chunks/chunk-EZ2KD5NA.js";import{A as Re,B as Fe,C as je,D as Se,E as Te,F as _e,a as q,b as _,c as V,d as v,e as H,f as pe,g as ge,j as de,k as ye,l as z,m as we,n as be,o as Ne,p as Ee,q as Ae,r as I,s as R,t as j,u as xe,v as Me,w as $e,x as Oe,y as ke,z as ve}from"./chunks/chunk-WXC25OPJ.js";import{a as K,b as Ie,c as Ce,d as Le,e as Pe,f as Ue}from"./chunks/chunk-UH2N3ZQW.js";import"./chunks/chunk-XJQKSR52.js";import"./chunks/chunk-GSPOO2G3.js";import"./chunks/chunk-EDH53DXN.js";import"./chunks/chunk-OX3SBG5X.js";import{b as S,c as J,g as T,h as X}from"./chunks/chunk-4OKAZJJG.js";import{a as G}from"./chunks/chunk-WKEFHOFR.js";var B=4*Number.EPSILON,qe={4:[0,1],5:[.5,.5],6:[0,0],8:[1/3,1/3],9:[3/8,3/8]};function Ve(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),d=o(Math.ceil(a));if(a>g&&d!==m){let b=a-g;return(1-b)*m+b*d}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]=qe[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),f=o(i+1);return l===1?f:l>0&&l<1&&s!==f?(1-l)*s+l*f: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=z(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 f=l.map(a=>Number.isNaN(a)||i.length===0?NaN:Ve(i,Math.min(Math.max(a,0),1),r));return typeof n=="number"?f[0]:f}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 Be(e,n={}){let t=z(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)),f=s.length;if((i||l)&&f%2===0){if(i&&l)throw new RangeError("'low' and 'high' cannot be both TRUE");let a=f/2+(l?1:0),g=s.sort((m,d)=>m-d);return o*g[a-1]}return o*R(s)}var Y=e=>e===null||typeof e=="number"&&Number.isNaN(e),ee=e=>Array.isArray(e)||ArrayBuffer.isView(e);function We(e){if(ee(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 ne(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(We),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=>!Y(l[i])))}function Ze(e){if(ee(e))return Array.from(e).filter(r=>!Y(r));let n=ne(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 te(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,f=1/0,a=-1/0;for(let w of t)w<f&&(f=w),w>a&&(a=w);let g=a-f,m,d;if(g===0&&a===0)m=1,d=!0;else{m=Math.max(Math.abs(f),Math.abs(a));let M=(1+(s>=1.5*l+.5?1/(1+l):1.5/(1+s)))*Math.max(1,r)*Number.EPSILON;d=g<m*M*3}d?(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-f/r));let b=2**-20*De;m<b?m=b:m>Number.MAX_VALUE/1.25&&(m=Number.MAX_VALUE/1.25);let y=10**Math.floor(Math.log10(m)),x=[[2*y,l],[5*y,s],[10*y,l]],N=y;for(let[w,M]of x)if(w-m<M*(m-N))N=w;else break;let h=1e-10,u=Math.floor(f/N+h);for(;u*N>f+h*N;)u--;for(;!Number.isFinite(u*N);)u++;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-u);if(p<o){let w=o-p,M=Math.floor(w/2),k=w%2;f===0&&u===0&&a!==0?c+=w:a===0&&c===0&&f!==0?u-=w:u>=0?(c+=M,u-=M+k):(u-=M,c+=M+k),p=o}let E=u*N<f?u*N:f,A=c*N>a?c*N:a;if(p<=0)return[E];let $;if(Number.isFinite(A-E))$=K(E,A,p+1);else{let w=A/p-E/p;$=Array.from({length:p+1},(M,k)=>E+k*w),$[p]=A}let O=A/p-E/p;return $.map(w=>Math.abs(w)<1e-14*O?0:w)}var De=22250738585072014e-324;function Qe(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function Je(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*I(e)*t**-.3333333333333333;return l>0?Math.max(1,Math.ceil(i/l)):1}case"fd":case"freedman-diaconis":{let l=e.map(Qe),s=2*W(l);for(let f=1/8;s===0&&f>=1/512;f/=2){let[a,g]=C(l,[f,1-f]);s=(g-a)/(1-2*f)}return s===0&&(s=3.5*I(e)),s>0?Math.ceil(i/s*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function Xe(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 Ge(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,u)=>h-u);else{i=!0;let h=typeof l=="string"?Je(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[u,c]=j(t);s=te([u,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 f=s.length,[a,g]=r>0?j(t):[0,0],m=1e-7*Xe(s,g-a),d=s.map((h,u)=>o?u===0&&i?h-m:h+m:u<f-1?h-m:i?h+m:h-m),b=new Array(Math.max(0,f-1)).fill(0),y=0;for(let h of t){let u=He(h,d,o,i);u>=0&&(b[u]++,y++)}if(y<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let x=b.map((h,u)=>h/(r*(s[u+1]-s[u]))),N=b.map((h,u)=>.5*(s[u+1]+s[u]));return{breaks:s,counts:b,density:x,mids:N}}function He(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,f=o;for(;s<f;){let a=s+f>>1;e<=n[a]?f=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 Ke(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 L=e=>e===null||typeof e=="number"&&Number.isNaN(e),Ye=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?G(e,n):Number(e)-Number(n),en=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?S(e):e>0?"Inf":"-Inf";function nn(e,n){let t=Array.from(n,s=>s===0?0:s),r=new Set(t.filter(s=>!L(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=>!L(s)))].sort(Ye),l=new Map(i.map((s,f)=>[s,f]));return{levels:i,codes:t.map(s=>L(s)?-1:l.get(s))}}var F=e=>Array.isArray(e)||e instanceof Float64Array;function le(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)=>nn(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,f=1;for(let a of r){let g=a.codes[l];if(g<0){s=-1;break}s+=g*f,f*=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 ae(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 ie=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function tn(e,n,t){let r=Array.from(e),o=le(n),i=Z(o,ie(o.length,"index"),r.length),l=D(i).map(a=>a.length===0?null:{value:t(a.map(g=>r[g]))}),f=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:f}}function rn(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 on(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 sn(e,n,t={}){let r=t.sep??".",o=le(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?on(e):e.length,s=Z(o,ie(o.length,"f"),l),f=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 d=ae(s,m).map(en).join(r);a.set(d,i?rn(e,g):g.map(b=>f[b]))}),a}function re(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 oe(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 ln(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(),{rhs:o}=J(`~ ${e.slice(t+1)}`),i=/^[A-Za-z.][A-Za-z0-9._]*$/,l;if(r!=="."){let a=/^cbind\s*\((.*)\)$/s.exec(r);if(l=a===null?[r]:a[1].split(",").map(g=>g.trim()),l.some(g=>!i.test(g)||g==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}else if(T(o,[]).length<T(o,["."]).length)throw new SyntaxError("invalid formula: '.' cannot be on both sides");let s=l===void 0?[]:n.filter(a=>!l.includes(a)),f=T(o,s);return X(o,()=>0,s),{values:l??n.filter(a=>!f.includes(a)),groups:f}}function se(e,n,t,r,o,i){let l=r[0]?.length??n[0]?.length??0;e.forEach((m,d)=>{if(n[d].length!==l)throw new RangeError(`variable lengths differ (found for '${m}')`)});let s=Z(r,t,l),f=D(s).map((m,d)=>({cell:d,rows:m.filter(o)})).filter(m=>m.rows.length>0),a={},g=f.map(m=>ae(s,m.cell));return t.forEach((m,d)=>{a[m]=g.map(b=>b[d])}),e.forEach((m,d)=>{let b=n[d],x=f.map(h=>i(h.rows.map(u=>b[u]))).map(h=>{if(typeof h=="number")return{names:void 0,values:[h]};if(Array.isArray(h))return{names:void 0,values:[...h]};let u=h;return{names:Object.keys(u),values:Object.values(u)}}),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 u=x[0].names?.[h]??String(h+1);a[`${m}.${u}`]=x.map(c=>c.values[h])}}),a}function an(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:f,groups:a}=ln(e,Object.keys(s)),g=y=>Object.prototype.hasOwnProperty.call(s,y),m=f.map(y=>re(y,g(y)?s[y]:void 0)),d=a.map(y=>oe(s,y));return se(f,m,a,d,y=>m.every(x=>!Number.isNaN(x[y]))&&d.every(x=>!L(x[y])),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=>re(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=>oe(n,s));return se(r,o,i,l,()=>!0,t)}var P=e=>typeof e=="string"?[e]:[...e];function ue(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new Error(`Column \`${t}\` doesn't exist.`)}function cn(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 un(e,n){let t=null;for(let r of n){let o=cn(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,f)=>l===null?null:l[f+1]??null)})}function mn(e,n,t,r){let o=new RegExp(n,"g"),i=[],l=[],s=e.map((a,g)=>{let m=[],d=0;for(let b of a.matchAll(o))b[0].length!==0&&(m.push(a.slice(d,b.index)),d=b.index+b[0].length);return m.push(a.slice(d)),m.length>t&&i.push(g+1),m.length<t&&l.push(g+1),Array.from({length:t},(b,y)=>m[y]??null)}),f=a=>`${a.length} rows [${a.join(", ")}]`;return i.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${f(i)}.`),l.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${f(l)}.`),s}function hn(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?mn(e,o,n.length,r):fn(e,i,n.length)}function pn(e,n){let t=q(e),r=Object.keys(e),o=typeof n.cols=="function"?r.filter(n.cols):[...new Set(n.cols)];if(ue(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=[],f=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),a=o.map(u=>f===null?u:u.replace(f,"")),g=hn(a,i,n,s),m=[],d=[];if(l<0)m.push(...g),d.push({name:n.valuesTo??"value",sources:[...o]});else{let u=new Map,c=new Map;g.forEach((p,E)=>{let A=p.filter((k,U)=>U!==l),$=JSON.stringify(A),O=u.get($);if(O===void 0){O=m.length,u.set($,O),m.push(A);for(let k of d)k.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),d.push(M)),M.sources[O]!==null)throw new Error(`the names give the value column '${w}' twice for one key`);M.sources[O]=o[E]})}let b=d.map(u=>un(e,u.sources.filter(c=>c!==null))),y=[];if(n.colsVary==="slowest")for(let u=0;u<m.length;u++)for(let c=0;c<t;c++)y.push([c,u]);else for(let u=0;u<t;u++)for(let c=0;c<m.length;c++)y.push([u,c]);let x=(u,c,p)=>{let E=u.sources[p];return E==null?null:e[E][c]};n.valuesDropNa===!0&&(y=y.filter(([u,c])=>d.some(p=>!_(x(p,u,c)))));let N={},h=y.map(([u])=>u);for(let u of r)o.includes(u)||v(N,u,V(e[u],h));if(i.forEach((u,c)=>{if(c===l)return;let p=n.namesTransform?.[u],E=A=>{let $=m[A][c<l||l<0?c:c-1];return $===null||p===void 0?$:p($)};v(N,u,y.map(([,A])=>E(A)))}),d.forEach((u,c)=>{let p=b[c]==="double";if(p&&u.sources.every(E=>E!==null&&e[E]instanceof Float64Array))v(N,u.name,Float64Array.from(y,([E,A])=>x(u,E,A)));else{let E=y.map(([A,$])=>{let O=x(u,A,$);return p&&typeof O=="boolean"?Number(O):O});v(N,u.name,E)}}),n.onWarning!==void 0)for(let u of new Set(s))n.onWarning(u);return N}var gn=e=>_(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function ce(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(i,l)=>{let s=JSON.stringify(e.map(a=>gn(a[l]))),f=t.get(s);return f===void 0&&(f=r.length,t.set(s,f),r.push(l)),f}),firsts:r}}function dn(e){return _(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);ue(e,[...i,...r,...o]);let l=n.namesPrefix??"",s=n.namesSep??"_",f=ce(i.map(c=>e[c]),t),a=ce(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=H(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=>dn(e[p][c])).join(s)),d=a.firsts.length,b=Array.from({length:f.firsts.length*d},()=>[]);for(let c=0;c<t;c++)b[f.codes[c]*d+a.codes[c]].push(c);let y=c=>typeof c=="function",x=c=>typeof c!="object"||c===null,N=(c,p)=>{let E=e[c],A=Q(n.valuesFn,y,c),$=Q(n.valuesFill,x,c)??null,O=f.firsts.map((w,M)=>{let k=b[M*d+p];return k.length===0?$:A!==void 0?A(k.map(U=>E[U])):E[k[0]]});return E instanceof Float64Array&&O.every(w=>w===null||typeof w=="number")?Float64Array.from(O,w=>w===null?NaN:w):O};for(let c of o)if(Q(n.valuesFn,y,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)v(h,c,V(e[c],f.firsts));let u=(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)v(h,u(p,c),N(p,c));else for(let c of o)for(let p of g)v(h,u(c,p),N(c,p));return h}export{W as IQR,an as aggregate,ne as completeCases,he as cor,me as cov,$e as cummax,Oe as cummin,Me as cumprod,xe as cumsum,Pe as cut,Te as cv,ke as diff,Ke as ecdf,Ue as findInterval,ze as fivenum,de as fromRows,Fe as geometricMean,Ge as hist,Re as kurtosis,Be as mad,Ne as mean,Se as meanAD,R as median,pe as merge,je as modes,Ze as naOmit,pn as pivotLonger,yn as pivotWider,te as pretty,be as prod,C as quantile,j as range,fe as rank,_e as scale,I as sd,ve as skewness,sn as split,ge as subset,we as sum,Ce as table,Ie as tabulate,tn as tapply,ye as toRows,Le as unique,Ae as variance,Ee 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>;