@numero-uno-jpn/rstats 0.11.0 → 0.11.1
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 +13 -0
- package/README.ja.md +5 -4
- package/README.md +6 -4
- package/dist/chunks/{chunk-YSWGDOWK.js → chunk-2X7JYQBI.js} +2 -2
- package/dist/chunks/{chunk-F5EDJFEO.js → chunk-36GVER3O.js} +2 -2
- package/dist/chunks/{chunk-7GQMKH3Z.js → chunk-3WUXRSM6.js} +1 -1
- package/dist/chunks/{chunk-JWBO5WVN.js → chunk-6I6QKTFK.js} +2 -2
- package/dist/chunks/{chunk-EZWBRCJL.js → chunk-ETOEZTGL.js} +1 -1
- package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-FVPDVRJQ.js} +2 -2
- package/dist/chunks/{chunk-EZAFN5CD.js → chunk-GG4BJMJW.js} +1 -1
- package/dist/chunks/{chunk-5WDJPHYY.js → chunk-HITD7CX6.js} +1 -1
- package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-KK4GE65D.js} +2 -2
- package/dist/chunks/{chunk-AHHS6AC4.js → chunk-LAUYSGV4.js} +2 -2
- package/dist/chunks/{chunk-ALM3VHFP.js → chunk-M6GDXKKS.js} +1 -1
- package/dist/chunks/{chunk-C5XTWMGB.js → chunk-PHHUHR7T.js} +1 -1
- package/dist/chunks/{chunk-TOGXTCZO.js → chunk-WQPFDDIY.js} +2 -2
- package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-X2AWQSVS.js} +2 -2
- package/dist/chunks/{chunk-Y5CNQ266.js → chunk-ZRJQD7VS.js} +2 -2
- package/dist/data/grouping.d.ts +33 -12
- package/dist/data/grouping.js +2 -0
- package/dist/descriptive/basic.d.ts +130 -17
- package/dist/descriptive/basic.js +115 -14
- package/dist/descriptive/cov.d.ts +22 -12
- package/dist/descriptive/dataFrames.d.ts +39 -11
- package/dist/descriptive/dataFrames.js +14 -6
- package/dist/descriptive/factanal.d.ts +26 -6
- package/dist/descriptive/factanal.js +7 -3
- package/dist/descriptive/hist.d.ts +27 -6
- package/dist/descriptive/hist.js +9 -3
- package/dist/descriptive/missing.d.ts +13 -6
- package/dist/descriptive/missing.js +4 -2
- package/dist/descriptive/moments.d.ts +91 -13
- package/dist/descriptive/moments.js +66 -9
- package/dist/descriptive/omega.d.ts +28 -6
- package/dist/descriptive/omega.js +16 -4
- package/dist/descriptive/pivot.d.ts +22 -6
- package/dist/descriptive/pivot.js +7 -3
- package/dist/descriptive/quantile.d.ts +33 -5
- package/dist/descriptive/quantile.js +20 -2
- package/dist/descriptive/rank.d.ts +12 -2
- package/dist/descriptive/rank.js +2 -0
- package/dist/descriptive/table.d.ts +55 -7
- package/dist/descriptive/table.js +38 -4
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.d.ts +40 -5
- package/dist/distributions/arcsine.js +35 -4
- package/dist/distributions/beta.d.ts +12 -0
- package/dist/distributions/beta.js +12 -0
- package/dist/distributions/binomial.d.ts +18 -0
- package/dist/distributions/binomial.js +18 -0
- package/dist/distributions/bvnorm.d.ts +4 -1
- package/dist/distributions/bvnorm.js +4 -1
- package/dist/distributions/cauchy.d.ts +24 -0
- package/dist/distributions/cauchy.js +24 -0
- package/dist/distributions/chisq.d.ts +18 -0
- package/dist/distributions/chisq.js +18 -0
- package/dist/distributions/exponential.d.ts +29 -1
- package/dist/distributions/exponential.js +24 -0
- package/dist/distributions/f.d.ts +18 -0
- package/dist/distributions/f.js +18 -0
- package/dist/distributions/gamma.d.ts +20 -0
- package/dist/distributions/gamma.js +18 -0
- package/dist/distributions/geometric.d.ts +24 -0
- package/dist/distributions/geometric.js +24 -0
- package/dist/distributions/hypergeometric.d.ts +24 -0
- package/dist/distributions/hypergeometric.js +24 -0
- package/dist/distributions/invgamma.d.ts +32 -4
- package/dist/distributions/invgamma.js +27 -3
- package/dist/distributions/kumaraswamy.d.ts +31 -3
- package/dist/distributions/kumaraswamy.js +31 -3
- package/dist/distributions/laplace.d.ts +36 -4
- package/dist/distributions/laplace.js +31 -3
- package/dist/distributions/logistic.d.ts +29 -1
- package/dist/distributions/logistic.js +24 -0
- package/dist/distributions/lognormal.d.ts +29 -1
- package/dist/distributions/lognormal.js +24 -0
- package/dist/distributions/multinomial.d.ts +7 -1
- package/dist/distributions/multinomial.js +2 -0
- package/dist/distributions/negbinomial.d.ts +29 -1
- package/dist/distributions/negbinomial.js +24 -0
- package/dist/distributions/normal.d.ts +11 -1
- package/dist/distributions/normal.js +6 -0
- package/dist/distributions/pareto.d.ts +36 -4
- package/dist/distributions/pareto.js +31 -3
- package/dist/distributions/poisson.d.ts +18 -0
- package/dist/distributions/poisson.js +18 -0
- package/dist/distributions/signrank.d.ts +24 -0
- package/dist/distributions/signrank.js +24 -0
- package/dist/distributions/summary.d.ts +20 -2
- package/dist/distributions/summary.js +4 -0
- package/dist/distributions/t.d.ts +18 -0
- package/dist/distributions/t.js +18 -0
- package/dist/distributions/triangular.d.ts +36 -4
- package/dist/distributions/triangular.js +31 -3
- package/dist/distributions/tukey.d.ts +15 -1
- package/dist/distributions/tukey.js +10 -0
- package/dist/distributions/uniform.d.ts +29 -1
- package/dist/distributions/uniform.js +24 -0
- package/dist/distributions/weibull.d.ts +29 -1
- package/dist/distributions/weibull.js +24 -0
- package/dist/distributions/wilcox.d.ts +24 -0
- package/dist/distributions/wilcox.js +24 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +1 -1
- package/dist/entries/numerics.d.ts +1 -1
- package/dist/entries/tests.js +1 -1
- package/dist/htest/agreement.d.ts +61 -23
- package/dist/htest/agreement.js +19 -9
- package/dist/htest/ansariTest.d.ts +8 -2
- package/dist/htest/aov.d.ts +43 -10
- package/dist/htest/aov.js +17 -3
- package/dist/htest/binomTest.d.ts +12 -2
- package/dist/htest/binomTest.js +2 -0
- package/dist/htest/brunnerMunzelTest.d.ts +9 -3
- package/dist/htest/brunnerMunzelTest.js +4 -2
- package/dist/htest/chisqTest.d.ts +19 -3
- package/dist/htest/cor.d.ts +20 -4
- package/dist/htest/effectSize.d.ts +70 -12
- package/dist/htest/effectSize.js +40 -7
- package/dist/htest/fisherTest.d.ts +9 -1
- package/dist/htest/fisherTest.js +2 -0
- package/dist/htest/groups.d.ts +5 -1
- package/dist/htest/ksTest.d.ts +20 -3
- package/dist/htest/leveneTest.d.ts +15 -4
- package/dist/htest/leveneTest.js +5 -2
- package/dist/htest/mantelhaenTest.d.ts +25 -3
- package/dist/htest/mantelhaenTest.js +15 -1
- package/dist/htest/mcnemarTest.d.ts +14 -4
- package/dist/htest/mcnemarTest.js +4 -2
- package/dist/htest/multipleComparisons.d.ts +173 -29
- package/dist/htest/multipleComparisons.js +123 -19
- package/dist/htest/normalityTests.d.ts +56 -9
- package/dist/htest/normalityTests.js +40 -6
- package/dist/htest/onewayTest.d.ts +32 -3
- package/dist/htest/onewayTest.js +10 -0
- package/dist/htest/pAdjust.d.ts +9 -1
- package/dist/htest/pAdjust.js +2 -0
- package/dist/htest/pairwise.d.ts +50 -5
- package/dist/htest/pairwise.js +25 -0
- package/dist/htest/poissonTest.d.ts +12 -2
- package/dist/htest/poissonTest.js +2 -0
- package/dist/htest/polycor.d.ts +29 -10
- package/dist/htest/power.d.ts +60 -6
- package/dist/htest/power.js +6 -0
- package/dist/htest/propTest.d.ts +13 -2
- package/dist/htest/propTest.js +2 -0
- package/dist/htest/pwr.d.ts +286 -36
- package/dist/htest/pwr.js +116 -15
- package/dist/htest/rankTests.d.ts +80 -12
- package/dist/htest/rankTests.js +11 -2
- package/dist/htest/tTest.d.ts +13 -3
- package/dist/htest/trendTests.d.ts +29 -8
- package/dist/htest/trendTests.js +8 -4
- package/dist/htest/types.d.ts +14 -2
- package/dist/htest/varTest.d.ts +25 -8
- package/dist/htest/wilcoxTest.d.ts +10 -2
- package/dist/internal/dpq.d.ts +4 -0
- package/dist/internal/noncentral.d.ts +2 -0
- package/dist/internal/vectorize.d.ts +4 -0
- package/dist/linalg/basic.d.ts +39 -5
- package/dist/linalg/basic.js +15 -0
- package/dist/linalg/chol.d.ts +26 -5
- package/dist/linalg/chol.js +7 -0
- package/dist/linalg/eigen.d.ts +16 -7
- package/dist/linalg/eigen.js +6 -5
- package/dist/linalg/expm.d.ts +15 -5
- package/dist/linalg/expm.js +5 -3
- package/dist/linalg/kappa.d.ts +21 -1
- package/dist/linalg/kappa.js +16 -0
- package/dist/linalg/lu.d.ts +30 -6
- package/dist/linalg/lu.js +15 -3
- package/dist/linalg/matrix.d.ts +4 -0
- package/dist/linalg/norm.d.ts +16 -1
- package/dist/linalg/norm.js +9 -0
- package/dist/linalg/ops.d.ts +156 -35
- package/dist/linalg/ops.js +96 -15
- package/dist/linalg/qr.d.ts +87 -12
- package/dist/linalg/qr.js +31 -0
- package/dist/linalg/schur.d.ts +8 -2
- package/dist/linalg/schur.js +3 -1
- package/dist/linalg/solve.d.ts +42 -6
- package/dist/linalg/solve.js +22 -0
- package/dist/linalg/svd.d.ts +12 -2
- package/dist/linalg/svd.js +2 -0
- package/dist/linalg.js +2 -2
- package/dist/models/anovaSequential.d.ts +26 -4
- package/dist/models/anovaSequential.js +3 -1
- package/dist/models/aovEz.d.ts +29 -6
- package/dist/models/aovEz.js +5 -2
- package/dist/models/aovStrata.d.ts +12 -2
- package/dist/models/carAnova.d.ts +9 -3
- package/dist/models/carAnova.js +4 -2
- package/dist/models/coxph.d.ts +33 -7
- package/dist/models/coxph.js +8 -3
- package/dist/models/glm.d.ts +128 -21
- package/dist/models/glm.js +71 -14
- package/dist/models/glmAnova.d.ts +30 -5
- package/dist/models/glmAnova.js +15 -2
- package/dist/models/glmConfint.d.ts +16 -2
- package/dist/models/glmConfint.js +9 -1
- package/dist/models/glmFamily.d.ts +27 -5
- package/dist/models/lm.d.ts +75 -17
- package/dist/models/lm.js +22 -4
- package/dist/models/mauchly.d.ts +20 -5
- package/dist/models/mauchly.js +7 -3
- package/dist/models/modelFrame.d.ts +5 -1
- package/dist/models/modelMatrix.d.ts +18 -4
- package/dist/models/modelMatrix.js +3 -1
- package/dist/models/survival.d.ts +41 -9
- package/dist/models/survival.js +10 -4
- package/dist/numerics/deriv.d.ts +21 -6
- package/dist/numerics/deriv.js +16 -5
- package/dist/numerics/integrate.d.ts +37 -7
- package/dist/numerics/integrate.js +8 -2
- package/dist/numerics/interp.d.ts +63 -12
- package/dist/numerics/interp.js +30 -6
- package/dist/numerics/ode.d.ts +15 -5
- package/dist/numerics/ode.js +5 -3
- package/dist/numerics.js +2 -2
- package/dist/optim/optim.d.ts +32 -8
- package/dist/optim/optim.js +8 -4
- package/dist/random/beta.d.ts +8 -0
- package/dist/random/beta.js +8 -0
- package/dist/random/binomial.d.ts +16 -0
- package/dist/random/binomial.js +16 -0
- package/dist/random/continuous.d.ts +51 -0
- package/dist/random/continuous.js +51 -0
- package/dist/random/extra.d.ts +66 -6
- package/dist/random/extra.js +66 -6
- package/dist/random/gamma.d.ts +33 -0
- package/dist/random/gamma.js +33 -0
- package/dist/random/hyper.d.ts +8 -0
- package/dist/random/hyper.js +8 -0
- package/dist/random/poisson.d.ts +25 -0
- package/dist/random/poisson.js +25 -0
- package/dist/random/r2dtable.d.ts +2 -0
- package/dist/random/r2dtable.js +2 -0
- package/dist/random/rank.d.ts +16 -0
- package/dist/random/rank.js +16 -0
- package/dist/random/rng.d.ts +49 -6
- package/dist/random/rng.js +29 -2
- package/dist/random/sample.d.ts +10 -2
- package/dist/random/sample.js +5 -1
- package/dist/random/streams.d.ts +13 -0
- package/dist/random/streams.js +13 -0
- package/dist/rstats.js +1 -1
- package/dist/special/besselIK.d.ts +11 -3
- package/dist/special/besselIK.js +6 -2
- package/dist/special/besselJY.d.ts +6 -2
- package/dist/special/besselJY.js +6 -2
- package/dist/special/beta.d.ts +16 -2
- package/dist/special/beta.js +16 -2
- package/dist/special/choose.d.ts +13 -5
- package/dist/special/choose.js +13 -5
- package/dist/special/erf.d.ts +8 -3
- package/dist/special/erf.js +8 -3
- package/dist/special/extra.d.ts +30 -10
- package/dist/special/extra.js +25 -9
- package/dist/special/gamma.d.ts +18 -2
- package/dist/special/gamma.js +18 -2
- package/dist/special/log1p.d.ts +16 -7
- package/dist/special/log1p.js +16 -7
- package/dist/special/psigamma.d.ts +9 -3
- package/dist/special/psigamma.js +9 -3
- package/dist/special/rCompatible.d.ts +5 -1
- package/dist/special.js +2 -2
- package/dist/tests.js +2 -2
- package/llms.txt +2 -0
- package/package.json +1 -1
|
@@ -1,28 +1,37 @@
|
|
|
1
|
+
import { type CorMethod } from "../htest/cor.js";
|
|
1
2
|
import type { Sample } from "../htest/types.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export type { CorMethod };
|
|
4
|
+
/**
|
|
5
|
+
* Handling of missing values, as R's `use`.
|
|
6
|
+
*
|
|
7
|
+
* @category Descriptive statistics
|
|
8
|
+
*/
|
|
5
9
|
export type CorUse = "everything" | "all.obs" | "complete.obs" | "na.or.complete" | "pairwise.complete.obs";
|
|
6
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Options for {@link cov} and {@link cor}.
|
|
12
|
+
*
|
|
13
|
+
* @category Descriptive statistics
|
|
14
|
+
*/
|
|
7
15
|
export interface CovOptions {
|
|
8
16
|
/** Default `"pearson"`. Unambiguous abbreviations are accepted. */
|
|
9
17
|
method?: CorMethod | (string & {});
|
|
10
18
|
/** Default `"everything"`. Unambiguous abbreviations are accepted. */
|
|
11
19
|
use?: CorUse | (string & {});
|
|
12
20
|
}
|
|
13
|
-
type Input = Sample | readonly (readonly number[])[];
|
|
14
21
|
/**
|
|
15
22
|
* Covariance of two vectors, or covariance matrix of the columns of a matrix (or between the columns of `x` and `y`).
|
|
16
23
|
* Equivalent to R's `cov()`.
|
|
17
24
|
*
|
|
18
25
|
* @example
|
|
19
26
|
* ```ts
|
|
20
|
-
* cov([1, 2, 3, 4], [2, 4, 5, 9]);
|
|
21
|
-
* cov([[1, 2], [2, 4], [3, 5], [4, 9]]); //
|
|
27
|
+
* cov([1, 2, 3, 4], [2, 4, 5, 9]); // 3.6666666666666665
|
|
28
|
+
* cov([[1, 2], [2, 4], [3, 5], [4, 9]]); // [[1.6666666666666667, 3.6666666666666665], [3.6666666666666665, 8.666666666666666]]
|
|
22
29
|
* ```
|
|
30
|
+
*
|
|
31
|
+
* @category Descriptive statistics
|
|
23
32
|
*/
|
|
24
33
|
export declare function cov(x: Sample, y: Sample, options?: CovOptions): number;
|
|
25
|
-
export declare function cov(x:
|
|
34
|
+
export declare function cov(x: Sample | readonly (readonly number[])[], y?: Sample | readonly (readonly number[])[], options?: CovOptions): number | number[][];
|
|
26
35
|
/**
|
|
27
36
|
* Correlation of two vectors, or correlation matrix of the columns of a matrix (or between the columns of `x` and
|
|
28
37
|
* `y`). Equivalent to R's `cor()`. Pearson correlations are computed in double-double, so they can be slightly more
|
|
@@ -30,10 +39,11 @@ export declare function cov(x: Input, y?: Input, options?: CovOptions): number |
|
|
|
30
39
|
*
|
|
31
40
|
* @example
|
|
32
41
|
* ```ts
|
|
33
|
-
* cor([1, 2, 3, 4], [2, 4, 5, 9]);
|
|
34
|
-
* cor([1, 2, 3, 4], [2, 4, 5, 9], { method: "spearman" });
|
|
42
|
+
* cor([1, 2, 3, 4], [2, 4, 5, 9]); // 0.9647638212377322
|
|
43
|
+
* cor([1, 2, 3, 4], [2, 4, 5, 9], { method: "spearman" }); // 1
|
|
35
44
|
* ```
|
|
45
|
+
*
|
|
46
|
+
* @category Descriptive statistics
|
|
36
47
|
*/
|
|
37
48
|
export declare function cor(x: Sample, y: Sample, options?: CovOptions): number;
|
|
38
|
-
export declare function cor(x:
|
|
39
|
-
export {};
|
|
49
|
+
export declare function cor(x: Sample | readonly (readonly number[])[], y?: Sample | readonly (readonly number[])[], options?: CovOptions): number | number[][];
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { type DataFrame } from "../models/modelFrame.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* One value of a data frame column (`null`: missing).
|
|
4
|
+
*
|
|
5
|
+
* @category Data frames
|
|
6
|
+
*/
|
|
3
7
|
export type DataValue = number | string | boolean | null;
|
|
4
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* A row of a data frame, as passed to the condition of {@link subset}: column name to value.
|
|
10
|
+
*
|
|
11
|
+
* @category Data frames
|
|
12
|
+
*/
|
|
5
13
|
export type DataRow = Record<string, DataValue>;
|
|
6
14
|
/** One column of a data frame. */
|
|
7
15
|
export type Column = DataFrame[string];
|
|
@@ -14,7 +22,11 @@ export declare function pick(col: Column, rows: readonly number[]): Column;
|
|
|
14
22
|
export declare function addColumn(out: DataFrame, name: string, col: Column): void;
|
|
15
23
|
/** Comparison of two values for sorting: numbers as numbers, text by code point, FALSE before TRUE, missing last */
|
|
16
24
|
export declare function compareValues(a: DataValue, b: DataValue): number;
|
|
17
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Options for {@link merge}.
|
|
27
|
+
*
|
|
28
|
+
* @category Data frames
|
|
29
|
+
*/
|
|
18
30
|
export interface MergeOptions {
|
|
19
31
|
/** The key columns, in both frames. Default: the column names common to both, in x's order. */
|
|
20
32
|
by?: string | readonly string[];
|
|
@@ -34,8 +46,8 @@ export interface MergeOptions {
|
|
|
34
46
|
suffixes?: readonly [string, string];
|
|
35
47
|
}
|
|
36
48
|
/**
|
|
37
|
-
* Join two data frames on key columns. Equivalent to R's `merge()
|
|
38
|
-
* equal keys (missing keys match each other), and with `allX` / `allY` the rows without a match. Columns: the keys
|
|
49
|
+
* Join two data frames on key columns. Equivalent to R's `merge()`. For data frames: every pair of rows of x and y
|
|
50
|
+
* with equal keys (missing keys match each other), and with `allX` / `allY` the rows without a match. Columns: the keys
|
|
39
51
|
* (named as in x), x's other columns, y's other columns; a non-key name present in both gets the suffixes. Rows are
|
|
40
52
|
* ordered by the key unless `sort` is false (several keys: as text joined with "\r" unless `allX` or `allY`, as R
|
|
41
53
|
* does); without key columns, the cross join (x varying fastest).
|
|
@@ -47,16 +59,22 @@ export interface MergeOptions {
|
|
|
47
59
|
* merge(x, y); // { id: [1, 2, 2], v: [20, 30, 30], w: [0.5, 1.5, 2.5] }
|
|
48
60
|
* merge(x, y, { all: true }); // also id 3 (w missing) and id 4 (v missing)
|
|
49
61
|
* ```
|
|
62
|
+
*
|
|
63
|
+
* @category Data frames
|
|
50
64
|
*/
|
|
51
65
|
export declare function merge(x: DataFrame, y: DataFrame, options?: MergeOptions): DataFrame;
|
|
52
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Options for {@link subset}.
|
|
68
|
+
*
|
|
69
|
+
* @category Data frames
|
|
70
|
+
*/
|
|
53
71
|
export interface SubsetOptions {
|
|
54
72
|
/** The columns to keep, in this order. Default: all, in their order. */
|
|
55
73
|
select?: readonly string[];
|
|
56
74
|
}
|
|
57
75
|
/**
|
|
58
|
-
* The rows of a data frame that meet a condition, and optionally some of its columns. Equivalent to R's `subset()
|
|
59
|
-
*
|
|
76
|
+
* The rows of a data frame that meet a condition, and optionally some of its columns. Equivalent to R's `subset()`.
|
|
77
|
+
* For a data frame: `keep` is a boolean per row or a function of the row; a missing (`null`) or non-boolean result
|
|
60
78
|
* counts as false, as R drops the rows whose condition is NA.
|
|
61
79
|
*
|
|
62
80
|
* @example
|
|
@@ -65,6 +83,8 @@ export interface SubsetOptions {
|
|
|
65
83
|
* subset(d, (row) => (row.y as number) > 4); // { y: [5, 7], g: ["a", "a"] }
|
|
66
84
|
* subset(d, [true, true, false, false], { select: ["g"] }); // { g: ["a", "b"] }
|
|
67
85
|
* ```
|
|
86
|
+
*
|
|
87
|
+
* @category Data frames
|
|
68
88
|
*/
|
|
69
89
|
export declare function subset(data: DataFrame, keep: readonly (boolean | null)[] | ((row: DataRow) => boolean | null | undefined), options?: SubsetOptions): DataFrame;
|
|
70
90
|
/**
|
|
@@ -77,7 +97,11 @@ export declare function rbindFrames(frames: readonly DataFrame[]): DataFrame;
|
|
|
77
97
|
* {@link cbind}. A column name that occurs twice is an error (an object cannot hold two columns of the same name).
|
|
78
98
|
*/
|
|
79
99
|
export declare function cbindFrames(frames: readonly DataFrame[]): DataFrame;
|
|
80
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Options of {@link fromRows}.
|
|
102
|
+
*
|
|
103
|
+
* @category Data frames
|
|
104
|
+
*/
|
|
81
105
|
export interface FromRowsOptions {
|
|
82
106
|
/**
|
|
83
107
|
* The columns to take, in this order. Default: every key that occurs in some row, in the order of first
|
|
@@ -89,22 +113,26 @@ export interface FromRowsOptions {
|
|
|
89
113
|
* A data frame (an object of columns) from an array of row objects, the usual shape of JSON and of parsed CSV:
|
|
90
114
|
* `[{ age: 30, score: 5 }, { age: 41, score: 7 }]` becomes `{ age: [30, 41], score: [5, 7] }`. A key that a row
|
|
91
115
|
* lacks, and `undefined`, become `null` (a missing value). Values must be numbers, strings, booleans or `null`, and
|
|
92
|
-
* one column may not mix numbers, strings and booleans. Not an R function
|
|
116
|
+
* one column may not mix numbers, strings and booleans. Not an R function. R reads data as data frames directly.
|
|
93
117
|
*
|
|
94
118
|
* @example
|
|
95
119
|
* ```ts
|
|
96
120
|
* fromRows([{ id: "a", score: 5 }, { id: "b" }]); // { id: ["a", "b"], score: [5, null] }
|
|
97
121
|
* ```
|
|
122
|
+
*
|
|
123
|
+
* @category Data frames
|
|
98
124
|
*/
|
|
99
125
|
export declare function fromRows(rows: readonly Readonly<Record<string, unknown>>[], options?: FromRowsOptions): DataFrame;
|
|
100
126
|
/**
|
|
101
127
|
* The rows of a data frame as an array of objects, the inverse of {@link fromRows}: `{ age: [30, 41], score: [5, 7]
|
|
102
128
|
* }` becomes `[{ age: 30, score: 5 }, { age: 41, score: 7 }]`. Missing values stay as they are (`null`, or `NaN` in a
|
|
103
|
-
* numeric column).
|
|
129
|
+
* numeric column). Not an R function. R keeps data in data frames and has no need for row objects.
|
|
104
130
|
*
|
|
105
131
|
* @example
|
|
106
132
|
* ```ts
|
|
107
133
|
* toRows({ id: ["a", "b"], score: [5, null] }); // [{ id: "a", score: 5 }, { id: "b", score: null }]
|
|
108
134
|
* ```
|
|
135
|
+
*
|
|
136
|
+
* @category Data frames
|
|
109
137
|
*/
|
|
110
138
|
export declare function toRows(data: DataFrame): DataRow[];
|
|
@@ -150,8 +150,8 @@ function keyColumns(frame, names) {
|
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
|
-
* Join two data frames on key columns. Equivalent to R's `merge()
|
|
154
|
-
* equal keys (missing keys match each other), and with `allX` / `allY` the rows without a match. Columns: the keys
|
|
153
|
+
* Join two data frames on key columns. Equivalent to R's `merge()`. For data frames: every pair of rows of x and y
|
|
154
|
+
* with equal keys (missing keys match each other), and with `allX` / `allY` the rows without a match. Columns: the keys
|
|
155
155
|
* (named as in x), x's other columns, y's other columns; a non-key name present in both gets the suffixes. Rows are
|
|
156
156
|
* ordered by the key unless `sort` is false (several keys: as text joined with "\r" unless `allX` or `allY`, as R
|
|
157
157
|
* does); without key columns, the cross join (x varying fastest).
|
|
@@ -163,6 +163,8 @@ function keyColumns(frame, names) {
|
|
|
163
163
|
* merge(x, y); // { id: [1, 2, 2], v: [20, 30, 30], w: [0.5, 1.5, 2.5] }
|
|
164
164
|
* merge(x, y, { all: true }); // also id 3 (w missing) and id 4 (v missing)
|
|
165
165
|
* ```
|
|
166
|
+
*
|
|
167
|
+
* @category Data frames
|
|
166
168
|
*/
|
|
167
169
|
export function merge(x, y, options = {}) {
|
|
168
170
|
const xNames = Object.keys(x);
|
|
@@ -266,8 +268,8 @@ export function merge(x, y, options = {}) {
|
|
|
266
268
|
return out;
|
|
267
269
|
}
|
|
268
270
|
/**
|
|
269
|
-
* The rows of a data frame that meet a condition, and optionally some of its columns. Equivalent to R's `subset()
|
|
270
|
-
*
|
|
271
|
+
* The rows of a data frame that meet a condition, and optionally some of its columns. Equivalent to R's `subset()`.
|
|
272
|
+
* For a data frame: `keep` is a boolean per row or a function of the row; a missing (`null`) or non-boolean result
|
|
271
273
|
* counts as false, as R drops the rows whose condition is NA.
|
|
272
274
|
*
|
|
273
275
|
* @example
|
|
@@ -276,6 +278,8 @@ export function merge(x, y, options = {}) {
|
|
|
276
278
|
* subset(d, (row) => (row.y as number) > 4); // { y: [5, 7], g: ["a", "a"] }
|
|
277
279
|
* subset(d, [true, true, false, false], { select: ["g"] }); // { g: ["a", "b"] }
|
|
278
280
|
* ```
|
|
281
|
+
*
|
|
282
|
+
* @category Data frames
|
|
279
283
|
*/
|
|
280
284
|
export function subset(data, keep, options = {}) {
|
|
281
285
|
const names = Object.keys(data);
|
|
@@ -340,12 +344,14 @@ export function cbindFrames(frames) {
|
|
|
340
344
|
* A data frame (an object of columns) from an array of row objects, the usual shape of JSON and of parsed CSV:
|
|
341
345
|
* `[{ age: 30, score: 5 }, { age: 41, score: 7 }]` becomes `{ age: [30, 41], score: [5, 7] }`. A key that a row
|
|
342
346
|
* lacks, and `undefined`, become `null` (a missing value). Values must be numbers, strings, booleans or `null`, and
|
|
343
|
-
* one column may not mix numbers, strings and booleans. Not an R function
|
|
347
|
+
* one column may not mix numbers, strings and booleans. Not an R function. R reads data as data frames directly.
|
|
344
348
|
*
|
|
345
349
|
* @example
|
|
346
350
|
* ```ts
|
|
347
351
|
* fromRows([{ id: "a", score: 5 }, { id: "b" }]); // { id: ["a", "b"], score: [5, null] }
|
|
348
352
|
* ```
|
|
353
|
+
*
|
|
354
|
+
* @category Data frames
|
|
349
355
|
*/
|
|
350
356
|
export function fromRows(rows, options = {}) {
|
|
351
357
|
let names = options.columns;
|
|
@@ -378,12 +384,14 @@ export function fromRows(rows, options = {}) {
|
|
|
378
384
|
/**
|
|
379
385
|
* The rows of a data frame as an array of objects, the inverse of {@link fromRows}: `{ age: [30, 41], score: [5, 7]
|
|
380
386
|
* }` becomes `[{ age: 30, score: 5 }, { age: 41, score: 7 }]`. Missing values stay as they are (`null`, or `NaN` in a
|
|
381
|
-
* numeric column).
|
|
387
|
+
* numeric column). Not an R function. R keeps data in data frames and has no need for row objects.
|
|
382
388
|
*
|
|
383
389
|
* @example
|
|
384
390
|
* ```ts
|
|
385
391
|
* toRows({ id: ["a", "b"], score: [5, null] }); // [{ id: "a", score: 5 }, { id: "b", score: null }]
|
|
386
392
|
* ```
|
|
393
|
+
*
|
|
394
|
+
* @category Data frames
|
|
387
395
|
*/
|
|
388
396
|
export function toRows(data) {
|
|
389
397
|
const names = Object.keys(data);
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Rotations of {@link factanal}
|
|
3
|
+
*
|
|
4
|
+
* @category Agreement, reliability and factor analysis
|
|
5
|
+
*/
|
|
2
6
|
export type FactanalRotation = "varimax" | "promax" | "none";
|
|
3
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Options of {@link factanal}
|
|
9
|
+
*
|
|
10
|
+
* @category Agreement, reliability and factor analysis
|
|
11
|
+
*/
|
|
4
12
|
export interface FactanalOptions {
|
|
5
13
|
/** A covariance (or correlation) matrix to analyse instead of the data `x` (pass `null` as `x`). */
|
|
6
14
|
covmat?: readonly (readonly number[])[];
|
|
@@ -8,6 +16,7 @@ export interface FactanalOptions {
|
|
|
8
16
|
nObs?: number;
|
|
9
17
|
/** Default `"varimax"`. */
|
|
10
18
|
rotation?: FactanalRotation;
|
|
19
|
+
/** Settings of the optimisation (part of R's `control` list). */
|
|
11
20
|
control?: {
|
|
12
21
|
/** Lower bound of the uniquenesses. Default 0.005. */
|
|
13
22
|
lower?: number;
|
|
@@ -15,8 +24,13 @@ export interface FactanalOptions {
|
|
|
15
24
|
start?: readonly number[];
|
|
16
25
|
};
|
|
17
26
|
}
|
|
18
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Result of {@link factanal}
|
|
29
|
+
*
|
|
30
|
+
* @category Agreement, reliability and factor analysis
|
|
31
|
+
*/
|
|
19
32
|
export interface FactanalResult {
|
|
33
|
+
/** The uniquenesses, one per variable: the variance not explained by the factors. */
|
|
20
34
|
uniquenesses: number[];
|
|
21
35
|
/** The (rotated) loadings, p rows by `factors` columns, columns sorted by decreasing sum of squares, each column's sum positive */
|
|
22
36
|
loadings: number[][];
|
|
@@ -24,9 +38,11 @@ export interface FactanalResult {
|
|
|
24
38
|
rotmat?: number[][];
|
|
25
39
|
/** The likelihood-ratio statistic (NaN without n.obs or with no degrees of freedom) */
|
|
26
40
|
STATISTIC: number;
|
|
41
|
+
/** Degrees of freedom of the statistic, ((p - factors)^2 - (p + factors)) / 2. */
|
|
27
42
|
dof: number;
|
|
28
43
|
/** Its upper chi-squared tail probability (NaN as STATISTIC) */
|
|
29
44
|
PVAL: number;
|
|
45
|
+
/** Whether the optimisation converged. */
|
|
30
46
|
converged: boolean;
|
|
31
47
|
/** The minimised criterion */
|
|
32
48
|
objective: number;
|
|
@@ -42,15 +58,19 @@ export declare function varimax(L: readonly (readonly number[])[]): {
|
|
|
42
58
|
};
|
|
43
59
|
/**
|
|
44
60
|
* Maximum-likelihood factor analysis of a data matrix (rows are observations) or, with `options.covmat`, of a
|
|
45
|
-
* covariance matrix. Equivalent to R's `factanal()
|
|
61
|
+
* covariance matrix. Equivalent to R's `factanal()`. With `rotation` `"varimax"`, `"promax"` or `"none"`.
|
|
46
62
|
*
|
|
47
63
|
* @param x The data matrix (array of rows), or `null` with `options.covmat`.
|
|
48
64
|
* @param factors The number of factors.
|
|
49
65
|
*
|
|
50
66
|
* @example
|
|
51
67
|
* ```ts
|
|
52
|
-
* const
|
|
53
|
-
*
|
|
68
|
+
* const R = [[1, 0.72, 0.63], [0.72, 1, 0.56], [0.63, 0.56, 1]];
|
|
69
|
+
* const fa = factanal(null, 1, { covmat: R });
|
|
70
|
+
* fa.uniquenesses; // [0.19, 0.36, 0.51]
|
|
71
|
+
* fa.loadings; // [[0.9], [0.8], [0.7]]
|
|
54
72
|
* ```
|
|
73
|
+
*
|
|
74
|
+
* @category Agreement, reliability and factor analysis
|
|
55
75
|
*/
|
|
56
76
|
export declare function factanal(x: readonly (readonly number[])[] | null, factors: number, options?: FactanalOptions): FactanalResult;
|
|
@@ -92,16 +92,20 @@ function promax(L) {
|
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Maximum-likelihood factor analysis of a data matrix (rows are observations) or, with `options.covmat`, of a
|
|
95
|
-
* covariance matrix. Equivalent to R's `factanal()
|
|
95
|
+
* covariance matrix. Equivalent to R's `factanal()`. With `rotation` `"varimax"`, `"promax"` or `"none"`.
|
|
96
96
|
*
|
|
97
97
|
* @param x The data matrix (array of rows), or `null` with `options.covmat`.
|
|
98
98
|
* @param factors The number of factors.
|
|
99
99
|
*
|
|
100
100
|
* @example
|
|
101
101
|
* ```ts
|
|
102
|
-
* const
|
|
103
|
-
*
|
|
102
|
+
* const R = [[1, 0.72, 0.63], [0.72, 1, 0.56], [0.63, 0.56, 1]];
|
|
103
|
+
* const fa = factanal(null, 1, { covmat: R });
|
|
104
|
+
* fa.uniquenesses; // [0.19, 0.36, 0.51]
|
|
105
|
+
* fa.loadings; // [[0.9], [0.8], [0.7]]
|
|
104
106
|
* ```
|
|
107
|
+
*
|
|
108
|
+
* @category Agreement, reliability and factor analysis
|
|
105
109
|
*/
|
|
106
110
|
export function factanal(x, factors, options = {}) {
|
|
107
111
|
let cv;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { Sample } from "../htest/types.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link pretty}.
|
|
4
|
+
*
|
|
5
|
+
* @category Descriptive statistics
|
|
6
|
+
*/
|
|
3
7
|
export interface PrettyOptions {
|
|
4
8
|
/** Desired number of intervals. Default `5`. */
|
|
5
9
|
n?: number;
|
|
@@ -20,9 +24,15 @@ export interface PrettyOptions {
|
|
|
20
24
|
* ```ts
|
|
21
25
|
* pretty([0.3, 9.6]); // [0, 2, 4, 6, 8, 10]
|
|
22
26
|
* ```
|
|
27
|
+
*
|
|
28
|
+
* @category Descriptive statistics
|
|
23
29
|
*/
|
|
24
30
|
export declare function pretty(x: Sample, options?: PrettyOptions): number[];
|
|
25
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Options for {@link hist}.
|
|
33
|
+
*
|
|
34
|
+
* @category Descriptive statistics
|
|
35
|
+
*/
|
|
26
36
|
export interface HistOptions {
|
|
27
37
|
/**
|
|
28
38
|
* Break points, a number of cells (a suggestion for pretty), or a rule: `"Sturges"` (default), `"Scott"` or
|
|
@@ -34,22 +44,31 @@ export interface HistOptions {
|
|
|
34
44
|
/** Close the first cell on the left (the last on the right when `right` is false). Default `true`. */
|
|
35
45
|
includeLowest?: boolean;
|
|
36
46
|
}
|
|
37
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Result of {@link hist}.
|
|
49
|
+
*
|
|
50
|
+
* @category Descriptive statistics
|
|
51
|
+
*/
|
|
38
52
|
export interface HistResult {
|
|
53
|
+
/** The cell boundaries, one more than the cells. */
|
|
39
54
|
breaks: number[];
|
|
55
|
+
/** Number of values in each cell. */
|
|
40
56
|
counts: number[];
|
|
41
57
|
/** counts / (n * cell width) */
|
|
42
58
|
density: number[];
|
|
59
|
+
/** Cell midpoints. */
|
|
43
60
|
mids: number[];
|
|
44
61
|
}
|
|
45
62
|
/**
|
|
46
|
-
* Histogram counts. Equivalent to R's `hist(x, plot = FALSE)
|
|
63
|
+
* Histogram counts. Equivalent to R's `hist(x, plot = FALSE)`. Break points (by default pretty points over the range
|
|
47
64
|
* with about Sturges' number of cells), counts, densities and cell midpoints. Non-finite values are dropped.
|
|
48
65
|
*
|
|
49
66
|
* @example
|
|
50
67
|
* ```ts
|
|
51
|
-
* hist([1, 2, 2, 3, 3, 3, 4]).counts; // [3, 3, 1] for breaks [1, 2, 3, 4]
|
|
68
|
+
* hist([1, 2, 2, 3, 3, 3, 4]).counts; // [3, 3, 1] (for breaks [1, 2, 3, 4])
|
|
52
69
|
* ```
|
|
70
|
+
*
|
|
71
|
+
* @category Descriptive statistics
|
|
53
72
|
*/
|
|
54
73
|
export declare function hist(x: Sample, options?: HistOptions): HistResult;
|
|
55
74
|
/**
|
|
@@ -58,7 +77,9 @@ export declare function hist(x: Sample, options?: HistOptions): HistResult;
|
|
|
58
77
|
*
|
|
59
78
|
* @example
|
|
60
79
|
* ```ts
|
|
61
|
-
* ecdf([3, 1, 2])(2); //
|
|
80
|
+
* ecdf([3, 1, 2])(2); // 0.6666666666666666
|
|
62
81
|
* ```
|
|
82
|
+
*
|
|
83
|
+
* @category Descriptive statistics
|
|
63
84
|
*/
|
|
64
85
|
export declare function ecdf(x: Sample): (q: number) => number;
|
package/dist/descriptive/hist.js
CHANGED
|
@@ -19,6 +19,8 @@ import { seqLength } from "../internal/seq.js";
|
|
|
19
19
|
* ```ts
|
|
20
20
|
* pretty([0.3, 9.6]); // [0, 2, 4, 6, 8, 10]
|
|
21
21
|
* ```
|
|
22
|
+
*
|
|
23
|
+
* @category Descriptive statistics
|
|
22
24
|
*/
|
|
23
25
|
export function pretty(x, options = {}) {
|
|
24
26
|
const finite = Array.from(x).filter(Number.isFinite);
|
|
@@ -176,13 +178,15 @@ function fuzzScale(br, dataRange) {
|
|
|
176
178
|
return Math.min(...widths.filter((w) => w > 0));
|
|
177
179
|
}
|
|
178
180
|
/**
|
|
179
|
-
* Histogram counts. Equivalent to R's `hist(x, plot = FALSE)
|
|
181
|
+
* Histogram counts. Equivalent to R's `hist(x, plot = FALSE)`. Break points (by default pretty points over the range
|
|
180
182
|
* with about Sturges' number of cells), counts, densities and cell midpoints. Non-finite values are dropped.
|
|
181
183
|
*
|
|
182
184
|
* @example
|
|
183
185
|
* ```ts
|
|
184
|
-
* hist([1, 2, 2, 3, 3, 3, 4]).counts; // [3, 3, 1] for breaks [1, 2, 3, 4]
|
|
186
|
+
* hist([1, 2, 2, 3, 3, 3, 4]).counts; // [3, 3, 1] (for breaks [1, 2, 3, 4])
|
|
185
187
|
* ```
|
|
188
|
+
*
|
|
189
|
+
* @category Descriptive statistics
|
|
186
190
|
*/
|
|
187
191
|
export function hist(x, options = {}) {
|
|
188
192
|
const xs = Array.from(x).filter(Number.isFinite);
|
|
@@ -277,8 +281,10 @@ function cellOf(v, f, right, includeLowest) {
|
|
|
277
281
|
*
|
|
278
282
|
* @example
|
|
279
283
|
* ```ts
|
|
280
|
-
* ecdf([3, 1, 2])(2); //
|
|
284
|
+
* ecdf([3, 1, 2])(2); // 0.6666666666666666
|
|
281
285
|
* ```
|
|
286
|
+
*
|
|
287
|
+
* @category Descriptive statistics
|
|
282
288
|
*/
|
|
283
289
|
export function ecdf(x) {
|
|
284
290
|
const s = Array.from(x)
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { DataFrame } from "../models/modelFrame.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* A vector: numbers (`NaN` missing), or strings, booleans or numbers with `null` for a missing value.
|
|
4
|
+
*
|
|
5
|
+
* @category Data frames
|
|
6
|
+
*/
|
|
3
7
|
export type MissingVector = readonly (number | string | boolean | null)[] | Float64Array;
|
|
4
8
|
/**
|
|
5
|
-
* Which rows have no missing value. Equivalent to R's `complete.cases()
|
|
6
|
-
* any argument is missing (`null`, or `NaN` in a numeric column) in that row.
|
|
9
|
+
* Which rows have no missing value. Equivalent to R's `complete.cases()`. One boolean per row, true when no column
|
|
10
|
+
* of any argument is missing (`null`, or `NaN` in a numeric column) in that row.
|
|
7
11
|
*
|
|
8
12
|
* @param args Data frames (objects of equal-length columns) or arrays, all with the same number of rows.
|
|
9
13
|
*
|
|
@@ -11,21 +15,24 @@ export type MissingVector = readonly (number | string | boolean | null)[] | Floa
|
|
|
11
15
|
* ```ts
|
|
12
16
|
* completeCases({ a: [1, NaN, 3], s: ["u", "v", null] }); // [true, false, false]
|
|
13
17
|
* ```
|
|
18
|
+
*
|
|
19
|
+
* @category Data frames
|
|
14
20
|
*/
|
|
15
21
|
export declare function completeCases(...args: (MissingVector | DataFrame)[]): boolean[];
|
|
16
22
|
/**
|
|
17
|
-
* The values that are not missing. Equivalent to R's `na.omit()
|
|
23
|
+
* The values that are not missing. Equivalent to R's `na.omit()`. For a vector.
|
|
18
24
|
*
|
|
19
25
|
* @example
|
|
20
26
|
* ```ts
|
|
21
27
|
* naOmit([1, NaN, 3]); // [1, 3]
|
|
22
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @category Data frames
|
|
23
31
|
*/
|
|
24
32
|
export declare function naOmit(x: readonly number[] | Float64Array): number[];
|
|
25
33
|
export declare function naOmit<T extends string | boolean | number>(x: readonly (T | null)[]): T[];
|
|
26
34
|
/**
|
|
27
|
-
* The complete rows of a data frame
|
|
28
|
-
* restricted to the rows where none is missing (`null`, or `NaN` in a numeric column); see {@link completeCases}.
|
|
35
|
+
* The complete rows of a data frame, as R's `na.omit()` for a data frame: the same columns, in order, restricted to the rows where none is missing (`null`, or `NaN` in a numeric column); see {@link completeCases}.
|
|
29
36
|
*
|
|
30
37
|
* @example
|
|
31
38
|
* ```ts
|
|
@@ -17,8 +17,8 @@ function columnsOf(x) {
|
|
|
17
17
|
return { columns, rows };
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Which rows have no missing value. Equivalent to R's `complete.cases()
|
|
21
|
-
* any argument is missing (`null`, or `NaN` in a numeric column) in that row.
|
|
20
|
+
* Which rows have no missing value. Equivalent to R's `complete.cases()`. One boolean per row, true when no column
|
|
21
|
+
* of any argument is missing (`null`, or `NaN` in a numeric column) in that row.
|
|
22
22
|
*
|
|
23
23
|
* @param args Data frames (objects of equal-length columns) or arrays, all with the same number of rows.
|
|
24
24
|
*
|
|
@@ -26,6 +26,8 @@ function columnsOf(x) {
|
|
|
26
26
|
* ```ts
|
|
27
27
|
* completeCases({ a: [1, NaN, 3], s: ["u", "v", null] }); // [true, false, false]
|
|
28
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @category Data frames
|
|
29
31
|
*/
|
|
30
32
|
export function completeCases(...args) {
|
|
31
33
|
if (args.length === 0)
|