@danielsimonjr/mathts-functions 0.30.0 → 0.31.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/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +626 -119
- package/dist/ml/dbscan-knn.d.ts +52 -0
- package/dist/ml/dbscan-knn.d.ts.map +1 -0
- package/dist/ml/kde.d.ts +37 -0
- package/dist/ml/kde.d.ts.map +1 -0
- package/dist/ml/logistic-regression.d.ts +34 -0
- package/dist/ml/logistic-regression.d.ts.map +1 -0
- package/dist/ml/ols.d.ts +37 -0
- package/dist/ml/ols.d.ts.map +1 -0
- package/dist/ml/regularized-regression.d.ts +65 -0
- package/dist/ml/regularized-regression.d.ts.map +1 -0
- package/dist/stats/inference-extra.d.ts +46 -0
- package/dist/stats/inference-extra.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Density-based clustering (DBSCAN) + k-nearest-neighbour classifier/regressor
|
|
3
|
+
* (Phase 3 Task 4 — ML primitives).
|
|
4
|
+
*
|
|
5
|
+
* All three functions share brute-force Euclidean-distance neighbour search.
|
|
6
|
+
* The library's exported `kdTree` (`typed/geometry.ts`) has no radius-query
|
|
7
|
+
* method, so DBSCAN's ε-neighborhoods are computed O(n²) brute-force here —
|
|
8
|
+
* correct, just not the asymptotically fastest option. A kd-tree range-search
|
|
9
|
+
* (and a kd-tree-backed k-NN search) is future work if this becomes a hot path.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* DBSCAN density-based clustering. A point is a **core point** if its
|
|
13
|
+
* ε-neighborhood (including itself) has at least `minPts` members; clusters
|
|
14
|
+
* are grown by expanding outward from core points through their neighbors
|
|
15
|
+
* (density-reachability). Points reached only from a core point's
|
|
16
|
+
* neighborhood but that are not themselves core are labeled as border points
|
|
17
|
+
* of that cluster; points never reached are **noise** (`-1`).
|
|
18
|
+
*
|
|
19
|
+
* @param points - Row-vectors (n × d)
|
|
20
|
+
* @param eps - Neighborhood radius (Euclidean)
|
|
21
|
+
* @param minPts - Minimum neighborhood size (including the point itself) for a core point
|
|
22
|
+
* @returns 0-based cluster label per point; `-1` marks noise
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* dbscan([[0, 0], [0.1, 0.1], [10, 10], [50, 50]], 1.0, 2)
|
|
26
|
+
* // => [0, 0, -1, -1] (one 2-point cluster, two noise points)
|
|
27
|
+
*/
|
|
28
|
+
export declare function dbscan(points: number[][], eps: number, minPts: number): number[];
|
|
29
|
+
/**
|
|
30
|
+
* k-nearest-neighbour classifier: majority vote of the `k` closest training
|
|
31
|
+
* points (Euclidean distance). Ties are broken by the label of the single
|
|
32
|
+
* nearest point among the tied labels.
|
|
33
|
+
*
|
|
34
|
+
* @param train - Training row-vectors (n × d)
|
|
35
|
+
* @param labels - Training labels (length n)
|
|
36
|
+
* @param query - Query row-vectors (m × d)
|
|
37
|
+
* @param k - Number of neighbors
|
|
38
|
+
* @returns Predicted label per query row
|
|
39
|
+
*/
|
|
40
|
+
export declare function knnClassify(train: number[][], labels: (number | string)[], query: number[][], k: number): (number | string)[];
|
|
41
|
+
/**
|
|
42
|
+
* k-nearest-neighbour regressor: mean of the `k` closest training targets
|
|
43
|
+
* (Euclidean distance).
|
|
44
|
+
*
|
|
45
|
+
* @param train - Training row-vectors (n × d)
|
|
46
|
+
* @param targets - Training targets (length n)
|
|
47
|
+
* @param query - Query row-vectors (m × d)
|
|
48
|
+
* @param k - Number of neighbors
|
|
49
|
+
* @returns Predicted (mean) target per query row
|
|
50
|
+
*/
|
|
51
|
+
export declare function knnRegress(train: number[][], targets: number[], query: number[][], k: number): number[];
|
|
52
|
+
//# sourceMappingURL=dbscan-knn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbscan-knn.d.ts","sourceRoot":"","sources":["../../src/ml/dbscan-knn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAoBH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAoChF;AASD;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EAAE,EAAE,EACjB,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAC3B,KAAK,EAAE,MAAM,EAAE,EAAE,EACjB,CAAC,EAAE,MAAM,GACR,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAwBrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,EAAE,EAAE,EACjB,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,EAAE,EAAE,EACjB,CAAC,EAAE,MAAM,GACR,MAAM,EAAE,CAMV"}
|
package/dist/ml/kde.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 1-D Gaussian kernel density estimation (Wave — ML primitives, Phase 3 Task 5).
|
|
3
|
+
*
|
|
4
|
+
* The first nonparametric density estimator in the library. Given samples
|
|
5
|
+
* `s_1..s_n`, estimates the density at query points via a sum of Gaussian
|
|
6
|
+
* "bumps" centered on each sample:
|
|
7
|
+
*
|
|
8
|
+
* density(x) = (1 / (n * h)) * sum_i phi((x - s_i) / h)
|
|
9
|
+
*
|
|
10
|
+
* where `phi` is the standard normal pdf and `h` is the bandwidth. Bandwidth
|
|
11
|
+
* defaults to Silverman's rule of thumb, which balances bias (too smooth)
|
|
12
|
+
* against variance (too noisy) using the sample spread.
|
|
13
|
+
*/
|
|
14
|
+
export interface GaussianKDEOptions {
|
|
15
|
+
/** Bandwidth (smoothing parameter). Defaults to Silverman's rule of thumb. */
|
|
16
|
+
bandwidth?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface GaussianKDEResult {
|
|
19
|
+
/** Evaluate the estimated density at each of `xs`. */
|
|
20
|
+
evaluate: (xs: number[]) => number[];
|
|
21
|
+
/** The bandwidth actually used (either supplied or Silverman's rule). */
|
|
22
|
+
bandwidth: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 1-D Gaussian kernel density estimation.
|
|
26
|
+
*
|
|
27
|
+
* @param samples - Observed sample values (n >= 2 for the default bandwidth;
|
|
28
|
+
* a single sample requires an explicit `opts.bandwidth`)
|
|
29
|
+
* @param opts - `bandwidth` (default: Silverman's rule of thumb)
|
|
30
|
+
* @returns `evaluate(xs)` — density at each query point — and the chosen `bandwidth`
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const kde = gaussianKDE([-1, 0, 0, 1]);
|
|
34
|
+
* kde.evaluate([0]); // => density near the sample center (a single peak)
|
|
35
|
+
*/
|
|
36
|
+
export declare function gaussianKDE(samples: number[], opts?: GaussianKDEOptions): GaussianKDEResult;
|
|
37
|
+
//# sourceMappingURL=kde.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kde.d.ts","sourceRoot":"","sources":["../../src/ml/kde.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,kBAAkB;IACjC,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,sDAAsD;IACtD,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;IACrC,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;CACnB;AAqDD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,GAAE,kBAAuB,GAAG,iBAAiB,CAoB/F"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface LogisticRegressionOptions {
|
|
2
|
+
/** Prepend a column of ones (default true). */
|
|
3
|
+
intercept?: boolean;
|
|
4
|
+
/** Convergence tolerance on the max-norm of the Newton step (default 1e-8). */
|
|
5
|
+
tol?: number;
|
|
6
|
+
/** Maximum IRLS iterations (default 100). */
|
|
7
|
+
maxIter?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface LogisticRegressionResult {
|
|
10
|
+
/** Fitted coefficients for the original predictors (excludes the intercept). */
|
|
11
|
+
coefficients: number[];
|
|
12
|
+
/** Fitted intercept (0 if `opts.intercept === false`). */
|
|
13
|
+
intercept: number;
|
|
14
|
+
/** Predict class probabilities (P(y=1|x)) for new rows. */
|
|
15
|
+
predictProba: (x: number[][]) => number[];
|
|
16
|
+
/** Predict class labels (threshold 0.5) for new rows. */
|
|
17
|
+
predict: (x: number[][]) => number[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Binary logistic regression `P(y=1|x) = sigmoid(xᵀβ)` fit by IRLS (Newton-Raphson
|
|
21
|
+
* on the Bernoulli log-likelihood).
|
|
22
|
+
*
|
|
23
|
+
* @param X - Design matrix (rows = observations, cols = predictors)
|
|
24
|
+
* @param y - Binary labels, each in {0, 1}
|
|
25
|
+
* @param opts - `intercept` (default true) prepends a column of ones to X;
|
|
26
|
+
* `tol` (default 1e-8) convergence tolerance; `maxIter` (default 100)
|
|
27
|
+
* @returns Fitted coefficients/intercept plus `predict`/`predictProba`
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const m = logisticRegression([[-2], [-1], [1], [2]], [0, 0, 1, 1]);
|
|
31
|
+
* m.predict([[3]]) // => [1]
|
|
32
|
+
*/
|
|
33
|
+
export declare function logisticRegression(X: number[][], y: number[], opts?: LogisticRegressionOptions): LogisticRegressionResult;
|
|
34
|
+
//# sourceMappingURL=logistic-regression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logistic-regression.d.ts","sourceRoot":"","sources":["../../src/ml/logistic-regression.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,yBAAyB;IACxC,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,+EAA+E;IAC/E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,wBAAwB;IACvC,gFAAgF;IAChF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,YAAY,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC;IAC1C,yDAAyD;IACzD,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC;CACtC;AAkBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,MAAM,EAAE,EAAE,EACb,CAAC,EAAE,MAAM,EAAE,EACX,IAAI,CAAC,EAAE,yBAAyB,GAC/B,wBAAwB,CAiG1B"}
|
package/dist/ml/ols.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface OlsOptions {
|
|
2
|
+
/** Prepend a column of ones (default true). */
|
|
3
|
+
intercept?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface OlsResult {
|
|
6
|
+
/** Fitted coefficients (intercept first, if included). */
|
|
7
|
+
coefficients: number[];
|
|
8
|
+
/** Standard error of each coefficient. */
|
|
9
|
+
stderr: number[];
|
|
10
|
+
/** t-statistic for each coefficient (H0: coefficient = 0). */
|
|
11
|
+
tValues: number[];
|
|
12
|
+
/** Two-sided p-value for each coefficient's t-statistic. */
|
|
13
|
+
pValues: number[];
|
|
14
|
+
/** Coefficient of determination. */
|
|
15
|
+
r2: number;
|
|
16
|
+
/** R² adjusted for the number of predictors. */
|
|
17
|
+
adjR2: number;
|
|
18
|
+
/** Overall model F-statistic (H0: all slope coefficients = 0). */
|
|
19
|
+
fStat: number;
|
|
20
|
+
/** Residuals y - Xβ. */
|
|
21
|
+
residuals: number[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Multiple linear regression `y ≈ Xβ` by ordinary least squares (normal equations),
|
|
25
|
+
* with full inference: standard errors, t/p-values per coefficient, R²/adjusted-R²,
|
|
26
|
+
* the overall model F-statistic, and residuals.
|
|
27
|
+
*
|
|
28
|
+
* @param X - Design matrix (rows = observations, cols = predictors)
|
|
29
|
+
* @param y - Response vector (length = number of observations)
|
|
30
|
+
* @param opts - `intercept` (default true) prepends a column of ones to X
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ols([[1, 1], [2, 0], [3, 1], [4, 0]], [6, 5, 10, 9])
|
|
34
|
+
* // => coefficients ~= [1, 2, 3] (y = 1 + 2*x1 + 3*x2), r2 = 1
|
|
35
|
+
*/
|
|
36
|
+
export declare function ols(X: number[][], y: number[], opts?: OlsOptions): OlsResult;
|
|
37
|
+
//# sourceMappingURL=ols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ols.d.ts","sourceRoot":"","sources":["../../src/ml/ols.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,0DAA0D;IAC1D,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,0CAA0C;IAC1C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,8DAA8D;IAC9D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,4DAA4D;IAC5D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,oCAAoC;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAqED;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,CAmC5E"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export interface RidgeOptions {
|
|
2
|
+
/** Center X/y and fit an unpenalized intercept (default true). */
|
|
3
|
+
intercept?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface CoordinateDescentOptions extends RidgeOptions {
|
|
6
|
+
/** Maximum coordinate-descent sweeps (default 1000). */
|
|
7
|
+
maxIter?: number;
|
|
8
|
+
/** Convergence tolerance on the max coefficient change per sweep (default 1e-7). */
|
|
9
|
+
tol?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface RegularizedRegressionResult {
|
|
12
|
+
/** Fitted coefficients, one per predictor column (intercept excluded). */
|
|
13
|
+
coefficients: number[];
|
|
14
|
+
/** Fitted intercept (0 if `opts.intercept === false`). */
|
|
15
|
+
intercept: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Ridge regression (L2-penalized least squares) with a closed-form solution on
|
|
19
|
+
* centered data: `β = (XᵀX + αI)⁻¹Xᵀy`. The intercept is never penalized.
|
|
20
|
+
*
|
|
21
|
+
* @param X - Design matrix (rows = observations, cols = predictors)
|
|
22
|
+
* @param y - Response vector (length = number of observations)
|
|
23
|
+
* @param alpha - L2 penalty strength (`alpha >= 0`; `alpha = 0` is OLS)
|
|
24
|
+
* @param opts - `intercept` (default true)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ridge([[1], [2], [3], [4]], [2, 4, 6, 8], 0)
|
|
28
|
+
* // => { coefficients: [2], intercept: 0 } (recovers the exact OLS fit)
|
|
29
|
+
*/
|
|
30
|
+
export declare function ridge(X: number[][], y: number[], alpha: number, opts?: RidgeOptions): RegularizedRegressionResult;
|
|
31
|
+
/**
|
|
32
|
+
* Lasso regression (L1-penalized least squares) via cyclic coordinate descent
|
|
33
|
+
* with soft-thresholding on standardized columns. Unlike ridge, large enough
|
|
34
|
+
* penalties drive coefficients to exactly 0 (sparse solutions). The intercept
|
|
35
|
+
* is never penalized.
|
|
36
|
+
*
|
|
37
|
+
* @param X - Design matrix (rows = observations, cols = predictors)
|
|
38
|
+
* @param y - Response vector (length = number of observations)
|
|
39
|
+
* @param alpha - L1 penalty strength (`alpha >= 0`; `alpha = 0` ~ OLS)
|
|
40
|
+
* @param opts - `intercept` (default true), `maxIter` (default 1000), `tol` (default 1e-7)
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* lasso([[1], [2], [3], [4]], [2, 4, 6, 8], 100)
|
|
44
|
+
* // => coefficients[0] === 0 (penalty overwhelms the signal)
|
|
45
|
+
*/
|
|
46
|
+
export declare function lasso(X: number[][], y: number[], alpha: number, opts?: CoordinateDescentOptions): RegularizedRegressionResult;
|
|
47
|
+
/**
|
|
48
|
+
* Elastic-net regression combining an L1 penalty (`alpha * l1Ratio`, soft-
|
|
49
|
+
* thresholded) and an L2 penalty (`alpha * (1 - l1Ratio)`, added to the
|
|
50
|
+
* coordinate-descent denominator) via the same cyclic coordinate descent as
|
|
51
|
+
* `lasso`. `l1Ratio = 1` is pure lasso; `l1Ratio = 0` is (coordinate-descent)
|
|
52
|
+
* ridge. The intercept is never penalized.
|
|
53
|
+
*
|
|
54
|
+
* @param X - Design matrix (rows = observations, cols = predictors)
|
|
55
|
+
* @param y - Response vector (length = number of observations)
|
|
56
|
+
* @param alpha - Overall penalty strength (`alpha >= 0`)
|
|
57
|
+
* @param l1Ratio - Mixing parameter in `[0, 1]` between L1 and L2
|
|
58
|
+
* @param opts - `intercept` (default true), `maxIter` (default 1000), `tol` (default 1e-7)
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* elasticNet([[1], [2], [3], [4]], [2, 4, 6, 8], 0.1, 0.5)
|
|
62
|
+
* // => finite coefficients blending ridge shrinkage and lasso sparsity
|
|
63
|
+
*/
|
|
64
|
+
export declare function elasticNet(X: number[][], y: number[], alpha: number, l1Ratio: number, opts?: CoordinateDescentOptions): RegularizedRegressionResult;
|
|
65
|
+
//# sourceMappingURL=regularized-regression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regularized-regression.d.ts","sourceRoot":"","sources":["../../src/ml/regularized-regression.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,YAAY;IAC3B,kEAAkE;IAClE,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,wBAAyB,SAAQ,YAAY;IAC5D,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,2BAA2B;IAC1C,0EAA0E;IAC1E,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC;CACnB;AAqDD;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CACnB,CAAC,EAAE,MAAM,EAAE,EAAE,EACb,CAAC,EAAE,MAAM,EAAE,EACX,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,YAAY,GAClB,2BAA2B,CAwB7B;AAyDD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CACnB,CAAC,EAAE,MAAM,EAAE,EAAE,EACb,CAAC,EAAE,MAAM,EAAE,EACX,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,wBAAwB,GAC9B,2BAA2B,CAc7B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CACxB,CAAC,EAAE,MAAM,EAAE,EAAE,EACb,CAAC,EAAE,MAAM,EAAE,EACX,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,wBAAwB,GAC9B,2BAA2B,CAiB7B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Result of {@link chi2Contingency}. */
|
|
2
|
+
export interface Chi2ContingencyResult {
|
|
3
|
+
chi2: number;
|
|
4
|
+
pValue: number;
|
|
5
|
+
dof: number;
|
|
6
|
+
expected: number[][];
|
|
7
|
+
cramersV: number;
|
|
8
|
+
}
|
|
9
|
+
/** Options for {@link chi2Contingency}. */
|
|
10
|
+
export interface Chi2ContingencyOptions {
|
|
11
|
+
/** Apply the Yates continuity correction on 2x2 tables. Default true (matches scipy). */
|
|
12
|
+
correction?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Chi-square test of independence on a contingency table.
|
|
16
|
+
*
|
|
17
|
+
* Expected counts `E_ij = rowSum_i * colSum_j / total`. `chi2 = sum((O_ij -
|
|
18
|
+
* E_ij)^2 / E_ij)`, with the Yates continuity correction
|
|
19
|
+
* `(|O_ij - E_ij| - 0.5)^2 / E_ij` applied on 2x2 tables when
|
|
20
|
+
* `opts.correction !== false` (default true, matching
|
|
21
|
+
* `scipy.stats.chi2_contingency`). `dof = (rows - 1) * (cols - 1)`; `pValue =
|
|
22
|
+
* 1 - chiSquaredCDF(chi2, dof)`. `cramersV = sqrt(chi2 / (total *
|
|
23
|
+
* min(rows-1, cols-1)))`.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* chi2Contingency([[10, 20], [30, 40]], { correction: false });
|
|
27
|
+
* // { chi2: 0.7937, pValue: 0.373, dof: 1, expected: [[12, 18], [28, 42]], cramersV }
|
|
28
|
+
*/
|
|
29
|
+
export declare function chi2Contingency(table: readonly (readonly number[])[], opts?: Chi2ContingencyOptions): Chi2ContingencyResult;
|
|
30
|
+
/** Supported multiple-testing correction methods. */
|
|
31
|
+
export type MultipleTestMethod = 'bonferroni' | 'holm' | 'bh';
|
|
32
|
+
/**
|
|
33
|
+
* Multiple-testing p-value adjustment, returned in the original input order.
|
|
34
|
+
* Matches `statsmodels.stats.multitest.multipletests`.
|
|
35
|
+
*
|
|
36
|
+
* - `bonferroni`: `min(1, p_i * n)`.
|
|
37
|
+
* - `holm` (step-down): sort ascending; adjusted_(k) = `min(1, max_{j<=k}
|
|
38
|
+
* (n - j + 1) * p_(j))`, enforced monotonic non-decreasing.
|
|
39
|
+
* - `bh` (Benjamini-Hochberg FDR, step-up): sort ascending; adjusted_(k) =
|
|
40
|
+
* `min(1, min_{j>=k} (n / j) * p_(j))`, enforced monotonic non-decreasing
|
|
41
|
+
* from the largest p-value down.
|
|
42
|
+
*
|
|
43
|
+
* @example multipleTest([0.01, 0.04, 0.5], 'bonferroni'); // [0.03, 0.12, 1]
|
|
44
|
+
*/
|
|
45
|
+
export declare function multipleTest(pValues: readonly number[], method: MultipleTestMethod): number[];
|
|
46
|
+
//# sourceMappingURL=inference-extra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference-extra.d.ts","sourceRoot":"","sources":["../../src/stats/inference-extra.ts"],"names":[],"mappings":"AAaA,yCAAyC;AACzC,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,2CAA2C;AAC3C,MAAM,WAAW,sBAAsB;IACrC,yFAAyF;IACzF,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EACrC,IAAI,GAAE,sBAA2B,GAChC,qBAAqB,CA0CvB;AAED,qDAAqD;AACrD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,MAAM,GAAG,IAAI,CAAC;AAE9D;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,kBAAkB,GAAG,MAAM,EAAE,CAiC7F"}
|
package/package.json
CHANGED