@numero-uno-jpn/rstats 0.16.0 → 0.17.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 +44 -18
- package/README.md +45 -18
- package/dist/chunks/chunk-2C33MXSW.js +3 -0
- package/dist/chunks/chunk-34S5SQY6.js +2 -0
- package/dist/chunks/{chunk-URIO5LY5.js → chunk-4WE3OO62.js} +2 -2
- package/dist/chunks/chunk-5AYHCITP.js +2 -0
- package/dist/chunks/chunk-6JJQL6HL.js +2 -0
- package/dist/chunks/chunk-C7V2FH6L.js +3 -0
- package/dist/chunks/chunk-CZI7KUO3.js +2 -0
- package/dist/chunks/chunk-DXI5N2ET.js +2 -0
- package/dist/chunks/chunk-FY3FVOBM.js +2 -0
- package/dist/chunks/{chunk-QNNL7AZ3.js → chunk-H3WVPZDL.js} +2 -2
- package/dist/chunks/chunk-LHUIJQHY.js +2 -0
- package/dist/chunks/chunk-LV3W2F7N.js +2 -0
- package/dist/chunks/chunk-M4ITG7YR.js +2 -0
- package/dist/chunks/{chunk-FLJNSXSW.js → chunk-NSYZTS26.js} +2 -2
- package/dist/chunks/chunk-ONY5CISH.js +2 -0
- package/dist/chunks/chunk-RFE7MVP7.js +2 -0
- package/dist/chunks/{chunk-W26LRYOJ.js → chunk-SE7V2KLO.js} +1 -1
- package/dist/chunks/chunk-THIGHOKK.js +2 -0
- package/dist/chunks/chunk-TNMJPQPV.js +2 -0
- package/dist/chunks/chunk-WM7VFXTV.js +2 -0
- package/dist/chunks/chunk-WMDYDTVQ.js +2 -0
- package/dist/chunks/chunk-XLSFJTTK.js +2 -0
- package/dist/chunks/{chunk-5UQCRBAG.js → chunk-Z37NELOS.js} +1 -1
- package/dist/chunks/chunk-ZFQWB222.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 +3 -0
- package/dist/entries/mixed.js +2 -0
- 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 +4 -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/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/lm.js +13 -3
- package/dist/models/lmer.d.ts +11 -6
- package/dist/models/lmer.js +20 -15
- package/dist/models/lmerAnova.d.ts +3 -3
- package/dist/models/lmerAnova.js +10 -5
- package/dist/models/lmerTest.d.ts +4 -4
- package/dist/models/lmerTest.js +19 -11
- package/dist/models/mauchly.d.ts +2 -0
- package/dist/models/mauchly.js +7 -2
- package/dist/models/modelFrame.js +2 -2
- package/dist/models/modelMatrix.js +7 -2
- 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 +15 -11
- package/llms.txt +5 -2
- 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-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/lmer.js
CHANGED
|
@@ -58,6 +58,10 @@ import { qr, qrCoef } from "../linalg/qr.js";
|
|
|
58
58
|
import { profiledDeviance } from "./mixedDeviance.js";
|
|
59
59
|
import { mixedModelStructure } from "./mixedStructure.js";
|
|
60
60
|
import { maxOf, minOf } from "../internal/extremes.js";
|
|
61
|
+
import { reported } from "../internal/warnings.js";
|
|
62
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
63
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
64
|
+
const LMER_KEYS = ["REML", "contrasts", "levels"];
|
|
61
65
|
/** Initial trust-region radius, relative to max(1, max |θ|) */
|
|
62
66
|
const INITIAL_RADIUS = 0.25;
|
|
63
67
|
/** Step of the central differences of the gradient that give the Hessian, relative to |θ_j| ... */
|
|
@@ -445,24 +449,20 @@ function minimiseCriterion(s, reml, criterion) {
|
|
|
445
449
|
throw new Error(OPTIMISATION_FAILED);
|
|
446
450
|
}
|
|
447
451
|
/**
|
|
448
|
-
* The option
|
|
449
|
-
* `options` must be an object when given (not null, not an array)
|
|
450
|
-
* of R that are not supported (the first gives an Error
|
|
451
|
-
*
|
|
452
|
+
* The first option check of lmer and of lmerTest's functions (internal; oracle/report-0.14.0-behaviour.md, section
|
|
453
|
+
* 3): `options` must be an object when given (not null, not an array), and none of its own keys, in order, among those
|
|
454
|
+
* of R that are not supported (the first gives an Error naming it). A key whose value is `undefined` counts as given.
|
|
455
|
+
* The unknown keys are checked after it (a RangeError of checkOptions, generated by scripts/option-keys.mjs, which
|
|
456
|
+
* keeps a first statement calling this function before its checks).
|
|
452
457
|
*/
|
|
453
|
-
export function
|
|
458
|
+
export function checkLmerOptions(fn, options, unsupported) {
|
|
454
459
|
if (options === undefined)
|
|
455
|
-
return
|
|
460
|
+
return;
|
|
456
461
|
if (typeof options !== "object" || options === null || Array.isArray(options))
|
|
457
462
|
throw new TypeError("options must be an object");
|
|
458
|
-
const
|
|
459
|
-
const notSupported = keys.find((k) => unsupported.includes(k));
|
|
463
|
+
const notSupported = Object.keys(options).find((k) => unsupported.includes(k));
|
|
460
464
|
if (notSupported !== undefined)
|
|
461
465
|
throw new Error(`${fn}: argument '${notSupported}' is not supported`);
|
|
462
|
-
const unknown = keys.filter((k) => !accepted.includes(k));
|
|
463
|
-
if (unknown.length > 0)
|
|
464
|
-
throw new TypeError(`unused argument${unknown.length === 1 ? "" : "s"} (${unknown.join(", ")})`);
|
|
465
|
-
return options;
|
|
466
466
|
}
|
|
467
467
|
/**
|
|
468
468
|
* A logical option as R's conditions take it (internal): `undefined` gives the default, a boolean itself, a number
|
|
@@ -479,7 +479,6 @@ export function logicalOption(value, defaultValue) {
|
|
|
479
479
|
throw new TypeError("argument is of length zero");
|
|
480
480
|
throw new TypeError("argument is not interpretable as logical");
|
|
481
481
|
}
|
|
482
|
-
const LMER_KEYS = ["REML", "contrasts", "levels"];
|
|
483
482
|
const LMER_UNSUPPORTED = ["weights", "offset", "subset", "naAction", "na.action", "control", "start", "verbose", "devFunOnly"];
|
|
484
483
|
/**
|
|
485
484
|
* Fit a linear mixed model by REML (default) or maximum likelihood. Equivalent to `lme4::lmer()` in R. With the
|
|
@@ -496,6 +495,10 @@ const LMER_UNSUPPORTED = ["weights", "offset", "subset", "naAction", "na.action"
|
|
|
496
495
|
* differ in the 5th to 9th significant digit). Elements on the boundary are exactly 0, and the fit is then singular.
|
|
497
496
|
* The computation is sparse (a sparse Cholesky factorisation, as in lme4), so many groups are handled quickly.
|
|
498
497
|
*
|
|
498
|
+
* The functions that take the fit ({@link lmerSummary}, {@link lmerAnova}, {@link lmerContest} and the others) need
|
|
499
|
+
* the object `lmer` returned itself: a copy of it (`structuredClone`, `{ ...fit }`, JSON or `postMessage`) lacks the
|
|
500
|
+
* internal values they use and is a TypeError. The fields of a copy keep their values.
|
|
501
|
+
*
|
|
499
502
|
* @param formula A formula such as `"Reaction ~ Days + (Days | Subject)"`.
|
|
500
503
|
* @param data The data frame: an object of columns.
|
|
501
504
|
* @param options `REML`, and `contrasts` and `levels` as in {@link lm} (see {@link LmerOptions} for the keys accepted).
|
|
@@ -518,7 +521,9 @@ const LMER_UNSUPPORTED = ["weights", "offset", "subset", "naAction", "na.action"
|
|
|
518
521
|
* @category Mixed models
|
|
519
522
|
*/
|
|
520
523
|
export function lmer(formula, data, options) {
|
|
521
|
-
|
|
524
|
+
checkLmerOptions("lmer", options, LMER_UNSUPPORTED);
|
|
525
|
+
checkOptions(options, LMER_KEYS, "lmer"); // generated: option-keys.mjs
|
|
526
|
+
return reported("lmer", lmerWithCriterion(formula, data, options, sparseCriterion));
|
|
522
527
|
}
|
|
523
528
|
/**
|
|
524
529
|
* The internals of every result returned by {@link lmer} (and {@link lmerWithCriterion}), keyed by the result object
|
|
@@ -540,7 +545,7 @@ export function lmerInternals(fit) {
|
|
|
540
545
|
* test of the sparse computation fits with the dense reference implementation through it.
|
|
541
546
|
*/
|
|
542
547
|
export function lmerWithCriterion(formula, data, options, criterion) {
|
|
543
|
-
const given =
|
|
548
|
+
const given = options ?? {};
|
|
544
549
|
const reml = logicalOption(given.REML, true);
|
|
545
550
|
options = { ...given, REML: reml };
|
|
546
551
|
const modelOptions = {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Warnings } from "
|
|
1
|
+
import { Warnings } from "../internal/warnings.js";
|
|
2
2
|
import { type LmerResult } from "./lmer.js";
|
|
3
3
|
import { type HypothesisType, type LmerHypotheses } from "./lmerHypotheses.js";
|
|
4
4
|
import { type LmerFRow, type LmerSatterthwaite } from "./lmerTest.js";
|
|
5
5
|
/**
|
|
6
6
|
* Options of {@link lmerAnova} for one fit. R's `ddf` gives the Error `lmerAnova: argument 'ddf' is not supported`,
|
|
7
|
-
* any other key
|
|
7
|
+
* any other key a RangeError.
|
|
8
8
|
*
|
|
9
9
|
* @category Mixed models
|
|
10
10
|
*/
|
|
@@ -41,7 +41,7 @@ export interface LmerAnovaTable {
|
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Options of {@link lmerAnova} for several fits. R's `modelNames` and `model.names` give the Error
|
|
44
|
-
* `lmerAnova: argument '<key>' is not supported`, any other key
|
|
44
|
+
* `lmerAnova: argument '<key>' is not supported`, any other key a RangeError.
|
|
45
45
|
*
|
|
46
46
|
* @category Mixed models
|
|
47
47
|
*/
|
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" };
|
|
@@ -165,9 +166,13 @@ function compareFits(fits, options) {
|
|
|
165
166
|
}
|
|
166
167
|
export function lmerAnova(fit, options) {
|
|
167
168
|
if (Array.isArray(fit)) {
|
|
168
|
-
|
|
169
|
+
checkLmerOptions("lmerAnova", options, ["modelNames", "model.names"]);
|
|
170
|
+
checkOptions(options, ["refit", "names"], "lmerAnova");
|
|
171
|
+
const checked = (options ?? {});
|
|
169
172
|
// (the logical value is checked with the options, before the fits)
|
|
170
|
-
return compareFits(fit, { ...checked, refit: logicalOption(checked.refit, true) });
|
|
173
|
+
return reported("lmerAnova", compareFits(fit, { ...checked, refit: logicalOption(checked.refit, true) }), ...fit);
|
|
171
174
|
}
|
|
172
|
-
|
|
175
|
+
checkLmerOptions("lmerAnova", options, ["ddf"]);
|
|
176
|
+
checkOptions(options, ["type"], "lmerAnova");
|
|
177
|
+
return reported("lmerAnova", anovaOfFit(fit, (options ?? {})), fit);
|
|
173
178
|
}
|
|
@@ -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
|
/**
|
|
@@ -65,8 +65,8 @@ export declare function lmerFTest(fit: LmerResult, L: readonly (readonly number[
|
|
|
65
65
|
/** {@link lmerFTest} with the Satterthwaite quantities given (internal) */
|
|
66
66
|
export declare function fTestOf(s: LmerSatterthwaite, L0: readonly (readonly number[])[], rhs: readonly number[] | undefined, warnings: Warnings): LmerFRow | undefined;
|
|
67
67
|
/**
|
|
68
|
-
* Options of {@link lmerSummary}. Any other key is
|
|
69
|
-
*
|
|
68
|
+
* Options of {@link lmerSummary}. Any other key is a RangeError (R's lmerTest ignores unknown arguments with a
|
|
69
|
+
* warning).
|
|
70
70
|
*
|
|
71
71
|
* @category Mixed models
|
|
72
72
|
*/
|
|
@@ -134,7 +134,7 @@ export interface LmerSummary {
|
|
|
134
134
|
export declare function lmerSummary(fit: LmerResult, options?: LmerSummaryOptions): LmerSummary;
|
|
135
135
|
/**
|
|
136
136
|
* 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
|
|
137
|
+
* `lmerContest: argument '<key>' is not supported`, any other key a RangeError.
|
|
138
138
|
*
|
|
139
139
|
* @category Mixed models
|
|
140
140
|
*/
|
package/dist/models/lmerTest.js
CHANGED
|
@@ -17,10 +17,15 @@ 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, 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 */
|
|
@@ -257,19 +262,21 @@ export function fTestOf(s, L0, rhs, warnings) {
|
|
|
257
262
|
* @category Mixed models
|
|
258
263
|
*/
|
|
259
264
|
export function lmerSummary(fit, options) {
|
|
260
|
-
|
|
265
|
+
checkLmerOptions("lmerSummary", options, []);
|
|
266
|
+
checkOptions(options, LMER_SUMMARY_KEYS, "lmerSummary"); // generated: option-keys.mjs
|
|
267
|
+
const ddf = options?.ddf ?? "Satterthwaite";
|
|
261
268
|
if (ddf !== "Satterthwaite" && ddf !== "lme4")
|
|
262
269
|
throw new RangeError(`ddf must be "Satterthwaite" or "lme4", not ${JSON.stringify(ddf)}`);
|
|
263
270
|
const internals = lmerInternals(fit);
|
|
264
271
|
const names = [...internals.structure.xColNames];
|
|
265
272
|
if (ddf === "lme4") {
|
|
266
273
|
const { estimate, stdError, tValue } = fit.coefTable;
|
|
267
|
-
return { ddf, names, estimate: [...estimate], stdError: [...stdError], tValue: [...tValue], messages: [], warnings: [] };
|
|
274
|
+
return reported("lmerSummary", { ddf, names, estimate: [...estimate], stdError: [...stdError], tValue: [...tValue], messages: [], warnings: [] }, fit);
|
|
268
275
|
}
|
|
269
276
|
const s = lmerSatterthwaite(fit);
|
|
270
277
|
const p = names.length;
|
|
271
278
|
const rows = names.map((_, i) => tTestOf(s, Array.from({ length: p }, (_, j) => (j === i ? 1 : 0)), 0));
|
|
272
|
-
return {
|
|
279
|
+
return reported("lmerSummary", {
|
|
273
280
|
ddf,
|
|
274
281
|
names,
|
|
275
282
|
estimate: rows.map((r) => r.estimate),
|
|
@@ -279,9 +286,8 @@ export function lmerSummary(fit, options) {
|
|
|
279
286
|
pValue: rows.map((r) => r.pValue),
|
|
280
287
|
messages: [],
|
|
281
288
|
warnings: [...s.warnings],
|
|
282
|
-
};
|
|
289
|
+
}, fit);
|
|
283
290
|
}
|
|
284
|
-
const CONTEST_KEYS = ["rhs", "joint", "confint", "level"];
|
|
285
291
|
const CONTEST_UNSUPPORTED = ["collect", "checkEstimability", "check_estimability", "ddf"];
|
|
286
292
|
/** The rows of a contrast argument: a vector is one row; each row must have one value per fixed effect */
|
|
287
293
|
function contrastRows(L, p) {
|
|
@@ -300,7 +306,9 @@ function contrastRows(L, p) {
|
|
|
300
306
|
return rows;
|
|
301
307
|
}
|
|
302
308
|
export function lmerContest(fit, L, options) {
|
|
303
|
-
|
|
309
|
+
checkLmerOptions("lmerContest", options, CONTEST_UNSUPPORTED);
|
|
310
|
+
checkOptions(options, LMER_CONTEST_KEYS, "lmerContest"); // generated: option-keys.mjs
|
|
311
|
+
options ??= {};
|
|
304
312
|
const joint = logicalOption(options.joint, true);
|
|
305
313
|
const confint = logicalOption(options.confint, true);
|
|
306
314
|
const internals = lmerInternals(fit);
|
|
@@ -324,7 +332,7 @@ export function lmerContest(fit, L, options) {
|
|
|
324
332
|
if (joint) {
|
|
325
333
|
const row = p === 0 ? undefined : lmerFTest(fit, rows, rhs, warnings);
|
|
326
334
|
const pick = (k) => (row === undefined ? [] : [row[k]]);
|
|
327
|
-
return {
|
|
335
|
+
return reported("lmerContest", {
|
|
328
336
|
joint: true,
|
|
329
337
|
sumSq: pick("sumSq"),
|
|
330
338
|
meanSq: pick("meanSq"),
|
|
@@ -334,7 +342,7 @@ export function lmerContest(fit, L, options) {
|
|
|
334
342
|
pValue: pick("pValue"),
|
|
335
343
|
messages: [],
|
|
336
344
|
warnings: warnings.list,
|
|
337
|
-
};
|
|
345
|
+
}, fit);
|
|
338
346
|
}
|
|
339
347
|
const tests = p === 0 ? [] : rows.map((row, i) => tTestOf(s, row, rhs[i]));
|
|
340
348
|
const out = {
|
|
@@ -352,5 +360,5 @@ export function lmerContest(fit, L, options) {
|
|
|
352
360
|
out.lower = tests.map((t, i) => t.estimate - t.stdError * quantiles[i]);
|
|
353
361
|
out.upper = tests.map((t, i) => t.estimate + t.stdError * quantiles[i]);
|
|
354
362
|
}
|
|
355
|
-
return out;
|
|
363
|
+
return reported("lmerContest", out, fit);
|
|
356
364
|
}
|
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
|
}
|
|
@@ -93,7 +93,7 @@ export function modelFrame(data, names, options = {}) {
|
|
|
93
93
|
const cols = names.map((v) => {
|
|
94
94
|
const c = Object.prototype.hasOwnProperty.call(data, v) ? data[v] : undefined;
|
|
95
95
|
if (c === undefined)
|
|
96
|
-
throw new
|
|
96
|
+
throw new RangeError(`object '${v}' not found`);
|
|
97
97
|
if (!Array.isArray(c) && !(c instanceof Float64Array))
|
|
98
98
|
throw new TypeError(`column '${v}' must be an array`);
|
|
99
99
|
return c;
|
|
@@ -102,7 +102,7 @@ export function modelFrame(data, names, options = {}) {
|
|
|
102
102
|
if (typeof options.weights === "string") {
|
|
103
103
|
const c = Object.prototype.hasOwnProperty.call(data, options.weights) ? data[options.weights] : undefined;
|
|
104
104
|
if (c === undefined)
|
|
105
|
-
throw new
|
|
105
|
+
throw new RangeError(`object '${options.weights}' not found`);
|
|
106
106
|
w = c;
|
|
107
107
|
}
|
|
108
108
|
else if (options.weights !== undefined)
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
// indicators.
|
|
8
8
|
import { parseFormula, termsOf } from "./formula.js";
|
|
9
9
|
import { modelFrame } from "./modelFrame.js";
|
|
10
|
+
import { reported } from "../internal/warnings.js";
|
|
11
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
12
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
13
|
+
const MODEL_MATRIX_KEYS = ["contrasts", "levels"];
|
|
10
14
|
/**
|
|
11
15
|
* The orthonormal polynomials of degrees 1..k-1 in the centred scores, as columns (one row per level): P_0 = 1/sqrt(k)
|
|
12
16
|
* and P_d from x P_(d-1) orthogonalised twice against every earlier P (the Stieltjes three-term recurrence spans the
|
|
@@ -214,9 +218,10 @@ export function design(parsed, data, options = {}, rhs = parsed.rhs) {
|
|
|
214
218
|
* @category Linear models and ANOVA
|
|
215
219
|
*/
|
|
216
220
|
export function modelMatrix(formula, data, options = {}) {
|
|
221
|
+
checkOptions(options, MODEL_MATRIX_KEYS, "modelMatrix"); // generated: option-keys.mjs
|
|
217
222
|
// the response only drops the rows where it is missing: any type, as R's model.matrix (#453)
|
|
218
223
|
const d = design(parseFormula(formula), data, { ...options, anyResponse: true });
|
|
219
|
-
return {
|
|
224
|
+
return reported("modelMatrix", {
|
|
220
225
|
colNames: d.colNames,
|
|
221
226
|
assign: d.assign,
|
|
222
227
|
x: d.x,
|
|
@@ -228,5 +233,5 @@ export function modelMatrix(formula, data, options = {}) {
|
|
|
228
233
|
// R's factors attribute is empty for a model without terms
|
|
229
234
|
factors: d.terms.terms.length > 0 ? d.terms.factors : [],
|
|
230
235
|
warnings: d.warnings,
|
|
231
|
-
};
|
|
236
|
+
});
|
|
232
237
|
}
|
|
@@ -33,6 +33,10 @@ export interface SurvdiffResult {
|
|
|
33
33
|
df: number;
|
|
34
34
|
/** Upper chi-squared tail on `df` degrees of freedom (NaN for df = 0: the data carry no information on the groups) */
|
|
35
35
|
pvalue: number;
|
|
36
|
+
/** Alias of `pvalue`: the same value. */
|
|
37
|
+
pValue: number;
|
|
38
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
39
|
+
warnings: string[];
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* Confidence interval type of {@link survfit}.
|
|
@@ -73,6 +77,8 @@ export interface SurvfitResult {
|
|
|
73
77
|
surv: number[];
|
|
74
78
|
/** Standard error of S(t) (S times the standard error of log S) */
|
|
75
79
|
stdErr: number[];
|
|
80
|
+
/** Alias of `stdErr`: the same array. */
|
|
81
|
+
stdError: number[];
|
|
76
82
|
/** Lower limit of the pointwise confidence interval of S(t) */
|
|
77
83
|
lower: number[];
|
|
78
84
|
/** Upper limit of the pointwise confidence interval of S(t) */
|
package/dist/models/survival.js
CHANGED
|
@@ -13,6 +13,10 @@ import { eigen } from "../linalg/eigen.js";
|
|
|
13
13
|
import { solve } from "../linalg/solve.js";
|
|
14
14
|
import { midpoint } from "../internal/extremes.js";
|
|
15
15
|
import { mergeTiedTimes } from "./tiedTimes.js";
|
|
16
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
17
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
18
|
+
const SURVDIFF_KEYS = ["rho"];
|
|
19
|
+
const SURVFIT_KEYS = ["group", "confType", "confInt"];
|
|
16
20
|
const isMissing = (v) => v === null || v === undefined || (typeof v === "number" && Number.isNaN(v));
|
|
17
21
|
/** Observations with no missing value, the sorted labels and the group index of each */
|
|
18
22
|
function prepare(time, status, group) {
|
|
@@ -76,6 +80,7 @@ function prepare(time, status, group) {
|
|
|
76
80
|
* @category Survival analysis
|
|
77
81
|
*/
|
|
78
82
|
export function survdiff(time, status, group, options = {}) {
|
|
83
|
+
checkOptions(options, SURVDIFF_KEYS, "survdiff"); // generated: option-keys.mjs
|
|
79
84
|
const { rho = 0 } = options;
|
|
80
85
|
if (!Number.isFinite(rho))
|
|
81
86
|
throw new RangeError("'rho' must be a finite number");
|
|
@@ -149,7 +154,7 @@ export function survdiff(time, status, group, options = {}) {
|
|
|
149
154
|
}
|
|
150
155
|
}
|
|
151
156
|
const pvalue = df === 0 ? NaN : pchisq(chisq, df, { lowerTail: false });
|
|
152
|
-
return { n, groups: labels, obs: observed, exp: expected, var: V, chisq, df, pvalue };
|
|
157
|
+
return { n, groups: labels, obs: observed, exp: expected, var: V, chisq, df, pvalue, pValue: pvalue, warnings: [] };
|
|
153
158
|
}
|
|
154
159
|
/**
|
|
155
160
|
* u' V^- u for a symmetric positive semi-definite V by its eigen decomposition, over the eigenvalues above 1e-10 of the
|
|
@@ -208,6 +213,7 @@ function curveMedian(time, curve) {
|
|
|
208
213
|
* @category Survival analysis
|
|
209
214
|
*/
|
|
210
215
|
export function survfit(time, status, options = {}) {
|
|
216
|
+
checkOptions(options, SURVFIT_KEYS, "survfit"); // generated: option-keys.mjs
|
|
211
217
|
const { group, confType = "log", confInt = 0.95 } = options;
|
|
212
218
|
if (confType !== "log" && confType !== "plain" && confType !== "log-log") {
|
|
213
219
|
throw new RangeError(`invalid 'confType': ${String(confType)}`);
|
|
@@ -219,8 +225,9 @@ export function survfit(time, status, options = {}) {
|
|
|
219
225
|
// (for alpha below 1e-8 the upper probability itself: 1 - alpha loses its digits and rounds to 1 below 1.1e-16; review 58)
|
|
220
226
|
const a2 = (1 - confInt) / 2;
|
|
221
227
|
const z = a2 < 1e-8 ? qnorm(a2, { lowerTail: false }) : qnorm(1 - (1 - confInt) / 2);
|
|
228
|
+
const stdErr = [];
|
|
222
229
|
const out = {
|
|
223
|
-
strata: [], time: [], nRisk: [], nEvent: [], nCensor: [], surv: [], stdErr:
|
|
230
|
+
strata: [], time: [], nRisk: [], nEvent: [], nCensor: [], surv: [], stdErr, stdError: stdErr, lower: [], upper: [],
|
|
224
231
|
median: [], medianRows: names,
|
|
225
232
|
};
|
|
226
233
|
names.forEach((name, g) => {
|
package/dist/numerics/deriv.js
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
// diagonal from second central differences, the off-diagonal entries from differences along e_i + e_j less the
|
|
8
8
|
// diagonal terms, each extrapolated the same way (with d = 0.1). "simple" is the forward difference with step eps.
|
|
9
9
|
// numDeriv's "complex" (complex-step) method needs a function of a complex argument and is not offered.
|
|
10
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
11
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
12
|
+
const GRAD_KEYS = ["method", "eps", "d", "zeroTol", "r"];
|
|
13
|
+
const HESSIAN_KEYS = ["method", "eps", "d", "zeroTol", "r"];
|
|
14
|
+
const JACOBIAN_KEYS = ["method", "eps", "d", "zeroTol", "r"];
|
|
10
15
|
function checkEps(eps) {
|
|
11
16
|
if (!(Number.isFinite(eps) && eps !== 0))
|
|
12
17
|
throw new RangeError("'eps' must be a finite nonzero number");
|
|
@@ -76,6 +81,7 @@ function method(options) {
|
|
|
76
81
|
* @category Numerical methods
|
|
77
82
|
*/
|
|
78
83
|
export function grad(func, x, options = {}) {
|
|
84
|
+
checkOptions(options, GRAD_KEYS, "grad"); // generated: option-keys.mjs
|
|
79
85
|
const xs = [...x];
|
|
80
86
|
const n = xs.length;
|
|
81
87
|
if (method(options) === "simple") {
|
|
@@ -114,6 +120,7 @@ export function grad(func, x, options = {}) {
|
|
|
114
120
|
* @category Numerical methods
|
|
115
121
|
*/
|
|
116
122
|
export function jacobian(func, x, options = {}) {
|
|
123
|
+
checkOptions(options, JACOBIAN_KEYS, "jacobian"); // generated: option-keys.mjs
|
|
117
124
|
const xs = [...x];
|
|
118
125
|
const n = xs.length;
|
|
119
126
|
const f0 = Array.from(func([...xs]));
|
|
@@ -159,6 +166,7 @@ export function jacobian(func, x, options = {}) {
|
|
|
159
166
|
* @category Numerical methods
|
|
160
167
|
*/
|
|
161
168
|
export function hessian(func, x, options = {}) {
|
|
169
|
+
checkOptions(options, HESSIAN_KEYS, "hessian"); // generated: option-keys.mjs
|
|
162
170
|
if ((options.method ?? "Richardson") !== "Richardson")
|
|
163
171
|
throw new RangeError('hessian supports only method "Richardson"');
|
|
164
172
|
const xs = [...x];
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
// largest finite numbers, and the result reports the iterations and Brent's estimate of the precision.
|
|
11
11
|
import { dqagie, dqagse } from "../integrate/quadpack.js";
|
|
12
12
|
import { localMin } from "../optim/localmin.js";
|
|
13
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
14
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
15
|
+
const INTEGRATE_KEYS = ["subdivisions", "relTol", "absTol", "stopOnError"];
|
|
16
|
+
const OPTIMIZE_KEYS = ["maximum", "tol"];
|
|
17
|
+
const UNIROOT_KEYS = ["tol", "maxiter", "extendInt", "fLower", "fUpper"];
|
|
13
18
|
const MESSAGES = [
|
|
14
19
|
"OK",
|
|
15
20
|
"maximum number of subdivisions reached",
|
|
@@ -31,6 +36,7 @@ const TOL = Number.EPSILON ** 0.25;
|
|
|
31
36
|
* @category Numerical methods
|
|
32
37
|
*/
|
|
33
38
|
export function integrate(f, lower, upper, options = {}) {
|
|
39
|
+
checkOptions(options, INTEGRATE_KEYS, "integrate"); // generated: option-keys.mjs
|
|
34
40
|
const subdivisions = options.subdivisions ?? 100;
|
|
35
41
|
const limit = Math.trunc(subdivisions);
|
|
36
42
|
const relTol = options.relTol ?? TOL;
|
|
@@ -102,6 +108,7 @@ export function integrate(f, lower, upper, options = {}) {
|
|
|
102
108
|
* @category Numerical methods
|
|
103
109
|
*/
|
|
104
110
|
export function optimize(f, lower, upper, options = {}) {
|
|
111
|
+
checkOptions(options, OPTIMIZE_KEYS, "optimize"); // generated: option-keys.mjs
|
|
105
112
|
const maximum = options.maximum ?? false;
|
|
106
113
|
const tol = options.tol ?? TOL;
|
|
107
114
|
// (a positive tol, as in R: with tol = 0 the search stopped narrowing among the subnormals, see localMin)
|
|
@@ -156,6 +163,7 @@ function extendIntArg(e) {
|
|
|
156
163
|
* @category Numerical methods
|
|
157
164
|
*/
|
|
158
165
|
export function uniroot(f, lower, upper, options = {}) {
|
|
166
|
+
checkOptions(options, UNIROOT_KEYS, "uniroot"); // generated: option-keys.mjs
|
|
159
167
|
// R's "invalid 'tol' value" for tol <= 0 (tol = 0 was accepted, Brent's method then ran to maxiter or the doubles)
|
|
160
168
|
const tol = options.tol ?? TOL;
|
|
161
169
|
if (!(tol > 0 && tol < Infinity))
|
|
@@ -103,35 +103,60 @@ export interface SplinefunOptions {
|
|
|
103
103
|
/** How to merge equal x values. Default `"mean"`. */
|
|
104
104
|
ties?: Ties;
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Options of the function that {@link splinefun} and {@link splinefunH} return.
|
|
108
|
+
*
|
|
109
|
+
* @category Numerical methods
|
|
110
|
+
*/
|
|
111
|
+
export interface SplineFunctionOptions {
|
|
112
|
+
/** Order of the derivative, 0 to 3 (a fraction is truncated, as R does). Default `0`. */
|
|
113
|
+
deriv?: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The function that {@link splinefun} and {@link splinefunH} return: the spline, or a derivative, at the points `xq`.
|
|
117
|
+
* The order of the derivative is the second argument or the option `deriv` (giving both is a RangeError).
|
|
118
|
+
*
|
|
119
|
+
* @category Numerical methods
|
|
120
|
+
*/
|
|
121
|
+
export interface SplineFunction {
|
|
122
|
+
/** The spline at `xq`, or its derivative of order `deriv` (0 to 3). */
|
|
123
|
+
(xq: Sample, deriv?: number): number[];
|
|
124
|
+
/** The spline at `xq`, with the order of the derivative in the options: `s(xq, { deriv: 1 })`. */
|
|
125
|
+
(xq: Sample, options: SplineFunctionOptions): number[];
|
|
126
|
+
}
|
|
106
127
|
/**
|
|
107
128
|
* The cubic spline through the points, as a function of `x` and the order of derivative (0 to 3; a fraction is
|
|
108
129
|
* truncated, as R does). Equivalent to R's `splinefun()`. Except that the third derivative of `"monoH.FC"` is the
|
|
109
|
-
* exact one (see {@link splinefunH}).
|
|
130
|
+
* exact one (see {@link splinefunH}). The order of derivative is the second argument of the function or its option
|
|
131
|
+
* `deriv` ({@link SplineFunction}).
|
|
110
132
|
*
|
|
111
133
|
* @example
|
|
112
134
|
* ```ts
|
|
113
135
|
* const s = splinefun([1, 2, 3, 4], [1, 4, 9, 16]);
|
|
114
|
-
* s([2.5]);
|
|
115
|
-
* s([2.5], 1);
|
|
136
|
+
* s([2.5]); // [6.25]
|
|
137
|
+
* s([2.5], 1); // [5]
|
|
138
|
+
* s([2.5], { deriv: 1 }); // [5]
|
|
116
139
|
* ```
|
|
117
140
|
*
|
|
118
141
|
* @category Numerical methods
|
|
119
142
|
*/
|
|
120
|
-
export declare function splinefun(x: Sample, y: Sample, options?: SplinefunOptions):
|
|
143
|
+
export declare function splinefun(x: Sample, y: Sample, options?: SplinefunOptions): SplineFunction;
|
|
121
144
|
/**
|
|
122
145
|
* The cubic Hermite spline with values `y` and slopes `m` at the points `x`, as a function of `x` and the order of
|
|
123
146
|
* derivative (0 to 3; a fraction is truncated, as R does); linear outside the data. Equivalent to R's `splinefunH()`.
|
|
124
147
|
* Except for the third derivative: on [x_i, x_{i+1}] it is the exact (6 m_i + 6 m_{i+1} - 12 delta) / h^2, with
|
|
125
|
-
* h = x_{i+1} - x_i and delta = (y_{i+1} - y_i) / h, where R divides by h only once (the two agree when h = 1).
|
|
148
|
+
* h = x_{i+1} - x_i and delta = (y_{i+1} - y_i) / h, where R divides by h only once (the two agree when h = 1). The
|
|
149
|
+
* order of derivative is the second argument of the function or its option `deriv` ({@link SplineFunction}).
|
|
126
150
|
*
|
|
127
151
|
* @example
|
|
128
152
|
* ```ts
|
|
129
|
-
* splinefunH([0, 2], [0, 0], [1, 1])([1], 3);
|
|
153
|
+
* splinefunH([0, 2], [0, 0], [1, 1])([1], 3); // [3] (R: 6)
|
|
154
|
+
* splinefunH([0, 2], [0, 0], [1, 1])([1], { deriv: 3 }); // [3]
|
|
130
155
|
* ```
|
|
131
156
|
*
|
|
132
157
|
* @category Numerical methods
|
|
133
158
|
*/
|
|
134
|
-
export declare function splinefunH(x: Sample, y: Sample, m: Sample):
|
|
159
|
+
export declare function splinefunH(x: Sample, y: Sample, m: Sample): SplineFunction;
|
|
135
160
|
/**
|
|
136
161
|
* Lagrange interpolation in barycentric form through the points (xi, yi). Equivalent to `pracma::barylag()` in R.
|
|
137
162
|
* The points must lie within the range of the nodes.
|