@numero-uno-jpn/rstats 1.6.0 → 1.7.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 +15 -0
- package/README.ja.md +11 -9
- package/README.md +12 -9
- package/dist/chunks/chunk-56AMJQ27.js +2 -0
- package/dist/chunks/{chunk-O5CMNUJL.js → chunk-76FLTZVF.js} +2 -2
- package/dist/chunks/chunk-AIEPW6DX.js +2 -0
- package/dist/chunks/chunk-B6KJ4RWG.js +2 -0
- package/dist/chunks/{chunk-2TVHT4PF.js → chunk-B7XZMIQO.js} +2 -2
- package/dist/chunks/chunk-BJMPSDJ7.js +2 -0
- package/dist/chunks/chunk-CB7STL5Z.js +2 -0
- package/dist/chunks/{chunk-ZL7EAPO5.js → chunk-CUT3IHMY.js} +1 -1
- package/dist/chunks/{chunk-FLITCXLY.js → chunk-CZUOG2U5.js} +2 -2
- package/dist/chunks/chunk-FQRNZEH2.js +2 -0
- package/dist/chunks/{chunk-BMEO5X5F.js → chunk-HORF36FD.js} +2 -2
- package/dist/chunks/{chunk-OZLDZOOA.js → chunk-HSJ4OT3H.js} +1 -1
- package/dist/chunks/chunk-J7ZVV4DN.js +2 -0
- package/dist/chunks/{chunk-RSTU6CX7.js → chunk-JXEXOD7K.js} +2 -2
- package/dist/chunks/chunk-KSH43GX4.js +2 -0
- package/dist/chunks/chunk-LMRCFKVK.js +2 -0
- package/dist/chunks/{chunk-2I7Z7L5J.js → chunk-MOJ2KIQE.js} +2 -2
- package/dist/chunks/{chunk-F7G74UNI.js → chunk-PCTRVBEJ.js} +2 -2
- package/dist/chunks/chunk-PLQQ4VFN.js +2 -0
- package/dist/chunks/{chunk-ABSUQPOG.js → chunk-QWDK3ZC2.js} +2 -2
- package/dist/chunks/chunk-R5BMFVIH.js +2 -0
- package/dist/chunks/chunk-R7F7ELS7.js +3 -0
- package/dist/chunks/{chunk-3PCHPKBD.js → chunk-RIP2RKAW.js} +2 -2
- package/dist/chunks/chunk-RX6MZO2Y.js +2 -0
- package/dist/chunks/{chunk-Z2XN4NN7.js → chunk-SDT3YHAG.js} +2 -2
- package/dist/chunks/{chunk-WAMHZ47G.js → chunk-THSV22QF.js} +2 -2
- package/dist/chunks/{chunk-7ZNFRZO4.js → chunk-TY3IFCLI.js} +2 -2
- package/dist/chunks/{chunk-SFZF44G6.js → chunk-V2Y2W7LE.js} +2 -2
- package/dist/chunks/{chunk-AHFMBHZW.js → chunk-VALULDEX.js} +1 -1
- package/dist/chunks/chunk-VQOU7U7R.js +2 -0
- package/dist/chunks/{chunk-KAAUNR3G.js → chunk-YKNRDPIB.js} +1 -1
- package/dist/chunks/chunk-YVJ4LDDE.js +2 -0
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/regression.d.ts +3 -0
- package/dist/entries/regression.js +6 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/nls.d.ts +286 -0
- package/dist/models/nls.js +1007 -0
- package/dist/models/nlsFormula.d.ts +37 -0
- package/dist/models/nlsFormula.js +295 -0
- package/dist/models/polr.d.ts +341 -0
- package/dist/models/polr.js +1028 -0
- package/dist/models/rlm.d.ts +282 -0
- package/dist/models/rlm.js +766 -0
- package/dist/numerics.js +2 -2
- package/dist/regression.js +3 -0
- package/dist/rstats.js +1 -1
- package/dist/special.js +2 -2
- package/dist/tests.js +14 -14
- package/llms.txt +5 -1
- package/package.json +6 -1
- package/dist/chunks/chunk-55XSRONZ.js +0 -3
- package/dist/chunks/chunk-5AITXV3T.js +0 -2
- package/dist/chunks/chunk-BJTGQ52J.js +0 -2
- package/dist/chunks/chunk-KND2BFD5.js +0 -2
- package/dist/chunks/chunk-N2PNW4HR.js +0 -2
- package/dist/chunks/chunk-NVIJXWS6.js +0 -2
- package/dist/chunks/chunk-TPBVVP32.js +0 -2
- package/dist/chunks/chunk-XNWSQVXS.js +0 -2
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import type { DataFrame } from "./modelFrame.js";
|
|
2
|
+
import type { Sample } from "../htest/types.js";
|
|
3
|
+
/** The score function used by robust regression.
|
|
4
|
+
*
|
|
5
|
+
* @category Regression
|
|
6
|
+
*/
|
|
7
|
+
export type RlmPsi = "huber" | "hampel" | "bisquare";
|
|
8
|
+
/** Options shared by the psi functions.
|
|
9
|
+
*
|
|
10
|
+
* @category Regression
|
|
11
|
+
*/
|
|
12
|
+
export interface RlmPsiHuberOptions {
|
|
13
|
+
/** Return the derivative of psi instead of psi(u)/u. Default 0. */
|
|
14
|
+
deriv?: 0 | 1;
|
|
15
|
+
/** Huber tuning constant. Default 1.345. */
|
|
16
|
+
k?: number;
|
|
17
|
+
}
|
|
18
|
+
/** Options for the Hampel psi function.
|
|
19
|
+
*
|
|
20
|
+
* @category Regression
|
|
21
|
+
*/
|
|
22
|
+
export interface RlmPsiHampelOptions {
|
|
23
|
+
/** Return the derivative of psi instead of psi(u)/u. Default 0. */
|
|
24
|
+
deriv?: 0 | 1;
|
|
25
|
+
/** First corner. Default 2. */
|
|
26
|
+
a?: number;
|
|
27
|
+
/** Second corner. Default 4. */
|
|
28
|
+
b?: number;
|
|
29
|
+
/** Rejection point. Default 8. */
|
|
30
|
+
c?: number;
|
|
31
|
+
}
|
|
32
|
+
/** Options for the bisquare psi function.
|
|
33
|
+
*
|
|
34
|
+
* @category Regression
|
|
35
|
+
*/
|
|
36
|
+
export interface RlmPsiBisquareOptions {
|
|
37
|
+
/** Return the derivative of psi instead of psi(u)/u. Default 0. */
|
|
38
|
+
deriv?: 0 | 1;
|
|
39
|
+
/** Tuning constant. Default 4.685. */
|
|
40
|
+
c?: number;
|
|
41
|
+
}
|
|
42
|
+
/** Scalar output returned by a robust score function.
|
|
43
|
+
*
|
|
44
|
+
* @category Regression
|
|
45
|
+
*/
|
|
46
|
+
export type PsiOutput = number | boolean;
|
|
47
|
+
/** Scalar or vector input accepted by the robust score functions.
|
|
48
|
+
*
|
|
49
|
+
* @category Regression
|
|
50
|
+
*/
|
|
51
|
+
export type PsiInput = number | Sample;
|
|
52
|
+
/** Scalar or vector output returned by the robust score functions.
|
|
53
|
+
*
|
|
54
|
+
* @category Regression
|
|
55
|
+
*/
|
|
56
|
+
export type PsiResult = PsiOutput | PsiOutput[];
|
|
57
|
+
/** Huber's psi function. Equivalent to R's `MASS::psi.huber()`.
|
|
58
|
+
*
|
|
59
|
+
* @param u Standardised residuals.
|
|
60
|
+
* @param options Tuning constant and output selection.
|
|
61
|
+
* @returns The IRLS weight psi(u)/u, or psi'(u) when deriv is 1.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* psiHuber([-2, 0, 1, 2]); // [0.6725, 1, 1, 0.6725]
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @category Regression
|
|
69
|
+
*/
|
|
70
|
+
export declare function psiHuber(u: PsiInput, options?: RlmPsiHuberOptions): PsiResult;
|
|
71
|
+
/** Hampel's three-part psi function. Equivalent to R's `MASS::psi.hampel()`.
|
|
72
|
+
*
|
|
73
|
+
* @param u Standardised residuals.
|
|
74
|
+
* @param options Three tuning points and output selection.
|
|
75
|
+
* @returns The IRLS weight psi(u)/u, or psi'(u) when deriv is 1.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* psiHampel([-5, -2, 0, 5, 9]); // [0.3, 1, 1, 0.3, 0]
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @category Regression
|
|
83
|
+
*/
|
|
84
|
+
export declare function psiHampel(u: PsiInput, options?: RlmPsiHampelOptions): number | number[];
|
|
85
|
+
/** Tukey's bisquare psi function. Equivalent to R's `MASS::psi.bisquare()`.
|
|
86
|
+
*
|
|
87
|
+
* @param u Standardised residuals.
|
|
88
|
+
* @param options Tuning constant and output selection.
|
|
89
|
+
* @returns The IRLS weight psi(u)/u, or psi'(u) when deriv is 1.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* psiBisquare([-5, 0, 2]); // [0, 1, 0.668733411888633]
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @category Regression
|
|
97
|
+
*/
|
|
98
|
+
export declare function psiBisquare(u: PsiInput, options?: RlmPsiBisquareOptions): number | number[];
|
|
99
|
+
/** Options for `rlm`.
|
|
100
|
+
*
|
|
101
|
+
* @category Regression
|
|
102
|
+
*/
|
|
103
|
+
export interface RlmOptions {
|
|
104
|
+
/** Estimation method. "MM" uses a deterministic S start and a fixed-scale redescending M step. Default "M". */
|
|
105
|
+
method?: "M" | "MM";
|
|
106
|
+
/** Score function. Default "huber". */
|
|
107
|
+
psi?: RlmPsi;
|
|
108
|
+
/** Scale estimator. "Huber" and "proposal 2" are equivalent. Default "MAD". */
|
|
109
|
+
scaleEst?: "MAD" | "Huber" | "proposal 2";
|
|
110
|
+
/** Least-squares start, deterministic LTS start, or initial coefficients. Default "ls". */
|
|
111
|
+
init?: "ls" | "lts" | Sample;
|
|
112
|
+
/** Non-negative observation weights, or a column name. */
|
|
113
|
+
weights?: Sample | string;
|
|
114
|
+
/** Meaning of weights. "inv" uses inverse-variance weights; "case" uses frequency weights. */
|
|
115
|
+
wtMethod?: "inv" | "case";
|
|
116
|
+
/** Huber tuning constant. Default 1.345. */
|
|
117
|
+
k?: number;
|
|
118
|
+
/** Hampel first corner. Default 2. */
|
|
119
|
+
a?: number;
|
|
120
|
+
/** Hampel second corner. Default 4. */
|
|
121
|
+
b?: number;
|
|
122
|
+
/** Hampel rejection point or bisquare tuning constant. Default 8 or 4.685. */
|
|
123
|
+
c?: number;
|
|
124
|
+
/** Proposal 2 scale tuning constant. Default 1.345. */
|
|
125
|
+
k2?: number;
|
|
126
|
+
/** Maximum number of IRLS iterations. Default 1000, allowing the estimating equations to reach their solution. */
|
|
127
|
+
maxit?: number;
|
|
128
|
+
/** Dimensionless estimating-equation and scale fixed-point tolerance. Default 1e-10. */
|
|
129
|
+
acc?: number;
|
|
130
|
+
}
|
|
131
|
+
/** Data and settings retained by an M fit.
|
|
132
|
+
*
|
|
133
|
+
* @category Regression
|
|
134
|
+
*/
|
|
135
|
+
export interface RlmModel {
|
|
136
|
+
/** Original model formula. */
|
|
137
|
+
formula: string;
|
|
138
|
+
/** Retained design matrix. */
|
|
139
|
+
x: number[][];
|
|
140
|
+
/** Retained response values. */
|
|
141
|
+
y: number[];
|
|
142
|
+
/** Names of design-matrix columns. */
|
|
143
|
+
columnNames: string[];
|
|
144
|
+
/** Prior observation weights. */
|
|
145
|
+
observationWeights: number[];
|
|
146
|
+
/** Interpretation of the observation weights. */
|
|
147
|
+
wtMethod: "inv" | "case";
|
|
148
|
+
/** Robust score function. */
|
|
149
|
+
psi: RlmPsi;
|
|
150
|
+
/** Residual scale estimator. */
|
|
151
|
+
scaleEst: "MAD" | "Huber" | "proposal 2";
|
|
152
|
+
/** Huber tuning constant. */
|
|
153
|
+
k: number;
|
|
154
|
+
/** Hampel first tuning point. */
|
|
155
|
+
a: number;
|
|
156
|
+
/** Hampel second tuning point. */
|
|
157
|
+
b: number;
|
|
158
|
+
/** Hampel rejection point or bisquare tuning constant. */
|
|
159
|
+
c: number;
|
|
160
|
+
/** Proposal 2 scale tuning constant. */
|
|
161
|
+
k2: number;
|
|
162
|
+
/** Original row indices retained after missing-value handling. */
|
|
163
|
+
rows: number[];
|
|
164
|
+
}
|
|
165
|
+
/** Result of `rlm`: robust coefficients, fitted values, scale and convergence diagnostics.
|
|
166
|
+
*
|
|
167
|
+
* @category Regression
|
|
168
|
+
*/
|
|
169
|
+
export interface RlmResult {
|
|
170
|
+
/** Named robust regression coefficients. */
|
|
171
|
+
coefficients: Record<string, number>;
|
|
172
|
+
/** Fitted response values. */
|
|
173
|
+
fittedValues: number[];
|
|
174
|
+
/** Observed minus fitted response values. */
|
|
175
|
+
residuals: number[];
|
|
176
|
+
/** Robust weights from the selected score function. */
|
|
177
|
+
robustWeights: number[];
|
|
178
|
+
/** Combined weights used in weighted least-squares steps. */
|
|
179
|
+
workingWeights: number[];
|
|
180
|
+
/** Estimated robust residual scale. */
|
|
181
|
+
scale: number;
|
|
182
|
+
/** Residual standard deviation estimate. */
|
|
183
|
+
stddev: number;
|
|
184
|
+
/** Estimated coefficient covariance matrix. */
|
|
185
|
+
covariance: number[][];
|
|
186
|
+
/** Unscaled coefficient covariance matrix. */
|
|
187
|
+
covarianceUnscaled: number[][];
|
|
188
|
+
/** Whether the estimating equations and scale iteration converged. */
|
|
189
|
+
converged: boolean;
|
|
190
|
+
/** Number of iterations performed. */
|
|
191
|
+
iterations: number;
|
|
192
|
+
/** Convergence diagnostics for the estimating equations and scale. */
|
|
193
|
+
convergence: number[];
|
|
194
|
+
/** Warnings produced during fitting. */
|
|
195
|
+
warnings: string[];
|
|
196
|
+
/** Model data and settings retained for companion methods. */
|
|
197
|
+
model: RlmModel;
|
|
198
|
+
/** Details of the deterministic high-breakdown initial estimate. */
|
|
199
|
+
initialization?: {
|
|
200
|
+
/** Initial estimator used before the M step. */
|
|
201
|
+
method: "LTS" | "S";
|
|
202
|
+
/** Named coefficients from the initial estimate. */
|
|
203
|
+
coefficients: Record<string, number>;
|
|
204
|
+
/** Objective value of the selected initial estimate. */
|
|
205
|
+
objective: number;
|
|
206
|
+
/** Number of candidate subsets evaluated. */
|
|
207
|
+
candidatesEvaluated: number;
|
|
208
|
+
/** Total number of candidate subsets, as a decimal string. */
|
|
209
|
+
candidateCount: string;
|
|
210
|
+
/** Whether every candidate subset was evaluated. */
|
|
211
|
+
exhaustive: boolean;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/** Coefficient table returned by {@link rlmSummary}.
|
|
215
|
+
*
|
|
216
|
+
* @category Regression
|
|
217
|
+
*/
|
|
218
|
+
export interface RlmSummaryResult {
|
|
219
|
+
/** Coefficient names. */
|
|
220
|
+
rows: string[];
|
|
221
|
+
/** Summary statistic column names. */
|
|
222
|
+
columns: ["Value", "Std. Error", "t value"];
|
|
223
|
+
/** Rows of estimates, standard errors and test statistics. */
|
|
224
|
+
values: number[][];
|
|
225
|
+
/** Warnings produced while computing the summary. */
|
|
226
|
+
warnings: string[];
|
|
227
|
+
}
|
|
228
|
+
/** Covariance matrix returned by {@link rlmVcov}.
|
|
229
|
+
*
|
|
230
|
+
* @category Regression
|
|
231
|
+
*/
|
|
232
|
+
export interface RlmVcovResult {
|
|
233
|
+
/** Coefficient names in matrix row order. */
|
|
234
|
+
rows: string[];
|
|
235
|
+
/** Coefficient names in matrix column order. */
|
|
236
|
+
columns: string[];
|
|
237
|
+
/** Covariance matrix values. */
|
|
238
|
+
values: number[][];
|
|
239
|
+
/** Warnings produced while computing the covariance. */
|
|
240
|
+
warnings: string[];
|
|
241
|
+
}
|
|
242
|
+
/** Robust M regression. Equivalent to R's `MASS::rlm()`.
|
|
243
|
+
*
|
|
244
|
+
* @param formula A formula such as `"y ~ x1 + x2"`.
|
|
245
|
+
* @param data Columns of equal-length observations.
|
|
246
|
+
* @param options Psi, scale, initial values, observation weights and iteration controls.
|
|
247
|
+
* @returns Coefficients, fitted values, residuals, robust weights, scale and covariance diagnostics.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* rlm("y ~ x", { y: [1, 2, 2.9, 4.2, 5], x: [1, 2, 3, 4, 5] }).coefficients;
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @category Regression
|
|
255
|
+
*/
|
|
256
|
+
export declare function rlm(formula: string, data: DataFrame, options?: RlmOptions): RlmResult;
|
|
257
|
+
/** Coefficient table of a robust fit. Equivalent to R's `summary.rlm()`.
|
|
258
|
+
*
|
|
259
|
+
* @param fit A fit returned by {@link rlm}.
|
|
260
|
+
* @returns Coefficients, standard errors and t statistics.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* rlmSummary(rlm("y ~ x", { y: [1, 2, 2.9, 4.2, 5], x: [1, 2, 3, 4, 5] }));
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @category Regression
|
|
268
|
+
*/
|
|
269
|
+
export declare function rlmSummary(fit: RlmResult, options?: Record<string, never>): RlmSummaryResult;
|
|
270
|
+
/** Covariance matrix of robust-regression coefficients. Equivalent to R's `vcov.rlm()`.
|
|
271
|
+
*
|
|
272
|
+
* @param fit A fit returned by {@link rlm}.
|
|
273
|
+
* @returns The covariance matrix in coefficient order.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* rlmVcov(rlm("y ~ x", { y: [1, 2, 2.9, 4.2, 5], x: [1, 2, 3, 4, 5] }));
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @category Regression
|
|
281
|
+
*/
|
|
282
|
+
export declare function rlmVcov(fit: RlmResult, options?: Record<string, never>): RlmVcovResult;
|