@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,48 +1,116 @@
|
|
|
1
1
|
import { type NaRmOptions } from "./basic.js";
|
|
2
2
|
import type { Sample } from "../htest/types.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link skewness} and {@link kurtosis}.
|
|
5
|
+
*
|
|
6
|
+
* @category Descriptive statistics
|
|
7
|
+
*/
|
|
4
8
|
export interface MomentOptions {
|
|
5
9
|
/** e1071's type: 1, 2 or 3. Default `3`. */
|
|
6
10
|
type?: 1 | 2 | 3;
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
|
-
* Sample skewness. Equivalent to `e1071::skewness()`
|
|
13
|
+
* Sample skewness. Equivalent to `e1071::skewness()` in R. Missing values are dropped; `{ type: 1 }` is jStat's
|
|
14
|
+
* skewness.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* skewness([1, 2, 3, 10]); // 0.6614
|
|
19
|
+
* skewness([1, 2, 3, 10], { type: 2 }); // 1.7636
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @category Descriptive statistics
|
|
10
23
|
*/
|
|
11
24
|
export declare function skewness(x: Sample, options?: MomentOptions): number;
|
|
12
25
|
/**
|
|
13
|
-
* Sample excess kurtosis. Equivalent to `e1071::kurtosis()`
|
|
14
|
-
* kurtosis.
|
|
26
|
+
* Sample excess kurtosis. Equivalent to `e1071::kurtosis()` in R. Missing values are dropped; `{ type: 1 }` is
|
|
27
|
+
* jStat's kurtosis.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* kurtosis([1, 2, 3, 10]); // -1.7454
|
|
32
|
+
* kurtosis([1, 2, 3, 10], { type: 1 }); // -0.7696
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @category Descriptive statistics
|
|
15
36
|
*/
|
|
16
37
|
export declare function kurtosis(x: Sample, options?: MomentOptions): number;
|
|
17
38
|
/**
|
|
18
|
-
* Geometric mean exp(mean(log x)). Equivalent to `DescTools::Gmean()
|
|
39
|
+
* Geometric mean exp(mean(log x)). Equivalent to `DescTools::Gmean()` in R. NaN with a negative value, 0 with a
|
|
40
|
+
* zero.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* geometricMean([1, 2, 4, 8]); // 2.82842712474619
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @category Descriptive statistics
|
|
19
48
|
*/
|
|
20
49
|
export declare function geometricMean(x: Sample, options?: NaRmOptions): number;
|
|
21
50
|
/**
|
|
22
|
-
* The most frequent values (all of them, in increasing order) and their frequency. Equivalent to
|
|
23
|
-
* (
|
|
51
|
+
* The most frequent values (all of them, in increasing order) and their frequency. Equivalent to
|
|
52
|
+
* `DescTools::Mode()` in R. Missing values are dropped; `value` is `[NaN]` and `frequency` NaN when every value
|
|
53
|
+
* occurs once.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* modes([1, 2, 2, 3, 3, 4]); // { value: [2, 3], frequency: 2 }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @category Descriptive statistics
|
|
24
61
|
*/
|
|
25
62
|
export declare function modes(x: Sample): {
|
|
63
|
+
/** The most frequent values, in increasing order (`[NaN]` when every value occurs once). */
|
|
26
64
|
value: number[];
|
|
65
|
+
/** How often each of them occurs (NaN when every value occurs once). */
|
|
27
66
|
frequency: number;
|
|
28
67
|
};
|
|
29
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Options for {@link meanAD}.
|
|
70
|
+
*
|
|
71
|
+
* @category Descriptive statistics
|
|
72
|
+
*/
|
|
30
73
|
export interface MeanADOptions {
|
|
31
74
|
/** Centre: the mean (default) or `"median"`, or a number. */
|
|
32
75
|
center?: "mean" | "median" | number;
|
|
33
76
|
}
|
|
34
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Mean absolute deviation from the centre. Equivalent to `DescTools::MeanAD()` in R. Missing values are dropped.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* meanAD([1, 2, 3, 10]); // 3
|
|
83
|
+
* meanAD([1, 2, 3, 10], { center: "median" }); // 2.5
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @category Descriptive statistics
|
|
87
|
+
*/
|
|
35
88
|
export declare function meanAD(x: Sample, options?: MeanADOptions): number;
|
|
36
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* Options for {@link cv}.
|
|
91
|
+
*
|
|
92
|
+
* @category Descriptive statistics
|
|
93
|
+
*/
|
|
37
94
|
export interface CvOptions extends NaRmOptions {
|
|
38
95
|
/** Small-sample correction. Default `false`. */
|
|
39
96
|
unbiased?: boolean;
|
|
40
97
|
}
|
|
41
98
|
/**
|
|
42
|
-
* Coefficient of variation sd / mean (sample standard deviation). Equivalent to `DescTools::CoefVar()
|
|
99
|
+
* Coefficient of variation sd / mean (sample standard deviation). Equivalent to `DescTools::CoefVar()` in R.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* cv([2, 4, 4, 4, 5, 5, 7, 9]); // 0.4276
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @category Descriptive statistics
|
|
43
107
|
*/
|
|
44
108
|
export declare function cv(x: Sample, options?: CvOptions): number;
|
|
45
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Options for {@link scale}.
|
|
111
|
+
*
|
|
112
|
+
* @category Descriptive statistics
|
|
113
|
+
*/
|
|
46
114
|
export interface ScaleOptions {
|
|
47
115
|
/** Subtract the column means (`true`, default), nothing (`false`) or the given values. */
|
|
48
116
|
center?: boolean | readonly number[];
|
|
@@ -53,11 +121,21 @@ export interface ScaleOptions {
|
|
|
53
121
|
scale?: boolean | readonly number[];
|
|
54
122
|
}
|
|
55
123
|
/**
|
|
56
|
-
* Centre and scale the columns of a matrix (array of rows; a vector is one column). Equivalent to R's `scale()
|
|
124
|
+
* Centre and scale the columns of a matrix (array of rows; a vector is one column). Equivalent to R's `scale()`.
|
|
57
125
|
* `center` and `scale` report the values used (R's attributes), when any.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* scale([1, 2, 3]); // { scaled: [[-1], [0], [1]], center: [2], scale: [1] }
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @category Descriptive statistics
|
|
58
133
|
*/
|
|
59
134
|
export declare function scale(x: Sample | readonly (readonly number[])[], options?: ScaleOptions): {
|
|
135
|
+
/** The centred and scaled matrix, as an array of rows (R's returned matrix). */
|
|
60
136
|
scaled: number[][];
|
|
137
|
+
/** The values subtracted from each column (R's `scaled:center` attribute); absent with `center: false`. */
|
|
61
138
|
center?: number[];
|
|
139
|
+
/** The values each column was divided by (R's `scaled:scale` attribute); absent with `scale: false`. */
|
|
62
140
|
scale?: number[];
|
|
63
141
|
};
|
|
@@ -29,7 +29,16 @@ function checkType(type) {
|
|
|
29
29
|
throw new RangeError("Invalid 'type' argument.");
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* Sample skewness. Equivalent to `e1071::skewness()`
|
|
32
|
+
* Sample skewness. Equivalent to `e1071::skewness()` in R. Missing values are dropped; `{ type: 1 }` is jStat's
|
|
33
|
+
* skewness.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* skewness([1, 2, 3, 10]); // 0.6614
|
|
38
|
+
* skewness([1, 2, 3, 10], { type: 2 }); // 1.7636
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @category Descriptive statistics
|
|
33
42
|
*/
|
|
34
43
|
export function skewness(x, options = {}) {
|
|
35
44
|
const type = options.type ?? 3;
|
|
@@ -48,8 +57,16 @@ export function skewness(x, options = {}) {
|
|
|
48
57
|
return g1 * (1 - 1 / n) ** 1.5;
|
|
49
58
|
}
|
|
50
59
|
/**
|
|
51
|
-
* Sample excess kurtosis. Equivalent to `e1071::kurtosis()`
|
|
52
|
-
* kurtosis.
|
|
60
|
+
* Sample excess kurtosis. Equivalent to `e1071::kurtosis()` in R. Missing values are dropped; `{ type: 1 }` is
|
|
61
|
+
* jStat's kurtosis.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* kurtosis([1, 2, 3, 10]); // -1.7454
|
|
66
|
+
* kurtosis([1, 2, 3, 10], { type: 1 }); // -0.7696
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @category Descriptive statistics
|
|
53
70
|
*/
|
|
54
71
|
export function kurtosis(x, options = {}) {
|
|
55
72
|
const type = options.type ?? 3;
|
|
@@ -68,7 +85,15 @@ export function kurtosis(x, options = {}) {
|
|
|
68
85
|
return r * (1 - 1 / n) ** 2 - 3;
|
|
69
86
|
}
|
|
70
87
|
/**
|
|
71
|
-
* Geometric mean exp(mean(log x)). Equivalent to `DescTools::Gmean()
|
|
88
|
+
* Geometric mean exp(mean(log x)). Equivalent to `DescTools::Gmean()` in R. NaN with a negative value, 0 with a
|
|
89
|
+
* zero.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* geometricMean([1, 2, 4, 8]); // 2.82842712474619
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @category Descriptive statistics
|
|
72
97
|
*/
|
|
73
98
|
export function geometricMean(x, options = {}) {
|
|
74
99
|
const xs = values(x, options.naRm);
|
|
@@ -81,8 +106,16 @@ export function geometricMean(x, options = {}) {
|
|
|
81
106
|
return Math.exp(meanOf(xs.map(Math.log)));
|
|
82
107
|
}
|
|
83
108
|
/**
|
|
84
|
-
* The most frequent values (all of them, in increasing order) and their frequency. Equivalent to
|
|
85
|
-
* (
|
|
109
|
+
* The most frequent values (all of them, in increasing order) and their frequency. Equivalent to
|
|
110
|
+
* `DescTools::Mode()` in R. Missing values are dropped; `value` is `[NaN]` and `frequency` NaN when every value
|
|
111
|
+
* occurs once.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* modes([1, 2, 2, 3, 3, 4]); // { value: [2, 3], frequency: 2 }
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @category Descriptive statistics
|
|
86
119
|
*/
|
|
87
120
|
export function modes(x) {
|
|
88
121
|
const xs = values(x, true);
|
|
@@ -97,7 +130,17 @@ export function modes(x) {
|
|
|
97
130
|
const value = [...counts.entries()].filter(([, c]) => c === best).map(([v]) => v);
|
|
98
131
|
return { value: value.sort((a, b) => a - b), frequency: best };
|
|
99
132
|
}
|
|
100
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Mean absolute deviation from the centre. Equivalent to `DescTools::MeanAD()` in R. Missing values are dropped.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* meanAD([1, 2, 3, 10]); // 3
|
|
139
|
+
* meanAD([1, 2, 3, 10], { center: "median" }); // 2.5
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @category Descriptive statistics
|
|
143
|
+
*/
|
|
101
144
|
export function meanAD(x, options = {}) {
|
|
102
145
|
const xs = values(x, true);
|
|
103
146
|
const c = options.center ?? "mean";
|
|
@@ -105,7 +148,14 @@ export function meanAD(x, options = {}) {
|
|
|
105
148
|
return meanOf(xs.map((v) => Math.abs(v - center)));
|
|
106
149
|
}
|
|
107
150
|
/**
|
|
108
|
-
* Coefficient of variation sd / mean (sample standard deviation). Equivalent to `DescTools::CoefVar()
|
|
151
|
+
* Coefficient of variation sd / mean (sample standard deviation). Equivalent to `DescTools::CoefVar()` in R.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* cv([2, 4, 4, 4, 5, 5, 7, 9]); // 0.4276
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @category Descriptive statistics
|
|
109
159
|
*/
|
|
110
160
|
export function cv(x, options = {}) {
|
|
111
161
|
const xs = values(x, options.naRm);
|
|
@@ -118,8 +168,15 @@ export function cv(x, options = {}) {
|
|
|
118
168
|
return res;
|
|
119
169
|
}
|
|
120
170
|
/**
|
|
121
|
-
* Centre and scale the columns of a matrix (array of rows; a vector is one column). Equivalent to R's `scale()
|
|
171
|
+
* Centre and scale the columns of a matrix (array of rows; a vector is one column). Equivalent to R's `scale()`.
|
|
122
172
|
* `center` and `scale` report the values used (R's attributes), when any.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* scale([1, 2, 3]); // { scaled: [[-1], [0], [1]], center: [2], scale: [1] }
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @category Descriptive statistics
|
|
123
180
|
*/
|
|
124
181
|
export function scale(x, options = {}) {
|
|
125
182
|
const rows = x.length > 0 && Array.isArray(x[0]) ? x.map((r) => [...r]) : Array.from(x, (v) => [v]);
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Options of {@link omega}
|
|
3
|
+
*
|
|
4
|
+
* @category Agreement, reliability and factor analysis
|
|
5
|
+
*/
|
|
2
6
|
export interface OmegaOptions {
|
|
3
7
|
/** The number of first-order (group) factors. Default 3. */
|
|
4
8
|
nfactors?: number;
|
|
5
9
|
/** A correlation (or covariance) matrix to analyse instead of the data `x` (pass `null` as `x`). */
|
|
6
10
|
covmat?: readonly (readonly number[])[];
|
|
7
11
|
}
|
|
8
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Result of {@link omega}
|
|
14
|
+
*
|
|
15
|
+
* @category Agreement, reliability and factor analysis
|
|
16
|
+
*/
|
|
9
17
|
export interface OmegaResult {
|
|
10
18
|
/** Omega hierarchical: the share of the total variance due to the general factor */
|
|
11
19
|
omegaH: number;
|
|
@@ -35,13 +43,15 @@ export interface OmegaResult {
|
|
|
35
43
|
key: number[];
|
|
36
44
|
/** Rows g, F1*, ...; columns total, general, group (NaN for a group with no items) */
|
|
37
45
|
omegaGroup: number[][];
|
|
46
|
+
/** The warnings R would give (e.g. an ultra-Heywood case, or one factor), each once. */
|
|
38
47
|
warnings: string[];
|
|
48
|
+
/** The messages R would print (e.g. for two factors), each once. */
|
|
39
49
|
messages: string[];
|
|
40
50
|
}
|
|
41
51
|
/**
|
|
42
52
|
* McDonald's omega (hierarchical, asymptotic and total) from a Schmid-Leiman transformation of an oblique minres
|
|
43
|
-
* factor solution. Equivalent to
|
|
44
|
-
*
|
|
53
|
+
* factor solution. Equivalent to `psych::omega()` in R. With its defaults (`fm = "minres"`, `rotate = "oblimin"`,
|
|
54
|
+
* `option = "equal"`, `flip = TRUE`).
|
|
45
55
|
*
|
|
46
56
|
* @param x The data matrix (array of rows, NaN for missing values: correlations of pairwise complete observations),
|
|
47
57
|
* or `null` with `options.covmat`.
|
|
@@ -49,8 +59,20 @@ export interface OmegaResult {
|
|
|
49
59
|
*
|
|
50
60
|
* @example
|
|
51
61
|
* ```ts
|
|
52
|
-
*
|
|
53
|
-
*
|
|
62
|
+
* // 6 items: general loadings 0.6, three pairs with group loadings 0.4
|
|
63
|
+
* const R = [
|
|
64
|
+
* [1, 0.52, 0.36, 0.36, 0.36, 0.36],
|
|
65
|
+
* [0.52, 1, 0.36, 0.36, 0.36, 0.36],
|
|
66
|
+
* [0.36, 0.36, 1, 0.52, 0.36, 0.36],
|
|
67
|
+
* [0.36, 0.36, 0.52, 1, 0.36, 0.36],
|
|
68
|
+
* [0.36, 0.36, 0.36, 0.36, 1, 0.52],
|
|
69
|
+
* [0.36, 0.36, 0.36, 0.36, 0.52, 1],
|
|
70
|
+
* ];
|
|
71
|
+
* const om = omega(null, { covmat: R });
|
|
72
|
+
* om.omegaH; // 0.7297
|
|
73
|
+
* om.omegaTot; // 0.8378378378378378
|
|
54
74
|
* ```
|
|
75
|
+
*
|
|
76
|
+
* @category Agreement, reliability and factor analysis
|
|
55
77
|
*/
|
|
56
78
|
export declare function omega(x: readonly (readonly number[])[] | null, options?: OmegaOptions): OmegaResult;
|
|
@@ -183,8 +183,8 @@ function oblimin(A) {
|
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
185
|
* McDonald's omega (hierarchical, asymptotic and total) from a Schmid-Leiman transformation of an oblique minres
|
|
186
|
-
* factor solution. Equivalent to
|
|
187
|
-
*
|
|
186
|
+
* factor solution. Equivalent to `psych::omega()` in R. With its defaults (`fm = "minres"`, `rotate = "oblimin"`,
|
|
187
|
+
* `option = "equal"`, `flip = TRUE`).
|
|
188
188
|
*
|
|
189
189
|
* @param x The data matrix (array of rows, NaN for missing values: correlations of pairwise complete observations),
|
|
190
190
|
* or `null` with `options.covmat`.
|
|
@@ -192,9 +192,21 @@ function oblimin(A) {
|
|
|
192
192
|
*
|
|
193
193
|
* @example
|
|
194
194
|
* ```ts
|
|
195
|
-
*
|
|
196
|
-
*
|
|
195
|
+
* // 6 items: general loadings 0.6, three pairs with group loadings 0.4
|
|
196
|
+
* const R = [
|
|
197
|
+
* [1, 0.52, 0.36, 0.36, 0.36, 0.36],
|
|
198
|
+
* [0.52, 1, 0.36, 0.36, 0.36, 0.36],
|
|
199
|
+
* [0.36, 0.36, 1, 0.52, 0.36, 0.36],
|
|
200
|
+
* [0.36, 0.36, 0.52, 1, 0.36, 0.36],
|
|
201
|
+
* [0.36, 0.36, 0.36, 0.36, 1, 0.52],
|
|
202
|
+
* [0.36, 0.36, 0.36, 0.36, 0.52, 1],
|
|
203
|
+
* ];
|
|
204
|
+
* const om = omega(null, { covmat: R });
|
|
205
|
+
* om.omegaH; // 0.7297
|
|
206
|
+
* om.omegaTot; // 0.8378378378378378
|
|
197
207
|
* ```
|
|
208
|
+
*
|
|
209
|
+
* @category Agreement, reliability and factor analysis
|
|
198
210
|
*/
|
|
199
211
|
export function omega(x, options = {}) {
|
|
200
212
|
const q = options.nfactors ?? 3;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { DataFrame } from "../models/modelFrame.js";
|
|
2
2
|
import { type DataValue } from "./dataFrames.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link pivotLonger} (tidyr's arguments in camelCase).
|
|
5
|
+
*
|
|
6
|
+
* @category Data frames
|
|
7
|
+
*/
|
|
4
8
|
export interface PivotLongerOptions {
|
|
5
9
|
/** The columns to pivot: their names, in this order, or a test of the name (selecting in the data's order). */
|
|
6
10
|
cols: readonly string[] | ((name: string) => boolean);
|
|
@@ -29,9 +33,17 @@ export interface PivotLongerOptions {
|
|
|
29
33
|
/** Called with each of tidyr's warnings, once per distinct warning, in order. Default: the warnings are dropped. */
|
|
30
34
|
onWarning?: (message: string) => void;
|
|
31
35
|
}
|
|
32
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* A summary of the values of one cell (in data order), for `valuesFn` of {@link pivotWider}.
|
|
38
|
+
*
|
|
39
|
+
* @category Data frames
|
|
40
|
+
*/
|
|
33
41
|
export type PivotSummary = (values: DataValue[]) => DataValue;
|
|
34
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Options for {@link pivotWider} (tidyr's arguments in camelCase).
|
|
44
|
+
*
|
|
45
|
+
* @category Data frames
|
|
46
|
+
*/
|
|
35
47
|
export interface PivotWiderOptions {
|
|
36
48
|
/** The column (or columns) whose values name the new columns. Default `"name"`. */
|
|
37
49
|
namesFrom?: string | readonly string[];
|
|
@@ -59,8 +71,8 @@ export interface PivotWiderOptions {
|
|
|
59
71
|
valuesFn?: PivotSummary | Readonly<Record<string, PivotSummary>>;
|
|
60
72
|
}
|
|
61
73
|
/**
|
|
62
|
-
* Reshapes a data frame from wide to long: the selected columns become rows. Equivalent to tidyr
|
|
63
|
-
*
|
|
74
|
+
* Reshapes a data frame from wide to long: the selected columns become rows. Equivalent to `tidyr::pivot_longer()` in
|
|
75
|
+
* R. The result has the columns not selected, a column per part of the selected names (`namesTo`), and the value
|
|
64
76
|
* column (`valuesTo`), or with `".value"` in `namesTo` one value column per value of that part. The values of the
|
|
65
77
|
* selected columns are combined into one type: numbers with booleans give numbers; strings with either are an error.
|
|
66
78
|
*
|
|
@@ -70,11 +82,13 @@ export interface PivotWiderOptions {
|
|
|
70
82
|
* pivotLonger(wide, { cols: ["t1", "t2"], namesTo: "time", valuesTo: "score" });
|
|
71
83
|
* // { id: ["s1", "s1", "s2", "s2"], time: ["t1", "t2", "t1", "t2"], score: [5.1, 6.3, 4.8, 7.2] }
|
|
72
84
|
* ```
|
|
85
|
+
*
|
|
86
|
+
* @category Data frames
|
|
73
87
|
*/
|
|
74
88
|
export declare function pivotLonger(data: DataFrame, options: PivotLongerOptions): DataFrame;
|
|
75
89
|
/**
|
|
76
90
|
* Reshapes a data frame from long to wide: the values of `namesFrom` become columns, filled from `valuesFrom`.
|
|
77
|
-
* Equivalent to tidyr
|
|
91
|
+
* Equivalent to `tidyr::pivot_wider()` in R. One row per combination of the id columns (in order of first appearance),
|
|
78
92
|
* the new columns in order of first appearance of their names (unless `namesSort`). A cell that no row fills is
|
|
79
93
|
* `valuesFill` (default missing). A cell that several rows fill is an error unless `valuesFn` summarises the values
|
|
80
94
|
* (tidyr makes a list column there, which a data frame here cannot hold).
|
|
@@ -85,5 +99,7 @@ export declare function pivotLonger(data: DataFrame, options: PivotLongerOptions
|
|
|
85
99
|
* pivotWider(long, { namesFrom: "time", valuesFrom: "score" });
|
|
86
100
|
* // { id: ["s1", "s2"], t1: [5.1, 4.8], t2: [6.3, null] }
|
|
87
101
|
* ```
|
|
102
|
+
*
|
|
103
|
+
* @category Data frames
|
|
88
104
|
*/
|
|
89
105
|
export declare function pivotWider(data: DataFrame, options?: PivotWiderOptions): DataFrame;
|
|
@@ -106,8 +106,8 @@ function nameParts(names, namesTo, options, warnings) {
|
|
|
106
106
|
: captures(names, namesPattern, namesTo.length);
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
|
-
* Reshapes a data frame from wide to long: the selected columns become rows. Equivalent to tidyr
|
|
110
|
-
*
|
|
109
|
+
* Reshapes a data frame from wide to long: the selected columns become rows. Equivalent to `tidyr::pivot_longer()` in
|
|
110
|
+
* R. The result has the columns not selected, a column per part of the selected names (`namesTo`), and the value
|
|
111
111
|
* column (`valuesTo`), or with `".value"` in `namesTo` one value column per value of that part. The values of the
|
|
112
112
|
* selected columns are combined into one type: numbers with booleans give numbers; strings with either are an error.
|
|
113
113
|
*
|
|
@@ -117,6 +117,8 @@ function nameParts(names, namesTo, options, warnings) {
|
|
|
117
117
|
* pivotLonger(wide, { cols: ["t1", "t2"], namesTo: "time", valuesTo: "score" });
|
|
118
118
|
* // { id: ["s1", "s1", "s2", "s2"], time: ["t1", "t2", "t1", "t2"], score: [5.1, 6.3, 4.8, 7.2] }
|
|
119
119
|
* ```
|
|
120
|
+
*
|
|
121
|
+
* @category Data frames
|
|
120
122
|
*/
|
|
121
123
|
export function pivotLonger(data, options) {
|
|
122
124
|
const n = rowCount(data);
|
|
@@ -259,7 +261,7 @@ function perColumn(option, isSingle, name) {
|
|
|
259
261
|
}
|
|
260
262
|
/**
|
|
261
263
|
* Reshapes a data frame from long to wide: the values of `namesFrom` become columns, filled from `valuesFrom`.
|
|
262
|
-
* Equivalent to tidyr
|
|
264
|
+
* Equivalent to `tidyr::pivot_wider()` in R. One row per combination of the id columns (in order of first appearance),
|
|
263
265
|
* the new columns in order of first appearance of their names (unless `namesSort`). A cell that no row fills is
|
|
264
266
|
* `valuesFill` (default missing). A cell that several rows fill is an error unless `valuesFn` summarises the values
|
|
265
267
|
* (tidyr makes a list column there, which a data frame here cannot hold).
|
|
@@ -270,6 +272,8 @@ function perColumn(option, isSingle, name) {
|
|
|
270
272
|
* pivotWider(long, { namesFrom: "time", valuesFrom: "score" });
|
|
271
273
|
* // { id: ["s1", "s2"], t1: [5.1, 4.8], t2: [6.3, null] }
|
|
272
274
|
* ```
|
|
275
|
+
*
|
|
276
|
+
* @category Data frames
|
|
273
277
|
*/
|
|
274
278
|
export function pivotWider(data, options = {}) {
|
|
275
279
|
const n = rowCount(data);
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { type NaRmOptions } from "./basic.js";
|
|
2
2
|
import type { Sample } from "../htest/types.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link quantile}.
|
|
5
|
+
*
|
|
6
|
+
* @category Descriptive statistics
|
|
7
|
+
*/
|
|
4
8
|
export interface QuantileOptions extends NaRmOptions {
|
|
5
9
|
/** Hyndman and Fan's definition, 1 to 9. Default `7`. */
|
|
6
10
|
type?: number;
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
|
-
* Sample quantiles. Equivalent to R's `quantile()
|
|
13
|
+
* Sample quantiles. Equivalent to R's `quantile()`. Without names (R's `names = FALSE`).
|
|
10
14
|
*
|
|
11
15
|
* @param x The data.
|
|
12
16
|
* @param probs Probabilities in [0, 1]. Default `[0, 0.25, 0.5, 0.75, 1]`. A single number gives a single number.
|
|
@@ -17,17 +21,39 @@ export interface QuantileOptions extends NaRmOptions {
|
|
|
17
21
|
* quantile([1, 2, 3, 4, 5, 6], 0.25); // 2.25 (type 7)
|
|
18
22
|
* quantile([1, 2, 3, 4, 5, 6], 0.25, { type: 9 }); // 1.9375 (jStat's quantiles)
|
|
19
23
|
* ```
|
|
24
|
+
*
|
|
25
|
+
* @category Descriptive statistics
|
|
20
26
|
*/
|
|
21
27
|
export declare function quantile(x: Sample, probs: number, options?: QuantileOptions): number;
|
|
22
28
|
export declare function quantile(x: Sample, probs?: readonly number[], options?: QuantileOptions): number[];
|
|
23
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Interquartile range, the difference of the 0.75 and 0.25 quantiles. Equivalent to R's `IQR()`.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* IQR([1, 2, 3, 4, 5, 6]); // 2.5
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @category Descriptive statistics
|
|
38
|
+
*/
|
|
24
39
|
export declare function IQR(x: Sample, options?: QuantileOptions): number;
|
|
25
40
|
/**
|
|
26
|
-
* Tukey's five-number summary (minimum, lower hinge, median, upper hinge, maximum). Equivalent to R's `fivenum()
|
|
41
|
+
* Tukey's five-number summary (minimum, lower hinge, median, upper hinge, maximum). Equivalent to R's `fivenum()`.
|
|
27
42
|
* `NaN` values are dropped.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* fivenum([1, 2, 3, 4, 5, 6]); // [1, 2, 3.5, 5, 6]
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @category Descriptive statistics
|
|
28
50
|
*/
|
|
29
51
|
export declare function fivenum(x: Sample): [number, number, number, number, number];
|
|
30
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Options for {@link mad}.
|
|
54
|
+
*
|
|
55
|
+
* @category Descriptive statistics
|
|
56
|
+
*/
|
|
31
57
|
export interface MadOptions extends NaRmOptions {
|
|
32
58
|
/** Centre. Default: the median. */
|
|
33
59
|
center?: number;
|
|
@@ -46,5 +72,7 @@ export interface MadOptions extends NaRmOptions {
|
|
|
46
72
|
* mad([1, 2, 3, 4, 100]); // 1.4826
|
|
47
73
|
* mad([1, 2, 3, 4, 100], { constant: 1 }); // 1 (jStat's meddev)
|
|
48
74
|
* ```
|
|
75
|
+
*
|
|
76
|
+
* @category Descriptive statistics
|
|
49
77
|
*/
|
|
50
78
|
export declare function mad(x: Sample, options?: MadOptions): number;
|
|
@@ -81,14 +81,30 @@ export function quantile(x, probs = [0, 0.25, 0.5, 0.75, 1], options = {}) {
|
|
|
81
81
|
});
|
|
82
82
|
return typeof probs === "number" ? out[0] : out;
|
|
83
83
|
}
|
|
84
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Interquartile range, the difference of the 0.75 and 0.25 quantiles. Equivalent to R's `IQR()`.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* IQR([1, 2, 3, 4, 5, 6]); // 2.5
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @category Descriptive statistics
|
|
93
|
+
*/
|
|
85
94
|
export function IQR(x, options = {}) {
|
|
86
95
|
const [a, b] = quantile(x, [0.25, 0.75], options);
|
|
87
96
|
return b - a;
|
|
88
97
|
}
|
|
89
98
|
/**
|
|
90
|
-
* Tukey's five-number summary (minimum, lower hinge, median, upper hinge, maximum). Equivalent to R's `fivenum()
|
|
99
|
+
* Tukey's five-number summary (minimum, lower hinge, median, upper hinge, maximum). Equivalent to R's `fivenum()`.
|
|
91
100
|
* `NaN` values are dropped.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* fivenum([1, 2, 3, 4, 5, 6]); // [1, 2, 3.5, 5, 6]
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @category Descriptive statistics
|
|
92
108
|
*/
|
|
93
109
|
export function fivenum(x) {
|
|
94
110
|
const s = Array.from(x)
|
|
@@ -109,6 +125,8 @@ export function fivenum(x) {
|
|
|
109
125
|
* mad([1, 2, 3, 4, 100]); // 1.4826
|
|
110
126
|
* mad([1, 2, 3, 4, 100], { constant: 1 }); // 1 (jStat's meddev)
|
|
111
127
|
* ```
|
|
128
|
+
*
|
|
129
|
+
* @category Descriptive statistics
|
|
112
130
|
*/
|
|
113
131
|
export function mad(x, options = {}) {
|
|
114
132
|
const xs = values(x, options.naRm);
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import type { Sample } from "../htest/types.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* How ties are ranked, as R's `ties.method`.
|
|
4
|
+
*
|
|
5
|
+
* @category Descriptive statistics
|
|
6
|
+
*/
|
|
3
7
|
export type TiesMethod = "average" | "first" | "last" | "random" | "max" | "min";
|
|
4
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Options for {@link rank}.
|
|
10
|
+
*
|
|
11
|
+
* @category Descriptive statistics
|
|
12
|
+
*/
|
|
5
13
|
export interface RankOptions {
|
|
6
14
|
/** Ranks of tied values. Default `"average"`. */
|
|
7
15
|
tiesMethod?: TiesMethod;
|
|
@@ -19,5 +27,7 @@ export interface RankOptions {
|
|
|
19
27
|
* rank([10, 20, 20, 30]); // [1, 2.5, 2.5, 4]
|
|
20
28
|
* rank([10, 20, 20, 30], { tiesMethod: "min" }); // [1, 2, 2, 4]
|
|
21
29
|
* ```
|
|
30
|
+
*
|
|
31
|
+
* @category Descriptive statistics
|
|
22
32
|
*/
|
|
23
33
|
export declare function rank(x: Sample, options?: RankOptions): number[];
|
package/dist/descriptive/rank.js
CHANGED
|
@@ -45,6 +45,8 @@ function rankValues(x, method) {
|
|
|
45
45
|
* rank([10, 20, 20, 30]); // [1, 2.5, 2.5, 4]
|
|
46
46
|
* rank([10, 20, 20, 30], { tiesMethod: "min" }); // [1, 2, 2, 4]
|
|
47
47
|
* ```
|
|
48
|
+
*
|
|
49
|
+
* @category Descriptive statistics
|
|
48
50
|
*/
|
|
49
51
|
export function rank(x, options = {}) {
|
|
50
52
|
const method = options.tiesMethod ?? "average";
|