@numero-uno-jpn/rstats 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/README.ja.md +33 -15
  3. package/README.md +32 -14
  4. package/dist/chunks/{chunk-4KCSBTR5.js → chunk-2VZW4XPK.js} +2 -2
  5. package/dist/chunks/chunk-4OOTEXZU.js +2 -0
  6. package/dist/chunks/{chunk-Z2HGLFZN.js → chunk-6TZVS6WC.js} +2 -2
  7. package/dist/chunks/{chunk-U7BRXOUS.js → chunk-6X2ZMPF5.js} +2 -2
  8. package/dist/chunks/{chunk-GJEKNJP7.js → chunk-AJZV2SVY.js} +2 -2
  9. package/dist/chunks/{chunk-GRUQRNX7.js → chunk-BNTBZ5W3.js} +3 -3
  10. package/dist/chunks/{chunk-DR4GQ7PW.js → chunk-EBRTF7RM.js} +1 -1
  11. package/dist/chunks/{chunk-OG7UORIX.js → chunk-FFNHG5SB.js} +1 -1
  12. package/dist/chunks/{chunk-N5BDSMXS.js → chunk-GUM57VVM.js} +1 -1
  13. package/dist/chunks/{chunk-GGJA3JRO.js → chunk-HBRSUHSU.js} +2 -2
  14. package/dist/chunks/{chunk-HRA7PCQT.js → chunk-I5NWGQOQ.js} +2 -2
  15. package/dist/chunks/chunk-IJV43Y7Q.js +2 -0
  16. package/dist/chunks/{chunk-YN5MLKDL.js → chunk-IOGQEMDE.js} +2 -2
  17. package/dist/chunks/{chunk-GYGQUYEP.js → chunk-JJRZ2TTF.js} +2 -2
  18. package/dist/chunks/{chunk-X4J6UJHN.js → chunk-LA4H6ZSC.js} +2 -2
  19. package/dist/chunks/{chunk-DTJG2IL2.js → chunk-LMNU4NHZ.js} +2 -2
  20. package/dist/chunks/{chunk-4VRMAYPY.js → chunk-LNUNKFIH.js} +3 -3
  21. package/dist/chunks/chunk-MJXETGT2.js +2 -0
  22. package/dist/chunks/chunk-P7ZHH2SF.js +2 -0
  23. package/dist/chunks/{chunk-HUWOSLKE.js → chunk-PDHBRDTF.js} +2 -2
  24. package/dist/chunks/{chunk-7KJ24LYK.js → chunk-RCGW2DCK.js} +2 -2
  25. package/dist/chunks/{chunk-QUTJEYDX.js → chunk-TZTVDVP4.js} +2 -2
  26. package/dist/chunks/{chunk-HZLSNJQM.js → chunk-UJYRU37Z.js} +2 -2
  27. package/dist/chunks/{chunk-EJYCDE4Z.js → chunk-UMDXXT3M.js} +1 -1
  28. package/dist/chunks/{chunk-7IJCUSA5.js → chunk-UOAFEB64.js} +2 -2
  29. package/dist/chunks/{chunk-JNWWLNE3.js → chunk-Z74ZOTUN.js} +2 -2
  30. package/dist/descriptive.js +2 -2
  31. package/dist/distributions.js +2 -2
  32. package/dist/entries/tests.d.ts +14 -0
  33. package/dist/entries/tests.js +14 -0
  34. package/dist/htest/agreement.d.ts +2 -2
  35. package/dist/htest/binomCI.d.ts +116 -0
  36. package/dist/htest/binomCI.js +252 -0
  37. package/dist/htest/blandAltman.d.ts +100 -0
  38. package/dist/htest/blandAltman.js +159 -0
  39. package/dist/htest/boschlooTest.d.ts +65 -0
  40. package/dist/htest/boschlooTest.js +394 -0
  41. package/dist/htest/chisqTest.d.ts +19 -0
  42. package/dist/htest/chisqTest.js +30 -2
  43. package/dist/htest/core/twoProportions.d.ts +48 -0
  44. package/dist/htest/core/twoProportions.js +476 -0
  45. package/dist/htest/diagnosticTests.d.ts +91 -0
  46. package/dist/htest/diagnosticTests.js +116 -0
  47. package/dist/htest/equivalence.d.ts +172 -0
  48. package/dist/htest/equivalence.js +189 -0
  49. package/dist/htest/fisherTest.d.ts +49 -0
  50. package/dist/htest/fisherTest.js +136 -13
  51. package/dist/htest/iccPsych.d.ts +106 -0
  52. package/dist/htest/iccPsych.js +332 -0
  53. package/dist/htest/ksTest.d.ts +1 -1
  54. package/dist/htest/mcreg.d.ts +209 -0
  55. package/dist/htest/mcreg.js +735 -0
  56. package/dist/htest/roc.d.ts +287 -0
  57. package/dist/htest/roc.js +635 -0
  58. package/dist/htest/rocTest.d.ts +139 -0
  59. package/dist/htest/rocTest.js +444 -0
  60. package/dist/htest/tTOST.d.ts +202 -0
  61. package/dist/htest/tTOST.js +558 -0
  62. package/dist/htest/tableTests.d.ts +216 -0
  63. package/dist/htest/tableTests.js +650 -0
  64. package/dist/htest/trendTests.d.ts +1 -1
  65. package/dist/htest/trendTests.js +1 -1
  66. package/dist/htest/twoByTwo.d.ts +203 -0
  67. package/dist/htest/twoByTwo.js +385 -0
  68. package/dist/internal/summary.js +5 -0
  69. package/dist/linalg/qr.d.ts +3 -0
  70. package/dist/linalg/qr.js +3 -0
  71. package/dist/linalg.js +2 -2
  72. package/dist/mixed.js +2 -2
  73. package/dist/models/coeftest.d.ts +139 -0
  74. package/dist/models/coeftest.js +237 -0
  75. package/dist/models/coxph.d.ts +60 -9
  76. package/dist/models/coxph.js +367 -38
  77. package/dist/models/glm.d.ts +11 -1
  78. package/dist/models/glm.js +19 -2
  79. package/dist/models/inputRows.d.ts +10 -0
  80. package/dist/models/inputRows.js +23 -0
  81. package/dist/models/lm.d.ts +8 -0
  82. package/dist/models/lm.js +14 -2
  83. package/dist/models/sandwich.d.ts +177 -0
  84. package/dist/models/sandwich.js +923 -0
  85. package/dist/numerics.js +2 -2
  86. package/dist/random/rng.d.ts +8 -1
  87. package/dist/random/rng.js +14 -1
  88. package/dist/rstats.js +16 -16
  89. package/dist/special/igam.js +140 -23
  90. package/dist/special/loader.js +8 -0
  91. package/dist/special.js +2 -2
  92. package/dist/tests.js +13 -13
  93. package/llms.txt +25 -0
  94. package/package.json +1 -1
  95. package/dist/chunks/chunk-NDTJ23A6.js +0 -2
  96. package/dist/chunks/chunk-UMLMY4XS.js +0 -2
  97. package/dist/chunks/chunk-Y4YWLSWU.js +0 -2
