@numero-uno-jpn/rstats 0.10.0 → 0.11.1

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 (280) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.ja.md +13 -9
  3. package/README.md +13 -8
  4. package/dist/chunks/{chunk-QJJWGNJP.js → chunk-2X7JYQBI.js} +2 -2
  5. package/dist/chunks/{chunk-O6PT7IVU.js → chunk-36GVER3O.js} +2 -2
  6. package/dist/chunks/{chunk-EWC6I75B.js → chunk-3WUXRSM6.js} +1 -1
  7. package/dist/chunks/{chunk-4NM37MGA.js → chunk-6I6QKTFK.js} +2 -2
  8. package/dist/chunks/{chunk-2XKG3DX4.js → chunk-ETOEZTGL.js} +1 -1
  9. package/dist/chunks/{chunk-IT354SHV.js → chunk-FVPDVRJQ.js} +2 -2
  10. package/dist/chunks/{chunk-QULPY6YM.js → chunk-GG4BJMJW.js} +1 -1
  11. package/dist/chunks/{chunk-7HPVUVZB.js → chunk-HITD7CX6.js} +1 -1
  12. package/dist/chunks/{chunk-LIMZKONM.js → chunk-KK4GE65D.js} +2 -2
  13. package/dist/chunks/chunk-LAUYSGV4.js +3 -0
  14. package/dist/chunks/chunk-M6GDXKKS.js +2 -0
  15. package/dist/chunks/{chunk-QFULZNHL.js → chunk-PHHUHR7T.js} +1 -1
  16. package/dist/chunks/{chunk-ENL43FNO.js → chunk-WQPFDDIY.js} +2 -2
  17. package/dist/chunks/chunk-X2AWQSVS.js +2 -0
  18. package/dist/chunks/{chunk-ZRIM4R4A.js → chunk-ZRJQD7VS.js} +2 -2
  19. package/dist/data/grouping.d.ts +100 -0
  20. package/dist/data/grouping.js +264 -0
  21. package/dist/descriptive/basic.d.ts +130 -17
  22. package/dist/descriptive/basic.js +115 -14
  23. package/dist/descriptive/cov.d.ts +22 -12
  24. package/dist/descriptive/dataFrames.d.ts +138 -0
  25. package/dist/descriptive/dataFrames.js +400 -0
  26. package/dist/descriptive/factanal.d.ts +26 -6
  27. package/dist/descriptive/factanal.js +7 -3
  28. package/dist/descriptive/hist.d.ts +27 -6
  29. package/dist/descriptive/hist.js +9 -3
  30. package/dist/descriptive/missing.d.ts +42 -0
  31. package/dist/descriptive/missing.js +52 -0
  32. package/dist/descriptive/moments.d.ts +91 -13
  33. package/dist/descriptive/moments.js +66 -9
  34. package/dist/descriptive/omega.d.ts +28 -6
  35. package/dist/descriptive/omega.js +16 -4
  36. package/dist/descriptive/pivot.d.ts +105 -0
  37. package/dist/descriptive/pivot.js +347 -0
  38. package/dist/descriptive/quantile.d.ts +33 -5
  39. package/dist/descriptive/quantile.js +20 -2
  40. package/dist/descriptive/rank.d.ts +12 -2
  41. package/dist/descriptive/rank.js +2 -0
  42. package/dist/descriptive/table.d.ts +55 -7
  43. package/dist/descriptive/table.js +38 -4
  44. package/dist/descriptive.js +2 -2
  45. package/dist/distributions/arcsine.d.ts +40 -5
  46. package/dist/distributions/arcsine.js +35 -4
  47. package/dist/distributions/beta.d.ts +12 -0
  48. package/dist/distributions/beta.js +12 -0
  49. package/dist/distributions/binomial.d.ts +18 -0
  50. package/dist/distributions/binomial.js +18 -0
  51. package/dist/distributions/bvnorm.d.ts +4 -1
  52. package/dist/distributions/bvnorm.js +4 -1
  53. package/dist/distributions/cauchy.d.ts +24 -0
  54. package/dist/distributions/cauchy.js +24 -0
  55. package/dist/distributions/chisq.d.ts +18 -0
  56. package/dist/distributions/chisq.js +18 -0
  57. package/dist/distributions/exponential.d.ts +29 -1
  58. package/dist/distributions/exponential.js +24 -0
  59. package/dist/distributions/f.d.ts +18 -0
  60. package/dist/distributions/f.js +18 -0
  61. package/dist/distributions/gamma.d.ts +20 -0
  62. package/dist/distributions/gamma.js +18 -0
  63. package/dist/distributions/geometric.d.ts +24 -0
  64. package/dist/distributions/geometric.js +24 -0
  65. package/dist/distributions/hypergeometric.d.ts +24 -0
  66. package/dist/distributions/hypergeometric.js +24 -0
  67. package/dist/distributions/invgamma.d.ts +32 -4
  68. package/dist/distributions/invgamma.js +27 -3
  69. package/dist/distributions/kumaraswamy.d.ts +31 -3
  70. package/dist/distributions/kumaraswamy.js +31 -3
  71. package/dist/distributions/laplace.d.ts +36 -4
  72. package/dist/distributions/laplace.js +31 -3
  73. package/dist/distributions/logistic.d.ts +29 -1
  74. package/dist/distributions/logistic.js +24 -0
  75. package/dist/distributions/lognormal.d.ts +29 -1
  76. package/dist/distributions/lognormal.js +24 -0
  77. package/dist/distributions/multinomial.d.ts +7 -1
  78. package/dist/distributions/multinomial.js +2 -0
  79. package/dist/distributions/negbinomial.d.ts +29 -1
  80. package/dist/distributions/negbinomial.js +24 -0
  81. package/dist/distributions/normal.d.ts +11 -1
  82. package/dist/distributions/normal.js +6 -0
  83. package/dist/distributions/pareto.d.ts +36 -4
  84. package/dist/distributions/pareto.js +31 -3
  85. package/dist/distributions/poisson.d.ts +18 -0
  86. package/dist/distributions/poisson.js +18 -0
  87. package/dist/distributions/signrank.d.ts +24 -0
  88. package/dist/distributions/signrank.js +24 -0
  89. package/dist/distributions/summary.d.ts +20 -2
  90. package/dist/distributions/summary.js +4 -0
  91. package/dist/distributions/t.d.ts +18 -0
  92. package/dist/distributions/t.js +18 -0
  93. package/dist/distributions/triangular.d.ts +36 -4
  94. package/dist/distributions/triangular.js +31 -3
  95. package/dist/distributions/tukey.d.ts +15 -1
  96. package/dist/distributions/tukey.js +10 -0
  97. package/dist/distributions/uniform.d.ts +29 -1
  98. package/dist/distributions/uniform.js +24 -0
  99. package/dist/distributions/weibull.d.ts +29 -1
  100. package/dist/distributions/weibull.js +24 -0
  101. package/dist/distributions/wilcox.d.ts +24 -0
  102. package/dist/distributions/wilcox.js +24 -0
  103. package/dist/distributions.js +2 -2
  104. package/dist/entries/descriptive.d.ts +5 -1
  105. package/dist/entries/descriptive.js +4 -0
  106. package/dist/entries/numerics.d.ts +1 -1
  107. package/dist/entries/tests.js +1 -1
  108. package/dist/htest/agreement.d.ts +61 -23
  109. package/dist/htest/agreement.js +19 -9
  110. package/dist/htest/ansariTest.d.ts +19 -1
  111. package/dist/htest/ansariTest.js +5 -17
  112. package/dist/htest/aov.d.ts +43 -10
  113. package/dist/htest/aov.js +17 -3
  114. package/dist/htest/binomTest.d.ts +12 -2
  115. package/dist/htest/binomTest.js +2 -0
  116. package/dist/htest/brunnerMunzelTest.d.ts +9 -3
  117. package/dist/htest/brunnerMunzelTest.js +4 -2
  118. package/dist/htest/chisqTest.d.ts +19 -3
  119. package/dist/htest/cor.d.ts +31 -3
  120. package/dist/htest/cor.js +9 -27
  121. package/dist/htest/effectSize.d.ts +70 -12
  122. package/dist/htest/effectSize.js +40 -7
  123. package/dist/htest/fisherTest.d.ts +9 -1
  124. package/dist/htest/fisherTest.js +2 -0
  125. package/dist/htest/groups.d.ts +5 -1
  126. package/dist/htest/ksTest.d.ts +32 -2
  127. package/dist/htest/ksTest.js +5 -8
  128. package/dist/htest/leveneTest.d.ts +15 -4
  129. package/dist/htest/leveneTest.js +5 -2
  130. package/dist/htest/mantelhaenTest.d.ts +25 -3
  131. package/dist/htest/mantelhaenTest.js +15 -1
  132. package/dist/htest/mcnemarTest.d.ts +14 -4
  133. package/dist/htest/mcnemarTest.js +4 -2
  134. package/dist/htest/multipleComparisons.d.ts +173 -29
  135. package/dist/htest/multipleComparisons.js +123 -19
  136. package/dist/htest/normalityTests.d.ts +56 -9
  137. package/dist/htest/normalityTests.js +40 -6
  138. package/dist/htest/onewayTest.d.ts +45 -2
  139. package/dist/htest/onewayTest.js +15 -7
  140. package/dist/htest/pAdjust.d.ts +9 -1
  141. package/dist/htest/pAdjust.js +2 -0
  142. package/dist/htest/pairwise.d.ts +50 -5
  143. package/dist/htest/pairwise.js +25 -0
  144. package/dist/htest/poissonTest.d.ts +12 -2
  145. package/dist/htest/poissonTest.js +2 -0
  146. package/dist/htest/polycor.d.ts +29 -10
  147. package/dist/htest/power.d.ts +60 -6
  148. package/dist/htest/power.js +6 -0
  149. package/dist/htest/propTest.d.ts +13 -2
  150. package/dist/htest/propTest.js +2 -0
  151. package/dist/htest/pwr.d.ts +286 -36
  152. package/dist/htest/pwr.js +116 -15
  153. package/dist/htest/rankTests.d.ts +132 -7
  154. package/dist/htest/rankTests.js +30 -33
  155. package/dist/htest/tTest.d.ts +32 -2
  156. package/dist/htest/tTest.js +19 -24
  157. package/dist/htest/testFormula.d.ts +57 -0
  158. package/dist/htest/testFormula.js +171 -0
  159. package/dist/htest/trendTests.d.ts +29 -8
  160. package/dist/htest/trendTests.js +8 -4
  161. package/dist/htest/types.d.ts +14 -2
  162. package/dist/htest/varTest.d.ts +46 -6
  163. package/dist/htest/varTest.js +11 -21
  164. package/dist/htest/wilcoxTest.d.ts +23 -1
  165. package/dist/htest/wilcoxTest.js +9 -24
  166. package/dist/internal/dpq.d.ts +4 -0
  167. package/dist/internal/noncentral.d.ts +2 -0
  168. package/dist/internal/vectorize.d.ts +4 -0
  169. package/dist/linalg/basic.d.ts +39 -5
  170. package/dist/linalg/basic.js +15 -0
  171. package/dist/linalg/chol.d.ts +26 -5
  172. package/dist/linalg/chol.js +7 -0
  173. package/dist/linalg/eigen.d.ts +16 -7
  174. package/dist/linalg/eigen.js +6 -5
  175. package/dist/linalg/expm.d.ts +15 -5
  176. package/dist/linalg/expm.js +5 -3
  177. package/dist/linalg/kappa.d.ts +21 -1
  178. package/dist/linalg/kappa.js +16 -0
  179. package/dist/linalg/lu.d.ts +30 -6
  180. package/dist/linalg/lu.js +15 -3
  181. package/dist/linalg/matrix.d.ts +4 -0
  182. package/dist/linalg/norm.d.ts +16 -1
  183. package/dist/linalg/norm.js +9 -0
  184. package/dist/linalg/ops.d.ts +168 -36
  185. package/dist/linalg/ops.js +116 -20
  186. package/dist/linalg/qr.d.ts +87 -12
  187. package/dist/linalg/qr.js +31 -0
  188. package/dist/linalg/schur.d.ts +8 -2
  189. package/dist/linalg/schur.js +3 -1
  190. package/dist/linalg/solve.d.ts +42 -6
  191. package/dist/linalg/solve.js +22 -0
  192. package/dist/linalg/svd.d.ts +12 -2
  193. package/dist/linalg/svd.js +2 -0
  194. package/dist/linalg.js +2 -2
  195. package/dist/models/anovaSequential.d.ts +26 -4
  196. package/dist/models/anovaSequential.js +3 -1
  197. package/dist/models/aovEz.d.ts +29 -6
  198. package/dist/models/aovEz.js +5 -2
  199. package/dist/models/aovStrata.d.ts +12 -2
  200. package/dist/models/carAnova.d.ts +9 -3
  201. package/dist/models/carAnova.js +4 -2
  202. package/dist/models/coxph.d.ts +33 -7
  203. package/dist/models/coxph.js +8 -3
  204. package/dist/models/glm.d.ts +128 -21
  205. package/dist/models/glm.js +71 -14
  206. package/dist/models/glmAnova.d.ts +30 -5
  207. package/dist/models/glmAnova.js +15 -2
  208. package/dist/models/glmConfint.d.ts +16 -2
  209. package/dist/models/glmConfint.js +9 -1
  210. package/dist/models/glmFamily.d.ts +27 -5
  211. package/dist/models/lm.d.ts +75 -17
  212. package/dist/models/lm.js +22 -4
  213. package/dist/models/mauchly.d.ts +20 -5
  214. package/dist/models/mauchly.js +7 -3
  215. package/dist/models/modelFrame.d.ts +5 -1
  216. package/dist/models/modelMatrix.d.ts +18 -4
  217. package/dist/models/modelMatrix.js +3 -1
  218. package/dist/models/survival.d.ts +41 -9
  219. package/dist/models/survival.js +10 -4
  220. package/dist/numerics/deriv.d.ts +21 -6
  221. package/dist/numerics/deriv.js +16 -5
  222. package/dist/numerics/integrate.d.ts +37 -7
  223. package/dist/numerics/integrate.js +8 -2
  224. package/dist/numerics/interp.d.ts +63 -12
  225. package/dist/numerics/interp.js +30 -6
  226. package/dist/numerics/ode.d.ts +15 -5
  227. package/dist/numerics/ode.js +5 -3
  228. package/dist/numerics.js +2 -2
  229. package/dist/optim/optim.d.ts +32 -8
  230. package/dist/optim/optim.js +8 -4
  231. package/dist/random/beta.d.ts +8 -0
  232. package/dist/random/beta.js +8 -0
  233. package/dist/random/binomial.d.ts +16 -0
  234. package/dist/random/binomial.js +16 -0
  235. package/dist/random/continuous.d.ts +51 -0
  236. package/dist/random/continuous.js +51 -0
  237. package/dist/random/extra.d.ts +66 -6
  238. package/dist/random/extra.js +66 -6
  239. package/dist/random/gamma.d.ts +33 -0
  240. package/dist/random/gamma.js +33 -0
  241. package/dist/random/hyper.d.ts +8 -0
  242. package/dist/random/hyper.js +8 -0
  243. package/dist/random/poisson.d.ts +25 -0
  244. package/dist/random/poisson.js +25 -0
  245. package/dist/random/r2dtable.d.ts +2 -0
  246. package/dist/random/r2dtable.js +2 -0
  247. package/dist/random/rank.d.ts +16 -0
  248. package/dist/random/rank.js +16 -0
  249. package/dist/random/rng.d.ts +49 -6
  250. package/dist/random/rng.js +29 -2
  251. package/dist/random/sample.d.ts +10 -2
  252. package/dist/random/sample.js +5 -1
  253. package/dist/random/streams.d.ts +13 -0
  254. package/dist/random/streams.js +13 -0
  255. package/dist/rstats.js +14 -14
  256. package/dist/special/besselIK.d.ts +11 -3
  257. package/dist/special/besselIK.js +6 -2
  258. package/dist/special/besselJY.d.ts +6 -2
  259. package/dist/special/besselJY.js +6 -2
  260. package/dist/special/beta.d.ts +16 -2
  261. package/dist/special/beta.js +16 -2
  262. package/dist/special/choose.d.ts +13 -5
  263. package/dist/special/choose.js +13 -5
  264. package/dist/special/erf.d.ts +8 -3
  265. package/dist/special/erf.js +8 -3
  266. package/dist/special/extra.d.ts +30 -10
  267. package/dist/special/extra.js +25 -9
  268. package/dist/special/gamma.d.ts +18 -2
  269. package/dist/special/gamma.js +18 -2
  270. package/dist/special/log1p.d.ts +16 -7
  271. package/dist/special/log1p.js +16 -7
  272. package/dist/special/psigamma.d.ts +9 -3
  273. package/dist/special/psigamma.js +9 -3
  274. package/dist/special/rCompatible.d.ts +5 -1
  275. package/dist/special.js +2 -2
  276. package/dist/tests.js +12 -13
  277. package/llms.txt +14 -0
  278. package/package.json +1 -1
  279. package/dist/chunks/chunk-AECGWZHD.js +0 -2
  280. package/dist/chunks/chunk-XWTZ4RTR.js +0 -2
