@numero-uno-jpn/rstats 0.16.0 → 1.0.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 (243) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/README.ja.md +57 -23
  3. package/README.md +60 -23
  4. package/dist/chunks/{chunk-5UQCRBAG.js → chunk-3W5NFFAA.js} +1 -1
  5. package/dist/chunks/chunk-4F2IALD4.js +3 -0
  6. package/dist/chunks/{chunk-QNNL7AZ3.js → chunk-4OLDGML4.js} +2 -2
  7. package/dist/chunks/chunk-63OPBEYO.js +2 -0
  8. package/dist/chunks/chunk-6XJBCRBV.js +2 -0
  9. package/dist/chunks/chunk-BQSIBJVX.js +2 -0
  10. package/dist/chunks/chunk-BWKHYRM6.js +3 -0
  11. package/dist/chunks/{chunk-W26LRYOJ.js → chunk-CKV4JWW2.js} +1 -1
  12. package/dist/chunks/chunk-DCAWMF4K.js +2 -0
  13. package/dist/chunks/chunk-F7YGX7PN.js +2 -0
  14. package/dist/chunks/chunk-H7I32ZZE.js +2 -0
  15. package/dist/chunks/chunk-IEOD5GWC.js +3 -0
  16. package/dist/chunks/chunk-KICBQGFN.js +2 -0
  17. package/dist/chunks/chunk-LROMWFAK.js +2 -0
  18. package/dist/chunks/chunk-NSWENS3S.js +2 -0
  19. package/dist/chunks/chunk-O2SQMGE3.js +2 -0
  20. package/dist/chunks/chunk-QQX46TCI.js +2 -0
  21. package/dist/chunks/chunk-QZK3CCBA.js +2 -0
  22. package/dist/chunks/chunk-UJ66VQIG.js +2 -0
  23. package/dist/chunks/chunk-UKNDX4BA.js +2 -0
  24. package/dist/chunks/chunk-WIBKS73G.js +2 -0
  25. package/dist/chunks/{chunk-URIO5LY5.js → chunk-WQWZ7FND.js} +2 -2
  26. package/dist/chunks/chunk-WWVMVZUL.js +2 -0
  27. package/dist/chunks/chunk-YG5S5AVP.js +2 -0
  28. package/dist/chunks/chunk-YHNMBYSW.js +2 -0
  29. package/dist/data/grouping.js +6 -2
  30. package/dist/descriptive/basic.js +20 -0
  31. package/dist/descriptive/cov.js +11 -0
  32. package/dist/descriptive/dataFrames.js +13 -5
  33. package/dist/descriptive/factanal.d.ts +2 -0
  34. package/dist/descriptive/factanal.js +10 -2
  35. package/dist/descriptive/hist.js +6 -0
  36. package/dist/descriptive/moments.js +14 -0
  37. package/dist/descriptive/omega.js +8 -3
  38. package/dist/descriptive/pivot.d.ts +4 -1
  39. package/dist/descriptive/pivot.js +27 -13
  40. package/dist/descriptive/quantile.js +8 -0
  41. package/dist/descriptive/rank.js +4 -0
  42. package/dist/descriptive/table.d.ts +20 -1
  43. package/dist/descriptive/table.js +14 -14
  44. package/dist/descriptive.js +2 -2
  45. package/dist/distributions/arcsine.js +8 -0
  46. package/dist/distributions/beta.js +9 -0
  47. package/dist/distributions/binomial.js +9 -0
  48. package/dist/distributions/cauchy.js +9 -0
  49. package/dist/distributions/chisq.js +9 -0
  50. package/dist/distributions/exponential.js +9 -0
  51. package/dist/distributions/f.js +9 -0
  52. package/dist/distributions/gamma.js +8 -0
  53. package/dist/distributions/geometric.js +9 -0
  54. package/dist/distributions/hypergeometric.js +8 -0
  55. package/dist/distributions/invgamma.js +8 -0
  56. package/dist/distributions/kumaraswamy.js +9 -0
  57. package/dist/distributions/laplace.js +9 -0
  58. package/dist/distributions/logistic.js +9 -0
  59. package/dist/distributions/lognormal.js +8 -0
  60. package/dist/distributions/multinomial.js +4 -0
  61. package/dist/distributions/negbinomial.js +8 -0
  62. package/dist/distributions/normal.js +8 -0
  63. package/dist/distributions/pareto.js +8 -0
  64. package/dist/distributions/poisson.js +9 -0
  65. package/dist/distributions/signrank.js +9 -0
  66. package/dist/distributions/summary.d.ts +2 -1
  67. package/dist/distributions/summary.js +31 -1
  68. package/dist/distributions/t.js +9 -0
  69. package/dist/distributions/triangular.js +9 -0
  70. package/dist/distributions/tukey.js +6 -0
  71. package/dist/distributions/uniform.js +8 -0
  72. package/dist/distributions/weibull.js +8 -0
  73. package/dist/distributions/wilcox.js +9 -0
  74. package/dist/distributions.js +2 -2
  75. package/dist/entries/descriptive.d.ts +3 -1
  76. package/dist/entries/descriptive.js +1 -1
  77. package/dist/entries/distributions.d.ts +1 -0
  78. package/dist/entries/distributions.js +2 -0
  79. package/dist/entries/linalg.d.ts +3 -1
  80. package/dist/entries/mixed.d.ts +9 -0
  81. package/dist/entries/mixed.js +8 -1
  82. package/dist/entries/numerics.d.ts +2 -1
  83. package/dist/entries/tests.d.ts +8 -5
  84. package/dist/entries/tests.js +3 -1
  85. package/dist/htest/agreement.d.ts +13 -0
  86. package/dist/htest/agreement.js +46 -7
  87. package/dist/htest/ansariTest.d.ts +2 -1
  88. package/dist/htest/ansariTest.js +43 -12
  89. package/dist/htest/aov.d.ts +28 -22
  90. package/dist/htest/aov.js +42 -13
  91. package/dist/htest/binomTest.js +6 -0
  92. package/dist/htest/brunnerMunzelTest.js +5 -0
  93. package/dist/htest/chisqTest.d.ts +3 -1
  94. package/dist/htest/chisqTest.js +21 -3
  95. package/dist/htest/cor.d.ts +7 -1
  96. package/dist/htest/cor.js +40 -7
  97. package/dist/htest/core/simulate.d.ts +6 -0
  98. package/dist/htest/core/simulate.js +20 -0
  99. package/dist/htest/effectSize.d.ts +3 -0
  100. package/dist/htest/effectSize.js +28 -8
  101. package/dist/htest/fisherTest.d.ts +2 -1
  102. package/dist/htest/fisherTest.js +52 -6
  103. package/dist/htest/ksTest.d.ts +4 -0
  104. package/dist/htest/ksTest.js +13 -4
  105. package/dist/htest/leveneTest.d.ts +2 -0
  106. package/dist/htest/leveneTest.js +9 -3
  107. package/dist/htest/mantelhaenTest.js +7 -0
  108. package/dist/htest/mcnemarTest.js +8 -0
  109. package/dist/htest/multipleComparisons.d.ts +16 -25
  110. package/dist/htest/multipleComparisons.js +26 -43
  111. package/dist/htest/normalityTests.js +10 -4
  112. package/dist/htest/onewayTest.js +10 -0
  113. package/dist/htest/pAdjust.js +4 -0
  114. package/dist/htest/pairwise.d.ts +2 -0
  115. package/dist/htest/pairwise.js +29 -6
  116. package/dist/htest/poissonTest.js +6 -0
  117. package/dist/htest/polycor.js +20 -10
  118. package/dist/htest/power.d.ts +4 -0
  119. package/dist/htest/power.js +16 -2
  120. package/dist/htest/propTest.d.ts +3 -0
  121. package/dist/htest/propTest.js +23 -2
  122. package/dist/htest/pwr.d.ts +38 -1
  123. package/dist/htest/pwr.js +38 -15
  124. package/dist/htest/rankTests.js +7 -1
  125. package/dist/htest/tTest.d.ts +2 -0
  126. package/dist/htest/tTest.js +9 -0
  127. package/dist/htest/testFormula.js +11 -11
  128. package/dist/htest/trendTests.d.ts +21 -1
  129. package/dist/htest/trendTests.js +13 -18
  130. package/dist/htest/types.d.ts +2 -0
  131. package/dist/htest/varTest.js +7 -0
  132. package/dist/htest/wilcoxTest.js +51 -9
  133. package/dist/internal/checkOptions.d.ts +11 -0
  134. package/dist/internal/checkOptions.js +31 -0
  135. package/dist/internal/optionalArgs.d.ts +12 -0
  136. package/dist/internal/optionalArgs.js +46 -0
  137. package/dist/internal/warnings.d.ts +66 -0
  138. package/dist/internal/warnings.js +122 -0
  139. package/dist/linalg/basic.js +7 -0
  140. package/dist/linalg/chol.js +6 -0
  141. package/dist/linalg/eigen.js +4 -0
  142. package/dist/linalg/expm.js +4 -0
  143. package/dist/linalg/kappa.js +6 -0
  144. package/dist/linalg/lu.js +5 -0
  145. package/dist/linalg/norm.js +4 -0
  146. package/dist/linalg/ops.d.ts +27 -2
  147. package/dist/linalg/ops.js +14 -13
  148. package/dist/linalg/qr.js +14 -0
  149. package/dist/linalg/solve.js +9 -0
  150. package/dist/linalg/svd.js +6 -2
  151. package/dist/linalg.js +2 -2
  152. package/dist/mixed.js +5 -4
  153. package/dist/models/anovaSequential.d.ts +16 -1
  154. package/dist/models/anovaSequential.js +50 -7
  155. package/dist/models/aovEz.js +16 -11
  156. package/dist/models/aovStrata.js +15 -4
  157. package/dist/models/carAnova.js +11 -17
  158. package/dist/models/coxph.d.ts +6 -0
  159. package/dist/models/coxph.js +21 -6
  160. package/dist/models/formula.d.ts +5 -2
  161. package/dist/models/formula.js +31 -8
  162. package/dist/models/glm.d.ts +22 -2
  163. package/dist/models/glm.js +32 -22
  164. package/dist/models/glmAnova.js +8 -3
  165. package/dist/models/glmConfint.js +6 -2
  166. package/dist/models/glmFamily.d.ts +1 -6
  167. package/dist/models/glmFamily.js +3 -22
  168. package/dist/models/glmer.d.ts +255 -0
  169. package/dist/models/glmer.js +635 -0
  170. package/dist/models/glmerAnova.d.ts +81 -0
  171. package/dist/models/glmerAnova.js +139 -0
  172. package/dist/models/glmerDeviance.d.ts +98 -0
  173. package/dist/models/glmerDeviance.js +576 -0
  174. package/dist/models/glmerFamily.d.ts +57 -0
  175. package/dist/models/glmerFamily.js +236 -0
  176. package/dist/models/glmerGradient.d.ts +46 -0
  177. package/dist/models/glmerGradient.js +301 -0
  178. package/dist/models/glmerStructure.d.ts +45 -0
  179. package/dist/models/glmerStructure.js +168 -0
  180. package/dist/models/glmerSummary.d.ts +102 -0
  181. package/dist/models/glmerSummary.js +94 -0
  182. package/dist/models/lm.js +13 -3
  183. package/dist/models/lmer.d.ts +27 -6
  184. package/dist/models/lmer.js +75 -321
  185. package/dist/models/lmerAnova.d.ts +52 -3
  186. package/dist/models/lmerAnova.js +101 -45
  187. package/dist/models/lmerTest.d.ts +12 -5
  188. package/dist/models/lmerTest.js +39 -18
  189. package/dist/models/mauchly.d.ts +2 -0
  190. package/dist/models/mauchly.js +7 -2
  191. package/dist/models/mixedDeviance.d.ts +28 -2
  192. package/dist/models/mixedDeviance.js +84 -56
  193. package/dist/models/mixedMinimiser.d.ts +83 -0
  194. package/dist/models/mixedMinimiser.js +438 -0
  195. package/dist/models/mixedPredict.d.ts +121 -0
  196. package/dist/models/mixedPredict.js +530 -0
  197. package/dist/models/mixedStructure.d.ts +62 -3
  198. package/dist/models/mixedStructure.js +74 -29
  199. package/dist/models/modelFrame.js +2 -2
  200. package/dist/models/modelMatrix.d.ts +8 -1
  201. package/dist/models/modelMatrix.js +56 -39
  202. package/dist/models/survival.d.ts +6 -0
  203. package/dist/models/survival.js +9 -2
  204. package/dist/numerics/deriv.js +8 -0
  205. package/dist/numerics/integrate.js +8 -0
  206. package/dist/numerics/interp.d.ts +32 -7
  207. package/dist/numerics/interp.js +27 -9
  208. package/dist/numerics/ode.js +4 -0
  209. package/dist/numerics.js +2 -2
  210. package/dist/optim/optim.js +17 -2
  211. package/dist/random/beta.js +5 -0
  212. package/dist/random/continuous.js +17 -0
  213. package/dist/random/extra.js +13 -0
  214. package/dist/random/gamma.js +11 -0
  215. package/dist/random/poisson.js +5 -0
  216. package/dist/random/rng.js +4 -0
  217. package/dist/random/sample.js +6 -0
  218. package/dist/rstats.js +17 -14
  219. package/dist/special/besselIK.js +7 -0
  220. package/dist/special/choose.js +7 -0
  221. package/dist/special/psigamma.js +7 -0
  222. package/dist/special.js +2 -2
  223. package/dist/tests.js +14 -11
  224. package/llms.txt +15 -4
  225. package/package.json +19 -10
  226. package/dist/chunks/chunk-2D2IQWUQ.js +0 -2
  227. package/dist/chunks/chunk-6CSTWA5E.js +0 -2
  228. package/dist/chunks/chunk-72Y3HZID.js +0 -2
  229. package/dist/chunks/chunk-BG2KLEHM.js +0 -2
  230. package/dist/chunks/chunk-CMEKBNHQ.js +0 -2
  231. package/dist/chunks/chunk-FLJNSXSW.js +0 -2
  232. package/dist/chunks/chunk-GM53LWSR.js +0 -2
  233. package/dist/chunks/chunk-JBCA56ZS.js +0 -3
  234. package/dist/chunks/chunk-K3RJAD2T.js +0 -2
  235. package/dist/chunks/chunk-KAZRWIB5.js +0 -2
  236. package/dist/chunks/chunk-KBVVIMXX.js +0 -3
  237. package/dist/chunks/chunk-N3SIFCZX.js +0 -2
  238. package/dist/chunks/chunk-SC6CV4Z3.js +0 -2
  239. package/dist/chunks/chunk-SYWOBOTR.js +0 -2
  240. package/dist/chunks/chunk-VTUGG2SV.js +0 -2
  241. package/dist/chunks/chunk-XHETEYVC.js +0 -2
  242. package/dist/chunks/chunk-YRZWONZB.js +0 -3
  243. package/dist/chunks/chunk-ZGABZMWX.js +0 -2
