@numero-uno-jpn/rstats 0.11.0 → 0.12.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 (289) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.ja.md +44 -13
  3. package/README.md +43 -11
  4. package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-3VMBBQLV.js} +2 -2
  5. package/dist/chunks/chunk-4OKAZJJG.js +3 -0
  6. package/dist/chunks/{chunk-EZAFN5CD.js → chunk-6BH65HGN.js} +1 -1
  7. package/dist/chunks/chunk-ATC4F4BX.js +2 -0
  8. package/dist/chunks/{chunk-JWBO5WVN.js → chunk-EDH53DXN.js} +2 -2
  9. package/dist/chunks/{chunk-Y5CNQ266.js → chunk-EZ2KD5NA.js} +2 -2
  10. package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-GSPOO2G3.js} +2 -2
  11. package/dist/chunks/{chunk-F5EDJFEO.js → chunk-K7AZ65H7.js} +2 -2
  12. package/dist/chunks/{chunk-YSWGDOWK.js → chunk-LEIH4U5X.js} +2 -2
  13. package/dist/chunks/{chunk-EZWBRCJL.js → chunk-OX3SBG5X.js} +1 -1
  14. package/dist/chunks/chunk-SGZQDJRR.js +2 -0
  15. package/dist/chunks/{chunk-C5XTWMGB.js → chunk-UH2N3ZQW.js} +1 -1
  16. package/dist/chunks/chunk-UV2MZYDQ.js +2 -0
  17. package/dist/chunks/{chunk-TOGXTCZO.js → chunk-VQHEOBTM.js} +2 -2
  18. package/dist/chunks/chunk-WJQZZYOI.js +2 -0
  19. package/dist/chunks/chunk-WKEFHOFR.js +2 -0
  20. package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-WXC25OPJ.js} +2 -2
  21. package/dist/chunks/{chunk-5WDJPHYY.js → chunk-XJQKSR52.js} +1 -1
  22. package/dist/data/grouping.d.ts +39 -15
  23. package/dist/data/grouping.js +21 -22
  24. package/dist/descriptive/basic.d.ts +130 -17
  25. package/dist/descriptive/basic.js +115 -14
  26. package/dist/descriptive/cov.d.ts +22 -12
  27. package/dist/descriptive/dataFrames.d.ts +39 -11
  28. package/dist/descriptive/dataFrames.js +14 -6
  29. package/dist/descriptive/factanal.d.ts +26 -6
  30. package/dist/descriptive/factanal.js +7 -3
  31. package/dist/descriptive/hist.d.ts +27 -6
  32. package/dist/descriptive/hist.js +9 -3
  33. package/dist/descriptive/missing.d.ts +13 -6
  34. package/dist/descriptive/missing.js +4 -2
  35. package/dist/descriptive/moments.d.ts +91 -13
  36. package/dist/descriptive/moments.js +66 -9
  37. package/dist/descriptive/omega.d.ts +28 -6
  38. package/dist/descriptive/omega.js +16 -4
  39. package/dist/descriptive/pivot.d.ts +22 -6
  40. package/dist/descriptive/pivot.js +7 -3
  41. package/dist/descriptive/quantile.d.ts +33 -5
  42. package/dist/descriptive/quantile.js +20 -2
  43. package/dist/descriptive/rank.d.ts +12 -2
  44. package/dist/descriptive/rank.js +2 -0
  45. package/dist/descriptive/table.d.ts +55 -7
  46. package/dist/descriptive/table.js +38 -4
  47. package/dist/descriptive.js +2 -2
  48. package/dist/distributions/arcsine.d.ts +40 -5
  49. package/dist/distributions/arcsine.js +35 -4
  50. package/dist/distributions/beta.d.ts +12 -0
  51. package/dist/distributions/beta.js +12 -0
  52. package/dist/distributions/binomial.d.ts +18 -0
  53. package/dist/distributions/binomial.js +18 -0
  54. package/dist/distributions/bvnorm.d.ts +4 -1
  55. package/dist/distributions/bvnorm.js +4 -1
  56. package/dist/distributions/cauchy.d.ts +24 -0
  57. package/dist/distributions/cauchy.js +24 -0
  58. package/dist/distributions/chisq.d.ts +18 -0
  59. package/dist/distributions/chisq.js +18 -0
  60. package/dist/distributions/exponential.d.ts +29 -1
  61. package/dist/distributions/exponential.js +24 -0
  62. package/dist/distributions/f.d.ts +18 -0
  63. package/dist/distributions/f.js +18 -0
  64. package/dist/distributions/gamma.d.ts +20 -0
  65. package/dist/distributions/gamma.js +18 -0
  66. package/dist/distributions/geometric.d.ts +24 -0
  67. package/dist/distributions/geometric.js +24 -0
  68. package/dist/distributions/hypergeometric.d.ts +24 -0
  69. package/dist/distributions/hypergeometric.js +24 -0
  70. package/dist/distributions/invgamma.d.ts +32 -4
  71. package/dist/distributions/invgamma.js +27 -3
  72. package/dist/distributions/kumaraswamy.d.ts +31 -3
  73. package/dist/distributions/kumaraswamy.js +31 -3
  74. package/dist/distributions/laplace.d.ts +36 -4
  75. package/dist/distributions/laplace.js +31 -3
  76. package/dist/distributions/logistic.d.ts +29 -1
  77. package/dist/distributions/logistic.js +24 -0
  78. package/dist/distributions/lognormal.d.ts +29 -1
  79. package/dist/distributions/lognormal.js +24 -0
  80. package/dist/distributions/multinomial.d.ts +7 -1
  81. package/dist/distributions/multinomial.js +2 -0
  82. package/dist/distributions/negbinomial.d.ts +29 -1
  83. package/dist/distributions/negbinomial.js +24 -0
  84. package/dist/distributions/normal.d.ts +11 -1
  85. package/dist/distributions/normal.js +6 -0
  86. package/dist/distributions/pareto.d.ts +36 -4
  87. package/dist/distributions/pareto.js +31 -3
  88. package/dist/distributions/poisson.d.ts +18 -0
  89. package/dist/distributions/poisson.js +18 -0
  90. package/dist/distributions/signrank.d.ts +24 -0
  91. package/dist/distributions/signrank.js +24 -0
  92. package/dist/distributions/summary.d.ts +20 -2
  93. package/dist/distributions/summary.js +4 -0
  94. package/dist/distributions/t.d.ts +18 -0
  95. package/dist/distributions/t.js +18 -0
  96. package/dist/distributions/triangular.d.ts +36 -4
  97. package/dist/distributions/triangular.js +31 -3
  98. package/dist/distributions/tukey.d.ts +15 -1
  99. package/dist/distributions/tukey.js +10 -0
  100. package/dist/distributions/uniform.d.ts +29 -1
  101. package/dist/distributions/uniform.js +24 -0
  102. package/dist/distributions/weibull.d.ts +29 -1
  103. package/dist/distributions/weibull.js +24 -0
  104. package/dist/distributions/wilcox.d.ts +24 -0
  105. package/dist/distributions/wilcox.js +24 -0
  106. package/dist/distributions.js +2 -2
  107. package/dist/entries/descriptive.d.ts +1 -1
  108. package/dist/entries/mixed.d.ts +1 -0
  109. package/dist/entries/mixed.js +2 -0
  110. package/dist/entries/numerics.d.ts +1 -1
  111. package/dist/entries/tests.js +1 -1
  112. package/dist/htest/agreement.d.ts +61 -23
  113. package/dist/htest/agreement.js +19 -9
  114. package/dist/htest/ansariTest.d.ts +8 -2
  115. package/dist/htest/aov.d.ts +43 -10
  116. package/dist/htest/aov.js +17 -3
  117. package/dist/htest/binomTest.d.ts +12 -2
  118. package/dist/htest/binomTest.js +2 -0
  119. package/dist/htest/brunnerMunzelTest.d.ts +9 -3
  120. package/dist/htest/brunnerMunzelTest.js +4 -2
  121. package/dist/htest/chisqTest.d.ts +19 -3
  122. package/dist/htest/cor.d.ts +20 -4
  123. package/dist/htest/effectSize.d.ts +70 -12
  124. package/dist/htest/effectSize.js +40 -7
  125. package/dist/htest/fisherTest.d.ts +9 -1
  126. package/dist/htest/fisherTest.js +2 -0
  127. package/dist/htest/groups.d.ts +5 -1
  128. package/dist/htest/ksTest.d.ts +20 -3
  129. package/dist/htest/leveneTest.d.ts +15 -4
  130. package/dist/htest/leveneTest.js +5 -2
  131. package/dist/htest/mantelhaenTest.d.ts +25 -3
  132. package/dist/htest/mantelhaenTest.js +15 -1
  133. package/dist/htest/mcnemarTest.d.ts +14 -4
  134. package/dist/htest/mcnemarTest.js +4 -2
  135. package/dist/htest/multipleComparisons.d.ts +173 -29
  136. package/dist/htest/multipleComparisons.js +123 -19
  137. package/dist/htest/normalityTests.d.ts +56 -9
  138. package/dist/htest/normalityTests.js +40 -6
  139. package/dist/htest/onewayTest.d.ts +32 -3
  140. package/dist/htest/onewayTest.js +10 -0
  141. package/dist/htest/pAdjust.d.ts +9 -1
  142. package/dist/htest/pAdjust.js +2 -0
  143. package/dist/htest/pairwise.d.ts +50 -5
  144. package/dist/htest/pairwise.js +25 -0
  145. package/dist/htest/poissonTest.d.ts +12 -2
  146. package/dist/htest/poissonTest.js +2 -0
  147. package/dist/htest/polycor.d.ts +29 -10
  148. package/dist/htest/power.d.ts +60 -6
  149. package/dist/htest/power.js +6 -0
  150. package/dist/htest/propTest.d.ts +13 -2
  151. package/dist/htest/propTest.js +2 -0
  152. package/dist/htest/pwr.d.ts +286 -36
  153. package/dist/htest/pwr.js +116 -15
  154. package/dist/htest/rankTests.d.ts +80 -12
  155. package/dist/htest/rankTests.js +11 -2
  156. package/dist/htest/tTest.d.ts +13 -3
  157. package/dist/htest/testFormula.js +6 -3
  158. package/dist/htest/trendTests.d.ts +29 -8
  159. package/dist/htest/trendTests.js +8 -4
  160. package/dist/htest/types.d.ts +14 -2
  161. package/dist/htest/varTest.d.ts +25 -8
  162. package/dist/htest/wilcoxTest.d.ts +10 -2
  163. package/dist/internal/dpq.d.ts +4 -0
  164. package/dist/internal/noncentral.d.ts +2 -0
  165. package/dist/internal/vectorize.d.ts +4 -0
  166. package/dist/linalg/basic.d.ts +39 -5
  167. package/dist/linalg/basic.js +15 -0
  168. package/dist/linalg/chol.d.ts +26 -5
  169. package/dist/linalg/chol.js +7 -0
  170. package/dist/linalg/eigen.d.ts +16 -7
  171. package/dist/linalg/eigen.js +6 -5
  172. package/dist/linalg/expm.d.ts +15 -5
  173. package/dist/linalg/expm.js +5 -3
  174. package/dist/linalg/kappa.d.ts +21 -1
  175. package/dist/linalg/kappa.js +16 -0
  176. package/dist/linalg/lu.d.ts +30 -6
  177. package/dist/linalg/lu.js +15 -3
  178. package/dist/linalg/matrix.d.ts +4 -0
  179. package/dist/linalg/norm.d.ts +16 -1
  180. package/dist/linalg/norm.js +9 -0
  181. package/dist/linalg/ops.d.ts +156 -35
  182. package/dist/linalg/ops.js +96 -15
  183. package/dist/linalg/qr.d.ts +87 -12
  184. package/dist/linalg/qr.js +31 -0
  185. package/dist/linalg/schur.d.ts +8 -2
  186. package/dist/linalg/schur.js +3 -1
  187. package/dist/linalg/solve.d.ts +42 -6
  188. package/dist/linalg/solve.js +22 -0
  189. package/dist/linalg/svd.d.ts +12 -2
  190. package/dist/linalg/svd.js +2 -0
  191. package/dist/linalg.js +2 -2
  192. package/dist/mixed.js +3 -0
  193. package/dist/models/anovaSequential.d.ts +26 -4
  194. package/dist/models/anovaSequential.js +3 -1
  195. package/dist/models/aovEz.d.ts +29 -6
  196. package/dist/models/aovEz.js +5 -2
  197. package/dist/models/aovStrata.d.ts +13 -3
  198. package/dist/models/aovStrata.js +5 -1
  199. package/dist/models/carAnova.d.ts +9 -3
  200. package/dist/models/carAnova.js +4 -2
  201. package/dist/models/coxph.d.ts +33 -7
  202. package/dist/models/coxph.js +8 -3
  203. package/dist/models/formula.d.ts +26 -1
  204. package/dist/models/formula.js +125 -9
  205. package/dist/models/glm.d.ts +128 -21
  206. package/dist/models/glm.js +71 -14
  207. package/dist/models/glmAnova.d.ts +30 -5
  208. package/dist/models/glmAnova.js +15 -2
  209. package/dist/models/glmConfint.d.ts +16 -2
  210. package/dist/models/glmConfint.js +9 -1
  211. package/dist/models/glmFamily.d.ts +27 -5
  212. package/dist/models/lm.d.ts +77 -19
  213. package/dist/models/lm.js +22 -4
  214. package/dist/models/lmer.d.ts +162 -0
  215. package/dist/models/lmer.js +457 -0
  216. package/dist/models/mauchly.d.ts +20 -5
  217. package/dist/models/mauchly.js +7 -3
  218. package/dist/models/mixedDeviance.d.ts +44 -0
  219. package/dist/models/mixedDeviance.js +872 -0
  220. package/dist/models/mixedStructure.d.ts +82 -0
  221. package/dist/models/mixedStructure.js +309 -0
  222. package/dist/models/modelFrame.d.ts +17 -2
  223. package/dist/models/modelFrame.js +36 -21
  224. package/dist/models/modelMatrix.d.ts +33 -8
  225. package/dist/models/modelMatrix.js +21 -5
  226. package/dist/models/survival.d.ts +41 -9
  227. package/dist/models/survival.js +10 -4
  228. package/dist/numerics/deriv.d.ts +21 -6
  229. package/dist/numerics/deriv.js +16 -5
  230. package/dist/numerics/integrate.d.ts +37 -7
  231. package/dist/numerics/integrate.js +8 -2
  232. package/dist/numerics/interp.d.ts +63 -12
  233. package/dist/numerics/interp.js +30 -6
  234. package/dist/numerics/ode.d.ts +15 -5
  235. package/dist/numerics/ode.js +5 -3
  236. package/dist/numerics.js +2 -2
  237. package/dist/optim/optim.d.ts +32 -8
  238. package/dist/optim/optim.js +8 -4
  239. package/dist/random/beta.d.ts +8 -0
  240. package/dist/random/beta.js +8 -0
  241. package/dist/random/binomial.d.ts +16 -0
  242. package/dist/random/binomial.js +16 -0
  243. package/dist/random/continuous.d.ts +51 -0
  244. package/dist/random/continuous.js +51 -0
  245. package/dist/random/extra.d.ts +66 -6
  246. package/dist/random/extra.js +66 -6
  247. package/dist/random/gamma.d.ts +33 -0
  248. package/dist/random/gamma.js +33 -0
  249. package/dist/random/hyper.d.ts +8 -0
  250. package/dist/random/hyper.js +8 -0
  251. package/dist/random/poisson.d.ts +25 -0
  252. package/dist/random/poisson.js +25 -0
  253. package/dist/random/r2dtable.d.ts +2 -0
  254. package/dist/random/r2dtable.js +2 -0
  255. package/dist/random/rank.d.ts +16 -0
  256. package/dist/random/rank.js +16 -0
  257. package/dist/random/rng.d.ts +49 -6
  258. package/dist/random/rng.js +29 -2
  259. package/dist/random/sample.d.ts +10 -2
  260. package/dist/random/sample.js +5 -1
  261. package/dist/random/streams.d.ts +13 -0
  262. package/dist/random/streams.js +13 -0
  263. package/dist/rstats.js +14 -14
  264. package/dist/special/besselIK.d.ts +11 -3
  265. package/dist/special/besselIK.js +6 -2
  266. package/dist/special/besselJY.d.ts +6 -2
  267. package/dist/special/besselJY.js +6 -2
  268. package/dist/special/beta.d.ts +16 -2
  269. package/dist/special/beta.js +16 -2
  270. package/dist/special/choose.d.ts +13 -5
  271. package/dist/special/choose.js +13 -5
  272. package/dist/special/erf.d.ts +8 -3
  273. package/dist/special/erf.js +8 -3
  274. package/dist/special/extra.d.ts +30 -10
  275. package/dist/special/extra.js +25 -9
  276. package/dist/special/gamma.d.ts +18 -2
  277. package/dist/special/gamma.js +18 -2
  278. package/dist/special/log1p.d.ts +16 -7
  279. package/dist/special/log1p.js +16 -7
  280. package/dist/special/psigamma.d.ts +9 -3
  281. package/dist/special/psigamma.js +9 -3
  282. package/dist/special/rCompatible.d.ts +5 -1
  283. package/dist/special.js +2 -2
  284. package/dist/tests.js +12 -12
  285. package/llms.txt +13 -3
  286. package/package.json +5 -1
  287. package/dist/chunks/chunk-7GQMKH3Z.js +0 -2
  288. package/dist/chunks/chunk-AHHS6AC4.js +0 -3
  289. package/dist/chunks/chunk-ALM3VHFP.js +0 -2