@@ -17,6 +17,7 @@ import { optionalArgs } from "../internal/optionalArgs.js";
17
17
  import { ldexp, ldexpWide, scaleToUnit } from "../internal/summary.js";
18
18
  import { NON_ESTIMABLE_WARNING, nonEstimableRows } from "./estimable.js";
19
19
  import { checkDot, checkedDot } from "../linalg/dot.js";
20
+ import { setInputRowCount } from "./inputRows.js";
20
21
  // Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
21
22
  import { checkOptions, nestedOptions } from "../internal/checkOptions.js";
22
23
  import { optionsIn } from "../internal/optionalArgs.js";
@@ -453,6 +454,7 @@ export function glm(x, y, options = {}) {
453
454
  // R loops over 1:maxit, so a fractional maxit runs (and reports) its integer part
454
455
  maxit: Math.floor(options.maxit ?? 25),
455
456
  start: options.start === undefined ? undefined : Array.from(options.start),
457
+ rows: keep.flatMap((k, i) => (k ? [i] : [])),
456
458
  };
457
459
  if (!(model.epsilon > 0 && model.epsilon < Infinity))
458
460
  throw new RangeError("value of 'epsilon' must be > 0 and finite");
@@ -462,7 +464,7 @@ export function glm(x, y, options = {}) {
462
464
  // (exact; src/internal/summary.ts), so that the deviance stays in range; see scaledView
463
465
  const k = !yIsMatrix && scalesWithResponse(familySpec) ? scaleToUnit([yGiven]).k : 0;
464
466
  if (k === 0)
465
- return reported("glm", fitModel(model));
467
+ return reported("glm", setInputRowCount(fitModel(model), nAll));
466
468
  const down = (v) => ldexp(v, -k);
467
469
  const scaled = fitModel({
468
470
  ...model,
@@ -470,7 +472,7 @@ export function glm(x, y, options = {}) {
470
472
  offset: offset.map(down),
471
473
  start: model.start?.map(down),
472
474
  });
473
- return reported("glm", unscaledResult(scaled, k, { ...model, yScale: k }));
475
+ return reported("glm", setInputRowCount(unscaledResult(scaled, k, { ...model, yScale: k }), nAll));
474
476
  }
475
477
  /** The fit of a model (the part of glm after its checks) */
476
478
  function fitModel(model) {
@@ -794,6 +796,21 @@ export function glmHatvalues(fit) {
794
796
  });
795
797
  return out;
796
798
  }
