@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
@@ -7,8 +7,15 @@ import { d0, dt0, dt1, quantileBoundaries } from "../internal/dpq.js";
7
7
  import { discreteQuantile } from "../internal/discrete.js";
8
8
  import { gammaInc } from "../special/igam.js";
9
9
  import { dpoisRaw } from "../special/loader.js";
10
+ import { logAddExp, logSubExp } from "../internal/ddexp.js";
10
11
  import { qnorm } from "./normal.js";
11
- import { nonInt } from "../internal/integer.js";
12
+ import { countAtMost, nonInt } from "../internal/integer.js";
13
+ // Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
14
+ import { checkOptions } from "../internal/checkOptions.js";
15
+ const DPOIS_KEYS = ["log"];
16
+ const PPOIS_KEYS = ["lowerTail", "logP"];
17
+ const QPOIS_KEYS = ["lowerTail", "logP"];
18
+ // Generated by `node scripts/option-keys.mjs --write` (end)
12
19
  /** Whether x is not an integer (relative tolerance 1e-9 as in R; see src/internal/integer.ts) */
13
20
  export const nonInteger = nonInt;
14
21
  export function dpois1(x, lambda, log) {
@@ -33,7 +40,30 @@ export function ppois1(q, lambda, lowerTail, logP) {
33
40
  return dt1(lowerTail, logP);
34
41
  if (!Number.isFinite(q))
35
42
  return dt1(lowerTail, logP);
36
- const x = Math.floor(q + 1e-7);
43
+ const x = countAtMost(q);
44
+ if (x + 1 - x === 1)
45
+ return gammaInc(x + 1, lambda, !lowerTail, logP);
46
+ // Beyond 2^53, x + 1 rounds (to x, or up to x + 2) and Q(x + 1, lambda) became Q(x, lambda): ppois(1e16, 1e16) was 0.4999999987, below
47
+ // 1/2 (R: 0.5000000027), and qpois(0.5, 1e16) 2 above the median 1e16. Without x + 1:
48
+ // P[X <= x] = Q(x, lambda) + dpois(x, lambda), P[X > x] = P(x, lambda) - dpois(x, lambda)
49
+ let v;
50
+ let term;
51
+ if (!logP) {
52
+ const t = gammaInc(x, lambda, !lowerTail, false);
53
+ term = dpoisRaw(x, lambda, false);
54
+ v = lowerTail ? t + term : t - term;
55
+ }
56
+ else {
57
+ const lt = gammaInc(x, lambda, !lowerTail, true);
58
+ term = dpoisRaw(x, lambda, true);
59
+ v = lowerTail ? logAddExp(lt, term) : logSubExp(lt, term);
60
+ }
61
+ if (Number.isNaN(term))
62
+ return NaN;
63
+ // The upper tail as a difference: where dpois is not resolved against it (deep tails, where both logs round to the
64
+ // same value), one unit of x is below the resolution of the result, and the rounded x + 1 serves (round 55)
65
+ if (lowerTail || (logP ? Number.isFinite(v) : v > 0))
66
+ return v;
37
67
  return gammaInc(x + 1, lambda, !lowerTail, logP);
38
68
  }
39
69
  export function qpois1(p, lambda, lowerTail, logP) {
@@ -54,7 +84,8 @@ export function qpois1(p, lambda, lowerTail, logP) {
54
84
  p,
55
85
  lowerTail,
56
86
  logP,
57
- cdf: (y, l, lg) => gammaInc(y + 1, lambda, !l, lg),
87
+ // (through ppois1, which also holds beyond 2^53 where y + 1 rounds to y)
88
+ cdf: (y, l, lg) => ppois1(y, lambda, l, lg),
58
89
  y0: Number.isFinite(y0) ? y0 : lambda,
59
90
  lo: 0,
60
91
  hi: Infinity,
@@ -77,6 +108,7 @@ export function qpois1(p, lambda, lowerTail, logP) {
77
108
  * @category Distributions
78
109
  */
79
110
  export function dpois(x, lambda, options = {}) {
111
+ checkOptions(options, DPOIS_KEYS, "dpois"); // generated: option-keys.mjs
80
112
  const log = options.log ?? false;
81
113
  return vectorize(x, (v) => dpois1(v, lambda, log));
82
114
  }
@@ -97,6 +129,7 @@ export function dpois(x, lambda, options = {}) {
97
129
  * @category Distributions
98
130
  */
99
131
  export function ppois(q, lambda, options = {}) {
132
+ checkOptions(options, PPOIS_KEYS, "ppois"); // generated: option-keys.mjs
100
133
  const { lowerTail = true, logP = false } = options;
101
134
  return vectorize(q, (v) => ppois1(v, lambda, lowerTail, logP));
102
135
  }
@@ -117,6 +150,7 @@ export function ppois(q, lambda, options = {}) {
117
150
  * @category Distributions
118
151
  */
119
152
  export function qpois(p, lambda, options = {}) {
153
+ checkOptions(options, QPOIS_KEYS, "qpois"); // generated: option-keys.mjs
120
154
  const { lowerTail = true, logP = false } = options;
121
155
  return vectorize(p, (v) => qpois1(v, lambda, lowerTail, logP));
122
156
  }
@@ -8,8 +8,14 @@
8
8
  import { vectorize } from "../internal/vectorize.js";
9
9
  import { d0, dt0, dt1, quantileBoundaries } from "../internal/dpq.js";
10
10
  import { discreteQuantile } from "../internal/discrete.js";
11
- import { nonInt, roundHalfEven } from "../internal/integer.js";
11
+ import { countAtMost, nonInt, roundHalfEven } from "../internal/integer.js";
12
12
  import { qnorm } from "./normal.js";
13
+ // Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
14
+ import { checkOptions } from "../internal/checkOptions.js";
15
+ const DSIGNRANK_KEYS = ["log"];
16
+ const PSIGNRANK_KEYS = ["lowerTail", "logP"];
17
+ const QSIGNRANK_KEYS = ["lowerTail", "logP"];
18
+ // Generated by `node scripts/option-keys.mjs --write` (end)
13
19
  /** Threshold at which counts are multiplied by 2^-SCALE_STEP to keep them from growing too large */
14
20
  const SCALE_LIMIT = 2 ** 900;
15
21
  const SCALE_STEP = -900;
@@ -152,7 +158,9 @@ function signrankN(n) {
152
158
  if (!Number.isFinite(n))
153
159
  return NaN;
154
160
  n = roundHalfEven(n);
155
- return n <= 0 ? NaN : n;
161
+ // The statistic ranges over 0..n(n + 1)/2: beyond 2^53 its values are not all doubles (NaN, as wilcox), and the
162
+ // rounded n(n + 1)/2 was taken as the end of the support. n(n + 1)/2 <= 2^53 exactly when n < 2^27
163
+ return n <= 0 || n >= 2 ** 27 ? NaN : n;
156
164
  }
157
165
  export function dsignrank1(x, n, log) {
158
166
  if (Number.isNaN(x) || Number.isNaN(n))
@@ -193,8 +201,9 @@ export function psignrank1(q, n, lowerTail, logP) {
193
201
  n = signrankN(n);
194
202
  if (Number.isNaN(n))
195
203
  return NaN;
196
- // R rounds q + 1e-7 to the nearest integer (psignrank(3.6, 5) is P[V <= 4])
197
- const x = roundHalfEven(q + 1e-7);
204
+ // R rounds q + 1e-7 to the nearest integer (psignrank(3.6, 5) is P[V <= 4], although V <= 3.6 is V <= 3). The
205
+ // largest count not above q, as the other discrete distribution functions (#145, #146)
206
+ const x = countAtMost(q);
198
207
  const total = (n * (n + 1)) / 2;
199
208
  if (x < 0)
200
209
  return dt0(lowerTail, logP);
@@ -244,6 +253,7 @@ export function qsignrank1(p, n, lowerTail, logP) {
244
253
  * @category Distributions
245
254
  */
246
255
  export function dsignrank(x, n, options = {}) {
256
+ checkOptions(options, DSIGNRANK_KEYS, "dsignrank"); // generated: option-keys.mjs
247
257
  const log = options.log ?? false;
248
258
  return vectorize(x, (v) => dsignrank1(v, n, log));
249
259
  }
@@ -266,6 +276,7 @@ export function dsignrank(x, n, options = {}) {
266
276
  * @category Distributions
267
277
  */
268
278
  export function psignrank(q, n, options = {}) {
279
+ checkOptions(options, PSIGNRANK_KEYS, "psignrank"); // generated: option-keys.mjs
269
280
  const { lowerTail = true, logP = false } = options;
270
281
  return vectorize(q, (v) => psignrank1(v, n, lowerTail, logP));
271
282
  }
@@ -288,6 +299,7 @@ export function psignrank(q, n, options = {}) {
288
299
  * @category Distributions
289
300
  */
290
301
  export function qsignrank(p, n, options = {}) {
302
+ checkOptions(options, QSIGNRANK_KEYS, "qsignrank"); // generated: option-keys.mjs
291
303
  const { lowerTail = true, logP = false } = options;
292
304
  return vectorize(p, (v) => qsignrank1(v, n, lowerTail, logP));
293
305
  }
@@ -28,7 +28,8 @@ export type DistName = "norm" | "lnorm" | "unif" | "exp" | "gamma" | "chisq" | "
28
28
  /**
29
29
  * Mean, variance, standard deviation, median, mode, skewness and excess kurtosis of a distribution, given by the
30
30
  * name of its d/p/q/r functions and their parameters (with the same names and defaults; `gamma` takes `rate` or
31
- * `scale`, `nbinom` takes `prob` or `mu`). Invalid parameters give NaN throughout.
31
+ * `scale`, `nbinom` takes `prob` or `mu`). Invalid parameters give NaN throughout. The distributions are the central
32
+ * ones: `ncp` of `chisq`, `beta`, `t` and `f` is not taken (an unknown key, a RangeError).
32
33
  * Not an R function. R has no function for these summaries; the R references are closed forms checked against
33
34
  * numerical moments.
34
35
  *