@numero-uno-jpn/rstats 0.15.2 → 0.16.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 (297) hide show
  1. package/CHANGELOG.md +280 -0
  2. package/README.ja.md +40 -33
  3. package/README.md +36 -28
  4. package/dist/chunks/chunk-2D2IQWUQ.js +2 -0
  5. package/dist/chunks/chunk-5UQCRBAG.js +2 -0
  6. package/dist/chunks/chunk-6CSTWA5E.js +2 -0
  7. package/dist/chunks/chunk-72Y3HZID.js +2 -0
  8. package/dist/chunks/chunk-BG2KLEHM.js +2 -0
  9. package/dist/chunks/chunk-CMEKBNHQ.js +2 -0
  10. package/dist/chunks/chunk-FLJNSXSW.js +2 -0
  11. package/dist/chunks/chunk-GM53LWSR.js +2 -0
  12. package/dist/chunks/chunk-JBCA56ZS.js +3 -0
  13. package/dist/chunks/chunk-K3RJAD2T.js +2 -0
  14. package/dist/chunks/chunk-KAZRWIB5.js +2 -0
  15. package/dist/chunks/chunk-KBVVIMXX.js +3 -0
  16. package/dist/chunks/chunk-N3SIFCZX.js +2 -0
  17. package/dist/chunks/chunk-QNNL7AZ3.js +2 -0
  18. package/dist/chunks/chunk-SC6CV4Z3.js +2 -0
  19. package/dist/chunks/chunk-SYWOBOTR.js +2 -0
  20. package/dist/chunks/chunk-URIO5LY5.js +2 -0
  21. package/dist/chunks/chunk-VTUGG2SV.js +2 -0
  22. package/dist/chunks/chunk-W26LRYOJ.js +2 -0
  23. package/dist/chunks/chunk-XHETEYVC.js +2 -0
  24. package/dist/chunks/{chunk-PWVQVJTP.js → chunk-YRZWONZB.js} +1 -1
  25. package/dist/chunks/chunk-ZGABZMWX.js +2 -0
  26. package/dist/data/grouping.js +20 -5
  27. package/dist/descriptive/basic.js +90 -8
  28. package/dist/descriptive/cov.js +12 -4
  29. package/dist/descriptive/dataFrames.d.ts +4 -2
  30. package/dist/descriptive/dataFrames.js +56 -18
  31. package/dist/descriptive/factanal.js +16 -7
  32. package/dist/descriptive/hist.d.ts +8 -5
  33. package/dist/descriptive/hist.js +71 -31
  34. package/dist/descriptive/missing.js +3 -1
  35. package/dist/descriptive/moments.js +72 -19
  36. package/dist/descriptive/omega.d.ts +1 -1
  37. package/dist/descriptive/omega.js +68 -9
  38. package/dist/descriptive/pivot.d.ts +21 -9
  39. package/dist/descriptive/pivot.js +161 -35
  40. package/dist/descriptive/quantile.js +2 -1
  41. package/dist/descriptive/rank.js +4 -1
  42. package/dist/descriptive/table.d.ts +3 -2
  43. package/dist/descriptive/table.js +24 -9
  44. package/dist/descriptive.js +2 -2
  45. package/dist/distributions/arcsine.js +19 -2
  46. package/dist/distributions/beta.js +35 -5
  47. package/dist/distributions/binomial.js +37 -14
  48. package/dist/distributions/bvnorm.js +11 -2
  49. package/dist/distributions/cauchy.js +87 -8
  50. package/dist/distributions/chisq.js +7 -3
  51. package/dist/distributions/exponential.js +11 -1
  52. package/dist/distributions/f.js +73 -22
  53. package/dist/distributions/gamma.js +61 -6
  54. package/dist/distributions/geometric.js +53 -14
  55. package/dist/distributions/hypergeometric.d.ts +5 -1
  56. package/dist/distributions/hypergeometric.js +93 -6
  57. package/dist/distributions/invgamma.js +6 -1
  58. package/dist/distributions/kumaraswamy.js +22 -4
  59. package/dist/distributions/laplace.js +31 -7
  60. package/dist/distributions/logistic.js +11 -2
  61. package/dist/distributions/lognormal.js +20 -3
  62. package/dist/distributions/multinomial.js +54 -11
  63. package/dist/distributions/nbeta.js +128 -35
  64. package/dist/distributions/nchisq.js +85 -14
  65. package/dist/distributions/negbinomial.js +100 -18
  66. package/dist/distributions/normal.js +35 -5
  67. package/dist/distributions/nt.d.ts +28 -3
  68. package/dist/distributions/nt.js +536 -35
  69. package/dist/distributions/pareto.js +9 -1
  70. package/dist/distributions/poisson.js +28 -3
  71. package/dist/distributions/signrank.js +7 -4
  72. package/dist/distributions/summary.js +450 -60
  73. package/dist/distributions/t.js +55 -3
  74. package/dist/distributions/triangular.js +45 -13
  75. package/dist/distributions/tukey.js +21 -2
  76. package/dist/distributions/uniform.js +2 -0
  77. package/dist/distributions/weibull.js +33 -3
  78. package/dist/distributions/wilcox.d.ts +9 -3
  79. package/dist/distributions/wilcox.js +155 -26
  80. package/dist/distributions.js +2 -2
  81. package/dist/htest/agreement.d.ts +3 -2
  82. package/dist/htest/agreement.js +76 -14
  83. package/dist/htest/ansariTest.d.ts +6 -1
  84. package/dist/htest/ansariTest.js +75 -8
  85. package/dist/htest/aov.d.ts +1 -1
  86. package/dist/htest/aov.js +48 -34
  87. package/dist/htest/binomTest.d.ts +5 -0
  88. package/dist/htest/binomTest.js +41 -17
  89. package/dist/htest/brunnerMunzelTest.d.ts +4 -3
  90. package/dist/htest/brunnerMunzelTest.js +7 -5
  91. package/dist/htest/chisqTest.d.ts +2 -1
  92. package/dist/htest/chisqTest.js +130 -43
  93. package/dist/htest/cor.d.ts +2 -1
  94. package/dist/htest/cor.js +17 -19
  95. package/dist/htest/core/ansari.d.ts +9 -0
  96. package/dist/htest/core/ansari.js +21 -1
  97. package/dist/htest/core/kolmogorov.d.ts +25 -0
  98. package/dist/htest/core/kolmogorov.js +123 -0
  99. package/dist/htest/core/mantelhaen.js +6 -4
  100. package/dist/htest/core/shapiro.d.ts +1 -1
  101. package/dist/htest/core/shapiro.js +5 -1
  102. package/dist/htest/dunnett.js +14 -5
  103. package/dist/htest/effectSize.d.ts +2 -0
  104. package/dist/htest/effectSize.js +91 -29
  105. package/dist/htest/fisherTest.d.ts +2 -2
  106. package/dist/htest/fisherTest.js +36 -18
  107. package/dist/htest/groups.d.ts +7 -0
  108. package/dist/htest/groups.js +21 -4
  109. package/dist/htest/ksTest.d.ts +3 -1
  110. package/dist/htest/ksTest.js +23 -2
  111. package/dist/htest/leveneTest.js +19 -3
  112. package/dist/htest/mantelhaenTest.js +125 -25
  113. package/dist/htest/mcnemarTest.js +32 -11
  114. package/dist/htest/multipleComparisons.d.ts +8 -1
  115. package/dist/htest/multipleComparisons.js +44 -21
  116. package/dist/htest/normalityTests.js +44 -10
  117. package/dist/htest/onewayTest.js +96 -5
  118. package/dist/htest/pAdjust.d.ts +3 -2
  119. package/dist/htest/pAdjust.js +38 -6
  120. package/dist/htest/pairwise.d.ts +1 -1
  121. package/dist/htest/pairwise.js +17 -15
  122. package/dist/htest/poissonTest.d.ts +1 -1
  123. package/dist/htest/poissonTest.js +111 -59
  124. package/dist/htest/polycor.js +27 -7
  125. package/dist/htest/power.d.ts +11 -1
  126. package/dist/htest/power.js +112 -8
  127. package/dist/htest/propTest.js +21 -4
  128. package/dist/htest/pwr.js +121 -24
  129. package/dist/htest/rankTests.js +29 -5
  130. package/dist/htest/tTest.js +44 -21
  131. package/dist/htest/trendTests.d.ts +7 -3
  132. package/dist/htest/trendTests.js +114 -20
  133. package/dist/htest/types.d.ts +5 -0
  134. package/dist/htest/types.js +7 -0
  135. package/dist/htest/varTest.js +45 -14
  136. package/dist/htest/wilcoxTest.js +114 -21
  137. package/dist/integrate/quadpack.js +27 -5
  138. package/dist/internal/covmat.d.ts +5 -0
  139. package/dist/internal/covmat.js +20 -0
  140. package/dist/internal/ddexp.d.ts +23 -1
  141. package/dist/internal/ddexp.js +86 -6
  142. package/dist/internal/discrete.d.ts +14 -0
  143. package/dist/internal/discrete.js +78 -5
  144. package/dist/internal/extremes.d.ts +9 -0
  145. package/dist/internal/extremes.js +24 -0
  146. package/dist/internal/fround.js +13 -4
  147. package/dist/internal/integer.d.ts +9 -0
  148. package/dist/internal/integer.js +12 -0
  149. package/dist/internal/invert.d.ts +5 -0
  150. package/dist/internal/invert.js +25 -7
  151. package/dist/internal/noncentral.d.ts +7 -0
  152. package/dist/internal/noncentral.js +9 -0
  153. package/dist/internal/poissonMixture.js +29 -6
  154. package/dist/internal/scaledInverse.d.ts +10 -0
  155. package/dist/internal/scaledInverse.js +22 -0
  156. package/dist/internal/seq.js +15 -2
  157. package/dist/internal/summary.d.ts +90 -0
  158. package/dist/internal/summary.js +458 -39
  159. package/dist/internal/uniroot.d.ts +7 -0
  160. package/dist/internal/uniroot.js +28 -3
  161. package/dist/linalg/basic.d.ts +3 -1
  162. package/dist/linalg/basic.js +51 -7
  163. package/dist/linalg/chol.js +4 -1
  164. package/dist/linalg/dot.d.ts +29 -0
  165. package/dist/linalg/dot.js +132 -0
  166. package/dist/linalg/eigen.d.ts +6 -1
  167. package/dist/linalg/eigen.js +71 -14
  168. package/dist/linalg/expm.d.ts +3 -2
  169. package/dist/linalg/expm.js +109 -15
  170. package/dist/linalg/kappa.js +58 -10
  171. package/dist/linalg/lu.d.ts +2 -1
  172. package/dist/linalg/lu.js +35 -5
  173. package/dist/linalg/matrix.d.ts +14 -0
  174. package/dist/linalg/matrix.js +24 -0
  175. package/dist/linalg/ops.js +60 -13
  176. package/dist/linalg/qr.d.ts +2 -1
  177. package/dist/linalg/qr.js +91 -23
  178. package/dist/linalg/schur.js +11 -3
  179. package/dist/linalg/solve.d.ts +6 -1
  180. package/dist/linalg/solve.js +147 -26
  181. package/dist/linalg/svd.d.ts +9 -2
  182. package/dist/linalg/svd.js +29 -11
  183. package/dist/linalg.js +2 -2
  184. package/dist/mixed.js +4 -4
  185. package/dist/models/anovaSequential.d.ts +16 -1
  186. package/dist/models/anovaSequential.js +124 -25
  187. package/dist/models/aovEz.js +140 -30
  188. package/dist/models/aovStrata.js +55 -22
  189. package/dist/models/carAnova.d.ts +1 -1
  190. package/dist/models/carAnova.js +83 -32
  191. package/dist/models/coxph.js +148 -66
  192. package/dist/models/estimable.d.ts +15 -0
  193. package/dist/models/estimable.js +68 -0
  194. package/dist/models/formula.d.ts +1 -1
  195. package/dist/models/formula.js +26 -8
  196. package/dist/models/glm.d.ts +35 -5
  197. package/dist/models/glm.js +398 -55
  198. package/dist/models/glmAnova.js +84 -13
  199. package/dist/models/glmConfint.d.ts +1 -1
  200. package/dist/models/glmConfint.js +115 -27
  201. package/dist/models/glmFamily.d.ts +10 -0
  202. package/dist/models/glmFamily.js +244 -40
  203. package/dist/models/lm.d.ts +12 -1
  204. package/dist/models/lm.js +235 -36
  205. package/dist/models/lmer.d.ts +20 -1
  206. package/dist/models/lmer.js +109 -27
  207. package/dist/models/lmerAnova.js +37 -4
  208. package/dist/models/lmerHypotheses.d.ts +6 -2
  209. package/dist/models/lmerHypotheses.js +14 -2
  210. package/dist/models/lmerTest.d.ts +9 -2
  211. package/dist/models/lmerTest.js +64 -19
  212. package/dist/models/mauchly.d.ts +4 -1
  213. package/dist/models/mauchly.js +34 -13
  214. package/dist/models/mixedStructure.js +6 -0
  215. package/dist/models/modelFrame.js +8 -2
  216. package/dist/models/modelMatrix.d.ts +3 -1
  217. package/dist/models/modelMatrix.js +40 -15
  218. package/dist/models/scaledTables.d.ts +8 -0
  219. package/dist/models/scaledTables.js +6 -0
  220. package/dist/models/survival.d.ts +6 -1
  221. package/dist/models/survival.js +67 -27
  222. package/dist/models/tiedTimes.d.ts +2 -0
  223. package/dist/models/tiedTimes.js +34 -0
  224. package/dist/numerics/deriv.d.ts +1 -1
  225. package/dist/numerics/deriv.js +64 -8
  226. package/dist/numerics/integrate.d.ts +9 -1
  227. package/dist/numerics/integrate.js +103 -16
  228. package/dist/numerics/interp.d.ts +8 -2
  229. package/dist/numerics/interp.js +352 -50
  230. package/dist/numerics/ode.js +55 -1
  231. package/dist/numerics.js +2 -2
  232. package/dist/optim/localmin.js +4 -0
  233. package/dist/optim/optim.d.ts +3 -1
  234. package/dist/optim/optim.js +80 -8
  235. package/dist/random/beta.js +53 -4
  236. package/dist/random/binomial.d.ts +14 -3
  237. package/dist/random/binomial.js +59 -24
  238. package/dist/random/continuous.js +33 -5
  239. package/dist/random/extra.js +42 -9
  240. package/dist/random/gamma.d.ts +4 -1
  241. package/dist/random/gamma.js +36 -8
  242. package/dist/random/hyper.js +9 -6
  243. package/dist/random/mt.js +17 -2
  244. package/dist/random/poisson.js +26 -3
  245. package/dist/random/r2dtable.d.ts +8 -1
  246. package/dist/random/r2dtable.js +24 -3
  247. package/dist/random/rank.d.ts +2 -0
  248. package/dist/random/rank.js +44 -4
  249. package/dist/random/sample.d.ts +12 -2
  250. package/dist/random/sample.js +57 -20
  251. package/dist/random/streams.js +4 -2
  252. package/dist/rstats.js +14 -14
  253. package/dist/special/besselIK.d.ts +12 -0
  254. package/dist/special/besselIK.js +168 -23
  255. package/dist/special/besselJY.d.ts +11 -1
  256. package/dist/special/besselJY.js +127 -19
  257. package/dist/special/besselSeries.d.ts +27 -0
  258. package/dist/special/besselSeries.js +45 -2
  259. package/dist/special/beta.js +11 -1
  260. package/dist/special/choose.js +17 -8
  261. package/dist/special/dd.js +122 -18
  262. package/dist/special/extra.js +14 -2
  263. package/dist/special/gamma.js +15 -2
  264. package/dist/special/igam.js +33 -6
  265. package/dist/special/incbet.js +100 -10
  266. package/dist/special/incbetLargeA.js +7 -2
  267. package/dist/special/incbetPrefactor.d.ts +5 -0
  268. package/dist/special/incbetPrefactor.js +14 -3
  269. package/dist/special/incbetTemme.d.ts +7 -0
  270. package/dist/special/incbetTemme.js +45 -12
  271. package/dist/special/loader.d.ts +1 -1
  272. package/dist/special/loader.js +179 -33
  273. package/dist/special/log1pmx.js +4 -0
  274. package/dist/special.js +2 -2
  275. package/dist/tests.js +11 -11
  276. package/llms.txt +12 -6
  277. package/package.json +1 -1
  278. package/dist/chunks/chunk-2CUKVVRO.js +0 -2
  279. package/dist/chunks/chunk-3WQCKGKP.js +0 -2
  280. package/dist/chunks/chunk-4Z2XDWKV.js +0 -2
  281. package/dist/chunks/chunk-AJBLCNZ7.js +0 -3
  282. package/dist/chunks/chunk-D4F7GQAY.js +0 -2
  283. package/dist/chunks/chunk-EBQMGCQZ.js +0 -2
  284. package/dist/chunks/chunk-HBMHR5SS.js +0 -2
  285. package/dist/chunks/chunk-IBPWRQIF.js +0 -2
  286. package/dist/chunks/chunk-JLAH3X77.js +0 -2
  287. package/dist/chunks/chunk-LG74QY5U.js +0 -2
  288. package/dist/chunks/chunk-PEYGUK32.js +0 -2
  289. package/dist/chunks/chunk-Q4PGYESP.js +0 -2
  290. package/dist/chunks/chunk-RCAL4VHM.js +0 -3
  291. package/dist/chunks/chunk-SREPSVTT.js +0 -2
  292. package/dist/chunks/chunk-UFT662QZ.js +0 -2
  293. package/dist/chunks/chunk-VWJ74UHC.js +0 -2
  294. package/dist/chunks/chunk-XNPU54NH.js +0 -2
  295. package/dist/chunks/chunk-XPLDEK6D.js +0 -2
  296. package/dist/chunks/chunk-YGT4P7EU.js +0 -2
  297. package/dist/chunks/chunk-YVREYVI2.js +0 -2
