@numero-uno-jpn/rstats 0.11.0 → 0.12.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 (289) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.ja.md +44 -13
  3. package/README.md +43 -11
  4. package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-3VMBBQLV.js} +2 -2
  5. package/dist/chunks/chunk-4OKAZJJG.js +3 -0
  6. package/dist/chunks/{chunk-EZAFN5CD.js → chunk-6BH65HGN.js} +1 -1
  7. package/dist/chunks/chunk-ATC4F4BX.js +2 -0
  8. package/dist/chunks/{chunk-JWBO5WVN.js → chunk-EDH53DXN.js} +2 -2
  9. package/dist/chunks/{chunk-Y5CNQ266.js → chunk-EZ2KD5NA.js} +2 -2
  10. package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-GSPOO2G3.js} +2 -2
  11. package/dist/chunks/{chunk-F5EDJFEO.js → chunk-K7AZ65H7.js} +2 -2
  12. package/dist/chunks/{chunk-YSWGDOWK.js → chunk-LEIH4U5X.js} +2 -2
  13. package/dist/chunks/{chunk-EZWBRCJL.js → chunk-OX3SBG5X.js} +1 -1
  14. package/dist/chunks/chunk-SGZQDJRR.js +2 -0
  15. package/dist/chunks/{chunk-C5XTWMGB.js → chunk-UH2N3ZQW.js} +1 -1
  16. package/dist/chunks/chunk-UV2MZYDQ.js +2 -0
  17. package/dist/chunks/{chunk-TOGXTCZO.js → chunk-VQHEOBTM.js} +2 -2
  18. package/dist/chunks/chunk-WJQZZYOI.js +2 -0
  19. package/dist/chunks/chunk-WKEFHOFR.js +2 -0
  20. package/dist/chunks/{chunk-CGBNKHNZ.js → chunk-WXC25OPJ.js} +2 -2
  21. package/dist/chunks/{chunk-5WDJPHYY.js → chunk-XJQKSR52.js} +1 -1
  22. package/dist/data/grouping.d.ts +39 -15
  23. package/dist/data/grouping.js +21 -22
  24. package/dist/descriptive/basic.d.ts +130 -17
  25. package/dist/descriptive/basic.js +115 -14
  26. package/dist/descriptive/cov.d.ts +22 -12
  27. package/dist/descriptive/dataFrames.d.ts +39 -11
  28. package/dist/descriptive/dataFrames.js +14 -6
  29. package/dist/descriptive/factanal.d.ts +26 -6
  30. package/dist/descriptive/factanal.js +7 -3
  31. package/dist/descriptive/hist.d.ts +27 -6
  32. package/dist/descriptive/hist.js +9 -3
  33. package/dist/descriptive/missing.d.ts +13 -6
  34. package/dist/descriptive/missing.js +4 -2
  35. package/dist/descriptive/moments.d.ts +91 -13
  36. package/dist/descriptive/moments.js +66 -9
  37. package/dist/descriptive/omega.d.ts +28 -6
  38. package/dist/descriptive/omega.js +16 -4
  39. package/dist/descriptive/pivot.d.ts +22 -6
  40. package/dist/descriptive/pivot.js +7 -3
  41. package/dist/descriptive/quantile.d.ts +33 -5
  42. package/dist/descriptive/quantile.js +20 -2
  43. package/dist/descriptive/rank.d.ts +12 -2
  44. package/dist/descriptive/rank.js +2 -0
  45. package/dist/descriptive/table.d.ts +55 -7
  46. package/dist/descriptive/table.js +38 -4
  47. package/dist/descriptive.js +2 -2
  48. package/dist/distributions/arcsine.d.ts +40 -5
  49. package/dist/distributions/arcsine.js +35 -4
  50. package/dist/distributions/beta.d.ts +12 -0
  51. package/dist/distributions/beta.js +12 -0
  52. package/dist/distributions/binomial.d.ts +18 -0
  53. package/dist/distributions/binomial.js +18 -0
  54. package/dist/distributions/bvnorm.d.ts +4 -1
  55. package/dist/distributions/bvnorm.js +4 -1
  56. package/dist/distributions/cauchy.d.ts +24 -0
  57. package/dist/distributions/cauchy.js +24 -0
  58. package/dist/distributions/chisq.d.ts +18 -0
  59. package/dist/distributions/chisq.js +18 -0
  60. package/dist/distributions/exponential.d.ts +29 -1
  61. package/dist/distributions/exponential.js +24 -0
  62. package/dist/distributions/f.d.ts +18 -0
  63. package/dist/distributions/f.js +18 -0
  64. package/dist/distributions/gamma.d.ts +20 -0
  65. package/dist/distributions/gamma.js +18 -0
  66. package/dist/distributions/geometric.d.ts +24 -0
  67. package/dist/distributions/geometric.js +24 -0
  68. package/dist/distributions/hypergeometric.d.ts +24 -0
  69. package/dist/distributions/hypergeometric.js +24 -0
  70. package/dist/distributions/invgamma.d.ts +32 -4
  71. package/dist/distributions/invgamma.js +27 -3
  72. package/dist/distributions/kumaraswamy.d.ts +31 -3
  73. package/dist/distributions/kumaraswamy.js +31 -3
  74. package/dist/distributions/laplace.d.ts +36 -4
  75. package/dist/distributions/laplace.js +31 -3
  76. package/dist/distributions/logistic.d.ts +29 -1
  77. package/dist/distributions/logistic.js +24 -0
  78. package/dist/distributions/lognormal.d.ts +29 -1
  79. package/dist/distributions/lognormal.js +24 -0
  80. package/dist/distributions/multinomial.d.ts +7 -1
  81. package/dist/distributions/multinomial.js +2 -0
  82. package/dist/distributions/negbinomial.d.ts +29 -1
  83. package/dist/distributions/negbinomial.js +24 -0
  84. package/dist/distributions/normal.d.ts +11 -1
  85. package/dist/distributions/normal.js +6 -0
  86. package/dist/distributions/pareto.d.ts +36 -4
  87. package/dist/distributions/pareto.js +31 -3
  88. package/dist/distributions/poisson.d.ts +18 -0
  89. package/dist/distributions/poisson.js +18 -0
  90. package/dist/distributions/signrank.d.ts +24 -0
  91. package/dist/distributions/signrank.js +24 -0
  92. package/dist/distributions/summary.d.ts +20 -2
  93. package/dist/distributions/summary.js +4 -0
  94. package/dist/distributions/t.d.ts +18 -0
  95. package/dist/distributions/t.js +18 -0
  96. package/dist/distributions/triangular.d.ts +36 -4
  97. package/dist/distributions/triangular.js +31 -3
  98. package/dist/distributions/tukey.d.ts +15 -1
  99. package/dist/distributions/tukey.js +10 -0
  100. package/dist/distributions/uniform.d.ts +29 -1
  101. package/dist/distributions/uniform.js +24 -0
  102. package/dist/distributions/weibull.d.ts +29 -1
  103. package/dist/distributions/weibull.js +24 -0
  104. package/dist/distributions/wilcox.d.ts +24 -0
  105. package/dist/distributions/wilcox.js +24 -0
  106. package/dist/distributions.js +2 -2
  107. package/dist/entries/descriptive.d.ts +1 -1
  108. package/dist/entries/mixed.d.ts +1 -0
  109. package/dist/entries/mixed.js +2 -0
  110. package/dist/entries/numerics.d.ts +1 -1
  111. package/dist/entries/tests.js +1 -1
  112. package/dist/htest/agreement.d.ts +61 -23
  113. package/dist/htest/agreement.js +19 -9
  114. package/dist/htest/ansariTest.d.ts +8 -2
  115. package/dist/htest/aov.d.ts +43 -10
  116. package/dist/htest/aov.js +17 -3
  117. package/dist/htest/binomTest.d.ts +12 -2
  118. package/dist/htest/binomTest.js +2 -0
  119. package/dist/htest/brunnerMunzelTest.d.ts +9 -3
  120. package/dist/htest/brunnerMunzelTest.js +4 -2
  121. package/dist/htest/chisqTest.d.ts +19 -3
  122. package/dist/htest/cor.d.ts +20 -4
  123. package/dist/htest/effectSize.d.ts +70 -12
  124. package/dist/htest/effectSize.js +40 -7
  125. package/dist/htest/fisherTest.d.ts +9 -1
  126. package/dist/htest/fisherTest.js +2 -0
  127. package/dist/htest/groups.d.ts +5 -1
  128. package/dist/htest/ksTest.d.ts +20 -3
  129. package/dist/htest/leveneTest.d.ts +15 -4
  130. package/dist/htest/leveneTest.js +5 -2
  131. package/dist/htest/mantelhaenTest.d.ts +25 -3
  132. package/dist/htest/mantelhaenTest.js +15 -1
  133. package/dist/htest/mcnemarTest.d.ts +14 -4
  134. package/dist/htest/mcnemarTest.js +4 -2
  135. package/dist/htest/multipleComparisons.d.ts +173 -29
  136. package/dist/htest/multipleComparisons.js +123 -19
  137. package/dist/htest/normalityTests.d.ts +56 -9
  138. package/dist/htest/normalityTests.js +40 -6
  139. package/dist/htest/onewayTest.d.ts +32 -3
  140. package/dist/htest/onewayTest.js +10 -0
  141. package/dist/htest/pAdjust.d.ts +9 -1
  142. package/dist/htest/pAdjust.js +2 -0
  143. package/dist/htest/pairwise.d.ts +50 -5
  144. package/dist/htest/pairwise.js +25 -0
  145. package/dist/htest/poissonTest.d.ts +12 -2
  146. package/dist/htest/poissonTest.js +2 -0
  147. package/dist/htest/polycor.d.ts +29 -10
  148. package/dist/htest/power.d.ts +60 -6
  149. package/dist/htest/power.js +6 -0
  150. package/dist/htest/propTest.d.ts +13 -2
  151. package/dist/htest/propTest.js +2 -0
  152. package/dist/htest/pwr.d.ts +286 -36
  153. package/dist/htest/pwr.js +116 -15
  154. package/dist/htest/rankTests.d.ts +80 -12
  155. package/dist/htest/rankTests.js +11 -2
  156. package/dist/htest/tTest.d.ts +13 -3
  157. package/dist/htest/testFormula.js +6 -3
  158. package/dist/htest/trendTests.d.ts +29 -8
  159. package/dist/htest/trendTests.js +8 -4
  160. package/dist/htest/types.d.ts +14 -2
  161. package/dist/htest/varTest.d.ts +25 -8
  162. package/dist/htest/wilcoxTest.d.ts +10 -2
  163. package/dist/internal/dpq.d.ts +4 -0
  164. package/dist/internal/noncentral.d.ts +2 -0
  165. package/dist/internal/vectorize.d.ts +4 -0
  166. package/dist/linalg/basic.d.ts +39 -5
  167. package/dist/linalg/basic.js +15 -0
  168. package/dist/linalg/chol.d.ts +26 -5
  169. package/dist/linalg/chol.js +7 -0
  170. package/dist/linalg/eigen.d.ts +16 -7
  171. package/dist/linalg/eigen.js +6 -5
  172. package/dist/linalg/expm.d.ts +15 -5
  173. package/dist/linalg/expm.js +5 -3
  174. package/dist/linalg/kappa.d.ts +21 -1
  175. package/dist/linalg/kappa.js +16 -0
  176. package/dist/linalg/lu.d.ts +30 -6
  177. package/dist/linalg/lu.js +15 -3
  178. package/dist/linalg/matrix.d.ts +4 -0
  179. package/dist/linalg/norm.d.ts +16 -1
  180. package/dist/linalg/norm.js +9 -0
  181. package/dist/linalg/ops.d.ts +156 -35
  182. package/dist/linalg/ops.js +96 -15
  183. package/dist/linalg/qr.d.ts +87 -12
  184. package/dist/linalg/qr.js +31 -0
  185. package/dist/linalg/schur.d.ts +8 -2
  186. package/dist/linalg/schur.js +3 -1
  187. package/dist/linalg/solve.d.ts +42 -6
  188. package/dist/linalg/solve.js +22 -0
  189. package/dist/linalg/svd.d.ts +12 -2
  190. package/dist/linalg/svd.js +2 -0
  191. package/dist/linalg.js +2 -2
  192. package/dist/mixed.js +3 -0
  193. package/dist/models/anovaSequential.d.ts +26 -4
  194. package/dist/models/anovaSequential.js +3 -1
  195. package/dist/models/aovEz.d.ts +29 -6
  196. package/dist/models/aovEz.js +5 -2
  197. package/dist/models/aovStrata.d.ts +13 -3
  198. package/dist/models/aovStrata.js +5 -1
  199. package/dist/models/carAnova.d.ts +9 -3
  200. package/dist/models/carAnova.js +4 -2
  201. package/dist/models/coxph.d.ts +33 -7
  202. package/dist/models/coxph.js +8 -3
  203. package/dist/models/formula.d.ts +26 -1
  204. package/dist/models/formula.js +125 -9
  205. package/dist/models/glm.d.ts +128 -21
  206. package/dist/models/glm.js +71 -14
  207. package/dist/models/glmAnova.d.ts +30 -5
  208. package/dist/models/glmAnova.js +15 -2
  209. package/dist/models/glmConfint.d.ts +16 -2
  210. package/dist/models/glmConfint.js +9 -1
  211. package/dist/models/glmFamily.d.ts +27 -5
  212. package/dist/models/lm.d.ts +77 -19
  213. package/dist/models/lm.js +22 -4
  214. package/dist/models/lmer.d.ts +162 -0
  215. package/dist/models/lmer.js +457 -0
  216. package/dist/models/mauchly.d.ts +20 -5
  217. package/dist/models/mauchly.js +7 -3
  218. package/dist/models/mixedDeviance.d.ts +44 -0
  219. package/dist/models/mixedDeviance.js +872 -0
  220. package/dist/models/mixedStructure.d.ts +82 -0
  221. package/dist/models/mixedStructure.js +309 -0
  222. package/dist/models/modelFrame.d.ts +17 -2
  223. package/dist/models/modelFrame.js +36 -21
  224. package/dist/models/modelMatrix.d.ts +33 -8
  225. package/dist/models/modelMatrix.js +21 -5
  226. package/dist/models/survival.d.ts +41 -9
  227. package/dist/models/survival.js +10 -4
  228. package/dist/numerics/deriv.d.ts +21 -6
  229. package/dist/numerics/deriv.js +16 -5
  230. package/dist/numerics/integrate.d.ts +37 -7
  231. package/dist/numerics/integrate.js +8 -2
  232. package/dist/numerics/interp.d.ts +63 -12
  233. package/dist/numerics/interp.js +30 -6
  234. package/dist/numerics/ode.d.ts +15 -5
  235. package/dist/numerics/ode.js +5 -3
  236. package/dist/numerics.js +2 -2
  237. package/dist/optim/optim.d.ts +32 -8
  238. package/dist/optim/optim.js +8 -4
  239. package/dist/random/beta.d.ts +8 -0
  240. package/dist/random/beta.js +8 -0
  241. package/dist/random/binomial.d.ts +16 -0
  242. package/dist/random/binomial.js +16 -0
  243. package/dist/random/continuous.d.ts +51 -0
  244. package/dist/random/continuous.js +51 -0
  245. package/dist/random/extra.d.ts +66 -6
  246. package/dist/random/extra.js +66 -6
  247. package/dist/random/gamma.d.ts +33 -0
  248. package/dist/random/gamma.js +33 -0
  249. package/dist/random/hyper.d.ts +8 -0
  250. package/dist/random/hyper.js +8 -0
  251. package/dist/random/poisson.d.ts +25 -0
  252. package/dist/random/poisson.js +25 -0
  253. package/dist/random/r2dtable.d.ts +2 -0
  254. package/dist/random/r2dtable.js +2 -0
  255. package/dist/random/rank.d.ts +16 -0
  256. package/dist/random/rank.js +16 -0
  257. package/dist/random/rng.d.ts +49 -6
  258. package/dist/random/rng.js +29 -2
  259. package/dist/random/sample.d.ts +10 -2
  260. package/dist/random/sample.js +5 -1
  261. package/dist/random/streams.d.ts +13 -0
  262. package/dist/random/streams.js +13 -0
  263. package/dist/rstats.js +14 -14
  264. package/dist/special/besselIK.d.ts +11 -3
  265. package/dist/special/besselIK.js +6 -2
  266. package/dist/special/besselJY.d.ts +6 -2
  267. package/dist/special/besselJY.js +6 -2
  268. package/dist/special/beta.d.ts +16 -2
  269. package/dist/special/beta.js +16 -2
  270. package/dist/special/choose.d.ts +13 -5
  271. package/dist/special/choose.js +13 -5
  272. package/dist/special/erf.d.ts +8 -3
  273. package/dist/special/erf.js +8 -3
  274. package/dist/special/extra.d.ts +30 -10
  275. package/dist/special/extra.js +25 -9
  276. package/dist/special/gamma.d.ts +18 -2
  277. package/dist/special/gamma.js +18 -2
  278. package/dist/special/log1p.d.ts +16 -7
  279. package/dist/special/log1p.js +16 -7
  280. package/dist/special/psigamma.d.ts +9 -3
  281. package/dist/special/psigamma.js +9 -3
  282. package/dist/special/rCompatible.d.ts +5 -1
  283. package/dist/special.js +2 -2
  284. package/dist/tests.js +12 -12
  285. package/llms.txt +13 -3
  286. package/package.json +5 -1
  287. package/dist/chunks/chunk-7GQMKH3Z.js +0 -2
  288. package/dist/chunks/chunk-AHHS6AC4.js +0 -3
  289. package/dist/chunks/chunk-ALM3VHFP.js +0 -2
