@numero-uno-jpn/rstats 0.5.0 → 0.6.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 (168) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.ja.md +36 -20
  3. package/README.md +34 -18
  4. package/THIRD_PARTY_NOTICES.md +25 -5
  5. package/dist/chunks/chunk-2JCIB5H2.js +2 -0
  6. package/dist/chunks/chunk-7JVSDGQQ.js +2 -0
  7. package/dist/chunks/chunk-7NK4SA6B.js +2 -0
  8. package/dist/chunks/chunk-AJYQNFXK.js +2 -0
  9. package/dist/chunks/chunk-DRNMIEYH.js +2 -0
  10. package/dist/chunks/chunk-NAYDS7CL.js +2 -0
  11. package/dist/chunks/chunk-NOCEAM44.js +2 -0
  12. package/dist/chunks/chunk-QNAIK4PY.js +2 -0
  13. package/dist/chunks/chunk-TPC6MTYC.js +2 -0
  14. package/dist/chunks/chunk-UGUQYWRQ.js +2 -0
  15. package/dist/chunks/chunk-XM2TVD63.js +2 -0
  16. package/dist/chunks/chunk-Y4IZV7XK.js +2 -0
  17. package/dist/chunks/chunk-ZWJ42QN6.js +2 -0
  18. package/dist/descriptive/basic.d.ts +73 -0
  19. package/dist/descriptive/basic.js +256 -0
  20. package/dist/descriptive/cov.d.ts +39 -0
  21. package/dist/descriptive/cov.js +105 -0
  22. package/dist/descriptive/hist.d.ts +64 -0
  23. package/dist/descriptive/hist.js +304 -0
  24. package/dist/descriptive/moments.d.ts +63 -0
  25. package/dist/descriptive/moments.js +158 -0
  26. package/dist/descriptive/quantile.d.ts +50 -0
  27. package/dist/descriptive/quantile.js +131 -0
  28. package/dist/descriptive/rank.d.ts +23 -0
  29. package/dist/descriptive/rank.js +72 -0
  30. package/dist/descriptive/table.d.ts +54 -0
  31. package/dist/descriptive/table.js +160 -0
  32. package/dist/descriptive.js +2 -0
  33. package/dist/distributions/arcsine.d.ts +24 -0
  34. package/dist/distributions/arcsine.js +73 -0
  35. package/dist/distributions/invgamma.d.ts +29 -0
  36. package/dist/distributions/invgamma.js +85 -0
  37. package/dist/distributions/kumaraswamy.d.ts +17 -0
  38. package/dist/distributions/kumaraswamy.js +96 -0
  39. package/dist/distributions/laplace.d.ts +23 -0
  40. package/dist/distributions/laplace.js +69 -0
  41. package/dist/distributions/multinomial.d.ts +24 -0
  42. package/dist/distributions/multinomial.js +70 -0
  43. package/dist/distributions/nbeta.js +28 -10
  44. package/dist/distributions/nchisq.js +20 -3
  45. package/dist/distributions/pareto.d.ts +23 -0
  46. package/dist/distributions/pareto.js +76 -0
  47. package/dist/distributions/summary.d.ts +25 -0
  48. package/dist/distributions/summary.js +289 -0
  49. package/dist/distributions/triangular.d.ts +25 -0
  50. package/dist/distributions/triangular.js +87 -0
  51. package/dist/distributions.js +2 -0
  52. package/dist/entries/descriptive.d.ts +7 -0
  53. package/dist/entries/descriptive.js +8 -0
  54. package/dist/entries/distributions.d.ts +41 -0
  55. package/dist/entries/distributions.js +41 -0
  56. package/dist/entries/linalg.d.ts +11 -0
  57. package/dist/entries/linalg.js +11 -0
  58. package/dist/entries/numerics.d.ts +8 -0
  59. package/dist/entries/numerics.js +6 -0
  60. package/dist/entries/special.d.ts +9 -0
  61. package/dist/entries/special.js +9 -0
  62. package/dist/entries/tests.d.ts +21 -0
  63. package/dist/entries/tests.js +20 -0
  64. package/dist/htest/ansariTest.d.ts +13 -0
  65. package/dist/htest/ansariTest.js +80 -0
  66. package/dist/htest/aov.d.ts +85 -0
  67. package/dist/htest/aov.js +178 -0
  68. package/dist/htest/binomTest.d.ts +36 -0
  69. package/dist/htest/binomTest.js +121 -0
  70. package/dist/htest/cor.d.ts +14 -0
  71. package/dist/htest/cor.js +4 -3
  72. package/dist/htest/core/ansari.d.ts +18 -0
  73. package/dist/htest/core/ansari.js +121 -0
  74. package/dist/htest/core/kolmogorov.d.ts +26 -0
  75. package/dist/htest/core/kolmogorov.js +221 -0
  76. package/dist/htest/core/mantelhaen.d.ts +26 -0
  77. package/dist/htest/core/mantelhaen.js +145 -0
  78. package/dist/htest/core/shapiro.d.ts +24 -0
  79. package/dist/htest/core/shapiro.js +142 -0
  80. package/dist/htest/core/smirnov.d.ts +20 -0
  81. package/dist/htest/core/smirnov.js +75 -0
  82. package/dist/htest/fisherTest.js +134 -120
  83. package/dist/htest/groups.d.ts +20 -0
  84. package/dist/htest/groups.js +62 -0
  85. package/dist/htest/ksTest.d.ts +31 -0
  86. package/dist/htest/ksTest.js +106 -0
  87. package/dist/htest/mantelhaenTest.d.ts +26 -0
  88. package/dist/htest/mantelhaenTest.js +196 -0
  89. package/dist/htest/mcnemarTest.d.ts +26 -0
  90. package/dist/htest/mcnemarTest.js +99 -0
  91. package/dist/htest/onewayTest.d.ts +26 -0
  92. package/dist/htest/onewayTest.js +97 -0
  93. package/dist/htest/pairwise.d.ts +64 -0
  94. package/dist/htest/pairwise.js +152 -0
  95. package/dist/htest/poissonTest.d.ts +35 -0
  96. package/dist/htest/poissonTest.js +170 -0
  97. package/dist/htest/propTest.d.ts +37 -0
  98. package/dist/htest/propTest.js +164 -0
  99. package/dist/htest/rankTests.d.ts +52 -0
  100. package/dist/htest/rankTests.js +234 -0
  101. package/dist/htest/types.d.ts +2 -0
  102. package/dist/htest/types.js +6 -0
  103. package/dist/htest/varTest.d.ts +48 -0
  104. package/dist/htest/varTest.js +118 -0
  105. package/dist/htest/wilcoxTest.js +136 -174
  106. package/dist/index.d.ts +6 -50
  107. package/dist/index.js +8 -50
  108. package/dist/integrate/quadpack.d.ts +29 -0
  109. package/dist/integrate/quadpack.js +525 -0
  110. package/dist/internal/seq.d.ts +5 -0
  111. package/dist/internal/seq.js +14 -0
  112. package/dist/internal/uniroot.js +10 -71
  113. package/dist/linalg/lu.d.ts +45 -0
  114. package/dist/linalg/lu.js +88 -0
  115. package/dist/linalg/ops.d.ts +90 -0
  116. package/dist/linalg/ops.js +320 -0
  117. package/dist/linalg.js +2 -0
  118. package/dist/models/lm.d.ts +98 -0
  119. package/dist/models/lm.js +187 -0
  120. package/dist/numerics/deriv.d.ts +37 -0
  121. package/dist/numerics/deriv.js +150 -0
  122. package/dist/numerics/integrate.d.ts +91 -0
  123. package/dist/numerics/integrate.js +264 -0
  124. package/dist/numerics/interp.d.ts +103 -0
  125. package/dist/numerics/interp.js +581 -0
  126. package/dist/numerics/ode.d.ts +23 -0
  127. package/dist/numerics/ode.js +59 -0
  128. package/dist/numerics.js +2 -0
  129. package/dist/optim/localmin.d.ts +16 -0
  130. package/dist/optim/localmin.js +97 -0
  131. package/dist/random/beta.js +1 -1
  132. package/dist/random/binomial.js +1 -1
  133. package/dist/random/continuous.js +1 -1
  134. package/dist/random/extra.d.ts +33 -0
  135. package/dist/random/extra.js +62 -0
  136. package/dist/random/gamma.js +1 -1
  137. package/dist/random/hyper.js +1 -1
  138. package/dist/random/mt.js +0 -1
  139. package/dist/random/poisson.js +0 -1
  140. package/dist/random/rank.js +1 -1
  141. package/dist/random/rng.js +1 -1
  142. package/dist/random/sample.js +1 -1
  143. package/dist/rstats.js +2 -2
  144. package/dist/special/besselIK.d.ts +38 -0
  145. package/dist/special/besselIK.js +315 -0
  146. package/dist/special/besselJY.d.ts +32 -0
  147. package/dist/special/besselJY.js +508 -0
  148. package/dist/special/besselSeries.d.ts +8 -0
  149. package/dist/special/besselSeries.js +24 -0
  150. package/dist/special/beta.js +22 -5
  151. package/dist/special/choose.d.ts +75 -0
  152. package/dist/special/choose.js +233 -0
  153. package/dist/special/erf.d.ts +28 -2
  154. package/dist/special/erf.js +37 -10
  155. package/dist/special/extra.d.ts +47 -0
  156. package/dist/special/extra.js +220 -0
  157. package/dist/special/igam.d.ts +4 -0
  158. package/dist/special/igam.js +57 -2
  159. package/dist/special/incbet.js +77 -22
  160. package/dist/special/lgammaDiff.d.ts +7 -0
  161. package/dist/special/lgammaDiff.js +16 -3
  162. package/dist/special/psigamma.d.ts +48 -0
  163. package/dist/special/psigamma.js +318 -0
  164. package/dist/special/rCompatible.d.ts +8 -0
  165. package/dist/special/rCompatible.js +1 -0
  166. package/dist/special.js +2 -0
  167. package/dist/tests.js +2 -0
  168. package/package.json +26 -1
