@numero-uno-jpn/rstats 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.ja.md +5 -4
  3. package/README.md +6 -4
  4. package/dist/chunks/{chunk-YSWGDOWK.js → chunk-2X7JYQBI.js} +2 -2
  5. package/dist/chunks/{chunk-F5EDJFEO.js → chunk-36GVER3O.js} +2 -2
  6. package/dist/chunks/{chunk-7GQMKH3Z.js → chunk-3WUXRSM6.js} +1 -1
  7. package/dist/chunks/{chunk-JWBO5WVN.js → chunk-6I6QKTFK.js} +2 -2
  8. package/dist/chunks/{chunk-EZWBRCJL.js → chunk-ETOEZTGL.js} +1 -1
  9. package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-FVPDVRJQ.js} +2 -2
  10. package/dist/chunks/{chunk-EZAFN5CD.js → chunk-GG4BJMJW.js} +1 -1
  11. package/dist/chunks/{chunk-5WDJPHYY.js → chunk-HITD7CX6.js} +1 -1
  12. package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-KK4GE65D.js} +2 -2
  13. package/dist/chunks/{chunk-AHHS6AC4.js → chunk-LAUYSGV4.js} +2 -2
  14. package/dist/chunks/{chunk-ALM3VHFP.js → chunk-M6GDXKKS.js} +1 -1
  15. package/dist/chunks/{chunk-C5XTWMGB.js → chunk-PHHUHR7T.js} +1 -1
  16. package/dist/chunks/{chunk-TOGXTCZO.js → chunk-WQPFDDIY.js} +2 -2
  17. package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-X2AWQSVS.js} +2 -2
  18. package/dist/chunks/{chunk-Y5CNQ266.js → chunk-ZRJQD7VS.js} +2 -2
  19. package/dist/data/grouping.d.ts +33 -12
  20. package/dist/data/grouping.js +2 -0
  21. package/dist/descriptive/basic.d.ts +130 -17
  22. package/dist/descriptive/basic.js +115 -14
  23. package/dist/descriptive/cov.d.ts +22 -12
  24. package/dist/descriptive/dataFrames.d.ts +39 -11
  25. package/dist/descriptive/dataFrames.js +14 -6
  26. package/dist/descriptive/factanal.d.ts +26 -6
  27. package/dist/descriptive/factanal.js +7 -3
  28. package/dist/descriptive/hist.d.ts +27 -6
  29. package/dist/descriptive/hist.js +9 -3
  30. package/dist/descriptive/missing.d.ts +13 -6
  31. package/dist/descriptive/missing.js +4 -2
  32. package/dist/descriptive/moments.d.ts +91 -13
  33. package/dist/descriptive/moments.js +66 -9
  34. package/dist/descriptive/omega.d.ts +28 -6
  35. package/dist/descriptive/omega.js +16 -4
  36. package/dist/descriptive/pivot.d.ts +22 -6
  37. package/dist/descriptive/pivot.js +7 -3
  38. package/dist/descriptive/quantile.d.ts +33 -5
  39. package/dist/descriptive/quantile.js +20 -2
  40. package/dist/descriptive/rank.d.ts +12 -2
  41. package/dist/descriptive/rank.js +2 -0
  42. package/dist/descriptive/table.d.ts +55 -7
  43. package/dist/descriptive/table.js +38 -4
  44. package/dist/descriptive.js +2 -2
  45. package/dist/distributions/arcsine.d.ts +40 -5
  46. package/dist/distributions/arcsine.js +35 -4
  47. package/dist/distributions/beta.d.ts +12 -0
  48. package/dist/distributions/beta.js +12 -0
  49. package/dist/distributions/binomial.d.ts +18 -0
  50. package/dist/distributions/binomial.js +18 -0
  51. package/dist/distributions/bvnorm.d.ts +4 -1
  52. package/dist/distributions/bvnorm.js +4 -1
  53. package/dist/distributions/cauchy.d.ts +24 -0
  54. package/dist/distributions/cauchy.js +24 -0
  55. package/dist/distributions/chisq.d.ts +18 -0
  56. package/dist/distributions/chisq.js +18 -0
  57. package/dist/distributions/exponential.d.ts +29 -1
  58. package/dist/distributions/exponential.js +24 -0
  59. package/dist/distributions/f.d.ts +18 -0
  60. package/dist/distributions/f.js +18 -0
  61. package/dist/distributions/gamma.d.ts +20 -0
  62. package/dist/distributions/gamma.js +18 -0
  63. package/dist/distributions/geometric.d.ts +24 -0
  64. package/dist/distributions/geometric.js +24 -0
  65. package/dist/distributions/hypergeometric.d.ts +24 -0
  66. package/dist/distributions/hypergeometric.js +24 -0
  67. package/dist/distributions/invgamma.d.ts +32 -4
  68. package/dist/distributions/invgamma.js +27 -3
  69. package/dist/distributions/kumaraswamy.d.ts +31 -3
  70. package/dist/distributions/kumaraswamy.js +31 -3
  71. package/dist/distributions/laplace.d.ts +36 -4
  72. package/dist/distributions/laplace.js +31 -3
  73. package/dist/distributions/logistic.d.ts +29 -1
  74. package/dist/distributions/logistic.js +24 -0
  75. package/dist/distributions/lognormal.d.ts +29 -1
  76. package/dist/distributions/lognormal.js +24 -0
  77. package/dist/distributions/multinomial.d.ts +7 -1
  78. package/dist/distributions/multinomial.js +2 -0
  79. package/dist/distributions/negbinomial.d.ts +29 -1
  80. package/dist/distributions/negbinomial.js +24 -0
  81. package/dist/distributions/normal.d.ts +11 -1
  82. package/dist/distributions/normal.js +6 -0
  83. package/dist/distributions/pareto.d.ts +36 -4
  84. package/dist/distributions/pareto.js +31 -3
  85. package/dist/distributions/poisson.d.ts +18 -0
  86. package/dist/distributions/poisson.js +18 -0
  87. package/dist/distributions/signrank.d.ts +24 -0
  88. package/dist/distributions/signrank.js +24 -0
  89. package/dist/distributions/summary.d.ts +20 -2
  90. package/dist/distributions/summary.js +4 -0
  91. package/dist/distributions/t.d.ts +18 -0
  92. package/dist/distributions/t.js +18 -0
  93. package/dist/distributions/triangular.d.ts +36 -4
  94. package/dist/distributions/triangular.js +31 -3
  95. package/dist/distributions/tukey.d.ts +15 -1
  96. package/dist/distributions/tukey.js +10 -0
  97. package/dist/distributions/uniform.d.ts +29 -1
  98. package/dist/distributions/uniform.js +24 -0
  99. package/dist/distributions/weibull.d.ts +29 -1
  100. package/dist/distributions/weibull.js +24 -0
  101. package/dist/distributions/wilcox.d.ts +24 -0
  102. package/dist/distributions/wilcox.js +24 -0
  103. package/dist/distributions.js +2 -2
  104. package/dist/entries/descriptive.d.ts +1 -1
  105. package/dist/entries/numerics.d.ts +1 -1
  106. package/dist/entries/tests.js +1 -1
  107. package/dist/htest/agreement.d.ts +61 -23
  108. package/dist/htest/agreement.js +19 -9
  109. package/dist/htest/ansariTest.d.ts +8 -2
  110. package/dist/htest/aov.d.ts +43 -10
  111. package/dist/htest/aov.js +17 -3
  112. package/dist/htest/binomTest.d.ts +12 -2
  113. package/dist/htest/binomTest.js +2 -0
  114. package/dist/htest/brunnerMunzelTest.d.ts +9 -3
  115. package/dist/htest/brunnerMunzelTest.js +4 -2
  116. package/dist/htest/chisqTest.d.ts +19 -3
  117. package/dist/htest/cor.d.ts +20 -4
  118. package/dist/htest/effectSize.d.ts +70 -12
  119. package/dist/htest/effectSize.js +40 -7
  120. package/dist/htest/fisherTest.d.ts +9 -1
  121. package/dist/htest/fisherTest.js +2 -0
  122. package/dist/htest/groups.d.ts +5 -1
  123. package/dist/htest/ksTest.d.ts +20 -3
  124. package/dist/htest/leveneTest.d.ts +15 -4
  125. package/dist/htest/leveneTest.js +5 -2
  126. package/dist/htest/mantelhaenTest.d.ts +25 -3
  127. package/dist/htest/mantelhaenTest.js +15 -1
  128. package/dist/htest/mcnemarTest.d.ts +14 -4
  129. package/dist/htest/mcnemarTest.js +4 -2
  130. package/dist/htest/multipleComparisons.d.ts +173 -29
  131. package/dist/htest/multipleComparisons.js +123 -19
  132. package/dist/htest/normalityTests.d.ts +56 -9
  133. package/dist/htest/normalityTests.js +40 -6
  134. package/dist/htest/onewayTest.d.ts +32 -3
  135. package/dist/htest/onewayTest.js +10 -0
  136. package/dist/htest/pAdjust.d.ts +9 -1
  137. package/dist/htest/pAdjust.js +2 -0
  138. package/dist/htest/pairwise.d.ts +50 -5
  139. package/dist/htest/pairwise.js +25 -0
  140. package/dist/htest/poissonTest.d.ts +12 -2
  141. package/dist/htest/poissonTest.js +2 -0
  142. package/dist/htest/polycor.d.ts +29 -10
  143. package/dist/htest/power.d.ts +60 -6
  144. package/dist/htest/power.js +6 -0
  145. package/dist/htest/propTest.d.ts +13 -2
  146. package/dist/htest/propTest.js +2 -0
  147. package/dist/htest/pwr.d.ts +286 -36
  148. package/dist/htest/pwr.js +116 -15
  149. package/dist/htest/rankTests.d.ts +80 -12
  150. package/dist/htest/rankTests.js +11 -2
  151. package/dist/htest/tTest.d.ts +13 -3
  152. package/dist/htest/trendTests.d.ts +29 -8
  153. package/dist/htest/trendTests.js +8 -4
  154. package/dist/htest/types.d.ts +14 -2
  155. package/dist/htest/varTest.d.ts +25 -8
  156. package/dist/htest/wilcoxTest.d.ts +10 -2
  157. package/dist/internal/dpq.d.ts +4 -0
  158. package/dist/internal/noncentral.d.ts +2 -0
  159. package/dist/internal/vectorize.d.ts +4 -0
  160. package/dist/linalg/basic.d.ts +39 -5
  161. package/dist/linalg/basic.js +15 -0
  162. package/dist/linalg/chol.d.ts +26 -5
  163. package/dist/linalg/chol.js +7 -0
  164. package/dist/linalg/eigen.d.ts +16 -7
  165. package/dist/linalg/eigen.js +6 -5
  166. package/dist/linalg/expm.d.ts +15 -5
  167. package/dist/linalg/expm.js +5 -3
  168. package/dist/linalg/kappa.d.ts +21 -1
  169. package/dist/linalg/kappa.js +16 -0
  170. package/dist/linalg/lu.d.ts +30 -6
  171. package/dist/linalg/lu.js +15 -3
  172. package/dist/linalg/matrix.d.ts +4 -0
  173. package/dist/linalg/norm.d.ts +16 -1
  174. package/dist/linalg/norm.js +9 -0
  175. package/dist/linalg/ops.d.ts +156 -35
  176. package/dist/linalg/ops.js +96 -15
  177. package/dist/linalg/qr.d.ts +87 -12
  178. package/dist/linalg/qr.js +31 -0
  179. package/dist/linalg/schur.d.ts +8 -2
  180. package/dist/linalg/schur.js +3 -1
  181. package/dist/linalg/solve.d.ts +42 -6
  182. package/dist/linalg/solve.js +22 -0
  183. package/dist/linalg/svd.d.ts +12 -2
  184. package/dist/linalg/svd.js +2 -0
  185. package/dist/linalg.js +2 -2
  186. package/dist/models/anovaSequential.d.ts +26 -4
  187. package/dist/models/anovaSequential.js +3 -1
  188. package/dist/models/aovEz.d.ts +29 -6
  189. package/dist/models/aovEz.js +5 -2
  190. package/dist/models/aovStrata.d.ts +12 -2
  191. package/dist/models/carAnova.d.ts +9 -3
  192. package/dist/models/carAnova.js +4 -2
  193. package/dist/models/coxph.d.ts +33 -7
  194. package/dist/models/coxph.js +8 -3
  195. package/dist/models/glm.d.ts +128 -21
  196. package/dist/models/glm.js +71 -14
  197. package/dist/models/glmAnova.d.ts +30 -5
  198. package/dist/models/glmAnova.js +15 -2
  199. package/dist/models/glmConfint.d.ts +16 -2
  200. package/dist/models/glmConfint.js +9 -1
  201. package/dist/models/glmFamily.d.ts +27 -5
  202. package/dist/models/lm.d.ts +75 -17
  203. package/dist/models/lm.js +22 -4
  204. package/dist/models/mauchly.d.ts +20 -5
  205. package/dist/models/mauchly.js +7 -3
  206. package/dist/models/modelFrame.d.ts +5 -1
  207. package/dist/models/modelMatrix.d.ts +18 -4
  208. package/dist/models/modelMatrix.js +3 -1
  209. package/dist/models/survival.d.ts +41 -9
  210. package/dist/models/survival.js +10 -4
  211. package/dist/numerics/deriv.d.ts +21 -6
  212. package/dist/numerics/deriv.js +16 -5
  213. package/dist/numerics/integrate.d.ts +37 -7
  214. package/dist/numerics/integrate.js +8 -2
  215. package/dist/numerics/interp.d.ts +63 -12
  216. package/dist/numerics/interp.js +30 -6
  217. package/dist/numerics/ode.d.ts +15 -5
  218. package/dist/numerics/ode.js +5 -3
  219. package/dist/numerics.js +2 -2
  220. package/dist/optim/optim.d.ts +32 -8
  221. package/dist/optim/optim.js +8 -4
  222. package/dist/random/beta.d.ts +8 -0
  223. package/dist/random/beta.js +8 -0
  224. package/dist/random/binomial.d.ts +16 -0
  225. package/dist/random/binomial.js +16 -0
  226. package/dist/random/continuous.d.ts +51 -0
  227. package/dist/random/continuous.js +51 -0
  228. package/dist/random/extra.d.ts +66 -6
  229. package/dist/random/extra.js +66 -6
  230. package/dist/random/gamma.d.ts +33 -0
  231. package/dist/random/gamma.js +33 -0
  232. package/dist/random/hyper.d.ts +8 -0
  233. package/dist/random/hyper.js +8 -0
  234. package/dist/random/poisson.d.ts +25 -0
  235. package/dist/random/poisson.js +25 -0
  236. package/dist/random/r2dtable.d.ts +2 -0
  237. package/dist/random/r2dtable.js +2 -0
  238. package/dist/random/rank.d.ts +16 -0
  239. package/dist/random/rank.js +16 -0
  240. package/dist/random/rng.d.ts +49 -6
  241. package/dist/random/rng.js +29 -2
  242. package/dist/random/sample.d.ts +10 -2
  243. package/dist/random/sample.js +5 -1
  244. package/dist/random/streams.d.ts +13 -0
  245. package/dist/random/streams.js +13 -0
  246. package/dist/rstats.js +1 -1
  247. package/dist/special/besselIK.d.ts +11 -3
  248. package/dist/special/besselIK.js +6 -2
  249. package/dist/special/besselJY.d.ts +6 -2
  250. package/dist/special/besselJY.js +6 -2
  251. package/dist/special/beta.d.ts +16 -2
  252. package/dist/special/beta.js +16 -2
  253. package/dist/special/choose.d.ts +13 -5
  254. package/dist/special/choose.js +13 -5
  255. package/dist/special/erf.d.ts +8 -3
  256. package/dist/special/erf.js +8 -3
  257. package/dist/special/extra.d.ts +30 -10
  258. package/dist/special/extra.js +25 -9
  259. package/dist/special/gamma.d.ts +18 -2
  260. package/dist/special/gamma.js +18 -2
  261. package/dist/special/log1p.d.ts +16 -7
  262. package/dist/special/log1p.js +16 -7
  263. package/dist/special/psigamma.d.ts +9 -3
  264. package/dist/special/psigamma.js +9 -3
  265. package/dist/special/rCompatible.d.ts +5 -1
  266. package/dist/special.js +2 -2
  267. package/dist/tests.js +2 -2
  268. package/llms.txt +2 -0
  269. package/package.json +1 -1
