@numero-uno-jpn/rstats 0.15.3 → 0.17.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 (322) hide show
  1. package/CHANGELOG.md +294 -0
  2. package/README.ja.md +68 -35
  3. package/README.md +65 -30
  4. package/dist/chunks/chunk-2C33MXSW.js +3 -0
  5. package/dist/chunks/chunk-34S5SQY6.js +2 -0
  6. package/dist/chunks/chunk-4WE3OO62.js +2 -0
  7. package/dist/chunks/chunk-5AYHCITP.js +2 -0
  8. package/dist/chunks/chunk-6JJQL6HL.js +2 -0
  9. package/dist/chunks/chunk-C7V2FH6L.js +3 -0
  10. package/dist/chunks/chunk-CZI7KUO3.js +2 -0
  11. package/dist/chunks/chunk-DXI5N2ET.js +2 -0
  12. package/dist/chunks/chunk-FY3FVOBM.js +2 -0
  13. package/dist/chunks/chunk-H3WVPZDL.js +2 -0
  14. package/dist/chunks/chunk-LHUIJQHY.js +2 -0
  15. package/dist/chunks/chunk-LV3W2F7N.js +2 -0
  16. package/dist/chunks/chunk-M4ITG7YR.js +2 -0
  17. package/dist/chunks/chunk-NSYZTS26.js +2 -0
  18. package/dist/chunks/chunk-ONY5CISH.js +2 -0
  19. package/dist/chunks/chunk-RFE7MVP7.js +2 -0
  20. package/dist/chunks/chunk-SE7V2KLO.js +2 -0
  21. package/dist/chunks/chunk-THIGHOKK.js +2 -0
  22. package/dist/chunks/chunk-TNMJPQPV.js +2 -0
  23. package/dist/chunks/chunk-WM7VFXTV.js +2 -0
  24. package/dist/chunks/chunk-WMDYDTVQ.js +2 -0
  25. package/dist/chunks/chunk-XLSFJTTK.js +2 -0
  26. package/dist/chunks/chunk-Z37NELOS.js +2 -0
  27. package/dist/chunks/chunk-ZFQWB222.js +2 -0
  28. package/dist/data/grouping.js +26 -7
  29. package/dist/descriptive/basic.js +110 -8
  30. package/dist/descriptive/cov.js +23 -4
  31. package/dist/descriptive/dataFrames.d.ts +4 -2
  32. package/dist/descriptive/dataFrames.js +69 -23
  33. package/dist/descriptive/factanal.d.ts +2 -0
  34. package/dist/descriptive/factanal.js +26 -9
  35. package/dist/descriptive/hist.d.ts +8 -5
  36. package/dist/descriptive/hist.js +77 -31
  37. package/dist/descriptive/missing.js +3 -1
  38. package/dist/descriptive/moments.js +86 -19
  39. package/dist/descriptive/omega.d.ts +1 -1
  40. package/dist/descriptive/omega.js +74 -10
  41. package/dist/descriptive/pivot.d.ts +25 -10
  42. package/dist/descriptive/pivot.js +182 -42
  43. package/dist/descriptive/quantile.js +10 -1
  44. package/dist/descriptive/rank.js +8 -1
  45. package/dist/descriptive/table.d.ts +23 -3
  46. package/dist/descriptive/table.js +36 -21
  47. package/dist/descriptive.js +2 -2
  48. package/dist/distributions/arcsine.js +27 -2
  49. package/dist/distributions/beta.js +33 -4
  50. package/dist/distributions/binomial.js +46 -14
  51. package/dist/distributions/bvnorm.js +11 -2
  52. package/dist/distributions/cauchy.js +21 -4
  53. package/dist/distributions/chisq.js +16 -3
  54. package/dist/distributions/exponential.js +14 -0
  55. package/dist/distributions/f.js +41 -17
  56. package/dist/distributions/gamma.js +35 -3
  57. package/dist/distributions/geometric.js +58 -13
  58. package/dist/distributions/hypergeometric.d.ts +5 -1
  59. package/dist/distributions/hypergeometric.js +101 -6
  60. package/dist/distributions/invgamma.js +10 -1
  61. package/dist/distributions/kumaraswamy.js +9 -0
  62. package/dist/distributions/laplace.js +36 -6
  63. package/dist/distributions/logistic.js +13 -1
  64. package/dist/distributions/lognormal.js +16 -2
  65. package/dist/distributions/multinomial.js +58 -11
  66. package/dist/distributions/nbeta.js +62 -11
  67. package/dist/distributions/nchisq.js +30 -6
  68. package/dist/distributions/negbinomial.js +102 -17
  69. package/dist/distributions/normal.js +17 -4
  70. package/dist/distributions/nt.js +392 -17
  71. package/dist/distributions/pareto.js +12 -1
  72. package/dist/distributions/poisson.js +37 -3
  73. package/dist/distributions/signrank.js +16 -4
  74. package/dist/distributions/summary.d.ts +2 -1
  75. package/dist/distributions/summary.js +481 -61
  76. package/dist/distributions/t.js +9 -0
  77. package/dist/distributions/triangular.js +19 -5
  78. package/dist/distributions/tukey.js +11 -2
  79. package/dist/distributions/uniform.js +8 -0
  80. package/dist/distributions/weibull.js +18 -0
  81. package/dist/distributions/wilcox.d.ts +9 -3
  82. package/dist/distributions/wilcox.js +164 -26
  83. package/dist/distributions.js +2 -2
  84. package/dist/entries/descriptive.d.ts +3 -1
  85. package/dist/entries/descriptive.js +1 -1
  86. package/dist/entries/distributions.d.ts +1 -0
  87. package/dist/entries/distributions.js +2 -0
  88. package/dist/entries/linalg.d.ts +3 -1
  89. package/dist/entries/mixed.d.ts +3 -0
  90. package/dist/entries/mixed.js +2 -0
  91. package/dist/entries/numerics.d.ts +2 -1
  92. package/dist/entries/tests.d.ts +8 -5
  93. package/dist/entries/tests.js +3 -1
  94. package/dist/htest/agreement.d.ts +16 -2
  95. package/dist/htest/agreement.js +122 -21
  96. package/dist/htest/ansariTest.d.ts +8 -2
  97. package/dist/htest/ansariTest.js +116 -18
  98. package/dist/htest/aov.d.ts +29 -23
  99. package/dist/htest/aov.js +90 -47
  100. package/dist/htest/binomTest.d.ts +5 -0
  101. package/dist/htest/binomTest.js +47 -17
  102. package/dist/htest/brunnerMunzelTest.d.ts +4 -3
  103. package/dist/htest/brunnerMunzelTest.js +12 -5
  104. package/dist/htest/chisqTest.d.ts +5 -2
  105. package/dist/htest/chisqTest.js +151 -46
  106. package/dist/htest/cor.d.ts +9 -2
  107. package/dist/htest/cor.js +57 -26
  108. package/dist/htest/core/ansari.d.ts +9 -0
  109. package/dist/htest/core/ansari.js +21 -1
  110. package/dist/htest/core/kolmogorov.d.ts +25 -0
  111. package/dist/htest/core/kolmogorov.js +123 -0
  112. package/dist/htest/core/mantelhaen.js +6 -4
  113. package/dist/htest/core/shapiro.d.ts +1 -1
  114. package/dist/htest/core/shapiro.js +5 -1
  115. package/dist/htest/core/simulate.d.ts +6 -0
  116. package/dist/htest/core/simulate.js +20 -0
  117. package/dist/htest/dunnett.js +14 -5
  118. package/dist/htest/effectSize.d.ts +5 -0
  119. package/dist/htest/effectSize.js +117 -35
  120. package/dist/htest/fisherTest.d.ts +4 -3
  121. package/dist/htest/fisherTest.js +88 -24
  122. package/dist/htest/groups.d.ts +7 -0
  123. package/dist/htest/groups.js +21 -4
  124. package/dist/htest/ksTest.d.ts +7 -1
  125. package/dist/htest/ksTest.js +36 -6
  126. package/dist/htest/leveneTest.d.ts +2 -0
  127. package/dist/htest/leveneTest.js +28 -6
  128. package/dist/htest/mantelhaenTest.js +132 -25
  129. package/dist/htest/mcnemarTest.js +40 -11
  130. package/dist/htest/multipleComparisons.d.ts +24 -26
  131. package/dist/htest/multipleComparisons.js +70 -64
  132. package/dist/htest/normalityTests.js +54 -14
  133. package/dist/htest/onewayTest.js +106 -5
  134. package/dist/htest/pAdjust.d.ts +3 -2
  135. package/dist/htest/pAdjust.js +42 -6
  136. package/dist/htest/pairwise.d.ts +3 -1
  137. package/dist/htest/pairwise.js +46 -21
  138. package/dist/htest/poissonTest.d.ts +1 -1
  139. package/dist/htest/poissonTest.js +117 -59
  140. package/dist/htest/polycor.js +47 -17
  141. package/dist/htest/power.d.ts +15 -1
  142. package/dist/htest/power.js +128 -10
  143. package/dist/htest/propTest.d.ts +3 -0
  144. package/dist/htest/propTest.js +44 -6
  145. package/dist/htest/pwr.d.ts +38 -1
  146. package/dist/htest/pwr.js +159 -39
  147. package/dist/htest/rankTests.js +36 -6
  148. package/dist/htest/tTest.d.ts +2 -0
  149. package/dist/htest/tTest.js +53 -21
  150. package/dist/htest/testFormula.js +11 -11
  151. package/dist/htest/trendTests.d.ts +28 -4
  152. package/dist/htest/trendTests.js +124 -35
  153. package/dist/htest/types.d.ts +7 -0
  154. package/dist/htest/types.js +7 -0
  155. package/dist/htest/varTest.js +52 -14
  156. package/dist/htest/wilcoxTest.js +164 -29
  157. package/dist/integrate/quadpack.js +27 -5
  158. package/dist/internal/checkOptions.d.ts +11 -0
  159. package/dist/internal/checkOptions.js +31 -0
  160. package/dist/internal/covmat.d.ts +5 -0
  161. package/dist/internal/covmat.js +20 -0
  162. package/dist/internal/ddexp.d.ts +15 -1
  163. package/dist/internal/ddexp.js +59 -6
  164. package/dist/internal/discrete.d.ts +14 -0
  165. package/dist/internal/discrete.js +78 -5
  166. package/dist/internal/extremes.d.ts +9 -0
  167. package/dist/internal/extremes.js +24 -0
  168. package/dist/internal/fround.js +13 -4
  169. package/dist/internal/integer.d.ts +9 -0
  170. package/dist/internal/integer.js +12 -0
  171. package/dist/internal/invert.js +15 -2
  172. package/dist/internal/optionalArgs.d.ts +12 -0
  173. package/dist/internal/optionalArgs.js +46 -0
  174. package/dist/internal/scaledInverse.d.ts +10 -0
  175. package/dist/internal/scaledInverse.js +22 -0
  176. package/dist/internal/seq.js +15 -2
  177. package/dist/internal/summary.d.ts +90 -0
  178. package/dist/internal/summary.js +458 -39
  179. package/dist/internal/uniroot.d.ts +7 -0
  180. package/dist/internal/uniroot.js +28 -3
  181. package/dist/internal/warnings.d.ts +66 -0
  182. package/dist/internal/warnings.js +122 -0
  183. package/dist/linalg/basic.d.ts +3 -1
  184. package/dist/linalg/basic.js +58 -7
  185. package/dist/linalg/chol.js +10 -1
  186. package/dist/linalg/dot.d.ts +29 -0
  187. package/dist/linalg/dot.js +132 -0
  188. package/dist/linalg/eigen.d.ts +6 -1
  189. package/dist/linalg/eigen.js +75 -14
  190. package/dist/linalg/expm.d.ts +3 -2
  191. package/dist/linalg/expm.js +113 -15
  192. package/dist/linalg/kappa.js +64 -10
  193. package/dist/linalg/lu.d.ts +2 -1
  194. package/dist/linalg/lu.js +40 -5
  195. package/dist/linalg/matrix.d.ts +14 -0
  196. package/dist/linalg/matrix.js +24 -0
  197. package/dist/linalg/norm.js +4 -0
  198. package/dist/linalg/ops.d.ts +27 -2
  199. package/dist/linalg/ops.js +74 -26
  200. package/dist/linalg/qr.d.ts +2 -1
  201. package/dist/linalg/qr.js +105 -23
  202. package/dist/linalg/schur.js +11 -3
  203. package/dist/linalg/solve.d.ts +6 -1
  204. package/dist/linalg/solve.js +156 -26
  205. package/dist/linalg/svd.d.ts +9 -2
  206. package/dist/linalg/svd.js +33 -11
  207. package/dist/linalg.js +2 -2
  208. package/dist/mixed.js +4 -4
  209. package/dist/models/anovaSequential.d.ts +32 -2
  210. package/dist/models/anovaSequential.js +170 -28
  211. package/dist/models/aovEz.js +154 -39
  212. package/dist/models/aovStrata.js +68 -24
  213. package/dist/models/carAnova.d.ts +1 -1
  214. package/dist/models/carAnova.js +78 -33
  215. package/dist/models/coxph.d.ts +6 -0
  216. package/dist/models/coxph.js +166 -69
  217. package/dist/models/estimable.d.ts +15 -0
  218. package/dist/models/estimable.js +68 -0
  219. package/dist/models/formula.d.ts +1 -1
  220. package/dist/models/formula.js +26 -8
  221. package/dist/models/glm.d.ts +57 -7
  222. package/dist/models/glm.js +427 -74
  223. package/dist/models/glmAnova.js +90 -14
  224. package/dist/models/glmConfint.d.ts +1 -1
  225. package/dist/models/glmConfint.js +121 -29
  226. package/dist/models/glmFamily.d.ts +11 -6
  227. package/dist/models/glmFamily.js +247 -62
  228. package/dist/models/lm.d.ts +12 -1
  229. package/dist/models/lm.js +246 -37
  230. package/dist/models/lmer.d.ts +31 -7
  231. package/dist/models/lmer.js +129 -42
  232. package/dist/models/lmerAnova.d.ts +3 -3
  233. package/dist/models/lmerAnova.js +47 -9
  234. package/dist/models/lmerHypotheses.d.ts +6 -2
  235. package/dist/models/lmerHypotheses.js +14 -2
  236. package/dist/models/lmerTest.d.ts +13 -6
  237. package/dist/models/lmerTest.js +82 -29
  238. package/dist/models/mauchly.d.ts +6 -1
  239. package/dist/models/mauchly.js +41 -15
  240. package/dist/models/mixedStructure.js +6 -0
  241. package/dist/models/modelFrame.js +10 -4
  242. package/dist/models/modelMatrix.d.ts +3 -1
  243. package/dist/models/modelMatrix.js +47 -17
  244. package/dist/models/scaledTables.d.ts +8 -0
  245. package/dist/models/scaledTables.js +6 -0
  246. package/dist/models/survival.d.ts +12 -1
  247. package/dist/models/survival.js +75 -28
  248. package/dist/models/tiedTimes.d.ts +2 -0
  249. package/dist/models/tiedTimes.js +34 -0
  250. package/dist/numerics/deriv.d.ts +1 -1
  251. package/dist/numerics/deriv.js +72 -8
  252. package/dist/numerics/integrate.d.ts +9 -1
  253. package/dist/numerics/integrate.js +111 -16
  254. package/dist/numerics/interp.d.ts +40 -9
  255. package/dist/numerics/interp.js +375 -55
  256. package/dist/numerics/ode.js +59 -1
  257. package/dist/numerics.js +2 -2
  258. package/dist/optim/localmin.js +4 -0
  259. package/dist/optim/optim.d.ts +3 -1
  260. package/dist/optim/optim.js +97 -10
  261. package/dist/random/beta.js +58 -4
  262. package/dist/random/binomial.d.ts +14 -3
  263. package/dist/random/binomial.js +59 -24
  264. package/dist/random/continuous.js +50 -5
  265. package/dist/random/extra.js +55 -9
  266. package/dist/random/gamma.d.ts +4 -1
  267. package/dist/random/gamma.js +47 -8
  268. package/dist/random/hyper.js +9 -6
  269. package/dist/random/mt.js +17 -2
  270. package/dist/random/poisson.js +31 -3
  271. package/dist/random/r2dtable.d.ts +8 -1
  272. package/dist/random/r2dtable.js +24 -3
  273. package/dist/random/rank.d.ts +2 -0
  274. package/dist/random/rank.js +44 -4
  275. package/dist/random/rng.js +4 -0
  276. package/dist/random/sample.d.ts +12 -2
  277. package/dist/random/sample.js +63 -20
  278. package/dist/random/streams.js +4 -2
  279. package/dist/rstats.js +17 -14
  280. package/dist/special/besselIK.d.ts +12 -0
  281. package/dist/special/besselIK.js +175 -23
  282. package/dist/special/besselJY.d.ts +11 -1
  283. package/dist/special/besselJY.js +127 -19
  284. package/dist/special/besselSeries.d.ts +27 -0
  285. package/dist/special/besselSeries.js +45 -2
  286. package/dist/special/beta.js +4 -1
  287. package/dist/special/choose.js +24 -8
  288. package/dist/special/dd.js +122 -18
  289. package/dist/special/extra.js +14 -2
  290. package/dist/special/gamma.js +11 -2
  291. package/dist/special/incbet.js +30 -4
  292. package/dist/special/incbetTemme.d.ts +7 -0
  293. package/dist/special/incbetTemme.js +45 -12
  294. package/dist/special/loader.d.ts +1 -1
  295. package/dist/special/loader.js +117 -20
  296. package/dist/special/log1pmx.js +4 -0
  297. package/dist/special/psigamma.js +7 -0
  298. package/dist/special.js +2 -2
  299. package/dist/tests.js +15 -11
  300. package/llms.txt +15 -6
  301. package/package.json +19 -10
  302. package/dist/chunks/chunk-3THFTB36.js +0 -2
  303. package/dist/chunks/chunk-3TSWYE5L.js +0 -2
  304. package/dist/chunks/chunk-3WPU6LGK.js +0 -2
  305. package/dist/chunks/chunk-5ITR67MB.js +0 -2
  306. package/dist/chunks/chunk-5NRFU6F6.js +0 -2
  307. package/dist/chunks/chunk-E2LCSVQV.js +0 -2
  308. package/dist/chunks/chunk-FCNVTIPJ.js +0 -2
  309. package/dist/chunks/chunk-FKAKALOZ.js +0 -2
  310. package/dist/chunks/chunk-HD73UKPT.js +0 -2
  311. package/dist/chunks/chunk-IUULP3LE.js +0 -2
  312. package/dist/chunks/chunk-JQG3YQOC.js +0 -2
  313. package/dist/chunks/chunk-KT66SB7R.js +0 -2
  314. package/dist/chunks/chunk-MAUAOQG3.js +0 -2
  315. package/dist/chunks/chunk-MDYE7QP2.js +0 -2
  316. package/dist/chunks/chunk-NM3Z2UBQ.js +0 -2
  317. package/dist/chunks/chunk-PMJI5QO6.js +0 -3
  318. package/dist/chunks/chunk-UF7KOTHF.js +0 -3
  319. package/dist/chunks/chunk-UOE57JGT.js +0 -2
  320. package/dist/chunks/chunk-USPEBXSR.js +0 -2
  321. package/dist/chunks/chunk-VLUL2HFW.js +0 -3
  322. package/dist/chunks/chunk-ZIX7NYQF.js +0 -2
