@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
|
@@ -109,10 +109,19 @@ function pooled(d) {
|
|
|
109
109
|
return { m: d.groups.map(mean), s2: ss / df, df: d.N - d.k };
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
|
-
* Dunn's all-pairs test of mean ranks with adjusted p-values. Equivalent to PMCMRplus
|
|
112
|
+
* Dunn's all-pairs test of mean ranks with adjusted p-values. Equivalent to `PMCMRplus::kwAllPairsDunnTest()` in R.
|
|
113
113
|
*
|
|
114
114
|
* @param x Response values.
|
|
115
115
|
* @param g Group labels, parallel to `x` (groups in the order of the sorted labels).
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
120
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
121
|
+
* kwAllPairsDunnTest(x, g).pValue; // [[0.3594249897579995, NaN], [0.02187107427460692, 0.3594249897579995]]
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @category Multiple comparisons
|
|
116
125
|
*/
|
|
117
126
|
export function kwAllPairsDunnTest(x, g, options = {}) {
|
|
118
127
|
const adjust = options.pAdjustMethod ?? "holm";
|
|
@@ -124,9 +133,18 @@ export function kwAllPairsDunnTest(x, g, options = {}) {
|
|
|
124
133
|
return allPairs(d, "Dunn's all-pairs test", z, p, adjust, C !== 0 ? [TIES_WARNING] : []);
|
|
125
134
|
}
|
|
126
135
|
/**
|
|
127
|
-
* Dunn's many-to-one test of mean ranks against the control (the first group). Equivalent to
|
|
128
|
-
* `kwManyOneDunnTest()
|
|
129
|
-
* normal probabilities (R approximates them by randomised integration).
|
|
136
|
+
* Dunn's many-to-one test of mean ranks against the control (the first group). Equivalent to
|
|
137
|
+
* `PMCMRplus::kwManyOneDunnTest()` in R. With `pAdjustMethod` `"single-step"` (the default) the p-values are the
|
|
138
|
+
* exact simultaneous normal probabilities (R approximates them by randomised integration).
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
143
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
144
|
+
* kwManyOneDunnTest(x, g).pValue; // [[0.30272579742071715], [0.013938744281312318]]
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @category Multiple comparisons
|
|
130
148
|
*/
|
|
131
149
|
export function kwManyOneDunnTest(x, g, options = {}) {
|
|
132
150
|
const alternative = matchAlternative(options.alternative);
|
|
@@ -155,8 +173,17 @@ function manyOneNormalP(z, lambda, alternative, adjust) {
|
|
|
155
173
|
}
|
|
156
174
|
/**
|
|
157
175
|
* Dunnett's many-to-one test of means against the control (the first group), with the pooled variance. Equivalent to
|
|
158
|
-
* PMCMRplus
|
|
176
|
+
* `PMCMRplus::dunnettTest()` in R. The p-values are the exact multivariate t probabilities (R approximates them by
|
|
159
177
|
* randomised integration); two-sided, as in PMCMRplus, `min(1, 2 P(max T_i >= |t|))`.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
182
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
183
|
+
* dunnettTest(x, g).pValue; // [[0.026103399464872296], [0.0011111316275120736]]
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @category Multiple comparisons
|
|
160
187
|
*/
|
|
161
188
|
export function dunnettTest(x, g, options = {}) {
|
|
162
189
|
const alternative = matchAlternative(options.alternative);
|
|
@@ -174,12 +201,21 @@ export function dunnettTest(x, g, options = {}) {
|
|
|
174
201
|
/**
|
|
175
202
|
* Steel's many-to-one rank test in its normal approximation: the Mann-Whitney statistic of each group against the
|
|
176
203
|
* control (the first group), each pair ranked on its own (midranks), standardised with the tie-corrected variance.
|
|
177
|
-
* Equivalent to PMCMRplus
|
|
204
|
+
* Equivalent to `PMCMRplus::manyOneUTest()` in R. The statistic is positive when the group ranks higher than the
|
|
178
205
|
* control. With `pAdjustMethod` `"single-step"` (the default; at least three groups) the p-values are the exact
|
|
179
206
|
* simultaneous normal probabilities (R approximates them by randomised integration).
|
|
180
207
|
*
|
|
181
208
|
* @param x Response values.
|
|
182
209
|
* @param g Group labels, parallel to `x` (groups in the order of the sorted labels).
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
214
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
215
|
+
* manyOneUTest(x, g).pValue; // [[0.08993551204759488], [0.08993551204759488]]
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @category Multiple comparisons
|
|
183
219
|
*/
|
|
184
220
|
export function manyOneUTest(x, g, options = {}) {
|
|
185
221
|
const alternative = matchAlternative(options.alternative);
|
|
@@ -213,8 +249,18 @@ export function manyOneUTest(x, g, options = {}) {
|
|
|
213
249
|
return manyOne(d, "Wilcoxon, Mann, Whittney U-test\n\tfor multiple comparisons with one control", z, p, adjust);
|
|
214
250
|
}
|
|
215
251
|
/**
|
|
216
|
-
* Dwass-Steel-Critchlow-Fligner all-pairs test of pairwise Mann-Whitney statistics. Equivalent to
|
|
217
|
-
* `dscfAllPairsTest()
|
|
252
|
+
* Dwass-Steel-Critchlow-Fligner all-pairs test of pairwise Mann-Whitney statistics. Equivalent to
|
|
253
|
+
* `PMCMRplus::dscfAllPairsTest()` in R. The statistic, sqrt(2) (U - n_i n_j / 2) / sqrt(Var U) with the smaller U,
|
|
254
|
+
* is never positive.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
259
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
260
|
+
* dscfAllPairsTest(x, g).pValue; // [[0.12122941216677251, NaN], [0.12122941216677251, 0.12122941216677251]]
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @category Multiple comparisons
|
|
218
264
|
*/
|
|
219
265
|
export function dscfAllPairsTest(x, g) {
|
|
220
266
|
const d = layout(x, g);
|
|
@@ -240,7 +286,16 @@ export function dscfAllPairsTest(x, g) {
|
|
|
240
286
|
}
|
|
241
287
|
/**
|
|
242
288
|
* Games-Howell all-pairs test of means with Welch's standard errors and degrees of freedom. Equivalent to
|
|
243
|
-
* PMCMRplus
|
|
289
|
+
* `PMCMRplus::gamesHowellTest()` in R.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
294
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
295
|
+
* gamesHowellTest(x, g).pValue; // [[0.05271565998164183, NaN], [0.009781818487986175, 0.08494498877912128]]
|
|
296
|
+
* ```
|
|
297
|
+
*
|
|
298
|
+
* @category Multiple comparisons
|
|
244
299
|
*/
|
|
245
300
|
export function gamesHowellTest(x, g) {
|
|
246
301
|
const d = layout(x, g);
|
|
@@ -253,7 +308,18 @@ export function gamesHowellTest(x, g) {
|
|
|
253
308
|
});
|
|
254
309
|
return allPairs(d, "Games-Howell test", q, p, "none");
|
|
255
310
|
}
|
|
256
|
-
/**
|
|
311
|
+
/**
|
|
312
|
+
* Tukey's all-pairs test of means (Tukey-Kramer for unequal sizes). Equivalent to `PMCMRplus::tukeyTest()` in R.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
317
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
318
|
+
* tukeyTest(x, g).pValue; // [[0.03403130149294014, NaN], [0.001492661804896774, 0.04527523376597547]]
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @category Multiple comparisons
|
|
322
|
+
*/
|
|
257
323
|
export function tukeyTest(x, g) {
|
|
258
324
|
const d = layout(x, g);
|
|
259
325
|
const { m, s2, df } = pooled(d);
|
|
@@ -262,12 +328,28 @@ export function tukeyTest(x, g) {
|
|
|
262
328
|
return allPairs(d, "Tukey's test", q, p, "single-step");
|
|
263
329
|
}
|
|
264
330
|
/**
|
|
265
|
-
* Steel's many-to-one rank test
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* internally.
|
|
331
|
+
* Steel's many-to-one rank test. Equivalent to `PMCMRplus::steelTest()` in R. It behaves as `steelTest()` of
|
|
332
|
+
* PMCMRplus 1.9.12 does: that fails on every input, so this reproduces its errors. A two-sided
|
|
333
|
+
* alternative is rejected (`'arg' should be one of “greater”, “less”`), unequal group sizes give `Steel's test is
|
|
334
|
+
* only valid for balanced designs.`, and balanced data the error PMCMRplus raises internally.
|
|
269
335
|
*
|
|
270
336
|
* @throws Always.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```ts
|
|
340
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
341
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
342
|
+
* const message = (() => {
|
|
343
|
+
* try {
|
|
344
|
+
* steelTest(x, g, { alternative: "greater" });
|
|
345
|
+
* } catch (e) {
|
|
346
|
+
* return (e as Error).message;
|
|
347
|
+
* }
|
|
348
|
+
* })();
|
|
349
|
+
* message; // "'data' must be of a vector type, was 'NULL'"
|
|
350
|
+
* ```
|
|
351
|
+
*
|
|
352
|
+
* @category Multiple comparisons
|
|
271
353
|
*/
|
|
272
354
|
export function steelTest(x, g, options = {}) {
|
|
273
355
|
const alternative = options.alternative === undefined ? "greater" : matchAlternative(options.alternative);
|
|
@@ -279,9 +361,20 @@ export function steelTest(x, g, options = {}) {
|
|
|
279
361
|
throw new Error("'data' must be of a vector type, was 'NULL'");
|
|
280
362
|
}
|
|
281
363
|
/**
|
|
282
|
-
* Dunn's test of all pairs of mean ranks. Equivalent to dunn.test
|
|
364
|
+
* Dunn's test of all pairs of mean ranks. Equivalent to `dunn.test::dunn.test(x, g, method, altp)` in R. The step-wise
|
|
283
365
|
* adjustments multiply (or transform) each p-value by the factor of its rank and cap it at 1, without enforcing
|
|
284
366
|
* monotonicity, as dunn.test does (unlike `pAdjust`).
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
371
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
372
|
+
* const r = dunnTest(x, g, { method: "bonferroni" });
|
|
373
|
+
* r.comparisons; // ["a - b", "a - c", "b - c"]
|
|
374
|
+
* r.PAdjusted; // [0.26956874231849964, 0.01093553713730346, 0.26956874231849964]
|
|
375
|
+
* ```
|
|
376
|
+
*
|
|
377
|
+
* @category Multiple comparisons
|
|
285
378
|
*/
|
|
286
379
|
export function dunnTest(x, g, options = {}) {
|
|
287
380
|
const method = options.method ?? "none";
|
|
@@ -347,10 +440,21 @@ function dunnAdjust(P, method) {
|
|
|
347
440
|
}
|
|
348
441
|
}
|
|
349
442
|
/**
|
|
350
|
-
* Dunnett's many-to-one comparisons of a one-way ANOVA with simultaneous p-values. Equivalent to
|
|
351
|
-
* `summary(glht(aov(y ~ g), linfct = mcp(g = "Dunnett"), alternative))`, with the
|
|
352
|
-
* (R approximates them by randomised integration): two-sided
|
|
353
|
-
* `P(min T_i <= t)`.
|
|
443
|
+
* Dunnett's many-to-one comparisons of a one-way ANOVA with simultaneous p-values. Equivalent to
|
|
444
|
+
* `multcomp::glht()` in R. It gives `summary(glht(aov(y ~ g), linfct = mcp(g = "Dunnett"), alternative))`, with the
|
|
445
|
+
* exact multivariate t probabilities (R approximates them by randomised integration): two-sided
|
|
446
|
+
* `P(max |T_i| >= |t|)`, greater `P(max T_i >= t)`, less `P(min T_i <= t)`.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```ts
|
|
450
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
451
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
452
|
+
* const r = glhtDunnett(x, g);
|
|
453
|
+
* r.names; // ["b - a", "c - a"]
|
|
454
|
+
* r.p; // [0.02601829573165104, 0.0011091043143827048]
|
|
455
|
+
* ```
|
|
456
|
+
*
|
|
457
|
+
* @category Multiple comparisons
|
|
354
458
|
*/
|
|
355
459
|
export function glhtDunnett(x, g, options = {}) {
|
|
356
460
|
const alternative = matchAlternative(options.alternative);
|
|
@@ -1,36 +1,75 @@
|
|
|
1
1
|
import type { HTest, Sample } from "./types.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Result of a normality test: no `alternative`, as nortest returns none.
|
|
4
|
+
*
|
|
5
|
+
* @category Hypothesis tests
|
|
6
|
+
*/
|
|
3
7
|
export type NormalityTestResult = Omit<HTest, "alternative">;
|
|
4
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Result of {@link cvmTest}, with nortest's warning for a p-value below the approximation's range.
|
|
10
|
+
*
|
|
11
|
+
* @category Hypothesis tests
|
|
12
|
+
*/
|
|
5
13
|
export interface CvmTestResult extends NormalityTestResult {
|
|
14
|
+
/** Warnings, as nortest gives them (empty when there are none). */
|
|
6
15
|
warnings: string[];
|
|
7
16
|
}
|
|
8
17
|
/**
|
|
9
|
-
* Anderson-Darling test for normality. Equivalent to nortest
|
|
18
|
+
* Anderson-Darling test for normality. Equivalent to `nortest::ad.test()` in R. `NaN` values are dropped; at least 8
|
|
10
19
|
* values are needed.
|
|
11
20
|
*
|
|
12
21
|
* @example
|
|
13
22
|
* ```ts
|
|
14
23
|
* adTest([2.1, 3.4, 1.9, 5.6, 4.4, 3.8, 2.9, 4.1, 3.3, 2.6]).statistic; // 0.15414195923525043
|
|
15
24
|
* ```
|
|
25
|
+
*
|
|
26
|
+
* @category Hypothesis tests
|
|
16
27
|
*/
|
|
17
28
|
export declare function adTest(x: Sample): NormalityTestResult;
|
|
18
29
|
/**
|
|
19
|
-
* Cramer-von Mises test for normality. Equivalent to nortest
|
|
30
|
+
* Cramer-von Mises test for normality. Equivalent to `nortest::cvm.test()` in R. `NaN` values are dropped; at least 8
|
|
20
31
|
* values are needed.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
36
|
+
* cvmTest(x).pValue; // 0.8725514730213816
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @category Hypothesis tests
|
|
21
40
|
*/
|
|
22
41
|
export declare function cvmTest(x: Sample): CvmTestResult;
|
|
23
42
|
/**
|
|
24
|
-
* Lilliefors (Kolmogorov-Smirnov) test for normality. Equivalent to nortest
|
|
43
|
+
* Lilliefors (Kolmogorov-Smirnov) test for normality. Equivalent to `nortest::lillie.test()` in R. `NaN` values are
|
|
25
44
|
* dropped; at least 5 values are needed.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
49
|
+
* lillieTest(x).pValue; // 0.9287268902599117
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @category Hypothesis tests
|
|
26
53
|
*/
|
|
27
54
|
export declare function lillieTest(x: Sample): NormalityTestResult;
|
|
28
55
|
/**
|
|
29
|
-
* Shapiro-Francia test for normality. Equivalent to nortest
|
|
30
|
-
* must be between 5 and 5000.
|
|
56
|
+
* Shapiro-Francia test for normality. Equivalent to `nortest::sf.test()` in R. `NaN` values are dropped; the sample
|
|
57
|
+
* size must be between 5 and 5000.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
62
|
+
* sfTest(x).pValue; // 0.8583583366365347
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @category Hypothesis tests
|
|
31
66
|
*/
|
|
32
67
|
export declare function sfTest(x: Sample): NormalityTestResult;
|
|
33
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Options for {@link pearsonTest}.
|
|
70
|
+
*
|
|
71
|
+
* @category Hypothesis tests
|
|
72
|
+
*/
|
|
34
73
|
export interface PearsonTestOptions {
|
|
35
74
|
/** Number of classes. Default `ceil(2 n^(2/5))`. */
|
|
36
75
|
nClasses?: number;
|
|
@@ -39,6 +78,14 @@ export interface PearsonTestOptions {
|
|
|
39
78
|
}
|
|
40
79
|
/**
|
|
41
80
|
* Pearson chi-square test for normality, with classes of equal probability under the fitted normal distribution.
|
|
42
|
-
* Equivalent to nortest
|
|
81
|
+
* Equivalent to `nortest::pearson.test()` in R. `NaN` values are dropped.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
86
|
+
* pearsonTest(x).pValue; // 0.8494670333918255
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @category Hypothesis tests
|
|
43
90
|
*/
|
|
44
91
|
export declare function pearsonTest(x: Sample, options?: PearsonTestOptions): NormalityTestResult;
|
|
@@ -20,13 +20,15 @@ function standardized(xs) {
|
|
|
20
20
|
return xs.map((v) => (v - m) / s);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* Anderson-Darling test for normality. Equivalent to nortest
|
|
23
|
+
* Anderson-Darling test for normality. Equivalent to `nortest::ad.test()` in R. `NaN` values are dropped; at least 8
|
|
24
24
|
* values are needed.
|
|
25
25
|
*
|
|
26
26
|
* @example
|
|
27
27
|
* ```ts
|
|
28
28
|
* adTest([2.1, 3.4, 1.9, 5.6, 4.4, 3.8, 2.9, 4.1, 3.3, 2.6]).statistic; // 0.15414195923525043
|
|
29
29
|
* ```
|
|
30
|
+
*
|
|
31
|
+
* @category Hypothesis tests
|
|
30
32
|
*/
|
|
31
33
|
export function adTest(x) {
|
|
32
34
|
const xs = sorted(x);
|
|
@@ -54,8 +56,16 @@ export function adTest(x) {
|
|
|
54
56
|
return { method: "Anderson-Darling normality test", statistic: a, statisticName: "A", pValue };
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
57
|
-
* Cramer-von Mises test for normality. Equivalent to nortest
|
|
59
|
+
* Cramer-von Mises test for normality. Equivalent to `nortest::cvm.test()` in R. `NaN` values are dropped; at least 8
|
|
58
60
|
* values are needed.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
65
|
+
* cvmTest(x).pValue; // 0.8725514730213816
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @category Hypothesis tests
|
|
59
69
|
*/
|
|
60
70
|
export function cvmTest(x) {
|
|
61
71
|
const xs = sorted(x);
|
|
@@ -85,8 +95,16 @@ export function cvmTest(x) {
|
|
|
85
95
|
return { method: "Cramer-von Mises normality test", statistic: w, statisticName: "W", pValue, warnings };
|
|
86
96
|
}
|
|
87
97
|
/**
|
|
88
|
-
* Lilliefors (Kolmogorov-Smirnov) test for normality. Equivalent to nortest
|
|
98
|
+
* Lilliefors (Kolmogorov-Smirnov) test for normality. Equivalent to `nortest::lillie.test()` in R. `NaN` values are
|
|
89
99
|
* dropped; at least 5 values are needed.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
104
|
+
* lillieTest(x).pValue; // 0.9287268902599117
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @category Hypothesis tests
|
|
90
108
|
*/
|
|
91
109
|
export function lillieTest(x) {
|
|
92
110
|
const xs = sorted(x);
|
|
@@ -120,8 +138,16 @@ export function lillieTest(x) {
|
|
|
120
138
|
return { method: "Lilliefors (Kolmogorov-Smirnov) normality test", statistic: d, statisticName: "D", pValue };
|
|
121
139
|
}
|
|
122
140
|
/**
|
|
123
|
-
* Shapiro-Francia test for normality. Equivalent to nortest
|
|
124
|
-
* must be between 5 and 5000.
|
|
141
|
+
* Shapiro-Francia test for normality. Equivalent to `nortest::sf.test()` in R. `NaN` values are dropped; the sample
|
|
142
|
+
* size must be between 5 and 5000.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
147
|
+
* sfTest(x).pValue; // 0.8583583366365347
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @category Hypothesis tests
|
|
125
151
|
*/
|
|
126
152
|
export function sfTest(x) {
|
|
127
153
|
const xs = sorted(x);
|
|
@@ -139,7 +165,15 @@ export function sfTest(x) {
|
|
|
139
165
|
}
|
|
140
166
|
/**
|
|
141
167
|
* Pearson chi-square test for normality, with classes of equal probability under the fitted normal distribution.
|
|
142
|
-
* Equivalent to nortest
|
|
168
|
+
* Equivalent to `nortest::pearson.test()` in R. `NaN` values are dropped.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
173
|
+
* pearsonTest(x).pValue; // 0.8494670333918255
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @category Hypothesis tests
|
|
143
177
|
*/
|
|
144
178
|
export function pearsonTest(x, options = {}) {
|
|
145
179
|
const xs = sorted(x);
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import type { DataFrame } from "../models/modelFrame.js";
|
|
2
2
|
import { type GroupLabel } from "./groups.js";
|
|
3
3
|
import type { HTest, Sample } from "./types.js";
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Options for {@link onewayTest}.
|
|
6
|
+
*
|
|
7
|
+
* @category Hypothesis tests
|
|
8
|
+
*/
|
|
5
9
|
export interface OnewayTestOptions {
|
|
6
10
|
/** Assume equal variances (the classical F test). Default `false` (Welch's test). */
|
|
7
11
|
varEqual?: boolean;
|
|
8
12
|
}
|
|
9
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Result of {@link onewayTest}: an F statistic with two degrees of freedom.
|
|
15
|
+
*
|
|
16
|
+
* @category Hypothesis tests
|
|
17
|
+
*/
|
|
10
18
|
export interface OnewayTestResult extends Omit<HTest, "alternative" | "parameter" | "parameterName"> {
|
|
11
19
|
/** `[num df, denom df]`. */
|
|
12
20
|
parameter: [number, number];
|
|
21
|
+
/** Names of `parameter`: `["num df", "denom df"]`. */
|
|
13
22
|
parameterName: [string, string];
|
|
14
23
|
}
|
|
15
24
|
/**
|
|
@@ -20,10 +29,20 @@ export interface OnewayTestResult extends Omit<HTest, "alternative" | "parameter
|
|
|
20
29
|
* @param g Group labels, parallel to `x` (or the options, when `x` is an array of samples).
|
|
21
30
|
*
|
|
22
31
|
* There is also a formula form, `onewayTest("y ~ A + B", data, options)` (next overload).
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const r = onewayTest([[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]]);
|
|
36
|
+
* r.statistic; // 0.39190547838578593 (Welch)
|
|
37
|
+
* r.parameter; // [2, 5.518701575163452]
|
|
38
|
+
* r.pValue; // 0.693185476837351
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @category Hypothesis tests
|
|
23
42
|
*/
|
|
24
43
|
export declare function onewayTest(x: Sample | readonly Sample[], g?: readonly GroupLabel[] | OnewayTestOptions, options?: OnewayTestOptions): OnewayTestResult;
|
|
25
44
|
/**
|
|
26
|
-
* One-way analysis of means from a formula and a data frame.
|
|
45
|
+
* One-way analysis of means from a formula and a data frame. As R's `oneway.test(formula, data)`:
|
|
27
46
|
* `"y ~ A"` has one group per level of `A`; with several factors, `"y ~ A + B"`, the groups are the combinations of
|
|
28
47
|
* their levels present in the data (R's `interaction()`, the first factor varying fastest). Only the variables of
|
|
29
48
|
* the formula count: the rows where one of them is missing are dropped.
|
|
@@ -36,5 +55,15 @@ export declare function onewayTest(formula: string, data: DataFrame, options?: O
|
|
|
36
55
|
/**
|
|
37
56
|
* Shapiro-Wilk test of normality. Equivalent to R's `shapiro.test()`. `NaN` values are dropped; the sample size must
|
|
38
57
|
* be between 3 and 5000.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
62
|
+
* const r = shapiroTest(x);
|
|
63
|
+
* r.statistic; // 0.9586525103840963
|
|
64
|
+
* r.pValue; // 0.7704047318146288
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @category Hypothesis tests
|
|
39
68
|
*/
|
|
40
69
|
export declare function shapiroTest(x: Sample): Omit<HTest, "alternative">;
|
package/dist/htest/onewayTest.js
CHANGED
|
@@ -73,6 +73,16 @@ export function onewayTest(x, g, options = {}) {
|
|
|
73
73
|
/**
|
|
74
74
|
* Shapiro-Wilk test of normality. Equivalent to R's `shapiro.test()`. `NaN` values are dropped; the sample size must
|
|
75
75
|
* be between 3 and 5000.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const x = [2.1, 3.4, 1.9, 5.6, 4.4, 3.3, 2.8, 4.1, 3.9, 6.2];
|
|
80
|
+
* const r = shapiroTest(x);
|
|
81
|
+
* r.statistic; // 0.9586525103840963
|
|
82
|
+
* r.pValue; // 0.7704047318146288
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @category Hypothesis tests
|
|
76
86
|
*/
|
|
77
87
|
export function shapiroTest(x) {
|
|
78
88
|
const xs = Array.from(x)
|
package/dist/htest/pAdjust.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adjustment method for {@link pAdjust}, as in R's `p.adjust.methods`. `"fdr"` is an alias of `"BH"`.
|
|
3
|
+
*
|
|
4
|
+
* @category Multiple comparisons
|
|
3
5
|
*/
|
|
4
6
|
export type PAdjustMethod = "holm" | "hochberg" | "hommel" | "bonferroni" | "BH" | "BY" | "fdr" | "none";
|
|
5
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Options for {@link pAdjust}.
|
|
9
|
+
*
|
|
10
|
+
* @category Multiple comparisons
|
|
11
|
+
*/
|
|
6
12
|
export interface PAdjustOptions {
|
|
7
13
|
/** Adjustment method. Default `"holm"`. Unambiguous abbreviations are accepted, as in R. */
|
|
8
14
|
method?: PAdjustMethod | (string & {});
|
|
@@ -30,5 +36,7 @@ export interface PAdjustOptions {
|
|
|
30
36
|
* pAdjust(p, "BH"); // [0.05, 0.05, 0.05, 0.05, 0.05]
|
|
31
37
|
* pAdjust(p, { method: "bonferroni", n: 10 });
|
|
32
38
|
* ```
|
|
39
|
+
*
|
|
40
|
+
* @category Multiple comparisons
|
|
33
41
|
*/
|
|
34
42
|
export declare function pAdjust(p: readonly number[] | Float64Array, options?: PAdjustOptions | PAdjustMethod | (string & {})): number[];
|
package/dist/htest/pAdjust.js
CHANGED
|
@@ -40,6 +40,8 @@ function matchMethod(m) {
|
|
|
40
40
|
* pAdjust(p, "BH"); // [0.05, 0.05, 0.05, 0.05, 0.05]
|
|
41
41
|
* pAdjust(p, { method: "bonferroni", n: 10 });
|
|
42
42
|
* ```
|
|
43
|
+
*
|
|
44
|
+
* @category Multiple comparisons
|
|
43
45
|
*/
|
|
44
46
|
export function pAdjust(p, options = {}) {
|
|
45
47
|
const opts = typeof options === "string" ? { method: options } : options;
|
package/dist/htest/pairwise.d.ts
CHANGED
|
@@ -2,7 +2,11 @@ import type { GroupLabel } from "./groups.js";
|
|
|
2
2
|
import { type PAdjustMethod } from "./pAdjust.js";
|
|
3
3
|
import { type Alternative, type Sample } from "./types.js";
|
|
4
4
|
import { type WilcoxTestOptions } from "./wilcoxTest.js";
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Result of the pairwise comparisons (R's `pairwise.htest`).
|
|
7
|
+
*
|
|
8
|
+
* @category Multiple comparisons
|
|
9
|
+
*/
|
|
6
10
|
export interface PairwiseResult {
|
|
7
11
|
/** Description of the tests (R's `method`). */
|
|
8
12
|
method: string;
|
|
@@ -18,14 +22,22 @@ export interface PairwiseResult {
|
|
|
18
22
|
/** Adjustment method. */
|
|
19
23
|
pAdjustMethod: PAdjustMethod | string;
|
|
20
24
|
}
|
|
21
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Common options of the pairwise comparisons.
|
|
27
|
+
*
|
|
28
|
+
* @category Multiple comparisons
|
|
29
|
+
*/
|
|
22
30
|
export interface PairwiseOptions {
|
|
23
31
|
/** p-value adjustment (see `pAdjust`). Default `"holm"`. */
|
|
24
32
|
pAdjustMethod?: PAdjustMethod | (string & {});
|
|
25
33
|
/** Alternative hypothesis for each comparison of row group against column group. Default `"two.sided"`. */
|
|
26
34
|
alternative?: Alternative | "two" | "l" | "g";
|
|
27
35
|
}
|
|
28
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Options for {@link pairwiseTTest}.
|
|
38
|
+
*
|
|
39
|
+
* @category Multiple comparisons
|
|
40
|
+
*/
|
|
29
41
|
export interface PairwiseTTestOptions extends PairwiseOptions {
|
|
30
42
|
/** Pool the standard deviation over all groups. Default `!paired`. */
|
|
31
43
|
poolSd?: boolean;
|
|
@@ -37,17 +49,43 @@ export interface PairwiseTTestOptions extends PairwiseOptions {
|
|
|
37
49
|
*
|
|
38
50
|
* @param x Response values.
|
|
39
51
|
* @param g Group labels, parallel to `x`.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
56
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
57
|
+
* pairwiseTTest(x, g).pValue; // [[0.029519264601117815, NaN], [0.0018407330776394456, 0.029519264601117815]]
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @category Multiple comparisons
|
|
40
61
|
*/
|
|
41
62
|
export declare function pairwiseTTest(x: Sample, g: readonly GroupLabel[], options?: PairwiseTTestOptions): PairwiseResult;
|
|
42
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Options for {@link pairwiseWilcoxTest}: those of the comparisons themselves, as for `wilcoxTest`.
|
|
65
|
+
*
|
|
66
|
+
* @category Multiple comparisons
|
|
67
|
+
*/
|
|
43
68
|
export interface PairwiseWilcoxTestOptions extends PairwiseOptions, Omit<WilcoxTestOptions, "alternative" | "confInt"> {
|
|
44
69
|
}
|
|
45
70
|
/**
|
|
46
71
|
* Pairwise Wilcoxon rank sum (or signed rank, with `paired`) tests between groups, with adjusted p-values. Equivalent
|
|
47
72
|
* to R's `pairwise.wilcox.test()`. `method` is that of the last comparison, as in R.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
77
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
78
|
+
* pairwiseWilcoxTest(x, g).pValue; // [[0.3, NaN], [0.3, 0.3]]
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @category Multiple comparisons
|
|
48
82
|
*/
|
|
49
83
|
export declare function pairwiseWilcoxTest(x: Sample, g: readonly GroupLabel[], options?: PairwiseWilcoxTestOptions): PairwiseResult;
|
|
50
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Options for {@link pairwisePropTest}.
|
|
86
|
+
*
|
|
87
|
+
* @category Multiple comparisons
|
|
88
|
+
*/
|
|
51
89
|
export interface PairwisePropTestOptions {
|
|
52
90
|
/** p-value adjustment (see `pAdjust`). Default `"holm"`. */
|
|
53
91
|
pAdjustMethod?: PAdjustMethod | (string & {});
|
|
@@ -60,5 +98,12 @@ export interface PairwisePropTestOptions {
|
|
|
60
98
|
* @param x Numbers of successes per group.
|
|
61
99
|
* @param n Numbers of trials per group. Groups with `NaN` in `x` or `n` are dropped (the rows and columns are then
|
|
62
100
|
* numbered over the groups kept, as in R).
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* pairwisePropTest([15, 25, 40], [50, 50, 50]).pValue; // [[0.06619257972219345, NaN], [0.000004217380554293543, 0.006666708050273146]]
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @category Multiple comparisons
|
|
63
108
|
*/
|
|
64
109
|
export declare function pairwisePropTest(x: readonly number[], n: readonly number[], options?: PairwisePropTestOptions): PairwiseResult;
|
package/dist/htest/pairwise.js
CHANGED
|
@@ -61,6 +61,15 @@ function result(method, levels, pValue, adjust) {
|
|
|
61
61
|
*
|
|
62
62
|
* @param x Response values.
|
|
63
63
|
* @param g Group labels, parallel to `x`.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
68
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
69
|
+
* pairwiseTTest(x, g).pValue; // [[0.029519264601117815, NaN], [0.0018407330776394456, 0.029519264601117815]]
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @category Multiple comparisons
|
|
64
73
|
*/
|
|
65
74
|
export function pairwiseTTest(x, g, options = {}) {
|
|
66
75
|
const paired = options.paired ?? false;
|
|
@@ -106,6 +115,15 @@ export function pairwiseTTest(x, g, options = {}) {
|
|
|
106
115
|
/**
|
|
107
116
|
* Pairwise Wilcoxon rank sum (or signed rank, with `paired`) tests between groups, with adjusted p-values. Equivalent
|
|
108
117
|
* to R's `pairwise.wilcox.test()`. `method` is that of the last comparison, as in R.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
122
|
+
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
123
|
+
* pairwiseWilcoxTest(x, g).pValue; // [[0.3, NaN], [0.3, 0.3]]
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @category Multiple comparisons
|
|
109
127
|
*/
|
|
110
128
|
export function pairwiseWilcoxTest(x, g, options = {}) {
|
|
111
129
|
const { pAdjustMethod, alternative, ...rest } = options;
|
|
@@ -128,6 +146,13 @@ export function pairwiseWilcoxTest(x, g, options = {}) {
|
|
|
128
146
|
* @param x Numbers of successes per group.
|
|
129
147
|
* @param n Numbers of trials per group. Groups with `NaN` in `x` or `n` are dropped (the rows and columns are then
|
|
130
148
|
* numbered over the groups kept, as in R).
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* pairwisePropTest([15, 25, 40], [50, 50, 50]).pValue; // [[0.06619257972219345, NaN], [0.000004217380554293543, 0.006666708050273146]]
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @category Multiple comparisons
|
|
131
156
|
*/
|
|
132
157
|
export function pairwisePropTest(x, n, options = {}) {
|
|
133
158
|
if (x.length !== n.length)
|