@@ -93,20 +93,29 @@ function standardizedDifference(x, y, options, adjust) {
93
93
  }
94
94
  /**
95
95
  * Cohen's d: the standardized difference of means of two samples (pooled or averaged standard deviation), of paired
96
- * samples, or of one sample against `mu`, with a confidence interval from the noncentral t distribution. Equivalent
97
- * to effectsize's `cohens_d()`.
96
+ * samples, or of one sample against `mu`, with a confidence interval from the noncentral t distribution.
97
+ * Equivalent to `effectsize::cohens_d()` in R.
98
98
  *
99
99
  * @example
100
100
  * ```ts
101
101
  * cohensD([5.1, 4.9, 6.2, 5.8], [4.1, 4.5, 3.9, 5.0]).value; // 2.049693834034246
102
102
  * ```
103
+ *
104
+ * @category Effect sizes and power
103
105
  */
104
106
  export function cohensD(x, y, options = {}) {
105
107
  return standardizedDifference(x, y, options, options.adjust ?? false);
106
108
  }
107
109
  /**
108
- * Hedges' g: Cohen's d and its interval multiplied by the small-sample correction J(df). Equivalent to effectsize's
109
- * `hedges_g()`.
110
+ * Hedges' g: Cohen's d and its interval multiplied by the small-sample correction J(df). Equivalent to
111
+ * `effectsize::hedges_g()` in R.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * hedgesG([5.1, 4.9, 6.2, 5.8], [4.1, 4.5, 3.9, 5.0]).value; // 1.7804187661174387
116
+ * ```
117
+ *
118
+ * @category Effect sizes and power
110
119
  */