@@ -12,26 +12,65 @@ import { generate } from "./common.js";
12
12
  import { rgamma1 } from "./gamma.js";
13
13
  import { expRand, unifRand } from "./rng.js";
14
14
  /**
15
- * Random numbers from the inverse gamma distribution. Equivalent to `extraDistr::rinvgamma(n, alpha, beta = 1)`.
15
+ * Random numbers from the inverse gamma distribution. Equivalent to `extraDistr::rinvgamma(n, alpha, beta = 1)` in R.
16
16
  *
17
17
  * @param n Number of values to generate.
18
18
  * @param alpha Shape.
19
19
  * @param options.beta Scale. Default `1`.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * setSeed(1);
24
+ * rinvgamma(2, 3, { beta: 2 }); // [1.24409, 0.3964566]
25
+ * ```
26
+ *
27
+ * @category Random numbers
20
28
  */
21
29
  export function rinvgamma(n, alpha, options = {}) {
22
30
  const { beta = 1 } = options;
23
31
  return generate(n, () => (alpha > 0 && beta > 0 && Number.isFinite(alpha) && Number.isFinite(beta) ? 1 / rgamma1(alpha, 1 / beta) : NaN));
24
32
  }
25
- /** Random numbers from the Kumaraswamy distribution. Equivalent to `extraDistr::rkumar(n, a, b)`. */
33
+ /**
34
+ * Random numbers from the Kumaraswamy distribution. Equivalent to `extraDistr::rkumar(n, a, b)` in R.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * setSeed(1);
39
+ * rkumar(2, 2, 3); // [0.5977236, 0.5298335]
40
+ * ```
41
+ *
42
+ * @category Random numbers
43
+ */
26
44
  export function rkumar(n, a, b) {
27
45
  return generate(n, () => (a > 0 && b > 0 && Number.isFinite(a) && Number.isFinite(b) ? qkumar1(1 - unifRand(), a, b, true, false) : NaN));
28
46
  }
