@numero-uno-jpn/rstats 1.6.0 → 1.8.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 +33 -0
- package/README.ja.md +11 -9
- package/README.md +12 -9
- package/dist/chunks/{chunk-O5CMNUJL.js → chunk-2X6PE6JF.js} +2 -2
- package/dist/chunks/{chunk-KAAUNR3G.js → chunk-2ZQ2TSZS.js} +1 -1
- package/dist/chunks/{chunk-F7G74UNI.js → chunk-3DO726WZ.js} +2 -2
- package/dist/chunks/{chunk-WAMHZ47G.js → chunk-45HUI3M4.js} +2 -2
- package/dist/chunks/{chunk-ABSUQPOG.js → chunk-52RWDNO6.js} +2 -2
- package/dist/chunks/chunk-53OM63EU.js +2 -0
- package/dist/chunks/{chunk-2I7Z7L5J.js → chunk-73IRLCTF.js} +2 -2
- package/dist/chunks/chunk-7ODUCEGX.js +2 -0
- package/dist/chunks/{chunk-55XSRONZ.js → chunk-ANZUXEMH.js} +2 -2
- package/dist/chunks/chunk-BHQGMZTI.js +2 -0
- package/dist/chunks/{chunk-3PCHPKBD.js → chunk-D3LKPD4H.js} +2 -2
- package/dist/chunks/chunk-DG2RTNIR.js +2 -0
- package/dist/chunks/{chunk-Z2XN4NN7.js → chunk-GRTQ7FYQ.js} +2 -2
- package/dist/chunks/chunk-HXYH5ZMB.js +2 -0
- package/dist/chunks/{chunk-NVIJXWS6.js → chunk-HYJ4MIZE.js} +2 -2
- package/dist/chunks/{chunk-ZL7EAPO5.js → chunk-IJST2ZGT.js} +1 -1
- package/dist/chunks/{chunk-2TVHT4PF.js → chunk-JIAFWEED.js} +2 -2
- package/dist/chunks/{chunk-7ZNFRZO4.js → chunk-JXJDCQYE.js} +2 -2
- package/dist/chunks/{chunk-FLITCXLY.js → chunk-LZB43TUL.js} +2 -2
- package/dist/chunks/chunk-MLNWWGGE.js +2 -0
- package/dist/chunks/{chunk-OZLDZOOA.js → chunk-QQHF5T2A.js} +1 -1
- package/dist/chunks/chunk-RWZ6ICYN.js +2 -0
- package/dist/chunks/{chunk-RSTU6CX7.js → chunk-TQM6KGKT.js} +2 -2
- package/dist/chunks/chunk-TUL6UFLQ.js +2 -0
- package/dist/chunks/{chunk-BMEO5X5F.js → chunk-TYMC2D5I.js} +2 -2
- package/dist/chunks/chunk-V7ECXPWY.js +2 -0
- package/dist/chunks/chunk-VB6PVRSN.js +2 -0
- package/dist/chunks/chunk-Y4KNH43T.js +2 -0
- package/dist/chunks/{chunk-AHFMBHZW.js → chunk-YD4U3QZ3.js} +1 -1
- package/dist/chunks/{chunk-SFZF44G6.js → chunk-YT62DNDS.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/regression.d.ts +7 -0
- package/dist/entries/regression.js +12 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/gee.d.ts +280 -0
- package/dist/models/gee.js +704 -0
- package/dist/models/glmnet.d.ts +259 -0
- package/dist/models/glmnet.js +1112 -0
- package/dist/models/modelMatrix.d.ts +2 -0
- 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/models/rq.d.ts +203 -0
- package/dist/models/rq.js +1089 -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 +15 -15
- package/llms.txt +8 -1
- package/package.json +6 -1
- 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-TPBVVP32.js +0 -2
- package/dist/chunks/chunk-XNWSQVXS.js +0 -2
|
@@ -52,6 +52,8 @@ export interface ModelMatrixResult {
|
|
|
52
52
|
/**
|
|
53
53
|
* A contrast the internal model-matrix code accepts: those of {@link ContrastName} and R's `contr.poly` (orthogonal
|
|
54
54
|
* polynomials in the level scores 1, 2, ..., columns `.L`, `.Q`, `.C`, `^4`, ...), which lmer's fixed effects may use.
|
|
55
|
+
*
|
|
56
|
+
* @category Regression
|
|
55
57
|
*/
|
|
56
58
|
export type DesignContrast = ContrastName | "contr.poly";
|
|
57
59
|
/** A contrast matrix (one row per level) and its column names */
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type { DataFrame } from "./modelFrame.js";
|
|
2
|
+
import type { Sample } from "../htest/types.js";
|
|
3
|
+
import { type NlsExpr } from "./nlsFormula.js";
|
|
4
|
+
/** Algorithm used to fit a nonlinear least-squares model.
|
|
5
|
+
*
|
|
6
|
+
* @category Regression
|
|
7
|
+
*/
|
|
8
|
+
export type NlsAlgorithm = "default" | "plinear" | "port";
|
|
9
|
+
/** Convergence controls for nonlinear least squares.
|
|
10
|
+
*
|
|
11
|
+
* @category Regression
|
|
12
|
+
*/
|
|
13
|
+
export interface NlsControl {
|
|
14
|
+
/** Maximum number of iterations. */
|
|
15
|
+
maxiter?: number;
|
|
16
|
+
/** Relative convergence tolerance. */
|
|
17
|
+
tol?: number;
|
|
18
|
+
/** Minimum step-length factor used by the line search. */
|
|
19
|
+
minFactor?: number;
|
|
20
|
+
/** Whether non-convergence is reported as a warning instead of an error. */
|
|
21
|
+
warnOnly?: boolean;
|
|
22
|
+
/** Positive offset used in the convergence scaling criterion. */
|
|
23
|
+
scaleOffset?: number;
|
|
24
|
+
}
|
|
25
|
+
/** Options for {@link nls}.
|
|
26
|
+
*
|
|
27
|
+
* @category Regression
|
|
28
|
+
*/
|
|
29
|
+
export interface NlsOptions {
|
|
30
|
+
/** Named initial parameter values. */
|
|
31
|
+
start?: Record<string, number>;
|
|
32
|
+
/** Nonlinear least-squares algorithm. */
|
|
33
|
+
algorithm?: NlsAlgorithm;
|
|
34
|
+
/** Non-negative observation weights, or the name of a data column. */
|
|
35
|
+
weights?: Sample | string;
|
|
36
|
+
/** Lower parameter bounds for the bounded algorithm. */
|
|
37
|
+
lower?: number | readonly number[] | Record<string, number>;
|
|
38
|
+
/** Upper parameter bounds for the bounded algorithm. */
|
|
39
|
+
upper?: number | readonly number[] | Record<string, number>;
|
|
40
|
+
/** Convergence controls. */
|
|
41
|
+
control?: NlsControl;
|
|
42
|
+
}
|
|
43
|
+
/** Internal and public fitted-model quantities.
|
|
44
|
+
*
|
|
45
|
+
* @category Regression
|
|
46
|
+
*/
|
|
47
|
+
export interface NlsModel {
|
|
48
|
+
/** Original model formula. */
|
|
49
|
+
formula: string;
|
|
50
|
+
/** Response expression label. */
|
|
51
|
+
response: string;
|
|
52
|
+
/** Parameter names in coefficient order. */
|
|
53
|
+
parameterNames: string[];
|
|
54
|
+
/** Named parameter estimates. */
|
|
55
|
+
coefficients: Record<string, number>;
|
|
56
|
+
/** Fitted response values. */
|
|
57
|
+
fitted: number[];
|
|
58
|
+
/** Observed minus fitted response values. */
|
|
59
|
+
residuals: number[];
|
|
60
|
+
/** Response values used in fitting. */
|
|
61
|
+
y: number[];
|
|
62
|
+
/** Observation weights used in fitting. */
|
|
63
|
+
weights: number[];
|
|
64
|
+
/** Original row indices retained after missing-value handling. */
|
|
65
|
+
rows: number[];
|
|
66
|
+
/** Numeric data columns retained for prediction and profiling. */
|
|
67
|
+
data: Record<string, number[]>;
|
|
68
|
+
/** Parsed expression tree used internally. @internal */
|
|
69
|
+
expression: NlsExpr;
|
|
70
|
+
/** Weighted residual sum of squares. */
|
|
71
|
+
deviance: number;
|
|
72
|
+
/** Residual standard error estimate. */
|
|
73
|
+
sigma: number;
|
|
74
|
+
/** Residual degrees of freedom. */
|
|
75
|
+
dfResidual: number;
|
|
76
|
+
/** Number of observations used in fitting. */
|
|
77
|
+
nobs: number;
|
|
78
|
+
/** Estimated parameter covariance matrix. */
|
|
79
|
+
covariance: number[][];
|
|
80
|
+
/** Estimated parameter correlation matrix. */
|
|
81
|
+
correlation: number[][];
|
|
82
|
+
/** Whether the convergence criterion was met. */
|
|
83
|
+
converged: boolean;
|
|
84
|
+
/** Number of iterations performed. */
|
|
85
|
+
iterations: number;
|
|
86
|
+
/** Algorithm used for fitting. */
|
|
87
|
+
algorithm: NlsAlgorithm;
|
|
88
|
+
/** Warnings produced during fitting. */
|
|
89
|
+
warnings: string[];
|
|
90
|
+
/** Whether the residual sum of squares is exactly zero. */
|
|
91
|
+
exactFit: boolean;
|
|
92
|
+
}
|
|
93
|
+
/** Result returned by {@link nls}.
|
|
94
|
+
*
|
|
95
|
+
* @category Regression
|
|
96
|
+
*/
|
|
97
|
+
export interface NlsResult extends NlsModel {
|
|
98
|
+
}
|
|
99
|
+
/** Result returned by {@link nlsSummary}.
|
|
100
|
+
*
|
|
101
|
+
* @category Regression
|
|
102
|
+
*/
|
|
103
|
+
export interface NlsSummaryResult {
|
|
104
|
+
/** Coefficient table with estimates, standard errors and test statistics. */
|
|
105
|
+
coefficients: {
|
|
106
|
+
/** Coefficient names in row order. */
|
|
107
|
+
rows: string[];
|
|
108
|
+
/** Summary statistic column names. */
|
|
109
|
+
cols: string[];
|
|
110
|
+
/** Rows of coefficient estimates, standard errors and test statistics. */
|
|
111
|
+
values: number[][];
|
|
112
|
+
};
|
|
113
|
+
/** Residual standard error estimate. */
|
|
114
|
+
sigma: number;
|
|
115
|
+
/** Residual and model degrees of freedom. */
|
|
116
|
+
df: [number, number];
|
|
117
|
+
/** Weighted residual sum of squares. */
|
|
118
|
+
deviance: number;
|
|
119
|
+
/** Number of observations used in fitting. */
|
|
120
|
+
nobs: number;
|
|
121
|
+
/** Warnings produced while computing the summary. */
|
|
122
|
+
warnings: string[];
|
|
123
|
+
}
|
|
124
|
+
/** Options for {@link nlsPredict}.
|
|
125
|
+
*
|
|
126
|
+
* @category Regression
|
|
127
|
+
*/
|
|
128
|
+
export interface NlsPredictOptions {
|
|
129
|
+
/** New data columns at which to evaluate the fitted expression. */
|
|
130
|
+
newdata: DataFrame;
|
|
131
|
+
}
|
|
132
|
+
/** Options for {@link nlsConfint}.
|
|
133
|
+
*
|
|
134
|
+
* @category Regression
|
|
135
|
+
*/
|
|
136
|
+
export interface NlsConfintOptions {
|
|
137
|
+
/** Confidence-interval method; profile by default. */
|
|
138
|
+
method?: "profile" | "wald";
|
|
139
|
+
/** Confidence level between zero and one. */
|
|
140
|
+
level?: number;
|
|
141
|
+
/** Parameter names for which to compute intervals; omitted means all estimable parameters. */
|
|
142
|
+
parm?: readonly string[];
|
|
143
|
+
}
|
|
144
|
+
/** Result returned by {@link nlsConfint}.
|
|
145
|
+
*
|
|
146
|
+
* @category Regression
|
|
147
|
+
*/
|
|
148
|
+
export interface NlsConfintResult {
|
|
149
|
+
/** Parameter names for the intervals. */
|
|
150
|
+
rows: string[];
|
|
151
|
+
/** Lower and upper confidence-limit labels. */
|
|
152
|
+
cols: [string, string];
|
|
153
|
+
/** Lower and upper confidence limits, one pair per parameter. */
|
|
154
|
+
values: [number, number][];
|
|
155
|
+
/** Warnings produced while computing the intervals. */
|
|
156
|
+
warnings: string[];
|
|
157
|
+
}
|
|
158
|
+
/** Result returned by {@link nlsAnova}.
|
|
159
|
+
*
|
|
160
|
+
* @category Regression
|
|
161
|
+
*/
|
|
162
|
+
export interface NlsAnovaResult {
|
|
163
|
+
/** Sequential analysis-of-variance table. */
|
|
164
|
+
table: {
|
|
165
|
+
/** Formula for each fitted model. */
|
|
166
|
+
Model: string[];
|
|
167
|
+
/** Residual degrees of freedom for each model. */
|
|
168
|
+
"Res.Df": number[];
|
|
169
|
+
/** Residual sum of squares for each model. */
|
|
170
|
+
"Res.Sum Sq": number[];
|
|
171
|
+
/** Difference in residual degrees of freedom for each comparison. */
|
|
172
|
+
"Df": (number | "NA")[];
|
|
173
|
+
/** Difference in residual sum of squares for each comparison. */
|
|
174
|
+
"Sum Sq": (number | "NA")[];
|
|
175
|
+
/** F statistic for each comparison. */
|
|
176
|
+
"F value": (number | "NA")[];
|
|
177
|
+
/** Upper-tail F-test probability for each comparison. */
|
|
178
|
+
"Pr(>F)": (number | "NA")[];
|
|
179
|
+
};
|
|
180
|
+
/** Warnings produced while comparing models. */
|
|
181
|
+
warnings: string[];
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Nonlinear least-squares regression. Equivalent to R's `nls()`.
|
|
185
|
+
*
|
|
186
|
+
* Fits a user-specified nonlinear mean function by Gauss-Newton, variable projection, or bound-constrained
|
|
187
|
+
* least squares. Formula expressions are parsed safely and differentiated symbolically.
|
|
188
|
+
*
|
|
189
|
+
* @param formula Response and nonlinear mean expression.
|
|
190
|
+
* @param data Numeric data columns.
|
|
191
|
+
* @param options Starting values, algorithm, weights, and convergence controls.
|
|
192
|
+
* @returns The fitted coefficients, residuals, covariance, and convergence diagnostics.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* const data = { conc: [0.02, 0.06, 0.11, 0.22, 0.56, 1.1], rate: [76, 97, 123, 159, 191, 207] };
|
|
197
|
+
* const fit = nls("rate ~ Vm * conc / (K + conc)", data, { start: { Vm: 200, K: 0.05 } });
|
|
198
|
+
* fit.coefficients;
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @category Regression
|
|
202
|
+
*/
|
|
203
|
+
export declare function nls(formula: string, data: DataFrame, options?: NlsOptions): NlsResult;
|
|
204
|
+
/**
|
|
205
|
+
* Summary of a nonlinear least-squares fit. Equivalent to R's `summary.nls()`.
|
|
206
|
+
*
|
|
207
|
+
* @param fit A fitted nonlinear model.
|
|
208
|
+
* @returns The coefficient table, residual scale, and residual degrees of freedom.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* const data = { conc: [0.02, 0.06, 0.11, 0.22, 0.56, 1.1], rate: [76, 97, 123, 159, 191, 207] };
|
|
213
|
+
* const fit = nls("rate ~ Vm * conc / (K + conc)", data, { start: { Vm: 200, K: 0.05 } });
|
|
214
|
+
* nlsSummary(fit);
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @category Regression
|
|
218
|
+
*/
|
|
219
|
+
export declare function nlsSummary(fit: NlsResult): NlsSummaryResult;
|
|
220
|
+
/**
|
|
221
|
+
* Covariance matrix of a nonlinear least-squares fit. Equivalent to R's `vcov.nls()`.
|
|
222
|
+
*
|
|
223
|
+
* @param fit A fitted nonlinear model.
|
|
224
|
+
* @returns The covariance matrix in coefficient order.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* const data = { conc: [0.02, 0.06, 0.11, 0.22, 0.56, 1.1], rate: [76, 97, 123, 159, 191, 207] };
|
|
229
|
+
* const fit = nls("rate ~ Vm * conc / (K + conc)", data, { start: { Vm: 200, K: 0.05 } });
|
|
230
|
+
* nlsVcov(fit);
|
|
231
|
+
* ```
|
|
232
|
+
*
|
|
233
|
+
* @category Regression
|
|
234
|
+
*/
|
|
235
|
+
export declare function nlsVcov(fit: NlsResult): number[][];
|
|
236
|
+
/**
|
|
237
|
+
* Predictions from a nonlinear least-squares fit. Equivalent to R's `predict.nls()`.
|
|
238
|
+
*
|
|
239
|
+
* @param fit A fitted nonlinear model.
|
|
240
|
+
* @param options New predictor data.
|
|
241
|
+
* @returns One fitted mean per row of new data.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* const data = { conc: [0.02, 0.06, 0.11, 0.22, 0.56, 1.1], rate: [76, 97, 123, 159, 191, 207] };
|
|
246
|
+
* const fit = nls("rate ~ Vm * conc / (K + conc)", data, { start: { Vm: 200, K: 0.05 } });
|
|
247
|
+
* nlsPredict(fit, { newdata: { conc: [0.1, 0.5] } });
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @category Regression
|
|
251
|
+
*/
|
|
252
|
+
export declare function nlsPredict(fit: NlsResult, options: NlsPredictOptions): number[];
|
|
253
|
+
/**
|
|
254
|
+
* Wald or profile confidence intervals for nonlinear parameters. Equivalent to R's `confint.nls()`.
|
|
255
|
+
*
|
|
256
|
+
* @param fit A fitted nonlinear model.
|
|
257
|
+
* @param options Interval method, confidence level, and parameter names.
|
|
258
|
+
* @returns A two-column confidence interval matrix.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* const data = { conc: [0.02, 0.06, 0.11, 0.22, 0.56, 1.1], rate: [76, 97, 123, 159, 191, 207] };
|
|
263
|
+
* const fit = nls("rate ~ Vm * conc / (K + conc)", data, { start: { Vm: 200, K: 0.05 } });
|
|
264
|
+
* nlsConfint(fit, { method: "wald", level: 0.95 });
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @category Regression
|
|
268
|
+
*/
|
|
269
|
+
export declare function nlsConfint(fit: NlsResult, options?: NlsConfintOptions): NlsConfintResult;
|
|
270
|
+
/**
|
|
271
|
+
* Analysis of variance for nested nonlinear least-squares fits. Equivalent to R's `anova.nls()`.
|
|
272
|
+
*
|
|
273
|
+
* @param fits Two or more nested fits to the same observations.
|
|
274
|
+
* @returns The sequential F-test table.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* const data = { x: [1, 2, 3, 4, 5], y: [2, 3, 5, 7, 8] };
|
|
279
|
+
* const small = nls("y ~ a * x", data, { start: { a: 1 } });
|
|
280
|
+
* const large = nls("y ~ a * x + b", data, { start: { a: 1, b: 0 } });
|
|
281
|
+
* nlsAnova(small, large);
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @category Regression
|
|
285
|
+
*/
|
|
286
|
+
export declare function nlsAnova(...fits: NlsResult[]): NlsAnovaResult;
|