@numero-uno-jpn/rstats 0.11.0 → 0.11.1
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 +13 -0
- package/README.ja.md +5 -4
- package/README.md +6 -4
- package/dist/chunks/{chunk-YSWGDOWK.js → chunk-2X7JYQBI.js} +2 -2
- package/dist/chunks/{chunk-F5EDJFEO.js → chunk-36GVER3O.js} +2 -2
- package/dist/chunks/{chunk-7GQMKH3Z.js → chunk-3WUXRSM6.js} +1 -1
- package/dist/chunks/{chunk-JWBO5WVN.js → chunk-6I6QKTFK.js} +2 -2
- package/dist/chunks/{chunk-EZWBRCJL.js → chunk-ETOEZTGL.js} +1 -1
- package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-FVPDVRJQ.js} +2 -2
- package/dist/chunks/{chunk-EZAFN5CD.js → chunk-GG4BJMJW.js} +1 -1
- package/dist/chunks/{chunk-5WDJPHYY.js → chunk-HITD7CX6.js} +1 -1
- package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-KK4GE65D.js} +2 -2
- package/dist/chunks/{chunk-AHHS6AC4.js → chunk-LAUYSGV4.js} +2 -2
- package/dist/chunks/{chunk-ALM3VHFP.js → chunk-M6GDXKKS.js} +1 -1
- package/dist/chunks/{chunk-C5XTWMGB.js → chunk-PHHUHR7T.js} +1 -1
- package/dist/chunks/{chunk-TOGXTCZO.js → chunk-WQPFDDIY.js} +2 -2
- package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-X2AWQSVS.js} +2 -2
- package/dist/chunks/{chunk-Y5CNQ266.js → chunk-ZRJQD7VS.js} +2 -2
- package/dist/data/grouping.d.ts +33 -12
- package/dist/data/grouping.js +2 -0
- package/dist/descriptive/basic.d.ts +130 -17
- package/dist/descriptive/basic.js +115 -14
- package/dist/descriptive/cov.d.ts +22 -12
- package/dist/descriptive/dataFrames.d.ts +39 -11
- package/dist/descriptive/dataFrames.js +14 -6
- package/dist/descriptive/factanal.d.ts +26 -6
- package/dist/descriptive/factanal.js +7 -3
- package/dist/descriptive/hist.d.ts +27 -6
- package/dist/descriptive/hist.js +9 -3
- package/dist/descriptive/missing.d.ts +13 -6
- package/dist/descriptive/missing.js +4 -2
- package/dist/descriptive/moments.d.ts +91 -13
- package/dist/descriptive/moments.js +66 -9
- package/dist/descriptive/omega.d.ts +28 -6
- package/dist/descriptive/omega.js +16 -4
- package/dist/descriptive/pivot.d.ts +22 -6
- package/dist/descriptive/pivot.js +7 -3
- package/dist/descriptive/quantile.d.ts +33 -5
- package/dist/descriptive/quantile.js +20 -2
- package/dist/descriptive/rank.d.ts +12 -2
- package/dist/descriptive/rank.js +2 -0
- package/dist/descriptive/table.d.ts +55 -7
- package/dist/descriptive/table.js +38 -4
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.d.ts +40 -5
- package/dist/distributions/arcsine.js +35 -4
- package/dist/distributions/beta.d.ts +12 -0
- package/dist/distributions/beta.js +12 -0
- package/dist/distributions/binomial.d.ts +18 -0
- package/dist/distributions/binomial.js +18 -0
- package/dist/distributions/bvnorm.d.ts +4 -1
- package/dist/distributions/bvnorm.js +4 -1
- package/dist/distributions/cauchy.d.ts +24 -0
- package/dist/distributions/cauchy.js +24 -0
- package/dist/distributions/chisq.d.ts +18 -0
- package/dist/distributions/chisq.js +18 -0
- package/dist/distributions/exponential.d.ts +29 -1
- package/dist/distributions/exponential.js +24 -0
- package/dist/distributions/f.d.ts +18 -0
- package/dist/distributions/f.js +18 -0
- package/dist/distributions/gamma.d.ts +20 -0
- package/dist/distributions/gamma.js +18 -0
- package/dist/distributions/geometric.d.ts +24 -0
- package/dist/distributions/geometric.js +24 -0
- package/dist/distributions/hypergeometric.d.ts +24 -0
- package/dist/distributions/hypergeometric.js +24 -0
- package/dist/distributions/invgamma.d.ts +32 -4
- package/dist/distributions/invgamma.js +27 -3
- package/dist/distributions/kumaraswamy.d.ts +31 -3
- package/dist/distributions/kumaraswamy.js +31 -3
- package/dist/distributions/laplace.d.ts +36 -4
- package/dist/distributions/laplace.js +31 -3
- package/dist/distributions/logistic.d.ts +29 -1
- package/dist/distributions/logistic.js +24 -0
- package/dist/distributions/lognormal.d.ts +29 -1
- package/dist/distributions/lognormal.js +24 -0
- package/dist/distributions/multinomial.d.ts +7 -1
- package/dist/distributions/multinomial.js +2 -0
- package/dist/distributions/negbinomial.d.ts +29 -1
- package/dist/distributions/negbinomial.js +24 -0
- package/dist/distributions/normal.d.ts +11 -1
- package/dist/distributions/normal.js +6 -0
- package/dist/distributions/pareto.d.ts +36 -4
- package/dist/distributions/pareto.js +31 -3
- package/dist/distributions/poisson.d.ts +18 -0
- package/dist/distributions/poisson.js +18 -0
- package/dist/distributions/signrank.d.ts +24 -0
- package/dist/distributions/signrank.js +24 -0
- package/dist/distributions/summary.d.ts +20 -2
- package/dist/distributions/summary.js +4 -0
- package/dist/distributions/t.d.ts +18 -0
- package/dist/distributions/t.js +18 -0
- package/dist/distributions/triangular.d.ts +36 -4
- package/dist/distributions/triangular.js +31 -3
- package/dist/distributions/tukey.d.ts +15 -1
- package/dist/distributions/tukey.js +10 -0
- package/dist/distributions/uniform.d.ts +29 -1
- package/dist/distributions/uniform.js +24 -0
- package/dist/distributions/weibull.d.ts +29 -1
- package/dist/distributions/weibull.js +24 -0
- package/dist/distributions/wilcox.d.ts +24 -0
- package/dist/distributions/wilcox.js +24 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +1 -1
- package/dist/entries/numerics.d.ts +1 -1
- package/dist/entries/tests.js +1 -1
- package/dist/htest/agreement.d.ts +61 -23
- package/dist/htest/agreement.js +19 -9
- package/dist/htest/ansariTest.d.ts +8 -2
- package/dist/htest/aov.d.ts +43 -10
- package/dist/htest/aov.js +17 -3
- package/dist/htest/binomTest.d.ts +12 -2
- package/dist/htest/binomTest.js +2 -0
- package/dist/htest/brunnerMunzelTest.d.ts +9 -3
- package/dist/htest/brunnerMunzelTest.js +4 -2
- package/dist/htest/chisqTest.d.ts +19 -3
- package/dist/htest/cor.d.ts +20 -4
- package/dist/htest/effectSize.d.ts +70 -12
- package/dist/htest/effectSize.js +40 -7
- package/dist/htest/fisherTest.d.ts +9 -1
- package/dist/htest/fisherTest.js +2 -0
- package/dist/htest/groups.d.ts +5 -1
- package/dist/htest/ksTest.d.ts +20 -3
- package/dist/htest/leveneTest.d.ts +15 -4
- package/dist/htest/leveneTest.js +5 -2
- package/dist/htest/mantelhaenTest.d.ts +25 -3
- package/dist/htest/mantelhaenTest.js +15 -1
- package/dist/htest/mcnemarTest.d.ts +14 -4
- package/dist/htest/mcnemarTest.js +4 -2
- package/dist/htest/multipleComparisons.d.ts +173 -29
- package/dist/htest/multipleComparisons.js +123 -19
- package/dist/htest/normalityTests.d.ts +56 -9
- package/dist/htest/normalityTests.js +40 -6
- package/dist/htest/onewayTest.d.ts +32 -3
- package/dist/htest/onewayTest.js +10 -0
- package/dist/htest/pAdjust.d.ts +9 -1
- package/dist/htest/pAdjust.js +2 -0
- package/dist/htest/pairwise.d.ts +50 -5
- package/dist/htest/pairwise.js +25 -0
- package/dist/htest/poissonTest.d.ts +12 -2
- package/dist/htest/poissonTest.js +2 -0
- package/dist/htest/polycor.d.ts +29 -10
- package/dist/htest/power.d.ts +60 -6
- package/dist/htest/power.js +6 -0
- package/dist/htest/propTest.d.ts +13 -2
- package/dist/htest/propTest.js +2 -0
- package/dist/htest/pwr.d.ts +286 -36
- package/dist/htest/pwr.js +116 -15
- package/dist/htest/rankTests.d.ts +80 -12
- package/dist/htest/rankTests.js +11 -2
- package/dist/htest/tTest.d.ts +13 -3
- package/dist/htest/trendTests.d.ts +29 -8
- package/dist/htest/trendTests.js +8 -4
- package/dist/htest/types.d.ts +14 -2
- package/dist/htest/varTest.d.ts +25 -8
- package/dist/htest/wilcoxTest.d.ts +10 -2
- package/dist/internal/dpq.d.ts +4 -0
- package/dist/internal/noncentral.d.ts +2 -0
- package/dist/internal/vectorize.d.ts +4 -0
- package/dist/linalg/basic.d.ts +39 -5
- package/dist/linalg/basic.js +15 -0
- package/dist/linalg/chol.d.ts +26 -5
- package/dist/linalg/chol.js +7 -0
- package/dist/linalg/eigen.d.ts +16 -7
- package/dist/linalg/eigen.js +6 -5
- package/dist/linalg/expm.d.ts +15 -5
- package/dist/linalg/expm.js +5 -3
- package/dist/linalg/kappa.d.ts +21 -1
- package/dist/linalg/kappa.js +16 -0
- package/dist/linalg/lu.d.ts +30 -6
- package/dist/linalg/lu.js +15 -3
- package/dist/linalg/matrix.d.ts +4 -0
- package/dist/linalg/norm.d.ts +16 -1
- package/dist/linalg/norm.js +9 -0
- package/dist/linalg/ops.d.ts +156 -35
- package/dist/linalg/ops.js +96 -15
- package/dist/linalg/qr.d.ts +87 -12
- package/dist/linalg/qr.js +31 -0
- package/dist/linalg/schur.d.ts +8 -2
- package/dist/linalg/schur.js +3 -1
- package/dist/linalg/solve.d.ts +42 -6
- package/dist/linalg/solve.js +22 -0
- package/dist/linalg/svd.d.ts +12 -2
- package/dist/linalg/svd.js +2 -0
- package/dist/linalg.js +2 -2
- package/dist/models/anovaSequential.d.ts +26 -4
- package/dist/models/anovaSequential.js +3 -1
- package/dist/models/aovEz.d.ts +29 -6
- package/dist/models/aovEz.js +5 -2
- package/dist/models/aovStrata.d.ts +12 -2
- package/dist/models/carAnova.d.ts +9 -3
- package/dist/models/carAnova.js +4 -2
- package/dist/models/coxph.d.ts +33 -7
- package/dist/models/coxph.js +8 -3
- package/dist/models/glm.d.ts +128 -21
- package/dist/models/glm.js +71 -14
- package/dist/models/glmAnova.d.ts +30 -5
- package/dist/models/glmAnova.js +15 -2
- package/dist/models/glmConfint.d.ts +16 -2
- package/dist/models/glmConfint.js +9 -1
- package/dist/models/glmFamily.d.ts +27 -5
- package/dist/models/lm.d.ts +75 -17
- package/dist/models/lm.js +22 -4
- package/dist/models/mauchly.d.ts +20 -5
- package/dist/models/mauchly.js +7 -3
- package/dist/models/modelFrame.d.ts +5 -1
- package/dist/models/modelMatrix.d.ts +18 -4
- package/dist/models/modelMatrix.js +3 -1
- package/dist/models/survival.d.ts +41 -9
- package/dist/models/survival.js +10 -4
- package/dist/numerics/deriv.d.ts +21 -6
- package/dist/numerics/deriv.js +16 -5
- package/dist/numerics/integrate.d.ts +37 -7
- package/dist/numerics/integrate.js +8 -2
- package/dist/numerics/interp.d.ts +63 -12
- package/dist/numerics/interp.js +30 -6
- package/dist/numerics/ode.d.ts +15 -5
- package/dist/numerics/ode.js +5 -3
- package/dist/numerics.js +2 -2
- package/dist/optim/optim.d.ts +32 -8
- package/dist/optim/optim.js +8 -4
- package/dist/random/beta.d.ts +8 -0
- package/dist/random/beta.js +8 -0
- package/dist/random/binomial.d.ts +16 -0
- package/dist/random/binomial.js +16 -0
- package/dist/random/continuous.d.ts +51 -0
- package/dist/random/continuous.js +51 -0
- package/dist/random/extra.d.ts +66 -6
- package/dist/random/extra.js +66 -6
- package/dist/random/gamma.d.ts +33 -0
- package/dist/random/gamma.js +33 -0
- package/dist/random/hyper.d.ts +8 -0
- package/dist/random/hyper.js +8 -0
- package/dist/random/poisson.d.ts +25 -0
- package/dist/random/poisson.js +25 -0
- package/dist/random/r2dtable.d.ts +2 -0
- package/dist/random/r2dtable.js +2 -0
- package/dist/random/rank.d.ts +16 -0
- package/dist/random/rank.js +16 -0
- package/dist/random/rng.d.ts +49 -6
- package/dist/random/rng.js +29 -2
- package/dist/random/sample.d.ts +10 -2
- package/dist/random/sample.js +5 -1
- package/dist/random/streams.d.ts +13 -0
- package/dist/random/streams.js +13 -0
- package/dist/rstats.js +1 -1
- package/dist/special/besselIK.d.ts +11 -3
- package/dist/special/besselIK.js +6 -2
- package/dist/special/besselJY.d.ts +6 -2
- package/dist/special/besselJY.js +6 -2
- package/dist/special/beta.d.ts +16 -2
- package/dist/special/beta.js +16 -2
- package/dist/special/choose.d.ts +13 -5
- package/dist/special/choose.js +13 -5
- package/dist/special/erf.d.ts +8 -3
- package/dist/special/erf.js +8 -3
- package/dist/special/extra.d.ts +30 -10
- package/dist/special/extra.js +25 -9
- package/dist/special/gamma.d.ts +18 -2
- package/dist/special/gamma.js +18 -2
- package/dist/special/log1p.d.ts +16 -7
- package/dist/special/log1p.js +16 -7
- package/dist/special/psigamma.d.ts +9 -3
- package/dist/special/psigamma.js +9 -3
- package/dist/special/rCompatible.d.ts +5 -1
- package/dist/special.js +2 -2
- package/dist/tests.js +2 -2
- package/llms.txt +2 -0
- package/package.json +1 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { AovStrataFit, AovStratum } from "./aovStrata.js";
|
|
2
2
|
import type { LmFormulaResult } from "./lm.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* An analysis of variance table, in the form of R's printed table.
|
|
5
|
+
*
|
|
6
|
+
* @category Linear models and ANOVA
|
|
7
|
+
*/
|
|
4
8
|
export interface AnovaTable {
|
|
5
9
|
/** R's column names, such as `"Df"`, `"Sum Sq"`, `"Mean Sq"`, `"F value"`, `"Pr(>F)"`. */
|
|
6
10
|
colNames: string[];
|
|
@@ -22,7 +26,7 @@ export declare function sequentialTerms(fit: LmFormulaResult): {
|
|
|
22
26
|
rss: number;
|
|
23
27
|
};
|
|
24
28
|
/**
|
|
25
|
-
* Analysis of variance of linear models fitted from a formula. With one fit, the table of sequential (type I) sums
|
|
29
|
+
* Analysis of variance of linear models fitted from a formula. Equivalent to R's `anova()`. With one fit, the table of sequential (type I) sums
|
|
26
30
|
* of squares, equivalent to R's `anova(fit)`: one row per term (the intercept left out), in the order of the model,
|
|
27
31
|
* and `Residuals`. With several fits, the comparison of the models in the order given, equivalent to R's
|
|
28
32
|
* `anova(fit1, fit2, ...)`: columns `Res.Df`, `RSS`, `Df`, `Sum of Sq`, `F`, `Pr(>F)`, the F tests scaled by the
|
|
@@ -37,21 +41,39 @@ export declare function sequentialTerms(fit: LmFormulaResult): {
|
|
|
37
41
|
* const t = anova(lm("y ~ g", data));
|
|
38
42
|
* t.rowNames; // ["g", "Residuals"]
|
|
39
43
|
* ```
|
|
44
|
+
*
|
|
45
|
+
* @category Linear models and ANOVA
|
|
40
46
|
*/
|
|
41
47
|
export declare function anova(fit: LmFormulaResult, ...fits: LmFormulaResult[]): AnovaTable;
|
|
42
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Result of {@link aovSummary} for a fit with error strata.
|
|
50
|
+
*
|
|
51
|
+
* @category Linear models and ANOVA
|
|
52
|
+
*/
|
|
43
53
|
export interface AovStrataSummary {
|
|
44
54
|
/** The table of each stratum, in order, without the intercept stratum. */
|
|
45
55
|
strata: AovStratum[];
|
|
56
|
+
/** Warnings of the summary (empty; the fit's warnings are in its own `warnings`). */
|
|
46
57
|
warnings: string[];
|
|
47
58
|
}
|
|
48
59
|
/**
|
|
49
|
-
* The table of
|
|
60
|
+
* The table of an analysis of variance fitted by {@link aov}. Equivalent to R's `summary()`. As R's
|
|
61
|
+
* `summary(aov(formula, data))` for a fit without `Error()`: the rows of {@link anova}'s
|
|
50
62
|
* sequential table, except that without residual degrees of freedom there is no `Residuals` row and no `F value` and
|
|
51
63
|
* `Pr(>F)` columns. For a fit with an `Error()` term, the tables of the strata (`{ strata: [{ stratum: "Error: id",
|
|
52
64
|
* colNames, rowNames, table }, ...] }`), without the intercept stratum.
|
|
53
65
|
*
|
|
54
66
|
* @param fit A fit from {@link aov} (or {@link lm}) with a formula.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const fit = aov("y ~ g", { y: [4.2, 5.1, 6.3, 5.8, 7.9, 8.4], g: ["a", "a", "b", "b", "c", "c"] });
|
|
71
|
+
* const t = aovSummary(fit);
|
|
72
|
+
* t.colNames; // ["Df", "Sum Sq", "Mean Sq", "F value", "Pr(>F)"]
|
|
73
|
+
* t.table[0]; // [2, 12.413, 6.2067, 28.427, 0.011221]
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @category Linear models and ANOVA
|
|
55
77
|
*/
|
|
56
78
|
export declare function aovSummary(fit: AovStrataFit): AovStrataSummary;
|
|
57
79
|
export declare function aovSummary(fit: LmFormulaResult): AnovaTable;
|
|
@@ -81,7 +81,7 @@ function comparisonTable(fits) {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
* Analysis of variance of linear models fitted from a formula. With one fit, the table of sequential (type I) sums
|
|
84
|
+
* Analysis of variance of linear models fitted from a formula. Equivalent to R's `anova()`. With one fit, the table of sequential (type I) sums
|
|
85
85
|
* of squares, equivalent to R's `anova(fit)`: one row per term (the intercept left out), in the order of the model,
|
|
86
86
|
* and `Residuals`. With several fits, the comparison of the models in the order given, equivalent to R's
|
|
87
87
|
* `anova(fit1, fit2, ...)`: columns `Res.Df`, `RSS`, `Df`, `Sum of Sq`, `F`, `Pr(>F)`, the F tests scaled by the
|
|
@@ -96,6 +96,8 @@ function comparisonTable(fits) {
|
|
|
96
96
|
* const t = anova(lm("y ~ g", data));
|
|
97
97
|
* t.rowNames; // ["g", "Residuals"]
|
|
98
98
|
* ```
|
|
99
|
+
*
|
|
100
|
+
* @category Linear models and ANOVA
|
|
99
101
|
*/
|
|
100
102
|
export function anova(fit, ...fits) {
|
|
101
103
|
const all = [fit, ...fits];
|
package/dist/models/aovEz.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { type DataFrame } from "./modelFrame.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* An effect size of {@link aovEz}: generalized (`"ges"`) or partial (`"pes"`) eta squared.
|
|
4
|
+
*
|
|
5
|
+
* @category Linear models and ANOVA
|
|
6
|
+
*/
|
|
3
7
|
export type AovEzEffectSize = "ges" | "pes";
|
|
4
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Options for {@link aovEz}.
|
|
10
|
+
*
|
|
11
|
+
* @category Linear models and ANOVA
|
|
12
|
+
*/
|
|
5
13
|
export interface AovEzOptions {
|
|
6
14
|
/** Column of the subject identifiers. */
|
|
7
15
|
id: string;
|
|
@@ -20,13 +28,24 @@ export interface AovEzOptions {
|
|
|
20
28
|
/** Observed (not manipulated) factors, for the generalized eta squared. */
|
|
21
29
|
observed?: readonly string[] | string;
|
|
22
30
|
}
|
|
23
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* A table of {@link aovEz}.
|
|
33
|
+
*
|
|
34
|
+
* @category Linear models and ANOVA
|
|
35
|
+
*/
|
|
24
36
|
export interface AovEzTable {
|
|
37
|
+
/** Column names, such as afex's `"num Df"`, `"den Df"`, `"MSE"`, `"F"`, `"ges"`, `"Pr(>F)"`. */
|
|
25
38
|
colNames: string[];
|
|
39
|
+
/** Row names: the terms (and `"(Intercept)"` in car's tables). */
|
|
26
40
|
rowNames: string[];
|
|
41
|
+
/** One array per row, one value per column. */
|
|
27
42
|
table: number[][];
|
|
28
43
|
}
|
|
29
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Result of {@link aovEz}.
|
|
46
|
+
*
|
|
47
|
+
* @category Linear models and ANOVA
|
|
48
|
+
*/
|
|
30
49
|
export interface AovEzResult {
|
|
31
50
|
/** afex's anova table (without the intercept). */
|
|
32
51
|
anova: AovEzTable;
|
|
@@ -38,11 +57,13 @@ export interface AovEzResult {
|
|
|
38
57
|
sphericity?: AovEzTable;
|
|
39
58
|
/** The within-subject factors (columns), as given. */
|
|
40
59
|
within: string[];
|
|
60
|
+
/** afex's and car's warnings (averaged cells, removed subjects, `HF eps > 1 treated as 1`, ...). */
|
|
41
61
|
warnings: string[];
|
|
42
62
|
}
|
|
43
63
|
/**
|
|
44
|
-
* Repeated-measures (within-subjects), between-subjects and mixed analysis of variance from long data
|
|
45
|
-
* `aov_ez(
|
|
64
|
+
* Repeated-measures (within-subjects), between-subjects and mixed analysis of variance from long data. Equivalent to
|
|
65
|
+
* `afex::aov_ez()` in R. As afex's
|
|
66
|
+
* `aov_ez(id, dv, data, between, within, type, observed, anova_table = list(correction, es))`, it returns afex's
|
|
46
67
|
* anova table and car's univariate tests, sphericity corrections (Greenhouse-Geisser, Huynh-Feldt) and Mauchly tests.
|
|
47
68
|
*
|
|
48
69
|
* Between-subjects factors use `contr.sum` and sorted levels; the levels of within-subjects factors are taken in order
|
|
@@ -60,5 +81,7 @@ export interface AovEzResult {
|
|
|
60
81
|
* };
|
|
61
82
|
* aovEz(data, { id: "id", dv: "y", within: "W" }).anova.rowNames; // ["W"]
|
|
62
83
|
* ```
|
|
84
|
+
*
|
|
85
|
+
* @category Linear models and ANOVA
|
|
63
86
|
*/
|
|
64
87
|
export declare function aovEz(data: DataFrame, options: AovEzOptions): AovEzResult;
|
package/dist/models/aovEz.js
CHANGED
|
@@ -59,8 +59,9 @@ function anovaTable(rows, errorSS, es, observed) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Repeated-measures (within-subjects), between-subjects and mixed analysis of variance from long data
|
|
63
|
-
* `aov_ez(
|
|
62
|
+
* Repeated-measures (within-subjects), between-subjects and mixed analysis of variance from long data. Equivalent to
|
|
63
|
+
* `afex::aov_ez()` in R. As afex's
|
|
64
|
+
* `aov_ez(id, dv, data, between, within, type, observed, anova_table = list(correction, es))`, it returns afex's
|
|
64
65
|
* anova table and car's univariate tests, sphericity corrections (Greenhouse-Geisser, Huynh-Feldt) and Mauchly tests.
|
|
65
66
|
*
|
|
66
67
|
* Between-subjects factors use `contr.sum` and sorted levels; the levels of within-subjects factors are taken in order
|
|
@@ -78,6 +79,8 @@ function anovaTable(rows, errorSS, es, observed) {
|
|
|
78
79
|
* };
|
|
79
80
|
* aovEz(data, { id: "id", dv: "y", within: "W" }).anova.rowNames; // ["W"]
|
|
80
81
|
* ```
|
|
82
|
+
*
|
|
83
|
+
* @category Linear models and ANOVA
|
|
81
84
|
*/
|
|
82
85
|
export function aovEz(data, options) {
|
|
83
86
|
const between = list(options.between);
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import type { FormulaNode, ParsedFormula } from "./formula.js";
|
|
2
2
|
import type { LmFormulaOptions } from "./lm.js";
|
|
3
3
|
import type { DataFrame } from "./modelFrame.js";
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The table of one error stratum, as `summary(aov(...))` prints it.
|
|
6
|
+
*
|
|
7
|
+
* @category Linear models and ANOVA
|
|
8
|
+
*/
|
|
5
9
|
export interface AovStratum {
|
|
6
10
|
/** `"Error: id"`, `"Error: id:W"`, `"Error: Within"`. */
|
|
7
11
|
stratum: string;
|
|
12
|
+
/** R's column names: `"Df"`, `"Sum Sq"`, `"Mean Sq"`, and `"F value"`, `"Pr(>F)"` when there are residuals. */
|
|
8
13
|
colNames: string[];
|
|
14
|
+
/** Row names: the labels of the terms in the stratum, then `"Residuals"` when its df is positive. */
|
|
9
15
|
rowNames: string[];
|
|
10
16
|
/** One array per row; NaN where R prints nothing. */
|
|
11
17
|
table: number[][];
|
|
12
18
|
}
|
|
13
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Result of {@link aov} with an `Error()` term.
|
|
21
|
+
*
|
|
22
|
+
* @category Linear models and ANOVA
|
|
23
|
+
*/
|
|
14
24
|
export interface AovStrataFit {
|
|
15
25
|
/** The formula. */
|
|
16
26
|
formula: string;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { AnovaTable } from "./anovaSequential.js";
|
|
2
2
|
import type { LmFormulaResult } from "./lm.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link Anova}.
|
|
5
|
+
*
|
|
6
|
+
* @category Linear models and ANOVA
|
|
7
|
+
*/
|
|
4
8
|
export interface AnovaOptions {
|
|
5
9
|
/** The type of the tests: 2 (default, as car) or 3; `"II"` and `"III"` are accepted too. */
|
|
6
10
|
type?: 2 | 3 | "II" | "III";
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
|
-
* Type II or type III tests of the terms of a linear model
|
|
10
|
-
* for an `lm` fit
|
|
13
|
+
* Type II or type III tests of the terms of a linear model. Equivalent to `car::Anova()` in R. As
|
|
14
|
+
* `car::Anova(fit, type = 2)` or `type = 3` for an `lm` fit: columns `Sum Sq`, `Df`, `F value`, `Pr(>F)`; rows the terms (type III: `(Intercept)` first when the
|
|
11
15
|
* model has one) and `Residuals`.
|
|
12
16
|
*
|
|
13
17
|
* Type II tests each term after all the others except the terms that contain it (car's marginality; it does not
|
|
@@ -26,5 +30,7 @@ export interface AnovaOptions {
|
|
|
26
30
|
* const t = Anova(lm("y ~ A * B", data, { contrasts: { A: "contr.sum", B: "contr.sum" } }), { type: 3 });
|
|
27
31
|
* t.rowNames; // ["(Intercept)", "A", "B", "A:B", "Residuals"]
|
|
28
32
|
* ```
|
|
33
|
+
*
|
|
34
|
+
* @category Linear models and ANOVA
|
|
29
35
|
*/
|
|
30
36
|
export declare function Anova(fit: LmFormulaResult, options?: AnovaOptions): AnovaTable;
|
package/dist/models/carAnova.js
CHANGED
|
@@ -38,8 +38,8 @@ function addedSS(fit, base, added) {
|
|
|
38
38
|
return { ss: ss[0], df };
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
* Type II or type III tests of the terms of a linear model
|
|
42
|
-
* for an `lm` fit
|
|
41
|
+
* Type II or type III tests of the terms of a linear model. Equivalent to `car::Anova()` in R. As
|
|
42
|
+
* `car::Anova(fit, type = 2)` or `type = 3` for an `lm` fit: columns `Sum Sq`, `Df`, `F value`, `Pr(>F)`; rows the terms (type III: `(Intercept)` first when the
|
|
43
43
|
* model has one) and `Residuals`.
|
|
44
44
|
*
|
|
45
45
|
* Type II tests each term after all the others except the terms that contain it (car's marginality; it does not
|
|
@@ -58,6 +58,8 @@ function addedSS(fit, base, added) {
|
|
|
58
58
|
* const t = Anova(lm("y ~ A * B", data, { contrasts: { A: "contr.sum", B: "contr.sum" } }), { type: 3 });
|
|
59
59
|
* t.rowNames; // ["(Intercept)", "A", "B", "A:B", "Residuals"]
|
|
60
60
|
* ```
|
|
61
|
+
*
|
|
62
|
+
* @category Linear models and ANOVA
|
|
61
63
|
*/
|
|
62
64
|
export function Anova(fit, options = {}) {
|
|
63
65
|
if (typeof fit !== "object" || fit === null || !Array.isArray(fit.effects)) {
|
package/dist/models/coxph.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { GroupLabel } from "../htest/groups.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Control of the Newton-Raphson iterations of {@link coxph} (R's `coxph.control`).
|
|
4
|
+
*
|
|
5
|
+
* @category Survival analysis
|
|
6
|
+
*/
|
|
3
7
|
export interface CoxphControl {
|
|
4
8
|
/** Convergence tolerance on the relative change of the log partial likelihood. Default 1e-9. */
|
|
5
9
|
eps?: number;
|
|
@@ -10,7 +14,11 @@ export interface CoxphControl {
|
|
|
10
14
|
/** Tolerance of the check for infinite coefficients. Default sqrt(`eps`). */
|
|
11
15
|
tolerInf?: number;
|
|
12
16
|
}
|
|
13
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Options for {@link coxph}.
|
|
19
|
+
*
|
|
20
|
+
* @category Survival analysis
|
|
21
|
+
*/
|
|
14
22
|
export interface CoxphOptions {
|
|
15
23
|
/** Handling of tied event times. Default `"efron"`. */
|
|
16
24
|
ties?: "efron" | "breslow";
|
|
@@ -27,13 +35,24 @@ export interface CoxphOptions {
|
|
|
27
35
|
/** Confidence level of the intervals of exp(coef). Default 0.95. */
|
|
28
36
|
confLevel?: number;
|
|
29
37
|
}
|
|
30
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* A test statistic with its degrees of freedom and upper chi-squared tail.
|
|
40
|
+
*
|
|
41
|
+
* @category Survival analysis
|
|
42
|
+
*/
|
|
31
43
|
export interface CoxphTest {
|
|
44
|
+
/** The chi-squared statistic (R's `test`). */
|
|
32
45
|
statistic: number;
|
|
46
|
+
/** Degrees of freedom (R's `df`). */
|
|
33
47
|
df: number;
|
|
48
|
+
/** Upper chi-squared tail (R's `pvalue`). */
|
|
34
49
|
pValue: number;
|
|
35
50
|
}
|
|
36
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Result of {@link coxph}.
|
|
53
|
+
*
|
|
54
|
+
* @category Survival analysis
|
|
55
|
+
*/
|
|
37
56
|
export interface CoxphResult {
|
|
38
57
|
/** Coefficients (NaN for R's NA: an aliased column or one whose information fell below the tolerance) */
|
|
39
58
|
coefficients: number[];
|
|
@@ -73,15 +92,18 @@ export interface CoxphResult {
|
|
|
73
92
|
waldtest: CoxphTest;
|
|
74
93
|
/** R^2 (1 - exp(-logtest / n)) and its maximum (1 - exp(2 loglik[0] / n)) */
|
|
75
94
|
rsq: {
|
|
95
|
+
/** R^2, 1 - exp(-logtest / n) (R's `rsq`). */
|
|
76
96
|
rsq: number;
|
|
97
|
+
/** Its maximum, 1 - exp(2 loglik[0] / n) (R's `maxrsq`). */
|
|
77
98
|
maxrsq: number;
|
|
78
99
|
};
|
|
79
100
|
/** R's warnings, each once, in order of first appearance. */
|
|
80
101
|
warnings: string[];
|
|
81
102
|
}
|
|
82
103
|
/**
|
|
83
|
-
* Cox proportional hazards regression. Equivalent to R's `coxph(
|
|
84
|
-
* ties, init, control)`
|
|
104
|
+
* Cox proportional hazards regression. Equivalent to R's `survival::coxph()`. As
|
|
105
|
+
* `coxph(Surv(time, status) ~ x [+ strata(strata)], weights, ties, init, control)` for right-censored data, with the
|
|
106
|
+
* values of `summary(fit)`.
|
|
85
107
|
*
|
|
86
108
|
* Rows with a missing time, status, covariate, weight or stratum are dropped. Times within sqrt(eps) of each other are
|
|
87
109
|
* treated as tied. Covariates whose values all lie in `nocenter` are not centred; the others are centred by their
|
|
@@ -95,7 +117,11 @@ export interface CoxphResult {
|
|
|
95
117
|
*
|
|
96
118
|
* @example
|
|
97
119
|
* ```ts
|
|
98
|
-
* coxph([5, 3, 8, 1, 9, 4], [1, 1, 0, 1, 0, 1], [[1.2], [0.3], [-0.5], [2], [0.7], [0.1]])
|
|
120
|
+
* const fit = coxph([5, 3, 8, 1, 9, 4], [1, 1, 0, 1, 0, 1], [[1.2], [0.3], [-0.5], [2], [0.7], [0.1]]);
|
|
121
|
+
* fit.coefficients; // [1.0324]
|
|
122
|
+
* fit.logtest.pValue; // 0.18817
|
|
99
123
|
* ```
|
|
124
|
+
*
|
|
125
|
+
* @category Survival analysis
|
|
100
126
|
*/
|
|
101
127
|
export declare function coxph(time: readonly number[], status: readonly number[], x: readonly (readonly number[])[], options?: CoxphOptions): CoxphResult;
|
package/dist/models/coxph.js
CHANGED
|
@@ -233,8 +233,9 @@ const chisqTest = (statistic, df) => ({
|
|
|
233
233
|
pValue: pchisq(statistic, df, { lowerTail: false }),
|
|
234
234
|
});
|
|
235
235
|
/**
|
|
236
|
-
* Cox proportional hazards regression. Equivalent to R's `coxph(
|
|
237
|
-
* ties, init, control)`
|
|
236
|
+
* Cox proportional hazards regression. Equivalent to R's `survival::coxph()`. As
|
|
237
|
+
* `coxph(Surv(time, status) ~ x [+ strata(strata)], weights, ties, init, control)` for right-censored data, with the
|
|
238
|
+
* values of `summary(fit)`.
|
|
238
239
|
*
|
|
239
240
|
* Rows with a missing time, status, covariate, weight or stratum are dropped. Times within sqrt(eps) of each other are
|
|
240
241
|
* treated as tied. Covariates whose values all lie in `nocenter` are not centred; the others are centred by their
|
|
@@ -248,8 +249,12 @@ const chisqTest = (statistic, df) => ({
|
|
|
248
249
|
*
|
|
249
250
|
* @example
|
|
250
251
|
* ```ts
|
|
251
|
-
* coxph([5, 3, 8, 1, 9, 4], [1, 1, 0, 1, 0, 1], [[1.2], [0.3], [-0.5], [2], [0.7], [0.1]])
|
|
252
|
+
* const fit = coxph([5, 3, 8, 1, 9, 4], [1, 1, 0, 1, 0, 1], [[1.2], [0.3], [-0.5], [2], [0.7], [0.1]]);
|
|
253
|
+
* fit.coefficients; // [1.0324]
|
|
254
|
+
* fit.logtest.pValue; // 0.18817
|
|
252
255
|
* ```
|
|
256
|
+
*
|
|
257
|
+
* @category Survival analysis
|
|
253
258
|
*/
|
|
254
259
|
export function coxph(time, status, x, options = {}) {
|
|
255
260
|
const { ties = "efron", weights, strata, init, control = {}, nocenter = [-1, 0, 1], confLevel = 0.95 } = options;
|
package/dist/models/glm.d.ts
CHANGED
|
@@ -3,7 +3,11 @@ import { type QR } from "../linalg/qr.js";
|
|
|
3
3
|
import type { Sample } from "../htest/types.js";
|
|
4
4
|
import { Warnings, type Family, type GlmFamilyName, type GlmFamilySpec, type GlmLink } from "./glmFamily.js";
|
|
5
5
|
export type { GlmFamilyName, GlmFamilySpec, GlmLink, GlmLinkName, QuasiVariance } from "./glmFamily.js";
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Options for {@link glm}.
|
|
8
|
+
*
|
|
9
|
+
* @category Generalized linear models
|
|
10
|
+
*/
|
|
7
11
|
export interface GlmOptions {
|
|
8
12
|
/**
|
|
9
13
|
* The family: a name (`"gaussian"`, the default, `"binomial"`, `"quasibinomial"`, `"poisson"`, `"quasipoisson"`,
|
|
@@ -26,7 +30,11 @@ export interface GlmOptions {
|
|
|
26
30
|
/** Include an intercept (a column of ones before the columns of `x`). Default `true`. */
|
|
27
31
|
intercept?: boolean;
|
|
28
32
|
}
|
|
29
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The data and settings of a fit, kept for the refits of {@link glmConfint} and {@link glmAnova}.
|
|
35
|
+
*
|
|
36
|
+
* @category Generalized linear models
|
|
37
|
+
*/
|
|
30
38
|
export interface GlmModel {
|
|
31
39
|
/** Model matrix (with the column of ones), rows with a missing value dropped. */
|
|
32
40
|
x: number[][];
|
|
@@ -36,31 +44,48 @@ export interface GlmModel {
|
|
|
36
44
|
yGiven: number[] | number[][];
|
|
37
45
|
/** Prior weights as given (1 when not given). */
|
|
38
46
|
priorGiven: number[];
|
|
47
|
+
/** Offset, one per row (0 when not given). */
|
|
39
48
|
offset: number[];
|
|
40
49
|
/** Whether an offset was given. */
|
|
41
50
|
hasOffset: boolean;
|
|
51
|
+
/** Whether the model has an intercept. */
|
|
42
52
|
intercept: boolean;
|
|
53
|
+
/** The family and link of the fit. */
|
|
43
54
|
familySpec: GlmFamilySpec;
|
|
55
|
+
/** Convergence tolerance (R's `glm.control(epsilon)`). */
|
|
44
56
|
epsilon: number;
|
|
57
|
+
/** Maximum number of iterations (R's `glm.control(maxit)`). */
|
|
45
58
|
maxit: number;
|
|
59
|
+
/** Starting coefficients, if given. */
|
|
46
60
|
start: number[] | undefined;
|
|
47
61
|
}
|
|
48
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Result of {@link glm}: R's `glm` object.
|
|
64
|
+
*
|
|
65
|
+
* @category Generalized linear models
|
|
66
|
+
*/
|
|
49
67
|
export interface GlmResult {
|
|
50
68
|
/** Coefficients (intercept first); NaN for aliased columns. */
|
|
51
69
|
coefficients: number[];
|
|
52
70
|
/** Fitted means, one per row (rows with a missing value dropped). */
|
|
53
71
|
fittedValues: number[];
|
|
72
|
+
/** Linear predictors, one per row, offset included (R's `linear.predictors`). */
|
|
54
73
|
linearPredictors: number[];
|
|
74
|
+
/** Residual deviance. */
|
|
55
75
|
deviance: number;
|
|
76
|
+
/** Deviance of the model with the intercept only, or of the empty model without intercept (R's `null.deviance`). */
|
|
56
77
|
nullDeviance: number;
|
|
57
78
|
/** AIC; NaN for the quasi families. */
|
|
58
79
|
aic: number;
|
|
80
|
+
/** Numerical rank of the model matrix. */
|
|
59
81
|
rank: number;
|
|
82
|
+
/** Residual degrees of freedom (R's `df.residual`). */
|
|
60
83
|
dfResidual: number;
|
|
84
|
+
/** Degrees of freedom of the null deviance (R's `df.null`). */
|
|
61
85
|
dfNull: number;
|
|
62
86
|
/** Number of iterations. */
|
|
63
87
|
iter: number;
|
|
88
|
+
/** Whether the iterations converged. */
|
|
64
89
|
converged: boolean;
|
|
65
90
|
/** Whether the step was truncated (halved) in the last iteration. */
|
|
66
91
|
boundary: boolean;
|
|
@@ -74,11 +99,13 @@ export interface GlmResult {
|
|
|
74
99
|
residuals: number[];
|
|
75
100
|
/** The family's name and the link's name (`"mu^0.333"` for a power link). */
|
|
76
101
|
family: GlmFamilyName;
|
|
102
|
+
/** The link's name, such as `"logit"`. */
|
|
77
103
|
link: string;
|
|
78
104
|
/** R's warnings, each once, in order of first appearance. */
|
|
79
105
|
warnings: string[];
|
|
80
106
|
/** QR decomposition of the last weighted least squares problem (undefined for a model without columns). */
|
|
81
107
|
qr: QR | undefined;
|
|
108
|
+
/** The data and settings of the fit, for the refits of {@link glmConfint} and {@link glmAnova}. */
|
|
82
109
|
model: GlmModel;
|
|
83
110
|
}
|
|
84
111
|
/** Input of the iteratively reweighted least squares (after the response has been read) */
|
|
@@ -137,7 +164,7 @@ export declare function refit(model: GlmModel, cols: number[], warnings: Warning
|
|
|
137
164
|
};
|
|
138
165
|
/**
|
|
139
166
|
* Fit a generalized linear model by iteratively reweighted least squares. Equivalent to R's
|
|
140
|
-
* `glm(y ~ x, family = ...)
|
|
167
|
+
* `glm(y ~ x, family = ...)`. Or `y ~ x - 1` without intercept; the predictors are given as a matrix instead of a
|
|
141
168
|
* formula. Rows with a missing value (NaN) in `x`, `y`, the weights or the offset are dropped. Every family and link
|
|
142
169
|
* of R's `stats` is available; R's warnings are returned in `warnings`. See {@link glmSummary}, {@link glmResiduals},
|
|
143
170
|
* {@link glmPredict}, {@link glmConfint} and {@link glmAnova} for the methods.
|
|
@@ -149,27 +176,41 @@ export declare function refit(model: GlmModel, cols: number[], warnings: Warning
|
|
|
149
176
|
* @example
|
|
150
177
|
* ```ts
|
|
151
178
|
* const fit = glm([1, 2, 3, 4, 5, 6], [0, 0, 1, 0, 1, 1], { family: "binomial" });
|
|
152
|
-
* fit.coefficients; // [
|
|
153
|
-
* glmSummary(fit).pValue;
|
|
179
|
+
* fit.coefficients; // [-4.2491, 1.214]
|
|
180
|
+
* glmSummary(fit).pValue; // [0.20976, 0.18341]
|
|
154
181
|
* ```
|
|
182
|
+
*
|
|
183
|
+
* @category Generalized linear models
|
|
155
184
|
*/
|
|
156
185
|
export declare function glm(x: MatrixInput | Sample, y: Sample | MatrixInput, options?: GlmOptions): GlmResult;
|
|
157
186
|
/** The family object of a fit */
|
|
158
187
|
export declare function familyOf(fit: GlmResult): Family;
|
|
159
188
|
/** Pearson dispersion of summary.glm (1 for binomial and poisson) */
|
|
160
189
|
export declare function glmDispersion(fit: GlmResult, warnings?: Warnings): number;
|
|
161
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* Options for {@link glmSummary}.
|
|
192
|
+
*
|
|
193
|
+
* @category Generalized linear models
|
|
194
|
+
*/
|
|
162
195
|
export interface GlmSummaryOptions {
|
|
163
196
|
/** Dispersion to use instead of the estimate (or 1 for binomial and poisson). */
|
|
164
197
|
dispersion?: number;
|
|
165
198
|
}
|
|
166
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Result of {@link glmSummary}: the quantities of R's `summary(glm)`.
|
|
201
|
+
*
|
|
202
|
+
* @category Generalized linear models
|
|
203
|
+
*/
|
|
167
204
|
export interface GlmSummary {
|
|
205
|
+
/** The dispersion used (estimated, given, or 1 for binomial and poisson). */
|
|
168
206
|
dispersion: number;
|
|
169
207
|
/** The coefficient table of the columns that are not aliased, in their order. */
|
|
170
208
|
estimate: number[];
|
|
209
|
+
/** Standard errors (R's `Std. Error`). */
|
|
171
210
|
stdError: number[];
|
|
211
|
+
/** z or t statistics (see `statisticName`). */
|
|
172
212
|
statistic: number[];
|
|
213
|
+
/** Two-sided p-values (R's `Pr(>|z|)` or `Pr(>|t|)`). */
|
|
173
214
|
pValue: number[];
|
|
174
215
|
/** `"z value"` when the dispersion is fixed (binomial, poisson), else `"t value"`. */
|
|
175
216
|
statisticName: "z value" | "t value";
|
|
@@ -177,35 +218,90 @@ export interface GlmSummary {
|
|
|
177
218
|
covUnscaled: number[][];
|
|
178
219
|
/** covUnscaled times the dispersion. */
|
|
179
220
|
covScaled: number[][];
|
|
221
|
+
/** Residual degrees of freedom (R's `df.residual`). */
|
|
180
222
|
dfResidual: number;
|
|
181
223
|
/** Warnings (such as "observations with zero weight not used for calculating dispersion"). */
|
|
182
224
|
warnings: string[];
|
|
183
225
|
}
|
|
184
226
|
/**
|
|
185
|
-
* Summary of a generalized linear model: the dispersion, the coefficient table and the covariance of the estimates
|
|
186
|
-
* Equivalent to R's `summary()
|
|
227
|
+
* Summary of a generalized linear model: the dispersion, the coefficient table and the covariance of the estimates,
|
|
228
|
+
* for a `glm` fit. Equivalent to R's `summary()`.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* const fit = glm([1, 2, 3, 4, 5, 6], [0, 0, 1, 0, 1, 1], { family: "binomial" });
|
|
233
|
+
* const s = glmSummary(fit);
|
|
234
|
+
* s.estimate; // [-4.2491, 1.214]
|
|
235
|
+
* s.stdError; // [3.3878, 0.91258]
|
|
236
|
+
* s.statisticName; // "z value"
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @category Generalized linear models
|
|
187
240
|
*/
|
|
188
241
|
export declare function glmSummary(fit: GlmResult, options?: GlmSummaryOptions): GlmSummary;
|
|
189
|
-
/**
|
|
242
|
+
/**
|
|
243
|
+
* Kinds of residuals of {@link glmResiduals}.
|
|
244
|
+
*
|
|
245
|
+
* @category Generalized linear models
|
|
246
|
+
*/
|
|
190
247
|
export type GlmResidualType = "deviance" | "pearson" | "working" | "response";
|
|
191
248
|
/**
|
|
192
|
-
* Residuals of a generalized linear model, one per row
|
|
193
|
-
* (
|
|
249
|
+
* Residuals of a generalized linear model, one per row, for a `glm` fit (default `"deviance"`). Equivalent to R's
|
|
250
|
+
* `residuals(fit, type)`.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* const fit = glm([1, 2, 3, 4, 5, 6], [0, 0, 1, 0, 1, 1], { family: "binomial" });
|
|
255
|
+
* glmResiduals(fit); // [-0.30644, -0.54776, 1.4436, -1.4436, 0.54776, 0.30644]
|
|
256
|
+
* glmResiduals(fit, "pearson"); // [-0.21925, -0.40231, 1.3546, -1.3546, 0.40231, 0.21925]
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* @category Generalized linear models
|
|
194
260
|
*/
|
|
195
261
|
export declare function glmResiduals(fit: GlmResult, type?: GlmResidualType): number[];
|
|
196
262
|
/**
|
|
197
|
-
* Diagonal of the hat matrix of the last weighted least squares step, for the rows of non-zero prior weight
|
|
198
|
-
* Equivalent to R's `hatvalues()
|
|
263
|
+
* Diagonal of the hat matrix of the last weighted least squares step, for the rows of non-zero prior weight, for a
|
|
264
|
+
* `glm` fit. Equivalent to R's `hatvalues()`.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* const fit = glm([1, 2, 3, 4, 5, 6], [0, 0, 1, 0, 1, 1], { family: "binomial" });
|
|
269
|
+
* glmHatvalues(fit); // [0.28361, 0.37762, 0.33877, 0.33877, 0.37762, 0.28361]
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* @category Generalized linear models
|
|
199
273
|
*/
|
|
200
274
|
export declare function glmHatvalues(fit: GlmResult): number[];
|
|
201
275
|
/**
|
|
202
|
-
* Standardized deviance residuals, for the rows of non-zero prior weight. Equivalent to R's
|
|
203
|
-
* `
|
|
276
|
+
* Standardized deviance residuals, for the rows of non-zero prior weight, for a `glm` fit. Equivalent to R's
|
|
277
|
+
* `rstandard()`.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* const fit = glm([1, 2, 3, 4, 5, 6], [0, 0, 1, 0, 1, 1], { family: "binomial" });
|
|
282
|
+
* glmRstandard(fit); // [-0.36205, -0.69432, 1.7753, -1.7753, 0.69432, 0.36205]
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* @category Generalized linear models
|
|
204
286
|
*/
|
|
205
287
|
export declare function glmRstandard(fit: GlmResult, options?: GlmSummaryOptions): number[];
|
|
206
|
-
/**
|
|
288
|
+
/**
|
|
289
|
+
* Cook's distances, for the rows of non-zero prior weight, for a `glm` fit. Equivalent to R's `cooks.distance()`.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* const fit = glm([1, 2, 3, 4, 5, 6], [0, 0, 1, 0, 1, 1], { family: "binomial" });
|
|
294
|
+
* glmCooksDistance(fit); // [0.013283, 0.078894, 0.71087, 0.71087, 0.078894, 0.013283]
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @category Generalized linear models
|
|
298
|
+
*/
|
|
207
299
|
export declare function glmCooksDistance(fit: GlmResult, options?: GlmSummaryOptions): number[];
|
|
208
|
-
/**
|
|
300
|
+
/**
|
|
301
|
+
* Options for {@link glmPredict}.
|
|
302
|
+
*
|
|
303
|
+
* @category Generalized linear models
|
|
304
|
+
*/
|
|
209
305
|
export interface GlmPredictOptions {
|
|
210
306
|
/** New predictor values, with the columns of `x` (no column of ones). Default: the data of the fit. */
|
|
211
307
|
newdata?: MatrixInput | Sample;
|
|
@@ -217,10 +313,21 @@ export interface GlmPredictOptions {
|
|
|
217
313
|
dispersion?: number;
|
|
218
314
|
}
|
|
219
315
|
/**
|
|
220
|
-
* Predictions of a generalized linear model with their standard errors. Equivalent to R's
|
|
221
|
-
* `predict(fit, newdata, type, se.fit = TRUE)
|
|
316
|
+
* Predictions of a generalized linear model with their standard errors, for a `glm` fit. Equivalent to R's
|
|
317
|
+
* `predict(fit, newdata, type, se.fit = TRUE)`. Aliased columns are left out, as R does.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```ts
|
|
321
|
+
* const fit = glm([1, 2, 3, 4, 5, 6], [0, 0, 1, 0, 1, 1], { family: "binomial" });
|
|
322
|
+
* glmPredict(fit, { newdata: [7] }); // { fit: [4.2491], seFit: [3.3878] }
|
|
323
|
+
* glmPredict(fit, { newdata: [7], type: "response" }).fit; // [0.98592]
|
|
324
|
+
* ```
|
|
325
|
+
*
|
|
326
|
+
* @category Generalized linear models
|
|
222
327
|
*/
|
|
223
328
|
export declare function glmPredict(fit: GlmResult, options?: GlmPredictOptions): {
|
|
329
|
+
/** Predictions on the scale of `type`, one per row. */
|
|
224
330
|
fit: number[];
|
|
331
|
+
/** Their standard errors (R's `se.fit`). */
|
|
225
332
|
seFit: number[];
|
|
226
333
|
};
|