29
- /** Random numbers from the Pareto distribution. Equivalent to `extraDistr::rpareto(n, a = 1, b = 1)`. */
47
+ /**
48
+ * Random numbers from the Pareto distribution. Equivalent to `extraDistr::rpareto(n, a = 1, b = 1)` in R.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * setSeed(1);
53
+ * rpareto(2, { a: 3, b: 1 }); // [1.555872, 1.390286]
54
+ * ```
55
+ *
56
+ * @category Random numbers
57
+ */
30
58
  export function rpareto(n, options = {}) {
31
59
  const { a = 1, b = 1 } = options;
32
60
  return generate(n, () => (a > 0 && b > 0 && Number.isFinite(a) && Number.isFinite(b) ? qpareto1(1 - unifRand(), a, b, true, false) : NaN));
33
61
  }
34
- /** Random numbers from the triangular distribution. Equivalent to `extraDistr::rtriang(n, a = -1, b = 1, c = (a + b)/2)`. */
62
+ /**
63
+ * Random numbers from the triangular distribution.
64
+ * Equivalent to `extraDistr::rtriang(n, a = -1, b = 1, c = (a + b)/2)` in R.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * setSeed(1);
69
+ * rtriang(2, { a: 0, b: 2, c: 1 }); // [0.6376326, 1.481061]
70
+ * ```
71
+ *
72
+ * @category Random numbers
73
+ */
35
74
  export function rtriang(n, options = {}) {
36
75
  const { a = -1, b = 1 } = options;
37
76
  const c = options.c ?? (a + b) / 2;
@@ -44,7 +83,17 @@ export function rtriang(n, options = {}) {
44
83
  return a + (b - a) * ((1 - cc) * Math.min(u, v) + cc * Math.max(u, v));
45
84
  });