@@ -0,0 +1,88 @@
1
+ // LU decomposition with partial pivoting (Matrix::lu / LAPACK's dgetrf) and principal components (R's prcomp).
2
+ //
3
+ // Written for rStats.js (no ported code). lu: Gaussian elimination by columns; the pivot of each column is the first
4
+ // entry of largest absolute value at or below the diagonal (LAPACK's idamax rule), so the row exchanges are the same
5
+ // as dgetrf's, and the multipliers are formed as LAPACK does, a_ij * (1 / pivot); rectangular matrices are allowed
6
+ // (L is m x min(m, n), U is min(m, n) x n), and a zero pivot leaves a 0 on the diagonal of U. prcomp: centre and scale
7
+ // the columns as R's scale, then the singular value decomposition:
8
+ // sdev = d / sqrt(max(1, n - 1)), rotation = V, scores = X V.
9
+ import { scale as scaleColumns } from "../descriptive/moments.js";
10
+ import { svd } from "./svd.js";
11
+ import { matMul } from "./ops.js";
12
+ /** Smallest normal double (LAPACK's dlamch("S")): below it, 1 / pivot would overflow. */
13
+ const SFMIN = 2.2250738585072014e-308;
14
+ /**
15
+ * LU decomposition with partial (row) pivoting, `x = P L U`. Equivalent to `Matrix::expand(Matrix::lu(x))`
16
+ * (LAPACK's dgetrf).
17
+ *
18
+ * @example
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]]
21
+ * ```
22
+ */
23
+ export function lu(x) {
24
+ const m = x.length;
25
+ const n = m === 0 ? 0 : x[0].length;
26
+ const a = x.map((r) => {
27
+ if (r.length !== n)
28
+ throw new TypeError("all rows of the matrix must have the same length");
29
+ return Array.from(r);
30
+ });
31
+ const perm = Array.from({ length: m }, (_, i) => i);
32
+ const k = Math.min(m, n);
33
+ for (let j = 0; j < k; j++) {
34
+ let p = j;
35
+ let best = Math.abs(a[j][j]);
36
+ for (let i = j + 1; i < m; i++) {
37
+ const v = Math.abs(a[i][j]);
38
+ if (v > best || Number.isNaN(best)) {
39
+ best = v;
40
+ p = i;
41
+ }
42
+ }
43
+ if (p !== j) {
44
+ [a[p], a[j]] = [a[j], a[p]];
45
+ [perm[p], perm[j]] = [perm[j], perm[p]];
46
+ }
47
+ const piv = a[j][j];
48
+ if (piv === 0)
49
+ continue;
50
+ // the multipliers as LAPACK forms them: times the reciprocal of the pivot, unless that would overflow
51
+ const inv = Math.abs(piv) >= SFMIN ? 1 / piv : NaN;
52
+ for (let i = j + 1; i < m; i++) {
53
+ const f = Number.isNaN(inv) ? a[i][j] / piv : a[i][j] * inv;
54
+ a[i][j] = f;
55
+ for (let c = j + 1; c < n; c++)
56
+ a[i][c] = a[i][c] - f * a[j][c];
57
+ }
58
+ }
59
+ const L = Array.from({ length: m }, (_, i) => Array.from({ length: k }, (_, j) => (i === j ? 1 : i > j ? a[i][j] : 0)));
60
+ const U = Array.from({ length: k }, (_, i) => Array.from({ length: n }, (_, j) => (j >= i ? a[i][j] : 0)));
61
+ // row i of P L U is row perm[i] of x: P has a 1 at (perm[i], i)
62
+ const P = Array.from({ length: m }, () => new Array(m).fill(0));
63
+ perm.forEach((r, i) => (P[r][i] = 1));
64
+ return { P, L, U };
65
+ }
66
+ /**
67
+ * Principal components of the columns of `x` (observations as rows). Equivalent to R's `prcomp()`. The sign of each
68
+ * component is arbitrary, as in R.
69
+ */
70
+ export function prcomp(x, options = {}) {
71
+ const rows = x.map((r) => Array.from(r));
72
+ const s = scaleColumns(rows, { center: options.center ?? true, scale: options.scale ?? false });
73
+ if (s.scale?.some((v) => v === 0))
74
+ throw new RangeError("cannot rescale a constant/zero column to unit variance");
75
+ const dec = svd(s.scaled, { nu: 0 });
76
+ const n = rows.length;
77
+ const rotation = dec.v;
78
+ const out = {
79
+ sdev: dec.d.map((d) => d / Math.sqrt(Math.max(1, n - 1))),
80
+ rotation,
81
+ x: matMul(s.scaled, rotation),
82
+ };
83
+ if (s.center !== undefined)
84
+ out.center = s.center;
85
+ if (s.scale !== undefined)
86
+ out.scale = s.scale;
87
+ return out;
88
+ }
@@ -0,0 +1,90 @@
1
+ import type { Sample } from "../htest/types.js";
2
+ /** A vector (plain array) or a matrix (array of rows). */
3
+ export type Operand = number | Sample | readonly (readonly number[])[];
4
+ type Matrix = number[][];
5
+ /**
6
+ * Matrix product. Equivalent to R's `x %*% y`: a vector is taken as a row or a column so that the product is
7
+ * defined (two vectors give their inner product as a 1 x 1 matrix).
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * matMul([[1, 2], [3, 4]], [[5], [6]]); // [[17], [39]]
12
+ * ```
13
+ */
14
+ export declare function matMul(x: Operand, y: Operand): Matrix;
15
+ /** Element-wise sum with R's recycling (R's `x + y`). */
16
+ export declare function add(x: Operand, y: Operand): number[] | Matrix;
17
+ /** Element-wise difference with R's recycling (R's `x - y`). */
18
+ export declare function subtract(x: Operand, y: Operand): number[] | Matrix;
19
+ /** Element-wise product with R's recycling (R's `x * y`); the matrix product is {@link matMul}. */
20
+ export declare function multiply(x: Operand, y: Operand): number[] | Matrix;
21
+ /** Element-wise quotient with R's recycling (R's `x / y`). */
22
+ export declare function divide(x: Operand, y: Operand): number[] | Matrix;
23
+ /**
24
+ * Outer product of two vectors: the matrix of `fun(x[i], y[j])`. Equivalent to R's `outer()`; `fun` is `"*"`
25
+ * (default), `"+"`, `"-"`, `"/"`, `"^"` or a function of two numbers.
26
+ */
27
+ export declare function outer(x: Sample, y: Sample, fun?: "*" | "+" | "-" | "/" | "^" | ((a: number, b: number) => number)): Matrix;
28
+ /** Transpose. Equivalent to R's `t()`: a vector becomes a 1-row matrix. */
29
+ export declare function t(x: Operand): Matrix;
30
+ /** Options for {@link diag}. */
31
+ export interface DiagOptions {
32
+ nrow?: number;
33
+ ncol?: number;
34
+ }
35
+ /**
36
+ * R's `diag()`, with its three meanings: the diagonal of a matrix (as a vector); the diagonal matrix of a vector of
37
+ * length 2 or more (its values recycled along the diagonal of an `nrow` x `ncol` matrix when given); and for a single
38
+ * number n, the n x n identity matrix (with `nrow`/`ncol`, a matrix with that number on the diagonal).
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * diag([[1, 2], [3, 4]]); // [1, 4]
43
+ * diag([2, 3]); // [[2, 0], [0, 3]]
44
+ * diag(3); // 3 x 3 identity
45
+ * ```
46
+ */
47
+ export declare function diag(x: Operand, options?: DiagOptions): number[] | Matrix;
48
+ /** Combine vectors and matrices as columns. Equivalent to R's `cbind()` (vectors recycled to the number of rows). */
49
+ export declare function cbind(...args: Operand[]): Matrix;
50
+ /** Combine vectors and matrices as rows. Equivalent to R's `rbind()`. */
51
+ export declare function rbind(...args: Operand[]): Matrix;
52
+ /** Options for {@link matrix}. */
53
+ export interface MatrixOptions {
54
+ nrow?: number;
55
+ ncol?: number;
56
+ /** Fill by rows instead of by columns (R's default). Default `false`. */
57
+ byrow?: boolean;
58
+ }
59
+ /**
60
+ * Build a matrix from data, recycled to fill it. Equivalent to R's `matrix()`: filled by columns unless `byrow`.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * matrix([1, 2, 3, 4, 5, 6], { nrow: 2 }); // [[1, 3, 5], [2, 4, 6]]
65
+ * matrix(0, { nrow: 2, ncol: 3 }); // zeros
66
+ * ```
67
+ */
68
+ export declare function matrix(data: number | Sample, options?: MatrixOptions): Matrix;
69
+ /** Kronecker product. Equivalent to R's `kronecker()` (two vectors give a vector). */
70
+ export declare function kronecker(x: Operand, y: Operand): number[] | Matrix;
71
+ /** Options for {@link seq}. */
72
+ export interface SeqOptions {
73
+ /** Increment. */
74
+ by?: number;
75
+ /** Desired length. */
76
+ lengthOut?: number;
77
+ }
78
+ /**
79
+ * Regular sequences. Equivalent to R's `seq()`: `seq(from, to)` steps by ±1; `by` steps by the increment, up to
80
+ * `to`; `lengthOut` gives that many values, both ends exact. `from` or `to` may be omitted (`undefined`) when the
81
+ * other two are given; `seq(n)` alone is `1, 2, ..., n`.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * seq(0, 1, { by: 0.25 }); // [0, 0.25, 0.5, 0.75, 1]
86
+ * seq(0, 1, { lengthOut: 3 }); // [0, 0.5, 1]
87
+ * ```
88
+ */
89
+ export declare function seq(from?: number, to?: number, options?: SeqOptions): number[];
90
+ export {};
@@ -0,0 +1,320 @@
1
+ // Matrix arithmetic and construction: R's %*% (matMul), element-wise +, -, *, / with R's recycling (add, subtract,
2
+ // multiply, divide), outer, t, diag, cbind, rbind, matrix, kronecker and seq.
3
+ //
4
+ // Written for rStats.js (no ported code). Matrices are arrays of rows, as everywhere in rStats.js; a plain array is a
5
+ // vector, which R treats as a row or a column as the operation needs. Element-wise operations recycle a shorter
6
+ // vector over a matrix in column-major order (R's storage order), as R does.
7
+ function isMatrix(x) {
8
+ return typeof x !== "number" && x.length > 0 && Array.isArray(x[0]);
9
+ }
10
+ function asVector(x) {
11
+ return typeof x === "number" ? [x] : Array.from(x);
12
+ }
13
+ function checkRows(x) {
14
+ const nc = x[0].length;
15
+ if (x.some((r) => r.length !== nc))
16
+ throw new TypeError("all rows of the matrix must have the same length");
17
+ return nc;
18
+ }
19
+ /**
20
+ * Matrix product. Equivalent to R's `x %*% y`: a vector is taken as a row or a column so that the product is
21
+ * defined (two vectors give their inner product as a 1 x 1 matrix).
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * matMul([[1, 2], [3, 4]], [[5], [6]]); // [[17], [39]]
26
+ * ```
27
+ */
28
+ export function matMul(x, y) {
29
+ let a;
30
+ let b;
31
+ if (isMatrix(x) && isMatrix(y)) {
32
+ a = x.map((r) => [...r]);
33
+ b = y.map((r) => [...r]);
34
+ }
35
+ else if (isMatrix(x)) {
36
+ const v = asVector(y);
37
+ const nc = checkRows(x);
38
+ a = x.map((r) => [...r]);
39
+ b = nc === v.length ? v.map((t) => [t]) : nc === 1 ? [v] : [];
40
+ }
41
+ else if (isMatrix(y)) {
42
+ const v = asVector(x);
43
+ b = y.map((r) => [...r]);
44
+ a = y.length === v.length ? [v] : y.length === 1 ? v.map((t) => [t]) : [];
45
+ }
46
+ else {
47
+ const u = asVector(x);
48
+ const v = asVector(y);
49
+ if (u.length === v.length) {
50
+ a = [u];
51
+ b = v.map((t) => [t]);
52
+ }
53
+ else if (u.length === 1) {
54
+ a = [u];
55
+ b = [v];
56
+ }
57
+ else if (v.length === 1) {
58
+ a = u.map((t) => [t]);
59
+ b = [v];
60
+ }
61
+ else
62
+ throw new RangeError("non-conformable arguments");
63
+ }
64
+ const n = a[0]?.length ?? 0;
65
+ if (a.length === 0 || b.length !== n)
66
+ throw new RangeError("non-conformable arguments");
67
+ checkRows(a);
68
+ const p = checkRows(b);
69
+ return a.map((row) => {
70
+ const out = new Array(p).fill(0);
71
+ for (let j = 0; j < p; j++) {
72
+ let s = 0;
73
+ for (let k = 0; k < n; k++)
74
+ s += row[k] * b[k][j];
75
+ out[j] = s;
76
+ }
77
+ return out;
78
+ });
79
+ }
80
+ /** Element-wise operation with R's recycling */
81
+ function elementwise(x, y, f) {
82
+ const mx = isMatrix(x);
83
+ const my = isMatrix(y);
84
+ if (mx && my) {
85
+ const nc = checkRows(x);
86
+ if (x.length !== y.length || nc !== checkRows(y))
87
+ throw new RangeError("non-conformable arrays");
88
+ return x.map((r, i) => r.map((v, j) => f(v, y[i][j])));
89
+ }
90
+ if (mx || my) {
91
+ const m = (mx ? x : y);
92
+ const v = asVector(mx ? y : x);
93
+ const nr = m.length;
94
+ const nc = checkRows(m);
95
+ if (v.length === 0)
96
+ return m.map((r) => r.map(() => NaN));
97
+ if (v.length > nr * nc)
98
+ throw new RangeError("dims [product " + nr * nc + "] do not match the length of object [" + v.length + "]");
99
+ // element (i, j) is number i + j nr in column-major order
100
+ return m.map((r, i) => r.map((t, j) => (mx ? f(t, v[(i + j * nr) % v.length]) : f(v[(i + j * nr) % v.length], t))));
101
+ }
102
+ const u = asVector(x);
103
+ const v = asVector(y);
104
+ if (u.length === 0 || v.length === 0)
105
+ return [];
106
+ const n = Math.max(u.length, v.length);
107
+ return Array.from({ length: n }, (_, i) => f(u[i % u.length], v[i % v.length]));
108
+ }
109
+ /** Element-wise sum with R's recycling (R's `x + y`). */
110
+ export function add(x, y) {
111
+ return elementwise(x, y, (a, b) => a + b);
112
+ }
113
+ /** Element-wise difference with R's recycling (R's `x - y`). */
114
+ export function subtract(x, y) {
115
+ return elementwise(x, y, (a, b) => a - b);
116
+ }
117
+ /** Element-wise product with R's recycling (R's `x * y`); the matrix product is {@link matMul}. */
118
+ export function multiply(x, y) {
119
+ return elementwise(x, y, (a, b) => a * b);
120
+ }
121
+ /** Element-wise quotient with R's recycling (R's `x / y`). */
122
+ export function divide(x, y) {
123
+ return elementwise(x, y, (a, b) => a / b);
124
+ }
125
+ const OUTER_OPS = {
126
+ "*": (a, b) => a * b,
127
+ "+": (a, b) => a + b,
128
+ "-": (a, b) => a - b,
129
+ "/": (a, b) => a / b,
130
+ "^": (a, b) => a ** b,
131
+ };
132
+ /**
133
+ * Outer product of two vectors: the matrix of `fun(x[i], y[j])`. Equivalent to R's `outer()`; `fun` is `"*"`
134
+ * (default), `"+"`, `"-"`, `"/"`, `"^"` or a function of two numbers.
135
+ */
136
+ export function outer(x, y, fun = "*") {
137
+ const f = typeof fun === "function" ? fun : OUTER_OPS[fun];
138
+ if (f === undefined)
139
+ throw new RangeError(`invalid fun "${String(fun)}"`);
140
+ const u = Array.from(x);
141
+ const v = Array.from(y);
142
+ return u.map((a) => v.map((b) => f(a, b)));
143
+ }
144
+ /** Transpose. Equivalent to R's `t()`: a vector becomes a 1-row matrix. */
145
+ export function t(x) {
146
+ if (!isMatrix(x))
147
+ return [asVector(x)];
148
+ const nc = checkRows(x);
149
+ return Array.from({ length: nc }, (_, j) => x.map((r) => r[j]));
150
+ }
151
+ /**
152
+ * R's `diag()`, with its three meanings: the diagonal of a matrix (as a vector); the diagonal matrix of a vector of
153
+ * length 2 or more (its values recycled along the diagonal of an `nrow` x `ncol` matrix when given); and for a single
154
+ * number n, the n x n identity matrix (with `nrow`/`ncol`, a matrix with that number on the diagonal).
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * diag([[1, 2], [3, 4]]); // [1, 4]
159
+ * diag([2, 3]); // [[2, 0], [0, 3]]
160
+ * diag(3); // 3 x 3 identity
161
+ * ```
162
+ */
163
+ export function diag(x, options = {}) {
164
+ if (isMatrix(x)) {
165
+ const nc = checkRows(x);
166
+ return Array.from({ length: Math.min(x.length, nc) }, (_, i) => x[i][i]);
167
+ }
168
+ const v = asVector(x);
169
+ let values;
170
+ let nrow;
171
+ if (v.length === 1 && options.nrow === undefined && options.ncol === undefined) {
172
+ nrow = Math.trunc(v[0]);
173
+ if (!(nrow >= 0))
174
+ throw new RangeError("invalid 'nrow' value (< 0)");
175
+ values = [1];
176
+ }
177
+ else {
178
+ values = v;
179
+ nrow = options.nrow ?? v.length;
180
+ }
181
+ const ncol = options.ncol ?? nrow;
182
+ const out = Array.from({ length: nrow }, () => new Array(ncol).fill(0));
183
+ for (let i = 0; i < Math.min(nrow, ncol); i++)
184
+ out[i][i] = values[i % values.length];
185
+ return nrow === 0 ? [] : out;
186
+ }
187
+ /** Columns of an operand for binding: a matrix's columns, or a vector (scalar) as one column of `n` values */
188
+ function bindParts(args, byColumn) {
189
+ const parts = args.map((a) => (isMatrix(a) ? (byColumn ? t(a) : a.map((r) => [...r])) : [asVector(a)]));
190
+ // the common length: the matrices' rows (cbind) or columns (rbind), else the longest vector
191
+ const mats = args.filter(isMatrix);
192
+ const len = mats.length > 0 ? (byColumn ? mats[0].length : checkRows(mats[0])) : Math.max(...parts.map((p) => p[0].length));
193
+ mats.forEach((m, k) => {
194
+ const l = byColumn ? m.length : checkRows(m);
195
+ if (l !== len) {
196
+ throw new RangeError(`number of ${byColumn ? "rows" : "columns"} of matrices must match (see arg ${k + 2})`);
197
+ }
198
+ });
199
+ return parts.flatMap((p) => p.map((v) => Array.from({ length: len }, (_, i) => v[i % v.length])));
200
+ }
201
+ /** Combine vectors and matrices as columns. Equivalent to R's `cbind()` (vectors recycled to the number of rows). */
202
+ export function cbind(...args) {
203
+ return t(bindParts(args, true));
204
+ }
205
+ /** Combine vectors and matrices as rows. Equivalent to R's `rbind()`. */
206
+ export function rbind(...args) {
207
+ return bindParts(args, false);
208
+ }
209
+ /**
210
+ * Build a matrix from data, recycled to fill it. Equivalent to R's `matrix()`: filled by columns unless `byrow`.
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * matrix([1, 2, 3, 4, 5, 6], { nrow: 2 }); // [[1, 3, 5], [2, 4, 6]]
215
+ * matrix(0, { nrow: 2, ncol: 3 }); // zeros
216
+ * ```
217
+ */
218
+ export function matrix(data, options = {}) {
219
+ const v = asVector(data);
220
+ const len = v.length;
221
+ let { nrow, ncol } = options;
222
+ if (nrow === undefined && ncol === undefined) {
223
+ nrow = len;
224
+ ncol = 1;
225
+ }
226
+ else if (nrow === undefined)
227
+ nrow = Math.ceil(len / ncol);
228
+ else if (ncol === undefined)
229
+ ncol = Math.ceil(len / nrow);
230
+ const byrow = options.byrow ?? false;
231
+ return Array.from({ length: nrow }, (_, i) => Array.from({ length: ncol }, (_, j) => (len === 0 ? NaN : v[(byrow ? i * ncol + j : i + j * nrow) % len])));
232
+ }
233
+ /** Kronecker product. Equivalent to R's `kronecker()` (two vectors give a vector). */
234
+ export function kronecker(x, y) {
235
+ if (!isMatrix(x) && !isMatrix(y)) {
236
+ const u = asVector(x);
237
+ const v = asVector(y);
238
+ return u.flatMap((a) => v.map((b) => a * b));
239
+ }
240
+ const a = isMatrix(x) ? x : asVector(x).map((v) => [v]);
241
+ const b = isMatrix(y) ? y : asVector(y).map((v) => [v]);
242
+ const out = [];
243
+ for (const ra of a)
244
+ for (const rb of b)
245
+ out.push(ra.flatMap((va) => rb.map((vb) => va * vb)));
246
+ return out;
247
+ }
248
+ /**
249
+ * Regular sequences. Equivalent to R's `seq()`: `seq(from, to)` steps by ±1; `by` steps by the increment, up to
250
+ * `to`; `lengthOut` gives that many values, both ends exact. `from` or `to` may be omitted (`undefined`) when the
251
+ * other two are given; `seq(n)` alone is `1, 2, ..., n`.
252
+ *
253
+ * @example
254
+ * ```ts
255
+ * seq(0, 1, { by: 0.25 }); // [0, 0.25, 0.5, 0.75, 1]
256
+ * seq(0, 1, { lengthOut: 3 }); // [0, 0.5, 1]
257
+ * ```
258
+ */
259
+ export function seq(from, to, options = {}) {
260
+ const { by, lengthOut } = options;
261
+ if (to === undefined && by === undefined && lengthOut === undefined && from !== undefined) {
262
+ if (!Number.isFinite(from))
263
+ throw new RangeError("'from' must be a finite number");
264
+ return colon(1, from);
265
+ }
266
+ if (from !== undefined && !Number.isFinite(from))
267
+ throw new RangeError("'from' must be a finite number");
268
+ if (to !== undefined && !Number.isFinite(to))
269
+ throw new RangeError("'to' must be a finite number");
270
+ if (lengthOut === undefined) {
271
+ if (by === undefined)
272
+ return colon(from ?? 1, to ?? 1);
273
+ const a = from ?? 1;
274
+ const b = to ?? 1;
275
+ const del = b - a;
276
+ if (del === 0 && b === 0)
277
+ return [b];
278
+ const n = del / by;
279
+ if (!Number.isFinite(n)) {
280
+ if (by === 0 && del === 0)
281
+ return [a];
282
+ throw new RangeError("invalid '(to - from)/by'");
283
+ }
284
+ if (n < 0)
285
+ throw new RangeError("wrong sign in 'by' argument");
286
+ if (Math.abs(del) / Math.max(Math.abs(b), Math.abs(a)) < 100 * Number.EPSILON)
287
+ return [a];
288
+ const k = Math.trunc(n + 1e-10);
289
+ // the last value may overshoot `to` by rounding: hold it at `to`
290
+ return Array.from({ length: k + 1 }, (_, i) => (by > 0 ? Math.min(a + i * by, b) : Math.max(a + i * by, b)));
291
+ }
292
+ if (!Number.isFinite(lengthOut) || lengthOut < 0)
293
+ throw new RangeError("'length.out' must be a non-negative number");
294
+ const len = Math.ceil(lengthOut);
295
+ if (len === 0)
296
+ return [];
297
+ if (by === undefined) {
298
+ const b = to ?? (from ?? 1) + (len - 1);
299
+ const a = from ?? b - (len - 1);
300
+ if (len <= 2)
301
+ return [a, b].slice(0, len);
302
+ if (a === b)
303
+ return new Array(len).fill(a);
304
+ const step = (b - a) / (len - 1);
305
+ return Array.from({ length: len }, (_, i) => (i === 0 ? a : i === len - 1 ? b : a + i * step));
306
+ }
307
+ if (to === undefined) {
308
+ const a = from ?? 1;
309
+ return Array.from({ length: len }, (_, i) => a + i * by);
310
+ }
311
+ if (from === undefined)
312
+ return Array.from({ length: len }, (_, i) => to - (len - 1 - i) * by);
313
+ throw new RangeError("too many arguments");
314
+ }
315
+ /** R's from:to */
316
+ function colon(from, to) {
317
+ const n = Math.trunc(Math.abs(to - from) + 1 + 1.1920928955078125e-7);
318
+ const s = from <= to ? 1 : -1;
319
+ return Array.from({ length: n }, (_, i) => from + s * i);
320
+ }
package/dist/linalg.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! rStats.js 0.6.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{a as x,b as K,c as $,d as P,e as I,f as T,g as W,h as Q,i as ot,j as at,k as st,l as lt,m as ft,n as it,o as C,p as ct,q as ht,r as L,s as U,t as X,u as ut,v as mt,w as D,x as bt,y as wt}from"./chunks/chunk-ZWJ42QN6.js";import{u as Y}from"./chunks/chunk-Y4IZV7XK.js";import"./chunks/chunk-7NK4SA6B.js";import"./chunks/chunk-UGUQYWRQ.js";function dt(i,s){let e=P(i),l=s===void 0?e:P(s);if(e.nrow!==l.nrow)throw new TypeError(`non-conformable arguments (${e.nrow} and ${l.nrow} rows)`);let c=e.nrow,n=x(e.ncol,l.ncol);for(let a=0;a<l.ncol;a++)for(let r=0;r<e.ncol;r++){if(s===void 0&&r>a)continue;let t=0;for(let o=0;o<c;o++)t+=e.data[o+r*c]*l.data[o+a*c];n.data[r+a*e.ncol]=t}return s===void 0&&Z(n),I(n)}function Mt(i,s){let e=P(i),l=s===void 0?e:P(s);if(e.ncol!==l.ncol)throw new TypeError(`non-conformable arguments (${e.ncol} and ${l.ncol} columns)`);let c=x(e.nrow,l.nrow);for(let n=0;n<l.nrow;n++)for(let a=0;a<e.nrow;a++){if(s===void 0&&a>n)continue;let r=0;for(let t=0;t<e.ncol;t++)r+=e.data[a+t*e.nrow]*l.data[n+t*l.nrow];c.data[a+n*e.nrow]=r}return s===void 0&&Z(c),I(c)}function Z(i){let s=i.nrow;for(let e=0;e<s;e++)for(let l=e+1;l<s;l++)i.data[l+e*s]=i.data[e+l*s]}function gt(i,s,e={}){return B(i,s,e.k,e.upperTri??!0,e.transpose??!1)}function pt(i,s,e={}){return B(i,s,e.k,e.upperTri??!1,e.transpose??!1)}function B(i,s,e,l,c){let n=$(i),a=P(s),r=e??n.ncol;if(!Number.isInteger(r)||r<1||r>n.nrow||r>n.ncol||r>a.nrow)throw new RangeError(`invalid k (got ${r})`);for(let o=0;o<r;o++)if(n.data[o+o*n.nrow]===0)throw new Error(`singular matrix: diagonal element ${o+1} is zero`);let t=x(r,a.ncol);for(let o=0;o<a.ncol;o++)for(let u=0;u<r;u++)t.data[u+o*r]=a.data[u+o*a.nrow];return vt(n,r,t,l,c),K(s)?I(t):Array.from(t.data)}function vt(i,s,e,l,c){let n=i.nrow,a=i.data,r=e.nrow,t=e.data;for(let o=0;o<e.ncol;o++){let u=o*r;if(!c&&l){for(let w=s-1;w>=0;w--)if(t[u+w]!==0){t[u+w]/=a[w+w*n];let h=t[u+w];for(let f=0;f<w;f++)t[u+f]-=h*a[f+w*n]}}else if(c)if(l)for(let w=0;w<s;w++){let h=t[u+w];for(let f=0;f<w;f++)h-=a[f+w*n]*t[u+f];t[u+w]=h/a[w+w*n]}else for(let w=s-1;w>=0;w--){let h=t[u+w];for(let f=w+1;f<s;f++)h-=a[f+w*n]*t[u+f];t[u+w]=h/a[w+w*n]}else for(let w=0;w<s;w++)if(t[u+w]!==0){t[u+w]/=a[w+w*n];let h=t[u+w];for(let f=w+1;f<s;f++)t[u+f]-=h*a[f+w*n]}}}function kt(i,s={}){let e=s.norm===void 0?s.exact?"2":"O":yt(s.norm);if(s.exact){if(e==="2"){let n=L(i,{nu:0,nv:0}).d,a=Math.min(...n);return a===0?1/0:Math.max(...n)/a}return U(i,{type:e})*U(X(i),{type:e})}if(e!=="O"&&e!=="I")throw new RangeError(`norm must be "1", "O" or "I" when exact is false (got "${s.norm}")`);if((s.method??"qr")==="direct")return s.triangular?1/tt($(i),(s.uplo??"U")==="U",e):1/D(i,{norm:e});let l=$(i),c=l.nrow<l.ncol?I(T(l)):i;return 1/tt($(C(Q(c))),!0,e)}function tt(i,s,e){return Et(e==="I"?T(i):i,s)}function yt(i){let s=i.toUpperCase();if(s==="1"||s==="O")return"O";if(s==="E")return"F";if(s==="I"||s==="F"||s==="M"||s==="2")return s;throw new RangeError(`invalid norm "${i}"`)}function Et(i,s){let e=Math.min(i.nrow,i.ncol),l=i.nrow,c=(h,f)=>i.data[h+f*l],n=!s,a=0;for(let h=0;h<e;h++){let[f,d]=n?[h,e-h]:[0,h+1],b=0;for(let M=f;M<f+d;M++)b+=Math.abs(c(M,h));a=Math.max(a,b)}let r=1,t=new Float64Array(e),o=h=>{for(let f=0;f<e;f++)t[f]*=h};for(let h=0;h<e;h++){let f=n?e-1-h:h,d=c(f,f);if(t[f]!==0&&(r=t[f]>0?-Math.abs(r):Math.abs(r)),Math.abs(r-t[f])>Math.abs(d)){let j=Math.abs(d)/Math.abs(r-t[f]);o(j),r*=j}let b=r-t[f],M=-r-t[f],p=Math.abs(b),A=Math.abs(M);if(d!==0?(b/=d,M/=d):(b=1,M=1),h!==e-1){let[j,k]=n?[0,f-1]:[f+1,e-1];for(let y=j;y<=k;y++)A+=Math.abs(t[y]+M*c(f,y)),t[y]+=b*c(f,y),p+=Math.abs(t[y]);if(p<A){let y=M-b;b=M;for(let _=j;_<=k;_++)t[_]+=y*c(f,_)}}t[f]=b}o(1/nt(t));let u=1;for(let h=0;h<e;h++){let f=n?h:e-1-h,d=c(f,f);if(Math.abs(t[f])>Math.abs(d)){let b=Math.abs(d)/Math.abs(t[f]);o(b),u*=b}if(d!==0?t[f]/=d:t[f]=1,h<e-1){let b=-t[f];if(n)for(let M=f+1;M<e;M++)t[M]+=b*c(M,f);else for(let M=0;M<f;M++)t[M]+=b*c(M,f)}}let w=1/nt(t);return o(w),u*=w,a!==0?u/a:0}function nt(i){let s=0;for(let e of i)s+=Math.abs(e);return s}function jt(i,s={}){let e=s.tol??Math.sqrt(Number.EPSILON),l=$(i),{d:c,u:n,v:a}=L(i),r=l.nrow,t=l.ncol,o=x(t,r),u=Math.max(e*(c[0]??0),0);for(let w=0;w<c.length;w++){if(!(c[w]>u))continue;let h=1/c[w];for(let f=0;f<r;f++){let d=n[f][w]*h;for(let b=0;b<t;b++)o.data[b+f*t]+=a[b][w]*d}}return I(o)}function At(i,s={}){let e=$(i);if(W(e),e.nrow===0)throw new RangeError("the matrix has zero dimension");for(let n of e.data)if(!Number.isFinite(n))throw new RangeError("the matrix contains NaN or infinite values");let l=s.symmetric??Nt(e),c=!(s.onlyValues??!1);return l?qt(e,c):_t(e,c)}function Nt(i){let s=i.nrow,e=0,l=0;for(let t=0;t<s;t++)for(let o=0;o<s;o++)e+=Math.abs(i.data[o+t*s]-i.data[t+o*s]),l+=Math.abs(i.data[o+t*s]);let c=100*Number.EPSILON,n=s*s,a=l/n,r=e/n;return(Number.isFinite(a)&&a>c?r/a:r)<=c}function qt(i,s){let e=i.nrow,l=x(e,e);for(let t=0;t<e;t++)for(let o=t;o<e;o++)l.data[o+t*e]=i.data[o+t*e],l.data[t+o*e]=i.data[o+t*e];let c=new Float64Array(e),n=new Float64Array(e);xt(l,c,n),Rt(l,c,n);let a=Array.from(c).reverse();if(!s)return{values:a};let r=x(e,e);for(let t=0;t<e;t++)r.data.set(l.data.subarray((e-1-t)*e,(e-t)*e),t*e);return{values:a,vectors:I(r)}}function xt(i,s,e){let l=i.nrow,c=i.data,n=(a,r)=>a+r*l;for(let a=0;a<l;a++)s[a]=c[n(l-1,a)];for(let a=l-1;a>0;a--){let r=0,t=0;for(let o=0;o<a;o++)r+=Math.abs(s[o]);if(r===0){e[a]=s[a-1];for(let o=0;o<a;o++)s[o]=c[n(a-1,o)],c[n(a,o)]=0,c[n(o,a)]=0}else{for(let h=0;h<a;h++)s[h]/=r,t+=s[h]*s[h];let o=s[a-1],u=Math.sqrt(t);o>0&&(u=-u),e[a]=r*u,t-=o*u,s[a-1]=o-u;for(let h=0;h<a;h++)e[h]=0;for(let h=0;h<a;h++){o=s[h],c[n(h,a)]=o,u=e[h]+c[n(h,h)]*o;for(let f=h+1;f<=a-1;f++)u+=c[n(f,h)]*s[f],e[f]+=c[n(f,h)]*o;e[h]=u}o=0;for(let h=0;h<a;h++)e[h]/=t,o+=e[h]*s[h];let w=o/(t+t);for(let h=0;h<a;h++)e[h]-=w*s[h];for(let h=0;h<a;h++){o=s[h],u=e[h];for(let f=h;f<=a-1;f++)c[n(f,h)]-=o*e[f]+u*s[f];s[h]=c[n(a-1,h)],c[n(a,h)]=0}}s[a]=t}for(let a=0;a<l-1;a++){c[n(l-1,a)]=c[n(a,a)],c[n(a,a)]=1;let r=s[a+1];if(r!==0){for(let t=0;t<=a;t++)s[t]=c[n(t,a+1)]/r;for(let t=0;t<=a;t++){let o=0;for(let u=0;u<=a;u++)o+=c[n(u,a+1)]*c[n(u,t)];for(let u=0;u<=a;u++)c[n(u,t)]-=o*s[u]}}for(let t=0;t<=a;t++)c[n(t,a+1)]=0}for(let a=0;a<l;a++)s[a]=c[n(l-1,a)],c[n(l-1,a)]=0;c[n(l-1,l-1)]=1,e[0]=0}function Rt(i,s,e){let l=i.nrow,c=i.data,n=(o,u)=>o+u*l;for(let o=1;o<l;o++)e[o-1]=e[o];e[l-1]=0;let a=0,r=0,t=Number.EPSILON;for(let o=0;o<l;o++){r=Math.max(r,Math.abs(s[o])+Math.abs(e[o]));let u=o;for(;u<l-1&&Math.abs(e[u])>t*r;)u++;if(u>o){let w=0;do{if(++w>100)throw new Error("the eigendecomposition did not converge");let h=s[o],f=(s[o+1]-h)/(2*e[o]),d=Math.hypot(f,1);f<0&&(d=-d),s[o]=e[o]/(f+d),s[o+1]=e[o]*(f+d);let b=s[o+1],M=h-s[o];for(let N=o+2;N<l;N++)s[N]-=M;a+=M,f=s[u];let p=1,A=p,j=p,k=e[o+1],y=0,_=0;for(let N=u-1;N>=o;N--){j=A,A=p,_=y,h=p*e[N],M=p*f,d=Math.hypot(f,e[N]),e[N+1]=y*d,y=e[N]/d,p=f/d,f=p*s[N]-y*h,s[N+1]=M+y*(p*h+y*s[N]);for(let S=0;S<l;S++)M=c[n(S,N+1)],c[n(S,N+1)]=y*c[n(S,N)]+p*M,c[n(S,N)]=p*c[n(S,N)]-y*M}f=-y*_*j*k*e[o]/b,e[o]=y*f,s[o]=p*f}while(Math.abs(e[o])>t*r)}s[o]=s[o]+a,e[o]=0}for(let o=0;o<l-1;o++){let u=o,w=s[o];for(let h=o+1;h<l;h++)s[h]<w&&(u=h,w=s[h]);if(u!==o){s[u]=s[o],s[o]=w;for(let h=0;h<l;h++){let f=c[n(h,o)];c[n(h,o)]=c[n(h,u)],c[n(h,u)]=f}}}}function _t(i,s){let e=i.nrow,l={nrow:e,ncol:e,data:i.data.slice()},c=x(e,e),n=new Float64Array(e),a=new Float64Array(e);It(l,c),Ot(l,c,n,a);let r=Array.from(n,(b,M)=>Math.hypot(b,a[M])),t=Array.from({length:e},(b,M)=>M).sort((b,M)=>r[M]-r[b]||b-M),o=a.some(b=>b!==0),u={values:t.map(b=>n[b])};if(o&&(u.valuesIm=t.map(b=>a[b])),!s)return u;let w=x(e,e),h=x(e,e);for(let b=0;b<e;b++){let M=c.data.subarray(b*e,(b+1)*e);if(a[b]===0)w.data.set(M,b*e);else if(a[b]>0){let p=c.data.subarray((b+1)*e,(b+2)*e);w.data.set(M,b*e),h.data.set(p,b*e),w.data.set(M,(b+1)*e);for(let A=0;A<e;A++)h.data[A+(b+1)*e]=-p[A]}}Ft(w,h);let f=x(e,e),d=x(e,e);return t.forEach((b,M)=>{f.data.set(w.data.subarray(b*e,(b+1)*e),M*e),d.data.set(h.data.subarray(b*e,(b+1)*e),M*e)}),u.vectors=I(f),o&&(u.vectorsIm=I(d)),u}function Ft(i,s){let e=i.nrow;for(let l=0;l<e;l++){let c=l*e,n=0,a=0,r=-1;for(let w=0;w<e;w++){let h=Math.hypot(i.data[c+w],s.data[c+w]);n+=h*h,h>r&&(r=h,a=w)}let t=Math.sqrt(n);if(t===0)continue;let o=i.data[c+a]/r/t,u=-s.data[c+a]/r/t;for(let w=0;w<e;w++){let h=i.data[c+w],f=s.data[c+w];i.data[c+w]=h*o-f*u,s.data[c+w]=h*u+f*o}s.data[c+a]=0}}function It(i,s){let e=i.nrow,l=i.data,c=s.data,n=(o,u)=>o+u*e,a=new Float64Array(e),r=0,t=e-1;for(let o=r+1;o<=t-1;o++){let u=0;for(let f=o;f<=t;f++)u+=Math.abs(l[n(f,o-1)]);if(u===0)continue;let w=0;for(let f=t;f>=o;f--)a[f]=l[n(f,o-1)]/u,w+=a[f]*a[f];let h=Math.sqrt(w);a[o]>0&&(h=-h),w-=a[o]*h,a[o]=a[o]-h;for(let f=o;f<e;f++){let d=0;for(let b=t;b>=o;b--)d+=a[b]*l[n(b,f)];d/=w;for(let b=o;b<=t;b++)l[n(b,f)]-=d*a[b]}for(let f=0;f<=t;f++){let d=0;for(let b=t;b>=o;b--)d+=a[b]*l[n(f,b)];d/=w;for(let b=o;b<=t;b++)l[n(f,b)]-=d*a[b]}a[o]=u*a[o],l[n(o,o-1)]=u*h}for(let o=0;o<e;o++)for(let u=0;u<e;u++)c[n(o,u)]=o===u?1:0;for(let o=t-1;o>=r+1;o--)if(l[n(o,o-1)]!==0){for(let u=o+1;u<=t;u++)a[u]=l[n(u,o-1)];for(let u=o;u<=t;u++){let w=0;for(let h=o;h<=t;h++)w+=a[h]*c[n(h,u)];w=w/a[o]/l[n(o,o-1)];for(let h=o;h<=t;h++)c[n(h,u)]+=w*a[h]}}}function z(i,s,e,l){if(Math.abs(e)>Math.abs(l)){let a=l/e,r=e+a*l;return[(i+a*s)/r,(s-a*i)/r]}let c=e/l,n=l+c*e;return[(c*i+s)/n,(c*s-i)/n]}function Ot(i,s,e,l){let c=i.nrow,n=i.data,a=s.data,r=(E,m)=>E+m*c,t=c-1,o=0,u=c-1,w=Number.EPSILON,h=0,f=0,d=0,b=0,M=0,p=0,A,j,k,y,_=0;for(let E=0;E<c;E++)for(let m=Math.max(E-1,0);m<c;m++)_+=Math.abs(n[r(E,m)]);let N=0,S=0;for(;t>=o;){let E=t;for(;E>o&&(M=Math.abs(n[r(E-1,E-1)])+Math.abs(n[r(E,E)]),M===0&&(M=_),!(Math.abs(n[r(E,E-1)])<w*M));)E--;if(E===t)n[r(t,t)]=n[r(t,t)]+h,e[t]=n[r(t,t)],l[t]=0,t--,N=0;else if(E===t-1){if(j=n[r(t,t-1)]*n[r(t-1,t)],f=(n[r(t-1,t-1)]-n[r(t,t)])/2,d=f*f+j,p=Math.sqrt(Math.abs(d)),n[r(t,t)]=n[r(t,t)]+h,n[r(t-1,t-1)]=n[r(t-1,t-1)]+h,k=n[r(t,t)],d>=0){p=f>=0?f+p:f-p,e[t-1]=k+p,e[t]=e[t-1],p!==0&&(e[t]=k-j/p),l[t-1]=0,l[t]=0,k=n[r(t,t-1)],M=Math.abs(k)+Math.abs(p),f=k/M,d=p/M,b=Math.sqrt(f*f+d*d),f/=b,d/=b;for(let m=t-1;m<c;m++)p=n[r(t-1,m)],n[r(t-1,m)]=d*p+f*n[r(t,m)],n[r(t,m)]=d*n[r(t,m)]-f*p;for(let m=0;m<=t;m++)p=n[r(m,t-1)],n[r(m,t-1)]=d*p+f*n[r(m,t)],n[r(m,t)]=d*n[r(m,t)]-f*p;for(let m=o;m<=u;m++)p=a[r(m,t-1)],a[r(m,t-1)]=d*p+f*a[r(m,t)],a[r(m,t)]=d*a[r(m,t)]-f*p}else e[t-1]=k+f,e[t]=k+f,l[t-1]=p,l[t]=-p;t-=2,N=0}else{if(k=n[r(t,t)],y=0,j=0,E<t&&(y=n[r(t-1,t-1)],j=n[r(t,t-1)]*n[r(t-1,t)]),N===10){h+=k;for(let g=o;g<=t;g++)n[r(g,g)]-=k;M=Math.abs(n[r(t,t-1)])+Math.abs(n[r(t-1,t-2)]),k=y=.75*M,j=-.4375*M*M}if(N===30&&(M=(y-k)/2,M=M*M+j,M>0)){M=Math.sqrt(M),y<k&&(M=-M),M=k-j/((y-k)/2+M);for(let g=o;g<=t;g++)n[r(g,g)]-=M;h+=M,k=y=j=.964}if(N++,++S>100*c)throw new Error("the eigendecomposition did not converge");let m=t-2;for(;m>=E&&(p=n[r(m,m)],b=k-p,M=y-p,f=(b*M-j)/n[r(m+1,m)]+n[r(m,m+1)],d=n[r(m+1,m+1)]-p-b-M,b=n[r(m+2,m+1)],M=Math.abs(f)+Math.abs(d)+Math.abs(b),f/=M,d/=M,b/=M,!(m===E||Math.abs(n[r(m,m-1)])*(Math.abs(d)+Math.abs(b))<w*(Math.abs(f)*(Math.abs(n[r(m-1,m-1)])+Math.abs(p)+Math.abs(n[r(m+1,m+1)])))));)m--;for(let g=m+2;g<=t;g++)n[r(g,g-2)]=0,g>m+2&&(n[r(g,g-3)]=0);for(let g=m;g<=t-1;g++){let F=g!==t-1;if(g!==m){if(f=n[r(g,g-1)],d=n[r(g+1,g-1)],b=F?n[r(g+2,g-1)]:0,k=Math.abs(f)+Math.abs(d)+Math.abs(b),k===0)continue;f/=k,d/=k,b/=k}if(M=Math.sqrt(f*f+d*d+b*b),f<0&&(M=-M),M!==0){g!==m?n[r(g,g-1)]=-M*k:E!==m&&(n[r(g,g-1)]=-n[r(g,g-1)]),f+=M,k=f/M,y=d/M,p=b/M,d/=f,b/=f;for(let v=g;v<c;v++)f=n[r(g,v)]+d*n[r(g+1,v)],F&&(f+=b*n[r(g+2,v)],n[r(g+2,v)]=n[r(g+2,v)]-f*p),n[r(g,v)]=n[r(g,v)]-f*k,n[r(g+1,v)]=n[r(g+1,v)]-f*y;for(let v=0;v<=Math.min(t,g+3);v++)f=k*n[r(v,g)]+y*n[r(v,g+1)],F&&(f+=p*n[r(v,g+2)],n[r(v,g+2)]=n[r(v,g+2)]-f*b),n[r(v,g)]=n[r(v,g)]-f,n[r(v,g+1)]=n[r(v,g+1)]-f*d;for(let v=o;v<=u;v++)f=k*a[r(v,g)]+y*a[r(v,g+1)],F&&(f+=p*a[r(v,g+2)],a[r(v,g+2)]=a[r(v,g+2)]-f*b),a[r(v,g)]=a[r(v,g)]-f,a[r(v,g+1)]=a[r(v,g+1)]-f*d}}}}if(_!==0){for(t=c-1;t>=0;t--)if(f=e[t],d=l[t],d===0){let E=t;n[r(t,t)]=1;for(let m=t-1;m>=0;m--){j=n[r(m,m)]-f,b=0;for(let g=E;g<=t;g++)b+=n[r(m,g)]*n[r(g,t)];if(l[m]<0)p=j,M=b;else if(E=m,l[m]===0?n[r(m,t)]=j!==0?-b/j:-b/(w*_):(k=n[r(m,m+1)],y=n[r(m+1,m)],d=(e[m]-f)*(e[m]-f)+l[m]*l[m],A=(k*M-p*b)/d,n[r(m,t)]=A,n[r(m+1,t)]=Math.abs(k)>Math.abs(p)?(-b-j*A)/k:(-M-y*A)/p),A=Math.abs(n[r(m,t)]),w*A*A>1)for(let g=m;g<=t;g++)n[r(g,t)]=n[r(g,t)]/A}}else if(d<0){let E=t-1;Math.abs(n[r(t,t-1)])>Math.abs(n[r(t-1,t)])?(n[r(t-1,t-1)]=d/n[r(t,t-1)],n[r(t-1,t)]=-(n[r(t,t)]-f)/n[r(t,t-1)]):[n[r(t-1,t-1)],n[r(t-1,t)]]=z(0,-n[r(t-1,t)],n[r(t-1,t-1)]-f,d),n[r(t,t-1)]=0,n[r(t,t)]=1;for(let m=t-2;m>=0;m--){let g=0,F=0;for(let v=E;v<=t;v++)g+=n[r(m,v)]*n[r(v,t-1)],F+=n[r(m,v)]*n[r(v,t)];if(j=n[r(m,m)]-f,l[m]<0)p=j,b=g,M=F;else{if(E=m,l[m]===0)[n[r(m,t-1)],n[r(m,t)]]=z(-g,-F,j,d);else{k=n[r(m,m+1)],y=n[r(m+1,m)];let v=(e[m]-f)*(e[m]-f)+l[m]*l[m]-d*d,J=(e[m]-f)*2*d;v===0&&J===0&&(v=w*_*(Math.abs(j)+Math.abs(d)+Math.abs(k)+Math.abs(y)+Math.abs(p))),[n[r(m,t-1)],n[r(m,t)]]=z(k*b-p*g+d*F,k*M-p*F-d*g,v,J),Math.abs(k)>Math.abs(p)+Math.abs(d)?(n[r(m+1,t-1)]=(-g-j*n[r(m,t-1)]+d*n[r(m,t)])/k,n[r(m+1,t)]=(-F-j*n[r(m,t)]-d*n[r(m,t-1)])/k):[n[r(m+1,t-1)],n[r(m+1,t)]]=z(-b-y*n[r(m,t-1)],-M-y*n[r(m,t)],p,d)}if(A=Math.max(Math.abs(n[r(m,t-1)]),Math.abs(n[r(m,t)])),w*A*A>1)for(let v=m;v<=t;v++)n[r(v,t-1)]=n[r(v,t-1)]/A,n[r(v,t)]=n[r(v,t)]/A}}}for(let E=c-1;E>=o;E--)for(let m=o;m<=u;m++){p=0;for(let g=o;g<=Math.min(E,u);g++)p+=a[r(m,g)]*n[r(g,E)];a[r(m,E)]=p}}}function R(i){return typeof i!="number"&&i.length>0&&Array.isArray(i[0])}function q(i){return typeof i=="number"?[i]:Array.from(i)}function O(i){let s=i[0].length;if(i.some(e=>e.length!==s))throw new TypeError("all rows of the matrix must have the same length");return s}function G(i,s){let e,l;if(R(i)&&R(s))e=i.map(a=>[...a]),l=s.map(a=>[...a]);else if(R(i)){let a=q(s),r=O(i);e=i.map(t=>[...t]),l=r===a.length?a.map(t=>[t]):r===1?[a]:[]}else if(R(s)){let a=q(i);l=s.map(r=>[...r]),e=s.length===a.length?[a]:s.length===1?a.map(r=>[r]):[]}else{let a=q(i),r=q(s);if(a.length===r.length)e=[a],l=r.map(t=>[t]);else if(a.length===1)e=[a],l=[r];else if(r.length===1)e=a.map(t=>[t]),l=[r];else throw new RangeError("non-conformable arguments")}let c=e[0]?.length??0;if(e.length===0||l.length!==c)throw new RangeError("non-conformable arguments");O(e);let n=O(l);return e.map(a=>{let r=new Array(n).fill(0);for(let t=0;t<n;t++){let o=0;for(let u=0;u<c;u++)o+=a[u]*l[u][t];r[t]=o}return r})}function V(i,s,e){let l=R(i),c=R(s);if(l&&c){let t=O(i);if(i.length!==s.length||t!==O(s))throw new RangeError("non-conformable arrays");return i.map((o,u)=>o.map((w,h)=>e(w,s[u][h])))}if(l||c){let t=l?i:s,o=q(l?s:i),u=t.length,w=O(t);if(o.length===0)return t.map(h=>h.map(()=>NaN));if(o.length>u*w)throw new RangeError("dims [product "+u*w+"] do not match the length of object ["+o.length+"]");return t.map((h,f)=>h.map((d,b)=>l?e(d,o[(f+b*u)%o.length]):e(o[(f+b*u)%o.length],d)))}let n=q(i),a=q(s);if(n.length===0||a.length===0)return[];let r=Math.max(n.length,a.length);return Array.from({length:r},(t,o)=>e(n[o%n.length],a[o%a.length]))}function St(i,s){return V(i,s,(e,l)=>e+l)}function $t(i,s){return V(i,s,(e,l)=>e-l)}function Pt(i,s){return V(i,s,(e,l)=>e*l)}function Lt(i,s){return V(i,s,(e,l)=>e/l)}var Ut={"*":(i,s)=>i*s,"+":(i,s)=>i+s,"-":(i,s)=>i-s,"/":(i,s)=>i/s,"^":(i,s)=>i**s};function zt(i,s,e="*"){let l=typeof e=="function"?e:Ut[e];if(l===void 0)throw new RangeError(`invalid fun "${String(e)}"`);let c=Array.from(i),n=Array.from(s);return c.map(a=>n.map(r=>l(a,r)))}function H(i){if(!R(i))return[q(i)];let s=O(i);return Array.from({length:s},(e,l)=>i.map(c=>c[l]))}function Vt(i,s={}){if(R(i)){let r=O(i);return Array.from({length:Math.min(i.length,r)},(t,o)=>i[o][o])}let e=q(i),l,c;if(e.length===1&&s.nrow===void 0&&s.ncol===void 0){if(c=Math.trunc(e[0]),!(c>=0))throw new RangeError("invalid 'nrow' value (< 0)");l=[1]}else l=e,c=s.nrow??e.length;let n=s.ncol??c,a=Array.from({length:c},()=>new Array(n).fill(0));for(let r=0;r<Math.min(c,n);r++)a[r][r]=l[r%l.length];return c===0?[]:a}function et(i,s){let e=i.map(n=>R(n)?s?H(n):n.map(a=>[...a]):[q(n)]),l=i.filter(R),c=l.length>0?s?l[0].length:O(l[0]):Math.max(...e.map(n=>n[0].length));return l.forEach((n,a)=>{if((s?n.length:O(n))!==c)throw new RangeError(`number of ${s?"rows":"columns"} of matrices must match (see arg ${a+2})`)}),e.flatMap(n=>n.map(a=>Array.from({length:c},(r,t)=>a[t%a.length])))}function Tt(...i){return H(et(i,!0))}function Qt(...i){return et(i,!1)}function Ct(i,s={}){let e=q(i),l=e.length,{nrow:c,ncol:n}=s;c===void 0&&n===void 0?(c=l,n=1):c===void 0?c=Math.ceil(l/n):n===void 0&&(n=Math.ceil(l/c));let a=s.byrow??!1;return Array.from({length:c},(r,t)=>Array.from({length:n},(o,u)=>l===0?NaN:e[(a?t*n+u:t+u*c)%l]))}function Xt(i,s){if(!R(i)&&!R(s)){let n=q(i),a=q(s);return n.flatMap(r=>a.map(t=>r*t))}let e=R(i)?i:q(i).map(n=>[n]),l=R(s)?s:q(s).map(n=>[n]),c=[];for(let n of e)for(let a of l)c.push(n.flatMap(r=>a.map(t=>r*t)));return c}function Dt(i,s,e={}){let{by:l,lengthOut:c}=e;if(s===void 0&&l===void 0&&c===void 0&&i!==void 0){if(!Number.isFinite(i))throw new RangeError("'from' must be a finite number");return rt(1,i)}if(i!==void 0&&!Number.isFinite(i))throw new RangeError("'from' must be a finite number");if(s!==void 0&&!Number.isFinite(s))throw new RangeError("'to' must be a finite number");if(c===void 0){if(l===void 0)return rt(i??1,s??1);let a=i??1,r=s??1,t=r-a;if(t===0&&r===0)return[r];let o=t/l;if(!Number.isFinite(o)){if(l===0&&t===0)return[a];throw new RangeError("invalid '(to - from)/by'")}if(o<0)throw new RangeError("wrong sign in 'by' argument");if(Math.abs(t)/Math.max(Math.abs(r),Math.abs(a))<100*Number.EPSILON)return[a];let u=Math.trunc(o+1e-10);return Array.from({length:u+1},(w,h)=>l>0?Math.min(a+h*l,r):Math.max(a+h*l,r))}if(!Number.isFinite(c)||c<0)throw new RangeError("'length.out' must be a non-negative number");let n=Math.ceil(c);if(n===0)return[];if(l===void 0){let a=s??(i??1)+(n-1),r=i??a-(n-1);if(n<=2)return[r,a].slice(0,n);if(r===a)return new Array(n).fill(r);let t=(a-r)/(n-1);return Array.from({length:n},(o,u)=>u===0?r:u===n-1?a:r+u*t)}if(s===void 0){let a=i??1;return Array.from({length:n},(r,t)=>a+t*l)}if(i===void 0)return Array.from({length:n},(a,r)=>s-(n-1-r)*l);throw new RangeError("too many arguments")}function rt(i,s){let e=Math.trunc(Math.abs(s-i)+1+11920928955078125e-23),l=i<=s?1:-1;return Array.from({length:e},(c,n)=>i+l*n)}var Gt=22250738585072014e-324;function Ht(i){let s=i.length,e=s===0?0:i[0].length,l=i.map(o=>{if(o.length!==e)throw new TypeError("all rows of the matrix must have the same length");return Array.from(o)}),c=Array.from({length:s},(o,u)=>u),n=Math.min(s,e);for(let o=0;o<n;o++){let u=o,w=Math.abs(l[o][o]);for(let d=o+1;d<s;d++){let b=Math.abs(l[d][o]);(b>w||Number.isNaN(w))&&(w=b,u=d)}u!==o&&([l[u],l[o]]=[l[o],l[u]],[c[u],c[o]]=[c[o],c[u]]);let h=l[o][o];if(h===0)continue;let f=Math.abs(h)>=Gt?1/h:NaN;for(let d=o+1;d<s;d++){let b=Number.isNaN(f)?l[d][o]/h:l[d][o]*f;l[d][o]=b;for(let M=o+1;M<e;M++)l[d][M]=l[d][M]-b*l[o][M]}}let a=Array.from({length:s},(o,u)=>Array.from({length:n},(w,h)=>u===h?1:u>h?l[u][h]:0)),r=Array.from({length:n},(o,u)=>Array.from({length:e},(w,h)=>h>=u?l[u][h]:0)),t=Array.from({length:s},()=>new Array(s).fill(0));return c.forEach((o,u)=>t[o][u]=1),{P:t,L:a,U:r}}function Jt(i,s={}){let e=i.map(t=>Array.from(t)),l=Y(e,{center:s.center??!0,scale:s.scale??!1});if(l.scale?.some(t=>t===0))throw new RangeError("cannot rescale a constant/zero column to unit variance");let c=L(l.scaled,{nu:0}),n=e.length,a=c.v,r={sdev:c.d.map(t=>t/Math.sqrt(Math.max(1,n-1))),rotation:a,x:G(l.scaled,a)};return l.center!==void 0&&(r.center=l.center),l.scale!==void 0&&(r.scale=l.scale),r}export{St as add,gt as backsolve,Tt as cbind,bt as chol,wt as chol2inv,dt as crossprod,mt as det,ut as determinant,Vt as diag,Lt as divide,At as eigen,pt as forwardsolve,jt as ginv,kt as kappa,Xt as kronecker,Ht as lu,G as matMul,Ct as matrix,Pt as multiply,U as norm,zt as outer,Jt as prcomp,Q as qr,st as qrCoef,ft as qrFitted,it as qrQ,ot as qrQty,at as qrQy,C as qrR,lt as qrResid,ht as qrSolve,ct as qrX,Qt as rbind,D as rcond,Dt as seq,X as solve,$t as subtract,L as svd,H as t,Mt as tcrossprod};
@@ -0,0 +1,98 @@
1
+ import type { MatrixInput } from "../linalg/matrix.js";
2
+ import { type QR } from "../linalg/qr.js";
3
+ import type { Sample } from "../htest/types.js";
4
+ /** Options for {@link lm}. */
5
+ export interface LmOptions {
6
+ /** Include an intercept (a column of ones before the columns of `x`). Default `true`. */
7
+ intercept?: boolean;
8
+ /** Weights for weighted least squares (non-negative; rows of weight 0 are left out of the fit). */
9
+ weights?: Sample;
10
+ }
11
+ /** Result of {@link lm}: the fit and the quantities of R's `summary(lm)`. */
12
+ export interface LmResult {
13
+ /** Coefficients (intercept first); NaN for aliased columns. */
14
+ coefficients: number[];
15
+ /** Residuals y - fitted (rows with a missing value dropped; rows of weight 0 included). */
16
+ residuals: number[];
17
+ fittedValues: number[];
18
+ /** Numerical rank of the model matrix. */
19
+ rank: number;
20
+ /** Residual degrees of freedom, n - rank (n counts the rows of non-zero weight). */
21
+ dfResidual: number;
22
+ /** The coefficient table of the columns that are not aliased, in their order. */
23
+ coefTable: {
24
+ estimate: number[];
25
+ stdError: number[];
26
+ tValue: number[];
27
+ pValue: number[];
28
+ };
29
+ /** Residual standard error. */
30
+ sigma: number;
31
+ /** R^2; 0 for a model with nothing beyond the intercept, as in R. */
32
+ rSquared: number;
33
+ /** Adjusted R^2; 0 for a model with nothing beyond the intercept, as in R. */
34
+ adjRSquared: number;
35
+ /**
36
+ * Overall F statistic with its degrees of freedom. Absent (as is `fPValue`) when the model has nothing beyond the
37
+ * intercept, where R's `summary(lm)` has no `fstatistic`.
38
+ */
39
+ fStatistic?: {
40
+ value: number;
41
+ numdf: number;
42
+ dendf: number;
43
+ };
44
+ /** p-value of the overall F test; absent with `fStatistic`. */
45
+ fPValue?: number;
46
+ /** Whether the model has an intercept. */
47
+ intercept: boolean;
48
+ /** The QR decomposition of the (weighted) model matrix. */
49
+ qr: QR;
50
+ }
51
+ /**
52
+ * Fit a linear model by least squares. Equivalent to R's `lm(y ~ x)` (or `y ~ x - 1` without intercept, with
53
+ * `weights` for weighted least squares) together with `summary()`; the predictors are given as a matrix instead of a
54
+ * formula. Rows with a missing value in `x`, `y` or the weights are dropped.
55
+ *
56
+ * @param x Predictors: a matrix (array of rows, one column per predictor) or a vector (one predictor).
57
+ * @param y Response.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const fit = lm([1, 2, 3, 4, 5], [2.1, 3.9, 6.2, 7.8, 10.1]);
62
+ * fit.coefficients; // [intercept, slope]
63
+ * fit.rSquared;
64
+ * ```
65
+ */
66
+ export declare function lm(x: MatrixInput | Sample, y: Sample, options?: LmOptions): LmResult;
67
+ /** Options for {@link confint}. */
68
+ export interface ConfintOptions {
69
+ /** Confidence level. Default `0.95`. */
70
+ level?: number;
71
+ }
72
+ /**
73
+ * Confidence intervals for the coefficients of a linear model (NaN for aliased columns). Equivalent to R's
74
+ * `confint()` for an `lm` fit.
75
+ */
76
+ export declare function confint(fit: LmResult, options?: ConfintOptions): {
77
+ lower: number[];
78
+ upper: number[];
79
+ };
80
+ /** Options for {@link predict}. */
81
+ export interface PredictOptions {
82
+ /** `"none"` (default), `"confidence"` (for the mean response) or `"prediction"` (for a new observation). */
83
+ interval?: "none" | "confidence" | "prediction";
84
+ /** Confidence level of the interval. Default `0.95`. */
85
+ level?: number;
86
+ }
87
+ /**
88
+ * Predictions of a linear model at new values of the predictors, with standard errors and optionally intervals.
89
+ * Equivalent to R's `predict()` for an `lm` fit (`se.fit = TRUE`). Aliased columns are left out, as R does.
90
+ *
91
+ * @param newdata New predictor values, with the columns of `x` (no column of ones).
92
+ */
93
+ export declare function predict(fit: LmResult, newdata: MatrixInput | Sample, options?: PredictOptions): {
94
+ fit: number[];
95
+ seFit: number[];
96
+ lwr?: number[];
97
+ upr?: number[];
98
+ };