@numero-uno-jpn/rstats 1.3.0 → 1.4.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 (56) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.ja.md +7 -7
  3. package/README.md +7 -7
  4. package/dist/chunks/{chunk-HBRSUHSU.js → chunk-27VFB3SA.js} +2 -2
  5. package/dist/chunks/{chunk-Z74ZOTUN.js → chunk-56GFP4UU.js} +2 -2
  6. package/dist/chunks/{chunk-JJRZ2TTF.js → chunk-5SW3L6J3.js} +2 -2
  7. package/dist/chunks/{chunk-TZTVDVP4.js → chunk-6FZAJQ4H.js} +2 -2
  8. package/dist/chunks/{chunk-I5NWGQOQ.js → chunk-BQJFFGYP.js} +2 -2
  9. package/dist/chunks/{chunk-2VZW4XPK.js → chunk-F6Z3GLWA.js} +2 -2
  10. package/dist/chunks/{chunk-LA4H6ZSC.js → chunk-GBSMRVUY.js} +2 -2
  11. package/dist/chunks/{chunk-P7ZHH2SF.js → chunk-GEF2YRBV.js} +2 -2
  12. package/dist/chunks/{chunk-6X2ZMPF5.js → chunk-GIER5WMB.js} +2 -2
  13. package/dist/chunks/{chunk-AJZV2SVY.js → chunk-GLGOV3A5.js} +2 -2
  14. package/dist/chunks/{chunk-6TZVS6WC.js → chunk-H72MW7YP.js} +2 -2
  15. package/dist/chunks/{chunk-UJYRU37Z.js → chunk-HWB7XRX2.js} +2 -2
  16. package/dist/chunks/chunk-J72MLFUG.js +2 -0
  17. package/dist/chunks/{chunk-PDHBRDTF.js → chunk-PZ66PUWC.js} +1 -1
  18. package/dist/chunks/{chunk-FFNHG5SB.js → chunk-RUZATICF.js} +1 -1
  19. package/dist/chunks/{chunk-UMDXXT3M.js → chunk-RY7CCWVU.js} +1 -1
  20. package/dist/chunks/{chunk-UOAFEB64.js → chunk-S2YCFUCA.js} +2 -2
  21. package/dist/chunks/chunk-SVS54D6Z.js +2 -0
  22. package/dist/chunks/{chunk-LNUNKFIH.js → chunk-TEHMTQNB.js} +2 -2
  23. package/dist/chunks/{chunk-IJV43Y7Q.js → chunk-UMMCVF53.js} +2 -2
  24. package/dist/chunks/{chunk-BNTBZ5W3.js → chunk-UNP4HBPP.js} +2 -2
  25. package/dist/chunks/{chunk-LMNU4NHZ.js → chunk-V2KVTAVV.js} +2 -2
  26. package/dist/chunks/{chunk-EBRTF7RM.js → chunk-WWJGCBWH.js} +1 -1
  27. package/dist/chunks/chunk-X7K6EF7S.js +2 -0
  28. package/dist/chunks/{chunk-GUM57VVM.js → chunk-YBOSCQF2.js} +1 -1
  29. package/dist/chunks/{chunk-IOGQEMDE.js → chunk-ZQSOMEIM.js} +2 -2
  30. package/dist/chunks/{chunk-RCGW2DCK.js → chunk-ZRFZ5UIB.js} +2 -2
  31. package/dist/descriptive.js +2 -2
  32. package/dist/distributions.js +2 -2
  33. package/dist/entries/tests.d.ts +4 -0
  34. package/dist/entries/tests.js +4 -0
  35. package/dist/linalg.js +2 -2
  36. package/dist/mixed.js +2 -2
  37. package/dist/models/competingRisks.d.ts +188 -0
  38. package/dist/models/competingRisks.js +673 -0
  39. package/dist/models/coxZph.d.ts +67 -0
  40. package/dist/models/coxZph.js +479 -0
  41. package/dist/models/coxph.d.ts +61 -21
  42. package/dist/models/coxph.js +305 -65
  43. package/dist/models/rmst2.d.ts +126 -0
  44. package/dist/models/rmst2.js +365 -0
  45. package/dist/models/survival.d.ts +65 -24
  46. package/dist/models/survival.js +407 -72
  47. package/dist/models/survreg.d.ts +160 -0
  48. package/dist/models/survreg.js +809 -0
  49. package/dist/numerics.js +2 -2
  50. package/dist/rstats.js +16 -16
  51. package/dist/special.js +2 -2
  52. package/dist/tests.js +13 -13
  53. package/llms.txt +8 -0
  54. package/package.json +1 -1
  55. package/dist/chunks/chunk-4OOTEXZU.js +0 -2
  56. package/dist/chunks/chunk-MJXETGT2.js +0 -2