46
85
  }
47
- /** Random numbers from the Laplace distribution. Equivalent to `extraDistr::rlaplace(n, mu = 0, sigma = 1)`. */
86
+ /**
87
+ * Random numbers from the Laplace distribution. Equivalent to `extraDistr::rlaplace(n, mu = 0, sigma = 1)` in R.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * setSeed(1);
92
+ * rlaplace(2, { mu: 0, sigma: 1 }); // [-0.7551818, 0.1457067]
93
+ * ```
94
+ *
95
+ * @category Random numbers
96
+ */
48
97
  export function rlaplace(n, options = {}) {
49
98
  const { mu = 0, sigma = 1 } = options;
50
99
  return generate(n, () => {
@@ -55,7 +104,18 @@ export function rlaplace(n, options = {}) {
55
104
  return mu + sigma * s * e;
56
105
  });
57
106
  }
58
- /** Random numbers from the arcsine distribution on (a, b), by inversion: `qarcsine(runif(n), a, b)`. */
107
+ /**
108
+ * Random numbers from the arcsine distribution on (a, b), by inversion: `qarcsine(runif(n), a, b)`.
109
+ * Not an R function. The arcsine distribution is neither in base R nor in extraDistr.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * setSeed(1);
114
+ * rarcsine(2, { a: 0, b: 1 }); // [0.1640851, 0.3044923]
115
+ * ```
116
+ *
117
+ * @category Random numbers
118
+ */
59
119
  export function rarcsine(n, options = {}) {
60
120
  const { a = 0, b = 1 } = options;
61
121
  return generate(n, () => (Number.isFinite(a) && Number.isFinite(b) && a < b ? qarcsine1(unifRand(), a, b, true, false) : NaN));
@@ -8,6 +8,14 @@ export declare function rgamma1(a: number, scale: number): number;
8
8
  * @param options.rate Rate. Default `1`. Give either `rate` or `scale`.
9
9
  * @param options.scale Scale (`1 / rate`). Default `1`. Giving both is an error unless `scale = 1 / rate`.
10
10
  * @returns An array of `n` values; `NaN` for invalid parameters.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * setSeed(1);
15
+ * rgamma(2, 2, { rate: 1 }); // [0.830865, 3.570756]
16
+ * ```
17
+ *
18
+ * @category Random numbers
11
19
  */
12
20
  export declare function rgamma(n: number, shape: number, options?: {
13
21
  rate?: number;
@@ -23,6 +31,15 @@ export declare function rnchisq1(df: number, ncp: number): number;
23
31
  * @param df Degrees of freedom.
24
32
  * @param options.ncp Non-centrality parameter. If omitted, the central distribution is used.
25
33
  * @returns An array of `n` values; `NaN` for invalid parameters.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * setSeed(1);
38
+ * rchisq(2, 3); // [0.9433146, 5.543782]
39
+ * rchisq(2, 3, { ncp: 1 });
40
+ * ```
41
+ *
42
+ * @category Random numbers
26
43
  */
27
44
  export declare function rchisq(n: number, df: number, options?: {
28
45
  ncp?: number;
@@ -34,6 +51,14 @@ export declare function rchisq(n: number, df: number, options?: {
34
51
  * @param df Degrees of freedom (may be `Infinity`).
35
52
  * @param options.ncp Non-centrality parameter. If omitted, the central distribution is used.
36
53
  * @returns An array of `n` values; `NaN` for invalid parameters.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * setSeed(1);
58
+ * rt(2, 5); // [-0.6576941, -0.5973472]
59
+ * ```
60
+ *
61
+ * @category Random numbers
37
62
  */
38
63
  export declare function rt(n: number, df: number, options?: {
39
64
  ncp?: number;
@@ -46,6 +71,14 @@ export declare function rt(n: number, df: number, options?: {
46
71
  * @param df2 Denominator degrees of freedom.
47
72
  * @param options.ncp Non-centrality parameter. If omitted, the central distribution is used.
48
73
  * @returns An array of `n` values; `NaN` for invalid parameters.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * setSeed(1);
78
+ * rf(2, 3, 10); // [0.2025231, 1.645713]
79
+ * ```
80
+ *
81
+ * @category Random numbers
49
82
  */
50
83
  export declare function rf(n: number, df1: number, df2: number, options?: {
51
84
  ncp?: number;
@@ -126,6 +126,14 @@ export function rgamma1(a, scale) {
126
126
  * @param options.rate Rate. Default `1`. Give either `rate` or `scale`.
127
127
  * @param options.scale Scale (`1 / rate`). Default `1`. Giving both is an error unless `scale = 1 / rate`.
128
128
  * @returns An array of `n` values; `NaN` for invalid parameters.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * setSeed(1);
133
+ * rgamma(2, 2, { rate: 1 }); // [0.830865, 3.570756]
134
+ * ```
135
+ *
136
+ * @category Random numbers
129
137
  */
130
138
  export function rgamma(n, shape, options = {}) {
131
139
  const scale = gammaScale(options);
@@ -156,6 +164,15 @@ export function rnchisq1(df, ncp) {
156
164
  * @param df Degrees of freedom.
157
165
  * @param options.ncp Non-centrality parameter. If omitted, the central distribution is used.
158
166
  * @returns An array of `n` values; `NaN` for invalid parameters.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * setSeed(1);
171
+ * rchisq(2, 3); // [0.9433146, 5.543782]
172
+ * rchisq(2, 3, { ncp: 1 });
173
+ * ```
174
+ *
175
+ * @category Random numbers
159
176
  */
160
177
  export function rchisq(n, df, options = {}) {
161
178
  const { ncp } = options;
@@ -170,6 +187,14 @@ export function rchisq(n, df, options = {}) {
170
187
  * @param df Degrees of freedom (may be `Infinity`).
171
188
  * @param options.ncp Non-centrality parameter. If omitted, the central distribution is used.
172
189
  * @returns An array of `n` values; `NaN` for invalid parameters.
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * setSeed(1);
194
+ * rt(2, 5); // [-0.6576941, -0.5973472]
195
+ * ```
196
+ *
197
+ * @category Random numbers
173
198
  */
174
199
  export function rt(n, df, options = {}) {
175
200
  const { ncp } = options;
@@ -198,6 +223,14 @@ export function rt(n, df, options = {}) {
198
223
  * @param df2 Denominator degrees of freedom.
199
224
  * @param options.ncp Non-centrality parameter. If omitted, the central distribution is used.
200
225
  * @returns An array of `n` values; `NaN` for invalid parameters.
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * setSeed(1);
230
+ * rf(2, 3, 10); // [0.2025231, 1.645713]
231
+ * ```
232
+ *
233
+ * @category Random numbers
201
234
  */
202
235
  export function rf(n, df1, df2, options = {}) {
203
236
  const { ncp } = options;
@@ -8,5 +8,13 @@ export declare function rhyper1(nn1in: number, nn2in: number, kkin: number): num
8
8
  * @param n Number of black balls in the urn.
9
9
  * @param k Number of balls drawn from the urn.
10
10
  * @returns An array of `nn` values (the number of white balls drawn); `NaN` for invalid parameters.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * setSeed(1);
15
+ * rhyper(5, 10, 7, 8); // [5, 5, 5, 3, 6]
16
+ * ```
17
+ *
18
+ * @category Random numbers
11
19
  */
12
20
  export declare function rhyper(nn: number, m: number, n: number, k: number): number[];
@@ -234,6 +234,14 @@ function accept(ix, v) {
234
234
  * @param n Number of black balls in the urn.
235
235
  * @param k Number of balls drawn from the urn.
236
236
  * @returns An array of `nn` values (the number of white balls drawn); `NaN` for invalid parameters.
237
+ *
238
+ * @example
239
+ * ```ts
240
+ * setSeed(1);
241
+ * rhyper(5, 10, 7, 8); // [5, 5, 5, 3, 6]
242
+ * ```
243
+ *
244
+ * @category Random numbers
237
245
  */
238
246
  export function rhyper(nn, m, n, k) {
239
247
  return generate(nn, () => rhyper1(m, n, k));
@@ -6,6 +6,14 @@ export declare function rpois1(mu: number): number;
6
6
  * @param n Number of values to generate (fractions are truncated, as in R).
7
7
  * @param lambda Mean.
8
8
  * @returns An array of `n` values; `NaN` for invalid parameters.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * setSeed(1);
13
+ * rpois(5, 3); // [2, 2, 3, 5, 2]
14
+ * ```
15
+ *
16
+ * @category Random numbers
9
17
  */
10
18
  export declare function rpois(n: number, lambda: number): number[];
11
19
  /**
@@ -15,6 +23,14 @@ export declare function rpois(n: number, lambda: number): number[];
15
23
  * @param n Number of values to generate (fractions are truncated, as in R).
16
24
  * @param prob Probability of success in each trial, in (0, 1].
17
25
  * @returns An array of `n` values; `NaN` for invalid parameters.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * setSeed(1);
30
+ * rgeom(5, 0.3); // [1, 1, 7, 0, 3]
31
+ * ```
32
+ *
33
+ * @category Random numbers
18
34
  */
19
35
  export declare function rgeom(n: number, prob: number): number[];
20
36
  /**
@@ -26,6 +42,15 @@ export declare function rgeom(n: number, prob: number): number[];
26
42
  * @param options.mu Mean (alternative parametrization). Give exactly one of `prob` and `mu`.
27
43
  * @returns An array of `n` values; `NaN` for invalid parameters.
28
44
  * @throws TypeError unless exactly one of `prob` and `mu` is given.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * setSeed(1);
49
+ * rnbinom(5, 3, { prob: 0.5 }); // [3, 2, 2, 2, 2]
50
+ * rnbinom(5, 3, { mu: 2 });
51
+ * ```
52
+ *
53
+ * @category Random numbers
29
54
  */
30
55
  export declare function rnbinom(n: number, size: number, options: {
31
56
  prob?: number;
@@ -153,6 +153,14 @@ export function rpois1(mu) {
153
153
  * @param n Number of values to generate (fractions are truncated, as in R).
154
154
  * @param lambda Mean.
155
155
  * @returns An array of `n` values; `NaN` for invalid parameters.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * setSeed(1);
160
+ * rpois(5, 3); // [2, 2, 3, 5, 2]
161
+ * ```
162
+ *
163
+ * @category Random numbers
156
164
  */
157
165
  export function rpois(n, lambda) {
158
166
  return generate(n, () => rpois1(lambda));
@@ -164,6 +172,14 @@ export function rpois(n, lambda) {
164
172
  * @param n Number of values to generate (fractions are truncated, as in R).
165
173
  * @param prob Probability of success in each trial, in (0, 1].
166
174
  * @returns An array of `n` values; `NaN` for invalid parameters.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * setSeed(1);
179
+ * rgeom(5, 0.3); // [1, 1, 7, 0, 3]
180
+ * ```
181
+ *
182
+ * @category Random numbers
167
183
  */
168
184
  export function rgeom(n, prob) {
169
185
  return generate(n, () => {
@@ -181,6 +197,15 @@ export function rgeom(n, prob) {
181
197
  * @param options.mu Mean (alternative parametrization). Give exactly one of `prob` and `mu`.
182
198
  * @returns An array of `n` values; `NaN` for invalid parameters.
183
199
  * @throws TypeError unless exactly one of `prob` and `mu` is given.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * setSeed(1);
204
+ * rnbinom(5, 3, { prob: 0.5 }); // [3, 2, 2, 2, 2]
205
+ * rnbinom(5, 3, { mu: 2 });
206
+ * ```
207
+ *
208
+ * @category Random numbers
184
209
  */
185
210
  export function rnbinom(n, size, options) {
186
211
  const { prob, mu } = options;
@@ -22,5 +22,7 @@ export declare function rcont2(r: readonly number[], c: readonly number[], fact:
22
22
  * setSeed(1);
23
23
  * r2dtable(1, [3, 2], [2, 3]); // [[[1, 2], [1, 1]]] (R: set.seed(1); r2dtable(1, c(3, 2), c(2, 3)))
24
24
  * ```
25
+ *
26
+ * @category Random numbers
25
27
  */
26
28
  export declare function r2dtable(n: number, r: readonly number[], c: readonly number[]): number[][][];
@@ -132,6 +132,8 @@ function margins(v, name) {
132
132
  * setSeed(1);
133
133
  * r2dtable(1, [3, 2], [2, 3]); // [[[1, 2], [1, 1]]] (R: set.seed(1); r2dtable(1, c(3, 2), c(2, 3)))
134
134
  * ```
135
+ *
136
+ * @category Random numbers
135
137
  */
136
138
  export function r2dtable(n, r, c) {
137
139
  const count = Math.trunc(n);
@@ -5,6 +5,14 @@
5
5
  * @param nn Number of values to generate.
6
6
  * @param n Number of observations in the sample.
7
7
  * @returns An array of `nn` values; `NaN` for invalid parameters.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * setSeed(1);
12
+ * rsignrank(5, 10); // [37, 33, 13, 29, 40]
13
+ * ```
14
+ *
15
+ * @category Random numbers
8
16
  */
9
17
  export declare function rsignrank(nn: number, n: number): number[];
10
18
  /**
@@ -15,5 +23,13 @@ export declare function rsignrank(nn: number, n: number): number[];
15
23
  * @param m Number of observations in the first sample.
16
24
  * @param n Number of observations in the second sample.
17
25
  * @returns An array of `nn` values; `NaN` for invalid parameters.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * setSeed(1);
30
+ * rwilcox(5, 4, 6); // [7, 5, 12, 17, 10]
31
+ * ```
32
+ *
33
+ * @category Random numbers
18
34
  */
19
35
  export declare function rwilcox(nn: number, m: number, n: number): number[];
@@ -10,6 +10,14 @@ import { generate } from "./common.js";
10
10
  * @param nn Number of values to generate.
11
11
  * @param n Number of observations in the sample.
12
12
  * @returns An array of `nn` values; `NaN` for invalid parameters.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * setSeed(1);
17
+ * rsignrank(5, 10); // [37, 33, 13, 29, 40]
18
+ * ```
19
+ *
20
+ * @category Random numbers
13
21
  */
14
22
  export function rsignrank(nn, n) {
15
23
  return generate(nn, () => {
@@ -35,6 +43,14 @@ export function rsignrank(nn, n) {
35
43
  * @param m Number of observations in the first sample.
36
44
  * @param n Number of observations in the second sample.
37
45
  * @returns An array of `nn` values; `NaN` for invalid parameters.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * setSeed(1);
50
+ * rwilcox(5, 4, 6); // [7, 5, 12, 17, 10]
51
+ * ```
52
+ *
53
+ * @category Random numbers
38
54
  */
39
55
  export function rwilcox(nn, m, n) {
40
56
  return generate(nn, () => {
@@ -1,8 +1,20 @@
1
- /** A uniform random number generator, R's `RNGkind(kind)`. */
1
+ /**
2
+ * A uniform random number generator, R's `RNGkind(kind)`.
3
+ *
4
+ * @category Random numbers
5
+ */
2
6
  export type RNGKindName = "Mersenne-Twister" | "L'Ecuyer-CMRG";
3
- /** How `sample` turns uniforms into indices, R's `RNGkind(sample.kind)`. */
7
+ /**
8
+ * How `sample` turns uniforms into indices, R's `RNGkind(sample.kind)`.
9
+ *
10
+ * @category Random numbers
11
+ */
4
12
  export type SampleKindName = "Rejection" | "Rounding";
5
- /** Options for {@link RNGkind}. Omitted entries keep the current setting, as in R. */
13
+ /**
14
+ * Options for {@link RNGkind}. Omitted entries keep the current setting, as in R.
15
+ *
16
+ * @category Random numbers
17
+ */
6
18
  export interface RNGKindOptions {
7
19
  /** Uniform generator: `"Mersenne-Twister"` (R's default), `"L'Ecuyer-CMRG"`, or `"default"`. */
8
20
  kind?: RNGKindName | "default" | undefined;
@@ -12,7 +24,11 @@ export interface RNGKindOptions {
12
24
  */
13
25
  sampleKind?: SampleKindName | "default" | undefined;
14
26
  }
15
- /** The kinds in effect, as returned by {@link RNGkind}. */
27
+ /**
28
+ * The kinds in effect, as returned by {@link RNGkind}.
29
+ *
30
+ * @category Random numbers
31
+ */
16
32
  export interface RNGKinds {
17
33
  /** The uniform generator. */
18
34
  kind: RNGKindName;
@@ -40,6 +56,8 @@ export interface RNGKinds {
40
56
  * rnorm(3); // [-0.6264538107423324, 0.18364332422208224, -0.8356286124100472]
41
57
  * // R: set.seed(1); rnorm(3)
42
58
  * ```
59
+ *
60
+ * @category Random numbers
43
61
  */
44
62
  export declare function setSeed(seed: number): void;
45
63
  /**
@@ -74,24 +92,49 @@ export declare function setSeed(seed: number): void;
74
92
  * sampleInt(10, { size: 3 }); // [2, 3, 4]
75
93
  * // R: set.seed(1, kind = "default", sample.kind = "Rounding"); sample.int(10, 3) - 1
76
94
  * ```
95
+ *
96
+ * @category Random numbers
77
97
  */
78
98
  export declare function RNGkind(options?: RNGKindOptions): RNGKinds;
79
99
  /**
80
- * Returns a copy of the current generator state. Equivalent to reading R's `.Random.seed`.
100
+ * Returns a copy of the current generator state, as reading R's `.Random.seed` does.
101
+ * Equivalent to R's `.Random.seed`.
81
102
  *
82
103
  * @returns The same integers as R's `.Random.seed`: the kind code (`10403` for R's default,
83
104
  * `403` with `sampleKind: "Rounding"`, `10407` for L'Ecuyer-CMRG), followed by 625 integers
84
105
  * for Mersenne-Twister or 6 for L'Ecuyer-CMRG (unsigned seeds of 2^31 or more appear as
85
106
  * negative numbers, as in R). Pass it to {@link setRandomSeed} to restore the state.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * setSeed(1);
111
+ * const s = getRandomSeed();
112
+ * s.length; // 626
113
+ * s[0]; // 10403
114
+ * ```
115
+ *
116
+ * @category Random numbers
86
117
  */
87
118
  export declare function getRandomSeed(): Int32Array;
88
119
  /**
89
- * Restores a generator state, including its kinds. Equivalent to assigning R's `.Random.seed`.
120
+ * Restores a generator state, including its kinds, as assigning R's `.Random.seed` does.
121
+ * Equivalent to R's `.Random.seed`.
90
122
  *
91
123
  * @param state The integers returned by {@link getRandomSeed}, or copied from R's `.Random.seed`.
92
124
  * @throws RangeError for a kind code other than those of Mersenne-Twister or L'Ecuyer-CMRG with
93
125
  * Inversion and Rejection or Rounding (`10403`, `403`, `10407`, `407`), a state of the wrong
94
126
  * length, or an invalid L'Ecuyer-CMRG state (R reseeds from the clock in these cases).
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * setSeed(1);
131
+ * const s = getRandomSeed();
132
+ * runif(2); // [0.2655087, 0.3721239]
133
+ * setRandomSeed(s);
134
+ * runif(2); // [0.2655087, 0.3721239] (the same again)
135
+ * ```
136
+ *
137
+ * @category Random numbers
95
138
  */
96
139
  export declare function setRandomSeed(state: ArrayLike<number>): void;
97
140
  /** One uniform on (0, 1) (R's unif_rand) */
@@ -46,6 +46,8 @@ function ensureSeeded() {
46
46
  * rnorm(3); // [-0.6264538107423324, 0.18364332422208224, -0.8356286124100472]
47
47
  * // R: set.seed(1); rnorm(3)
48
48
  * ```
49
+ *
50
+ * @category Random numbers
49
51
  */
50
52
  export function setSeed(seed) {
51
53
  if (!Number.isFinite(seed))
@@ -99,6 +101,8 @@ function lookup(table, name, what) {
99
101
  * sampleInt(10, { size: 3 }); // [2, 3, 4]
100
102
  * // R: set.seed(1, kind = "default", sample.kind = "Rounding"); sample.int(10, 3) - 1
101
103
  * ```
104
+ *
105
+ * @category Random numbers
102
106
  */
103
107
  export function RNGkind(options = {}) {
104
108
  const previous = {
@@ -121,12 +125,23 @@ export function RNGkind(options = {}) {
121
125
  /** Value of .Random.seed[1]: uniform kind (3 Mersenne-Twister, 7 L'Ecuyer-CMRG) + 100 × normal 4 (Inversion) + 10000 × sample kind (0 Rounding, 1 Rejection) */
122
126
  const kindCode = () => (gen === mt ? 3 : 7) + 400 + (rounding ? 0 : 10000);
123
127
  /**
124
- * Returns a copy of the current generator state. Equivalent to reading R's `.Random.seed`.
128
+ * Returns a copy of the current generator state, as reading R's `.Random.seed` does.
129
+ * Equivalent to R's `.Random.seed`.
125
130
  *
126
131
  * @returns The same integers as R's `.Random.seed`: the kind code (`10403` for R's default,
127
132
  * `403` with `sampleKind: "Rounding"`, `10407` for L'Ecuyer-CMRG), followed by 625 integers
128
133
  * for Mersenne-Twister or 6 for L'Ecuyer-CMRG (unsigned seeds of 2^31 or more appear as
129
134
  * negative numbers, as in R). Pass it to {@link setRandomSeed} to restore the state.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * setSeed(1);
139
+ * const s = getRandomSeed();
140
+ * s.length; // 626
141
+ * s[0]; // 10403
142
+ * ```
143
+ *
144
+ * @category Random numbers
130
145
  */
131
146
  export function getRandomSeed() {
132
147
  ensureSeeded();
@@ -136,12 +151,24 @@ export function getRandomSeed() {
136
151
  return Int32Array.of(kindCode(), ...gen.s);
137
152
  }
138
153
  /**
139
- * Restores a generator state, including its kinds. Equivalent to assigning R's `.Random.seed`.
154
+ * Restores a generator state, including its kinds, as assigning R's `.Random.seed` does.
155
+ * Equivalent to R's `.Random.seed`.
140
156
  *
141
157
  * @param state The integers returned by {@link getRandomSeed}, or copied from R's `.Random.seed`.
142
158
  * @throws RangeError for a kind code other than those of Mersenne-Twister or L'Ecuyer-CMRG with
143
159
  * Inversion and Rejection or Rounding (`10403`, `403`, `10407`, `407`), a state of the wrong
144
160
  * length, or an invalid L'Ecuyer-CMRG state (R reseeds from the clock in these cases).
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * setSeed(1);
165
+ * const s = getRandomSeed();
166
+ * runif(2); // [0.2655087, 0.3721239]
167
+ * setRandomSeed(s);
168
+ * runif(2); // [0.2655087, 0.3721239] (the same again)
169
+ * ```
170
+ *
171
+ * @category Random numbers
145
172
  */
146
173
  export function setRandomSeed(state) {
147
174
  const code = state[0];
@@ -1,4 +1,8 @@
1
- /** Options for {@link sample} and {@link sampleInt}. */
1
+ /**
2
+ * Options for {@link sample} and {@link sampleInt}.
3
+ *
4
+ * @category Random numbers
5
+ */
2
6
  export interface SampleOptions {
3
7
  /** Number of items to draw. Default: the number of candidates (a random permutation). */
4
8
  size?: number;
@@ -8,7 +12,7 @@ export interface SampleOptions {
8
12
  prob?: readonly number[];
9
13
  }
10
14
  /**
11
- * Random sample of integers from `0..n-1`. Equivalent to R's `sample.int()`, but 0-based.
15
+ * Random sample of integers from `0..n-1`. Equivalent to R's `sample.int()`. Unlike R, it is 0-based.
12
16
  *
13
17
  * The result is R's `sample.int(n, ...)` minus 1, so it can be used directly as array
14
18
  * indices. It consumes the same random numbers as R (default `sample.kind = "Rejection"`).
@@ -22,6 +26,8 @@ export interface SampleOptions {
22
26
  * setSeed(42);
23
27
  * sampleInt(10, { size: 3 }); // [0, 4, 9] (R: set.seed(42); sample.int(10, 3) - 1)
24
28
  * ```
29
+ *
30
+ * @category Random numbers
25
31
  */
26
32
  export declare function sampleInt(n: number, options?: SampleOptions): number[];
27
33
  /**
@@ -41,5 +47,7 @@ export declare function sampleInt(n: number, options?: SampleOptions): number[];
41
47
  * sample(["a", "b", "c", "d", "e"]); // ["a", "e", "d", "c", "b"]
42
48
  * sample([1, 2, 3], { size: 5, replace: true, prob: [0.5, 0.3, 0.2] });
43
49
  * ```
50
+ *
51
+ * @category Random numbers
44
52
  */
45
53
  export declare function sample<T>(x: readonly T[], options?: SampleOptions): T[];
@@ -8,7 +8,7 @@
8
8
  // All of this was verified against observed R output.
9
9
  import { isRounding, unifIndex, unifRand } from "./rng.js";
10
10
  /**
11
- * Random sample of integers from `0..n-1`. Equivalent to R's `sample.int()`, but 0-based.
11
+ * Random sample of integers from `0..n-1`. Equivalent to R's `sample.int()`. Unlike R, it is 0-based.
12
12
  *
13
13
  * The result is R's `sample.int(n, ...)` minus 1, so it can be used directly as array
14
14
  * indices. It consumes the same random numbers as R (default `sample.kind = "Rejection"`).
@@ -22,6 +22,8 @@ import { isRounding, unifIndex, unifRand } from "./rng.js";
22
22
  * setSeed(42);
23
23
  * sampleInt(10, { size: 3 }); // [0, 4, 9] (R: set.seed(42); sample.int(10, 3) - 1)
24
24
  * ```
25
+ *
26
+ * @category Random numbers
25
27
  */
26
28
  export function sampleInt(n, options = {}) {
27
29
  return sampleInt1(n, options).map((v) => v - 1);
@@ -105,6 +107,8 @@ function sampleInt1(n, options) {
105
107
  * sample(["a", "b", "c", "d", "e"]); // ["a", "e", "d", "c", "b"]
106
108
  * sample([1, 2, 3], { size: 5, replace: true, prob: [0.5, 0.3, 0.2] });
107
109
  * ```
110
+ *
111
+ * @category Random numbers
108
112
  */
109
113
  export function sample(x, options = {}) {
110
114
  return sampleInt1(x.length, options).map((i) => x[i - 1]);
@@ -21,6 +21,8 @@
21
21
  * setRandomSeed(s2);
22
22
  * runif(2); // [0.31369782407981056, 0.9280126525616814]
23
23
  * ```
24
+ *
25
+ * @category Random numbers
24
26
  */
25
27
  export declare function nextRNGStream(state: ArrayLike<number>): Int32Array;
26
28
  /**
@@ -30,5 +32,16 @@ export declare function nextRNGStream(state: ArrayLike<number>): Int32Array;
30
32
  * @param state A 7-integer state, as for {@link nextRNGStream}.
31
33
  * @returns A new state of the same form.
32
34
  * @throws RangeError if `state` is not a valid L'Ecuyer-CMRG state.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * RNGkind({ kind: "L'Ecuyer-CMRG" });
39
+ * setSeed(1);
40
+ * setRandomSeed(nextRNGSubStream(getRandomSeed()));
41
+ * // R: .Random.seed <- parallel::nextRNGSubStream(.Random.seed)
42
+ * runif(2); // [0.9158314, 0.1484848]
43
+ * ```
44
+ *
45
+ * @category Random numbers
33
46
  */
34
47
  export declare function nextRNGSubStream(state: ArrayLike<number>): Int32Array;