799
+ /**
800
+ * For each row of non-zero prior weight (in order, as glmHatvalues), its row in the fit's QR decomposition, or -1 for
801
+ * a row the last least squares step left out
802
+ */
803
+ export function glmQrRows(fit) {
804
+ const out = [];
805
+ let k = 0;
806
+ const usedRows = USED_ROWS.get(fit) ?? fit.weights.map((v) => v > 0);
807
+ fit.priorWeights.forEach((w, i) => {
808
+ const r = usedRows[i] ? k++ : -1;
809
+ if (w > 0)
810
+ out.push(r);
811
+ });
812
+ return out;
813
+ }
797
814
  function median(v) {
798
815
  const s = v.slice().sort((a, b) => a - b);
799
816
  const m = s.length >> 1;
@@ -0,0 +1,10 @@
1
+ import type { DataFrame } from "./modelFrame.js";
2
+ /** Records the number of input rows of a fit and returns the fit */
3
+ export declare function setInputRowCount<T extends object>(fit: T, n: number | undefined): T;
4
+ /**
5
+ * The number of input rows of a fit: as recorded, or else one more than the last row used (a fit copied from the
6
+ * result, whose trailing rows dropped for a missing value cannot be known)
7
+ */
8
+ export declare function inputRowCount(fit: object, rows: readonly number[]): number;
9
+ /** The number of rows of a data frame: the length of a column of the formula's variables, else of its first column */
10
+ export declare function dataRowCount(data: DataFrame, variables: readonly string[]): number | undefined;
@@ -0,0 +1,23 @@
1
+ // The number of input rows a fit was given (before the rows with a missing value were dropped), for the functions that
2
+ // take one value per input row of a fit (vcovCL's cluster). Kept beside the result, not in it.
3
+ const INPUT_ROWS = new WeakMap();
4
+ /** Records the number of input rows of a fit and returns the fit */
5
+ export function setInputRowCount(fit, n) {
6
+ if (n !== undefined)
7
+ INPUT_ROWS.set(fit, n);
8
+ return fit;
9
+ }
10
+ /**
11
+ * The number of input rows of a fit: as recorded, or else one more than the last row used (a fit copied from the
12
+ * result, whose trailing rows dropped for a missing value cannot be known)
13
+ */
14
+ export function inputRowCount(fit, rows) {
15
+ return INPUT_ROWS.get(fit) ?? (rows.length === 0 ? 0 : rows[rows.length - 1] + 1);
16
+ }
17
+ /** The number of rows of a data frame: the length of a column of the formula's variables, else of its first column */
18
+ export function dataRowCount(data, variables) {
19
+ for (const v of variables)
20
+ if (Object.hasOwn(data, v))
21
+ return data[v].length;
22
+ return Object.values(data)[0]?.length;
23
+ }
@@ -65,6 +65,12 @@ export interface LmResult {
65
65
  intercept: boolean;
66
66
  /** The QR decomposition of the (weighted) model matrix. */
67
67
  qr: QR;
68
+ /** The model matrix (with the column of ones when there is an intercept) of the rows used, unweighted. */
69
+ x: number[][];
70
+ /** 0-based indices of the input rows used (the rows without a missing value; rows of weight 0 included). */
71
+ rows: number[];
72
+ /** The weights of the rows used, if any. */
73
+ weights?: number[];
68
74
  }
69
75
  /**
70
76
  * Options of {@link lm} with a formula.
@@ -178,6 +184,8 @@ export interface LmCore {
178
184
  * fitted values, effects, sigma and standard errors are multiplied by 2^k, the residual sum of squares by 2^2k.
179
185
  */
180
186
  export declare function fitLm(Xall: number[][], Yall: number[], Wall: number[] | undefined, intercept: boolean, precise?: boolean): LmCore;
187
+ /** The exponent qw of the weights of an lm fit's decomposition (0 for the decomposition with the weights given) */
188
+ export declare function qrWeightExponent(q: QR): number;
181
189
  /**
182
190
  * Options for {@link confint}.
183
191
  *
package/dist/models/lm.js CHANGED
@@ -25,6 +25,7 @@ import { design } from "./modelMatrix.js";
25
25
  import { NON_ESTIMABLE_WARNING, nonEstimableRows } from "./estimable.js";
26
26
  import { checkDot, checkedDot } from "../linalg/dot.js";
27
27
  import { reported } from "../internal/warnings.js";
28
+ import { dataRowCount, setInputRowCount } from "./inputRows.js";
28
29
  // Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
29
30
  import { checkOptions } from "../internal/checkOptions.js";
30
31
  const LM_KEYS = ["weights", "contrasts", "levels", "intercept"];
@@ -77,7 +78,8 @@ export function lmFormulaFit(formula, d, aov) {
77
78
  export function lm(x, y, options = {}) {
78
79
  checkOptions(options, LM_KEYS, "lm"); // generated: option-keys.mjs
79
80
  if (typeof x === "string") {
80
- return reported("lm", lmFormulaFit(x, design(parseFormula(x), y, { ...options, dropUnusedLevels: true }), false));
81
+ const d = design(parseFormula(x), y, { ...options, dropUnusedLevels: true });
82
+ return reported("lm", setInputRowCount(lmFormulaFit(x, d, false), dataRowCount(y, d.terms.variables)));
81
83
  }
82
84
  return lmMatrix(x, y, options);
83
85
  }
@@ -100,7 +102,9 @@ function lmMatrix(x, y, options) {
100
102
  throw new RangeError("missing or negative weights not allowed");
101
103
  const Xall = xr.filter((_, i) => keep[i]).map((r) => (intercept ? [1, ...r] : r));
102
104
  const Yall = ys.filter((_, i) => keep[i]);
103
- return fitLm(Xall, Yall, Wall, intercept).result;
105
+ const result = fitLm(Xall, Yall, Wall, intercept).result;
106
+ result.rows = keep.flatMap((k, i) => (k ? [i] : []));
107
+ return setInputRowCount(result, ys.length);
104
108
  }
105
109
  /**
106
110
  * The coefficients, fitted values, residuals, effects and sums of squares of a fit recomputed in double-double on the
@@ -222,6 +226,10 @@ function zeroWeightRows(core, Xall, Yall, Wall) {
222
226
  * absent for the decomposition with the weights given
223
227
  */
224
228
  const QR_WEIGHT_EXPONENT = new WeakMap();
229
+ /** The exponent qw of the weights of an lm fit's decomposition (0 for the decomposition with the weights given) */
230
+ export function qrWeightExponent(q) {
231
+ return QR_WEIGHT_EXPONENT.get(q) ?? 0;
232
+ }
225
233
  /** Whether every entry of a decomposition is finite */
226
234
  function finiteQR(q) {
227
235
  return q.qr.every((r) => r.every(Number.isFinite)) && q.qraux.every(Number.isFinite);
@@ -353,7 +361,11 @@ function fitLmUnit(Xall, Yall, Wall, intercept, precise) {
353
361
  adjRSquared: 0,
354
362
  intercept,
355
363
  qr: q,
364
+ x: Xall,
365
+ rows: Xall.map((_, i) => i),
356
366
  };
367
+ if (Wall !== undefined)
368
+ result.weights = Wall;
357
369
  const dfInt = intercept ? 1 : 0;
358
370
  const numdf = rank - dfInt;
359
371
  const core = { result, fitRows, effects: (pf?.effects ?? []).map((e) => ldexp(e, kw / 2)), rss: ldexp(rss, kw + rs) };
@@ -0,0 +1,177 @@
1
+ import { type GlmResult } from "./glm.js";
2
+ import { type LmResult } from "./lm.js";
3
+ /**
4
+ * A fit that {@link vcovHC}, {@link vcovCL}, {@link coeftest} and {@link coefci} take: the result of {@link lm} (from a
5
+ * matrix or a formula) or of {@link glm}.
6
+ *
7
+ * @category Linear models and ANOVA
8
+ */
9
+ export type RobustFit = LmResult | GlmResult;
10
+ /**
11
+ * A covariance matrix of the coefficients that are not aliased, with their names: the result of {@link vcovHC} and
12
+ * {@link vcovCL}.
13
+ *
14
+ * @category Linear models and ANOVA
15
+ */
16
+ export interface VcovResult {
17
+ /** The covariance matrix (k × k, k the number of coefficients that are not aliased), or the meat with `sandwich: false`. */
18
+ vcov: number[][];
19
+ /**
20
+ * The names of its rows and columns: the coefficient names of a formula fit, else `"(Intercept)"`, `"x1"`, `"x2"`,
21
+ * ... (aliased coefficients left out).
22
+ */
23
+ names: string[];
24
+ /** R's warnings. */
25
+ warnings: string[];
26
+ }
27
+ /**
28
+ * Types of {@link vcovHC}.
29
+ *
30
+ * @category Linear models and ANOVA
31
+ */
32
+ export type VcovHCType = "const" | "HC" | "HC0" | "HC1" | "HC2" | "HC3" | "HC4" | "HC4m" | "HC5";
33
+ /**
34
+ * Options for {@link vcovHC}.
35
+ *
36
+ * @category Linear models and ANOVA
37
+ */
38
+ export interface VcovHCOptions {
39
+ /**
40
+ * The estimator: `"HC3"` (default), `"const"`, `"HC0"` (alias `"HC"`), `"HC1"`, `"HC2"`, `"HC4"`, `"HC4m"` or
41
+ * `"HC5"`. Unambiguous abbreviations are accepted, as R's `match.arg`.
42
+ */
43
+ type?: VcovHCType;
44
+ /**
45
+ * The weights omega_i of the meat instead of the type's: an array of one value per row of non-zero weight (or one per
46
+ * row used, those of weight 0 then left out), or a function `(res, hat, df) => omega` of the residual factors, the
47
+ * hat values and n - k.
48
+ */
49
+ omega?: readonly number[] | ((res: number[], hat: number[], df: number) => readonly number[]);
50
+ /** Return the sandwich (default `true`) or the meat only (`false`). */
51
+ sandwich?: boolean;
52
+ }
53
+ /**
54
+ * Types of {@link vcovCL}.
55
+ *
56
+ * @category Linear models and ANOVA
57
+ */
58
+ export type VcovCLType = "HC" | "HC0" | "HC1" | "HC2" | "HC3";
59
+ /**
60
+ * A cluster label: a number, a string or a boolean (`null`, `undefined` and NaN are missing, an error).
61
+ *
62
+ * @category Linear models and ANOVA
63
+ */
64
+ export type ClusterLabel = number | string | boolean | null | undefined;
65
+ /**
66
+ * Options for {@link vcovCL}.
67
+ *
68
+ * @category Linear models and ANOVA
69
+ */
70
+ export interface VcovCLOptions {
71
+ /**
72
+ * The clusters: one label per input row of the fit (the rows the fit dropped for a missing value are dropped here
73
+ * too), an array or a typed array, or for multi-way clustering an array of such arrays, one per clustering
74
+ * dimension. Default: every observation its own cluster.
75
+ */
76
+ cluster?: readonly ClusterLabel[] | Float64Array | Int32Array | readonly (readonly ClusterLabel[] | Float64Array | Int32Array)[];
77
+ /** `"HC0"` (alias `"HC"`), `"HC1"`, `"HC2"` or `"HC3"`. Default `"HC1"` for an lm fit and `"HC0"` for a glm fit, as sandwich. */
78
+ type?: VcovCLType;
79
+ /** Multiply each clustering term by G / (G - 1), G its number of clusters. Default `true`. */
80
+ cadjust?: boolean;
81
+ /** Multi-way clustering: use clusters of one observation for the intersection of all dimensions. Default `false`. */
82
+ multi0?: boolean;
83
+ /** Set negative eigenvalues of the result to 0. Default `false`. */
84
+ fix?: boolean;
85
+ /** Return the sandwich (default `true`) or the meat only (`false`). */
86
+ sandwich?: boolean;
87
+ }
88
+ /**
89
+ * A covariance in units of powers of 2: V_ab = mant_ab 2^(exp_a + exp_b). Kept by the matrix returned (whose entries
90
+ * are those values rounded to double, Infinity or 0 where they are not representable), so that coeftest and coefci
91
+ * take the standard errors sqrt(mant_aa) 2^exp_a, which are representable where V is not (responses near 1e±300)
92
+ */
93
+ export interface ScaledVcov {
94
+ mant: number[][];
95
+ exp: number[];
96
+ }
97
+ export declare const scaledVcovs: WeakMap<object, ScaledVcov>;
98
+ /**
99
+ * The standard error of row j of a covariance matrix kept in scaledVcovs: sqrt(mant_jj) 2^exp_j, or undefined if the
100
+ * matrix has no record or was changed since
101
+ */
102
+ export declare function scaledStandardError(V: object, j: number, entry: number): number | undefined;
103
+ export declare function isGlm(fit: RobustFit): fit is GlmResult;
104
+ export declare function checkFit(fit: unknown): asserts fit is RobustFit;
105
+ export declare function coefficientNames(fit: RobustFit): string[];
106
+ /**
107
+ * The model-based covariance of the coefficients that are not aliased (R's vcov(fit) without the NA rows): sigma^2 A
108
+ * for an lm, the dispersion of summary.glm times A for a glm, with A = (X'WX)^-1 from the fit's QR factor. Formed as
109
+ * inv_ab d~ 2^(x - e_a - e_b - shift) with the dispersion d = d~ 2^x (x even), so that the standard errors are
110
+ * representable where sigma^2 or the covariance is not (the same bits as A d wherever that is in range)
111
+ */
112
+ export declare function modelCovariance(fit: RobustFit): {
113
+ vcov: number[][];
114
+ names: string[];
115
+ };
116
+ /**
117
+ * Heteroskedasticity-consistent covariance matrix of the coefficients of an `lm` or `glm` fit. Equivalent to R's
118
+ * `sandwich::vcovHC()`.
119
+ *
120
+ * The sandwich A (X' diag(omega) X) A (Zeileis 2006), A = (X'WX)^-1, with omega_i = res_i^2 (HC0, White 1980), times n
121
+ * / (n - k) (HC1), divided by 1 - h_i (HC2) or (1 - h_i)^2 (HC3, MacKinnon and White 1985), by (1 - h_i)^delta_i
122
+ * (HC4, Cribari-Neto 2004; HC4m, Cribari-Neto and da Silva 2011) or by its square root (HC5, Cribari-Neto et al.
123
+ * 2007), with HC4m's gamma = (1, 1.5) and HC5's k = 0.7 fixed as in sandwich; res_i is w_i e_i for an lm and W_i z_i /
124
+ * phi_s for a glm (working weights and residuals). `"const"` is the model-based covariance of the fit (R's `vcov(fit)`:
125
+ * sigma^2 A, or the dispersion times A for a glm); sandwich's `"const"` equals it only for an unweighted lm.
126
+ *
127
+ * Rows of prior weight 0 are left out (R counts them in n and returns different values); a hat value of 1 gives R's
128
+ * warning, and with HC2 to HC5, whose value is then undefined (R's NaN), an error, as is HC1 with as many
129
+ * observations as coefficients. Aliased coefficients are left out of the matrix. Data far from 1 (weights, responses)
130
+ * are handled in units of powers of 2: entries that are not representable are Infinity or 0, and {@link coeftest}
131
+ * still gives their standard errors, from a record kept with the matrix object returned (a copy of the matrix loses it:
132
+ * pass the result or its original matrix). See docs/differences-from-r.md.
133
+ *
134
+ * @param fit The result of {@link lm} or {@link glm}.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * const fit = lm([1, 2, 3, 4, 5, 6], [1.1, 2.3, 2.8, 4.5, 4.9, 6.4]);
139
+ * vcovHC(fit).vcov; // [[0.043766, -0.01134], [-0.01134, 0.0045125]] (HC3)
140
+ * vcovHC(fit, { type: "HC0" }).names; // ["(Intercept)", "x1"]
141
+ * ```
142
+ *
143
+ * @category Linear models and ANOVA
144
+ */
145
+ export declare function vcovHC(fit: RobustFit, options?: VcovHCOptions): VcovResult;
146
+ /**
147
+ * Clustered covariance matrix of the coefficients of an `lm` or `glm` fit. Equivalent to R's
148
+ * `sandwich::vcovCL()`.
149
+ *
150
+ * The meat sums the estimating functions within each cluster (Zeileis, Köll and Graham 2020), times G / (G - 1) with
151
+ * `cadjust`; HC1 multiplies by (n - 1) / (n - k). Several clustering dimensions are combined by inclusion and exclusion
152
+ * over all their intersections, each term with its own G (Cameron, Gelbach and Miller 2011); `multi0` uses clusters of
153
+ * one observation for the full intersection. HC2 and HC3 adjust each cluster's residuals by (I - H_gg)^-1/2 or
154
+ * (I - H_gg)^-1 in the symmetric form of Bell and McCaffrey (2002) (for HC3 the leave-one-cluster-out jackknife),
155
+ * which is sandwich's for an unweighted lm; sandwich transposes the adjustment for a weighted lm or a glm. A singular
156
+ * block (cluster fixed effects) is an error. `fix` sets negative eigenvalues to 0.
157
+ *
158
+ * The default type is HC1 for an lm and HC0 for a glm, as sandwich. Without `cluster` each observation is its own
159
+ * cluster. G is the number of distinct labels among the rows used (labels are compared as text, numbers with 15
160
+ * significant digits as R's `as.character`: 1 and 1 + 2^-52, or 0.1 + 0.2 and 0.3, are one label); intersections of
161
+ * dimensions are tuples of labels; at least two clusters are needed. Rows of prior weight 0 are left out. HC1 needs
162
+ * more observations than coefficients. Data far from 1 as {@link vcovHC} (the same record of the units, lost by a copy
163
+ * of the matrix); with `fix`, a negative eigenvalue is set to 0 in the units of the largest coefficient's variance, so
164
+ * that coefficients whose scale is about 2^537 or more below it then get variance 0. See docs/differences-from-r.md.
165
+ *
166
+ * @param fit The result of {@link lm} or {@link glm}.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * const fit = lm([1, 2, 3, 4, 5, 6, 7, 8], [1.2, 1.9, 3.2, 3.8, 5.3, 5.9, 7.1, 8.2]);
171
+ * vcovCL(fit, { cluster: ["a", "a", "b", "b", "c", "c", "d", "d"] }).vcov;
172
+ * // [[0.002257, -0.00053463], [-0.00053463, 0.00016363]] (HC1)
173
+ * ```
174
+ *
175
+ * @category Linear models and ANOVA
176
+ */
177
+ export declare function vcovCL(fit: RobustFit, options?: VcovCLOptions): VcovResult;