@numero-uno-jpn/rstats 0.16.0 → 1.0.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 +205 -0
- package/README.ja.md +57 -23
- package/README.md +60 -23
- package/dist/chunks/{chunk-5UQCRBAG.js → chunk-3W5NFFAA.js} +1 -1
- package/dist/chunks/chunk-4F2IALD4.js +3 -0
- package/dist/chunks/{chunk-QNNL7AZ3.js → chunk-4OLDGML4.js} +2 -2
- package/dist/chunks/chunk-63OPBEYO.js +2 -0
- package/dist/chunks/chunk-6XJBCRBV.js +2 -0
- package/dist/chunks/chunk-BQSIBJVX.js +2 -0
- package/dist/chunks/chunk-BWKHYRM6.js +3 -0
- package/dist/chunks/{chunk-W26LRYOJ.js → chunk-CKV4JWW2.js} +1 -1
- package/dist/chunks/chunk-DCAWMF4K.js +2 -0
- package/dist/chunks/chunk-F7YGX7PN.js +2 -0
- package/dist/chunks/chunk-H7I32ZZE.js +2 -0
- package/dist/chunks/chunk-IEOD5GWC.js +3 -0
- package/dist/chunks/chunk-KICBQGFN.js +2 -0
- package/dist/chunks/chunk-LROMWFAK.js +2 -0
- package/dist/chunks/chunk-NSWENS3S.js +2 -0
- package/dist/chunks/chunk-O2SQMGE3.js +2 -0
- package/dist/chunks/chunk-QQX46TCI.js +2 -0
- package/dist/chunks/chunk-QZK3CCBA.js +2 -0
- package/dist/chunks/chunk-UJ66VQIG.js +2 -0
- package/dist/chunks/chunk-UKNDX4BA.js +2 -0
- package/dist/chunks/chunk-WIBKS73G.js +2 -0
- package/dist/chunks/{chunk-URIO5LY5.js → chunk-WQWZ7FND.js} +2 -2
- package/dist/chunks/chunk-WWVMVZUL.js +2 -0
- package/dist/chunks/chunk-YG5S5AVP.js +2 -0
- package/dist/chunks/chunk-YHNMBYSW.js +2 -0
- package/dist/data/grouping.js +6 -2
- package/dist/descriptive/basic.js +20 -0
- package/dist/descriptive/cov.js +11 -0
- package/dist/descriptive/dataFrames.js +13 -5
- package/dist/descriptive/factanal.d.ts +2 -0
- package/dist/descriptive/factanal.js +10 -2
- package/dist/descriptive/hist.js +6 -0
- package/dist/descriptive/moments.js +14 -0
- package/dist/descriptive/omega.js +8 -3
- package/dist/descriptive/pivot.d.ts +4 -1
- package/dist/descriptive/pivot.js +27 -13
- package/dist/descriptive/quantile.js +8 -0
- package/dist/descriptive/rank.js +4 -0
- package/dist/descriptive/table.d.ts +20 -1
- package/dist/descriptive/table.js +14 -14
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.js +8 -0
- package/dist/distributions/beta.js +9 -0
- package/dist/distributions/binomial.js +9 -0
- package/dist/distributions/cauchy.js +9 -0
- package/dist/distributions/chisq.js +9 -0
- package/dist/distributions/exponential.js +9 -0
- package/dist/distributions/f.js +9 -0
- package/dist/distributions/gamma.js +8 -0
- package/dist/distributions/geometric.js +9 -0
- package/dist/distributions/hypergeometric.js +8 -0
- package/dist/distributions/invgamma.js +8 -0
- package/dist/distributions/kumaraswamy.js +9 -0
- package/dist/distributions/laplace.js +9 -0
- package/dist/distributions/logistic.js +9 -0
- package/dist/distributions/lognormal.js +8 -0
- package/dist/distributions/multinomial.js +4 -0
- package/dist/distributions/negbinomial.js +8 -0
- package/dist/distributions/normal.js +8 -0
- package/dist/distributions/pareto.js +8 -0
- package/dist/distributions/poisson.js +9 -0
- package/dist/distributions/signrank.js +9 -0
- package/dist/distributions/summary.d.ts +2 -1
- package/dist/distributions/summary.js +31 -1
- package/dist/distributions/t.js +9 -0
- package/dist/distributions/triangular.js +9 -0
- package/dist/distributions/tukey.js +6 -0
- package/dist/distributions/uniform.js +8 -0
- package/dist/distributions/weibull.js +8 -0
- package/dist/distributions/wilcox.js +9 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +3 -1
- package/dist/entries/descriptive.js +1 -1
- package/dist/entries/distributions.d.ts +1 -0
- package/dist/entries/distributions.js +2 -0
- package/dist/entries/linalg.d.ts +3 -1
- package/dist/entries/mixed.d.ts +9 -0
- package/dist/entries/mixed.js +8 -1
- package/dist/entries/numerics.d.ts +2 -1
- package/dist/entries/tests.d.ts +8 -5
- package/dist/entries/tests.js +3 -1
- package/dist/htest/agreement.d.ts +13 -0
- package/dist/htest/agreement.js +46 -7
- package/dist/htest/ansariTest.d.ts +2 -1
- package/dist/htest/ansariTest.js +43 -12
- package/dist/htest/aov.d.ts +28 -22
- package/dist/htest/aov.js +42 -13
- package/dist/htest/binomTest.js +6 -0
- package/dist/htest/brunnerMunzelTest.js +5 -0
- package/dist/htest/chisqTest.d.ts +3 -1
- package/dist/htest/chisqTest.js +21 -3
- package/dist/htest/cor.d.ts +7 -1
- package/dist/htest/cor.js +40 -7
- package/dist/htest/core/simulate.d.ts +6 -0
- package/dist/htest/core/simulate.js +20 -0
- package/dist/htest/effectSize.d.ts +3 -0
- package/dist/htest/effectSize.js +28 -8
- package/dist/htest/fisherTest.d.ts +2 -1
- package/dist/htest/fisherTest.js +52 -6
- package/dist/htest/ksTest.d.ts +4 -0
- package/dist/htest/ksTest.js +13 -4
- package/dist/htest/leveneTest.d.ts +2 -0
- package/dist/htest/leveneTest.js +9 -3
- package/dist/htest/mantelhaenTest.js +7 -0
- package/dist/htest/mcnemarTest.js +8 -0
- package/dist/htest/multipleComparisons.d.ts +16 -25
- package/dist/htest/multipleComparisons.js +26 -43
- package/dist/htest/normalityTests.js +10 -4
- package/dist/htest/onewayTest.js +10 -0
- package/dist/htest/pAdjust.js +4 -0
- package/dist/htest/pairwise.d.ts +2 -0
- package/dist/htest/pairwise.js +29 -6
- package/dist/htest/poissonTest.js +6 -0
- package/dist/htest/polycor.js +20 -10
- package/dist/htest/power.d.ts +4 -0
- package/dist/htest/power.js +16 -2
- package/dist/htest/propTest.d.ts +3 -0
- package/dist/htest/propTest.js +23 -2
- package/dist/htest/pwr.d.ts +38 -1
- package/dist/htest/pwr.js +38 -15
- package/dist/htest/rankTests.js +7 -1
- package/dist/htest/tTest.d.ts +2 -0
- package/dist/htest/tTest.js +9 -0
- package/dist/htest/testFormula.js +11 -11
- package/dist/htest/trendTests.d.ts +21 -1
- package/dist/htest/trendTests.js +13 -18
- package/dist/htest/types.d.ts +2 -0
- package/dist/htest/varTest.js +7 -0
- package/dist/htest/wilcoxTest.js +51 -9
- package/dist/internal/checkOptions.d.ts +11 -0
- package/dist/internal/checkOptions.js +31 -0
- package/dist/internal/optionalArgs.d.ts +12 -0
- package/dist/internal/optionalArgs.js +46 -0
- package/dist/internal/warnings.d.ts +66 -0
- package/dist/internal/warnings.js +122 -0
- package/dist/linalg/basic.js +7 -0
- package/dist/linalg/chol.js +6 -0
- package/dist/linalg/eigen.js +4 -0
- package/dist/linalg/expm.js +4 -0
- package/dist/linalg/kappa.js +6 -0
- package/dist/linalg/lu.js +5 -0
- package/dist/linalg/norm.js +4 -0
- package/dist/linalg/ops.d.ts +27 -2
- package/dist/linalg/ops.js +14 -13
- package/dist/linalg/qr.js +14 -0
- package/dist/linalg/solve.js +9 -0
- package/dist/linalg/svd.js +6 -2
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +5 -4
- package/dist/models/anovaSequential.d.ts +16 -1
- package/dist/models/anovaSequential.js +50 -7
- package/dist/models/aovEz.js +16 -11
- package/dist/models/aovStrata.js +15 -4
- package/dist/models/carAnova.js +11 -17
- package/dist/models/coxph.d.ts +6 -0
- package/dist/models/coxph.js +21 -6
- package/dist/models/formula.d.ts +5 -2
- package/dist/models/formula.js +31 -8
- package/dist/models/glm.d.ts +22 -2
- package/dist/models/glm.js +32 -22
- package/dist/models/glmAnova.js +8 -3
- package/dist/models/glmConfint.js +6 -2
- package/dist/models/glmFamily.d.ts +1 -6
- package/dist/models/glmFamily.js +3 -22
- package/dist/models/glmer.d.ts +255 -0
- package/dist/models/glmer.js +635 -0
- package/dist/models/glmerAnova.d.ts +81 -0
- package/dist/models/glmerAnova.js +139 -0
- package/dist/models/glmerDeviance.d.ts +98 -0
- package/dist/models/glmerDeviance.js +576 -0
- package/dist/models/glmerFamily.d.ts +57 -0
- package/dist/models/glmerFamily.js +236 -0
- package/dist/models/glmerGradient.d.ts +46 -0
- package/dist/models/glmerGradient.js +301 -0
- package/dist/models/glmerStructure.d.ts +45 -0
- package/dist/models/glmerStructure.js +168 -0
- package/dist/models/glmerSummary.d.ts +102 -0
- package/dist/models/glmerSummary.js +94 -0
- package/dist/models/lm.js +13 -3
- package/dist/models/lmer.d.ts +27 -6
- package/dist/models/lmer.js +75 -321
- package/dist/models/lmerAnova.d.ts +52 -3
- package/dist/models/lmerAnova.js +101 -45
- package/dist/models/lmerTest.d.ts +12 -5
- package/dist/models/lmerTest.js +39 -18
- package/dist/models/mauchly.d.ts +2 -0
- package/dist/models/mauchly.js +7 -2
- package/dist/models/mixedDeviance.d.ts +28 -2
- package/dist/models/mixedDeviance.js +84 -56
- package/dist/models/mixedMinimiser.d.ts +83 -0
- package/dist/models/mixedMinimiser.js +438 -0
- package/dist/models/mixedPredict.d.ts +121 -0
- package/dist/models/mixedPredict.js +530 -0
- package/dist/models/mixedStructure.d.ts +62 -3
- package/dist/models/mixedStructure.js +74 -29
- package/dist/models/modelFrame.js +2 -2
- package/dist/models/modelMatrix.d.ts +8 -1
- package/dist/models/modelMatrix.js +56 -39
- package/dist/models/survival.d.ts +6 -0
- package/dist/models/survival.js +9 -2
- package/dist/numerics/deriv.js +8 -0
- package/dist/numerics/integrate.js +8 -0
- package/dist/numerics/interp.d.ts +32 -7
- package/dist/numerics/interp.js +27 -9
- package/dist/numerics/ode.js +4 -0
- package/dist/numerics.js +2 -2
- package/dist/optim/optim.js +17 -2
- package/dist/random/beta.js +5 -0
- package/dist/random/continuous.js +17 -0
- package/dist/random/extra.js +13 -0
- package/dist/random/gamma.js +11 -0
- package/dist/random/poisson.js +5 -0
- package/dist/random/rng.js +4 -0
- package/dist/random/sample.js +6 -0
- package/dist/rstats.js +17 -14
- package/dist/special/besselIK.js +7 -0
- package/dist/special/choose.js +7 -0
- package/dist/special/psigamma.js +7 -0
- package/dist/special.js +2 -2
- package/dist/tests.js +14 -11
- package/llms.txt +15 -4
- package/package.json +19 -10
- package/dist/chunks/chunk-2D2IQWUQ.js +0 -2
- package/dist/chunks/chunk-6CSTWA5E.js +0 -2
- package/dist/chunks/chunk-72Y3HZID.js +0 -2
- package/dist/chunks/chunk-BG2KLEHM.js +0 -2
- package/dist/chunks/chunk-CMEKBNHQ.js +0 -2
- package/dist/chunks/chunk-FLJNSXSW.js +0 -2
- package/dist/chunks/chunk-GM53LWSR.js +0 -2
- package/dist/chunks/chunk-JBCA56ZS.js +0 -3
- package/dist/chunks/chunk-K3RJAD2T.js +0 -2
- package/dist/chunks/chunk-KAZRWIB5.js +0 -2
- package/dist/chunks/chunk-KBVVIMXX.js +0 -3
- package/dist/chunks/chunk-N3SIFCZX.js +0 -2
- package/dist/chunks/chunk-SC6CV4Z3.js +0 -2
- package/dist/chunks/chunk-SYWOBOTR.js +0 -2
- package/dist/chunks/chunk-VTUGG2SV.js +0 -2
- package/dist/chunks/chunk-XHETEYVC.js +0 -2
- package/dist/chunks/chunk-YRZWONZB.js +0 -3
- package/dist/chunks/chunk-ZGABZMWX.js +0 -2
package/dist/models/lmerAnova.js
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
// matrices come from src/models/lmerHypotheses.ts, the F-tests from src/models/lmerTest.ts; the comparison refits REML
|
|
7
7
|
// fits by maximum likelihood with lmer's own minimiser (the exact ML optimum).
|
|
8
8
|
import { pgamma1 } from "../distributions/gamma.js";
|
|
9
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
9
10
|
import { nestedColumns } from "./estimable.js";
|
|
10
|
-
import { Warnings } from "
|
|
11
|
-
import {
|
|
11
|
+
import { reported, Warnings } from "../internal/warnings.js";
|
|
12
|
+
import { checkLmerOptions, lmerInternals, lmerWithCriterion, logicalOption } from "./lmer.js";
|
|
12
13
|
import { fixedEffectsDescription, lmerHypotheses } from "./lmerHypotheses.js";
|
|
13
14
|
import { fTestOf, lmerSatterthwaite } from "./lmerTest.js";
|
|
14
15
|
const TYPES = { I: "I", II: "II", III: "III", 1: "I", 2: "II", 3: "III" };
|
|
@@ -83,32 +84,74 @@ function sameFrame(a, b) {
|
|
|
83
84
|
return v !== undefined && u.length === v.length && Array.prototype.every.call(u, (x, i) => Object.is(x, v[i]));
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
87
|
+
/** The model of an lmer fit in a comparison (internal) */
|
|
88
|
+
export function comparedLmer(fit) {
|
|
89
|
+
const internals = lmerInternals(fit);
|
|
90
|
+
const { snapshot, data } = internals;
|
|
91
|
+
const lhs = fit.formula.slice(0, fit.formula.indexOf("~"));
|
|
92
|
+
const ones = () => new Array(fit.nObs).fill(1);
|
|
93
|
+
return {
|
|
94
|
+
nObs: fit.nObs,
|
|
95
|
+
df: fit.df,
|
|
96
|
+
logLik: fit.logLik,
|
|
97
|
+
reml: fit.REML,
|
|
98
|
+
refitLogLik: () => lmerWithCriterion(fit.formula, snapshot, { ...internals.options, REML: false }, internals.criterion).logLik,
|
|
99
|
+
mixed: { data, snapshot, rows: fit.rows, response: lhs.replace(/\s+/g, "") },
|
|
100
|
+
// (the left-hand side of lmer's formula is a column name)
|
|
101
|
+
response: () => fit.rows.map((i) => Number(snapshot[lhs.trim()]?.[i] ?? NaN)),
|
|
102
|
+
weights: ones,
|
|
103
|
+
family: "gaussian",
|
|
104
|
+
link: "identity",
|
|
105
|
+
offset: () => new Array(fit.nObs).fill(0),
|
|
106
|
+
x: () => internals.structure.x,
|
|
107
|
+
randomTerms: fit.varCorr,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Whether two vectors are equal element by element */
|
|
111
|
+
function sameValues(a, b) {
|
|
112
|
+
return a.length === b.length && a.every((v, i) => v === b[i] || (Number.isNaN(v) && Number.isNaN(b[i])));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* lme4's likelihood-ratio comparison of fits (internal; lmerAnova's and glmerAnova's): the checks that the fits are of
|
|
116
|
+
* the same observations, the names, the ML refits of REML fits, the rows sorted by the number of parameters and the
|
|
117
|
+
* test where the fit of the row before is nested in the row's. `fn` names the function in its error for fewer than
|
|
118
|
+
* two fits.
|
|
119
|
+
*/
|
|
120
|
+
export function compareModels(fn, models, options) {
|
|
121
|
+
if (models.length < 2)
|
|
122
|
+
throw new TypeError(`${fn} needs one fit, or an array of at least two fits to compare`);
|
|
90
123
|
// (only the number of observations is compared, as lme4 does; the fits must also share the data object below)
|
|
91
|
-
if (
|
|
124
|
+
if (models.some((f) => f.nObs !== models[0].nObs))
|
|
92
125
|
throw new Error("models were not all fitted to the same size of dataset");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
const mixed = models.flatMap((m) => (m.mixed === undefined ? [] : [m.mixed]));
|
|
127
|
+
const first = mixed[0];
|
|
128
|
+
if (first !== undefined) {
|
|
129
|
+
if (mixed.some((i) => i.data !== first.data))
|
|
130
|
+
throw new Error("all models must be fit to the same data object");
|
|
131
|
+
// (the same object changed between the fits holds different data)
|
|
132
|
+
if (mixed.some((i) => !sameFrame(i.snapshot, first.snapshot)))
|
|
133
|
+
throw new Error("all models must be fit to the same data object");
|
|
134
|
+
// A likelihood ratio compares likelihoods of the same observations: the same rows of the data and the same response
|
|
135
|
+
// (lme4 compares only the number of rows, and returns a test for fits of different rows or responses)
|
|
136
|
+
const sameRows = (r) => r.length === first.rows.length && r.every((v, i) => v === first.rows[i]);
|
|
137
|
+
if (mixed.some((i) => !sameRows(i.rows)))
|
|
138
|
+
throw new Error("models were not all fitted to the same rows of the data");
|
|
139
|
+
}
|
|
140
|
+
// the response: by the formulas' left-hand sides between fits with a formula, by value against a fit without (glm)
|
|
141
|
+
const reference = models.find((m) => m.mixed !== undefined) ?? models[0];
|
|
142
|
+
const sameResponse = (m) => m.mixed !== undefined && reference.mixed !== undefined ? m.mixed.response === reference.mixed.response : sameValues(m.response(), reference.response());
|
|
143
|
+
if (models.some((m) => m !== reference && !sameResponse(m)))
|
|
105
144
|
throw new Error("models were not all fitted to the same response");
|
|
145
|
+
// (the prior weights are part of the data: a binomial proportion with weights m and a 0/1 response differ)
|
|
146
|
+
if (models.some((m) => m !== reference && !sameValues(m.weights(), reference.weights()))) {
|
|
147
|
+
throw new Error("models were not all fitted with the same prior weights");
|
|
148
|
+
}
|
|
106
149
|
const warnings = new Warnings();
|
|
107
150
|
const messages = [];
|
|
108
|
-
let names =
|
|
151
|
+
let names = models.map((_, i) => `MODEL${i + 1}`);
|
|
109
152
|
if (options.names !== undefined) {
|
|
110
|
-
if (options.names.length !==
|
|
111
|
-
throw new TypeError(`names must be ${
|
|
153
|
+
if (options.names.length !== models.length || options.names.some((n) => typeof n !== "string")) {
|
|
154
|
+
throw new TypeError(`names must be ${models.length} strings, one per fit`);
|
|
112
155
|
}
|
|
113
156
|
if (new Set(options.names).size === options.names.length)
|
|
114
157
|
names = [...options.names];
|
|
@@ -118,34 +161,38 @@ function compareFits(fits, options) {
|
|
|
118
161
|
const refit = logicalOption(options.refit, true);
|
|
119
162
|
let logLik;
|
|
120
163
|
if (refit) {
|
|
121
|
-
if (
|
|
164
|
+
if (models.some((f) => f.reml))
|
|
122
165
|
messages.push("refitting model(s) with ML (instead of REML)");
|
|
123
|
-
logLik =
|
|
124
|
-
if (!f.REML)
|
|
125
|
-
return f.logLik;
|
|
126
|
-
const { snapshot, options: o, criterion } = internals[i];
|
|
127
|
-
return lmerWithCriterion(f.formula, snapshot, { ...o, REML: false }, criterion).logLik;
|
|
128
|
-
});
|
|
166
|
+
logLik = models.map((f) => (f.reml && f.refitLogLik !== undefined ? f.refitLogLik() : f.logLik));
|
|
129
167
|
}
|
|
130
168
|
else {
|
|
131
|
-
if (
|
|
169
|
+
if (models.some((f) => f.reml) && models.some((f) => !f.reml))
|
|
132
170
|
warnings.add("some models fit with REML = TRUE, some not");
|
|
133
|
-
logLik =
|
|
171
|
+
logLik = models.map((f) => f.logLik);
|
|
134
172
|
}
|
|
135
173
|
// sorted by the number of parameters (stable)
|
|
136
|
-
const order =
|
|
137
|
-
const n =
|
|
138
|
-
const npar = order.map((i) =>
|
|
174
|
+
const order = models.map((_, i) => i).sort((a, b) => models[a].df - models[b].df || a - b);
|
|
175
|
+
const n = models[0].nObs;
|
|
176
|
+
const npar = order.map((i) => models[i].df);
|
|
139
177
|
const ll = order.map((i) => logLik[i]);
|
|
140
178
|
// A likelihood ratio test needs the smaller fit to be a special case of the larger one (lme4 gives a p-value for any
|
|
141
|
-
// pair):
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
179
|
+
// pair): the same family and link (an lmer fit is gaussian with the identity link) and the same offset, its
|
|
180
|
+
// fixed-effect columns among the larger fit's, and each of its random-effect terms within a term of the same grouping
|
|
181
|
+
// factor there ((1 | g) + (0 + x | g) within (1 + x | g), not the converse). Otherwise no test (AIC and BIC still
|
|
182
|
+
// compare the fits). The fixed effects are compared as column spaces (the fits use the same rows of the same data):
|
|
183
|
+
// by their names, the same factor in other contrasts (contr.sum against contr.treatment) looked not nested and was
|
|
184
|
+
// not tested (issue #8)
|
|
185
|
+
// The offsets and the columns are compared on the rows of positive weight only (the fits share their weights): rows
|
|
186
|
+
// of weight 0 are not in the likelihoods, and one of them made nested columns look otherwise, as in glmAnova and
|
|
187
|
+
// anovaSequential (#509)
|
|
188
|
+
const positive = reference.weights().map((w) => w !== 0);
|
|
189
|
+
const counted = (rows) => rows.filter((_, i) => positive[i]);
|
|
190
|
+
const nestedIn = (small, large) => small.family === large.family &&
|
|
191
|
+
small.link === large.link &&
|
|
192
|
+
sameValues(counted(small.offset()), counted(large.offset())) &&
|
|
193
|
+
nestedColumns(counted(small.x()), counted(large.x())) &&
|
|
194
|
+
small.randomTerms.every((t) => large.randomTerms.some((u) => u.group === t.group && t.columns.every((c) => u.columns.includes(c))));
|
|
195
|
+
const nested = order.map((i, k) => k > 0 && nestedIn(models[order[k - 1]], models[i]));
|
|
149
196
|
const Chisq = ll.map((v, k) => (k === 0 || !nested[k] ? NaN : 2 * Math.max(0, v - ll[k - 1])));
|
|
150
197
|
const Df = npar.map((v, k) => (k === 0 ? NaN : v - npar[k - 1]));
|
|
151
198
|
const pValue = Chisq.map((x, k) => (k === 0 || Df[k] === 0 ? NaN : pgamma1(x, Df[k] / 2, 2, false, false)));
|
|
@@ -163,11 +210,20 @@ function compareFits(fits, options) {
|
|
|
163
210
|
warnings: warnings.list,
|
|
164
211
|
};
|
|
165
212
|
}
|
|
213
|
+
function compareFits(fits, options) {
|
|
214
|
+
if (fits.length < 2)
|
|
215
|
+
throw new TypeError("lmerAnova needs one fit, or an array of at least two fits to compare");
|
|
216
|
+
return compareModels("lmerAnova", fits.map(comparedLmer), options);
|
|
217
|
+
}
|
|
166
218
|
export function lmerAnova(fit, options) {
|
|
167
219
|
if (Array.isArray(fit)) {
|
|
168
|
-
|
|
220
|
+
checkLmerOptions("lmerAnova", options, ["modelNames", "model.names"]);
|
|
221
|
+
checkOptions(options, ["refit", "names"], "lmerAnova");
|
|
222
|
+
const checked = (options ?? {});
|
|
169
223
|
// (the logical value is checked with the options, before the fits)
|
|
170
|
-
return compareFits(fit, { ...checked, refit: logicalOption(checked.refit, true) });
|
|
224
|
+
return reported("lmerAnova", compareFits(fit, { ...checked, refit: logicalOption(checked.refit, true) }), ...fit);
|
|
171
225
|
}
|
|
172
|
-
|
|
226
|
+
checkLmerOptions("lmerAnova", options, ["ddf"]);
|
|
227
|
+
checkOptions(options, ["type"], "lmerAnova");
|
|
228
|
+
return reported("lmerAnova", anovaOfFit(fit, (options ?? {})), fit);
|
|
173
229
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Warnings } from "
|
|
1
|
+
import { Warnings } from "../internal/warnings.js";
|
|
2
2
|
import { type LmerResult } from "./lmer.js";
|
|
3
3
|
import type { MixedModelStructure } from "./mixedStructure.js";
|
|
4
4
|
/**
|
|
@@ -21,6 +21,13 @@ export interface LmerSatterthwaite {
|
|
|
21
21
|
* #9): estimates, standard errors and right-hand sides are scaled by it in the tests, sums of squares by 4^scale
|
|
22
22
|
*/
|
|
23
23
|
scale: number;
|
|
24
|
+
/**
|
|
25
|
+
* The quantities above are also those of X with column k divided by 2^xScale[k] (β, vcov and the jacobian in the
|
|
26
|
+
* units of β'_k = 2^xScale[k] β_k): 0 unless the column's largest |value| is beyond 2^±500, where the cross-products
|
|
27
|
+
* of X overflow or underflow (predictors times 1e-160 gave a vcov of Infinity and standard errors NaN). The tests
|
|
28
|
+
* take their contrasts to these units (L β = (L D⁻¹) β' with D = diag(2^xScale))
|
|
29
|
+
*/
|
|
30
|
+
xScale: number[];
|
|
24
31
|
}
|
|
25
32
|
/** The warnings about the Hessian's eigenvalues (negative, or close to 0; internal) */
|
|
26
33
|
export declare function hessianWarnings(values: readonly number[]): string[];
|
|
@@ -44,7 +51,7 @@ export interface TRow {
|
|
|
44
51
|
pValue: number;
|
|
45
52
|
}
|
|
46
53
|
/** l'β̂ − rhs over its standard error, with Satterthwaite's degrees of freedom 2 var² / (g'Ag), g_k = l'J_k l */
|
|
47
|
-
export declare function tTestOf(s: LmerSatterthwaite, l0: readonly number[], rhs0: number
|
|
54
|
+
export declare function tTestOf(s: LmerSatterthwaite, l0: readonly number[], rhs0: number): TRow;
|
|
48
55
|
/** One row of an F table (internal): lmerTest's `Sum Sq`, `Mean Sq`, `NumDF`, `DenDF`, `F value`, `Pr(>F)` */
|
|
49
56
|
export interface LmerFRow {
|
|
50
57
|
sumSq: number;
|
|
@@ -65,8 +72,8 @@ export declare function lmerFTest(fit: LmerResult, L: readonly (readonly number[
|
|
|
65
72
|
/** {@link lmerFTest} with the Satterthwaite quantities given (internal) */
|
|
66
73
|
export declare function fTestOf(s: LmerSatterthwaite, L0: readonly (readonly number[])[], rhs: readonly number[] | undefined, warnings: Warnings): LmerFRow | undefined;
|
|
67
74
|
/**
|
|
68
|
-
* Options of {@link lmerSummary}. Any other key is
|
|
69
|
-
*
|
|
75
|
+
* Options of {@link lmerSummary}. Any other key is a RangeError (R's lmerTest ignores unknown arguments with a
|
|
76
|
+
* warning).
|
|
70
77
|
*
|
|
71
78
|
* @category Mixed models
|
|
72
79
|
*/
|
|
@@ -134,7 +141,7 @@ export interface LmerSummary {
|
|
|
134
141
|
export declare function lmerSummary(fit: LmerResult, options?: LmerSummaryOptions): LmerSummary;
|
|
135
142
|
/**
|
|
136
143
|
* Options of {@link lmerContest}. R's `collect`, `checkEstimability`, `check_estimability` and `ddf` give the Error
|
|
137
|
-
* `lmerContest: argument '<key>' is not supported`, any other key
|
|
144
|
+
* `lmerContest: argument '<key>' is not supported`, any other key a RangeError.
|
|
138
145
|
*
|
|
139
146
|
* @category Mixed models
|
|
140
147
|
*/
|
package/dist/models/lmerTest.js
CHANGED
|
@@ -17,16 +17,25 @@ import { pt1, qt1 } from "../distributions/t.js";
|
|
|
17
17
|
import { eigen } from "../linalg/eigen.js";
|
|
18
18
|
import { ginv } from "../linalg/kappa.js";
|
|
19
19
|
import { rangeExponent } from "../linalg/matrix.js";
|
|
20
|
-
import { Warnings } from "
|
|
20
|
+
import { reported, Warnings } from "../internal/warnings.js";
|
|
21
21
|
import { ldexp } from "../internal/summary.js";
|
|
22
|
-
import {
|
|
22
|
+
import { checkLmerOptions, extremeColumnExponents, lmerInternals, logicalOption, thetaColumnExponents } from "./lmer.js";
|
|
23
23
|
import { varparDerivatives } from "./mixedDerivatives.js";
|
|
24
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
25
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
26
|
+
const LMER_CONTEST_KEYS = ["rhs", "joint", "confint", "level"];
|
|
27
|
+
const LMER_SUMMARY_KEYS = ["ddf"];
|
|
28
|
+
// Generated by `node scripts/option-keys.mjs --write` (end)
|
|
24
29
|
/** Eigenvalues of the Hessian within this of 0 (or below) are left out of its inverse and warned about */
|
|
25
30
|
const HESSIAN_TOLERANCE = 1e-8;
|
|
26
31
|
/** Eigenvalues of L V L' at most this times the largest are left out of a joint test */
|
|
27
32
|
const RANK_TOLERANCE = Math.sqrt(Number.EPSILON);
|
|
28
33
|
/** Satterthwaite's degrees of freedom of a joint test are averaged when they differ by less than this */
|
|
29
34
|
const EQUAL_DF_TOLERANCE = 1e-8;
|
|
35
|
+
/** A contrast in the units of the scaled columns of X (see LmerSatterthwaite.xScale) */
|
|
36
|
+
function scaledContrast(s, l) {
|
|
37
|
+
return s.xScale.every((e) => e === 0) ? l : l.map((v, k) => ldexp(v, -s.xScale[k]));
|
|
38
|
+
}
|
|
30
39
|
const satterthwaiteByFit = new WeakMap();
|
|
31
40
|
/** A number as C's printf("%1.1e") writes it: "-3.2e-04" */
|
|
32
41
|
function formatE1(v) {
|
|
@@ -74,7 +83,10 @@ export function satterthwaiteAt(structure, theta, reml, beta0 = []) {
|
|
|
74
83
|
for (const v of structure.y)
|
|
75
84
|
top = Math.max(top, Math.abs(v));
|
|
76
85
|
const scale = top > 2 ** 500 || top < 2 ** -500 ? Math.floor(Math.log2(top)) : 0;
|
|
77
|
-
const
|
|
86
|
+
const scaledY = scale === 0 ? structure : { ...structure, y: structure.y.map((v) => ldexp(v, -scale)) };
|
|
87
|
+
// columns of X of extreme scale divided by powers of 2 (exact; see LmerSatterthwaite.xScale): otherwise nothing changes
|
|
88
|
+
const xScale = extremeColumnExponents(structure.x, structure.xColNames.length);
|
|
89
|
+
const st = xScale.every((e) => e === 0) ? scaledY : { ...scaledY, x: scaledY.x.map((row) => row.map((v, k) => ldexp(v, -xScale[k]))) };
|
|
78
90
|
const d = varparDerivatives(st, theta, reml);
|
|
79
91
|
const m = d.varpar.length;
|
|
80
92
|
// The Hessian in coordinates of comparable scale, D H D: θ_k times 2^e_k (the columns of Z of its row; see
|
|
@@ -105,12 +117,13 @@ export function satterthwaiteAt(structure, theta, reml, beta0 = []) {
|
|
|
105
117
|
hessian: d.hessian,
|
|
106
118
|
hessianEigenvalues: values,
|
|
107
119
|
vcovVarpar,
|
|
108
|
-
beta: d.beta.map((b, k) => b + ldexp(beta0[k] ?? 0, -scale)),
|
|
120
|
+
beta: d.beta.map((b, k) => b + ldexp(beta0[k] ?? 0, xScale[k] - scale)),
|
|
109
121
|
sigma: d.varpar[m - 1],
|
|
110
122
|
vcov: d.vcov,
|
|
111
123
|
jacobian: d.jacobian,
|
|
112
124
|
warnings: hessianWarnings(values),
|
|
113
125
|
scale,
|
|
126
|
+
xScale,
|
|
114
127
|
};
|
|
115
128
|
}
|
|
116
129
|
const quadraticForm = (l, m) => {
|
|
@@ -127,7 +140,11 @@ const quadraticForm = (l, m) => {
|
|
|
127
140
|
};
|
|
128
141
|
const dot = (a, b) => a.reduce((s, v, i) => s + v * b[i], 0);
|
|
129
142
|
/** l'β̂ − rhs over its standard error, with Satterthwaite's degrees of freedom 2 var² / (g'Ag), g_k = l'J_k l */
|
|
130
|
-
export function tTestOf(s, l0, rhs0
|
|
143
|
+
export function tTestOf(s, l0, rhs0) {
|
|
144
|
+
return tTestScaled(s, scaledContrast(s, l0), rhs0, s.beta);
|
|
145
|
+
}
|
|
146
|
+
/** {@link tTestOf} with l in the units of the scaled columns of X (see LmerSatterthwaite.xScale) */
|
|
147
|
+
function tTestScaled(s, l0, rhs0, beta) {
|
|
131
148
|
if (l0.some(Number.isNaN) || Number.isNaN(rhs0))
|
|
132
149
|
return { estimate: NaN, stdError: NaN, df: NaN, tValue: NaN, pValue: NaN };
|
|
133
150
|
// a contrast of extreme magnitude (1e160, 1e-200) divided by 2^k with its rhs: the test does not depend on it, and
|
|
@@ -179,8 +196,9 @@ export function fTestOf(s, L0, rhs, warnings) {
|
|
|
179
196
|
// L of extreme magnitude and its rhs divided by one power of 2 (the test does not depend on it; the same factor for
|
|
180
197
|
// every row keeps the eigenvectors of L V L', and with them the rotated contrasts and the df). L V L' overflowed or
|
|
181
198
|
// underflowed (#58)
|
|
182
|
-
const
|
|
183
|
-
const
|
|
199
|
+
const L1 = L0.map((row) => scaledContrast(s, row));
|
|
200
|
+
const k = rangeExponent(L1.flat());
|
|
201
|
+
const L = k === 0 ? L1 : L1.map((row) => row.map((v) => ldexp(v, -k)));
|
|
184
202
|
// (the right-hand side in the units of the scaled response: tTestOf scales its own, the joint test below uses these)
|
|
185
203
|
const given = (rhs ?? new Array(r).fill(0)).map((v) => ldexp(v, -k));
|
|
186
204
|
const right = given.map((v) => ldexp(v, -s.scale));
|
|
@@ -189,7 +207,7 @@ export function fTestOf(s, L0, rhs, warnings) {
|
|
|
189
207
|
const l = L[0];
|
|
190
208
|
if (!l.some(Number.isNaN) && !(l.reduce((sum, v, j) => sum + v * l.reduce((t, w, k) => t + s.vcov[j][k] * w, 0), 0) > 0))
|
|
191
209
|
return undefined;
|
|
192
|
-
const t =
|
|
210
|
+
const t = tTestScaled(s, l, given[0], s.beta);
|
|
193
211
|
return fRowOf(s, t.tValue * t.tValue, 1, t.df);
|
|
194
212
|
}
|
|
195
213
|
if (L.some((row) => row.some(Number.isNaN)) || right.some(Number.isNaN))
|
|
@@ -215,7 +233,7 @@ export function fTestOf(s, L0, rhs, warnings) {
|
|
|
215
233
|
const p = s.beta.length;
|
|
216
234
|
const rotated = Array.from({ length: kept }, (_, k) => Array.from({ length: p }, (_, j) => L.reduce((sum, row, i) => sum + e.vectors[i][k] * row[j], 0)));
|
|
217
235
|
if (kept === 1) {
|
|
218
|
-
const t =
|
|
236
|
+
const t = tTestScaled(s, rotated[0], 0, beta);
|
|
219
237
|
return fRowOf(s, t.tValue * t.tValue, 1, t.df);
|
|
220
238
|
}
|
|
221
239
|
let f = 0;
|
|
@@ -257,19 +275,21 @@ export function fTestOf(s, L0, rhs, warnings) {
|
|
|
257
275
|
* @category Mixed models
|
|
258
276
|
*/
|
|
259
277
|
export function lmerSummary(fit, options) {
|
|
260
|
-
|
|
278
|
+
checkLmerOptions("lmerSummary", options, []);
|
|
279
|
+
checkOptions(options, LMER_SUMMARY_KEYS, "lmerSummary"); // generated: option-keys.mjs
|
|
280
|
+
const ddf = options?.ddf ?? "Satterthwaite";
|
|
261
281
|
if (ddf !== "Satterthwaite" && ddf !== "lme4")
|
|
262
282
|
throw new RangeError(`ddf must be "Satterthwaite" or "lme4", not ${JSON.stringify(ddf)}`);
|
|
263
283
|
const internals = lmerInternals(fit);
|
|
264
284
|
const names = [...internals.structure.xColNames];
|
|
265
285
|
if (ddf === "lme4") {
|
|
266
286
|
const { estimate, stdError, tValue } = fit.coefTable;
|
|
267
|
-
return { ddf, names, estimate: [...estimate], stdError: [...stdError], tValue: [...tValue], messages: [], warnings: [] };
|
|
287
|
+
return reported("lmerSummary", { ddf, names, estimate: [...estimate], stdError: [...stdError], tValue: [...tValue], messages: [], warnings: [] }, fit);
|
|
268
288
|
}
|
|
269
289
|
const s = lmerSatterthwaite(fit);
|
|
270
290
|
const p = names.length;
|
|
271
291
|
const rows = names.map((_, i) => tTestOf(s, Array.from({ length: p }, (_, j) => (j === i ? 1 : 0)), 0));
|
|
272
|
-
return {
|
|
292
|
+
return reported("lmerSummary", {
|
|
273
293
|
ddf,
|
|
274
294
|
names,
|
|
275
295
|
estimate: rows.map((r) => r.estimate),
|
|
@@ -279,9 +299,8 @@ export function lmerSummary(fit, options) {
|
|
|
279
299
|
pValue: rows.map((r) => r.pValue),
|
|
280
300
|
messages: [],
|
|
281
301
|
warnings: [...s.warnings],
|
|
282
|
-
};
|
|
302
|
+
}, fit);
|
|
283
303
|
}
|
|
284
|
-
const CONTEST_KEYS = ["rhs", "joint", "confint", "level"];
|
|
285
304
|
const CONTEST_UNSUPPORTED = ["collect", "checkEstimability", "check_estimability", "ddf"];
|
|
286
305
|
/** The rows of a contrast argument: a vector is one row; each row must have one value per fixed effect */
|
|
287
306
|
function contrastRows(L, p) {
|
|
@@ -300,7 +319,9 @@ function contrastRows(L, p) {
|
|
|
300
319
|
return rows;
|
|
301
320
|
}
|
|
302
321
|
export function lmerContest(fit, L, options) {
|
|
303
|
-
|
|
322
|
+
checkLmerOptions("lmerContest", options, CONTEST_UNSUPPORTED);
|
|
323
|
+
checkOptions(options, LMER_CONTEST_KEYS, "lmerContest"); // generated: option-keys.mjs
|
|
324
|
+
options ??= {};
|
|
304
325
|
const joint = logicalOption(options.joint, true);
|
|
305
326
|
const confint = logicalOption(options.confint, true);
|
|
306
327
|
const internals = lmerInternals(fit);
|
|
@@ -324,7 +345,7 @@ export function lmerContest(fit, L, options) {
|
|
|
324
345
|
if (joint) {
|
|
325
346
|
const row = p === 0 ? undefined : lmerFTest(fit, rows, rhs, warnings);
|
|
326
347
|
const pick = (k) => (row === undefined ? [] : [row[k]]);
|
|
327
|
-
return {
|
|
348
|
+
return reported("lmerContest", {
|
|
328
349
|
joint: true,
|
|
329
350
|
sumSq: pick("sumSq"),
|
|
330
351
|
meanSq: pick("meanSq"),
|
|
@@ -334,7 +355,7 @@ export function lmerContest(fit, L, options) {
|
|
|
334
355
|
pValue: pick("pValue"),
|
|
335
356
|
messages: [],
|
|
336
357
|
warnings: warnings.list,
|
|
337
|
-
};
|
|
358
|
+
}, fit);
|
|
338
359
|
}
|
|
339
360
|
const tests = p === 0 ? [] : rows.map((row, i) => tTestOf(s, row, rhs[i]));
|
|
340
361
|
const out = {
|
|
@@ -352,5 +373,5 @@ export function lmerContest(fit, L, options) {
|
|
|
352
373
|
out.lower = tests.map((t, i) => t.estimate - t.stdError * quantiles[i]);
|
|
353
374
|
out.upper = tests.map((t, i) => t.estimate + t.stdError * quantiles[i]);
|
|
354
375
|
}
|
|
355
|
-
return out;
|
|
376
|
+
return reported("lmerContest", out, fit);
|
|
356
377
|
}
|
package/dist/models/mauchly.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export interface MauchlyTestResult {
|
|
|
30
30
|
pValue: number;
|
|
31
31
|
/** Name of the test (R's `method`). */
|
|
32
32
|
method: "Mauchly's test of sphericity";
|
|
33
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
34
|
+
warnings: string[];
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* W = det(U) / (trace(U)/p)^p of a p x p matrix U, as det(U / (trace(U)/p)): the scaled matrix has trace p, so
|
package/dist/models/mauchly.js
CHANGED
|
@@ -15,6 +15,10 @@ import { ddLeastSquaresMulti } from "./ddLeastSquares.js";
|
|
|
15
15
|
import { ddDet, ddTrace } from "./ddMatrix.js";
|
|
16
16
|
import { compareCodePoints } from "./modelFrame.js";
|
|
17
17
|
import { modelMatrix } from "./modelMatrix.js";
|
|
18
|
+
import { unreported } from "../internal/warnings.js";
|
|
19
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
20
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
21
|
+
const MAUCHLY_TEST_KEYS = ["group", "idata", "M", "X"];
|
|
18
22
|
const upperChisq = (q, df) => pgamma1(q, df / 2, 2, false, false);
|
|
19
23
|
/**
|
|
20
24
|
* W = det(U) / (trace(U)/p)^p of a p x p matrix U, as det(U / (trace(U)/p)): the scaled matrix has trace p, so
|
|
@@ -82,6 +86,7 @@ export function contrastCrossprod(S, mcols, xcols) {
|
|
|
82
86
|
* @category Linear models and ANOVA
|
|
83
87
|
*/
|
|
84
88
|
export function mauchlyTest(y, options = {}) {
|
|
89
|
+
checkOptions(options, MAUCHLY_TEST_KEYS, "mauchlyTest"); // generated: option-keys.mjs
|
|
85
90
|
const all = y.map((r) => Array.from(r));
|
|
86
91
|
const k = all[0]?.length ?? 0;
|
|
87
92
|
if (k === 0 || all.some((r) => r.length !== k))
|
|
@@ -123,7 +128,7 @@ export function mauchlyTest(y, options = {}) {
|
|
|
123
128
|
}));
|
|
124
129
|
const idata = options.idata ?? { index: Array.from({ length: k }, (_, i) => i + 1) };
|
|
125
130
|
const design = (f) => {
|
|
126
|
-
const m = modelMatrix(f, idata);
|
|
131
|
+
const m = unreported(() => modelMatrix(f, idata));
|
|
127
132
|
if (m.x.length !== k)
|
|
128
133
|
throw new RangeError("idata must have one row per column of y");
|
|
129
134
|
return columnsOf(m.x, m.colNames.length);
|
|
@@ -145,5 +150,5 @@ export function mauchlyTest(y, options = {}) {
|
|
|
145
150
|
if (n < pp)
|
|
146
151
|
throw new RangeError(`too few residual degrees of freedom for the test: ${n} for ${pp} dimension(s)`);
|
|
147
152
|
const W = sphericityW(U);
|
|
148
|
-
return { statistic: W, statisticName: "W", pValue: mauchlyPValue(W, pp, n, k), method: "Mauchly's test of sphericity" };
|
|
153
|
+
return { statistic: W, statisticName: "W", pValue: mauchlyPValue(W, pp, n, k), method: "Mauchly's test of sphericity", warnings: [] };
|
|
149
154
|
}
|
|
@@ -77,15 +77,41 @@ export interface SparseSystem {
|
|
|
77
77
|
* at colStart[column] + (rows of the diagonal block from the column) + blockPatternOffset[b] + r (0 on the diagonal)
|
|
78
78
|
*/
|
|
79
79
|
blockPatternOffset: Int32Array;
|
|
80
|
+
/**
|
|
81
|
+
* For each row i and each pair of terms k ≥ l, the block of Z'Z (its index in the sorted blocks) that the row adds
|
|
82
|
+
* to, at i nPairs + k (k + 1) / 2 + l: the weighted cross-product Z'WZ of glmer is formed with it
|
|
83
|
+
*/
|
|
84
|
+
rowBlocks: Int32Array;
|
|
80
85
|
}
|
|
86
|
+
/** The groups of columns, the cross-products and the pattern of the factor of a structure (cached) */
|
|
87
|
+
export declare function sparseSystemOf(s: MixedModelStructure): SparseSystem;
|
|
88
|
+
/** Z'WZ by blocks, in the layout of the system's Z'Z (glmer's working weights `w`, one per row) */
|
|
89
|
+
export declare function weightedCrossProduct(sys: SparseSystem, s: MixedModelStructure, w: ArrayLike<number>): Float64Array;
|
|
90
|
+
/** Z v (n-vector) from the sparse Z, for a q-vector v */
|
|
91
|
+
export declare function zTimes(sys: SparseSystem, v: ArrayLike<number>): Float64Array;
|
|
92
|
+
/** Z' v (q-vector) from the sparse Z, for an n-vector v */
|
|
93
|
+
export declare function zTransposeTimes(sys: SparseSystem, v: ArrayLike<number>): Float64Array;
|
|
94
|
+
/** The blocks T_k at θ (nc × nc, column-major, lower triangular) */
|
|
95
|
+
export declare function blocksOf(sys: SparseSystem, theta: readonly number[]): Float64Array[];
|
|
81
96
|
/** Λ_θ w (q-vector) */
|
|
82
97
|
export declare function lambdaTimes(sys: SparseSystem, t: Float64Array[], w: Float64Array): Float64Array;
|
|
83
98
|
/** Λ_θ' M for a q × ncol column-major M */
|
|
84
99
|
export declare function lambdaTransposeTimes(sys: SparseSystem, t: Float64Array[], m: Float64Array, ncol?: number): Float64Array;
|
|
100
|
+
/**
|
|
101
|
+
* The blocks of A = Λ_θ' Z'Z Λ_θ + I (the layout of Z'Z), each T_g' Z'Z(g, h) T_h, the identity added on the diagonal
|
|
102
|
+
* (with `zz`, Z'WZ by blocks instead of Z'Z: glmer's Λ_θ' Z'WZ Λ_θ + I)
|
|
103
|
+
*/
|
|
104
|
+
export declare function blocksOfA(sys: SparseSystem, t: Float64Array[], zz?: Float64Array): Float64Array;
|
|
105
|
+
/** The values of the Cholesky factor L of A (A = L L', the pattern of the system), from the blocks of A */
|
|
106
|
+
export declare function factorise(sys: SparseSystem, a: Float64Array): Float64Array;
|
|
85
107
|
/** Solves L x = v in place (v of length q, at an offset) */
|
|
86
108
|
export declare function solveL(sys: SparseSystem, l: Float64Array, v: Float64Array, offset?: number): void;
|
|
87
109
|
/** Solves L' x = v in place */
|
|
88
110
|
export declare function solveLt(sys: SparseSystem, l: Float64Array, v: Float64Array, offset?: number): void;
|
|
111
|
+
/** Solves L x = v in place, with L = R' and R the upper-triangular factor (column-major, k × k) */
|
|
112
|
+
export declare function forwardSolve(r: Float64Array, k: number, v: Float64Array): void;
|
|
113
|
+
/** Solves R x = v in place, R upper triangular (column-major, k × k) */
|
|
114
|
+
export declare function backSolve(r: Float64Array, k: number, v: Float64Array): void;
|
|
89
115
|
/** The full symmetric inverse of R'R from an upper-triangular factor R (column-major, k × k; R is not changed) */
|
|
90
116
|
export declare function inverseFromFactor(r: Float64Array, k: number): Float64Array;
|
|
91
117
|
/**
|
|
@@ -151,6 +177,6 @@ export declare function selectedInverseTangent(sys: SparseSystem, l: Float64Arra
|
|
|
151
177
|
* S_k = Σ over the levels G of term k of (Y Λ' Z'Z) on G's columns (nc_k × nc_k, column-major), for Y = A⁻¹ given by
|
|
152
178
|
* its selected inverse `inv` (the layout of L's values) and Λ by its blocks `t` (see {@link sparseGradient}). Linear
|
|
153
179
|
* in `inv` and in `t`, so that the derivatives of the sums (src/models/mixedDerivatives.ts) come from the derivative
|
|
154
|
-
* of the selected inverse and of the blocks.
|
|
180
|
+
* of the selected inverse and of the blocks. With `zz` (Z'WZ by blocks, glmer's gradient), Λ'Z'WZ in place of Λ'Z'Z.
|
|
155
181
|
*/
|
|
156
|
-
export declare function levelTraceSums(sys: SparseSystem, inv: Float64Array, t: Float64Array[]): Float64Array[];
|
|
182
|
+
export declare function levelTraceSums(sys: SparseSystem, inv: Float64Array, t: Float64Array[], zz?: Float64Array): Float64Array[];
|