@numero-uno-jpn/rstats 1.2.0 → 1.4.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 +128 -0
- package/README.ja.md +28 -11
- package/README.md +27 -10
- package/dist/chunks/{chunk-RRO4LMCB.js → chunk-27VFB3SA.js} +2 -2
- package/dist/chunks/{chunk-BKV3FINA.js → chunk-56GFP4UU.js} +2 -2
- package/dist/chunks/{chunk-JWBSEL3V.js → chunk-5SW3L6J3.js} +2 -2
- package/dist/chunks/{chunk-NSU6U3ET.js → chunk-6FZAJQ4H.js} +2 -2
- package/dist/chunks/{chunk-VERBXW6E.js → chunk-BQJFFGYP.js} +2 -2
- package/dist/chunks/{chunk-ORE5ZRCY.js → chunk-F6Z3GLWA.js} +2 -2
- package/dist/chunks/{chunk-2NNBUYHJ.js → chunk-GBSMRVUY.js} +2 -2
- package/dist/chunks/{chunk-7WG7X2UI.js → chunk-GEF2YRBV.js} +2 -2
- package/dist/chunks/{chunk-L23RSC2N.js → chunk-GIER5WMB.js} +2 -2
- package/dist/chunks/{chunk-IAWXF73N.js → chunk-GLGOV3A5.js} +2 -2
- package/dist/chunks/{chunk-F3EQLL4F.js → chunk-H72MW7YP.js} +2 -2
- package/dist/chunks/{chunk-T5DRIITM.js → chunk-HWB7XRX2.js} +2 -2
- package/dist/chunks/chunk-J72MLFUG.js +2 -0
- package/dist/chunks/{chunk-TNETWBF5.js → chunk-PZ66PUWC.js} +2 -2
- package/dist/chunks/{chunk-IMPRIQE5.js → chunk-RUZATICF.js} +1 -1
- package/dist/chunks/{chunk-BI7NYJWP.js → chunk-RY7CCWVU.js} +1 -1
- package/dist/chunks/{chunk-7INBXTVV.js → chunk-S2YCFUCA.js} +2 -2
- package/dist/chunks/chunk-SVS54D6Z.js +2 -0
- package/dist/chunks/{chunk-HBHMEPGY.js → chunk-TEHMTQNB.js} +3 -3
- package/dist/chunks/chunk-UMMCVF53.js +2 -0
- package/dist/chunks/{chunk-5SGTWSCB.js → chunk-UNP4HBPP.js} +2 -2
- package/dist/chunks/{chunk-A66M3ZEA.js → chunk-V2KVTAVV.js} +2 -2
- package/dist/chunks/{chunk-EEU7D4RU.js → chunk-WWJGCBWH.js} +1 -1
- package/dist/chunks/chunk-X7K6EF7S.js +2 -0
- package/dist/chunks/{chunk-73LNRWU3.js → chunk-YBOSCQF2.js} +1 -1
- package/dist/chunks/{chunk-6FZHTD5G.js → chunk-ZQSOMEIM.js} +2 -2
- package/dist/chunks/{chunk-4AOTAT3O.js → chunk-ZRFZ5UIB.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/tests.d.ts +13 -0
- package/dist/entries/tests.js +13 -0
- package/dist/htest/agreement.d.ts +2 -2
- package/dist/htest/blandAltman.d.ts +100 -0
- package/dist/htest/blandAltman.js +159 -0
- package/dist/htest/diagnosticTests.d.ts +91 -0
- package/dist/htest/diagnosticTests.js +116 -0
- package/dist/htest/iccPsych.d.ts +106 -0
- package/dist/htest/iccPsych.js +332 -0
- package/dist/htest/ksTest.d.ts +1 -1
- package/dist/htest/mcreg.d.ts +209 -0
- package/dist/htest/mcreg.js +735 -0
- package/dist/htest/roc.d.ts +287 -0
- package/dist/htest/roc.js +635 -0
- package/dist/htest/rocTest.d.ts +139 -0
- package/dist/htest/rocTest.js +444 -0
- package/dist/htest/tTOST.d.ts +202 -0
- package/dist/htest/tTOST.js +558 -0
- package/dist/htest/trendTests.d.ts +1 -1
- package/dist/htest/trendTests.js +1 -1
- package/dist/internal/summary.js +5 -0
- package/dist/linalg/qr.d.ts +3 -0
- package/dist/linalg/qr.js +3 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/coeftest.d.ts +139 -0
- package/dist/models/coeftest.js +237 -0
- package/dist/models/competingRisks.d.ts +188 -0
- package/dist/models/competingRisks.js +673 -0
- package/dist/models/coxZph.d.ts +67 -0
- package/dist/models/coxZph.js +479 -0
- package/dist/models/coxph.d.ts +107 -16
- package/dist/models/coxph.js +641 -72
- package/dist/models/glm.d.ts +11 -1
- package/dist/models/glm.js +19 -2
- package/dist/models/inputRows.d.ts +10 -0
- package/dist/models/inputRows.js +23 -0
- package/dist/models/lm.d.ts +8 -0
- package/dist/models/lm.js +14 -2
- package/dist/models/rmst2.d.ts +126 -0
- package/dist/models/rmst2.js +365 -0
- package/dist/models/sandwich.d.ts +177 -0
- package/dist/models/sandwich.js +923 -0
- package/dist/models/survival.d.ts +65 -24
- package/dist/models/survival.js +407 -72
- package/dist/models/survreg.d.ts +160 -0
- package/dist/models/survreg.js +809 -0
- package/dist/numerics.js +2 -2
- package/dist/random/rng.d.ts +8 -1
- package/dist/random/rng.js +14 -1
- package/dist/rstats.js +16 -16
- package/dist/special.js +2 -2
- package/dist/tests.js +13 -13
- package/llms.txt +25 -0
- package/package.json +1 -1
- package/dist/chunks/chunk-47IIPUFN.js +0 -2
- package/dist/chunks/chunk-CQB4BJBR.js +0 -2
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// Tests and confidence intervals of the coefficients of lm and glm fits with a given covariance matrix (such as one of
|
|
2
|
+
// vcovHC or vcovCL): the lmtest package's coeftest and coefci.
|
|
3
|
+
//
|
|
4
|
+
// Written for rStats.js (no ported code) from oracle/robust-behaviour.md (a description of the behaviour of lmtest
|
|
5
|
+
// 0.9-40): Wald statistics estimate / standard error with the standard errors from the diagonal of the covariance, t
|
|
6
|
+
// tests on the residual degrees of freedom of an lm and z tests for a glm (Zeileis and Hothorn 2002, "Diagnostic
|
|
7
|
+
// checking in regression relationships", R News 2(3), 7-10).
|
|
8
|
+
import { pt1, qt1 } from "../distributions/t.js";
|
|
9
|
+
import { pnorm, qnorm } from "../distributions/normal.js";
|
|
10
|
+
import { reported, unreported } from "../internal/warnings.js";
|
|
11
|
+
import { checkFit, coefficientNames, isGlm, modelCovariance, scaledStandardError } from "./sandwich.js";
|
|
12
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
13
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
14
|
+
const COEFTEST_KEYS = ["vcov", "df"];
|
|
15
|
+
const COEFCI_KEYS = ["parm", "level", "vcov", "df"];
|
|
16
|
+
function isVcovResult(v) {
|
|
17
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && Array.isArray(v.vcov) && Array.isArray(v.names);
|
|
18
|
+
}
|
|
19
|
+
function checkMatrix(m) {
|
|
20
|
+
if (!Array.isArray(m) || m.some((r) => !Array.isArray(r) && !ArrayBuffer.isView(r)))
|
|
21
|
+
throw new TypeError("'vcov' must be a matrix (an array of rows)");
|
|
22
|
+
const rows = m.map((r) => Array.from(r, Number));
|
|
23
|
+
if (rows.some((r) => r.length !== rows.length))
|
|
24
|
+
throw new RangeError("'vcov' must be a square matrix");
|
|
25
|
+
return rows;
|
|
26
|
+
}
|
|
27
|
+
const unique = (v) => new Set(v).size === v.length;
|
|
28
|
+
/** The estimates and standard errors of the coefficients kept, with their names and the warnings of the covariance */
|
|
29
|
+
function coefficientTable(fit, vcov) {
|
|
30
|
+
checkFit(fit);
|
|
31
|
+
const estAll = fit.coefficients;
|
|
32
|
+
const namesAll = coefficientNames(fit);
|
|
33
|
+
const p = estAll.length;
|
|
34
|
+
const aliased = estAll.map((b) => Number.isNaN(b));
|
|
35
|
+
let V;
|
|
36
|
+
let vNames;
|
|
37
|
+
let warnings = [];
|
|
38
|
+
let se;
|
|
39
|
+
if (vcov === undefined) {
|
|
40
|
+
// the fit's own covariance: the aliased coefficients stay, with NaN (R's vcov has NA rows for them); the standard
|
|
41
|
+
// errors from its scaled form (representable where the covariance is not, responses near 1e±300)
|
|
42
|
+
const m = modelCovariance(fit);
|
|
43
|
+
const pos = new Map(m.names.map((nm, i) => [nm, i]));
|
|
44
|
+
const kept = namesAll.map((nm, j) => (aliased[j] ? undefined : pos.get(nm)));
|
|
45
|
+
V = kept.map((a) => kept.map((b) => (a === undefined || b === undefined ? NaN : m.vcov[a][b])));
|
|
46
|
+
vNames = namesAll;
|
|
47
|
+
se = kept.map((a) => (a === undefined ? NaN : (scaledStandardError(m.vcov, a, m.vcov[a][a]) ?? Math.sqrt(m.vcov[a][a]))));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const v = typeof vcov === "function" ? unreported(() => vcov(fit)) : vcov;
|
|
51
|
+
const given = isVcovResult(v) ? v.vcov : v;
|
|
52
|
+
if (isVcovResult(v)) {
|
|
53
|
+
V = checkMatrix(v.vcov);
|
|
54
|
+
vNames = v.names.slice();
|
|
55
|
+
if (vNames.length !== V.length)
|
|
56
|
+
throw new RangeError("'vcov' must have one name per row");
|
|
57
|
+
warnings = [...(v.warnings ?? [])];
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
V = checkMatrix(v);
|
|
61
|
+
// the standard errors: of a result of vcovHC or vcovCL from its scaled form (representable where the variance is
|
|
62
|
+
// Infinity or 0), else the square root of the diagonal, which must be a finite non-negative number (R gives NaN,
|
|
63
|
+
// with "NaNs produced" for a negative variance; errors here). Only the diagonal is used: the matrix is not checked
|
|
64
|
+
// for symmetry
|
|
65
|
+
se = V.map((r, j) => {
|
|
66
|
+
const d = r[j];
|
|
67
|
+
const s = typeof given === "object" && given !== null ? scaledStandardError(given, j, d) : undefined;
|
|
68
|
+
if (s !== undefined && !Number.isNaN(s))
|
|
69
|
+
return s;
|
|
70
|
+
if (!Number.isFinite(d))
|
|
71
|
+
throw new RangeError(`the variance of coefficient ${j + 1} in 'vcov' is not a finite number`);
|
|
72
|
+
if (d < 0)
|
|
73
|
+
throw new RangeError(`the variance of coefficient ${j + 1} in 'vcov' is negative`);
|
|
74
|
+
return Math.sqrt(d);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (vNames !== undefined && unique(vNames) && unique(namesAll)) {
|
|
78
|
+
// by name: the coefficients whose names the covariance has, in the fit's order
|
|
79
|
+
const pos = new Map(vNames.map((nm, i) => [nm, i]));
|
|
80
|
+
const js = namesAll.flatMap((nm, j) => (pos.has(nm) ? [j] : []));
|
|
81
|
+
return { est: js.map((j) => estAll[j]), se: js.map((j) => se[pos.get(namesAll[j])]), names: js.map((j) => namesAll[j]), warnings };
|
|
82
|
+
}
|
|
83
|
+
// by position: one row per coefficient, or per coefficient that is not aliased
|
|
84
|
+
let js;
|
|
85
|
+
if (V.length === p)
|
|
86
|
+
js = estAll.map((_, j) => j);
|
|
87
|
+
else if (V.length === fit.rank)
|
|
88
|
+
js = estAll.flatMap((_, j) => (aliased[j] ? [] : [j]));
|
|
89
|
+
else {
|
|
90
|
+
const sizes = fit.rank === p ? `${p} x ${p}` : `${p} x ${p} or ${fit.rank} x ${fit.rank}`;
|
|
91
|
+
throw new RangeError(`'vcov' must be ${sizes}, one row per coefficient`);
|
|
92
|
+
}
|
|
93
|
+
return { est: js.map((j) => estAll[j]), se, names: js.map((j) => namesAll[j]), warnings };
|
|
94
|
+
}
|
|
95
|
+
/** The degrees of freedom (lmtest's default: the residual degrees of freedom for an lm, Infinity for a glm) */
|
|
96
|
+
function dfOf(fit, df) {
|
|
97
|
+
if (df === undefined)
|
|
98
|
+
return isGlm(fit) ? Infinity : fit.dfResidual;
|
|
99
|
+
if (typeof df !== "number")
|
|
100
|
+
throw new TypeError("'df' must be a number");
|
|
101
|
+
if (Number.isNaN(df))
|
|
102
|
+
throw new RangeError("'df' must not be NaN");
|
|
103
|
+
return df;
|
|
104
|
+
}
|
|
105
|
+
/** Whether t tests are used: a positive finite df (else z, as lmtest) */
|
|
106
|
+
const useT = (df) => Number.isFinite(df) && df > 0;
|
|
107
|
+
function nobsOf(fit) {
|
|
108
|
+
return isGlm(fit) ? fit.priorWeights.filter((w) => w !== 0).length : fit.rank + fit.dfResidual;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Tests of the coefficients of an `lm` or `glm` fit with a given covariance matrix. Equivalent to R's
|
|
112
|
+
* `lmtest::coeftest()`.
|
|
113
|
+
*
|
|
114
|
+
* Each coefficient's estimate divided by its standard error (the square root of the covariance's diagonal), with a t
|
|
115
|
+
* test on `df` degrees of freedom or a z test. The default `df` is the residual degrees of freedom of an lm and
|
|
116
|
+
* `Infinity` (z tests) for a glm of every family, as lmtest (unlike `glmSummary`, which uses t tests where the
|
|
117
|
+
* dispersion is estimated). A covariance whose diagonal has a negative, NaN or infinite variance is an error (R gives
|
|
118
|
+
* NaN); only the diagonal is used (the matrix is not checked for symmetry, as R's). For a result of {@link vcovHC} or
|
|
119
|
+
* {@link vcovCL} (or the fit's own covariance) the standard errors come from the covariance in units of powers of 2,
|
|
120
|
+
* so they are right where the matrix holds Infinity or 0 (a response around 1e±300). That record belongs to the matrix
|
|
121
|
+
* object returned: a copy of it (`vcov.map((r) => r.slice())`, `structuredClone`, JSON) loses it and gives the values
|
|
122
|
+
* the copy holds (se 0, z Infinity and p 0 where it holds 0); pass the result or its original matrix instead.
|
|
123
|
+
*
|
|
124
|
+
* @param fit The result of {@link lm} or {@link glm}.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const fit = lm([1, 2, 3, 4, 5, 6], [1.1, 2.3, 2.8, 4.5, 4.9, 6.4]);
|
|
129
|
+
* const t = coeftest(fit, { vcov: (f) => vcovHC(f, { type: "HC1" }) });
|
|
130
|
+
* t.stdError; // [0.17608, 0.049777]
|
|
131
|
+
* t.pValue; // [0.72421, 0.0000324]
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @category Linear models and ANOVA
|
|
135
|
+
*/
|
|
136
|
+
export function coeftest(fit, options = {}) {
|
|
137
|
+
checkOptions(options, COEFTEST_KEYS, "coeftest"); // generated: option-keys.mjs
|
|
138
|
+
const { est, se, names, warnings } = coefficientTable(fit, options.vcov);
|
|
139
|
+
const df = dfOf(fit, options.df);
|
|
140
|
+
const t = useT(df);
|
|
141
|
+
const statistic = est.map((b, j) => b / se[j]);
|
|
142
|
+
const pValue = statistic.map((s) => (Number.isNaN(s) ? NaN : t ? 2 * pt1(-Math.abs(s), df, true, false) : 2 * pnorm(-Math.abs(s))));
|
|
143
|
+
return reported("coeftest", {
|
|
144
|
+
estimate: est,
|
|
145
|
+
stdError: se,
|
|
146
|
+
statistic,
|
|
147
|
+
pValue,
|
|
148
|
+
names,
|
|
149
|
+
statisticName: t ? "t value" : "z value",
|
|
150
|
+
df,
|
|
151
|
+
method: t ? "t test of coefficients" : "z test of coefficients",
|
|
152
|
+
nobs: nobsOf(fit),
|
|
153
|
+
warnings,
|
|
154
|
+
}, fit, typeof options.vcov === "function" ? undefined : options.vcov);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* R's column names of an interval: format(100 * c(a, 1 - a), digits = 3) followed by " %", both numbers with the
|
|
158
|
+
* decimals the one that needs more of them takes to show 3 significant digits (trailing zeros dropped)
|
|
159
|
+
*/
|
|
160
|
+
function percentNames(a) {
|
|
161
|
+
const v = [100 * a, 100 * (1 - a)];
|
|
162
|
+
const decimals = v.map((x) => {
|
|
163
|
+
if (x === 0 || !Number.isFinite(x))
|
|
164
|
+
return 0;
|
|
165
|
+
const e = Math.floor(Math.log10(Math.abs(x)));
|
|
166
|
+
const s = x.toFixed(Math.max(0, 2 - e));
|
|
167
|
+
const frac = s.includes(".") ? s.replace(/0+$/, "").split(".")[1] : "";
|
|
168
|
+
return frac.length;
|
|
169
|
+
});
|
|
170
|
+
const d = Math.max(...decimals);
|
|
171
|
+
return [`${v[0].toFixed(d)} %`, `${v[1].toFixed(d)} %`];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Confidence intervals of the coefficients of an `lm` or `glm` fit with a given covariance matrix. Equivalent to R's
|
|
175
|
+
* `lmtest::coefci()`.
|
|
176
|
+
*
|
|
177
|
+
* The limits estimate ± q se with the t quantile on `df` degrees of freedom, or the normal quantile (by default for a
|
|
178
|
+
* glm of every family, as lmtest). `parm` takes 0-based indices (R: 1-based) or names. The standard errors as in
|
|
179
|
+
* {@link coeftest}: from the covariance in units of powers of 2 for a result of {@link vcovHC} or {@link vcovCL} or
|
|
180
|
+
* its original matrix, not for a copy of the matrix (which gives intervals of width 0 where it holds 0).
|
|
181
|
+
*
|
|
182
|
+
* @param fit The result of {@link lm} or {@link glm}.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* const fit = lm([1, 2, 3, 4, 5, 6], [1.1, 2.3, 2.8, 4.5, 4.9, 6.4]);
|
|
187
|
+
* const ci = coefci(fit, { vcov: (f) => vcovHC(f) });
|
|
188
|
+
* ci.colNames; // ["2.5 %", "97.5 %"]
|
|
189
|
+
* ci.lower; // [-0.51418, 0.84206]
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @category Linear models and ANOVA
|
|
193
|
+
*/
|
|
194
|
+
export function coefci(fit, options = {}) {
|
|
195
|
+
checkOptions(options, COEFCI_KEYS, "coefci"); // generated: option-keys.mjs
|
|
196
|
+
const level = options.level ?? 0.95;
|
|
197
|
+
if (typeof level !== "number")
|
|
198
|
+
throw new TypeError("'level' must be a number");
|
|
199
|
+
// R computes NaN limits outside [0, 1] (with "NaNs produced"): an error
|
|
200
|
+
if (!(level >= 0 && level <= 1))
|
|
201
|
+
throw new RangeError("'level' must be between 0 and 1");
|
|
202
|
+
const tab = coefficientTable(fit, options.vcov);
|
|
203
|
+
const df = dfOf(fit, options.df);
|
|
204
|
+
let rows = tab.est.map((_, j) => j);
|
|
205
|
+
const parm = options.parm;
|
|
206
|
+
if (parm !== undefined) {
|
|
207
|
+
const list = (Array.isArray(parm) ? parm : [parm]);
|
|
208
|
+
if (list.every((v) => typeof v === "string")) {
|
|
209
|
+
const wanted = new Set(list);
|
|
210
|
+
rows = rows.filter((j) => wanted.has(tab.names[j]));
|
|
211
|
+
}
|
|
212
|
+
else if (list.every((v) => typeof v === "number")) {
|
|
213
|
+
rows = list.map((j) => {
|
|
214
|
+
if (!Number.isInteger(j) || j < 0)
|
|
215
|
+
throw new RangeError("'parm' must hold 0-based indices or names");
|
|
216
|
+
if (j >= tab.est.length)
|
|
217
|
+
throw new RangeError("subscript out of bounds");
|
|
218
|
+
return j;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
else
|
|
222
|
+
throw new TypeError("'parm' must hold 0-based indices or names");
|
|
223
|
+
}
|
|
224
|
+
const a = (1 - level) / 2;
|
|
225
|
+
// the lower quantile, and the upper from the upper tail where 1 - a has lost its digits
|
|
226
|
+
const [lo, hi] = useT(df)
|
|
227
|
+
? [qt1(a, df, true, false), a < 1e-8 ? qt1(a, df, false, false) : qt1(1 - a, df, true, false)]
|
|
228
|
+
: [qnorm(a), a < 1e-8 ? qnorm(a, { lowerTail: false }) : qnorm(1 - a)];
|
|
229
|
+
const limit = (b, s, q) => b + q * s;
|
|
230
|
+
return reported("coefci", {
|
|
231
|
+
lower: rows.map((j) => limit(tab.est[j], tab.se[j], lo)),
|
|
232
|
+
upper: rows.map((j) => limit(tab.est[j], tab.se[j], hi)),
|
|
233
|
+
names: rows.map((j) => tab.names[j]),
|
|
234
|
+
colNames: percentNames(a),
|
|
235
|
+
warnings: tab.warnings,
|
|
236
|
+
}, fit, typeof options.vcov === "function" ? undefined : options.vcov);
|
|
237
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { type GroupLabel } from "../htest/groups.js";
|
|
2
|
+
/** A cumulative-incidence curve, represented by its step-function corners.
|
|
3
|
+
* @category Survival analysis
|
|
4
|
+
*/
|
|
5
|
+
export interface CumincCurve {
|
|
6
|
+
name: string;
|
|
7
|
+
group: string;
|
|
8
|
+
cause: string;
|
|
9
|
+
time: number[];
|
|
10
|
+
est: number[];
|
|
11
|
+
var: number[];
|
|
12
|
+
}
|
|
13
|
+
/** One cause's Gray test across the groups.
|
|
14
|
+
* @category Survival analysis
|
|
15
|
+
*/
|
|
16
|
+
export interface CumincTest {
|
|
17
|
+
cause: string;
|
|
18
|
+
stat: number;
|
|
19
|
+
df: number;
|
|
20
|
+
pValue: number;
|
|
21
|
+
}
|
|
22
|
+
/** Options for {@link cuminc}.
|
|
23
|
+
* @category Survival analysis
|
|
24
|
+
*/
|
|
25
|
+
export interface CumincOptions {
|
|
26
|
+
/** Group labels, one per observation. Omitted: one group. */
|
|
27
|
+
group?: readonly (GroupLabel | null)[];
|
|
28
|
+
/** Stratification labels for Gray's test; curves remain group-specific. */
|
|
29
|
+
strata?: readonly (GroupLabel | null)[];
|
|
30
|
+
/** Power of the Gray test's weight, G(t-)^rho. Default 0. */
|
|
31
|
+
rho?: number;
|
|
32
|
+
/** Censoring code. Default 0. */
|
|
33
|
+
cencode?: GroupLabel;
|
|
34
|
+
}
|
|
35
|
+
/** Result of {@link cuminc}.
|
|
36
|
+
* @category Survival analysis
|
|
37
|
+
*/
|
|
38
|
+
export interface CumincResult {
|
|
39
|
+
curves: CumincCurve[];
|
|
40
|
+
tests?: CumincTest[];
|
|
41
|
+
warnings: string[];
|
|
42
|
+
}
|
|
43
|
+
/** Result of {@link timepoints}.
|
|
44
|
+
* @category Survival analysis
|
|
45
|
+
*/
|
|
46
|
+
export interface TimepointsResult {
|
|
47
|
+
curveNames: string[];
|
|
48
|
+
times: number[];
|
|
49
|
+
est: number[][];
|
|
50
|
+
var: number[][];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Cumulative incidence functions and Gray's tests for competing risks. Equivalent to `cmprsk::cuminc()` in R.
|
|
54
|
+
* Uses the Aalen-Johansen cumulative-incidence estimator and Gray's weighted test; tied-time
|
|
55
|
+
* variance uses the documented hypergeometric correction.
|
|
56
|
+
*
|
|
57
|
+
* @param time Follow-up times (finite and non-negative).
|
|
58
|
+
* @param status Event codes; every code other than `cencode` is a competing event cause.
|
|
59
|
+
* @param options See {@link CumincOptions}.
|
|
60
|
+
* @returns One step-function curve for each group and cause, optional Gray tests, and warnings.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const fit = cuminc([1, 2, 3, 4], [1, 0, 2, 1]);
|
|
65
|
+
* fit.curves[0]!.est;
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @category Survival analysis
|
|
69
|
+
*/
|
|
70
|
+
export declare function cuminc(time: readonly number[], status: readonly GroupLabel[], options?: CumincOptions): CumincResult;
|
|
71
|
+
/**
|
|
72
|
+
* Evaluate cumulative-incidence curves at requested times. Equivalent to `cmprsk::timepoints()` in R.
|
|
73
|
+
* At a requested time the last corner at or before it is used; values before zero or after a
|
|
74
|
+
* group's final follow-up are NaN.
|
|
75
|
+
*
|
|
76
|
+
* @param fit Result of {@link cuminc}.
|
|
77
|
+
* @param times Evaluation times.
|
|
78
|
+
* @returns Matrices with one row per curve and one column per sorted unique requested time.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const fit = cuminc([1, 2, 3], [1, 0, 1]);
|
|
83
|
+
* timepoints(fit, [1, 2]).est;
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @category Survival analysis
|
|
87
|
+
*/
|
|
88
|
+
export declare function timepoints(fit: CumincResult, times: readonly number[]): TimepointsResult;
|
|
89
|
+
/** Time-dependent covariate transformation for {@link crr}.
|
|
90
|
+
* @category Survival analysis
|
|
91
|
+
*/
|
|
92
|
+
export type CrrTimeFunction = (times: readonly number[]) => readonly (readonly number[])[];
|
|
93
|
+
/** Options for {@link crr}.
|
|
94
|
+
* @category Survival analysis
|
|
95
|
+
*/
|
|
96
|
+
export interface CrrOptions {
|
|
97
|
+
/** Time-dependent covariate matrix, one row per observation. */
|
|
98
|
+
cov2?: readonly (readonly number[])[];
|
|
99
|
+
/** Transform the unique failure times to a matrix with one row per time. Required with cov2. */
|
|
100
|
+
tf?: CrrTimeFunction;
|
|
101
|
+
/** Cause whose subdistribution hazard is modelled. Default 1. */
|
|
102
|
+
failcode?: GroupLabel;
|
|
103
|
+
/** Censoring code. Default 0. */
|
|
104
|
+
cencode?: GroupLabel;
|
|
105
|
+
/** Convergence tolerance. Default 1e-6. */
|
|
106
|
+
gtol?: number;
|
|
107
|
+
/** Maximum Newton iterations. Default 10. */
|
|
108
|
+
maxiter?: number;
|
|
109
|
+
/** Initial coefficient vector. Default all zero. */
|
|
110
|
+
init?: readonly number[];
|
|
111
|
+
/** Whether to compute the sandwich variance and residuals. Default true. */
|
|
112
|
+
variance?: boolean;
|
|
113
|
+
/** Confidence level for exponentiated coefficient intervals. Default 0.95. */
|
|
114
|
+
confLevel?: number;
|
|
115
|
+
/** Coefficient names, in the order of cov1 then cov2 interactions. */
|
|
116
|
+
names?: readonly string[];
|
|
117
|
+
}
|
|
118
|
+
/** Fine-Gray regression fit.
|
|
119
|
+
* @category Survival analysis
|
|
120
|
+
*/
|
|
121
|
+
export interface CrrResult {
|
|
122
|
+
coefficients: number[];
|
|
123
|
+
names: string[];
|
|
124
|
+
var: number[][];
|
|
125
|
+
se?: number[];
|
|
126
|
+
z?: number[];
|
|
127
|
+
pValue?: number[];
|
|
128
|
+
lower?: number[];
|
|
129
|
+
upper?: number[];
|
|
130
|
+
expCoef?: number[];
|
|
131
|
+
loglik: number;
|
|
132
|
+
loglikNull: number;
|
|
133
|
+
logtest: {
|
|
134
|
+
statistic: number;
|
|
135
|
+
df: number;
|
|
136
|
+
};
|
|
137
|
+
score: number[];
|
|
138
|
+
inf: number[][];
|
|
139
|
+
invinf: number[][];
|
|
140
|
+
converged: boolean;
|
|
141
|
+
iterations: number;
|
|
142
|
+
n: number;
|
|
143
|
+
nMissing: number;
|
|
144
|
+
uftime: number[];
|
|
145
|
+
bfitj: number[];
|
|
146
|
+
res: number[][] | null;
|
|
147
|
+
tfs: number[][];
|
|
148
|
+
warnings: string[];
|
|
149
|
+
/** Number of baseline and time-varying covariates. */
|
|
150
|
+
covariateDimensions: [number, number];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Fine-Gray proportional subdistribution hazards regression. Equivalent to `cmprsk::crr()` in R.
|
|
154
|
+
* The censoring distribution is estimated by the verified {@link survfit}; Newton-Raphson
|
|
155
|
+
* solves the weighted estimating equations and the variance is the subject-level sandwich.
|
|
156
|
+
*
|
|
157
|
+
* @param time Follow-up times (finite; negative values are allowed).
|
|
158
|
+
* @param status Event codes.
|
|
159
|
+
* @param cov1 Baseline covariate matrix (rows are observations); pass undefined when using only cov2.
|
|
160
|
+
* @param options See {@link CrrOptions}.
|
|
161
|
+
* @returns Coefficients, information, sandwich variance, baseline subdistribution hazard and diagnostics.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const fit = crr([1, 2, 3, 4, 5, 6], [1, 0, 1, 2, 0, 1], [[0], [1], [2], [1], [0], [2]]);
|
|
166
|
+
* fit.coefficients;
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @category Survival analysis
|
|
170
|
+
*/
|
|
171
|
+
export declare function crr(time: readonly number[], status: readonly GroupLabel[], cov1: readonly (readonly number[])[] | undefined, options?: CrrOptions): CrrResult;
|
|
172
|
+
/**
|
|
173
|
+
* Predict cumulative incidence from a Fine-Gray fit. Equivalent to `cmprsk::predict.crr()` in R.
|
|
174
|
+
*
|
|
175
|
+
* @param fit Result of {@link crr}.
|
|
176
|
+
* @param cov1 New baseline covariate matrix.
|
|
177
|
+
* @param cov2 New time-varying covariate matrix, when the fit used cov2.
|
|
178
|
+
* @returns A matrix whose first column is failure time and remaining columns are predicted incidences.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* const fit = crr([1, 2, 3, 4, 5, 6], [1, 0, 1, 2, 0, 1], [[0], [1], [2], [1], [0], [2]]);
|
|
183
|
+
* predictCrr(fit, [[0], [1]]);
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @category Survival analysis
|
|
187
|
+
*/
|
|
188
|
+
export declare function predictCrr(fit: CrrResult, cov1: readonly (readonly number[])[] | undefined, cov2?: readonly (readonly number[])[]): number[][];
|