@numero-uno-jpn/rstats 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.ja.md +6 -5
- package/README.md +6 -5
- package/dist/causal/balance.d.ts +106 -0
- package/dist/causal/balance.js +216 -0
- package/dist/causal/match.d.ts +86 -0
- package/dist/causal/match.js +155 -0
- package/dist/causal/scale.d.ts +8 -0
- package/dist/causal/scale.js +26 -0
- package/dist/causal.js +2 -0
- package/dist/chunks/{chunk-IRO6MXW2.js → chunk-2P42OXYW.js} +2 -2
- package/dist/chunks/{chunk-M4SLTLOX.js → chunk-3QOW56EJ.js} +2 -2
- package/dist/chunks/{chunk-XLBSUUWY.js → chunk-3QSYPBUM.js} +2 -2
- package/dist/chunks/{chunk-46DELNLN.js → chunk-4B7NEJCE.js} +2 -2
- package/dist/chunks/{chunk-OG5FTIWF.js → chunk-4GRV66HW.js} +2 -2
- package/dist/chunks/{chunk-HIPKYBZ3.js → chunk-4U65I4J2.js} +2 -2
- package/dist/chunks/{chunk-MJLK2RIQ.js → chunk-52KGBGFL.js} +1 -1
- package/dist/chunks/{chunk-JFZOKMZA.js → chunk-5AR4V7MW.js} +2 -2
- package/dist/chunks/{chunk-YPDFCKL4.js → chunk-7FXBOYIH.js} +2 -2
- package/dist/chunks/{chunk-NO675KX4.js → chunk-7K2LMKZR.js} +2 -2
- package/dist/chunks/chunk-7UI4PW32.js +2 -0
- package/dist/chunks/{chunk-BNHMQU7V.js → chunk-CHKBDZC4.js} +2 -2
- package/dist/chunks/{chunk-W2D6IDBY.js → chunk-CKBUE4FV.js} +2 -2
- package/dist/chunks/{chunk-SV6SLUVB.js → chunk-CMTCPLIA.js} +2 -2
- package/dist/chunks/chunk-DWVTVOQS.js +2 -0
- package/dist/chunks/{chunk-QY4OBLXK.js → chunk-FFMMKXMK.js} +2 -2
- package/dist/chunks/{chunk-EV7ZQC6D.js → chunk-HF3QOIZX.js} +2 -2
- package/dist/chunks/chunk-JG26HC2H.js +2 -0
- package/dist/chunks/{chunk-KICTA3JY.js → chunk-L54WIMTZ.js} +2 -2
- package/dist/chunks/{chunk-TNU4SMV3.js → chunk-MAFZ5FGL.js} +2 -2
- package/dist/chunks/{chunk-Y2SS3GX2.js → chunk-MJ7IY7AF.js} +2 -2
- package/dist/chunks/chunk-MUYGPZ37.js +3 -0
- package/dist/chunks/{chunk-PF6LEBKO.js → chunk-NAACMR7H.js} +2 -2
- package/dist/chunks/{chunk-OWOBNS75.js → chunk-NGDBJR3K.js} +2 -2
- package/dist/chunks/{chunk-P23KCD67.js → chunk-NQT7ZWL6.js} +2 -2
- package/dist/chunks/{chunk-ZW5OCUIY.js → chunk-O6OMXX5U.js} +1 -1
- package/dist/chunks/{chunk-JWMVP7XO.js → chunk-PYFASERO.js} +2 -2
- package/dist/chunks/{chunk-W27XXELU.js → chunk-QT32BMYA.js} +2 -2
- package/dist/chunks/{chunk-DMT423BG.js → chunk-SKQHW2GD.js} +2 -2
- package/dist/chunks/{chunk-JD6JHIVV.js → chunk-SLMS3FQD.js} +1 -1
- package/dist/chunks/{chunk-BA32XHDA.js → chunk-SZR5HAMB.js} +2 -2
- package/dist/chunks/{chunk-QRUQEJJ5.js → chunk-T5TE5KCP.js} +2 -2
- package/dist/chunks/{chunk-BZBPPRSH.js → chunk-ULQXNAI6.js} +2 -2
- package/dist/chunks/{chunk-3K5KP3M2.js → chunk-UPFMYDF7.js} +2 -2
- package/dist/chunks/{chunk-WHKUEZQI.js → chunk-WACTNIKS.js} +2 -2
- package/dist/chunks/{chunk-BGY7Y3P4.js → chunk-WSDLT4AR.js} +1 -1
- package/dist/chunks/{chunk-HCHZ6M34.js → chunk-WUNTM7PJ.js} +2 -2
- package/dist/chunks/chunk-XQSYV3IZ.js +2 -0
- package/dist/chunks/{chunk-BKH5GQNA.js → chunk-YKCZF4ES.js} +2 -2
- package/dist/chunks/{chunk-XKQSKVCL.js → chunk-ZHAT6244.js} +2 -2
- package/dist/chunks/{chunk-S5JZMHAW.js → chunk-ZK7FW5UX.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/causal.d.ts +2 -0
- package/dist/entries/causal.js +3 -0
- package/dist/entries/tests.d.ts +1 -0
- package/dist/entries/tests.js +1 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/clogit.d.ts +80 -0
- package/dist/models/clogit.js +211 -0
- package/dist/models/coxph.d.ts +9 -0
- package/dist/models/coxph.js +3 -3
- package/dist/multivariate.js +2 -2
- package/dist/numerics.js +2 -2
- package/dist/regression.js +2 -2
- package/dist/rstats.js +18 -18
- package/dist/special.js +2 -2
- package/dist/tests.js +15 -15
- package/dist/timeseries.js +2 -2
- package/package.json +6 -1
- package/dist/chunks/chunk-6VIOWV53.js +0 -2
- package/dist/chunks/chunk-HPWRADJM.js +0 -2
- package/dist/chunks/chunk-Z6UI6ON2.js +0 -3
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Conditional logistic regression, after survival's clogit(case ~ x + strata(set), method): "exact" maximises the
|
|
2
|
+
// exact conditional likelihood (Gail, Lubin & Rubinstein (1981), "Likelihood calculations for matched case-control
|
|
3
|
+
// studies and survival studies with tied death times", Biometrika 68, 703-707), "approximate" (= "breslow") is the
|
|
4
|
+
// Cox partial likelihood with Breslow's ties on equal times (coxph). Newton-Raphson as coxph (Therneau & Grambsch
|
|
5
|
+
// 2000, chapter 3). Written for rStats.js from the documentation and the published output (no ported code).
|
|
6
|
+
import { pchisq } from "../distributions/chisq.js";
|
|
7
|
+
import { qnorm } from "../distributions/normal.js";
|
|
8
|
+
import { cholFactor, cholInverse, cholSolve, coxph } from "./coxph.js";
|
|
9
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
10
|
+
import { checkOptions, nestedOptions } from "../internal/checkOptions.js";
|
|
11
|
+
const CLOGIT_KEYS = ["method", "confLevel", "control"];
|
|
12
|
+
const CLOGIT_CONTROL_KEYS = ["eps", "iterMax"];
|
|
13
|
+
/**
|
|
14
|
+
* Log likelihood, score and information of the exact conditional likelihood at beta (covariates centred). For each set,
|
|
15
|
+
* B_k (the sum over the subsets of size k of the products of r = exp(eta - max eta)) and its first and second
|
|
16
|
+
* derivatives D_k, H_k are built one member at a time (B_k += r B_{k-1}, from the largest k down). B_k grows like the
|
|
17
|
+
* binomial coefficient, past the doubles for large sets (a set of 2000 with 1000 cases): each k keeps its own power of 2.
|
|
18
|
+
*/
|
|
19
|
+
function evaluateExact(sets, beta) {
|
|
20
|
+
const p = beta.length;
|
|
21
|
+
let loglik = 0;
|
|
22
|
+
const score = new Array(p).fill(0);
|
|
23
|
+
const info = Array.from({ length: p }, () => new Array(p).fill(0));
|
|
24
|
+
for (const { x, cases: d } of sets) {
|
|
25
|
+
const m = x.length;
|
|
26
|
+
if (d === 0 || d === m)
|
|
27
|
+
continue; // a set of cases only or controls only carries no information
|
|
28
|
+
const eta = x.map((row) => row.reduce((acc, v, j) => acc + v * beta[j], 0));
|
|
29
|
+
const top = Math.max(...eta);
|
|
30
|
+
const B = new Array(d + 1).fill(0);
|
|
31
|
+
const E = new Array(d + 1).fill(0); // B_k, D_k, H_k are stored divided by 2^E[k]
|
|
32
|
+
const D = Array.from({ length: d + 1 }, () => new Array(p).fill(0));
|
|
33
|
+
const H = Array.from({ length: d + 1 }, () => Array.from({ length: p }, () => new Array(p).fill(0)));
|
|
34
|
+
B[0] = 1;
|
|
35
|
+
for (let i = 0; i < m; i++) {
|
|
36
|
+
const xi = x[i];
|
|
37
|
+
const r = Math.exp(eta[i] - top);
|
|
38
|
+
for (let k = Math.min(d, i + 1); k >= 1; k--) {
|
|
39
|
+
// new_k = old_k + r old_{k-1}, the two in the common unit 2^e
|
|
40
|
+
const e = B[k] === 0 ? E[k - 1] : Math.max(E[k], E[k - 1]);
|
|
41
|
+
const fa = B[k] === 0 ? 0 : 2 ** (E[k] - e);
|
|
42
|
+
const fb = r * 2 ** (E[k - 1] - e);
|
|
43
|
+
const bPrev = B[k - 1], dPrev = D[k - 1], hPrev = H[k - 1], dk = D[k], hk = H[k];
|
|
44
|
+
B[k] = B[k] * fa + fb * bPrev;
|
|
45
|
+
for (let a = 0; a < p; a++) {
|
|
46
|
+
const da = dk[a];
|
|
47
|
+
dk[a] = da * fa + fb * (xi[a] * bPrev + dPrev[a]);
|
|
48
|
+
for (let b = 0; b < p; b++) {
|
|
49
|
+
hk[a][b] = hk[a][b] * fa + fb * (xi[a] * xi[b] * bPrev + xi[a] * dPrev[b] + xi[b] * dPrev[a] + hPrev[a][b]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
E[k] = e;
|
|
53
|
+
// keep the stored B_k near 1 (D_k and H_k are of the same order times the covariates)
|
|
54
|
+
if (B[k] > 2 ** 256 || (B[k] > 0 && B[k] < 2 ** -256)) {
|
|
55
|
+
const shift = Math.floor(Math.log2(B[k]));
|
|
56
|
+
const f = 2 ** -shift;
|
|
57
|
+
B[k] = B[k] * f;
|
|
58
|
+
for (let a = 0; a < p; a++) {
|
|
59
|
+
dk[a] = dk[a] * f;
|
|
60
|
+
for (let b = 0; b < p; b++)
|
|
61
|
+
hk[a][b] = hk[a][b] * f;
|
|
62
|
+
}
|
|
63
|
+
E[k] = e + shift;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
let num = 0;
|
|
68
|
+
for (let i = 0; i < d; i++)
|
|
69
|
+
num += eta[i] - top;
|
|
70
|
+
loglik += num - (Math.log(B[d]) + E[d] * Math.LN2);
|
|
71
|
+
for (let a = 0; a < p; a++) {
|
|
72
|
+
let sx = 0;
|
|
73
|
+
for (let i = 0; i < d; i++)
|
|
74
|
+
sx += x[i][a];
|
|
75
|
+
const ma = D[d][a] / B[d];
|
|
76
|
+
score[a] += sx - ma;
|
|
77
|
+
for (let b = 0; b < p; b++)
|
|
78
|
+
info[a][b] += H[d][a][b] / B[d] - ma * (D[d][b] / B[d]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { loglik, score, info };
|
|
82
|
+
}
|
|
83
|
+
function test(statistic, df) {
|
|
84
|
+
return { statistic, df, pValue: pchisq(statistic, df, { lowerTail: false }) };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Conditional logistic regression for matched sets (1:1, 1:M or several cases per set). Equivalent to
|
|
88
|
+
* `survival::clogit()` in R. The call followed is `clogit(y ~ x1 + ... + strata(set), method)`.
|
|
89
|
+
*
|
|
90
|
+
* `y` is 1 for a case and 0 for a control, `x` one row of covariates per observation, `strata` the matched set of
|
|
91
|
+
* each observation (for matched pairs from {@link match}, the pair number). Sets with only cases or only controls
|
|
92
|
+
* carry no information. `"exact"` (R's default) uses the exact conditional likelihood, summing over the subsets of each
|
|
93
|
+
* set with as many members as it has cases; `"approximate"` is Breslow's approximation, the same as {@link coxph}
|
|
94
|
+
* with equal times, `ties: "breslow"` and these strata.
|
|
95
|
+
* @category Survival analysis
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const y = [1, 0, 1, 0, 1, 0, 0, 1];
|
|
99
|
+
* const x = [[1], [0], [1], [0], [0], [0], [1], [0]];
|
|
100
|
+
* const fit = clogit(y, x, [1, 1, 2, 2, 3, 3, 4, 4]);
|
|
101
|
+
* fit.coefficients; // [0.6931471805599454] (log 2: two discordant pairs for x, one against)
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function clogit(y, x, strata, options = {}) {
|
|
105
|
+
checkOptions(options, CLOGIT_KEYS, "clogit"); // generated: option-keys.mjs
|
|
106
|
+
checkOptions(nestedOptions(options, "control"), CLOGIT_CONTROL_KEYS, "clogit", "control"); // generated: option-keys.mjs
|
|
107
|
+
const { method = "exact", confLevel = 0.95, control = {} } = options;
|
|
108
|
+
const { eps = 1e-9, iterMax = 20 } = control;
|
|
109
|
+
const n = y.length;
|
|
110
|
+
if (x.length !== n || strata.length !== n)
|
|
111
|
+
throw new RangeError("'y', 'x' and 'strata' must have the same length");
|
|
112
|
+
if (method !== "exact" && method !== "approximate" && method !== "breslow")
|
|
113
|
+
throw new RangeError(`invalid 'method': ${String(method)}`);
|
|
114
|
+
y.forEach((v, i) => { if (v !== 0 && v !== 1)
|
|
115
|
+
throw new RangeError(`'y' must be 0 or 1 (element ${i + 1})`); });
|
|
116
|
+
const p = x[0]?.length ?? 0;
|
|
117
|
+
if (p === 0 || x.some((row) => row.length !== p || row.some((v) => !Number.isFinite(v)))) {
|
|
118
|
+
throw new RangeError("'x' must have the same positive number of finite covariates in every row");
|
|
119
|
+
}
|
|
120
|
+
const zq = qnorm((1 + confLevel) / 2);
|
|
121
|
+
const finish = (coefficients, variance, loglik, score, wald, iter, m, warnings) => {
|
|
122
|
+
const se = variance.map((row, i) => Math.sqrt(row[i]));
|
|
123
|
+
const z = coefficients.map((c, i) => c / se[i]);
|
|
124
|
+
return {
|
|
125
|
+
coefficients, var: variance, loglik, score, wald, iter, n, nevent: y.reduce((s, v) => s + v, 0), method: m, se, z,
|
|
126
|
+
p: z.map((v) => pchisq(v * v, 1, { lowerTail: false })),
|
|
127
|
+
lower: coefficients.map((c, i) => Math.exp(c - zq * se[i])), upper: coefficients.map((c, i) => Math.exp(c + zq * se[i])),
|
|
128
|
+
logtest: test(2 * (loglik[1] - loglik[0]), p), sctest: test(score, p), waldtest: test(wald, p), warnings,
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
if (method !== "exact") {
|
|
132
|
+
const fit = coxph(new Array(n).fill(1), y, x, { ties: "breslow", strata, confLevel, control: { eps, iterMax } });
|
|
133
|
+
return finish(fit.coefficients, fit.var, fit.loglik, fit.score, fit.wald, fit.iter, "breslow", fit.warnings);
|
|
134
|
+
}
|
|
135
|
+
// matched sets with the cases first; covariates centred on the overall means (the likelihood does not change)
|
|
136
|
+
const means = Array.from({ length: p }, (_, j) => x.reduce((s, row) => s + row[j], 0) / n);
|
|
137
|
+
const groups = new Map();
|
|
138
|
+
for (let i = 0; i < n; i++) {
|
|
139
|
+
let g = groups.get(strata[i]);
|
|
140
|
+
if (g === undefined) {
|
|
141
|
+
g = { cases: [], controls: [] };
|
|
142
|
+
groups.set(strata[i], g);
|
|
143
|
+
}
|
|
144
|
+
(y[i] === 1 ? g.cases : g.controls).push(x[i].map((v, j) => v - means[j]));
|
|
145
|
+
}
|
|
146
|
+
const sets = [...groups.values()].map((g) => ({ x: [...g.cases, ...g.controls], cases: g.cases.length }));
|
|
147
|
+
// Newton-Raphson with step halving, as coxph; the pivots of the information below 2^-39 of the largest are dropped
|
|
148
|
+
// (an aliased covariate gets NaN, as R's NA)
|
|
149
|
+
const tolerChol = 2 ** -39;
|
|
150
|
+
const factorOf = (info) => {
|
|
151
|
+
const f = info.map((row) => row.slice());
|
|
152
|
+
return { f, rank: cholFactor(f, tolerChol) };
|
|
153
|
+
};
|
|
154
|
+
let beta = new Array(p).fill(0);
|
|
155
|
+
let ev = evaluateExact(sets, beta);
|
|
156
|
+
const loglik = [ev.loglik, ev.loglik];
|
|
157
|
+
let { f: factor } = factorOf(ev.info);
|
|
158
|
+
let step = cholSolve(factor, ev.score);
|
|
159
|
+
const score = ev.score.reduce((acc, u, i) => acc + u * step[i], 0);
|
|
160
|
+
const warnings = [];
|
|
161
|
+
// the coefficients accepted at each iteration (0: the start), for the iterations-ran-out case below
|
|
162
|
+
const accepted = [beta];
|
|
163
|
+
let best = ev.loglik;
|
|
164
|
+
let next = beta.map((b, i) => b + step[i]);
|
|
165
|
+
let halvings = 0;
|
|
166
|
+
let converged = false;
|
|
167
|
+
let iter = 0;
|
|
168
|
+
for (iter = 1; iter <= iterMax; iter++) {
|
|
169
|
+
ev = evaluateExact(sets, next);
|
|
170
|
+
const finite = Number.isFinite(ev.loglik) && ev.score.every(Number.isFinite);
|
|
171
|
+
// (no shortcut for an unchanged log likelihood: R's exact fit with only uninformative sets, 0 / 0, runs out)
|
|
172
|
+
if (finite && Math.abs(1 - best / ev.loglik) <= eps) {
|
|
173
|
+
converged = true;
|
|
174
|
+
beta = next;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
if (!finite || ev.loglik < best) {
|
|
178
|
+
halvings++;
|
|
179
|
+
next = next.map((b, i) => (b + halvings * beta[i]) / (halvings + 1));
|
|
180
|
+
accepted.push(beta);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
halvings = 0;
|
|
184
|
+
best = ev.loglik;
|
|
185
|
+
({ f: factor } = factorOf(ev.info));
|
|
186
|
+
step = cholSolve(factor, ev.score);
|
|
187
|
+
beta = next;
|
|
188
|
+
accepted.push(beta);
|
|
189
|
+
next = next.map((b, i) => b + step[i]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (!converged) {
|
|
193
|
+
// R's exact fit reports iter.max iterations with the coefficients accepted at iteration max(1, iter.max - 1)
|
|
194
|
+
// (experiments/psm112-edge-iter.txt: iter.max = 1, 2, 3, 5 give the approximate fit's coefficients after 1, 1, 2, 4)
|
|
195
|
+
iter = iterMax;
|
|
196
|
+
beta = accepted[Math.max(1, iterMax - 1)] ?? beta;
|
|
197
|
+
warnings.push("Ran out of iterations and did not converge");
|
|
198
|
+
}
|
|
199
|
+
ev = evaluateExact(sets, beta);
|
|
200
|
+
loglik[1] = ev.loglik;
|
|
201
|
+
const fin = factorOf(ev.info);
|
|
202
|
+
const inverse = cholInverse(fin.f);
|
|
203
|
+
const coefficients = beta.map((b, j) => (fin.rank < p && inverse[j][j] === 0 ? NaN : b));
|
|
204
|
+
// Wald statistic beta' var^-1 beta over the coefficients kept
|
|
205
|
+
const kept = coefficients.map((c, j) => (Number.isNaN(c) ? -1 : j)).filter((j) => j >= 0);
|
|
206
|
+
let wald = 0;
|
|
207
|
+
for (const a of kept)
|
|
208
|
+
for (const b of kept)
|
|
209
|
+
wald += beta[a] * ev.info[a][b] * beta[b];
|
|
210
|
+
return finish(coefficients, inverse, loglik, score, wald, iter, "exact", warnings);
|
|
211
|
+
}
|
package/dist/models/coxph.d.ts
CHANGED
|
@@ -174,6 +174,15 @@ export interface CoxphResult {
|
|
|
174
174
|
/** R's warnings, each once, in order of first appearance. */
|
|
175
175
|
warnings: string[];
|
|
176
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Generalised Cholesky factorisation M = L D L' in place (D on the diagonal, L below it), pivots below the tolerance
|
|
179
|
+
* set to 0. Returns the rank (negative when M is not non-negative definite).
|
|
180
|
+
*/
|
|
181
|
+
export declare function cholFactor(m: number[][], tol: number): number;
|
|
182
|
+
/** Solves M y = b with the factor of {@link cholFactor} (0 for the dropped pivots) */
|
|
183
|
+
export declare function cholSolve(m: readonly number[][], b: readonly number[]): number[];
|
|
184
|
+
/** The (generalised) inverse from the factor of {@link cholFactor}, in place; returns the full symmetric matrix */
|
|
185
|
+
export declare function cholInverse(m: number[][]): number[][];
|
|
177
186
|
/**
|
|
178
187
|
* Cox proportional hazards regression. Equivalent to R's `survival::coxph()`. As
|
|
179
188
|
* `coxph(Surv(time, status) ~ x ...)` for right-censored data and `coxph(Surv(start, stop, status) ~ x ...)` for
|
package/dist/models/coxph.js
CHANGED
|
@@ -441,7 +441,7 @@ function scoreResidualsCounting(data, beta, efron) {
|
|
|
441
441
|
* Generalised Cholesky factorisation M = L D L' in place (D on the diagonal, L below it), pivots below the tolerance
|
|
442
442
|
* set to 0. Returns the rank (negative when M is not non-negative definite).
|
|
443
443
|
*/
|
|
444
|
-
function cholFactor(m, tol) {
|
|
444
|
+
export function cholFactor(m, tol) {
|
|
445
445
|
const p = m.length;
|
|
446
446
|
let scale = 0;
|
|
447
447
|
let anyPositive = false;
|
|
@@ -481,7 +481,7 @@ function cholFactor(m, tol) {
|
|
|
481
481
|
return nonNegative ? rank : -rank;
|
|
482
482
|
}
|
|
483
483
|
/** Solves M y = b with the factor of {@link cholFactor} (0 for the dropped pivots) */
|
|
484
|
-
function cholSolve(m, b) {
|
|
484
|
+
export function cholSolve(m, b) {
|
|
485
485
|
const p = m.length;
|
|
486
486
|
const y = b.slice();
|
|
487
487
|
for (let i = 0; i < p; i++) {
|
|
@@ -503,7 +503,7 @@ function cholSolve(m, b) {
|
|
|
503
503
|
return y;
|
|
504
504
|
}
|
|
505
505
|
/** The (generalised) inverse from the factor of {@link cholFactor}, in place; returns the full symmetric matrix */
|
|
506
|
-
function cholInverse(m) {
|
|
506
|
+
export function cholInverse(m) {
|
|
507
507
|
const p = m.length;
|
|
508
508
|
for (let i = 0; i < p; i++) {
|
|
509
509
|
if (!(m[i][i] > 0))
|