@@ -27,7 +27,17 @@ export interface CohenESResult {
27
27
  method: string;
28
28
  }
29
29
  /**
30
- * Cohen's conventional effect sizes. Equivalent to `pwr::cohen.ES(test, size)` in R.
30
+ * Options for {@link cohenES}.
31
+ *
32
+ * @category Effect sizes and power
33
+ */
34
+ export interface CohenESOptions {
35
+ /** The conventional size: `"small"` (default), `"medium"` or `"large"`. */
36
+ size?: "small" | "medium" | "large" | (string & {});
37
+ }
38
+ /**
39
+ * Cohen's conventional effect sizes. Equivalent to `pwr::cohen.ES(test, size)` in R. The size is the second argument
40
+ * or the option `size` (giving both is a RangeError).
31
41
  *
32
42
  * @example
33
43
  * ```ts
@@ -37,6 +47,15 @@ export interface CohenESResult {
37
47
  * @category Effect sizes and power
38
48
  */
39
49
  export declare function cohenES(test?: CohenTest | (string & {}), size?: "small" | "medium" | "large" | (string & {})): CohenESResult;
50
+ /**
51
+ * Cohen's conventional effect sizes, with the size in the options: `cohenES("anov", { size: "medium" })`.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * cohenES("anov", { size: "medium" }).effectSize; // 0.25
56
+ * ```
57
+ */
58
+ export declare function cohenES(test: CohenTest | (string & {}) | undefined, options: CohenESOptions): CohenESResult;
40
59
  /**
41
60
  * Effect size h of two proportions: `2 asin(sqrt(p1)) - 2 asin(sqrt(p2))`. Equivalent to `pwr::ES.h()` in R.
42
61
  *
@@ -116,6 +135,8 @@ export interface PwrTTestResult {
116
135
  note?: string;
117
136
  /** Description of the calculation. */
