@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
package/dist/htest/effectSize.js
CHANGED
|
@@ -93,20 +93,29 @@ function standardizedDifference(x, y, options, adjust) {
|
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Cohen's d: the standardized difference of means of two samples (pooled or averaged standard deviation), of paired
|
|
96
|
-
* samples, or of one sample against `mu`, with a confidence interval from the noncentral t distribution.
|
|
97
|
-
* to effectsize
|
|
96
|
+
* samples, or of one sample against `mu`, with a confidence interval from the noncentral t distribution.
|
|
97
|
+
* Equivalent to `effectsize::cohens_d()` in R.
|
|
98
98
|
*
|
|
99
99
|
* @example
|
|
100
100
|
* ```ts
|
|
101
101
|
* cohensD([5.1, 4.9, 6.2, 5.8], [4.1, 4.5, 3.9, 5.0]).value; // 2.049693834034246
|
|
102
102
|
* ```
|
|
103
|
+
*
|
|
104
|
+
* @category Effect sizes and power
|
|
103
105
|
*/
|
|
104
106
|
export function cohensD(x, y, options = {}) {
|
|
105
107
|
return standardizedDifference(x, y, options, options.adjust ?? false);
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
108
|
-
* Hedges' g: Cohen's d and its interval multiplied by the small-sample correction J(df). Equivalent to
|
|
109
|
-
* `hedges_g()
|
|
110
|
+
* Hedges' g: Cohen's d and its interval multiplied by the small-sample correction J(df). Equivalent to
|
|
111
|
+
* `effectsize::hedges_g()` in R.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* hedgesG([5.1, 4.9, 6.2, 5.8], [4.1, 4.5, 3.9, 5.0]).value; // 1.7804187661174387
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @category Effect sizes and power
|
|
110
119
|
*/
|
|
111
120
|
export function hedgesG(x, y, options = {}) {
|
|
112
121
|
return standardizedDifference(x, y, options, true);
|
|
@@ -353,7 +362,7 @@ function strataEffectSize(model, kind, options) {
|
|
|
353
362
|
}
|
|
354
363
|
/**
|
|
355
364
|
* Eta squared of the terms of an analysis-of-variance table (partial by default, or generalized), with confidence
|
|
356
|
-
* intervals from the noncentral F distribution. Equivalent to effectsize
|
|
365
|
+
* intervals from the noncentral F distribution. Equivalent to `effectsize::eta_squared()` in R. It takes a table of
|
|
357
366
|
* `anova()` or `Anova()`; a fit from `lm()` with a formula is replaced by its `anova()` table.
|
|
358
367
|
*
|
|
359
368
|
* Repeated measures: for a fit of `aov()` with an `Error()` term (or its {@link aovSummary}) each term is measured
|
|
@@ -362,23 +371,47 @@ function strataEffectSize(model, kind, options) {
|
|
|
362
371
|
*
|
|
363
372
|
* @example
|
|
364
373
|
* ```ts
|
|
374
|
+
* const data = { y: [2.1, 3.9, 6.2, 7.8, 10.1, 11.8], g: ["a", "a", "b", "b", "c", "c"] };
|
|
365
375
|
* etaSquared(anova(lm("y ~ g", data))).colNames; // ["Eta2", "CI", "CI_low", "CI_high"]
|
|
376
|
+
* const long = {
|
|
377
|
+
* y: [5, 7, 8, 4, 6, 9, 6, 8, 8, 5, 5, 7],
|
|
378
|
+
* W: ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a", "b", "c"],
|
|
379
|
+
* id: ["s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3", "s4", "s4", "s4"],
|
|
380
|
+
* };
|
|
366
381
|
* etaSquared(aov("y ~ W + Error(id/W)", long)).groups; // ["id:W"]
|
|
367
382
|
* ```
|
|
383
|
+
*
|
|
384
|
+
* @category Effect sizes and power
|
|
368
385
|
*/
|
|
369
386
|
export function etaSquared(model, options = {}) {
|
|
370
387
|
return anovaEffectSize(model, "Eta2", options);
|
|
371
388
|
}
|
|
372
389
|
/**
|
|
373
390
|
* Omega squared of the terms of an analysis-of-variance table, also of repeated-measures designs (see
|
|
374
|
-
* {@link etaSquared}). Equivalent to effectsize
|
|
391
|
+
* {@link etaSquared}). Equivalent to `effectsize::omega_squared()` in R.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```ts
|
|
395
|
+
* const data = { y: [2.1, 3.9, 6.2, 7.8, 10.1, 11.8], g: ["a", "a", "b", "b", "c", "c"] };
|
|
396
|
+
* omegaSquared(anova(lm("y ~ g", data))).table; // [[0.8740518865645682, 0.95, 0.0566677410780818, 1]]
|
|
397
|
+
* ```
|
|
398
|
+
*
|
|
399
|
+
* @category Effect sizes and power
|
|
375
400
|
*/
|
|
376
401
|
export function omegaSquared(model, options = {}) {
|
|
377
402
|
return anovaEffectSize(model, "Omega2", options);
|
|
378
403
|
}
|
|
379
404
|
/**
|
|
380
405
|
* Epsilon squared of the terms of an analysis-of-variance table, also of repeated-measures designs (see
|
|
381
|
-
* {@link etaSquared}). Equivalent to effectsize
|
|
406
|
+
* {@link etaSquared}). Equivalent to `effectsize::epsilon_squared()` in R.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```ts
|
|
410
|
+
* const data = { y: [2.1, 3.9, 6.2, 7.8, 10.1, 11.8], g: ["a", "a", "b", "b", "c", "c"] };
|
|
411
|
+
* epsilonSquared(anova(lm("y ~ g", data))).table; // [[0.8927928150213428, 0.95, 0.1720126241673212, 1]]
|
|
412
|
+
* ```
|
|
413
|
+
*
|
|
414
|
+
* @category Effect sizes and power
|
|
382
415
|
*/
|
|
383
416
|
export function epsilonSquared(model, options = {}) {
|
|
384
417
|
return anovaEffectSize(model, "Epsilon2", options);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type Alternative, type HTest, type Counts } from "./types.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link fisherTest}.
|
|
4
|
+
*
|
|
5
|
+
* @category Hypothesis tests
|
|
6
|
+
*/
|
|
3
7
|
export interface FisherTestOptions {
|
|
4
8
|
/**
|
|
5
9
|
* Alternative hypothesis: `"two.sided"`, `"less"` or `"greater"`. Default `"two.sided"`.
|
|
@@ -26,6 +30,8 @@ export interface FisherTestOptions {
|
|
|
26
30
|
* `fisher.test()` does not return a statistic. For 2 x 2 tables, `estimate` is the
|
|
27
31
|
* conditional maximum likelihood estimate of the odds ratio and `confInt` its interval;
|
|
28
32
|
* for larger tables only `method`, `alternative` and `pValue` are set.
|
|
33
|
+
*
|
|
34
|
+
* @category Hypothesis tests
|
|
29
35
|
*/
|
|
30
36
|
export interface FisherTestResult extends Omit<HTest, "statistic" | "statisticName"> {
|
|
31
37
|
}
|
|
@@ -55,5 +61,7 @@ export interface FisherTestResult extends Omit<HTest, "statistic" | "statisticNa
|
|
|
55
61
|
* r.estimate; // 6.408308867005792 (conditional MLE of the odds ratio)
|
|
56
62
|
* r.confInt; // [0.2117329153055031, 621.9337505454175]
|
|
57
63
|
* ```
|
|
64
|
+
*
|
|
65
|
+
* @category Hypothesis tests
|
|
58
66
|
*/
|
|
59
67
|
export declare function fisherTest(x: readonly Counts[], options?: FisherTestOptions): FisherTestResult;
|
package/dist/htest/fisherTest.js
CHANGED
|
@@ -65,6 +65,8 @@ import { matchAlternative } from "./types.js";
|
|
|
65
65
|
* r.estimate; // 6.408308867005792 (conditional MLE of the odds ratio)
|
|
66
66
|
* r.confInt; // [0.2117329153055031, 621.9337505454175]
|
|
67
67
|
* ```
|
|
68
|
+
*
|
|
69
|
+
* @category Hypothesis tests
|
|
68
70
|
*/
|
|
69
71
|
export function fisherTest(x, options = {}) {
|
|
70
72
|
const nr = x.length;
|
package/dist/htest/groups.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { Sample } from "./types.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Group label: a number or a string.
|
|
4
|
+
*
|
|
5
|
+
* @category Hypothesis tests
|
|
6
|
+
*/
|
|
3
7
|
export type GroupLabel = number | string;
|
|
4
8
|
/** Groups with their labels: the sorted labels (x, g form) or the 1-based positions in the list (list form) */
|
|
5
9
|
export interface LabelledGroups {
|
package/dist/htest/ksTest.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { DataFrame } from "../models/modelFrame.js";
|
|
2
2
|
import { type Alternative, type HTest, type Sample } from "./types.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link ksTest}.
|
|
5
|
+
*
|
|
6
|
+
* @category Hypothesis tests
|
|
7
|
+
*/
|
|
4
8
|
export interface KsTestOptions {
|
|
5
9
|
/**
|
|
6
10
|
* Alternative hypothesis (unambiguous abbreviations accepted). `"greater"`: the distribution function of `x` lies
|
|
@@ -16,13 +20,17 @@ export interface KsTestOptions {
|
|
|
16
20
|
/**
|
|
17
21
|
* Result of {@link ksTest}. As in R, `alternative` describes the hypothesis in words ("two-sided", "the CDF of x lies
|
|
18
22
|
* above the null hypothesis", ...), and `exact` tells whether the p-value is exact.
|
|
23
|
+
*
|
|
24
|
+
* @category Hypothesis tests
|
|
19
25
|
*/
|
|
20
26
|
export interface KsTestResult extends Omit<HTest, "alternative"> {
|
|
27
|
+
/** Description of the alternative hypothesis, as R prints it (e.g. `"two-sided"`). */
|
|
21
28
|
alternative: string;
|
|
29
|
+
/** Whether the p-value is exact. */
|
|
22
30
|
exact: boolean;
|
|
23
31
|
}
|
|
24
32
|
/**
|
|
25
|
-
* Kolmogorov-Smirnov test. Equivalent to R's `ks.test()
|
|
33
|
+
* Kolmogorov-Smirnov test. Equivalent to R's `ks.test()`. Takes a distribution function given as a function (for
|
|
26
34
|
* example `(q) => pnorm(q)`) or a second sample. `NaN` values are dropped.
|
|
27
35
|
*
|
|
28
36
|
* @param x Sample.
|
|
@@ -30,10 +38,19 @@ export interface KsTestResult extends Omit<HTest, "alternative"> {
|
|
|
30
38
|
* @param options See {@link KsTestOptions}.
|
|
31
39
|
*
|
|
32
40
|
* There is also a formula form for two samples, `ksTest("y ~ g", data, options)` (next overload).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const x = [0.61, -1.2, 0.33, 1.57, -0.42, 0.08, -0.85, 1.1];
|
|
45
|
+
* ksTest(x, (q) => pnorm(q)).pValue; // 0.9716870044206776
|
|
46
|
+
* ksTest(x, [0.9, 2.1, 1.4, 2.8, 1.7, 0.4]).statistic; // 0.625
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @category Hypothesis tests
|
|
33
50
|
*/
|
|
34
51
|
export declare function ksTest(x: Sample, y: Sample | ((q: number) => number), options?: KsTestOptions): KsTestResult;
|
|
35
52
|
/**
|
|
36
|
-
* Two-sample Kolmogorov-Smirnov test from a formula and a data frame.
|
|
53
|
+
* Two-sample Kolmogorov-Smirnov test from a formula and a data frame. As R's `ks.test(formula, data)`:
|
|
37
54
|
* `"y ~ g"` compares the two levels of `g` (the first level is `x`). Only the variables of the formula count: the
|
|
38
55
|
* rows where one of them is missing are dropped.
|
|
39
56
|
*
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { type GroupLabel } from "./groups.js";
|
|
2
2
|
import type { Sample } from "./types.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link leveneTest}.
|
|
5
|
+
*
|
|
6
|
+
* @category Hypothesis tests
|
|
7
|
+
*/
|
|
4
8
|
export interface LeveneTestOptions {
|
|
5
9
|
/** The centre of each group: `"median"` (default) or `"mean"`. */
|
|
6
10
|
center?: "median" | "mean" | (string & {});
|
|
7
11
|
}
|
|
8
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Result of {@link leveneTest}: car's table.
|
|
14
|
+
*
|
|
15
|
+
* @category Hypothesis tests
|
|
16
|
+
*/
|
|
9
17
|
export interface LeveneTestResult {
|
|
10
18
|
/** `["Df", "F value", "Pr(>F)"]`. */
|
|
11
19
|
colNames: string[];
|
|
@@ -15,8 +23,9 @@ export interface LeveneTestResult {
|
|
|
15
23
|
table: number[][];
|
|
16
24
|
}
|
|
17
25
|
/**
|
|
18
|
-
* Levene's test for homogeneity of variance across groups. Equivalent to car
|
|
19
|
-
* median)` (or `mean`). Pairs with a missing value are dropped; groups are ordered by
|
|
26
|
+
* Levene's test for homogeneity of variance across groups. Equivalent to `car::leveneTest()` in R. Computes
|
|
27
|
+
* `leveneTest(y ~ g, center = median)` (or `mean`). Pairs with a missing value are dropped; groups are ordered by
|
|
28
|
+
* their sorted labels.
|
|
20
29
|
*
|
|
21
30
|
* @param y The values.
|
|
22
31
|
* @param g Group labels, parallel to `y`.
|
|
@@ -26,5 +35,7 @@ export interface LeveneTestResult {
|
|
|
26
35
|
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
27
36
|
* leveneTest([4.2, 5.1, 6.3, 5.8, 7.9, 8.4, 6.6, 7.0, 5.5], g).table[0]; // [2, 0.15936952714535912, 0.8561748951935417]
|
|
28
37
|
* ```
|
|
38
|
+
*
|
|
39
|
+
* @category Hypothesis tests
|
|
29
40
|
*/
|
|
30
41
|
export declare function leveneTest(y: Sample, g: readonly GroupLabel[], options?: LeveneTestOptions): LeveneTestResult;
|
package/dist/htest/leveneTest.js
CHANGED
|
@@ -8,8 +8,9 @@ import { aov } from "./aov.js";
|
|
|
8
8
|
import { labelledGroups, median } from "./groups.js";
|
|
9
9
|
import { matchChoice } from "./power.js";
|
|
10
10
|
/**
|
|
11
|
-
* Levene's test for homogeneity of variance across groups. Equivalent to car
|
|
12
|
-
* median)` (or `mean`). Pairs with a missing value are dropped; groups are ordered by
|
|
11
|
+
* Levene's test for homogeneity of variance across groups. Equivalent to `car::leveneTest()` in R. Computes
|
|
12
|
+
* `leveneTest(y ~ g, center = median)` (or `mean`). Pairs with a missing value are dropped; groups are ordered by
|
|
13
|
+
* their sorted labels.
|
|
13
14
|
*
|
|
14
15
|
* @param y The values.
|
|
15
16
|
* @param g Group labels, parallel to `y`.
|
|
@@ -19,6 +20,8 @@ import { matchChoice } from "./power.js";
|
|
|
19
20
|
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
20
21
|
* leveneTest([4.2, 5.1, 6.3, 5.8, 7.9, 8.4, 6.6, 7.0, 5.5], g).table[0]; // [2, 0.15936952714535912, 0.8561748951935417]
|
|
21
22
|
* ```
|
|
23
|
+
*
|
|
24
|
+
* @category Hypothesis tests
|
|
22
25
|
*/
|
|
23
26
|
export function leveneTest(y, g, options = {}) {
|
|
24
27
|
const center = matchChoice(options.center ?? "median", ["median", "mean"]);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type Alternative, type HTest } from "./types.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link mantelhaenTest}.
|
|
4
|
+
*
|
|
5
|
+
* @category Hypothesis tests
|
|
6
|
+
*/
|
|
3
7
|
export interface MantelhaenTestOptions {
|
|
4
8
|
/** Alternative hypothesis (2 x 2 x K only). Default `"two.sided"`. */
|
|
5
9
|
alternative?: Alternative | "two" | "l" | "g";
|
|
@@ -10,17 +14,35 @@ export interface MantelhaenTestOptions {
|
|
|
10
14
|
/** Confidence level of the interval for the common odds ratio. Default `0.95`. */
|
|
11
15
|
confLevel?: number;
|
|
12
16
|
}
|
|
13
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Result of {@link mantelhaenTest}. 2 x 2 x K tables add the common odds ratio and its interval.
|
|
19
|
+
*
|
|
20
|
+
* @category Hypothesis tests
|
|
21
|
+
*/
|
|
14
22
|
export interface MantelhaenTestResult extends Omit<HTest, "alternative"> {
|
|
15
23
|
/** Present for 2 x 2 x K tables. */
|
|
16
24
|
alternative?: Alternative;
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
19
27
|
* Cochran-Mantel-Haenszel chi-squared test of conditional independence in a set of contingency tables, one per
|
|
20
|
-
* stratum. Equivalent to R's `mantelhaen.test()
|
|
28
|
+
* stratum. Equivalent to R's `mantelhaen.test()`. Takes the strata as R takes a three-dimensional array.
|
|
21
29
|
*
|
|
22
30
|
* @param strata The K strata, each an I x J table of counts as an array of rows (all of the same shape; I, J >= 2,
|
|
23
31
|
* K >= 2 for the asymptotic test).
|
|
24
32
|
* @param options See {@link MantelhaenTestOptions}.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const r = mantelhaenTest([
|
|
37
|
+
* [[10, 5], [4, 12]],
|
|
38
|
+
* [[8, 6], [5, 9]],
|
|
39
|
+
* [[12, 4], [6, 10]],
|
|
40
|
+
* ]);
|
|
41
|
+
* r.statistic; // 8.972595458903124
|
|
42
|
+
* r.pValue; // 0.002740590103473906
|
|
43
|
+
* r.estimate; // 4.13218122372723 (common odds ratio)
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @category Hypothesis tests
|
|
25
47
|
*/
|
|
26
48
|
export declare function mantelhaenTest(strata: readonly (readonly (readonly number[])[])[], options?: MantelhaenTestOptions): MantelhaenTestResult;
|
|
@@ -21,11 +21,25 @@ import { ConvolvedNoncentralHyper, conditionalMLE, lowerLimit, upperLimit } from
|
|
|
21
21
|
import { checkConfLevelOpen, matchAlternative } from "./types.js";
|
|
22
22
|
/**
|
|
23
23
|
* Cochran-Mantel-Haenszel chi-squared test of conditional independence in a set of contingency tables, one per
|
|
24
|
-
* stratum. Equivalent to R's `mantelhaen.test()
|
|
24
|
+
* stratum. Equivalent to R's `mantelhaen.test()`. Takes the strata as R takes a three-dimensional array.
|
|
25
25
|
*
|
|
26
26
|
* @param strata The K strata, each an I x J table of counts as an array of rows (all of the same shape; I, J >= 2,
|
|
27
27
|
* K >= 2 for the asymptotic test).
|
|
28
28
|
* @param options See {@link MantelhaenTestOptions}.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const r = mantelhaenTest([
|
|
33
|
+
* [[10, 5], [4, 12]],
|
|
34
|
+
* [[8, 6], [5, 9]],
|
|
35
|
+
* [[12, 4], [6, 10]],
|
|
36
|
+
* ]);
|
|
37
|
+
* r.statistic; // 8.972595458903124
|
|
38
|
+
* r.pValue; // 0.002740590103473906
|
|
39
|
+
* r.estimate; // 4.13218122372723 (common odds ratio)
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @category Hypothesis tests
|
|
29
43
|
*/
|
|
30
44
|
export function mantelhaenTest(strata, options = {}) {
|
|
31
45
|
const K = strata.length;
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import type { HTest } from "./types.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link mcnemarTest}.
|
|
4
|
+
*
|
|
5
|
+
* @category Hypothesis tests
|
|
6
|
+
*/
|
|
3
7
|
export interface McnemarTestOptions {
|
|
4
8
|
/** Apply the continuity correction (2 x 2 tables only). Default `true`. */
|
|
5
9
|
correct?: boolean;
|
|
6
10
|
}
|
|
7
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Result of {@link mcnemarTest}. Has no `alternative`, as R's `mcnemar.test()` returns none.
|
|
13
|
+
*
|
|
14
|
+
* @category Hypothesis tests
|
|
15
|
+
*/
|
|
8
16
|
export interface McnemarTestResult extends Omit<HTest, "alternative"> {
|
|
9
17
|
/** Degrees of freedom (`parameterName` is `"df"`). */
|
|
10
18
|
parameter: number;
|
|
11
19
|
}
|
|
12
20
|
/**
|
|
13
21
|
* McNemar's chi-squared test for symmetry of rows and columns in a square table of counts. Equivalent to R's
|
|
14
|
-
* `mcnemar.test()
|
|
22
|
+
* `mcnemar.test()`. Takes a matrix, or two factors given as paired category codes.
|
|
15
23
|
*
|
|
16
24
|
* @param x Square table of counts as an array of rows, or the first of two paired samples of category codes.
|
|
17
25
|
* @param y Second paired sample of category codes, when `x` is a sample. May be omitted (and the options passed in
|
|
@@ -20,7 +28,9 @@ export interface McnemarTestResult extends Omit<HTest, "alternative"> {
|
|
|
20
28
|
*
|
|
21
29
|
* @example
|
|
22
30
|
* ```ts
|
|
23
|
-
* mcnemarTest([[794, 86], [150, 570]]).statistic; //
|
|
31
|
+
* mcnemarTest([[794, 86], [150, 570]]).statistic; // 16.81779661016949
|
|
24
32
|
* ```
|
|
33
|
+
*
|
|
34
|
+
* @category Hypothesis tests
|
|
25
35
|
*/
|
|
26
36
|
export declare function mcnemarTest(x: readonly (readonly number[])[] | readonly (number | string)[], y?: readonly (number | string)[] | McnemarTestOptions, options?: McnemarTestOptions): McnemarTestResult;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { pgamma1 } from "../distributions/gamma.js";
|
|
7
7
|
/**
|
|
8
8
|
* McNemar's chi-squared test for symmetry of rows and columns in a square table of counts. Equivalent to R's
|
|
9
|
-
* `mcnemar.test()
|
|
9
|
+
* `mcnemar.test()`. Takes a matrix, or two factors given as paired category codes.
|
|
10
10
|
*
|
|
11
11
|
* @param x Square table of counts as an array of rows, or the first of two paired samples of category codes.
|
|
12
12
|
* @param y Second paired sample of category codes, when `x` is a sample. May be omitted (and the options passed in
|
|
@@ -15,8 +15,10 @@ import { pgamma1 } from "../distributions/gamma.js";
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
18
|
-
* mcnemarTest([[794, 86], [150, 570]]).statistic; //
|
|
18
|
+
* mcnemarTest([[794, 86], [150, 570]]).statistic; // 16.81779661016949
|
|
19
19
|
* ```
|
|
20
|
+
*
|
|
21
|
+
* @category Hypothesis tests
|
|
20
22
|
*/
|
|
21
23
|
export function mcnemarTest(x, y, options = {}) {
|
|
22
24
|
let table;
|