@numero-uno-jpn/rstats 0.7.0 → 0.9.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 (61) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/README.ja.md +47 -14
  3. package/README.md +49 -15
  4. package/THIRD_PARTY_NOTICES.md +35 -0
  5. package/dist/chunks/chunk-24U4DKRY.js +2 -0
  6. package/dist/chunks/{chunk-J3SNI7KY.js → chunk-5K4PS7IV.js} +2 -2
  7. package/dist/chunks/{chunk-MVG5LUZU.js → chunk-BGVMSDVJ.js} +2 -2
  8. package/dist/chunks/chunk-FC2TLHZC.js +2 -0
  9. package/dist/chunks/{chunk-ZW52Z3GY.js → chunk-H2AP6TCR.js} +1 -1
  10. package/dist/chunks/chunk-IVOBWYLV.js +2 -0
  11. package/dist/chunks/{chunk-UIOAWLAN.js → chunk-JLSTEMSN.js} +1 -1
  12. package/dist/chunks/chunk-LE7TBHNI.js +2 -0
  13. package/dist/chunks/{chunk-ZYA4ISAT.js → chunk-LWUSYIQ4.js} +1 -1
  14. package/dist/chunks/{chunk-AFKYWGKN.js → chunk-MF4VBCHQ.js} +2 -2
  15. package/dist/chunks/{chunk-SXSJXDD3.js → chunk-MSAUU6PY.js} +2 -2
  16. package/dist/chunks/{chunk-XYXHHF5L.js → chunk-TOVTN5Y2.js} +1 -1
  17. package/dist/chunks/{chunk-JCZAB6C5.js → chunk-YC4JWUKG.js} +2 -2
  18. package/dist/chunks/{chunk-QNQJA6KZ.js → chunk-ZRO446BP.js} +2 -2
  19. package/dist/descriptive.js +2 -2
  20. package/dist/distributions/beta.js +21 -5
  21. package/dist/distributions.js +2 -2
  22. package/dist/entries/distributions.d.ts +2 -1
  23. package/dist/entries/distributions.js +2 -1
  24. package/dist/entries/tests.d.ts +4 -0
  25. package/dist/entries/tests.js +4 -0
  26. package/dist/htest/brunnerMunzelTest.d.ts +28 -0
  27. package/dist/htest/brunnerMunzelTest.js +86 -0
  28. package/dist/linalg.js +2 -2
  29. package/dist/models/glm.d.ts +226 -0
  30. package/dist/models/glm.js +546 -0
  31. package/dist/models/glmAnova.d.ts +31 -0
  32. package/dist/models/glmAnova.js +146 -0
  33. package/dist/models/glmConfint.d.ts +25 -0
  34. package/dist/models/glmConfint.js +139 -0
  35. package/dist/models/glmFamily.d.ts +66 -0
  36. package/dist/models/glmFamily.js +359 -0
  37. package/dist/numerics.js +2 -2
  38. package/dist/random/lecuyer.d.ts +20 -0
  39. package/dist/random/lecuyer.js +71 -0
  40. package/dist/random/rng.d.ts +78 -11
  41. package/dist/random/rng.js +128 -26
  42. package/dist/random/sample.js +24 -7
  43. package/dist/random/streams.d.ts +34 -0
  44. package/dist/random/streams.js +75 -0
  45. package/dist/rstats.js +4 -3
  46. package/dist/special/igam.d.ts +1 -0
  47. package/dist/special/igam.js +1 -1
  48. package/dist/special/incbet.js +487 -6
  49. package/dist/special/incbetLargeA.d.ts +15 -0
  50. package/dist/special/incbetLargeA.js +200 -0
  51. package/dist/special/incbetTemme.d.ts +19 -0
  52. package/dist/special/incbetTemme.js +216 -0
  53. package/dist/special/loader.js +151 -118
  54. package/dist/special.js +2 -2
  55. package/dist/tests.js +4 -3
  56. package/package.json +1 -1
  57. package/dist/chunks/chunk-6R7YDHA2.js +0 -2
  58. package/dist/chunks/chunk-ANYGLFT4.js +0 -2
  59. package/dist/chunks/chunk-BI5RSUZ2.js +0 -2
  60. package/dist/chunks/chunk-PTPPP4TI.js +0 -2
  61. package/dist/chunks/chunk-YKN6OGJL.js +0 -2