118
137
  method: string;
138
+ /** R's warnings, each once, in R's order (an empty array when there are none). */
139
+ warnings: string[];
119
140
  }
120
141
  /**
121
142
  * Power of a t test of means, or the sample size, effect size or significance level for a given power.
@@ -163,6 +184,8 @@ export interface PwrT2nTestResult {
163
184
  alternative: Alternative;
164
185
  /** Description of the calculation. */
165
186
  method: string;
187
+ /** R's warnings, each once, in R's order (an empty array when there are none). */
188
+ warnings: string[];
166
189
  }
167
190
  /**
168
191
  * Power of a two-sample t test with unequal sample sizes, or a sample size, the effect size or the significance
@@ -208,6 +231,8 @@ export interface Pwr2pTestResult {
208
231
  method: string;
209
232
  /** A note on the sample sizes (absent for {@link pwrPTest}). */
210
233
  note?: string;
234
+ /** R's warnings, each once, in R's order (an empty array when there are none). */
235
+ warnings: string[];
211
236
  }
212
237
  /**
213
238
  * Power of the test of two proportions with equal sample sizes (arcsine transformation), or the effect size, sample
@@ -264,6 +289,8 @@ export interface PwrNormTestResult {
264
289
  alternative: Alternative;
265
290
  /** Description of the calculation. */
