@numero-uno-jpn/rstats 0.10.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 (280) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.ja.md +13 -9
  3. package/README.md +13 -8
  4. package/dist/chunks/{chunk-QJJWGNJP.js → chunk-2X7JYQBI.js} +2 -2
  5. package/dist/chunks/{chunk-O6PT7IVU.js → chunk-36GVER3O.js} +2 -2
  6. package/dist/chunks/{chunk-EWC6I75B.js → chunk-3WUXRSM6.js} +1 -1
  7. package/dist/chunks/{chunk-4NM37MGA.js → chunk-6I6QKTFK.js} +2 -2
  8. package/dist/chunks/{chunk-2XKG3DX4.js → chunk-ETOEZTGL.js} +1 -1
  9. package/dist/chunks/{chunk-IT354SHV.js → chunk-FVPDVRJQ.js} +2 -2
  10. package/dist/chunks/{chunk-QULPY6YM.js → chunk-GG4BJMJW.js} +1 -1
  11. package/dist/chunks/{chunk-7HPVUVZB.js → chunk-HITD7CX6.js} +1 -1
  12. package/dist/chunks/{chunk-LIMZKONM.js → chunk-KK4GE65D.js} +2 -2
  13. package/dist/chunks/chunk-LAUYSGV4.js +3 -0
  14. package/dist/chunks/chunk-M6GDXKKS.js +2 -0
  15. package/dist/chunks/{chunk-QFULZNHL.js → chunk-PHHUHR7T.js} +1 -1
  16. package/dist/chunks/{chunk-ENL43FNO.js → chunk-WQPFDDIY.js} +2 -2
  17. package/dist/chunks/chunk-X2AWQSVS.js +2 -0
  18. package/dist/chunks/{chunk-ZRIM4R4A.js → chunk-ZRJQD7VS.js} +2 -2
  19. package/dist/data/grouping.d.ts +100 -0
  20. package/dist/data/grouping.js +264 -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 +138 -0
  25. package/dist/descriptive/dataFrames.js +400 -0
  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 +42 -0
  31. package/dist/descriptive/missing.js +52 -0
  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 +105 -0
  37. package/dist/descriptive/pivot.js +347 -0
  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 +5 -1
  105. package/dist/entries/descriptive.js +4 -0
  106. package/dist/entries/numerics.d.ts +1 -1
  107. package/dist/entries/tests.js +1 -1
  108. package/dist/htest/agreement.d.ts +61 -23
  109. package/dist/htest/agreement.js +19 -9
  110. package/dist/htest/ansariTest.d.ts +19 -1
  111. package/dist/htest/ansariTest.js +5 -17
  112. package/dist/htest/aov.d.ts +43 -10
  113. package/dist/htest/aov.js +17 -3
  114. package/dist/htest/binomTest.d.ts +12 -2
  115. package/dist/htest/binomTest.js +2 -0
  116. package/dist/htest/brunnerMunzelTest.d.ts +9 -3
  117. package/dist/htest/brunnerMunzelTest.js +4 -2
  118. package/dist/htest/chisqTest.d.ts +19 -3
  119. package/dist/htest/cor.d.ts +31 -3
  120. package/dist/htest/cor.js +9 -27
  121. package/dist/htest/effectSize.d.ts +70 -12
  122. package/dist/htest/effectSize.js +40 -7
  123. package/dist/htest/fisherTest.d.ts +9 -1
  124. package/dist/htest/fisherTest.js +2 -0
  125. package/dist/htest/groups.d.ts +5 -1
  126. package/dist/htest/ksTest.d.ts +32 -2
  127. package/dist/htest/ksTest.js +5 -8
  128. package/dist/htest/leveneTest.d.ts +15 -4
  129. package/dist/htest/leveneTest.js +5 -2
  130. package/dist/htest/mantelhaenTest.d.ts +25 -3
  131. package/dist/htest/mantelhaenTest.js +15 -1
  132. package/dist/htest/mcnemarTest.d.ts +14 -4
  133. package/dist/htest/mcnemarTest.js +4 -2
  134. package/dist/htest/multipleComparisons.d.ts +173 -29
  135. package/dist/htest/multipleComparisons.js +123 -19
  136. package/dist/htest/normalityTests.d.ts +56 -9
  137. package/dist/htest/normalityTests.js +40 -6
  138. package/dist/htest/onewayTest.d.ts +45 -2
  139. package/dist/htest/onewayTest.js +15 -7
  140. package/dist/htest/pAdjust.d.ts +9 -1
  141. package/dist/htest/pAdjust.js +2 -0
  142. package/dist/htest/pairwise.d.ts +50 -5
  143. package/dist/htest/pairwise.js +25 -0
  144. package/dist/htest/poissonTest.d.ts +12 -2
  145. package/dist/htest/poissonTest.js +2 -0
  146. package/dist/htest/polycor.d.ts +29 -10
  147. package/dist/htest/power.d.ts +60 -6
  148. package/dist/htest/power.js +6 -0
  149. package/dist/htest/propTest.d.ts +13 -2
  150. package/dist/htest/propTest.js +2 -0
  151. package/dist/htest/pwr.d.ts +286 -36
  152. package/dist/htest/pwr.js +116 -15
  153. package/dist/htest/rankTests.d.ts +132 -7
  154. package/dist/htest/rankTests.js +30 -33
  155. package/dist/htest/tTest.d.ts +32 -2
  156. package/dist/htest/tTest.js +19 -24
  157. package/dist/htest/testFormula.d.ts +57 -0
  158. package/dist/htest/testFormula.js +171 -0
  159. package/dist/htest/trendTests.d.ts +29 -8
  160. package/dist/htest/trendTests.js +8 -4
  161. package/dist/htest/types.d.ts +14 -2
  162. package/dist/htest/varTest.d.ts +46 -6
  163. package/dist/htest/varTest.js +11 -21
  164. package/dist/htest/wilcoxTest.d.ts +23 -1
  165. package/dist/htest/wilcoxTest.js +9 -24
  166. package/dist/internal/dpq.d.ts +4 -0
  167. package/dist/internal/noncentral.d.ts +2 -0
  168. package/dist/internal/vectorize.d.ts +4 -0
  169. package/dist/linalg/basic.d.ts +39 -5
  170. package/dist/linalg/basic.js +15 -0
  171. package/dist/linalg/chol.d.ts +26 -5
  172. package/dist/linalg/chol.js +7 -0
  173. package/dist/linalg/eigen.d.ts +16 -7
  174. package/dist/linalg/eigen.js +6 -5
  175. package/dist/linalg/expm.d.ts +15 -5
  176. package/dist/linalg/expm.js +5 -3
  177. package/dist/linalg/kappa.d.ts +21 -1
  178. package/dist/linalg/kappa.js +16 -0
  179. package/dist/linalg/lu.d.ts +30 -6
  180. package/dist/linalg/lu.js +15 -3
  181. package/dist/linalg/matrix.d.ts +4 -0
  182. package/dist/linalg/norm.d.ts +16 -1
  183. package/dist/linalg/norm.js +9 -0
  184. package/dist/linalg/ops.d.ts +168 -36
  185. package/dist/linalg/ops.js +116 -20
  186. package/dist/linalg/qr.d.ts +87 -12
  187. package/dist/linalg/qr.js +31 -0
  188. package/dist/linalg/schur.d.ts +8 -2
  189. package/dist/linalg/schur.js +3 -1
  190. package/dist/linalg/solve.d.ts +42 -6
  191. package/dist/linalg/solve.js +22 -0
  192. package/dist/linalg/svd.d.ts +12 -2
  193. package/dist/linalg/svd.js +2 -0
  194. package/dist/linalg.js +2 -2
  195. package/dist/models/anovaSequential.d.ts +26 -4
  196. package/dist/models/anovaSequential.js +3 -1
  197. package/dist/models/aovEz.d.ts +29 -6
  198. package/dist/models/aovEz.js +5 -2
  199. package/dist/models/aovStrata.d.ts +12 -2
  200. package/dist/models/carAnova.d.ts +9 -3
  201. package/dist/models/carAnova.js +4 -2
  202. package/dist/models/coxph.d.ts +33 -7
  203. package/dist/models/coxph.js +8 -3
  204. package/dist/models/glm.d.ts +128 -21
  205. package/dist/models/glm.js +71 -14
  206. package/dist/models/glmAnova.d.ts +30 -5
  207. package/dist/models/glmAnova.js +15 -2
  208. package/dist/models/glmConfint.d.ts +16 -2
  209. package/dist/models/glmConfint.js +9 -1
  210. package/dist/models/glmFamily.d.ts +27 -5
  211. package/dist/models/lm.d.ts +75 -17
  212. package/dist/models/lm.js +22 -4
  213. package/dist/models/mauchly.d.ts +20 -5
  214. package/dist/models/mauchly.js +7 -3
  215. package/dist/models/modelFrame.d.ts +5 -1
  216. package/dist/models/modelMatrix.d.ts +18 -4
  217. package/dist/models/modelMatrix.js +3 -1
  218. package/dist/models/survival.d.ts +41 -9
  219. package/dist/models/survival.js +10 -4
  220. package/dist/numerics/deriv.d.ts +21 -6
  221. package/dist/numerics/deriv.js +16 -5
  222. package/dist/numerics/integrate.d.ts +37 -7
  223. package/dist/numerics/integrate.js +8 -2
  224. package/dist/numerics/interp.d.ts +63 -12
  225. package/dist/numerics/interp.js +30 -6
  226. package/dist/numerics/ode.d.ts +15 -5
  227. package/dist/numerics/ode.js +5 -3
  228. package/dist/numerics.js +2 -2
  229. package/dist/optim/optim.d.ts +32 -8
  230. package/dist/optim/optim.js +8 -4
  231. package/dist/random/beta.d.ts +8 -0
  232. package/dist/random/beta.js +8 -0
  233. package/dist/random/binomial.d.ts +16 -0
  234. package/dist/random/binomial.js +16 -0
  235. package/dist/random/continuous.d.ts +51 -0
  236. package/dist/random/continuous.js +51 -0
  237. package/dist/random/extra.d.ts +66 -6
  238. package/dist/random/extra.js +66 -6
  239. package/dist/random/gamma.d.ts +33 -0
  240. package/dist/random/gamma.js +33 -0
  241. package/dist/random/hyper.d.ts +8 -0
  242. package/dist/random/hyper.js +8 -0
  243. package/dist/random/poisson.d.ts +25 -0
  244. package/dist/random/poisson.js +25 -0
  245. package/dist/random/r2dtable.d.ts +2 -0
  246. package/dist/random/r2dtable.js +2 -0
  247. package/dist/random/rank.d.ts +16 -0
  248. package/dist/random/rank.js +16 -0
  249. package/dist/random/rng.d.ts +49 -6
  250. package/dist/random/rng.js +29 -2
  251. package/dist/random/sample.d.ts +10 -2
  252. package/dist/random/sample.js +5 -1
  253. package/dist/random/streams.d.ts +13 -0
  254. package/dist/random/streams.js +13 -0
  255. package/dist/rstats.js +14 -14
  256. package/dist/special/besselIK.d.ts +11 -3
  257. package/dist/special/besselIK.js +6 -2
  258. package/dist/special/besselJY.d.ts +6 -2
  259. package/dist/special/besselJY.js +6 -2
  260. package/dist/special/beta.d.ts +16 -2
  261. package/dist/special/beta.js +16 -2
  262. package/dist/special/choose.d.ts +13 -5
  263. package/dist/special/choose.js +13 -5
  264. package/dist/special/erf.d.ts +8 -3
  265. package/dist/special/erf.js +8 -3
  266. package/dist/special/extra.d.ts +30 -10
  267. package/dist/special/extra.js +25 -9
  268. package/dist/special/gamma.d.ts +18 -2
  269. package/dist/special/gamma.js +18 -2
  270. package/dist/special/log1p.d.ts +16 -7
  271. package/dist/special/log1p.js +16 -7
  272. package/dist/special/psigamma.d.ts +9 -3
  273. package/dist/special/psigamma.js +9 -3
  274. package/dist/special/rCompatible.d.ts +5 -1
  275. package/dist/special.js +2 -2
  276. package/dist/tests.js +12 -13
  277. package/llms.txt +14 -0
  278. package/package.json +1 -1
  279. package/dist/chunks/chunk-AECGWZHD.js +0 -2
  280. package/dist/chunks/chunk-XWTZ4RTR.js +0 -2