@@ -15,7 +15,10 @@ import { ldexp } from "../internal/summary.js";
15
15
  import { uniroot } from "../internal/uniroot.js";
16
16
  import { qr, qrResid } from "../linalg/qr.js";
17
17
  import { glmSummary, refit, scaledView } from "./glm.js";
18
- import { Warnings } from "./glmFamily.js";
18
+ import { unreported, Warnings } from "../internal/warnings.js";
19
+ // Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
20
+ import { checkOptions } from "../internal/checkOptions.js";
21
+ const GLM_CONFINT_KEYS = ["parm", "level", "test"];
19
22
  /**
20
23
  * Settings of the fits iterated to convergence: until the coefficients stop changing (at most 100 iterations), and
21
24
  * the tolerance of the QR decomposition that of epsilon = 1e-300 (columns found aliased by the fit are left out)
@@ -102,6 +105,7 @@ export function scoreStatistic(x, r, v, intercept, tol = 1e-11) {
102
105
  * @category Generalized linear models
103
106
  */
104
107
  export function glmConfint(given, options = {}) {
108
+ checkOptions(options, GLM_CONFINT_KEYS, "glmConfint"); // generated: option-keys.mjs
105
109
  // on the scaled fit (scaledView); the limits scaled back
106
110
  const { fit, k } = scaledView(given);
107
111
  const level = options.level ?? 0.95;
@@ -139,7 +143,7 @@ export function glmConfint(given, options = {}) {
139
143
  qr: full.fit.qr,
140
144
  rank: full.fit.rank,
141
145
  };
142
- const summary = glmSummary(convergedFit);
146
+ const summary = unreported(() => glmSummary(convergedFit));
143
147
  const dispersion = summary.dispersion;
144
148
  const se = new Array(p).fill(NaN);
145
149
  const piv = full.fit.qr === undefined ? [] : full.fit.qr.pivot.slice(0, full.fit.rank);
@@ -1,3 +1,4 @@
1
+ import { type Warnings } from "../internal/warnings.js";
1
2
  /**
2
3
  * Names of the families of R's stats.
3
4
  *
@@ -72,12 +73,6 @@ export interface Family extends LinkFunctions {
72
73
  /** The variance function is mu^varPower (gaussian 0, poisson 1, Gamma 2, inverse.gaussian 3 and their quasi) */
73
74
  varPower?: number;
74
75
  }
