@numero-uno-jpn/rstats 0.10.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.
Files changed (280) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.ja.md +13 -9
  3. package/README.md +13 -8
  4. package/dist/chunks/{chunk-QJJWGNJP.js → chunk-2X7JYQBI.js} +2 -2
  5. package/dist/chunks/{chunk-O6PT7IVU.js → chunk-36GVER3O.js} +2 -2
  6. package/dist/chunks/{chunk-EWC6I75B.js → chunk-3WUXRSM6.js} +1 -1
  7. package/dist/chunks/{chunk-4NM37MGA.js → chunk-6I6QKTFK.js} +2 -2
  8. package/dist/chunks/{chunk-2XKG3DX4.js → chunk-ETOEZTGL.js} +1 -1
  9. package/dist/chunks/{chunk-IT354SHV.js → chunk-FVPDVRJQ.js} +2 -2
  10. package/dist/chunks/{chunk-QULPY6YM.js → chunk-GG4BJMJW.js} +1 -1
  11. package/dist/chunks/{chunk-7HPVUVZB.js → chunk-HITD7CX6.js} +1 -1
  12. package/dist/chunks/{chunk-LIMZKONM.js → chunk-KK4GE65D.js} +2 -2
  13. package/dist/chunks/chunk-LAUYSGV4.js +3 -0
  14. package/dist/chunks/chunk-M6GDXKKS.js +2 -0
  15. package/dist/chunks/{chunk-QFULZNHL.js → chunk-PHHUHR7T.js} +1 -1
  16. package/dist/chunks/{chunk-ENL43FNO.js → chunk-WQPFDDIY.js} +2 -2
  17. package/dist/chunks/chunk-X2AWQSVS.js +2 -0
  18. package/dist/chunks/{chunk-ZRIM4R4A.js → chunk-ZRJQD7VS.js} +2 -2
  19. package/dist/data/grouping.d.ts +100 -0
  20. package/dist/data/grouping.js +264 -0
  21. package/dist/descriptive/basic.d.ts +130 -17
  22. package/dist/descriptive/basic.js +115 -14
  23. package/dist/descriptive/cov.d.ts +22 -12
  24. package/dist/descriptive/dataFrames.d.ts +138 -0
  25. package/dist/descriptive/dataFrames.js +400 -0
  26. package/dist/descriptive/factanal.d.ts +26 -6
  27. package/dist/descriptive/factanal.js +7 -3
  28. package/dist/descriptive/hist.d.ts +27 -6
  29. package/dist/descriptive/hist.js +9 -3
  30. package/dist/descriptive/missing.d.ts +42 -0
  31. package/dist/descriptive/missing.js +52 -0
  32. package/dist/descriptive/moments.d.ts +91 -13
  33. package/dist/descriptive/moments.js +66 -9
  34. package/dist/descriptive/omega.d.ts +28 -6
  35. package/dist/descriptive/omega.js +16 -4
  36. package/dist/descriptive/pivot.d.ts +105 -0
  37. package/dist/descriptive/pivot.js +347 -0
  38. package/dist/descriptive/quantile.d.ts +33 -5
  39. package/dist/descriptive/quantile.js +20 -2
  40. package/dist/descriptive/rank.d.ts +12 -2
  41. package/dist/descriptive/rank.js +2 -0
  42. package/dist/descriptive/table.d.ts +55 -7
  43. package/dist/descriptive/table.js +38 -4
  44. package/dist/descriptive.js +2 -2
  45. package/dist/distributions/arcsine.d.ts +40 -5
  46. package/dist/distributions/arcsine.js +35 -4
  47. package/dist/distributions/beta.d.ts +12 -0
  48. package/dist/distributions/beta.js +12 -0
  49. package/dist/distributions/binomial.d.ts +18 -0
  50. package/dist/distributions/binomial.js +18 -0
  51. package/dist/distributions/bvnorm.d.ts +4 -1
  52. package/dist/distributions/bvnorm.js +4 -1
  53. package/dist/distributions/cauchy.d.ts +24 -0
  54. package/dist/distributions/cauchy.js +24 -0
  55. package/dist/distributions/chisq.d.ts +18 -0
  56. package/dist/distributions/chisq.js +18 -0
  57. package/dist/distributions/exponential.d.ts +29 -1
  58. package/dist/distributions/exponential.js +24 -0
  59. package/dist/distributions/f.d.ts +18 -0
  60. package/dist/distributions/f.js +18 -0
  61. package/dist/distributions/gamma.d.ts +20 -0
  62. package/dist/distributions/gamma.js +18 -0
  63. package/dist/distributions/geometric.d.ts +24 -0
  64. package/dist/distributions/geometric.js +24 -0
  65. package/dist/distributions/hypergeometric.d.ts +24 -0
  66. package/dist/distributions/hypergeometric.js +24 -0
  67. package/dist/distributions/invgamma.d.ts +32 -4
  68. package/dist/distributions/invgamma.js +27 -3
  69. package/dist/distributions/kumaraswamy.d.ts +31 -3
  70. package/dist/distributions/kumaraswamy.js +31 -3
  71. package/dist/distributions/laplace.d.ts +36 -4
  72. package/dist/distributions/laplace.js +31 -3
  73. package/dist/distributions/logistic.d.ts +29 -1
  74. package/dist/distributions/logistic.js +24 -0
  75. package/dist/distributions/lognormal.d.ts +29 -1
  76. package/dist/distributions/lognormal.js +24 -0
  77. package/dist/distributions/multinomial.d.ts +7 -1
  78. package/dist/distributions/multinomial.js +2 -0
  79. package/dist/distributions/negbinomial.d.ts +29 -1
  80. package/dist/distributions/negbinomial.js +24 -0
  81. package/dist/distributions/normal.d.ts +11 -1
  82. package/dist/distributions/normal.js +6 -0
  83. package/dist/distributions/pareto.d.ts +36 -4
  84. package/dist/distributions/pareto.js +31 -3
  85. package/dist/distributions/poisson.d.ts +18 -0
  86. package/dist/distributions/poisson.js +18 -0
  87. package/dist/distributions/signrank.d.ts +24 -0
  88. package/dist/distributions/signrank.js +24 -0
  89. package/dist/distributions/summary.d.ts +20 -2
  90. package/dist/distributions/summary.js +4 -0
  91. package/dist/distributions/t.d.ts +18 -0
  92. package/dist/distributions/t.js +18 -0
  93. package/dist/distributions/triangular.d.ts +36 -4
  94. package/dist/distributions/triangular.js +31 -3
  95. package/dist/distributions/tukey.d.ts +15 -1
  96. package/dist/distributions/tukey.js +10 -0
  97. package/dist/distributions/uniform.d.ts +29 -1
  98. package/dist/distributions/uniform.js +24 -0
  99. package/dist/distributions/weibull.d.ts +29 -1
  100. package/dist/distributions/weibull.js +24 -0
  101. package/dist/distributions/wilcox.d.ts +24 -0
  102. package/dist/distributions/wilcox.js +24 -0
  103. package/dist/distributions.js +2 -2
  104. package/dist/entries/descriptive.d.ts +5 -1
  105. package/dist/entries/descriptive.js +4 -0
  106. package/dist/entries/numerics.d.ts +1 -1
  107. package/dist/entries/tests.js +1 -1
  108. package/dist/htest/agreement.d.ts +61 -23
  109. package/dist/htest/agreement.js +19 -9
  110. package/dist/htest/ansariTest.d.ts +19 -1
  111. package/dist/htest/ansariTest.js +5 -17
  112. package/dist/htest/aov.d.ts +43 -10
  113. package/dist/htest/aov.js +17 -3
  114. package/dist/htest/binomTest.d.ts +12 -2
  115. package/dist/htest/binomTest.js +2 -0
  116. package/dist/htest/brunnerMunzelTest.d.ts +9 -3
  117. package/dist/htest/brunnerMunzelTest.js +4 -2
  118. package/dist/htest/chisqTest.d.ts +19 -3
  119. package/dist/htest/cor.d.ts +31 -3
  120. package/dist/htest/cor.js +9 -27
  121. package/dist/htest/effectSize.d.ts +70 -12
  122. package/dist/htest/effectSize.js +40 -7
  123. package/dist/htest/fisherTest.d.ts +9 -1
  124. package/dist/htest/fisherTest.js +2 -0
  125. package/dist/htest/groups.d.ts +5 -1
  126. package/dist/htest/ksTest.d.ts +32 -2
  127. package/dist/htest/ksTest.js +5 -8
  128. package/dist/htest/leveneTest.d.ts +15 -4
  129. package/dist/htest/leveneTest.js +5 -2
  130. package/dist/htest/mantelhaenTest.d.ts +25 -3
  131. package/dist/htest/mantelhaenTest.js +15 -1
  132. package/dist/htest/mcnemarTest.d.ts +14 -4
  133. package/dist/htest/mcnemarTest.js +4 -2
  134. package/dist/htest/multipleComparisons.d.ts +173 -29
  135. package/dist/htest/multipleComparisons.js +123 -19
  136. package/dist/htest/normalityTests.d.ts +56 -9
  137. package/dist/htest/normalityTests.js +40 -6
  138. package/dist/htest/onewayTest.d.ts +45 -2
  139. package/dist/htest/onewayTest.js +15 -7
  140. package/dist/htest/pAdjust.d.ts +9 -1
  141. package/dist/htest/pAdjust.js +2 -0
  142. package/dist/htest/pairwise.d.ts +50 -5
  143. package/dist/htest/pairwise.js +25 -0
  144. package/dist/htest/poissonTest.d.ts +12 -2
  145. package/dist/htest/poissonTest.js +2 -0
  146. package/dist/htest/polycor.d.ts +29 -10
  147. package/dist/htest/power.d.ts +60 -6
  148. package/dist/htest/power.js +6 -0
  149. package/dist/htest/propTest.d.ts +13 -2
  150. package/dist/htest/propTest.js +2 -0
  151. package/dist/htest/pwr.d.ts +286 -36
  152. package/dist/htest/pwr.js +116 -15
  153. package/dist/htest/rankTests.d.ts +132 -7
  154. package/dist/htest/rankTests.js +30 -33
  155. package/dist/htest/tTest.d.ts +32 -2
  156. package/dist/htest/tTest.js +19 -24
  157. package/dist/htest/testFormula.d.ts +57 -0
  158. package/dist/htest/testFormula.js +171 -0
  159. package/dist/htest/trendTests.d.ts +29 -8
  160. package/dist/htest/trendTests.js +8 -4
  161. package/dist/htest/types.d.ts +14 -2
  162. package/dist/htest/varTest.d.ts +46 -6
  163. package/dist/htest/varTest.js +11 -21
  164. package/dist/htest/wilcoxTest.d.ts +23 -1
  165. package/dist/htest/wilcoxTest.js +9 -24
  166. package/dist/internal/dpq.d.ts +4 -0
  167. package/dist/internal/noncentral.d.ts +2 -0
  168. package/dist/internal/vectorize.d.ts +4 -0
  169. package/dist/linalg/basic.d.ts +39 -5
  170. package/dist/linalg/basic.js +15 -0
  171. package/dist/linalg/chol.d.ts +26 -5
  172. package/dist/linalg/chol.js +7 -0
  173. package/dist/linalg/eigen.d.ts +16 -7
  174. package/dist/linalg/eigen.js +6 -5
  175. package/dist/linalg/expm.d.ts +15 -5
  176. package/dist/linalg/expm.js +5 -3
  177. package/dist/linalg/kappa.d.ts +21 -1
  178. package/dist/linalg/kappa.js +16 -0
  179. package/dist/linalg/lu.d.ts +30 -6
  180. package/dist/linalg/lu.js +15 -3
  181. package/dist/linalg/matrix.d.ts +4 -0
  182. package/dist/linalg/norm.d.ts +16 -1
  183. package/dist/linalg/norm.js +9 -0
  184. package/dist/linalg/ops.d.ts +168 -36
  185. package/dist/linalg/ops.js +116 -20
  186. package/dist/linalg/qr.d.ts +87 -12
  187. package/dist/linalg/qr.js +31 -0
  188. package/dist/linalg/schur.d.ts +8 -2
  189. package/dist/linalg/schur.js +3 -1
  190. package/dist/linalg/solve.d.ts +42 -6
  191. package/dist/linalg/solve.js +22 -0
  192. package/dist/linalg/svd.d.ts +12 -2
  193. package/dist/linalg/svd.js +2 -0
  194. package/dist/linalg.js +2 -2
  195. package/dist/models/anovaSequential.d.ts +26 -4
  196. package/dist/models/anovaSequential.js +3 -1
  197. package/dist/models/aovEz.d.ts +29 -6
  198. package/dist/models/aovEz.js +5 -2
  199. package/dist/models/aovStrata.d.ts +12 -2
  200. package/dist/models/carAnova.d.ts +9 -3
  201. package/dist/models/carAnova.js +4 -2
  202. package/dist/models/coxph.d.ts +33 -7
  203. package/dist/models/coxph.js +8 -3
  204. package/dist/models/glm.d.ts +128 -21
  205. package/dist/models/glm.js +71 -14
  206. package/dist/models/glmAnova.d.ts +30 -5
  207. package/dist/models/glmAnova.js +15 -2
  208. package/dist/models/glmConfint.d.ts +16 -2
  209. package/dist/models/glmConfint.js +9 -1
  210. package/dist/models/glmFamily.d.ts +27 -5
  211. package/dist/models/lm.d.ts +75 -17
  212. package/dist/models/lm.js +22 -4
  213. package/dist/models/mauchly.d.ts +20 -5
  214. package/dist/models/mauchly.js +7 -3
  215. package/dist/models/modelFrame.d.ts +5 -1
  216. package/dist/models/modelMatrix.d.ts +18 -4
  217. package/dist/models/modelMatrix.js +3 -1
  218. package/dist/models/survival.d.ts +41 -9
  219. package/dist/models/survival.js +10 -4
  220. package/dist/numerics/deriv.d.ts +21 -6
  221. package/dist/numerics/deriv.js +16 -5
  222. package/dist/numerics/integrate.d.ts +37 -7
  223. package/dist/numerics/integrate.js +8 -2
  224. package/dist/numerics/interp.d.ts +63 -12
  225. package/dist/numerics/interp.js +30 -6
  226. package/dist/numerics/ode.d.ts +15 -5
  227. package/dist/numerics/ode.js +5 -3
  228. package/dist/numerics.js +2 -2
  229. package/dist/optim/optim.d.ts +32 -8
  230. package/dist/optim/optim.js +8 -4
  231. package/dist/random/beta.d.ts +8 -0
  232. package/dist/random/beta.js +8 -0
  233. package/dist/random/binomial.d.ts +16 -0
  234. package/dist/random/binomial.js +16 -0
  235. package/dist/random/continuous.d.ts +51 -0
  236. package/dist/random/continuous.js +51 -0
  237. package/dist/random/extra.d.ts +66 -6
  238. package/dist/random/extra.js +66 -6
  239. package/dist/random/gamma.d.ts +33 -0
  240. package/dist/random/gamma.js +33 -0
  241. package/dist/random/hyper.d.ts +8 -0
  242. package/dist/random/hyper.js +8 -0
  243. package/dist/random/poisson.d.ts +25 -0
  244. package/dist/random/poisson.js +25 -0
  245. package/dist/random/r2dtable.d.ts +2 -0
  246. package/dist/random/r2dtable.js +2 -0
  247. package/dist/random/rank.d.ts +16 -0
  248. package/dist/random/rank.js +16 -0
  249. package/dist/random/rng.d.ts +49 -6
  250. package/dist/random/rng.js +29 -2
  251. package/dist/random/sample.d.ts +10 -2
  252. package/dist/random/sample.js +5 -1
  253. package/dist/random/streams.d.ts +13 -0
  254. package/dist/random/streams.js +13 -0
  255. package/dist/rstats.js +14 -14
  256. package/dist/special/besselIK.d.ts +11 -3
  257. package/dist/special/besselIK.js +6 -2
  258. package/dist/special/besselJY.d.ts +6 -2
  259. package/dist/special/besselJY.js +6 -2
  260. package/dist/special/beta.d.ts +16 -2
  261. package/dist/special/beta.js +16 -2
  262. package/dist/special/choose.d.ts +13 -5
  263. package/dist/special/choose.js +13 -5
  264. package/dist/special/erf.d.ts +8 -3
  265. package/dist/special/erf.js +8 -3
  266. package/dist/special/extra.d.ts +30 -10
  267. package/dist/special/extra.js +25 -9
  268. package/dist/special/gamma.d.ts +18 -2
  269. package/dist/special/gamma.js +18 -2
  270. package/dist/special/log1p.d.ts +16 -7
  271. package/dist/special/log1p.js +16 -7
  272. package/dist/special/psigamma.d.ts +9 -3
  273. package/dist/special/psigamma.js +9 -3
  274. package/dist/special/rCompatible.d.ts +5 -1
  275. package/dist/special.js +2 -2
  276. package/dist/tests.js +12 -13
  277. package/llms.txt +14 -0
  278. package/package.json +1 -1
  279. package/dist/chunks/chunk-AECGWZHD.js +0 -2
  280. package/dist/chunks/chunk-XWTZ4RTR.js +0 -2