@@ -0,0 +1,57 @@
1
+ import { type DataFrame } from "../models/modelFrame.js";
2
+ /** A grouping variable as a factor: its levels and the 0-based level of each row. */
3
+ interface GroupFactor {
4
+ levels: string[];
5
+ codes: number[];
6
+ }
7
+ /** The data of a two-sample test's formula: one sample (`y ~ 1`), a pair (`Pair(a, b) ~ 1`) or two groups (`y ~ g`) */
8
+ export type TwoSampleData = {
9
+ kind: "one";
10
+ x: number[];
11
+ } | {
12
+ kind: "paired";
13
+ x: number[];
14
+ y: number[];
15
+ } | {
16
+ kind: "two";
17
+ x: number[];
18
+ y: number[];
19
+ levels: [string, string];
20
+ };
21
+ /**
22
+ * The samples of a two-sample test's formula. `oneSample` allows `y ~ 1` and `Pair(a, b) ~ 1` (t.test and
23
+ * wilcox.test).
24
+ */
25
+ export declare function twoSampleData(formula: string, data: DataFrame, oneSample: boolean): TwoSampleData;
26
+ /** The two samples of a formula `y ~ g` whose group has two levels (var.test, ansari.test, mood.test, ks.test) */
27
+ export declare function twoGroupData(formula: string, data: DataFrame): {
28
+ x: number[];
29
+ y: number[];
30
+ };
31
+ /** The response and group of a formula `y ~ g` with one variable on the right (kruskal.test, fligner.test, bartlett.test) */
32
+ export declare function kSampleData(formula: string, data: DataFrame): {
33
+ values: number[];
34
+ group: GroupFactor;
35
+ };
36
+ /** The samples of each level, in the order of the levels */
37
+ export declare function samplesByLevel(values: readonly number[], group: GroupFactor): number[][];
38
+ /**
39
+ * The response and groups of oneway.test's formula `y ~ A` or `y ~ A + B + ...`: with several factors the groups are
40
+ * the combinations present in the data, numbered with the first factor varying fastest (R's interaction()).
41
+ */
42
+ export declare function onewayData(formula: string, data: DataFrame): {
43
+ values: number[];
44
+ groups: number[];
45
+ };
46
+ /**
47
+ * The matrix (one row per block, one column per group, levels in order) of a blocked design's formula `y ~ w | b`
48
+ * (friedman.test, quade.test). Rows with a missing value are dropped first; every combination of group and block must
49
+ * then occur exactly once.
50
+ */
51
+ export declare function blockData(formula: string, data: DataFrame): number[][];
52
+ /** The two variables of cor.test's one-sided formula `~ x + z` */
53
+ export declare function correlationData(formula: string, data: DataFrame): {
54
+ x: number[];
55
+ y: number[];
56
+ };
57
+ export {};
@@ -0,0 +1,171 @@
1
+ // Formula forms of the hypothesis tests (R's formula methods of t.test, wilcox.test, kruskal.test, friedman.test,
2
+ // cor.test, ...): the data a formula selects from a data frame, which the tests then pass to their default forms.
3
+ //
4
+ // Written for rStats.js (no ported code) from oracle/formulatests-behaviour.md. Only the variables of the formula
5
+ // count: the rows where one of them is missing are dropped (src/models/modelFrame.ts), and a grouping variable becomes
6
+ // a factor of the remaining values, with sorted levels (numbers as numbers, strings by code point) and no unused
7
+ // level. The formula is parsed with src/models/formula.ts; `Pair(a, b)` on the left and `|` on the right, which that
8
+ // parser does not know, are split off the text first.
9
+ import { parseFormula, termsOf } from "../models/formula.js";
10
+ import { modelFrame } from "../models/modelFrame.js";
11
+ import { formatR } from "./core/simulate.js";
12
+ /** A variable of a model frame as a factor: numbers sorted as numbers and labelled as R prints them */
13
+ function groupFactor(v) {
14
+ if (v.kind === "factor")
15
+ return { levels: v.levels, codes: v.codes };
16
+ const sorted = [...new Set(v.values)].sort((a, b) => a - b);
17
+ const levels = [...new Set(sorted.map(formatR))];
18
+ const position = new Map(levels.map((l, i) => [l, i]));
19
+ return { levels, codes: v.values.map((x) => position.get(formatR(x))) };
20
+ }
21
+ /** The values of a numeric variable of a model frame (a response or a variable of a correlation) */
22
+ function numericValues(v, name) {
23
+ if (v.kind !== "numeric")
24
+ throw new TypeError(`'${name}' must be a numeric column`);
25
+ return v.values;
26
+ }
27
+ /** The terms of a formula without `Pair()` or `|`, and the names of the variables of its right-hand side */
28
+ function plainTerms(formula, data) {
29
+ const parsed = parseFormula(formula);
30
+ const terms = termsOf(parsed, Object.keys(data));
31
+ return { terms, rhsVariables: terms.variables.slice(terms.response === 0 ? 1 : 0) };
32
+ }
33
+ /** The text on each side of the formula's `~` (the left side empty for a one-sided formula) */
34
+ function splitTilde(formula) {
35
+ if (typeof formula !== "string")
36
+ throw new TypeError("the formula must be a string");
37
+ const at = formula.indexOf("~");
38
+ return at < 0 ? undefined : { lhs: formula.slice(0, at).trim(), rhs: formula.slice(at + 1) };
39
+ }
40
+ const PAIR = /^Pair\s*\(\s*([A-Za-z.][A-Za-z0-9._]*)\s*,\s*([A-Za-z.][A-Za-z0-9._]*)\s*\)$/;
41
+ const MISSING_OR_INCORRECT = "'formula' missing or incorrect";
42
+ /** Whether a right-hand side is the intercept alone (`~ 1`) */
43
+ const interceptOnly = (terms, rhsVariables) => rhsVariables.length === 0 && terms.terms.length === 0 && terms.intercept;
44
+ /**
45
+ * The samples of a two-sample test's formula. `oneSample` allows `y ~ 1` and `Pair(a, b) ~ 1` (t.test and
46
+ * wilcox.test).
47
+ */
48
+ export function twoSampleData(formula, data, oneSample) {
49
+ const sides = splitTilde(formula);
50
+ const pair = sides === undefined ? null : PAIR.exec(sides.lhs);
51
+ if (pair !== null) {
52
+ const { terms, rhsVariables } = plainTerms(`~${sides.rhs}`, data);
53
+ if (!oneSample || !interceptOnly(terms, rhsVariables))
54
+ throw new Error(MISSING_OR_INCORRECT);
55
+ const frame = modelFrame(data, [pair[1], pair[2]]);
56
+ return { kind: "paired", x: numericValues(frame.variables[0], pair[1]), y: numericValues(frame.variables[1], pair[2]) };
57
+ }
58
+ const { terms, rhsVariables } = plainTerms(formula, data);
59
+ if (terms.response < 0)
60
+ throw new Error(MISSING_OR_INCORRECT);
61
+ const response = terms.variables[0];
62
+ if (oneSample && interceptOnly(terms, rhsVariables)) {
63
+ return { kind: "one", x: numericValues(modelFrame(data, [response]).variables[0], response) };
64
+ }
65
+ if (rhsVariables.length !== 1 || terms.terms.length !== 1)
66
+ throw new Error(MISSING_OR_INCORRECT);
67
+ const frame = modelFrame(data, [response, rhsVariables[0]], { dropUnusedLevels: true });
68
+ const values = numericValues(frame.variables[0], response);
69
+ const group = groupFactor(frame.variables[1]);
70
+ if (group.levels.length !== 2)
71
+ throw new Error("grouping factor must have exactly 2 levels");
72
+ return {
73
+ kind: "two",
74
+ x: values.filter((_, i) => group.codes[i] === 0),
75
+ y: values.filter((_, i) => group.codes[i] === 1),
76
+ levels: [group.levels[0], group.levels[1]],
77
+ };
78
+ }
79
+ /** The two samples of a formula `y ~ g` whose group has two levels (var.test, ansari.test, mood.test, ks.test) */
80
+ export function twoGroupData(formula, data) {
81
+ const d = twoSampleData(formula, data, false);
82
+ if (d.kind !== "two")
83
+ throw new Error(MISSING_OR_INCORRECT);
84
+ return d;
85
+ }
86
+ /** The response and group of a formula `y ~ g` with one variable on the right (kruskal.test, fligner.test, bartlett.test) */
87
+ export function kSampleData(formula, data) {
88
+ const { terms, rhsVariables } = plainTerms(formula, data);
89
+ if (terms.response < 0)
90
+ throw new Error(MISSING_OR_INCORRECT);
91
+ if (rhsVariables.length !== 1)
92
+ throw new Error("'formula' should be of the form response ~ group");
93
+ const response = terms.variables[0];
94
+ const frame = modelFrame(data, [response, rhsVariables[0]], { dropUnusedLevels: true });
95
+ return { values: numericValues(frame.variables[0], response), group: groupFactor(frame.variables[1]) };
96
+ }
97
+ /** The samples of each level, in the order of the levels */
98
+ export function samplesByLevel(values, group) {
99
+ const out = group.levels.map(() => []);
100
+ values.forEach((v, i) => out[group.codes[i]].push(v));
101
+ return out;
102
+ }
103
+ /**
104
+ * The response and groups of oneway.test's formula `y ~ A` or `y ~ A + B + ...`: with several factors the groups are
105
+ * the combinations present in the data, numbered with the first factor varying fastest (R's interaction()).
106
+ */
107
+ export function onewayData(formula, data) {
108
+ const { terms, rhsVariables } = plainTerms(formula, data);
109
+ if (terms.response < 0 || rhsVariables.length === 0)
110
+ throw new Error(MISSING_OR_INCORRECT);
111
+ const response = terms.variables[0];
112
+ const frame = modelFrame(data, [response, ...rhsVariables], { dropUnusedLevels: true });
113
+ const factors = frame.variables.slice(1).map(groupFactor);
114
+ const groups = frame.rows.map((_, i) => {
115
+ let code = 0;
116
+ let stride = 1;
117
+ for (const f of factors) {
118
+ code += f.codes[i] * stride;
119
+ stride *= f.levels.length;
120
+ }
121
+ return code;
122
+ });
123
+ return { values: numericValues(frame.variables[0], response), groups };
124
+ }
125
+ const INCORRECT_BLOCKS = "incorrect specification for 'formula'";
126
+ /**
127
+ * The matrix (one row per block, one column per group, levels in order) of a blocked design's formula `y ~ w | b`
128
+ * (friedman.test, quade.test). Rows with a missing value are dropped first; every combination of group and block must
129
+ * then occur exactly once.
130
+ */
131
+ export function blockData(formula, data) {
132
+ const sides = splitTilde(formula);
133
+ const parts = sides?.rhs.split("|");
134
+ if (sides === undefined || sides.lhs === "" || parts.length !== 2)
135
+ throw new Error(INCORRECT_BLOCKS);
136
+ const one = (text) => {
137
+ const { terms, rhsVariables } = plainTerms(text, data);
138
+ if (rhsVariables.length !== 1 || terms.terms.length !== 1)
139
+ throw new Error(INCORRECT_BLOCKS);
140
+ return rhsVariables[0];
141
+ };
142
+ const { terms } = plainTerms(`${sides.lhs} ~ 1`, data);
143
+ const response = terms.variables[0];
144
+ const groupName = one(`~${parts[0]}`);
145
+ const blockName = one(`~${parts[1]}`);
146
+ const frame = modelFrame(data, [response, groupName, blockName], { dropUnusedLevels: true });
147
+ const values = numericValues(frame.variables[0], response);
148
+ const group = groupFactor(frame.variables[1]);
149
+ const block = groupFactor(frame.variables[2]);
150
+ const matrix = block.levels.map(() => group.levels.map(() => NaN));
151
+ const counts = block.levels.map(() => group.levels.map(() => 0));
152
+ values.forEach((v, i) => {
153
+ const b = block.codes[i];
154
+ const w = group.codes[i];
155
+ counts[b][w]++;
156
+ matrix[b][w] = v;
157
+ });
158
+ if (counts.some((row) => row.some((c) => c !== 1)))
159
+ throw new Error("not an unreplicated complete block design");
160
+ return matrix;
161
+ }
162
+ /** The two variables of cor.test's one-sided formula `~ x + z` */
163
+ export function correlationData(formula, data) {
164
+ const { terms, rhsVariables } = plainTerms(formula, data);
165
+ if (terms.response >= 0)
166
+ throw new Error("'formula' missing or invalid");
167
+ if (rhsVariables.length !== 2)
168
+ throw new Error("invalid formula");
169
+ const frame = modelFrame(data, rhsVariables);
170
+ return { x: numericValues(frame.variables[0], rhsVariables[0]), y: numericValues(frame.variables[1], rhsVariables[1]) };
171
+ }
@@ -1,6 +1,10 @@
1
1
  import type { GroupLabel } from "./groups.js";