75
- /** Collects warnings in order of first appearance, each once (as the fixtures list R's warnings) */
76
- export declare class Warnings {
77
- readonly list: string[];
78
- add(message: string): void;
79
- }
80
- export declare function withWarnings<T>(sink: Warnings, f: () => T): T;
81
76
  /** Resolves a family name or specification (and a link given separately) to its functions */
82
77
  export declare function makeFamily(family: GlmFamilyName | GlmFamilySpec, link?: GlmLink): Family;
83
78
  /** The response after the family has read it, with the prior weights, the starting means and the binomial sizes */
@@ -11,6 +11,7 @@ import { dnorm, pnorm, qnorm } from "../distributions/normal.js";
11
11
  import { dpois1, nonInteger } from "../distributions/poisson.js";
12
12
  import { roundHalfEven } from "../internal/integer.js";
13
13
  import { ldexp } from "../internal/summary.js";
14
+ import { warn } from "../internal/warnings.js";
14
15
  import { bd0 } from "../special/loader.js";
15
16
  import { log1pmx } from "../special/log1p.js";
16
17
  const ALLOWED = {
@@ -25,30 +26,10 @@ const ALLOWED = {
25
26
  };
26
27
  const positive = (eta) => Number.isFinite(eta) && eta > 0;
27
28
  const anyEta = () => true;
28
- /** Collects warnings in order of first appearance, each once (as the fixtures list R's warnings) */
29
- export class Warnings {
30
- list = [];
31
- add(message) {
32
- if (!this.list.includes(message))
33
- this.list.push(message);
34
- }
35
- }
36
- /** The warnings sink of the link functions that warn ("NaNs produced"); set while a fit runs */
37
- let currentWarnings;
38
- export function withWarnings(sink, f) {
39
- const saved = currentWarnings;
40
- currentWarnings = sink;
41
- try {
42
- return f();
43
- }
44
- finally {
45
- currentWarnings = saved;
46
- }
47
- }
48
29
  /** Square root that warns as R's sqrt does when it produces NaN */
49
30
  function sqrtWarn(x) {
50
31
  if (x < 0)
51
- currentWarnings?.add("NaNs produced");
32
+ warn("NaNs produced");
52
33
  return Math.sqrt(x);
53
34
  }
54
35
  /**
@@ -57,7 +38,7 @@ function sqrtWarn(x) {
57
38
  */
58
39
  function logWarn(x) {
59
40
  if (x < 0)
60
- currentWarnings?.add("NaNs produced");
41
+ warn("NaNs produced");
61
42
  return Math.log(x);
62
43
  }
63
44
  /** A number as C's printf("%g") writes it: 6 significant digits, fixed or scientific, trailing zeros dropped */
@@ -0,0 +1,255 @@
1
+ import { type GlmLinkName } from "./glmFamily.js";
2
+ import { type GlmerFamilyName } from "./glmerFamily.js";
3
+ import { type GlmerStructure } from "./glmerStructure.js";
4
+ import { type LmerContrastName, type LmerRanef, type LmerVarCorr } from "./lmer.js";
5
+ import type { DataFrame } from "./modelFrame.js";
6
+ /**
7
+ * Options of {@link glmer}. Only the keys below are accepted: R's `subset`, `naAction`, `na.action`, `control`,
8
+ * `verbose`, `devFunOnly`, `mustart` and `etastart` give the Error `glmer: argument '<key>' is not supported`, any
9
+ * other key a RangeError (a key whose value is `undefined` included).
10
+ *
11
+ * @category Mixed models
12
+ */
13
+ export interface GlmerOptions {
14
+ /**
15
+ * The family: `"binomial"`, `"poisson"`, `"Gamma"`, `"inverse.gaussian"` or `"gaussian"` (default, as R's; with the
16
+ * identity link it is a linear mixed model, a RangeError telling to use {@link lmer}). The quasi families are the
17
+ * error `"quasi" families cannot be used in glmer`.
18
+ */
19
+ family?: GlmerFamilyName;
20
+ /**
21
+ * The link: any of `"logit"`, `"probit"`, `"cauchit"`, `"cloglog"`, `"identity"`, `"log"`, `"sqrt"`, `"1/mu^2"`,
22
+ * `"inverse"` (default: the family's, as in R: binomial logit, poisson log, Gamma inverse, inverse.gaussian
23
+ * 1/mu^2, gaussian identity).
24
+ */
25
+ link?: GlmLinkName;
26
+ /**
27
+ * Prior weights (non-negative): one per row of `data` (`null` or NaN is missing and drops the row), or the name of
28
+ * a numeric column. For the binomial family with proportions as the response, the numbers of trials.
29
+ */
30
+ weights?: readonly (number | null)[] | Float64Array | string;
31
+ /** Offset added to the linear predictor: one per row of `data` (`null` or NaN drops the row), or a column name. */
32
+ offset?: readonly (number | null)[] | Float64Array | string;
33
+ /**
34
+ * 1 (default): the Laplace approximation, the deviance minimised over θ and β; 0: over θ only, with β from the
35
+ * penalised IRLS (faster, less exact); 2 to 100: adaptive Gauss-Hermite quadrature with that many points, more
36
+ * exact than the Laplace approximation. A non-integer is truncated as in R (−0.5 is 0); negative values after that
37
+ * are a RangeError (R uses 0), above 100 R's error. Above 1 the model must have a single random-effects term with one column, such as
38
+ * `(1 | g)` (otherwise R's errors `nAGQ > 1 is only available for models with a single, scalar random-effects
39
+ * term` or `AGQ only defined for a single scalar random-effects term`), and the family must be binomial or
40
+ * poisson: for Gamma, inverse.gaussian and gaussian it is a RangeError, since lme4 holds the dispersion at 1 there
41
+ * and its estimates are not maximum likelihood (R fits them).
42
+ */
43
+ nAGQ?: number;
44
+ /**
45
+ * Where the search begins (it does not change the estimate unless the deviance has several minima): `theta`, the
46
+ * covariance parameters (the length of θ, diagonal elements not negative), and `fixef`, the fixed effects (nAGQ = 1
47
+ * only), each with R's error messages.
48
+ */
49
+ start?: {
50
+ /** Starting values of θ (R's `start = list(theta = ...)`). */
51
+ theta?: readonly number[];
52
+ /** Starting values of the fixed effects (R's `start = list(fixef = ...)`; not with nAGQ = 0, as in R). */
53
+ fixef?: readonly number[];
54
+ };
55
+ /**
56
+ * A contrast per factor of the fixed-effects part, as in {@link lmer} (see {@link LmerContrastName}); the
57
+ * random-effects terms always use treatment contrasts.
58
+ */
59
+ contrasts?: Record<string, LmerContrastName>;
60
+ /**
61
+ * The order of the levels of a factor (`{ A: ["c", "a", "b"] }`), as `factor(x, levels = ...)` in R. For a binomial
62
+ * response given as strings, the first level is failure and the others success.
63
+ */
64
+ levels?: Record<string, readonly string[]>;
65
+ }
66
+ /**
67
+ * Result of {@link glmer}: the fit of a generalized linear mixed model and the quantities of R's methods for it.
68
+ *
69
+ * @category Mixed models
70
+ */
71
+ export interface GlmerResult {
72
+ /** The formula. */
73
+ formula: string;
74
+ /** The family. */
75
+ family: GlmerFamilyName;
76
+ /** The link. */
77
+ link: GlmLinkName;
78
+ /** 1 (the Laplace approximation), 0 (β from the penalised IRLS) or the number of quadrature points (2 to 100). */
79
+ nAGQ: number;
80
+ /** Number of rows used (rows with prior weight 0 included; R's `nobs()`). */
81
+ nObs: number;
82
+ /** 0-based indices of the rows of `data` used (rows with a missing value in a variable, a weight or the offset dropped). */
83
+ rows: number[];
84
+ /** The estimate of the covariance parameters θ (R's `getME(fit, "theta")`): the lower triangles of the relative covariance factors, by term, column-major. */
85
+ theta: number[];
86
+ /** Names of the columns of the fixed-effects model matrix (aliased columns dropped). */
87
+ fixefNames: string[];
88
+ /** The fixed effects β̂ (R's `fixef()`). */
89
+ fixef: number[];
90
+ /** The coefficient table of the fixed effects (R's `coef(summary(fit))`, without the p-values). */
91
+ coefTable: {
92
+ /** Estimates (R's `Estimate`). */
93
+ estimate: number[];
94
+ /** Standard errors (R's `Std. Error`). */
95
+ stdError: number[];
96
+ /** Estimates over standard errors (R's `z value`; R labels it `t value` for Gamma, inverse.gaussian and gaussian). */
97
+ zValue: number[];
98
+ };
99
+ /** The covariance matrix of the fixed effects (R's `vcov()`), array of rows. */
100
+ vcov: number[][];
101
+ /**
102
+ * How `vcov` was computed: `"hessian"`, 2 times the block of the fixed effects of the inverse Hessian of the
103
+ * deviance in (θ, β) (R's default for nAGQ = 1 when the fit is not singular, nObs < 10000 and there are fewer than
104
+ * 20 parameters), or `"RX"`, σ² (R_X'R_X)⁻¹ of the penalised IRLS at the conditional mode.
105
+ */
106
+ vcovFrom: "hessian" | "RX";
107
+ /**
108
+ * R's `sigma()`: 1 for binomial and poisson; otherwise the square root of the sum of the squared Pearson residuals
109
+ * plus the squared length of the spherical random effects, over nObs.
110
+ */
111
+ sigma: number;
112
+ /** The variance components, one entry per random-effects term (R's `VarCorr()`; not scaled by sigma). */
113
+ varCorr: LmerVarCorr[];
114
+ /** The conditional modes of the random effects, one entry per grouping factor (R's `ranef()`). */
115
+ ranef: LmerRanef[];
116
+ /** The fitted means μ̂, one per row used (R's `fitted()`; for a binomial response the probabilities). */
117
+ fitted: number[];
118
+ /** The linear predictor η̂ = offset + Xβ̂ + Zb̂, one per row used (R's `predict()`). */
119
+ linearPredictor: number[];
120
+ /** The deviance residuals (R's `residuals()`, whose default type for glmer is `"deviance"`). */
121
+ residuals: number[];
122
+ /** The Pearson residuals √w (y − μ̂) / √V(μ̂) (R's `residuals(fit, "pearson")`). */
123
+ pearsonResiduals: number[];
124
+ /** The working residuals (y − μ̂) / μ'(η̂) (R's `residuals(fit, "working")`). */
125
+ workingResiduals: number[];
126
+ /** The response residuals y − μ̂ (R's `residuals(fit, "response")`; y the proportion for `cbind(s, f)`). */
127
+ responseResiduals: number[];
128
+ /** The sum of the squared deviance residuals (R's `deviance()`; not −2 logLik). */
129
+ deviance: number;
130
+ /**
131
+ * The log-likelihood: of the Laplace approximation, −1/2 times the deviance minimised (R's `logLik()`), or with
132
+ * nAGQ > 1 of the quadrature, including the constant of the saturated model that R's `logLik()` leaves out there
133
+ * (so that it is comparable with nAGQ = 1 and with glm).
134
+ */
135
+ logLik: number;
136
+ /** Degrees of freedom of the log-likelihood: the numbers of fixed effects and of θ, plus 1 for the families with a dispersion. */
137
+ df: number;
138
+ /** Akaike's information criterion (R's `AIC()`). */
139
+ AIC: number;
140
+ /** Schwarz's Bayesian information criterion (R's `BIC()`). */
141
+ BIC: number;
142
+ /** Whether the fit is singular: a diagonal element of a relative covariance factor below 1e-4 (R's `isSingular()`). */
143
+ singular: boolean;
144
+ /** R's messages (a rank-deficient fixed-effects matrix, a singular fit). */
145
+ messages: string[];
146
+ /** R's warnings (predictors on very different scales, the response, the fallback of vcov). */
147
+ warnings: string[];
148
+ }
149
+ export declare const VCOV_FALLBACK = "variance-covariance matrix computed from finite-difference Hessian is\nnot positive definite or contains NA values: falling back to var-cov estimated from RX";
150
+ /**
151
+ * What a fit by {@link glmer} was made from and with (internal: not exported from the package), for the functions that
152
+ * work on a fit beyond its result fields (glmerSummary, glmerAnova, prediction): the model's structure, the data object
153
+ * (model comparison requires the same object) and its snapshot (prediction rebuilds the model from it), the options as
154
+ * given (the weights and the offset as an array or a column name), and the estimate with R_X'R_X, the random effects,
155
+ * the linear predictor and the means at it.
156
+ */
157
+ export interface GlmerInternals {
158
+ /** The structure of the model (X, Z, the terms, the family, the response, prior weights and offset of the rows used) */
159
+ structure: GlmerStructure;
160
+ /** The data frame given to glmer (the same object, not a copy: fits are compared on the same data object) */
161
+ data: DataFrame;
162
+ /** A copy of the columns of `data` at the time of the fit */
163
+ snapshot: DataFrame;
164
+ /** The options given to glmer (a copy; `weights` and `offset` as given, arrays copied) */
165
+ options: GlmerOptions;
166
+ /** The estimate θ̂ (a copy) */
167
+ theta: number[];
168
+ /** The fixed effects β̂ (a copy) */
169
+ beta: number[];
170
+ /**
171
+ * R_X'R_X = X'WX − X'WZΛ (Λ'Z'WZΛ + I)⁻¹ Λ'Z'WX at θ̂ with the Fisher weights at the conditional mode (not scaled by
172
+ * σ²; array of rows)
173
+ */
174
+ rxtrx: number[][];
175
+ /** The random effects b̂ = Λ_θ̂ û at the conditional mode, in the order of the columns of Z (a copy) */
176
+ b: number[];
177
+ /** The linear predictor η̂ at the mode, one per row used (a copy) */
178
+ eta: number[];
179
+ /** The fitted means μ̂ (lme4's inverse link), one per row used (a copy) */
180
+ mu: number[];
181
+ /** R's sigma (1 for binomial and poisson) */
182
+ sigma: number;
183
+ }
184
+ /** Whether an object is a result returned by {@link glmer} (internal) */
185
+ export declare function isGlmerFit(fit: unknown): fit is GlmerResult;
186
+ /**
187
+ * The internals of a fit (see {@link GlmerInternals}). Internal. Throws a TypeError for an object that is not a result
188
+ * returned by {@link glmer}.
189
+ */
190
+ export declare function glmerInternals(fit: GlmerResult): GlmerInternals;
191
+ /**
192
+ * Fit a generalized linear mixed model by the Laplace approximation (`nAGQ = 1`, default), by adaptive Gauss-Hermite
193
+ * quadrature (`nAGQ` from 2 to 100) or with the fixed effects from the penalised IRLS (`nAGQ = 0`). Equivalent to `lme4::glmer()` in R. With the quantities of its methods:
194
+ * `fixef()`, `coef(summary())` (without p-values), `vcov()`, `sigma()`, `VarCorr()`, `ranef()`, `fitted()`,
195
+ * `predict()`, `residuals()` of the four types, `deviance()`, `logLik()`, `AIC()`, `BIC()` and `isSingular()`.
196
+ *
197
+ * The families are binomial, poisson, Gamma, inverse.gaussian and gaussian (not with the identity link: that is
198
+ * {@link lmer}), with the links of {@link glm} and lme4's own inverse links and variance functions. The formula is
199
+ * as in {@link lmer}; a binomial response may be 0/1 values, booleans, strings or a factor (the first level failure),
200
+ * proportions with the numbers of trials as `weights`, or `cbind(successes, failures)` with two column names on the
201
+ * left-hand side.
202
+ *
203
+ * The estimate is the exact minimiser of the Laplace deviance computed at the exact conditional mode of the random
204
+ * effects (lme4's optimiser and its penalised IRLS stop early, so lme4's values typically differ in the 4th to 6th
205
+ * significant digit, its standard errors by up to about 1%). Elements of θ on the boundary are exactly 0, and the fit
206
+ * is then singular. lme4's warnings about its optimiser and its convergence checks are not given.
207
+ *
208
+ * The scale of the response: lme4's Laplace criterion leaves out the dispersion, so for the poisson,
209
+ * inverse.gaussian and gaussian families it is not invariant to the scale of the response (or of the prior weights).
210
+ * Where the information about the random effects at the start, Σ W z² of a column of Z (W the working weights at
211
+ * the starting means), is above 2^40 (the penalised system then loses about 40 of its 53 bits), or below 2^-40 and
212
+ * the fit fails or a term ends at θ = 0 on a criterion flat to rounding, the result is a RangeError saying so. For
213
+ * data like the example below: poisson counts up to about 1e11 (prior weights up to about 2^34), inverse.gaussian
214
+ * with the log link up to about 1e13, gaussian with the log link from about 1e-6 to 5e4 fit; beyond, the RangeError.
215
+ * Gamma fits are not limited by the scale of the response (its criterion is invariant; with the log link a tiny
216
+ * response is rescaled).
217
+ *
218
+ * Adaptive Gauss-Hermite quadrature (`nAGQ > 1`) needs a single scalar random-effects term such as `(1 | g)`, with
219
+ * R's errors otherwise. It is offered for binomial and poisson only: for Gamma, inverse.gaussian and gaussian it is a
220
+ * RangeError, since lme4 holds the dispersion at 1 there, so that its estimates would not be maximum likelihood. Its
221
+ * `logLik`, `AIC` and `BIC` are those of the log-likelihood, unlike R's, which leave out the constant of the
222
+ * saturated model (`aic − Σ` deviance residuals) for nAGQ > 1: they differ from R's by that constant and are
223
+ * comparable with the Laplace fit's.
224
+ *
225
+ * @param formula A formula such as `"cbind(inc, notinc) ~ period + (1 | herd)"` or `"y ~ x + (1 | g)"`.
226
+ * @param data The data frame: an object of columns.
227
+ * @param options `family`, `link`, `weights`, `offset`, `nAGQ`, `start`, and `contrasts` and `levels` as in
228
+ * {@link lmer} (see {@link GlmerOptions} for the keys accepted).
229
+ *
230
+ * @example
231
+ * ```ts
232
+ * // R: lme4::glmer(y ~ x + (1 | g), data, family = poisson)
233
+ * const fit = glmer("y ~ x + (1 | g)", {
234
+ * y: [2, 3, 6, 7, 8, 1, 0, 3, 2, 5, 4, 6, 9, 8, 13, 0, 2, 1, 4, 3],
235
+ * x: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
236
+ * g: ["a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "c", "c", "c", "c", "c", "d", "d", "d", "d", "d"],
237
+ * }, { family: "poisson" });
238
+ * fit.fixef; // [0.2512, 0.3242]
239
+ * fit.coefTable.stdError; // [0.4183, 0.08098]
240
+ * fit.varCorr[0].sd; // [0.5423]
241
+ * fit.ranef[0].values; // [[0.2840], [-0.4170], [0.6920], [-0.4819]]
242
+ * fit.logLik; // -39.392
243
+ * ```
244
+ *
245
+ * @category Mixed models
246
+ */
247
+ export declare function glmer(formula: string, data: DataFrame, options?: GlmerOptions): GlmerResult;
248
+ /**
249
+ * The largest information of a column of Z about its random effect at the start, Σ_i W_i z_ij² over the rows of the
250
+ * column (Z scaled as in the fit, so that θ' = 1 is the start of the minimisation; W the working weights at the
251
+ * family's starting means). The Laplace criterion resolves θ' where θ'² times this is neither negligible against the
252
+ * 1 of Λ'Z'WZΛ + I nor so large that the system loses its digits against the fixed effects (internal; exported for
253
+ * the tests)
254
+ */
255
+ export declare function startInformation(s: GlmerStructure): number;