266
291
  method: string;
292
+ /** R's warnings, each once, in R's order (an empty array when there are none). */
293
+ warnings: string[];
267
294
  }
268
295
  /**
269
296
  * Power of the test of a mean of a normal distribution with known variance, or the effect size, sample size or
@@ -313,6 +340,8 @@ export interface Pwr2p2nTestResult {
313
340
  method: string;
314
341
  /** A note on the sample sizes. */
315
342
  note: string;
343
+ /** R's warnings, each once, in R's order (an empty array when there are none). */
344
+ warnings: string[];
316
345
  }
317
346
  /**
318
347
  * Power of the test of two proportions with unequal sample sizes (arcsine transformation), or the effect size, a
@@ -356,6 +385,8 @@ export interface PwrRTestResult {
356
385
  alternative: Alternative;
357
386
  /** Description of the calculation. */
358
387
  method: string;
388
+ /** R's warnings, each once, in R's order (an empty array when there are none). */
389
+ warnings: string[];
359
390
  }
360
391
  /**
361
392
  * Power of the test of a correlation (Fisher's z transformation), or the sample size, correlation or significance
@@ -404,6 +435,8 @@ export interface PwrChisqTestResult {
404
435
  method: string;
405
436
  /** A note on the sample size. */
406
437
  note: string;
438
+ /** R's warnings, each once, in R's order (an empty array when there are none). */
439
+ warnings: string[];
407
440
  }
408
441
  /**
409
442
  * Power of a chi-squared test, or the effect size, number of observations or significance level for a given power.
@@ -451,6 +484,8 @@ export interface PwrAnovaTestResult {
451
484
  note: string;
452
485
  /** Description of the calculation. */
453
486
  method: string;
487
+ /** R's warnings, each once, in R's order (an empty array when there are none). */
488
+ warnings: string[];
454
489
  }
455
490
  /**
456
491
  * Power of the F test of a balanced one-way analysis of variance, or the number of groups, sample size, effect size
@@ -496,6 +531,8 @@ export interface PwrF2TestResult {
496
531
  power: number;
497
532
  /** Description of the calculation. */
498
533
  method: string;
534
+ /** R's warnings, each once, in R's order (an empty array when there are none). */
535
+ warnings: string[];
499
536
  }
