@numero-uno-jpn/rstats 1.19.0 → 1.20.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.
Files changed (135) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.ja.md +6 -6
  3. package/README.md +6 -6
  4. package/dist/causal.js +2 -2
  5. package/dist/chunks/chunk-33ODAPMR.js +2 -0
  6. package/dist/chunks/chunk-3ST6RZXG.js +2 -0
  7. package/dist/chunks/{chunk-FAKOND5W.js → chunk-4EQN74JN.js} +2 -2
  8. package/dist/chunks/chunk-5RRFO4NU.js +2 -0
  9. package/dist/chunks/{chunk-ILQ4VWSD.js → chunk-64DDDGJU.js} +2 -2
  10. package/dist/chunks/chunk-66TEOHPF.js +2 -0
  11. package/dist/chunks/chunk-6ISDROPG.js +2 -0
  12. package/dist/chunks/{chunk-OTETSONJ.js → chunk-6LAKI2QG.js} +2 -2
  13. package/dist/chunks/{chunk-SJJJ7Y4X.js → chunk-6QCH4LAL.js} +2 -2
  14. package/dist/chunks/{chunk-FCGTZ6BD.js → chunk-6RA73LXX.js} +2 -2
  15. package/dist/chunks/{chunk-MPBFXHXT.js → chunk-7C2ECGT6.js} +1 -1
  16. package/dist/chunks/{chunk-QH4GK3JN.js → chunk-7KPFNJBE.js} +2 -2
  17. package/dist/chunks/chunk-ARPXG2PG.js +2 -0
  18. package/dist/chunks/chunk-AWXW4WSX.js +2 -0
  19. package/dist/chunks/{chunk-WWRKCRTZ.js → chunk-B5GSH3AK.js} +1 -1
  20. package/dist/chunks/{chunk-XHHDBEHB.js → chunk-BLDLJHUG.js} +2 -2
  21. package/dist/chunks/{chunk-ANFN3X2M.js → chunk-BU4I544S.js} +2 -2
  22. package/dist/chunks/{chunk-LWFKGF43.js → chunk-CAUNJ7S6.js} +2 -2
  23. package/dist/chunks/chunk-DFGW4QWU.js +2 -0
  24. package/dist/chunks/{chunk-MOYWWJP4.js → chunk-DPCCSFCG.js} +1 -1
  25. package/dist/chunks/chunk-EXS5QD7V.js +2 -0
  26. package/dist/chunks/chunk-FOCHNNP3.js +2 -0
  27. package/dist/chunks/{chunk-VNLSP22M.js → chunk-HEPGGURG.js} +2 -2
  28. package/dist/chunks/chunk-INNFAVT3.js +2 -0
  29. package/dist/chunks/chunk-JEELIABM.js +2 -0
  30. package/dist/chunks/chunk-KNF2GPJV.js +2 -0
  31. package/dist/chunks/chunk-L4ZS7MAX.js +2 -0
  32. package/dist/chunks/{chunk-7D7FBLWD.js → chunk-LZAB4M7P.js} +2 -2
  33. package/dist/chunks/chunk-LZTDYQRS.js +3 -0
  34. package/dist/chunks/{chunk-AS2XTRHH.js → chunk-MTSU2QHB.js} +2 -2
  35. package/dist/chunks/{chunk-5NW4WT4F.js → chunk-MXRN2G7O.js} +2 -2
  36. package/dist/chunks/chunk-OFDD4GTZ.js +2 -0
  37. package/dist/chunks/chunk-OOHFFLMY.js +2 -0
  38. package/dist/chunks/chunk-OOO5AAM7.js +2 -0
  39. package/dist/chunks/chunk-PJJJR3H6.js +2 -0
  40. package/dist/chunks/chunk-PVRNAOO7.js +2 -0
  41. package/dist/chunks/chunk-Q2JLU5YD.js +2 -0
  42. package/dist/chunks/{chunk-SAFH76DR.js → chunk-QCQBK5AC.js} +2 -2
  43. package/dist/chunks/chunk-RXK4KSKH.js +2 -0
  44. package/dist/chunks/chunk-UC3YYJHM.js +4 -0
  45. package/dist/chunks/chunk-UPACHZ4F.js +2 -0
  46. package/dist/chunks/{chunk-DXSVV47D.js → chunk-VCXPGCA4.js} +2 -2
  47. package/dist/chunks/chunk-VFL4GGYT.js +2 -0
  48. package/dist/chunks/chunk-VL72MQOQ.js +2 -0
  49. package/dist/chunks/chunk-VSV5QGXX.js +2 -0
  50. package/dist/chunks/{chunk-U6RXYALO.js → chunk-WMEF5XWO.js} +2 -2
  51. package/dist/chunks/chunk-X6JS6ZZB.js +2 -0
  52. package/dist/chunks/chunk-YEDVOX5V.js +2 -0
  53. package/dist/chunks/chunk-ZCTB4N5J.js +3 -0
  54. package/dist/descriptive.js +2 -2
  55. package/dist/distributions.js +2 -2
  56. package/dist/entries/tests.d.ts +5 -0
  57. package/dist/entries/tests.js +5 -0
  58. package/dist/entries/timeseries.d.ts +11 -0
  59. package/dist/entries/timeseries.js +11 -0
  60. package/dist/linalg.js +2 -2
  61. package/dist/meta/metabin.d.ts +32 -0
  62. package/dist/meta/metabin.js +137 -0
  63. package/dist/meta/metaextra.d.ts +153 -0
  64. package/dist/meta/metaextra.js +290 -0
  65. package/dist/meta/metagen.d.ts +124 -0
  66. package/dist/meta/metagen.js +263 -0
  67. package/dist/meta/metaother.d.ts +87 -0
  68. package/dist/meta/metaother.js +342 -0
  69. package/dist/meta/netmeta.d.ts +256 -0
  70. package/dist/meta/netmeta.js +547 -0
  71. package/dist/mixed.js +3 -4
  72. package/dist/models/glmFamily.js +4 -1
  73. package/dist/models/metaAnalysis.d.ts +4 -0
  74. package/dist/models/metaAnalysis.js +100 -18
  75. package/dist/multivariate.js +2 -2
  76. package/dist/numerics.js +2 -2
  77. package/dist/regression.js +2 -2
  78. package/dist/rstats.js +20 -18
  79. package/dist/special.js +2 -2
  80. package/dist/tests.js +15 -15
  81. package/dist/timeseries/acf.js +5 -2
  82. package/dist/timeseries/arima.d.ts +154 -0
  83. package/dist/timeseries/arima.js +1007 -0
  84. package/dist/timeseries/autoArima.d.ts +70 -0
  85. package/dist/timeseries/autoArima.js +191 -0
  86. package/dist/timeseries/ets.d.ts +158 -0
  87. package/dist/timeseries/ets.js +883 -0
  88. package/dist/timeseries/forecastArima.d.ts +136 -0
  89. package/dist/timeseries/forecastArima.js +432 -0
  90. package/dist/timeseries/forecastDispatch.d.ts +83 -0
  91. package/dist/timeseries/forecastDispatch.js +130 -0
  92. package/dist/timeseries/forecastSimple.d.ts +177 -0
  93. package/dist/timeseries/forecastSimple.js +371 -0
  94. package/dist/timeseries/forecastUtils.d.ts +260 -0
  95. package/dist/timeseries/forecastUtils.js +619 -0
  96. package/dist/timeseries/holtWinters.d.ts +65 -0
  97. package/dist/timeseries/holtWinters.js +193 -0
  98. package/dist/timeseries/input.d.ts +8 -0
  99. package/dist/timeseries/input.js +27 -0
  100. package/dist/timeseries/ocsbCritical.d.ts +2 -0
  101. package/dist/timeseries/ocsbCritical.js +6 -0
  102. package/dist/timeseries/scale.d.ts +16 -0
  103. package/dist/timeseries/scale.js +48 -0
  104. package/dist/timeseries/statsTs.d.ts +128 -0
  105. package/dist/timeseries/statsTs.js +456 -0
  106. package/dist/timeseries/stl.d.ts +131 -0
  107. package/dist/timeseries/stl.js +489 -0
  108. package/dist/timeseries/tseries.d.ts +110 -0
  109. package/dist/timeseries/tseries.js +369 -0
  110. package/dist/timeseries.js +2 -2
  111. package/package.json +1 -1
  112. package/dist/chunks/chunk-2S45NNTL.js +0 -2
  113. package/dist/chunks/chunk-4JFGT4PN.js +0 -2
  114. package/dist/chunks/chunk-4JRJU5F5.js +0 -2
  115. package/dist/chunks/chunk-6ZGEYAFC.js +0 -2
  116. package/dist/chunks/chunk-BJ5WAL2C.js +0 -2
  117. package/dist/chunks/chunk-CEOSH3H2.js +0 -2
  118. package/dist/chunks/chunk-CMNKXRZF.js +0 -3
  119. package/dist/chunks/chunk-CNJLPH6W.js +0 -2
  120. package/dist/chunks/chunk-FELX2TZZ.js +0 -2
  121. package/dist/chunks/chunk-G4B2SQR6.js +0 -4
  122. package/dist/chunks/chunk-HPIZAWMT.js +0 -2
  123. package/dist/chunks/chunk-I5XUWUEV.js +0 -2
  124. package/dist/chunks/chunk-JLFRYDYO.js +0 -2
  125. package/dist/chunks/chunk-JXKHFSGK.js +0 -2
  126. package/dist/chunks/chunk-LBU73UMS.js +0 -2
  127. package/dist/chunks/chunk-LSZTDKIB.js +0 -2
  128. package/dist/chunks/chunk-M5J3DHXB.js +0 -2
  129. package/dist/chunks/chunk-NWNJEAKI.js +0 -2
  130. package/dist/chunks/chunk-QVE7V5UG.js +0 -2
  131. package/dist/chunks/chunk-RMGEIU4Z.js +0 -2
  132. package/dist/chunks/chunk-TVU4N6BA.js +0 -2
  133. package/dist/chunks/chunk-W4EITKLJ.js +0 -2
  134. package/dist/chunks/chunk-XJMBX6A2.js +0 -2
  135. package/dist/chunks/chunk-YZ6SBFFG.js +0 -2
