@numero-uno-jpn/rstats 1.1.0 → 1.3.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 +142 -0
- package/README.ja.md +33 -15
- package/README.md +32 -14
- package/dist/chunks/{chunk-4KCSBTR5.js → chunk-2VZW4XPK.js} +2 -2
- package/dist/chunks/chunk-4OOTEXZU.js +2 -0
- package/dist/chunks/{chunk-Z2HGLFZN.js → chunk-6TZVS6WC.js} +2 -2
- package/dist/chunks/{chunk-U7BRXOUS.js → chunk-6X2ZMPF5.js} +2 -2
- package/dist/chunks/{chunk-GJEKNJP7.js → chunk-AJZV2SVY.js} +2 -2
- package/dist/chunks/{chunk-GRUQRNX7.js → chunk-BNTBZ5W3.js} +3 -3
- package/dist/chunks/{chunk-DR4GQ7PW.js → chunk-EBRTF7RM.js} +1 -1
- package/dist/chunks/{chunk-OG7UORIX.js → chunk-FFNHG5SB.js} +1 -1
- package/dist/chunks/{chunk-N5BDSMXS.js → chunk-GUM57VVM.js} +1 -1
- package/dist/chunks/{chunk-GGJA3JRO.js → chunk-HBRSUHSU.js} +2 -2
- package/dist/chunks/{chunk-HRA7PCQT.js → chunk-I5NWGQOQ.js} +2 -2
- package/dist/chunks/chunk-IJV43Y7Q.js +2 -0
- package/dist/chunks/{chunk-YN5MLKDL.js → chunk-IOGQEMDE.js} +2 -2
- package/dist/chunks/{chunk-GYGQUYEP.js → chunk-JJRZ2TTF.js} +2 -2
- package/dist/chunks/{chunk-X4J6UJHN.js → chunk-LA4H6ZSC.js} +2 -2
- package/dist/chunks/{chunk-DTJG2IL2.js → chunk-LMNU4NHZ.js} +2 -2
- package/dist/chunks/{chunk-4VRMAYPY.js → chunk-LNUNKFIH.js} +3 -3
- package/dist/chunks/chunk-MJXETGT2.js +2 -0
- package/dist/chunks/chunk-P7ZHH2SF.js +2 -0
- package/dist/chunks/{chunk-HUWOSLKE.js → chunk-PDHBRDTF.js} +2 -2
- package/dist/chunks/{chunk-7KJ24LYK.js → chunk-RCGW2DCK.js} +2 -2
- package/dist/chunks/{chunk-QUTJEYDX.js → chunk-TZTVDVP4.js} +2 -2
- package/dist/chunks/{chunk-HZLSNJQM.js → chunk-UJYRU37Z.js} +2 -2
- package/dist/chunks/{chunk-EJYCDE4Z.js → chunk-UMDXXT3M.js} +1 -1
- package/dist/chunks/{chunk-7IJCUSA5.js → chunk-UOAFEB64.js} +2 -2
- package/dist/chunks/{chunk-JNWWLNE3.js → chunk-Z74ZOTUN.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/tests.d.ts +14 -0
- package/dist/entries/tests.js +14 -0
- package/dist/htest/agreement.d.ts +2 -2
- package/dist/htest/binomCI.d.ts +116 -0
- package/dist/htest/binomCI.js +252 -0
- package/dist/htest/blandAltman.d.ts +100 -0
- package/dist/htest/blandAltman.js +159 -0
- package/dist/htest/boschlooTest.d.ts +65 -0
- package/dist/htest/boschlooTest.js +394 -0
- package/dist/htest/chisqTest.d.ts +19 -0
- package/dist/htest/chisqTest.js +30 -2
- package/dist/htest/core/twoProportions.d.ts +48 -0
- package/dist/htest/core/twoProportions.js +476 -0
- package/dist/htest/diagnosticTests.d.ts +91 -0
- package/dist/htest/diagnosticTests.js +116 -0
- package/dist/htest/equivalence.d.ts +172 -0
- package/dist/htest/equivalence.js +189 -0
- package/dist/htest/fisherTest.d.ts +49 -0
- package/dist/htest/fisherTest.js +136 -13
- package/dist/htest/iccPsych.d.ts +106 -0
- package/dist/htest/iccPsych.js +332 -0
- package/dist/htest/ksTest.d.ts +1 -1
- package/dist/htest/mcreg.d.ts +209 -0
- package/dist/htest/mcreg.js +735 -0
- package/dist/htest/roc.d.ts +287 -0
- package/dist/htest/roc.js +635 -0
- package/dist/htest/rocTest.d.ts +139 -0
- package/dist/htest/rocTest.js +444 -0
- package/dist/htest/tTOST.d.ts +202 -0
- package/dist/htest/tTOST.js +558 -0
- package/dist/htest/tableTests.d.ts +216 -0
- package/dist/htest/tableTests.js +650 -0
- package/dist/htest/trendTests.d.ts +1 -1
- package/dist/htest/trendTests.js +1 -1
- package/dist/htest/twoByTwo.d.ts +203 -0
- package/dist/htest/twoByTwo.js +385 -0
- package/dist/internal/summary.js +5 -0
- package/dist/linalg/qr.d.ts +3 -0
- package/dist/linalg/qr.js +3 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/coeftest.d.ts +139 -0
- package/dist/models/coeftest.js +237 -0
- package/dist/models/coxph.d.ts +60 -9
- package/dist/models/coxph.js +367 -38
- package/dist/models/glm.d.ts +11 -1
- package/dist/models/glm.js +19 -2
- package/dist/models/inputRows.d.ts +10 -0
- package/dist/models/inputRows.js +23 -0
- package/dist/models/lm.d.ts +8 -0
- package/dist/models/lm.js +14 -2
- package/dist/models/sandwich.d.ts +177 -0
- package/dist/models/sandwich.js +923 -0
- package/dist/numerics.js +2 -2
- package/dist/random/rng.d.ts +8 -1
- package/dist/random/rng.js +14 -1
- package/dist/rstats.js +16 -16
- package/dist/special/igam.js +140 -23
- package/dist/special/loader.js +8 -0
- package/dist/special.js +2 -2
- package/dist/tests.js +13 -13
- package/llms.txt +25 -0
- package/package.json +1 -1
- package/dist/chunks/chunk-NDTJ23A6.js +0 -2
- package/dist/chunks/chunk-UMLMY4XS.js +0 -2
- package/dist/chunks/chunk-Y4YWLSWU.js +0 -2
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { type Alternative, type Counts, type HTest } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Freeman-Tukey deviate sqrt(O) + sqrt(O + 1) - sqrt(4E + 1) (Bishop, Fienberg and Holland 1975, 14.7). The plain
|
|
4
|
+
* formula cancels for large counts (sqrt(O) + sqrt(O + 1) against sqrt(4E + 1), losing eps sqrt(O) absolute); here it
|
|
5
|
+
* is (a^2 - b^2) / (a + b) with a = sqrt(O) + sqrt(O + 1), b = sqrt(4E + 1) and
|
|
6
|
+
* a^2 - b^2 = 2(O - E) + 2 ((O - E)(O + E) + O) / (sqrt(O (O + 1)) + E), whose rounding is a few eps absolute
|
|
7
|
+
*/
|
|
8
|
+
export declare function freemanTukeyDeviate(O: number, E: number): number;
|
|
9
|
+
/** Freeman-Tukey deviates of a vector or a table (rows) */
|
|
10
|
+
export declare function freemanTukeyResiduals(O: readonly number[], E: readonly number[]): number[];
|
|
11
|
+
export declare function freemanTukeyResiduals(O: readonly (readonly number[])[], E: readonly (readonly number[])[]): number[][];
|
|
12
|
+
/**
|
|
13
|
+
* Corrections of {@link gTest}.
|
|
14
|
+
*
|
|
15
|
+
* @category Hypothesis tests
|
|
16
|
+
*/
|
|
17
|
+
export type GTestCorrection = "none" | "williams" | "yates";
|
|
18
|
+
/**
|
|
19
|
+
* Options for {@link gTest}.
|
|
20
|
+
*
|
|
21
|
+
* @category Hypothesis tests
|
|
22
|
+
*/
|
|
23
|
+
export interface GTestOptions {
|
|
24
|
+
/**
|
|
25
|
+
* `"none"` (default), `"williams"` (Williams' correction q of the statistic) or `"yates"` (Yates' correction of the
|
|
26
|
+
* counts by 0.5, 2 x 2 tables and two-category goodness of fit only). Unambiguous abbreviations are accepted.
|
|
27
|
+
*/
|
|
28
|
+
correct?: GTestCorrection | (string & {});
|
|
29
|
+
/** Expected probabilities for the goodness-of-fit test. Default: equal probabilities. Ignored for a table. */
|
|
30
|
+
p?: readonly number[];
|
|
31
|
+
/** Rescale `p` to sum to 1. Default `false`, in which case `p` must sum to 1 (within sqrt(eps)). */
|
|
32
|
+
rescaleP?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Result of {@link gTest}. Has no `alternative`, as DescTools' `GTest` returns none.
|
|
36
|
+
*
|
|
37
|
+
* @category Hypothesis tests
|
|
38
|
+
*/
|
|
39
|
+
export interface GTestResult extends Omit<HTest, "alternative"> {
|
|
40
|
+
/** Degrees of freedom (`parameterName` is `"X-squared df"`, as DescTools). */
|
|
41
|
+
parameter: number;
|
|
42
|
+
/** The counts, after Yates' correction where it is applied (as DescTools); an array of rows for a table. */
|
|
43
|
+
observed: number[] | number[][];
|
|
44
|
+
/** Expected counts under the null hypothesis. */
|
|
45
|
+
expected: number[] | number[][];
|
|
46
|
+
/**
|
|
47
|
+
* Freeman-Tukey deviates `sqrt(O) + sqrt(O + 1) - sqrt(4E + 1)` of the counts given (without Yates' correction),
|
|
48
|
+
* approximately standard normal under the null hypothesis.
|
|
49
|
+
*/
|
|
50
|
+
ftResiduals: number[] | number[][];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Log-likelihood ratio (G) test of independence in a contingency table, or of goodness of fit of counts to given
|
|
54
|
+
* probabilities. Equivalent to `DescTools::GTest()` in R.
|
|
55
|
+
*
|
|
56
|
+
* For a table (an array of rows), `G = 2 sum x log(x / E) / q` with `E` the products of the margins over the total and
|
|
57
|
+
* `(r - 1)(c - 1)` degrees of freedom, counting empty rows and columns as DescTools; for a vector (or a table with one
|
|
58
|
+
* row or column), `E = n p` and `k - 1` degrees of freedom. `correct: "williams"` divides by Williams' q
|
|
59
|
+
* (`1 + (n sum 1/R_i - 1)(n sum 1/C_j - 1) / (6 n (r - 1)(c - 1))` for a table, which is not defined with an empty
|
|
60
|
+
* row or column: an error, where DescTools gives G = 0 and p = 1; and `1 + (k + 1) / (6n)` for a vector). `correct: "yates"` moves the counts of a 2 x 2 table by 0.5 toward
|
|
61
|
+
* independence as DescTools does: the off-diagonal cells up and the diagonal down when `x11 x22 - x12 x21 > 0`, and
|
|
62
|
+
* the other way otherwise, also when it is 0 (so that a table of exact independence gets a positive G), and without
|
|
63
|
+
* stopping at 0 (a cell that becomes negative makes G NaN, with the warning "NaNs produced"). For two counts it moves
|
|
64
|
+
* them by 0.5 toward `E` when they differ from it by more than 0.25.
|
|
65
|
+
*
|
|
66
|
+
* The p-value is the upper tail of chi-squared (DescTools computes `1 - pchisq` for a table, which is 0 below about
|
|
67
|
+
* 1e-16). G is summed as a deviance, without the cancellation of the plain sum. The result also has the Freeman-Tukey
|
|
68
|
+
* deviates `ftResiduals`.
|
|
69
|
+
*
|
|
70
|
+
* @param x Counts (nonnegative, finite; not all 0), or a contingency table as an array of rows.
|
|
71
|
+
* @param options See {@link GTestOptions}.
|
|
72
|
+
* @returns The test result, with `statisticName` `"G"`; see {@link GTestResult}.
|
|
73
|
+
* @throws RangeError for negative or non-finite counts, a total of 0, fewer than 2 counts, `p` of the wrong length,
|
|
74
|
+
* negative or not summing to 1, `"yates"` for anything but a 2 x 2 table or two counts, and `"williams"` for a
|
|
75
|
+
* table with an empty row or column.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* gTest([[12, 5], [7, 9]]).statistic; // 2.4600430077307167
|
|
80
|
+
* gTest([[12, 5], [7, 9]], { correct: "williams" }).pValue; // 0.12530270793206313
|
|
81
|
+
* gTest([10, 20, 30], { p: [0.2, 0.3, 0.5] }).pValue; // 0.7527706003419717
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @category Hypothesis tests
|
|
85
|
+
*/
|
|
86
|
+
export declare function gTest(x: Counts | readonly Counts[], options?: GTestOptions): GTestResult;
|
|
87
|
+
/**
|
|
88
|
+
* Result of {@link stuartMaxwellTest}. Has no `alternative`, as DescTools' `StuartMaxwellTest` returns none.
|
|
89
|
+
*
|
|
90
|
+
* @category Hypothesis tests
|
|
91
|
+
*/
|
|
92
|
+
export interface StuartMaxwellTestResult extends Omit<HTest, "alternative"> {
|
|
93
|
+
/** Degrees of freedom: the number of categories left, less 1 (`parameterName` is `"df"`). */
|
|
94
|
+
parameter: number;
|
|
95
|
+
/** The total of the table without the categories removed. */
|
|
96
|
+
N: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Stuart-Maxwell test of marginal homogeneity of a square table (paired classifications into the same categories).
|
|
100
|
+
* Equivalent to `DescTools::StuartMaxwellTest()` in R. The degrees of freedom differ where categories are removed.
|
|
101
|
+
*
|
|
102
|
+
* Categories with no counts off the diagonal (in their row and column) are removed. With the K categories left, `d`
|
|
103
|
+
* the differences of the row and column sums of the first K - 1 and `S` their covariance (`S_ii = r_i + c_i - 2 x_ii`,
|
|
104
|
+
* `S_ij = -(x_ij + x_ji)`), the statistic `d' S^-1 d` is chi-squared with K - 1 degrees of freedom (DescTools keeps the
|
|
105
|
+
* original number of categories less 1). For a 2 x 2 table it is McNemar's statistic without correction.
|
|
106
|
+
*
|
|
107
|
+
* @param table A square table of counts as an array of rows.
|
|
108
|
+
* @returns The test result, with `statisticName` `"chi-squared"`; see {@link StuartMaxwellTestResult}.
|
|
109
|
+
* @throws RangeError for a table that is not square with at least two rows, negative or non-finite counts, fewer
|
|
110
|
+
* than 2 categories left ("Too many equal marginals, cannot compute") and categories whose off-diagonal counts fall
|
|
111
|
+
* into unconnected groups (S is then singular).
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* stuartMaxwellTest([[20, 3, 2], [4, 15, 6], [1, 5, 30]]).statistic; // 0.30534351145038163
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @category Hypothesis tests
|
|
119
|
+
*/
|
|
120
|
+
export declare function stuartMaxwellTest(table: readonly Counts[]): StuartMaxwellTestResult;
|
|
121
|
+
/**
|
|
122
|
+
* Options for {@link goodmanKruskalGamma}.
|
|
123
|
+
*
|
|
124
|
+
* @category Hypothesis tests
|
|
125
|
+
*/
|
|
126
|
+
export interface GoodmanKruskalGammaOptions {
|
|
127
|
+
/** Confidence level of `confInt`, in (0, 1). Default `0.95`. */
|
|
128
|
+
confLevel?: number;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Result of {@link goodmanKruskalGamma}.
|
|
132
|
+
*
|
|
133
|
+
* @category Hypothesis tests
|
|
134
|
+
*/
|
|
135
|
+
export interface GoodmanKruskalGammaResult {
|
|
136
|
+
/** Gamma, `(C - D) / (C + D)` with C and D the numbers of concordant and discordant pairs (NaN when both are 0). */
|
|
137
|
+
estimate: number;
|
|
138
|
+
/** The Wald interval `gamma -/+ z ase`, clipped to [-1, 1]. */
|
|
139
|
+
confInt: [number, number];
|
|
140
|
+
/** The confidence level of `confInt`. */
|
|
141
|
+
confLevel: number;
|
|
142
|
+
/** The asymptotic standard error ASE1 (not under the null hypothesis). */
|
|
143
|
+
ase: number;
|
|
144
|
+
/** Warnings (none: DescTools gives none either). */
|
|
145
|
+
warnings: string[];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Goodman and Kruskal's gamma of a table of two ordered classifications, with its asymptotic standard error and a
|
|
149
|
+
* Wald confidence interval. Equivalent to `DescTools::GoodmanKruskalGamma()` in R.
|
|
150
|
+
*
|
|
151
|
+
* `gamma = (C - D) / (C + D)` with C and D the numbers of concordant and discordant pairs. The standard error is the
|
|
152
|
+
* non-null ASE1 (Agresti 2010, section 7.1): `sqrt(sum x psi^2)` with `psi_ij = 2 (D Pc_ij - C Pd_ij) / (C + D)^2`,
|
|
153
|
+
* `Pc_ij` the counts above-left and below-right of cell (i, j) and `Pd_ij` those above-right and below-left. The
|
|
154
|
+
* interval is `[max(-1, gamma - z ase), min(1, gamma + z ase)]`, z the normal quantile of `1 - (1 - confLevel) / 2`.
|
|
155
|
+
* Without concordant or discordant pairs (a table with one row, for example) gamma and the interval are NaN, as
|
|
156
|
+
* DescTools. No test of gamma = 0 is given (it would need the null standard error).
|
|
157
|
+
*
|
|
158
|
+
* @param table A table of counts (nonnegative, finite) as an array of rows; rows and columns in their order.
|
|
159
|
+
* @param options See {@link GoodmanKruskalGammaOptions}.
|
|
160
|
+
* @returns See {@link GoodmanKruskalGammaResult}.
|
|
161
|
+
* @throws RangeError for negative or non-finite counts, or a level outside (0, 1).
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const g = goodmanKruskalGamma([[10, 5, 2], [3, 8, 6], [1, 4, 9]]);
|
|
166
|
+
* g.estimate; // 0.6703296703296703
|
|
167
|
+
* g.confInt; // [0.4241347346132843, 0.9165246060460562]
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @category Hypothesis tests
|
|
171
|
+
*/
|
|
172
|
+
export declare function goodmanKruskalGamma(table: readonly Counts[], options?: GoodmanKruskalGammaOptions): GoodmanKruskalGammaResult;
|
|
173
|
+
/**
|
|
174
|
+
* Options for {@link lblTest}.
|
|
175
|
+
*
|
|
176
|
+
* @category Hypothesis tests
|
|
177
|
+
*/
|
|
178
|
+
export interface LblTestOptions {
|
|
179
|
+
/** `"two.sided"` (default), `"less"` (negative association) or `"greater"` (positive association). */
|
|
180
|
+
alternative?: Alternative | (string & {});
|
|
181
|
+
/** Scores of the rows. Default `1, 2, ..., r`. */
|
|
182
|
+
rowScores?: readonly number[];
|
|
183
|
+
/** Scores of the columns. Default `1, 2, ..., c`. */
|
|
184
|
+
colScores?: readonly number[];
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Result of {@link lblTest}.
|
|
188
|
+
*
|
|
189
|
+
* @category Hypothesis tests
|
|
190
|
+
*/
|
|
191
|
+
export type LblTestResult = HTest;
|
|
192
|
+
/**
|
|
193
|
+
* Asymptotic linear-by-linear association test of a table of two ordered classifications (the Mantel test of trend).
|
|
194
|
+
* Equivalent to `coin::lbl_test()` in R. As coin's asymptotic test, except for tables with a two-level factor.
|
|
195
|
+
*
|
|
196
|
+
* `Z = sqrt(N - 1) r`, r the Pearson correlation of the row and column scores over the N observations: the linear
|
|
197
|
+
* statistic `sum x_ij u_i v_j` standardised by its permutation (conditional) mean and variance. The scores are 1..k
|
|
198
|
+
* by default for every factor (the level index; empty rows and columns keep their place). coin leaves a two-level
|
|
199
|
+
* factor unordered and codes it by an indicator of its first level, which turns the sign of Z, and refuses 2 x 2
|
|
200
|
+
* tables; here two-level factors are scored like the others and a 2 x 2 table is tested (Z^2 is then the 'N - 1'
|
|
201
|
+
* chi-squared statistic). p-values from the normal distribution: `"greater"` is positive association.
|
|
202
|
+
*
|
|
203
|
+
* @param table A table of counts (nonnegative, finite) as an array of rows.
|
|
204
|
+
* @param options See {@link LblTestOptions}.
|
|
205
|
+
* @returns The test result, with `statisticName` `"Z"`; see {@link LblTestResult}.
|
|
206
|
+
* @throws RangeError for negative or non-finite counts, a total of at most 1, scores of the wrong length or not
|
|
207
|
+
* finite, and tables whose row or column scores do not vary over the observations (Z undefined).
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* lblTest([[10, 5, 2], [3, 8, 6], [1, 4, 9]]).statistic; // 3.601652214003794
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @category Hypothesis tests
|
|
215
|
+
*/
|
|
216
|
+
export declare function lblTest(table: readonly Counts[], options?: LblTestOptions): LblTestResult;
|