linreg-core 0.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/LICENSE-APACHE +190 -0
- package/LICENSE-MIT +21 -0
- package/README.md +555 -0
- package/linreg_core.d.ts +743 -0
- package/linreg_core.js +1438 -0
- package/linreg_core_bg.wasm +0 -0
- package/package.json +34 -0
package/linreg_core.js
ADDED
|
@@ -0,0 +1,1438 @@
|
|
|
1
|
+
/* @ts-self-types="./linreg_core.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Performs the Anderson-Darling test for normality via WASM.
|
|
5
|
+
*
|
|
6
|
+
* The Anderson-Darling test checks whether the residuals are normally distributed
|
|
7
|
+
* by comparing the empirical distribution to the expected normal distribution.
|
|
8
|
+
* This test is particularly sensitive to deviations in the tails of the distribution.
|
|
9
|
+
* A significant p-value suggests that the residuals deviate from normality.
|
|
10
|
+
*
|
|
11
|
+
* # Arguments
|
|
12
|
+
*
|
|
13
|
+
* * `y_json` - JSON array of response variable values
|
|
14
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
15
|
+
*
|
|
16
|
+
* # Returns
|
|
17
|
+
*
|
|
18
|
+
* JSON string containing the A² statistic, p-value, and interpretation.
|
|
19
|
+
*
|
|
20
|
+
* # Errors
|
|
21
|
+
*
|
|
22
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
23
|
+
* @param {string} y_json
|
|
24
|
+
* @param {string} x_vars_json
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
export function anderson_darling_test(y_json, x_vars_json) {
|
|
28
|
+
let deferred3_0;
|
|
29
|
+
let deferred3_1;
|
|
30
|
+
try {
|
|
31
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
32
|
+
const len0 = WASM_VECTOR_LEN;
|
|
33
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
34
|
+
const len1 = WASM_VECTOR_LEN;
|
|
35
|
+
const ret = wasm.anderson_darling_test(ptr0, len0, ptr1, len1);
|
|
36
|
+
deferred3_0 = ret[0];
|
|
37
|
+
deferred3_1 = ret[1];
|
|
38
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
39
|
+
} finally {
|
|
40
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Performs the Breusch-Godfrey test for higher-order serial correlation via WASM.
|
|
46
|
+
*
|
|
47
|
+
* Unlike the Durbin-Watson test which only detects first-order autocorrelation,
|
|
48
|
+
* the Breusch-Godfrey test can detect serial correlation at any lag order.
|
|
49
|
+
*
|
|
50
|
+
* # Arguments
|
|
51
|
+
*
|
|
52
|
+
* * `y_json` - JSON array of response variable values
|
|
53
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
54
|
+
* * `order` - Maximum order of serial correlation to test (default: 1)
|
|
55
|
+
* * `test_type` - Type of test statistic: "chisq" or "f" (default: "chisq")
|
|
56
|
+
*
|
|
57
|
+
* # Returns
|
|
58
|
+
*
|
|
59
|
+
* JSON string containing test statistic, p-value, degrees of freedom, and interpretation.
|
|
60
|
+
*
|
|
61
|
+
* # Errors
|
|
62
|
+
*
|
|
63
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
64
|
+
* @param {string} y_json
|
|
65
|
+
* @param {string} x_vars_json
|
|
66
|
+
* @param {number} order
|
|
67
|
+
* @param {string} test_type
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
export function breusch_godfrey_test(y_json, x_vars_json, order, test_type) {
|
|
71
|
+
let deferred4_0;
|
|
72
|
+
let deferred4_1;
|
|
73
|
+
try {
|
|
74
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
75
|
+
const len0 = WASM_VECTOR_LEN;
|
|
76
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
77
|
+
const len1 = WASM_VECTOR_LEN;
|
|
78
|
+
const ptr2 = passStringToWasm0(test_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
79
|
+
const len2 = WASM_VECTOR_LEN;
|
|
80
|
+
const ret = wasm.breusch_godfrey_test(ptr0, len0, ptr1, len1, order, ptr2, len2);
|
|
81
|
+
deferred4_0 = ret[0];
|
|
82
|
+
deferred4_1 = ret[1];
|
|
83
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
84
|
+
} finally {
|
|
85
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Performs the Breusch-Pagan test for heteroscedasticity via WASM.
|
|
91
|
+
*
|
|
92
|
+
* The Breusch-Pagan test checks whether the variance of residuals is constant
|
|
93
|
+
* across the range of predicted values (homoscedasticity assumption).
|
|
94
|
+
* A significant p-value suggests heteroscedasticity.
|
|
95
|
+
*
|
|
96
|
+
* # Arguments
|
|
97
|
+
*
|
|
98
|
+
* * `y_json` - JSON array of response variable values
|
|
99
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
100
|
+
*
|
|
101
|
+
* # Returns
|
|
102
|
+
*
|
|
103
|
+
* JSON string containing test statistic, p-value, and interpretation.
|
|
104
|
+
*
|
|
105
|
+
* # Errors
|
|
106
|
+
*
|
|
107
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
108
|
+
* @param {string} y_json
|
|
109
|
+
* @param {string} x_vars_json
|
|
110
|
+
* @returns {string}
|
|
111
|
+
*/
|
|
112
|
+
export function breusch_pagan_test(y_json, x_vars_json) {
|
|
113
|
+
let deferred3_0;
|
|
114
|
+
let deferred3_1;
|
|
115
|
+
try {
|
|
116
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
117
|
+
const len0 = WASM_VECTOR_LEN;
|
|
118
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
119
|
+
const len1 = WASM_VECTOR_LEN;
|
|
120
|
+
const ret = wasm.breusch_pagan_test(ptr0, len0, ptr1, len1);
|
|
121
|
+
deferred3_0 = ret[0];
|
|
122
|
+
deferred3_1 = ret[1];
|
|
123
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
124
|
+
} finally {
|
|
125
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Computes Cook's distance for identifying influential observations via WASM.
|
|
131
|
+
*
|
|
132
|
+
* Cook's distance measures how much each observation influences the regression
|
|
133
|
+
* model by comparing coefficient estimates with and without that observation.
|
|
134
|
+
* Unlike hypothesis tests, this is an influence measure - not a test with p-values.
|
|
135
|
+
*
|
|
136
|
+
* # Arguments
|
|
137
|
+
*
|
|
138
|
+
* * `y_json` - JSON array of response variable values
|
|
139
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
140
|
+
*
|
|
141
|
+
* # Returns
|
|
142
|
+
*
|
|
143
|
+
* JSON string containing:
|
|
144
|
+
* - Vector of Cook's distances (one per observation)
|
|
145
|
+
* - Thresholds for identifying influential observations
|
|
146
|
+
* - Indices of potentially influential observations
|
|
147
|
+
* - Interpretation and guidance
|
|
148
|
+
*
|
|
149
|
+
* # Errors
|
|
150
|
+
*
|
|
151
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
152
|
+
* @param {string} y_json
|
|
153
|
+
* @param {string} x_vars_json
|
|
154
|
+
* @returns {string}
|
|
155
|
+
*/
|
|
156
|
+
export function cooks_distance_test(y_json, x_vars_json) {
|
|
157
|
+
let deferred3_0;
|
|
158
|
+
let deferred3_1;
|
|
159
|
+
try {
|
|
160
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
161
|
+
const len0 = WASM_VECTOR_LEN;
|
|
162
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
163
|
+
const len1 = WASM_VECTOR_LEN;
|
|
164
|
+
const ret = wasm.cooks_distance_test(ptr0, len0, ptr1, len1);
|
|
165
|
+
deferred3_0 = ret[0];
|
|
166
|
+
deferred3_1 = ret[1];
|
|
167
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
168
|
+
} finally {
|
|
169
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Performs the Durbin-Watson test for autocorrelation via WASM.
|
|
175
|
+
*
|
|
176
|
+
* The Durbin-Watson test checks for autocorrelation in the residuals.
|
|
177
|
+
* Values near 2 indicate no autocorrelation, values near 0 suggest positive
|
|
178
|
+
* autocorrelation, and values near 4 suggest negative autocorrelation.
|
|
179
|
+
*
|
|
180
|
+
* # Arguments
|
|
181
|
+
*
|
|
182
|
+
* * `y_json` - JSON array of response variable values
|
|
183
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
184
|
+
*
|
|
185
|
+
* # Returns
|
|
186
|
+
*
|
|
187
|
+
* JSON string containing the DW statistic and interpretation.
|
|
188
|
+
*
|
|
189
|
+
* # Errors
|
|
190
|
+
*
|
|
191
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
192
|
+
* @param {string} y_json
|
|
193
|
+
* @param {string} x_vars_json
|
|
194
|
+
* @returns {string}
|
|
195
|
+
*/
|
|
196
|
+
export function durbin_watson_test(y_json, x_vars_json) {
|
|
197
|
+
let deferred3_0;
|
|
198
|
+
let deferred3_1;
|
|
199
|
+
try {
|
|
200
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
201
|
+
const len0 = WASM_VECTOR_LEN;
|
|
202
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
203
|
+
const len1 = WASM_VECTOR_LEN;
|
|
204
|
+
const ret = wasm.durbin_watson_test(ptr0, len0, ptr1, len1);
|
|
205
|
+
deferred3_0 = ret[0];
|
|
206
|
+
deferred3_1 = ret[1];
|
|
207
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
208
|
+
} finally {
|
|
209
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Performs Elastic Net regression via WASM.
|
|
215
|
+
*
|
|
216
|
+
* Elastic Net combines L1 (Lasso) and L2 (Ridge) penalties.
|
|
217
|
+
*
|
|
218
|
+
* # Arguments
|
|
219
|
+
*
|
|
220
|
+
* * `y_json` - JSON array of response variable values
|
|
221
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
222
|
+
* * `variable_names` - JSON array of variable names
|
|
223
|
+
* * `lambda` - Regularization strength (>= 0)
|
|
224
|
+
* * `alpha` - Elastic net mixing parameter (0 = Ridge, 1 = Lasso)
|
|
225
|
+
* * `standardize` - Whether to standardize predictors (recommended: true)
|
|
226
|
+
* * `max_iter` - Maximum coordinate descent iterations
|
|
227
|
+
* * `tol` - Convergence tolerance
|
|
228
|
+
*
|
|
229
|
+
* # Returns
|
|
230
|
+
*
|
|
231
|
+
* JSON string containing regression results (same fields as Lasso).
|
|
232
|
+
*
|
|
233
|
+
* # Errors
|
|
234
|
+
*
|
|
235
|
+
* Returns a JSON error object if parsing fails, parameters are invalid,
|
|
236
|
+
* or domain check fails.
|
|
237
|
+
* @param {string} y_json
|
|
238
|
+
* @param {string} x_vars_json
|
|
239
|
+
* @param {string} _variable_names
|
|
240
|
+
* @param {number} lambda
|
|
241
|
+
* @param {number} alpha
|
|
242
|
+
* @param {boolean} standardize
|
|
243
|
+
* @param {number} max_iter
|
|
244
|
+
* @param {number} tol
|
|
245
|
+
* @returns {string}
|
|
246
|
+
*/
|
|
247
|
+
export function elastic_net_regression(y_json, x_vars_json, _variable_names, lambda, alpha, standardize, max_iter, tol) {
|
|
248
|
+
let deferred4_0;
|
|
249
|
+
let deferred4_1;
|
|
250
|
+
try {
|
|
251
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
252
|
+
const len0 = WASM_VECTOR_LEN;
|
|
253
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
254
|
+
const len1 = WASM_VECTOR_LEN;
|
|
255
|
+
const ptr2 = passStringToWasm0(_variable_names, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
256
|
+
const len2 = WASM_VECTOR_LEN;
|
|
257
|
+
const ret = wasm.elastic_net_regression(ptr0, len0, ptr1, len1, ptr2, len2, lambda, alpha, standardize, max_iter, tol);
|
|
258
|
+
deferred4_0 = ret[0];
|
|
259
|
+
deferred4_1 = ret[1];
|
|
260
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
261
|
+
} finally {
|
|
262
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Computes the inverse of the standard normal CDF (probit function).
|
|
268
|
+
*
|
|
269
|
+
* Returns the z-score such that P(Z ≤ z) = p for a standard normal distribution.
|
|
270
|
+
*
|
|
271
|
+
* # Arguments
|
|
272
|
+
*
|
|
273
|
+
* * `p` - Probability (0 < p < 1)
|
|
274
|
+
*
|
|
275
|
+
* # Returns
|
|
276
|
+
*
|
|
277
|
+
* The z-score, or `NaN` if domain check fails.
|
|
278
|
+
* @param {number} p
|
|
279
|
+
* @returns {number}
|
|
280
|
+
*/
|
|
281
|
+
export function get_normal_inverse(p) {
|
|
282
|
+
const ret = wasm.get_normal_inverse(p);
|
|
283
|
+
return ret;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Computes the Student's t-distribution cumulative distribution function.
|
|
288
|
+
*
|
|
289
|
+
* Returns P(T ≤ t) for a t-distribution with the given degrees of freedom.
|
|
290
|
+
*
|
|
291
|
+
* # Arguments
|
|
292
|
+
*
|
|
293
|
+
* * `t` - t-statistic value
|
|
294
|
+
* * `df` - Degrees of freedom
|
|
295
|
+
*
|
|
296
|
+
* # Returns
|
|
297
|
+
*
|
|
298
|
+
* The CDF value, or `NaN` if domain check fails.
|
|
299
|
+
* @param {number} t
|
|
300
|
+
* @param {number} df
|
|
301
|
+
* @returns {number}
|
|
302
|
+
*/
|
|
303
|
+
export function get_t_cdf(t, df) {
|
|
304
|
+
const ret = wasm.get_t_cdf(t, df);
|
|
305
|
+
return ret;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Computes the critical t-value for a given significance level.
|
|
310
|
+
*
|
|
311
|
+
* Returns the t-value such that the area under the t-distribution curve
|
|
312
|
+
* to the right equals alpha/2 (two-tailed test).
|
|
313
|
+
*
|
|
314
|
+
* # Arguments
|
|
315
|
+
*
|
|
316
|
+
* * `alpha` - Significance level (typically 0.05 for 95% confidence)
|
|
317
|
+
* * `df` - Degrees of freedom
|
|
318
|
+
*
|
|
319
|
+
* # Returns
|
|
320
|
+
*
|
|
321
|
+
* The critical t-value, or `NaN` if domain check fails.
|
|
322
|
+
* @param {number} alpha
|
|
323
|
+
* @param {number} df
|
|
324
|
+
* @returns {number}
|
|
325
|
+
*/
|
|
326
|
+
export function get_t_critical(alpha, df) {
|
|
327
|
+
const ret = wasm.get_t_critical(alpha, df);
|
|
328
|
+
return ret;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Returns the current version of the library.
|
|
333
|
+
*
|
|
334
|
+
* Returns the Cargo package version as a string (e.g., "0.1.0").
|
|
335
|
+
*
|
|
336
|
+
* # Errors
|
|
337
|
+
*
|
|
338
|
+
* Returns a JSON error object if domain check fails.
|
|
339
|
+
* @returns {string}
|
|
340
|
+
*/
|
|
341
|
+
export function get_version() {
|
|
342
|
+
let deferred1_0;
|
|
343
|
+
let deferred1_1;
|
|
344
|
+
try {
|
|
345
|
+
const ret = wasm.get_version();
|
|
346
|
+
deferred1_0 = ret[0];
|
|
347
|
+
deferred1_1 = ret[1];
|
|
348
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
349
|
+
} finally {
|
|
350
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Performs the Harvey-Collier test for linearity via WASM.
|
|
356
|
+
*
|
|
357
|
+
* The Harvey-Collier test checks whether the residuals exhibit a linear trend,
|
|
358
|
+
* which would indicate that the model's functional form is misspecified.
|
|
359
|
+
* A significant p-value suggests non-linearity.
|
|
360
|
+
*
|
|
361
|
+
* # Arguments
|
|
362
|
+
*
|
|
363
|
+
* * `y_json` - JSON array of response variable values
|
|
364
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
365
|
+
*
|
|
366
|
+
* # Returns
|
|
367
|
+
*
|
|
368
|
+
* JSON string containing test statistic, p-value, and interpretation.
|
|
369
|
+
*
|
|
370
|
+
* # Errors
|
|
371
|
+
*
|
|
372
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
373
|
+
* @param {string} y_json
|
|
374
|
+
* @param {string} x_vars_json
|
|
375
|
+
* @returns {string}
|
|
376
|
+
*/
|
|
377
|
+
export function harvey_collier_test(y_json, x_vars_json) {
|
|
378
|
+
let deferred3_0;
|
|
379
|
+
let deferred3_1;
|
|
380
|
+
try {
|
|
381
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
382
|
+
const len0 = WASM_VECTOR_LEN;
|
|
383
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
384
|
+
const len1 = WASM_VECTOR_LEN;
|
|
385
|
+
const ret = wasm.harvey_collier_test(ptr0, len0, ptr1, len1);
|
|
386
|
+
deferred3_0 = ret[0];
|
|
387
|
+
deferred3_1 = ret[1];
|
|
388
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
389
|
+
} finally {
|
|
390
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Performs the Jarque-Bera test for normality via WASM.
|
|
396
|
+
*
|
|
397
|
+
* The Jarque-Bera test checks whether the residuals are normally distributed
|
|
398
|
+
* by examining skewness and kurtosis. A significant p-value suggests that
|
|
399
|
+
* the residuals deviate from normality.
|
|
400
|
+
*
|
|
401
|
+
* # Arguments
|
|
402
|
+
*
|
|
403
|
+
* * `y_json` - JSON array of response variable values
|
|
404
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
405
|
+
*
|
|
406
|
+
* # Returns
|
|
407
|
+
*
|
|
408
|
+
* JSON string containing test statistic, p-value, and interpretation.
|
|
409
|
+
*
|
|
410
|
+
* # Errors
|
|
411
|
+
*
|
|
412
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
413
|
+
* @param {string} y_json
|
|
414
|
+
* @param {string} x_vars_json
|
|
415
|
+
* @returns {string}
|
|
416
|
+
*/
|
|
417
|
+
export function jarque_bera_test(y_json, x_vars_json) {
|
|
418
|
+
let deferred3_0;
|
|
419
|
+
let deferred3_1;
|
|
420
|
+
try {
|
|
421
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
422
|
+
const len0 = WASM_VECTOR_LEN;
|
|
423
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
424
|
+
const len1 = WASM_VECTOR_LEN;
|
|
425
|
+
const ret = wasm.jarque_bera_test(ptr0, len0, ptr1, len1);
|
|
426
|
+
deferred3_0 = ret[0];
|
|
427
|
+
deferred3_1 = ret[1];
|
|
428
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
429
|
+
} finally {
|
|
430
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Performs Lasso regression via WASM.
|
|
436
|
+
*
|
|
437
|
+
* Lasso regression adds an L1 penalty to the coefficients, which performs
|
|
438
|
+
* automatic variable selection by shrinking some coefficients to exactly zero.
|
|
439
|
+
* The intercept is never penalized.
|
|
440
|
+
*
|
|
441
|
+
* # Arguments
|
|
442
|
+
*
|
|
443
|
+
* * `y_json` - JSON array of response variable values
|
|
444
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
445
|
+
* * `variable_names` - JSON array of variable names
|
|
446
|
+
* * `lambda` - Regularization strength (>= 0, typical range 0.01 to 10)
|
|
447
|
+
* * `standardize` - Whether to standardize predictors (recommended: true)
|
|
448
|
+
* * `max_iter` - Maximum coordinate descent iterations (default: 100000)
|
|
449
|
+
* * `tol` - Convergence tolerance (default: 1e-7)
|
|
450
|
+
*
|
|
451
|
+
* # Returns
|
|
452
|
+
*
|
|
453
|
+
* JSON string containing:
|
|
454
|
+
* - `lambda` - Lambda value used
|
|
455
|
+
* - `intercept` - Intercept coefficient
|
|
456
|
+
* - `coefficients` - Slope coefficients (some may be exactly zero)
|
|
457
|
+
* - `fitted_values` - Predictions on training data
|
|
458
|
+
* - `residuals` - Residuals (y - fitted_values)
|
|
459
|
+
* - `n_nonzero` - Number of non-zero coefficients (excluding intercept)
|
|
460
|
+
* - `iterations` - Number of coordinate descent iterations
|
|
461
|
+
* - `converged` - Whether the algorithm converged
|
|
462
|
+
*
|
|
463
|
+
* # Errors
|
|
464
|
+
*
|
|
465
|
+
* Returns a JSON error object if parsing fails, lambda is negative,
|
|
466
|
+
* or domain check fails.
|
|
467
|
+
* @param {string} y_json
|
|
468
|
+
* @param {string} x_vars_json
|
|
469
|
+
* @param {string} _variable_names
|
|
470
|
+
* @param {number} lambda
|
|
471
|
+
* @param {boolean} standardize
|
|
472
|
+
* @param {number} max_iter
|
|
473
|
+
* @param {number} tol
|
|
474
|
+
* @returns {string}
|
|
475
|
+
*/
|
|
476
|
+
export function lasso_regression(y_json, x_vars_json, _variable_names, lambda, standardize, max_iter, tol) {
|
|
477
|
+
let deferred4_0;
|
|
478
|
+
let deferred4_1;
|
|
479
|
+
try {
|
|
480
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
481
|
+
const len0 = WASM_VECTOR_LEN;
|
|
482
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
483
|
+
const len1 = WASM_VECTOR_LEN;
|
|
484
|
+
const ptr2 = passStringToWasm0(_variable_names, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
485
|
+
const len2 = WASM_VECTOR_LEN;
|
|
486
|
+
const ret = wasm.lasso_regression(ptr0, len0, ptr1, len1, ptr2, len2, lambda, standardize, max_iter, tol);
|
|
487
|
+
deferred4_0 = ret[0];
|
|
488
|
+
deferred4_1 = ret[1];
|
|
489
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
490
|
+
} finally {
|
|
491
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Generates a lambda path for regularized regression via WASM.
|
|
497
|
+
*
|
|
498
|
+
* Creates a logarithmically-spaced sequence of lambda values from lambda_max
|
|
499
|
+
* (where all penalized coefficients are zero) down to lambda_min. This is
|
|
500
|
+
* useful for fitting regularization paths and selecting optimal lambda via
|
|
501
|
+
* cross-validation.
|
|
502
|
+
*
|
|
503
|
+
* # Arguments
|
|
504
|
+
*
|
|
505
|
+
* * `y_json` - JSON array of response variable values
|
|
506
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
507
|
+
* * `n_lambda` - Number of lambda values to generate (default: 100)
|
|
508
|
+
* * `lambda_min_ratio` - Ratio for smallest lambda (default: 0.0001 if n >= p, else 0.01)
|
|
509
|
+
*
|
|
510
|
+
* # Returns
|
|
511
|
+
*
|
|
512
|
+
* JSON string containing:
|
|
513
|
+
* - `lambda_path` - Array of lambda values in decreasing order
|
|
514
|
+
* - `lambda_max` - Maximum lambda value
|
|
515
|
+
* - `lambda_min` - Minimum lambda value
|
|
516
|
+
* - `n_lambda` - Number of lambda values
|
|
517
|
+
*
|
|
518
|
+
* # Errors
|
|
519
|
+
*
|
|
520
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
521
|
+
* @param {string} y_json
|
|
522
|
+
* @param {string} x_vars_json
|
|
523
|
+
* @param {number} n_lambda
|
|
524
|
+
* @param {number} lambda_min_ratio
|
|
525
|
+
* @returns {string}
|
|
526
|
+
*/
|
|
527
|
+
export function make_lambda_path(y_json, x_vars_json, n_lambda, lambda_min_ratio) {
|
|
528
|
+
let deferred3_0;
|
|
529
|
+
let deferred3_1;
|
|
530
|
+
try {
|
|
531
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
532
|
+
const len0 = WASM_VECTOR_LEN;
|
|
533
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
534
|
+
const len1 = WASM_VECTOR_LEN;
|
|
535
|
+
const ret = wasm.make_lambda_path(ptr0, len0, ptr1, len1, n_lambda, lambda_min_ratio);
|
|
536
|
+
deferred3_0 = ret[0];
|
|
537
|
+
deferred3_1 = ret[1];
|
|
538
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
539
|
+
} finally {
|
|
540
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Performs OLS regression via WASM.
|
|
546
|
+
*
|
|
547
|
+
* All parameters and return values are JSON-encoded strings for JavaScript
|
|
548
|
+
* interoperability. Returns regression output including coefficients,
|
|
549
|
+
* standard errors, diagnostic statistics, and VIF analysis.
|
|
550
|
+
*
|
|
551
|
+
* # Arguments
|
|
552
|
+
*
|
|
553
|
+
* * `y_json` - JSON array of response variable values: `[1.0, 2.0, 3.0]`
|
|
554
|
+
* * `x_vars_json` - JSON array of predictor arrays: `[[1.0, 2.0], [0.5, 1.0]]`
|
|
555
|
+
* * `variable_names` - JSON array of variable names: `["Intercept", "X1", "X2"]`
|
|
556
|
+
*
|
|
557
|
+
* # Returns
|
|
558
|
+
*
|
|
559
|
+
* JSON string containing the complete regression output with coefficients,
|
|
560
|
+
* standard errors, t-statistics, p-values, R², F-statistic, residuals, leverage, VIF, etc.
|
|
561
|
+
*
|
|
562
|
+
* # Errors
|
|
563
|
+
*
|
|
564
|
+
* Returns a JSON error object if:
|
|
565
|
+
* - JSON parsing fails
|
|
566
|
+
* - Insufficient data (n ≤ k + 1)
|
|
567
|
+
* - Matrix is singular
|
|
568
|
+
* - Domain check fails
|
|
569
|
+
* @param {string} y_json
|
|
570
|
+
* @param {string} x_vars_json
|
|
571
|
+
* @param {string} variable_names
|
|
572
|
+
* @returns {string}
|
|
573
|
+
*/
|
|
574
|
+
export function ols_regression(y_json, x_vars_json, variable_names) {
|
|
575
|
+
let deferred4_0;
|
|
576
|
+
let deferred4_1;
|
|
577
|
+
try {
|
|
578
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
579
|
+
const len0 = WASM_VECTOR_LEN;
|
|
580
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
581
|
+
const len1 = WASM_VECTOR_LEN;
|
|
582
|
+
const ptr2 = passStringToWasm0(variable_names, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
583
|
+
const len2 = WASM_VECTOR_LEN;
|
|
584
|
+
const ret = wasm.ols_regression(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
585
|
+
deferred4_0 = ret[0];
|
|
586
|
+
deferred4_1 = ret[1];
|
|
587
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
588
|
+
} finally {
|
|
589
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Parses CSV data and returns it as a JSON string.
|
|
595
|
+
*
|
|
596
|
+
* Parses the CSV content and identifies numeric columns. Returns a JSON object
|
|
597
|
+
* with headers, data rows, and a list of numeric column names.
|
|
598
|
+
*
|
|
599
|
+
* # Arguments
|
|
600
|
+
*
|
|
601
|
+
* * `content` - CSV content as a string
|
|
602
|
+
*
|
|
603
|
+
* # Returns
|
|
604
|
+
*
|
|
605
|
+
* JSON string with structure:
|
|
606
|
+
* ```json
|
|
607
|
+
* {
|
|
608
|
+
* "headers": ["col1", "col2", ...],
|
|
609
|
+
* "data": [{"col1": 1.0, "col2": "text"}, ...],
|
|
610
|
+
* "numeric_columns": ["col1", ...]
|
|
611
|
+
* }
|
|
612
|
+
* ```
|
|
613
|
+
*
|
|
614
|
+
* # Errors
|
|
615
|
+
*
|
|
616
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
617
|
+
* @param {string} content
|
|
618
|
+
* @returns {string}
|
|
619
|
+
*/
|
|
620
|
+
export function parse_csv(content) {
|
|
621
|
+
let deferred2_0;
|
|
622
|
+
let deferred2_1;
|
|
623
|
+
try {
|
|
624
|
+
const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
625
|
+
const len0 = WASM_VECTOR_LEN;
|
|
626
|
+
const ret = wasm.parse_csv(ptr0, len0);
|
|
627
|
+
deferred2_0 = ret[0];
|
|
628
|
+
deferred2_1 = ret[1];
|
|
629
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
630
|
+
} finally {
|
|
631
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Performs the Python method White test for heteroscedasticity via WASM.
|
|
637
|
+
*
|
|
638
|
+
* This implementation matches Python's `statsmodels.stats.diagnostic.het_white()` function.
|
|
639
|
+
* Uses the LINPACK QR decomposition with column pivoting and the Python-specific
|
|
640
|
+
* auxiliary matrix structure (intercept, X, X², and cross-products).
|
|
641
|
+
*
|
|
642
|
+
* # Arguments
|
|
643
|
+
*
|
|
644
|
+
* * `y_json` - JSON array of response variable values
|
|
645
|
+
* * `x_vars_json` - JSON array of predictor arrays (each array is a column)
|
|
646
|
+
*
|
|
647
|
+
* # Returns
|
|
648
|
+
*
|
|
649
|
+
* JSON string containing test statistic, p-value, and interpretation.
|
|
650
|
+
*
|
|
651
|
+
* # Errors
|
|
652
|
+
*
|
|
653
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
654
|
+
* @param {string} y_json
|
|
655
|
+
* @param {string} x_vars_json
|
|
656
|
+
* @returns {string}
|
|
657
|
+
*/
|
|
658
|
+
export function python_white_test(y_json, x_vars_json) {
|
|
659
|
+
let deferred3_0;
|
|
660
|
+
let deferred3_1;
|
|
661
|
+
try {
|
|
662
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
663
|
+
const len0 = WASM_VECTOR_LEN;
|
|
664
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
665
|
+
const len1 = WASM_VECTOR_LEN;
|
|
666
|
+
const ret = wasm.python_white_test(ptr0, len0, ptr1, len1);
|
|
667
|
+
deferred3_0 = ret[0];
|
|
668
|
+
deferred3_1 = ret[1];
|
|
669
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
670
|
+
} finally {
|
|
671
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Performs the R method White test for heteroscedasticity via WASM.
|
|
677
|
+
*
|
|
678
|
+
* This implementation matches R's `skedastic::white()` function behavior.
|
|
679
|
+
* Uses the standard QR decomposition and the R-specific auxiliary matrix
|
|
680
|
+
* structure (intercept, X, X² only - no cross-products).
|
|
681
|
+
*
|
|
682
|
+
* # Arguments
|
|
683
|
+
*
|
|
684
|
+
* * `y_json` - JSON array of response variable values
|
|
685
|
+
* * `x_vars_json` - JSON array of predictor arrays (each array is a column)
|
|
686
|
+
*
|
|
687
|
+
* # Returns
|
|
688
|
+
*
|
|
689
|
+
* JSON string containing test statistic, p-value, and interpretation.
|
|
690
|
+
*
|
|
691
|
+
* # Errors
|
|
692
|
+
*
|
|
693
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
694
|
+
* @param {string} y_json
|
|
695
|
+
* @param {string} x_vars_json
|
|
696
|
+
* @returns {string}
|
|
697
|
+
*/
|
|
698
|
+
export function r_white_test(y_json, x_vars_json) {
|
|
699
|
+
let deferred3_0;
|
|
700
|
+
let deferred3_1;
|
|
701
|
+
try {
|
|
702
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
703
|
+
const len0 = WASM_VECTOR_LEN;
|
|
704
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
705
|
+
const len1 = WASM_VECTOR_LEN;
|
|
706
|
+
const ret = wasm.r_white_test(ptr0, len0, ptr1, len1);
|
|
707
|
+
deferred3_0 = ret[0];
|
|
708
|
+
deferred3_1 = ret[1];
|
|
709
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
710
|
+
} finally {
|
|
711
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Performs the Rainbow test for linearity via WASM.
|
|
717
|
+
*
|
|
718
|
+
* The Rainbow test checks whether the relationship between predictors and response
|
|
719
|
+
* is linear. A significant p-value suggests non-linearity.
|
|
720
|
+
*
|
|
721
|
+
* # Arguments
|
|
722
|
+
*
|
|
723
|
+
* * `y_json` - JSON array of response variable values
|
|
724
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
725
|
+
* * `fraction` - Fraction of data to use in the central subset (0.0 to 1.0, typically 0.5)
|
|
726
|
+
* * `method` - Method to use: "r", "python", or "both" (case-insensitive, defaults to "r")
|
|
727
|
+
*
|
|
728
|
+
* # Returns
|
|
729
|
+
*
|
|
730
|
+
* JSON string containing test statistic, p-value, and interpretation.
|
|
731
|
+
*
|
|
732
|
+
* # Errors
|
|
733
|
+
*
|
|
734
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
735
|
+
* @param {string} y_json
|
|
736
|
+
* @param {string} x_vars_json
|
|
737
|
+
* @param {number} fraction
|
|
738
|
+
* @param {string} method
|
|
739
|
+
* @returns {string}
|
|
740
|
+
*/
|
|
741
|
+
export function rainbow_test(y_json, x_vars_json, fraction, method) {
|
|
742
|
+
let deferred4_0;
|
|
743
|
+
let deferred4_1;
|
|
744
|
+
try {
|
|
745
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
746
|
+
const len0 = WASM_VECTOR_LEN;
|
|
747
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
748
|
+
const len1 = WASM_VECTOR_LEN;
|
|
749
|
+
const ptr2 = passStringToWasm0(method, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
750
|
+
const len2 = WASM_VECTOR_LEN;
|
|
751
|
+
const ret = wasm.rainbow_test(ptr0, len0, ptr1, len1, fraction, ptr2, len2);
|
|
752
|
+
deferred4_0 = ret[0];
|
|
753
|
+
deferred4_1 = ret[1];
|
|
754
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
755
|
+
} finally {
|
|
756
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Performs the RESET test for model specification error via WASM.
|
|
762
|
+
*
|
|
763
|
+
* The RESET (Regression Specification Error Test) test checks whether the model
|
|
764
|
+
* is correctly specified by testing if additional terms (powers of fitted values,
|
|
765
|
+
* regressors, or first principal component) significantly improve the model fit.
|
|
766
|
+
*
|
|
767
|
+
* # Arguments
|
|
768
|
+
*
|
|
769
|
+
* * `y_json` - JSON array of response variable values
|
|
770
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
771
|
+
* * `powers_json` - JSON array of powers to use (e.g., [2, 3] for ŷ², ŷ³)
|
|
772
|
+
* * `type_` - Type of terms to add: "fitted", "regressor", or "princomp"
|
|
773
|
+
*
|
|
774
|
+
* # Returns
|
|
775
|
+
*
|
|
776
|
+
* JSON string containing the F-statistic, p-value, and interpretation.
|
|
777
|
+
*
|
|
778
|
+
* # Errors
|
|
779
|
+
*
|
|
780
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
781
|
+
* @param {string} y_json
|
|
782
|
+
* @param {string} x_vars_json
|
|
783
|
+
* @param {string} powers_json
|
|
784
|
+
* @param {string} type_
|
|
785
|
+
* @returns {string}
|
|
786
|
+
*/
|
|
787
|
+
export function reset_test(y_json, x_vars_json, powers_json, type_) {
|
|
788
|
+
let deferred5_0;
|
|
789
|
+
let deferred5_1;
|
|
790
|
+
try {
|
|
791
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
792
|
+
const len0 = WASM_VECTOR_LEN;
|
|
793
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
794
|
+
const len1 = WASM_VECTOR_LEN;
|
|
795
|
+
const ptr2 = passStringToWasm0(powers_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
796
|
+
const len2 = WASM_VECTOR_LEN;
|
|
797
|
+
const ptr3 = passStringToWasm0(type_, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
798
|
+
const len3 = WASM_VECTOR_LEN;
|
|
799
|
+
const ret = wasm.reset_test(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
800
|
+
deferred5_0 = ret[0];
|
|
801
|
+
deferred5_1 = ret[1];
|
|
802
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
803
|
+
} finally {
|
|
804
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Performs Ridge regression via WASM.
|
|
810
|
+
*
|
|
811
|
+
* Ridge regression adds an L2 penalty to the coefficients, which helps with
|
|
812
|
+
* multicollinearity and overfitting. The intercept is never penalized.
|
|
813
|
+
*
|
|
814
|
+
* # Arguments
|
|
815
|
+
*
|
|
816
|
+
* * `y_json` - JSON array of response variable values
|
|
817
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
818
|
+
* * `variable_names` - JSON array of variable names
|
|
819
|
+
* * `lambda` - Regularization strength (>= 0, typical range 0.01 to 100)
|
|
820
|
+
* * `standardize` - Whether to standardize predictors (recommended: true)
|
|
821
|
+
*
|
|
822
|
+
* # Returns
|
|
823
|
+
*
|
|
824
|
+
* JSON string containing:
|
|
825
|
+
* - `lambda` - Lambda value used
|
|
826
|
+
* - `intercept` - Intercept coefficient
|
|
827
|
+
* - `coefficients` - Slope coefficients
|
|
828
|
+
* - `fitted_values` - Predictions on training data
|
|
829
|
+
* - `residuals` - Residuals (y - fitted_values)
|
|
830
|
+
* - `df` - Effective degrees of freedom
|
|
831
|
+
*
|
|
832
|
+
* # Errors
|
|
833
|
+
*
|
|
834
|
+
* Returns a JSON error object if parsing fails, lambda is negative,
|
|
835
|
+
* or domain check fails.
|
|
836
|
+
* @param {string} y_json
|
|
837
|
+
* @param {string} x_vars_json
|
|
838
|
+
* @param {string} _variable_names
|
|
839
|
+
* @param {number} lambda
|
|
840
|
+
* @param {boolean} standardize
|
|
841
|
+
* @returns {string}
|
|
842
|
+
*/
|
|
843
|
+
export function ridge_regression(y_json, x_vars_json, _variable_names, lambda, standardize) {
|
|
844
|
+
let deferred4_0;
|
|
845
|
+
let deferred4_1;
|
|
846
|
+
try {
|
|
847
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
848
|
+
const len0 = WASM_VECTOR_LEN;
|
|
849
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
850
|
+
const len1 = WASM_VECTOR_LEN;
|
|
851
|
+
const ptr2 = passStringToWasm0(_variable_names, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
852
|
+
const len2 = WASM_VECTOR_LEN;
|
|
853
|
+
const ret = wasm.ridge_regression(ptr0, len0, ptr1, len1, ptr2, len2, lambda, standardize);
|
|
854
|
+
deferred4_0 = ret[0];
|
|
855
|
+
deferred4_1 = ret[1];
|
|
856
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
857
|
+
} finally {
|
|
858
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Performs the Shapiro-Wilk test for normality via WASM.
|
|
864
|
+
*
|
|
865
|
+
* The Shapiro-Wilk test is a powerful test for normality,
|
|
866
|
+
* especially for small to moderate sample sizes (3 ≤ n ≤ 5000). It tests
|
|
867
|
+
* the null hypothesis that the residuals are normally distributed.
|
|
868
|
+
*
|
|
869
|
+
* # Arguments
|
|
870
|
+
*
|
|
871
|
+
* * `y_json` - JSON array of response variable values
|
|
872
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
873
|
+
*
|
|
874
|
+
* # Returns
|
|
875
|
+
*
|
|
876
|
+
* JSON string containing the W statistic (ranges from 0 to 1), p-value,
|
|
877
|
+
* and interpretation.
|
|
878
|
+
*
|
|
879
|
+
* # Errors
|
|
880
|
+
*
|
|
881
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
882
|
+
* @param {string} y_json
|
|
883
|
+
* @param {string} x_vars_json
|
|
884
|
+
* @returns {string}
|
|
885
|
+
*/
|
|
886
|
+
export function shapiro_wilk_test(y_json, x_vars_json) {
|
|
887
|
+
let deferred3_0;
|
|
888
|
+
let deferred3_1;
|
|
889
|
+
try {
|
|
890
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
891
|
+
const len0 = WASM_VECTOR_LEN;
|
|
892
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
893
|
+
const len1 = WASM_VECTOR_LEN;
|
|
894
|
+
const ret = wasm.shapiro_wilk_test(ptr0, len0, ptr1, len1);
|
|
895
|
+
deferred3_0 = ret[0];
|
|
896
|
+
deferred3_1 = ret[1];
|
|
897
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
898
|
+
} finally {
|
|
899
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* Computes the correlation coefficient between two JSON arrays of f64 values.
|
|
905
|
+
*
|
|
906
|
+
* # Arguments
|
|
907
|
+
*
|
|
908
|
+
* * `x_json` - JSON string representing the first array of f64 values
|
|
909
|
+
* * `y_json` - JSON string representing the second array of f64 values
|
|
910
|
+
*
|
|
911
|
+
* # Returns
|
|
912
|
+
*
|
|
913
|
+
* JSON string with the correlation coefficient, or "null" if input is invalid
|
|
914
|
+
* @param {string} x_json
|
|
915
|
+
* @param {string} y_json
|
|
916
|
+
* @returns {string}
|
|
917
|
+
*/
|
|
918
|
+
export function stats_correlation(x_json, y_json) {
|
|
919
|
+
let deferred3_0;
|
|
920
|
+
let deferred3_1;
|
|
921
|
+
try {
|
|
922
|
+
const ptr0 = passStringToWasm0(x_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
923
|
+
const len0 = WASM_VECTOR_LEN;
|
|
924
|
+
const ptr1 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
925
|
+
const len1 = WASM_VECTOR_LEN;
|
|
926
|
+
const ret = wasm.stats_correlation(ptr0, len0, ptr1, len1);
|
|
927
|
+
deferred3_0 = ret[0];
|
|
928
|
+
deferred3_1 = ret[1];
|
|
929
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
930
|
+
} finally {
|
|
931
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* Computes the arithmetic mean of a JSON array of f64 values.
|
|
937
|
+
*
|
|
938
|
+
* # Arguments
|
|
939
|
+
*
|
|
940
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
941
|
+
*
|
|
942
|
+
* # Returns
|
|
943
|
+
*
|
|
944
|
+
* JSON string with the mean, or "null" if input is invalid/empty
|
|
945
|
+
* @param {string} data_json
|
|
946
|
+
* @returns {string}
|
|
947
|
+
*/
|
|
948
|
+
export function stats_mean(data_json) {
|
|
949
|
+
let deferred2_0;
|
|
950
|
+
let deferred2_1;
|
|
951
|
+
try {
|
|
952
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
953
|
+
const len0 = WASM_VECTOR_LEN;
|
|
954
|
+
const ret = wasm.stats_mean(ptr0, len0);
|
|
955
|
+
deferred2_0 = ret[0];
|
|
956
|
+
deferred2_1 = ret[1];
|
|
957
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
958
|
+
} finally {
|
|
959
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Computes the median of a JSON array of f64 values.
|
|
965
|
+
*
|
|
966
|
+
* # Arguments
|
|
967
|
+
*
|
|
968
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
969
|
+
*
|
|
970
|
+
* # Returns
|
|
971
|
+
*
|
|
972
|
+
* JSON string with the median, or "null" if input is invalid/empty
|
|
973
|
+
* @param {string} data_json
|
|
974
|
+
* @returns {string}
|
|
975
|
+
*/
|
|
976
|
+
export function stats_median(data_json) {
|
|
977
|
+
let deferred2_0;
|
|
978
|
+
let deferred2_1;
|
|
979
|
+
try {
|
|
980
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
981
|
+
const len0 = WASM_VECTOR_LEN;
|
|
982
|
+
const ret = wasm.stats_median(ptr0, len0);
|
|
983
|
+
deferred2_0 = ret[0];
|
|
984
|
+
deferred2_1 = ret[1];
|
|
985
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
986
|
+
} finally {
|
|
987
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Computes a quantile of a JSON array of f64 values.
|
|
993
|
+
*
|
|
994
|
+
* # Arguments
|
|
995
|
+
*
|
|
996
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
997
|
+
* * `q` - Quantile to calculate (0.0 to 1.0)
|
|
998
|
+
*
|
|
999
|
+
* # Returns
|
|
1000
|
+
*
|
|
1001
|
+
* JSON string with the quantile value, or "null" if input is invalid
|
|
1002
|
+
* @param {string} data_json
|
|
1003
|
+
* @param {number} q
|
|
1004
|
+
* @returns {string}
|
|
1005
|
+
*/
|
|
1006
|
+
export function stats_quantile(data_json, q) {
|
|
1007
|
+
let deferred2_0;
|
|
1008
|
+
let deferred2_1;
|
|
1009
|
+
try {
|
|
1010
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1011
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1012
|
+
const ret = wasm.stats_quantile(ptr0, len0, q);
|
|
1013
|
+
deferred2_0 = ret[0];
|
|
1014
|
+
deferred2_1 = ret[1];
|
|
1015
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1016
|
+
} finally {
|
|
1017
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Computes the sample standard deviation of a JSON array of f64 values.
|
|
1023
|
+
*
|
|
1024
|
+
* Uses the (n-1) denominator for unbiased estimation.
|
|
1025
|
+
*
|
|
1026
|
+
* # Arguments
|
|
1027
|
+
*
|
|
1028
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
1029
|
+
*
|
|
1030
|
+
* # Returns
|
|
1031
|
+
*
|
|
1032
|
+
* JSON string with the standard deviation, or "null" if input is invalid
|
|
1033
|
+
* @param {string} data_json
|
|
1034
|
+
* @returns {string}
|
|
1035
|
+
*/
|
|
1036
|
+
export function stats_stddev(data_json) {
|
|
1037
|
+
let deferred2_0;
|
|
1038
|
+
let deferred2_1;
|
|
1039
|
+
try {
|
|
1040
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1041
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1042
|
+
const ret = wasm.stats_stddev(ptr0, len0);
|
|
1043
|
+
deferred2_0 = ret[0];
|
|
1044
|
+
deferred2_1 = ret[1];
|
|
1045
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1046
|
+
} finally {
|
|
1047
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Computes the sample variance of a JSON array of f64 values.
|
|
1053
|
+
*
|
|
1054
|
+
* Uses the (n-1) denominator for unbiased estimation.
|
|
1055
|
+
*
|
|
1056
|
+
* # Arguments
|
|
1057
|
+
*
|
|
1058
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
1059
|
+
*
|
|
1060
|
+
* # Returns
|
|
1061
|
+
*
|
|
1062
|
+
* JSON string with the variance, or "null" if input is invalid
|
|
1063
|
+
* @param {string} data_json
|
|
1064
|
+
* @returns {string}
|
|
1065
|
+
*/
|
|
1066
|
+
export function stats_variance(data_json) {
|
|
1067
|
+
let deferred2_0;
|
|
1068
|
+
let deferred2_1;
|
|
1069
|
+
try {
|
|
1070
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1071
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1072
|
+
const ret = wasm.stats_variance(ptr0, len0);
|
|
1073
|
+
deferred2_0 = ret[0];
|
|
1074
|
+
deferred2_1 = ret[1];
|
|
1075
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1076
|
+
} finally {
|
|
1077
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Simple test function to verify WASM is working.
|
|
1083
|
+
*
|
|
1084
|
+
* Returns a success message confirming the WASM module loaded correctly.
|
|
1085
|
+
*
|
|
1086
|
+
* # Errors
|
|
1087
|
+
*
|
|
1088
|
+
* Returns a JSON error object if domain check fails.
|
|
1089
|
+
* @returns {string}
|
|
1090
|
+
*/
|
|
1091
|
+
export function test() {
|
|
1092
|
+
let deferred1_0;
|
|
1093
|
+
let deferred1_1;
|
|
1094
|
+
try {
|
|
1095
|
+
const ret = wasm.test();
|
|
1096
|
+
deferred1_0 = ret[0];
|
|
1097
|
+
deferred1_1 = ret[1];
|
|
1098
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1099
|
+
} finally {
|
|
1100
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* Test function for confidence interval computation.
|
|
1106
|
+
*
|
|
1107
|
+
* Returns JSON with the computed confidence interval for a coefficient.
|
|
1108
|
+
*
|
|
1109
|
+
* # Errors
|
|
1110
|
+
*
|
|
1111
|
+
* Returns a JSON error object if domain check fails.
|
|
1112
|
+
* @param {number} coef
|
|
1113
|
+
* @param {number} se
|
|
1114
|
+
* @param {number} df
|
|
1115
|
+
* @param {number} alpha
|
|
1116
|
+
* @returns {string}
|
|
1117
|
+
*/
|
|
1118
|
+
export function test_ci(coef, se, df, alpha) {
|
|
1119
|
+
let deferred1_0;
|
|
1120
|
+
let deferred1_1;
|
|
1121
|
+
try {
|
|
1122
|
+
const ret = wasm.test_ci(coef, se, df, alpha);
|
|
1123
|
+
deferred1_0 = ret[0];
|
|
1124
|
+
deferred1_1 = ret[1];
|
|
1125
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1126
|
+
} finally {
|
|
1127
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Test function for regression validation against R reference values.
|
|
1133
|
+
*
|
|
1134
|
+
* Runs a regression on a housing dataset and compares results against R's lm() output.
|
|
1135
|
+
* Returns JSON with status "PASS" or "FAIL" with details.
|
|
1136
|
+
*
|
|
1137
|
+
* # Errors
|
|
1138
|
+
*
|
|
1139
|
+
* Returns a JSON error object if domain check fails.
|
|
1140
|
+
* @returns {string}
|
|
1141
|
+
*/
|
|
1142
|
+
export function test_housing_regression() {
|
|
1143
|
+
let deferred1_0;
|
|
1144
|
+
let deferred1_1;
|
|
1145
|
+
try {
|
|
1146
|
+
const ret = wasm.test_housing_regression();
|
|
1147
|
+
deferred1_0 = ret[0];
|
|
1148
|
+
deferred1_1 = ret[1];
|
|
1149
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1150
|
+
} finally {
|
|
1151
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Test function for R accuracy validation.
|
|
1157
|
+
*
|
|
1158
|
+
* Returns JSON comparing our statistical functions against R reference values.
|
|
1159
|
+
*
|
|
1160
|
+
* # Errors
|
|
1161
|
+
*
|
|
1162
|
+
* Returns a JSON error object if domain check fails.
|
|
1163
|
+
* @returns {string}
|
|
1164
|
+
*/
|
|
1165
|
+
export function test_r_accuracy() {
|
|
1166
|
+
let deferred1_0;
|
|
1167
|
+
let deferred1_1;
|
|
1168
|
+
try {
|
|
1169
|
+
const ret = wasm.test_r_accuracy();
|
|
1170
|
+
deferred1_0 = ret[0];
|
|
1171
|
+
deferred1_1 = ret[1];
|
|
1172
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1173
|
+
} finally {
|
|
1174
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* Test function for t-critical value computation.
|
|
1180
|
+
*
|
|
1181
|
+
* Returns JSON with the computed t-critical value for the given parameters.
|
|
1182
|
+
*
|
|
1183
|
+
* # Errors
|
|
1184
|
+
*
|
|
1185
|
+
* Returns a JSON error object if domain check fails.
|
|
1186
|
+
* @param {number} df
|
|
1187
|
+
* @param {number} alpha
|
|
1188
|
+
* @returns {string}
|
|
1189
|
+
*/
|
|
1190
|
+
export function test_t_critical(df, alpha) {
|
|
1191
|
+
let deferred1_0;
|
|
1192
|
+
let deferred1_1;
|
|
1193
|
+
try {
|
|
1194
|
+
const ret = wasm.test_t_critical(df, alpha);
|
|
1195
|
+
deferred1_0 = ret[0];
|
|
1196
|
+
deferred1_1 = ret[1];
|
|
1197
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1198
|
+
} finally {
|
|
1199
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* Performs the White test for heteroscedasticity via WASM.
|
|
1205
|
+
*
|
|
1206
|
+
* The White test is a more general test for heteroscedasticity that does not
|
|
1207
|
+
* assume a specific form of heteroscedasticity. A significant p-value suggests
|
|
1208
|
+
* that the error variance is not constant.
|
|
1209
|
+
*
|
|
1210
|
+
* # Arguments
|
|
1211
|
+
*
|
|
1212
|
+
* * `y_json` - JSON array of response variable values
|
|
1213
|
+
* * `x_vars_json` - JSON array of predictor arrays
|
|
1214
|
+
* * `method` - Method to use: "r", "python", or "both" (case-insensitive, defaults to "r")
|
|
1215
|
+
*
|
|
1216
|
+
* # Returns
|
|
1217
|
+
*
|
|
1218
|
+
* JSON string containing test statistic, p-value, and interpretation.
|
|
1219
|
+
*
|
|
1220
|
+
* # Errors
|
|
1221
|
+
*
|
|
1222
|
+
* Returns a JSON error object if parsing fails or domain check fails.
|
|
1223
|
+
* @param {string} y_json
|
|
1224
|
+
* @param {string} x_vars_json
|
|
1225
|
+
* @param {string} method
|
|
1226
|
+
* @returns {string}
|
|
1227
|
+
*/
|
|
1228
|
+
export function white_test(y_json, x_vars_json, method) {
|
|
1229
|
+
let deferred4_0;
|
|
1230
|
+
let deferred4_1;
|
|
1231
|
+
try {
|
|
1232
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1233
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1234
|
+
const ptr1 = passStringToWasm0(x_vars_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1235
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1236
|
+
const ptr2 = passStringToWasm0(method, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1237
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1238
|
+
const ret = wasm.white_test(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1239
|
+
deferred4_0 = ret[0];
|
|
1240
|
+
deferred4_1 = ret[1];
|
|
1241
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1242
|
+
} finally {
|
|
1243
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
function __wbg_get_imports() {
|
|
1248
|
+
const import0 = {
|
|
1249
|
+
__proto__: null,
|
|
1250
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
1251
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
1252
|
+
},
|
|
1253
|
+
__wbindgen_init_externref_table: function() {
|
|
1254
|
+
const table = wasm.__wbindgen_externrefs;
|
|
1255
|
+
const offset = table.grow(4);
|
|
1256
|
+
table.set(0, undefined);
|
|
1257
|
+
table.set(offset + 0, undefined);
|
|
1258
|
+
table.set(offset + 1, null);
|
|
1259
|
+
table.set(offset + 2, true);
|
|
1260
|
+
table.set(offset + 3, false);
|
|
1261
|
+
},
|
|
1262
|
+
};
|
|
1263
|
+
return {
|
|
1264
|
+
__proto__: null,
|
|
1265
|
+
"./linreg_core_bg.js": import0,
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
function getStringFromWasm0(ptr, len) {
|
|
1270
|
+
ptr = ptr >>> 0;
|
|
1271
|
+
return decodeText(ptr, len);
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
let cachedUint8ArrayMemory0 = null;
|
|
1275
|
+
function getUint8ArrayMemory0() {
|
|
1276
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
1277
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
1278
|
+
}
|
|
1279
|
+
return cachedUint8ArrayMemory0;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
1283
|
+
if (realloc === undefined) {
|
|
1284
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
1285
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
1286
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
1287
|
+
WASM_VECTOR_LEN = buf.length;
|
|
1288
|
+
return ptr;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
let len = arg.length;
|
|
1292
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
1293
|
+
|
|
1294
|
+
const mem = getUint8ArrayMemory0();
|
|
1295
|
+
|
|
1296
|
+
let offset = 0;
|
|
1297
|
+
|
|
1298
|
+
for (; offset < len; offset++) {
|
|
1299
|
+
const code = arg.charCodeAt(offset);
|
|
1300
|
+
if (code > 0x7F) break;
|
|
1301
|
+
mem[ptr + offset] = code;
|
|
1302
|
+
}
|
|
1303
|
+
if (offset !== len) {
|
|
1304
|
+
if (offset !== 0) {
|
|
1305
|
+
arg = arg.slice(offset);
|
|
1306
|
+
}
|
|
1307
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
1308
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
1309
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
1310
|
+
|
|
1311
|
+
offset += ret.written;
|
|
1312
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
WASM_VECTOR_LEN = offset;
|
|
1316
|
+
return ptr;
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
1320
|
+
cachedTextDecoder.decode();
|
|
1321
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
1322
|
+
let numBytesDecoded = 0;
|
|
1323
|
+
function decodeText(ptr, len) {
|
|
1324
|
+
numBytesDecoded += len;
|
|
1325
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
1326
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
1327
|
+
cachedTextDecoder.decode();
|
|
1328
|
+
numBytesDecoded = len;
|
|
1329
|
+
}
|
|
1330
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
const cachedTextEncoder = new TextEncoder();
|
|
1334
|
+
|
|
1335
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
1336
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
1337
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
1338
|
+
view.set(buf);
|
|
1339
|
+
return {
|
|
1340
|
+
read: arg.length,
|
|
1341
|
+
written: buf.length
|
|
1342
|
+
};
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
let WASM_VECTOR_LEN = 0;
|
|
1347
|
+
|
|
1348
|
+
let wasmModule, wasm;
|
|
1349
|
+
function __wbg_finalize_init(instance, module) {
|
|
1350
|
+
wasm = instance.exports;
|
|
1351
|
+
wasmModule = module;
|
|
1352
|
+
cachedUint8ArrayMemory0 = null;
|
|
1353
|
+
wasm.__wbindgen_start();
|
|
1354
|
+
return wasm;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
async function __wbg_load(module, imports) {
|
|
1358
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
1359
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
1360
|
+
try {
|
|
1361
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
1362
|
+
} catch (e) {
|
|
1363
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
1364
|
+
|
|
1365
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
1366
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
1367
|
+
|
|
1368
|
+
} else { throw e; }
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
const bytes = await module.arrayBuffer();
|
|
1373
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
1374
|
+
} else {
|
|
1375
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
1376
|
+
|
|
1377
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
1378
|
+
return { instance, module };
|
|
1379
|
+
} else {
|
|
1380
|
+
return instance;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
function expectedResponseType(type) {
|
|
1385
|
+
switch (type) {
|
|
1386
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
1387
|
+
}
|
|
1388
|
+
return false;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
function initSync(module) {
|
|
1393
|
+
if (wasm !== undefined) return wasm;
|
|
1394
|
+
|
|
1395
|
+
|
|
1396
|
+
if (module !== undefined) {
|
|
1397
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
1398
|
+
({module} = module)
|
|
1399
|
+
} else {
|
|
1400
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
const imports = __wbg_get_imports();
|
|
1405
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
1406
|
+
module = new WebAssembly.Module(module);
|
|
1407
|
+
}
|
|
1408
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
1409
|
+
return __wbg_finalize_init(instance, module);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
async function __wbg_init(module_or_path) {
|
|
1413
|
+
if (wasm !== undefined) return wasm;
|
|
1414
|
+
|
|
1415
|
+
|
|
1416
|
+
if (module_or_path !== undefined) {
|
|
1417
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
1418
|
+
({module_or_path} = module_or_path)
|
|
1419
|
+
} else {
|
|
1420
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
if (module_or_path === undefined) {
|
|
1425
|
+
module_or_path = new URL('linreg_core_bg.wasm', import.meta.url);
|
|
1426
|
+
}
|
|
1427
|
+
const imports = __wbg_get_imports();
|
|
1428
|
+
|
|
1429
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
1430
|
+
module_or_path = fetch(module_or_path);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
1434
|
+
|
|
1435
|
+
return __wbg_finalize_init(instance, module);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
export { initSync, __wbg_init as default };
|