@numero-uno-jpn/rstats 1.16.0 → 1.18.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 (92) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.ja.md +6 -6
  3. package/README.md +6 -6
  4. package/dist/causal/mediationProcedures.js +18 -1
  5. package/dist/causal/moderation.js +11 -2
  6. package/dist/causal.js +2 -2
  7. package/dist/chunks/{chunk-J74CELYL.js → chunk-2JB7F646.js} +2 -2
  8. package/dist/chunks/{chunk-K23MXTLC.js → chunk-3JFRDXN7.js} +2 -2
  9. package/dist/chunks/chunk-53WQDB3C.js +2 -0
  10. package/dist/chunks/{chunk-DP6TE35N.js → chunk-5CTWYFMB.js} +2 -2
  11. package/dist/chunks/chunk-6I23C2YJ.js +2 -0
  12. package/dist/chunks/{chunk-57BGTHS7.js → chunk-CTZUYKVL.js} +2 -2
  13. package/dist/chunks/{chunk-UMXY4R4G.js → chunk-EC77KAAM.js} +2 -2
  14. package/dist/chunks/{chunk-37YHUVXL.js → chunk-FLFNMSHI.js} +2 -2
  15. package/dist/chunks/{chunk-FCE6N6PI.js → chunk-GEHMND3C.js} +2 -2
  16. package/dist/chunks/{chunk-W5D6CIZM.js → chunk-GIK34P23.js} +2 -2
  17. package/dist/chunks/chunk-H6Z7JVSD.js +2 -0
  18. package/dist/chunks/{chunk-HOH5KGSU.js → chunk-HG4LJBNV.js} +2 -2
  19. package/dist/chunks/chunk-HGAEVPVS.js +2 -0
  20. package/dist/chunks/{chunk-ISOLPXQV.js → chunk-HMLYEFQN.js} +2 -2
  21. package/dist/chunks/chunk-HRRCC2BD.js +2 -0
  22. package/dist/chunks/chunk-IBHMM2SL.js +2 -0
  23. package/dist/chunks/chunk-ICDW3I2F.js +2 -0
  24. package/dist/chunks/{chunk-6DP2U23T.js → chunk-IKMW63BE.js} +2 -2
  25. package/dist/chunks/{chunk-KSN6A4OK.js → chunk-IOJVFYHW.js} +2 -2
  26. package/dist/chunks/chunk-IW4S634O.js +2 -0
  27. package/dist/chunks/{chunk-ZZ6KYMBW.js → chunk-JF4PXFJE.js} +2 -2
  28. package/dist/chunks/{chunk-NQWFURFV.js → chunk-JPWYGTUN.js} +2 -2
  29. package/dist/chunks/{chunk-XMA2NWYX.js → chunk-KJMLQHCY.js} +1 -1
  30. package/dist/chunks/chunk-KVJBCT3D.js +2 -0
  31. package/dist/chunks/chunk-LCIX76FR.js +2 -0
  32. package/dist/chunks/chunk-LY5XGFPU.js +2 -0
  33. package/dist/chunks/{chunk-JYE3T7FS.js → chunk-MKZH65DK.js} +2 -2
  34. package/dist/chunks/{chunk-B5QE2FDM.js → chunk-MVPHISOV.js} +1 -1
  35. package/dist/chunks/chunk-MXZ64QME.js +2 -0
  36. package/dist/chunks/{chunk-XAMWBGTP.js → chunk-N7BUE54L.js} +2 -2
  37. package/dist/chunks/{chunk-244M5C2B.js → chunk-NDZVVNBB.js} +2 -2
  38. package/dist/chunks/{chunk-AC22FPFB.js → chunk-NOTJ45G3.js} +2 -2
  39. package/dist/chunks/{chunk-MNPZUMPL.js → chunk-QUD3374N.js} +2 -2
  40. package/dist/chunks/{chunk-AIII5VRA.js → chunk-RXYZQ3UX.js} +2 -2
  41. package/dist/chunks/{chunk-LHMG6Q5C.js → chunk-SCFFHEDZ.js} +2 -2
  42. package/dist/chunks/{chunk-BHNDCNWM.js → chunk-V6FMGGUV.js} +2 -2
  43. package/dist/chunks/{chunk-FHHI3PYN.js → chunk-VATAUY7N.js} +2 -2
  44. package/dist/chunks/chunk-W5M3R4NH.js +2 -0
  45. package/dist/chunks/{chunk-H6WBOIFZ.js → chunk-WYVUCQO3.js} +1 -1
  46. package/dist/chunks/{chunk-7MFMRNMT.js → chunk-XQCHC3SH.js} +1 -1
  47. package/dist/chunks/{chunk-IPMC3VOC.js → chunk-XUMVTGMM.js} +2 -2
  48. package/dist/chunks/{chunk-6MHLWTBF.js → chunk-YXMHWS5R.js} +2 -2
  49. package/dist/chunks/{chunk-K5IP4ZJ5.js → chunk-Z33Q545U.js} +2 -2
  50. package/dist/descriptive/qcc.d.ts +320 -0
  51. package/dist/descriptive/qcc.js +524 -0
  52. package/dist/descriptive/qccTools.d.ts +301 -0
  53. package/dist/descriptive/qccTools.js +390 -0
  54. package/dist/descriptive.js +2 -2
  55. package/dist/distributions.js +2 -2
  56. package/dist/entries/descriptive.d.ts +2 -0
  57. package/dist/entries/descriptive.js +2 -0
  58. package/dist/entries/regression.d.ts +4 -0
  59. package/dist/entries/regression.js +8 -0
  60. package/dist/linalg.js +2 -2
  61. package/dist/mixed.js +2 -2
  62. package/dist/models/betareg.d.ts +278 -0
  63. package/dist/models/betareg.js +600 -0
  64. package/dist/models/bradleyterry.d.ts +188 -0
  65. package/dist/models/bradleyterry.js +533 -0
  66. package/dist/models/loglin.d.ts +186 -0
  67. package/dist/models/loglin.js +349 -0
  68. package/dist/models/survreg.d.ts +48 -0
  69. package/dist/models/survreg.js +29 -6
  70. package/dist/models/tobit.d.ts +132 -0
  71. package/dist/models/tobit.js +183 -0
  72. package/dist/multivariate.js +2 -2
  73. package/dist/numerics.js +2 -2
  74. package/dist/regression.js +3 -3
  75. package/dist/rstats.js +17 -17
  76. package/dist/special.js +2 -2
  77. package/dist/tests.js +15 -15
  78. package/dist/timeseries.js +2 -2
  79. package/package.json +1 -1
  80. package/dist/chunks/chunk-3L333CTJ.js +0 -2
  81. package/dist/chunks/chunk-3RO5FWJ5.js +0 -2
  82. package/dist/chunks/chunk-3VKN6K3P.js +0 -2
  83. package/dist/chunks/chunk-7IU5OE5I.js +0 -2
  84. package/dist/chunks/chunk-GKDA5W53.js +0 -2
  85. package/dist/chunks/chunk-IVJTWTGV.js +0 -2
  86. package/dist/chunks/chunk-NCVEJDRI.js +0 -2
  87. package/dist/chunks/chunk-P3Q6IJMR.js +0 -2
  88. package/dist/chunks/chunk-PIWXBWMD.js +0 -2
  89. package/dist/chunks/chunk-QBY63DGM.js +0 -2
  90. package/dist/chunks/chunk-RV4SUKXV.js +0 -2
  91. package/dist/chunks/chunk-SALMA4XX.js +0 -2
  92. package/dist/chunks/chunk-ZTZX2UYP.js +0 -2