package/dist/mixed.js ADDED
@@ -0,0 +1,3 @@
1
+ /*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{a as lt}from"./chunks/chunk-UV2MZYDQ.js";import{h as bt,u as At,w as xt}from"./chunks/chunk-WJQZZYOI.js";import{b as st,c as gt,e as dt,f as ct,h as wt,i as at}from"./chunks/chunk-4OKAZJJG.js";import{b as vt}from"./chunks/chunk-WKEFHOFR.js";var Mt=1,kt=new WeakMap;function Ct(r){let n=kt.get(r);if(n!==void 0)return n;let s=r.y.length,l=r.xColNames.length,o=r.q,i=r.terms.length,t=r.terms.reduce((f,M)=>f+M.nLevels,0),e=new Int32Array(t+1),m=new Int32Array(t),b=[],p=[],j=0;r.terms.forEach((f,M)=>{let P=f.columns.length;b.push(j),p.push(P);for(let N=0;N<f.nLevels;N++,j++)e[j]=f.zOffset+N*P,m[j]=M}),e[t]=o;let _=r.terms.map((f,M)=>{let P=p[M],N=new Int32Array(P*P).fill(-1);for(let{row:Y,col:Z,theta:J}of r.lambda)Z>=f.zOffset&&Z<f.zOffset+P&&(N[Y-f.zOffset+(Z-f.zOffset)*P]=J);return N}),k=r.terms.map(f=>r.groups[f.group].codes),u=new Int32Array(s+1);for(let f=0;f<s;f++){let M=0;for(let P of r.terms)for(let N of P.matrix[f])N!==0&&M++;u[f+1]=u[f]+M}let I=u,C=I[s],$=new Int32Array(C),y=new Float64Array(C);{let f=0;for(let M=0;M<s;M++)r.terms.forEach((P,N)=>{let Y=P.zOffset+k[N][M]*p[N];P.matrix[M].forEach((Z,J)=>{Z!==0&&($[f]=Y+J,y[f++]=Z)})})}let A=new Map,x=[],z=[],D=(f,M)=>{let P=M*t+f,N=A.get(P);return N===void 0&&(N=x.length,A.set(P,N),x.push(f),z.push(M)),N};for(let f=0;f<t;f++)D(f,f);let S=new Int32Array(i),G=i*(i+1)/2,H=new Int32Array(s*G);for(let f=0;f<s;f++){for(let M=0;M<i;M++)S[M]=b[M]+k[M][f];for(let M=0;M<i;M++)for(let P=0;P<=M;P++)H[f*G+M*(M+1)/2+P]=D(S[M],S[P])}let U=x.length,g=Array.from({length:U},(f,M)=>M).sort((f,M)=>z[f]-z[M]||x[f]-x[M]),T=new Int32Array(U);g.forEach((f,M)=>T[f]=M);let E=new Int32Array(t+1),V=new Int32Array(U),L=new Int32Array(U+1);g.forEach((f,M)=>{V[M]=x[f],E[z[f]+1]++;let P=p[m[x[f]]]*p[m[z[f]]];L[M+1]=L[M]+P});for(let f=0;f<t;f++)E[f+1]+=E[f];let B=new Float64Array(L[U]),K=new Float64Array(o*l),X=new Float64Array(o),c=new Float64Array(l);for(let f=0;f<s;f++){let M=r.x[f],P=r.y[f];for(let N=0;N<i;N++){let Y=r.terms[N].matrix[f],Z=p[N];for(let J=0;J<=N;J++){let Nt=r.terms[J].matrix[f],jt=p[J],Lt=T[H[f*G+N*(N+1)/2+J]],qt=L[Lt];for(let ot=0;ot<jt;ot++){let pt=Nt[ot];if(pt!==0)for(let rt=0;rt<Z;rt++)B[qt+rt+ot*Z]+=Y[rt]*pt}}}for(let N=I[f];N<I[f+1];N++){let Y=$[N],Z=y[N];for(let J=0;J<l;J++)K[Y+J*o]+=Z*M[J];X[Y]+=Z*P}for(let N=0;N<l;N++)c[N]+=M[N]*P}let a=new Array(t),O=Array.from({length:t},()=>[]),h=new Int32Array(t).fill(-1);for(let f=0;f<t;f++){let M=[],P=Y=>{Y!==f&&h[Y]!==f&&(h[Y]=f,M.push(Y))};for(let Y=E[f]+1;Y<E[f+1];Y++)P(V[Y]);for(let Y of O[f])for(let Z of a[Y])P(Z);let N=Int32Array.from(M).sort();a[f]=N,N.length>0&&O[N[0]].push(f)}let v=new Int32Array(U);{let f=new Int32Array(t);for(let M=0;M<t;M++){let P=0;for(let N of a[M])f[N]=P,P+=e[N+1]-e[N];for(let N=E[M]+1;N<E[M+1];N++)v[N]=f[V[N]]}}let F=new Int32Array(o+1);for(let f=0;f<t;f++){let M=0;for(let P of a[f])M+=e[P+1]-e[P];for(let P=e[f];P<e[f+1];P++)F[P+1]=F[P]+(e[f+1]-P)+M}let R=new Int32Array(F[o]),w=new Int32Array(o+1);for(let f=0;f<t;f++)for(let M=e[f];M<e[f+1];M++){let P=F[M];for(let N=M;N<e[f+1];N++)R[P++]=N;for(let N of a[f])for(let Y=e[N];Y<e[N+1];Y++)R[P++]=Y}for(let f=0;f<o;f++)for(let M=F[f]+1;M<F[f+1];M++)w[R[M]+1]++;for(let f=0;f<o;f++)w[f+1]+=w[f];let d=w.slice(),q=w.slice(0,o),W=new Int32Array(d[o]),tt=new Int32Array(d[o]);for(let f=0;f<o;f++)for(let M=F[f]+1;M<F[f+1];M++){let P=q[R[M]]++;W[P]=f,tt[P]=M}let et={n:s,p:l,q:o,nGroups:t,groupStart:e,groupTerm:m,termNc:p,termTheta:_,blockStart:E,blockRow:V,blockValueStart:L,zz:B,zx:K,zy:X,xy:c,rowStart:I,rowCols:$,rowValues:y,colStart:F,colRows:R,rowListStart:d,rowListCol:W,rowListPos:tt,blockPatternOffset:v};return kt.set(r,et),et}function _t(r,n){return r.termTheta.map(s=>Float64Array.from(s,l=>l<0?0:n[l]))}function ft(r,n,s){let l=new Float64Array(r.q);for(let o=0;o<r.nGroups;o++){let i=r.groupTerm[o],t=r.termNc[i],e=n[i],m=r.groupStart[o];for(let b=0;b<t;b++){let p=s[m+b];if(p!==0)for(let j=b;j<t;j++)l[m+j]+=e[j+b*t]*p}}return l}function nt(r,n,s,l=1){let o=r.q,i=new Float64Array(o*l);for(let t=0;t<r.nGroups;t++){let e=r.groupTerm[t],m=r.termNc[e],b=n[e],p=r.groupStart[t];for(let j=0;j<l;j++){let _=p+j*o;for(let k=0;k<m;k++){let u=0;for(let I=k;I<m;I++)u+=b[I+k*m]*s[_+I];i[_+k]=u}}}return i}function Vt(r,n){let s=new Float64Array(r.zz.length),l=new Float64Array(64);for(let o=0;o<r.nGroups;o++){let i=r.groupTerm[o],t=r.termNc[i],e=n[i];for(let m=r.blockStart[o];m<r.blockStart[o+1];m++){let b=r.groupTerm[r.blockRow[m]],p=r.termNc[b],j=n[b],_=r.blockValueStart[m];if(p===1&&t===1)s[_]=j[0]*r.zz[_]*e[0];else{let k=l.length>=p*t?l:new Float64Array(p*t);for(let u=0;u<t;u++)for(let I=0;I<p;I++){let C=0;for(let $=u;$<t;$++)C+=r.zz[_+I+$*p]*e[$+u*t];k[I+u*p]=C}for(let u=0;u<t;u++)for(let I=0;I<p;I++){let C=0;for(let $=I;$<p;$++)C+=j[$+I*p]*k[$+u*p];s[_+I+u*p]=C}}if(m===r.blockStart[o])for(let k=0;k<t;k++)s[_+k+k*t]+=1}}return s}function Pt(r,n){let{q:s,colStart:l,colRows:o,rowListStart:i,rowListCol:t,rowListPos:e}=r,m=new Float64Array(o.length),b=new Float64Array(s);for(let p=0;p<r.nGroups;p++){let j=r.termNc[r.groupTerm[p]],_=r.groupStart[p];for(let k=0;k<j;k++){let u=_+k;for(let y=r.blockStart[p];y<r.blockStart[p+1];y++){let A=r.blockRow[y],x=r.termNc[r.groupTerm[A]],z=r.blockValueStart[y]+k*x,D=r.groupStart[A];for(let S=A===p?k:0;S<x;S++)b[D+S]=n[z+S]}for(let y=i[u];y<i[u+1];y++){let A=t[y],x=e[y],z=m[x];if(z===0)continue;let D=l[A+1];for(let S=x;S<D;S++)b[o[S]]-=m[S]*z}let I=b[u];if(!(I>0))throw new Error("the penalised least-squares matrix is not positive definite");let C=Math.sqrt(I),$=l[u];m[$]=C,b[u]=0;for(let y=$+1;y<l[u+1];y++){let A=o[y];m[y]=b[A]/C,b[A]=0}}}return m}function it(r,n,s,l=0){let{q:o,colStart:i,colRows:t}=r;for(let e=0;e<o;e++){let m=i[e],b=s[l+e]/=n[m];if(b!==0)for(let p=m+1;p<i[e+1];p++)s[l+t[p]]-=n[p]*b}}function mt(r,n,s,l=0){let{q:o,colStart:i,colRows:t}=r;for(let e=o-1;e>=0;e--){let m=i[e],b=s[l+e];for(let p=m+1;p<i[e+1];p++)b-=n[p]*s[l+t[p]];s[l+e]=b/n[m]}}function Dt(r,n,s){for(let l=0;l<n;l++){let o=l*n,i=s[l];for(let t=0;t<l;t++)i-=r[t+o]*s[t];s[l]=i/r[l+o]}}function Gt(r,n,s){for(let l=n-1;l>=0;l--){let o=s[l]/=r[l+l*n],i=l*n;for(let t=0;t<l;t++)s[t]-=r[t+i]*o}}function $t(r,n){let s=r.slice();for(let l=0;l<n;l++)for(let o=l+1;o<n;o++)s[o+l*n]=0;xt({nrow:n,ncol:n,data:s});for(let l=0;l<n;l++)for(let o=l+1;o<n;o++)s[o+l*n]=s[l+o*n];return s}function ut(r,n,s,l={}){if(n.length!==r.theta.length)throw new RangeError(`theta must have length ${r.theta.length}, not ${n.length}`);if(n.some(a=>!Number.isFinite(a)))throw new RangeError("theta must be finite");let o=Ct(r),{n:i,p:t,q:e}=o,m=_t(o,n),b=Pt(o,Vt(o,m)),p=a=>{let O=new Float64Array(i);for(let h=0;h<i;h++){let v=0;for(let F=o.rowStart[h];F<o.rowStart[h+1];F++)v+=o.rowValues[F]*a[o.rowCols[F]];O[h]=v}return O},j=a=>{let O=new Float64Array(e);for(let h=0;h<i;h++){let v=a[h];for(let F=o.rowStart[h];F<o.rowStart[h+1];F++)O[o.rowCols[F]]+=o.rowValues[F]*v}return O},_=a=>{it(o,b,a),mt(o,b,a)},k=nt(o,m,o.zx,t);for(let a=0;a<t;a++)it(o,b,k,a*e);let u=[],I=[];for(let a=0;a<t;a++){let O=k.slice(a*e,(a+1)*e);mt(o,b,O);let h=Float64Array.from(r.x,R=>R[a]),v=()=>{let R=p(ft(o,m,O));return h.map((w,d)=>w-R[d])},F=v();for(let R=0;R<Mt;R++){let w=nt(o,m,j(F));for(let d=0;d<e;d++)w[d]-=O[d];_(w);for(let d=0;d<e;d++)O[d]+=w[d];F=v()}u.push(F),I.push(O)}let C=new Float64Array(t*t);for(let a=0;a<t;a++)for(let O=a;O<t;O++){let h=0,v=u[a],F=u[O];for(let d=0;d<i;d++)h+=v[d]*F[d];let R=I[a],w=I[O];for(let d=0;d<e;d++)h+=R[d]*w[d];C[a+O*t]=h,C[O+a*t]=h}let $={nrow:t,ncol:t,data:C};if(t>0&&At($)>0)throw new Error("the fixed-effects matrix of the penalised least squares is not positive definite");let y=(a,O)=>{it(o,b,a);for(let h=0;h<t;h++){let v=O[h];for(let F=0;F<e;F++)v-=k[F+h*e]*a[F];O[h]=v}Dt(C,t,O),Gt(C,t,O);for(let h=0;h<t;h++){let v=O[h];for(let F=0;F<e;F++)a[F]-=k[F+h*e]*v}mt(o,b,a)},A=(a,O)=>{let h=p(O),v=new Float64Array(i);for(let F=0;F<i;F++){let R=r.x[F],w=h[F];for(let d=0;d<t;d++)w+=R[d]*a[d];v[F]=r.y[F]-w}return v},x=nt(o,m,o.zy),z=Float64Array.from(o.xy);y(x,z);let D=ft(o,m,x),S=A(z,D);for(let a=0;a<Mt;a++){let O=nt(o,m,j(S));for(let v=0;v<e;v++)O[v]-=x[v];let h=new Float64Array(t);for(let v=0;v<i;v++){let F=r.x[v],R=S[v];for(let w=0;w<t;w++)h[w]+=F[w]*R}y(O,h);for(let v=0;v<e;v++)x[v]+=O[v];for(let v=0;v<t;v++)z[v]+=h[v];D=ft(o,m,x),S=A(z,D)}let G=Array.from(z),H=Array.from(x),U=Array.from(D),g=0;for(let a of S)g+=a*a;let T=0;for(let a of H)T+=a*a;let E=g+T,V=0;for(let a=0;a<e;a++)V+=Math.log(b[o.colStart[a]]);V*=2;let L=0;for(let a=0;a<t;a++)L+=Math.log(C[a+a*t]);L*=2;let B=s?i-t:i,X={deviance:(s?V+L:V)+B*(1+Math.log(2*Math.PI*E/B)),beta:G,u:H,b:U,rss:g,ussq:T,prss:E,logDetL:V,logDetRX:L},c=l.gradient===!0||l.rxInverse===!0?$t(C,t):void 0;return l.rxInverse===!0&&(X.rxInverse=Array.from({length:t},(a,O)=>Array.from({length:t},(h,v)=>c[O+v*t]))),l.gradient===!0&&(X.gradient=Bt(r,o,m,b,n,s,{res:S,uv:x,prss:E,ws:I,xResiduals:u,sInverse:c})),X}function Ut(r,n){let{q:s,colStart:l,colRows:o}=r,i=new Float64Array(n.length),t=new Int32Array(s).fill(-1),e=new Float64Array(s),m=new Float64Array(s);for(let b=s-1;b>=0;b--){let p=l[b],j=l[b+1];for(let u=p+1;u<j;u++){let I=o[u];t[I]=b,e[I]=n[u],m[I]=0}for(let u=p+1;u<j;u++){let I=o[u],C=n[u],$=l[I],y=i[$]*C;for(let A=$+1;A<l[I+1];A++){let x=o[A];if(t[x]!==b)continue;let z=i[A];m[x]+=z*C,y+=z*e[x]}m[I]+=y}let _=n[p],k=1/_;for(let u=p+1;u<j;u++){let I=-m[o[u]]/_;i[u]=I,k-=n[u]*I}i[p]=k/_}return i}function Bt(r,n,s,l,o,i,{res:t,uv:e,prss:m,ws:b,xResiduals:p,sInverse:j}){let{n:_,p:k,q:u,colStart:I,zz:C}=n,$=Ut(n,l),y=n.termNc.map(g=>new Float64Array(g*g)),A=new Float64Array(16),x=new Float64Array(16);for(let g=0;g<n.nGroups;g++){let T=n.groupTerm[g],E=n.termNc[T],V=s[T],L=n.groupStart[g];for(let B=n.blockStart[g];B<n.blockStart[g+1];B++){let K=n.blockRow[B],X=n.groupTerm[K],c=n.termNc[X],a=s[X],O=n.blockValueStart[B];if(E===1&&c===1){let R=K===g?I[L]:I[L]+1+n.blockPatternOffset[B],w=$[R]*C[O];y[T][0]+=w*a[0],K!==g&&(y[X][0]+=w*V[0]);continue}let h=c*E;A.length<h&&(A=new Float64Array(h),x=new Float64Array(Math.max(h,c*c,E*E)));for(let R=0;R<E;R++){let w=I[L+R];if(K===g)for(let d=R;d<c;d++){let q=$[w+d-R];A[d+R*c]=q,A[R+d*c]=q}else{let d=w+(E-R)+n.blockPatternOffset[B];for(let q=0;q<c;q++)A[q+R*c]=$[d+q]}}for(let R=0;R<E;R++)for(let w=0;w<c;w++){let d=0;for(let q=w;q<c;q++)d+=a[q+w*c]*C[O+q+R*c];x[w+R*c]=d}let v=y[T];for(let R=0;R<E;R++)for(let w=0;w<E;w++){let d=0;for(let q=0;q<c;q++)d+=A[q+R*c]*x[q+w*c];v[R+w*E]+=d}if(K===g)continue;for(let R=0;R<c;R++)for(let w=0;w<E;w++){let d=0;for(let q=w;q<E;q++)d+=V[q+w*E]*C[O+R+q*c];x[w+R*E]=d}let F=y[X];for(let R=0;R<c;R++)for(let w=0;w<c;w++){let d=0;for(let q=0;q<E;q++)d+=A[R+q*c]*x[q+w*E];F[R+w*c]+=d}}}let z=new Array(o.length).fill(0);n.termTheta.forEach((g,T)=>{let E=n.termNc[T];for(let V=0;V<E;V++)for(let L=V;L<E;L++)z[g[L+V*E]]+=2*y[T][V+L*E]});let D=new Float64Array(u);for(let g=0;g<_;g++){let T=t[g];for(let E=n.rowStart[g];E<n.rowStart[g+1];E++)D[n.rowCols[E]]+=n.rowValues[E]*T}let S,G;if(i&&k>0){S=new Float64Array(u*k);for(let g=0;g<k;g++)for(let T=0;T<k;T++){let E=j[T+g*k],V=b[T];for(let L=0;L<u;L++)S[L+g*u]+=V[L]*E}G=new Float64Array(k*u);for(let g=0;g<_;g++)for(let T=n.rowStart[g];T<n.rowStart[g+1];T++){let E=n.rowCols[T],V=n.rowValues[T];for(let L=0;L<k;L++)G[L+E*k]+=p[L][g]*V}}let U=2*(i?_-k:_)/m;for(let{row:g,col:T,theta:E}of r.lambda){let V=0;if(S!==void 0&&G!==void 0)for(let L=0;L<k;L++)V+=S[T+L*u]*G[L+g*k];z[E]-=2*V+U*D[g]*e[T]}return z}function Xt(r){let n=[],s=e=>{e.type==="var"?n.includes(e.name)||n.push(e.name):e.type==="binary"?(s(e.left),e.op!=="^"&&s(e.right)):(e.type==="unary"||e.type==="paren"||e.type==="Error")&&s(e.arg)};s(r);let{terms:l}=wt(r,e=>n.indexOf(e),[]);if(l.length===0)throw new SyntaxError(`invalid formula: no grouping factor in '${ct(r)}'`);let o=l.map((e,m)=>[e,m]).sort((e,m)=>e[0].length-m[0].length||e[1]-m[1]).map(([e])=>e.map(m=>n[m])),i=!1,t=e=>{e.type==="binary"?(e.op==="/"&&(i=!0),t(e.left),t(e.right)):(e.type==="unary"||e.type==="paren"||e.type==="Error")&&t(e.arg)};return t(r),i&&(o=o.map(e=>[...e].reverse()).reverse()),o}function Ht(r){if(r.kind==="factor")return vt(r);let n=[...new Set(r.values)].sort((o,i)=>o-i),s=[],l=new Map;for(let o of n){let i=st(o);l.has(i)||(l.set(i,s.length),s.push(i))}return{levels:s,codes:r.values.map(o=>l.get(st(o)))}}function yt(r,n,s={}){let l=gt(r,!1,!0);if(l.response===void 0)throw new TypeError("the formula has no response");let{fixed:o,bars:i}=dt(l.rhs);if(typeof n!="object"||n===null)throw new TypeError("data must be an object of columns");let t={...s.levels===void 0?{}:{levels:s.levels},dropUnusedLevels:!0},e=o??{type:"num",value:1,text:"1"},m=s.contrasts===void 0?{}:{contrasts:s.contrasts,contrastVariables:at({response:l.response,rhs:e},Object.keys(n)).variables},b=lt(l,n,{...t,...m},e),{frame:p}=b,j=p.rows.length;if(j===0)throw new RangeError("0 (non-NA) cases");if(i.length===0)throw new Error("No random effects terms specified in formula");let _=b.terms.variables,k=[];for(let c of i){let a=[c.lhs];if(c.double){let h=at(l,Object.keys(n),c.lhs);a=h.intercept?[{type:"num",value:1,text:"1"}]:[];for(let v of h.terms){let F=v.map(R=>({type:"var",name:_[R]})).reduce((R,w)=>({type:"binary",op:":",left:R,right:w}));a.push({type:"binary",op:"+",left:{type:"num",value:0,text:"0"},right:F})}}let O=Xt(c.group);for(let h of a)for(let v of O)k.push({lhs:h,groupVariables:v})}let u=new Map,I=c=>{let a=c.join(":"),O=u.get(a);if(O!==void 0)return O;let h=c.map(F=>Ht(p.variables[_.indexOf(F)])),v;if(h.length===1)v=h[0];else{let F=new Map;for(let d=0;d<j;d++){let q=h.map(W=>W.codes[d]);F.set(q.join(","),q)}let R=[...F.values()].sort((d,q)=>{for(let W=0;W<d.length;W++)if(d[W]!==q[W])return d[W]-q[W];return 0}),w=new Map(R.map((d,q)=>[d.join(","),q]));v={levels:R.map(d=>d.map((q,W)=>h[W].levels[q]).join(":")),codes:Array.from({length:j},(d,q)=>w.get(h.map(W=>W.codes[q]).join(",")))}}return u.set(a,v),v},C=k.map(c=>({...c,name:c.groupVariables.join(":"),factor:I(c.groupVariables)})),$=C;C.some((c,a)=>a>0&&c.factor.levels.length>C[a-1].factor.levels.length)&&($=C.map((c,a)=>[c,a]).sort((c,a)=>c[0].factor.levels.length-a[0].factor.levels.length||c[1]-a[1]).map(([c])=>c).reverse());let y=[],A=[],x=0,z=0;for(let c of $){let a=y.findIndex(F=>F.name===c.name);a<0&&(a=y.length,y.push({name:c.name,levels:c.factor.levels,codes:c.factor.codes}));let O=lt(l,n,t,c.lhs),h=O.colNames.length,v=c.factor.levels.length;A.push({label:`${ct(c.lhs)} | ${c.name}`,group:a,columns:O.colNames,matrix:O.x,nLevels:v,zOffset:x,thetaOffset:z}),x+=v*h,z+=h*(h+1)/2}if(y.some(c=>c.levels.length<2))throw new RangeError("grouping factors must have > 1 sampled level");let D=y.filter(c=>c.levels.length>=j).map(c=>c.name);if(D.length>0)throw new RangeError(`number of levels of each grouping factor must be < number of observations (problems: ${D.join(", ")})`);for(let c of A){let a=c.nLevels*c.columns.length;if(j<=a)throw new RangeError(`number of observations (=${j}) <= number of random effects (=${a}) for term (${c.label}); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable`)}let S=[],G=[],H=[],U=[],g=[];for(let c of A){let{levels:a,codes:O}=y[c.group],h=c.columns.length,v=Array.from({length:a.length*h},()=>({rows:[],values:[]}));for(let w=0;w<j;w++){let d=c.matrix[w],q=O[w]*h;for(let W=0;W<h;W++){let tt=d[W];if(tt===0)continue;let et=v[q+W];et.rows.push(w),et.values.push(tt)}}for(let w=0;w<a.length;w++)for(let d=0;d<h;d++)S.push(v[w*h+d]),G.push(a[w]);let F=Array.from({length:h},()=>new Array(h).fill(-1)),R=c.thetaOffset;for(let w=0;w<h;w++)for(let d=w;d<h;d++)F[d][w]=R++,H.push(d===w?1:0),U.push(d===w?0:-1/0);for(let w=0;w<c.nLevels;w++){let d=c.zOffset+w*h;for(let q=0;q<h;q++)for(let W=q;W<h;W++)g.push({row:d+W,col:d+q,theta:F[W][q]})}}let T=[],E=b.x,V=b.colNames;if(V.length>0){let c=bt(E),a=new Set(c.pivot.slice(c.rank));if(a.size>0){let O=V.map((h,v)=>v).filter(h=>!a.has(h));E=E.map(h=>O.map(v=>h[v])),V=O.map(h=>V[h]),T.push(`fixed-effect model matrix is rank deficient so dropping ${a.size} ${a.size===1?"column / coefficient":"columns / coefficients"}`)}}let L=[...b.warnings],B=[];for(let c=0;c<V.length;c++){let a=E.map(v=>v[c]);if(a.every(v=>v===0||v===1))continue;let O=a.reduce((v,F)=>v+F,0)/j,h=Math.sqrt(a.reduce((v,F)=>v+(F-O)**2,0)/(j-1));B.push(h)}let K=Math.log(1e3);return B.some((c,a)=>Math.abs(Math.log(c))>K||B.some((O,h)=>h!==a&&Math.abs(Math.log(c/O))>K))&&L.push(`Some predictor variables are on very different scales: consider rescaling.
3
+ You may also use (g)lmerControl(autoscale = TRUE) to improve numerical stability.`),{rows:p.rows,y:b.y,xColNames:V,x:E,terms:A,groups:y,q:S.length,z:S,zColLevels:G,theta:H,lower:U,lambda:g,messages:T,warnings:L}}var St=.25,Wt=1e-4,Yt=1e-6,Et=1e-6,It=1e-4,Kt=.001,Ot=1e-13,Ft=1e-10,Zt=1e-9,Jt=500,Tt=.75,Rt="lmer: the minimisation of the criterion over theta did not converge";function zt(r){let n=r.length,s=r.map(o=>o.slice()),l=s.map((o,i)=>s.map((t,e)=>i===e?1:0));for(let o=0;o<100;o++){let i=0,t=0;for(let e=0;e<n;e++)for(let m=0;m<n;m++)t+=s[e][m]**2,e!==m&&(i+=s[e][m]**2);if(i<=1e-32*t)break;for(let e=0;e<n-1;e++)for(let m=e+1;m<n;m++){let b=s[e][m];if(b===0)continue;let p=(s[m][m]-s[e][e])/(2*b),j=Math.sign(p||1)/(Math.abs(p)+Math.sqrt(1+p*p)),_=1/Math.sqrt(1+j*j),k=j*_;for(let u=0;u<n;u++){let I=s[u][e],C=s[u][m];s[u][e]=_*I-k*C,s[u][m]=k*I+_*C}for(let u=0;u<n;u++){let I=s[e][u],C=s[m][u];s[e][u]=_*I-k*C,s[m][u]=k*I+_*C}for(let u=0;u<n;u++){let I=l[u][e],C=l[u][m];l[u][e]=_*I-k*C,l[u][m]=k*I+_*C}}}return{values:s.map((o,i)=>o[i]),vectors:s.map((o,i)=>l.map(t=>t[i]))}}var ht=r=>Math.sqrt(r.reduce((n,s)=>n+s*s,0)),Q=(r,n)=>r.reduce((s,l,o)=>s+l*n[o],0);function Qt(r,n,s,l,o){let i=r.length,{values:t,vectors:e}=n,m=e.map(A=>Q(A,r)),b=A=>{let x=new Array(i).fill(0);return A.forEach((z,D)=>e[D].forEach((S,G)=>x[G]+=z*S)),x},p=Math.min(...t);if(p>-l&&t.every((A,x)=>A>l||Math.abs(m[x])<=o)){let A=b(t.map((x,z)=>x>l?-m[z]/x:0));if(ht(A)<=s)return{step:A,newton:!0}}let j=Math.max(0,-p),_=A=>Math.sqrt(t.reduce((x,z,D)=>x+(m[D]/(z+A))**2,0)),k=Math.max(l,1e-12*Math.max(...t.map(Math.abs),1));if(_(j+k)>=s){let A=j+k,x=j+ht(r)/s+Math.max(...t.map(Math.abs))+k;for(let z=0;z<200&&x-A>1e-15*x;z++){let D=(A+x)/2;_(D)>s?A=D:x=D}return{step:b(t.map((z,D)=>-m[D]/(z+x))),newton:!1}}let u=t.map(A=>A+j<=k),I=b(t.map((A,x)=>u[x]?0:-m[x]/(A+j))),C=t.indexOf(p),$=Math.sqrt(Math.max(0,s*s-Q(I,I))),y=-Math.sign(m[C])||1;return{step:I.map((A,x)=>A+y*$*e[C][x]),newton:!1}}function te(r){let n=[];for(let s of r.terms){let l=s.columns.length,o=s.thetaOffset;for(let i=0;i<l;i++){let t=[];for(let e=i;e<l;e++)t.push(o++);n.push(t)}}return n}var ee=(r,n,s)=>{let l=ut(r,n,s,{gradient:!0});return{f:l.deviance,g:l.gradient}};function oe(r,n,s){let l=r.lower.map(y=>y===0),o=y=>s(r,y,n),i=r.theta.slice(),{f:t,g:e}=o(i),m=new Set,b=new Set,p=()=>Math.max(1,...i.map(Math.abs)),j=()=>Zt*Math.max(1,Math.abs(t)),_=St*p(),k=1/0,u,I=y=>{let A=Yt*p(),x=y.map(z=>{let D=Math.max(Wt*Math.abs(i[z]),A),S=i.slice();S[z]=i[z]+D;let G=i.slice();G[z]=i[z]-D;let H=o(S).g,U=o(G).g;return y.map(g=>(H[g]-U[g])/(2*D))});return y.map((z,D)=>y.map((S,G)=>(x[D][G]+x[G][D])/2))},C=y=>{let A=u===void 0||u.free.length!==y.length||u.free.some((c,a)=>c!==y[a]),x=A?I(y):u.h;u=void 0;let z=zt(x),D=Et*Math.max(...z.values.map(Math.abs)),S=y.map(c=>e[c]),{step:G,newton:H}=Qt(S,z,_,D,j()),U=i.slice();y.forEach((c,a)=>U[c]=i[c]+G[a]);let g=Math.max(...G.map(Math.abs))/p(),T=o(U);if(!Number.isFinite(T.f))throw new Error(Rt);let E=-(Q(S,G)+Q(G,x.map(c=>Q(c,G)))/2),V=Math.abs(t-T.f)>1e-10*Math.abs(t)?t-T.f:-(Q(S,G)+Q(y.map(c=>T.g[c]),G))/2,L=E>0?V/E:V>=0?1:-1;(L>.1||g<=Ft)&&(i=U,t=T.f,e=T.g);let B=ht(G);if(L<.25?_=Math.max(B/4,Ot*p()):L>.75&&B>=.99*_&&(_*=2),!H)return k=1/0,!1;let X=y.every(c=>Math.abs(e[c])<=j())&&(g<=Ot||A&&g<=Ft&&g>=.5*k);return L>Tt&&L<1/Tt&&g<.5*k&&(u={free:y,h:x}),k=g,X},$=()=>{if(m.size===0)return!1;let y=i.map((H,U)=>U),A=zt(I(y)),x=Et*Math.max(...A.values.map(Math.abs)),z=A.values.indexOf(Math.min(...A.values));if(!(A.values[z]<-x))return!1;let D=A.vectors[z],S=y.filter((H,U)=>m.has(H)&&Math.abs(D[U])>1e-8);if(S.length===0)return!1;for(let H of S)m.delete(H),b.add(H);let G=Kt*p();return y.forEach((H,U)=>i[H]=i[H]+G*D[U]),{f:t,g:e}=o(i),!0};for(let y=0;y<Jt;y++){let A=i.map((S,G)=>G).filter(S=>!m.has(S));if(A.length>0&&!C(A))continue;let x=A.filter(S=>l[S]&&!b.has(S)&&Math.abs(i[S])<It*p());if(x.length>0){for(let S of x)i[S]=0,m.add(S);({f:t,g:e}=o(i)),k=1/0,u=void 0;continue}let z=1e-12*Math.max(1,Math.abs(t)),D=[...m].filter(S=>Math.abs(e[S])>z);if(D.length>0)for(let S of D)m.delete(S),b.add(S);else if(!$()){for(let S of te(r))if(i[S[0]]<0)for(let G of S)i[G]=-i[G];return i.map(S=>S===0?0:S)}_=Math.max(_,St*It*p()),k=1/0,u=void 0}throw new Error(Rt)}function re(r,n,s={}){return ne(r,n,s,ee)}function ne(r,n,s,l){let o=s.REML??!0,i={};s.contrasts!==void 0&&(i.contrasts=s.contrasts),s.levels!==void 0&&(i.levels=s.levels);let t=yt(r,n,i),e=oe(t,o,l),m=ut(t,e,o,{rxInverse:!0}),b=t.y.length,p=t.xColNames.length,j=2*Math.PI,_=m.logDetL+b*(1+Math.log(j*m.prss/b)),k=m.logDetL+m.logDetRX+(b-p)*(1+Math.log(j*m.prss/(b-p))),u=m.prss/(o?b-p:b),I=Math.sqrt(u),C=m.rxInverse.map(g=>g.map(T=>u*T)),$=C.map((g,T)=>Math.sqrt(g[T])),y=m.beta.map((g,T)=>g/$[T]),A=t.terms.map(g=>{let T=g.columns.length,E=Array.from({length:T},()=>new Array(T).fill(0)),V=g.thetaOffset;for(let X=0;X<T;X++)for(let c=X;c<T;c++)E[c][X]=e[V++];let L=E.map(X=>E.map(c=>u*X.reduce((a,O,h)=>a+O*c[h],0))),B=L.map((X,c)=>Math.sqrt(X[c])),K=L.map((X,c)=>X.map((a,O)=>c===O?1:a/(B[c]*B[O])));return{group:t.groups[g.group].name,columns:[...g.columns],sd:B,corr:K}}),x=t.groups.map((g,T)=>{let E=t.terms.filter(V=>V.group===T);return{group:g.name,levels:[...g.levels],columns:E.flatMap(V=>V.columns),values:g.levels.map((V,L)=>E.flatMap(B=>{let K=B.columns.length;return B.columns.map((X,c)=>m.b[B.zOffset+L*K+c])}))}}),z=t.x.map(g=>g.reduce((T,E,V)=>T+E*m.beta[V],0));t.z.forEach((g,T)=>{let E=m.b[T];E!==0&&g.rows.forEach((V,L)=>z[V]+=g.values[L]*E)});let D=t.y.map((g,T)=>g-z[T]),S=-(o?k:_)/2,G=p+e.length+1,H=e.some((g,T)=>t.lower[T]===0&&g<1e-4),U=[...t.messages];return H&&U.push("boundary (singular) fit: see help('isSingular')"),{formula:r,REML:o,nObs:b,rows:[...t.rows],theta:e,fixefNames:[...t.xColNames],fixef:m.beta,coefTable:{estimate:[...m.beta],stdError:$,tValue:y},vcov:C,sigma:I,varCorr:A,ranef:x,fitted:z,residuals:D,logLik:S,df:G,AIC:-2*S+2*G,BIC:-2*S+Math.log(b)*G,deviance:_,REMLcrit:k,singular:H,messages:U,warnings:[...t.warnings]}}export{re as lmer};
@@ -1,6 +1,10 @@
1
1
  import type { AovStrataFit, AovStratum } from "./aovStrata.js";
2
2
  import type { LmFormulaResult } from "./lm.js";
3
- /** An analysis of variance table, in the form of R's printed table. */
3
+ /**
4
+ * An analysis of variance table, in the form of R's printed table.
5
+ *
6
+ * @category Linear models and ANOVA
7
+ */
4
8
  export interface AnovaTable {
5
9
  /** R's column names, such as `"Df"`, `"Sum Sq"`, `"Mean Sq"`, `"F value"`, `"Pr(>F)"`. */
6
10
  colNames: string[];
@@ -22,7 +26,7 @@ export declare function sequentialTerms(fit: LmFormulaResult): {
22
26
  rss: number;
23
27
  };
24
28
  /**
25
- * Analysis of variance of linear models fitted from a formula. With one fit, the table of sequential (type I) sums
29
+ * Analysis of variance of linear models fitted from a formula. Equivalent to R's `anova()`. With one fit, the table of sequential (type I) sums
26
30
  * of squares, equivalent to R's `anova(fit)`: one row per term (the intercept left out), in the order of the model,
27
31
  * and `Residuals`. With several fits, the comparison of the models in the order given, equivalent to R's
28
32
  * `anova(fit1, fit2, ...)`: columns `Res.Df`, `RSS`, `Df`, `Sum of Sq`, `F`, `Pr(>F)`, the F tests scaled by the
@@ -37,21 +41,39 @@ export declare function sequentialTerms(fit: LmFormulaResult): {
37
41
  * const t = anova(lm("y ~ g", data));
38
42
  * t.rowNames; // ["g", "Residuals"]
39
43
  * ```
44
+ *
45
+ * @category Linear models and ANOVA
40
46
  */
41
47
  export declare function anova(fit: LmFormulaResult, ...fits: LmFormulaResult[]): AnovaTable;
42
- /** Result of {@link aovSummary} for a fit with error strata. */
48
+ /**
49
+ * Result of {@link aovSummary} for a fit with error strata.
50
+ *
51
+ * @category Linear models and ANOVA
52
+ */
43
53
  export interface AovStrataSummary {
44
54
  /** The table of each stratum, in order, without the intercept stratum. */
45
55
  strata: AovStratum[];
56
+ /** Warnings of the summary (empty; the fit's warnings are in its own `warnings`). */
46
57
  warnings: string[];
47
58
  }
48
59
  /**
49
- * The table of R's `summary(aov(formula, data))` for a fit without `Error()`: the rows of {@link anova}'s
60
+ * The table of an analysis of variance fitted by {@link aov}. Equivalent to R's `summary()`. As R's
61
+ * `summary(aov(formula, data))` for a fit without `Error()`: the rows of {@link anova}'s
50
62
  * sequential table, except that without residual degrees of freedom there is no `Residuals` row and no `F value` and
51
63
  * `Pr(>F)` columns. For a fit with an `Error()` term, the tables of the strata (`{ strata: [{ stratum: "Error: id",
52
64
  * colNames, rowNames, table }, ...] }`), without the intercept stratum.
53
65
  *
54
66
  * @param fit A fit from {@link aov} (or {@link lm}) with a formula.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const fit = aov("y ~ g", { y: [4.2, 5.1, 6.3, 5.8, 7.9, 8.4], g: ["a", "a", "b", "b", "c", "c"] });
71
+ * const t = aovSummary(fit);
72
+ * t.colNames; // ["Df", "Sum Sq", "Mean Sq", "F value", "Pr(>F)"]
73
+ * t.table[0]; // [2, 12.413, 6.2067, 28.427, 0.011221]
74
+ * ```
75
+ *
76
+ * @category Linear models and ANOVA
55
77
  */
56
78
  export declare function aovSummary(fit: AovStrataFit): AovStrataSummary;
57
79
  export declare function aovSummary(fit: LmFormulaResult): AnovaTable;
@@ -81,7 +81,7 @@ function comparisonTable(fits) {
81
81
  };
82
82
  }