2
2
  import type { HTest, Sample } from "./types.js";
3
- /** Result of {@link propTrendTest}: no `alternative`, as R returns none. */
3
+ /**
4
+ * Result of {@link propTrendTest}: no `alternative`, as R returns none.
5
+ *
6
+ * @category Hypothesis tests
7
+ */
4
8
  export interface PropTrendTestResult extends Omit<HTest, "alternative"> {
5
9
  /** Degrees of freedom (1). */
6
10
  parameter: number;
@@ -16,11 +20,21 @@ export interface PropTrendTestResult extends Omit<HTest, "alternative"> {
16
20
  * ```ts
17
21
  * propTrendTest([15, 10, 8, 4], [30, 30, 30, 30]).statistic; // 9.573428850537288
18
22
  * ```
23
+ *
24
+ * @category Hypothesis tests
19
25
  */
20
26
  export declare function propTrendTest(x: Sample, n: Sample, score?: Sample): PropTrendTestResult;
21
- /** Alternative of {@link jonckheereTest}. */
27
+ /**
28
+ * Alternative of {@link jonckheereTest}.
29
+ *
30
+ * @category Hypothesis tests
31
+ */
22
32
  export type JonckheereAlternative = "two.sided" | "increasing" | "decreasing";
23
- /** Options for {@link jonckheereTest}. */
33
+ /**
34
+ * Options for {@link jonckheereTest}.
35
+ *
36
+ * @category Hypothesis tests
37
+ */
24
38
  export interface JonckheereTestOptions {
25
39
  /** `"two.sided"` (default), `"increasing"` or `"decreasing"` (unambiguous abbreviations accepted). */
26
40
  alternative?: JonckheereAlternative | (string & {});
@@ -34,17 +48,22 @@ export interface JonckheereTestOptions {
34
48
  /** The order of the groups. Default: the labels sorted (numbers as numbers, strings by code point). */
35
49
  levels?: readonly GroupLabel[];
36
50
  }
37
- /** Result of {@link jonckheereTest}. */
51
+ /**
52
+ * Result of {@link jonckheereTest}.
53
+ *
54
+ * @category Hypothesis tests
55
+ */
38
56
  export interface JonckheereTestResult extends Omit<HTest, "alternative"> {
57
+ /** Alternative hypothesis: `"two.sided"`, `"increasing"` or `"decreasing"`. */
39
58
  alternative: JonckheereAlternative;
40
59
  /** The packages' warnings (normal approximation). */
41
60
  warnings: string[];
42
61
  }
43
62
  /**
44
- * Jonckheere-Terpstra test of equal distributions against ordered alternatives. Equivalent to DescTools'
45
- * `JonckheereTerpstraTest(x, g, alternative, exact)` (with `g` an ordered factor) or, with `variant: "clinfun"`, to
46
- * clinfun's `jonckheere.test(x, g, alternative)` (whose two-sided p-value is `2 min(p_increasing, p_decreasing,
47
- * 0.5)`; DescTools caps it at 1 instead of 0.5). Pairs with a missing value are dropped.
63
+ * Jonckheere-Terpstra test of equal distributions against ordered alternatives. Equivalent to
64
+ * `DescTools::JonckheereTerpstraTest()` in R. Computes `JonckheereTerpstraTest(x, g, alternative, exact)` (with `g`
65
+ * an ordered factor) or, with `variant: "clinfun"`, clinfun's `jonckheere.test(x, g, alternative)` (whose
66
+ * two-sided p-value is `2 min(p_increasing, p_decreasing, 0.5)`; DescTools caps it at 1 instead of 0.5). Pairs with a missing value are dropped.
48
67
  *
49
68
  * @param x The values.
50
69
  * @param g Group labels, parallel to `x`, in the order of the alternative.
@@ -53,5 +72,7 @@ export interface JonckheereTestResult extends Omit<HTest, "alternative"> {
53
72
  * ```ts
54
73
  * jonckheereTest([1.1, 2.0, 2.4, 3.5, 3.1, 4.6], [1, 1, 2, 2, 3, 3], { alternative: "increasing" }).statistic; // 11
55
74
  * ```
75
+ *
76
+ * @category Hypothesis tests
56
77
  */
57
78
  export declare function jonckheereTest(x: Sample, g: readonly GroupLabel[], options?: JonckheereTestOptions): JonckheereTestResult;
@@ -25,6 +25,8 @@ import { matchChoice } from "./power.js";
25
25
  * ```ts
26
26
  * propTrendTest([15, 10, 8, 4], [30, 30, 30, 30]).statistic; // 9.573428850537288
27
27
  * ```
28
+ *
29
+ * @category Hypothesis tests
28
30
  */
29
31
  export function propTrendTest(x, n, score) {
30
32
  const xs = Array.from(x);
@@ -84,10 +86,10 @@ function orderedGroups(x, g, levels) {
84
86
  return groups;
85
87
  }
86
88
  /**
87
- * Jonckheere-Terpstra test of equal distributions against ordered alternatives. Equivalent to DescTools'
88
- * `JonckheereTerpstraTest(x, g, alternative, exact)` (with `g` an ordered factor) or, with `variant: "clinfun"`, to
89
- * clinfun's `jonckheere.test(x, g, alternative)` (whose two-sided p-value is `2 min(p_increasing, p_decreasing,
90
- * 0.5)`; DescTools caps it at 1 instead of 0.5). Pairs with a missing value are dropped.
89
+ * Jonckheere-Terpstra test of equal distributions against ordered alternatives. Equivalent to
90
+ * `DescTools::JonckheereTerpstraTest()` in R. Computes `JonckheereTerpstraTest(x, g, alternative, exact)` (with `g`
91
+ * an ordered factor) or, with `variant: "clinfun"`, clinfun's `jonckheere.test(x, g, alternative)` (whose
92
+ * two-sided p-value is `2 min(p_increasing, p_decreasing, 0.5)`; DescTools caps it at 1 instead of 0.5). Pairs with a missing value are dropped.
91
93
  *
92
94
  * @param x The values.
93
95
  * @param g Group labels, parallel to `x`, in the order of the alternative.
@@ -96,6 +98,8 @@ function orderedGroups(x, g, levels) {
96
98
  * ```ts
97
99
  * jonckheereTest([1.1, 2.0, 2.4, 3.5, 3.1, 4.6], [1, 1, 2, 2, 3, 3], { alternative: "increasing" }).statistic; // 11
98
100
  * ```
101
+ *
102
+ * @category Hypothesis tests
99
103
  */
100
104
  export function jonckheereTest(x, g, options = {}) {
101
105
  const alternative = matchChoice(options.alternative, ["two.sided", "increasing", "decreasing"]);
@@ -1,11 +1,21 @@
1
1
  /**
2
2
  * Alternative hypothesis of a test, as in R. Test options also accept unambiguous
3
3
  * abbreviations (`"two"`, `"l"`, `"g"`), like R's `match.arg()`.
4
+ *
5
+ * @category Hypothesis tests
4
6
  */
5
7
  export type Alternative = "two.sided" | "less" | "greater";
6
- /** A sample: an array of numbers. */
8
+ /**
9
+ * A sample: an array of numbers.
10
+ *
11
+ * @category Hypothesis tests
12
+ */
7
13
  export type Sample = readonly number[] | Float64Array;
8
- /** Counts: an array of numbers. A contingency table is passed as an array of rows. */
14
+ /**
15
+ * Counts: an array of numbers. A contingency table is passed as an array of rows.
16
+ *
17
+ * @category Hypothesis tests
18
+ */
9
19
  export type Counts = readonly number[] | Float64Array;
10
20
  /**
11
21
  * Result of a hypothesis test: a plain object mirroring R's `htest` class.
@@ -14,6 +24,8 @@ export type Counts = readonly number[] | Float64Array;
14
24
  * number and a separate `...Name` field. `estimate` is an array only when there are two
15
25
  * estimates (for example the two means of a two-sample t-test). `conf.int`'s
16
26
  * `conf.level` attribute becomes `confLevel`.
27
+ *
28
+ * @category Hypothesis tests
17
29
  */
18
30
  export interface HTest {
19
31
  /** Description of the test, as R's `method` (e.g. `"Welch Two Sample t-test"`). */
@@ -1,5 +1,10 @@
1
+ import type { DataFrame } from "../models/modelFrame.js";
1
2
  import { type Alternative, type HTest, type Sample } from "./types.js";
2
- /** Options for {@link varTest}. */
3
+ /**
4
+ * Options for {@link varTest}.
5
+ *
6
+ * @category Hypothesis tests
7
+ */
3
8
  export interface VarTestOptions {
4
9
  /** Hypothesized ratio of the variances of `x` and `y`. Default `1`. */
5
10
  ratio?: number;
@@ -8,10 +13,15 @@ export interface VarTestOptions {
8
13
  /** Confidence level of the interval. Default `0.95`. */
9
14
  confLevel?: number;
10
15
  }
11
- /** Result of {@link varTest}. The F distribution has two degrees of freedom, so `parameter` is a pair. */
16
+ /**
17
+ * Result of {@link varTest}. The F distribution has two degrees of freedom, so `parameter` is a pair.
18
+ *
19
+ * @category Hypothesis tests
20
+ */
12
21
  export interface VarTestResult extends Omit<HTest, "parameter" | "parameterName"> {
13
22
  /** `[num df, denom df]`. */
14
23
  parameter: [number, number];
24
+ /** Names of `parameter`: `["num df", "denom df"]`. */
15
25
  parameterName: [string, string];
16
26
  confInt: [number, number];
17
27
  confLevel: number;
@@ -25,18 +35,35 @@ export interface VarTestResult extends Omit<HTest, "parameter" | "parameterName"
25
35
  *
26
36
  * @example
27
37
  * ```ts
28
- * varTest([1, 3, 2, 5, 4], [2, 9, 4, 12, 7, 1]).statistic; // 0.2307692
38
+ * varTest([1, 3, 2, 5, 4], [2, 9, 4, 12, 7, 1]).statistic; // 0.13761467889908255
29
39
  * ```
40
+ *
41
+ * There is also a formula form, `varTest("y ~ g", data, options)` (next overload).
42
+ *
43
+ * @category Hypothesis tests
30
44
  */
31
45
  export declare function varTest(x: Sample, y: Sample, options?: VarTestOptions): VarTestResult;
32
- /** Result of {@link bartlettTest}. Has no `alternative`, as R's `bartlett.test()` returns none. */
46
+ /**
47
+ * F test of two variances from a formula and a data frame. As R's `var.test(formula, data)`: `"y ~ g"`
48
+ * compares the two levels of `g` (the first level is `x`). Only the variables of the formula count: the rows where
49
+ * one of them is missing are dropped.
50
+ *
51
+ * @param formula `"y ~ g"`.
52
+ * @param data The data frame: an object of columns (`null` or `NaN` for a missing value).
53
+ */
54
+ export declare function varTest(formula: string, data: DataFrame, options?: VarTestOptions): VarTestResult;
55
+ /**
56
+ * Result of {@link bartlettTest}. Has no `alternative`, as R's `bartlett.test()` returns none.
57
+ *
58
+ * @category Hypothesis tests
59
+ */
33
60
  export interface BartlettTestResult extends Omit<HTest, "alternative"> {
34
61
  /** Degrees of freedom (`parameterName` is `"df"`). */
35
62
  parameter: number;
36
63
  }
37
64
  /**
38
- * Bartlett's test that the variances of several normal samples are equal. Equivalent to R's `bartlett.test()` with
39
- * a list of samples. `NaN` and infinite values are dropped, as in R.
65
+ * Bartlett's test that the variances of several normal samples are equal. Equivalent to R's `bartlett.test()`.
66
+ * Takes a list of samples. `NaN` and infinite values are dropped, as in R.
40
67
  *
41
68
  * @param groups The samples (at least two), each with at least two finite values.
42
69
  *
@@ -44,5 +71,18 @@ export interface BartlettTestResult extends Omit<HTest, "alternative"> {
44
71
  * ```ts
45
72
  * bartlettTest([[1, 3, 2, 5], [2, 9, 4, 12, 7], [3, 3.5, 4, 2]]).statistic;
46
73
  * ```
74
+ *
75
+ * There is also a formula form, `bartlettTest("y ~ g", data)` (next overload).
76
+ *
77
+ * @category Hypothesis tests
47
78
  */
48
79
  export declare function bartlettTest(groups: readonly Sample[]): BartlettTestResult;
80
+ /**
81
+ * Bartlett's test from a formula and a data frame. As R's `bartlett.test(formula, data)`: `"y ~ g"`, one
82
+ * group per level of `g`, in the order of the levels. Only the variables of the formula count: the rows where one of
83
+ * them is missing are dropped.
84
+ *
85
+ * @param formula `"y ~ g"` (one variable on each side).
86
+ * @param data The data frame: an object of columns (`null` or `NaN` for a missing value).
87
+ */
88
+ export declare function bartlettTest(formula: string, data: DataFrame): BartlettTestResult;
@@ -8,17 +8,13 @@
8
8
  import { pf1, qf1 } from "../distributions/f.js";
9
9
  import { pgamma1 } from "../distributions/gamma.js";
10
10
  import { variance } from "../internal/summary.js";
11
+ import { kSampleData, samplesByLevel, twoGroupData } from "./testFormula.js";
11
12
  import { checkConfLevelOpen, matchAlternative } from "./types.js";
12
- /**
13
- * F test that the variances of two normal samples have a given ratio. Equivalent to R's `var.test()`. `NaN` values
14
- * are dropped.
15
- *
16
- * @example
17
- * ```ts
18
- * varTest([1, 3, 2, 5, 4], [2, 9, 4, 12, 7, 1]).statistic; // 0.2307692
19
- * ```
20
- */
21
13
  export function varTest(x, y, options = {}) {
14
+ if (typeof x === "string") {
15
+ const d = twoGroupData(x, y);
16
+ return varTest(d.x, d.y, options);
17
+ }
22
18
  // as in R, infinite values are dropped along with NaN
23
19
  const xs = Array.from(x).filter(Number.isFinite);
24
20
  const ys = Array.from(y).filter(Number.isFinite);
@@ -69,18 +65,12 @@ export function varTest(x, y, options = {}) {
69
65
  nullValueName: "ratio of variances",
70
66
  };
71
67
  }
72
- /**
73
- * Bartlett's test that the variances of several normal samples are equal. Equivalent to R's `bartlett.test()` with
74
- * a list of samples. `NaN` and infinite values are dropped, as in R.
75
- *
76
- * @param groups The samples (at least two), each with at least two finite values.
77
- *
78
- * @example
79
- * ```ts
80
- * bartlettTest([[1, 3, 2, 5], [2, 9, 4, 12, 7], [3, 3.5, 4, 2]]).statistic;
81
- * ```
82
- */
83
- export function bartlettTest(groups) {
68
+ export function bartlettTest(x, data) {
69
+ if (typeof x === "string") {
70
+ const d = kSampleData(x, data);
71
+ return bartlettTest(samplesByLevel(d.values, d.group));
72
+ }
73
+ const groups = x;
84
74
  const k = groups.length;
85
75
  if (k < 2)
86
76
  throw new RangeError("'x' must be a list with at least 2 elements");
@@ -1,5 +1,10 @@
1
+ import type { DataFrame } from "../models/modelFrame.js";
1
2
  import { type Alternative, type HTest, type Sample } from "./types.js";
2
- /** Options for {@link wilcoxTest}. */
3
+ /**
4
+ * Options for {@link wilcoxTest}.
5
+ *
6
+ * @category Hypothesis tests
7
+ */
3
8
  export interface WilcoxTestOptions {
4
9
  /**
5
10
  * Alternative hypothesis: `"two.sided"`, `"less"` or `"greater"`. Default `"two.sided"`.
@@ -29,6 +34,8 @@ export interface WilcoxTestOptions {
29
34
  * Result of {@link wilcoxTest}. `statisticName` is `"V"` for the signed rank test and `"W"`
30
35
  * for the rank sum test; `parameter` is not set. `estimate` and `confInt` are set only
31
36
  * with `confInt: true`.
37
+ *
38
+ * @category Hypothesis tests
32
39
  */
33
40
  export interface WilcoxTestResult extends HTest {
34
41
  /** `mu`. */
@@ -57,5 +64,20 @@ export interface WilcoxTestResult extends HTest {
57
64
  * r.statistic; // 40 (V)
58
65
  * r.pValue; // 0.01953125
59
66
  * ```
67
+ *
68
+ * There is also a formula form, `wilcoxTest("y ~ g", data, options)` (next overload).
69
+ *
70
+ * @category Hypothesis tests
60
71
  */
61
72
  export declare function wilcoxTest(x: Sample, y?: Sample | WilcoxTestOptions, options?: WilcoxTestOptions): WilcoxTestResult;
73
+ /**
74
+ * Wilcoxon tests from a formula and a data frame. As R's `wilcox.test(formula, data)`: `"y ~ g"` is the
75
+ * rank sum test of the two levels of `g` (the first level is `x`), `"y ~ 1"` the signed rank test and
76
+ * `"Pair(a, b) ~ 1"` the paired test of `a` and `b` (the option `paired` is not allowed). Only the variables of the
77
+ * formula count: the rows where one of them is missing are dropped.
78
+ *
79
+ * @param formula `"y ~ g"`, `"y ~ 1"` or `"Pair(a, b) ~ 1"`.
80
+ * @param data The data frame: an object of columns (`null` or `NaN` for a missing value).
81
+ * @param options See {@link WilcoxTestOptions}.
82
+ */
83
+ export declare function wilcoxTest(formula: string, data: DataFrame, options?: WilcoxTestOptions): WilcoxTestResult;
@@ -23,32 +23,17 @@ import { pwilcox1, qwilcox1 } from "../distributions/wilcox.js";
23
23
  import { pnorm, qnorm } from "../distributions/normal.js";
24
24
  import { completePairs, dropNaN, mean, rank, tieCounts, } from "../internal/summary.js";
25
25
  import { uniroot } from "../internal/uniroot.js";
26
+ import { twoSampleData } from "./testFormula.js";
26
27
  import { matchAlternative } from "./types.js";
27
- /**
28
- * Wilcoxon signed rank and rank sum (Mann-Whitney) tests. Equivalent to R's `wilcox.test()`.
29
- *
30
- * With one sample (or `paired: true`) performs the signed rank test; with two samples the
31
- * rank sum test. The choice between exact and normal-approximation p-values, the
32
- * Hodges-Lehmann estimates and the confidence intervals follow R, including R's behavior
33
- * when the requested confidence level cannot be reached. Only `NaN` is dropped; infinite
34
- * values are kept and ranked (as R actually does).
35
- *
36
- * @param x Sample.
37
- * @param y Second sample for a two-sample or paired test. May be omitted, and the options
38
- * passed in its place: `wilcoxTest(x, { mu: 1 })`.
39
- * @param options See {@link WilcoxTestOptions}.
40
- * @returns The test result; see {@link WilcoxTestResult}.
41
- *
42
- * @example
43
- * ```ts
44
- * const x = [1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30];
45
- * const y = [0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29];
46
- * const r = wilcoxTest(x, y, { paired: true, alternative: "greater" });
47
- * r.statistic; // 40 (V)
48
- * r.pValue; // 0.01953125
49
- * ```
50
- */
51
28
  export function wilcoxTest(x, y, options = {}) {
29
+ if (typeof x === "string") {
30
+ if (options.paired !== undefined)
31
+ throw new Error("cannot use 'paired' in formula method");
32
+ const d = twoSampleData(x, y, true);
33
+ if (d.kind === "one")
34
+ return wilcoxTest(d.x, options);
35
+ return wilcoxTest(d.x, d.y, d.kind === "paired" ? { ...options, paired: true } : options);
36
+ }
52
37
  // Also accept the form wilcoxTest(x, { mu: 1 })
53
38
  let ys;
54
39
  if (y !== undefined && !ArrayBuffer.isView(y) && !Array.isArray(y))
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Options shared by the distribution (`p*`) and quantile (`q*`) functions.
3
3
  * Correspond to R's `lower.tail` and `log.p` arguments.
4
+ *
5
+ * @category Distributions
4
6
  */
5
7
  export interface TailOptions {
6
8
  /** If `true`, probabilities are P[X <= x]; if `false`, P[X > x]. Default `true`. */
@@ -11,6 +13,8 @@ export interface TailOptions {
11
13
  /**
12
14
  * Options shared by the density / probability mass (`d*`) functions.
13
15
  * Corresponds to R's `log` argument.
16
+ *
17
+ * @category Distributions
14
18
  */
15
19
  export interface DensityOptions {
16
20
  /** If `true`, return the log of the density (or probability). Default `false`. */
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * Noncentrality option accepted by the chi-squared, t, F and beta distribution functions.
3
+ *
4
+ * @category Distributions
3
5
  */
4
6
  export interface NoncentralOption {
5
7
  /**
@@ -2,11 +2,15 @@
2
2
  * Input accepted as the vectorized first argument of the distribution functions
3
3
  * (the counterpart of R's automatic vectorization).
4
4
  * A number gives a number, a `number[]` gives a `number[]`, and a `Float64Array` gives a `Float64Array`.
5
+ *
6
+ * @category Distributions
5
7
  */
6
8
  export type Vectorizable = number | readonly number[] | Float64Array;
7
9
  /**
8
10
  * Result type matching the shape of a {@link Vectorizable} input:
9
11
  * `number` for a number, `Float64Array` for a `Float64Array`, and `number[]` for an array.
12
+ *
13
+ * @category Distributions
10
14
  */
11
15
  export type VectorResult<T extends Vectorizable> = T extends number ? number : T extends Float64Array ? Float64Array : number[];
12
16
  export declare function vectorize<T extends Vectorizable>(x: T, f: (v: number) => number): VectorResult<T>;