@numero-uno-jpn/rstats 1.18.0 → 1.20.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 (139) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.ja.md +7 -7
  3. package/README.md +7 -7
  4. package/dist/causal.js +2 -2
  5. package/dist/chunks/chunk-33ODAPMR.js +2 -0
  6. package/dist/chunks/chunk-3ST6RZXG.js +2 -0
  7. package/dist/chunks/{chunk-JF4PXFJE.js → chunk-4EQN74JN.js} +2 -2
  8. package/dist/chunks/chunk-5RRFO4NU.js +2 -0
  9. package/dist/chunks/{chunk-3JFRDXN7.js → chunk-64DDDGJU.js} +2 -2
  10. package/dist/chunks/chunk-66TEOHPF.js +2 -0
  11. package/dist/chunks/chunk-6ISDROPG.js +2 -0
  12. package/dist/chunks/{chunk-EC77KAAM.js → chunk-6LAKI2QG.js} +2 -2
  13. package/dist/chunks/{chunk-5CTWYFMB.js → chunk-6QCH4LAL.js} +2 -2
  14. package/dist/chunks/{chunk-H6Z7JVSD.js → chunk-6RA73LXX.js} +2 -2
  15. package/dist/chunks/{chunk-KJMLQHCY.js → chunk-7C2ECGT6.js} +1 -1
  16. package/dist/chunks/{chunk-SCFFHEDZ.js → chunk-7KPFNJBE.js} +2 -2
  17. package/dist/chunks/chunk-ARPXG2PG.js +2 -0
  18. package/dist/chunks/chunk-AWXW4WSX.js +2 -0
  19. package/dist/chunks/{chunk-XQCHC3SH.js → chunk-B5GSH3AK.js} +1 -1
  20. package/dist/chunks/{chunk-2JB7F646.js → chunk-BLDLJHUG.js} +2 -2
  21. package/dist/chunks/{chunk-IKMW63BE.js → chunk-BU4I544S.js} +2 -2
  22. package/dist/chunks/{chunk-LCIX76FR.js → chunk-CAUNJ7S6.js} +2 -2
  23. package/dist/chunks/chunk-DFGW4QWU.js +2 -0
  24. package/dist/chunks/{chunk-WYVUCQO3.js → chunk-DPCCSFCG.js} +1 -1
  25. package/dist/chunks/chunk-EXS5QD7V.js +2 -0
  26. package/dist/chunks/chunk-FOCHNNP3.js +2 -0
  27. package/dist/chunks/{chunk-MXZ64QME.js → chunk-HEPGGURG.js} +2 -2
  28. package/dist/chunks/chunk-INNFAVT3.js +2 -0
  29. package/dist/chunks/chunk-JEELIABM.js +2 -0
  30. package/dist/chunks/chunk-KNF2GPJV.js +2 -0
  31. package/dist/chunks/chunk-L4ZS7MAX.js +2 -0
  32. package/dist/chunks/{chunk-RXYZQ3UX.js → chunk-LZAB4M7P.js} +2 -2
  33. package/dist/chunks/chunk-LZTDYQRS.js +3 -0
  34. package/dist/chunks/{chunk-N7BUE54L.js → chunk-MTSU2QHB.js} +2 -2
  35. package/dist/chunks/{chunk-GIK34P23.js → chunk-MXRN2G7O.js} +2 -2
  36. package/dist/chunks/chunk-OFDD4GTZ.js +2 -0
  37. package/dist/chunks/chunk-OOHFFLMY.js +2 -0
  38. package/dist/chunks/chunk-OOO5AAM7.js +2 -0
  39. package/dist/chunks/chunk-PJJJR3H6.js +2 -0
  40. package/dist/chunks/chunk-PVRNAOO7.js +2 -0
  41. package/dist/chunks/chunk-Q2JLU5YD.js +2 -0
  42. package/dist/chunks/{chunk-Z33Q545U.js → chunk-QCQBK5AC.js} +2 -2
  43. package/dist/chunks/chunk-RXK4KSKH.js +2 -0
  44. package/dist/chunks/chunk-UC3YYJHM.js +4 -0
  45. package/dist/chunks/chunk-UPACHZ4F.js +2 -0
  46. package/dist/chunks/{chunk-VATAUY7N.js → chunk-VCXPGCA4.js} +2 -2
  47. package/dist/chunks/chunk-VFL4GGYT.js +2 -0
  48. package/dist/chunks/chunk-VL72MQOQ.js +2 -0
  49. package/dist/chunks/chunk-VSV5QGXX.js +2 -0
  50. package/dist/chunks/{chunk-CTZUYKVL.js → chunk-WMEF5XWO.js} +2 -2
  51. package/dist/chunks/chunk-X6JS6ZZB.js +2 -0
  52. package/dist/chunks/chunk-YEDVOX5V.js +2 -0
  53. package/dist/chunks/chunk-ZCTB4N5J.js +3 -0
  54. package/dist/descriptive.js +2 -2
  55. package/dist/distributions/normal.d.ts +4 -0
  56. package/dist/distributions/normal.js +4 -2
  57. package/dist/distributions.js +2 -2
  58. package/dist/entries/tests.d.ts +6 -0
  59. package/dist/entries/tests.js +6 -0
  60. package/dist/entries/timeseries.d.ts +11 -0
  61. package/dist/entries/timeseries.js +11 -0
  62. package/dist/htest/timeROC.d.ts +564 -0
  63. package/dist/htest/timeROC.js +1106 -0
  64. package/dist/linalg.js +2 -2
  65. package/dist/meta/metabin.d.ts +32 -0
  66. package/dist/meta/metabin.js +137 -0
  67. package/dist/meta/metaextra.d.ts +153 -0
  68. package/dist/meta/metaextra.js +290 -0
  69. package/dist/meta/metagen.d.ts +124 -0
  70. package/dist/meta/metagen.js +263 -0
  71. package/dist/meta/metaother.d.ts +87 -0
  72. package/dist/meta/metaother.js +342 -0
  73. package/dist/meta/netmeta.d.ts +256 -0
  74. package/dist/meta/netmeta.js +547 -0
  75. package/dist/mixed.js +3 -4
  76. package/dist/models/glmFamily.js +4 -1
  77. package/dist/models/metaAnalysis.d.ts +4 -0
  78. package/dist/models/metaAnalysis.js +100 -18
  79. package/dist/multivariate.js +2 -2
  80. package/dist/numerics.js +2 -2
  81. package/dist/regression.js +2 -2
  82. package/dist/rstats.js +20 -18
  83. package/dist/special.js +2 -2
  84. package/dist/tests.js +15 -15
  85. package/dist/timeseries/acf.js +5 -2
  86. package/dist/timeseries/arima.d.ts +154 -0
  87. package/dist/timeseries/arima.js +1007 -0
  88. package/dist/timeseries/autoArima.d.ts +70 -0
  89. package/dist/timeseries/autoArima.js +191 -0
  90. package/dist/timeseries/ets.d.ts +158 -0
  91. package/dist/timeseries/ets.js +883 -0
  92. package/dist/timeseries/forecastArima.d.ts +136 -0
  93. package/dist/timeseries/forecastArima.js +432 -0
  94. package/dist/timeseries/forecastDispatch.d.ts +83 -0
  95. package/dist/timeseries/forecastDispatch.js +130 -0
  96. package/dist/timeseries/forecastSimple.d.ts +177 -0
  97. package/dist/timeseries/forecastSimple.js +371 -0
  98. package/dist/timeseries/forecastUtils.d.ts +260 -0
  99. package/dist/timeseries/forecastUtils.js +619 -0
  100. package/dist/timeseries/holtWinters.d.ts +65 -0
  101. package/dist/timeseries/holtWinters.js +193 -0
  102. package/dist/timeseries/input.d.ts +8 -0
  103. package/dist/timeseries/input.js +27 -0
  104. package/dist/timeseries/ocsbCritical.d.ts +2 -0
  105. package/dist/timeseries/ocsbCritical.js +6 -0
  106. package/dist/timeseries/scale.d.ts +16 -0
  107. package/dist/timeseries/scale.js +48 -0
  108. package/dist/timeseries/statsTs.d.ts +128 -0
  109. package/dist/timeseries/statsTs.js +456 -0
  110. package/dist/timeseries/stl.d.ts +131 -0
  111. package/dist/timeseries/stl.js +489 -0
  112. package/dist/timeseries/tseries.d.ts +110 -0
  113. package/dist/timeseries/tseries.js +369 -0
  114. package/dist/timeseries.js +2 -2
  115. package/package.json +1 -1
  116. package/dist/chunks/chunk-53WQDB3C.js +0 -2
  117. package/dist/chunks/chunk-6I23C2YJ.js +0 -2
  118. package/dist/chunks/chunk-FLFNMSHI.js +0 -3
  119. package/dist/chunks/chunk-GEHMND3C.js +0 -2
  120. package/dist/chunks/chunk-HG4LJBNV.js +0 -2
  121. package/dist/chunks/chunk-HGAEVPVS.js +0 -2
  122. package/dist/chunks/chunk-HMLYEFQN.js +0 -2
  123. package/dist/chunks/chunk-HRRCC2BD.js +0 -2
  124. package/dist/chunks/chunk-IBHMM2SL.js +0 -2
  125. package/dist/chunks/chunk-ICDW3I2F.js +0 -2
  126. package/dist/chunks/chunk-IOJVFYHW.js +0 -2
  127. package/dist/chunks/chunk-IW4S634O.js +0 -2
  128. package/dist/chunks/chunk-JPWYGTUN.js +0 -2
  129. package/dist/chunks/chunk-KVJBCT3D.js +0 -2
  130. package/dist/chunks/chunk-LY5XGFPU.js +0 -2
  131. package/dist/chunks/chunk-MKZH65DK.js +0 -2
  132. package/dist/chunks/chunk-MVPHISOV.js +0 -2
  133. package/dist/chunks/chunk-NDZVVNBB.js +0 -2
  134. package/dist/chunks/chunk-NOTJ45G3.js +0 -4
  135. package/dist/chunks/chunk-QUD3374N.js +0 -2
  136. package/dist/chunks/chunk-V6FMGGUV.js +0 -2
  137. package/dist/chunks/chunk-W5M3R4NH.js +0 -2
  138. package/dist/chunks/chunk-XUMVTGMM.js +0 -2
  139. package/dist/chunks/chunk-YXMHWS5R.js +0 -2