@@ -7,13 +7,15 @@
7
7
  // and the order of equal weights also matches R.
8
8
  // All of this was verified against observed R output.
9
9
  import { isRounding, unifIndex, unifRand } from "./rng.js";
10
+ import { maxOf } from "../internal/extremes.js";
10
11
  /**
11
12
  * Random sample of integers from `0..n-1`. Equivalent to R's `sample.int()`. Unlike R, it is 0-based.
12
13
  *
13
14
  * The result is R's `sample.int(n, ...)` minus 1, so it can be used directly as array
14
15
  * indices. It consumes the same random numbers as R (default `sample.kind = "Rejection"`).
15
16
  *
16
- * @param n Number of candidates (a non-negative number less than 2^31).
17
+ * @param n Number of candidates: a non-negative number up to 4.5e15 (2^52, as R); below 2^31 with `prob`, and for
18
+ * sampling without replacement more than n / 2 of them.
17
19
  * @param options See {@link SampleOptions}.
18
20
  * @returns The drawn integers, each in `0..n-1`.
19
21
  *
@@ -36,21 +38,27 @@ function sampleInt1(n, options) {
36
38
  const { replace = false, prob } = options;
37
39
  const sizeGiven = options.size !== undefined;
38
40
  const size = sizeGiven ? options.size : n;
39
- if (!Number.isFinite(size) || size < 0)
41
+ // truncated first, as R: a size in (-1, 0) is 0 (#94)
42
+ if (!Number.isFinite(size) || size <= -1)
40
43
  throw new RangeError("size must be a non-negative number");
41
44
  const k = Math.trunc(size);
45
+ if (n === 0 && k > 0)
46
+ throw new RangeError("cannot take a sample from an empty population");
42
47
  if (prob !== undefined) {
48
+ // R's weighted path takes size as an integer: 2^31 or more is rejected before any allocation or draw (#414)
49
+ if (k >= 2 ** 31)
50
+ throw new RangeError("size must be less than 2^31 with prob");
43
51
  if (n >= 2 ** 31)
44
52
  throw new RangeError("n must be less than 2^31 with prob");
45
53
  if (prob.length !== n)
46
54
  throw new TypeError("prob must have length n");
47
55
  const p = fixupProb(prob, k, replace);
48
56
  if (replace) {
49
- let nc = 0;
50
- for (let i = 0; i < n; i++)
51
- if (n * p[i] > 0.1)
52
- nc++;
53
- return nc > 200 ? walkerSample(p, k) : probSampleReplace(p, k);
57
+ const draw = replaceDrawer(p);
58
+ const out = new Array(k);
59
+ for (let i = 0; i < k; i++)
60
+ out[i] = draw();
61
+ return out;
54
62
  }
55
63
  if (k > n)
56
64
  throw new RangeError("cannot take a sample larger than the population when replace is false");
@@ -90,6 +98,31 @@ function sampleInt1(n, options) {
90
98
  }
91
99
  return out;
92
100
  }
101
+ /**
102
+ * One draw at a time from 0..n-1 with replacement and weights `prob`: the same draws, from the same uniforms, as
103
+ * consecutive elements of `sampleInt(n, { size, replace: true, prob })` (the method depends only on n and prob), with
104
+ * the same checks of n and prob. For simulations that count draws without keeping them (internal; #287)
105
+ */
106
+ export function sampleIntReplaceDrawer(n, prob) {
107
+ if (!Number.isFinite(n) || n < 0 || n > 4.5e15)
108
+ throw new RangeError("n must be a non-negative number up to 4.5e15");
109
+ n = Math.trunc(n);
110
+ if (n >= 2 ** 31)
111
+ throw new RangeError("n must be less than 2^31 with prob");
112
+ if (prob.length !== n)
113
+ throw new TypeError("prob must have length n");
114
+ const draw = replaceDrawer(fixupProb(prob, 0, true));
115
+ return () => draw() - 1;
116
+ }
117
+ /** The weighted draw with replacement (1-based): Walker's alias method with more than 200 large weights, as R */
118
+ function replaceDrawer(p) {
119
+ const n = p.length;
120
+ let nc = 0;
121
+ for (let i = 0; i < n; i++)
122
+ if (n * p[i] > 0.1)
123
+ nc++;
124
+ return nc > 200 ? walkerDrawer(p) : probReplaceDrawer(p);
125
+ }
93
126
  /**
94
127
  * Random sample of the elements of an array. Equivalent to R's `sample()`.
95
128
  *
@@ -129,6 +162,14 @@ function fixupProb(prob, k, replace) {
129
162
  }
130
163
  if (npos === 0 || (!replace && k > npos))
131
164
  throw new RangeError("too few positive probabilities");
165
+ if (sum === Infinity) {
166
+ // Finite weights whose sum overflows: rescale by the largest before summing
167
+ const mx = maxOf(prob);
168
+ sum = 0;
169
+ for (const v of prob)
170
+ sum += v / mx;
171
+ return Float64Array.from(prob, (v) => v / mx / sum);
172
+ }
132
173
  return Float64Array.from(prob, (v) => v / sum);
133
174
  }
134
175
  /** Sort a in decreasing order, permuting ib alongside (heapsort; ties end up in the same order as R) */