111
120
  export function hedgesG(x, y, options = {}) {
112
121
  return standardizedDifference(x, y, options, true);
@@ -353,7 +362,7 @@ function strataEffectSize(model, kind, options) {
353
362
  }
354
363
  /**
355
364
  * Eta squared of the terms of an analysis-of-variance table (partial by default, or generalized), with confidence
356
- * intervals from the noncentral F distribution. Equivalent to effectsize's `eta_squared()` for a table of
365
+ * intervals from the noncentral F distribution. Equivalent to `effectsize::eta_squared()` in R. It takes a table of
357
366
  * `anova()` or `Anova()`; a fit from `lm()` with a formula is replaced by its `anova()` table.
358
367
  *
359
368
  * Repeated measures: for a fit of `aov()` with an `Error()` term (or its {@link aovSummary}) each term is measured
@@ -362,23 +371,47 @@ function strataEffectSize(model, kind, options) {
362
371
  *
363
372
  * @example
364
373
  * ```ts
374
+ * const data = { y: [2.1, 3.9, 6.2, 7.8, 10.1, 11.8], g: ["a", "a", "b", "b", "c", "c"] };
365
375
  * etaSquared(anova(lm("y ~ g", data))).colNames; // ["Eta2", "CI", "CI_low", "CI_high"]
376
+ * const long = {
377
+ * y: [5, 7, 8, 4, 6, 9, 6, 8, 8, 5, 5, 7],
378
+ * W: ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a", "b", "c"],
379
+ * id: ["s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3", "s4", "s4", "s4"],
380
+ * };
366
381
  * etaSquared(aov("y ~ W + Error(id/W)", long)).groups; // ["id:W"]
367
382
  * ```
383
+ *
384
+ * @category Effect sizes and power
368
385
  */
369
386
  export function etaSquared(model, options = {}) {
370
387
  return anovaEffectSize(model, "Eta2", options);
371
388
  }
372
389
  /**
373
390
  * Omega squared of the terms of an analysis-of-variance table, also of repeated-measures designs (see
374
- * {@link etaSquared}). Equivalent to effectsize's `omega_squared()`.
391
+ * {@link etaSquared}). Equivalent to `effectsize::omega_squared()` in R.
392
+ *
393
+ * @example
394
+ * ```ts
395
+ * const data = { y: [2.1, 3.9, 6.2, 7.8, 10.1, 11.8], g: ["a", "a", "b", "b", "c", "c"] };
396
+ * omegaSquared(anova(lm("y ~ g", data))).table; // [[0.8740518865645682, 0.95, 0.0566677410780818, 1]]
397
+ * ```
398
+ *
399
+ * @category Effect sizes and power
375
400
  */
376
401
  export function omegaSquared(model, options = {}) {
377
402
  return anovaEffectSize(model, "Omega2", options);
378
403
  }
379
404
  /**
380
405
  * Epsilon squared of the terms of an analysis-of-variance table, also of repeated-measures designs (see
381
- * {@link etaSquared}). Equivalent to effectsize's `epsilon_squared()`.
406
+ * {@link etaSquared}). Equivalent to `effectsize::epsilon_squared()` in R.
407
+ *
408
+ * @example
409
+ * ```ts
410
+ * const data = { y: [2.1, 3.9, 6.2, 7.8, 10.1, 11.8], g: ["a", "a", "b", "b", "c", "c"] };
411
+ * epsilonSquared(anova(lm("y ~ g", data))).table; // [[0.8927928150213428, 0.95, 0.1720126241673212, 1]]
412
+ * ```
413
+ *
414
+ * @category Effect sizes and power
382
415
  */
383
416
  export function epsilonSquared(model, options = {}) {
384
417
  return anovaEffectSize(model, "Epsilon2", options);
@@ -1,5 +1,9 @@
1
1
  import { type Alternative, type HTest, type Counts } from "./types.js";
2
- /** Options for {@link fisherTest}. */
2
+ /**
3
+ * Options for {@link fisherTest}.
4
+ *
5
+ * @category Hypothesis tests
6
+ */
3
7
  export interface FisherTestOptions {
4
8
  /**
5
9
  * Alternative hypothesis: `"two.sided"`, `"less"` or `"greater"`. Default `"two.sided"`.
@@ -26,6 +30,8 @@ export interface FisherTestOptions {
26
30
  * `fisher.test()` does not return a statistic. For 2 x 2 tables, `estimate` is the
27
31
  * conditional maximum likelihood estimate of the odds ratio and `confInt` its interval;
28
32
  * for larger tables only `method`, `alternative` and `pValue` are set.
33
+ *
34
+ * @category Hypothesis tests
29
35
  */
30
36
  export interface FisherTestResult extends Omit<HTest, "statistic" | "statisticName"> {
31
37
  }
@@ -55,5 +61,7 @@ export interface FisherTestResult extends Omit<HTest, "statistic" | "statisticNa
55
61
  * r.estimate; // 6.408308867005792 (conditional MLE of the odds ratio)
56
62
  * r.confInt; // [0.2117329153055031, 621.9337505454175]
57
63
  * ```
64
+ *
65
+ * @category Hypothesis tests
58
66
  */
59
67
  export declare function fisherTest(x: readonly Counts[], options?: FisherTestOptions): FisherTestResult;
@@ -65,6 +65,8 @@ import { matchAlternative } from "./types.js";
65
65
  * r.estimate; // 6.408308867005792 (conditional MLE of the odds ratio)
66
66
  * r.confInt; // [0.2117329153055031, 621.9337505454175]
67
67
  * ```
68
+ *
69
+ * @category Hypothesis tests
68
70
  */
69
71
  export function fisherTest(x, options = {}) {
70
72
  const nr = x.length;
@@ -1,5 +1,9 @@
1
1
  import type { Sample } from "./types.js";
2
- /** Group label: a number or a string. */
2
+ /**
3
+ * Group label: a number or a string.
4
+ *
5
+ * @category Hypothesis tests
6
+ */
3
7
  export type GroupLabel = number | string;
4
8
  /** Groups with their labels: the sorted labels (x, g form) or the 1-based positions in the list (list form) */
5
9
  export interface LabelledGroups {
@@ -1,6 +1,10 @@
1
1
  import type { DataFrame } from "../models/modelFrame.js";
2
2
  import { type Alternative, type HTest, type Sample } from "./types.js";
3
- /** Options for {@link ksTest}. */
3
+ /**
4
+ * Options for {@link ksTest}.
5
+ *
6
+ * @category Hypothesis tests
7
+ */
4
8
  export interface KsTestOptions {
5
9
  /**
6
10
  * Alternative hypothesis (unambiguous abbreviations accepted). `"greater"`: the distribution function of `x` lies
@@ -16,13 +20,17 @@ export interface KsTestOptions {
16
20
  /**
17
21
  * Result of {@link ksTest}. As in R, `alternative` describes the hypothesis in words ("two-sided", "the CDF of x lies
18
22
  * above the null hypothesis", ...), and `exact` tells whether the p-value is exact.
23
+ *
24
+ * @category Hypothesis tests
19
25
  */
20
26
  export interface KsTestResult extends Omit<HTest, "alternative"> {
27
+ /** Description of the alternative hypothesis, as R prints it (e.g. `"two-sided"`). */
21
28
  alternative: string;
29
+ /** Whether the p-value is exact. */
22
30
  exact: boolean;
23
31
  }
24
32
  /**
25
- * Kolmogorov-Smirnov test. Equivalent to R's `ks.test()`, with a distribution function given as a function (for
33
+ * Kolmogorov-Smirnov test. Equivalent to R's `ks.test()`. Takes a distribution function given as a function (for
26
34
  * example `(q) => pnorm(q)`) or a second sample. `NaN` values are dropped.
27
35
  *
28
36
  * @param x Sample.
@@ -30,10 +38,19 @@ export interface KsTestResult extends Omit<HTest, "alternative"> {
30
38
  * @param options See {@link KsTestOptions}.
31
39
  *
32
40
  * There is also a formula form for two samples, `ksTest("y ~ g", data, options)` (next overload).
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const x = [0.61, -1.2, 0.33, 1.57, -0.42, 0.08, -0.85, 1.1];
45
+ * ksTest(x, (q) => pnorm(q)).pValue; // 0.9716870044206776
46
+ * ksTest(x, [0.9, 2.1, 1.4, 2.8, 1.7, 0.4]).statistic; // 0.625
47
+ * ```
48
+ *
49
+ * @category Hypothesis tests
33
50
  */
34
51
  export declare function ksTest(x: Sample, y: Sample | ((q: number) => number), options?: KsTestOptions): KsTestResult;
35
52
  /**
36
- * Two-sample Kolmogorov-Smirnov test from a formula and a data frame. Equivalent to R's `ks.test(formula, data)`:
53
+ * Two-sample Kolmogorov-Smirnov test from a formula and a data frame. As R's `ks.test(formula, data)`:
37
54
  * `"y ~ g"` compares the two levels of `g` (the first level is `x`). Only the variables of the formula count: the
38
55
  * rows where one of them is missing are dropped.
39
56
  *
@@ -1,11 +1,19 @@
1
1
  import { type GroupLabel } from "./groups.js";
2
2
  import type { Sample } from "./types.js";
3
- /** Options for {@link leveneTest}. */
3
+ /**
4
+ * Options for {@link leveneTest}.
5
+ *
6
+ * @category Hypothesis tests
7
+ */
4
8
  export interface LeveneTestOptions {
5
9
  /** The centre of each group: `"median"` (default) or `"mean"`. */
6
10
  center?: "median" | "mean" | (string & {});
7
11
  }
8
- /** Result of {@link leveneTest}: car's table. */
12
+ /**
13
+ * Result of {@link leveneTest}: car's table.
14
+ *
15
+ * @category Hypothesis tests
16
+ */
9
17
  export interface LeveneTestResult {
10
18
  /** `["Df", "F value", "Pr(>F)"]`. */
11
19
  colNames: string[];
@@ -15,8 +23,9 @@ export interface LeveneTestResult {
15
23
  table: number[][];
16
24
  }
17
25
  /**
18
- * Levene's test for homogeneity of variance across groups. Equivalent to car's `leveneTest(y ~ g, center =
19
- * median)` (or `mean`). Pairs with a missing value are dropped; groups are ordered by their sorted labels.
26
+ * Levene's test for homogeneity of variance across groups. Equivalent to `car::leveneTest()` in R. Computes
27
+ * `leveneTest(y ~ g, center = median)` (or `mean`). Pairs with a missing value are dropped; groups are ordered by
28
+ * their sorted labels.
20
29
  *
21
30
  * @param y The values.
22
31
  * @param g Group labels, parallel to `y`.
@@ -26,5 +35,7 @@ export interface LeveneTestResult {
26
35
  * const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
27
36
  * leveneTest([4.2, 5.1, 6.3, 5.8, 7.9, 8.4, 6.6, 7.0, 5.5], g).table[0]; // [2, 0.15936952714535912, 0.8561748951935417]
28
37
  * ```
38
+ *
39
+ * @category Hypothesis tests
29
40
  */
30
41
  export declare function leveneTest(y: Sample, g: readonly GroupLabel[], options?: LeveneTestOptions): LeveneTestResult;
@@ -8,8 +8,9 @@ import { aov } from "./aov.js";
8
8
  import { labelledGroups, median } from "./groups.js";
9
9
  import { matchChoice } from "./power.js";
10
10
  /**
11
- * Levene's test for homogeneity of variance across groups. Equivalent to car's `leveneTest(y ~ g, center =
12
- * median)` (or `mean`). Pairs with a missing value are dropped; groups are ordered by their sorted labels.
11
+ * Levene's test for homogeneity of variance across groups. Equivalent to `car::leveneTest()` in R. Computes
12
+ * `leveneTest(y ~ g, center = median)` (or `mean`). Pairs with a missing value are dropped; groups are ordered by
13
+ * their sorted labels.
13
14
  *
14
15
  * @param y The values.
15
16
  * @param g Group labels, parallel to `y`.
@@ -19,6 +20,8 @@ import { matchChoice } from "./power.js";
19
20
  * const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
20
21
  * leveneTest([4.2, 5.1, 6.3, 5.8, 7.9, 8.4, 6.6, 7.0, 5.5], g).table[0]; // [2, 0.15936952714535912, 0.8561748951935417]
21
22
  * ```
23
+ *
24
+ * @category Hypothesis tests
22
25
  */
23
26
  export function leveneTest(y, g, options = {}) {
24
27
  const center = matchChoice(options.center ?? "median", ["median", "mean"]);
@@ -1,5 +1,9 @@
1
1
  import { type Alternative, type HTest } from "./types.js";
2
- /** Options for {@link mantelhaenTest}. */
2
+ /**
3
+ * Options for {@link mantelhaenTest}.
4
+ *
5
+ * @category Hypothesis tests
6
+ */
3
7
  export interface MantelhaenTestOptions {
4
8
  /** Alternative hypothesis (2 x 2 x K only). Default `"two.sided"`. */
5
9
  alternative?: Alternative | "two" | "l" | "g";
@@ -10,17 +14,35 @@ export interface MantelhaenTestOptions {
10
14
  /** Confidence level of the interval for the common odds ratio. Default `0.95`. */
11
15
  confLevel?: number;
12
16
  }
13
- /** Result of {@link mantelhaenTest}. 2 x 2 x K tables add the common odds ratio and its interval. */
17
+ /**
18
+ * Result of {@link mantelhaenTest}. 2 x 2 x K tables add the common odds ratio and its interval.
19
+ *
20
+ * @category Hypothesis tests
21
+ */
14
22
  export interface MantelhaenTestResult extends Omit<HTest, "alternative"> {
15
23
  /** Present for 2 x 2 x K tables. */
16
24
  alternative?: Alternative;
17
25
  }
18
26
  /**
19
27
  * Cochran-Mantel-Haenszel chi-squared test of conditional independence in a set of contingency tables, one per
20
- * stratum. Equivalent to R's `mantelhaen.test()` with a three-dimensional array.
28
+ * stratum. Equivalent to R's `mantelhaen.test()`. Takes the strata as R takes a three-dimensional array.
21
29
  *
22
30
  * @param strata The K strata, each an I x J table of counts as an array of rows (all of the same shape; I, J >= 2,
23
31
  * K >= 2 for the asymptotic test).
24
32
  * @param options See {@link MantelhaenTestOptions}.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const r = mantelhaenTest([
37
+ * [[10, 5], [4, 12]],
38
+ * [[8, 6], [5, 9]],
39
+ * [[12, 4], [6, 10]],
40
+ * ]);
41
+ * r.statistic; // 8.972595458903124
42
+ * r.pValue; // 0.002740590103473906
43
+ * r.estimate; // 4.13218122372723 (common odds ratio)
44
+ * ```
45
+ *
46
+ * @category Hypothesis tests
25
47
  */
26
48
  export declare function mantelhaenTest(strata: readonly (readonly (readonly number[])[])[], options?: MantelhaenTestOptions): MantelhaenTestResult;
@@ -21,11 +21,25 @@ import { ConvolvedNoncentralHyper, conditionalMLE, lowerLimit, upperLimit } from
21
21
  import { checkConfLevelOpen, matchAlternative } from "./types.js";
22
22
  /**
23
23
  * Cochran-Mantel-Haenszel chi-squared test of conditional independence in a set of contingency tables, one per
24
- * stratum. Equivalent to R's `mantelhaen.test()` with a three-dimensional array.
24
+ * stratum. Equivalent to R's `mantelhaen.test()`. Takes the strata as R takes a three-dimensional array.
25
25
  *
26
26
  * @param strata The K strata, each an I x J table of counts as an array of rows (all of the same shape; I, J >= 2,
27
27
  * K >= 2 for the asymptotic test).
28
28
  * @param options See {@link MantelhaenTestOptions}.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const r = mantelhaenTest([
33
+ * [[10, 5], [4, 12]],
34
+ * [[8, 6], [5, 9]],
35
+ * [[12, 4], [6, 10]],
36
+ * ]);
37
+ * r.statistic; // 8.972595458903124
38
+ * r.pValue; // 0.002740590103473906
39
+ * r.estimate; // 4.13218122372723 (common odds ratio)
40
+ * ```
41
+ *
42
+ * @category Hypothesis tests
29
43
  */
30
44
  export function mantelhaenTest(strata, options = {}) {
31
45
  const K = strata.length;
@@ -1,17 +1,25 @@
1
1
  import type { HTest } from "./types.js";
2
- /** Options for {@link mcnemarTest}. */
2
+ /**
3
+ * Options for {@link mcnemarTest}.
4
+ *
5
+ * @category Hypothesis tests
6
+ */
3
7
  export interface McnemarTestOptions {
4
8
  /** Apply the continuity correction (2 x 2 tables only). Default `true`. */
5
9
  correct?: boolean;
6
10
  }
7
- /** Result of {@link mcnemarTest}. Has no `alternative`, as R's `mcnemar.test()` returns none. */
11
+ /**
12
+ * Result of {@link mcnemarTest}. Has no `alternative`, as R's `mcnemar.test()` returns none.
13
+ *
14
+ * @category Hypothesis tests
15
+ */
8
16
  export interface McnemarTestResult extends Omit<HTest, "alternative"> {
9
17
  /** Degrees of freedom (`parameterName` is `"df"`). */
10
18
  parameter: number;
11
19
  }
12
20
  /**
13
21
  * McNemar's chi-squared test for symmetry of rows and columns in a square table of counts. Equivalent to R's
14
- * `mcnemar.test()` with a matrix, or with two factors given as paired category codes.
22
+ * `mcnemar.test()`. Takes a matrix, or two factors given as paired category codes.
15
23
  *
16
24
  * @param x Square table of counts as an array of rows, or the first of two paired samples of category codes.
17
25
  * @param y Second paired sample of category codes, when `x` is a sample. May be omitted (and the options passed in
@@ -20,7 +28,9 @@ export interface McnemarTestResult extends Omit<HTest, "alternative"> {
20
28
  *
21
29
  * @example
22
30
  * ```ts
23
- * mcnemarTest([[794, 86], [150, 570]]).statistic; // 34.71186
31
+ * mcnemarTest([[794, 86], [150, 570]]).statistic; // 16.81779661016949
24
32
  * ```
33
+ *
34
+ * @category Hypothesis tests
25
35
  */
26
36
  export declare function mcnemarTest(x: readonly (readonly number[])[] | readonly (number | string)[], y?: readonly (number | string)[] | McnemarTestOptions, options?: McnemarTestOptions): McnemarTestResult;
@@ -6,7 +6,7 @@
6
6
  import { pgamma1 } from "../distributions/gamma.js";
7
7
  /**
8
8
  * McNemar's chi-squared test for symmetry of rows and columns in a square table of counts. Equivalent to R's
9
- * `mcnemar.test()` with a matrix, or with two factors given as paired category codes.
9
+ * `mcnemar.test()`. Takes a matrix, or two factors given as paired category codes.
10
10
  *
11
11
  * @param x Square table of counts as an array of rows, or the first of two paired samples of category codes.
12
12
  * @param y Second paired sample of category codes, when `x` is a sample. May be omitted (and the options passed in
@@ -15,8 +15,10 @@ import { pgamma1 } from "../distributions/gamma.js";
15
15
  *
16
16
  * @example
17
17
  * ```ts
18
- * mcnemarTest([[794, 86], [150, 570]]).statistic; // 34.71186
18
+ * mcnemarTest([[794, 86], [150, 570]]).statistic; // 16.81779661016949
19
19
  * ```
20
+ *
21
+ * @category Hypothesis tests
20
22
  */
21
23
  export function mcnemarTest(x, y, options = {}) {
22
24
  let table;