@numero-uno-jpn/rstats 1.2.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.ja.md +27 -10
  3. package/README.md +26 -9
  4. package/dist/chunks/{chunk-ORE5ZRCY.js → chunk-2VZW4XPK.js} +2 -2
  5. package/dist/chunks/chunk-4OOTEXZU.js +2 -0
  6. package/dist/chunks/{chunk-F3EQLL4F.js → chunk-6TZVS6WC.js} +2 -2
  7. package/dist/chunks/{chunk-L23RSC2N.js → chunk-6X2ZMPF5.js} +2 -2
  8. package/dist/chunks/{chunk-IAWXF73N.js → chunk-AJZV2SVY.js} +2 -2
  9. package/dist/chunks/{chunk-5SGTWSCB.js → chunk-BNTBZ5W3.js} +2 -2
  10. package/dist/chunks/{chunk-EEU7D4RU.js → chunk-EBRTF7RM.js} +1 -1
  11. package/dist/chunks/{chunk-IMPRIQE5.js → chunk-FFNHG5SB.js} +1 -1
  12. package/dist/chunks/{chunk-73LNRWU3.js → chunk-GUM57VVM.js} +1 -1
  13. package/dist/chunks/{chunk-RRO4LMCB.js → chunk-HBRSUHSU.js} +2 -2
  14. package/dist/chunks/{chunk-VERBXW6E.js → chunk-I5NWGQOQ.js} +2 -2
  15. package/dist/chunks/chunk-IJV43Y7Q.js +2 -0
  16. package/dist/chunks/{chunk-6FZHTD5G.js → chunk-IOGQEMDE.js} +2 -2
  17. package/dist/chunks/{chunk-JWBSEL3V.js → chunk-JJRZ2TTF.js} +2 -2
  18. package/dist/chunks/{chunk-2NNBUYHJ.js → chunk-LA4H6ZSC.js} +2 -2
  19. package/dist/chunks/{chunk-A66M3ZEA.js → chunk-LMNU4NHZ.js} +2 -2
  20. package/dist/chunks/{chunk-HBHMEPGY.js → chunk-LNUNKFIH.js} +3 -3
  21. package/dist/chunks/chunk-MJXETGT2.js +2 -0
  22. package/dist/chunks/{chunk-7WG7X2UI.js → chunk-P7ZHH2SF.js} +2 -2
  23. package/dist/chunks/{chunk-TNETWBF5.js → chunk-PDHBRDTF.js} +2 -2
  24. package/dist/chunks/{chunk-4AOTAT3O.js → chunk-RCGW2DCK.js} +2 -2
  25. package/dist/chunks/{chunk-NSU6U3ET.js → chunk-TZTVDVP4.js} +2 -2
  26. package/dist/chunks/{chunk-T5DRIITM.js → chunk-UJYRU37Z.js} +2 -2
  27. package/dist/chunks/{chunk-BI7NYJWP.js → chunk-UMDXXT3M.js} +1 -1
  28. package/dist/chunks/{chunk-7INBXTVV.js → chunk-UOAFEB64.js} +2 -2
  29. package/dist/chunks/{chunk-BKV3FINA.js → chunk-Z74ZOTUN.js} +2 -2
  30. package/dist/descriptive.js +2 -2
  31. package/dist/distributions.js +2 -2
  32. package/dist/entries/tests.d.ts +9 -0
  33. package/dist/entries/tests.js +9 -0
  34. package/dist/htest/agreement.d.ts +2 -2
  35. package/dist/htest/blandAltman.d.ts +100 -0
  36. package/dist/htest/blandAltman.js +159 -0
  37. package/dist/htest/diagnosticTests.d.ts +91 -0
  38. package/dist/htest/diagnosticTests.js +116 -0
  39. package/dist/htest/iccPsych.d.ts +106 -0
  40. package/dist/htest/iccPsych.js +332 -0
  41. package/dist/htest/ksTest.d.ts +1 -1
  42. package/dist/htest/mcreg.d.ts +209 -0
  43. package/dist/htest/mcreg.js +735 -0
  44. package/dist/htest/roc.d.ts +287 -0
  45. package/dist/htest/roc.js +635 -0
  46. package/dist/htest/rocTest.d.ts +139 -0
  47. package/dist/htest/rocTest.js +444 -0
  48. package/dist/htest/tTOST.d.ts +202 -0
  49. package/dist/htest/tTOST.js +558 -0
  50. package/dist/htest/trendTests.d.ts +1 -1
  51. package/dist/htest/trendTests.js +1 -1
  52. package/dist/internal/summary.js +5 -0
  53. package/dist/linalg/qr.d.ts +3 -0
  54. package/dist/linalg/qr.js +3 -0
  55. package/dist/linalg.js +2 -2
  56. package/dist/mixed.js +2 -2
  57. package/dist/models/coeftest.d.ts +139 -0
  58. package/dist/models/coeftest.js +237 -0
  59. package/dist/models/coxph.d.ts +60 -9
  60. package/dist/models/coxph.js +367 -38
  61. package/dist/models/glm.d.ts +11 -1
  62. package/dist/models/glm.js +19 -2
  63. package/dist/models/inputRows.d.ts +10 -0
  64. package/dist/models/inputRows.js +23 -0
  65. package/dist/models/lm.d.ts +8 -0
  66. package/dist/models/lm.js +14 -2
  67. package/dist/models/sandwich.d.ts +177 -0
  68. package/dist/models/sandwich.js +923 -0
  69. package/dist/numerics.js +2 -2
  70. package/dist/random/rng.d.ts +8 -1
  71. package/dist/random/rng.js +14 -1
  72. package/dist/rstats.js +16 -16
  73. package/dist/special.js +2 -2
  74. package/dist/tests.js +13 -13
  75. package/llms.txt +17 -0
  76. package/package.json +1 -1
  77. package/dist/chunks/chunk-47IIPUFN.js +0 -2
  78. package/dist/chunks/chunk-CQB4BJBR.js +0 -2