500
537
  /**
501
538
  * Power of the F test of a general linear model, or the degrees of freedom, effect size or significance level for a
package/dist/htest/pwr.js CHANGED
@@ -9,7 +9,23 @@ import { pchisq, qchisq } from "../distributions/chisq.js";
9
9
  import { pf, qf } from "../distributions/f.js";
10
10
  import { pnorm, qnorm } from "../distributions/normal.js";
11
11
  import { qt } from "../distributions/t.js";
12
- import { checkExactlyOne, isUnknown, matchChoice, ptNcp, solveFor } from "./power.js";
12
+ import { ldexp, squareOver } from "../internal/summary.js";
13
+ import { optionalArgs } from "../internal/optionalArgs.js";
14
+ import { checkExactlyOne, fPowerHugeDf, hugeDf, isUnknown, matchChoice, ptNcp, solveFor } from "./power.js";
15
+ // Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
16
+ import { checkOptions } from "../internal/checkOptions.js";
17
+ import { optionsIn } from "../internal/optionalArgs.js";
18
+ const PWR_TTEST_KEYS = ["n", "d", "type", "sigLevel", "power", "alternative"];
19
+ const PWR_T2N_TEST_KEYS = ["n1", "n2", "d", "sigLevel", "power", "alternative"];
20
+ const PWR2P_TEST_KEYS = ["h", "n", "sigLevel", "power", "alternative"];
21
+ const PWR2P2N_TEST_KEYS = ["h", "n1", "n2", "sigLevel", "power", "alternative"];
22
+ const PWR_PTEST_KEYS = ["h", "n", "sigLevel", "power", "alternative"];
23
+ const PWR_NORM_TEST_KEYS = ["d", "n", "sigLevel", "power", "alternative"];
24
+ const PWR_RTEST_KEYS = ["n", "r", "sigLevel", "power", "alternative"];
25
+ const PWR_CHISQ_TEST_KEYS = ["w", "N", "df", "sigLevel", "power"];
26
+ const PWR_ANOVA_TEST_KEYS = ["k", "n", "f", "sigLevel", "power"];
27
+ const PWR_F2_TEST_KEYS = ["u", "v", "f2", "sigLevel", "power"];
28
+ const COHEN_ES_KEYS = ["size"];
13
29
  const COHEN = {
14
30
  p: [0.2, 0.5, 0.8],
15
31
  t: [0.2, 0.5, 0.8],
@@ -18,17 +34,9 @@ const COHEN = {
18
34
  chisq: [0.1, 0.3, 0.5],
19
35
  f2: [0.02, 0.15, 0.35],
20
36
  };
21
- /**
22
- * Cohen's conventional effect sizes. Equivalent to `pwr::cohen.ES(test, size)` in R.
23
- *
24
- * @example
25
- * ```ts
26
- * cohenES("anov", "medium").effectSize; // 0.25
27
- * ```
28
- *
29
- * @category Effect sizes and power
30
- */
31
- export function cohenES(test = "p", size = "small") {
37
+ export function cohenES(test = "p", ...args) {
38
+ checkOptions(optionsIn(args), COHEN_ES_KEYS, "cohenES"); // generated: option-keys.mjs
39
+ const size = optionalArgs(["size"], args).size ?? "small";
32
40
  const t = matchChoice(test, ["p", "t", "r", "anov", "chisq", "f2"]);
33
41
  const s = matchChoice(size, ["small", "medium", "large"]);
34
42
  return { test: t, size: s, effectSize: COHEN[t][["small", "medium", "large"].indexOf(s)], method: "Conventional effect size from Cohen (1982)" };
@@ -44,6 +52,9 @@ export function cohenES(test = "p", size = "small") {
44
52
  * @category Effect sizes and power
45
53
  */
46
54
  export function esH(p1, p2) {
55
+ // (a probability outside [0, 1] gave NaN through asin)
56
+ if (!isProbability(p1) || !isProbability(p2))
57
+ throw new RangeError("p1 and p2 must be probabilities in [0, 1]");
47
58
  return 2 * Math.asin(Math.sqrt(p1)) - 2 * Math.asin(Math.sqrt(p2));
48
59
  }
49
60
  /**
@@ -59,9 +70,14 @@ export function esH(p1, p2) {
59
70
  export function esW1(p0, p1) {
60
71
  if (p0.length !== p1.length)
61
72
  throw new RangeError("'P0' and 'P1' must have the same length");
73
+ if (![...p0, ...p1].every(isProbability))
74
+ throw new RangeError("'P0' and 'P1' must be probabilities in [0, 1]");
62
75
  let s = 0;
76
+ // a cell with p0 = p1 = 0 adds nothing (0 / 0 was NaN); p0 = 0 < p1 adds Inf, as pwr. squareOver forms
77
+ // (d / sqrt(p0))^2 where d^2 underflows (esW1([1e-320, 1], [1e-200, 1]) gave 0 for 1e-40)
63
78
  for (let i = 0; i < p0.length; i++)
64
- s += (p1[i] - p0[i]) ** 2 / p0[i];
79
+ if (p0[i] !== 0 || p1[i] !== 0)
80
+ s += squareOver(p1[i] - p0[i], p0[i]);
65
81
  return Math.sqrt(s);
66
82
  }
67
83
  /**
@@ -76,6 +92,12 @@ export function esW1(p0, p1) {
76
92
  * @category Effect sizes and power
77
93
  */
78
94
  export function esW2(p) {
95
+ // (an empty matrix gave 0, a ragged one NaN)
96
+ if (p.length === 0 || p[0].length === 0 || p.some((r) => r.length !== p[0].length)) {
97
+ throw new RangeError("'P' must be a non-empty matrix (rows of the same length)");
98
+ }
99
+ if (!p.every((r) => r.every(isProbability)))
100
+ throw new RangeError("'P' must contain probabilities in [0, 1]");
79
101
  const rows = p.map((r) => r.reduce((a, b) => a + b, 0));
80
102
  const nc = p[0]?.length ?? 0;
81
103
  const cols = Array.from({ length: nc }, (_, j) => p.reduce((a, r) => a + r[j], 0));
@@ -84,11 +106,25 @@ export function esW2(p) {
84
106
  for (let j = 0; j < nc; j++) {
85
107
  for (let i = 0; i < p.length; i++) {
86
108
  const p0 = rows[i] * cols[j];
87
- s += (p[i][j] - p0) ** 2 / p0;
109
+ // (a cell of an empty row or column, p0 = p = 0, adds nothing: 0 / 0 was NaN)
110
+ if (p0 === 0 && p[i][j] === 0)
111
+ continue;
112
+ if (p0 >= MIN_NORMAL)
113
+ s += squareOver(p[i][j] - p0, p0);
114
+ else {
115
+ // (p0 below the normal range, with a row and column sum not 0: (p / sqrt(r c) - sqrt(r c))^2 from the square
116
+ // roots of the sums, as r c may round or underflow to 0; esW2([[1e-200, 0], [0, 1]]) gave NaN for 1)
117
+ const sr = Math.sqrt(rows[i]);
118
+ const sc = Math.sqrt(cols[j]);
119
+ const z = p[i][j] / sr / sc - sr * sc;
120
+ s += z * z;
121
+ }
88
122
  }
89
123
  }
90
124
  return Math.sqrt(s);
91
125
  }
126
+ const MIN_NORMAL = 2 ** -1022;
127
+ const isProbability = (v) => v >= 0 && v <= 1;
92
128
  const SIG_MESSAGE = "‘sig.level’ must be numeric in [0, 1]";
93
129
  const POWER_MESSAGE = "‘power’ must be numeric in [0, 1]";
94
130
  function checkProbabilities(sigLevel, power) {
@@ -100,6 +136,9 @@ function checkProbabilities(sigLevel, power) {
100
136
  }
101
137
  /** A string effect size replaced by Cohen's value for the test */
102
138
  function effect(es, test) {
139
+ // (NaN gave a NaN power silently; pwr stops on it in most functions)
140
+ if (typeof es === "number" && Number.isNaN(es))
141
+ throw new RangeError("the effect size must not be NaN");
103
142
  return typeof es === "string" ? cohenES(test, es).effectSize : es;
104
143
  }
105
144
  const ALTERNATIVES = ["two.sided", "less", "greater"];
@@ -116,13 +155,31 @@ function tPower(nu, ncp, sig, alt) {
116
155
  const q = qt(sig / 2, nu, { lowerTail: false });
117
156
  return ptNcp(q, nu, ncp, false) + ptNcp(-q, nu, ncp, true);
118
157
  }
158
+ /**
159
+ * The upper critical value qnorm(1 - a): for a < 1e-8 the quantile of the upper tail a (1 - a loses digits, and rounds to
160
+ * 1 below 1.1e-16: sigLevel 1e-20 gave a power of 1e-30 for 2.7e-13), as for the confidence levels close to 1 elsewhere
161
+ */
162
+ const upperCritical = (a) => (a < 1e-8 ? qnorm(a, { lowerTail: false }) : qnorm(1 - a));
119
163
  /** The power of a normal test with shift `es * scale`, by pwr's rejection regions */
120
164
  function normalPower(shift, sig, alt) {
121
165
  if (alt === "greater")
122
- return pnorm(qnorm(1 - sig) - shift, { lowerTail: false });
166
+ return pnorm(upperCritical(sig) - shift, { lowerTail: false });
123
167
  if (alt === "less")
124
168
  return pnorm(qnorm(sig) - shift);
125
- return (pnorm(qnorm(1 - sig / 2) - shift, { lowerTail: false }) + pnorm(qnorm(sig / 2) - shift));
169
+ return pnorm(upperCritical(sig / 2) - shift, { lowerTail: false }) + pnorm(qnorm(sig / 2) - shift);
170
+ }
171
+ /** The product of finite factors, each scaled to [1, 2) by a power of 2 and the exponents added back at the end */
172
+ function scaledProduct(xs) {
173
+ let v = 1;
174
+ let e = 0;
175
+ for (const x of xs) {
176
+ if (x === 0)
177
+ return 0;
178
+ const k = Math.floor(Math.log2(Math.abs(x)));
179
+ v *= ldexp(x, -k);
180
+ e += k;
181
+ }
182
+ return ldexp(v, e);
126
183
  }
127
184
  /**
128
185
  * Power of a t test of means, or the sample size, effect size or significance level for a given power.
@@ -137,11 +194,14 @@ function normalPower(shift, sig, alt) {
137
194
  * @category Effect sizes and power
138
195
  */
139
196
  export function pwrTTest(options = {}) {
197
+ checkOptions(options, PWR_TTEST_KEYS, "pwrTTest"); // generated: option-keys.mjs
140
198
  let { n, power } = options;
141
199
  let d = effect(options.d, "t");
142
200
  let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
143
201
  checkExactlyOne([n, d, power, sigLevel], "exactly one of n, d, power, and sig.level must be NULL");
144
202
  checkProbabilities(sigLevel, power);
203
+ if (!isUnknown(n) && !(n >= 2))
204
+ throw new RangeError("number of observations in each group must be at least 2");
145
205
  const type = matchChoice(options.type, ["two.sample", "one.sample", "paired"]);
146
206
  const alt = matchChoice(options.alternative, ALTERNATIVES);
147
207
  const ts = type === "two.sample" ? 2 : 1;
@@ -161,7 +221,7 @@ export function pwrTTest(options = {}) {
161
221
  }
162
222
  const note = type === "paired" ? "n is number of *pairs*" : type === "two.sample" ? "n is number in *each* group" : undefined;
163
223
  const method = { "two.sample": "Two-sample", "one.sample": "One-sample", paired: "Paired" }[type] + " t test power calculation";
164
- return { n: n, d: d, sigLevel: sigLevel, power, alternative: alt, ...(note === undefined ? {} : { note }), method };
224
+ return { n: n, d: d, sigLevel: sigLevel, power, alternative: alt, ...(note === undefined ? {} : { note }), method, warnings: [] };
165
225
  }
166
226
  /**
167
227
  * Power of a two-sample t test with unequal sample sizes, or a sample size, the effect size or the significance
@@ -176,14 +236,15 @@ export function pwrTTest(options = {}) {
176
236
  * @category Effect sizes and power
177
237
  */
178
238
  export function pwrT2nTest(options = {}) {
239
+ checkOptions(options, PWR_T2N_TEST_KEYS, "pwrT2nTest"); // generated: option-keys.mjs
179
240
  let { n1, n2, power } = options;
180
241
  let d = effect(options.d, "t");
181
242
  let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
182
243
  checkExactlyOne([n1, n2, d, power, sigLevel], "exactly one of n1, n2, d, power, and sig.level must be NULL");
183
244
  checkProbabilities(sigLevel, power);
184
- if (!isUnknown(n1) && n1 < 2)
245
+ if (!isUnknown(n1) && !(n1 >= 2))
185
246
  throw new RangeError("number of observations in the first group must be at least 2");
186
- if (!isUnknown(n2) && n2 < 2)
247
+ if (!isUnknown(n2) && !(n2 >= 2))
187
248
  throw new RangeError("number of observations in the second group must be at least 2");
188
249
  const alt = matchChoice(options.alternative, ALTERNATIVES);
189
250
  if (alt === "two.sided" && !isUnknown(d))
@@ -202,7 +263,7 @@ export function pwrT2nTest(options = {}) {
202
263
  else
203
264
  sigLevel = solveFor((x) => powerOf(n1, n2, d, x) - target, 1e-10, 1 - 1e-10);
204
265
  }
205
- return { n1: n1, n2: n2, d: d, sigLevel: sigLevel, power, alternative: alt, method: "t test power calculation" };
266
+ return { n1: n1, n2: n2, d: d, sigLevel: sigLevel, power, alternative: alt, method: "t test power calculation", warnings: [] };
206
267
  }
207
268
  /** The normal-approximation tests: pwr.2p.test (scale sqrt(n/2)), pwr.p.test and pwr.norm.test (sqrt(n)) */
208
269
  function normalTest(es0, options, name, scale, nLower, esLower) {
@@ -211,7 +272,7 @@ function normalTest(es0, options, name, scale, nLower, esLower) {
211
272
  let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
212
273
  checkExactlyOne([es, n, power, sigLevel], `exactly one of ${name}, n, power, and sig.level must be NULL`);
213
274
  checkProbabilities(sigLevel, power);
214
- if (!isUnknown(n) && n < 1)
275
+ if (!isUnknown(n) && !(n >= 1))
215
276
  throw new RangeError("number of observations in each group must be at least 1");
216
277
  const alt = matchChoice(options.alternative, ALTERNATIVES);
217
278
  if (alt === "two.sided" && !isUnknown(es))
@@ -243,6 +304,7 @@ function normalTest(es0, options, name, scale, nLower, esLower) {
243
304
  * @category Effect sizes and power
244
305
  */
245
306
  export function pwr2pTest(options = {}) {
307
+ checkOptions(options, PWR2P_TEST_KEYS, "pwr2pTest"); // generated: option-keys.mjs
246
308
  const r = normalTest(options.h, options, "h", (n) => Math.sqrt(n / 2), 2 + 1e-10, 1e-10);
247
309
  return {
248
310
  h: r.es,
@@ -252,6 +314,7 @@ export function pwr2pTest(options = {}) {
252
314
  alternative: r.alternative,
253
315
  method: "Difference of proportion power calculation for binomial distribution (arcsine transformation)",
254
316
  note: "same sample sizes",
317
+ warnings: [],
255
318
  };
256
319
  }
257
320
  /**
@@ -267,6 +330,7 @@ export function pwr2pTest(options = {}) {
267
330
  * @category Effect sizes and power
268
331
  */
269
332
  export function pwrPTest(options = {}) {
333
+ checkOptions(options, PWR_PTEST_KEYS, "pwrPTest"); // generated: option-keys.mjs
270
334
  const r = normalTest(options.h, options, "h", (n) => Math.sqrt(n), 2 + 1e-10, 1e-10);
271
335
  return {
272
336
  h: r.es,
@@ -275,6 +339,7 @@ export function pwrPTest(options = {}) {
275
339
  power: r.power,
276
340
  alternative: r.alternative,
277
341
  method: "proportion power calculation for binomial distribution (arcsine transformation)",
342
+ warnings: [],
278
343
  };
279
344
  }
280
345
  /**
@@ -290,6 +355,7 @@ export function pwrPTest(options = {}) {
290
355
  * @category Effect sizes and power
291
356
  */
292
357
  export function pwrNormTest(options = {}) {
358
+ checkOptions(options, PWR_NORM_TEST_KEYS, "pwrNormTest"); // generated: option-keys.mjs
293
359
  const r = normalTest(options.d, options, "d", (n) => Math.sqrt(n), 1 + 1e-10, 1e-10);
294
360
  return {
295
361
  d: r.es,
@@ -298,6 +364,7 @@ export function pwrNormTest(options = {}) {
298
364
  power: r.power,
299
365
  alternative: r.alternative,
300
366
  method: "Mean power calculation for normal distribution with known variance",
367
+ warnings: [],
301
368
  };
302
369
  }
303
370
  /**
@@ -313,19 +380,29 @@ export function pwrNormTest(options = {}) {
313
380
  * @category Effect sizes and power
314
381
  */
315
382
  export function pwr2p2nTest(options = {}) {
383
+ checkOptions(options, PWR2P2N_TEST_KEYS, "pwr2p2nTest"); // generated: option-keys.mjs
316
384
  let { n1, n2, power } = options;
317
385
  let h = effect(options.h, "p");
318
386
  let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
319
387
  checkExactlyOne([h, n1, n2, power, sigLevel], "exactly one of h, n1, n2, power, and sig.level must be NULL");
320
388
  checkProbabilities(sigLevel, power);
321
- if (!isUnknown(n1) && n1 < 2)
389
+ if (!isUnknown(n1) && !(n1 >= 2))
322
390
  throw new RangeError("number of observations in the first group must be at least 2");
323
- if (!isUnknown(n2) && n2 < 2)
391
+ if (!isUnknown(n2) && !(n2 >= 2))
324
392
  throw new RangeError("number of observations in the second group must be at least 2");
325
393
  const alt = matchChoice(options.alternative, ALTERNATIVES);
326
394
  if (alt === "two.sided" && !isUnknown(h))
327
395
  h = Math.abs(h);
328
- const powerOf = (h, n1, n2, sig) => normalPower(h * Math.sqrt((n1 * n2) / (n1 + n2)), sig, alt);
396
+ // the effective size n1 n2 / (n1 + n2); where the product overflows (finite sizes above about 1e154) as
397
+ // a / (1 + a/b) with a <= b (the same bits elsewhere; pwr gives power 1 there)
398
+ const effectiveN = (n1, n2) => {
399
+ const prod = n1 * n2;
400
+ if (Number.isFinite(prod) || !Number.isFinite(n1) || !Number.isFinite(n2))
401
+ return prod / (n1 + n2);
402
+ const a = Math.min(n1, n2);
403
+ return a / (1 + a / Math.max(n1, n2));
404
+ };
405
+ const powerOf = (h, n1, n2, sig) => normalPower(h * Math.sqrt(effectiveN(n1, n2)), sig, alt);
329
406
  if (isUnknown(power))
330
407
  power = powerOf(h, n1, n2, sigLevel);
331
408
  else {
@@ -348,6 +425,7 @@ export function pwr2p2nTest(options = {}) {
348
425
  alternative: alt,
349
426
  method: "difference of proportion power calculation for binomial distribution (arcsine transformation)",
350
427
  note: "different sample sizes",
428
+ warnings: [],
351
429
  };
352
430
  }
353
431
  /**
@@ -364,19 +442,26 @@ export function pwr2p2nTest(options = {}) {
364
442
  * @category Effect sizes and power
365
443
  */
366
444
  export function pwrRTest(options = {}) {
445
+ checkOptions(options, PWR_RTEST_KEYS, "pwrRTest"); // generated: option-keys.mjs
367
446
  let { n, power } = options;
368
447
  let r = effect(options.r, "r");
369
448
  let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
370
449
  checkExactlyOne([n, r, power, sigLevel], "exactly one of n, r, power, and sig.level must be NULL");
371
450
  checkProbabilities(sigLevel, power);
372
- if (!isUnknown(n) && n < 4)
451
+ if (!isUnknown(n) && !(n >= 4))
373
452
  throw new RangeError("number of observations must be at least 4");
453
+ // (a correlation outside [-1, 1] gave NaN through atanh)
454
+ if (!isUnknown(r) && !(Math.abs(r) <= 1))
455
+ throw new RangeError("'r' must be in [-1, 1]");
374
456
  const alt = matchChoice(options.alternative, ALTERNATIVES);
375
457
  if (alt === "two.sided" && !isUnknown(r))
376
458
  r = Math.abs(r);
377
459
  const upper = (n, r, sig, twoSided) => {
378
460
  const t = qt(twoSided ? sig / 2 : sig, n - 2, { lowerTail: false });
379
- const rc = Math.sqrt(t ** 2 / (t ** 2 + n - 2));
461
+ const den = t ** 2 + n - 2;
462
+ // (where t^2 + n - 2 overflows for a finite t, 1 / sqrt(1 + ((n - 2) / t) / t): Inf / Inf gave NaN, as
463
+ // pwrRTest({ n: 4, r: 0.5, sigLevel: 1e-320 }) with t = 7e159)
464
+ const rc = den === Infinity && Number.isFinite(t) ? 1 / Math.sqrt(1 + (n - 2) / t / t) : Math.sqrt(t ** 2 / den);
380
465
  const zr = Math.atanh(r) + r / (2 * (n - 1));
381
466
  const zrc = Math.atanh(rc);
382
467
  const p = pnorm((zr - zrc) * Math.sqrt(n - 3));
@@ -406,6 +491,7 @@ export function pwrRTest(options = {}) {
406
491
  power,
407
492
  alternative: alt,
408
493
  method: "approximate correlation power calculation (arctangh transformation)",
494
+ warnings: [],
409
495
  };
410
496
  }
411
497
  /**
@@ -421,6 +507,7 @@ export function pwrRTest(options = {}) {
421
507
  * @category Effect sizes and power
422
508
  */
423
509
  export function pwrChisqTest(options) {
510
+ checkOptions(options, PWR_CHISQ_TEST_KEYS, "pwrChisqTest"); // generated: option-keys.mjs
424
511
  let { N, power } = options;
425
512
  const { df } = options;
426
513
  let w = effect(options.w, "chisq");
@@ -428,12 +515,18 @@ export function pwrChisqTest(options) {
428
515
  checkExactlyOne([w, N, power, sigLevel], "exactly one of w, N, power, and sig.level must be NULL");
429
516
  if (typeof df !== "number")
430
517
  throw new TypeError('argument "df" is missing, with no default');
518
+ if (!(df > 0 && df < Infinity))
519
+ throw new RangeError("'df' must be a positive finite number");
431
520
  checkProbabilities(sigLevel, power);
432
- if (!isUnknown(w) && w < 0)
521
+ if (!isUnknown(w) && !(w >= 0))
433
522
  throw new RangeError("w must be positive");
434
- if (!isUnknown(N) && N < 1)
523
+ if (!isUnknown(N) && !(N >= 1))
435
524
  throw new RangeError("number of observations must be at least 1");
436
- const powerOf = (w, N, sig) => pchisq(qchisq(sig, df, { lowerTail: false }), df, { ncp: N * w ** 2, lowerTail: false });
525
+ // a noncentrality beyond the doubles: the power is its limit 1 (NaN from the distribution with ncp = Inf)
526
+ const powerOf = (w, N, sig) => {
527
+ const ncp = N * w ** 2;
528
+ return ncp === Infinity ? 1 : pchisq(qchisq(sig, df, { lowerTail: false }), df, { ncp, lowerTail: false });
529
+ };
437
530
  if (isUnknown(power))
438
531
  power = powerOf(w, N, sigLevel);
439
532
  else {
@@ -445,7 +538,7 @@ export function pwrChisqTest(options) {
445
538
  else
446
539
  sigLevel = solveFor((x) => powerOf(w, N, x) - target, 1e-10, 1 - 1e-10);
447
540
  }
448
- return { w: w, N: N, df, sigLevel: sigLevel, power, method: "Chi squared power calculation", note: "N is the number of observations" };
541
+ return { w: w, N: N, df, sigLevel: sigLevel, power, method: "Chi squared power calculation", note: "N is the number of observations", warnings: [] };
449
542
  }
450
543
  /**
451
544
  * Power of the F test of a balanced one-way analysis of variance, or the number of groups, sample size, effect size
@@ -460,21 +553,33 @@ export function pwrChisqTest(options) {
460
553
  * @category Effect sizes and power
461
554
  */
462
555
  export function pwrAnovaTest(options = {}) {
556
+ checkOptions(options, PWR_ANOVA_TEST_KEYS, "pwrAnovaTest"); // generated: option-keys.mjs
463
557
  let { k, n, power } = options;
464
558
  let f = effect(options.f, "anov");
465
559
  let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
466
560
  checkExactlyOne([k, n, f, power, sigLevel], "exactly one of k, n, f, power, and sig.level must be NULL");
467
561
  checkProbabilities(sigLevel, power);
468
- if (!isUnknown(f) && f < 0)
562
+ if (!isUnknown(f) && !(f >= 0))
469
563
  throw new RangeError("f must be positive");
470
- if (!isUnknown(k) && k < 2)
564
+ if (!isUnknown(k) && !(k >= 2))
471
565
  throw new RangeError("number of groups must be at least 2");
472
- if (!isUnknown(n) && n < 2)
566
+ if (!isUnknown(n) && !(n >= 2))
473
567
  throw new RangeError("number of observations in each group must be at least 2");
474
568
  const powerOf = (k, n, f, sig) => {
475
569
  const df1 = k - 1;
476
570
  const df2 = (n - 1) * k;
477
- return pf(qf(sig, df1, df2, { lowerTail: false }), df1, df2, { ncp: k * n * f ** 2, lowerTail: false });
571
+ let ncp = k * n * f ** 2;
572
+ // (where k n overflows or f^2 underflows for finite factors, from the factors scaled by powers of 2: k = n = 1e160,
573
+ // f = 1e-160 gave the limit 1 for the noncentrality 1)
574
+ if (!Number.isFinite(ncp) && Number.isFinite(k) && Number.isFinite(n) && Number.isFinite(f))
575
+ ncp = scaledProduct([k, n, f, f]);
576
+ // (a noncentrality beyond the doubles: the limit 1)
577
+ if (ncp === Infinity)
578
+ return 1;
579
+ // (both degrees of freedom above 1e16: the normal approximation, the critical value being 1 to a few digits; R NaN)
580
+ if (hugeDf(df1, df2))
581
+ return fPowerHugeDf(df1, df2, ncp, sig);
582
+ return pf(qf(sig, df1, df2, { lowerTail: false }), df1, df2, { ncp, lowerTail: false });
478
583
  };
479
584
  if (isUnknown(power))
480
585
  power = powerOf(k, n, f, sigLevel);
@@ -497,6 +602,7 @@ export function pwrAnovaTest(options = {}) {
497
602
  power,
498
603
  note: "n is number in each group",
499
604
  method: "Balanced one-way analysis of variance power calculation",
605
+ warnings: [],
500
606
  };
501
607
  }
502
608
  /**
@@ -512,18 +618,32 @@ export function pwrAnovaTest(options = {}) {
512
618
  * @category Effect sizes and power
513
619
  */
514
620
  export function pwrF2Test(options = {}) {
621
+ checkOptions(options, PWR_F2_TEST_KEYS, "pwrF2Test"); // generated: option-keys.mjs
515
622
  let { u, v, power } = options;
516
623
  let f2 = effect(options.f2, "f2");
517
624
  let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
518
625
  checkExactlyOne([u, v, f2, power, sigLevel], "exactly one of u, v, f2, power, and sig.level must be NULL");
519
626
  checkProbabilities(sigLevel, power);
520
- if (!isUnknown(f2) && f2 < 0)
627
+ if (!isUnknown(f2) && !(f2 >= 0))
521
628
  throw new RangeError("f2 must be positive");
522
- if (!isUnknown(u) && u < 1)
629
+ if (!isUnknown(u) && !(u >= 1))
523
630
  throw new RangeError("degree of freedom u for numerator must be at least 1");
524
- if (!isUnknown(v) && v < 1)
631
+ if (!isUnknown(v) && !(v >= 1))
525
632
  throw new RangeError("degree of freedom v for denominator must be at least 1");
526
- const powerOf = (u, v, f2, sig) => pf(qf(sig, u, v, { lowerTail: false }), u, v, { ncp: f2 * (u + v + 1), lowerTail: false });
633
+ // a noncentrality beyond the doubles: the power is its limit 1
634
+ const powerOf = (u, v, f2, sig) => {
635
+ let ncp = f2 * (u + v + 1);
636
+ // (where u + v overflows for finite degrees of freedom, from the halves: u = v = 1e308, f2 = 1e-308 gave the limit 1
637
+ // for the noncentrality 2)
638
+ if (!Number.isFinite(ncp) && Number.isFinite(u) && Number.isFinite(v) && Number.isFinite(f2))
639
+ ncp = 2 * (f2 * (u / 2 + v / 2 + 0.5));
640
+ if (ncp === Infinity)
641
+ return 1;
642
+ // (both degrees of freedom above 1e16: the normal approximation, the critical value being 1 to a few digits; R NaN)
643
+ if (hugeDf(u, v))
644
+ return fPowerHugeDf(u, v, ncp, sig);
645
+ return pf(qf(sig, u, v, { lowerTail: false }), u, v, { ncp, lowerTail: false });
646
+ };
527
647
  if (isUnknown(power))
528
648
  power = powerOf(u, v, f2, sigLevel);
529
649
  else {
@@ -537,5 +657,5 @@ export function pwrF2Test(options = {}) {
537
657
  else
538
658
  sigLevel = solveFor((x) => powerOf(u, v, f2, x) - target, 1e-10, 1 - 1e-10);
539
659
  }
540
- return { u: u, v: v, f2: f2, sigLevel: sigLevel, power, method: "Multiple regression power calculation" };
660
+ return { u: u, v: v, f2: f2, sigLevel: sigLevel, power, method: "Multiple regression power calculation", warnings: [] };
541
661
  }