@@ -13,6 +13,8 @@ export interface CoxphControl {
13
13
  tolerChol?: number;
14
14
  /** Tolerance of the check for infinite coefficients. Default sqrt(`eps`). */
15
15
  tolerInf?: number;
16
+ /** Whether to merge event times (and start/stop times for counting-process data) within the tolerance of aeqSurv. Default true. */
17
+ timefix?: boolean;
16
18
  }
17
19
  /**
18
20
  * Options for {@link coxph}.
@@ -20,6 +22,10 @@ export interface CoxphControl {
20
22
  * @category Survival analysis
21
23
  */
22
24
  export interface CoxphOptions {
25
+ /** Start times for counting-process data; when present, time is the stop time. */
26
+ start?: readonly number[];
27
+ /** Subject identifiers for counting-process data; missing identifiers drop their rows. */
28
+ id?: readonly (GroupLabel | null)[];
23
29
  /** Handling of tied event times. Default `"efron"`. */
24
30
  ties?: "efron" | "breslow";
25
31
  /** Case weights (positive). A weight that is not an integer switches the robust variance on (see `robust`). */
@@ -35,14 +41,16 @@ export interface CoxphOptions {
35
41
  /** Confidence level of the intervals of exp(coef). Default 0.95. */
36
42
  confLevel?: number;
37
43
  /**
38
- * Whether to use the robust (Lin-Wei sandwich) variance. Default as R: `true` when `cluster` is given or some case
39
- * weight is not an integer, else `false`. With `false` a `cluster` is ignored (with R's warning).
44
+ * Whether to use the robust (Lin-Wei sandwich) variance. Default as R: `true` when `cluster` is given, a counting
45
+ * process `id` has repeated event rows, or some case weight is not an integer, else `false`. With `false` a
46
+ * `cluster` is ignored (with R's warning).
40
47
  */
41
48
  robust?: boolean;
42
49
  /**
43
50
  * Cluster labels, one per observation, for the robust variance (R's `cluster`): the observations of a cluster are
44
51
  * treated as correlated. Rows with a missing label (`null` or NaN) are dropped, like rows with a missing stratum.
45
- * Without it, each observation is its own cluster. At least two clusters are needed.
52
+ * For counting-process data, `id` supplies the subject clusters when `cluster` is absent. Without either, each row
53
+ * is its own cluster for the default robust variance of non-integer weights. At least two clusters are needed.
46
54
  */
47
55
  cluster?: readonly (GroupLabel | null)[];
48
56
  }
@@ -59,12 +67,40 @@ export interface CoxphTest {
59
67
  /** Upper chi-squared tail (R's `pvalue`). */
60
68
  pValue: number;
61
69
  }
70
+ /**
71
+ * Processed coxph data retained privately for coxZph; all row arrays are in the fit's used-input order unless named sorted.
72
+ *
73
+ * @internal
74
+ * @category Survival analysis
75
+ */
76
+ export interface CoxphZphData {
77
+ time: number[];
78
+ start?: number[];
79
+ status: boolean[];
80
+ weights: number[];
81
+ strata?: GroupLabel[];
82
+ x: number[][];
83
+ sortedToInput: number[];
84
+ sortedTime: number[];
85
+ sortedStart?: number[];
86
+ sortedEvent: boolean[];
87
+ sortedWeight: number[];
88
+ sortedX: number[][];
89
+ stratumIndex: number[];
90
+ stratumEnd: boolean[];
91
+ betaScaled: number[];
92
+ inverseCovariateScale: number[];
93
+ weightExp: number;
94
+ ties: "efron" | "breslow";
95
+ }
62
96
  /**
63
97
  * Result of {@link coxph}.
64
98
  *
65
99
  * @category Survival analysis
66
100
  */
67
101
  export interface CoxphResult {
102
+ /** @internal Non-enumerable fit data used by coxZph; not part of the serialized result. */
103
+ coxZphData?: CoxphZphData;
68
104
  /** Coefficients (NaN for R's NA: an aliased column or one whose information fell below the tolerance) */
69
105
  coefficients: number[];
70
106
  /**
@@ -78,7 +114,7 @@ export interface CoxphResult {
78
114
  score: number;
79
115
  /** The Wald statistic of the non-NA coefficients (against `init` when given) */
80
116
  wald: number;
81
- /** Number of iterations (`iterMax + 1` when they ran out) */
117
+ /** Number of iterations (`iterMax + 1` for right-censored fits, `iterMax` for counting-process fits when they ran out). */
82
118
  iter: number;
83
119
  /** The means used to centre the covariates (0 for the columns not centred) */
84
120
  means: number[];
@@ -86,6 +122,8 @@ export interface CoxphResult {
86
122
  n: number;
87
123
  /** Number of events */
88
124
  nevent: number;
125
+ /** Number of distinct subjects, only when id was supplied. */
126
+ nId?: number;
89
127
  /** Linear predictors (centred by the means), one per observation used, in input order */
90
128
  linearPredictors: number[];
91
129
  /**
@@ -138,27 +176,27 @@ export interface CoxphResult {
138
176
  }
139
177
  /**
140
178
  * Cox proportional hazards regression. Equivalent to R's `survival::coxph()`. As
141
- * `coxph(Surv(time, status) ~ x [+ strata(strata)], weights, ties, init, robust, cluster, control)` for right-censored
142
- * data, with the values of `summary(fit)`.
143
- *
144
- * With `robust` (by default when `cluster` is given or a case weight is not an integer) the variance is the robust
145
- * (Lin-Wei sandwich) one, summed over the clusters (each observation its own cluster without `cluster`), as R:
179
+ * `coxph(Surv(time, status) ~ x ...)` for right-censored data and `coxph(Surv(start, stop, status) ~ x ...)` for
180
+ * counting-process data (with the option `start`), with the values of `summary(fit)`.
181
+ * With `robust` (by default when `cluster` is given, a counting-process `id` has repeated event rows, or a case
182
+ * weight is not an integer) the variance is the robust (Lin-Wei sandwich) one, summed over the clusters (each
183
+ * observation its own cluster without `cluster` or `id`), as R:
146
184
  * `var` is the robust variance and `naiveVar` the model-based one; `se` (and `stdError`) stay the model-based standard
147
185
  * errors (R's `se(coef)`), while `z`, `p`, the intervals `lower`/`upper`, `wald` and `waldtest` use the robust ones
148
186
  * (`robustSe`); `robscore` is the robust score test at `init`. The likelihood ratio and score tests and the R^2 ignore
149
187
  * the clustering.
150
188
  *
151
- * Rows with a missing time, status, covariate, weight or stratum are dropped. Times within sqrt(eps) of each other are
152
- * treated as tied. Covariates whose values all lie in `nocenter` are not centred; the others are centred by their
153
- * weighted means, which only shifts the linear predictors. R's warnings (non-convergence, possibly infinite
154
- * coefficients) are returned in `warnings`.
189
+ * Rows with a missing time, status, covariate, weight, stratum, cluster or id are dropped. With `start`, the time is
190
+ * the stop time and the risk set is `start < t <= stop`; start and stop times are merged together unless
191
+ * `control.timefix` is false. Counting-process means are unweighted; right-censored means are weighted. With `id`,
192
+ * `nId` reports distinct subjects; `rsq` still uses the number of rows. R's warnings are returned in `warnings`.
155
193
  *
156
- * @param time Follow-up times.
157
- * @param status 1 for an event, 0 for a censored time.
194
+ * @param time Follow-up/stop times; with `start`, these are the stop times.
195
+ * @param status 1 for an event, 0 for a censored time (other counting-process values are dropped with a warning).
158
196
  * @param x The covariate matrix, one row per observation (at least one column).
159
197
  * @param options See {@link CoxphOptions}.
160
- * @throws TypeError if `robust` is not a boolean. RangeError for invalid arguments, among them an infinite weight
161
- * and a robust variance with fewer than two clusters.
198
+ * @throws TypeError if `robust` or `control.timefix` is not a boolean. RangeError for invalid arguments, among them
199
+ * an infinite weight, an interval with `start >= stop`, and a robust variance with fewer than two clusters.
162
200
  *
163
201
  * @example
164
202
  * ```ts
@@ -171,14 +209,16 @@ export interface CoxphResult {
171
209
  */
172
210
  export declare function coxph(time: readonly number[], status: readonly number[], x: readonly (readonly number[])[], options?: CoxphOptions): CoxphResult;
173
211
  /**
174
- * The fit of {@link coxph}, and with the robust variance also the residuals it was made from (for the tests; not
175
- * exported from the package): R's `residuals(fit, type = "score")` (unweighted) and `residuals(fit, type =
176
- * "dfbeta")` (weighted), one row per observation used, in input order.
212
+ * The fit of {@link coxph}, plus the score and dfbeta residuals used by the tests (not exported from the package):
213
+ * R's `residuals(fit, type = "score")` (unweighted) and `residuals(fit, type = "dfbeta")` (weighted), one row per
214
+ * observation used, in input order. Counting-process fixtures also compare the final score vector and convergence flag.
177
215
  *
178
216
  * @internal
179
217
  */
180
- export declare function fitCoxph(time: readonly number[], status: readonly number[], x: readonly (readonly number[])[], options?: CoxphOptions): {
218
+ export declare function fitCoxph(time: readonly number[], status: readonly number[], x: readonly (readonly number[])[], options?: CoxphOptions, collectCountingResiduals?: boolean): {
181
219
  result: CoxphResult;
182
220
  scoreResiduals?: number[][];
183
221
  dfbeta?: number[][];
222
+ first?: number[];
223
+ converged?: boolean;
184
224
  };