@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
@@ -1,6 +1,10 @@
1
1
  import type { DataFrame } from "../models/modelFrame.js";
2
2
  import { type Alternative, type HTest, type Sample } from "./types.js";
3
- /** Options for {@link varTest}. */
3
+ /**
4
+ * Options for {@link varTest}.
5
+ *
6
+ * @category Hypothesis tests
7
+ */
4
8
  export interface VarTestOptions {
5
9
  /** Hypothesized ratio of the variances of `x` and `y`. Default `1`. */
6
10
  ratio?: number;
@@ -9,10 +13,15 @@ export interface VarTestOptions {
9
13
  /** Confidence level of the interval. Default `0.95`. */
10
14
  confLevel?: number;
11
15
  }
12
- /** Result of {@link varTest}. The F distribution has two degrees of freedom, so `parameter` is a pair. */
16
+ /**
17
+ * Result of {@link varTest}. The F distribution has two degrees of freedom, so `parameter` is a pair.
18
+ *
19
+ * @category Hypothesis tests
20
+ */
13
21
  export interface VarTestResult extends Omit<HTest, "parameter" | "parameterName"> {
14
22
  /** `[num df, denom df]`. */
15
23
  parameter: [number, number];
24
+ /** Names of `parameter`: `["num df", "denom df"]`. */
16
25
  parameterName: [string, string];
17
26
  confInt: [number, number];
18
27
  confLevel: number;
@@ -26,14 +35,16 @@ export interface VarTestResult extends Omit<HTest, "parameter" | "parameterName"
26
35
  *
27
36
  * @example
28
37
  * ```ts
29
- * varTest([1, 3, 2, 5, 4], [2, 9, 4, 12, 7, 1]).statistic; // 0.2307692
38
+ * varTest([1, 3, 2, 5, 4], [2, 9, 4, 12, 7, 1]).statistic; // 0.13761467889908255
30
39
  * ```
31
40
  *
32
41
  * There is also a formula form, `varTest("y ~ g", data, options)` (next overload).
42
+ *
43
+ * @category Hypothesis tests
33
44
  */
34
45
  export declare function varTest(x: Sample, y: Sample, options?: VarTestOptions): VarTestResult;
35
46
  /**
36
- * F test of two variances from a formula and a data frame. Equivalent to R's `var.test(formula, data)`: `"y ~ g"`
47
+ * F test of two variances from a formula and a data frame. As R's `var.test(formula, data)`: `"y ~ g"`
37
48
  * compares the two levels of `g` (the first level is `x`). Only the variables of the formula count: the rows where
38
49
  * one of them is missing are dropped.
39
50
  *
@@ -41,14 +52,18 @@ export declare function varTest(x: Sample, y: Sample, options?: VarTestOptions):
41
52
  * @param data The data frame: an object of columns (`null` or `NaN` for a missing value).
42
53
  */
43
54
  export declare function varTest(formula: string, data: DataFrame, options?: VarTestOptions): VarTestResult;
44
- /** Result of {@link bartlettTest}. Has no `alternative`, as R's `bartlett.test()` returns none. */
55
+ /**
56
+ * Result of {@link bartlettTest}. Has no `alternative`, as R's `bartlett.test()` returns none.
57
+ *
58
+ * @category Hypothesis tests
59
+ */
45
60
  export interface BartlettTestResult extends Omit<HTest, "alternative"> {
46
61
  /** Degrees of freedom (`parameterName` is `"df"`). */
47
62
  parameter: number;
48
63
  }
49
64
  /**
50
- * Bartlett's test that the variances of several normal samples are equal. Equivalent to R's `bartlett.test()` with
51
- * a list of samples. `NaN` and infinite values are dropped, as in R.
65
+ * Bartlett's test that the variances of several normal samples are equal. Equivalent to R's `bartlett.test()`.
66
+ * Takes a list of samples. `NaN` and infinite values are dropped, as in R.
52
67
  *
53
68
  * @param groups The samples (at least two), each with at least two finite values.
54
69
  *
@@ -58,10 +73,12 @@ export interface BartlettTestResult extends Omit<HTest, "alternative"> {
58
73
  * ```
59
74
  *
60
75
  * There is also a formula form, `bartlettTest("y ~ g", data)` (next overload).
76
+ *
77
+ * @category Hypothesis tests
61
78
  */
62
79
  export declare function bartlettTest(groups: readonly Sample[]): BartlettTestResult;
63
80
  /**
64
- * Bartlett's test from a formula and a data frame. Equivalent to R's `bartlett.test(formula, data)`: `"y ~ g"`, one
81
+ * Bartlett's test from a formula and a data frame. As R's `bartlett.test(formula, data)`: `"y ~ g"`, one
65
82
  * group per level of `g`, in the order of the levels. Only the variables of the formula count: the rows where one of
66
83
  * them is missing are dropped.
67
84
  *
@@ -1,6 +1,10 @@
1
1
  import type { DataFrame } from "../models/modelFrame.js";
2
2
  import { type Alternative, type HTest, type Sample } from "./types.js";
3
- /** Options for {@link wilcoxTest}. */
3
+ /**
4
+ * Options for {@link wilcoxTest}.
5
+ *
6
+ * @category Hypothesis tests
7
+ */
4
8
  export interface WilcoxTestOptions {
5
9
  /**
6
10
  * Alternative hypothesis: `"two.sided"`, `"less"` or `"greater"`. Default `"two.sided"`.
@@ -30,6 +34,8 @@ export interface WilcoxTestOptions {
30
34
  * Result of {@link wilcoxTest}. `statisticName` is `"V"` for the signed rank test and `"W"`
31
35
  * for the rank sum test; `parameter` is not set. `estimate` and `confInt` are set only
32
36
  * with `confInt: true`.
37
+ *
38
+ * @category Hypothesis tests
33
39
  */
34
40
  export interface WilcoxTestResult extends HTest {
35
41
  /** `mu`. */
@@ -60,10 +66,12 @@ export interface WilcoxTestResult extends HTest {
60
66
  * ```
61
67
  *
62
68
  * There is also a formula form, `wilcoxTest("y ~ g", data, options)` (next overload).
69
+ *
70
+ * @category Hypothesis tests
63
71
  */
64
72
  export declare function wilcoxTest(x: Sample, y?: Sample | WilcoxTestOptions, options?: WilcoxTestOptions): WilcoxTestResult;
65
73
  /**
66
- * Wilcoxon tests from a formula and a data frame. Equivalent to R's `wilcox.test(formula, data)`: `"y ~ g"` is the
74
+ * Wilcoxon tests from a formula and a data frame. As R's `wilcox.test(formula, data)`: `"y ~ g"` is the
67
75
  * rank sum test of the two levels of `g` (the first level is `x`), `"y ~ 1"` the signed rank test and
68
76
  * `"Pair(a, b) ~ 1"` the paired test of `a` and `b` (the option `paired` is not allowed). Only the variables of the
69
77
  * formula count: the rows where one of them is missing are dropped.
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Options shared by the distribution (`p*`) and quantile (`q*`) functions.
3
3
  * Correspond to R's `lower.tail` and `log.p` arguments.
4
+ *
5
+ * @category Distributions
4
6
  */
5
7
  export interface TailOptions {
6
8
  /** If `true`, probabilities are P[X <= x]; if `false`, P[X > x]. Default `true`. */
@@ -11,6 +13,8 @@ export interface TailOptions {
11
13
  /**
12
14
  * Options shared by the density / probability mass (`d*`) functions.
13
15
  * Corresponds to R's `log` argument.
16
+ *
17
+ * @category Distributions
14
18
  */
15
19
  export interface DensityOptions {
16
20
  /** If `true`, return the log of the density (or probability). Default `false`. */
@@ -1,5 +1,7 @@
1
1
  /**
2
2
  * Noncentrality option accepted by the chi-squared, t, F and beta distribution functions.
3
+ *
4
+ * @category Distributions
3
5
  */
4
6
  export interface NoncentralOption {
5
7
  /**
@@ -2,11 +2,15 @@
2
2
  * Input accepted as the vectorized first argument of the distribution functions
3
3
  * (the counterpart of R's automatic vectorization).
4
4
  * A number gives a number, a `number[]` gives a `number[]`, and a `Float64Array` gives a `Float64Array`.
5
+ *
6
+ * @category Distributions
5
7
  */
6
8
  export type Vectorizable = number | readonly number[] | Float64Array;
7
9
  /**
8
10
  * Result type matching the shape of a {@link Vectorizable} input:
9
11
  * `number` for a number, `Float64Array` for a `Float64Array`, and `number[]` for an array.
12
+ *
13
+ * @category Distributions
10
14
  */
11
15
  export type VectorResult<T extends Vectorizable> = T extends number ? number : T extends Float64Array ? Float64Array : number[];
12
16
  export declare function vectorize<T extends Vectorizable>(x: T, f: (v: number) => number): VectorResult<T>;
@@ -7,6 +7,14 @@ import { type Mat, type MatrixInput, type VectorOrMatrix } from "./matrix.js";
7
7
  * @param x A matrix (array of rows) or a vector.
8
8
  * @param y A matrix or a vector with the same number of rows as `x`. Defaults to `x`.
9
9
  * @returns The product as an array of rows (`ncol(x)` x `ncol(y)`).
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * crossprod([[1, 2], [3, 4]]); // [[10, 14], [14, 20]]
14
+ * crossprod([[1, 2], [3, 4]], [1, 1]); // [[4], [6]]
15
+ * ```
16
+ *
17
+ * @category Linear algebra
10
18
  */
11
19
  export declare function crossprod(x: VectorOrMatrix, y?: VectorOrMatrix): number[][];
12
20
  /**
@@ -17,9 +25,20 @@ export declare function crossprod(x: VectorOrMatrix, y?: VectorOrMatrix): number
17
25
  * @param x A matrix (array of rows) or a vector.
18
26
  * @param y A matrix or a vector with the same number of columns as `x`. Defaults to `x`.
19
27
  * @returns The product as an array of rows (`nrow(x)` x `nrow(y)`).
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * tcrossprod([[1, 2], [3, 4]]); // [[5, 11], [11, 25]]
32
+ * ```
33
+ *
34
+ * @category Linear algebra
20
35
  */
21
36
  export declare function tcrossprod(x: VectorOrMatrix, y?: VectorOrMatrix): number[][];
22
- /** Options for {@link backsolve} and {@link forwardsolve}. */
37
+ /**
38
+ * Options for {@link backsolve} and {@link forwardsolve}.
39
+ *
40
+ * @category Linear algebra
41
+ */
23
42
  export interface BacksolveOptions {
24
43
  /** Number of rows and columns of the triangular matrix to use (its top-left `k` x `k` block). Default: the number of columns of the matrix. */
25
44
  k?: number;
@@ -38,10 +57,18 @@ export interface BacksolveOptions {
38
57
  * @param x The right-hand side vector.
39
58
  * @param options See {@link BacksolveOptions}.
40
59
  * @returns The solution `y`, a vector of length `k`.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * backsolve([[2, 1], [0, 4]], [4, 8]); // [1, 2]
64
+ * backsolve([[2, 1], [0, 4]], [[4, 2], [8, 4]]); // [[1, 0.5], [2, 1]]
65
+ * ```
66
+ *
67
+ * @category Linear algebra
41
68
  */
42
69
  export declare function backsolve(r: MatrixInput, x: readonly number[] | Float64Array, options?: BacksolveOptions): number[];
43
70
  /**
44
- * Solves the triangular system `r y = x` with a matrix right-hand side. Equivalent to R's `backsolve()`.
71
+ * Solves the triangular system `r y = x` with a matrix right-hand side.
45
72
  *
46
73
  * @param r A triangular matrix (array of rows).
47
74
  * @param x The right-hand side matrix (array of rows); only its first `k` rows are used.
@@ -50,7 +77,7 @@ export declare function backsolve(r: MatrixInput, x: readonly number[] | Float64
50
77
  */
51
78
  export declare function backsolve(r: MatrixInput, x: MatrixInput, options?: BacksolveOptions): number[][];
52
79
  /**
53
- * Solves the triangular system `r y = x`. Equivalent to R's `backsolve()`.
80
+ * Solves the triangular system `r y = x`.
54
81
  *
55
82
  * @param r A triangular matrix (array of rows).
56
83
  * @param x The right-hand side, a vector or a matrix.
@@ -68,10 +95,17 @@ export declare function backsolve(r: MatrixInput, x: VectorOrMatrix, options?: B
68
95
  * @param x The right-hand side vector.
69
96
  * @param options See {@link BacksolveOptions}.
70
97
  * @returns The solution `y`, a vector of length `k`.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * forwardsolve([[2, 0], [1, 4]], [4, 10]); // [2, 2]
102
+ * ```
103
+ *
104
+ * @category Linear algebra
71
105
  */
72
106
  export declare function forwardsolve(l: MatrixInput, x: readonly number[] | Float64Array, options?: BacksolveOptions): number[];
73
107
  /**
74
- * Solves the triangular system `l y = x` with a matrix right-hand side. Equivalent to R's `forwardsolve()`.
108
+ * Solves the triangular system `l y = x` with a matrix right-hand side.
75
109
  *
76
110
  * @param l A triangular matrix (array of rows).
77
111
  * @param x The right-hand side matrix (array of rows); only its first `k` rows are used.
@@ -80,7 +114,7 @@ export declare function forwardsolve(l: MatrixInput, x: readonly number[] | Floa
80
114
  */
81
115
  export declare function forwardsolve(l: MatrixInput, x: MatrixInput, options?: BacksolveOptions): number[][];
82
116
  /**
83
- * Solves the triangular system `l y = x`. Equivalent to R's `forwardsolve()`.
117
+ * Solves the triangular system `l y = x`.
84
118
  *
85
119
  * @param l A triangular matrix (array of rows).
86
120
  * @param x The right-hand side, a vector or a matrix.
@@ -15,6 +15,14 @@ import { fromMat, isMatrixInput, newMat, toMat, toMatOrColumn } from "./matrix.j
15
15
  * @param x A matrix (array of rows) or a vector.
16
16
  * @param y A matrix or a vector with the same number of rows as `x`. Defaults to `x`.
17
17
  * @returns The product as an array of rows (`ncol(x)` x `ncol(y)`).
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * crossprod([[1, 2], [3, 4]]); // [[10, 14], [14, 20]]
22
+ * crossprod([[1, 2], [3, 4]], [1, 1]); // [[4], [6]]
23
+ * ```
24
+ *
25
+ * @category Linear algebra
18
26
  */
19
27
  export function crossprod(x, y) {
20
28
  const a = toMatOrColumn(x);
@@ -46,6 +54,13 @@ export function crossprod(x, y) {
46
54
  * @param x A matrix (array of rows) or a vector.
47
55
  * @param y A matrix or a vector with the same number of columns as `x`. Defaults to `x`.
48
56
  * @returns The product as an array of rows (`nrow(x)` x `nrow(y)`).
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * tcrossprod([[1, 2], [3, 4]]); // [[5, 11], [11, 25]]
61
+ * ```
62
+ *
63
+ * @category Linear algebra
49
64
  */
50
65
  export function tcrossprod(x, y) {
51
66
  const a = toMatOrColumn(x);
@@ -1,12 +1,20 @@
1
1
  import { type Mat, type MatrixInput } from "./matrix.js";
2
- /** Options for {@link chol}. */
2
+ /**
3
+ * Options for {@link chol}.
4
+ *
5
+ * @category Linear algebra
6
+ */
3
7
  export interface CholOptions {
4
8
  /** Use diagonal pivoting (largest remaining diagonal first), which also works for positive semi-definite matrices. Default: `false`. */
5
9
  pivot?: boolean;
6
10
  /** Stopping tolerance for the pivoted decomposition. A negative value means `n * eps * max(diag(x))`. Default: `-1`. Used only with `pivot: true`. */
7
11
  tol?: number;
8
12
  }
9
- /** Result of {@link chol} with `pivot: true`. */
13
+ /**
14
+ * Result of {@link chol} with `pivot: true`.
15
+ *
16
+ * @category Linear algebra
17
+ */
10
18
  export interface CholPivotResult {
11
19
  /** The upper triangular factor `R`, such that `x[pivot, pivot] = t(R) R` (within the first `rank` rows). */
12
20
  r: number[][];
@@ -30,12 +38,14 @@ export interface CholPivotResult {
30
38
  * chol([[4, 2], [2, 3]]);
31
39
  * // [[2, 1], [0, 1.4142135623730951]]
32
40
  * ```
41
+ *
42
+ * @category Linear algebra
33
43
  */
34
44
  export declare function chol(x: MatrixInput, options?: CholOptions & {
35
45
  pivot?: false;
36
46
  }): number[][];
37
47
  /**
38
- * Pivoted Cholesky decomposition. Equivalent to R's `chol(x, pivot = TRUE)`.
48
+ * Pivoted Cholesky decomposition, as R's `chol(x, pivot = TRUE)`.
39
49
  *
40
50
  * Does not throw for rank-deficient (positive semi-definite) matrices; check `rank` instead (R gives a
41
51
  * warning). Rows of `r` after `rank` are not meaningful: the diagonal element at the stopping position holds
@@ -55,7 +65,7 @@ export declare function chol(x: MatrixInput, options: CholOptions & {
55
65
  pivot: true;
56
66
  }): CholPivotResult;
57
67
  /**
58
- * Cholesky decomposition, with or without pivoting. Equivalent to R's `chol()`.
68
+ * Cholesky decomposition, with or without pivoting.
59
69
  *
60
70
  * @param x A square symmetric matrix (array of rows).
61
71
  * @param options See {@link CholOptions}.
@@ -64,7 +74,11 @@ export declare function chol(x: MatrixInput, options: CholOptions & {
64
74
  export declare function chol(x: MatrixInput, options?: CholOptions): number[][] | CholPivotResult;
65
75
  /** Overwrite a with its upper-triangular Cholesky factor (dpotf2). Returns the failing column (1-based), or 0 on success */
66
76
  export declare function potf2(A: Mat): number;
67
- /** Options for {@link chol2inv}. */
77
+ /**
78
+ * Options for {@link chol2inv}.
79
+ *
80
+ * @category Linear algebra
81
+ */
68
82
  export interface Chol2InvOptions {
69
83
  /** Number of rows and columns of `x` to use (its top-left `size` x `size` upper triangle). Default: the number of columns of `x`. */
70
84
  size?: number;
@@ -77,6 +91,13 @@ export interface Chol2InvOptions {
77
91
  * @param x The upper triangular Cholesky factor `R` (array of rows), e.g. from {@link chol}. A vector is treated as a one-column matrix.
78
92
  * @param options See {@link Chol2InvOptions}.
79
93
  * @returns The symmetric inverse matrix (`size` x `size`) as an array of rows.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * chol2inv([[2, 1], [0, 1]]); // [[0.5, -0.5], [-0.5, 1]]
98
+ * ```
99
+ *
100
+ * @category Linear algebra
80
101
  */
81
102
  export declare function chol2inv(x: MatrixInput | readonly number[] | Float64Array, options?: Chol2InvOptions): number[][];
82
103
  /** From upper-triangular R, compute the upper triangle of (t(R) R)^-1 in place (dpotri = dtrti2 + dlauu2) */
@@ -128,6 +128,13 @@ function pstf2(A, tol) {
128
128
  * @param x The upper triangular Cholesky factor `R` (array of rows), e.g. from {@link chol}. A vector is treated as a one-column matrix.
129
129
  * @param options See {@link Chol2InvOptions}.
130
130
  * @returns The symmetric inverse matrix (`size` x `size`) as an array of rows.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * chol2inv([[2, 1], [0, 1]]); // [[0.5, -0.5], [-0.5, 1]]
135
+ * ```
136
+ *
137
+ * @category Linear algebra
131
138
  */
132
139
  export function chol2inv(x, options = {}) {
133
140
  const m = toMatOrColumn(x);
@@ -1,5 +1,9 @@
1
1
  import { type Mat, type MatrixInput } from "./matrix.js";
2
- /** Options for {@link eigen}. */
2
+ /**
3
+ * Options for {@link eigen}.
4
+ *
5
+ * @category Linear algebra
6
+ */
3
7
  export interface EigenOptions {
4
8
  /**
5
9
  * Treat the matrix as symmetric (only its lower triangle is then used). Default: detected automatically,
@@ -9,7 +13,11 @@ export interface EigenOptions {
9
13
  /** Compute only the eigenvalues. Default: `false`. R's `only.values`. */
10
14
  onlyValues?: boolean;
11
15
  }
12
- /** Result of {@link eigen}. */
16
+ /**
17
+ * Result of {@link eigen}.
18
+ *
19
+ * @category Linear algebra
20
+ */
13
21
  export interface EigenResult {
14
22
  /**
15
23
  * The eigenvalues (their real parts if complex). Sorted in decreasing order for a symmetric matrix, and by
@@ -39,13 +47,14 @@ export interface EigenResult {
39
47
  *
40
48
  * @example
41
49
  * ```ts
42
- * eigen([[2, 1], [1, 2]]);
43
- * // values: [3, 1] (up to rounding)
44
- * // vectors: [[0.7071, 0.7071], [0.7071, -0.7071]] (signs may differ from R)
50
+ * const e = eigen([[2, 1], [1, 2]]);
51
+ * e.values; // [3, 1]
52
+ * e.vectors; // [[0.7071, 0.7071], [0.7071, -0.7071]] (signs may differ from R)
45
53
  *
46
- * eigen([[0, -1], [1, 0]]);
47
- * // values: [0, 0], valuesIm: [1, -1]
54
+ * eigen([[0, -1], [1, 0]]); // { values: [0, 0], valuesIm: [1, -1] }
48
55
  * ```
56
+ *
57
+ * @category Linear algebra
49
58
  */
50
59
  export declare function eigen(x: MatrixInput, options?: EigenOptions): EigenResult;
51
60
  /** Same test as R's isSymmetric (all.equal(A, t(A), tolerance = 100 ε)) */
@@ -31,13 +31,14 @@ import { fromMat, newMat, requireSquare, toMat } from "./matrix.js";
31
31
  *
32
32
  * @example
33
33
  * ```ts
34
- * eigen([[2, 1], [1, 2]]);
35
- * // values: [3, 1] (up to rounding)
36
- * // vectors: [[0.7071, 0.7071], [0.7071, -0.7071]] (signs may differ from R)
34
+ * const e = eigen([[2, 1], [1, 2]]);
35
+ * e.values; // [3, 1]
36
+ * e.vectors; // [[0.7071, 0.7071], [0.7071, -0.7071]] (signs may differ from R)
37
37
  *
38
- * eigen([[0, -1], [1, 0]]);
39
- * // values: [0, 0], valuesIm: [1, -1]
38
+ * eigen([[0, -1], [1, 0]]); // { values: [0, 0], valuesIm: [1, -1] }
40
39
  * ```
40
+ *
41
+ * @category Linear algebra
41
42
  */
42
43
  export function eigen(x, options = {}) {
43
44
  const a = toMat(x);
@@ -1,7 +1,15 @@
1
1
  import { type Mat, type MatrixInput } from "./matrix.js";
2
- /** Methods of {@link expm}. */
2
+ /**
3
+ * Methods of {@link expm}.
4
+ *
5
+ * @category Linear algebra
6
+ */
3
7
  export type ExpmMethod = "Higham08.b" | "Higham08" | "Pade" | "Taylor" | "PadeO" | "TaylorO";
4
- /** Options for {@link expm}. */
8
+ /**
9
+ * Options for {@link expm}.
10
+ *
11
+ * @category Linear algebra
12
+ */
5
13
  export interface ExpmOptions {
6
14
  /**
7
15
  * `"Higham08.b"` (default): Higham's scaling and squaring with Padé approximants after balancing (LAPACK's
@@ -17,8 +25,8 @@ export interface ExpmOptions {
17
25
  order?: number;
18
26
  }
19
27
  /**
20
- * Matrix exponential. Equivalent to R's `expm::expm(x, method, order)` with methods `"Higham08.b"` (the default),
21
- * `"Higham08"`, `"Pade"`, `"Taylor"`, `"PadeO"` and `"TaylorO"`.
28
+ * Matrix exponential. Equivalent to `expm::expm(x, method, order)` in R. The methods are `"Higham08.b"` (the
29
+ * default), `"Higham08"`, `"Pade"`, `"Taylor"`, `"PadeO"` and `"TaylorO"`.
22
30
  *
23
31
  * `"Higham08.b"` and `"Higham08"` use the scaling and squaring method with Padé approximants of degree 3, 5, 7, 9 or
24
32
  * 13 (Higham 2005), with or without balancing first, and throw if a linear system of the method is computationally
@@ -32,8 +40,10 @@ export interface ExpmOptions {
32
40
  * @example
33
41
  * ```ts
34
42
  * expm([[0, 1], [0, 0]]); // [[1, 1], [0, 1]]
35
- * expm([[0, -1], [1, 0]]); // [[cos 1, -sin 1], [sin 1, cos 1]] (up to rounding)
43
+ * expm([[0, -1], [1, 0]]); // [[0.5403023059, -0.8414709848], [0.8414709848, 0.5403023059]] (cos 1 and sin 1)
36
44
  * ```
45
+ *
46
+ * @category Linear algebra
37
47
  */
38
48
  export declare function expm(x: MatrixInput, options?: ExpmOptions): number[][];
39
49
  /**
@@ -23,8 +23,8 @@ import { infNorm, oneNorm } from "./norm.js";
23
23
  import { solve } from "./solve.js";
24
24
  const METHODS = ["Higham08.b", "Higham08", "Pade", "Taylor", "PadeO", "TaylorO"];
25
25
  /**
26
- * Matrix exponential. Equivalent to R's `expm::expm(x, method, order)` with methods `"Higham08.b"` (the default),
27
- * `"Higham08"`, `"Pade"`, `"Taylor"`, `"PadeO"` and `"TaylorO"`.
26
+ * Matrix exponential. Equivalent to `expm::expm(x, method, order)` in R. The methods are `"Higham08.b"` (the
27
+ * default), `"Higham08"`, `"Pade"`, `"Taylor"`, `"PadeO"` and `"TaylorO"`.
28
28
  *
29
29
  * `"Higham08.b"` and `"Higham08"` use the scaling and squaring method with Padé approximants of degree 3, 5, 7, 9 or
30
30
  * 13 (Higham 2005), with or without balancing first, and throw if a linear system of the method is computationally
@@ -38,8 +38,10 @@ const METHODS = ["Higham08.b", "Higham08", "Pade", "Taylor", "PadeO", "TaylorO"]
38
38
  * @example
39
39
  * ```ts
40
40
  * expm([[0, 1], [0, 0]]); // [[1, 1], [0, 1]]
41
- * expm([[0, -1], [1, 0]]); // [[cos 1, -sin 1], [sin 1, cos 1]] (up to rounding)
41
+ * expm([[0, -1], [1, 0]]); // [[0.5403023059, -0.8414709848], [0.8414709848, 0.5403023059]] (cos 1 and sin 1)
42
42
  * ```
43
+ *
44
+ * @category Linear algebra
43
45
  */
44
46
  export function expm(x, options = {}) {
45
47
  const method = options.method ?? "Higham08.b";
@@ -1,6 +1,10 @@
1
1
  import { type Mat, type MatrixInput } from "./matrix.js";
2
2
  import { type NormType } from "./norm.js";
3
- /** Options for {@link kappa}. */
3
+ /**
4
+ * Options for {@link kappa}.
5
+ *
6
+ * @category Linear algebra
7
+ */
4
8
  export interface KappaOptions {
5
9
  /** Compute the condition number exactly instead of estimating it. Default: `false`. */
6
10
  exact?: boolean;
@@ -29,6 +33,14 @@ export interface KappaOptions {
29
33
  * @param z A matrix (array of rows).
30
34
  * @param options See {@link KappaOptions}.
31
35
  * @returns The (estimated) condition number.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * kappa([[1, 2], [3, 4]]); // 17.85 (LINPACK estimate)
40
+ * kappa([[1, 2], [3, 4]], { exact: true }); // 14.933034373659272
41
+ * ```
42
+ *
43
+ * @category Linear algebra
32
44
  */
33
45
  export declare function kappa(z: MatrixInput, options?: KappaOptions): number;
34
46
  /**
@@ -45,6 +57,14 @@ export declare function trco(T: Mat, upper: boolean): number;
45
57
  * @param x A matrix (array of rows).
46
58
  * @param options `tol`: relative tolerance for treating singular values as zero. Default: `sqrt(Number.EPSILON)`.
47
59
  * @returns The generalized inverse (`ncol` x `nrow`) as an array of rows.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * ginv([[1, 2], [3, 4]]); // [[-2, 1], [1.5, -0.5]]
64
+ * ginv([[1, 1], [1, 1]]); // [[0.25, 0.25], [0.25, 0.25]]
65
+ * ```
66
+ *
67
+ * @category Linear algebra
48
68
  */
49
69
  export declare function ginv(x: MatrixInput, options?: {
50
70
  tol?: number;
@@ -27,6 +27,14 @@ import { svd } from "./svd.js";
27
27
  * @param z A matrix (array of rows).
28
28
  * @param options See {@link KappaOptions}.
29
29
  * @returns The (estimated) condition number.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * kappa([[1, 2], [3, 4]]); // 17.85 (LINPACK estimate)
34
+ * kappa([[1, 2], [3, 4]], { exact: true }); // 14.933034373659272
35
+ * ```
36
+ *
37
+ * @category Linear algebra
30
38
  */
31
39
  export function kappa(z, options = {}) {
32
40
  // The default norm is "2" if exact, "1" if estimated
@@ -176,6 +184,14 @@ function asum(z) {
176
184
  * @param x A matrix (array of rows).
177
185
  * @param options `tol`: relative tolerance for treating singular values as zero. Default: `sqrt(Number.EPSILON)`.
178
186
  * @returns The generalized inverse (`ncol` x `nrow`) as an array of rows.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * ginv([[1, 2], [3, 4]]); // [[-2, 1], [1.5, -0.5]]
191
+ * ginv([[1, 1], [1, 1]]); // [[0.25, 0.25], [0.25, 0.25]]
192
+ * ```
193
+ *
194
+ * @category Linear algebra
179
195
  */
180
196
  export function ginv(x, options = {}) {
181
197
  const tol = options.tol ?? Math.sqrt(Number.EPSILON);
@@ -1,5 +1,9 @@
1
1
  import type { MatrixInput } from "./matrix.js";
2
- /** Result of {@link lu}: `x = P L U`. */
2
+ /**
3
+ * Result of {@link lu}: `x = P L U`.
4
+ *
5
+ * @category Linear algebra
6
+ */
3
7
  export interface LuResult {
4
8
  /** Permutation matrix (m x m). */
5
9
  P: number[][];
@@ -9,23 +13,34 @@ export interface LuResult {
9
13
  U: number[][];
10
14
  }
11
15
  /**
12
- * LU decomposition with partial (row) pivoting, `x = P L U`. Equivalent to `Matrix::expand(Matrix::lu(x))`
13
- * (LAPACK's dgetrf).
16
+ * LU decomposition with partial (row) pivoting, `x = P L U`. Equivalent to R's `Matrix::lu()`. The factors are those
17
+ * of `Matrix::expand(Matrix::lu(x))` (LAPACK's dgetrf).
14
18
  *
15
19
  * @example
16
20
  * ```ts
17
- * const { P, L, U } = lu([[1, 2], [3, 4]]); // P = [[0, 1], [1, 0]], L = [[1, 0], [1/3, 1]], U = [[3, 4], [0, 2/3]]
21
+ * lu([[1, 2], [3, 4]]);
22
+ * // { P: [[0, 1], [1, 0]], L: [[1, 0], [0.3333333333333333, 1]], U: [[3, 4], [0, 0.6666666666666667]] }
18
23
  * ```
24
+ *
25
+ * @category Linear algebra
19
26
  */
20
27
  export declare function lu(x: MatrixInput): LuResult;
21
- /** Options for {@link prcomp}. */
28
+ /**
29
+ * Options for {@link prcomp}.
30
+ *
31
+ * @category Linear algebra
32
+ */
22
33
  export interface PrcompOptions {
23
34
  /** Centre the columns (default `true`), or subtract the given values. */
24
35
  center?: boolean | readonly number[];
25
36
  /** Scale the columns to unit variance (default `false`), or divide by the given values. */
26
37
  scale?: boolean | readonly number[];
27
38
  }
28
- /** Result of {@link prcomp}. */
39
+ /**
40
+ * Result of {@link prcomp}.
41
+ *
42
+ * @category Linear algebra
43
+ */
29
44
  export interface PrcompResult {
30
45
  /** Standard deviations of the principal components. */
31
46
  sdev: number[];
@@ -41,5 +56,14 @@ export interface PrcompResult {
41
56
  /**
42
57
  * Principal components of the columns of `x` (observations as rows). Equivalent to R's `prcomp()`. The sign of each
43
58
  * component is arbitrary, as in R.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const pc = prcomp([[1, 2], [2, 1], [3, 4], [4, 3]]);
63
+ * pc.sdev; // [1.632993161855452, 0.816496580927726]
64
+ * pc.x; // [[-1.4142, 0.7071], [-1.4142, -0.7071], [1.4142, 0.7071], [1.4142, -0.7071]] (signs may differ from R)
65
+ * ```
66
+ *
67
+ * @category Linear algebra
44
68
  */
45
69
  export declare function prcomp(x: MatrixInput, options?: PrcompOptions): PrcompResult;