@@ -0,0 +1,146 @@
1
+ // Analysis of deviance for generalized linear models: R's anova for one glm fit (terms added in order) and for a
2
+ // comparison of several fits, with the chi-squared (likelihood ratio), F, Rao score and Cp columns.
3
+ //
4
+ // Written for rStats.js (no ported code) from oracle/glm-behaviour.md and R's help pages (?anova.glm,
5
+ // ?stat.anova) and McCullagh and Nelder (1989). Each column of x is one term (x1, x2, ...). The score statistic of a
6
+ // smaller model against a larger one is computed from the working residuals and working weights of the smaller
7
+ // model's fit, regressed by weighted least squares on the larger model's matrix.
8
+ import { pf1 } from "../distributions/f.js";
9
+ import { pgamma1 } from "../distributions/gamma.js";
10
+ import { glmDispersion, refit } from "./glm.js";
11
+ import { makeFamily, Warnings } from "./glmFamily.js";
12
+ import { scoreStatistic } from "./glmConfint.js";
13
+ /** Upper tail of chi-squared with df degrees of freedom */
14
+ const pchisqUpper = (q, df) => pgamma1(q, df / 2, 2, false, false);
15
+ /** The working residuals and weights of the fit of the model with the given columns */
16
+ function rowOf(model, cols, warnings) {
17
+ const { fit, w } = refit(model, cols, warnings);
18
+ const nOk = w.filter((v) => v > 0).length;
19
+ return { dfRes: nOk - fit.rank, dev: fit.deviance, fit, x: model.x.map((r) => cols.map((j) => r[j])), intercept: model.intercept };
20
+ }
21
+ /** Score statistic of the smaller model's fit against the larger model's matrix */
22
+ const rao = (small, large) => scoreStatistic(large.x, small.fit.workingResiduals, small.fit.workingWeights, large.intercept);
23
+ /**
24
+ * Analysis of deviance. Equivalent to R's `anova()` for one `glm` fit (the sequential table, each column of `x`
25
+ * added in order) or for several fits of the same data (`anova(fit1, fit2, ...)`).
26
+ *
27
+ * @param fits One fit, or an array of fits to compare.
28
+ */
29
+ export function glmAnova(fits, options = {}) {
30
+ const list = Array.isArray(fits) ? fits : [fits];
31
+ if (list.length === 0)
32
+ throw new RangeError("no fits to compare");
33
+ const warnings = new Warnings();
34
+ const compare = Array.isArray(fits) && list.length > 1;
35
+ const first = list[0];
36
+ const fam = makeFamily(first.model.familySpec);
37
+ const fixed = fam.fixedDispersion;
38
+ const test = options.test === undefined ? (options.dispersion !== undefined || fixed ? "Chisq" : "F") : options.test;
39
+ const rows = [];
40
+ let df;
41
+ let devDiff;
42
+ let score = [];
43
+ let ref;
44
+ if (!compare) {
45
+ const fit = first;
46
+ const model = fit.model;
47
+ const nTerms = model.x.length > 0 ? model.x[0].length - (model.intercept ? 1 : 0) : 0;
48
+ const base = model.intercept ? [0] : [];
49
+ const colsOf = (k) => [...base, ...Array.from({ length: k }, (_, j) => j + base.length)];
50
+ const fitRows = [];
51
+ // the refits with the first k terms; the last is the fit itself
52
+ for (let k = 0; k <= nTerms; k++) {
53
+ if (k === nTerms) {
54
+ fitRows.push({ dfRes: fit.dfResidual, dev: fit.deviance, fit: asIrls(fit), x: model.x, intercept: model.intercept });
55
+ }
56
+ else if (k > 0 || test === "Rao")
57
+ fitRows.push(rowOf(model, colsOf(k), warnings));
58
+ else
59
+ fitRows.push(undefined);
60
+ }
61
+ rows.push({ name: "NULL", dfRes: fit.dfNull, dev: fit.nullDeviance });
62
+ for (let k = 1; k <= nTerms; k++)
63
+ rows.push({ name: `x${k}`, dfRes: fitRows[k].dfRes, dev: fitRows[k].dev });
64
+ df = rows.map((r, i) => (i === 0 ? NaN : rows[i - 1].dfRes - r.dfRes));
65
+ devDiff = rows.map((r, i) => (i === 0 ? NaN : Math.max(rows[i - 1].dev - r.dev, 0)));
66
+ if (test === "Rao")
67
+ score = rows.map((_, i) => (i === 0 ? NaN : rao(fitRows[i - 1], fitRows[i])));
68
+ ref = fit;
69
+ }
70
+ else {
71
+ const n = list[0].model.x.length;
72
+ if (list.some((f) => f.model.x.length !== n))
73
+ throw new RangeError("models were not all fitted to the same size of dataset");
74
+ list.forEach((f, i) => rows.push({ name: String(i + 1), dfRes: f.dfResidual, dev: f.deviance }));
75
+ df = rows.map((r, i) => (i === 0 ? NaN : rows[i - 1].dfRes - r.dfRes));
76
+ devDiff = rows.map((r, i) => (i === 0 ? NaN : rows[i - 1].dev - r.dev));
77
+ if (test === "Rao") {
78
+ const fr = list.map((f) => ({ dfRes: f.dfResidual, dev: f.deviance, fit: asIrls(f), x: f.model.x, intercept: f.model.intercept }));
79
+ score = rows.map((_, i) => {
80
+ if (i === 0)
81
+ return NaN;
82
+ // the smaller model is the one with more residual degrees of freedom
83
+ return df[i] < 0 ? -rao(fr[i], fr[i - 1]) : rao(fr[i - 1], fr[i]);
84
+ });
85
+ }
86
+ ref = list.reduce((a, b) => (b.dfResidual < a.dfResidual ? b : a));
87
+ }
88
+ const summaryWarnings = new Warnings();
89
+ const dispersion = options.dispersion ?? glmDispersion(ref, summaryWarnings);
90
+ summaryWarnings.list.forEach((m) => warnings.add(m));
91
+ const dfDispersion = fixed ? Infinity : ref.dfResidual;
92
+ const head = compare ? ["Resid. Df", "Resid. Dev", "Df", "Deviance"] : ["Df", "Deviance", "Resid. Df", "Resid. Dev"];
93
+ const cells = rows.map((r, i) => (compare ? [r.dfRes, r.dev, df[i], devDiff[i]] : [df[i], devDiff[i], r.dfRes, r.dev]));
94
+ const colNames = [...head];
95
+ const chisqP = (stat) => rows.map((_, i) => {
96
+ if (i === 0 || df[i] === 0)
97
+ return NaN;
98
+ const v = (stat[i] / dispersion) * Math.sign(df[i]);
99
+ return v < 0 || Number.isNaN(v) ? NaN : pchisqUpper(v, Math.abs(df[i]));
100
+ });
101
+ let extra = [];
102
+ if (test === "Chisq" || test === "LRT") {
103
+ colNames.push("Pr(>Chi)");
104
+ extra = [chisqP(devDiff)];
105
+ }
106
+ else if (test === "Rao") {
107
+ colNames.push("Rao", "Pr(>Chi)");
108
+ extra = [score, chisqP(score)];
109
+ }
110
+ else if (test === "F") {
111
+ if (fixed)
112
+ warnings.add(`using F test with a '${fam.family}' family is inappropriate`);
113
+ if (dfDispersion !== 0) {
114
+ const F = rows.map((_, i) => {
115
+ const v = devDiff[i] / df[i] / dispersion;
116
+ return i === 0 || df[i] === 0 || v < 0 ? NaN : v;
117
+ });
118
+ colNames.push("F", "Pr(>F)");
119
+ extra = [F, F.map((v, i) => (Number.isNaN(v) ? NaN : pf1(v, Math.abs(df[i]), dfDispersion, false, false)))];
120
+ }
121
+ }
122
+ else if (test === "Cp") {
123
+ const n = ref.model.x.length;
124
+ colNames.push("Cp");
125
+ extra = [rows.map((r) => r.dev + 2 * dispersion * (n - r.dfRes))];
126
+ }
127
+ const table = cells.map((r, i) => [...r, ...extra.map((col) => col[i])]);
128
+ return { colNames, rowNames: rows.map((r) => r.name), table, warnings: warnings.list };
129
+ }
130
+ /** The parts of a fit that the score statistic uses */
131
+ function asIrls(fit) {
132
+ return {
133
+ coefficients: fit.coefficients,
134
+ eta: fit.linearPredictors,
135
+ mu: fit.fittedValues,
136
+ deviance: fit.deviance,
137
+ iter: fit.iter,
138
+ converged: fit.converged,
139
+ boundary: fit.boundary,
140
+ rank: fit.rank,
141
+ qr: fit.qr,
142
+ used: fit.weights.map((v) => v > 0),
143
+ workingWeights: fit.weights,
144
+ workingResiduals: fit.residuals,
145
+ };
146
+ }
@@ -0,0 +1,25 @@
1
+ import { type GlmResult } from "./glm.js";
2
+ /** Options for {@link glmConfint}. */
3
+ export interface GlmConfintOptions {
4
+ /** Indices of the coefficients (0-based, intercept first). Default: all. */
5
+ parm?: readonly number[];
6
+ /** Confidence level. Default `0.95`. */
7
+ level?: number;
8
+ /** `"LRT"` (default; the likelihood ratio) or `"Rao"` (the score statistic). */
9
+ test?: "LRT" | "Rao";
10
+ }
11
+ /**
12
+ * Score statistic of residuals r with weights v regressed on the columns of x (rows of weight 0 left out): the
13
+ * weighted sum of squares of r about its weighted mean (about 0 without intercept) minus the residual sum of squares.
14
+ */
15
+ export declare function scoreStatistic(x: number[][], r: number[], v: number[], intercept: boolean, tol?: number): number;
16
+ /**
17
+ * Profile likelihood confidence intervals for the coefficients of a generalized linear model (NaN for aliased
18
+ * columns, and for a limit that the profile does not reach). Equivalent to R's `confint()` for a `glm` fit, but with
19
+ * the exact solutions of the profile equations, where R interpolates a spline through a grid of profile points (and
20
+ * is up to about 5e-4 standard errors from them).
21
+ */
22
+ export declare function glmConfint(fit: GlmResult, options?: GlmConfintOptions): {
23
+ lower: number[];
24
+ upper: number[];
25
+ };
@@ -0,0 +1,139 @@
1
+ // Profile likelihood confidence intervals for the coefficients of a glm (R's confint for a glm fit, MASS's method
2
+ // before R 4.4), with the exact limits instead of R's spline interpolation of the profile.
3
+ //
4
+ // Written for rStats.js (no ported code) from oracle/glm-behaviour.md and R's help pages (?confint, ?profile.glm).
5
+ // The signed root of the likelihood ratio statistic (McCullagh and Nelder 1989) of coefficient j is
6
+ // z(b) = sign(b - b_j) sqrt((D(b) - D) / phi),
7
+ // with D(b) the deviance of the fit with b_j fixed at b (its column moved into the offset), D the deviance of the fit and
8
+ // phi its dispersion; for the score test (test = "Rao") D(b) - D is replaced by the score statistic of the restricted
9
+ // fit. The limits solve z(b) = qnorm((1 -/+ level) / 2) by Brent's method on a bracket found by doubling the distance
10
+ // from the estimate (up to 2^30 standard errors). All fits are iterated until the coefficients stop changing (to
11
+ // rounding, at most 100 iterations): the deviance is stationary at the estimate, so R's rule on its relative change
12
+ // stops while the coefficients, the dispersion and the score statistic can still move by about sqrt(epsilon).
13
+ import { qnorm } from "../distributions/normal.js";
14
+ import { uniroot } from "../internal/uniroot.js";
15
+ import { qr, qrResid } from "../linalg/qr.js";
16
+ import { glmSummary, refit } from "./glm.js";
17
+ import { Warnings } from "./glmFamily.js";
18
+ /**
19
+ * Settings of the fits iterated to convergence: until the coefficients stop changing (at most 100 iterations), and
20
+ * the tolerance of the QR decomposition that of epsilon = 1e-300 (columns found aliased by the fit are left out)
21
+ */
22
+ const CONVERGED = { epsilon: 1e-300, maxit: 100, untilCoefficients: true };
23
+ /**
24
+ * Score statistic of residuals r with weights v regressed on the columns of x (rows of weight 0 left out): the
25
+ * weighted sum of squares of r about its weighted mean (about 0 without intercept) minus the residual sum of squares.
26
+ */
27
+ export function scoreStatistic(x, r, v, intercept, tol = 1e-11) {
28
+ const rows = [];
29
+ for (let i = 0; i < r.length; i++)
30
+ if (v[i] > 0)
31
+ rows.push(i);
32
+ let sw = 0;
33
+ let swr = 0;
34
+ for (const i of rows) {
35
+ sw += v[i];
36
+ swr += v[i] * r[i];
37
+ }
38
+ const centre = intercept ? swr / sw : 0;
39
+ let total = 0;
40
+ for (const i of rows)
41
+ total += v[i] * (r[i] - centre) ** 2;
42
+ const p = x.length > 0 ? x[0].length : 0;
43
+ if (p === 0 || rows.length === 0)
44
+ return 0;
45
+ const s = rows.map((i) => Math.sqrt(v[i]));
46
+ const q = qr(rows.map((i, k) => x[i].map((t) => t * s[k])), { tol });
47
+ const res = qrResid(q, rows.map((i, k) => r[i] * s[k]));
48
+ let rss = 0;
49
+ for (const e of res)
50
+ rss += e * e;
51
+ return total - rss;
52
+ }
53
+ /**
54
+ * Profile likelihood confidence intervals for the coefficients of a generalized linear model (NaN for aliased
55
+ * columns, and for a limit that the profile does not reach). Equivalent to R's `confint()` for a `glm` fit, but with
56
+ * the exact solutions of the profile equations, where R interpolates a spline through a grid of profile points (and
57
+ * is up to about 5e-4 standard errors from them).
58
+ */
59
+ export function glmConfint(fit, options = {}) {
60
+ const level = options.level ?? 0.95;
61
+ const test = options.test ?? "LRT";
62
+ if (!(level > 0 && level < 1))
63
+ throw new RangeError("'level' must be in (0, 1)");
64
+ const p = fit.coefficients.length;
65
+ const parm = options.parm ?? Array.from({ length: p }, (_, j) => j);
66
+ for (const j of parm)
67
+ if (!Number.isInteger(j) || j < 0 || j >= p)
68
+ throw new RangeError(`invalid coefficient index ${j}`);
69
+ const model = fit.model;
70
+ const cols = fit.coefficients.map((_, j) => j).filter((j) => !Number.isNaN(fit.coefficients[j]));
71
+ const warnings = new Warnings();
72
+ // the fit iterated until it has converged (columns found aliased left out)
73
+ const full = refit(model, cols, warnings, {
74
+ ...CONVERGED,
75
+ start: model.start === undefined ? undefined : cols.map((j) => model.start[j]),
76
+ });
77
+ const B = new Array(p).fill(NaN);
78
+ cols.forEach((j, k) => (B[j] = full.fit.coefficients[k]));
79
+ const convergedFit = {
80
+ ...fit,
81
+ coefficients: B,
82
+ weights: full.fit.workingWeights,
83
+ residuals: full.fit.workingResiduals,
84
+ qr: full.fit.qr,
85
+ rank: full.fit.rank,
86
+ };
87
+ const summary = glmSummary(convergedFit);
88
+ const dispersion = summary.dispersion;
89
+ const se = new Array(p).fill(NaN);
90
+ const piv = full.fit.qr === undefined ? [] : full.fit.qr.pivot.slice(0, full.fit.rank);
91
+ piv.forEach((k, m) => (se[cols[k]] = summary.stdError[m]));
92
+ const xFull = model.x.map((r) => cols.map((j) => r[j]));
93
+ const eta0 = full.fit.eta;
94
+ const zStat = (j, b) => {
95
+ const others = cols.filter((c) => c !== j);
96
+ const restricted = refit(model, others, new Warnings(), {
97
+ ...CONVERGED,
98
+ start: undefined,
99
+ etastart: eta0,
100
+ extraOffset: model.x.map((r) => r[j] * b),
101
+ }).fit;
102
+ const stat = test === "LRT"
103
+ ? restricted.deviance - full.fit.deviance
104
+ : scoreStatistic(xFull, restricted.workingResiduals, restricted.workingWeights, false);
105
+ return Math.sign(b - B[j]) * Math.sqrt(Math.max(stat / dispersion, 0));
106
+ };
107
+ const cut = [qnorm((1 - level) / 2), qnorm((1 + level) / 2)];
108
+ const lower = parm.map(() => NaN);
109
+ const upper = parm.map(() => NaN);
110
+ parm.forEach((j, k) => {
111
+ if (Number.isNaN(B[j]))
112
+ return;
113
+ for (const side of [0, 1]) {
114
+ const dir = side === 0 ? -1 : 1;
115
+ let far = NaN;
116
+ let zFar = NaN;
117
+ for (let e = 0; e <= 30; e++) {
118
+ const b = B[j] + dir * 2 ** e * se[j];
119
+ const z = zStat(j, b);
120
+ if (Math.abs(z) >= Math.abs(cut[side])) {
121
+ far = b;
122
+ zFar = z;
123
+ break;
124
+ }
125
+ }
126
+ if (Number.isNaN(far))
127
+ continue;
128
+ const f = (b) => (b === B[j] ? -cut[side] : zStat(j, b) - cut[side]);
129
+ const [lo, hi] = side === 0 ? [far, B[j]] : [B[j], far];
130
+ const [fLo, fHi] = side === 0 ? [zFar - cut[side], -cut[side]] : [-cut[side], zFar - cut[side]];
131
+ const root = uniroot(f, lo, hi, { tol: 1e-14 * se[j], maxIter: 500, fLower: fLo, fUpper: fHi });
132
+ if (side === 0)
133
+ lower[k] = root;
134
+ else
135
+ upper[k] = root;
136
+ }
137
+ });
138
+ return { lower, upper };
139
+ }
@@ -0,0 +1,66 @@
1
+ /** Names of the families of R's stats. */
2
+ export type GlmFamilyName = "gaussian" | "binomial" | "quasibinomial" | "poisson" | "quasipoisson" | "Gamma" | "inverse.gaussian" | "quasi";
3
+ /** Names of the links of R's stats (`make.link`). */
4
+ export type GlmLinkName = "identity" | "log" | "inverse" | "logit" | "probit" | "cauchit" | "cloglog" | "sqrt" | "1/mu^2";
5
+ /** A link: one of R's named links or a power link `mu^power` (R's `power(lambda)`; `power <= 0` is the log link). */
6
+ export type GlmLink = GlmLinkName | {
7
+ power: number;
8
+ };
9
+ /** Variance functions of the `quasi` family. */
10
+ export type QuasiVariance = "constant" | "mu(1-mu)" | "mu" | "mu^2" | "mu^3";
11
+ /** A family with its link (and, for `quasi`, its variance function), as R's family objects such as `quasi(link = "log", variance = "mu^2")`. */
12
+ export interface GlmFamilySpec {
13
+ family: GlmFamilyName;
14
+ /** The link. Default: the family's default (the first of its allowed links). */
15
+ link?: GlmLink;
16
+ /** Variance function of `quasi`. Default `"constant"`. */
17
+ variance?: QuasiVariance;
18
+ }
19
+ /** A link resolved to its functions. */
20
+ export interface LinkFunctions {
21
+ name: string;
22
+ /** eta = g(mu) */
23
+ link(mu: number): number;
24
+ /** mu = g^-1(eta) */
25
+ linkinv(eta: number): number;
26
+ /** d mu / d eta */
27
+ muEta(eta: number): number;
28
+ /** Whether a linear predictor is in the domain of the inverse link */
29
+ etaOk(eta: number): boolean;
30
+ }
31
+ /** A family resolved to its functions (the counterpart of R's family object). */
32
+ export interface Family extends LinkFunctions {
33
+ family: GlmFamilyName;
34
+ /** For quasi: the variance function's name */
35
+ varianceName: QuasiVariance | undefined;
36
+ variance(mu: number): number;
37
+ muOk(mu: number): boolean;
38
+ /** Deviance contribution of one observation with prior weight w */
39
+ devContribution(y: number, mu: number, w: number): number;
40
+ /** Whether the dispersion is fixed at 1 (binomial and poisson) */
41
+ fixedDispersion: boolean;
42
+ }
43
+ /** Collects warnings in order of first appearance, each once (as the fixtures list R's warnings) */
44
+ export declare class Warnings {
45
+ readonly list: string[];
46
+ add(message: string): void;
47
+ }
48
+ export declare function withWarnings<T>(sink: Warnings, f: () => T): T;
49
+ /** Resolves a family name or specification (and a link given separately) to its functions */
50
+ export declare function makeFamily(family: GlmFamilyName | GlmFamilySpec, link?: GlmLink): Family;
51
+ /** The response after the family has read it, with the prior weights, the starting means and the binomial sizes */
52
+ export interface PreparedResponse {
53
+ y: number[];
54
+ weights: number[];
55
+ mustart: number[];
56
+ /** Binomial sizes (s + f for a two-column response, 1 otherwise); undefined for the other families */
57
+ size: number[] | undefined;
58
+ }
59
+ /**
60
+ * Checks the response and computes the starting means (R's family initialize). `y` is a vector or, for the binomial
61
+ * families, rows (successes, failures). `hasStart`: starting values were given, so the gaussian check of the
62
+ * starting means is skipped.
63
+ */
64
+ export declare function prepareResponse(fam: Family, y: number[] | number[][], prior: number[], hasStart: boolean, warnings: Warnings): PreparedResponse;
65
+ /** The family's AIC before the 2 rank term (R's family$aic); NaN for the quasi families */
66
+ export declare function familyAic(fam: Family, y: number[], mu: number[], w: number[], size: number[] | undefined, dev: number, warnings: Warnings): number;