@@ -185,22 +226,20 @@ function sortedByWeight(p) {
185
226
  revsort(p, perm);
186
227
  return perm;
187
228
  }
188
- function probSampleReplace(prob, k) {
229
+ function probReplaceDrawer(prob) {
189
230
  const p = Float64Array.from(prob);
190
231
  const n = p.length;
191
232
  const perm = sortedByWeight(p);
192
233
  for (let i = 1; i < n; i++)
193
234
  p[i] += p[i - 1];
194
- const out = new Array(k);
195
- for (let i = 0; i < k; i++) {
235
+ return () => {
196
236
  const rU = unifRand();
197
237
  let j = 0;
198
238
  for (; j < n - 1; j++)
199
239
  if (rU <= p[j])
200
240
  break;
201
- out[i] = perm[j];
202
- }
203
- return out;
241
+ return perm[j];
242
+ };
204
243
  }
205
244
  function probSampleNoReplace(prob, k) {
206
245
  const p = Float64Array.from(prob);
@@ -226,8 +265,8 @@ function probSampleNoReplace(prob, k) {
226
265
  }
227
266
  return out;
228
267
  }
229
- /** Sampling with replacement by Walker's alias method */
230
- function walkerSample(p, k) {
268
+ /** Sampling with replacement by Walker's alias method (one draw per call) */
269
+ function walkerDrawer(p) {
231
270
  const n = p.length;
232
271
  const q = new Float64Array(n);
233
272
  const a = new Int32Array(n);
@@ -258,8 +297,7 @@ function walkerSample(p, k) {
258
297
  // is n times one uniform; otherwise t is a uniform integer and u another uniform. The comparison is made on t + u
259
298
  // and q[t] + t, as R does (in doubles)
260
299
  const rounding = isRounding();
261
- const out = new Array(k);
262
- for (let i = 0; i < k; i++) {
300
+ return () => {
263
301
  let t;
264
302
  let rU;
265
303
  if (rounding) {
@@ -270,7 +308,6 @@ function walkerSample(p, k) {
270
308
  t = unifIndex(n);
271
309
  rU = t + unifRand();
272
310
  }
273
- out[i] = rU < q[t] + t ? t + 1 : a[t] + 1;
274
- }
275
- return out;
311
+ return rU < q[t] + t ? t + 1 : a[t] + 1;
312
+ };
276
313
  }
@@ -18,8 +18,10 @@ function mulMod(a, b, m) {
18
18
  }
19
19
  function jump(state, a1, a2) {
20
20
  const code = state[0];
21
- if (!Number.isInteger(code) || code % 100 !== 7)
22
- throw new RangeError("the state must be a .Random.seed of L'Ecuyer-CMRG (kind code ending in 07)");
21
+ // the kind codes setRandomSeed takes for L'Ecuyer-CMRG (R accepts any code ending in 07, such as 7, which would give a
22
+ // state setRandomSeed cannot restore)
23
+ if (code !== 10407 && code !== 407)
24
+ throw new RangeError("the state must be a .Random.seed of L'Ecuyer-CMRG (kind code 10407 or 407)");
23
25
  const s = checkState(state);
24
26
  const out = new Int32Array(7);
25
27
  out[0] = code;