@@ -0,0 +1,202 @@
1
+ import type { Sample } from "./types.js";
2
+ /**
3
+ * Options for {@link tTOST} and {@link tsumTOST}. The equivalence bounds are required: `eqb`, or `lowEqbound` and
4
+ * `highEqbound`. Unambiguous abbreviations of the choices are accepted.
5
+ *
6
+ * @category Hypothesis tests
7
+ */
8
+ export interface TTOSTOptions {
9
+ /** The bounds: a number `e` for `(-|e|, |e|)`, or two numbers `[low, high]` (in either order). */
10
+ eqb?: number | readonly number[];
11
+ /** The lower bound (with `highEqbound`, where `eqb` is not given). */
12
+ lowEqbound?: number;
13
+ /** The upper bound (with `lowEqbound`, where `eqb` is not given). */
14
+ highEqbound?: number;
15
+ /** `"EQU"` (default): equivalence, the effect lies inside the bounds; `"MET"`: minimal effect, outside them. */
16
+ hypothesis?: "EQU" | "MET" | (string & {});
17
+ /** Paired samples. Default `false`. */
18
+ paired?: boolean;
19
+ /** Two samples: pooled variance (Student's t) instead of Welch's. Default `false`. */
20
+ varEqual?: boolean;
21
+ /** The level of each one-sided test, in (0, 0.5); the intervals are 1 − 2 alpha intervals. Default `0.05`. */
22
+ alpha?: number;
23
+ /** The difference (or mean) of the two-sided t test (the `tTest` row). Default `0`. */
24
+ mu?: number;
25
+ /** `"raw"` (default): the bounds are in the units of the data; `"SMD"`: in units of the standardised difference. */
26
+ eqboundType?: "raw" | "SMD" | (string & {});
27
+ /** Hedges' small-sample correction J of the standardised difference (g instead of d). Default `true`. */
28
+ biasCorrection?: boolean;
29
+ /** Paired samples: standardise by the SD of the differences over sqrt(2(1 − r)) (d_rm). Default `false`. */
30
+ rmCorrection?: boolean;
31
+ /** `"glass1"` or `"glass2"`: Glass's delta, standardised by the SD of the first or second sample. */
32
+ glass?: "glass1" | "glass2" | (string & {});
33
+ /** Interval of the standardised difference: `"nct"` (default), `"goulet"`, `"t"` or `"z"`. */
34
+ smdCi?: "nct" | "goulet" | "t" | "z" | (string & {});
35
+ }
36
+ /**
37
+ * Summary statistics for {@link tsumTOST}. One sample: `m1`, `sd1`, `n1`; two samples: also `m2`, `sd2`, `n2`;
38
+ * paired samples (option `paired`): also `r12`, the correlation of the pairs.
39
+ *
40
+ * @category Hypothesis tests
41
+ */
42
+ export interface TsumTOSTStatistics {
43
+ /** Mean of the first sample. */
44
+ m1: number;
45
+ /** Standard deviation of the first sample. */
46
+ sd1: number;
47
+ /** Size of the first sample. */
48
+ n1: number;
49
+ /** Mean of the second sample. */
50
+ m2?: number;
51
+ /** Standard deviation of the second sample. */
52
+ sd2?: number;
53
+ /** Size of the second sample. */
54
+ n2?: number;
55
+ /** Paired samples: the correlation of the pairs. */
56
+ r12?: number;
57
+ }
58
+ /**
59
+ * One t test of {@link TTOSTResult}.
60
+ *
61
+ * @category Hypothesis tests
62
+ */
63
+ export interface TTOSTTest {
64
+ /** The t statistic. */
65
+ t: number;
66
+ /** Standard error of the difference (or mean). */
67
+ se: number;
68
+ /** Degrees of freedom. */
69
+ df: number;
70
+ /** p-value. */
71
+ pValue: number;
72
+ }
73
+ /**
74
+ * Result of {@link tTOST} and {@link tsumTOST}.
75
+ *
76
+ * @category Hypothesis tests
77
+ */
78
+ export interface TTOSTResult {
79
+ /** The two-sided t test of the difference against `mu` (TOSTER's "t-test" row). */
80
+ tTest: TTOSTTest;
81
+ /** The test of the lower bound: alternative "greater" (EQU) or "less" (MET). */
82
+ lower: TTOSTTest;
83
+ /** The test of the upper bound: alternative "less" (EQU) or "greater" (MET). */
84
+ upper: TTOSTTest;
85
+ /** The p-value of the TOST: the larger (EQU) or the smaller (MET) of the p-values of `lower` and `upper`. */
86
+ pValue: number;
87
+ /** The bounds `[low, high]` in the units of the data (`raw`) and of the standardised difference (`smd`). */
88
+ bounds: {
89
+ /** `[low, high]` in the units of the data. */
90
+ raw: [number, number];
91
+ /** `[low, high]` in the units of the standardised difference. */
92
+ smd: [number, number];
93
+ };
94
+ /** The raw effect, the difference minus `mu`: estimate, standard error and 1 − 2 alpha interval. */
95
+ raw: {
96
+ /** The difference minus `mu`. */
97
+ estimate: number;
98
+ /** Its standard error. */
99
+ se: number;
100
+ /** Its 1 − 2 alpha interval. */
101
+ confInt: [number, number];
102
+ };
103
+ /**
104
+ * The standardised mean difference: its label (`"Hedges's g(av)"`, `"Cohen's d"`, `"Hedges's g(z)"`, `"Glass's
105
+ * delta(g)"`, ...), estimate, standard error, 1 − 2 alpha interval, the degrees of freedom of its interval and the
106
+ * bias correction J (1 without it).
107
+ */
108
+ smd: {
109
+ /** The name of the standardised difference, such as `"Hedges's g(av)"`. */
110
+ label: string;
111
+ /** The estimate. */
112
+ estimate: number;
113
+ /** Its standard error. */
114
+ se: number;
115
+ /** Its 1 − 2 alpha interval. */
116
+ confInt: [number, number];
117
+ /** The degrees of freedom of the interval. */
118
+ df: number;
119
+ /** The bias correction J (1 without it). */
120
+ J: number;
121
+ };
122
+ /** `1 - 2 alpha`. */
123
+ confLevel: number;
124
+ /** The t test's method (`"Welch Two Sample t-test"`, `" Two Sample t-test"`, `"Paired t-test"`, `"One Sample t-test"`). */
125
+ method: string;
126
+ /** `"EQU"` or `"MET"`. */
127
+ hypothesis: "EQU" | "MET";
128
+ /** TOSTER's notes, as warnings. */
129
+ warnings: string[];
130
+ }
131
+ /**
132
+ * Two one-sided t tests (TOST) of equivalence, or minimal-effect tests, for one sample, two samples or paired samples,
133
+ * with the standardised mean difference and its interval. Equivalent to `TOSTER::t_TOST()` in R.
134
+ *
135
+ * With `hypothesis: "EQU"` (the default) equivalence, low < difference < high, is shown at level alpha when both the
136
+ * test of the lower bound (alternative "greater") and that of the upper bound (alternative "less") reject; the
137
+ * p-value is the larger of the two. With `"MET"` the alternatives are reversed and the p-value is the smaller. The
138
+ * effect is the difference minus `mu`: mean(x) - mean(y) - mu (two samples, Welch's or pooled), the mean of x - y
139
+ * minus mu (paired) or the mean of x minus mu (one sample). The bounds, the raw estimate and interval and the
140
+ * standardised difference all refer to that effect. The intervals are 1 - 2 alpha intervals (90% for the default alpha
141
+ * 0.05).
142
+ *
143
+ * The standardised difference is Hedges' g (Cohen's d without `biasCorrection`) with the average SD
144
+ * `sqrt((s1² + s2²)/2)` for Welch's test, the pooled SD with `varEqual`, the SD of the differences for paired samples
145
+ * (d_z, or d_rm with `rmCorrection`), the SD of one sample with `glass`, or the SD for one sample. Its interval is from
146
+ * the noncentral t (`"nct"`, as exact roots; TOSTER's optimiser is about 1e-9 accurate), Goulet-Pelletier and
147
+ * Cousineau's (`"goulet"`), or `g -+ q se` with a t or normal quantile (`"t"`, `"z"`).
148
+ *
149
+ * Differences from TOSTER (decisions 20-23 of oracle/methodcomparison-behaviour.md): `mu` is subtracted everywhere
150
+ * (TOSTER tests the bounds on the difference itself, gives the raw interval of the difference, the two-sample SMD of
151
+ * the difference plus mu and the paired SMD without mu); the one-sample `"t"` and `"z"` intervals of the standardised
152
+ * difference are 1 - 2 alpha intervals (TOSTER's 1 - alpha); TOSTER's notes are warnings; alpha must be in (0, 0.5).
153
+ * With `mu` 0 only the last three apply.
154
+ *
155
+ * With 2 observations (df 1) Hedges' correction J(1) is 0: the bias-corrected standardised difference is 0 (and its
156
+ * `"nct"` interval), and some of its standard errors and intervals are NaN or infinite, as TOSTER's formulas give.
157
+ *
158
+ * @param x Sample (NaN values are dropped; for paired samples, the pairs with a NaN).
159
+ * @param y Second sample (omit for one sample).
160
+ * @param options See {@link TTOSTOptions}; the bounds are required.
161
+ * @returns See {@link TTOSTResult}.
162
+ * @throws TypeError without bounds, for options of the wrong type, or for samples that are not arrays of numbers
163
+ * (`null` or strings in them); RangeError for infinite values, alpha outside (0, 0.5), bounds that are not finite or
164
+ * in the wrong order, an unknown choice, or fewer than 2 observations in a sample; Error where the t test has too
165
+ * few observations or the data are essentially constant.
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * const r = tTOST([5.1, 4.9, 5.6, 5.8, 6.0, 5.4, 5.2, 6.1], [5.3, 5.0, 5.5, 5.7, 5.9, 5.2, 4.8, 5.6, 5.0], { eqb: 0.5 });
170
+ * r.pValue; // 0.06280707532313813
171
+ * r.raw.confInt; // [-0.16777332363212605, 0.5261066569654603] (90%)
172
+ * r.smd.label; // "Hedges's g(av)"
173
+ * ```
174
+ *
175
+ * @category Hypothesis tests
176
+ */
177
+ export declare function tTOST(x: Sample, y?: Sample, options?: TTOSTOptions): TTOSTResult;
178
+ /**
179
+ * {@link tTOST} from summary statistics: means, standard deviations, sample sizes and, for paired samples, the
180
+ * correlation of the pairs. Equivalent to `TOSTER::tsum_TOST()` in R.
181
+ *
182
+ * The tests and effect sizes are those of tTOST for data with these summaries (Welch's or pooled for two samples;
183
+ * paired from the SD of the differences sqrt(sd1² + sd2² - 2 r12 sd1 sd2)). The one-sided p-values are upper tails
184
+ * where TOSTER takes `1 - pt(t, df)`, so small ones keep their digits. For paired samples with n1 != n2 the smaller
185
+ * is used, with TOSTER's warning `Unequal number of pairs; using smallest n`.
186
+ *
187
+ * @param stats See {@link TsumTOSTStatistics}.
188
+ * @param options See {@link TTOSTOptions}; the bounds are required.
189
+ * @returns See {@link TTOSTResult}.
190
+ * @throws RangeError for sizes below 2 (or not integers), standard deviations that are not positive, a correlation
191
+ * outside (-1, 1), missing statistics of the second sample, or the errors of {@link tTOST}'s options.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * const r = tsumTOST({ m1: 5.5125, sd1: 0.4357, n1: 8, m2: 5.3333, sd2: 0.3536, n2: 9 }, { eqb: 0.5 });
196
+ * r.pValue; // 0.060568376615229305
197
+ * r.smd.confInt; // [-0.35185844793775967, 1.1906849789772087]
198
+ * ```
199
+ *
200
+ * @category Hypothesis tests
201
+ */
202
+ export declare function tsumTOST(stats: TsumTOSTStatistics, options?: TTOSTOptions): TTOSTResult;