@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
package/dist/htest/polycor.js
CHANGED
|
@@ -22,6 +22,12 @@ import { optimize } from "../numerics/integrate.js";
|
|
|
22
22
|
import { solve } from "../linalg/solve.js";
|
|
23
23
|
import { formatR } from "./core/simulate.js";
|
|
24
24
|
import { maxOf } from "../internal/extremes.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
|
+
import { isOptionsObject } from "../internal/optionalArgs.js";
|
|
29
|
+
const POLYCHOR_KEYS = ["ML", "stdErr"];
|
|
30
|
+
const POLYSERIAL_KEYS = ["ML", "stdErr"];
|
|
25
31
|
const BOUND = 0.9999;
|
|
26
32
|
/** Normal quantiles of the cumulative proportions of the counts, without the last (which would be +Inf) */
|
|
27
33
|
function thresholds(counts) {
|
|
@@ -296,6 +302,9 @@ function inverseNegHessian(hessian, bounded) {
|
|
|
296
302
|
}
|
|
297
303
|
const inadmissibleWarning = (rho) => `inadmissible correlation set to ${rho > 0 ? "0.9999" : "-0.9999"}`;
|
|
298
304
|
export function polychor(x, yOrOptions, maybeOptions) {
|
|
305
|
+
if (isOptionsObject(yOrOptions))
|
|
306
|
+
checkOptions(yOrOptions, POLYCHOR_KEYS, "polychor"); // generated: option-keys.mjs
|
|
307
|
+
checkOptions(maybeOptions, POLYCHOR_KEYS, "polychor"); // generated: option-keys.mjs
|
|
299
308
|
let tab;
|
|
300
309
|
let options;
|
|
301
310
|
if (!isVector(yOrOptions)) {
|
|
@@ -352,7 +361,7 @@ export function polychor(x, yOrOptions, maybeOptions) {
|
|
|
352
361
|
if (c < 2)
|
|
353
362
|
warnings.push("the table has fewer than 2 columns");
|
|
354
363
|
if (r < 2 || c < 2)
|
|
355
|
-
return { rho: NaN, warnings };
|
|
364
|
+
return reported("polychor", { rho: NaN, warnings });
|
|
356
365
|
const rowCuts = [-Infinity, ...thresholds(tab.map((row) => sum(row))), Infinity];
|
|
357
366
|
const colCuts = [-Infinity, ...thresholds(tab[0].map((_, j) => sum(tab.map((row) => row[j])))), Infinity];
|
|
358
367
|
const negLogLik = (rho0) => {
|
|
@@ -371,7 +380,7 @@ export function polychor(x, yOrOptions, maybeOptions) {
|
|
|
371
380
|
};
|
|
372
381
|
const twoStep = optimize(negLogLik, -BOUND, BOUND).optimum;
|
|
373
382
|
if (!ML && !stdErr)
|
|
374
|
-
return { rho: twoStep, warnings };
|
|
383
|
+
return reported("polychor", { rho: twoStep, warnings });
|
|
375
384
|
// maximum likelihood: θ = (ρ, the inner row thresholds, the inner column thresholds) with ML, ρ alone otherwise
|
|
376
385
|
const extend = (cuts) => [-Infinity, ...cuts, Infinity];
|
|
377
386
|
const innerRow = rowCuts.slice(1, r);
|
|
@@ -384,7 +393,7 @@ export function polychor(x, yOrOptions, maybeOptions) {
|
|
|
384
393
|
if (bounded)
|
|
385
394
|
warnings.push(inadmissibleWarning(rho));
|
|
386
395
|
if (!stdErr)
|
|
387
|
-
return { rho, warnings };
|
|
396
|
+
return reported("polychor", { rho, warnings });
|
|
388
397
|
const fittedRow = ML ? extend(theta.slice(1, r)) : rowCuts;
|
|
389
398
|
const fittedCol = ML ? extend(theta.slice(r)) : colCuts;
|
|
390
399
|
const n = sum(tab.map((row) => sum(row)));
|
|
@@ -408,7 +417,7 @@ export function polychor(x, yOrOptions, maybeOptions) {
|
|
|
408
417
|
}
|
|
409
418
|
}
|
|
410
419
|
const variances = inverseNegHessian(at.hessian, bounded);
|
|
411
|
-
return {
|
|
420
|
+
return reported("polychor", {
|
|
412
421
|
rho,
|
|
413
422
|
warnings,
|
|
414
423
|
var: k === 0 ? variances : variances.map((row) => row.map((v) => ldexp(v, -k))),
|
|
@@ -417,7 +426,7 @@ export function polychor(x, yOrOptions, maybeOptions) {
|
|
|
417
426
|
n: ldexp(n, k),
|
|
418
427
|
rowCuts: fittedRow.slice(1, r),
|
|
419
428
|
colCuts: fittedCol.slice(1, c),
|
|
420
|
-
};
|
|
429
|
+
});
|
|
421
430
|
}
|
|
422
431
|
/** polycor's chi-square for the polyserial model: the standardised codes and z binned, against the bivariate normal */
|
|
423
432
|
function polyserialChisq(codes, z, cuts, rho) {
|
|
@@ -441,6 +450,7 @@ function polyserialChisq(codes, z, cuts, rho) {
|
|
|
441
450
|
return 2 * sum(terms);
|
|
442
451
|
}
|
|
443
452
|
export function polyserial(x, y, options = {}) {
|
|
453
|
+
checkOptions(options, POLYSERIAL_KEYS, "polyserial"); // generated: option-keys.mjs
|
|
444
454
|
if (x.length !== y.length)
|
|
445
455
|
throw new RangeError("'x' and 'y' must have the same length");
|
|
446
456
|
const { ML = false, stdErr = false } = options;
|
|
@@ -450,7 +460,7 @@ export function polyserial(x, y, options = {}) {
|
|
|
450
460
|
const n = xv.length;
|
|
451
461
|
const levels = sortedDistinct(yv);
|
|
452
462
|
if (levels.length < 2)
|
|
453
|
-
return { rho: NaN, warnings: ["y has fewer than 2 levels"] };
|
|
463
|
+
return reported("polyserial", { rho: NaN, warnings: ["y has fewer than 2 levels"] });
|
|
454
464
|
const code = new Map(levels.map((v, i) => [v, i + 1]));
|
|
455
465
|
const yc = yv.map((v) => code.get(v));
|
|
456
466
|
const counts = levels.map(() => 0);
|
|
@@ -465,7 +475,7 @@ export function polyserial(x, y, options = {}) {
|
|
|
465
475
|
rho = bounded;
|
|
466
476
|
}
|
|
467
477
|
if (!ML && !stdErr)
|
|
468
|
-
return { rho, warnings };
|
|
478
|
+
return reported("polyserial", { rho, warnings });
|
|
469
479
|
// maximum likelihood: θ = (ρ, the thresholds) with ML, ρ alone otherwise
|
|
470
480
|
const z = standardise(xv);
|
|
471
481
|
const category = yc.map((v) => v - 1);
|
|
@@ -474,10 +484,10 @@ export function polyserial(x, y, options = {}) {
|
|
|
474
484
|
if (bounded)
|
|
475
485
|
warnings.push(inadmissibleWarning(theta[0]));
|
|
476
486
|
if (!stdErr)
|
|
477
|
-
return { rho: theta[0], warnings };
|
|
487
|
+
return reported("polyserial", { rho: theta[0], warnings });
|
|
478
488
|
const fittedCuts = ML ? theta.slice(1) : cuts;
|
|
479
489
|
const s = levels.length;
|
|
480
|
-
return {
|
|
490
|
+
return reported("polyserial", {
|
|
481
491
|
rho: theta[0],
|
|
482
492
|
warnings,
|
|
483
493
|
var: inverseNegHessian(at.hessian, bounded),
|
|
@@ -486,5 +496,5 @@ export function polyserial(x, y, options = {}) {
|
|
|
486
496
|
df: 4 * s - s - 1,
|
|
487
497
|
n,
|
|
488
498
|
cuts: fittedCuts,
|
|
489
|
-
};
|
|
499
|
+
});
|
|
490
500
|
}
|
package/dist/htest/power.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ export interface PowerTTestResult {
|
|
|
55
55
|
note?: string;
|
|
56
56
|
/** Description of the calculation. */
|
|
57
57
|
method: string;
|
|
58
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
59
|
+
warnings: string[];
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
60
62
|
* Power of a one- or two-sample t test, or the sample size, difference, standard deviation or significance level
|
|
@@ -170,6 +172,8 @@ export interface PowerAnovaTestResult {
|
|
|
170
172
|
note: string;
|
|
171
173
|
/** Description of the calculation. */
|
|
172
174
|
method: string;
|
|
175
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
176
|
+
warnings: string[];
|
|
173
177
|
}
|
|
174
178
|
/** Whether an F test's power is taken from the normal approximation (df1 finite, both above 1e16) */
|
|
175
179
|
export declare const hugeDf: (df1: number, df2: number) => boolean;
|
package/dist/htest/power.js
CHANGED
|
@@ -9,6 +9,15 @@ import { pnorm, qnorm } from "../distributions/normal.js";
|
|
|
9
9
|
import { pt, qt } from "../distributions/t.js";
|
|
10
10
|
import { ldexp } from "../internal/summary.js";
|
|
11
11
|
import { uniroot } from "../numerics/integrate.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 POWER_TTEST_KEYS = /* @__PURE__ */ new Set([
|
|
16
|
+
"n", "delta", "sd", "sigLevel", "power", "type", "alternative", "strict", "tol",
|
|
17
|
+
]);
|
|
18
|
+
const POWER_PROP_TEST_KEYS = ["n", "p1", "p2", "sigLevel", "power", "alternative", "strict", "tol"];
|
|
19
|
+
const POWER_ANOVA_TEST_KEYS = ["groups", "n", "betweenVar", "withinVar", "sigLevel", "power"];
|
|
20
|
+
// Generated by `node scripts/option-keys.mjs --write` (end)
|
|
12
21
|
const TOL = Number.EPSILON ** 0.25;
|
|
13
22
|
/** R's match.arg: the value in full, also from an unambiguous abbreviation */
|
|
14
23
|
export function matchChoice(value, choices) {
|
|
@@ -62,6 +71,7 @@ const SIG_MESSAGE = "'sig.level' must be numeric in [0, 1]";
|
|
|
62
71
|
* @category Effect sizes and power
|
|
63
72
|
*/
|
|
64
73
|
export function powerTTest(options = {}) {
|
|
74
|
+
checkOptions(options, POWER_TTEST_KEYS, "powerTTest"); // generated: option-keys.mjs
|
|
65
75
|
let { n, delta, power } = options;
|
|
66
76
|
let sd = options.sd === undefined ? 1 : options.sd;
|
|
67
77
|
let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
|
|
@@ -132,6 +142,7 @@ export function powerTTest(options = {}) {
|
|
|
132
142
|
alternative,
|
|
133
143
|
...(note === undefined ? {} : { note }),
|
|
134
144
|
method,
|
|
145
|
+
warnings: [],
|
|
135
146
|
};
|
|
136
147
|
}
|
|
137
148
|
/**
|
|
@@ -146,6 +157,7 @@ export function powerTTest(options = {}) {
|
|
|
146
157
|
* @category Effect sizes and power
|
|
147
158
|
*/
|
|
148
159
|
export function powerPropTest(options = {}) {
|
|
160
|
+
checkOptions(options, POWER_PROP_TEST_KEYS, "powerPropTest"); // generated: option-keys.mjs
|
|
149
161
|
let { n, p1, p2, power } = options;
|
|
150
162
|
let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
|
|
151
163
|
checkExactlyOne([n, p1, p2, power, sigLevel], "exactly one of 'n', 'p1', 'p2', 'power', and 'sig.level' must be NULL");
|
|
@@ -207,7 +219,7 @@ export function powerPropTest(options = {}) {
|
|
|
207
219
|
warnings.push("No significance level [0, 1] can be found to achieve the desired power");
|
|
208
220
|
}
|
|
209
221
|
}
|
|
210
|
-
return {
|
|
222
|
+
return reported("powerPropTest", {
|
|
211
223
|
n: n,
|
|
212
224
|
p1: p1,
|
|
213
225
|
p2: p2,
|
|
@@ -217,7 +229,7 @@ export function powerPropTest(options = {}) {
|
|
|
217
229
|
note: "n is number in *each* group",
|
|
218
230
|
method: "Two-sample comparison of proportions power calculation",
|
|
219
231
|
warnings,
|
|
220
|
-
};
|
|
232
|
+
});
|
|
221
233
|
}
|
|
222
234
|
/**
|
|
223
235
|
* Above this, both degrees of freedom of an F test are huge enough for {@link fPowerHugeDf} (pwrF2Test, pwrAnovaTest,
|
|
@@ -266,6 +278,7 @@ function scaledProductOver(a, b, c, d) {
|
|
|
266
278
|
* @category Effect sizes and power
|
|
267
279
|
*/
|
|
268
280
|
export function powerAnovaTest(options = {}) {
|
|
281
|
+
checkOptions(options, POWER_ANOVA_TEST_KEYS, "powerAnovaTest"); // generated: option-keys.mjs
|
|
269
282
|
let { groups, n, betweenVar, withinVar, power } = options;
|
|
270
283
|
let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
|
|
271
284
|
checkExactlyOne([groups, n, betweenVar, withinVar, power, sigLevel], "exactly one of 'groups', 'n', 'between.var', 'within.var', 'power', and 'sig.level' must be NULL");
|
|
@@ -333,5 +346,6 @@ export function powerAnovaTest(options = {}) {
|
|
|
333
346
|
power,
|
|
334
347
|
note: "n is number in each group",
|
|
335
348
|
method: "Balanced one-way analysis of variance power calculation",
|
|
349
|
+
warnings: [],
|
|
336
350
|
};
|
|
337
351
|
}
|
package/dist/htest/propTest.d.ts
CHANGED
|
@@ -33,6 +33,9 @@ export interface PropTestResult extends Omit<HTest, "nullValue" | "nullValueName
|
|
|
33
33
|
/**
|
|
34
34
|
* Test of equal or given proportions. Equivalent to R's `prop.test()`.
|
|
35
35
|
*
|
|
36
|
+
* As R, `warnings` has "Chi-squared approximation may be incorrect" where an expected count of the table of successes
|
|
37
|
+
* and failures (n p or n (1 - p), p the given or the pooled proportion) is below 5.
|
|
38
|
+
*
|
|
36
39
|
* @param x Numbers of successes, or a table of rows `[successes, failures]`.
|
|
37
40
|
* @param n Numbers of trials (omitted, and the options passed in its place, when `x` is a table).
|
|
38
41
|
* @param options See {@link PropTestOptions}.
|
package/dist/htest/propTest.js
CHANGED
|
@@ -8,14 +8,26 @@
|
|
|
8
8
|
// statistic is then exactly 0). One-sided alternatives use the signed square root of the statistic as a normal
|
|
9
9
|
// deviate. Intervals: the Wilson score interval (Wilson, JASA 22, 1927) with continuity correction for one proportion
|
|
10
10
|
// (Newcombe, Statistics in Medicine 17, 1998, method 4), and the Wald interval with continuity correction for the
|
|
11
|
-
// difference of two.
|
|
11
|
+
// difference of two. R's warning "Chi-squared approximation may be incorrect" where an expected count n p or n (1 - p)
|
|
12
|
+
// is below 5 (p the given or the pooled proportion).
|
|
12
13
|
import { pgamma1 } from "../distributions/gamma.js";
|
|
13
14
|
import { pnorm, qnorm } from "../distributions/normal.js";
|
|
14
15
|
import { ldexp, squareOver } from "../internal/summary.js";
|
|
15
16
|
import { checkConfLevelOpen, matchAlternative } from "./types.js";
|
|
17
|
+
import { reported } from "../internal/warnings.js";
|
|
18
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
19
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
20
|
+
import { isOptionsObject } from "../internal/optionalArgs.js";
|
|
21
|
+
const PROP_TEST_KEYS = ["p", "alternative", "confLevel", "correct"];
|
|
22
|
+
// Generated by `node scripts/option-keys.mjs --write` (end)
|
|
23
|
+
/** R's warning where an expected count of the table is below 5 */
|
|
24
|
+
const APPROXIMATION = "Chi-squared approximation may be incorrect";
|
|
16
25
|
/**
|
|
17
26
|
* Test of equal or given proportions. Equivalent to R's `prop.test()`.
|
|
18
27
|
*
|
|
28
|
+
* As R, `warnings` has "Chi-squared approximation may be incorrect" where an expected count of the table of successes
|
|
29
|
+
* and failures (n p or n (1 - p), p the given or the pooled proportion) is below 5.
|
|
30
|
+
*
|
|
19
31
|
* @param x Numbers of successes, or a table of rows `[successes, failures]`.
|
|
20
32
|
* @param n Numbers of trials (omitted, and the options passed in its place, when `x` is a table).
|
|
21
33
|
* @param options See {@link PropTestOptions}.
|
|
@@ -29,6 +41,9 @@ import { checkConfLevelOpen, matchAlternative } from "./types.js";
|
|
|
29
41
|
* @category Hypothesis tests
|
|
30
42
|
*/
|
|
31
43
|
export function propTest(x, n, options = {}) {
|
|
44
|
+
if (isOptionsObject(n))
|
|
45
|
+
checkOptions(n, PROP_TEST_KEYS, "propTest"); // generated: option-keys.mjs
|
|
46
|
+
checkOptions(options, PROP_TEST_KEYS, "propTest"); // generated: option-keys.mjs
|
|
32
47
|
// ---- inputs: successes and trials per group ----
|
|
33
48
|
let xs;
|
|
34
49
|
let ns;
|
|
@@ -103,6 +118,11 @@ export function propTest(x, n, options = {}) {
|
|
|
103
118
|
}
|
|
104
119
|
// ---- Pearson's chi-squared on the k x 2 table of successes and failures ----
|
|
105
120
|
const pooled = pooledProportion(xs, ns);
|
|
121
|
+
// R's expected counts n p and n (1 - p) of the table, checked whatever the correction
|
|
122
|
+
const small = ns.some((v, i) => {
|
|
123
|
+
const pi = p?.[i] ?? pooled;
|
|
124
|
+
return v * pi < 5 || v * (1 - pi) < 5;
|
|
125
|
+
});
|
|
106
126
|
let statistic = 0;
|
|
107
127
|
if (!capped) {
|
|
108
128
|
for (let i = 0; i < k; i++) {
|
|
@@ -158,6 +178,7 @@ export function propTest(x, n, options = {}) {
|
|
|
158
178
|
pValue,
|
|
159
179
|
estimate: k === 1 ? phat[0] : phat,
|
|
160
180
|
estimateNames: names,
|
|
181
|
+
warnings: small ? [APPROXIMATION] : [],
|
|
161
182
|
};
|
|
162
183
|
if (p !== undefined) {
|
|
163
184
|
result.nullValue = k === 1 ? p[0] : p;
|
|
@@ -167,7 +188,7 @@ export function propTest(x, n, options = {}) {
|
|
|
167
188
|
result.confInt = confInt;
|
|
168
189
|
result.confLevel = confLevel;
|
|
169
190
|
}
|
|
170
|
-
return result;
|
|
191
|
+
return reported("propTest", result);
|
|
171
192
|
}
|
|
172
193
|
/**
|
|
173
194
|
* sum(x) / sum(n). Where the total of the trials overflows (each n is finite), both totals in units of 2^s with
|
package/dist/htest/pwr.d.ts
CHANGED
|
@@ -27,7 +27,17 @@ export interface CohenESResult {
|
|
|
27
27
|
method: string;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Options for {@link cohenES}.
|
|
31
|
+
*
|
|
32
|
+
* @category Effect sizes and power
|
|
33
|
+
*/
|
|
34
|
+
export interface CohenESOptions {
|
|
35
|
+
/** The conventional size: `"small"` (default), `"medium"` or `"large"`. */
|
|
36
|
+
size?: "small" | "medium" | "large" | (string & {});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Cohen's conventional effect sizes. Equivalent to `pwr::cohen.ES(test, size)` in R. The size is the second argument
|
|
40
|
+
* or the option `size` (giving both is a RangeError).
|
|
31
41
|
*
|
|
32
42
|
* @example
|
|
33
43
|
* ```ts
|
|
@@ -37,6 +47,15 @@ export interface CohenESResult {
|
|
|
37
47
|
* @category Effect sizes and power
|
|
38
48
|
*/
|
|
39
49
|
export declare function cohenES(test?: CohenTest | (string & {}), size?: "small" | "medium" | "large" | (string & {})): CohenESResult;
|
|
50
|
+
/**
|
|
51
|
+
* Cohen's conventional effect sizes, with the size in the options: `cohenES("anov", { size: "medium" })`.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* cohenES("anov", { size: "medium" }).effectSize; // 0.25
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function cohenES(test: CohenTest | (string & {}) | undefined, options: CohenESOptions): CohenESResult;
|
|
40
59
|
/**
|
|
41
60
|
* Effect size h of two proportions: `2 asin(sqrt(p1)) - 2 asin(sqrt(p2))`. Equivalent to `pwr::ES.h()` in R.
|
|
42
61
|
*
|
|
@@ -116,6 +135,8 @@ export interface PwrTTestResult {
|
|
|
116
135
|
note?: string;
|
|
117
136
|
/** Description of the calculation. */
|
|
118
137
|
method: string;
|
|
138
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
139
|
+
warnings: string[];
|
|
119
140
|
}
|
|
120
141
|
/**
|
|
121
142
|
* Power of a t test of means, or the sample size, effect size or significance level for a given power.
|
|
@@ -163,6 +184,8 @@ export interface PwrT2nTestResult {
|
|
|
163
184
|
alternative: Alternative;
|
|
164
185
|
/** Description of the calculation. */
|
|
165
186
|
method: string;
|
|
187
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
188
|
+
warnings: string[];
|
|
166
189
|
}
|
|
167
190
|
/**
|
|
168
191
|
* Power of a two-sample t test with unequal sample sizes, or a sample size, the effect size or the significance
|
|
@@ -208,6 +231,8 @@ export interface Pwr2pTestResult {
|
|
|
208
231
|
method: string;
|
|
209
232
|
/** A note on the sample sizes (absent for {@link pwrPTest}). */
|
|
210
233
|
note?: string;
|
|
234
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
235
|
+
warnings: string[];
|
|
211
236
|
}
|
|
212
237
|
/**
|
|
213
238
|
* Power of the test of two proportions with equal sample sizes (arcsine transformation), or the effect size, sample
|
|
@@ -264,6 +289,8 @@ export interface PwrNormTestResult {
|
|
|
264
289
|
alternative: Alternative;
|
|
265
290
|
/** Description of the calculation. */
|
|
266
291
|
method: string;
|
|
292
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
293
|
+
warnings: string[];
|
|
267
294
|
}
|
|
268
295
|
/**
|
|
269
296
|
* Power of the test of a mean of a normal distribution with known variance, or the effect size, sample size or
|
|
@@ -313,6 +340,8 @@ export interface Pwr2p2nTestResult {
|
|
|
313
340
|
method: string;
|
|
314
341
|
/** A note on the sample sizes. */
|
|
315
342
|
note: string;
|
|
343
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
344
|
+
warnings: string[];
|
|
316
345
|
}
|
|
317
346
|
/**
|
|
318
347
|
* Power of the test of two proportions with unequal sample sizes (arcsine transformation), or the effect size, a
|
|
@@ -356,6 +385,8 @@ export interface PwrRTestResult {
|
|
|
356
385
|
alternative: Alternative;
|
|
357
386
|
/** Description of the calculation. */
|
|
358
387
|
method: string;
|
|
388
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
389
|
+
warnings: string[];
|
|
359
390
|
}
|
|
360
391
|
/**
|
|
361
392
|
* Power of the test of a correlation (Fisher's z transformation), or the sample size, correlation or significance
|
|
@@ -404,6 +435,8 @@ export interface PwrChisqTestResult {
|
|
|
404
435
|
method: string;
|
|
405
436
|
/** A note on the sample size. */
|
|
406
437
|
note: string;
|
|
438
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
439
|
+
warnings: string[];
|
|
407
440
|
}
|
|
408
441
|
/**
|
|
409
442
|
* Power of a chi-squared test, or the effect size, number of observations or significance level for a given power.
|
|
@@ -451,6 +484,8 @@ export interface PwrAnovaTestResult {
|
|
|
451
484
|
note: string;
|
|
452
485
|
/** Description of the calculation. */
|
|
453
486
|
method: string;
|
|
487
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
488
|
+
warnings: string[];
|
|
454
489
|
}
|
|
455
490
|
/**
|
|
456
491
|
* Power of the F test of a balanced one-way analysis of variance, or the number of groups, sample size, effect size
|
|
@@ -496,6 +531,8 @@ export interface PwrF2TestResult {
|
|
|
496
531
|
power: number;
|
|
497
532
|
/** Description of the calculation. */
|
|
498
533
|
method: string;
|
|
534
|
+
/** R's warnings, each once, in R's order (an empty array when there are none). */
|
|
535
|
+
warnings: string[];
|
|
499
536
|
}
|
|
500
537
|
/**
|
|
501
538
|
* Power of the F test of a general linear model, or the degrees of freedom, effect size or significance level for a
|
package/dist/htest/pwr.js
CHANGED
|
@@ -10,7 +10,22 @@ import { pf, qf } from "../distributions/f.js";
|
|
|
10
10
|
import { pnorm, qnorm } from "../distributions/normal.js";
|
|
11
11
|
import { qt } from "../distributions/t.js";
|
|
12
12
|
import { ldexp, squareOver } from "../internal/summary.js";
|
|
13
|
+
import { optionalArgs } from "../internal/optionalArgs.js";
|
|
13
14
|
import { checkExactlyOne, fPowerHugeDf, hugeDf, isUnknown, matchChoice, ptNcp, solveFor } from "./power.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
|
+
import { optionsIn } from "../internal/optionalArgs.js";
|
|
18
|
+
const PWR_TTEST_KEYS = ["n", "d", "type", "sigLevel", "power", "alternative"];
|
|
19
|
+
const PWR_T2N_TEST_KEYS = ["n1", "n2", "d", "sigLevel", "power", "alternative"];
|
|
20
|
+
const PWR2P_TEST_KEYS = ["h", "n", "sigLevel", "power", "alternative"];
|
|
21
|
+
const PWR2P2N_TEST_KEYS = ["h", "n1", "n2", "sigLevel", "power", "alternative"];
|
|
22
|
+
const PWR_PTEST_KEYS = ["h", "n", "sigLevel", "power", "alternative"];
|
|
23
|
+
const PWR_NORM_TEST_KEYS = ["d", "n", "sigLevel", "power", "alternative"];
|
|
24
|
+
const PWR_RTEST_KEYS = ["n", "r", "sigLevel", "power", "alternative"];
|
|
25
|
+
const PWR_CHISQ_TEST_KEYS = ["w", "N", "df", "sigLevel", "power"];
|
|
26
|
+
const PWR_ANOVA_TEST_KEYS = ["k", "n", "f", "sigLevel", "power"];
|
|
27
|
+
const PWR_F2_TEST_KEYS = ["u", "v", "f2", "sigLevel", "power"];
|
|
28
|
+
const COHEN_ES_KEYS = ["size"];
|
|
14
29
|
const COHEN = {
|
|
15
30
|
p: [0.2, 0.5, 0.8],
|
|
16
31
|
t: [0.2, 0.5, 0.8],
|
|
@@ -19,17 +34,9 @@ const COHEN = {
|
|
|
19
34
|
chisq: [0.1, 0.3, 0.5],
|
|
20
35
|
f2: [0.02, 0.15, 0.35],
|
|
21
36
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* cohenES("anov", "medium").effectSize; // 0.25
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @category Effect sizes and power
|
|
31
|
-
*/
|
|
32
|
-
export function cohenES(test = "p", size = "small") {
|
|
37
|
+
export function cohenES(test = "p", ...args) {
|
|
38
|
+
checkOptions(optionsIn(args), COHEN_ES_KEYS, "cohenES"); // generated: option-keys.mjs
|
|
39
|
+
const size = optionalArgs(["size"], args).size ?? "small";
|
|
33
40
|
const t = matchChoice(test, ["p", "t", "r", "anov", "chisq", "f2"]);
|
|
34
41
|
const s = matchChoice(size, ["small", "medium", "large"]);
|
|
35
42
|
return { test: t, size: s, effectSize: COHEN[t][["small", "medium", "large"].indexOf(s)], method: "Conventional effect size from Cohen (1982)" };
|
|
@@ -187,6 +194,7 @@ function scaledProduct(xs) {
|
|
|
187
194
|
* @category Effect sizes and power
|
|
188
195
|
*/
|
|
189
196
|
export function pwrTTest(options = {}) {
|
|
197
|
+
checkOptions(options, PWR_TTEST_KEYS, "pwrTTest"); // generated: option-keys.mjs
|
|
190
198
|
let { n, power } = options;
|
|
191
199
|
let d = effect(options.d, "t");
|
|
192
200
|
let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
|
|
@@ -213,7 +221,7 @@ export function pwrTTest(options = {}) {
|
|
|
213
221
|
}
|
|
214
222
|
const note = type === "paired" ? "n is number of *pairs*" : type === "two.sample" ? "n is number in *each* group" : undefined;
|
|
215
223
|
const method = { "two.sample": "Two-sample", "one.sample": "One-sample", paired: "Paired" }[type] + " t test power calculation";
|
|
216
|
-
return { n: n, d: d, sigLevel: sigLevel, power, alternative: alt, ...(note === undefined ? {} : { note }), method };
|
|
224
|
+
return { n: n, d: d, sigLevel: sigLevel, power, alternative: alt, ...(note === undefined ? {} : { note }), method, warnings: [] };
|
|
217
225
|
}
|
|
218
226
|
/**
|
|
219
227
|
* Power of a two-sample t test with unequal sample sizes, or a sample size, the effect size or the significance
|
|
@@ -228,6 +236,7 @@ export function pwrTTest(options = {}) {
|
|
|
228
236
|
* @category Effect sizes and power
|
|
229
237
|
*/
|
|
230
238
|
export function pwrT2nTest(options = {}) {
|
|
239
|
+
checkOptions(options, PWR_T2N_TEST_KEYS, "pwrT2nTest"); // generated: option-keys.mjs
|
|
231
240
|
let { n1, n2, power } = options;
|
|
232
241
|
let d = effect(options.d, "t");
|
|
233
242
|
let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
|
|
@@ -254,7 +263,7 @@ export function pwrT2nTest(options = {}) {
|
|
|
254
263
|
else
|
|
255
264
|
sigLevel = solveFor((x) => powerOf(n1, n2, d, x) - target, 1e-10, 1 - 1e-10);
|
|
256
265
|
}
|
|
257
|
-
return { n1: n1, n2: n2, d: d, sigLevel: sigLevel, power, alternative: alt, method: "t test power calculation" };
|
|
266
|
+
return { n1: n1, n2: n2, d: d, sigLevel: sigLevel, power, alternative: alt, method: "t test power calculation", warnings: [] };
|
|
258
267
|
}
|
|
259
268
|
/** The normal-approximation tests: pwr.2p.test (scale sqrt(n/2)), pwr.p.test and pwr.norm.test (sqrt(n)) */
|
|
260
269
|
function normalTest(es0, options, name, scale, nLower, esLower) {
|
|
@@ -295,6 +304,7 @@ function normalTest(es0, options, name, scale, nLower, esLower) {
|
|
|
295
304
|
* @category Effect sizes and power
|
|
296
305
|
*/
|
|
297
306
|
export function pwr2pTest(options = {}) {
|
|
307
|
+
checkOptions(options, PWR2P_TEST_KEYS, "pwr2pTest"); // generated: option-keys.mjs
|
|
298
308
|
const r = normalTest(options.h, options, "h", (n) => Math.sqrt(n / 2), 2 + 1e-10, 1e-10);
|
|
299
309
|
return {
|
|
300
310
|
h: r.es,
|
|
@@ -304,6 +314,7 @@ export function pwr2pTest(options = {}) {
|
|
|
304
314
|
alternative: r.alternative,
|
|
305
315
|
method: "Difference of proportion power calculation for binomial distribution (arcsine transformation)",
|
|
306
316
|
note: "same sample sizes",
|
|
317
|
+
warnings: [],
|
|
307
318
|
};
|
|
308
319
|
}
|
|
309
320
|
/**
|
|
@@ -319,6 +330,7 @@ export function pwr2pTest(options = {}) {
|
|
|
319
330
|
* @category Effect sizes and power
|
|
320
331
|
*/
|
|
321
332
|
export function pwrPTest(options = {}) {
|
|
333
|
+
checkOptions(options, PWR_PTEST_KEYS, "pwrPTest"); // generated: option-keys.mjs
|
|
322
334
|
const r = normalTest(options.h, options, "h", (n) => Math.sqrt(n), 2 + 1e-10, 1e-10);
|
|
323
335
|
return {
|
|
324
336
|
h: r.es,
|
|
@@ -327,6 +339,7 @@ export function pwrPTest(options = {}) {
|
|
|
327
339
|
power: r.power,
|
|
328
340
|
alternative: r.alternative,
|
|
329
341
|
method: "proportion power calculation for binomial distribution (arcsine transformation)",
|
|
342
|
+
warnings: [],
|
|
330
343
|
};
|
|
331
344
|
}
|
|
332
345
|
/**
|
|
@@ -342,6 +355,7 @@ export function pwrPTest(options = {}) {
|
|
|
342
355
|
* @category Effect sizes and power
|
|
343
356
|
*/
|
|
344
357
|
export function pwrNormTest(options = {}) {
|
|
358
|
+
checkOptions(options, PWR_NORM_TEST_KEYS, "pwrNormTest"); // generated: option-keys.mjs
|
|
345
359
|
const r = normalTest(options.d, options, "d", (n) => Math.sqrt(n), 1 + 1e-10, 1e-10);
|
|
346
360
|
return {
|
|
347
361
|
d: r.es,
|
|
@@ -350,6 +364,7 @@ export function pwrNormTest(options = {}) {
|
|
|
350
364
|
power: r.power,
|
|
351
365
|
alternative: r.alternative,
|
|
352
366
|
method: "Mean power calculation for normal distribution with known variance",
|
|
367
|
+
warnings: [],
|
|
353
368
|
};
|
|
354
369
|
}
|
|
355
370
|
/**
|
|
@@ -365,6 +380,7 @@ export function pwrNormTest(options = {}) {
|
|
|
365
380
|
* @category Effect sizes and power
|
|
366
381
|
*/
|
|
367
382
|
export function pwr2p2nTest(options = {}) {
|
|
383
|
+
checkOptions(options, PWR2P2N_TEST_KEYS, "pwr2p2nTest"); // generated: option-keys.mjs
|
|
368
384
|
let { n1, n2, power } = options;
|
|
369
385
|
let h = effect(options.h, "p");
|
|
370
386
|
let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
|
|
@@ -409,6 +425,7 @@ export function pwr2p2nTest(options = {}) {
|
|
|
409
425
|
alternative: alt,
|
|
410
426
|
method: "difference of proportion power calculation for binomial distribution (arcsine transformation)",
|
|
411
427
|
note: "different sample sizes",
|
|
428
|
+
warnings: [],
|
|
412
429
|
};
|
|
413
430
|
}
|
|
414
431
|
/**
|
|
@@ -425,6 +442,7 @@ export function pwr2p2nTest(options = {}) {
|
|
|
425
442
|
* @category Effect sizes and power
|
|
426
443
|
*/
|
|
427
444
|
export function pwrRTest(options = {}) {
|
|
445
|
+
checkOptions(options, PWR_RTEST_KEYS, "pwrRTest"); // generated: option-keys.mjs
|
|
428
446
|
let { n, power } = options;
|
|
429
447
|
let r = effect(options.r, "r");
|
|
430
448
|
let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
|
|
@@ -473,6 +491,7 @@ export function pwrRTest(options = {}) {
|
|
|
473
491
|
power,
|
|
474
492
|
alternative: alt,
|
|
475
493
|
method: "approximate correlation power calculation (arctangh transformation)",
|
|
494
|
+
warnings: [],
|
|
476
495
|
};
|
|
477
496
|
}
|
|
478
497
|
/**
|
|
@@ -488,6 +507,7 @@ export function pwrRTest(options = {}) {
|
|
|
488
507
|
* @category Effect sizes and power
|
|
489
508
|
*/
|
|
490
509
|
export function pwrChisqTest(options) {
|
|
510
|
+
checkOptions(options, PWR_CHISQ_TEST_KEYS, "pwrChisqTest"); // generated: option-keys.mjs
|
|
491
511
|
let { N, power } = options;
|
|
492
512
|
const { df } = options;
|
|
493
513
|
let w = effect(options.w, "chisq");
|
|
@@ -518,7 +538,7 @@ export function pwrChisqTest(options) {
|
|
|
518
538
|
else
|
|
519
539
|
sigLevel = solveFor((x) => powerOf(w, N, x) - target, 1e-10, 1 - 1e-10);
|
|
520
540
|
}
|
|
521
|
-
return { w: w, N: N, df, sigLevel: sigLevel, power, method: "Chi squared power calculation", note: "N is the number of observations" };
|
|
541
|
+
return { w: w, N: N, df, sigLevel: sigLevel, power, method: "Chi squared power calculation", note: "N is the number of observations", warnings: [] };
|
|
522
542
|
}
|
|
523
543
|
/**
|
|
524
544
|
* Power of the F test of a balanced one-way analysis of variance, or the number of groups, sample size, effect size
|
|
@@ -533,6 +553,7 @@ export function pwrChisqTest(options) {
|
|
|
533
553
|
* @category Effect sizes and power
|
|
534
554
|
*/
|
|
535
555
|
export function pwrAnovaTest(options = {}) {
|
|
556
|
+
checkOptions(options, PWR_ANOVA_TEST_KEYS, "pwrAnovaTest"); // generated: option-keys.mjs
|
|
536
557
|
let { k, n, power } = options;
|
|
537
558
|
let f = effect(options.f, "anov");
|
|
538
559
|
let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
|
|
@@ -581,6 +602,7 @@ export function pwrAnovaTest(options = {}) {
|
|
|
581
602
|
power,
|
|
582
603
|
note: "n is number in each group",
|
|
583
604
|
method: "Balanced one-way analysis of variance power calculation",
|
|
605
|
+
warnings: [],
|
|
584
606
|
};
|
|
585
607
|
}
|
|
586
608
|
/**
|
|
@@ -596,6 +618,7 @@ export function pwrAnovaTest(options = {}) {
|
|
|
596
618
|
* @category Effect sizes and power
|
|
597
619
|
*/
|
|
598
620
|
export function pwrF2Test(options = {}) {
|
|
621
|
+
checkOptions(options, PWR_F2_TEST_KEYS, "pwrF2Test"); // generated: option-keys.mjs
|
|
599
622
|
let { u, v, power } = options;
|
|
600
623
|
let f2 = effect(options.f2, "f2");
|
|
601
624
|
let sigLevel = options.sigLevel === undefined ? 0.05 : options.sigLevel;
|
|
@@ -634,5 +657,5 @@ export function pwrF2Test(options = {}) {
|
|
|
634
657
|
else
|
|
635
658
|
sigLevel = solveFor((x) => powerOf(u, v, f2, x) - target, 1e-10, 1 - 1e-10);
|
|
636
659
|
}
|
|
637
|
-
return { u: u, v: v, f2: f2, sigLevel: sigLevel, power, method: "Multiple regression power calculation" };
|
|
660
|
+
return { u: u, v: v, f2: f2, sigLevel: sigLevel, power, method: "Multiple regression power calculation", warnings: [] };
|
|
638
661
|
}
|
package/dist/htest/rankTests.js
CHANGED
|
@@ -24,6 +24,9 @@ import { completeRows, median, toGroups } from "./groups.js";
|
|
|
24
24
|
import { blockData, kSampleData, twoGroupData } from "./testFormula.js";
|
|
25
25
|
import { matchAlternative } from "./types.js";
|
|
26
26
|
import { maxOf, minOf } from "../internal/extremes.js";
|
|
27
|
+
// Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
|
|
28
|
+
import { checkOptions } from "../internal/checkOptions.js";
|
|
29
|
+
const MOOD_TEST_KEYS = ["alternative"];
|
|
27
30
|
function chisqResult(method, name, statistic, df) {
|
|
28
31
|
return {
|
|
29
32
|
method,
|
|
@@ -32,6 +35,7 @@ function chisqResult(method, name, statistic, df) {
|
|
|
32
35
|
parameter: df,
|
|
33
36
|
parameterName: "df",
|
|
34
37
|
pValue: pgamma1(statistic, df / 2, 2, false, false),
|
|
38
|
+
warnings: [],
|
|
35
39
|
};
|
|
36
40
|
}
|
|
37
41
|
function sumTies(x) {
|
|
@@ -165,6 +169,7 @@ export function quadeTest(y, data) {
|
|
|
165
169
|
parameter,
|
|
166
170
|
parameterName: ["num df", "denom df"],
|
|
167
171
|
pValue,
|
|
172
|
+
warnings: [],
|
|
168
173
|
};
|
|
169
174
|
}
|
|
170
175
|
export function flignerTest(x, g) {
|
|
@@ -211,6 +216,7 @@ export function flignerTest(x, g) {
|
|
|
211
216
|
return chisqResult("Fligner-Killeen test of homogeneity of variances", "Fligner-Killeen:med chi-squared", stat, k - 1);
|
|
212
217
|
}
|
|
213
218
|
export function moodTest(x, y, options = {}) {
|
|
219
|
+
checkOptions(options, MOOD_TEST_KEYS, "moodTest"); // generated: option-keys.mjs
|
|
214
220
|
if (typeof x === "string") {
|
|
215
221
|
const d = twoGroupData(x, y);
|
|
216
222
|
return moodTest(d.x, d.y, options);
|
|
@@ -261,5 +267,5 @@ export function moodTest(x, y, options = {}) {
|
|
|
261
267
|
: alternative === "greater"
|
|
262
268
|
? pnorm(zstat, { lowerTail: false })
|
|
263
269
|
: 2 * pnorm(-Math.abs(zstat));
|
|
264
|
-
return { method: "Mood two-sample test of scale", alternative, statistic: zstat, statisticName: "Z", pValue };
|
|
270
|
+
return { method: "Mood two-sample test of scale", alternative, statistic: zstat, statisticName: "Z", pValue, warnings: [] };
|
|
265
271
|
}
|
package/dist/htest/tTest.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export interface TTestResult extends HTest {
|
|
|
38
38
|
nullValue: number;
|
|
39
39
|
/** Standard error of the mean (or difference), R's `stderr`. */
|
|
40
40
|
stdErr: number;
|
|
41
|
+
/** Alias of `stdErr`: the same value. */
|
|
42
|
+
stdError: number;
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
45
|
* Student's t-test. Equivalent to R's `t.test()`.
|
package/dist/htest/tTest.js
CHANGED
|
@@ -10,7 +10,14 @@ import { pt1, qt1 } from "../distributions/t.js";
|
|
|
10
10
|
import { completePairs, dropNaN, ldexp, mean, pairedDifferences, satterthwaiteDfSe, scaleToUnit, variance } from "../internal/summary.js";
|
|
11
11
|
import { twoSampleData } from "./testFormula.js";
|
|
12
12
|
import { checkConfLevel, matchAlternative } from "./types.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
|
+
import { isOptionsObject } from "../internal/optionalArgs.js";
|
|
16
|
+
const T_TEST_KEYS = ["alternative", "mu", "paired", "varEqual", "confLevel"];
|
|
13
17
|
export function tTest(x, y, options = {}) {
|
|
18
|
+
if (typeof x !== "string" && isOptionsObject(y))
|
|
19
|
+
checkOptions(y, T_TEST_KEYS, "tTest"); // generated: option-keys.mjs
|
|
20
|
+
checkOptions(options, T_TEST_KEYS, "tTest"); // generated: option-keys.mjs
|
|
14
21
|
if (typeof x === "string")
|
|
15
22
|
return tTestFormula(x, y, options);
|
|
16
23
|
// Also accept the form tTest(x, { mu: 1 })
|
|
@@ -154,6 +161,8 @@ export function tTest(x, y, options = {}) {
|
|
|
154
161
|
nullValue: mu,
|
|
155
162
|
nullValueName,
|
|
156
163
|
stdErr,
|
|
164
|
+
stdError: stdErr,
|
|
165
|
+
warnings: [],
|
|
157
166
|
};
|
|
158
167
|
}
|
|
159
168
|
/** t.test from a formula: the default form on the data the formula selects, with the estimates named after the levels */
|