package/dist/linalg.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! rStats.js 1.18.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 qt,b as vt,c as Nt,d as kt,e as L,f as Et,g as St,h as Ft,i as Pt,j as It,k as Rt,l as Ot,m as Tt,n as At,o as jt,p as _t,q as Ht}from"./chunks/chunk-NDZVVNBB.js";import{g as U}from"./chunks/chunk-V6FMGGUV.js";import"./chunks/chunk-SCFFHEDZ.js";import"./chunks/chunk-QUD3374N.js";import{a as Lt,b as Ut}from"./chunks/chunk-XUMVTGMM.js";import"./chunks/chunk-CTZUYKVL.js";import{a as pt,b as I,c as Y,d as H,e as Mt,f as gt,g as wt}from"./chunks/chunk-JPWYGTUN.js";import{a as at,b as st,c as ct,d as it,e as lt,f as ft,g as mt,h as ut,i as ht,j as dt,k as P,n as j,o as bt,q as G,r as J}from"./chunks/chunk-IBHMM2SL.js";import{a as yt,c as xt}from"./chunks/chunk-IKMW63BE.js";import{d as k,f as F,h as v,j as A,l as K}from"./chunks/chunk-MXZ64QME.js";import"./chunks/chunk-XQCHC3SH.js";import{a as B}from"./chunks/chunk-KJMLQHCY.js";import{h as q}from"./chunks/chunk-HG4LJBNV.js";import{l as T}from"./chunks/chunk-MVPHISOV.js";function Ct(e){let n=F(e);A(n);let t=n.nrow;if(t===0)throw new RangeError("the matrix has zero dimension");for(let r of n.data)if(!Number.isFinite(r))throw new RangeError("the matrix contains NaN or infinite values");let a=K(n.data),u={nrow:t,ncol:t,data:a===0?n.data.slice():n.data.map(r=>q(r,-a))},l=k(t,t),m=new Float64Array(t),h=new Float64Array(t);G(u,l),J(u,l,m,h,!0);let d=u.data,s=l.data,o=(r,c)=>r+c*t,M=new Uint8Array(t);for(let r=0;r+1<t;r++)h[r]>0&&h[r+1]<0&&(M[r++]=1);for(let r=0;r<t;r++)for(let c=r+1;c<t;c++)c===r+1&&M[r]||(d[o(c,r)]=0);let f=new Array(t),p=new Array(t);for(let r=0;r<t;r++){if(!M[r]){f[r]=d[o(r,r)],p[r]=0;continue}let c=Qt(d[o(r,r)],d[o(r,r+1)],d[o(r+1,r)],d[o(r+1,r+1)]);d[o(r,r)]=c.a,d[o(r,r+1)]=c.b,d[o(r+1,r)]=c.c,d[o(r+1,r+1)]=c.d;let{cs:y,sn:w}=c;for(let g=r+2;g<t;g++){let x=d[o(r,g)],b=d[o(r+1,g)];d[o(r,g)]=y*x+w*b,d[o(r+1,g)]=y*b-w*x}for(let g=0;g<r;g++){let x=d[o(g,r)],b=d[o(g,r+1)];d[o(g,r)]=y*x+w*b,d[o(g,r+1)]=y*b-w*x}for(let g=0;g<t;g++){let x=s[o(g,r)],b=s[o(g,r+1)];s[o(g,r)]=y*x+w*b,s[o(g,r+1)]=y*b-w*x}f[r]=c.rt1r,p[r]=c.rt1i,f[r+1]=c.rt2r,p[r+1]=c.rt2i,r++}if(a===0)return{T:v(u),Q:v(l),valuesRe:f,valuesIm:p};let i=r=>q(r,a);return{T:v(u).map(r=>r.map(i)),Q:v(l),valuesRe:f.map(i),valuesIm:p.map(i)}}var E=(e,n)=>n>=0&&!Object.is(n,-0)?Math.abs(e):-Math.abs(e);function Qt(e,n,t,a){let u=22250738585072014e-324,l=Number.EPSILON,m=4,h=2**Math.trunc(Math.log(u/l)/Math.log(2)/2),d=1/h,s,o;if(t===0)s=1,o=0;else if(n===0){s=0,o=1;let f=a;a=e,e=f,n=-t,t=0}else if(e-a===0&&E(1,n)!==E(1,t))s=1,o=0;else{let f=e-a,p=.5*f,i=Math.max(Math.abs(n),Math.abs(t)),r=Math.min(Math.abs(n),Math.abs(t))*E(1,n)*E(1,t),c=Math.max(Math.abs(p),i),y=p/c*p+i/c*r;if(y>=m*l){y=p+E(Math.sqrt(c)*Math.sqrt(y),p),e=a+y,a=a-i/y*r;let w=Math.hypot(t,y);s=y/w,o=t/w,n=n-t,t=0}else{let w=0,g=n+t;for(;w++,c=Math.max(Math.abs(f),Math.abs(g)),!(!(c>=d&&(g*=h,f*=h,w<=20))&&!(c<=h&&(g*=d,f*=d,w<=20))););p=.5*f;let x=Math.hypot(g,f);s=Math.sqrt(.5*(1+Math.abs(g)/x)),o=-(p/(x*s))*E(1,g);let b=e*s+n*o,S=-e*o+n*s,Q=t*s+a*o,X=-t*o+a*s;if(e=b*s+Q*o,n=S*s+X*o,t=-b*o+Q*s,a=-S*o+X*s,f=.5*(e+a),e=f,a=f,t!==0)if(n!==0){if(E(1,n)===E(1,t)){let $=Math.sqrt(Math.abs(n)),z=Math.sqrt(Math.abs(t));p=E($*z,t),x=1/Math.sqrt(Math.abs(n+t)),e=f+p,a=f-p,n=n-t,t=0;let D=$*x,V=z*x;f=s*D-o*V,o=s*V+o*D,s=f}}else n=-t,t=0,f=s,s=-o,o=f}}let M=t===0?0:Math.sqrt(Math.abs(n))*Math.sqrt(Math.abs(t));return{a:e,b:n,c:t,d:a,cs:s,sn:o,rt1r:e,rt1i:M,rt2r:a,rt2i:-M}}var Xt=["method","order"],$t=["Higham08.b","Higham08","Pade","Taylor","PadeO","TaylorO"];function zt(e,n={}){T(n,Xt,"expm");let t=n.method??"Higham08.b";if(!$t.includes(t))throw new RangeError(`unknown method: ${String(t)}`);let a=n.order??8,u=t==="Pade"||t==="PadeO"||t==="Taylor"||t==="TaylorO";if(u&&!(Number.isInteger(a)&&a>=1&&a<=2147483647))throw new RangeError("order must be a positive integer at most 2147483647");let l=F(e);A(l);let m=l.nrow;if(m===0)return[];if(m===1)return[[Math.exp(l.data[0])]];if(u&&a*(m**3+64)>2**31)throw new RangeError(`order = ${a} is too large for a ${m} x ${m} matrix: order * (n^3 + 64) must be at most 2^31`);for(let f of l.data)if(!Number.isFinite(f))throw new RangeError("the matrix contains NaN or infinite values");if(t==="Taylor"||t==="TaylorO")return v(Gt(l,a));if(t==="Pade"||t==="PadeO")return v(Jt(l,a));let h,d;t==="Higham08.b"?(h=j("P",l),d=j("S",l)):Kt(l)&&(d=j("S",l));let s=Yt(l),o=s.data,M=(f,p)=>f+p*m;if(d){let f=d.scale;for(let p=0;p<m;p++)for(let i=0;i<m;i++)o[M(i,p)]=o[M(i,p)]*f[i]/f[p]}if(h){let f=h.scale,p=i=>{let r=f[i];if(r!==i){for(let c=0;c<m;c++)[o[M(c,i)],o[M(c,r)]]=[o[M(c,r)],o[M(c,i)]];for(let c=0;c<m;c++)[o[M(i,c)],o[M(r,c)]]=[o[M(r,c)],o[M(i,c)]]}};for(let i=h.ilo-1;i>=0;i--)p(i);for(let i=h.ihi+1;i<m;i++)p(i)}return v(s)}var Dt={3:[120,60,12,1],5:[30240,15120,3360,420,30,1],7:[17297280,8648640,1995840,277200,25200,1512,56,1],9:[17643225600,8821612800,2075673600,302702400,30270240,2162160,110880,3960,90,1]},Vt=[6476475253248e4,3238237626624e4,7771770303897600,0x437e459424400,129060195264e3,0x99a917d4d00,670442572800,33522128640,1323241920,40840800,960960,16380,182,1];function Bt(e,n){if(n<1/0)return Math.log2(n);let t=0;for(let u of e.data)t=Math.max(t,Math.abs(u));let a=Math.floor(Math.log2(t));return Math.log2(I({...e,data:e.data.map(u=>q(u,-a))}))+a}function Z(e,n){return Math.max(0,Math.ceil(Bt(e,n)-Math.log2(5.4)))}function Kt(e){let n=I(e);if(n<=2.1)return!1;let t=Z(e,n);return t>0&&e.data.some(a=>a!==0&&Math.abs(q(a,-t))<2**-1022)}function Yt(e){let n=e.nrow,t=I(e),a=C(n),u,l,m=0;if(t<=2.1){let o=t<=.015?3:t<=.25?5:t<=.95?7:9,M=Dt[o],f=N(e,e),p=_([[M[1],a]]),i=_([[M[0],a]]),r=f;for(let c=1;c<=(o-1)/2;c++)c>1&&(r=N(r,f)),R(p,M[2*c+1],r),R(i,M[2*c],r);u=N(e,p),l=i}else{m=Z(e,t);let o={...e,data:e.data.map(w=>q(w,-m))},M=N(o,o),f=N(M,M),p=N(M,f),i=Vt,r=_([[i[13],p],[i[11],f],[i[9],M]]),c=N(p,r);for(let[w,g]of[[7,p],[5,f],[3,M],[1,a]])R(c,i[w],g);u=N(o,c);let y=_([[i[12],p],[i[10],f],[i[8],M]]);l=N(p,y);for(let[w,g]of[[6,p],[4,f],[2,M],[0,a]])R(l,i[w],g)}let h=k(n,n),d=k(n,n);for(let o=0;o<n*n;o++)h.data[o]=l.data[o]-u.data[o],d.data[o]=l.data[o]+u.data[o];let s=F(H(v(h),v(d)));for(let o=0;o<m;o++)s=et(s,s);return s}function tt(e){let n=I(e),t=Y(e),a=n*t<1/0?Math.sqrt(n*t):Math.sqrt(n)*Math.sqrt(t),u=1;for(;2**u<a;)u++;let l=u+4;if(!e.data.some(h=>h!==0&&Math.abs(q(h,-l))<2**-1022))return l;if(a===0||n*t<2**-1e3)return Math.max(0,Math.ceil((Math.log2(n)+Math.log2(t))/2)+4);let m=u;for(;m>-4&&2**(m-1)>=a;)m--;return Math.max(0,m+4)}function nt(e,n){let t=Math.max(0,n-1e3);return{A:t===0?e:O(e,2**-t),N:2**(n-t)}}function ot(e,n){for(let t=0;t<n;t++)e=et(e,e);return e}function rt(e){let n=e.nrow;for(let t=0;t<n;t++)e.data[t+t*n]=e.data[t+t*n]+1}function Gt(e,n){let t=tt(e),{A:a,N:u}=nt(e,t),l=C(e.nrow);for(let m=n;m>=1;m--)l=O(N(l,a),1/(m*u)),rt(l);return ot(l,t)}function W(e,n,t,a){let u=a===1?e:O(e,-1),l=C(e.nrow);for(let m=n;m>=1;m--){let h=(n-m+1)/(m*(2*n-m+1)*t);l=O(N(l,u),h),rt(l)}return l}function Jt(e,n){let t=e.nrow,a=tt(e),{A:u,N:l}=nt(e,a),m=W(u,n,l,1),h=W(u,n,l,-1),d=k(t,t);for(let s=0;s<t;s++)d.data.set(Wt(h,m.data.subarray(s*t,(s+1)*t)),s*t);return ot(d,a)}function Wt(e,n){let t=e.nrow,a=1e-100,u=i=>{let r=new Float64Array(t);for(let c=0;c<t;c++){let y=0;for(let w=0;w<t;w++)y+=e.data[c+w*t]*i[w];r[c]=y}return r},l=(i,r)=>{let c=0;for(let y=0;y<t;y++)c+=i[y]*r[y];return c},m=(i,r,c)=>{let y=new Float64Array(t);for(let w=0;w<t;w++)y[w]=i[w]+r*c[w];return y},h=new Float64Array(t),d=Float64Array.from(n),s=Float64Array.from(n),o=Float64Array.from(n),M=Float64Array.from(n),f=Math.sqrt(l(d,d)),p=l(M,n);if(Math.abs(p)<=a)return h;for(let i=0;i<t;i++){let r=u(s),c=l(M,r);if(Math.abs(c)<=a)return h;let y=p/c;if(Math.abs(y)<=a)return h;let w=m(o,-y,r);r=m(o,1,w);let g=u(r);d=m(d,-y,g);let x=Math.sqrt(l(d,d));if(h=m(h,y,r),Math.abs(x/f)<=1e-30)return h;let b=l(M,d);if(Math.abs(b)<=a)return h;let S=b/p;p=b,o=m(d,S,w),g=m(w,S,s),s=m(o,S,g)}return h}function C(e){let n=k(e,e);for(let t=0;t<e;t++)n.data[t+t*e]=1;return n}function et(e,n){let t=e.nrow,a=e.ncol,u=n.ncol,l=k(t,u);for(let m=0;m<u;m++)for(let h=0;h<t;h++){let d=0;for(let s=0;s<a;s++){let o=e.data[h+s*t],M=n.data[s+m*a];o===0&&Math.abs(M)===1/0||M===0&&Math.abs(o)===1/0||(d+=o*M)}l.data[h+m*t]=d}return l}function N(e,n){let t=e.nrow,a=e.ncol,u=n.ncol,l=k(t,u);for(let m=0;m<u;m++)for(let h=0;h<t;h++){let d=0;for(let s=0;s<a;s++)d+=e.data[h+s*t]*n.data[s+m*a];l.data[h+m*t]=d}return l}function O(e,n){return{nrow:e.nrow,ncol:e.ncol,data:e.data.map(t=>t*n)}}function R(e,n,t){for(let a=0;a<e.data.length;a++)e.data[a]=e.data[a]+n*t.data[a]}function _(e){let[n,t]=e[0],a=O(t,n);for(let u=1;u<e.length;u++)R(a,e[u][0],e[u][1]);return a}var Zt=["center","scale","rank","tol"],tn=22250738585072014e-324;function nn(e){let n=e.length,t=n===0?0:e[0].length,a=e.map(s=>{if(s.length!==t)throw new TypeError("all rows of the matrix must have the same length");if(!s.every(Number.isFinite))throw new RangeError("the matrix contains NaN or infinite values");return Array.from(s)}),u=Array.from({length:n},(s,o)=>o),l=Math.min(n,t);for(let s=0;s<l;s++){let o=s,M=Math.abs(a[s][s]);for(let i=s+1;i<n;i++){let r=Math.abs(a[i][s]);(r>M||Number.isNaN(M))&&(M=r,o=i)}o!==s&&([a[o],a[s]]=[a[s],a[o]],[u[o],u[s]]=[u[s],u[o]]);let f=a[s][s];if(f===0)continue;let p=Math.abs(f)>=tn?1/f:NaN;for(let i=s+1;i<n;i++){let r=Number.isNaN(p)?a[i][s]/f:a[i][s]*p;a[i][s]=r;for(let c=s+1;c<t;c++)a[i][c]=a[i][c]-r*a[s][c]}}let m=Array.from({length:n},(s,o)=>Array.from({length:l},(M,f)=>o===f?1:o>f?a[o][f]:0)),h=Array.from({length:l},(s,o)=>Array.from({length:t},(M,f)=>f>=o?a[o][f]:0)),d=Array.from({length:n},()=>new Array(n).fill(0));return u.forEach((s,o)=>d[s][o]=1),{P:d,L:m,U:h}}function on(e,n={}){T(n,Zt,"prcomp");let{rank:t,tol:a}=n;if(t!==void 0){if(!Number.isFinite(t))throw new RangeError("is.finite(rank.) is not TRUE");if(!(Math.trunc(t)>0&&Math.abs(t)<2**31))throw new RangeError("as.integer(rank.) > 0 is not TRUE")}let u=e.map(c=>Array.from(c)),l=n.center??!0,m=n.scale??!1,h=U(u,{center:l,scale:m});if(h.scale?.some(c=>c===0))throw new RangeError("cannot rescale a constant/zero column to unit variance");let d=u.length,s=c=>c.every(y=>y.every(Number.isFinite)),o=s(u)&&s(h.scaled)?P(h.scaled,{nu:0}):void 0,M=0;if(s(u)&&(o===void 0||o.d.some(c=>c===1/0))){let c=Math.floor(Math.log2(B(u.flat().map(Math.abs)))),y=g=>typeof g=="boolean"?g:g.map(x=>q(x,-c)),w=U(u.map(g=>g.map(x=>q(x,-c))),{center:y(l),scale:y(m)});o=P(w.scaled,{nu:0}),m===!1&&(M=c),h={scaled:w.scaled},w.center!==void 0&&(h.center=w.center.map(g=>q(g,c))),w.scale!==void 0&&(h.scale=w.scale.map(g=>q(g,c)))}o??=P(h.scaled,{nu:0});let f=o.d.map(c=>q(c/Math.sqrt(Math.max(1,d-1)),M)),p=t===void 0?f.length:Math.min(Math.trunc(t),f.length);if(Number.isNaN(a))throw new RangeError("'tol' must not be NaN");a!==void 0&&(p=Math.min(p,f.filter(c=>c>f[0]*a).length));let i=o.v.map(c=>c.slice(0,p)),r={sdev:f,rotation:i,x:L(h.scaled,o.v).map(c=>c.slice(0,p).map(y=>q(y,M)))};return h.center!==void 0&&(r.center=h.center),h.scale!==void 0&&(r.scale=h.scale),r}export{Et as add,Nt as backsolve,Tt as cbind,yt as chol,xt as chol2inv,qt as crossprod,gt as det,Mt as determinant,Ot as diag,Pt as divide,bt as eigen,zt as expm,kt as forwardsolve,Ut as ginv,Lt as kappa,_t as kronecker,nn as lu,L as matMul,jt as matrix,Ft as multiply,pt as norm,It as outer,on as prcomp,at as qr,it as qrCoef,ft as qrFitted,mt as qrQ,st as qrQty,ct as qrQy,ut as qrR,lt as qrResid,dt as qrSolve,ht as qrX,At as rbind,wt as rcond,Ct as schur,Ht as seq,H as solve,St as subtract,P as svd,Rt as t,vt as tcrossprod};
1
+ /*! rStats.js 1.20.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 Xt,b as $t}from"./chunks/chunk-X6JS6ZZB.js";import{a as qt,b as wt,c as yt,d as bt}from"./chunks/chunk-L4ZS7MAX.js";import{a as vt,b as kt,c as St,d as Nt,e as Et,f as It,g as Pt,h as Ft,i as Ot,j as Tt,k as jt,l as Rt,m as Ht}from"./chunks/chunk-33ODAPMR.js";import"./chunks/chunk-Q2JLU5YD.js";import"./chunks/chunk-7KPFNJBE.js";import"./chunks/chunk-3ST6RZXG.js";import{a as Lt,b as Qt}from"./chunks/chunk-EXS5QD7V.js";import"./chunks/chunk-WMEF5XWO.js";import{a as mt,b as P,c as B,d as H,e as ht,f as dt,g as Mt}from"./chunks/chunk-OOO5AAM7.js";import{a as ot,b as rt,c as nt,d as at,e as et,f as st,g as ct,h as it,i as lt,j as ft,k as ut,n as j,o as gt,q as _,r as G}from"./chunks/chunk-DFGW4QWU.js";import{a as pt,c as xt}from"./chunks/chunk-BU4I544S.js";import{d as k,f as I,h as b,j as T,l as z}from"./chunks/chunk-HEPGGURG.js";import"./chunks/chunk-B5GSH3AK.js";import"./chunks/chunk-7C2ECGT6.js";import{l as V,u as N}from"./chunks/chunk-ARPXG2PG.js";function Ct(o){let r=I(o);T(r);let t=r.nrow;if(t===0)throw new RangeError("the matrix has zero dimension");for(let n of r.data)if(!Number.isFinite(n))throw new RangeError("the matrix contains NaN or infinite values");let e=z(r.data),m={nrow:t,ncol:t,data:e===0?r.data.slice():r.data.map(n=>N(n,-e))},c=k(t,t),i=new Float64Array(t),h=new Float64Array(t);_(m,c),G(m,c,i,h,!0);let u=m.data,l=c.data,a=(n,s)=>n+s*t,p=new Uint8Array(t);for(let n=0;n+1<t;n++)h[n]>0&&h[n+1]<0&&(p[n++]=1);for(let n=0;n<t;n++)for(let s=n+1;s<t;s++)s===n+1&&p[n]||(u[a(s,n)]=0);let d=new Array(t),M=new Array(t);for(let n=0;n<t;n++){if(!p[n]){d[n]=u[a(n,n)],M[n]=0;continue}let s=Dt(u[a(n,n)],u[a(n,n+1)],u[a(n+1,n)],u[a(n+1,n+1)]);u[a(n,n)]=s.a,u[a(n,n+1)]=s.b,u[a(n+1,n)]=s.c,u[a(n+1,n+1)]=s.d;let{cs:q,sn:g}=s;for(let x=n+2;x<t;x++){let w=u[a(n,x)],y=u[a(n+1,x)];u[a(n,x)]=q*w+g*y,u[a(n+1,x)]=q*y-g*w}for(let x=0;x<n;x++){let w=u[a(x,n)],y=u[a(x,n+1)];u[a(x,n)]=q*w+g*y,u[a(x,n+1)]=q*y-g*w}for(let x=0;x<t;x++){let w=l[a(x,n)],y=l[a(x,n+1)];l[a(x,n)]=q*w+g*y,l[a(x,n+1)]=q*y-g*w}d[n]=s.rt1r,M[n]=s.rt1i,d[n+1]=s.rt2r,M[n+1]=s.rt2i,n++}if(e===0)return{T:b(m),Q:b(c),valuesRe:d,valuesIm:M};let f=n=>N(n,e);return{T:b(m).map(n=>n.map(f)),Q:b(c),valuesRe:d.map(f),valuesIm:M.map(f)}}var S=(o,r)=>r>=0&&!Object.is(r,-0)?Math.abs(o):-Math.abs(o);function Dt(o,r,t,e){let m=22250738585072014e-324,c=Number.EPSILON,i=4,h=2**Math.trunc(Math.log(m/c)/Math.log(2)/2),u=1/h,l,a;if(t===0)l=1,a=0;else if(r===0){l=0,a=1;let d=e;e=o,o=d,r=-t,t=0}else if(o-e===0&&S(1,r)!==S(1,t))l=1,a=0;else{let d=o-e,M=.5*d,f=Math.max(Math.abs(r),Math.abs(t)),n=Math.min(Math.abs(r),Math.abs(t))*S(1,r)*S(1,t),s=Math.max(Math.abs(M),f),q=M/s*M+f/s*n;if(q>=i*c){q=M+S(Math.sqrt(s)*Math.sqrt(q),M),o=e+q,e=e-f/q*n;let g=Math.hypot(t,q);l=q/g,a=t/g,r=r-t,t=0}else{let g=0,x=r+t;for(;g++,s=Math.max(Math.abs(d),Math.abs(x)),!(!(s>=u&&(x*=h,d*=h,g<=20))&&!(s<=h&&(x*=u,d*=u,g<=20))););M=.5*d;let w=Math.hypot(x,d);l=Math.sqrt(.5*(1+Math.abs(x)/w)),a=-(M/(w*l))*S(1,x);let y=o*l+r*a,E=-o*a+r*l,Q=t*l+e*a,X=-t*a+e*l;if(o=y*l+Q*a,r=E*l+X*a,t=-y*a+Q*l,e=-E*a+X*l,d=.5*(o+e),o=d,e=d,t!==0)if(r!==0){if(S(1,r)===S(1,t)){let $=Math.sqrt(Math.abs(r)),C=Math.sqrt(Math.abs(t));M=S($*C,t),w=1/Math.sqrt(Math.abs(r+t)),o=d+M,e=d-M,r=r-t,t=0;let D=$*w,U=C*w;d=l*D-a*U,a=l*U+a*D,l=d}}else r=-t,t=0,d=l,l=-a,a=d}}let p=t===0?0:Math.sqrt(Math.abs(r))*Math.sqrt(Math.abs(t));return{a:o,b:r,c:t,d:e,cs:l,sn:a,rt1r:o,rt1i:p,rt2r:e,rt2i:-p}}var Ut=["method","order"],Vt=["Higham08.b","Higham08","Pade","Taylor","PadeO","TaylorO"];function zt(o,r={}){V(r,Ut,"expm");let t=r.method??"Higham08.b";if(!Vt.includes(t))throw new RangeError(`unknown method: ${String(t)}`);let e=r.order??8,m=t==="Pade"||t==="PadeO"||t==="Taylor"||t==="TaylorO";if(m&&!(Number.isInteger(e)&&e>=1&&e<=2147483647))throw new RangeError("order must be a positive integer at most 2147483647");let c=I(o);T(c);let i=c.nrow;if(i===0)return[];if(i===1)return[[Math.exp(c.data[0])]];if(m&&e*(i**3+64)>2**31)throw new RangeError(`order = ${e} is too large for a ${i} x ${i} matrix: order * (n^3 + 64) must be at most 2^31`);for(let d of c.data)if(!Number.isFinite(d))throw new RangeError("the matrix contains NaN or infinite values");if(t==="Taylor"||t==="TaylorO")return b(At(c,e));if(t==="Pade"||t==="PadeO")return b(Jt(c,e));let h,u;t==="Higham08.b"?(h=j("P",c),u=j("S",c)):Kt(c)&&(u=j("S",c));let l=Yt(c),a=l.data,p=(d,M)=>d+M*i;if(u){let d=u.scale;for(let M=0;M<i;M++)for(let f=0;f<i;f++)a[p(f,M)]=a[p(f,M)]*d[f]/d[M]}if(h){let d=h.scale,M=f=>{let n=d[f];if(n!==f){for(let s=0;s<i;s++)[a[p(s,f)],a[p(s,n)]]=[a[p(s,n)],a[p(s,f)]];for(let s=0;s<i;s++)[a[p(f,s)],a[p(n,s)]]=[a[p(n,s)],a[p(f,s)]]}};for(let f=h.ilo-1;f>=0;f--)M(f);for(let f=h.ihi+1;f<i;f++)M(f)}return b(l)}var Bt={3:[120,60,12,1],5:[30240,15120,3360,420,30,1],7:[17297280,8648640,1995840,277200,25200,1512,56,1],9:[17643225600,8821612800,2075673600,302702400,30270240,2162160,110880,3960,90,1]},_t=[6476475253248e4,3238237626624e4,7771770303897600,0x437e459424400,129060195264e3,0x99a917d4d00,670442572800,33522128640,1323241920,40840800,960960,16380,182,1];function Gt(o,r){if(r<1/0)return Math.log2(r);let t=0;for(let m of o.data)t=Math.max(t,Math.abs(m));let e=Math.floor(Math.log2(t));return Math.log2(P({...o,data:o.data.map(m=>N(m,-e))}))+e}function Y(o,r){return Math.max(0,Math.ceil(Gt(o,r)-Math.log2(5.4)))}function Kt(o){let r=P(o);if(r<=2.1)return!1;let t=Y(o,r);return t>0&&o.data.some(e=>e!==0&&Math.abs(N(e,-t))<2**-1022)}function Yt(o){let r=o.nrow,t=P(o),e=L(r),m,c,i=0;if(t<=2.1){let a=t<=.015?3:t<=.25?5:t<=.95?7:9,p=Bt[a],d=v(o,o),M=R([[p[1],e]]),f=R([[p[0],e]]),n=d;for(let s=1;s<=(a-1)/2;s++)s>1&&(n=v(n,d)),F(M,p[2*s+1],n),F(f,p[2*s],n);m=v(o,M),c=f}else{i=Y(o,t);let a={...o,data:o.data.map(g=>N(g,-i))},p=v(a,a),d=v(p,p),M=v(p,d),f=_t,n=R([[f[13],M],[f[11],d],[f[9],p]]),s=v(M,n);for(let[g,x]of[[7,M],[5,d],[3,p],[1,e]])F(s,f[g],x);m=v(a,s);let q=R([[f[12],M],[f[10],d],[f[8],p]]);c=v(M,q);for(let[g,x]of[[6,M],[4,d],[2,p],[0,e]])F(c,f[g],x)}let h=k(r,r),u=k(r,r);for(let a=0;a<r*r;a++)h.data[a]=c.data[a]-m.data[a],u.data[a]=c.data[a]+m.data[a];let l=I(H(b(h),b(u)));for(let a=0;a<i;a++)l=tt(l,l);return l}function A(o){let r=P(o),t=B(o),e=r*t<1/0?Math.sqrt(r*t):Math.sqrt(r)*Math.sqrt(t),m=1;for(;2**m<e;)m++;let c=m+4;if(!o.data.some(h=>h!==0&&Math.abs(N(h,-c))<2**-1022))return c;if(e===0||r*t<2**-1e3)return Math.max(0,Math.ceil((Math.log2(r)+Math.log2(t))/2)+4);let i=m;for(;i>-4&&2**(i-1)>=e;)i--;return Math.max(0,i+4)}function J(o,r){let t=Math.max(0,r-1e3);return{A:t===0?o:O(o,2**-t),N:2**(r-t)}}function W(o,r){for(let t=0;t<r;t++)o=tt(o,o);return o}function Z(o){let r=o.nrow;for(let t=0;t<r;t++)o.data[t+t*r]=o.data[t+t*r]+1}function At(o,r){let t=A(o),{A:e,N:m}=J(o,t),c=L(o.nrow);for(let i=r;i>=1;i--)c=O(v(c,e),1/(i*m)),Z(c);return W(c,t)}function K(o,r,t,e){let m=e===1?o:O(o,-1),c=L(o.nrow);for(let i=r;i>=1;i--){let h=(r-i+1)/(i*(2*r-i+1)*t);c=O(v(c,m),h),Z(c)}return c}function Jt(o,r){let t=o.nrow,e=A(o),{A:m,N:c}=J(o,e),i=K(m,r,c,1),h=K(m,r,c,-1),u=k(t,t);for(let l=0;l<t;l++)u.data.set(Wt(h,i.data.subarray(l*t,(l+1)*t)),l*t);return W(u,e)}function Wt(o,r){let t=o.nrow,e=1e-100,m=f=>{let n=new Float64Array(t);for(let s=0;s<t;s++){let q=0;for(let g=0;g<t;g++)q+=o.data[s+g*t]*f[g];n[s]=q}return n},c=(f,n)=>{let s=0;for(let q=0;q<t;q++)s+=f[q]*n[q];return s},i=(f,n,s)=>{let q=new Float64Array(t);for(let g=0;g<t;g++)q[g]=f[g]+n*s[g];return q},h=new Float64Array(t),u=Float64Array.from(r),l=Float64Array.from(r),a=Float64Array.from(r),p=Float64Array.from(r),d=Math.sqrt(c(u,u)),M=c(p,r);if(Math.abs(M)<=e)return h;for(let f=0;f<t;f++){let n=m(l),s=c(p,n);if(Math.abs(s)<=e)return h;let q=M/s;if(Math.abs(q)<=e)return h;let g=i(a,-q,n);n=i(a,1,g);let x=m(n);u=i(u,-q,x);let w=Math.sqrt(c(u,u));if(h=i(h,q,n),Math.abs(w/d)<=1e-30)return h;let y=c(p,u);if(Math.abs(y)<=e)return h;let E=y/M;M=y,a=i(u,E,g),x=i(g,E,l),l=i(a,E,x)}return h}function L(o){let r=k(o,o);for(let t=0;t<o;t++)r.data[t+t*o]=1;return r}function tt(o,r){let t=o.nrow,e=o.ncol,m=r.ncol,c=k(t,m);for(let i=0;i<m;i++)for(let h=0;h<t;h++){let u=0;for(let l=0;l<e;l++){let a=o.data[h+l*t],p=r.data[l+i*e];a===0&&Math.abs(p)===1/0||p===0&&Math.abs(a)===1/0||(u+=a*p)}c.data[h+i*t]=u}return c}function v(o,r){let t=o.nrow,e=o.ncol,m=r.ncol,c=k(t,m);for(let i=0;i<m;i++)for(let h=0;h<t;h++){let u=0;for(let l=0;l<e;l++)u+=o.data[h+l*t]*r.data[l+i*e];c.data[h+i*t]=u}return c}function O(o,r){return{nrow:o.nrow,ncol:o.ncol,data:o.data.map(t=>t*r)}}function F(o,r,t){for(let e=0;e<o.data.length;e++)o.data[e]=o.data[e]+r*t.data[e]}function R(o){let[r,t]=o[0],e=O(t,r);for(let m=1;m<o.length;m++)F(e,o[m][0],o[m][1]);return e}export{kt as add,yt as backsolve,Ot as cbind,pt as chol,xt as chol2inv,qt as crossprod,dt as det,ht as determinant,Ft as diag,Et as divide,gt as eigen,zt as expm,bt as forwardsolve,Qt as ginv,Lt as kappa,Rt as kronecker,Xt as lu,vt as matMul,jt as matrix,Nt as multiply,mt as norm,It as outer,$t as prcomp,ot as qr,at as qrCoef,st as qrFitted,ct as qrQ,rt as qrQty,nt as qrQy,it as qrR,et as qrResid,ft as qrSolve,lt as qrX,Tt as rbind,Mt as rcond,Ct as schur,Ht as seq,H as solve,St as subtract,ut as svd,Pt as t,wt as tcrossprod};
@@ -0,0 +1,32 @@
1
+ import { type MetaCommonOptions, type MetaResult } from "./metagen.js";
2
+ /**
3
+ * Options of {@link metabin}.
4
+ *
5
+ * @category Meta-analysis
6
+ */
7
+ export interface MetabinOptions extends MetaCommonOptions {
8
+ /** "RR" (default), "OR" or "RD". */
9
+ sm?: "RR" | "OR" | "RD";
10
+ /** "MH" (default), "Inverse" or "Peto" (OR only). */
11
+ method?: "MH" | "Inverse" | "Peto";
12
+ /** The continuity correction (default 0.5). */
13
+ incr?: number;
14
+ /** Which studies get it: "only0" (studies with a zero cell, default), "all", "if0all" (all when any has a zero). */
15
+ methodIncr?: "only0" | "all" | "if0all";
16
+ /** Keep studies with no or all events in both groups (default false; RD keeps them anyway). */
17
+ allstudies?: boolean;
18
+ /** The MH estimate without any increment (default false). */
19
+ MHexact?: boolean;
20
+ /** With methodTau "DL", Q about the MH estimate (default true). */
21
+ QCochrane?: boolean;
22
+ }
23
+ /**
24
+ * Meta-analysis of binary outcomes (meta's `metabin()`): events e1 / e2 of totals n1 / n2. The common effect by
25
+ * Mantel-Haenszel (OR with the Robins-Breslow-Greenland variance; RR and RD with Greenland and Robins'), Peto's
26
+ * (O - E) / V or the inverse variance; the random effect and heterogeneity as {@link metagen} on the study values.
27
+ * Studies with a zero cell get `incr` (0.5); studies with no or all events in both groups are left out for OR and RR.
28
+ * Equivalent to `meta::metabin()` in R.
29
+ *
30
+ * @category Meta-analysis
31
+ */
32
+ export declare function metabin(e1: readonly number[], n1: readonly number[], e2: readonly number[], n2: readonly number[], options?: MetabinOptions): MetaResult;
@@ -0,0 +1,137 @@
1
+ // meta's metabin: meta-analysis of binary outcomes (Mantel-Haenszel, Peto, inverse variance; OR, RR, RD). Written for
2
+ // rStats.js from the behaviour specification oracle/tsmeta-behaviour.md ("metabin") with the details found in
3
+ // experiments/tsmeta120-log.md (items 64-65, 97). No R or package source was read.
4
+ import { pchisq } from "../distributions/chisq.js";
5
+ import { pnorm, qnorm } from "../distributions/normal.js";
6
+ import { metaCore } from "./metagen.js";
7
+ // Generated by `node scripts/option-keys.mjs --write` from the option types; do not edit (begin)
8
+ import { checkOptions } from "../internal/checkOptions.js";
9
+ const METABIN_KEYS = /* @__PURE__ */ new Set([
10
+ "methodTau", "sm", "method", "incr", "methodIncr", "allstudies", "MHexact", "QCochrane", "methodRandomCi",
11
+ "methodTauCi", "level", "levelMa", "levelPredict",
12
+ ]);
13
+ const sum = (v) => v.reduce((a, b) => a + b, 0);
14
+ /**
15
+ * Meta-analysis of binary outcomes (meta's `metabin()`): events e1 / e2 of totals n1 / n2. The common effect by
16
+ * Mantel-Haenszel (OR with the Robins-Breslow-Greenland variance; RR and RD with Greenland and Robins'), Peto's
17
+ * (O - E) / V or the inverse variance; the random effect and heterogeneity as {@link metagen} on the study values.
18
+ * Studies with a zero cell get `incr` (0.5); studies with no or all events in both groups are left out for OR and RR.
19
+ * Equivalent to `meta::metabin()` in R.
20
+ *
21
+ * @category Meta-analysis
22
+ */
23
+ export function metabin(e1, n1, e2, n2, options = {}) {
24
+ checkOptions(options, METABIN_KEYS, "metabin"); // generated: option-keys.mjs
25
+ const K = e1.length;
26
+ if (![n1, e2, n2].every((v) => v.length === K))
27
+ throw new RangeError("metabin: e1, n1, e2 and n2 must have the same length");
28
+ for (let i = 0; i < K; i++)
29
+ if (!(e1[i] >= 0 && e1[i] <= n1[i] && e2[i] >= 0 && e2[i] <= n2[i] && n1[i] > 0 && n2[i] > 0))
30
+ throw new RangeError("metabin: events must lie in 0..n and n > 0");
31
+ const sm = options.sm ?? "RR";
32
+ const method = options.method ?? "MH";
33
+ const incr = options.incr ?? 0.5;
34
+ const mi = options.methodIncr ?? "only0";
35
+ if (method === "Peto" && sm !== "OR")
36
+ throw new RangeError("metabin: Peto's method is for sm = 'OR'");
37
+ const a = e1.map(Number), c = e2.map(Number), b = a.map((x, i) => n1[i] - x), d = c.map((x, i) => n2[i] - x);
38
+ const zeroCell = a.map((_, i) => a[i] === 0 || b[i] === 0 || c[i] === 0 || d[i] === 0);
39
+ const doubleZero = a.map((_, i) => (a[i] === 0 && c[i] === 0) || (b[i] === 0 && d[i] === 0));
40
+ const keep = a.map((_, i) => sm === "RD" || options.allstudies || !doubleZero[i]);
41
+ const anyZero = zeroCell.some((z, i) => z && keep[i]);
42
+ const inc = a.map((_, i) => (mi === "all" || (mi === "if0all" && anyZero) || zeroCell[i] ? incr : 0));
43
+ // study values
44
+ const TE = new Array(K).fill(NaN), seTE = new Array(K).fill(NaN);
45
+ for (let i = 0; i < K; i++) {
46
+ if (!keep[i])
47
+ continue;
48
+ const t = inc[i];
49
+ const A = a[i] + t, B = b[i] + t, C = c[i] + t, D = d[i] + t;
50
+ if (method === "Peto") {
51
+ const N = n1[i] + n2[i];
52
+ const m1 = a[i] + c[i];
53
+ const E = (n1[i] * m1) / N;
54
+ const V = (n1[i] * n2[i] * m1 * (N - m1)) / (N * N * (N - 1));
55
+ TE[i] = (a[i] - E) / V;
56
+ seTE[i] = 1 / Math.sqrt(V);
57
+ }
58
+ else if (sm === "OR") {
59
+ TE[i] = Math.log((A * D) / (B * C));
60
+ seTE[i] = Math.sqrt(1 / A + 1 / B + 1 / C + 1 / D);
61
+ }
62
+ else if (sm === "RR") {
63
+ const N1 = n1[i] + t, N2 = n2[i] + t; // the increment added once to the group size (log 65)
64
+ TE[i] = Math.log(A / N1) - Math.log(C / N2);
65
+ seTE[i] = Math.sqrt(1 / A - 1 / N1 + 1 / C - 1 / N2);
66
+ }
67
+ else {
68
+ TE[i] = a[i] / n1[i] - c[i] / n2[i]; // the raw difference, the variance of the incremented cells
69
+ seTE[i] = Math.sqrt((A * B) / (A + B) ** 3 + (C * D) / (C + D) ** 3);
70
+ }
71
+ }
72
+ const idx = TE.map((v, i) => (keep[i] && Number.isFinite(v) && Number.isFinite(seTE[i]) && seTE[i] > 0 ? i : -1)).filter((i) => i >= 0);
73
+ const core = metaCore(idx.map((i) => TE[i]), idx.map((i) => seTE[i]), options);
74
+ const res = { ...core, TE, seTE, k: idx.length };
75
+ const spread = (v) => { const o = new Array(K).fill(0); idx.forEach((i, j) => { o[i] = v[j]; }); return o; };
76
+ res["w.random"] = spread(core["w.random"]);
77
+ const level = options.levelMa ?? options.level ?? 0.95;
78
+ const z = qnorm(0.5 + level / 2);
79
+ const setCommon = (te, se, w) => {
80
+ const st = te / se;
81
+ Object.assign(res, { "TE.common": te, "seTE.common": se, "lower.common": te - z * se, "upper.common": te + z * se, "statistic.common": st, "pval.common": 2 * pnorm(-Math.abs(st)), "w.common": w });
82
+ };
83
+ if (method === "Peto") {
84
+ // Peto: sum(O - E) / sum(V), the inverse variance of the study values
85
+ setCommon(core["TE.common"], core["seTE.common"], spread(core["w.common"]));
86
+ }
87
+ else if (method === "MH") {
88
+ // MH.exact drops the increment
89
+ const t = a.map((_, i) => (options.MHexact ? 0 : inc[i]));
90
+ const A = idx.map((i) => a[i] + t[i]), B = idx.map((i) => b[i] + t[i]), C = idx.map((i) => c[i] + t[i]), D = idx.map((i) => d[i] + t[i]);
91
+ const N1 = A.map((x, j) => x + B[j]), N2 = C.map((x, j) => x + D[j]), N = N1.map((x, j) => x + N2[j]);
92
+ let te, se, w;
93
+ if (sm === "OR") {
94
+ const R = A.map((x, j) => (x * D[j]) / N[j]), S = B.map((x, j) => (x * C[j]) / N[j]);
95
+ const P = A.map((x, j) => (x + D[j]) / N[j]), Qv = B.map((x, j) => (x + C[j]) / N[j]);
96
+ const sR = sum(R), sS = sum(S);
97
+ te = Math.log(sR / sS);
98
+ se = Math.sqrt(sum(P.map((p, j) => p * R[j])) / (2 * sR * sR) + sum(P.map((p, j) => p * S[j] + Qv[j] * R[j])) / (2 * sR * sS) + sum(Qv.map((q, j) => q * S[j])) / (2 * sS * sS));
99
+ w = S;
100
+ }
101
+ else if (sm === "RR") {
102
+ const R = A.map((x, j) => (x * N2[j]) / N[j]), S = C.map((x, j) => (x * N1[j]) / N[j]);
103
+ te = Math.log(sum(R) / sum(S));
104
+ se = Math.sqrt(sum(N.map((n, j) => (N1[j] * N2[j] * (A[j] + C[j]) - A[j] * C[j] * n) / (n * n))) / (sum(R) * sum(S)));
105
+ w = S;
106
+ }
107
+ else {
108
+ // the weights from the incremented group sizes, the raw risk differences (log 97)
109
+ const W = N1.map((x, j) => (x * N2[j]) / N[j]);
110
+ te = sum(W.map((wj, j) => wj * TE[idx[j]])) / sum(W);
111
+ se = Math.sqrt(sum(N.map((n, j) => (A[j] * B[j] * N2[j] ** 3 + C[j] * D[j] * N1[j] ** 3) / (N1[j] * N2[j] * n * n))) / sum(W) ** 2);
112
+ w = W;
113
+ }
114
+ setCommon(te, se, spread(w));
115
+ // with DL and Q.Cochrane, Q (and so DL's tau2) is taken about the MH estimate
116
+ if ((options.methodTau ?? "REML") === "DL" && (options.QCochrane ?? true)) {
117
+ const ti = idx.map((i) => TE[i]), wi = idx.map((i) => 1 / seTE[i] ** 2);
118
+ const Q = sum(ti.map((x, j) => wi[j] * (x - te) ** 2));
119
+ const df = idx.length - 1;
120
+ const sw = sum(wi);
121
+ const tau2 = Math.max(0, (Q - df) / (sw - sum(wi.map((x) => x * x)) / sw));
122
+ const re = metaCore(ti, idx.map((i) => seTE[i]), { ...options, methodTau: "DL", fixedTau2: tau2, fixedQ: Q });
123
+ Object.assign(res, pickRandom(re), { Q, "pval.Q": pchisq(Q, df, { lowerTail: false }), "w.random": spread(re["w.random"]) });
124
+ }
125
+ }
126
+ else
127
+ setCommon(core["TE.common"], core["seTE.common"], spread(core["w.common"]));
128
+ return res;
129
+ }
130
+ function pickRandom(m) {
131
+ const keys = ["TE.random", "seTE.random", "lower.random", "upper.random", "statistic.random", "pval.random", "df.random", "seTE.predict", "lower.predict", "upper.predict",
132
+ "tau2", "lower.tau2", "upper.tau2", "tau", "lower.tau", "upper.tau", "H", "lower.H", "upper.H", "I2", "lower.I2", "upper.I2"];
133
+ const o = {};
134
+ for (const k of keys)
135
+ o[k] = m[k];
136
+ return o;
137
+ }
@@ -0,0 +1,153 @@
1
+ import { type RmaResult } from "../models/metaAnalysis.js";
2
+ import { type MetaCommonOptions, type MetaResult } from "./metagen.js";
3
+ /**
4
+ * The result of {@link metaSubgroup}.
5
+ *
6
+ * @category Meta-analysis
7
+ */
8
+ export interface MetaSubgroupResult {
9
+ levels: string[];
10
+ "TE.common.w": number[];
11
+ "seTE.common.w": number[];
12
+ "TE.random.w": number[];
13
+ "seTE.random.w": number[];
14
+ "tau2.w": number[];
15
+ "Q.w": number[];
16
+ "k.w": number[];
17
+ "Q.w.common": number;
18
+ /** With `tauCommon`: equal to Q.w.common (as meta); otherwise absent. */
19
+ "Q.w.random"?: number;
20
+ "Q.b.common": number;
21
+ "Q.b.random": number;
22
+ "df.Q.b": number;
23
+ "df.Q.w": number;
24
+ "pval.Q.b.common": number;
25
+ "pval.Q.b.random": number;
26
+ /** The overall tau2 and random effect (of `overall`). */
27
+ tau2: number;
28
+ "TE.random": number;
29
+ "seTE.random": number;
30
+ }
31
+ /**
32
+ * Subgroup analysis (meta's `subgroup` argument): `refit(rows)` fits the same meta-analysis to the given study rows
33
+ * (for example `(r) => metabin(pick(e1, r), ...)`). Within each subgroup the common and random effects; Q.b = Q of the
34
+ * subgroup estimates with weights 1/se^2 (common and random), Q.w = the within-subgroup Q. With `tauCommon`, one tau2
35
+ * for all subgroups: that of the meta-regression on the subgroup (rma with the subgroup as a factor); the overall
36
+ * estimates stay those of `overall`.
37
+ * Not an R function. R: the `subgroup` argument of meta's functions.
38
+ *
39
+ * @category Meta-analysis
40
+ */
41
+ export declare function metaSubgroup(overall: MetaResult, subgroup: readonly (string | number)[], refit: (rows: number[]) => MetaResult, options?: MetaCommonOptions & {
42
+ tauCommon?: boolean;
43
+ }): MetaSubgroupResult;
44
+ /**
45
+ * A test for funnel plot asymmetry from {@link metabias}.
46
+ *
47
+ * @category Meta-analysis
48
+ */
49
+ export interface MetabiasResult {
50
+ statistic: number;
51
+ df: number | null;
52
+ pValue: number;
53
+ estimate: [number, number];
54
+ method: string;
55
+ }
56
+ /**
57
+ * Tests for funnel plot asymmetry (meta's `metabias()`): "Egger" (default for continuous outcomes: the intercept of
58
+ * TE/seTE on 1/seTE, t on k - 2), "Begg" (Kendall's S of the standardised deviations against the variances, no
59
+ * continuity correction), "Thompson" (Thompson-Sharp: the REML meta-regression on seTE, its z with t(k - 2) p),
60
+ * "Harbord" (binary: lm(Z/sqrt(V) ~ sqrt(V)) with Z = O - E and V the hypergeometric variance) and "Peters" (binary:
61
+ * lm(TE ~ 1/N) with weights 1/(1/(a + c) + 1/(b + d))). Harbord and Peters need the 2 x 2 counts (`counts`).
62
+ * Equivalent to `meta::metabias()` in R.
63
+ *
64
+ * @category Meta-analysis
65
+ */
66
+ export declare function metabias(m: MetaResult, options?: {
67
+ method?: "Egger" | "Begg" | "Thompson" | "Harbord" | "Peters";
68
+ counts?: {
69
+ e1: readonly number[];
70
+ n1: readonly number[];
71
+ e2: readonly number[];
72
+ n2: readonly number[];
73
+ };
74
+ }): MetabiasResult;
75
+ /**
76
+ * Meta-regression (meta's `metareg()`): rma(TE, seTE^2, mods, method = the meta-analysis's tau2 method) on the studies
77
+ * with finite values. `mods` has one row per study (all studies, as given to the meta function).
78
+ * Equivalent to `meta::metareg()` in R.
79
+ *
80
+ * @category Meta-analysis
81
+ */
82
+ export declare function metareg(m: MetaResult, mods: readonly (readonly number[])[]): RmaResult;
83
+ /**
84
+ * Leave-one-out or cumulative estimates of {@link metainf} / {@link metacum}.
85
+ *
86
+ * @category Meta-analysis
87
+ */
88
+ export interface MetaInfluenceResult {
89
+ TE: number[];
90
+ seTE: number[];
91
+ lower: number[];
92
+ upper: number[];
93
+ pval: number[];
94
+ tau2: number[];
95
+ I2: number[];
96
+ }
97
+ /**
98
+ * Leave-one-out meta-analysis (meta's `metainf()`): the pooled estimate without each study in turn; `pooled` "common"
99
+ * (default) or "random".
100
+ * Equivalent to `meta::metainf()` in R.
101
+ *
102
+ * @category Meta-analysis
103
+ */
104
+ export declare function metainf(m: MetaResult, options?: MetaCommonOptions & {
105
+ pooled?: "common" | "random";
106
+ }): MetaInfluenceResult;
107
+ /**
108
+ * Cumulative meta-analysis (meta's `metacum()`): the pooled estimate of the first 1, 2, ... studies; `pooled` "common"
109
+ * (default) or "random".
110
+ * Equivalent to `meta::metacum()` in R.
111
+ *
112
+ * @category Meta-analysis
113
+ */
114
+ export declare function metacum(m: MetaResult, options?: MetaCommonOptions & {
115
+ pooled?: "common" | "random";
116
+ }): MetaInfluenceResult;
117
+ /**
118
+ * The coordinates of Baujat's plot (meta's `baujat()`): x = each study's contribution to Q, w (TE - TE.common)^2;
119
+ * y = its influence on the common estimate, (TE.common - TE.common without it)^2 / seTE.common without it^2.
120
+ * Equivalent to `meta::baujat()` in R.
121
+ *
122
+ * @category Meta-analysis
123
+ */
124
+ export declare function baujat(m: MetaResult): {
125
+ x: number[];
126
+ y: number[];
127
+ };
128
+ /**
129
+ * The result of {@link trimfill}.
130
+ *
131
+ * @category Meta-analysis
132
+ */
133
+ export interface TrimfillResult {
134
+ k0: number;
135
+ side: "left" | "right";
136
+ TE: number[];
137
+ seTE: number[];
138
+ filled: boolean[];
139
+ meta: MetaResult;
140
+ }
141
+ /**
142
+ * Duval and Tweedie's trim-and-fill (meta's `trimfill()`): the L0 estimator on the common-effect model, iterated
143
+ * (trim the k0 most extreme studies on one side, re-estimate, re-rank), the side opposite to the asymmetry (the sign of
144
+ * the Egger-type regression of TE on seTE); the k0 mirrored studies 2 theta - TE added, then the meta-analysis of the
145
+ * augmented data (random effect with the given tau2 method, default REML).
146
+ * Equivalent to `meta::trimfill()` in R.
147
+ *
148
+ * @category Meta-analysis
149
+ */
150
+ export declare function trimfill(m: MetaResult, options?: MetaCommonOptions & {
151
+ side?: "left" | "right";
152
+ maxiter?: number;
153
+ }): TrimfillResult;