@@ -0,0 +1,278 @@
1
+ import { type DesignContrast } from "./modelMatrix.js";
2
+ import type { DataFrame } from "./modelFrame.js";
3
+ import type { Sample } from "../htest/types.js";
4
+ /**
5
+ * Links of the mean in {@link betareg}.
6
+ * @category Regression
7
+ */
8
+ export type BetaregLink = "logit" | "probit" | "cloglog" | "cauchit" | "log" | "loglog";
9
+ /**
10
+ * Links of the precision in {@link betareg}.
11
+ * @category Regression
12
+ */
13
+ export type BetaregPhiLink = "identity" | "log" | "sqrt";
14
+ /**
15
+ * Estimators of {@link betareg}: maximum likelihood, bias-corrected, bias-reduced.
16
+ * @category Regression
17
+ */
18
+ export type BetaregType = "ML" | "BC" | "BR";
19
+ /**
20
+ * Options for {@link betareg}.
21
+ * @category Regression
22
+ */
23
+ export interface BetaregOptions {
24
+ /** Link of the mean (default `"logit"`). */
25
+ link?: BetaregLink;
26
+ /** Link of the precision phi (default `"identity"` for `y ~ x`, `"log"` for `y ~ x | z`). */
27
+ linkPhi?: BetaregPhiLink;
28
+ /** Estimator: `"ML"` (default), `"BC"` (bias-corrected) or `"BR"` (bias-reduced), as Kosmidis and Firth (2010). */
29
+ type?: BetaregType;
30
+ /** Case weights, one per row of `data` (non-negative), or the name of a column of `data`. */
31
+ weights?: Sample | string;
32
+ /** A contrast per factor of the formula (default treatment contrasts). */
33
+ contrasts?: Record<string, DesignContrast>;
34
+ /** Iterations: at most `maxit` (default 5000) Fisher scoring steps for ML and BR. */
35
+ maxit?: number;
36
+ }
37
+ /**
38
+ * What predictions on new data need.
39
+ * @category Regression
40
+ */
41
+ export interface BetaregModel {
42
+ /** The right-hand side of the mean model (parsed). */
43
+ meanRhs: unknown;
44
+ /** The right-hand side of the precision model (parsed; undefined for a constant precision). */
45
+ precisionRhs: unknown;
46
+ /** The levels of the factors. */
47
+ factorLevels: Record<string, readonly string[]>;
48
+ /** The contrasts given. */
49
+ contrasts: Record<string, DesignContrast>;
50
+ /** The variables of both parts (without the response). */
51
+ variables: string[];
52
+ /** The mean model's matrix of the rows used. */
53
+ x: number[][];
54
+ /** The precision model's matrix. */
55
+ z: number[][];
56
+ /** The response. */
57
+ y: number[];
58
+ /** The case weights. */
59
+ weights: number[];
60
+ /** 0-based rows of the data used. */
61
+ rows: number[];
62
+ /** The mean model's matrix as fitted: columns centred and divided by a power of 2 (the hat values use it). */
63
+ xScaled: number[][];
64
+ }
65
+ /**
66
+ * Result of {@link betareg}.
67
+ * @category Regression
68
+ */
69
+ export interface BetaregResult {
70
+ /** Coefficients of the mean model and of the precision model. */
71
+ coefficients: BetaregCoefficients;
72
+ /** Names of the mean coefficients. */
73
+ meanNames: string[];
74
+ /** `(phi)` for a constant precision with the identity link, else `(phi)_` and the term. */
75
+ precisionNames: string[];
76
+ /** All names (mean, then precision), the rows and columns of `vcov`. */
77
+ names: string[];
78
+ /** Covariance of all coefficients: the inverse of the expected information at the estimates. */
79
+ vcov: number[][];
80
+ /** Log-likelihood at the estimates. */
81
+ loglik: number;
82
+ /** Squared (weighted) correlation of the linear predictor and the link-transformed response. */
83
+ pseudoRSquared: number;
84
+ /** The first-order bias at the maximum likelihood estimates (`type: "BC"` only), as R's `bias`. */
85
+ bias?: number[];
86
+ /** Fitted means. */
87
+ fitted: number[];
88
+ /** Linear predictors of the mean. */
89
+ linearPredictor: number[];
90
+ /** Fitted precisions. */
91
+ precision: number[];
92
+ /** Link of the mean. */
93
+ link: BetaregLink;
94
+ /** Link of the precision. */
95
+ linkPhi: BetaregPhiLink;
96
+ /** The estimator. */
97
+ type: BetaregType;
98
+ /** Rows used. */
99
+ n: number;
100
+ /** Rows with a positive weight. */
101
+ nobs: number;
102
+ /** Residual degrees of freedom of the null model (constant mean and precision): nobs − 2. */
103
+ dfNull: number;
104
+ /** Residual degrees of freedom of this model. */
105
+ dfResidual: number;
106
+ /** Fisher scoring iterations (rStats.js's, not R's BFGS and scoring counts). */
107
+ iterations: number;
108
+ /** Whether the iterations converged. */
109
+ converged: boolean;
110
+ /** What predictions and residuals need. */
111
+ model: BetaregModel;
112
+ /** Warnings. */
113
+ warnings: string[];
114
+ }
115
+ /**
116
+ * The coefficients of a {@link betareg} fit.
117
+ * @category Regression
118
+ */
119
+ export interface BetaregCoefficients {
120
+ /** Of the mean model. */
121
+ mean: number[];
122
+ /** Of the precision model. */
123
+ precision: number[];
124
+ }
125
+ /**
126
+ * A Wald table of {@link betaregSummary}.
127
+ * @category Regression
128
+ */
129
+ export interface BetaregCoefficientTable {
130
+ /** Coefficient names. */
131
+ names: string[];
132
+ /** Estimates. */
133
+ estimate: number[];
134
+ /** Standard errors. */
135
+ se: number[];
136
+ /** Wald z statistics. */
137
+ z: number[];
138
+ /** Two-sided p-values. */
139
+ p: number[];
140
+ }
141
+ /**
142
+ * Beta regression for rates and proportions in (0, 1): the mean linked to a linear predictor, the precision phi
143
+ * constant (`y ~ x`) or linked to its own regressors (`y ~ x | z`), fitted by maximum likelihood, or bias-corrected or
144
+ * bias-reduced (Kosmidis and Firth 2010). Equivalent to R's `betareg::betareg()`.
145
+ *
146
+ * The response must lie strictly between 0 and 1 (R fits an extended-support distribution to 0 and 1; rStats.js does
147
+ * not). rStats.js maximises the likelihood to convergence by Fisher scoring; R stops its optimiser slightly earlier,
148
+ * so estimates agree with R's to about 1e-7 relative.
149
+ * @example
150
+ * ```ts
151
+ * const fit = betareg("y ~ x", { y: [0.21, 0.35, 0.3, 0.52, 0.48, 0.66, 0.6, 0.81], x: [1, 2, 3, 4, 5, 6, 7, 8] });
152
+ * fit.coefficients; // { mean: [-1.5409, 0.33424], precision: [62.03] }
153
+ * ```
154
+ * @category Regression
155
+ */
156
+ export declare function betareg(formula: string, data: DataFrame, options?: BetaregOptions): BetaregResult;
157
+ /**
158
+ * Result of {@link betaregSummary}.
159
+ * @category Regression
160
+ */
161
+ export interface BetaregSummaryResult {
162
+ /** Wald table of the mean coefficients. */
163
+ mean: BetaregCoefficientTable;
164
+ /** Wald table of the precision coefficients. */
165
+ precision: BetaregCoefficientTable;
166
+ /** Log-likelihood. */
167
+ loglik: number;
168
+ /** Number of coefficients (the degrees of freedom of the log-likelihood). */
169
+ df: number;
170
+ /** Akaike's information criterion. */
171
+ aic: number;
172
+ /** Pseudo R². */
173
+ pseudoRSquared: number;
174
+ /** The estimator. */
175
+ type: BetaregType;
176
+ /** Link of the mean. */
177
+ link: BetaregLink;
178
+ /** Link of the precision. */
179
+ linkPhi: BetaregPhiLink;
180
+ /** Minimum, quartiles and maximum of the quantile residuals. */
181
+ residuals: number[];
182
+ }
183
+ /**
184
+ * Summary of a {@link betareg} fit: Wald tests of the mean and precision coefficients. Equivalent to
185
+ * `betareg::summary.betareg()` in R.
186
+ * @example
187
+ * ```ts
188
+ * const fit = betareg("y ~ x", { y: [0.21, 0.35, 0.3, 0.52, 0.48, 0.66, 0.6, 0.81], x: [1, 2, 3, 4, 5, 6, 7, 8] });
189
+ * betaregSummary(fit).mean.p; // [2.355e-12, 2.267e-14]
190
+ * ```
191
+ * @category Regression
192
+ */
193
+ export declare function betaregSummary(fit: BetaregResult): BetaregSummaryResult;
194
+ /**
195
+ * Options for {@link betaregConfint}.
196
+ * @category Regression
197
+ */
198
+ export interface BetaregConfintOptions {
199
+ /** Confidence level (default 0.95). */
200
+ level?: number;
201
+ }
202
+ /**
203
+ * Result of {@link betaregConfint}.
204
+ * @category Regression
205
+ */
206
+ export interface BetaregConfintResult {
207
+ /** Coefficient names (mean, then precision). */
208
+ names: string[];
209
+ /** Lower limits. */
210
+ lower: number[];
211
+ /** Upper limits. */
212
+ upper: number[];
213
+ }
214
+ /**
215
+ * Wald confidence intervals of all coefficients of a {@link betareg} fit. Equivalent to R's
216
+ * `confint()`.
217
+ * @example
218
+ * ```ts
219
+ * const fit = betareg("y ~ x", { y: [0.21, 0.35, 0.3, 0.52, 0.48, 0.66, 0.6, 0.81], x: [1, 2, 3, 4, 5, 6, 7, 8] });
220
+ * betaregConfint(fit, { level: 0.9 });
221
+ * // { names: ["(Intercept)", "x", "(phi)"], lower: [-1.9023, 0.26223, 11.375], upper: [-1.1794, 0.40625, 112.68] }
222
+ * ```
223
+ * @category Regression
224
+ */
225
+ export declare function betaregConfint(fit: BetaregResult, options?: BetaregConfintOptions): BetaregConfintResult;
226
+ /**
227
+ * Options for {@link betaregPredict}.
228
+ * @category Regression
229
+ */
230
+ export interface BetaregPredictOptions {
231
+ /** New data (default: the rows of the fit). */
232
+ newdata?: DataFrame;
233
+ /**
234
+ * `"response"` (the mean, default), `"link"`, `"precision"`, `"variance"`, `"parameters"` (rows of [mu, phi]),
235
+ * `"density"`, `"probability"` or `"quantile"` (at `at`).
236
+ */
237
+ type?: "response" | "link" | "precision" | "variance" | "parameters" | "density" | "probability" | "quantile";
238
+ /** Where `"density"`, `"probability"` and `"quantile"` are evaluated (default 0.5). */
239
+ at?: number | readonly number[];
240
+ /**
241
+ * One value of `at` per row (a vector) or every value at every row (a matrix of rows x at). Default: per row when
242
+ * `at` has as many values as there are rows, else the matrix (as R).
243
+ */
244
+ elementwise?: boolean;
245
+ }
246
+ /**
247
+ * Predictions of a {@link betareg} fit: means, linear predictors, precisions, variances, or the density,
248
+ * distribution function or quantiles of the fitted beta distributions. Equivalent to
249
+ * `betareg::predict.betareg()` in R.
250
+ * @example
251
+ * ```ts
252
+ * const fit = betareg("y ~ x", { y: [0.21, 0.35, 0.3, 0.52, 0.48, 0.66, 0.6, 0.81], x: [1, 2, 3, 4, 5, 6, 7, 8] });
253
+ * betaregPredict(fit, { newdata: { x: [2.5, 9] } }); // [0.33064, 0.81265]
254
+ * betaregPredict(fit, { type: "quantile", at: [0.1, 0.9] }); // one row per observation: [[0.16414, 0.30026], ...]
255
+ * ```
256
+ * @category Regression
257
+ */
258
+ export declare function betaregPredict(fit: BetaregResult, options?: BetaregPredictOptions): number[] | number[][];
259
+ /**
260
+ * Options for {@link betaregResiduals}.
261
+ * @category Regression
262
+ */
263
+ export interface BetaregResidualsOptions {
264
+ /** `"quantile"` (default), `"deviance"`, `"pearson"`, `"response"`, `"weighted"`, `"sweighted"` or `"sweighted2"`. */
265
+ type?: "quantile" | "deviance" | "pearson" | "response" | "weighted" | "sweighted" | "sweighted2";
266
+ }
267
+ /**
268
+ * Residuals of a {@link betareg} fit (Espinheira, Ferrari and Cribari-Neto 2008; quantile residuals of Dunn and Smyth
269
+ * 1996). Every type but `"response"` is multiplied by the square root of the case weight, as R. Equivalent to
270
+ * `betareg::residuals.betareg()` in R.
271
+ * @example
272
+ * ```ts
273
+ * const fit = betareg("y ~ x", { y: [0.21, 0.35, 0.3, 0.52, 0.48, 0.66, 0.6, 0.81], x: [1, 2, 3, 4, 5, 6, 7, 8] });
274
+ * betaregResiduals(fit, { type: "sweighted2" }).slice(0, 3); // [-0.38464, 1.1271, -1.2608]
275
+ * ```
276
+ * @category Regression
277
+ */
278
+ export declare function betaregResiduals(fit: BetaregResult, options?: BetaregResidualsOptions): number[];