@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.
Files changed (97) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/README.ja.md +33 -15
  3. package/README.md +32 -14
  4. package/dist/chunks/{chunk-4KCSBTR5.js → chunk-2VZW4XPK.js} +2 -2
  5. package/dist/chunks/chunk-4OOTEXZU.js +2 -0
  6. package/dist/chunks/{chunk-Z2HGLFZN.js → chunk-6TZVS6WC.js} +2 -2
  7. package/dist/chunks/{chunk-U7BRXOUS.js → chunk-6X2ZMPF5.js} +2 -2
  8. package/dist/chunks/{chunk-GJEKNJP7.js → chunk-AJZV2SVY.js} +2 -2
  9. package/dist/chunks/{chunk-GRUQRNX7.js → chunk-BNTBZ5W3.js} +3 -3
  10. package/dist/chunks/{chunk-DR4GQ7PW.js → chunk-EBRTF7RM.js} +1 -1
  11. package/dist/chunks/{chunk-OG7UORIX.js → chunk-FFNHG5SB.js} +1 -1
  12. package/dist/chunks/{chunk-N5BDSMXS.js → chunk-GUM57VVM.js} +1 -1
  13. package/dist/chunks/{chunk-GGJA3JRO.js → chunk-HBRSUHSU.js} +2 -2
  14. package/dist/chunks/{chunk-HRA7PCQT.js → chunk-I5NWGQOQ.js} +2 -2
  15. package/dist/chunks/chunk-IJV43Y7Q.js +2 -0
  16. package/dist/chunks/{chunk-YN5MLKDL.js → chunk-IOGQEMDE.js} +2 -2
  17. package/dist/chunks/{chunk-GYGQUYEP.js → chunk-JJRZ2TTF.js} +2 -2
  18. package/dist/chunks/{chunk-X4J6UJHN.js → chunk-LA4H6ZSC.js} +2 -2
  19. package/dist/chunks/{chunk-DTJG2IL2.js → chunk-LMNU4NHZ.js} +2 -2
  20. package/dist/chunks/{chunk-4VRMAYPY.js → chunk-LNUNKFIH.js} +3 -3
  21. package/dist/chunks/chunk-MJXETGT2.js +2 -0
  22. package/dist/chunks/chunk-P7ZHH2SF.js +2 -0
  23. package/dist/chunks/{chunk-HUWOSLKE.js → chunk-PDHBRDTF.js} +2 -2
  24. package/dist/chunks/{chunk-7KJ24LYK.js → chunk-RCGW2DCK.js} +2 -2
  25. package/dist/chunks/{chunk-QUTJEYDX.js → chunk-TZTVDVP4.js} +2 -2
  26. package/dist/chunks/{chunk-HZLSNJQM.js → chunk-UJYRU37Z.js} +2 -2
  27. package/dist/chunks/{chunk-EJYCDE4Z.js → chunk-UMDXXT3M.js} +1 -1
  28. package/dist/chunks/{chunk-7IJCUSA5.js → chunk-UOAFEB64.js} +2 -2
  29. package/dist/chunks/{chunk-JNWWLNE3.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 +14 -0
  33. package/dist/entries/tests.js +14 -0
  34. package/dist/htest/agreement.d.ts +2 -2
  35. package/dist/htest/binomCI.d.ts +116 -0
  36. package/dist/htest/binomCI.js +252 -0
  37. package/dist/htest/blandAltman.d.ts +100 -0
  38. package/dist/htest/blandAltman.js +159 -0
  39. package/dist/htest/boschlooTest.d.ts +65 -0
  40. package/dist/htest/boschlooTest.js +394 -0
  41. package/dist/htest/chisqTest.d.ts +19 -0
  42. package/dist/htest/chisqTest.js +30 -2
  43. package/dist/htest/core/twoProportions.d.ts +48 -0
  44. package/dist/htest/core/twoProportions.js +476 -0
  45. package/dist/htest/diagnosticTests.d.ts +91 -0
  46. package/dist/htest/diagnosticTests.js +116 -0
  47. package/dist/htest/equivalence.d.ts +172 -0
  48. package/dist/htest/equivalence.js +189 -0
  49. package/dist/htest/fisherTest.d.ts +49 -0
  50. package/dist/htest/fisherTest.js +136 -13
  51. package/dist/htest/iccPsych.d.ts +106 -0
  52. package/dist/htest/iccPsych.js +332 -0
  53. package/dist/htest/ksTest.d.ts +1 -1
  54. package/dist/htest/mcreg.d.ts +209 -0
  55. package/dist/htest/mcreg.js +735 -0
  56. package/dist/htest/roc.d.ts +287 -0
  57. package/dist/htest/roc.js +635 -0
  58. package/dist/htest/rocTest.d.ts +139 -0
  59. package/dist/htest/rocTest.js +444 -0
  60. package/dist/htest/tTOST.d.ts +202 -0
  61. package/dist/htest/tTOST.js +558 -0
  62. package/dist/htest/tableTests.d.ts +216 -0
  63. package/dist/htest/tableTests.js +650 -0
  64. package/dist/htest/trendTests.d.ts +1 -1
  65. package/dist/htest/trendTests.js +1 -1
  66. package/dist/htest/twoByTwo.d.ts +203 -0
  67. package/dist/htest/twoByTwo.js +385 -0
  68. package/dist/internal/summary.js +5 -0
  69. package/dist/linalg/qr.d.ts +3 -0
  70. package/dist/linalg/qr.js +3 -0
  71. package/dist/linalg.js +2 -2
  72. package/dist/mixed.js +2 -2
  73. package/dist/models/coeftest.d.ts +139 -0
  74. package/dist/models/coeftest.js +237 -0
  75. package/dist/models/coxph.d.ts +60 -9
  76. package/dist/models/coxph.js +367 -38
  77. package/dist/models/glm.d.ts +11 -1
  78. package/dist/models/glm.js +19 -2
  79. package/dist/models/inputRows.d.ts +10 -0
  80. package/dist/models/inputRows.js +23 -0
  81. package/dist/models/lm.d.ts +8 -0
  82. package/dist/models/lm.js +14 -2
  83. package/dist/models/sandwich.d.ts +177 -0
  84. package/dist/models/sandwich.js +923 -0
  85. package/dist/numerics.js +2 -2
  86. package/dist/random/rng.d.ts +8 -1
  87. package/dist/random/rng.js +14 -1
  88. package/dist/rstats.js +16 -16
  89. package/dist/special/igam.js +140 -23
  90. package/dist/special/loader.js +8 -0
  91. package/dist/special.js +2 -2
  92. package/dist/tests.js +13 -13
  93. package/llms.txt +25 -0
  94. package/package.json +1 -1
  95. package/dist/chunks/chunk-NDTJ23A6.js +0 -2
  96. package/dist/chunks/chunk-UMLMY4XS.js +0 -2
  97. package/dist/chunks/chunk-Y4YWLSWU.js +0 -2
@@ -0,0 +1,209 @@
1
+ import type { Sample } from "./types.js";
2
+ /**
3
+ * Regression methods of {@link mcreg}.
4
+ *
5
+ * @category Agreement, reliability and factor analysis
6
+ */
7
+ export type McregMethod = "PaBa" | "Deming" | "WDeming";
8
+ /**
9
+ * Interval methods of {@link mcreg}.
10
+ *
11
+ * @category Agreement, reliability and factor analysis
12
+ */
13
+ export type McregCiMethod = "analytical" | "jackknife" | "bootstrap" | "nestedbootstrap";
14
+ /**
15
+ * Bootstrap intervals of {@link mcreg}.
16
+ *
17
+ * @category Agreement, reliability and factor analysis
18
+ */
19
+ export type McregBootstrapCiMethod = "quantile" | "Student" | "BCa" | "tBoot";
20
+ /**
21
+ * Options for {@link mcreg}.
22
+ *
23
+ * @category Agreement, reliability and factor analysis
24
+ */
25
+ export interface McregOptions {
26
+ /**
27
+ * `"PaBa"` (Passing-Bablok, the default, as mcr), `"Deming"` or `"WDeming"` (weighted Deming, constant coefficient
28
+ * of variation). Unambiguous abbreviations are accepted.
29
+ */
30
+ methodReg?: McregMethod | (string & {});
31
+ /**
32
+ * `"analytical"` (the default for Deming and Passing-Bablok; not available for weighted Deming), `"jackknife"` (the
33
+ * default for weighted Deming), `"bootstrap"` or `"nestedbootstrap"`. mcr's default is `"bootstrap"`.
34
+ */
35
+ methodCi?: McregCiMethod | (string & {});
36
+ /**
37
+ * The bootstrap interval: `"quantile"` (the default), `"Student"`, `"BCa"` or `"tBoot"` (bootstrap-t: with Deming
38
+ * or with nested resamples).
39
+ */
40
+ methodBootstrapCi?: McregBootstrapCiMethod | (string & {});
41
+ /**
42
+ * The ratio of the error variances σ²(x)/σ²(y), x the reference method (mcr's `error.ratio`; Deming and weighted
43
+ * Deming), positive and finite. Default `1`.
44
+ */
45
+ errorRatio?: number;
46
+ /** Level of the intervals, in (0, 1) (mcr's `1 - alpha`). Default `0.95`. */
47
+ confLevel?: number;
48
+ /** Passing-Bablok: the mean of two middle slopes as `"radian"` (tan of the mean angle, the default) or `"tangent"`. */
49
+ slopeMeasure?: "radian" | "tangent" | (string & {});
50
+ /** Number of bootstrap resamples, a positive integer. Default `999`. */
51
+ nsamples?: number;
52
+ /** Number of inner resamples of each resample for `"nestedbootstrap"`, a positive integer. Default `25`. */
53
+ nnested?: number;
54
+ /**
55
+ * Seed of the resamples: the stream of R's `set.seed(rngSeed, kind = "Mersenne-Twister")`, as mcr's `rng.seed`; the
56
+ * state of the generator is restored afterwards if it had one (in a session that never drew a random number, the
57
+ * stream of the seed continues, as in R). Without it the resamples are drawn from the current stream.
58
+ */
59
+ rngSeed?: number;
60
+ /** Weighted Deming: the largest number of iterations, a positive integer. Default `30`. */
61
+ iterMax?: number;
62
+ /** Weighted Deming: the iteration stops when both coefficients change by less than this (absolute). Default `1e-6`. */
63
+ threshold?: number;
64
+ /** Drop the pairs with `NaN` (otherwise they are an error). Default `false`. */
65
+ naRm?: boolean;
66
+ }
67
+ /**
68
+ * A coefficient of {@link McregResult}.
69
+ *
70
+ * @category Agreement, reliability and factor analysis
71
+ */
72
+ export interface McregCoefficient {
73
+ /** The estimate from all the data. */
74
+ estimate: number;
75
+ /** Its standard error (`NaN` where the method has none: Passing-Bablok analytical, bootstrap quantile and BCa). */
76
+ se: number;
77
+ /** The interval at `confLevel`. */
78
+ confInt: [number, number];
79
+ }
80
+ /**
81
+ * Result of {@link mcreg}.
82
+ *
83
+ * @category Agreement, reliability and factor analysis
84
+ */
85
+ export interface McregResult {
86
+ /** The regression method, in full. */
87
+ methodReg: McregMethod;
88
+ /** The interval method, in full. */
89
+ methodCi: McregCiMethod;
90
+ /** The bootstrap interval, in full (bootstrap methods only). */
91
+ methodBootstrapCi?: McregBootstrapCiMethod;
92
+ /** The level of the intervals. */
93
+ confLevel: number;
94
+ /** The ratio of the error variances used (1 for Passing-Bablok). */
95
+ errorRatio: number;
96
+ /** Number of pairs used. */
97
+ n: number;
98
+ /** The intercept (mcr's row `Intercept` of `@para`). */
99
+ intercept: McregCoefficient;
100
+ /** The slope (mcr's row `Slope` of `@para`). */
101
+ slope: McregCoefficient;
102
+ /** The mean of x (Deming), the weighted mean of the last iteration (weighted Deming), `NaN` (Passing-Bablok). */
103
+ xmean: number;
104
+ /** Weighted Deming: the weights of the last iteration (mcr's `@weight`); Infinity where beyond the double range. */
105
+ weights?: number[];
106
+ /** Jackknife: the leave-one-out coefficients (mcr's `@B0jack`, `@B1jack`; also for the BCa interval). */
107
+ jackknife?: {
108
+ /** The intercepts with each point left out (mcr's `@B0jack`). */
109
+ intercept: number[];
110
+ /** The slopes with each point left out (mcr's `@B1jack`). */
111
+ slope: number[];
112
+ };
113
+ /**
114
+ * Bootstrap: the coefficients of the resamples kept, in the order drawn (mcr's `@B0`, `@B1`), their standard errors
115
+ * (`@sigmaB0`, `@sigmaB1`: the standard deviation of the nested estimates, the analytical standard error for Deming,
116
+ * the jackknife one for weighted Deming with BCa, else `NaN`), the global standard errors (`@glob.sigma`) and the
117
+ * number of resamples kept.
118
+ */
119
+ bootstrap?: {
120
+ /** The intercepts of the resamples kept, in the order drawn (mcr's `@B0`). */
121
+ intercept: number[];
122
+ /** The slopes of the resamples kept (mcr's `@B1`). */
123
+ slope: number[];
124
+ /** The standard errors of the intercepts (mcr's `@sigmaB0`). */
125
+ sigmaIntercept: number[];
126
+ /** The standard errors of the slopes (mcr's `@sigmaB1`). */
127
+ sigmaSlope: number[];
128
+ /** The global standard errors of the intercept and the slope (mcr's `@glob.sigma`). */
129
+ globalSigma: [number, number];
130
+ /** The number of resamples kept. */
131
+ nsamples: number;
132
+ };
133
+ /**
134
+ * Passing-Bablok: the linearity statistic (mcr's `calcCUSUM`): the numbers of points above and below the line and
135
+ * the largest absolute cumulative sum of their scores ordered along the line.
136
+ */
137
+ cusum?: {
138
+ /** The number of points above the line. */
139
+ nPos: number;
140
+ /** The number of points below the line. */
141
+ nNeg: number;
142
+ /** The largest absolute cumulative sum of the scores ordered along the line. */
143
+ maxCusum: number;
144
+ };
145
+ /** Warnings (the weighted Deming iteration not converging, degenerate resamples, an undefined interval). */
146
+ warnings: string[];
147
+ }
148
+ /**
149
+ * Method comparison regression of y (test method) on x (reference method): Deming, weighted Deming or Passing-Bablok
150
+ * regression with analytical, jackknife or bootstrap intervals. Equivalent to `mcr::mcreg()` in R.
151
+ *
152
+ * - **Deming** (`"Deming"`): the slope minimises the squared distances in the metric of the error variances, λ =
153
+ * `errorRatio` = σ²(x)/σ²(y) (mcr's convention; λ → 0 gives the least-squares slope of y on x). The analytical
154
+ * standard errors are Strike's (1991), with t intervals on n - 2 degrees of freedom.
155
+ * - **Weighted Deming** (`"WDeming"`): Linnet's (1990) iteration for errors proportional to the level (constant
156
+ * coefficient of variation), stopped as mcr when both coefficients change by less than `threshold` (absolute), with
157
+ * a warning when `iterMax` iterations are reached. No analytical interval (jackknife by default). Values must be
158
+ * positive. Since the threshold is absolute, data of very large magnitude (around 1e150) may not converge and
159
+ * data of very small magnitude (around 1e-150) stop after the first iteration; choose `threshold` in the units of
160
+ * the data.
161
+ * - **Passing-Bablok** (`"PaBa"`): the shifted median of the n(n - 1)/2 pairwise slopes and the rank interval of
162
+ * Passing and Bablok (1983); the intercept is the median of y - b x and its limits those of the slope's limits.
163
+ * Differences below a relative 1e-12 count as ties (mcr's rule; a pair tied in x only is vertical), so data with a
164
+ * large offset (1e12 + O(1)) have most differences set to 0; the mean of two middle slopes is tan of the mean angle
165
+ * (`slopeMeasure: "radian"`, mcr's default; it changes when y is rescaled, as angles do not scale) or the mean slope
166
+ * (`"tangent"`). Where the interval is not defined (too few points, always for n <= 4) its limits and the
167
+ * intercept's are -Infinity and Infinity, with a warning. Values must not be negative. The result has the CUSUM
168
+ * statistic of linearity (`cusum`; no test decision).
169
+ * - **jackknife**: the leave-one-out estimates, the standard error sd(pseudo-values)/sqrt(n) and the interval estimate
170
+ * ± t se on n - 2 degrees of freedom (Linnet 1993); the estimates are those of all the data.
171
+ * - **bootstrap**: `nsamples` resamples of the pairs with replacement; `"quantile"` the percentile interval,
172
+ * `"Student"` estimate ± t sd(B), `"BCa"` the bias-corrected and accelerated interval (jackknife acceleration),
173
+ * `"tBoot"` the bootstrap-t interval with the analytical standard errors (Deming) or, with `"nestedbootstrap"`, the
174
+ * standard deviation of `nnested` inner resamples of each resample. Resamples with constant x or y are dropped
175
+ * with mcr's warning (an error when more than 5% are). The resamples are drawn as R's `sample(1:n, n, replace =
176
+ * TRUE)` from the current random stream, or from `set.seed(rngSeed)` as mcr's `rng.seed` (the generator's state is
177
+ * then restored if it had one), so the values are mcr's for the same seed. With very few points (n = 5) the
178
+ * bootstrap-t limits can be infinite or huge, because resamples of 2 or 3 distinct points have standard errors 0.
179
+ *
180
+ * Unlike mcr, the default interval is `"analytical"` (`"jackknife"` for weighted Deming) rather than a random
181
+ * bootstrap; `confLevel` replaces mcr's `alpha` (= 1 - confLevel); 2 or fewer points, constant x or y, infinite
182
+ * values and data whose Deming covariance is 0 are errors. Passing-Bablok's odd-position slopes are dy/dx (mcr: tan of
183
+ * its angle, a few ulps off). PaBaLarge, LinReg, WLinReg, PBequi and TS are not offered.
184
+ *
185
+ * @param x Measurements by the reference method.
186
+ * @param y Measurements by the test method, paired with `x`.
187
+ * @param options See {@link McregOptions}.
188
+ * @returns See {@link McregResult}.
189
+ * @throws TypeError if `x` and `y` differ in length; RangeError for missing values without `naRm`, infinite values,
190
+ * fewer than 3 pairs, constant x or y, negative values (Passing-Bablok), values that are not positive (weighted
191
+ * Deming), more than 5793 points (Passing-Bablok), an analytical interval for weighted Deming, a bootstrap-t
192
+ * interval without nested resamples for Passing-Bablok or weighted Deming, too many degenerate resamples, a zero
193
+ * covariance (Deming), or an invalid option.
194
+ *
195
+ * @example
196
+ * ```ts
197
+ * const x = [1, 2, 3, 4, 5, 6, 7];
198
+ * const y = [1.2, 1.9, 3.2, 3.8, 5.1, 6.4, 6.6];
199
+ * const d = mcreg(x, y, { methodReg: "Deming" });
200
+ * d.slope.estimate; // 0.97547950725034482
201
+ * d.slope.confInt; // [0.83267195599246846, 1.1182870585082212]
202
+ * const pb = mcreg(x, y); // Passing-Bablok
203
+ * pb.slope.estimate; // 0.95
204
+ * pb.intercept.confInt; // [-0.8524794459077718, 0.80365513709218339]
205
+ * ```
206
+ *
207
+ * @category Agreement, reliability and factor analysis
208
+ */
209
+ export declare function mcreg(x: Sample, y: Sample, options?: McregOptions): McregResult;