@@ -1,5 +1,6 @@
1
1
  // Univariate autocorrelation, partial autocorrelation and cross-correlation.
2
2
  import { qnorm } from "../distributions/normal.js";
3
+ import { centred } from "./scale.js";
3
4
  // Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
4
5
  import { checkOptions } from "../internal/checkOptions.js";
5
6
  const ACF_KEYS = ["type", "lagMax", "demean", "naAction", "ci"];
@@ -247,7 +248,8 @@ function build(x, y, options, isCross) {
247
248
  */
248
249
  export function acf(input, options = {}) {
249
250
  checkOptions(options, ACF_KEYS, "acf"); // generated: option-keys.mjs
250
- const x = series(input);
251
+ // demeaned, the series less a large common value (exact; log 110: y + 1e15 lost digits in the mean)
252
+ const x = (options.demean ?? true) ? centred(series(input)) : series(input);
251
253
  const type = options.type ?? "correlation";
252
254
  if (type !== "correlation" && type !== "covariance" && type !== "partial")
253
255
  throw new RangeError("'type' must be 'correlation', 'covariance' or 'partial'");
@@ -269,7 +271,8 @@ export function pacf(input, options = {}) {
269
271
  */
270
272
  export function ccf(xInput, yInput, options = {}) {
271
273
  checkOptions(options, CCF_KEYS, "ccf"); // generated: option-keys.mjs
272
- const x = series(xInput), y = series(yInput);
274
+ const dm = options.demean ?? true;
275
+ const x = dm ? centred(series(xInput)) : series(xInput), y = dm ? centred(series(yInput)) : series(yInput);
273
276
  const type = options.type ?? "correlation";
274
277
  if (type !== "correlation" && type !== "covariance")
275
278
  throw new RangeError("'type' must be 'correlation' or 'covariance'");
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Seasonal part of an ARIMA model.
3
+ *
4
+ * @category Time series
5
+ */
6
+ export interface ArimaSeasonal {
7
+ /** (P, D, Q). Default [0, 0, 0]. */
8
+ order?: readonly [number, number, number];
9
+ /** The period. Default the series' frequency. */
10
+ period?: number;
11
+ }
12
+ /**
13
+ * Options of {@link arima}.
14
+ *
15
+ * @category Time series
16
+ */
17
+ export interface ArimaOptions {
18
+ /** (p, d, q). Default [0, 0, 0]. */
19
+ order?: readonly [number, number, number];
20
+ /** The seasonal part (an order, or an order and a period). */
21
+ seasonal?: ArimaSeasonal | readonly [number, number, number];
22
+ /** The series' frequency (the seasonal period by default). Default 1. */
23
+ frequency?: number;
24
+ /** Regressors: one array per regressor, each of the series' length. */
25
+ xreg?: readonly (readonly number[])[];
26
+ /** Names of the regressors. Default "xreg1", "xreg2", ... (or "xreg" for one). */
27
+ xregNames?: readonly string[];
28
+ /** Include a mean (ignored when differenced). Default true. */
29
+ includeMean?: boolean;
30
+ /** Transform the AR parameters to stationarity during the ML optimisation. Default true. */
31
+ transformPars?: boolean;
32
+ /** Fixed values (NaN for the free ones), in the order of the coefficients. */
33
+ fixed?: readonly number[];
34
+ /** Starting values (NaN filled by defaults). */
35
+ init?: readonly number[];
36
+ /** "CSS-ML" (default), "ML" or "CSS". */
37
+ method?: "CSS-ML" | "ML" | "CSS";
38
+ /** Initial observations ignored by CSS (at least the AR lags). */
39
+ nCond?: number;
40
+ /** Prior variance multiple of the presample values in a differenced model. Default 1e6. */
41
+ kappa?: number;
42
+ /** "R" (default): the variance matrix from R's numerical Hessian (agrees with R); "exact": a converged Hessian. */
43
+ hessian?: "R" | "exact";
44
+ }
45
+ /**
46
+ * The state space model behind a fit, for forecasting.
47
+ *
48
+ * @category Time series
49
+ */
50
+ export interface ArimaStateModel {
51
+ phi: number[];
52
+ theta: number[];
53
+ delta: number[];
54
+ /** Filtered state and covariance at the end of the series (in units of sigma2). */
55
+ a: number[];
56
+ P: number[][];
57
+ }
58
+ /**
59
+ * Result of {@link arima}.
60
+ *
61
+ * @category Time series
62
+ */
63
+ export interface ArimaResult {
64
+ /** The coefficients (AR, MA, seasonal AR, seasonal MA, intercept, regressors). */
65
+ coef: number[];
66
+ /** Their names (ar1, ma1, sar1, sma1, intercept, regressor names). */
67
+ coefNames: string[];
68
+ /** The MLE of the innovations variance (CSS: the mean of the squared CSS residuals). */
69
+ sigma2: number;
70
+ /** The variance matrix of the free coefficients (rows and columns as `coefNames` of the free ones). */
71
+ varCoef: number[][];
72
+ /** The maximised log-likelihood of the differenced data (CSS: R's approximation). */
73
+ loglik: number;
74
+ /** -2 loglik + 2 (free coefficients + 1); NaN for CSS. */
75
+ aic: number;
76
+ /** (p, q, P, Q, period, d, D). */
77
+ arma: [number, number, number, number, number, number, number];
78
+ /** The fitted innovations (standardised one-step errors; NaN at missing values). */
79
+ residuals: number[];
80
+ /** "CSS-ML", "ML" or "CSS". */
81
+ method: "CSS-ML" | "ML" | "CSS";
82
+ /** Initial observations not used by CSS. */
83
+ nCond: number;
84
+ /** The number of observations used in the likelihood. */
85
+ nobs: number;
86
+ /** The optimiser's convergence code (0 = converged). */
87
+ code: number;
88
+ /** Mask of the free coefficients. */
89
+ mask: boolean[];
90
+ /** The state space model at the end of the series. */
91
+ model: ArimaStateModel;
92
+ /** The series (as given). */
93
+ x: number[];
94
+ /** The regressors (as given), including no intercept column. */
95
+ xreg: number[][];
96
+ /** Whether a mean was included. */
97
+ includeMean: boolean;
98
+ }
99
+ /** The full AR and MA coefficients (lags 1..) from the non-seasonal and seasonal ones. */
100
+ export declare function expandArma(ar: readonly number[], ma: readonly number[], sar: readonly number[], sma: readonly number[], s: number): {
101
+ phi: number[];
102
+ theta: number[];
103
+ };
104
+ /**
105
+ * The roots' smallest modulus of 1 + c_1 z + ... + c_k z^k (Infinity for a constant). Not an R function.
106
+ *
107
+ * @category Time series
108
+ */
109
+ export declare function minRootModulus(c: readonly number[]): number;
110
+ export declare function stationaryCovariance(phi: readonly number[], theta: readonly number[], r: number): number[][];
111
+ /**
112
+ * Fits an ARIMA model by exact maximum likelihood (Kalman filter) or conditional sum of squares. Equivalent to R's
113
+ * `arima()`. The estimates are taken to the optimum, where R's optimiser may stop slightly short.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * // R's lh (48 luteinizing hormone measurements)
118
+ * const lh = [2.4, 2.4, 2.4, 2.2, 2.1, 1.5, 2.3, 2.3, 2.5, 2.0, 1.9, 1.7, 2.2, 1.8, 3.2, 3.2, 2.7, 2.2, 2.2, 1.9, 1.9, 1.8, 2.7, 3.0,
119
+ * 2.3, 2.0, 2.0, 2.9, 2.9, 2.7, 2.7, 2.3, 2.6, 2.4, 1.8, 1.7, 1.5, 1.4, 2.1, 3.3, 3.5, 3.5, 3.1, 2.6, 2.1, 3.4, 3.0, 2.9];
120
+ * const fit = arima(lh, { order: [1, 0, 0] });
121
+ * fit.coef; // [0.5739243884, 2.413285608] (ar1, intercept; the last digits differ between platforms' math libraries)
122
+ * ```
123
+ *
124
+ * @category Time series
125
+ */
126
+ export declare function arima(xIn: readonly number[], options?: ArimaOptions): ArimaResult;
127
+ /** The fit of x / c on the scale of x (the regression coefficients, the state, sigma2 and the likelihood). */
128
+ export declare function unscaleArima(fs: ArimaResult, c: number, x: number[]): ArimaResult;
129
+ /** Records that `r` is the fit `fs` (of the series / c) mapped back: forecasts are then made from `fs`. */
130
+ export declare function registerScaledArima(r: object, fs: ArimaResult, c: number): void;
131
+ /** The standardised fit behind `r`, when there is one. */
132
+ export declare function scaledArima(r: object): {
133
+ fit: ArimaResult;
134
+ c: number;
135
+ } | undefined;
136
+ /**
137
+ * Result of {@link predictArima}.
138
+ *
139
+ * @category Time series
140
+ */
141
+ export interface PredictArimaResult {
142
+ pred: number[];
143
+ se: number[];
144
+ }
145
+ /**
146
+ * Forecasts from an {@link arima} fit by the Kalman filter (the exact predictor from the finite past). Equivalent to
147
+ * R's `predict.Arima()`.
148
+ *
149
+ * @category Time series
150
+ */
151
+ export declare function predictArima(fit: ArimaResult, nAhead?: number, options?: {
152
+ newxreg?: readonly (readonly number[])[];
153
+ sigma2?: number;
154
+ }): PredictArimaResult;