@@ -1,16 +1,28 @@
1
1
  import { type FormulaNode, type ParsedFormula, type Terms } from "./formula.js";
2
2
  import { type DataFrame, type ModelFrame } from "./modelFrame.js";
3
3
  import type { Sample } from "../htest/types.js";
4
- /** A contrast of a factor: R's `contr.treatment`, `contr.sum` or `contr.helmert`. */
4
+ /**
5
+ * A contrast of a factor: R's `contr.treatment`, `contr.sum` or `contr.helmert`.
6
+ *
7
+ * @category Linear models and ANOVA
8
+ */
5
9
  export type ContrastName = "contr.treatment" | "contr.sum" | "contr.helmert";
6
- /** Options for {@link modelMatrix}. */
10
+ /**
11
+ * Options for {@link modelMatrix}.
12
+ *
13
+ * @category Linear models and ANOVA
14
+ */
7
15
  export interface ModelMatrixOptions {
8
16
  /** A contrast per factor (default `"contr.treatment"`). */
9
17
  contrasts?: Record<string, ContrastName>;
10
18
  /** The order of the levels of a factor (`{ A: ["c", "a", "b"] }`), as `factor(x, levels = ...)` in R. */
11
19
  levels?: Record<string, readonly string[]>;
12
20
  }
13
- /** Result of {@link modelMatrix}. */
21
+ /**
22
+ * Result of {@link modelMatrix}.
23
+ *
24
+ * @category Linear models and ANOVA
25
+ */
14
26
  export interface ModelMatrixResult {
15
27
  /** Column names, such as `"(Intercept)"`, `"Ab"`, `"Ab:Bq"`, `"x"`. */
16
28
  colNames: string[];
@@ -69,7 +81,7 @@ export interface DesignOptions extends ModelMatrixOptions {
69
81
  export declare function design(parsed: ParsedFormula, data: DataFrame, options?: DesignOptions, rhs?: FormulaNode | undefined): Design;
70
82
  /**
71
83
  * The model matrix of a formula on a data frame, with the attributes of R's `terms()`. Equivalent to R's
72
- * `model.matrix(formula, data)` (with `contrasts.arg`), together with `attr(terms(formula), ...)`.
84
+ * `model.matrix(formula, data)`. With `contrasts.arg`, together with `attr(terms(formula), ...)`.
73
85
  *
74
86
  * Strings are factors (levels sorted by code point unless `levels` gives them), booleans factors with levels FALSE
75
87
  * and TRUE, numbers numeric. Rows with a missing value (`null`, or `NaN` in a numeric column) in any variable of the
@@ -84,5 +96,7 @@ export declare function design(parsed: ParsedFormula, data: DataFrame, options?:
84
96
  * m.colNames; // ["(Intercept)", "Ab"]
85
97
  * m.x; // [[1, 0], [1, 1], [1, 0], [1, 1]]
86
98
  * ```
99
+ *
100
+ * @category Linear models and ANOVA
87
101
  */
88
102
  export declare function modelMatrix(formula: string, data: DataFrame, options?: ModelMatrixOptions): ModelMatrixResult;
@@ -136,7 +136,7 @@ export function design(parsed, data, options = {}, rhs = parsed.rhs) {
136
136
  }
137
137
  /**
138
138
  * The model matrix of a formula on a data frame, with the attributes of R's `terms()`. Equivalent to R's
139
- * `model.matrix(formula, data)` (with `contrasts.arg`), together with `attr(terms(formula), ...)`.
139
+ * `model.matrix(formula, data)`. With `contrasts.arg`, together with `attr(terms(formula), ...)`.
140
140
  *
141
141
  * Strings are factors (levels sorted by code point unless `levels` gives them), booleans factors with levels FALSE
142
142
  * and TRUE, numbers numeric. Rows with a missing value (`null`, or `NaN` in a numeric column) in any variable of the
@@ -151,6 +151,8 @@ export function design(parsed, data, options = {}, rhs = parsed.rhs) {
151
151
  * m.colNames; // ["(Intercept)", "Ab"]
152
152
  * m.x; // [[1, 0], [1, 1], [1, 0], [1, 1]]
153
153
  * ```
154
+ *
155
+ * @category Linear models and ANOVA
154
156
  */
155
157
  export function modelMatrix(formula, data, options = {}) {
156
158
  const d = design(parseFormula(formula), data, options);
@@ -1,10 +1,18 @@
1
1
  import type { GroupLabel } from "../htest/groups.js";
2
- /** Options for {@link survdiff}. */
2
+ /**
3
+ * Options for {@link survdiff}.
4
+ *
5
+ * @category Survival analysis
6
+ */
3
7
  export interface SurvdiffOptions {
4
8
  /** Exponent of the weights S(t-)^rho (pooled Kaplan-Meier estimate just before each event time). Default 0. */
5
9
  rho?: number;
6
10
  }
7
- /** Result of {@link survdiff}. */
11
+ /**
12
+ * Result of {@link survdiff}.
13
+ *
14
+ * @category Survival analysis
15
+ */
8
16
  export interface SurvdiffResult {
9
17
  /** Number of observations per group */
10
18
  n: number[];
@@ -21,9 +29,17 @@ export interface SurvdiffResult {
21
29
  /** Upper chi-squared tail on (number of groups with a positive expected count) - 1 degrees of freedom */
22
30
  pvalue: number;
23
31
  }
24
- /** Confidence interval type of {@link survfit}. */
32
+ /**
33
+ * Confidence interval type of {@link survfit}.
34
+ *
35
+ * @category Survival analysis
36
+ */
25
37
  export type SurvfitConfType = "log" | "plain" | "log-log";
26
- /** Options for {@link survfit}. */
38
+ /**
39
+ * Options for {@link survfit}.
40
+ *
41
+ * @category Survival analysis
42
+ */
27
43
  export interface SurvfitOptions {
28
44
  /** Group labels, one per observation: one curve per group. Omitted: a single curve. */
29
45
  group?: readonly GroupLabel[];
@@ -32,19 +48,29 @@ export interface SurvfitOptions {
32
48
  /** Confidence level. Default 0.95. */
33
49
  confInt?: number;
34
50
  }
35
- /** Result of {@link survfit}: the rows of R's `summary(fit, censored = TRUE)` and the medians. */
51
+ /**
52
+ * Result of {@link survfit}: the rows of R's `summary(fit, censored = TRUE)` and the medians.
53
+ *
54
+ * @category Survival analysis
55
+ */
36
56
  export interface SurvfitResult {
37
57
  /** Stratum of each row (`"group=<label>"`, or `"all"` for a single curve) */
38
58
  strata: string[];
59
+ /** Time of each row (the distinct times of the stratum, censored ones included) */
39
60
  time: number[];
61
+ /** Number at risk just before the time (R's `n.risk`) */
40
62
  nRisk: number[];
63
+ /** Number of events at the time (R's `n.event`) */
41
64
  nEvent: number[];
65
+ /** Number censored at the time (R's `n.censor`) */
42
66
  nCensor: number[];
43
67
  /** Kaplan-Meier estimate S(t) */
44
68
  surv: number[];
45
69
  /** Standard error of S(t) (S times the standard error of log S) */
46
70
  stdErr: number[];
71
+ /** Lower limit of the pointwise confidence interval of S(t) */
47
72
  lower: number[];
73
+ /** Upper limit of the pointwise confidence interval of S(t) */
48
74
  upper: number[];
49
75
  /** Per stratum, [median, lower limit, upper limit] (NaN for R's NA) */
50
76
  median: number[][];
@@ -53,7 +79,7 @@ export interface SurvfitResult {
53
79
  }
54
80
  /**
55
81
  * Test of the difference between survival curves: the G-rho family of Harrington and Fleming, the log-rank test for
56
- * `rho = 0`. Equivalent to R's `survdiff(Surv(time, status) ~ group, rho = rho)` (package survival).
82
+ * `rho = 0`. Equivalent to R's `survival::survdiff()`. As `survdiff(Surv(time, status) ~ group, rho = rho)`.
57
83
  *
58
84
  * Rows with a missing time, status or group are dropped.
59
85
  *
@@ -64,14 +90,18 @@ export interface SurvfitResult {
64
90
  *
65
91
  * @example
66
92
  * ```ts
67
- * survdiff([1, 2, 3, 4, 5, 6], [1, 1, 0, 1, 1, 1], ["a", "b", "a", "b", "a", "b"]).chisq;
93
+ * const r = survdiff([1, 2, 3, 4, 5, 6], [1, 1, 0, 1, 1, 1], ["a", "b", "a", "b", "a", "b"]);
94
+ * r.chisq; // 0.073903
95
+ * r.pvalue; // 0.78574
68
96
  * ```
97
+ *
98
+ * @category Survival analysis
69
99
  */
70
100
  export declare function survdiff(time: readonly number[], status: readonly number[], group: readonly (GroupLabel | null)[], options?: SurvdiffOptions): SurvdiffResult;
71
101
  /**
72
102
  * Kaplan-Meier estimate of the survival function with Greenwood's standard error and pointwise confidence intervals.
73
- * Equivalent to R's `summary(survfit(Surv(time, status) ~ group, conf.type, conf.int), censored = TRUE)` (package
74
- * survival), with the medians and their confidence limits of `summary(fit)$table`.
103
+ * Equivalent to R's `survival::survfit()`. As `summary(survfit(Surv(time, status) ~ group, conf.type, conf.int),
104
+ * censored = TRUE)`, with the medians and their confidence limits of `summary(fit)$table`.
75
105
  *
76
106
  * Rows with a missing time, status or group are dropped.
77
107
  *
@@ -83,5 +113,7 @@ export declare function survdiff(time: readonly number[], status: readonly numbe
83
113
  * ```ts
84
114
  * survfit([1, 2, 2, 3, 4], [1, 1, 0, 1, 0]).surv; // [0.8, 0.6, 0.3, 0.3]
85
115
  * ```
116
+ *
117
+ * @category Survival analysis
86
118
  */
87
119
  export declare function survfit(time: readonly number[], status: readonly number[], options?: SurvfitOptions): SurvfitResult;
@@ -43,7 +43,7 @@ function prepare(time, status, group) {
43
43
  }
44
44
  /**
45
45
  * Test of the difference between survival curves: the G-rho family of Harrington and Fleming, the log-rank test for
46
- * `rho = 0`. Equivalent to R's `survdiff(Surv(time, status) ~ group, rho = rho)` (package survival).
46
+ * `rho = 0`. Equivalent to R's `survival::survdiff()`. As `survdiff(Surv(time, status) ~ group, rho = rho)`.
47
47
  *
48
48
  * Rows with a missing time, status or group are dropped.
49
49
  *
@@ -54,8 +54,12 @@ function prepare(time, status, group) {
54
54
  *
55
55
  * @example
56
56
  * ```ts
57
- * survdiff([1, 2, 3, 4, 5, 6], [1, 1, 0, 1, 1, 1], ["a", "b", "a", "b", "a", "b"]).chisq;
57
+ * const r = survdiff([1, 2, 3, 4, 5, 6], [1, 1, 0, 1, 1, 1], ["a", "b", "a", "b", "a", "b"]);
58
+ * r.chisq; // 0.073903
59
+ * r.pvalue; // 0.78574
58
60
  * ```
61
+ *
62
+ * @category Survival analysis
59
63
  */
60
64
  export function survdiff(time, status, group, options = {}) {
61
65
  const { rho = 0 } = options;
@@ -144,8 +148,8 @@ function curveMedian(time, nEvent, curve) {
144
148
  }
145
149
  /**
146
150
  * Kaplan-Meier estimate of the survival function with Greenwood's standard error and pointwise confidence intervals.
147
- * Equivalent to R's `summary(survfit(Surv(time, status) ~ group, conf.type, conf.int), censored = TRUE)` (package
148
- * survival), with the medians and their confidence limits of `summary(fit)$table`.
151
+ * Equivalent to R's `survival::survfit()`. As `summary(survfit(Surv(time, status) ~ group, conf.type, conf.int),
152
+ * censored = TRUE)`, with the medians and their confidence limits of `summary(fit)$table`.
149
153
  *
150
154
  * Rows with a missing time, status or group are dropped.
151
155
  *
@@ -157,6 +161,8 @@ function curveMedian(time, nEvent, curve) {
157
161
  * ```ts
158
162
  * survfit([1, 2, 2, 3, 4], [1, 1, 0, 1, 0]).surv; // [0.8, 0.6, 0.3, 0.3]
159
163
  * ```
164
+ *
165
+ * @category Survival analysis
160
166
  */
161
167
  export function survfit(time, status, options = {}) {
162
168
  const { group, confType = "log", confInt = 0.95 } = options;
@@ -1,4 +1,8 @@
1
- /** Options for {@link grad}, {@link jacobian} and {@link hessian}. */
1
+ /**
2
+ * Options for {@link grad}, {@link jacobian} and {@link hessian}.
3
+ *
4
+ * @category Numerical methods
5
+ */
2
6
  export interface DerivOptions {
3
7
  /** `"Richardson"` (default) or `"simple"` (forward difference; not for `hessian`). */
4
8
  method?: "Richardson" | "simple";
@@ -12,26 +16,37 @@ export interface DerivOptions {
12
16
  r?: number;
13
17
  }
14
18
  /**
15
- * Gradient of a scalar function of a vector. Equivalent to `numDeriv::grad(func, x, method)`.
19
+ * Gradient of a scalar function of a vector. Equivalent to `numDeriv::grad(func, x, method)` in R.
16
20
  *
17
21
  * @example
18
22
  * ```ts
19
- * grad((x) => x[0]! ** 2 + Math.sin(x[1]!), [1, 0]); // ≈ [2, 1]
23
+ * grad((x) => x[0]! ** 2 + Math.sin(x[1]!), [1, 0]); // [2, 1]
20
24
  * ```
25
+ *
26
+ * @category Numerical methods
21
27
  */
22
28
  export declare function grad(func: (x: number[]) => number, x: readonly number[], options?: DerivOptions): number[];
23
29
  /**
24
30
  * Jacobian of a vector function of a vector: row i holds the derivatives of the i-th value. Equivalent to
25
- * `numDeriv::jacobian(func, x, method)`.
31
+ * `numDeriv::jacobian(func, x, method)` in R.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * jacobian((x) => [x[0]! * x[1]!, x[0]! + 2 * x[1]!], [2, 3]); // [[3, 2], [1, 2]]
36
+ * ```
37
+ *
38
+ * @category Numerical methods
26
39
  */
27
40
  export declare function jacobian(func: (x: number[]) => readonly number[], x: readonly number[], options?: DerivOptions): number[][];
28
41
  /**
29
42
  * Hessian matrix of a scalar function of a vector, by Richardson extrapolation (Bates and Watts). Equivalent to
30
- * `numDeriv::hessian(func, x)`.
43
+ * `numDeriv::hessian(func, x)` in R.
31
44
  *
32
45
  * @example
33
46
  * ```ts
34
- * hessian((x) => x[0]! ** 2 * x[1]!, [1, 2]); // ≈ [[4, 2], [2, 0]]
47
+ * hessian((x) => x[0]! ** 2 * x[1]! ** 2, [1, 2]); // [[8, 8], [8, 2]]
35
48
  * ```
49
+ *
50
+ * @category Numerical methods
36
51
  */
37
52
  export declare function hessian(func: (x: number[]) => number, x: readonly number[], options?: DerivOptions): number[][];
@@ -38,12 +38,14 @@ function method(options) {
38
38
  return m;
39
39
  }
40
40
  /**
41
- * Gradient of a scalar function of a vector. Equivalent to `numDeriv::grad(func, x, method)`.
41
+ * Gradient of a scalar function of a vector. Equivalent to `numDeriv::grad(func, x, method)` in R.
42
42
  *
43
43
  * @example
44
44
  * ```ts
45
- * grad((x) => x[0]! ** 2 + Math.sin(x[1]!), [1, 0]); // ≈ [2, 1]
45
+ * grad((x) => x[0]! ** 2 + Math.sin(x[1]!), [1, 0]); // [2, 1]
46
46
  * ```
47
+ *
48
+ * @category Numerical methods
47
49
  */
48
50
  export function grad(func, x, options = {}) {
49
51
  const xs = [...x];
@@ -74,7 +76,14 @@ export function grad(func, x, options = {}) {
74
76
  }
75
77
  /**
76
78
  * Jacobian of a vector function of a vector: row i holds the derivatives of the i-th value. Equivalent to
77
- * `numDeriv::jacobian(func, x, method)`.
79
+ * `numDeriv::jacobian(func, x, method)` in R.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * jacobian((x) => [x[0]! * x[1]!, x[0]! + 2 * x[1]!], [2, 3]); // [[3, 2], [1, 2]]
84
+ * ```
85
+ *
86
+ * @category Numerical methods
78
87
  */
79
88
  export function jacobian(func, x, options = {}) {
80
89
  const xs = [...x];
@@ -105,12 +114,14 @@ export function jacobian(func, x, options = {}) {
105
114
  }
106
115
  /**
107
116
  * Hessian matrix of a scalar function of a vector, by Richardson extrapolation (Bates and Watts). Equivalent to
108
- * `numDeriv::hessian(func, x)`.
117
+ * `numDeriv::hessian(func, x)` in R.
109
118
  *
110
119
  * @example
111
120
  * ```ts
112
- * hessian((x) => x[0]! ** 2 * x[1]!, [1, 2]); // ≈ [[4, 2], [2, 0]]
121
+ * hessian((x) => x[0]! ** 2 * x[1]! ** 2, [1, 2]); // [[8, 8], [8, 2]]
113
122
  * ```
123
+ *
124
+ * @category Numerical methods
114
125
  */
115
126
  export function hessian(func, x, options = {}) {
116
127
  if ((options.method ?? "Richardson") !== "Richardson")
@@ -1,4 +1,8 @@
1
- /** Options for {@link integrate}. */
1
+ /**
2
+ * Options for {@link integrate}.
3
+ *
4
+ * @category Numerical methods
5
+ */
2
6
  export interface IntegrateOptions {
3
7
  /** Maximum number of subintervals. Default `100`. */
4
8
  subdivisions?: number;
@@ -9,8 +13,13 @@ export interface IntegrateOptions {
9
13
  /** Throw when QUADPACK reports a problem (default `true`); otherwise return the result with its code. */
10
14
  stopOnError?: boolean;
11
15
  }
12
- /** Result of {@link integrate}. */
16
+ /**
17
+ * Result of {@link integrate}.
18
+ *
19
+ * @category Numerical methods
20
+ */
13
21
  export interface IntegrateResult {
22
+ /** The estimate of the integral. */
14
23
  value: number;
15
24
  /** Estimate of the absolute error. */
16
25
  absError: number;
@@ -27,11 +36,17 @@ export interface IntegrateResult {
27
36
  *
28
37
  * @example
29
38
  * ```ts
30
- * integrate((x) => Math.exp(-x * x / 2), -Infinity, Infinity).value; // 2.5066282746310002 (sqrt(2 pi))
39
+ * integrate((x) => Math.exp(-x * x / 2), -Infinity, Infinity).value; // 2.506628274115034 (sqrt(2 pi) = 2.5066282746310002)
31
40
  * ```
41
+ *
42
+ * @category Numerical methods
32
43
  */
33
44
  export declare function integrate(f: (x: number) => number, lower: number, upper: number, options?: IntegrateOptions): IntegrateResult;
34
- /** Options for {@link optimize}. */
45
+ /**
46
+ * Options for {@link optimize}.
47
+ *
48
+ * @category Numerical methods
49
+ */
35
50
  export interface OptimizeOptions {
36
51
  /** Maximise instead of minimise. Default `false`. */
37
52
  maximum?: boolean;
@@ -40,19 +55,27 @@ export interface OptimizeOptions {
40
55
  }
41
56
  /**
42
57
  * Minimum (or maximum) of a function of one variable on an interval, by Brent's golden-section and parabolic
43
- * search. Equivalent to R's `optimize()`: `optimum` is the location (R's `minimum`/`maximum`) and `objective` the
58
+ * search. Equivalent to R's `optimize()`. `optimum` is the location (R's `minimum`/`maximum`) and `objective` the
44
59
  * function there. `lower` must be less than `upper`, as in R.
45
60
  *
46
61
  * @example
47
62
  * ```ts
48
63
  * optimize((x) => (x - 1 / 3) ** 2, 0, 1).optimum; // 0.3333333333333333
49
64
  * ```
65
+ *
66
+ * @category Numerical methods
50
67
  */
51
68
  export declare function optimize(f: (x: number) => number, lower: number, upper: number, options?: OptimizeOptions): {
69
+ /** Location of the minimum or maximum (R's `minimum` or `maximum`). */
52
70
  optimum: number;
71
+ /** Value of the function there. */
53
72
  objective: number;
54
73
  };
55
- /** Options for {@link uniroot}. */
74
+ /**
75
+ * Options for {@link uniroot}.
76
+ *
77
+ * @category Numerical methods
78
+ */
56
79
  export interface UnirootOptions {
57
80
  /** Accuracy. Default `eps^0.25`. */
58
81
  tol?: number;
@@ -68,8 +91,13 @@ export interface UnirootOptions {
68
91
  /** f(upper), when already known. */
69
92
  fUpper?: number;
70
93
  }
71
- /** Result of {@link uniroot}. */
94
+ /**
95
+ * Result of {@link uniroot}.
96
+ *
97
+ * @category Numerical methods
98
+ */
72
99
  export interface UnirootResult {
100
+ /** The root found. */
73
101
  root: number;
74
102
  /** f at the root. */
75
103
  fRoot: number;
@@ -87,5 +115,7 @@ export interface UnirootResult {
87
115
  * ```ts
88
116
  * uniroot((x) => x * x - 2, 0, 2, { tol: 1e-12 }).root; // 1.4142135623731364
89
117
  * ```
118
+ *
119
+ * @category Numerical methods
90
120
  */
91
121
  export declare function uniroot(f: (x: number) => number, lower: number, upper: number, options?: UnirootOptions): UnirootResult;
@@ -25,8 +25,10 @@ const TOL = Number.EPSILON ** 0.25;
25
25
  *
26
26
  * @example
27
27
  * ```ts
28
- * integrate((x) => Math.exp(-x * x / 2), -Infinity, Infinity).value; // 2.5066282746310002 (sqrt(2 pi))
28
+ * integrate((x) => Math.exp(-x * x / 2), -Infinity, Infinity).value; // 2.506628274115034 (sqrt(2 pi) = 2.5066282746310002)
29
29
  * ```
30
+ *
31
+ * @category Numerical methods
30
32
  */
31
33
  export function integrate(f, lower, upper, options = {}) {
32
34
  const limit = options.subdivisions ?? 100;
@@ -59,13 +61,15 @@ export function integrate(f, lower, upper, options = {}) {
59
61
  }
60
62
  /**
61
63
  * Minimum (or maximum) of a function of one variable on an interval, by Brent's golden-section and parabolic
62
- * search. Equivalent to R's `optimize()`: `optimum` is the location (R's `minimum`/`maximum`) and `objective` the
64
+ * search. Equivalent to R's `optimize()`. `optimum` is the location (R's `minimum`/`maximum`) and `objective` the
63
65
  * function there. `lower` must be less than `upper`, as in R.
64
66
  *
65
67
  * @example
66
68
  * ```ts
67
69
  * optimize((x) => (x - 1 / 3) ** 2, 0, 1).optimum; // 0.3333333333333333
68
70
  * ```
71
+ *
72
+ * @category Numerical methods
69
73
  */
70
74
  export function optimize(f, lower, upper, options = {}) {
71
75
  const maximum = options.maximum ?? false;
@@ -82,6 +86,8 @@ export function optimize(f, lower, upper, options = {}) {
82
86
  * ```ts
83
87
  * uniroot((x) => x * x - 2, 0, 2, { tol: 1e-12 }).root; // 1.4142135623731364
84
88
  * ```
89
+ *
90
+ * @category Numerical methods
85
91
  */
86
92
  export function uniroot(f, lower, upper, options = {}) {
87
93
  const tol = options.tol ?? TOL;
@@ -1,6 +1,16 @@
1
1
  import type { Sample } from "../htest/types.js";
2
- type Ties = "mean" | "min" | "max" | ((v: number[]) => number);
3
- /** Options for {@link approx}. */
2
+ /**
3
+ * How equal `x` values are merged before interpolating (R's `ties`): `"mean"`, `"min"` or `"max"` of their `y`, or a
4
+ * function of their `y` values.
5
+ *
6
+ * @category Numerical methods
7
+ */
8
+ export type Ties = "mean" | "min" | "max" | ((v: number[]) => number);
9
+ /**
10
+ * Options for {@link approx}.
11
+ *
12
+ * @category Numerical methods
13
+ */
4
14
  export interface ApproxOptions {
5
15
  /** Points to interpolate at. Default: `n` equally spaced points over the range of `x`. */
6
16
  xout?: Sample;
@@ -26,20 +36,34 @@ export interface ApproxOptions {
26
36
  * ```ts
27
37
  * approx([1, 2, 3], [10, 20, 40], { xout: [1.5, 2.5] }).y; // [15, 30]
28
38
  * ```
39
+ *
40
+ * @category Numerical methods
29
41
  */
30
42
  export declare function approx(x: Sample, y: Sample, options?: ApproxOptions): {
43
+ /** The points interpolated at (`xout`, or the equally spaced points). */
31
44
  x: number[];
45
+ /** The interpolated values, one per point of `x`. */
32
46
  y: number[];
33
47
  };
34
- /** Cubic spline method. */
48
+ /**
49
+ * Cubic spline method.
50
+ *
51
+ * @category Numerical methods
52
+ */
35
53
  export type SplineMethod = "fmm" | "natural" | "periodic" | "hyman";
36
- /** Options for {@link spline}. */
54
+ /**
55
+ * Options for {@link spline}.
56
+ *
57
+ * @category Numerical methods
58
+ */
37
59
  export interface SplineOptions {
38
60
  /** Number of equally spaced points from `xmin` to `xmax`. Default `3 * x.length`. */
39
61
  n?: number;
40
62
  /** `"fmm"` (default), `"natural"`, `"periodic"` or `"hyman"`. */
41
63
  method?: SplineMethod;
64
+ /** Left end of the equally spaced points. Default: the smallest `x`. */
42
65
  xmin?: number;
66
+ /** Right end of the equally spaced points. Default: the largest `x`. */
43
67
  xmax?: number;
44
68
  /** Points to interpolate at (then `n`, `xmin` and `xmax` are not used). */
45
69
  xout?: Sample;
@@ -53,12 +77,20 @@ export interface SplineOptions {
53
77
  * ```ts
54
78
  * spline([1, 2, 3, 4], [1, 4, 9, 16], { xout: [2.5] }).y; // [6.25]
55
79
  * ```
80
+ *
81
+ * @category Numerical methods
56
82
  */
57
83
  export declare function spline(x: Sample, y: Sample, options?: SplineOptions): {
84
+ /** The points interpolated at (`xout`, or the equally spaced points). */
58
85
  x: number[];
86
+ /** The interpolated values, one per point of `x`. */
59
87
  y: number[];
60
88
  };
61
- /** Options for {@link splinefun}. */
89
+ /**
90
+ * Options for {@link splinefun}.
91
+ *
92
+ * @category Numerical methods
93
+ */
62
94
  export interface SplinefunOptions {
63
95
  /** `"fmm"` (default), `"natural"`, `"periodic"`, `"monoH.FC"` or `"hyman"`. */
64
96
  method?: SplineMethod | "monoH.FC";
@@ -67,7 +99,7 @@ export interface SplinefunOptions {
67
99
  }
68
100
  /**
69
101
  * The cubic spline through the points, as a function of `x` and the order of derivative (0 to 3; a fraction is
70
- * truncated, as R does). Equivalent to R's `splinefun()`, except that the third derivative of `"monoH.FC"` is the
102
+ * truncated, as R does). Equivalent to R's `splinefun()`. Except that the third derivative of `"monoH.FC"` is the
71
103
  * exact one (see {@link splinefunH}).
72
104
  *
73
105
  * @example
@@ -76,28 +108,47 @@ export interface SplinefunOptions {
76
108
  * s([2.5]); // [6.25]
77
109
  * s([2.5], 1); // [5]
78
110
  * ```
111
+ *
112
+ * @category Numerical methods
79
113
  */
80
114
  export declare function splinefun(x: Sample, y: Sample, options?: SplinefunOptions): (xq: Sample, deriv?: number) => number[];
81
115
  /**
82
116
  * The cubic Hermite spline with values `y` and slopes `m` at the points `x`, as a function of `x` and the order of
83
- * derivative (0 to 3; a fraction is truncated, as R does); linear outside the data. Equivalent to R's `splinefunH()`,
84
- * except for the third derivative: on [x_i, x_{i+1}] it is the exact (6 m_i + 6 m_{i+1} - 12 delta) / h^2, with
117
+ * derivative (0 to 3; a fraction is truncated, as R does); linear outside the data. Equivalent to R's `splinefunH()`.
118
+ * Except for the third derivative: on [x_i, x_{i+1}] it is the exact (6 m_i + 6 m_{i+1} - 12 delta) / h^2, with
85
119
  * h = x_{i+1} - x_i and delta = (y_{i+1} - y_i) / h, where R divides by h only once (the two agree when h = 1).
86
120
  *
87
121
  * @example
88
122
  * ```ts
89
123
  * splinefunH([0, 2], [0, 0], [1, 1])([1], 3); // [3] (R: 6)
90
124
  * ```
125
+ *
126
+ * @category Numerical methods
91
127
  */
92
128
  export declare function splinefunH(x: Sample, y: Sample, m: Sample): (xq: Sample, deriv?: number) => number[];
93
129
  /**
94
- * Lagrange interpolation in barycentric form through the points (xi, yi). Equivalent to `pracma::barylag()`; the
95
- * points must lie within the range of the nodes.
130
+ * Lagrange interpolation in barycentric form through the points (xi, yi). Equivalent to `pracma::barylag()` in R.
131
+ * The points must lie within the range of the nodes.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * barylag([0, 1, 2], [1, 3, 7], [0.5, 1.5]); // [1.75, 4.75]
136
+ * ```
137
+ *
138
+ * @category Numerical methods
96
139
  */
97
140
  export declare function barylag(xi: Sample, yi: Sample, x: Sample): number[];
98
141
  /**
99
142
  * The polynomial of degree 2n - 1 through n points with given values and derivatives (global Hermite
100
- * interpolation, jStat's hermite), evaluated at `x`. Computed by divided differences on the doubled nodes.
143
+ * interpolation, jStat's hermite), evaluated at `x`. Not an R function. Neither base R nor the recommended packages
144
+ * have it (for piecewise cubic Hermite interpolation, see {@link splinefunH}). Computed by divided differences on
145
+ * the doubled nodes.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * hermiteInterp([0, 1], [0, 1], [0, 0], [0.25, 0.5]); // [0.15625, 0.5]
150
+ * ```
151
+ *
152
+ * @category Numerical methods
101
153
  */
102
154
  export declare function hermiteInterp(xi: Sample, yi: Sample, di: Sample, x: Sample): number[];
103
- export {};