@numero-uno-jpn/rstats 0.11.0 → 0.12.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 +57 -0
- package/README.ja.md +44 -13
- package/README.md +43 -11
- package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-3VMBBQLV.js} +2 -2
- package/dist/chunks/chunk-4OKAZJJG.js +3 -0
- package/dist/chunks/{chunk-EZAFN5CD.js → chunk-6BH65HGN.js} +1 -1
- package/dist/chunks/chunk-ATC4F4BX.js +2 -0
- package/dist/chunks/{chunk-JWBO5WVN.js → chunk-EDH53DXN.js} +2 -2
- package/dist/chunks/{chunk-Y5CNQ266.js → chunk-EZ2KD5NA.js} +2 -2
- package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-GSPOO2G3.js} +2 -2
- package/dist/chunks/{chunk-F5EDJFEO.js → chunk-K7AZ65H7.js} +2 -2
- package/dist/chunks/{chunk-YSWGDOWK.js → chunk-LEIH4U5X.js} +2 -2
- package/dist/chunks/{chunk-EZWBRCJL.js → chunk-OX3SBG5X.js} +1 -1
- package/dist/chunks/chunk-SGZQDJRR.js +2 -0
- package/dist/chunks/{chunk-C5XTWMGB.js → chunk-UH2N3ZQW.js} +1 -1
- package/dist/chunks/chunk-UV2MZYDQ.js +2 -0
- package/dist/chunks/{chunk-TOGXTCZO.js → chunk-VQHEOBTM.js} +2 -2
- package/dist/chunks/chunk-WJQZZYOI.js +2 -0
- package/dist/chunks/chunk-WKEFHOFR.js +2 -0
- package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-WXC25OPJ.js} +2 -2
- package/dist/chunks/{chunk-5WDJPHYY.js → chunk-XJQKSR52.js} +1 -1
- package/dist/data/grouping.d.ts +39 -15
- package/dist/data/grouping.js +21 -22
- 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/mixed.d.ts +1 -0
- package/dist/entries/mixed.js +2 -0
- 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/testFormula.js +6 -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/mixed.js +3 -0
- 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 +13 -3
- package/dist/models/aovStrata.js +5 -1
- 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/formula.d.ts +26 -1
- package/dist/models/formula.js +125 -9
- 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 +77 -19
- package/dist/models/lm.js +22 -4
- package/dist/models/lmer.d.ts +162 -0
- package/dist/models/lmer.js +457 -0
- package/dist/models/mauchly.d.ts +20 -5
- package/dist/models/mauchly.js +7 -3
- package/dist/models/mixedDeviance.d.ts +44 -0
- package/dist/models/mixedDeviance.js +872 -0
- package/dist/models/mixedStructure.d.ts +82 -0
- package/dist/models/mixedStructure.js +309 -0
- package/dist/models/modelFrame.d.ts +17 -2
- package/dist/models/modelFrame.js +36 -21
- package/dist/models/modelMatrix.d.ts +33 -8
- package/dist/models/modelMatrix.js +21 -5
- 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 +14 -14
- 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 +12 -12
- package/llms.txt +13 -3
- package/package.json +5 -1
- package/dist/chunks/chunk-7GQMKH3Z.js +0 -2
- package/dist/chunks/chunk-AHHS6AC4.js +0 -3
- package/dist/chunks/chunk-ALM3VHFP.js +0 -2
package/dist/htest/pwr.js
CHANGED
|
@@ -19,23 +19,43 @@ const COHEN = {
|
|
|
19
19
|
f2: [0.02, 0.15, 0.35],
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
* Cohen's conventional effect sizes. Equivalent to pwr
|
|
22
|
+
* Cohen's conventional effect sizes. Equivalent to `pwr::cohen.ES(test, size)` in R.
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* ```ts
|
|
26
26
|
* cohenES("anov", "medium").effectSize; // 0.25
|
|
27
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* @category Effect sizes and power
|
|
28
30
|
*/
|
|
29
31
|
export function cohenES(test = "p", size = "small") {
|
|
30
32
|
const t = matchChoice(test, ["p", "t", "r", "anov", "chisq", "f2"]);
|
|
31
33
|
const s = matchChoice(size, ["small", "medium", "large"]);
|
|
32
34
|
return { test: t, size: s, effectSize: COHEN[t][["small", "medium", "large"].indexOf(s)], method: "Conventional effect size from Cohen (1982)" };
|
|
33
35
|
}
|
|
34
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Effect size h of two proportions: `2 asin(sqrt(p1)) - 2 asin(sqrt(p2))`. Equivalent to `pwr::ES.h()` in R.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* esH(0.65, 0.45); // 0.40486007517695755
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @category Effect sizes and power
|
|
45
|
+
*/
|
|
35
46
|
export function esH(p1, p2) {
|
|
36
47
|
return 2 * Math.asin(Math.sqrt(p1)) - 2 * Math.asin(Math.sqrt(p2));
|
|
37
48
|
}
|
|
38
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Effect size w of a goodness-of-fit test, `sqrt(sum((p1 - p0)^2 / p0))`. Equivalent to `pwr::ES.w1()` in R.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* esW1([0.25, 0.25, 0.25, 0.25], [0.4, 0.2, 0.2, 0.2]); // 0.34641016151377546
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @category Effect sizes and power
|
|
58
|
+
*/
|
|
39
59
|
export function esW1(p0, p1) {
|
|
40
60
|
if (p0.length !== p1.length)
|
|
41
61
|
throw new RangeError("'P0' and 'P1' must have the same length");
|
|
@@ -46,7 +66,14 @@ export function esW1(p0, p1) {
|
|
|
46
66
|
}
|
|
47
67
|
/**
|
|
48
68
|
* Effect size w of a test of association, for a matrix of cell probabilities (an array of rows): with the row sums
|
|
49
|
-
* r and column sums c, `p0 = r c'` and `sqrt(sum((p - p0)^2 / p0))`. Equivalent to pwr
|
|
69
|
+
* r and column sums c, `p0 = r c'` and `sqrt(sum((p - p0)^2 / p0))`. Equivalent to `pwr::ES.w2()` in R.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* esW2([[0.3, 0.2], [0.1, 0.4]]); // 0.40824829046386296
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @category Effect sizes and power
|
|
50
77
|
*/
|
|
51
78
|
export function esW2(p) {
|
|
52
79
|
const rows = p.map((r) => r.reduce((a, b) => a + b, 0));
|
|
@@ -98,14 +125,16 @@ function normalPower(shift, sig, alt) {
|
|
|
98
125
|
return (pnorm(qnorm(1 - sig / 2) - shift, { lowerTail: false }) + pnorm(qnorm(sig / 2) - shift));
|
|
99
126
|
}
|
|
100
127
|
/**
|
|
101
|
-
* Power of a t test of means, or the sample size, effect size or significance level for a given power.
|
|
102
|
-
* to
|
|
128
|
+
* Power of a t test of means, or the sample size, effect size or significance level for a given power.
|
|
129
|
+
* Equivalent to `pwr::pwr.t.test()` in R.
|
|
103
130
|
*
|
|
104
131
|
* @example
|
|
105
132
|
* ```ts
|
|
106
133
|
* pwrTTest({ n: 20, d: 0.5 }).power; // 0.3379390289250411
|
|
107
134
|
* pwrTTest({ d: 0.5, power: 0.8 }).n; // 63.76561044415068
|
|
108
135
|
* ```
|
|
136
|
+
*
|
|
137
|
+
* @category Effect sizes and power
|
|
109
138
|
*/
|
|
110
139
|
export function pwrTTest(options = {}) {
|
|
111
140
|
let { n, power } = options;
|
|
@@ -136,7 +165,15 @@ export function pwrTTest(options = {}) {
|
|
|
136
165
|
}
|
|
137
166
|
/**
|
|
138
167
|
* Power of a two-sample t test with unequal sample sizes, or a sample size, the effect size or the significance
|
|
139
|
-
* level for a given power. Equivalent to
|
|
168
|
+
* level for a given power. Equivalent to `pwr::pwr.t2n.test()` in R.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* pwrT2nTest({ n1: 20, n2: 30, d: 0.5 }).power; // 0.39656999440895696
|
|
173
|
+
* pwrT2nTest({ n1: 50, d: 0.5, power: 0.8 }).n2; // 87.70891347276086
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @category Effect sizes and power
|
|
140
177
|
*/
|
|
141
178
|
export function pwrT2nTest(options = {}) {
|
|
142
179
|
let { n1, n2, power } = options;
|
|
@@ -195,7 +232,15 @@ function normalTest(es0, options, name, scale, nLower, esLower) {
|
|
|
195
232
|
}
|
|
196
233
|
/**
|
|
197
234
|
* Power of the test of two proportions with equal sample sizes (arcsine transformation), or the effect size, sample
|
|
198
|
-
* size or significance level for a given power. Equivalent to
|
|
235
|
+
* size or significance level for a given power. Equivalent to `pwr::pwr.2p.test()` in R.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* pwr2pTest({ h: 0.3, n: 80 }).power; // 0.47510087057263806
|
|
240
|
+
* pwr2pTest({ h: esH(0.65, 0.45), power: 0.8 }).n; // 95.76938656160651
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @category Effect sizes and power
|
|
199
244
|
*/
|
|
200
245
|
export function pwr2pTest(options = {}) {
|
|
201
246
|
const r = normalTest(options.h, options, "h", (n) => Math.sqrt(n / 2), 2 + 1e-10, 1e-10);
|
|
@@ -211,7 +256,15 @@ export function pwr2pTest(options = {}) {
|
|
|
211
256
|
}
|
|
212
257
|
/**
|
|
213
258
|
* Power of the test of one proportion (arcsine transformation), or the effect size, sample size or significance
|
|
214
|
-
* level for a given power. Equivalent to
|
|
259
|
+
* level for a given power. Equivalent to `pwr::pwr.p.test()` in R.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* pwrPTest({ h: 0.2, n: 60 }).power; // 0.34084512406749834
|
|
264
|
+
* pwrPTest({ h: 0.2, power: 0.8 }).n; // 196.221512550509
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @category Effect sizes and power
|
|
215
268
|
*/
|
|
216
269
|
export function pwrPTest(options = {}) {
|
|
217
270
|
const r = normalTest(options.h, options, "h", (n) => Math.sqrt(n), 2 + 1e-10, 1e-10);
|
|
@@ -226,7 +279,15 @@ export function pwrPTest(options = {}) {
|
|
|
226
279
|
}
|
|
227
280
|
/**
|
|
228
281
|
* Power of the test of a mean of a normal distribution with known variance, or the effect size, sample size or
|
|
229
|
-
* significance level for a given power. Equivalent to
|
|
282
|
+
* significance level for a given power. Equivalent to `pwr::pwr.norm.test()` in R.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```ts
|
|
286
|
+
* pwrNormTest({ d: 0.3, n: 50 }).power; // 0.5641160254310038
|
|
287
|
+
* pwrNormTest({ d: 0.3, power: 0.8 }).n; // 87.20953791564195
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @category Effect sizes and power
|
|
230
291
|
*/
|
|
231
292
|
export function pwrNormTest(options = {}) {
|
|
232
293
|
const r = normalTest(options.d, options, "d", (n) => Math.sqrt(n), 1 + 1e-10, 1e-10);
|
|
@@ -241,7 +302,15 @@ export function pwrNormTest(options = {}) {
|
|
|
241
302
|
}
|
|
242
303
|
/**
|
|
243
304
|
* Power of the test of two proportions with unequal sample sizes (arcsine transformation), or the effect size, a
|
|
244
|
-
* sample size or the significance level for a given power. Equivalent to
|
|
305
|
+
* sample size or the significance level for a given power. Equivalent to `pwr::pwr.2p2n.test()` in R.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* pwr2p2nTest({ h: 0.3, n1: 80, n2: 120 }).power; // 0.5471899635264242
|
|
310
|
+
* pwr2p2nTest({ h: 0.3, n1: 200, power: 0.8 }).n2; // 154.6399892648981
|
|
311
|
+
* ```
|
|
312
|
+
*
|
|
313
|
+
* @category Effect sizes and power
|
|
245
314
|
*/
|
|
246
315
|
export function pwr2p2nTest(options = {}) {
|
|
247
316
|
let { n1, n2, power } = options;
|
|
@@ -283,8 +352,16 @@ export function pwr2p2nTest(options = {}) {
|
|
|
283
352
|
}
|
|
284
353
|
/**
|
|
285
354
|
* Power of the test of a correlation (Fisher's z transformation), or the sample size, correlation or significance
|
|
286
|
-
* level for a given power. Equivalent to
|
|
355
|
+
* level for a given power. Equivalent to `pwr::pwr.r.test()` in R. As in pwr, the power computed for `"less"` reports
|
|
287
356
|
* `r` negated.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* pwrRTest({ n: 50, r: 0.3 }).power; // 0.571555841860208
|
|
361
|
+
* pwrRTest({ r: 0.3, power: 0.8 }).n; // 84.07363978228769
|
|
362
|
+
* ```
|
|
363
|
+
*
|
|
364
|
+
* @category Effect sizes and power
|
|
288
365
|
*/
|
|
289
366
|
export function pwrRTest(options = {}) {
|
|
290
367
|
let { n, power } = options;
|
|
@@ -333,7 +410,15 @@ export function pwrRTest(options = {}) {
|
|
|
333
410
|
}
|
|
334
411
|
/**
|
|
335
412
|
* Power of a chi-squared test, or the effect size, number of observations or significance level for a given power.
|
|
336
|
-
* Equivalent to
|
|
413
|
+
* Equivalent to `pwr::pwr.chisq.test()` in R.
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```ts
|
|
417
|
+
* pwrChisqTest({ w: 0.3, N: 100, df: 3 }).power; // 0.7112535997950422
|
|
418
|
+
* pwrChisqTest({ w: 0.3, df: 3, power: 0.8 }).N; // 121.13959310294602
|
|
419
|
+
* ```
|
|
420
|
+
*
|
|
421
|
+
* @category Effect sizes and power
|
|
337
422
|
*/
|
|
338
423
|
export function pwrChisqTest(options) {
|
|
339
424
|
let { N, power } = options;
|
|
@@ -364,7 +449,15 @@ export function pwrChisqTest(options) {
|
|
|
364
449
|
}
|
|
365
450
|
/**
|
|
366
451
|
* Power of the F test of a balanced one-way analysis of variance, or the number of groups, sample size, effect size
|
|
367
|
-
* or significance level for a given power. Equivalent to
|
|
452
|
+
* or significance level for a given power. Equivalent to `pwr::pwr.anova.test()` in R.
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* pwrAnovaTest({ k: 4, n: 20, f: 0.25 }).power; // 0.42039009037704295
|
|
457
|
+
* pwrAnovaTest({ k: 4, f: 0.25, power: 0.8 }).n; // 44.59927432039623
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* @category Effect sizes and power
|
|
368
461
|
*/
|
|
369
462
|
export function pwrAnovaTest(options = {}) {
|
|
370
463
|
let { k, n, power } = options;
|
|
@@ -408,7 +501,15 @@ export function pwrAnovaTest(options = {}) {
|
|
|
408
501
|
}
|
|
409
502
|
/**
|
|
410
503
|
* Power of the F test of a general linear model, or the degrees of freedom, effect size or significance level for a
|
|
411
|
-
* given power. Equivalent to
|
|
504
|
+
* given power. Equivalent to `pwr::pwr.f2.test()` in R.
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```ts
|
|
508
|
+
* pwrF2Test({ u: 3, v: 60, f2: 0.15 }).power; // 0.7109605416866717
|
|
509
|
+
* pwrF2Test({ u: 3, f2: 0.15, power: 0.8 }).v; // 72.70582657950871
|
|
510
|
+
* ```
|
|
511
|
+
*
|
|
512
|
+
* @category Effect sizes and power
|
|
412
513
|
*/
|
|
413
514
|
export function pwrF2Test(options = {}) {
|
|
414
515
|
let { u, v, power } = options;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { DataFrame } from "../models/modelFrame.js";
|
|
2
2
|
import { type GroupLabel } from "./groups.js";
|
|
3
3
|
import { type Alternative, type HTest, type Sample } from "./types.js";
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Result of a k-sample test with a chi-squared statistic. Has no `alternative`, as R returns none.
|
|
6
|
+
*
|
|
7
|
+
* @category Hypothesis tests
|
|
8
|
+
*/
|
|
5
9
|
export interface ChisqStatTestResult extends Omit<HTest, "alternative"> {
|
|
6
10
|
/** Degrees of freedom (`parameterName` is `"df"`). */
|
|
7
11
|
parameter: number;
|
|
@@ -14,10 +18,19 @@ export interface ChisqStatTestResult extends Omit<HTest, "alternative"> {
|
|
|
14
18
|
* @param g Group labels, parallel to `x`.
|
|
15
19
|
*
|
|
16
20
|
* There is also a formula form, `kruskalTest("y ~ g", data)` (next overload).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const r = kruskalTest([[2.9, 3.0, 2.5, 2.6, 3.2], [3.8, 2.7, 4.0, 2.4], [2.8, 3.4, 3.7, 2.2, 2.0]]);
|
|
25
|
+
* r.statistic; // 0.7714285714285722
|
|
26
|
+
* r.pValue; // 0.6799647735788935
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @category Hypothesis tests
|
|
17
30
|
*/
|
|
18
31
|
export declare function kruskalTest(x: Sample | readonly Sample[], g?: readonly GroupLabel[]): ChisqStatTestResult;
|
|
19
32
|
/**
|
|
20
|
-
* Kruskal-Wallis test from a formula and a data frame.
|
|
33
|
+
* Kruskal-Wallis test from a formula and a data frame. As R's `kruskal.test(formula, data)`: `"y ~ g"`,
|
|
21
34
|
* one group per level of `g`. Only the variables of the formula count: the rows where one of them is missing are
|
|
22
35
|
* dropped.
|
|
23
36
|
*
|
|
@@ -26,16 +39,25 @@ export declare function kruskalTest(x: Sample | readonly Sample[], g?: readonly
|
|
|
26
39
|
*/
|
|
27
40
|
export declare function kruskalTest(formula: string, data: DataFrame): ChisqStatTestResult;
|
|
28
41
|
/**
|
|
29
|
-
* Friedman rank sum test for an unreplicated complete block design. Equivalent to R's `friedman.test()
|
|
42
|
+
* Friedman rank sum test for an unreplicated complete block design. Equivalent to R's `friedman.test()`. Takes a
|
|
30
43
|
* matrix.
|
|
31
44
|
*
|
|
32
45
|
* @param y Blocks as rows, treatments as columns. Rows with a missing value are dropped.
|
|
33
46
|
*
|
|
34
47
|
* There is also a formula form, `friedmanTest("y ~ w | b", data)` (next overload).
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const r = friedmanTest([[5.4, 5.5, 5.55], [5.85, 5.7, 5.75], [5.2, 5.6, 5.5], [5.55, 5.5, 5.4], [5.9, 5.85, 5.7]]);
|
|
52
|
+
* r.statistic; // 0.4
|
|
53
|
+
* r.pValue; // 0.8187307530779818
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @category Hypothesis tests
|
|
35
57
|
*/
|
|
36
58
|
export declare function friedmanTest(y: readonly (readonly number[])[]): ChisqStatTestResult;
|
|
37
59
|
/**
|
|
38
|
-
* Friedman test from a formula and a data frame.
|
|
60
|
+
* Friedman test from a formula and a data frame. As R's `friedman.test(formula, data)`: `"y ~ w | b"`
|
|
39
61
|
* with the groups `w` and the blocks `b`. The rows where `y`, `w` or `b` is missing are dropped first; then every
|
|
40
62
|
* combination of group and block must occur exactly once (else the error `not an unreplicated complete block
|
|
41
63
|
* design`, so that one missing value fails, unlike the matrix form, which drops its block).
|
|
@@ -45,28 +67,52 @@ export declare function friedmanTest(y: readonly (readonly number[])[]): ChisqSt
|
|
|
45
67
|
*/
|
|
46
68
|
export declare function friedmanTest(formula: string, data: DataFrame): ChisqStatTestResult;
|
|
47
69
|
/**
|
|
48
|
-
* Cochran's Q test for binary responses in an unreplicated complete block design. Equivalent to
|
|
49
|
-
* `CochranQTest()`
|
|
70
|
+
* Cochran's Q test for binary responses in an unreplicated complete block design. Equivalent to
|
|
71
|
+
* `DescTools::CochranQTest()` in R. Takes a matrix: the Friedman test of the 0/1 matrix (with ties), reported as Q.
|
|
50
72
|
*
|
|
51
73
|
* @param y Blocks as rows, treatments as columns, values 0 or 1. Rows with a missing value are dropped.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const r = cochranQTest([[1, 1, 0], [1, 0, 0], [1, 1, 1], [0, 0, 0], [1, 1, 0], [1, 0, 1]]);
|
|
78
|
+
* r.statistic; // 3.5
|
|
79
|
+
* r.pValue; // 0.17377394345044514
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @category Hypothesis tests
|
|
52
83
|
*/
|
|
53
84
|
export declare function cochranQTest(y: readonly (readonly number[])[]): ChisqStatTestResult;
|
|
54
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Result of {@link quadeTest}: an F statistic with two degrees of freedom.
|
|
87
|
+
*
|
|
88
|
+
* @category Hypothesis tests
|
|
89
|
+
*/
|
|
55
90
|
export interface QuadeTestResult extends Omit<HTest, "alternative" | "parameter" | "parameterName"> {
|
|
56
91
|
/** `[num df, denom df]`. */
|
|
57
92
|
parameter: [number, number];
|
|
93
|
+
/** Names of `parameter`: `["num df", "denom df"]`. */
|
|
58
94
|
parameterName: [string, string];
|
|
59
95
|
}
|
|
60
96
|
/**
|
|
61
|
-
* Quade test for an unreplicated complete block design. Equivalent to R's `quade.test()
|
|
97
|
+
* Quade test for an unreplicated complete block design. Equivalent to R's `quade.test()`. Takes a matrix.
|
|
62
98
|
*
|
|
63
99
|
* @param y Blocks as rows, treatments as columns. Rows with a missing value are dropped.
|
|
64
100
|
*
|
|
65
101
|
* There is also a formula form, `quadeTest("y ~ w | b", data)` (next overload).
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const r = quadeTest([[5.4, 5.5, 5.55], [5.85, 5.7, 5.75], [5.2, 5.6, 5.5], [5.55, 5.5, 5.4], [5.9, 5.85, 5.7]]);
|
|
106
|
+
* r.statistic; // 0.20634920634920637
|
|
107
|
+
* r.parameter; // [2, 8]
|
|
108
|
+
* r.pValue; // 0.8177464498805584
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @category Hypothesis tests
|
|
66
112
|
*/
|
|
67
113
|
export declare function quadeTest(y: readonly (readonly number[])[]): QuadeTestResult;
|
|
68
114
|
/**
|
|
69
|
-
* Quade test from a formula and a data frame.
|
|
115
|
+
* Quade test from a formula and a data frame. As R's `quade.test(formula, data)`: `"y ~ w | b"` with the
|
|
70
116
|
* groups `w` and the blocks `b`. The rows where `y`, `w` or `b` is missing are dropped first; then every combination
|
|
71
117
|
* of group and block must occur exactly once (else the error `not an unreplicated complete block design`).
|
|
72
118
|
*
|
|
@@ -82,10 +128,19 @@ export declare function quadeTest(formula: string, data: DataFrame): QuadeTestRe
|
|
|
82
128
|
* @param g Group labels, parallel to `x`.
|
|
83
129
|
*
|
|
84
130
|
* There is also a formula form, `flignerTest("y ~ g", data)` (next overload).
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const r = flignerTest([[2.9, 3.0, 2.5, 2.6, 3.2], [3.8, 2.7, 4.0, 2.4], [2.8, 3.4, 3.7, 2.2, 2.0]]);
|
|
135
|
+
* r.statistic; // 5.209183208821734
|
|
136
|
+
* r.pValue; // 0.07393332507668932
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @category Hypothesis tests
|
|
85
140
|
*/
|
|
86
141
|
export declare function flignerTest(x: Sample | readonly Sample[], g?: readonly GroupLabel[]): ChisqStatTestResult;
|
|
87
142
|
/**
|
|
88
|
-
* Fligner-Killeen test from a formula and a data frame.
|
|
143
|
+
* Fligner-Killeen test from a formula and a data frame. As R's `fligner.test(formula, data)`: `"y ~ g"`,
|
|
89
144
|
* one group per level of `g`. Only the variables of the formula count: the rows where one of them is missing are
|
|
90
145
|
* dropped.
|
|
91
146
|
*
|
|
@@ -93,7 +148,11 @@ export declare function flignerTest(x: Sample | readonly Sample[], g?: readonly
|
|
|
93
148
|
* @param data The data frame: an object of columns (`null` or `NaN` for a missing value).
|
|
94
149
|
*/
|
|
95
150
|
export declare function flignerTest(formula: string, data: DataFrame): ChisqStatTestResult;
|
|
96
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* Options for {@link moodTest}.
|
|
153
|
+
*
|
|
154
|
+
* @category Hypothesis tests
|
|
155
|
+
*/
|
|
97
156
|
export interface MoodTestOptions {
|
|
98
157
|
/** Alternative hypothesis (unambiguous abbreviations accepted). Default `"two.sided"`. */
|
|
99
158
|
alternative?: Alternative | "two" | "l" | "g";
|
|
@@ -103,10 +162,19 @@ export interface MoodTestOptions {
|
|
|
103
162
|
* of the scores of their positions.
|
|
104
163
|
*
|
|
105
164
|
* There is also a formula form, `moodTest("y ~ g", data, options)` (next overload).
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const r = moodTest([0.8, 1.9, 2.4, 3.1, 4.6, 5.0], [2.6, 2.9, 3.0, 3.3, 3.5]);
|
|
169
|
+
* r.statistic; // 2.0919054414739633
|
|
170
|
+
* r.pValue; // 0.03644697523591335
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @category Hypothesis tests
|
|
106
174
|
*/
|
|
107
175
|
export declare function moodTest(x: Sample, y: Sample, options?: MoodTestOptions): HTest;
|
|
108
176
|
/**
|
|
109
|
-
* Mood's test from a formula and a data frame.
|
|
177
|
+
* Mood's test from a formula and a data frame. As R's `mood.test(formula, data)`: `"y ~ g"` compares the
|
|
110
178
|
* two levels of `g` (the first level is `x`). Only the variables of the formula count: the rows where one of them is
|
|
111
179
|
* missing are dropped.
|
|
112
180
|
*
|
package/dist/htest/rankTests.js
CHANGED
|
@@ -87,10 +87,19 @@ export function friedmanTest(y, data) {
|
|
|
87
87
|
return chisqResult("Friedman rank sum test", "Friedman chi-squared", stat, k - 1);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
|
-
* Cochran's Q test for binary responses in an unreplicated complete block design. Equivalent to
|
|
91
|
-
* `CochranQTest()`
|
|
90
|
+
* Cochran's Q test for binary responses in an unreplicated complete block design. Equivalent to
|
|
91
|
+
* `DescTools::CochranQTest()` in R. Takes a matrix: the Friedman test of the 0/1 matrix (with ties), reported as Q.
|
|
92
92
|
*
|
|
93
93
|
* @param y Blocks as rows, treatments as columns, values 0 or 1. Rows with a missing value are dropped.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* const r = cochranQTest([[1, 1, 0], [1, 0, 0], [1, 1, 1], [0, 0, 0], [1, 1, 0], [1, 0, 1]]);
|
|
98
|
+
* r.statistic; // 3.5
|
|
99
|
+
* r.pValue; // 0.17377394345044514
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @category Hypothesis tests
|
|
94
103
|
*/
|
|
95
104
|
export function cochranQTest(y) {
|
|
96
105
|
return { ...friedmanTest(y), method: "Cochran's Q test", statisticName: "Q" };
|
package/dist/htest/tTest.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 tTest}.
|
|
5
|
+
*
|
|
6
|
+
* @category Hypothesis tests
|
|
7
|
+
*/
|
|
4
8
|
export interface TTestOptions {
|
|
5
9
|
/**
|
|
6
10
|
* Alternative hypothesis: `"two.sided"`, `"less"` or `"greater"`. Default `"two.sided"`.
|
|
@@ -16,7 +20,11 @@ export interface TTestOptions {
|
|
|
16
20
|
/** Confidence level of the interval. Default `0.95`. */
|
|
17
21
|
confLevel?: number;
|
|
18
22
|
}
|
|
19
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Result of {@link tTest}.
|
|
25
|
+
*
|
|
26
|
+
* @category Hypothesis tests
|
|
27
|
+
*/
|
|
20
28
|
export interface TTestResult extends HTest {
|
|
21
29
|
/** Degrees of freedom of the t distribution (`parameterName` is `"df"`). */
|
|
22
30
|
parameter: number;
|
|
@@ -56,10 +64,12 @@ export interface TTestResult extends HTest {
|
|
|
56
64
|
* ```
|
|
57
65
|
*
|
|
58
66
|
* There is also a formula form, `tTest("y ~ g", data, options)` (next overload).
|
|
67
|
+
*
|
|
68
|
+
* @category Hypothesis tests
|
|
59
69
|
*/
|
|
60
70
|
export declare function tTest(x: Sample, y?: Sample | TTestOptions, options?: TTestOptions): TTestResult;
|
|
61
71
|
/**
|
|
62
|
-
* Student's t-test from a formula and a data frame.
|
|
72
|
+
* Student's t-test from a formula and a data frame. As R's `t.test(formula, data)`: `"y ~ g"` compares
|
|
63
73
|
* the two levels of `g` (the first level is `x`; `estimateNames` and `nullValueName` name the levels, as in R),
|
|
64
74
|
* `"y ~ 1"` is the one-sample test and `"Pair(a, b) ~ 1"` the paired test of `a` and `b` (the option `paired` is not
|
|
65
75
|
* allowed). Only the variables of the formula count: the rows where one of them is missing are dropped.
|
|
@@ -7,12 +7,15 @@
|
|
|
7
7
|
// level. The formula is parsed with src/models/formula.ts; `Pair(a, b)` on the left and `|` on the right, which that
|
|
8
8
|
// parser does not know, are split off the text first.
|
|
9
9
|
import { parseFormula, termsOf } from "../models/formula.js";
|
|
10
|
-
import { modelFrame } from "../models/modelFrame.js";
|
|
10
|
+
import { modelFrame, presentLevels } from "../models/modelFrame.js";
|
|
11
11
|
import { formatR } from "./core/simulate.js";
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* A variable of a model frame as a factor of the values present: numbers sorted as numbers and labelled as R prints
|
|
14
|
+
* them, a boolean's levels FALSE and TRUE only if they occur
|
|
15
|
+
*/
|
|
13
16
|
function groupFactor(v) {
|
|
14
17
|
if (v.kind === "factor")
|
|
15
|
-
return
|
|
18
|
+
return presentLevels(v);
|
|
16
19
|
const sorted = [...new Set(v.values)].sort((a, b) => a - b);
|
|
17
20
|
const levels = [...new Set(sorted.map(formatR))];
|
|
18
21
|
const position = new Map(levels.map((l, i) => [l, i]));
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { GroupLabel } from "./groups.js";
|
|
2
2
|
import type { HTest, Sample } from "./types.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Result of {@link propTrendTest}: no `alternative`, as R returns none.
|
|
5
|
+
*
|
|
6
|
+
* @category Hypothesis tests
|
|
7
|
+
*/
|
|
4
8
|
export interface PropTrendTestResult extends Omit<HTest, "alternative"> {
|
|
5
9
|
/** Degrees of freedom (1). */
|
|
6
10
|
parameter: number;
|
|
@@ -16,11 +20,21 @@ export interface PropTrendTestResult extends Omit<HTest, "alternative"> {
|
|
|
16
20
|
* ```ts
|
|
17
21
|
* propTrendTest([15, 10, 8, 4], [30, 30, 30, 30]).statistic; // 9.573428850537288
|
|
18
22
|
* ```
|
|
23
|
+
*
|
|
24
|
+
* @category Hypothesis tests
|
|
19
25
|
*/
|
|
20
26
|
export declare function propTrendTest(x: Sample, n: Sample, score?: Sample): PropTrendTestResult;
|
|
21
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Alternative of {@link jonckheereTest}.
|
|
29
|
+
*
|
|
30
|
+
* @category Hypothesis tests
|
|
31
|
+
*/
|
|
22
32
|
export type JonckheereAlternative = "two.sided" | "increasing" | "decreasing";
|
|
23
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Options for {@link jonckheereTest}.
|
|
35
|
+
*
|
|
36
|
+
* @category Hypothesis tests
|
|
37
|
+
*/
|
|
24
38
|
export interface JonckheereTestOptions {
|
|
25
39
|
/** `"two.sided"` (default), `"increasing"` or `"decreasing"` (unambiguous abbreviations accepted). */
|
|
26
40
|
alternative?: JonckheereAlternative | (string & {});
|
|
@@ -34,17 +48,22 @@ export interface JonckheereTestOptions {
|
|
|
34
48
|
/** The order of the groups. Default: the labels sorted (numbers as numbers, strings by code point). */
|
|
35
49
|
levels?: readonly GroupLabel[];
|
|
36
50
|
}
|
|
37
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Result of {@link jonckheereTest}.
|
|
53
|
+
*
|
|
54
|
+
* @category Hypothesis tests
|
|
55
|
+
*/
|
|
38
56
|
export interface JonckheereTestResult extends Omit<HTest, "alternative"> {
|
|
57
|
+
/** Alternative hypothesis: `"two.sided"`, `"increasing"` or `"decreasing"`. */
|
|
39
58
|
alternative: JonckheereAlternative;
|
|
40
59
|
/** The packages' warnings (normal approximation). */
|
|
41
60
|
warnings: string[];
|
|
42
61
|
}
|
|
43
62
|
/**
|
|
44
|
-
* Jonckheere-Terpstra test of equal distributions against ordered alternatives. Equivalent to
|
|
45
|
-
* `JonckheereTerpstraTest(x, g, alternative, exact)` (with `g`
|
|
46
|
-
* clinfun's `jonckheere.test(x, g, alternative)` (whose
|
|
47
|
-
* 0.5)`; DescTools caps it at 1 instead of 0.5). Pairs with a missing value are dropped.
|
|
63
|
+
* Jonckheere-Terpstra test of equal distributions against ordered alternatives. Equivalent to
|
|
64
|
+
* `DescTools::JonckheereTerpstraTest()` in R. Computes `JonckheereTerpstraTest(x, g, alternative, exact)` (with `g`
|
|
65
|
+
* an ordered factor) or, with `variant: "clinfun"`, clinfun's `jonckheere.test(x, g, alternative)` (whose
|
|
66
|
+
* two-sided p-value is `2 min(p_increasing, p_decreasing, 0.5)`; DescTools caps it at 1 instead of 0.5). Pairs with a missing value are dropped.
|
|
48
67
|
*
|
|
49
68
|
* @param x The values.
|
|
50
69
|
* @param g Group labels, parallel to `x`, in the order of the alternative.
|
|
@@ -53,5 +72,7 @@ export interface JonckheereTestResult extends Omit<HTest, "alternative"> {
|
|
|
53
72
|
* ```ts
|
|
54
73
|
* jonckheereTest([1.1, 2.0, 2.4, 3.5, 3.1, 4.6], [1, 1, 2, 2, 3, 3], { alternative: "increasing" }).statistic; // 11
|
|
55
74
|
* ```
|
|
75
|
+
*
|
|
76
|
+
* @category Hypothesis tests
|
|
56
77
|
*/
|
|
57
78
|
export declare function jonckheereTest(x: Sample, g: readonly GroupLabel[], options?: JonckheereTestOptions): JonckheereTestResult;
|
package/dist/htest/trendTests.js
CHANGED
|
@@ -25,6 +25,8 @@ import { matchChoice } from "./power.js";
|
|
|
25
25
|
* ```ts
|
|
26
26
|
* propTrendTest([15, 10, 8, 4], [30, 30, 30, 30]).statistic; // 9.573428850537288
|
|
27
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* @category Hypothesis tests
|
|
28
30
|
*/
|
|
29
31
|
export function propTrendTest(x, n, score) {
|
|
30
32
|
const xs = Array.from(x);
|
|
@@ -84,10 +86,10 @@ function orderedGroups(x, g, levels) {
|
|
|
84
86
|
return groups;
|
|
85
87
|
}
|
|
86
88
|
/**
|
|
87
|
-
* Jonckheere-Terpstra test of equal distributions against ordered alternatives. Equivalent to
|
|
88
|
-
* `JonckheereTerpstraTest(x, g, alternative, exact)` (with `g`
|
|
89
|
-
* clinfun's `jonckheere.test(x, g, alternative)` (whose
|
|
90
|
-
* 0.5)`; DescTools caps it at 1 instead of 0.5). Pairs with a missing value are dropped.
|
|
89
|
+
* Jonckheere-Terpstra test of equal distributions against ordered alternatives. Equivalent to
|
|
90
|
+
* `DescTools::JonckheereTerpstraTest()` in R. Computes `JonckheereTerpstraTest(x, g, alternative, exact)` (with `g`
|
|
91
|
+
* an ordered factor) or, with `variant: "clinfun"`, clinfun's `jonckheere.test(x, g, alternative)` (whose
|
|
92
|
+
* two-sided p-value is `2 min(p_increasing, p_decreasing, 0.5)`; DescTools caps it at 1 instead of 0.5). Pairs with a missing value are dropped.
|
|
91
93
|
*
|
|
92
94
|
* @param x The values.
|
|
93
95
|
* @param g Group labels, parallel to `x`, in the order of the alternative.
|
|
@@ -96,6 +98,8 @@ function orderedGroups(x, g, levels) {
|
|
|
96
98
|
* ```ts
|
|
97
99
|
* jonckheereTest([1.1, 2.0, 2.4, 3.5, 3.1, 4.6], [1, 1, 2, 2, 3, 3], { alternative: "increasing" }).statistic; // 11
|
|
98
100
|
* ```
|
|
101
|
+
*
|
|
102
|
+
* @category Hypothesis tests
|
|
99
103
|
*/
|
|
100
104
|
export function jonckheereTest(x, g, options = {}) {
|
|
101
105
|
const alternative = matchChoice(options.alternative, ["two.sided", "increasing", "decreasing"]);
|
package/dist/htest/types.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Alternative hypothesis of a test, as in R. Test options also accept unambiguous
|
|
3
3
|
* abbreviations (`"two"`, `"l"`, `"g"`), like R's `match.arg()`.
|
|
4
|
+
*
|
|
5
|
+
* @category Hypothesis tests
|
|
4
6
|
*/
|
|
5
7
|
export type Alternative = "two.sided" | "less" | "greater";
|
|
6
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* A sample: an array of numbers.
|
|
10
|
+
*
|
|
11
|
+
* @category Hypothesis tests
|
|
12
|
+
*/
|
|
7
13
|
export type Sample = readonly number[] | Float64Array;
|
|
8
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Counts: an array of numbers. A contingency table is passed as an array of rows.
|
|
16
|
+
*
|
|
17
|
+
* @category Hypothesis tests
|
|
18
|
+
*/
|
|
9
19
|
export type Counts = readonly number[] | Float64Array;
|
|
10
20
|
/**
|
|
11
21
|
* Result of a hypothesis test: a plain object mirroring R's `htest` class.
|
|
@@ -14,6 +24,8 @@ export type Counts = readonly number[] | Float64Array;
|
|
|
14
24
|
* number and a separate `...Name` field. `estimate` is an array only when there are two
|
|
15
25
|
* estimates (for example the two means of a two-sample t-test). `conf.int`'s
|
|
16
26
|
* `conf.level` attribute becomes `confLevel`.
|
|
27
|
+
*
|
|
28
|
+
* @category Hypothesis tests
|
|
17
29
|
*/
|
|
18
30
|
export interface HTest {
|
|
19
31
|
/** Description of the test, as R's `method` (e.g. `"Welch Two Sample t-test"`). */
|