@@ -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;
package/dist/linalg/lu.js CHANGED
@@ -12,13 +12,16 @@ import { matMul } from "./ops.js";
12
12
  /** Smallest normal double (LAPACK's dlamch("S")): below it, 1 / pivot would overflow. */
13
13
  const SFMIN = 2.2250738585072014e-308;
14
14
  /**
15
- * LU decomposition with partial (row) pivoting, `x = P L U`. Equivalent to `Matrix::expand(Matrix::lu(x))`
16
- * (LAPACK's dgetrf).
15
+ * LU decomposition with partial (row) pivoting, `x = P L U`. Equivalent to R's `Matrix::lu()`. The factors are those
16
+ * of `Matrix::expand(Matrix::lu(x))` (LAPACK's dgetrf).
17
17
  *
18
18
  * @example
19
19
  * ```ts
20
- * 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]]
20
+ * lu([[1, 2], [3, 4]]);
21
+ * // { P: [[0, 1], [1, 0]], L: [[1, 0], [0.3333333333333333, 1]], U: [[3, 4], [0, 0.6666666666666667]] }
21
22
  * ```
23
+ *
24
+ * @category Linear algebra
22
25
  */
23
26
  export function lu(x) {
24
27
  const m = x.length;
@@ -66,6 +69,15 @@ export function lu(x) {
66
69
  /**
67
70
  * Principal components of the columns of `x` (observations as rows). Equivalent to R's `prcomp()`. The sign of each
68
71
  * component is arbitrary, as in R.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const pc = prcomp([[1, 2], [2, 1], [3, 4], [4, 3]]);
76
+ * pc.sdev; // [1.632993161855452, 0.816496580927726]
77
+ * pc.x; // [[-1.4142, 0.7071], [-1.4142, -0.7071], [1.4142, 0.7071], [1.4142, -0.7071]] (signs may differ from R)
78
+ * ```
79
+ *
80
+ * @category Linear algebra
69
81
  */
70
82
  export function prcomp(x, options = {}) {
71
83
  const rows = x.map((r) => Array.from(r));
@@ -1,11 +1,15 @@
1
1
  /**
2
2
  * A matrix given as an array of rows. Each row may be a plain array or a `Float64Array`;
3
3
  * all rows must have the same length. A matrix with zero rows is treated as 0 x 0.
4
+ *
5
+ * @category Linear algebra
4
6
  */
5
7
  export type MatrixInput = readonly (readonly number[] | Float64Array)[];
6
8
  /**
7
9
  * A vector or a matrix (array of rows). Used for arguments that accept either, such as the
8
10
  * right-hand side of `backsolve`; a vector is treated as a one-column matrix, as in R.
11
+ *
12
+ * @category Linear algebra
9
13
  */
10
14
  export type VectorOrMatrix = readonly number[] | Float64Array | MatrixInput;
11
15
  /** Column-major matrix. Element (i, j) is data[i + j * nrow] */
@@ -2,9 +2,15 @@ import { type Mat, type MatrixInput } from "./matrix.js";
2
2
  /**
3
3
  * Matrix norm type for {@link norm}: `"O"`/`"1"` (one norm), `"I"` (infinity norm), `"F"`/`"E"` (Frobenius),
4
4
  * `"M"` (maximum modulus) or `"2"` (spectral norm). Case-insensitive, as in R.
5
+ *
6
+ * @category Linear algebra
5
7
  */
6
8
  export type NormType = "O" | "o" | "1" | "I" | "i" | "F" | "f" | "E" | "e" | "M" | "m" | "2";
7
- /** Options for {@link norm}. */
9
+ /**
10
+ * Options for {@link norm}.
11
+ *
12
+ * @category Linear algebra
13
+ */
8
14
  export interface NormOptions {
9
15
  /**
10
16
  * Which norm to compute (a single character, case-insensitive). Default: `"O"`.
@@ -24,6 +30,15 @@ export interface NormOptions {
24
30
  * @param x A matrix (array of rows).
25
31
  * @param options See {@link NormOptions}.
26
32
  * @returns The norm of `x`.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * norm([[1, -2], [3, 4]]); // 6 (one norm)
37
+ * norm([[1, -2], [3, 4]], { type: "I" }); // 7
38
+ * norm([[1, -2], [3, 4]], { type: "F" }); // 5.477225575051661
39
+ * ```
40
+ *
41
+ * @category Linear algebra
27
42
  */
28
43
  export declare function norm(x: MatrixInput, options?: NormOptions): number;
29
44
  export declare function oneNorm(m: Mat): number;
@@ -15,6 +15,15 @@ import { svdValues } from "./svd.js";
15
15
  * @param x A matrix (array of rows).
16
16
  * @param options See {@link NormOptions}.
17
17
  * @returns The norm of `x`.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * norm([[1, -2], [3, 4]]); // 6 (one norm)
22
+ * norm([[1, -2], [3, 4]], { type: "I" }); // 7
23
+ * norm([[1, -2], [3, 4]], { type: "F" }); // 5.477225575051661
24
+ * ```
25
+ *
26
+ * @category Linear algebra
18
27
  */
19
28
  export function norm(x, options = {}) {
20
29
  const m = toMat(x);