@numero-uno-jpn/rstats 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +128 -0
- package/README.ja.md +44 -18
- package/README.md +45 -18
- package/dist/chunks/chunk-2C33MXSW.js +3 -0
- package/dist/chunks/chunk-34S5SQY6.js +2 -0
- package/dist/chunks/{chunk-URIO5LY5.js → chunk-4WE3OO62.js} +2 -2
- package/dist/chunks/chunk-5AYHCITP.js +2 -0
- package/dist/chunks/chunk-6JJQL6HL.js +2 -0
- package/dist/chunks/chunk-C7V2FH6L.js +3 -0
- package/dist/chunks/chunk-CZI7KUO3.js +2 -0
- package/dist/chunks/chunk-DXI5N2ET.js +2 -0
- package/dist/chunks/chunk-FY3FVOBM.js +2 -0
- package/dist/chunks/{chunk-QNNL7AZ3.js → chunk-H3WVPZDL.js} +2 -2
- package/dist/chunks/chunk-LHUIJQHY.js +2 -0
- package/dist/chunks/chunk-LV3W2F7N.js +2 -0
- package/dist/chunks/chunk-M4ITG7YR.js +2 -0
- package/dist/chunks/{chunk-FLJNSXSW.js → chunk-NSYZTS26.js} +2 -2
- package/dist/chunks/chunk-ONY5CISH.js +2 -0
- package/dist/chunks/chunk-RFE7MVP7.js +2 -0
- package/dist/chunks/{chunk-W26LRYOJ.js → chunk-SE7V2KLO.js} +1 -1
- package/dist/chunks/chunk-THIGHOKK.js +2 -0
- package/dist/chunks/chunk-TNMJPQPV.js +2 -0
- package/dist/chunks/chunk-WM7VFXTV.js +2 -0
- package/dist/chunks/chunk-WMDYDTVQ.js +2 -0
- package/dist/chunks/chunk-XLSFJTTK.js +2 -0
- package/dist/chunks/{chunk-5UQCRBAG.js → chunk-Z37NELOS.js} +1 -1
- package/dist/chunks/chunk-ZFQWB222.js +2 -0
- package/dist/data/grouping.js +6 -2
- package/dist/descriptive/basic.js +20 -0
- package/dist/descriptive/cov.js +11 -0
- package/dist/descriptive/dataFrames.js +13 -5
- package/dist/descriptive/factanal.d.ts +2 -0
- package/dist/descriptive/factanal.js +10 -2
- package/dist/descriptive/hist.js +6 -0
- package/dist/descriptive/moments.js +14 -0
- package/dist/descriptive/omega.js +8 -3
- package/dist/descriptive/pivot.d.ts +4 -1
- package/dist/descriptive/pivot.js +27 -13
- package/dist/descriptive/quantile.js +8 -0
- package/dist/descriptive/rank.js +4 -0
- package/dist/descriptive/table.d.ts +20 -1
- package/dist/descriptive/table.js +14 -14
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.js +8 -0
- package/dist/distributions/beta.js +9 -0
- package/dist/distributions/binomial.js +9 -0
- package/dist/distributions/cauchy.js +9 -0
- package/dist/distributions/chisq.js +9 -0
- package/dist/distributions/exponential.js +9 -0
- package/dist/distributions/f.js +9 -0
- package/dist/distributions/gamma.js +8 -0
- package/dist/distributions/geometric.js +9 -0
- package/dist/distributions/hypergeometric.js +8 -0
- package/dist/distributions/invgamma.js +8 -0
- package/dist/distributions/kumaraswamy.js +9 -0
- package/dist/distributions/laplace.js +9 -0
- package/dist/distributions/logistic.js +9 -0
- package/dist/distributions/lognormal.js +8 -0
- package/dist/distributions/multinomial.js +4 -0
- package/dist/distributions/negbinomial.js +8 -0
- package/dist/distributions/normal.js +8 -0
- package/dist/distributions/pareto.js +8 -0
- package/dist/distributions/poisson.js +9 -0
- package/dist/distributions/signrank.js +9 -0
- package/dist/distributions/summary.d.ts +2 -1
- package/dist/distributions/summary.js +31 -1
- package/dist/distributions/t.js +9 -0
- package/dist/distributions/triangular.js +9 -0
- package/dist/distributions/tukey.js +6 -0
- package/dist/distributions/uniform.js +8 -0
- package/dist/distributions/weibull.js +8 -0
- package/dist/distributions/wilcox.js +9 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +3 -1
- package/dist/entries/descriptive.js +1 -1
- package/dist/entries/distributions.d.ts +1 -0
- package/dist/entries/distributions.js +2 -0
- package/dist/entries/linalg.d.ts +3 -1
- package/dist/entries/mixed.d.ts +3 -0
- package/dist/entries/mixed.js +2 -0
- package/dist/entries/numerics.d.ts +2 -1
- package/dist/entries/tests.d.ts +8 -5
- package/dist/entries/tests.js +3 -1
- package/dist/htest/agreement.d.ts +13 -0
- package/dist/htest/agreement.js +46 -7
- package/dist/htest/ansariTest.d.ts +2 -1
- package/dist/htest/ansariTest.js +43 -12
- package/dist/htest/aov.d.ts +28 -22
- package/dist/htest/aov.js +42 -13
- package/dist/htest/binomTest.js +6 -0
- package/dist/htest/brunnerMunzelTest.js +5 -0
- package/dist/htest/chisqTest.d.ts +3 -1
- package/dist/htest/chisqTest.js +21 -3
- package/dist/htest/cor.d.ts +7 -1
- package/dist/htest/cor.js +40 -7
- package/dist/htest/core/simulate.d.ts +6 -0
- package/dist/htest/core/simulate.js +20 -0
- package/dist/htest/effectSize.d.ts +3 -0
- package/dist/htest/effectSize.js +28 -8
- package/dist/htest/fisherTest.d.ts +2 -1
- package/dist/htest/fisherTest.js +52 -6
- package/dist/htest/ksTest.d.ts +4 -0
- package/dist/htest/ksTest.js +13 -4
- package/dist/htest/leveneTest.d.ts +2 -0
- package/dist/htest/leveneTest.js +9 -3
- package/dist/htest/mantelhaenTest.js +7 -0
- package/dist/htest/mcnemarTest.js +8 -0
- package/dist/htest/multipleComparisons.d.ts +16 -25
- package/dist/htest/multipleComparisons.js +26 -43
- package/dist/htest/normalityTests.js +10 -4
- package/dist/htest/onewayTest.js +10 -0
- package/dist/htest/pAdjust.js +4 -0
- package/dist/htest/pairwise.d.ts +2 -0
- package/dist/htest/pairwise.js +29 -6
- package/dist/htest/poissonTest.js +6 -0
- package/dist/htest/polycor.js +20 -10
- package/dist/htest/power.d.ts +4 -0
- package/dist/htest/power.js +16 -2
- package/dist/htest/propTest.d.ts +3 -0
- package/dist/htest/propTest.js +23 -2
- package/dist/htest/pwr.d.ts +38 -1
- package/dist/htest/pwr.js +38 -15
- package/dist/htest/rankTests.js +7 -1
- package/dist/htest/tTest.d.ts +2 -0
- package/dist/htest/tTest.js +9 -0
- package/dist/htest/testFormula.js +11 -11
- package/dist/htest/trendTests.d.ts +21 -1
- package/dist/htest/trendTests.js +13 -18
- package/dist/htest/types.d.ts +2 -0
- package/dist/htest/varTest.js +7 -0
- package/dist/htest/wilcoxTest.js +51 -9
- package/dist/internal/checkOptions.d.ts +11 -0
- package/dist/internal/checkOptions.js +31 -0
- package/dist/internal/optionalArgs.d.ts +12 -0
- package/dist/internal/optionalArgs.js +46 -0
- package/dist/internal/warnings.d.ts +66 -0
- package/dist/internal/warnings.js +122 -0
- package/dist/linalg/basic.js +7 -0
- package/dist/linalg/chol.js +6 -0
- package/dist/linalg/eigen.js +4 -0
- package/dist/linalg/expm.js +4 -0
- package/dist/linalg/kappa.js +6 -0
- package/dist/linalg/lu.js +5 -0
- package/dist/linalg/norm.js +4 -0
- package/dist/linalg/ops.d.ts +27 -2
- package/dist/linalg/ops.js +14 -13
- package/dist/linalg/qr.js +14 -0
- package/dist/linalg/solve.js +9 -0
- package/dist/linalg/svd.js +6 -2
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +4 -4
- package/dist/models/anovaSequential.d.ts +16 -1
- package/dist/models/anovaSequential.js +50 -7
- package/dist/models/aovEz.js +16 -11
- package/dist/models/aovStrata.js +15 -4
- package/dist/models/carAnova.js +11 -17
- package/dist/models/coxph.d.ts +6 -0
- package/dist/models/coxph.js +21 -6
- package/dist/models/glm.d.ts +22 -2
- package/dist/models/glm.js +32 -22
- package/dist/models/glmAnova.js +8 -3
- package/dist/models/glmConfint.js +6 -2
- package/dist/models/glmFamily.d.ts +1 -6
- package/dist/models/glmFamily.js +3 -22
- package/dist/models/lm.js +13 -3
- package/dist/models/lmer.d.ts +11 -6
- package/dist/models/lmer.js +20 -15
- package/dist/models/lmerAnova.d.ts +3 -3
- package/dist/models/lmerAnova.js +10 -5
- package/dist/models/lmerTest.d.ts +4 -4
- package/dist/models/lmerTest.js +19 -11
- package/dist/models/mauchly.d.ts +2 -0
- package/dist/models/mauchly.js +7 -2
- package/dist/models/modelFrame.js +2 -2
- package/dist/models/modelMatrix.js +7 -2
- package/dist/models/survival.d.ts +6 -0
- package/dist/models/survival.js +9 -2
- package/dist/numerics/deriv.js +8 -0
- package/dist/numerics/integrate.js +8 -0
- package/dist/numerics/interp.d.ts +32 -7
- package/dist/numerics/interp.js +27 -9
- package/dist/numerics/ode.js +4 -0
- package/dist/numerics.js +2 -2
- package/dist/optim/optim.js +17 -2
- package/dist/random/beta.js +5 -0
- package/dist/random/continuous.js +17 -0
- package/dist/random/extra.js +13 -0
- package/dist/random/gamma.js +11 -0
- package/dist/random/poisson.js +5 -0
- package/dist/random/rng.js +4 -0
- package/dist/random/sample.js +6 -0
- package/dist/rstats.js +17 -14
- package/dist/special/besselIK.js +7 -0
- package/dist/special/choose.js +7 -0
- package/dist/special/psigamma.js +7 -0
- package/dist/special.js +2 -2
- package/dist/tests.js +15 -11
- package/llms.txt +5 -2
- package/package.json +19 -10
- package/dist/chunks/chunk-2D2IQWUQ.js +0 -2
- package/dist/chunks/chunk-6CSTWA5E.js +0 -2
- package/dist/chunks/chunk-72Y3HZID.js +0 -2
- package/dist/chunks/chunk-BG2KLEHM.js +0 -2
- package/dist/chunks/chunk-CMEKBNHQ.js +0 -2
- package/dist/chunks/chunk-GM53LWSR.js +0 -2
- package/dist/chunks/chunk-JBCA56ZS.js +0 -3
- package/dist/chunks/chunk-K3RJAD2T.js +0 -2
- package/dist/chunks/chunk-KAZRWIB5.js +0 -2
- package/dist/chunks/chunk-KBVVIMXX.js +0 -3
- package/dist/chunks/chunk-N3SIFCZX.js +0 -2
- package/dist/chunks/chunk-SC6CV4Z3.js +0 -2
- package/dist/chunks/chunk-SYWOBOTR.js +0 -2
- package/dist/chunks/chunk-VTUGG2SV.js +0 -2
- package/dist/chunks/chunk-XHETEYVC.js +0 -2
- package/dist/chunks/chunk-YRZWONZB.js +0 -3
- package/dist/chunks/chunk-ZGABZMWX.js +0 -2
|
@@ -20,6 +20,9 @@ import { ldexp, productOver, squareOver } from "../internal/summary.js";
|
|
|
20
20
|
import { ddAdd } from "../special/dd.js";
|
|
21
21
|
import { ConvolvedNoncentralHyper, conditionalMLE, lowerLimit, upperLimit } from "./core/mantelhaen.js";
|
|
22
22
|
import { checkConfLevelOpen, matchAlternative } from "./types.js";
|
|
23
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
24
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
25
|
+
const MANTELHAEN_TEST_KEYS = ["alternative", "correct", "exact", "confLevel"];
|
|
23
26
|
/**
|
|
24
27
|
* Cochran-Mantel-Haenszel chi-squared test of conditional independence in a set of contingency tables, one per
|
|
25
28
|
* stratum. Equivalent to R's `mantelhaen.test()`. Takes the strata as R takes a three-dimensional array.
|
|
@@ -43,6 +46,7 @@ import { checkConfLevelOpen, matchAlternative } from "./types.js";
|
|
|
43
46
|
* @category Hypothesis tests
|
|
44
47
|
*/
|
|
45
48
|
export function mantelhaenTest(strata, options = {}) {
|
|
49
|
+
checkOptions(options, MANTELHAEN_TEST_KEYS, "mantelhaenTest"); // generated: option-keys.mjs
|
|
46
50
|
const K = strata.length;
|
|
47
51
|
if (K < 1)
|
|
48
52
|
throw new RangeError("'x' must have at least one stratum");
|
|
@@ -190,6 +194,7 @@ function asymptotic2x2xK(tables, totals, alternative, correct, confLevel) {
|
|
|
190
194
|
estimateNames: "common odds ratio",
|
|
191
195
|
nullValue: 1,
|
|
192
196
|
nullValueName: "common odds ratio",
|
|
197
|
+
warnings: [],
|
|
193
198
|
};
|
|
194
199
|
}
|
|
195
200
|
/**
|
|
@@ -242,6 +247,7 @@ function exact2x2xK(tables, alternative, confLevel) {
|
|
|
242
247
|
estimateNames: "common odds ratio",
|
|
243
248
|
nullValue: 1,
|
|
244
249
|
nullValueName: "common odds ratio",
|
|
250
|
+
warnings: [],
|
|
245
251
|
};
|
|
246
252
|
}
|
|
247
253
|
function general(strata, totals, I, J) {
|
|
@@ -267,6 +273,7 @@ function general(strata, totals, I, J) {
|
|
|
267
273
|
parameter: p,
|
|
268
274
|
parameterName: "df",
|
|
269
275
|
pValue: pgamma1(statistic, p / 2, 2, false, false),
|
|
276
|
+
warnings: [],
|
|
270
277
|
};
|
|
271
278
|
}
|
|
272
279
|
const MIN_NORMAL = 2 ** -1022;
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
import { pgamma1 } from "../distributions/gamma.js";
|
|
7
7
|
import { ldexp, squareOver } from "../internal/summary.js";
|
|
8
8
|
import { compareLabels, factorLabels } from "./groups.js";
|
|
9
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
10
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
11
|
+
import { isOptionsObject } from "../internal/optionalArgs.js";
|
|
12
|
+
const MCNEMAR_TEST_KEYS = ["correct"];
|
|
9
13
|
/**
|
|
10
14
|
* McNemar's chi-squared test for symmetry of rows and columns in a square table of counts. Equivalent to R's
|
|
11
15
|
* `mcnemar.test()`. Takes a matrix, or two factors given as paired category codes.
|
|
@@ -23,6 +27,9 @@ import { compareLabels, factorLabels } from "./groups.js";
|
|
|
23
27
|
* @category Hypothesis tests
|
|
24
28
|
*/
|
|
25
29
|
export function mcnemarTest(x, y, options = {}) {
|
|
30
|
+
if (isOptionsObject(y))
|
|
31
|
+
checkOptions(y, MCNEMAR_TEST_KEYS, "mcnemarTest"); // generated: option-keys.mjs
|
|
32
|
+
checkOptions(options, MCNEMAR_TEST_KEYS, "mcnemarTest"); // generated: option-keys.mjs
|
|
26
33
|
let table;
|
|
27
34
|
if (x.length > 0 && Array.isArray(x[0])) {
|
|
28
35
|
if (y !== undefined && !Array.isArray(y))
|
|
@@ -77,6 +84,7 @@ export function mcnemarTest(x, y, options = {}) {
|
|
|
77
84
|
parameter: df,
|
|
78
85
|
parameterName: "df",
|
|
79
86
|
pValue: pgamma1(statistic, df / 2, 2, false, false),
|
|
87
|
+
warnings: [],
|
|
80
88
|
};
|
|
81
89
|
}
|
|
82
90
|
/**
|
|
@@ -173,31 +173,6 @@ export declare function gamesHowellTest(x: Sample, g: readonly GroupLabel[]): PM
|
|
|
173
173
|
* @category Multiple comparisons
|
|
174
174
|
*/
|
|
175
175
|
export declare function tukeyTest(x: Sample, g: readonly GroupLabel[]): PMCMRResult;
|
|
176
|
-
/**
|
|
177
|
-
* Steel's many-to-one rank test. Equivalent to `PMCMRplus::steelTest()` in R. It behaves as `steelTest()` of
|
|
178
|
-
* PMCMRplus 1.9.12 does: that fails on every input, so this reproduces its errors. A two-sided
|
|
179
|
-
* alternative is rejected (`'arg' should be one of “greater”, “less”`), unequal group sizes give `Steel's test is
|
|
180
|
-
* only valid for balanced designs.`, and balanced data the error PMCMRplus raises internally.
|
|
181
|
-
*
|
|
182
|
-
* @throws Always.
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* ```ts
|
|
186
|
-
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
187
|
-
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
188
|
-
* const message = (() => {
|
|
189
|
-
* try {
|
|
190
|
-
* steelTest(x, g, { alternative: "greater" });
|
|
191
|
-
* } catch (e) {
|
|
192
|
-
* return (e as Error).message;
|
|
193
|
-
* }
|
|
194
|
-
* })();
|
|
195
|
-
* message; // "'data' must be of a vector type, was 'NULL'"
|
|
196
|
-
* ```
|
|
197
|
-
*
|
|
198
|
-
* @category Multiple comparisons
|
|
199
|
-
*/
|
|
200
|
-
export declare function steelTest(x: Sample, g: readonly GroupLabel[], options?: ManyOneTestOptions): never;
|
|
201
176
|
/**
|
|
202
177
|
* Adjustment method of {@link dunnTest} (dunn.test's `method`).
|
|
203
178
|
*
|
|
@@ -229,8 +204,16 @@ export interface DunnTestResult {
|
|
|
229
204
|
P: number[];
|
|
230
205
|
/** Adjusted p-values (no monotonicity step). */
|
|
231
206
|
PAdjusted: number[];
|
|
207
|
+
/** Alias of `Z`: the same array. */
|
|
208
|
+
zValue: number[];
|
|
209
|
+
/** Alias of `P`: the same array. */
|
|
210
|
+
pValue: number[];
|
|
211
|
+
/** Alias of `PAdjusted`: the same array. */
|
|
212
|
+
pAdjusted: number[];
|
|
232
213
|
/** Labels of the comparisons, `"<label j> - <label i>"`, in the order (2,1), (3,1), (3,2), (4,1), ... */
|
|
233
214
|
comparisons: string[];
|
|
215
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
216
|
+
warnings: string[];
|
|
234
217
|
}
|
|
235
218
|
/**
|
|
236
219
|
* Dunn's test of all pairs of mean ranks. Equivalent to `dunn.test::dunn.test(x, g, method, altp)` in R. The step-wise
|
|
@@ -275,8 +258,16 @@ export interface GlhtDunnettResult {
|
|
|
275
258
|
t: number[];
|
|
276
259
|
/** Simultaneous (single-step) p-values. */
|
|
277
260
|
p: number[];
|
|
261
|
+
/** Alias of `se`: the same array. */
|
|
262
|
+
stdError: number[];
|
|
263
|
+
/** Alias of `t`: the same array. */
|
|
264
|
+
tValue: number[];
|
|
265
|
+
/** Alias of `p`: the same array. */
|
|
266
|
+
pValue: number[];
|
|
278
267
|
/** Residual degrees of freedom, N - k. */
|
|
279
268
|
df: number;
|
|
269
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
270
|
+
warnings: string[];
|
|
280
271
|
}
|
|
281
272
|
/**
|
|
282
273
|
* Dunnett's many-to-one comparisons of a one-way ANOVA with simultaneous p-values. Equivalent to
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Multiple comparisons after a one-way layout: PMCMRplus's dscfAllPairsTest, kwAllPairsDunnTest, kwManyOneDunnTest,
|
|
2
|
-
// dunnettTest, gamesHowellTest, tukeyTest
|
|
2
|
+
// dunnettTest, gamesHowellTest, tukeyTest and manyOneUTest, dunn.test's dunn.test and multcomp's Dunnett contrasts
|
|
3
3
|
// (summary(glht(aov(y ~ g), mcp(g = "Dunnett")))).
|
|
4
4
|
//
|
|
5
5
|
// Written for rStats.js from the published statistics and the behaviour described in oracle/mcomp-behaviour.md (no
|
|
@@ -22,6 +22,15 @@ import { labelledGroups } from "./groups.js";
|
|
|
22
22
|
import { pAdjust } from "./pAdjust.js";
|
|
23
23
|
import { kruskalTest } from "./rankTests.js";
|
|
24
24
|
import { matchAlternative } from "./types.js";
|
|
25
|
+
import { reported } from "../internal/warnings.js";
|
|
26
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
27
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
28
|
+
const KW_ALL_PAIRS_DUNN_TEST_KEYS = ["pAdjustMethod"];
|
|
29
|
+
const KW_MANY_ONE_DUNN_TEST_KEYS = ["pAdjustMethod", "alternative"];
|
|
30
|
+
const DUNNETT_TEST_KEYS = ["alternative"];
|
|
31
|
+
const MANY_ONE_UTEST_KEYS = ["pAdjustMethod", "alternative"];
|
|
32
|
+
const DUNN_TEST_KEYS = ["method", "altp"];
|
|
33
|
+
const GLHT_DUNNETT_KEYS = ["alternative"];
|
|
25
34
|
const TIES_WARNING = "Ties are present. z-quantiles were corrected for ties.";
|
|
26
35
|
function layout(x, g) {
|
|
27
36
|
const { labels, groups } = labelledGroups(x, g);
|
|
@@ -136,13 +145,14 @@ export function checkPooledVariance(df, ssWithin) {
|
|
|
136
145
|
* @category Multiple comparisons
|
|
137
146
|
*/
|
|
138
147
|
export function kwAllPairsDunnTest(x, g, options = {}) {
|
|
148
|
+
checkOptions(options, KW_ALL_PAIRS_DUNN_TEST_KEYS, "kwAllPairsDunnTest"); // generated: option-keys.mjs
|
|
139
149
|
const adjust = options.pAdjustMethod ?? "holm";
|
|
140
150
|
const d = layout(x, g);
|
|
141
151
|
const { R, C } = meanRanks(d);
|
|
142
152
|
const v = (d.N * (d.N + 1)) / 12 - C;
|
|
143
153
|
const z = lowerTable(d.k, (i, j) => Math.abs(R[i] - R[j]) / Math.sqrt(v * (1 / d.n[i] + 1 / d.n[j])));
|
|
144
154
|
const p = adjustLower(z.map((row) => row.map((s) => 2 * upperNormal(s))), adjust);
|
|
145
|
-
return allPairs(d, "Dunn's all-pairs test", z, p, adjust, C !== 0 ? [TIES_WARNING] : []);
|
|
155
|
+
return reported("kwAllPairsDunnTest", allPairs(d, "Dunn's all-pairs test", z, p, adjust, C !== 0 ? [TIES_WARNING] : []));
|
|
146
156
|
}
|
|
147
157
|
/**
|
|
148
158
|
* Dunn's many-to-one test of mean ranks against the control (the first group). Equivalent to
|
|
@@ -159,6 +169,7 @@ export function kwAllPairsDunnTest(x, g, options = {}) {
|
|
|
159
169
|
* @category Multiple comparisons
|
|
160
170
|
*/
|
|
161
171
|
export function kwManyOneDunnTest(x, g, options = {}) {
|
|
172
|
+
checkOptions(options, KW_MANY_ONE_DUNN_TEST_KEYS, "kwManyOneDunnTest"); // generated: option-keys.mjs
|
|
162
173
|
const alternative = matchAlternative(options.alternative);
|
|
163
174
|
const adjust = options.pAdjustMethod ?? "single-step";
|
|
164
175
|
const d = layout(x, g);
|
|
@@ -168,7 +179,7 @@ export function kwManyOneDunnTest(x, g, options = {}) {
|
|
|
168
179
|
const z = idx.map((j) => (R[j] - R[0]) / Math.sqrt(v * (1 / d.n[0] + 1 / d.n[j])));
|
|
169
180
|
const lambda = idx.map((j) => d.n[j] / (d.n[j] + d.n[0]));
|
|
170
181
|
const p = manyOneNormalP(z, lambda, alternative, adjust);
|
|
171
|
-
return manyOne(d, "Dunn's many-to-one test", z, p, adjust, C !== 0 ? [TIES_WARNING] : []);
|
|
182
|
+
return reported("kwManyOneDunnTest", manyOne(d, "Dunn's many-to-one test", z, p, adjust, C !== 0 ? [TIES_WARNING] : []));
|
|
172
183
|
}
|
|
173
184
|
/**
|
|
174
185
|
* Many-to-one p-values of normal statistics z (one per group against the control): `"single-step"`, the exact
|
|
@@ -198,6 +209,7 @@ function manyOneNormalP(z, lambda, alternative, adjust) {
|
|
|
198
209
|
* @category Multiple comparisons
|
|
199
210
|
*/
|
|
200
211
|
export function dunnettTest(x, g, options = {}) {
|
|
212
|
+
checkOptions(options, DUNNETT_TEST_KEYS, "dunnettTest"); // generated: option-keys.mjs
|
|
201
213
|
const alternative = matchAlternative(options.alternative);
|
|
202
214
|
const d = layout(x, g);
|
|
203
215
|
const { m, s2, df } = pooled(d);
|
|
@@ -208,7 +220,7 @@ export function dunnettTest(x, g, options = {}) {
|
|
|
208
220
|
const p = t.map((v) => alternative === "two.sided"
|
|
209
221
|
? Math.min(1, 2 * pDunnettUpper(Math.abs(v), lambda, df, false))
|
|
210
222
|
: pDunnettUpper(alternative === "greater" ? v : -v, lambda, df, false));
|
|
211
|
-
return manyOne(d, "Dunnett's-test for multiple\t\n comparisons with one control", t, p, "single-step");
|
|
223
|
+
return reported("dunnettTest", manyOne(d, "Dunnett's-test for multiple\t\n comparisons with one control", t, p, "single-step"));
|
|
212
224
|
}
|
|
213
225
|
/**
|
|
214
226
|
* Steel's many-to-one rank test in its normal approximation: the Mann-Whitney statistic of each group against the
|
|
@@ -230,6 +242,7 @@ export function dunnettTest(x, g, options = {}) {
|
|
|
230
242
|
* @category Multiple comparisons
|
|
231
243
|
*/
|
|
232
244
|
export function manyOneUTest(x, g, options = {}) {
|
|
245
|
+
checkOptions(options, MANY_ONE_UTEST_KEYS, "manyOneUTest"); // generated: option-keys.mjs
|
|
233
246
|
const alternative = matchAlternative(options.alternative);
|
|
234
247
|
const adjust = options.pAdjustMethod ?? "single-step";
|
|
235
248
|
const d = layout(x, g);
|
|
@@ -258,7 +271,7 @@ export function manyOneUTest(x, g, options = {}) {
|
|
|
258
271
|
});
|
|
259
272
|
const lambda = idx.map((j) => d.n[j] / (d.n[j] + n1));
|
|
260
273
|
const p = manyOneNormalP(z, lambda, alternative, adjust);
|
|
261
|
-
return manyOne(d, "Wilcoxon, Mann, Whittney U-test\n\tfor multiple comparisons with one control", z, p, adjust);
|
|
274
|
+
return reported("manyOneUTest", manyOne(d, "Wilcoxon, Mann, Whittney U-test\n\tfor multiple comparisons with one control", z, p, adjust));
|
|
262
275
|
}
|
|
263
276
|
/**
|
|
264
277
|
* Dwass-Steel-Critchlow-Fligner all-pairs test of pairwise Mann-Whitney statistics. Equivalent to
|
|
@@ -294,7 +307,7 @@ export function dscfAllPairsTest(x, g) {
|
|
|
294
307
|
return (Math.SQRT2 * (u - (ni * nj) / 2)) / Math.sqrt(v);
|
|
295
308
|
});
|
|
296
309
|
const p = stat.map((row) => row.map((q) => (Number.isNaN(q) ? NaN : upperRange(q, d.k, Infinity))));
|
|
297
|
-
return allPairs(d, "Dwass-Steele-Critchlow-Fligner all-pairs test", stat, p, "single-step");
|
|
310
|
+
return reported("dscfAllPairsTest", allPairs(d, "Dwass-Steele-Critchlow-Fligner all-pairs test", stat, p, "single-step"));
|
|
298
311
|
}
|
|
299
312
|
/**
|
|
300
313
|
* Games-Howell all-pairs test of means with Welch's standard errors and degrees of freedom. Equivalent to
|
|
@@ -320,7 +333,7 @@ export function gamesHowellTest(x, g) {
|
|
|
320
333
|
const df = satterthwaiteDfPM([gm.variance[i], gm.variance[j]], [d.n[i], d.n[j]]);
|
|
321
334
|
return upperRange(q[i - 1][j], d.k, df);
|
|
322
335
|
});
|
|
323
|
-
return allPairs(d, "Games-Howell test", q, p, "none");
|
|
336
|
+
return reported("gamesHowellTest", allPairs(d, "Games-Howell test", q, p, "none"));
|
|
324
337
|
}
|
|
325
338
|
/**
|
|
326
339
|
* Tukey's all-pairs test of means (Tukey-Kramer for unequal sizes). Equivalent to `PMCMRplus::tukeyTest()` in R.
|
|
@@ -342,40 +355,7 @@ export function tukeyTest(x, g) {
|
|
|
342
355
|
throw new RangeError("the studentized range needs at least 2 residual degrees of freedom");
|
|
343
356
|
const q = lowerTable(d.k, (i, j) => (m[i] - m[j]) / Math.sqrt((s2 * (1 / d.n[i] + 1 / d.n[j])) / 2));
|
|
344
357
|
const p = q.map((row) => row.map((v) => (Number.isNaN(v) ? NaN : upperRange(v, d.k, df))));
|
|
345
|
-
return allPairs(d, "Tukey's test", q, p, "single-step");
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Steel's many-to-one rank test. Equivalent to `PMCMRplus::steelTest()` in R. It behaves as `steelTest()` of
|
|
349
|
-
* PMCMRplus 1.9.12 does: that fails on every input, so this reproduces its errors. A two-sided
|
|
350
|
-
* alternative is rejected (`'arg' should be one of “greater”, “less”`), unequal group sizes give `Steel's test is
|
|
351
|
-
* only valid for balanced designs.`, and balanced data the error PMCMRplus raises internally.
|
|
352
|
-
*
|
|
353
|
-
* @throws Always.
|
|
354
|
-
*
|
|
355
|
-
* @example
|
|
356
|
-
* ```ts
|
|
357
|
-
* const x = [1.2, 2.3, 1.8, 2.9, 3.1, 3.6, 4.0, 4.4, 5.2];
|
|
358
|
-
* const g = ["a", "a", "a", "b", "b", "b", "c", "c", "c"];
|
|
359
|
-
* const message = (() => {
|
|
360
|
-
* try {
|
|
361
|
-
* steelTest(x, g, { alternative: "greater" });
|
|
362
|
-
* } catch (e) {
|
|
363
|
-
* return (e as Error).message;
|
|
364
|
-
* }
|
|
365
|
-
* })();
|
|
366
|
-
* message; // "'data' must be of a vector type, was 'NULL'"
|
|
367
|
-
* ```
|
|
368
|
-
*
|
|
369
|
-
* @category Multiple comparisons
|
|
370
|
-
*/
|
|
371
|
-
export function steelTest(x, g, options = {}) {
|
|
372
|
-
const alternative = options.alternative === undefined ? "greater" : matchAlternative(options.alternative);
|
|
373
|
-
if (alternative === "two.sided")
|
|
374
|
-
throw new RangeError("'arg' should be one of “greater”, “less”");
|
|
375
|
-
const d = layout(x, g);
|
|
376
|
-
if (d.n.some((v) => v !== d.n[0]))
|
|
377
|
-
throw new RangeError("Steel's test is only valid for balanced designs.");
|
|
378
|
-
throw new Error("'data' must be of a vector type, was 'NULL'");
|
|
358
|
+
return reported("tukeyTest", allPairs(d, "Tukey's test", q, p, "single-step"));
|
|
379
359
|
}
|
|
380
360
|
/**
|
|
381
361
|
* Dunn's test of all pairs of mean ranks. Equivalent to `dunn.test::dunn.test(x, g, method, altp)` in R. The step-wise
|
|
@@ -395,6 +375,7 @@ export function steelTest(x, g, options = {}) {
|
|
|
395
375
|
* @category Multiple comparisons
|
|
396
376
|
*/
|
|
397
377
|
export function dunnTest(x, g, options = {}) {
|
|
378
|
+
checkOptions(options, DUNN_TEST_KEYS, "dunnTest"); // generated: option-keys.mjs
|
|
398
379
|
const method = options.method ?? "none";
|
|
399
380
|
const altp = options.altp ?? false;
|
|
400
381
|
const d = layout(x, g);
|
|
@@ -410,7 +391,8 @@ export function dunnTest(x, g, options = {}) {
|
|
|
410
391
|
}
|
|
411
392
|
}
|
|
412
393
|
const P = Z.map((z) => (altp ? 2 : 1) * upperNormal(Math.abs(z)));
|
|
413
|
-
|
|
394
|
+
const PAdjusted = dunnAdjust(P, method);
|
|
395
|
+
return { chi2, Z, P, PAdjusted, zValue: Z, pValue: P, pAdjusted: PAdjusted, comparisons, warnings: [] };
|
|
414
396
|
}
|
|
415
397
|
/** dunn.test's adjustments: each value by the factor of its rank (tied values: the same rank), capped at 1 */
|
|
416
398
|
function dunnAdjust(P, method) {
|
|
@@ -478,6 +460,7 @@ function dunnAdjust(P, method) {
|
|
|
478
460
|
* @category Multiple comparisons
|
|
479
461
|
*/
|
|
480
462
|
export function glhtDunnett(x, g, options = {}) {
|
|
463
|
+
checkOptions(options, GLHT_DUNNETT_KEYS, "glhtDunnett"); // generated: option-keys.mjs
|
|
481
464
|
const alternative = matchAlternative(options.alternative);
|
|
482
465
|
const d = layout(x, g);
|
|
483
466
|
const { m, s2, df, k } = pooled(d);
|
|
@@ -492,5 +475,5 @@ export function glhtDunnett(x, g, options = {}) {
|
|
|
492
475
|
const p = t.map((v) => alternative === "two.sided"
|
|
493
476
|
? pDunnettUpper(v, lambda, df, true)
|
|
494
477
|
: pDunnettUpper(alternative === "greater" ? v : -v, lambda, df, false));
|
|
495
|
-
return { names: idx.map((j) => `${d.labels[j]} - ${d.labels[0]}`), estimate, se, t, p, df };
|
|
478
|
+
return { names: idx.map((j) => `${d.labels[j]} - ${d.labels[0]}`), estimate, se, t, p, stdError: se, tValue: t, pValue: p, df, warnings: [] };
|
|
496
479
|
}
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
import { pgamma1 } from "../distributions/gamma.js";
|
|
10
10
|
import { pnorm, qnorm } from "../distributions/normal.js";
|
|
11
11
|
import { covariance, dropNaN, scaleToUnit, standardize, variance } from "../internal/summary.js";
|
|
12
|
+
import { reported } from "../internal/warnings.js";
|
|
13
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
14
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
15
|
+
const PEARSON_TEST_KEYS = ["nClasses", "adjust"];
|
|
12
16
|
/** The sorted values without NaN */
|
|
13
17
|
function sorted(x) {
|
|
14
18
|
return dropNaN(Array.from(x)).sort((a, b) => a - b);
|
|
@@ -63,7 +67,7 @@ export function adTest(x) {
|
|
|
63
67
|
pValue = Math.exp(1.2937 - 5.709 * aa + 0.0186 * aa ** 2);
|
|
64
68
|
else
|
|
65
69
|
pValue = 3.7e-24;
|
|
66
|
-
return { method: "Anderson-Darling normality test", statistic: a, statisticName: "A", pValue };
|
|
70
|
+
return { method: "Anderson-Darling normality test", statistic: a, statisticName: "A", pValue, warnings: [] };
|
|
67
71
|
}
|
|
68
72
|
/**
|
|
69
73
|
* Cramer-von Mises test for normality. Equivalent to `nortest::cvm.test()` in R. `NaN` values are dropped; at least 8
|
|
@@ -102,7 +106,7 @@ export function cvmTest(x) {
|
|
|
102
106
|
pValue = 7.37e-10;
|
|
103
107
|
warnings.push("p-value is smaller than 7.37e-10, cannot be computed more accurately");
|
|
104
108
|
}
|
|
105
|
-
return { method: "Cramer-von Mises normality test", statistic: w, statisticName: "W", pValue, warnings };
|
|
109
|
+
return reported("cvmTest", { method: "Cramer-von Mises normality test", statistic: w, statisticName: "W", pValue, warnings });
|
|
106
110
|
}
|
|
107
111
|
/**
|
|
108
112
|
* Lilliefors (Kolmogorov-Smirnov) test for normality. Equivalent to `nortest::lillie.test()` in R. `NaN` values are
|
|
@@ -145,7 +149,7 @@ export function lillieTest(x) {
|
|
|
145
149
|
else
|
|
146
150
|
pValue = 0;
|
|
147
151
|
}
|
|
148
|
-
return { method: "Lilliefors (Kolmogorov-Smirnov) normality test", statistic: d, statisticName: "D", pValue };
|
|
152
|
+
return { method: "Lilliefors (Kolmogorov-Smirnov) normality test", statistic: d, statisticName: "D", pValue, warnings: [] };
|
|
149
153
|
}
|
|
150
154
|
/**
|
|
151
155
|
* Shapiro-Francia test for normality. Equivalent to `nortest::sf.test()` in R. `NaN` values are dropped; the sample
|
|
@@ -178,7 +182,7 @@ export function sfTest(x) {
|
|
|
178
182
|
const mu = -1.2725 + 1.0521 * (v - u);
|
|
179
183
|
const sig = 1.0308 - 0.26758 * (v + 2 / u);
|
|
180
184
|
const pValue = pnorm((Math.log(1 - w) - mu) / sig, { lowerTail: false });
|
|
181
|
-
return { method: "Shapiro-Francia normality test", statistic: w, statisticName: "W", pValue };
|
|
185
|
+
return { method: "Shapiro-Francia normality test", statistic: w, statisticName: "W", pValue, warnings: [] };
|
|
182
186
|
}
|
|
183
187
|
/**
|
|
184
188
|
* Pearson chi-square test for normality, with classes of equal probability under the fitted normal distribution.
|
|
@@ -193,6 +197,7 @@ export function sfTest(x) {
|
|
|
193
197
|
* @category Hypothesis tests
|
|
194
198
|
*/
|
|
195
199
|
export function pearsonTest(x, options = {}) {
|
|
200
|
+
checkOptions(options, PEARSON_TEST_KEYS, "pearsonTest"); // generated: option-keys.mjs
|
|
196
201
|
const xs = sorted(x);
|
|
197
202
|
const n = xs.length;
|
|
198
203
|
const k = options.nClasses ?? Math.ceil(2 * n ** (2 / 5));
|
|
@@ -228,5 +233,6 @@ export function pearsonTest(x, options = {}) {
|
|
|
228
233
|
statistic,
|
|
229
234
|
statisticName: "P",
|
|
230
235
|
pValue: pgamma1(statistic, df / 2, 2, false, false),
|
|
236
|
+
warnings: [],
|
|
231
237
|
};
|
|
232
238
|
}
|
package/dist/htest/onewayTest.js
CHANGED
|
@@ -11,8 +11,16 @@ import { swilkOneMinusW, swilkPValueFromOneMinusW } from "./core/shapiro.js";
|
|
|
11
11
|
import { toGroups } from "./groups.js";
|
|
12
12
|
import { checkPooledVariance } from "./multipleComparisons.js";
|
|
13
13
|
import { onewayData } from "./testFormula.js";
|
|
14
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
15
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
16
|
+
import { isOptionsObject } from "../internal/optionalArgs.js";
|
|
17
|
+
const ONEWAY_TEST_KEYS = ["varEqual"];
|
|
18
|
+
// Generated by `node scripts/option-keys.mjs --write` (end)
|
|
14
19
|
const MIN_NORMAL = 2 ** -1022;
|
|
15
20
|
export function onewayTest(x, g, options = {}) {
|
|
21
|
+
if (typeof x !== "string" && isOptionsObject(g))
|
|
22
|
+
checkOptions(g, ONEWAY_TEST_KEYS, "onewayTest"); // generated: option-keys.mjs
|
|
23
|
+
checkOptions(options, ONEWAY_TEST_KEYS, "onewayTest"); // generated: option-keys.mjs
|
|
16
24
|
if (typeof x === "string") {
|
|
17
25
|
const d = onewayData(x, g);
|
|
18
26
|
return onewayTest(d.values, d.groups, options);
|
|
@@ -130,6 +138,7 @@ export function onewayTest(x, g, options = {}) {
|
|
|
130
138
|
parameter: [k - 1, df2],
|
|
131
139
|
parameterName: ["num df", "denom df"],
|
|
132
140
|
pValue: pf1(statistic, k - 1, df2, false, false),
|
|
141
|
+
warnings: [],
|
|
133
142
|
};
|
|
134
143
|
}
|
|
135
144
|
/**
|
|
@@ -163,6 +172,7 @@ export function shapiroTest(x) {
|
|
|
163
172
|
statistic: 1 - w1,
|
|
164
173
|
statisticName: "W",
|
|
165
174
|
pValue: swilkPValueFromOneMinusW(w1, n),
|
|
175
|
+
warnings: [],
|
|
166
176
|
};
|
|
167
177
|
}
|
|
168
178
|
/**
|
package/dist/htest/pAdjust.js
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
// Differences from R: with Hommel, a non-integer n is an error (R silently returns something). For a length-0 p
|
|
14
14
|
// with Hommel and n > 0, R returns a length-1 value; here a length-0 result is returned
|
|
15
15
|
import { wideSum, wideSumAdd, wideSumValue } from "../internal/summary.js";
|
|
16
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
17
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
18
|
+
const P_ADJUST_KEYS = ["method", "n"];
|
|
16
19
|
const METHODS = ["holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"];
|
|
17
20
|
function matchMethod(m) {
|
|
18
21
|
if (METHODS.includes(m))
|
|
@@ -45,6 +48,7 @@ function matchMethod(m) {
|
|
|
45
48
|
* @category Multiple comparisons
|
|
46
49
|
*/
|
|
47
50
|
export function pAdjust(p, options = {}) {
|
|
51
|
+
checkOptions(options, P_ADJUST_KEYS, "pAdjust"); // generated: option-keys.mjs
|
|
48
52
|
const opts = typeof options === "string" ? { method: options } : options;
|
|
49
53
|
const method = matchMethod(opts.method ?? "holm");
|
|
50
54
|
const all = Array.from(p);
|
package/dist/htest/pairwise.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface PairwiseResult {
|
|
|
21
21
|
colNames: string[];
|
|
22
22
|
/** Adjustment method. */
|
|
23
23
|
pAdjustMethod: PAdjustMethod | string;
|
|
24
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
25
|
+
warnings: string[];
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Common options of the pairwise comparisons.
|
package/dist/htest/pairwise.js
CHANGED
|
@@ -15,6 +15,14 @@ import { propTest } from "./propTest.js";
|
|
|
15
15
|
import { tTest } from "./tTest.js";
|
|
16
16
|
import { matchAlternative } from "./types.js";
|
|
17
17
|
import { wilcoxTest } from "./wilcoxTest.js";
|
|
18
|
+
import { reported, unreported, Warnings } from "../internal/warnings.js";
|
|
19
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
20
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
21
|
+
const PAIRWISE_TTEST_KEYS = ["poolSd", "paired", "pAdjustMethod", "alternative"];
|
|
22
|
+
const PAIRWISE_WILCOX_TEST_KEYS = [
|
|
23
|
+
"mu", "paired", "exact", "correct", "confLevel", "tolRoot", "pAdjustMethod", "alternative",
|
|
24
|
+
];
|
|
25
|
+
const PAIRWISE_PROP_TEST_KEYS = ["pAdjustMethod", "correct"];
|
|
18
26
|
/** Group a sample by labels: levels sorted (numbers numerically, strings by code point), values in input order */
|
|
19
27
|
function byLevel(x, g, dropNaN) {
|
|
20
28
|
const xs = Array.from(x);
|
|
@@ -52,13 +60,14 @@ function table(k, compare, method) {
|
|
|
52
60
|
pos.forEach(([r, c], idx) => (out[r][c] = adj[idx]));
|
|
53
61
|
return out;
|
|
54
62
|
}
|
|
55
|
-
function result(method, levels, pValue, adjust) {
|
|
63
|
+
function result(method, levels, pValue, adjust, warnings = []) {
|
|
56
64
|
return {
|
|
57
65
|
method,
|
|
58
66
|
pValue,
|
|
59
67
|
rowNames: levels.slice(1).map(levelText),
|
|
60
68
|
colNames: levels.slice(0, -1).map(levelText),
|
|
61
69
|
pAdjustMethod: adjust,
|
|
70
|
+
warnings,
|
|
62
71
|
};
|
|
63
72
|
}
|
|
64
73
|
/**
|
|
@@ -77,6 +86,7 @@ function result(method, levels, pValue, adjust) {
|
|
|
77
86
|
* @category Multiple comparisons
|
|
78
87
|
*/
|
|
79
88
|
export function pairwiseTTest(x, g, options = {}) {
|
|
89
|
+
checkOptions(options, PAIRWISE_TTEST_KEYS, "pairwiseTTest"); // generated: option-keys.mjs
|
|
80
90
|
const paired = options.paired ?? false;
|
|
81
91
|
const poolSd = options.poolSd ?? !paired;
|
|
82
92
|
if (paired && poolSd)
|
|
@@ -113,7 +123,7 @@ export function pairwiseTTest(x, g, options = {}) {
|
|
|
113
123
|
}
|
|
114
124
|
else {
|
|
115
125
|
method = paired ? "paired t tests" : "t tests with non-pooled SD";
|
|
116
|
-
compare = (i, j) => tTest(groups[i], groups[j], { paired, alternative }).pValue;
|
|
126
|
+
compare = (i, j) => unreported(() => tTest(groups[i], groups[j], { paired, alternative })).pValue;
|
|
117
127
|
}
|
|
118
128
|
return result(method, levels, table(k, compare, adjust), adjust);
|
|
119
129
|
}
|
|
@@ -131,6 +141,7 @@ export function pairwiseTTest(x, g, options = {}) {
|
|
|
131
141
|
* @category Multiple comparisons
|
|
132
142
|
*/
|
|
133
143
|
export function pairwiseWilcoxTest(x, g, options = {}) {
|
|
144
|
+
checkOptions(options, PAIRWISE_WILCOX_TEST_KEYS, "pairwiseWilcoxTest"); // generated: option-keys.mjs
|
|
134
145
|
const { pAdjustMethod, alternative, ...rest } = options;
|
|
135
146
|
const adjust = pAdjustMethod ?? "holm";
|
|
136
147
|
const { levels, groups } = byLevel(x, g, !(rest.paired ?? false));
|
|
@@ -138,12 +149,16 @@ export function pairwiseWilcoxTest(x, g, options = {}) {
|
|
|
138
149
|
if (k < 2)
|
|
139
150
|
throw new RangeError("there must be at least two groups");
|
|
140
151
|
let method = "";
|
|
152
|
+
// the comparisons' warnings, each once, in the order of the comparisons (R repeats them for each)
|
|
153
|
+
const warnings = new Warnings();
|
|
141
154
|
const pv = table(k, (i, j) => {
|
|
142
|
-
const r = wilcoxTest(groups[i], groups[j], { ...rest, ...(alternative === undefined ? {} : { alternative }) });
|
|
155
|
+
const r = unreported(() => wilcoxTest(groups[i], groups[j], { ...rest, ...(alternative === undefined ? {} : { alternative }) }));
|
|
143
156
|
method = r.method;
|
|
157
|
+
for (const w of r.warnings)
|
|
158
|
+
warnings.add(w);
|
|
144
159
|
return r.pValue;
|
|
145
160
|
}, adjust);
|
|
146
|
-
return result(method, levels, pv, adjust);
|
|
161
|
+
return reported("pairwiseWilcoxTest", result(method, levels, pv, adjust, warnings.list));
|
|
147
162
|
}
|
|
148
163
|
/**
|
|
149
164
|
* Pairwise two-group tests of equal proportions, with adjusted p-values. Equivalent to R's `pairwise.prop.test()`.
|
|
@@ -160,6 +175,7 @@ export function pairwiseWilcoxTest(x, g, options = {}) {
|
|
|
160
175
|
* @category Multiple comparisons
|
|
161
176
|
*/
|
|
162
177
|
export function pairwisePropTest(x, n, options = {}) {
|
|
178
|
+
checkOptions(options, PAIRWISE_PROP_TEST_KEYS, "pairwisePropTest"); // generated: option-keys.mjs
|
|
163
179
|
if (x.length !== n.length)
|
|
164
180
|
throw new RangeError("'x' and 'n' must have the same length");
|
|
165
181
|
// as in R, groups with a missing count are dropped and the rest numbered 1, 2, ... in their order
|
|
@@ -176,7 +192,14 @@ export function pairwisePropTest(x, n, options = {}) {
|
|
|
176
192
|
throw new RangeError("too few groups");
|
|
177
193
|
const adjust = options.pAdjustMethod ?? "holm";
|
|
178
194
|
const correct = options.correct ?? true;
|
|
179
|
-
|
|
195
|
+
// the comparisons' warnings ("Chi-squared approximation may be incorrect"), each once (R repeats them for each)
|
|
196
|
+
const warnings = new Warnings();
|
|
197
|
+
const pv = table(k, (i, j) => {
|
|
198
|
+
const r = unreported(() => propTest([xs[i], xs[j]], [ns[i], ns[j]], { correct }));
|
|
199
|
+
for (const w of r.warnings)
|
|
200
|
+
warnings.add(w);
|
|
201
|
+
return r.pValue;
|
|
202
|
+
}, adjust);
|
|
180
203
|
const levels = Array.from({ length: k }, (_, i) => i + 1);
|
|
181
|
-
return result("Pairwise comparison of proportions", levels, pv, adjust);
|
|
204
|
+
return reported("pairwisePropTest", result("Pairwise comparison of proportions", levels, pv, adjust, warnings.list));
|
|
182
205
|
}
|
|
@@ -12,6 +12,9 @@ import { firstTrue, lastTrue } from "../internal/discrete.js";
|
|
|
12
12
|
import { ldexp } from "../internal/summary.js";
|
|
13
13
|
import { binomTestCounts } from "./binomTest.js";
|
|
14
14
|
import { checkConfLevel, checkConfLevelOpen, isCount, matchAlternative } from "./types.js";
|
|
15
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
16
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
17
|
+
const POISSON_TEST_KEYS = ["T", "r", "alternative", "confLevel"];
|
|
15
18
|
const REL_ERR = 1 + 1e-7;
|
|
16
19
|
/**
|
|
17
20
|
* Two-sided p-value of the count x under Poisson(m): the total probability of the counts whose probability is at most
|
|
@@ -111,6 +114,7 @@ function rateRatio(x1, x2, T1, T2) {
|
|
|
111
114
|
* @category Hypothesis tests
|
|
112
115
|
*/
|
|
113
116
|
export function poissonTest(x, options = {}) {
|
|
117
|
+
checkOptions(options, POISSON_TEST_KEYS, "poissonTest"); // generated: option-keys.mjs
|
|
114
118
|
const xs = typeof x === "number" ? [x] : Array.from(x);
|
|
115
119
|
if (xs.length < 1 || xs.length > 2)
|
|
116
120
|
throw new RangeError("incorrect length of 'x'");
|
|
@@ -182,6 +186,7 @@ export function poissonTest(x, options = {}) {
|
|
|
182
186
|
estimateNames: "rate ratio",
|
|
183
187
|
nullValue: r,
|
|
184
188
|
nullValueName: "rate ratio",
|
|
189
|
+
warnings: [],
|
|
185
190
|
};
|
|
186
191
|
}
|
|
187
192
|
const xv = counts[0];
|
|
@@ -220,5 +225,6 @@ export function poissonTest(x, options = {}) {
|
|
|
220
225
|
estimateNames: "event rate",
|
|
221
226
|
nullValue: r,
|
|
222
227
|
nullValueName: "event rate",
|
|
228
|
+
warnings: [],
|
|
223
229
|
};
|
|
224
230
|
}
|