83
83
  /**
84
- * Analysis of variance of linear models fitted from a formula. With one fit, the table of sequential (type I) sums
84
+ * Analysis of variance of linear models fitted from a formula. Equivalent to R's `anova()`. With one fit, the table of sequential (type I) sums
85
85
  * of squares, equivalent to R's `anova(fit)`: one row per term (the intercept left out), in the order of the model,
86
86
  * and `Residuals`. With several fits, the comparison of the models in the order given, equivalent to R's
87
87
  * `anova(fit1, fit2, ...)`: columns `Res.Df`, `RSS`, `Df`, `Sum of Sq`, `F`, `Pr(>F)`, the F tests scaled by the
@@ -96,6 +96,8 @@ function comparisonTable(fits) {
96
96
  * const t = anova(lm("y ~ g", data));
97
97
  * t.rowNames; // ["g", "Residuals"]
98
98
  * ```
99
+ *
100
+ * @category Linear models and ANOVA
99
101
  */
100
102
  export function anova(fit, ...fits) {
101
103
  const all = [fit, ...fits];
@@ -1,7 +1,15 @@
1
1
  import { type DataFrame } from "./modelFrame.js";
2
- /** An effect size of {@link aovEz}: generalized (`"ges"`) or partial (`"pes"`) eta squared. */
2
+ /**
3
+ * An effect size of {@link aovEz}: generalized (`"ges"`) or partial (`"pes"`) eta squared.
4
+ *
5
+ * @category Linear models and ANOVA
6
+ */
3
7
  export type AovEzEffectSize = "ges" | "pes";
4
- /** Options for {@link aovEz}. */
8
+ /**
9
+ * Options for {@link aovEz}.
10
+ *
11
+ * @category Linear models and ANOVA
12
+ */
5
13
  export interface AovEzOptions {
6
14
  /** Column of the subject identifiers. */
7
15
  id: string;
@@ -20,13 +28,24 @@ export interface AovEzOptions {
20
28
  /** Observed (not manipulated) factors, for the generalized eta squared. */
21
29
  observed?: readonly string[] | string;
22
30
  }
23
- /** A table of {@link aovEz}. */
31
+ /**
32
+ * A table of {@link aovEz}.
33
+ *
34
+ * @category Linear models and ANOVA
35
+ */
24
36
  export interface AovEzTable {
37
+ /** Column names, such as afex's `"num Df"`, `"den Df"`, `"MSE"`, `"F"`, `"ges"`, `"Pr(>F)"`. */
25
38
  colNames: string[];
39
+ /** Row names: the terms (and `"(Intercept)"` in car's tables). */
26
40
  rowNames: string[];
41
+ /** One array per row, one value per column. */
27
42
  table: number[][];
28
43
  }
29
- /** Result of {@link aovEz}. */
44
+ /**
45
+ * Result of {@link aovEz}.
46
+ *
47
+ * @category Linear models and ANOVA
48
+ */
30
49
  export interface AovEzResult {
31
50
  /** afex's anova table (without the intercept). */
32
51
  anova: AovEzTable;
@@ -38,11 +57,13 @@ export interface AovEzResult {
38
57
  sphericity?: AovEzTable;
39
58
  /** The within-subject factors (columns), as given. */
40
59
  within: string[];
60
+ /** afex's and car's warnings (averaged cells, removed subjects, `HF eps > 1 treated as 1`, ...). */
41
61
  warnings: string[];
42
62
  }
43
63
  /**
44
- * Repeated-measures (within-subjects), between-subjects and mixed analysis of variance from long data, as afex's
45
- * `aov_ez(id, dv, data, between, within, type, observed, anova_table = list(correction, es))`. Returns afex's
64
+ * Repeated-measures (within-subjects), between-subjects and mixed analysis of variance from long data. Equivalent to
65
+ * `afex::aov_ez()` in R. As afex's
66
+ * `aov_ez(id, dv, data, between, within, type, observed, anova_table = list(correction, es))`, it returns afex's
46
67
  * anova table and car's univariate tests, sphericity corrections (Greenhouse-Geisser, Huynh-Feldt) and Mauchly tests.
47
68
  *
48
69
  * Between-subjects factors use `contr.sum` and sorted levels; the levels of within-subjects factors are taken in order
@@ -60,5 +81,7 @@ export interface AovEzResult {
60
81
  * };
61
82
  * aovEz(data, { id: "id", dv: "y", within: "W" }).anova.rowNames; // ["W"]
62
83
  * ```
84
+ *
85
+ * @category Linear models and ANOVA
63
86
  */
64
87
  export declare function aovEz(data: DataFrame, options: AovEzOptions): AovEzResult;
@@ -59,8 +59,9 @@ function anovaTable(rows, errorSS, es, observed) {
59
59
  };
60
60
  }
61
61
  /**
62
- * Repeated-measures (within-subjects), between-subjects and mixed analysis of variance from long data, as afex's
63
- * `aov_ez(id, dv, data, between, within, type, observed, anova_table = list(correction, es))`. Returns afex's
62
+ * Repeated-measures (within-subjects), between-subjects and mixed analysis of variance from long data. Equivalent to
63
+ * `afex::aov_ez()` in R. As afex's
64
+ * `aov_ez(id, dv, data, between, within, type, observed, anova_table = list(correction, es))`, it returns afex's
64
65
  * anova table and car's univariate tests, sphericity corrections (Greenhouse-Geisser, Huynh-Feldt) and Mauchly tests.
65
66
  *
66
67
  * Between-subjects factors use `contr.sum` and sorted levels; the levels of within-subjects factors are taken in order
@@ -78,6 +79,8 @@ function anovaTable(rows, errorSS, es, observed) {
78
79
  * };
79
80
  * aovEz(data, { id: "id", dv: "y", within: "W" }).anova.rowNames; // ["W"]
80
81
  * ```
82
+ *
83
+ * @category Linear models and ANOVA
81
84
  */
82
85
  export function aovEz(data, options) {
83
86
  const between = list(options.between);
@@ -1,16 +1,26 @@
1
- import type { FormulaNode, ParsedFormula } from "./formula.js";
1
+ import { type FormulaNode, type ParsedFormula } from "./formula.js";
2
2
  import type { LmFormulaOptions } from "./lm.js";
3
3
  import type { DataFrame } from "./modelFrame.js";
4
- /** The table of one error stratum, as `summary(aov(...))` prints it. */
4
+ /**
5
+ * The table of one error stratum, as `summary(aov(...))` prints it.
6
+ *
7
+ * @category Linear models and ANOVA
8
+ */
5
9
  export interface AovStratum {
6
10
  /** `"Error: id"`, `"Error: id:W"`, `"Error: Within"`. */
7
11
  stratum: string;
12
+ /** R's column names: `"Df"`, `"Sum Sq"`, `"Mean Sq"`, and `"F value"`, `"Pr(>F)"` when there are residuals. */
8
13
  colNames: string[];
14
+ /** Row names: the labels of the terms in the stratum, then `"Residuals"` when its df is positive. */
9
15
  rowNames: string[];
10
16
  /** One array per row; NaN where R prints nothing. */
11
17
  table: number[][];
12
18
  }
13
- /** Result of {@link aov} with an `Error()` term. */
19
+ /**
20
+ * Result of {@link aov} with an `Error()` term.
21
+ *
22
+ * @category Linear models and ANOVA
23
+ */
14
24
  export interface AovStrataFit {
15
25
  /** The formula. */
16
26
  formula: string;
@@ -12,6 +12,7 @@ import { pf1 } from "../distributions/f.js";
12
12
  import { qr } from "../linalg/qr.js";
13
13
  import { ddAdd, ddMul } from "../special/dd.js";
14
14
  import { ddLeastSquares, ddLeastSquaresMulti, ddSumSquares } from "./ddLeastSquares.js";
15
+ import { termsOf } from "./formula.js";
15
16
  import { design } from "./modelMatrix.js";
16
17
  /** The table of a stratum: terms that have columns in it, then Residuals when its df is positive */
17
18
  function stratumTable(name, zy, zcols, assign, labels) {
@@ -65,7 +66,10 @@ export function aovStrataFit(formula, parsed, treatment, errorRhs, data, options
65
66
  if (options.weights !== undefined)
66
67
  throw new Error("weights are not supported in a multistratum aov() fit");
67
68
  // y ~ Error(id): no treatment terms, the intercept only
68
- const dt = design(parsed, data, { ...options, dropUnusedLevels: true }, treatment ?? { type: "num", value: 1, text: "1" });
69
+ const treatmentRhs = treatment ?? { type: "num", value: 1, text: "1" };
70
+ // (a contrast is for a variable of the formula without the Error() term: one only inside Error() is absent)
71
+ const contrastVariables = termsOf({ response: parsed.response, rhs: treatmentRhs }, Object.keys(data)).variables;
72
+ const dt = design(parsed, data, { ...options, dropUnusedLevels: true, contrastVariables }, treatmentRhs);
69
73
  const y = dt.y;
70
74
  if (y === undefined)
71
75
  throw new TypeError("the formula has no response");
@@ -1,13 +1,17 @@
1
1
  import type { AnovaTable } from "./anovaSequential.js";
2
2
  import type { LmFormulaResult } from "./lm.js";
3
- /** Options for {@link Anova}. */
3
+ /**
4
+ * Options for {@link Anova}.
5
+ *
6
+ * @category Linear models and ANOVA
7
+ */
4
8
  export interface AnovaOptions {
5
9
  /** The type of the tests: 2 (default, as car) or 3; `"II"` and `"III"` are accepted too. */
6
10
  type?: 2 | 3 | "II" | "III";
7
11
  }
8
12
  /**
9
- * Type II or type III tests of the terms of a linear model, equivalent to `car::Anova(fit, type = 2)` or `type = 3`
10
- * for an `lm` fit. Columns `Sum Sq`, `Df`, `F value`, `Pr(>F)`; rows the terms (type III: `(Intercept)` first when the
13
+ * Type II or type III tests of the terms of a linear model. Equivalent to `car::Anova()` in R. As
14
+ * `car::Anova(fit, type = 2)` or `type = 3` for an `lm` fit: columns `Sum Sq`, `Df`, `F value`, `Pr(>F)`; rows the terms (type III: `(Intercept)` first when the
11
15
  * model has one) and `Residuals`.
12
16
  *
13
17
  * Type II tests each term after all the others except the terms that contain it (car's marginality; it does not
@@ -26,5 +30,7 @@ export interface AnovaOptions {
26
30
  * const t = Anova(lm("y ~ A * B", data, { contrasts: { A: "contr.sum", B: "contr.sum" } }), { type: 3 });
27
31
  * t.rowNames; // ["(Intercept)", "A", "B", "A:B", "Residuals"]
28
32
  * ```
33
+ *
34
+ * @category Linear models and ANOVA
29
35
  */
30
36
  export declare function Anova(fit: LmFormulaResult, options?: AnovaOptions): AnovaTable;
@@ -38,8 +38,8 @@ function addedSS(fit, base, added) {
38
38
  return { ss: ss[0], df };
39
39
  }
40
40
  /**
41
- * Type II or type III tests of the terms of a linear model, equivalent to `car::Anova(fit, type = 2)` or `type = 3`
42
- * for an `lm` fit. Columns `Sum Sq`, `Df`, `F value`, `Pr(>F)`; rows the terms (type III: `(Intercept)` first when the
41
+ * Type II or type III tests of the terms of a linear model. Equivalent to `car::Anova()` in R. As
42
+ * `car::Anova(fit, type = 2)` or `type = 3` for an `lm` fit: columns `Sum Sq`, `Df`, `F value`, `Pr(>F)`; rows the terms (type III: `(Intercept)` first when the
43
43
  * model has one) and `Residuals`.
44
44
  *
45
45
  * Type II tests each term after all the others except the terms that contain it (car's marginality; it does not
@@ -58,6 +58,8 @@ function addedSS(fit, base, added) {
58
58
  * const t = Anova(lm("y ~ A * B", data, { contrasts: { A: "contr.sum", B: "contr.sum" } }), { type: 3 });
59
59
  * t.rowNames; // ["(Intercept)", "A", "B", "A:B", "Residuals"]
60
60
  * ```
61
+ *
62
+ * @category Linear models and ANOVA
61
63
  */
62
64
  export function Anova(fit, options = {}) {
63
65
  if (typeof fit !== "object" || fit === null || !Array.isArray(fit.effects)) {
@@ -1,5 +1,9 @@
1
1
  import type { GroupLabel } from "../htest/groups.js";
2
- /** Control of the Newton-Raphson iterations of {@link coxph} (R's `coxph.control`). */
2
+ /**
3
+ * Control of the Newton-Raphson iterations of {@link coxph} (R's `coxph.control`).
4
+ *
5
+ * @category Survival analysis
6
+ */
3
7
  export interface CoxphControl {
4
8
  /** Convergence tolerance on the relative change of the log partial likelihood. Default 1e-9. */
5
9
  eps?: number;
@@ -10,7 +14,11 @@ export interface CoxphControl {
10
14
  /** Tolerance of the check for infinite coefficients. Default sqrt(`eps`). */
11
15
  tolerInf?: number;
12
16
  }
13
- /** Options for {@link coxph}. */
17
+ /**
18
+ * Options for {@link coxph}.
19
+ *
20
+ * @category Survival analysis
21
+ */
14
22
  export interface CoxphOptions {
15
23
  /** Handling of tied event times. Default `"efron"`. */
16
24
  ties?: "efron" | "breslow";
@@ -27,13 +35,24 @@ export interface CoxphOptions {
27
35
  /** Confidence level of the intervals of exp(coef). Default 0.95. */
28
36
  confLevel?: number;
29
37
  }
30
- /** A test statistic with its degrees of freedom and upper chi-squared tail. */
38
+ /**
39
+ * A test statistic with its degrees of freedom and upper chi-squared tail.
40
+ *
41
+ * @category Survival analysis
42
+ */
31
43
  export interface CoxphTest {
44
+ /** The chi-squared statistic (R's `test`). */
32
45
  statistic: number;
46
+ /** Degrees of freedom (R's `df`). */
33
47
  df: number;
48
+ /** Upper chi-squared tail (R's `pvalue`). */
34
49
  pValue: number;
35
50
  }
36
- /** Result of {@link coxph}. */
51
+ /**
52
+ * Result of {@link coxph}.
53
+ *
54
+ * @category Survival analysis
55
+ */
37
56
  export interface CoxphResult {
38
57
  /** Coefficients (NaN for R's NA: an aliased column or one whose information fell below the tolerance) */
39
58
  coefficients: number[];
@@ -73,15 +92,18 @@ export interface CoxphResult {
73
92
  waldtest: CoxphTest;
74
93
  /** R^2 (1 - exp(-logtest / n)) and its maximum (1 - exp(2 loglik[0] / n)) */
75
94
  rsq: {
95
+ /** R^2, 1 - exp(-logtest / n) (R's `rsq`). */
76
96
  rsq: number;
97
+ /** Its maximum, 1 - exp(2 loglik[0] / n) (R's `maxrsq`). */
77
98
  maxrsq: number;
78
99
  };
79
100
  /** R's warnings, each once, in order of first appearance. */
80
101
  warnings: string[];
81
102
  }
82
103
  /**
83
- * Cox proportional hazards regression. Equivalent to R's `coxph(Surv(time, status) ~ x [+ strata(strata)], weights,
84
- * ties, init, control)` (package survival) for right-censored data, with the values of `summary(fit)`.
104
+ * Cox proportional hazards regression. Equivalent to R's `survival::coxph()`. As
105
+ * `coxph(Surv(time, status) ~ x [+ strata(strata)], weights, ties, init, control)` for right-censored data, with the
106
+ * values of `summary(fit)`.
85
107
  *
86
108
  * Rows with a missing time, status, covariate, weight or stratum are dropped. Times within sqrt(eps) of each other are
87
109
  * treated as tied. Covariates whose values all lie in `nocenter` are not centred; the others are centred by their
@@ -95,7 +117,11 @@ export interface CoxphResult {
95
117
  *
96
118
  * @example
97
119
  * ```ts
98
- * coxph([5, 3, 8, 1, 9, 4], [1, 1, 0, 1, 0, 1], [[1.2], [0.3], [-0.5], [2], [0.7], [0.1]]).coefficients;
120
+ * const fit = coxph([5, 3, 8, 1, 9, 4], [1, 1, 0, 1, 0, 1], [[1.2], [0.3], [-0.5], [2], [0.7], [0.1]]);
121
+ * fit.coefficients; // [1.0324]
122
+ * fit.logtest.pValue; // 0.18817
99
123
  * ```
124
+ *
125
+ * @category Survival analysis
100
126
  */
101
127
  export declare function coxph(time: readonly number[], status: readonly number[], x: readonly (readonly number[])[], options?: CoxphOptions): CoxphResult;
@@ -233,8 +233,9 @@ const chisqTest = (statistic, df) => ({
233
233
  pValue: pchisq(statistic, df, { lowerTail: false }),
234
234
  });
235
235
  /**
236
- * Cox proportional hazards regression. Equivalent to R's `coxph(Surv(time, status) ~ x [+ strata(strata)], weights,
237
- * ties, init, control)` (package survival) for right-censored data, with the values of `summary(fit)`.
236
+ * Cox proportional hazards regression. Equivalent to R's `survival::coxph()`. As
237
+ * `coxph(Surv(time, status) ~ x [+ strata(strata)], weights, ties, init, control)` for right-censored data, with the
238
+ * values of `summary(fit)`.
238
239
  *
239
240
  * Rows with a missing time, status, covariate, weight or stratum are dropped. Times within sqrt(eps) of each other are
240
241
  * treated as tied. Covariates whose values all lie in `nocenter` are not centred; the others are centred by their
@@ -248,8 +249,12 @@ const chisqTest = (statistic, df) => ({
248
249
  *
249
250
  * @example
250
251
  * ```ts
251
- * coxph([5, 3, 8, 1, 9, 4], [1, 1, 0, 1, 0, 1], [[1.2], [0.3], [-0.5], [2], [0.7], [0.1]]).coefficients;
252
+ * const fit = coxph([5, 3, 8, 1, 9, 4], [1, 1, 0, 1, 0, 1], [[1.2], [0.3], [-0.5], [2], [0.7], [0.1]]);
253
+ * fit.coefficients; // [1.0324]
254
+ * fit.logtest.pValue; // 0.18817
252
255
  * ```
256
+ *
257
+ * @category Survival analysis
253
258
  */
254
259
  export function coxph(time, status, x, options = {}) {
255
260
  const { ties = "efron", weights, strata, init, control = {}, nocenter = [-1, 0, 1], confLevel = 0.95 } = options;
@@ -23,6 +23,13 @@ export type FormulaNode = {
23
23
  } | {
24
24
  type: "Error";
25
25
  arg: FormulaNode;
26
+ }
27
+ /** A random-effects term `lhs | group` (`double`: `lhs || group`) */
28
+ | {
29
+ type: "bar";
30
+ double: boolean;
31
+ lhs: FormulaNode;
32
+ group: FormulaNode;
26
33
  };
27
34
  /** A parsed formula before expansion. */
28
35
  export interface ParsedFormula {
@@ -36,13 +43,26 @@ export interface ParsedFormula {
36
43
  * or uses something that is not supported (function calls other than Error(), backquoted names, ...).
37
44
  *
38
45
  * @param allowError Accept `Error(...)` terms (aov only).
46
+ * @param allowBars Accept the random-effects terms `(lhs | group)` and `(lhs || group)` (mixed models only).
39
47
  */
40
- export declare function parseFormula(formula: string, allowError?: boolean): ParsedFormula;
48
+ export declare function parseFormula(formula: string, allowError?: boolean, allowBars?: boolean): ParsedFormula;
41
49
  /** The `Error()` terms of a right-hand side (top-level summands) and the right-hand side without them. */
42
50
  export declare function splitErrorTerms(rhs: FormulaNode): {
43
51
  treatment: FormulaNode | undefined;
44
52
  errors: FormulaNode[];
45
53
  };
54
+ /** The random-effects terms of a right-hand side (summands, possibly in parentheses) and the right-hand side without them. */
55
+ export declare function splitBarTerms(rhs: FormulaNode): {
56
+ fixed: FormulaNode | undefined;
57
+ bars: Extract<FormulaNode, {
58
+ type: "bar";
59
+ }>[];
60
+ };
61
+ /**
62
+ * A formula node as R deparses it: `+`, `-`, `*` and `%in%` with a space on each side, `:`, `/` and `^` without,
63
+ * unary minus and plus without a space, parentheses as written.
64
+ */
65
+ export declare function deparseFormula(n: FormulaNode): string;
46
66
  /** Terms of a model: the variables of each term as indices into `variables`, in increasing order. */
47
67
  export interface Terms {
48
68
  /** The variable names: the response first (if any), then in order of first appearance in the formula. */
@@ -64,6 +84,11 @@ export interface Terms {
64
84
  /** Warnings of the expansion. */
65
85
  warnings: string[];
66
86
  }
87
+ /**
88
+ * The variable names of a right-hand side, in order of first appearance (`.` stands for `dot`), whatever its
89
+ * operators: R's variables of the model frame (aggregate's grouping variables).
90
+ */
91
+ export declare function formulaVariables(rhs: FormulaNode, dot: readonly string[]): string[];
67
92
  /**
68
93
  * Expands a right-hand side into terms (variable indices, increasing) and the intercept flag.
69
94
  *