@numero-uno-jpn/rstats 0.8.0 → 0.9.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 (39) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.ja.md +36 -9
  3. package/README.md +38 -10
  4. package/THIRD_PARTY_NOTICES.md +5 -0
  5. package/dist/chunks/chunk-24U4DKRY.js +2 -0
  6. package/dist/chunks/{chunk-XU4BGFZ6.js → chunk-5K4PS7IV.js} +2 -2
  7. package/dist/chunks/{chunk-VIPSPG3Y.js → chunk-BGVMSDVJ.js} +2 -2
  8. package/dist/chunks/{chunk-3I6EKGB6.js → chunk-FC2TLHZC.js} +2 -2
  9. package/dist/chunks/{chunk-OHPHNE3O.js → chunk-H2AP6TCR.js} +1 -1
  10. package/dist/chunks/{chunk-LXMMKO26.js → chunk-IVOBWYLV.js} +2 -2
  11. package/dist/chunks/{chunk-JVYV4633.js → chunk-JLSTEMSN.js} +1 -1
  12. package/dist/chunks/chunk-LE7TBHNI.js +2 -0
  13. package/dist/chunks/{chunk-32PRRONF.js → chunk-LWUSYIQ4.js} +1 -1
  14. package/dist/chunks/{chunk-RZ7SBJEG.js → chunk-MF4VBCHQ.js} +2 -2
  15. package/dist/chunks/{chunk-U633VFH3.js → chunk-MSAUU6PY.js} +2 -2
  16. package/dist/chunks/{chunk-YGWPU67I.js → chunk-TOVTN5Y2.js} +1 -1
  17. package/dist/chunks/{chunk-I3LAZE6C.js → chunk-YC4JWUKG.js} +2 -2
  18. package/dist/chunks/{chunk-SPQC445Q.js → chunk-ZRO446BP.js} +2 -2
  19. package/dist/descriptive.js +2 -2
  20. package/dist/distributions.js +2 -2
  21. package/dist/entries/tests.d.ts +3 -0
  22. package/dist/entries/tests.js +3 -0
  23. package/dist/linalg.js +2 -2
  24. package/dist/models/glm.d.ts +226 -0
  25. package/dist/models/glm.js +546 -0
  26. package/dist/models/glmAnova.d.ts +31 -0
  27. package/dist/models/glmAnova.js +146 -0
  28. package/dist/models/glmConfint.d.ts +25 -0
  29. package/dist/models/glmConfint.js +139 -0
  30. package/dist/models/glmFamily.d.ts +66 -0
  31. package/dist/models/glmFamily.js +359 -0
  32. package/dist/numerics.js +2 -2
  33. package/dist/rstats.js +4 -3
  34. package/dist/special.js +2 -2
  35. package/dist/tests.js +4 -3
  36. package/package.json +1 -1
  37. package/dist/chunks/chunk-EJRCDJ76.js +0 -2
  38. package/dist/chunks/chunk-JERGQKZM.js +0 -2
  39. package/dist/chunks/chunk-MJQLKEO5.js +0 -2
package/dist/special.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! rStats.js 0.8.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{e as ht}from"./chunks/chunk-EJRCDJ76.js";import{a as wt,b as Lt,c as _t,d as Et}from"./chunks/chunk-XU4BGFZ6.js";import{c as G,d as St,e as jt}from"./chunks/chunk-MJQLKEO5.js";import{A as v,C as Dt,D as Ft,b as $,c as qt,h as ft,k as d,l as q,m as U,n as _,o as C,p as Z,q as ct,u as z,v as lt,w as mt,y as ut}from"./chunks/chunk-3I6EKGB6.js";import{b as E,d as j,f as T,g as J,h as at,i as O,k as L}from"./chunks/chunk-OHPHNE3O.js";var Mt=22250738585072014e-324;function W(t,e,n){if(t<10)return Math.pow(e/2,t)/q(t+1)*n;let s=e/2,r=z(t,s,!1);if(r>=Mt&&s<700){let a=r*Math.exp(s)*n;if(Math.abs(a)>=Mt)return a}let o=z(t,s,!0)+s+Math.log(Math.abs(n));return Math.sign(n)*Math.exp(o)}var D=Number.EPSILON,H=1e6;function pt(t){return Math.expm1(C(t))}function Tt(t,e){let n=pt(t),s=pt(-t),r=Math.log(e/2),o=Math.exp(t*r),a=-r*t,i=Math.abs(t)<D?1:d(t)/(t*Math.PI),c=Math.abs(a)<D?1:Math.sinh(a)/a,l=Math.abs(t)<D?-.5772156649015329:.5/t*(n-s)*i,f=(2+n+s)*i/2,m=(n+1)/(2*o),u=(1+s)*o/2,M=(Math.cosh(a)*l+c*-r*f)/i,p=m,h=1,S=h*M,k=h*p;for(let I=1;I<H&&(M=(I*M+m+u)/(I*I-t*t),m/=I-t,u/=I+t,p=m-I*M,h*=e*e/(4*I),S+=h*M,k+=h*p,!(Math.abs(h*M)<Math.abs(S)*D));I++);return[S,2*k/e]}function At(t,e){let n=Math.sqrt(Number.MIN_VALUE*4503599627370496),s=n,r=n,o=0;for(let a=1;a<H;a++){let i=2*(t+a)/e;s=i+1/s,o=i+o,s===0&&(s=n),o===0&&(o=n),o=1/o;let c=s*o;if(r*=c,Math.abs(c-1)<=2*D)break}return r}function Jt(t,e){let n=t*t-.25,s=2*(e+1),r=1/s,o=r,a=r,i=0,c=1,l=-n,f=l,m=1+f*a;for(let p=2;p<H;p++){n-=2*(p-1),s+=2,r=1/(s+n*r),a*=s*r-1,o+=a;let h=(i-(s-2)*c)/n;if(i=c,c=h,l*=-n/p,f+=l*h,m+=f*a,h<D&&(l*=h,i/=h,c/=h),Math.abs(f*a)<Math.abs(m)*D)break}let u=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/m;return[M,M*u]}function V(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function bt(t,e){let n=Math.round(t),s=t-n,r,o;if(s===-.5)r=o=Math.sqrt(Math.PI/(2*e));else if(e<=2){let[i,c]=Tt(s,e),l=Math.exp(e);r=i*l,o=c*l}else[r,o]=Jt(s,e);let a=0;for(let i=1;i<=n;i++){let c=2*(s+i)/e,l=Math.log2(Math.abs(o))+Math.log2(c);if(l>900&&Number.isFinite(l)){let m=Math.ceil(l-800);r=V(r,-m),o=V(o,-m),a+=m}let f=c*o+r;r=o,o=f}return{k:r,k1:o,exp2:a}}function Kt(t,e){let n=e*e/4,s=1,r=0;for(let o=1;o<H&&(r+=s,s*=n/o,s/=o+t,!(Math.abs(s)<=D*Math.abs(r)));o++);return W(t,e,r+s)}function Rt(t,e,n){if(t===0||!Number.isFinite(t))return t;let s=t,r=e,o=n>0?700:-700,a=Math.exp(o);for(;Math.abs(n)>700;){n-=o,s*=a;let i=Math.floor(Math.log2(Math.abs(s)));s=V(s,-i),r+=i}return V(s*Math.exp(n),r)}function x(t,e,n){let s=t.ex+n;return s===0?V(t.m,t.e2):Rt(t.m,t.e2,s*e)}function Yt(t,e){if(t===.5)return{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(t>0&&e/t<.25)return{m:Kt(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<D*10&&e>100){let i=4*t*t,c=8*e,l=i-1,f=c,m=1-l/f;return l*=i-9,f*=c*2,m+=l/f,l*=i-25,f*=c*3,m-=l/f,{m:m/Math.sqrt(2*e*Math.PI),e2:0,ex:1}}let{k:s,k1:r,exp2:o}=bt(t,e),a=At(t,e);return{m:1/(e*(s*a+r)),e2:-o,ex:1}}function Nt(t,e){let n=4*t*t,s=8*e,r=(n-1)/s,o=r*(n-9)/(2*s),a=o*(n-25)/(3*s),i=a*(n-49)/(4*s),c=1+r+o+a;if(Math.abs(i)<D*Math.abs(c))return{m:c*Math.sqrt(Math.PI)/Math.sqrt(2*e),e2:0,ex:-1};let{k:l,exp2:f}=bt(t,e);return{m:l,e2:f,ex:-1}}function Ct(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?d(r)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return s?0:1/0;let a=s?-1:0,i=x(Yt(r,t),t,a);if(!o)return i;let c=Nt(r,t);return i+x({...c,m:2/Math.PI*d(r)*c.m},t,a)}function Qt(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e);return t===0?1/0:t===1/0?0:x(Nt(r,t),t,s?1:0)}var y=Number.EPSILON;function A(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function gt(t,e,n,s,r){let o=s,a=r,i=0;for(let c=1;c<=n;c++){let l=2*(t+c)/e,f=Math.log2(Math.abs(a))+Math.log2(l);if(f>900&&Number.isFinite(f)){let u=Math.ceil(f-800);o=A(o,-u),a=A(a,-u),i+=u}let m=l*a-o;o=a,a=m}return{y:o,y1:a,e2:i}}var K=1e6,g=Math.sqrt(22250738585072014e-324),Ut=Number.MAX_VALUE;function It(t){return Math.expm1(C(t))}function Q(t){return d(.5-Math.abs(t%2))}function dt(t,e){let n=-(e/2)*(e/2),s=1,r=0;for(let o=1;o<K&&(r+=s,s*=n/(o*(o+t)),!(Math.abs(s)<=y*Math.abs(r)));o++);return W(t,e,r+s)}function Vt(t,e){let n=Math.log(e/2),s=0,r=t>=170||709.78/t<Math.abs(n),o;if(r){let u=_(t);if(n=t*n,o=u-Math.log(Math.PI)-n,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,s=M}o=-Math.exp(o)}else{let u=q(t);n=Math.pow(e/2,t),Ut*n<u&&(u*=2**-1e3,s=1e3),o=-u/(Math.PI*n)}let a=-(e/2)*(e/2),i=1,c=0;for(let u=1;u<K&&(c+=i,i*=a/(u*(u-t)),!(Math.abs(i)<=y*Math.abs(c)));u++);let l=(c+i)*o,f;if(!r)f=q(-t)*Q(t)*n/Math.PI;else{let u=U(-t);f=Math.exp(u.value+n)*u.sign/Math.PI}i=1;let m=0;for(let u=1;u<K&&(m+=i,i*=a/(u*(u+t)),!(Math.abs(i)<=y*Math.abs(m)));u++);return m+=i,l-=A(f*m,-s),{m:l,e2:s}}function Xt(t,e){let n=1,s=0,r=1,o=8*e,a=1,i=4*t*t,c=1,l=!0;do{c*=(i-a*a)/(r*o),s+=c,r+=1,a+=2;let f=(a*a-i)/(r*o);l=Math.abs(f)<.5,c*=f,n+=c,r+=1,a+=2}while(Math.abs(c)>2*y*n&&l);return l?{p:n,q:s}:void 0}function Bt(t,e){let n=It(t),s=It(-t),r=d(t),o=d(t/2),a=Math.pow(e/2,t),i=Math.log(e/2),c=-i*t,l=Math.abs(c)<y?1:Math.sinh(c)/c,f=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,m=t===0?-.5772156649015329:(n-s)/((1+n)*(1+s)*2*t),u=(2+n+s)/((1+n)*(1+s)*2),M=Math.abs(t)<y?1/Math.PI:t/r,p=(m*Math.cosh(c)-u*i*l)*2*M,h=M/(a*(1+s)),S=M*a/(1+n),k=p+f*S,I=h,F=1,R=F*k,X=F*I,B=t*t,b=-e*e/4;for(let N=1;N<K&&(p=(N*p+h+S)/(N*N-B),h/=N-t,S/=N+t,k=p+f*S,I=h-N*k,F*=b/N,R+=F*k,X+=F*I,!(Math.abs(F*k)<Math.abs(R)*y));N++);return[-R,-2*X/e]}function Ot(t,e){let n=[g,0],s=[g,0],r=[0,0],o=1,a=[e,0];for(let i=1;i<K*100;i++){let c=E(t,i),l=O([2*c[0],2*c[1]],a);n=T(l,O([1,0],n)),r=T(l,r),n[0]===0&&(n=[g,0]),r[0]===0&&(r=[g,0]),r=O([1,0],r);let f=J(n,r);if(s=J(s,f),r[0]<0&&(o=-o),Math.abs(f[0]-1+f[1])<y*y)break}return{fv:-(s[0]+s[1]),sign:o}}function yt(t,e){if(e>30)return Ot(t,e);let n=g,s=g,r=0,o=1;for(let a=1;a<K*100;a++){let i=2*(t+a)/e;n=i-1/n,r=i-r,n===0&&(n=g),r===0&&(r=g),r=1/r;let c=n*r;if(s*=c,r<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-s,sign:o}}function Pt(t,e){let n=-.5/e,s=1,r=n,o=s,a=t*t,i=(.25-a)/e,c=2*e,l=2,f=r*r+1;o=l+i*r/f,r=c+i/f;let m=c,u=l;Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f;let M=r*m-o*u,p=o*m+r*u;f=n,n=f*M-s*p,s=f*p+s*M;for(let h=2;h<K&&(i=h-.5,i*=i,i-=a,l+=2,f=r*r+o*o,r=c+i*r/f,o=l-i*o/f,m=c+i*m,u=l+i*u,Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f,M=r*m-o*u,p=o*m+r*u,f=n,n=f*M-s*p,s=f*p+s*M,!(Math.abs(M-1)+Math.abs(p)<2*y));h++);return{p:n,q:s}}function Zt(t,e){let n=1,s=4*t*t,r=2*e;return r*=r,n+=(s-1)/(2*r),n+=3*(s-1)*(s-9)/(r*r*8),n+=15*(s-1)*(s-9)*(s-25)/(r*r*r*8*6),Math.sqrt(n*2/(Math.PI*e))}function Gt(t,e){let n=4*t*t,s=4*e,r=s*s,o=0;return o+=(n-1)/(2*s),s*=r,o+=(n-1)*(n-25)/(6*s),s*=r,o+=(n-1)*(n*n-114*n+1073)/(5*s),s*=r,o+=(n-1)*(5*n*n*n-1535*n*n+54703*n-375733)/(14*s),o}function Wt(t,e){let n=Zt(t,e),s=Gt(t,e),r=Math.cos(e),o=Math.sin(e),a=Q(t/2+.25),i=d(t/2+.25),c=Math.sin(s),l=Math.cos(s),f=(c*(r*a+o*i)+l*(o*a-r*i))*n;return{j:(l*(r*a+o*i)-c*(o*a-r*i))*n,y:f}}function tt(t,e,n){let s=Math.round(t),r=t-s,o=2/(e*Math.PI);if(!n&&(e<5||t>e*e/4))return{j:dt(t,e),y:{m:NaN,e2:0}};if(e<1&&r!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:dt(t,e),y:Vt(t,e)};if(Math.max(t,1)<e*.011048543456039806){let b=Wt(t,e);return{j:b.j,y:{m:b.y,e2:0}}}if(e>8){let b=Xt(t,e);if(b!==void 0){let N=(t/2+.25)%2,P=Math.sin(e),w=Math.cos(e),Y=d(N),rt=Q(N),st=P*rt-Y*w,ot=w*rt+P*Y,it=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:it*(b.p*ot-b.q*st),y:{m:it*(b.p*st+b.q*ot),e2:0}}}}if(e<=2){let[b,N]=Bt(r,e),P=gt(r,e,s,b,N),{fv:w}=yt(t,e);return{j:A(o/(P.y*w-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let{fv:a,sign:i}=yt(t,e);if(e>=t&&t>2){let{p:b,q:N}=Pt(t,e),P=t/e-a,w=(b-P)/N;w===0&&(w=t*y/e);let Y=i*Math.sqrt(o/(N+w*(b-P)));return{j:Y,y:{m:w*Y,e2:0}}}let c=g,l=a*i*c,f=i*c,m=0;for(let b=s;b>0;b--){let N=2*(r+b)/e;Math.abs(f)>2**900&&(l*=2**-900,f*=2**-900,m+=900);let P=N*f-l;P===0&&(P=l*y/2),l=f,f=P}let u=A(i*c/f,-m),M=l/f,{p,q:h}=Pt(r,e),S=r/e-M,k=(p-S)/h;k===0&&(k=r*y/e);let I=Math.sign(f)*Math.sqrt(o/(h+k*(p-S))),F=I*u,R=k*I,X=R*(r/e-p-h/k);if(!n)return{j:F,y:{m:NaN,e2:0}};let B=gt(r,e,s,R,X);return{j:F,y:{m:B.y,e2:B.e2}}}function Ht(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:s?d(n)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!s){let o=tt(n,t,!1).j;return e<0&&n%2===1?-o:o}let r=tt(n,t,!0);return Q(n)*r.j-A(d(n)*r.y.m,r.y.e2)}function $t(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0;if(t===0){if(!s)return-1/0;let i=Q(n);return i===0?0:i>0?-1/0:1/0}if(t===1/0)return 0;let r=tt(n,t,!0);if(!s)return A(r.y.m,r.y.e2);let o=Q(n),a=d(n);return(a!==0?a*r.j:0)+(o===0?0:A(o*r.y.m,r.y.e2))}function zt(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let n=_(e),s=q(e),r=l=>{let f=v(e,t,l,!1),m=s*f;if(Number.isFinite(s)&&f>kt&&Number.isFinite(m)&&m>kt)return[m,Math.log(m)];let u=n+v(e,t,l,!0);return u<710&&u>-746&&t>0&&(l?t<e:t>e)?vt(t,e,l):[Math.exp(u),u]},[o,a]=r(!0),[i,c]=r(!1);return{lower:o,upper:i,logLower:a,logUpper:c}}var kt=22250738585072014e-324;function vt(t,e,n){let s=j(at(L([t,0]),e),[-t,0]);n?s=j(s,L([mt(e,t)/e,0])):s=j(s,L([ut(e,t),0]));let r=s[0]+s[1];return[s[0]>-708?Math.exp(s[0])*(1+s[1]):Math.exp(r),r]}function et(t){return Number.isNaN(t)||t<0||t>2?NaN:-ft(t/2)*Math.SQRT1_2}function xt(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,n=Math.abs(t);if(n>=.5)return e*et(1-n);if(n<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let s=et(1-n);for(let r=0;r<3;r++){let o=($(s)-n)/(1.1283791670955126*Math.exp(-s*s));if(s-=o,Math.abs(o)<=1e-17*s)break}return e*s}function te(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let n=e===Math.floor(e);return t===Math.floor(t)&&n&&e>t?0:!Number.isFinite(t)||!Number.isFinite(e)?ie(t,e):n&&e<=1e3?ee(t,e):ne(t,e)}function ee(t,e){let n=[1,0];for(let s=0;s<e;s++){let r=E(t,-s),o=n[0]*r[0];if(!Number.isFinite(o)){let a=Math.sign(o);for(let i=s+1;i<e;i++)t-i<0&&(a=-a);return a*(1/0)}n=Math.abs(n[0])>1e290||Math.abs(r[0])>1e290?[(n[0]+n[1])*(r[0]+r[1]),0]:J(n,r)}return n[0]+n[1]}function ne(t,e){let[n,s]=E(t,-e);if(n+1<=0)return re(t,n,s);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let r;if(n>=15){if(e*Math.log(n+1)>720)return 1/0;let o=E(t,-n),a=T(J(o,L([t,0])),ct(n,[t,0]));a=j(a,[Z(t)-Z(n),0]),r=Math.sqrt(t/n)*Math.exp(a[0])*(1+a[1])}else if(t<30)r=q(t+1)/q(n+1);else{if(_(t+1)-_(n+1)>720)return 1/0;let o=T(nt(t+1),L([q(n+1),0]));r=Math.exp(o[0])*(1+o[1])}return s!==0&&Number.isFinite(r)&&r!==0&&(r*=Math.exp(-s*G(n+1))),r}function re(t,e,n){let s=j(E(e,1),[n,0]),r=d(s[0])+d(s[0]+.5)*Math.PI*s[1];if(r===0)return 0;let o=Math.sign(r),a=j(T(L([Math.abs(r),0]),oe),[-n*G(-e),0]);if(_(t+1)+_(-e)+a[0]>720)return o*(1/0);let i=j(j(nt(t+1),nt(-e)),a);return o*Math.exp(i[0])*(1+i[1])}var se=[.9189385332046728,-38782941580672414e-33],oe=[1.1447298858494002,10265951162707826e-33];function nt(t){if(t<15)return L([q(t),0]);let e=T(J(E(t,-.5),L([t,0])),[t,0]);return j(j(e,se),[Z(t),0])}function ie(t,e){let n=U(t+1),s=U(t-e+1);return n.sign*s.sign*Math.exp(n.value-s.value)}function ae(t){return Number.isNaN(t)||t<-1?NaN:t===-1||t===1/0?-1/0:lt(t)}function fe(t){return Number.isNaN(t)||t===-1/0?NaN:t===1/0||t<=-1&&t===Math.floor(t)?1/0:C(t)}function ce(t){return Number.isNaN(t)||t<0?NaN:t===0?-1/0:t===1/0?0:ht(-t)}function le(t){return Number.isNaN(t)?NaN:t<=-37?Math.exp(t):t<=18?Math.log1p(Math.exp(t)):t<=33.3?t+Math.exp(-t):t}export{Ct as besselI,Ht as besselJ,Qt as besselK,$t as besselY,Dt as beta,wt as choose,G as digamma,$ as erf,qt as erfc,et as erfcinv,xt as erfinv,_t as factorial,q as gamma,zt as gammainc,Ft as lbeta,Lt as lchoose,Et as lfactorial,_ as lgamma,fe as lgamma1p,ce as log1mexp,le as log1pexp,ae as log1pmx,te as perm,jt as psigamma,St as trigamma};
1
+ /*! rStats.js 0.9.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 wt,b as Lt,c as _t,d as Et}from"./chunks/chunk-5K4PS7IV.js";import{c as G,d as St,e as jt,j as ht}from"./chunks/chunk-LE7TBHNI.js";import{A as v,C as Dt,D as Ft,b as $,c as qt,h as ft,k as d,l as q,m as U,n as _,o as C,p as Z,q as ct,u as z,v as lt,w as mt,y as ut}from"./chunks/chunk-FC2TLHZC.js";import{b as E,d as j,f as T,g as J,h as at,i as O,k as L}from"./chunks/chunk-H2AP6TCR.js";var Mt=22250738585072014e-324;function W(t,e,n){if(t<10)return Math.pow(e/2,t)/q(t+1)*n;let s=e/2,r=z(t,s,!1);if(r>=Mt&&s<700){let a=r*Math.exp(s)*n;if(Math.abs(a)>=Mt)return a}let o=z(t,s,!0)+s+Math.log(Math.abs(n));return Math.sign(n)*Math.exp(o)}var D=Number.EPSILON,H=1e6;function pt(t){return Math.expm1(C(t))}function Tt(t,e){let n=pt(t),s=pt(-t),r=Math.log(e/2),o=Math.exp(t*r),a=-r*t,i=Math.abs(t)<D?1:d(t)/(t*Math.PI),c=Math.abs(a)<D?1:Math.sinh(a)/a,l=Math.abs(t)<D?-.5772156649015329:.5/t*(n-s)*i,f=(2+n+s)*i/2,m=(n+1)/(2*o),u=(1+s)*o/2,M=(Math.cosh(a)*l+c*-r*f)/i,p=m,h=1,S=h*M,k=h*p;for(let I=1;I<H&&(M=(I*M+m+u)/(I*I-t*t),m/=I-t,u/=I+t,p=m-I*M,h*=e*e/(4*I),S+=h*M,k+=h*p,!(Math.abs(h*M)<Math.abs(S)*D));I++);return[S,2*k/e]}function At(t,e){let n=Math.sqrt(Number.MIN_VALUE*4503599627370496),s=n,r=n,o=0;for(let a=1;a<H;a++){let i=2*(t+a)/e;s=i+1/s,o=i+o,s===0&&(s=n),o===0&&(o=n),o=1/o;let c=s*o;if(r*=c,Math.abs(c-1)<=2*D)break}return r}function Jt(t,e){let n=t*t-.25,s=2*(e+1),r=1/s,o=r,a=r,i=0,c=1,l=-n,f=l,m=1+f*a;for(let p=2;p<H;p++){n-=2*(p-1),s+=2,r=1/(s+n*r),a*=s*r-1,o+=a;let h=(i-(s-2)*c)/n;if(i=c,c=h,l*=-n/p,f+=l*h,m+=f*a,h<D&&(l*=h,i/=h,c/=h),Math.abs(f*a)<Math.abs(m)*D)break}let u=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/m;return[M,M*u]}function V(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function bt(t,e){let n=Math.round(t),s=t-n,r,o;if(s===-.5)r=o=Math.sqrt(Math.PI/(2*e));else if(e<=2){let[i,c]=Tt(s,e),l=Math.exp(e);r=i*l,o=c*l}else[r,o]=Jt(s,e);let a=0;for(let i=1;i<=n;i++){let c=2*(s+i)/e,l=Math.log2(Math.abs(o))+Math.log2(c);if(l>900&&Number.isFinite(l)){let m=Math.ceil(l-800);r=V(r,-m),o=V(o,-m),a+=m}let f=c*o+r;r=o,o=f}return{k:r,k1:o,exp2:a}}function Kt(t,e){let n=e*e/4,s=1,r=0;for(let o=1;o<H&&(r+=s,s*=n/o,s/=o+t,!(Math.abs(s)<=D*Math.abs(r)));o++);return W(t,e,r+s)}function Rt(t,e,n){if(t===0||!Number.isFinite(t))return t;let s=t,r=e,o=n>0?700:-700,a=Math.exp(o);for(;Math.abs(n)>700;){n-=o,s*=a;let i=Math.floor(Math.log2(Math.abs(s)));s=V(s,-i),r+=i}return V(s*Math.exp(n),r)}function x(t,e,n){let s=t.ex+n;return s===0?V(t.m,t.e2):Rt(t.m,t.e2,s*e)}function Yt(t,e){if(t===.5)return{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(t>0&&e/t<.25)return{m:Kt(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<D*10&&e>100){let i=4*t*t,c=8*e,l=i-1,f=c,m=1-l/f;return l*=i-9,f*=c*2,m+=l/f,l*=i-25,f*=c*3,m-=l/f,{m:m/Math.sqrt(2*e*Math.PI),e2:0,ex:1}}let{k:s,k1:r,exp2:o}=bt(t,e),a=At(t,e);return{m:1/(e*(s*a+r)),e2:-o,ex:1}}function Nt(t,e){let n=4*t*t,s=8*e,r=(n-1)/s,o=r*(n-9)/(2*s),a=o*(n-25)/(3*s),i=a*(n-49)/(4*s),c=1+r+o+a;if(Math.abs(i)<D*Math.abs(c))return{m:c*Math.sqrt(Math.PI)/Math.sqrt(2*e),e2:0,ex:-1};let{k:l,exp2:f}=bt(t,e);return{m:l,e2:f,ex:-1}}function Ct(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?d(r)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return s?0:1/0;let a=s?-1:0,i=x(Yt(r,t),t,a);if(!o)return i;let c=Nt(r,t);return i+x({...c,m:2/Math.PI*d(r)*c.m},t,a)}function Qt(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e);return t===0?1/0:t===1/0?0:x(Nt(r,t),t,s?1:0)}var y=Number.EPSILON;function A(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function gt(t,e,n,s,r){let o=s,a=r,i=0;for(let c=1;c<=n;c++){let l=2*(t+c)/e,f=Math.log2(Math.abs(a))+Math.log2(l);if(f>900&&Number.isFinite(f)){let u=Math.ceil(f-800);o=A(o,-u),a=A(a,-u),i+=u}let m=l*a-o;o=a,a=m}return{y:o,y1:a,e2:i}}var K=1e6,g=Math.sqrt(22250738585072014e-324),Ut=Number.MAX_VALUE;function It(t){return Math.expm1(C(t))}function Q(t){return d(.5-Math.abs(t%2))}function dt(t,e){let n=-(e/2)*(e/2),s=1,r=0;for(let o=1;o<K&&(r+=s,s*=n/(o*(o+t)),!(Math.abs(s)<=y*Math.abs(r)));o++);return W(t,e,r+s)}function Vt(t,e){let n=Math.log(e/2),s=0,r=t>=170||709.78/t<Math.abs(n),o;if(r){let u=_(t);if(n=t*n,o=u-Math.log(Math.PI)-n,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,s=M}o=-Math.exp(o)}else{let u=q(t);n=Math.pow(e/2,t),Ut*n<u&&(u*=2**-1e3,s=1e3),o=-u/(Math.PI*n)}let a=-(e/2)*(e/2),i=1,c=0;for(let u=1;u<K&&(c+=i,i*=a/(u*(u-t)),!(Math.abs(i)<=y*Math.abs(c)));u++);let l=(c+i)*o,f;if(!r)f=q(-t)*Q(t)*n/Math.PI;else{let u=U(-t);f=Math.exp(u.value+n)*u.sign/Math.PI}i=1;let m=0;for(let u=1;u<K&&(m+=i,i*=a/(u*(u+t)),!(Math.abs(i)<=y*Math.abs(m)));u++);return m+=i,l-=A(f*m,-s),{m:l,e2:s}}function Xt(t,e){let n=1,s=0,r=1,o=8*e,a=1,i=4*t*t,c=1,l=!0;do{c*=(i-a*a)/(r*o),s+=c,r+=1,a+=2;let f=(a*a-i)/(r*o);l=Math.abs(f)<.5,c*=f,n+=c,r+=1,a+=2}while(Math.abs(c)>2*y*n&&l);return l?{p:n,q:s}:void 0}function Bt(t,e){let n=It(t),s=It(-t),r=d(t),o=d(t/2),a=Math.pow(e/2,t),i=Math.log(e/2),c=-i*t,l=Math.abs(c)<y?1:Math.sinh(c)/c,f=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,m=t===0?-.5772156649015329:(n-s)/((1+n)*(1+s)*2*t),u=(2+n+s)/((1+n)*(1+s)*2),M=Math.abs(t)<y?1/Math.PI:t/r,p=(m*Math.cosh(c)-u*i*l)*2*M,h=M/(a*(1+s)),S=M*a/(1+n),k=p+f*S,I=h,F=1,R=F*k,X=F*I,B=t*t,b=-e*e/4;for(let N=1;N<K&&(p=(N*p+h+S)/(N*N-B),h/=N-t,S/=N+t,k=p+f*S,I=h-N*k,F*=b/N,R+=F*k,X+=F*I,!(Math.abs(F*k)<Math.abs(R)*y));N++);return[-R,-2*X/e]}function Ot(t,e){let n=[g,0],s=[g,0],r=[0,0],o=1,a=[e,0];for(let i=1;i<K*100;i++){let c=E(t,i),l=O([2*c[0],2*c[1]],a);n=T(l,O([1,0],n)),r=T(l,r),n[0]===0&&(n=[g,0]),r[0]===0&&(r=[g,0]),r=O([1,0],r);let f=J(n,r);if(s=J(s,f),r[0]<0&&(o=-o),Math.abs(f[0]-1+f[1])<y*y)break}return{fv:-(s[0]+s[1]),sign:o}}function yt(t,e){if(e>30)return Ot(t,e);let n=g,s=g,r=0,o=1;for(let a=1;a<K*100;a++){let i=2*(t+a)/e;n=i-1/n,r=i-r,n===0&&(n=g),r===0&&(r=g),r=1/r;let c=n*r;if(s*=c,r<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-s,sign:o}}function Pt(t,e){let n=-.5/e,s=1,r=n,o=s,a=t*t,i=(.25-a)/e,c=2*e,l=2,f=r*r+1;o=l+i*r/f,r=c+i/f;let m=c,u=l;Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f;let M=r*m-o*u,p=o*m+r*u;f=n,n=f*M-s*p,s=f*p+s*M;for(let h=2;h<K&&(i=h-.5,i*=i,i-=a,l+=2,f=r*r+o*o,r=c+i*r/f,o=l-i*o/f,m=c+i*m,u=l+i*u,Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f,M=r*m-o*u,p=o*m+r*u,f=n,n=f*M-s*p,s=f*p+s*M,!(Math.abs(M-1)+Math.abs(p)<2*y));h++);return{p:n,q:s}}function Zt(t,e){let n=1,s=4*t*t,r=2*e;return r*=r,n+=(s-1)/(2*r),n+=3*(s-1)*(s-9)/(r*r*8),n+=15*(s-1)*(s-9)*(s-25)/(r*r*r*8*6),Math.sqrt(n*2/(Math.PI*e))}function Gt(t,e){let n=4*t*t,s=4*e,r=s*s,o=0;return o+=(n-1)/(2*s),s*=r,o+=(n-1)*(n-25)/(6*s),s*=r,o+=(n-1)*(n*n-114*n+1073)/(5*s),s*=r,o+=(n-1)*(5*n*n*n-1535*n*n+54703*n-375733)/(14*s),o}function Wt(t,e){let n=Zt(t,e),s=Gt(t,e),r=Math.cos(e),o=Math.sin(e),a=Q(t/2+.25),i=d(t/2+.25),c=Math.sin(s),l=Math.cos(s),f=(c*(r*a+o*i)+l*(o*a-r*i))*n;return{j:(l*(r*a+o*i)-c*(o*a-r*i))*n,y:f}}function tt(t,e,n){let s=Math.round(t),r=t-s,o=2/(e*Math.PI);if(!n&&(e<5||t>e*e/4))return{j:dt(t,e),y:{m:NaN,e2:0}};if(e<1&&r!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:dt(t,e),y:Vt(t,e)};if(Math.max(t,1)<e*.011048543456039806){let b=Wt(t,e);return{j:b.j,y:{m:b.y,e2:0}}}if(e>8){let b=Xt(t,e);if(b!==void 0){let N=(t/2+.25)%2,P=Math.sin(e),w=Math.cos(e),Y=d(N),rt=Q(N),st=P*rt-Y*w,ot=w*rt+P*Y,it=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:it*(b.p*ot-b.q*st),y:{m:it*(b.p*st+b.q*ot),e2:0}}}}if(e<=2){let[b,N]=Bt(r,e),P=gt(r,e,s,b,N),{fv:w}=yt(t,e);return{j:A(o/(P.y*w-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let{fv:a,sign:i}=yt(t,e);if(e>=t&&t>2){let{p:b,q:N}=Pt(t,e),P=t/e-a,w=(b-P)/N;w===0&&(w=t*y/e);let Y=i*Math.sqrt(o/(N+w*(b-P)));return{j:Y,y:{m:w*Y,e2:0}}}let c=g,l=a*i*c,f=i*c,m=0;for(let b=s;b>0;b--){let N=2*(r+b)/e;Math.abs(f)>2**900&&(l*=2**-900,f*=2**-900,m+=900);let P=N*f-l;P===0&&(P=l*y/2),l=f,f=P}let u=A(i*c/f,-m),M=l/f,{p,q:h}=Pt(r,e),S=r/e-M,k=(p-S)/h;k===0&&(k=r*y/e);let I=Math.sign(f)*Math.sqrt(o/(h+k*(p-S))),F=I*u,R=k*I,X=R*(r/e-p-h/k);if(!n)return{j:F,y:{m:NaN,e2:0}};let B=gt(r,e,s,R,X);return{j:F,y:{m:B.y,e2:B.e2}}}function Ht(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:s?d(n)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!s){let o=tt(n,t,!1).j;return e<0&&n%2===1?-o:o}let r=tt(n,t,!0);return Q(n)*r.j-A(d(n)*r.y.m,r.y.e2)}function $t(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0;if(t===0){if(!s)return-1/0;let i=Q(n);return i===0?0:i>0?-1/0:1/0}if(t===1/0)return 0;let r=tt(n,t,!0);if(!s)return A(r.y.m,r.y.e2);let o=Q(n),a=d(n);return(a!==0?a*r.j:0)+(o===0?0:A(o*r.y.m,r.y.e2))}function zt(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let n=_(e),s=q(e),r=l=>{let f=v(e,t,l,!1),m=s*f;if(Number.isFinite(s)&&f>kt&&Number.isFinite(m)&&m>kt)return[m,Math.log(m)];let u=n+v(e,t,l,!0);return u<710&&u>-746&&t>0&&(l?t<e:t>e)?vt(t,e,l):[Math.exp(u),u]},[o,a]=r(!0),[i,c]=r(!1);return{lower:o,upper:i,logLower:a,logUpper:c}}var kt=22250738585072014e-324;function vt(t,e,n){let s=j(at(L([t,0]),e),[-t,0]);n?s=j(s,L([mt(e,t)/e,0])):s=j(s,L([ut(e,t),0]));let r=s[0]+s[1];return[s[0]>-708?Math.exp(s[0])*(1+s[1]):Math.exp(r),r]}function et(t){return Number.isNaN(t)||t<0||t>2?NaN:-ft(t/2)*Math.SQRT1_2}function xt(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,n=Math.abs(t);if(n>=.5)return e*et(1-n);if(n<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let s=et(1-n);for(let r=0;r<3;r++){let o=($(s)-n)/(1.1283791670955126*Math.exp(-s*s));if(s-=o,Math.abs(o)<=1e-17*s)break}return e*s}function te(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let n=e===Math.floor(e);return t===Math.floor(t)&&n&&e>t?0:!Number.isFinite(t)||!Number.isFinite(e)?ie(t,e):n&&e<=1e3?ee(t,e):ne(t,e)}function ee(t,e){let n=[1,0];for(let s=0;s<e;s++){let r=E(t,-s),o=n[0]*r[0];if(!Number.isFinite(o)){let a=Math.sign(o);for(let i=s+1;i<e;i++)t-i<0&&(a=-a);return a*(1/0)}n=Math.abs(n[0])>1e290||Math.abs(r[0])>1e290?[(n[0]+n[1])*(r[0]+r[1]),0]:J(n,r)}return n[0]+n[1]}function ne(t,e){let[n,s]=E(t,-e);if(n+1<=0)return re(t,n,s);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let r;if(n>=15){if(e*Math.log(n+1)>720)return 1/0;let o=E(t,-n),a=T(J(o,L([t,0])),ct(n,[t,0]));a=j(a,[Z(t)-Z(n),0]),r=Math.sqrt(t/n)*Math.exp(a[0])*(1+a[1])}else if(t<30)r=q(t+1)/q(n+1);else{if(_(t+1)-_(n+1)>720)return 1/0;let o=T(nt(t+1),L([q(n+1),0]));r=Math.exp(o[0])*(1+o[1])}return s!==0&&Number.isFinite(r)&&r!==0&&(r*=Math.exp(-s*G(n+1))),r}function re(t,e,n){let s=j(E(e,1),[n,0]),r=d(s[0])+d(s[0]+.5)*Math.PI*s[1];if(r===0)return 0;let o=Math.sign(r),a=j(T(L([Math.abs(r),0]),oe),[-n*G(-e),0]);if(_(t+1)+_(-e)+a[0]>720)return o*(1/0);let i=j(j(nt(t+1),nt(-e)),a);return o*Math.exp(i[0])*(1+i[1])}var se=[.9189385332046728,-38782941580672414e-33],oe=[1.1447298858494002,10265951162707826e-33];function nt(t){if(t<15)return L([q(t),0]);let e=T(J(E(t,-.5),L([t,0])),[t,0]);return j(j(e,se),[Z(t),0])}function ie(t,e){let n=U(t+1),s=U(t-e+1);return n.sign*s.sign*Math.exp(n.value-s.value)}function ae(t){return Number.isNaN(t)||t<-1?NaN:t===-1||t===1/0?-1/0:lt(t)}function fe(t){return Number.isNaN(t)||t===-1/0?NaN:t===1/0||t<=-1&&t===Math.floor(t)?1/0:C(t)}function ce(t){return Number.isNaN(t)||t<0?NaN:t===0?-1/0:t===1/0?0:ht(-t)}function le(t){return Number.isNaN(t)?NaN:t<=-37?Math.exp(t):t<=18?Math.log1p(Math.exp(t)):t<=33.3?t+Math.exp(-t):t}export{Ct as besselI,Ht as besselJ,Qt as besselK,$t as besselY,Dt as beta,wt as choose,G as digamma,$ as erf,qt as erfc,et as erfcinv,xt as erfinv,_t as factorial,q as gamma,zt as gammainc,Ft as lbeta,Lt as lchoose,Et as lfactorial,_ as lgamma,fe as lgamma1p,ce as log1mexp,le as log1pexp,ae as log1pmx,te as perm,jt as psigamma,St as trigamma};
package/dist/tests.js CHANGED
@@ -1,3 +1,4 @@
1
- /*! rStats.js 0.8.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{$ as qt,B as At,C as it,G as ut,H as Bt,M as ht,N as Me,R as pt,S as ye,W as ve,X as xe,Y as Ee,_ as Rt,c as K,d as Ot,l as _t,m as at,r as G,s as wt,x as $t}from"./chunks/chunk-JERGQKZM.js";import{h as ke,k as Ie,l as Se,t as Le,y as Ve}from"./chunks/chunk-JVYV4633.js";import{a as V,b as kt,c as X,f as cn}from"./chunks/chunk-U633VFH3.js";import{k as W,l as ot}from"./chunks/chunk-LXMMKO26.js";import{c as Te}from"./chunks/chunk-SPQC445Q.js";import"./chunks/chunk-32PRRONF.js";import{a as Nt,b as Z,c as U,e as Ae,f as $,g as lt,h as ct,i as Tt}from"./chunks/chunk-VIPSPG3Y.js";import{a as Re,d as qe}from"./chunks/chunk-XU4BGFZ6.js";import{b as be}from"./chunks/chunk-MJQLKEO5.js";import{g as P,h as F,s as Ne}from"./chunks/chunk-3I6EKGB6.js";import{b as zt,c as vt,d as C,e as ge,f as Q,g as xt,i as Et,k as we}from"./chunks/chunk-OHPHNE3O.js";function Ht(e,t,o={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?o=t:n=t;let r=V(o.alternative),s=o.mu??0,a=o.paired??!1,l=o.varEqual??!1,i=o.confLevel??.95;if(Number.isNaN(s))throw new RangeError("mu must be a number");if(kt(i),a&&n===void 0)throw new TypeError("y is required when paired is true");let f=Array.from(e),c=n===void 0?void 0:Array.from(n);if(a){let[E,R]=Tt(f,c);f=E.map((k,v)=>k-R[v]),c=void 0}else f=ct(f),c!==void 0&&(c=ct(c));let m,u,h,p,M,d,b,w=f.length;if(w<2)throw new Error("not enough 'x' observations");let g=Z(f),N=U(f);if(c===void 0){if(u=w-1,h=Math.sqrt(N/w),h<10*Number.EPSILON*Math.abs(g))throw new Error("data are essentially constant");m=(g-s)/h,d=a?"Paired t-test":"One Sample t-test",p=g,M=a?"mean difference":"mean of x",b=a?"mean difference":"mean"}else{let E=c.length;if(E<1||!l&&E<2)throw new Error("not enough 'y' observations");if(l&&w+E<3)throw new Error("not enough observations");let R=Z(c),k=U(c);if(d=`${l?"":"Welch"} Two Sample t-test`,p=[g,R],M=["mean of x","mean of y"],b="difference in means",l){u=w+E-2;let v=0;w>1&&(v+=(w-1)*N),E>1&&(v+=(E-1)*k),v/=u,h=Math.sqrt(v*(1/w+1/E))}else{let v=N/w,q=k/E;h=Math.sqrt(v+q),u=(h*h)**2/(v*v/(w-1)+q*q/(E-1))}if(h<10*Number.EPSILON*Math.max(Math.abs(g),Math.abs(R)))throw new Error("data are essentially constant");m=(g-R-s)/h}let y,x;if(r==="less")y=W(m,u,!0,!1),x=[-1/0,m+ot(i,u,!0,!1)];else if(r==="greater")y=W(m,u,!1,!1),x=[m-ot(i,u,!0,!1),1/0];else{y=2*W(-Math.abs(m),u,!0,!1);let E=1-i,R=ot(1-E/2,u,!0,!1);x=[m-R,m+R]}return x=[s+x[0]*h,s+x[1]*h],{method:d,alternative:r,statistic:m,statisticName:"t",parameter:u,parameterName:"df",pValue:y,confInt:x,confLevel:i,estimate:p,estimateNames:M,nullValue:s,nullValueName:b,stdErr:h}}function bt(e){return` with simulated p-value
3
- (based on ${fn(e)} replicates)`}function fn(e){if(!Number.isFinite(e)||e===0)return String(e);let t=e.toExponential(14).replace(/\.?0+e/,"e"),[o,n]=t.split("e"),r=Number(n),s=`${o}e${r<0?"-":"+"}${String(Math.abs(r)).padStart(2,"0")}`,a=String(Number(e.toPrecision(15)));return a.length<=s.length?a:s}function J(e){let t=[0,0],o=0;for(let n of e)t=C(t,[n,0]),o+=n;return Number.isFinite(o)?t[0]:o}function mn(e,t,o){return Array.isArray(t)?un(e,t,o??{}):hn(e,t??{})}var Fe=(e,t)=>e<t?-1:e>t?1:0;function un(e,t,o){if(e.length!==t.length)throw new RangeError("'x' and 'y' must have the same length");let n=u=>u==null;for(let u of[...e,...t])if(!n(u)&&typeof u!="string")throw new TypeError("factor values must be strings (or null for missing values)");let r=[],s=[];e.forEach((u,h)=>{let p=t[h];!n(u)&&!n(p)&&(r.push(u),s.push(p))});let a=[...new Set(r)].sort(Fe),l=[...new Set(s)].sort(Fe);if(a.length<2||l.length<2)throw new RangeError("'x' and 'y' must have at least 2 levels");let i=new Map(a.map((u,h)=>[u,h])),f=new Map(l.map((u,h)=>[u,h])),c=a.map(()=>l.map(()=>0));return r.forEach((u,h)=>c[i.get(u)][f.get(s[h])]++),{...Oe(c,o),rowLevels:a,colLevels:l}}function hn(e,t){if(e.length>0&&typeof e[0]!="number"){let n=e.map(s=>Array.from(s)),r=n[0].length;if(n.some(s=>s.length!==r))throw new TypeError("all rows of the matrix must have the same length");return n.length===1?Wt(n[0],t):r===1?Wt(n.map(s=>s[0]),t):Oe(n,t)}return Wt(Array.from(e),t)}function Ce(e){let t=e.B??2e3;if(!(t>=0&&t<2**31))throw new RangeError("'B' must be a non-negative number");return t}function Pe(e,t,o){let n=(1-64*Number.EPSILON)*t,r=0;for(let s=0;s<e.length;s++)e[s]>=n&&r++;return(1+r)/(o+1)}function je(e,t){return Number.isNaN(e)?NaN:K(e,t/2,2,!1,!1)}function ze(e){if(!e.some(t=>t<5)&&e.some(Number.isNaN))throw new RangeError("missing value where TRUE/FALSE needed (the expected counts contain NaN)")}function Wt(e,t){let o=e.length;if(e.some(m=>Number.isNaN(m)||m<0))throw new RangeError("all entries of 'x' must be non-negative and finite");if(o<2)throw new TypeError("'x' must have at least 2 elements");let n=J(e);if(!(n>0))throw new RangeError("at least one entry of 'x' must be positive");let r=t.p===void 0?e.map(()=>1/o):Array.from(t.p);if(r.length!==o)throw new TypeError("'x' and 'p' must have the same number of elements");if(r.some(Number.isNaN))throw new RangeError("p contains missing values");if(r.some(m=>m<0))throw new RangeError("probabilities must be non-negative");if(t.rescaleP??!1){let m=J(r);r=r.map(u=>u/m)}else if(Math.abs(J(r)-1)>Math.sqrt(Number.EPSILON))throw new RangeError("probabilities must sum to 1");let s=r.map(m=>n*m);ze(s);let a=r.map((m,u)=>s[u]*(1-m)),l=J(e.map((m,u)=>(m-s[u])**2/s[u])),i="Chi-squared test for given probabilities",f=o-1,c;if(t.simulatePValue??!1){let m=Ce(t);i+=bt(m),f=NaN,c=Pe(pn(n,r,s,m),l,m)}else c=je(l,f);return{method:i,statistic:l,statisticName:"X-squared",parameter:f,parameterName:"df",pValue:c,observed:e,expected:s,residuals:e.map((m,u)=>(m-s[u])/Math.sqrt(s[u])),stdres:e.map((m,u)=>(m-s[u])/Math.sqrt(a[u]))}}function pn(e,t,o,n){let r=t.length,s=Ee(r,{size:Math.trunc(n*e),replace:!0,prob:t}),a=Math.trunc(e);if(s.length===0)return new Float64Array(0);if(a===0)throw new RangeError("invalid 'nrow' value (too large or NA)");let l=Math.ceil(s.length/a),i=new Float64Array(l),f=new Float64Array(r);for(let c=0;c<l;c++){f.fill(0);for(let u=0;u<a;u++)f[s[(c*a+u)%s.length]]++;let m=0;for(let u=0;u<r;u++)m+=(f[u]-o[u])**2/o[u];i[c]=m}return i}function dn(e,t,o,n){let r=e.length,s=t.length,a=e.reduce((c,m)=>c+m,0),l=Rt(a),i=new Int32Array(r*s),f=new Float64Array(Math.trunc(n));for(let c=0;c<f.length;c++){qt(e,t,l,i);let m=0;for(let u=0;u<s;u++)for(let h=0;h<r;h++){let p=o[h][u];m+=(i[h+u*r]-p)**2/p}f[c]=m}return f}function Oe(e,t){let o=t.correct??!0,n=e.length,r=e[0].length,s=e.flat();if(s.some(w=>!(w>=0&&w<1/0)))throw new RangeError("all entries of 'x' must be non-negative and finite");let a=J(s);if(!(a>0))throw new RangeError("at least one entry of 'x' must be positive");let l=e.map(w=>J(w)),i=e[0].map((w,g)=>J(e.map(N=>N[g]))),f=l.map(w=>i.map(g=>w*g/a));ze(f.flat());let c=e.map((w,g)=>w.map((N,y)=>N-f[g][y])),m="Pearson's Chi-squared test",u,h=(n-1)*(r-1),p,M=(t.simulatePValue??!1)&&l.every(w=>w>0)&&i.every(w=>w>0),d=!M&&o&&n===2&&r===2?Math.min(.5,...c.flat().map(Math.abs)):0;if(M){let w=Ce(t);m+=bt(w),u=J(c.flatMap((N,y)=>N.map((x,E)=>x*x/f[y][E]))),h=NaN;let g=dn(l.map(N=>Math.trunc(N)),i.map(N=>Math.trunc(N)),f,w);p=Pe(g,u,w)}else d>0?(m+=" with Yates' continuity correction",u=J(c.flatMap((w,g)=>w.map((N,y)=>(Math.abs(N)-d)**2/f[g][y])))):u=J(c.flatMap((w,g)=>w.map((N,y)=>N*N/f[g][y])));let b=f.map((w,g)=>w.map((N,y)=>N*(1-l[g]/a)*(1-i[y]/a)));return{method:m,statistic:u,statisticName:"X-squared",parameter:h,parameterName:"df",pValue:p??je(u,h),observed:e,expected:f,residuals:c.map((w,g)=>w.map((N,y)=>N/Math.sqrt(f[g][y]))),stdres:c.map((w,g)=>w.map((N,y)=>N/Math.sqrt(b[g][y])))}}var gn=Math.pow(Number.EPSILON,.25);function Y(e,t,o,n={}){let r={tol:n.tol??gn,maxiter:n.maxIter??1e3};return n.fLower!==void 0&&(r.fLower=n.fLower),n.fUpper!==void 0&&(r.fUpper=n.fUpper),Te(e,t,o,r).root}function wn(e,t={}){let o=e.length,n=o===0?0:e[0].length;if(e.some(i=>i.length!==n))throw new TypeError("all rows of the matrix must have the same length");if(o<2||n<2)throw new TypeError("'x' must have at least 2 rows and columns");let r=e.map(i=>Array.from(i));if(r.flat().some(i=>Number.isNaN(i)||i<0))throw new RangeError("all entries of 'x' must be non-negative and finite");if(r.flat().some(i=>i===1/0))throw new RangeError("'x' has entries too large to be integer");let s=r.map(i=>i.map(be)),a="Fisher's Exact Test for Count Data";if(o===2&&n===2)return yn(s,t,a);let l=t.alternative??"two.sided";if(t.simulatePValue??!1){let i=t.B??2e3;if(!(i>=0&&i<2**31))throw new RangeError("'B' must be a non-negative number");return{method:a+bt(i),alternative:l,pValue:Nn(s,i)}}return{method:a,alternative:l,pValue:vn(s)}}function Nn(e,t){let o=e.filter(M=>M.some(d=>d>0)),n=e[0].map((M,d)=>d).filter(M=>e.some(d=>d[M]>0));if(o.length<=1)throw new RangeError("need 2 or more non-zero row marginals");if(n.length<=1)throw new RangeError("need 2 or more non-zero column marginals");let r=o.map(M=>n.map(d=>M[d])),s=r.map(M=>M.reduce((d,b)=>d+b,0)),a=r[0].map((M,d)=>r.reduce((b,w)=>b+w[d],0)),l=s.length,i=a.length,f=[0,0];for(let M of r.flat())f=C(f,[-qe(M),0]);let c=f[0]/(1+64*Number.EPSILON),m=Rt(s.reduce((M,d)=>M+d,0)),u=new Int32Array(l*i),h=0,p=Math.trunc(t);for(let M=0;M<p;M++){qt(s,a,m,u);let d=0;for(let b=0;b<u.length;b++)d-=m[u[b]];d<=c&&h++}return Math.max(0,Math.min(1,(1+h)/(t+1)))}var bn=1+1e-7,Mn=16;function Dt(e,t,o){let n=[0,0];for(let r=Math.max(0,t);r<=Math.min(o,e.length-1);r++)e[r]!==0&&(n=C(n,[e[r],0]));return n[0]}var Ut=class{m;n;k;lo;hi;logCentral;constructor(t,o,n){this.m=t,this.n=o,this.k=n,this.lo=Math.max(0,n-o),this.hi=Math.min(n,t),this.logCentral=new Float64Array(this.hi-this.lo+1);let r=0,s=1;for(let a=this.lo;a<=this.hi;a++){let l=a-this.lo;l%Mn===0||!(s>0&&s<1/0)?(r=ut(a,t,o,n,!0),s=1,this.logCentral[l]=r):this.logCentral[l]=r+Math.log(s),s*=(t-a)*(n-a)/((a+1)*(o-n+a+1))}}density(t){let o=this.logCentral.length,n=Math.log(t),r=new Float64Array(o),s=-1/0;for(let l=0;l<o;l++){let i=this.logCentral[l]+(this.lo+l)*n;r[l]=i,i>s&&(s=i)}for(let l=0;l<o;l++){let i=r[l]-s;r[l]=i<-746?0:Math.exp(i)}let a=Dt(r,0,o-1);for(let l=0;l<o;l++)r[l]!==0&&(r[l]=r[l]/a);return r}mean(t){if(t===0)return this.lo;if(t===1/0)return this.hi;let o=this.density(t),n=[0,0];for(let r=0;r<o.length;r++)o[r]!==0&&(n=C(n,[(this.lo+r)*o[r],0]));return n[0]}tail(t,o,n){if(o===1)return n?Bt(t-1,this.m,this.n,this.k,!1,!1):Bt(t,this.m,this.n,this.k,!0,!1);if(o===0||o===1/0){let a=o===0?this.lo:this.hi;return(n?t<=a:t>=a)?1:0}let r=this.density(o),s=t-this.lo;return n?Dt(r,s,r.length-1):Dt(r,0,s)}};function Kt(e,t){return t?Y(e,0,1):1/Y(o=>e(1/o),Number.EPSILON,1)}function yn(e,t,o){let n=V(t.alternative),r=t.or??1;if(!(r>=0))throw new RangeError("'or' must be a single number between 0 and Inf");let s=t.confLevel??.95;if(!(s>0&&s<1))throw new RangeError("confLevel must be a single number between 0 and 1");let[[a,l],[i,f]]=e,c=a,m=new Ut(a+i,l+f,a+l),{lo:u,hi:h}=m,p;if(n==="less")p=m.tail(c,r,!1);else if(n==="greater")p=m.tail(c,r,!0);else if(r===0)p=c===u?1:0;else if(r===1/0)p=c===h?1:0;else{let N=m.density(r),y=N[c-u]*bn,x=[0,0];for(let E of N)E<=y&&(x=C(x,[E,0]));p=x[0]}let M;if(c===u)M=0;else if(c===h)M=1/0;else{let N=m.mean(1);M=N===c?1:Kt(y=>m.mean(y)-c,N>c)}let d={method:o,alternative:n,pValue:p,estimate:M,estimateNames:"odds ratio",nullValue:r,nullValueName:"odds ratio"};if(!(t.confInt??!0))return d;let b=N=>{if(c===h)return 1/0;let y=m.tail(c,1,!1);return y===N?1:Kt(x=>m.tail(c,x,!1)-N,y<N)},w=N=>{if(c===u)return 0;let y=m.tail(c,1,!0);return y===N?1:Kt(x=>m.tail(c,x,!0)-N,y>N)},g;if(n==="less")g=[0,b(1-s)];else if(n==="greater")g=[w(1-s),1/0];else{let N=(1-s)/2;g=[w(N),b(N)]}return{...d,confInt:g,confLevel:s}}var It=[[0,0]];function tt(e){for(let t=It.length;t<=e;t++)It.push(C(It[t-1],we([t,0])));return It[e]}function St(e,t,o,n){let r=e+o,s=r-e,a=e-(r-s)+(o-s)+t+n,l=r+a;return[l,a-(l-r)]}var Xt=class{scale=-1/0;hi=0;lo=0;add(t,o,n){if(t>this.scale){let i=Number.isFinite(this.scale)?Math.exp(this.scale-t):0;this.hi*=i,this.lo*=i,this.scale=t}let r=n*Math.exp(t-this.scale)*(1+o),s=this.hi+r,a=s-this.hi,l=this.hi-(s-a)+(r-a)+this.lo;this.hi=s+l,this.lo=l-(this.hi-s)}value(){return this.scale===-1/0?0:this.hi*Math.exp(this.scale)}};function vn(e){let t=e.filter(g=>g.some(N=>N>0));if(t.length===0)throw new RangeError("all entries of the table are zero");let o=t[0].map((g,N)=>t.some(y=>y[N]>0));if(t=t.map(g=>g.filter((N,y)=>o[y])),t.length<2||t[0].length<2)return 1;t.length>t[0].length&&(t=t[0].map((g,N)=>t.map(y=>y[N])));let n=t.length,r=t.map(g=>g.reduce((N,y)=>N+y,0)),s=t[0].map((g,N)=>t.reduce((y,x)=>y+x[N],0)).sort((g,N)=>N-g),a=s.length,l=r.reduce((g,N)=>g+N,0),i=ge(tt(l));for(let g of r)i=C(i,tt(g));for(let g of s)i=C(i,tt(g));let f=[0,0];for(let g of t.flat())f=Q(f,tt(g));let c=C(f,[Math.log1p(1e-7),0]),m=1e-9*(1+Math.abs(c[0])),[u,h]=c,p=Array.from({length:a},()=>new Map),M=(g,N)=>{let y=N.join(","),x=p[g].get(y);if(x!==void 0)return x;let E=C(i,tt(N.reduce((A,L)=>A+L,0)));for(let A of N)E=Q(E,tt(A));for(let A=g;A<a;A++)E=Q(E,tt(s[A]));let R={R:N,KZ:E,max:0,min:0,edges:[],pastHi:[],pastLo:[],count:[],index:new Map};if(p[g].set(y,R),g===a-1){let A=[0,0];for(let L of N)A=Q(A,tt(L));return R.max=R.min=A[0],R.edges.push({to:R,hi:A[0],lo:A[1],mult:1}),R}let k=new Map,v=new Array(n+1).fill(0);for(let A=n-1;A>=0;A--)v[A]=v[A+1]+N[A];let q=new Array(n).fill(0),I=(A,L,j)=>{if(A===n-1){q[A]=L;let O=Q(j,tt(L)),et=N.map((rt,dt)=>rt-q[dt]).sort((rt,dt)=>rt-dt),B=M(g+1,et),D=`${et.join(",")}|${O[0]}`,nt=k.get(D);nt===void 0?k.set(D,{to:B,hi:O[0],lo:O[1],mult:1}):nt.mult++;return}let z=Math.max(0,L-v[A+1]),H=Math.min(N[A],L);for(let O=z;O<=H;O++)q[A]=O,I(A+1,L-O,Q(j,tt(O)))};if(I(0,s[g],[0,0]),R.edges=[...k.values()],R.max=Math.max(...R.edges.map(A=>A.hi+A.to.max)),R.min=Math.min(...R.edges.map(A=>A.hi+A.to.min)),g===a-2){let A=R.edges.map(B=>{let D=B.to.edges[0];return{v:C([B.hi,B.lo],[D.hi,D.lo]),mult:B.mult}});A.sort((B,D)=>B.v[0]-D.v[0]||B.v[1]-D.v[1]);let L=A.length,j=A[L-1].v[0],z=new Float64Array(L),H=new Float64Array(L),O=new Float64Array(L),et=[0,0];A.forEach(({v:B,mult:D},nt)=>{z[nt]=B[0],H[nt]=B[1];let rt=Q(B,[j,0]);et=C(et,[D*Math.exp(rt[0])*(1+rt[1]),0]),O[nt]=et[0]}),R.dist={hi:z,lo:H,cum:O,vmax:j,kv:C(i,[j,0])}}return R},d=M(0,[...r].sort((g,N)=>g-N)),b=new Xt,w=(g,N,y,x)=>{if(N+g.max<=u-m){let[I,A]=St(g.KZ[0],g.KZ[1],N,y);return b.add(I,A,x),!0}if(N+g.min>u+m)return!0;let E=g.dist;if(E===void 0)return!1;let[R,k]=St(u,h,-N,-y),v=0,q=E.hi.length;for(;v<q;){let I=v+q>>>1,A=E.hi[I];A<R||A===R&&E.lo[I]<=k?v=I+1:q=I}if(v>0){let[I,A]=St(E.kv[0],E.kv[1],N,y);b.add(I,A,x*E.cum[v-1])}return!0};w(d,0,0,1)||(d.pastHi.push(0),d.pastLo.push(0),d.count.push(1));for(let g=0;g<a-2;g++)for(let N of p[g].values()){let{pastHi:y,pastLo:x,count:E}=N;if(E.length!==0){for(let{to:R,hi:k,lo:v,mult:q}of N.edges)for(let I=0;I<E.length;I++){let[A,L]=St(y[I],x[I],k,v),j=E[I]*q;if(w(R,A,L,j))continue;let z=R.index.get(A);z===void 0?(R.index.set(A,R.count.length),R.pastHi.push(A),R.pastLo.push(L),R.count.push(j)):R.count[z]+=j}N.pastHi=N.pastLo=N.count=[],N.index.clear()}}return Math.min(1,b.value())}function Yt(e,t,o={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?o=t:n=t;let r=V(o.alternative),s=o.mu??0,a=o.paired??!1,l=o.exact??null,i=o.correct??!0,f=o.confInt??!1,c=o.confLevel??.95,m=o.tolRoot??1e-4;if(!Number.isFinite(s))throw new RangeError("mu must be a single finite number");if(f&&!(c>0&&c<1))throw new RangeError("confLevel must be a number strictly between 0 and 1");if(a&&n===void 0)throw new TypeError("y is required when paired is true");let u,h;if(a){let[M,d]=Tt(Array.from(e),Array.from(n));u=ct(M.map((b,w)=>b-d[w]))}else u=ct(Array.from(e)),n!==void 0&&(h=ct(Array.from(n)));if(u.length<1)throw new Error("not enough (non-missing) 'x' observations");if(h!==void 0&&h.length<1)throw new Error("not enough (non-missing) 'y' observations");let p={alternative:r,mu:s,correct:i,confInt:f,confLevel:c,tolRoot:m};return h===void 0?En(u,l,a,p):qn(u,h,l,p)}function Lt(e,t,o){return o?t==="two.sided"?Math.sign(e)*.5:t==="greater"?.5:-.5:0}function $e(e,t){return t==="less"?P(e):t==="greater"?P(e,{lowerTail:!1}):2*Math.min(P(e),P(e,{lowerTail:!1}))}function xn(e){if(!(e>0)||!Number.isFinite(e))return e;let o=1-Math.floor(Math.log10(e)),n=o>=0?e*10**o:e/10**-o,r=Math.round(n);return r-n===.5&&r%2!==0&&(r-=1),o>=0?r/10**o:r*10**-o}function Qt(e){let t=e.length;if(t===0)return NaN;let o=Math.floor(t/2);return t%2===1?e[o]:Z([e[o-1],e[o]])}var Gt=(e,t)=>e-t;function Be(e){let t=e.length,o=$(e.map(Math.abs)),n=0;for(let a=0;a<t;a++)e[a]>0&&(n+=o[a]);let r=0;for(let a of lt(o))r+=a*a*a-a;let s=Math.sqrt(t*(t+1)*(2*t+1)/24-r/48);return[n,n-t*(t+1)/4,s]}function En(e,t,o,n){let{alternative:r,mu:s,correct:a}=n,l=e.map(x=>x-s),i=l.some(x=>x===0);i&&(l=l.filter(x=>x!==0));let f=l.length,c=t??f<50,m=$(l.map(Math.abs)),u=lt(m).length>0,[h,p,M]=Be(l),d,b,w=c&&!u&&!i;if(w){b="Wilcoxon signed rank exact test";let x=f*(f+1)/2;if(r==="less")d=ht(h,f,!0,!1);else if(r==="greater")d=ht(h-1,f,!1,!1);else{let E=h>x/2?ht(h-1,f,!1,!1):ht(h,f,!0,!1);d=Math.min(1,2*E)}}else b=`Wilcoxon signed rank test${a?" with continuity correction":""}`,d=$e((p-Lt(p,r,a))/M,r);let g={method:b,alternative:r,statistic:h,statisticName:"V",pValue:d,nullValue:s,nullValueName:o?"location shift":"location"};if(!n.confInt)return g;let N=l.map(x=>x+s),y=w?An(N,n):Rn(N,n);return{...g,...y}}function Vt(e,t,o){return e==="less"?[-1/0,o]:e==="greater"?[t,1/0]:[t,o]}function _e(e,t,o){let n={confInt:Vt(e,NaN,NaN),confLevel:0,estimate:t};return o!==void 0&&(n.estimateNames=o),n}function He(e,t,o){let n=e(t==="two.sided"?o/2:o);return n===0?1:n}function We(e){if(!(e>0))throw new RangeError("tolRoot must be positive")}function An(e,t){let{alternative:o,confLevel:n}=t,r=e.length,s=[];for(let m=0;m<r;m++)for(let u=m;u<r;u++)s.push((e[m]+e[u])/2);s.sort(Gt);let a=s.length,l=1-n,i=He(m=>Me(m,r,!0,!1),o,l),f=ht(i-1,r,!0,!1),c=o==="two.sided"?2*f:f;return{confInt:Vt(o,s[i-1],s[a-i]),confLevel:c-l>l/2?1-xn(c):n,estimate:Qt(s),estimateNames:"(pseudo)median"}}function Rn(e,t){let{alternative:o,correct:n,confLevel:r,tolRoot:s}=t,a=e.length;if(a===0)return _e(o,NaN);let l=Math.min(...e),i=Math.max(...e);if(!Number.isFinite(l)||!Number.isFinite(i)||a===1||l===i)return _e(o,(l+i)/2,"midrange");let f=(g,N)=>{let[,y,x]=Be(e.map(E=>E-g).filter(E=>E!==0));return(y-Lt(y,o,N))/x},c=f(l,n),m=f(i,n),u=g=>-F(g),h=g=>o==="greater"?!(c<u(g)):o==="less"?!(m>F(g/2)):!(c<u(g/2))&&!(m>F(g/2)),p=1-r,M=!1;for(;!h(p)&&p<1;)p*=2,M=!0;We(s);let d=g=>Y(N=>f(N,n)-g,l,i,{tol:s,fLower:c-g,fUpper:m-g}),b;if(p>=1){let g=Qt([...e].sort(Gt));b=Vt(o,g,g)}else o==="greater"?b=[d(u(p)),1/0]:o==="less"?b=[-1/0,d(F(p))]:b=[d(u(p/2)),d(F(p/2))];let w=Y(g=>f(g,!1),l,i,{tol:s,fLower:f(l,!1),fUpper:f(i,!1)});return{confInt:b,confLevel:M?1-Math.min(1,p):r,estimate:w,estimateNames:"(pseudo)median"}}function De(e,t){let o=e.length,n=t.length,r=$([...e,...t]),s=0;for(let c=0;c<o;c++)s+=r[c];let a=s-o*(o+1)/2,l=0;for(let c of lt(r))l+=c*c*c-c;let i=o+n,f=Math.sqrt(o*n/12*(i+1-l/(i*(i-1))));return[a,a-o*n/2,f]}function qn(e,t,o,n){let{alternative:r,mu:s,correct:a}=n,l=e.length,i=t.length,f=e.map(N=>N-s),c=o??(l<50&&i<50),m=lt([...f,...t]).length>0,[u,h,p]=De(f,t),M,d,b=c&&!m;if(b)if(d="Wilcoxon rank sum exact test",r==="less")M=pt(u,l,i,!0,!1);else if(r==="greater")M=pt(u-1,l,i,!1,!1);else{let N=u>l*i/2?pt(u-1,l,i,!1,!1):pt(u,l,i,!0,!1);M=Math.min(1,2*N)}else d=`Wilcoxon rank sum test${a?" with continuity correction":""}`,M=$e((h-Lt(h,r,a))/p,r);let w={method:d,alternative:r,statistic:u,statisticName:"W",pValue:M,nullValue:s,nullValueName:"location shift"};if(!n.confInt)return w;let g=b?Tn(e,t,n):kn(e,t,n);return{...w,...g}}function Tn(e,t,o){let{alternative:n,confLevel:r}=o,s=e.length,a=t.length,l=[];for(let h of e)for(let p of t)l.push(h-p);l.sort(Gt);let i=l.length,f=1-r,c=He(h=>ye(h,s,a,!0,!1),n,f),m=pt(c-1,s,a,!0,!1),u=n==="two.sided"?2*m:m;return{confInt:Vt(n,l[c-1],l[i-c]),confLevel:u-f>f/2?1-u:r,estimate:Qt(l),estimateNames:"difference in location"}}function kn(e,t,o){let{alternative:n,correct:r,confLevel:s,tolRoot:a}=o,l=Math.min(...e)-Math.max(...t),i=Math.max(...e)-Math.min(...t);if(!Number.isFinite(l)||!Number.isFinite(i))throw new Error("cannot compute the confidence interval because the differences are not finite");let f=(h,p)=>{let[,M,d]=De(e.map(b=>b-h),t);return(M-Lt(M,n,p))/d},c=(h,p)=>{let M=f(l,p)-h,d=f(i,p)-h;if(Number.isNaN(M)||Number.isNaN(d))throw new Error("cannot compute the confidence interval because all observations are tied");return M<=0?l:d>=0?i:(We(a),Y(b=>f(b,p)-h,l,i,{tol:a,fLower:M,fUpper:d}))},m=1-s,u;return n==="greater"?u=[c(-F(m),r),1/0]:n==="less"?u=[-1/0,c(F(m),r)]:u=[c(-F(m/2),r),c(F(m/2),r)],{confInt:u,confLevel:s,estimate:c(0,!1),estimateNames:"difference in location"}}var Ke=["holm","hochberg","hommel","bonferroni","BH","BY","fdr","none"];function In(e){if(Ke.includes(e))return e;let t=Ke.filter(o=>o.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function Zt(e,t={}){let o=typeof t=="string"?{method:t}:t,n=In(o.method??"holm"),r=Array.from(e),s=[];for(let m=0;m<r.length;m++)Number.isNaN(r[m])||s.push(m);let a=s.length,l=o.n??a;if(!(l>=a))throw new RangeError("n must be at least the number of non-NaN p-values");if(l<=1)return r;let i=s.map(m=>r[m]),f=Sn(i,n,l),c=r.slice();return s.forEach((m,u)=>c[m]=f[u]),c}function Ft(e,t){let o=e.map((n,r)=>r);return o.sort((n,r)=>(t?e[r]-e[n]:e[n]-e[r])||n-r),o}function Sn(e,t,o){let n=e.length,r=new Array(n);switch(t){case"none":return e.slice();case"bonferroni":return e.map(s=>Math.min(1,o*s));case"holm":{let s=Ft(e,!1),a=-1/0;return s.forEach((l,i)=>{a=Math.max(a,(o-i)*e[l]),r[l]=Math.min(1,a)}),r}case"hochberg":{let s=Ft(e,!0),a=1/0;return s.forEach((l,i)=>{let f=n-i;a=Math.min(a,(o-f+1)*e[l]),r[l]=Math.min(1,a)}),r}case"BH":case"fdr":case"BY":{let s=t==="BY"?Ae(Array.from({length:Math.floor(o)},(i,f)=>1/(f+1))):1,a=Ft(e,!0),l=1/0;return a.forEach((i,f)=>{let c=n-f;l=Math.min(l,s*o/c*e[i]),r[i]=Math.min(1,l)}),r}case"hommel":return Ln(e,o)}}function Ln(e,t){if(!Number.isInteger(t))throw new RangeError("n must be an integer for the hommel method");let o=e.length,n=[...e,...new Array(t-o).fill(1)],r=Ft(n,!1),s=r.map(i=>n[i]),a=s.slice();for(let i=t;i>=2;i--){let f=1/0;for(let c=1;c<=i;c++)f=Math.min(f,i*s[t-i+c-1]/c);for(let c=t-i;c<t;c++)a[c]=Math.max(a[c],f);for(let c=0;c<t-i;c++)a[c]=Math.max(a[c],Math.min(i*s[c],f))}let l=new Array(o);return r.forEach((i,f)=>{i<o&&(l[i]=a[f])}),l}var Vn=1+1e-7;function Ct(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7*Math.max(1,Math.abs(e))}function Fn(e,t,o){if(o===0)return e===0?1:0;if(o===1)return e===t?1:0;let n=t*o;if(e===n)return 1;let r=At(e,t,o,!1)*Vn,s=0;if(e<n){for(let i=Math.ceil(n);i<=t;i++)At(i,t,o,!1)<=r&&s++;let l=s===0?0:it(t-s,t,o,!1,!1);return Math.min(1,it(e,t,o,!0,!1)+l)}for(let l=0;l<=Math.floor(n);l++)At(l,t,o,!1)<=r&&s++;let a=s===0?0:it(s-1,t,o,!0,!1);return Math.min(1,it(e-1,t,o,!1,!1)+a)}function Jt(e,t,o={}){let n,r;if(typeof e!="number"){if(e.length!==2)throw new RangeError("incorrect length of 'x'");if(t!==void 0&&typeof t!="number"&&(o=t),!Ct(e[0])||!Ct(e[1]))throw new RangeError("'x' must be nonnegative and integer");n=Math.round(e[0]),r=Math.round(e[0])+Math.round(e[1])}else{if(typeof t!="number")throw new TypeError("'n' is required when 'x' is a single number");if(!Ct(e))throw new RangeError("'x' must be nonnegative and integer");if(n=Math.round(e),!(Ct(t)&&Math.round(t)>=n&&t>0))throw new RangeError("'n' must be a positive integer >= 'x'");r=Math.round(t)}let s=o.p??.5;if(!(s>=0&&s<=1))throw new RangeError("'p' must be a single number between 0 and 1");let a=V(o.alternative),l=o.confLevel??.95;X(l);let i;a==="less"?i=it(n,r,s,!0,!1):a==="greater"?i=it(n-1,r,s,!1,!1):i=Fn(n,r,s);let f=u=>n===0?0:$t(u,n,r-n+1,!0,!1),c=u=>n===r?1:$t(1-u,n+1,r-n,!0,!1),m;if(a==="less")m=[0,c(1-l)];else if(a==="greater")m=[f(1-l),1];else{let u=(1-l)/2;m=[f(u),c(u)]}return{method:"Exact binomial test",alternative:a,statistic:n,statisticName:"number of successes",parameter:r,parameterName:"number of trials",pValue:i,confInt:m,confLevel:l,estimate:n/r,estimateNames:"probability of success",nullValue:s,nullValueName:"probability of success"}}var Cn=1+1e-7;function Pn(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7*Math.max(1,Math.abs(e))}function jn(e,t){if(t===0)return e===0?1:0;if(e===t)return 1;let o=_t(e,t,!1)*Cn,n=l=>_t(l,t,!1)<=o,r=Math.floor(t);if(e<t){let l=Math.max(e+1,r),i=l;if(!n(l)){let f=l,c=1;for(i=l+1;!n(i);)f=i,c*=2,i=l+c;for(;i-f>1;){let m=f+Math.floor((i-f)/2);n(m)?i=m:f=m}}return Math.min(1,at(e,t,!0,!1)+at(i-1,t,!1,!1))}let s=Math.min(e-1,r),a;if(!n(0))a=-1;else if(n(s))a=s;else{a=0;let l=s;for(;l-a>1;){let i=a+Math.floor((l-a)/2);n(i)?a=i:l=i}}return Math.min(1,at(a,t,!0,!1)+at(e-1,t,!1,!1))}function zn(e,t={}){let o=typeof e=="number"?[e]:Array.from(e);if(o.length<1||o.length>2)throw new RangeError("incorrect length of 'x'");if(!o.every(Pn))throw new RangeError("'x' must be finite, nonnegative, and integer");let n=o.map(Math.round),r=n.length,s=t.T??1,a=typeof s=="number"?new Array(r).fill(s):Array.from(s);if(a.length!==r)throw new RangeError("'x' and 'T' have incompatible length");if(!a.every(b=>Number.isFinite(b)&&b>=0))throw new RangeError("'T' must be nonnegative");let l=t.r??1;if(!(Number.isFinite(l)&&l>=0))throw new RangeError("'r' must be a single positive number");let i=V(t.alternative),f=t.confLevel??.95;if(X(f),r===2){let[b,w]=n,[g,N]=a,y=b+w,x=l*g/(l*g+N),E=Jt([b,w],{p:x,alternative:i,confLevel:f}),R=k=>k/(1-k)*(N/g);return{method:"Comparison of Poisson rates",alternative:i,statistic:b,statisticName:"count1",parameter:y*l*g/(g+l*N),parameterName:"expected count1",pValue:E.pValue,confInt:[R(E.confInt[0]),R(E.confInt[1])],confLevel:f,estimate:b/g/(w/N),estimateNames:"rate ratio",nullValue:l,nullValueName:"rate ratio"}}let c=n[0],m=a[0],u=l*m,h;i==="less"?h=at(c,u,!0,!1):i==="greater"?h=at(c-1,u,!1,!1):h=jn(c,u);let p=b=>c===0?0:Ot(b,c,1,!0,!1),M=b=>Ot(1-b,c+1,1,!0,!1),d;if(i==="less")d=[0,M(1-f)];else if(i==="greater")d=[p(1-f),1/0];else{let b=(1-f)/2;d=[p(b),M(b)]}return{method:"Exact Poisson test",alternative:i,statistic:c,statisticName:"number of events",parameter:m,parameterName:"time base",pValue:h,confInt:[d[0]/m,d[1]/m],confLevel:f,estimate:c/m,estimateNames:"event rate",nullValue:l,nullValueName:"event rate"}}function te(e,t,o={}){let n,r,s=o;if(typeof e!="number"&&e.length>0&&Array.isArray(e[0])){let v=e;if(v.some(q=>q.length!==2))throw new RangeError("'x' must have 2 columns");n=v.map(q=>q[0]),r=v.map(q=>q[0]+q[1]),t!==void 0&&typeof t=="object"&&!Array.isArray(t)&&(s=t)}else{if(t===void 0||typeof t=="object"&&!Array.isArray(t))throw new RangeError("'n' must be given");n=typeof e=="number"?[e]:Array.from(e),r=typeof t=="number"?[t]:Array.from(t)}if(n.length!==r.length)throw new RangeError("'x' and 'n' must have the same length");let a=n.length,l=[];for(let v=0;v<a;v++)!Number.isNaN(n[v])&&!Number.isNaN(r[v])&&l.push(v);let i=l.length;if(i<1)throw new RangeError("not enough data");if(n=l.map(v=>n[v]),r=l.map(v=>r[v]),r.some(v=>!(v>0)))throw new RangeError("elements of 'n' must be positive");if(n.some(v=>!(v>=0)))throw new RangeError("elements of 'x' must be nonnegative");if(n.some((v,q)=>v>r[q]))throw new RangeError("elements of 'x' must not be greater than those of 'n'");let f;if(s.p!==void 0){let v=typeof s.p=="number"?[s.p]:Array.from(s.p);if(v.length!==a)throw new RangeError("'p' must have the same length as 'x' and 'n'");if(f=l.map(q=>v[q]),f.some(q=>!(q>0&&q<1)))throw new RangeError("elements of 'p' must be in (0,1)")}let c=f!==void 0;i===1&&f===void 0&&(f=[.5]);let m=s.confLevel??.95;X(m);let u=V(s.alternative);(i>2||i===2&&c)&&(u="two.sided");let h=n.map((v,q)=>v/r[q]),p=i===2?h[0]-h[1]:0,M=i===2?1/r[0]+1/r[1]:0,d=(s.correct??!0)&&i<=2?.5:0,b=!1;if(d>0&&i===1){let v=Math.abs(n[0]-r[0]*f[0]);v<=d&&([d,b]=[v,!0])}else if(d>0&&i===2&&!c){let v=Math.abs(p)/M;v<=d&&([d,b]=[v,!0])}let w=n.reduce((v,q)=>v+q,0)/r.reduce((v,q)=>v+q,0),g=0;if(!b)for(let v=0;v<i;v++){let q=f?.[v]??w,I=r[v]*q,A=r[v]*(1-q);g+=(Math.abs(n[v]-I)-d)**2/I,g+=(Math.abs(r[v]-n[v]-A)-d)**2/A}let N=f!==void 0?i:i-1,y;if(u==="two.sided")y=K(g,N/2,2,!1,!1);else{let v=Math.sign(i===1?h[0]-f[0]:p);y=P(v*Math.sqrt(g),{lowerTail:u==="less"})}let x;if(i===1||i===2&&!c){let v=F(u==="two.sided"?(1+m)/2:m);if(i===1){let q=r[0],I=v*v,A=(O,et)=>(O+I/(2*q)+et*v*Math.sqrt(O*(1-O)/q+I/(4*q*q)))/(1+I/q),L=h[0]+d/q,j=h[0]-d/q,z=Math.min(1,Math.max(0,L>=1?1:A(L,1))),H=Math.min(1,Math.max(0,j<=0?0:A(j,-1)));x=u==="two.sided"?[H,z]:u==="greater"?[H,1]:[0,z]}else{let q=Math.sqrt(h.reduce((j,z,H)=>j+z*(1-z)/r[H],0)),I=v*q+d*M,A=Math.max(-1,p-I),L=Math.min(1,p+I);x=u==="two.sided"?[A,L]:u==="greater"?[A,1]:[-1,L]}}let E=i===1?"p":l.map(v=>`prop ${v+1}`),k={method:`${i===1?"1-sample proportions test":`${i}-sample test for ${c?"given proportions":"equality of proportions"}`} ${d!==0?"with":"without"} continuity correction`,alternative:u,statistic:g,statisticName:"X-squared",parameter:N,parameterName:"df",pValue:y,estimate:i===1?h[0]:h,estimateNames:E};return f!==void 0&&(k.nullValue=i===1?f[0]:f,k.nullValueName=E),x!==void 0&&(k.confInt=x,k.confLevel=m),k}function On(e,t,o={}){let n;if(e.length>0&&Array.isArray(e[0])){t!==void 0&&!Array.isArray(t)&&(o=t),n=e.map(c=>Array.from(c));let f=n.length;if(f<2||n.some(c=>c.length!==f))throw new RangeError("'x' must be square with at least two rows and columns");if(n.some(c=>c.some(m=>!Number.isFinite(m)||m<0)))throw new RangeError("all entries of 'x' must be nonnegative and finite")}else{if(!Array.isArray(t))throw new TypeError("'y' is required when 'x' is not a table");n=_n(e,t)}let r=o.correct??!0,s=n.length,a,l=r&&s===2&&n[0][1]!==n[1][0];if(l){let f=n[0][1],c=n[1][0];a=(Math.abs(f-c)-1)**2/(f+c)}else{a=0;for(let f=0;f<s;f++)for(let c=f+1;c<s;c++){let m=n[f][c],u=n[c][f];a+=(m-u)**2/(m+u)}}let i=s*(s-1)/2;return{method:l?"McNemar's Chi-squared test with continuity correction":"McNemar's Chi-squared test",statistic:a,statisticName:"McNemar's chi-squared",parameter:i,parameterName:"df",pValue:K(a,i/2,2,!1,!1)}}function _n(e,t){if(e.length!==t.length)throw new RangeError("'x' and 'y' must have the same length");let o=[];for(let f=0;f<e.length;f++){let c=e[f],m=t[f];typeof c=="number"&&Number.isNaN(c)||typeof m=="number"&&Number.isNaN(m)||o.push([c,m])}let n=f=>Array.from(new Set(f)).sort((c,m)=>typeof c=="number"&&typeof m=="number"?c-m:String(c)<String(m)?-1:String(c)>String(m)?1:0),r=n(o.map(f=>f[0])),s=n(o.map(f=>f[1]));if(r.length<2||r.length!==s.length)throw new RangeError("'x' and 'y' must have the same number of levels (minimum 2)");let a=new Map(r.map((f,c)=>[f,c])),l=new Map(s.map((f,c)=>[f,c])),i=r.map(()=>new Array(r.length).fill(0));for(let[f,c]of o)i[a.get(f)][l.get(c)]++;return i}function $n(e,t,o={}){let n=Array.from(e).filter(Number.isFinite),r=Array.from(t).filter(Number.isFinite),s=o.ratio??1;if(!(Number.isFinite(s)&&s>0))throw new RangeError("'ratio' must be a single positive number");let a=V(o.alternative),l=o.confLevel??.95;X(l);let i=n.length-1,f=r.length-1;if(i<1)throw new Error("not enough 'x' observations");if(f<1)throw new Error("not enough 'y' observations");let c=U(n)/U(r),m=c/s,u=G(m,i,f,!0,!1),h=G(m,i,f,!1,!1),p,M;if(a==="less")p=u,M=[0,c/wt(1-l,i,f,!0,!1)];else if(a==="greater")p=h,M=[c/wt(l,i,f,!0,!1),1/0];else{p=Math.min(1,2*Math.min(u,h));let d=(1-l)/2;M=[c/wt(1-d,i,f,!0,!1),c/wt(d,i,f,!0,!1)]}return{method:"F test to compare two variances",alternative:a,statistic:m,statisticName:"F",parameter:[i,f],parameterName:["num df","denom df"],pValue:p,confInt:M,confLevel:l,estimate:c,estimateNames:"ratio of variances",nullValue:s,nullValueName:"ratio of variances"}}function Bn(e){let t=e.length;if(t<2)throw new RangeError("'x' must be a list with at least 2 elements");let o=[],n=[];for(let c of e){let m=Array.from(c).filter(Number.isFinite);if(m.length<2)throw new RangeError("there must be at least 2 observations in each group");o.push(m.length-1),n.push(U(m))}let r=0,s=0,a=0,l=0;for(let c=0;c<t;c++)r+=o[c],s+=o[c]*n[c],a+=o[c]*Math.log(n[c]),l+=1/o[c];s/=r;let i=(r*Math.log(s)-a)/(1+(l-1/r)/(3*(t-1))),f=t-1;return{method:"Bartlett test of homogeneity of variances",statistic:i,statisticName:"Bartlett's K-squared",parameter:f,parameterName:"df",pValue:K(i,f/2,2,!1,!1)}}function ee(e,t,o="drop"){if(t===void 0){let a=e;if(a.length>0&&typeof a[0]=="number")throw new TypeError("'g' is required when 'x' is a single sample");let l=a.map(c=>Array.from(c).filter(m=>!Number.isNaN(m)));if(o==="error"&&l.some(c=>c.length===0))throw new RangeError("all groups must contain data");let i=[],f=[];return l.forEach((c,m)=>{c.length!==0&&(i.push(String(m+1)),f.push(c))}),{labels:i,groups:f}}let n=Array.from(e);if(n.length!==t.length)throw new RangeError("'x' and 'g' must have the same length");let r=new Map;for(let a=0;a<n.length;a++){let l=n[a],i=t[a];if(Number.isNaN(l)||typeof i=="number"&&Number.isNaN(i))continue;let f=r.get(i);f===void 0&&r.set(i,f=[]),f.push(l)}let s=Array.from(r.keys()).sort((a,l)=>typeof a=="number"&&typeof l=="number"?a-l:String(a)<String(l)?-1:String(a)>String(l)?1:0);return{labels:s.map(String),groups:s.map(a=>r.get(a))}}function ft(e,t,o="drop"){return ee(e,t,o).groups}function Ue(e){let t=[...e].sort((n,r)=>n-r),o=t.length;return o%2===1?t[(o-1)/2]:(t[o/2-1]+t[o/2])/2}function ne(e){if(e.length===0)throw new RangeError("'y' must have at least one row");let t=e[0].length;if(e.some(o=>o.length!==t))throw new RangeError("all rows of 'y' must have the same length");return e.filter(o=>o.every(n=>!Number.isNaN(n))).map(o=>Array.from(o))}function re(e,t,o,n){return{method:e,statistic:o,statisticName:t,parameter:n,parameterName:"df",pValue:K(o,n/2,2,!1,!1)}}function Xe(e){let t=0;for(let o of lt(e))t+=o*o*o-o;return t}function Hn(e,t){let o=ft(e,t,"error"),n=o.length;if(n<2)throw new RangeError("all observations are in the same group");let r=o.flat(),s=r.length,a=$(r),l=0,i=0;for(let f of o){let c=0;for(let m=0;m<f.length;m++)c+=a[i+m];i+=f.length,l+=c*c/f.length}return l=(12*l/(s*(s+1))-3*(s+1))/(1-Xe(r)/(s*s*s-s)),re("Kruskal-Wallis rank sum test","Kruskal-Wallis chi-squared",l,n-1)}function Wn(e){let t=ne(e),o=t.length,n=e[0]?.length??0;if(o<2||n<2)throw new RangeError("'y' must have at least two complete rows and two columns");let r=new Array(n).fill(0),s=0;for(let i of t){let f=$(i);for(let c=0;c<n;c++)r[c]+=f[c];s+=Xe(i)}let a=0;for(let i of r)a+=(i-o*(n+1)/2)**2;let l=12*a/(o*n*(n+1)-s/(n-1));return re("Friedman rank sum test","Friedman chi-squared",l,n-1)}function Dn(e){let t=ne(e),o=e.length,n=e[0]?.length??0;if(t.length<2||n<2)throw new RangeError("'y' must have at least two complete rows and two columns");let r=$(t.map(h=>Math.max(...h)-Math.min(...h))),s=new Array(n).fill(0),a=0;t.forEach((h,p)=>{let M=$(h);for(let d=0;d<n;d++){let b=r[p]*(M[d]-(n+1)/2);a+=b*b,s[d]+=b}});let l=0;for(let h of s)l+=h*h;l/=o;let i=n-1,f=(o-1)*(n-1),c,m,u=[i,f];if(a===l){c=NaN,u=[NaN,NaN];let h=0;for(let p=2;p<=n;p++)h+=Math.log(p);m=Math.exp((1-o)*h)}else c=(o-1)*l/(a-l),m=G(c,i,f,!1,!1);return{method:"Quade test",statistic:c,statisticName:"Quade F",parameter:u,parameterName:["num df","denom df"],pValue:m}}function Kn(e,t){let o=ft(e,t,"error"),n=o.length;if(n<2)throw new RangeError("all observations are in the same group");let r=o.flatMap(u=>{let h=Ue(u);return u.map(p=>Math.abs(p-h))}),s=r.length,l=$(r).map(u=>F((1+u/(s+1))/2)),i=0;for(let u of l)i+=u;let f=i/s,c=0,m=0;for(let u of o){let h=0;for(let p=0;p<u.length;p++)h+=l[m+p];m+=u.length,c+=u.length*(h/u.length-f)**2}return c/=U(l),re("Fligner-Killeen test of homogeneity of variances","Fligner-Killeen:med chi-squared",c,n-1)}function Un(e,t,o={}){let n=Array.from(e).filter(Number.isFinite),r=Array.from(t).filter(Number.isFinite),s=V(o.alternative),a=n.length,l=r.length,i=a+l;if(i<3)throw new RangeError("not enough observations");let f=n.concat(r),c=Array.from({length:i},(N,y)=>y).sort((N,y)=>f[N]-f[y]),m=new Array(i),u=0;for(;u<i;){let N=u;for(;N+1<i&&f[c[N+1]]===f[c[u]];)N++;let y=0;for(let x=u;x<=N;x++)y+=(x+1-(i+1)/2)**2;y/=N-u+1;for(let x=u;x<=N;x++)m[c[x]]=y;u=N+1}let h=0;for(let N=0;N<a;N++)h+=m[N];let p=0;for(let N of m)p+=N;p/=i;let M=0;for(let N of m)M+=(N-p)**2;let d=a*p,b=a*l/(i*(i-1))*M,w=(h-d)/Math.sqrt(b),g=s==="less"?P(w):s==="greater"?P(w,{lowerTail:!1}):2*P(-Math.abs(w));return{method:"Mood two-sample test of scale",alternative:s,statistic:w,statisticName:"Z",pValue:g}}function mt(e,t){let o=0;for(let n=e.length-1;n>=0;n--)o=o*t+e[n];return o}var Xn=[0,.221157,-.147981,-2.07119,4.434685,-2.706056],Yn=[0,.042981,-.293762,-1.752461,5.682633,-3.582633],Qn=[.544,-.39978,.025054,-6714e-7],Gn=[1.3822,-.77857,.062767,-.0020322],Zn=[-1.5861,-.31082,-.083751,.0038915],Jn=[-.4803,-.082676,.0030302],tr=[-2.273,.459];function er(e){if(!(e>=3)||e!==Math.floor(e))throw new RangeError("n must be an integer of at least 3");let t=new Float64Array(e);if(e===3)return t[0]=-Math.SQRT1_2,t[2]=Math.SQRT1_2,t;let o=Math.floor(e/2),n=new Float64Array(o),r=0;for(let m=0;m<o;m++)n[m]=-F((m+1-.375)/(e+.25)),r+=n[m]*n[m];r*=2;let s=Math.sqrt(r),a=1/Math.sqrt(e),l=n[0]/s+mt(Xn,a),i=new Float64Array(o);i[0]=l;let f,c;if(e>5){let m=n[1]/s+mt(Yn,a);i[1]=m,f=2,c=Math.sqrt((r-2*n[0]*n[0]-2*n[1]*n[1])/(1-2*l*l-2*m*m))}else f=1,c=Math.sqrt((r-2*n[0]*n[0])/(1-2*l*l));for(let m=f;m<o;m++)i[m]=n[m]/c;for(let m=0;m<o;m++)t[e-1-m]=i[m],t[m]=-i[m];return t}function Ye(e){let t=e.length,o=er(t),n=e[t-1]-e[0],r=0;for(let f of e)r+=f/n;r/=t;let s=0,a=0,l=0;for(let f=0;f<t;f++){let c=e[f]/n-r;s+=o[f]*o[f],a+=c*c,l+=o[f]*c}let i=Math.sqrt(s*a);return(i-l)*(i+l)/(s*a)}var nr=1.90985931710274,rr=1.0471975511966;function Qe(e,t){if(Number.isNaN(e)||!(t>=3))return NaN;if(t===3){let a=nr*(Math.asin(Math.sqrt(1-e))-rr);return Math.max(a,0)}let o=Math.log(e);if(t<=11){let a=mt(tr,t);if(o>=a)return 1e-99;let l=mt(Qn,t),i=Math.exp(mt(Gn,t));return P(-Math.log(a-o),{mean:l,sd:i,lowerTail:!1})}let n=Math.log(t),r=mt(Zn,n),s=Math.exp(mt(Jn,n));return P(o,{mean:r,sd:s,lowerTail:!1})}function or(e,t,o={}){let n;t!==void 0&&!Array.isArray(t)?o=t:n=t;let r=ft(e,n),s=o.varEqual??!1,a=r.length;if(a<2)throw new RangeError("not enough groups");let l=r.map(h=>h.length);if(l.some(h=>h<2))throw new RangeError("not enough observations");let i=r.map(Z),f=r.map(U),c=l.reduce((h,p)=>h+p,0),m,u;if(s){let h=Z(r.flat()),p=0,M=0;for(let d=0;d<a;d++)p+=l[d]*(i[d]-h)**2,M+=(l[d]-1)*f[d];u=c-a,m=p/(a-1)/(M/u)}else{let h=l.map((w,g)=>w/f[g]),p=h.reduce((w,g)=>w+g,0),M=0,d=0;for(let w=0;w<a;w++)M+=(1-h[w]/p)**2/(l[w]-1),d+=h[w]*i[w];M/=a*a-1,d/=p;let b=0;for(let w=0;w<a;w++)b+=h[w]*(i[w]-d)**2;m=b/((a-1)*(1+2*(a-2)*M)),u=1/(3*M)}return{method:s?"One-way analysis of means":"One-way analysis of means (not assuming equal variances)",statistic:m,statisticName:"F",parameter:[a-1,u],parameterName:["num df","denom df"],pValue:G(m,a-1,u,!1,!1)}}function sr(e){let t=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,s)=>r-s),o=t.length;if(o<3||o>5e3)throw new RangeError("sample size must be between 3 and 5000");if(!Number.isFinite(t[0])||!Number.isFinite(t[o-1]))throw new RangeError("'x' must be finite");if(t[o-1]===t[0])throw new RangeError("all 'x' values are identical");let n=Ye(t);return{method:"Shapiro-Wilk normality test",statistic:1-n,statisticName:"W",pValue:Qe(n,o)}}function oe(e,t,o){let n=[0,0];for(let r=Math.max(0,t);r<Math.min(o,e.length);r++)n=C(n,[e[r],0]);return n[0]}function ar([[e,t],[o,n]]){let r=e+o,s=t+n,a=e+t,l=Math.max(0,a-s),i=Math.min(a,r),f=new Float64Array(i-l+1);for(let c=l;c<=i;c++)f[c-l]=ut(c,r,s,a,!1);return{lo:l,d:f}}function ir(e,t){let o=new Float64Array(e.length+t.length-1);for(let n=0;n<e.length;n++){let r=e[n];if(r!==0)for(let s=0;s<t.length;s++)o[n+s]+=r*t[s]}return o}var Pt=class{lo;hi;logNull;constructor(t){let o=0,n=new Float64Array([1]);for(let r of t){let s=ar(r);o+=s.lo,n=ir(n,s.d)}this.lo=o,this.hi=o+n.length-1,this.logNull=n.map(Math.log)}density(t){let o=this.logNull.length,n=new Float64Array(o);if(t===0||t===1/0)return n[t===0?0:o-1]=1,n;let r=Math.log(t),s=-1/0;for(let l=0;l<o;l++){let i=this.logNull[l]+(this.lo+l)*r;n[l]=i,i>s&&(s=i)}for(let l=0;l<o;l++)n[l]=Math.exp(n[l]-s);let a=oe(n,0,o);for(let l=0;l<o;l++)n[l]=n[l]/a;return n}mean(t){if(t===0)return this.lo;if(t===1/0)return this.hi;let o=this.density(t),n=[0,0];for(let r=0;r<o.length;r++)n=C(n,[(this.lo+r)*o[r],0]);return n[0]}cdf(t,o,n){let r=this.density(o),s=t-this.lo;return n?oe(r,s,r.length):oe(r,0,s+1)}};function se(e,t){return t?Y(e,0,1):1/Y(o=>e(1/o),Number.EPSILON,1)}function Ge(e,t){if(t===e.lo)return 0;if(t===e.hi)return 1/0;let o=e.mean(1);return o===t?1:se(n=>e.mean(n)-t,o>t)}function ae(e,t,o){if(t===e.hi)return 1/0;let n=e.cdf(t,1,!1);return n===o?1:se(r=>o-e.cdf(t,r,!1),n<o)}function ie(e,t,o){if(t===e.lo)return 0;let n=e.cdf(t,1,!0);return n===o?1:se(r=>e.cdf(t,r,!0)-o,n>o)}function lr(e,t={}){let o=e.length;if(o<1)throw new RangeError("'x' must have at least one stratum");let n=e[0].length,r=e[0][0]?.length??0;if(n<2||r<2||o<2)throw new RangeError("each dimension in table must be >= 2");for(let c of e){if(c.length!==n||c.some(m=>m.length!==r))throw new RangeError("all strata must have the same dimensions");if(c.some(m=>m.some(u=>!Number.isFinite(u)||u<0)))throw new RangeError("all entries of 'x' must be nonnegative and finite")}let s=e.map(c=>c.reduce((m,u)=>m+u.reduce((h,p)=>h+p,0),0));if(s.some(c=>c<2))throw new RangeError("sample size in each stratum must be > 1");let a=V(t.alternative),l=t.correct??!0,i=t.exact??!1,f=t.confLevel??.95;if(X(f),n===2&&r===2){let c=e.map(m=>[[m[0][0],m[0][1]],[m[1][0],m[1][1]]]);return i?fr(c,a,f):cr(c,s,a,l,f)}return mr(e,s,n,r)}function cr(e,t,o,n,r){let s=0,a=0,l=0,i=0,f=0,c=0,m=0,u=0;e.forEach(([[N,y],[x,E]],R)=>{let k=t[R],v=N+y,q=x+E,I=N+x,A=y+E;s+=N,a+=v*I/k,l+=v*q*I*A/(k*k*(k-1));let L=(N+E)/k,j=(y+x)/k,z=N*E/k,H=y*x/k;i+=z,f+=H,c+=L*z,m+=L*H+j*z,u+=j*H});let h=s-a,p=n&&Math.abs(h)>=.5?.5:0,M=(Math.abs(h)-p)**2/l,d=o==="two.sided"?K(M,.5,2,!1,!1):P(Math.sign(h)*Math.sqrt(M),{lowerTail:o==="less"}),b=i/f,w=Math.sqrt(c/(2*i*i)+m/(2*i*f)+u/(2*f*f)),g;if(o==="less")g=[0,b*Math.exp(F(r)*w)];else if(o==="greater")g=[b*Math.exp(F(r,{lowerTail:!1})*w),1/0];else{let N=F((1+r)/2);g=[b*Math.exp(-N*w),b*Math.exp(N*w)]}return{method:`Mantel-Haenszel chi-squared test ${p!==0?"with":"without"} continuity correction`,alternative:o,statistic:M,statisticName:"Mantel-Haenszel X-squared",parameter:1,parameterName:"df",pValue:d,confInt:g,confLevel:r,estimate:b,estimateNames:"common odds ratio",nullValue:1,nullValueName:"common odds ratio"}}function fr(e,t,o){let n=new Pt(e),r=e.reduce((l,i)=>l+i[0][0],0),s;if(t==="two.sided"){let l=n.density(1),i=l[r-n.lo]*(1+1e-7),f=[0,0];for(let c of l)c<=i&&(f=C(f,[c,0]));s=Math.min(1,f[0])}else s=n.cdf(r,1,t==="greater");let a;if(t==="less")a=[0,ae(n,r,1-o)];else if(t==="greater")a=[ie(n,r,1-o),1/0];else{let l=(1-o)/2;a=[ie(n,r,l),ae(n,r,l)]}return{method:"Exact conditional test of independence in 2 x 2 x k tables",alternative:t,statistic:r,statisticName:"S",pValue:s,confInt:a,confLevel:o,estimate:Ge(n,r),estimateNames:"common odds ratio",nullValue:1,nullValueName:"common odds ratio"}}function mr(e,t,o,n){let r=(o-1)*(n-1),s=new Array(r).fill(0),a=Array.from({length:r},()=>new Array(r).fill(0));e.forEach((f,c)=>{let m=t[c],u=f.map(M=>M.reduce((d,b)=>d+b,0)),h=Array.from({length:n},(M,d)=>f.reduce((b,w)=>b+w[d],0)),p=1/(m*m*(m-1));for(let M=0;M<n-1;M++)for(let d=0;d<o-1;d++){let b=d+(o-1)*M;s[b]+=f[d][M]-u[d]*h[M]/m;for(let w=0;w<n-1;w++)for(let g=0;g<o-1;g++){let N=(d===g?m*u[d]:0)-u[d]*u[g],y=(M===w?m*h[M]:0)-h[M]*h[w];a[b][g+(o-1)*w]+=p*N*y}}});let l=Le(a,s),i=0;for(let f=0;f<r;f++)i+=s[f]*l[f];return{method:"Cochran-Mantel-Haenszel test",statistic:i,statisticName:"Cochran-Mantel-Haenszel M^2",parameter:r,parameterName:"df",pValue:K(i,r/2,2,!1,!1)}}var Ze=new Map;function ur(e,t){let o=`${e},${t}`,n=Ze.get(o);if(n!==void 0)return n;let r=e+t,s=[];for(let u=1;u<=r;u++)s.push(Math.min(u,r+1-u));let a=s.reduce((u,h)=>u+h,0),l=Array.from({length:e+1},()=>new Float64Array(a+1));l[0][0]=1;for(let u=0;u<r;u++){let h=r-u,p=s[u],M=Array.from({length:e+1},()=>new Float64Array(a+1));for(let d=0;d<=e;d++){let b=l[d],w=e-d;if(w>h)continue;let g=w/h;for(let N=0;N<=a;N++){let y=b[N];y!==0&&(w>0&&(M[d+1][N+p]+=y*g),w<h&&(M[d][N]+=y*(1-g)))}}l=M}let i=l[e],f=0;for(;f<i.length&&i[f]===0;)f++;let c=i.length-1;for(;c>f&&i[c]===0;)c--;let m={min:f,probs:i.slice(f,c+1)};return Ze.set(o,m),m}function le(e,t,o,n=!0){if(Number.isNaN(e)||!(t>=1)||!(o>=1)||t!==Math.floor(t)||o!==Math.floor(o))return NaN;let{min:r,probs:s}=ur(t,o),a=Math.floor(e+1e-7)-r,l=0;if(n)for(let i=0;i<=Math.min(a,s.length-1);i++)l+=s[i];else for(let i=Math.max(a+1,0);i<s.length;i++)l+=s[i];return Math.min(l,1)}var Je=new Map;function hr(e,t){let o=`${e},${t}`,n=Je.get(o);if(n!==void 0)return n;let r=e+t,s=0;for(let m=1;m<=r;m++)s+=Math.min(m,r+1-m);let a=Array.from({length:e+1},()=>new Float64Array(s+1));a[0][0]=1;for(let m=0;m<r;m++){let u=Math.min(m+1,r-m),h=Array.from({length:e+1},()=>new Float64Array(s+1));for(let p=0;p<=e;p++){if(e-p>r-m)continue;let M=a[p];for(let d=0;d<=s;d++){let b=M[d];b!==0&&(p<e&&(h[p+1][d+u]+=b),e-p<r-m&&(h[p][d]+=b))}}a=h}let l=a[e],i=0;for(;l[i]===0;)i++;let f=l.length-1;for(;l[f]===0;)f--;let c={min:i,counts:l.slice(i,f+1)};return Je.set(o,c),c}function jt(e,t,o){let{min:n,counts:r}=hr(t,o);if(e<=0)return n;if(e>=1)return n+r.length-1;let s=Re(t+o,t),a=0;for(let l=0;l<r.length;l++)if(a+=r[l]/s,a>=e)return n+l;return n+r.length-1}function pr(e,t,o={}){let n=Array.from(e).filter(g=>!Number.isNaN(g)),r=Array.from(t).filter(g=>!Number.isNaN(g)),s=n.length,a=r.length;if(s<1)throw new RangeError("not enough 'x' observations");if(a<1)throw new RangeError("not enough 'y' observations");let l=V(o.alternative),i=o.confInt??!1,f=o.confLevel??.95;i&&X(f);let c=s+a,m=$(n.concat(r)),u=m.map(g=>Math.min(g,c-g+1)),h=0;for(let g=0;g<s;g++)h+=u[g];let p=new Set(m).size<c,M=o.exact??(s<50&&a<50&&!p),d,b;if(M&&!p){let g=y=>le(y-1,s,a,!1),N=y=>le(y,s,a,!0);if(l==="two.sided"){let y=Math.floor((s+1)**2/4)+Math.floor(s*a/2)/2;d=Math.min(1,2*(h>y?g(h):N(h)))}else l==="less"?d=g(h):d=N(h);i&&(b=gr(n,r,l,f))}else{let g=0;for(let R of u)g+=R*R;let N=c%2===0,y=N?s*(c+2)/4:s*(c+1)**2/(4*c),x=N?s*a*(16*g-c*(c+2)**2)/(16*c*(c-1)):s*a*(16*c*g-(c+1)**4)/(16*c*c*(c-1)),E=(h-y)/Math.sqrt(x);d=l==="two.sided"?2*Math.min(P(E),P(E,{lowerTail:!1})):l==="less"?P(E,{lowerTail:!1}):P(E),i&&(b=wr(n,r,l,f))}let w={method:"Ansari-Bradley test",alternative:l,statistic:h,statisticName:"AB",pValue:d};return b!==void 0&&(w.confInt=b.confInt,w.confLevel=f,w.estimate=b.estimate,w.estimateNames="ratio of scales"),w.nullValue=1,w.nullValueName="ratio of scales",w}function tn(e,t,o){let n=e.length,r=n+t.length,s=dr(e.map(i=>i/o).concat(t)),a=s.map(i=>Math.min(i,r-i+1)),l=0;for(let i=0;i<n;i++)l+=a[i];return{ab:l,a,ties:new Set(s).size<r}}function dr(e){let t=e.filter(s=>!Number.isNaN(s));if(t.length===e.length)return $(e);let o=$(t),n=0,r=t.length;return e.map(s=>Number.isNaN(s)?++r:o[n++])}function ce(e,t,o){return e==="two.sided"?o(t):e==="greater"?[o(2*t)[0],1/0]:[0,o(2*t)[1]]}function gr(e,t,o,n){let r=e.length,s=t.length,a=[];for(let d of e)for(let b of t)d/b>=0&&a.push(d/b);a.sort((d,b)=>d-b);let l=a.length;if(l===0)return{confInt:ce(o,1-n,()=>[NaN,NaN]),estimate:NaN};let i=a.map((d,b)=>tn(e,t,d+(b<l-1?(a[b+1]-d)/2:d*1.01)).ab),f=(d,b,w)=>{let g=1/0;for(let y of i)(b?y-d>0:y-d>=0)&&y-d<g&&(g=y-d);let N=w?-1/0:1/0;return i.forEach((y,x)=>{y-d===g&&(N=w?Math.max(N,a[x]):Math.min(N,a[x]))}),N},c=d=>{let b=jt(d/2,r,s),w=jt(1-d/2,r,s);if(!i.some(y=>y-b>=0)||!i.some(y=>y-w>0))return[NaN,NaN];let g=f(b,!1,!1),N=f(w,!0,!0);return g>N?[f(w,!1,!1),f(b,!0,!0)]:[g,N]},m=ce(o,1-n,c),u=jt(.5,r,s),h=-1/0,p=1/0;i.forEach((d,b)=>{d-u<=0?h=Math.max(h,a[b]):p=Math.min(p,a[b])});let M=h===-1/0||p===1/0?NaN:(p+h)/2;return{confInt:m,estimate:M}}function wr(e,t,o,n){let r=e.length,s=t.length,a=r+s,l=a%2===0,i=(b,w)=>{let{ab:g,a:N,ties:y}=tn(e,t,b),x=l?g-r*(a+2)/4:g-r*(a+1)**2/(4*a),E;if(!y)E=Math.sqrt(l?r*s*(a+2)*(a-2)/(48*(a-1)):r*s*(a+1)*(3+a*a)/(48*a*a));else{let R=0;for(let k of N)R+=k*k;E=Math.sqrt(l?r*s*(16*R-a*(a+2)**2)/(16*a*(a-1)):r*s*(16*a*R-(a+1)**4)/(16*a*a*(a-1)))}return x/E-w},f=[],c=(b,w)=>{b.length===0||w.length===0||f.push(Math.min(...b)/Math.max(...w),Math.max(...b)/Math.min(...w))};if(c(e.filter(b=>b>0),t.filter(b=>b>0)),c(e.filter(b=>b<=0),t.filter(b=>b<0)),f.some(b=>!Number.isFinite(b)))return;let m=Math.min(...f),u=Math.max(...f),h=b=>Y(w=>i(w,b),m,u,{tol:1e-4}),p=b=>{let w=F(b/2),g=F(b/2,{lowerTail:!1});if(i(m,w)>0||i(u,g)<0)return[NaN,NaN];let N=h(w),y=h(g);return N<=y?[N,y]:[y,N]},M=ce(o,1-n,p),d=i(m,0)>0||i(u,0)<0?NaN:h(0);return{confInt:M,estimate:d}}function Nr(e,t,o={}){let n=Array.from(e).filter(R=>!Number.isNaN(R)),r=Array.from(t).filter(R=>!Number.isNaN(R)),s=n.length,a=r.length;if(s<1)throw new RangeError("not enough 'x' observations");if(a<1)throw new RangeError("not enough 'y' observations");let l=V(o.alternative),i=o.confLevel??.95;kt(i);let f=$(n.concat(r)),c=f.slice(0,s),m=f.slice(s),u=R=>R.reduce((k,v)=>k+v,0)/R.length,h=u(c),p=u(m),M=(R,k,v)=>{let q=(R.length+1)/2,I=0;for(let A=0;A<R.length;A++)I+=(R[A]-k[A]-v+q)**2;return I/(R.length-1)},d=M(c,$(n),h),b=M(m,$(r),p),w=(p-(a+1)/2)/s,g=s*d+a*b,N=s*a*(p-h)/(s+a)/Math.sqrt(g),y=g**2/((s*d)**2/(s-1)+(a*b)**2/(a-1)),x;l==="greater"?x=W(N,y,!0,!1):l==="less"?x=W(N,y,!1,!1):x=2*W(-Math.abs(N),y,!0,!1);let E=ot((1-i)/2,y,!1,!1)*Math.sqrt(d/(s*a**2)+b/(a*s**2));return{method:"Brunner-Munzel Test",alternative:l,statistic:N,statisticName:"Brunner-Munzel Test Statistic",parameter:y,parameterName:"df",pValue:x,confInt:[w-E,w+E],confLevel:i,estimate:w,estimateNames:"P(X<Y)+.5*P(X=Y)"}}var br=[1.2337005501361697,7831619385924639e-32];function Mr(e,t,o){let n=(c,m)=>{let u=new Float64Array(t*t);for(let h=0;h<t;h++)for(let p=0;p<t;p++){let M=c[h*t+p];if(M!==0)for(let d=0;d<t;d++)u[h*t+d]+=M*m[p*t+d]}return u},r=c=>{let m=0;for(let p of c)m=Math.max(m,Math.abs(p));if(m===0||!Number.isFinite(m))return 0;let u=Math.floor(Math.log2(m));if(Math.abs(u)<500)return 0;let h=2**-u;for(let p=0;p<c.length;p++)c[p]*=h;return u},s,a=0,l=e.slice(),i=0,f=o;for(;f>0;)f&1&&(s=s===void 0?l.slice():n(s,l),a+=i,a+=r(s)),f>>=1,f>0&&(l=n(l,l),i*=2,i+=r(l));return[s,a]}function en(e,t){if(Number.isNaN(t)||!(e>=1)||e!==Math.floor(e))return NaN;if(t<=1/(2*e))return 0;if(t>=1)return 1;if(e*t<1){let[c,m]=vt(e,t),u=2*c-1+2*m,h=1,p=0;for(let M=1;M<=e;M++)h*=M/e*u,h<2**-500&&(h*=2**500,p-=500);for(;p<-1e3;)h*=2**-1e3,p+=1e3;return h*2**p}let o=Math.floor(e*t)+1,n=2*o-1,r=o-e*t,s=new Float64Array(n*n);for(let c=0;c<n;c++)for(let m=0;m<n;m++)s[c*n+m]=c-m+1>=0?1:0;for(let c=0;c<n;c++)s[c*n]-=Math.pow(r,c+1),s[(n-1)*n+c]-=Math.pow(r,n-c);2*r-1>0&&(s[(n-1)*n]+=Math.pow(2*r-1,n));for(let c=0;c<n;c++)for(let m=0;m<n;m++){let u=c-m+1;if(u>0){let h=1;for(let p=2;p<=u;p++)h*=p;s[c*n+m]/=h}}let[a,l]=Mr(s,n,e),i=a[(o-1)*n+o-1],f=l;for(let c=1;c<=e;c++)i=i*c/e,Math.abs(i)<2**-500&&(i*=2**500,f-=500);for(;f>1e3;)i*=2**1e3,f-=1e3;for(;f<-1e3;)i*=2**-1e3,f+=1e3;return i*2**f}function fe(e,t=!0){if(Number.isNaN(e))return NaN;if(e<=0)return t?0:1;if(e===1/0)return t?1:0;if(e<1){let r=Et(br,vt(e,e)),s=r[0]+r[1],a=Math.exp(-r[0])*(1-r[1]),l=0;for(let f=2;f<100;f++){let c=Math.exp(-(2*f-1)*(2*f-1)*s);if(l+=c,c<=1e-17*(l+a))break}let i=Math.sqrt(2*Math.PI)/e*(a+l);return t?i:1-i}let o=0;for(let r=1;r<100;r++){let s=Math.exp(-2*r*r*e*e);if(o+=r%2===1?s:-s,s<=1e-17*Math.abs(o))break}let n=2*o;return t?1-n:n}function nn(e,t){if(Number.isNaN(t)||!(e>=1)||e!==Math.floor(e))return NaN;if(t<=0)return 1;if(t>1)return 0;let[o,n]=vt(e,t),r=Math.floor(e-o-n),s=0;for(let a=0;a<=r;a++){let l=C(zt(e-a,-o),[-n,0]);if(l[0]<=0)break;let i=C(zt(a,o),[n,0]),f=Et(i,[e,0]),c=Et(l,[e,0]);s+=Ne(a,e-a,f,c,!1)/(f[0]+f[1])}return Math.min(t*s,1)}function rn(e,t,o,n={}){let r=n.alternative??"two.sided";if(Number.isNaN(e)||!(t>=1)||!(o>=1)||t!==Math.floor(t)||o!==Math.floor(o))return NaN;if(e<=0)return 1;if(e>1)return 0;let s=t+o,a;if(n.z!==void 0){if(n.z.length!==s)throw new RangeError("z must have length m + n");let u=[...n.z].sort((h,p)=>h-p);a=new Array(s+1).fill(!1);for(let h=1;h<s;h++)a[h]=u[h]!==u[h-1]}let l=e*t*o*(1-1e-10),i=(u,h)=>{let p=u*o-h*t;return(r==="two.sided"?Math.abs(p):r==="greater"?p:-p)>=l},f=new Float64Array(o+1),c=new Float64Array(o+1),m=0;for(let u=0;u<=t;u++){for(let h=0;h<=o;h++){if(u===0&&h===0){c[0]=1;continue}let p=u+h,M=(u>0?u/p*f[h]:0)+(h>0?h/p*c[h-1]:0);(a===void 0?p<s:a[p])&&i(u,h)?(M>0&&(m+=M*ut(u,t,o,p,!1)),c[h]=0):c[h]=M}[f,c]=[c,f],c.fill(0)}return Math.min(m,1)}function on(e,t){return e==="two.sided"?"two-sided":`the CDF of x lies ${e==="less"?"below":"above"} ${t?"the null hypothesis":"that of y"}`}function yr(e,t,o={}){let n=Array.from(e).filter(w=>!Number.isNaN(w)).sort((w,g)=>w-g),r=n.length;if(r<1)throw new RangeError("not enough 'x' data");let s=V(o.alternative),a=s==="two.sided"?"D":s==="greater"?"D^+":"D^-";if(typeof t=="function"){let w=-1/0,g=-1/0;for(let R=0;R<r;R++){let k=t(n[R]);w=Math.max(w,(R+1)/r-k),g=Math.max(g,k-R/r)}let N=s==="two.sided"?Math.max(w,g):s==="greater"?w:g,y=new Set(n).size<r,x=o.exact??(r<100&&!y),E;return s==="two.sided"?E=x?1-en(r,N):fe(Math.sqrt(r)*N,!1):E=x?nn(r,N):Math.exp(-2*r*N*N),{method:`${x?"Exact":"Asymptotic"} one-sample Kolmogorov-Smirnov test`,alternative:on(s,!0),exact:x,statistic:N,statisticName:a,pValue:Math.min(1,Math.max(0,E))}}let l=Array.from(t).filter(w=>!Number.isNaN(w)),i=l.length;if(i<1)throw new RangeError("not enough 'y' data");let f=n.map(w=>[w,0]).concat(l.map(w=>[w,1]));f.sort((w,g)=>w[0]-g[0]);let c=0,m=0,u=0,h=0;for(let w=0;w<f.length;w++){if(f[w][1]===0?c++:m++,w+1<f.length&&f[w+1][0]===f[w][0])continue;let g=c/r-m/i;u=Math.max(u,g),h=Math.max(h,-g)}let p=s==="two.sided"?Math.max(u,h):s==="greater"?u:h,M=new Set(f.map(w=>w[0])).size<f.length,d=o.exact??r*i<1e4,b;if(d)b=rn(p,r,i,M?{alternative:s,z:f.map(w=>w[0])}:{alternative:s});else{let w=r*i/(r+i);b=s==="two.sided"?fe(Math.sqrt(w)*p,!1):Math.exp(-2*w*p*p)}return{method:`${d?"Exact":"Asymptotic"} two-sample Kolmogorov-Smirnov test`,alternative:on(s,!1),exact:d,statistic:p,statisticName:a,pValue:Math.min(1,Math.max(0,b))}}function sn(e,t,o){let n=Array.from(e);if(n.length!==t.length)throw new RangeError("'x' and 'g' must have the same length");let r=new Map;for(let a=0;a<n.length;a++){let l=t[a];if(typeof l=="number"&&Number.isNaN(l)||o&&Number.isNaN(n[a]))continue;let i=r.get(l);i===void 0&&r.set(l,i=[]),i.push(n[a])}let s=Array.from(r.keys()).sort((a,l)=>typeof a=="number"&&typeof l=="number"?a-l:String(a)<String(l)?-1:String(a)>String(l)?1:0);return{levels:s,groups:s.map(a=>r.get(a))}}function me(e,t,o){let n=[],r=[];for(let l=0;l<e-1;l++)for(let i=l+1;i<e;i++)n.push(t(i,l)),r.push([i-1,l]);let s=Zt(n,o),a=Array.from({length:e-1},()=>new Array(e-1).fill(NaN));return r.forEach(([l,i],f)=>a[l][i]=s[f]),a}function ue(e,t,o,n){return{method:e,pValue:o,rowNames:t.slice(1).map(String),colNames:t.slice(0,-1).map(String),pAdjustMethod:n}}function vr(e,t,o={}){let n=o.paired??!1,r=o.poolSd??!n;if(n&&r)throw new RangeError("pooling of SD is incompatible with paired tests");let s=V(o.alternative),a=o.pAdjustMethod??"holm",{levels:l,groups:i}=sn(e,t,!n),f=l.length;if(f<2)throw new RangeError("there must be at least two groups");let c,m;if(r){m="t tests with pooled SD";let u=i.map(b=>b.length),h=i.map(b=>b.length>0?Z(b):NaN),p=0,M=0;i.forEach(b=>{b.length>1&&(p+=U(b)*(b.length-1),M+=b.length-1)});let d=Math.sqrt(p/M);c=(b,w)=>{let g=(h[b]-h[w])/(d*Math.sqrt(1/u[b]+1/u[w]));return s==="less"?W(g,M,!0,!1):s==="greater"?W(g,M,!1,!1):2*W(-Math.abs(g),M,!0,!1)}}else m=n?"paired t tests":"t tests with non-pooled SD",c=(u,h)=>Ht(i[u],i[h],{paired:n,alternative:s}).pValue;return ue(m,l,me(f,c,a),a)}function xr(e,t,o={}){let{pAdjustMethod:n,alternative:r,...s}=o,a=n??"holm",{levels:l,groups:i}=sn(e,t,!(s.paired??!1)),f=l.length;if(f<2)throw new RangeError("there must be at least two groups");let c="",m=me(f,(u,h)=>{let p=Yt(i[u],i[h],{...s,...r===void 0?{}:{alternative:r}});return c=p.method,p.pValue},a);return ue(c,l,m,a)}function Er(e,t,o={}){if(e.length!==t.length)throw new RangeError("'x' and 'n' must have the same length");let n=[],r=[];e.forEach((c,m)=>{Number.isNaN(c)||Number.isNaN(t[m])||(n.push(c),r.push(t[m]))});let s=n.length;if(s<2)throw new RangeError("too few groups");let a=o.pAdjustMethod??"holm",l=o.correct??!0,i=me(s,(c,m)=>te([n[c],n[m]],[r[c],r[m]],{correct:l}).pValue,a),f=Array.from({length:s},(c,m)=>m+1);return ue("Pairwise comparison of proportions",f,i,a)}function an(e){let t=e.flat(),o=Nt(t),n=[0,0],r=[0,0],s=[];for(let a of e){let l=Nt(a);s.push(l[0]);let i=Q(l,o);n=C(n,xt(xt(i,i),[a.length,0]));for(let f of a){let c=Q([f,0],l);r=C(r,xt(c,c))}}return{ssb:n[0],ssw:r[0],means:s}}function Ar(e,t){let o=ft(e,t),n=o.length;if(n<2)throw new RangeError("contrasts can be applied only to factors with 2 or more levels");let r=o.reduce((u,h)=>u+h.length,0),{ssb:s,ssw:a}=an(o),l=n-1,i=r-n,f=s/l,c=a/i,m=f/c;return{df:[l,i],sumSq:[s,a],meanSq:[f,c],fValue:m,pValue:i>0?G(m,l,i,!1,!1):NaN}}function Rr(e,t,o={}){let n;t!==void 0&&!Array.isArray(t)?o=t:n=t;let{labels:r,groups:s}=ee(e,n),a=s.length;if(a<2)throw new RangeError("contrasts can be applied only to factors with 2 or more levels");let l=o.confLevel??.95,f=s.reduce((M,d)=>M+d.length,0)-a,{ssw:c,means:m}=an(s),u=c/f,h=xe(l,a,f),p={names:[],i:[],j:[],diff:[],lwr:[],upr:[],pAdj:[]};for(let M=0;M<a-1;M++)for(let d=M+1;d<a;d++){let b=m[d]-m[M],w=Math.sqrt(u/2*(1/s[d].length+1/s[M].length));p.names.push(`${r[d]}-${r[M]}`),p.i.push(d+1),p.j.push(M+1),p.diff.push(b),p.lwr.push(b-h*w),p.upr.push(b+h*w),p.pAdj.push(ve(Math.abs(b)/w,a,f,{lowerTail:!1}))}return p}function qr(e,t,o={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?o=t:n=t;let{sigmaX:r,sigmaY:s}=o,a=o.mu??0;if(r===void 0&&n===void 0)throw new RangeError("sigmaX (the known standard deviation of x) is required");if(r===void 0||n!==void 0&&s===void 0)throw new RangeError("sigmaX and sigmaY are both required for two samples");if(Number.isNaN(a))throw new RangeError("mu must be a number");let l=V(o.alternative),i=o.confLevel??.95;if(!(i>=0&&i<=1))throw new RangeError("confLevel must be between 0 and 1");let f=Array.from(e).filter(g=>!Number.isNaN(g)),c=n===void 0?void 0:Array.from(n).filter(g=>!Number.isNaN(g));if(f.length<3)throw new RangeError("x needs at least 3 non-missing values");if(c!==void 0&&c.length<3)throw new RangeError("y needs at least 3 non-missing values");let m=Nt(f)[0],u=c===void 0?NaN:Nt(c)[0],h=c===void 0?r/Math.sqrt(f.length):Math.sqrt(r**2/f.length+s**2/c.length),p=c===void 0?m:m-u,M=(p-a)/h,d,b;if(l==="less")d=P(M),b=[-1/0,p+F(i)*h];else if(l==="greater")d=P(M,{lowerTail:!1}),b=[p-F(i)*h,1/0];else{d=2*P(-Math.abs(M));let g=F(1-(1-i)/2)*h;b=[p-g,p+g]}let w=c!==void 0;return{method:w?"Two-sample z-Test":"One-sample z-Test",alternative:l,statistic:M,statisticName:"z",pValue:d,confInt:b,confLevel:i,estimate:w?[m,u]:m,estimateNames:w?["mean of x","mean of y"]:"mean of x",nullValue:a,nullValueName:w?"difference in means":"mean"}}function Tr(e,t,o={}){let n=o.intercept??!0,r=e.length>0&&typeof e[0]!="number"?e.map(T=>Array.from(T)):Array.from(e,T=>[T]),s=Array.from(t);if(r.length!==s.length)throw new RangeError("variable lengths differ (found for 'x')");let a=o.weights===void 0?void 0:Array.from(o.weights);if(a!==void 0&&a.length!==s.length)throw new RangeError("variable lengths differ (found for '(weights)')");if(a?.some(T=>T<0))throw new RangeError("missing or negative weights not allowed");let l=s.map((T,S)=>!Number.isNaN(T)&&r[S].every(_=>!Number.isNaN(_))&&(a===void 0||!Number.isNaN(a[S]))),i=r.filter((T,S)=>l[S]).map(T=>n?[1,...T]:T),f=s.filter((T,S)=>l[S]),c=a?.filter((T,S)=>l[S]);if(f.length===0)throw new RangeError("0 (non-NA) cases");let m=f.map((T,S)=>c===void 0||c[S]!==0),u=i.filter((T,S)=>m[S]),h=f.filter((T,S)=>m[S]),p=c?.filter((T,S)=>m[S]),M=h.length;if(M===0)throw new RangeError("all weights are zero");let d=p?.map(Math.sqrt),b=d===void 0?u:u.map((T,S)=>T.map(_=>_*d[S])),w=d===void 0?h:h.map((T,S)=>T*d[S]),g=ke(b),N=g.rank,y=Ie(g,w),x=Se(g,w),E=d===void 0?x:x.map((T,S)=>T/d[S]),R=[],k=[],v=0;f.forEach((T,S)=>{if(m[S])R.push(E[v]),k.push(T-E[v]),v++;else{let _=i[S].reduce((yt,ln,de)=>Number.isNaN(y[de])?yt:yt+ln*y[de],0);k.push(_),R.push(T-_)}});let q=k.filter((T,S)=>m[S]),I=M-N,A=p??new Array(M).fill(1),L=0;for(let T=0;T<M;T++)L+=A[T]*E[T]**2;let j=L/I,z=Math.sqrt(j),H=g.qr.slice(0,N).map(T=>T.slice(0,N)),O=N>0?Ve(H):[],B=g.pivot.slice(0,N).map((T,S)=>[T,S]).sort((T,S)=>T[0]-S[0]),D=B.map(([T])=>y[T]),nt=B.map(([,T])=>Math.sqrt(O[T][T]*j)),rt=D.map((T,S)=>T/nt[S]),dt=rt.map(T=>2*W(-Math.abs(T),I,!0,!1)),st={coefficients:y,residuals:R,fittedValues:k,rank:N,dfResidual:I,coefTable:{estimate:D,stdError:nt,tValue:rt,pValue:dt},sigma:z,rSquared:0,adjRSquared:0,intercept:n,qr:g},he=n?1:0,Mt=N-he;if(Mt===0)return st;let gt=0;if(n){let T=A.reduce((_,yt)=>_+yt,0),S=0;for(let _=0;_<M;_++)S+=A[_]*q[_]/T;for(let _=0;_<M;_++)gt+=A[_]*(q[_]-S)**2}else for(let T=0;T<M;T++)gt+=A[T]*q[T]**2;st.rSquared=gt/(gt+L),st.adjRSquared=1-(1-st.rSquared)*((M-he)/I);let pe=gt/Mt/j;return st.fStatistic={value:pe,numdf:Mt,dendf:I},st.fPValue=G(pe,Mt,I,!1,!1),st}function kr(e,t={}){let o=t.level??.95,n=ot((1+o)/2,e.dfResidual,!0,!1),{estimate:r,stdError:s}=e.coefTable,a=e.coefficients.map(()=>NaN),l=e.coefficients.map(()=>NaN),i=0;return e.coefficients.forEach((f,c)=>{Number.isNaN(f)||(a[c]=r[i]-n*s[i],l[c]=r[i]+n*s[i],i++)}),{lower:a,upper:l}}function Ir(e,t,o={}){let r=(t.length>0&&typeof t[0]!="number"?t.map(p=>Array.from(p)):Array.from(t,p=>[p])).map(p=>e.intercept?[1,...p]:p),s=e.rank,a=e.qr.pivot.slice(0,s),l=e.qr.qr.slice(0,s).map(p=>p.slice(0,s)),i=e.sigma**2,f=r.map(p=>p.reduce((M,d,b)=>Number.isNaN(e.coefficients[b])?M:M+d*e.coefficients[b],0)),c=r.map(p=>{let M=new Array(s).fill(0);for(let d=0;d<s;d++){let b=p[a[d]];for(let w=0;w<d;w++)b-=l[w][d]*M[w];M[d]=b/l[d][d]}return Math.sqrt(M.reduce((d,b)=>d+b*b,0)*i)}),m=o.interval??"none";if(m==="none")return{fit:f,seFit:c};let u=ot((1+(o.level??.95))/2,e.dfResidual,!0,!1),h=c.map(p=>u*Math.sqrt(p*p+(m==="prediction"?i:0)));return{fit:f,seFit:c,lwr:f.map((p,M)=>p-h[M]),upr:f.map((p,M)=>p+h[M])}}export{Rr as TukeyHSD,pr as ansariTest,Ar as aov,Bn as bartlettTest,Jt as binomTest,Nr as brunnerMunzelTest,mn as chisqTest,kr as confint,cn as corTest,wn as fisherTest,Kn as flignerTest,Wn as friedmanTest,Hn as kruskalTest,yr as ksTest,Tr as lm,lr as mantelhaenTest,On as mcnemarTest,Un as moodTest,or as onewayTest,Zt as pAdjust,Er as pairwisePropTest,vr as pairwiseTTest,xr as pairwiseWilcoxTest,zn as poissonTest,Ir as predict,te as propTest,Dn as quadeTest,sr as shapiroTest,Ht as tTest,$n as varTest,Yt as wilcoxTest,qr as zTest};
1
+ /*! rStats.js 0.9.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{C as pe,D as ce,H as Kt,I as Xt,J as st,N as ge,O as at,T as we,U as Qt,Y as Ne,Z as Yt,b as Gt,ba as Zt,c as G,ca as Jt,d as rt,da as en,fa as Pe,ga as ze,l as Ut,m as Ae,n as le,s as Q,t as qe,y as ot}from"./chunks/chunk-24U4DKRY.js";import{h as ve,j as sn,k as We,l as _e,t as an,y as je}from"./chunks/chunk-JLSTEMSN.js";import{a as $,b as De,c as J,f as Hn}from"./chunks/chunk-MSAUU6PY.js";import{k as B,l as ae}from"./chunks/chunk-IVOBWYLV.js";import{c as on}from"./chunks/chunk-ZRO446BP.js";import"./chunks/chunk-LWUSYIQ4.js";import{a as Te,b as te,c as Y,e as tn,f as H,g as fe,h as ue,i as $e}from"./chunks/chunk-BGVMSDVJ.js";import{a as nn,d as rn}from"./chunks/chunk-5K4PS7IV.js";import{b as Re}from"./chunks/chunk-LE7TBHNI.js";import{f as Ht,g as z,h as P,s as Bt}from"./chunks/chunk-FC2TLHZC.js";import{b as nt,c as Ve,d as D,e as _t,f as ee,g as Ce,i as Oe,k as jt}from"./chunks/chunk-H2AP6TCR.js";function it(t,e,n={}){let r;e!==void 0&&!ArrayBuffer.isView(e)&&!Array.isArray(e)?n=e:r=e;let o=$(n.alternative),a=n.mu??0,l=n.paired??!1,c=n.varEqual??!1,s=n.confLevel??.95;if(Number.isNaN(a))throw new RangeError("mu must be a number");if(De(s),l&&r===void 0)throw new TypeError("y is required when paired is true");let f=Array.from(t),i=r===void 0?void 0:Array.from(r);if(l){let[M,x]=$e(f,i);f=M.map((A,E)=>A-x[E]),i=void 0}else f=ue(f),i!==void 0&&(i=ue(i));let u,m,h,d,g,p,b,v=f.length;if(v<2)throw new Error("not enough 'x' observations");let w=te(f),N=Y(f);if(i===void 0){if(m=v-1,h=Math.sqrt(N/v),h<10*Number.EPSILON*Math.abs(w))throw new Error("data are essentially constant");u=(w-a)/h,p=l?"Paired t-test":"One Sample t-test",d=w,g=l?"mean difference":"mean of x",b=l?"mean difference":"mean"}else{let M=i.length;if(M<1||!c&&M<2)throw new Error("not enough 'y' observations");if(c&&v+M<3)throw new Error("not enough observations");let x=te(i),A=Y(i);if(p=`${c?"":"Welch"} Two Sample t-test`,d=[w,x],g=["mean of x","mean of y"],b="difference in means",c){m=v+M-2;let E=0;v>1&&(E+=(v-1)*N),M>1&&(E+=(M-1)*A),E/=m,h=Math.sqrt(E*(1/v+1/M))}else{let E=N/v,I=A/M;h=Math.sqrt(E+I),m=(h*h)**2/(E*E/(v-1)+I*I/(M-1))}if(h<10*Number.EPSILON*Math.max(Math.abs(w),Math.abs(x)))throw new Error("data are essentially constant");u=(w-x-a)/h}let y,k;if(o==="less")y=B(u,m,!0,!1),k=[-1/0,u+ae(s,m,!0,!1)];else if(o==="greater")y=B(u,m,!1,!1),k=[u-ae(s,m,!0,!1),1/0];else{y=2*B(-Math.abs(u),m,!0,!1);let M=1-s,x=ae(1-M/2,m,!0,!1);k=[u-x,u+x]}return k=[a+k[0]*h,a+k[1]*h],{method:p,alternative:o,statistic:u,statisticName:"t",parameter:m,parameterName:"df",pValue:y,confInt:k,confLevel:s,estimate:d,estimateNames:g,nullValue:a,nullValueName:b,stdErr:h}}function Ie(t){return` with simulated p-value
3
+ (based on ${Bn(t)} replicates)`}function Bn(t){if(!Number.isFinite(t)||t===0)return String(t);let e=t.toExponential(14).replace(/\.?0+e/,"e"),[n,r]=e.split("e"),o=Number(r),a=`${n}e${o<0?"-":"+"}${String(Math.abs(o)).padStart(2,"0")}`,l=String(Number(t.toPrecision(15)));return l.length<=a.length?l:a}function ne(t){let e=[0,0],n=0;for(let r of t)e=D(e,[r,0]),n+=r;return Number.isFinite(n)?e[0]:n}function Gn(t,e,n){return Array.isArray(e)?Un(t,e,n??{}):Kn(t,e??{})}var ln=(t,e)=>t<e?-1:t>e?1:0;function Un(t,e,n){if(t.length!==e.length)throw new RangeError("'x' and 'y' must have the same length");let r=m=>m==null;for(let m of[...t,...e])if(!r(m)&&typeof m!="string")throw new TypeError("factor values must be strings (or null for missing values)");let o=[],a=[];t.forEach((m,h)=>{let d=e[h];!r(m)&&!r(d)&&(o.push(m),a.push(d))});let l=[...new Set(o)].sort(ln),c=[...new Set(a)].sort(ln);if(l.length<2||c.length<2)throw new RangeError("'x' and 'y' must have at least 2 levels");let s=new Map(l.map((m,h)=>[m,h])),f=new Map(c.map((m,h)=>[m,h])),i=l.map(()=>c.map(()=>0));return o.forEach((m,h)=>i[s.get(m)][f.get(a[h])]++),{...hn(i,n),rowLevels:l,colLevels:c}}function Kn(t,e){if(t.length>0&&typeof t[0]!="number"){let r=t.map(a=>Array.from(a)),o=r[0].length;if(r.some(a=>a.length!==o))throw new TypeError("all rows of the matrix must have the same length");return r.length===1?lt(r[0],e):o===1?lt(r.map(a=>a[0]),e):hn(r,e)}return lt(Array.from(t),e)}function cn(t){let e=t.B??2e3;if(!(e>=0&&e<2**31))throw new RangeError("'B' must be a non-negative number");return e}function fn(t,e,n){let r=(1-64*Number.EPSILON)*e,o=0;for(let a=0;a<t.length;a++)t[a]>=r&&o++;return(1+o)/(n+1)}function un(t,e){return Number.isNaN(t)?NaN:G(t,e/2,2,!1,!1)}function mn(t){if(!t.some(e=>e<5)&&t.some(Number.isNaN))throw new RangeError("missing value where TRUE/FALSE needed (the expected counts contain NaN)")}function lt(t,e){let n=t.length;if(t.some(u=>Number.isNaN(u)||u<0))throw new RangeError("all entries of 'x' must be non-negative and finite");if(n<2)throw new TypeError("'x' must have at least 2 elements");let r=ne(t);if(!(r>0))throw new RangeError("at least one entry of 'x' must be positive");let o=e.p===void 0?t.map(()=>1/n):Array.from(e.p);if(o.length!==n)throw new TypeError("'x' and 'p' must have the same number of elements");if(o.some(Number.isNaN))throw new RangeError("p contains missing values");if(o.some(u=>u<0))throw new RangeError("probabilities must be non-negative");if(e.rescaleP??!1){let u=ne(o);o=o.map(m=>m/u)}else if(Math.abs(ne(o)-1)>Math.sqrt(Number.EPSILON))throw new RangeError("probabilities must sum to 1");let a=o.map(u=>r*u);mn(a);let l=o.map((u,m)=>a[m]*(1-u)),c=ne(t.map((u,m)=>(u-a[m])**2/a[m])),s="Chi-squared test for given probabilities",f=n-1,i;if(e.simulatePValue??!1){let u=cn(e);s+=Ie(u),f=NaN,i=fn(Xn(r,o,a,u),c,u)}else i=un(c,f);return{method:s,statistic:c,statisticName:"X-squared",parameter:f,parameterName:"df",pValue:i,observed:t,expected:a,residuals:t.map((u,m)=>(u-a[m])/Math.sqrt(a[m])),stdres:t.map((u,m)=>(u-a[m])/Math.sqrt(l[m]))}}function Xn(t,e,n,r){let o=e.length,a=en(o,{size:Math.trunc(r*t),replace:!0,prob:e}),l=Math.trunc(t);if(a.length===0)return new Float64Array(0);if(l===0)throw new RangeError("invalid 'nrow' value (too large or NA)");let c=Math.ceil(a.length/l),s=new Float64Array(c),f=new Float64Array(o);for(let i=0;i<c;i++){f.fill(0);for(let m=0;m<l;m++)f[a[(i*l+m)%a.length]]++;let u=0;for(let m=0;m<o;m++)u+=(f[m]-n[m])**2/n[m];s[i]=u}return s}function Qn(t,e,n,r){let o=t.length,a=e.length,l=t.reduce((i,u)=>i+u,0),c=Pe(l),s=new Int32Array(o*a),f=new Float64Array(Math.trunc(r));for(let i=0;i<f.length;i++){ze(t,e,c,s);let u=0;for(let m=0;m<a;m++)for(let h=0;h<o;h++){let d=n[h][m];u+=(s[h+m*o]-d)**2/d}f[i]=u}return f}function hn(t,e){let n=e.correct??!0,r=t.length,o=t[0].length,a=t.flat();if(a.some(v=>!(v>=0&&v<1/0)))throw new RangeError("all entries of 'x' must be non-negative and finite");let l=ne(a);if(!(l>0))throw new RangeError("at least one entry of 'x' must be positive");let c=t.map(v=>ne(v)),s=t[0].map((v,w)=>ne(t.map(N=>N[w]))),f=c.map(v=>s.map(w=>v*w/l));mn(f.flat());let i=t.map((v,w)=>v.map((N,y)=>N-f[w][y])),u="Pearson's Chi-squared test",m,h=(r-1)*(o-1),d,g=(e.simulatePValue??!1)&&c.every(v=>v>0)&&s.every(v=>v>0),p=!g&&n&&r===2&&o===2?Math.min(.5,...i.flat().map(Math.abs)):0;if(g){let v=cn(e);u+=Ie(v),m=ne(i.flatMap((N,y)=>N.map((k,M)=>k*k/f[y][M]))),h=NaN;let w=Qn(c.map(N=>Math.trunc(N)),s.map(N=>Math.trunc(N)),f,v);d=fn(w,m,v)}else p>0?(u+=" with Yates' continuity correction",m=ne(i.flatMap((v,w)=>v.map((N,y)=>(Math.abs(N)-p)**2/f[w][y])))):m=ne(i.flatMap((v,w)=>v.map((N,y)=>N*N/f[w][y])));let b=f.map((v,w)=>v.map((N,y)=>N*(1-c[w]/l)*(1-s[y]/l)));return{method:u,statistic:m,statisticName:"X-squared",parameter:h,parameterName:"df",pValue:d??un(m,h),observed:t,expected:f,residuals:i.map((v,w)=>v.map((N,y)=>N/Math.sqrt(f[w][y]))),stdres:i.map((v,w)=>v.map((N,y)=>N/Math.sqrt(b[w][y])))}}var Yn=Math.pow(Number.EPSILON,.25);function U(t,e,n,r={}){let o={tol:r.tol??Yn,maxiter:r.maxIter??1e3};return r.fLower!==void 0&&(o.fLower=r.fLower),r.fUpper!==void 0&&(o.fUpper=r.fUpper),on(t,e,n,o).root}function Zn(t,e={}){let n=t.length,r=n===0?0:t[0].length;if(t.some(s=>s.length!==r))throw new TypeError("all rows of the matrix must have the same length");if(n<2||r<2)throw new TypeError("'x' must have at least 2 rows and columns");let o=t.map(s=>Array.from(s));if(o.flat().some(s=>Number.isNaN(s)||s<0))throw new RangeError("all entries of 'x' must be non-negative and finite");if(o.flat().some(s=>s===1/0))throw new RangeError("'x' has entries too large to be integer");let a=o.map(s=>s.map(Re)),l="Fisher's Exact Test for Count Data";if(n===2&&r===2)return nr(a,e,l);let c=e.alternative??"two.sided";if(e.simulatePValue??!1){let s=e.B??2e3;if(!(s>=0&&s<2**31))throw new RangeError("'B' must be a non-negative number");return{method:l+Ie(s),alternative:c,pValue:Jn(a,s)}}return{method:l,alternative:c,pValue:rr(a)}}function Jn(t,e){let n=t.filter(g=>g.some(p=>p>0)),r=t[0].map((g,p)=>p).filter(g=>t.some(p=>p[g]>0));if(n.length<=1)throw new RangeError("need 2 or more non-zero row marginals");if(r.length<=1)throw new RangeError("need 2 or more non-zero column marginals");let o=n.map(g=>r.map(p=>g[p])),a=o.map(g=>g.reduce((p,b)=>p+b,0)),l=o[0].map((g,p)=>o.reduce((b,v)=>b+v[p],0)),c=a.length,s=l.length,f=[0,0];for(let g of o.flat())f=D(f,[-rn(g),0]);let i=f[0]/(1+64*Number.EPSILON),u=Pe(a.reduce((g,p)=>g+p,0)),m=new Int32Array(c*s),h=0,d=Math.trunc(e);for(let g=0;g<d;g++){ze(a,l,u,m);let p=0;for(let b=0;b<m.length;b++)p-=u[m[b]];p<=i&&h++}return Math.max(0,Math.min(1,(1+h)/(e+1)))}var er=1+1e-7,tr=16;function ct(t,e,n){let r=[0,0];for(let o=Math.max(0,e);o<=Math.min(n,t.length-1);o++)t[o]!==0&&(r=D(r,[t[o],0]));return r[0]}var ut=class{m;n;k;lo;hi;logCentral;constructor(e,n,r){this.m=e,this.n=n,this.k=r,this.lo=Math.max(0,r-n),this.hi=Math.min(r,e),this.logCentral=new Float64Array(this.hi-this.lo+1);let o=0,a=1;for(let l=this.lo;l<=this.hi;l++){let c=l-this.lo;c%tr===0||!(a>0&&a<1/0)?(o=ge(l,e,n,r,!0),a=1,this.logCentral[c]=o):this.logCentral[c]=o+Math.log(a),a*=(e-l)*(r-l)/((l+1)*(n-r+l+1))}}density(e){let n=this.logCentral.length,r=Math.log(e),o=new Float64Array(n),a=-1/0;for(let c=0;c<n;c++){let s=this.logCentral[c]+(this.lo+c)*r;o[c]=s,s>a&&(a=s)}for(let c=0;c<n;c++){let s=o[c]-a;o[c]=s<-746?0:Math.exp(s)}let l=ct(o,0,n-1);for(let c=0;c<n;c++)o[c]!==0&&(o[c]=o[c]/l);return o}mean(e){if(e===0)return this.lo;if(e===1/0)return this.hi;let n=this.density(e),r=[0,0];for(let o=0;o<n.length;o++)n[o]!==0&&(r=D(r,[(this.lo+o)*n[o],0]));return r[0]}tail(e,n,r){if(n===1)return r?at(e-1,this.m,this.n,this.k,!1,!1):at(e,this.m,this.n,this.k,!0,!1);if(n===0||n===1/0){let l=n===0?this.lo:this.hi;return(r?e<=l:e>=l)?1:0}let o=this.density(n),a=e-this.lo;return r?ct(o,a,o.length-1):ct(o,0,a)}};function ft(t,e){return e?U(t,0,1):1/U(n=>t(1/n),Number.EPSILON,1)}function nr(t,e,n){let r=$(e.alternative),o=e.or??1;if(!(o>=0))throw new RangeError("'or' must be a single number between 0 and Inf");let a=e.confLevel??.95;if(!(a>0&&a<1))throw new RangeError("confLevel must be a single number between 0 and 1");let[[l,c],[s,f]]=t,i=l,u=new ut(l+s,c+f,l+c),{lo:m,hi:h}=u,d;if(r==="less")d=u.tail(i,o,!1);else if(r==="greater")d=u.tail(i,o,!0);else if(o===0)d=i===m?1:0;else if(o===1/0)d=i===h?1:0;else{let N=u.density(o),y=N[i-m]*er,k=[0,0];for(let M of N)M<=y&&(k=D(k,[M,0]));d=k[0]}let g;if(i===m)g=0;else if(i===h)g=1/0;else{let N=u.mean(1);g=N===i?1:ft(y=>u.mean(y)-i,N>i)}let p={method:n,alternative:r,pValue:d,estimate:g,estimateNames:"odds ratio",nullValue:o,nullValueName:"odds ratio"};if(!(e.confInt??!0))return p;let b=N=>{if(i===h)return 1/0;let y=u.tail(i,1,!1);return y===N?1:ft(k=>u.tail(i,k,!1)-N,y<N)},v=N=>{if(i===m)return 0;let y=u.tail(i,1,!0);return y===N?1:ft(k=>u.tail(i,k,!0)-N,y>N)},w;if(r==="less")w=[0,b(1-a)];else if(r==="greater")w=[v(1-a),1/0];else{let N=(1-a)/2;w=[v(N),b(N)]}return{...p,confInt:w,confLevel:a}}var He=[[0,0]];function re(t){for(let e=He.length;e<=t;e++)He.push(D(He[e-1],jt([e,0])));return He[t]}function Be(t,e,n,r){let o=t+n,a=o-t,l=t-(o-a)+(n-a)+e+r,c=o+l;return[c,l-(c-o)]}var mt=class{scale=-1/0;hi=0;lo=0;add(e,n,r){if(e>this.scale){let s=Number.isFinite(this.scale)?Math.exp(this.scale-e):0;this.hi*=s,this.lo*=s,this.scale=e}let o=r*Math.exp(e-this.scale)*(1+n),a=this.hi+o,l=a-this.hi,c=this.hi-(a-l)+(o-l)+this.lo;this.hi=a+c,this.lo=c-(this.hi-a)}value(){return this.scale===-1/0?0:this.hi*Math.exp(this.scale)}};function rr(t){let e=t.filter(w=>w.some(N=>N>0));if(e.length===0)throw new RangeError("all entries of the table are zero");let n=e[0].map((w,N)=>e.some(y=>y[N]>0));if(e=e.map(w=>w.filter((N,y)=>n[y])),e.length<2||e[0].length<2)return 1;e.length>e[0].length&&(e=e[0].map((w,N)=>e.map(y=>y[N])));let r=e.length,o=e.map(w=>w.reduce((N,y)=>N+y,0)),a=e[0].map((w,N)=>e.reduce((y,k)=>y+k[N],0)).sort((w,N)=>N-w),l=a.length,c=o.reduce((w,N)=>w+N,0),s=_t(re(c));for(let w of o)s=D(s,re(w));for(let w of a)s=D(s,re(w));let f=[0,0];for(let w of e.flat())f=ee(f,re(w));let i=D(f,[Math.log1p(1e-7),0]),u=1e-9*(1+Math.abs(i[0])),[m,h]=i,d=Array.from({length:l},()=>new Map),g=(w,N)=>{let y=N.join(","),k=d[w].get(y);if(k!==void 0)return k;let M=D(s,re(N.reduce((R,F)=>R+F,0)));for(let R of N)M=ee(M,re(R));for(let R=w;R<l;R++)M=ee(M,re(a[R]));let x={R:N,KZ:M,max:0,min:0,edges:[],pastHi:[],pastLo:[],count:[],index:new Map};if(d[w].set(y,x),w===l-1){let R=[0,0];for(let F of N)R=ee(R,re(F));return x.max=x.min=R[0],x.edges.push({to:x,hi:R[0],lo:R[1],mult:1}),x}let A=new Map,E=new Array(r+1).fill(0);for(let R=r-1;R>=0;R--)E[R]=E[R+1]+N[R];let I=new Array(r).fill(0),q=(R,F,L)=>{if(R===r-1){I[R]=F;let C=ee(L,re(F)),W=N.map((se,Ee)=>se-I[Ee]).sort((se,Ee)=>se-Ee),_=g(w+1,W),X=`${W.join(",")}|${C[0]}`,oe=A.get(X);oe===void 0?A.set(X,{to:_,hi:C[0],lo:C[1],mult:1}):oe.mult++;return}let S=Math.max(0,F-E[R+1]),T=Math.min(N[R],F);for(let C=S;C<=T;C++)I[R]=C,q(R+1,F-C,ee(L,re(C)))};if(q(0,a[w],[0,0]),x.edges=[...A.values()],x.max=Math.max(...x.edges.map(R=>R.hi+R.to.max)),x.min=Math.min(...x.edges.map(R=>R.hi+R.to.min)),w===l-2){let R=x.edges.map(_=>{let X=_.to.edges[0];return{v:D([_.hi,_.lo],[X.hi,X.lo]),mult:_.mult}});R.sort((_,X)=>_.v[0]-X.v[0]||_.v[1]-X.v[1]);let F=R.length,L=R[F-1].v[0],S=new Float64Array(F),T=new Float64Array(F),C=new Float64Array(F),W=[0,0];R.forEach(({v:_,mult:X},oe)=>{S[oe]=_[0],T[oe]=_[1];let se=ee(_,[L,0]);W=D(W,[X*Math.exp(se[0])*(1+se[1]),0]),C[oe]=W[0]}),x.dist={hi:S,lo:T,cum:C,vmax:L,kv:D(s,[L,0])}}return x},p=g(0,[...o].sort((w,N)=>w-N)),b=new mt,v=(w,N,y,k)=>{if(N+w.max<=m-u){let[q,R]=Be(w.KZ[0],w.KZ[1],N,y);return b.add(q,R,k),!0}if(N+w.min>m+u)return!0;let M=w.dist;if(M===void 0)return!1;let[x,A]=Be(m,h,-N,-y),E=0,I=M.hi.length;for(;E<I;){let q=E+I>>>1,R=M.hi[q];R<x||R===x&&M.lo[q]<=A?E=q+1:I=q}if(E>0){let[q,R]=Be(M.kv[0],M.kv[1],N,y);b.add(q,R,k*M.cum[E-1])}return!0};v(p,0,0,1)||(p.pastHi.push(0),p.pastLo.push(0),p.count.push(1));for(let w=0;w<l-2;w++)for(let N of d[w].values()){let{pastHi:y,pastLo:k,count:M}=N;if(M.length!==0){for(let{to:x,hi:A,lo:E,mult:I}of N.edges)for(let q=0;q<M.length;q++){let[R,F]=Be(y[q],k[q],A,E),L=M[q]*I;if(v(x,R,F,L))continue;let S=x.index.get(R);S===void 0?(x.index.set(R,x.count.length),x.pastHi.push(R),x.pastLo.push(F),x.count.push(L)):x.count[S]+=L}N.pastHi=N.pastLo=N.count=[],N.index.clear()}}return Math.min(1,b.value())}function ht(t,e,n={}){let r;e!==void 0&&!ArrayBuffer.isView(e)&&!Array.isArray(e)?n=e:r=e;let o=$(n.alternative),a=n.mu??0,l=n.paired??!1,c=n.exact??null,s=n.correct??!0,f=n.confInt??!1,i=n.confLevel??.95,u=n.tolRoot??1e-4;if(!Number.isFinite(a))throw new RangeError("mu must be a single finite number");if(f&&!(i>0&&i<1))throw new RangeError("confLevel must be a number strictly between 0 and 1");if(l&&r===void 0)throw new TypeError("y is required when paired is true");let m,h;if(l){let[g,p]=$e(Array.from(t),Array.from(r));m=ue(g.map((b,v)=>b-p[v]))}else m=ue(Array.from(t)),r!==void 0&&(h=ue(Array.from(r)));if(m.length<1)throw new Error("not enough (non-missing) 'x' observations");if(h!==void 0&&h.length<1)throw new Error("not enough (non-missing) 'y' observations");let d={alternative:o,mu:a,correct:s,confInt:f,confLevel:i,tolRoot:u};return h===void 0?sr(m,c,l,d):lr(m,h,c,d)}function Ge(t,e,n){return n?e==="two.sided"?Math.sign(t)*.5:e==="greater"?.5:-.5:0}function pn(t,e){return e==="less"?z(t):e==="greater"?z(t,{lowerTail:!1}):2*Math.min(z(t),z(t,{lowerTail:!1}))}function or(t){if(!(t>0)||!Number.isFinite(t))return t;let n=1-Math.floor(Math.log10(t)),r=n>=0?t*10**n:t/10**-n,o=Math.round(r);return o-r===.5&&o%2!==0&&(o-=1),n>=0?o/10**n:o*10**-n}function dt(t){let e=t.length;if(e===0)return NaN;let n=Math.floor(e/2);return e%2===1?t[n]:te([t[n-1],t[n]])}var pt=(t,e)=>t-e;function gn(t){let e=t.length,n=H(t.map(Math.abs)),r=0;for(let l=0;l<e;l++)t[l]>0&&(r+=n[l]);let o=0;for(let l of fe(n))o+=l*l*l-l;let a=Math.sqrt(e*(e+1)*(2*e+1)/24-o/48);return[r,r-e*(e+1)/4,a]}function sr(t,e,n,r){let{alternative:o,mu:a,correct:l}=r,c=t.map(k=>k-a),s=c.some(k=>k===0);s&&(c=c.filter(k=>k!==0));let f=c.length,i=e??f<50,u=H(c.map(Math.abs)),m=fe(u).length>0,[h,d,g]=gn(c),p,b,v=i&&!m&&!s;if(v){b="Wilcoxon signed rank exact test";let k=f*(f+1)/2;if(o==="less")p=we(h,f,!0,!1);else if(o==="greater")p=we(h-1,f,!1,!1);else{let M=h>k/2?we(h-1,f,!1,!1):we(h,f,!0,!1);p=Math.min(1,2*M)}}else b=`Wilcoxon signed rank test${l?" with continuity correction":""}`,p=pn((d-Ge(d,o,l))/g,o);let w={method:b,alternative:o,statistic:h,statisticName:"V",pValue:p,nullValue:a,nullValueName:n?"location shift":"location"};if(!r.confInt)return w;let N=c.map(k=>k+a),y=v?ar(N,r):ir(N,r);return{...w,...y}}function Ue(t,e,n){return t==="less"?[-1/0,n]:t==="greater"?[e,1/0]:[e,n]}function dn(t,e,n){let r={confInt:Ue(t,NaN,NaN),confLevel:0,estimate:e};return n!==void 0&&(r.estimateNames=n),r}function wn(t,e,n){let r=t(e==="two.sided"?n/2:n);return r===0?1:r}function Nn(t){if(!(t>0))throw new RangeError("tolRoot must be positive")}function ar(t,e){let{alternative:n,confLevel:r}=e,o=t.length,a=[];for(let u=0;u<o;u++)for(let m=u;m<o;m++)a.push((t[u]+t[m])/2);a.sort(pt);let l=a.length,c=1-r,s=wn(u=>Qt(u,o,!0,!1),n,c),f=we(s-1,o,!0,!1),i=n==="two.sided"?2*f:f;return{confInt:Ue(n,a[s-1],a[l-s]),confLevel:i-c>c/2?1-or(i):r,estimate:dt(a),estimateNames:"(pseudo)median"}}function ir(t,e){let{alternative:n,correct:r,confLevel:o,tolRoot:a}=e,l=t.length;if(l===0)return dn(n,NaN);let c=Math.min(...t),s=Math.max(...t);if(!Number.isFinite(c)||!Number.isFinite(s)||l===1||c===s)return dn(n,(c+s)/2,"midrange");let f=(w,N)=>{let[,y,k]=gn(t.map(M=>M-w).filter(M=>M!==0));return(y-Ge(y,n,N))/k},i=f(c,r),u=f(s,r),m=w=>-P(w),h=w=>n==="greater"?!(i<m(w)):n==="less"?!(u>P(w/2)):!(i<m(w/2))&&!(u>P(w/2)),d=1-o,g=!1;for(;!h(d)&&d<1;)d*=2,g=!0;Nn(a);let p=w=>U(N=>f(N,r)-w,c,s,{tol:a,fLower:i-w,fUpper:u-w}),b;if(d>=1){let w=dt([...t].sort(pt));b=Ue(n,w,w)}else n==="greater"?b=[p(m(d)),1/0]:n==="less"?b=[-1/0,p(P(d))]:b=[p(m(d/2)),p(P(d/2))];let v=U(w=>f(w,!1),c,s,{tol:a,fLower:f(c,!1),fUpper:f(s,!1)});return{confInt:b,confLevel:g?1-Math.min(1,d):o,estimate:v,estimateNames:"(pseudo)median"}}function vn(t,e){let n=t.length,r=e.length,o=H([...t,...e]),a=0;for(let i=0;i<n;i++)a+=o[i];let l=a-n*(n+1)/2,c=0;for(let i of fe(o))c+=i*i*i-i;let s=n+r,f=Math.sqrt(n*r/12*(s+1-c/(s*(s-1))));return[l,l-n*r/2,f]}function lr(t,e,n,r){let{alternative:o,mu:a,correct:l}=r,c=t.length,s=e.length,f=t.map(N=>N-a),i=n??(c<50&&s<50),u=fe([...f,...e]).length>0,[m,h,d]=vn(f,e),g,p,b=i&&!u;if(b)if(p="Wilcoxon rank sum exact test",o==="less")g=Ne(m,c,s,!0,!1);else if(o==="greater")g=Ne(m-1,c,s,!1,!1);else{let N=m>c*s/2?Ne(m-1,c,s,!1,!1):Ne(m,c,s,!0,!1);g=Math.min(1,2*N)}else p=`Wilcoxon rank sum test${l?" with continuity correction":""}`,g=pn((h-Ge(h,o,l))/d,o);let v={method:p,alternative:o,statistic:m,statisticName:"W",pValue:g,nullValue:a,nullValueName:"location shift"};if(!r.confInt)return v;let w=b?cr(t,e,r):fr(t,e,r);return{...v,...w}}function cr(t,e,n){let{alternative:r,confLevel:o}=n,a=t.length,l=e.length,c=[];for(let h of t)for(let d of e)c.push(h-d);c.sort(pt);let s=c.length,f=1-o,i=wn(h=>Yt(h,a,l,!0,!1),r,f),u=Ne(i-1,a,l,!0,!1),m=r==="two.sided"?2*u:u;return{confInt:Ue(r,c[i-1],c[s-i]),confLevel:m-f>f/2?1-m:o,estimate:dt(c),estimateNames:"difference in location"}}function fr(t,e,n){let{alternative:r,correct:o,confLevel:a,tolRoot:l}=n,c=Math.min(...t)-Math.max(...e),s=Math.max(...t)-Math.min(...e);if(!Number.isFinite(c)||!Number.isFinite(s))throw new Error("cannot compute the confidence interval because the differences are not finite");let f=(h,d)=>{let[,g,p]=vn(t.map(b=>b-h),e);return(g-Ge(g,r,d))/p},i=(h,d)=>{let g=f(c,d)-h,p=f(s,d)-h;if(Number.isNaN(g)||Number.isNaN(p))throw new Error("cannot compute the confidence interval because all observations are tied");return g<=0?c:p>=0?s:(Nn(l),U(b=>f(b,d)-h,c,s,{tol:l,fLower:g,fUpper:p}))},u=1-a,m;return r==="greater"?m=[i(-P(u),o),1/0]:r==="less"?m=[-1/0,i(P(u),o)]:m=[i(-P(u/2),o),i(P(u/2),o)],{confInt:m,confLevel:a,estimate:i(0,!1),estimateNames:"difference in location"}}var bn=["holm","hochberg","hommel","bonferroni","BH","BY","fdr","none"];function ur(t){if(bn.includes(t))return t;let e=bn.filter(n=>n.startsWith(t));if(t.length===0||e.length!==1)throw new RangeError(`invalid method "${t}"`);return e[0]}function gt(t,e={}){let n=typeof e=="string"?{method:e}:e,r=ur(n.method??"holm"),o=Array.from(t),a=[];for(let u=0;u<o.length;u++)Number.isNaN(o[u])||a.push(u);let l=a.length,c=n.n??l;if(!(c>=l))throw new RangeError("n must be at least the number of non-NaN p-values");if(c<=1)return o;let s=a.map(u=>o[u]),f=mr(s,r,c),i=o.slice();return a.forEach((u,m)=>i[u]=f[m]),i}function Ke(t,e){let n=t.map((r,o)=>o);return n.sort((r,o)=>(e?t[o]-t[r]:t[r]-t[o])||r-o),n}function mr(t,e,n){let r=t.length,o=new Array(r);switch(e){case"none":return t.slice();case"bonferroni":return t.map(a=>Math.min(1,n*a));case"holm":{let a=Ke(t,!1),l=-1/0;return a.forEach((c,s)=>{l=Math.max(l,(n-s)*t[c]),o[c]=Math.min(1,l)}),o}case"hochberg":{let a=Ke(t,!0),l=1/0;return a.forEach((c,s)=>{let f=r-s;l=Math.min(l,(n-f+1)*t[c]),o[c]=Math.min(1,l)}),o}case"BH":case"fdr":case"BY":{let a=e==="BY"?tn(Array.from({length:Math.floor(n)},(s,f)=>1/(f+1))):1,l=Ke(t,!0),c=1/0;return l.forEach((s,f)=>{let i=r-f;c=Math.min(c,a*n/i*t[s]),o[s]=Math.min(1,c)}),o}case"hommel":return hr(t,n)}}function hr(t,e){if(!Number.isInteger(e))throw new RangeError("n must be an integer for the hommel method");let n=t.length,r=[...t,...new Array(e-n).fill(1)],o=Ke(r,!1),a=o.map(s=>r[s]),l=a.slice();for(let s=e;s>=2;s--){let f=1/0;for(let i=1;i<=s;i++)f=Math.min(f,s*a[e-s+i-1]/i);for(let i=e-s;i<e;i++)l[i]=Math.max(l[i],f);for(let i=0;i<e-s;i++)l[i]=Math.max(l[i],Math.min(s*a[i],f))}let c=new Array(n);return o.forEach((s,f)=>{s<n&&(c[s]=l[f])}),c}var dr=1+1e-7;function Xe(t){return Number.isFinite(t)&&t>=0&&Math.abs(t-Math.round(t))<=1e-7*Math.max(1,Math.abs(t))}function pr(t,e,n){if(n===0)return t===0?1:0;if(n===1)return t===e?1:0;let r=e*n;if(t===r)return 1;let o=pe(t,e,n,!1)*dr,a=0;if(t<r){for(let s=Math.ceil(r);s<=e;s++)pe(s,e,n,!1)<=o&&a++;let c=a===0?0:ce(e-a,e,n,!1,!1);return Math.min(1,ce(t,e,n,!0,!1)+c)}for(let c=0;c<=Math.floor(r);c++)pe(c,e,n,!1)<=o&&a++;let l=a===0?0:ce(a-1,e,n,!0,!1);return Math.min(1,ce(t-1,e,n,!1,!1)+l)}function wt(t,e,n={}){let r,o;if(typeof t!="number"){if(t.length!==2)throw new RangeError("incorrect length of 'x'");if(e!==void 0&&typeof e!="number"&&(n=e),!Xe(t[0])||!Xe(t[1]))throw new RangeError("'x' must be nonnegative and integer");r=Math.round(t[0]),o=Math.round(t[0])+Math.round(t[1])}else{if(typeof e!="number")throw new TypeError("'n' is required when 'x' is a single number");if(!Xe(t))throw new RangeError("'x' must be nonnegative and integer");if(r=Math.round(t),!(Xe(e)&&Math.round(e)>=r&&e>0))throw new RangeError("'n' must be a positive integer >= 'x'");o=Math.round(e)}let a=n.p??.5;if(!(a>=0&&a<=1))throw new RangeError("'p' must be a single number between 0 and 1");let l=$(n.alternative),c=n.confLevel??.95;J(c);let s;l==="less"?s=ce(r,o,a,!0,!1):l==="greater"?s=ce(r-1,o,a,!1,!1):s=pr(r,o,a);let f=m=>r===0?0:ot(m,r,o-r+1,!0,!1),i=m=>r===o?1:ot(1-m,r+1,o-r,!0,!1),u;if(l==="less")u=[0,i(1-c)];else if(l==="greater")u=[f(1-c),1];else{let m=(1-c)/2;u=[f(m),i(m)]}return{method:"Exact binomial test",alternative:l,statistic:r,statisticName:"number of successes",parameter:o,parameterName:"number of trials",pValue:s,confInt:u,confLevel:c,estimate:r/o,estimateNames:"probability of success",nullValue:a,nullValueName:"probability of success"}}var gr=1+1e-7;function wr(t){return Number.isFinite(t)&&t>=0&&Math.abs(t-Math.round(t))<=1e-7*Math.max(1,Math.abs(t))}function Nr(t,e){if(e===0)return t===0?1:0;if(t===e)return 1;let n=Ae(t,e,!1)*gr,r=c=>Ae(c,e,!1)<=n,o=Math.floor(e);if(t<e){let c=Math.max(t+1,o),s=c;if(!r(c)){let f=c,i=1;for(s=c+1;!r(s);)f=s,i*=2,s=c+i;for(;s-f>1;){let u=f+Math.floor((s-f)/2);r(u)?s=u:f=u}}return Math.min(1,le(t,e,!0,!1)+le(s-1,e,!1,!1))}let a=Math.min(t-1,o),l;if(!r(0))l=-1;else if(r(a))l=a;else{l=0;let c=a;for(;c-l>1;){let s=l+Math.floor((c-l)/2);r(s)?l=s:c=s}}return Math.min(1,le(l,e,!0,!1)+le(t-1,e,!1,!1))}function vr(t,e={}){let n=typeof t=="number"?[t]:Array.from(t);if(n.length<1||n.length>2)throw new RangeError("incorrect length of 'x'");if(!n.every(wr))throw new RangeError("'x' must be finite, nonnegative, and integer");let r=n.map(Math.round),o=r.length,a=e.T??1,l=typeof a=="number"?new Array(o).fill(a):Array.from(a);if(l.length!==o)throw new RangeError("'x' and 'T' have incompatible length");if(!l.every(b=>Number.isFinite(b)&&b>=0))throw new RangeError("'T' must be nonnegative");let c=e.r??1;if(!(Number.isFinite(c)&&c>=0))throw new RangeError("'r' must be a single positive number");let s=$(e.alternative),f=e.confLevel??.95;if(J(f),o===2){let[b,v]=r,[w,N]=l,y=b+v,k=c*w/(c*w+N),M=wt([b,v],{p:k,alternative:s,confLevel:f}),x=A=>A/(1-A)*(N/w);return{method:"Comparison of Poisson rates",alternative:s,statistic:b,statisticName:"count1",parameter:y*c*w/(w+c*N),parameterName:"expected count1",pValue:M.pValue,confInt:[x(M.confInt[0]),x(M.confInt[1])],confLevel:f,estimate:b/w/(v/N),estimateNames:"rate ratio",nullValue:c,nullValueName:"rate ratio"}}let i=r[0],u=l[0],m=c*u,h;s==="less"?h=le(i,m,!0,!1):s==="greater"?h=le(i-1,m,!1,!1):h=Nr(i,m);let d=b=>i===0?0:rt(b,i,1,!0,!1),g=b=>rt(1-b,i+1,1,!0,!1),p;if(s==="less")p=[0,g(1-f)];else if(s==="greater")p=[d(1-f),1/0];else{let b=(1-f)/2;p=[d(b),g(b)]}return{method:"Exact Poisson test",alternative:s,statistic:i,statisticName:"number of events",parameter:u,parameterName:"time base",pValue:h,confInt:[p[0]/u,p[1]/u],confLevel:f,estimate:i/u,estimateNames:"event rate",nullValue:c,nullValueName:"event rate"}}function Nt(t,e,n={}){let r,o,a=n;if(typeof t!="number"&&t.length>0&&Array.isArray(t[0])){let E=t;if(E.some(I=>I.length!==2))throw new RangeError("'x' must have 2 columns");r=E.map(I=>I[0]),o=E.map(I=>I[0]+I[1]),e!==void 0&&typeof e=="object"&&!Array.isArray(e)&&(a=e)}else{if(e===void 0||typeof e=="object"&&!Array.isArray(e))throw new RangeError("'n' must be given");r=typeof t=="number"?[t]:Array.from(t),o=typeof e=="number"?[e]:Array.from(e)}if(r.length!==o.length)throw new RangeError("'x' and 'n' must have the same length");let l=r.length,c=[];for(let E=0;E<l;E++)!Number.isNaN(r[E])&&!Number.isNaN(o[E])&&c.push(E);let s=c.length;if(s<1)throw new RangeError("not enough data");if(r=c.map(E=>r[E]),o=c.map(E=>o[E]),o.some(E=>!(E>0)))throw new RangeError("elements of 'n' must be positive");if(r.some(E=>!(E>=0)))throw new RangeError("elements of 'x' must be nonnegative");if(r.some((E,I)=>E>o[I]))throw new RangeError("elements of 'x' must not be greater than those of 'n'");let f;if(a.p!==void 0){let E=typeof a.p=="number"?[a.p]:Array.from(a.p);if(E.length!==l)throw new RangeError("'p' must have the same length as 'x' and 'n'");if(f=c.map(I=>E[I]),f.some(I=>!(I>0&&I<1)))throw new RangeError("elements of 'p' must be in (0,1)")}let i=f!==void 0;s===1&&f===void 0&&(f=[.5]);let u=a.confLevel??.95;J(u);let m=$(a.alternative);(s>2||s===2&&i)&&(m="two.sided");let h=r.map((E,I)=>E/o[I]),d=s===2?h[0]-h[1]:0,g=s===2?1/o[0]+1/o[1]:0,p=(a.correct??!0)&&s<=2?.5:0,b=!1;if(p>0&&s===1){let E=Math.abs(r[0]-o[0]*f[0]);E<=p&&([p,b]=[E,!0])}else if(p>0&&s===2&&!i){let E=Math.abs(d)/g;E<=p&&([p,b]=[E,!0])}let v=r.reduce((E,I)=>E+I,0)/o.reduce((E,I)=>E+I,0),w=0;if(!b)for(let E=0;E<s;E++){let I=f?.[E]??v,q=o[E]*I,R=o[E]*(1-I);w+=(Math.abs(r[E]-q)-p)**2/q,w+=(Math.abs(o[E]-r[E]-R)-p)**2/R}let N=f!==void 0?s:s-1,y;if(m==="two.sided")y=G(w,N/2,2,!1,!1);else{let E=Math.sign(s===1?h[0]-f[0]:d);y=z(E*Math.sqrt(w),{lowerTail:m==="less"})}let k;if(s===1||s===2&&!i){let E=P(m==="two.sided"?(1+u)/2:u);if(s===1){let I=o[0],q=E*E,R=(C,W)=>(C+q/(2*I)+W*E*Math.sqrt(C*(1-C)/I+q/(4*I*I)))/(1+q/I),F=h[0]+p/I,L=h[0]-p/I,S=Math.min(1,Math.max(0,F>=1?1:R(F,1))),T=Math.min(1,Math.max(0,L<=0?0:R(L,-1)));k=m==="two.sided"?[T,S]:m==="greater"?[T,1]:[0,S]}else{let I=Math.sqrt(h.reduce((L,S,T)=>L+S*(1-S)/o[T],0)),q=E*I+p*g,R=Math.max(-1,d-q),F=Math.min(1,d+q);k=m==="two.sided"?[R,F]:m==="greater"?[R,1]:[-1,F]}}let M=s===1?"p":c.map(E=>`prop ${E+1}`),A={method:`${s===1?"1-sample proportions test":`${s}-sample test for ${i?"given proportions":"equality of proportions"}`} ${p!==0?"with":"without"} continuity correction`,alternative:m,statistic:w,statisticName:"X-squared",parameter:N,parameterName:"df",pValue:y,estimate:s===1?h[0]:h,estimateNames:M};return f!==void 0&&(A.nullValue=s===1?f[0]:f,A.nullValueName=M),k!==void 0&&(A.confInt=k,A.confLevel=u),A}function br(t,e,n={}){let r;if(t.length>0&&Array.isArray(t[0])){e!==void 0&&!Array.isArray(e)&&(n=e),r=t.map(i=>Array.from(i));let f=r.length;if(f<2||r.some(i=>i.length!==f))throw new RangeError("'x' must be square with at least two rows and columns");if(r.some(i=>i.some(u=>!Number.isFinite(u)||u<0)))throw new RangeError("all entries of 'x' must be nonnegative and finite")}else{if(!Array.isArray(e))throw new TypeError("'y' is required when 'x' is not a table");r=yr(t,e)}let o=n.correct??!0,a=r.length,l,c=o&&a===2&&r[0][1]!==r[1][0];if(c){let f=r[0][1],i=r[1][0];l=(Math.abs(f-i)-1)**2/(f+i)}else{l=0;for(let f=0;f<a;f++)for(let i=f+1;i<a;i++){let u=r[f][i],m=r[i][f];l+=(u-m)**2/(u+m)}}let s=a*(a-1)/2;return{method:c?"McNemar's Chi-squared test with continuity correction":"McNemar's Chi-squared test",statistic:l,statisticName:"McNemar's chi-squared",parameter:s,parameterName:"df",pValue:G(l,s/2,2,!1,!1)}}function yr(t,e){if(t.length!==e.length)throw new RangeError("'x' and 'y' must have the same length");let n=[];for(let f=0;f<t.length;f++){let i=t[f],u=e[f];typeof i=="number"&&Number.isNaN(i)||typeof u=="number"&&Number.isNaN(u)||n.push([i,u])}let r=f=>Array.from(new Set(f)).sort((i,u)=>typeof i=="number"&&typeof u=="number"?i-u:String(i)<String(u)?-1:String(i)>String(u)?1:0),o=r(n.map(f=>f[0])),a=r(n.map(f=>f[1]));if(o.length<2||o.length!==a.length)throw new RangeError("'x' and 'y' must have the same number of levels (minimum 2)");let l=new Map(o.map((f,i)=>[f,i])),c=new Map(a.map((f,i)=>[f,i])),s=o.map(()=>new Array(o.length).fill(0));for(let[f,i]of n)s[l.get(f)][c.get(i)]++;return s}function Mr(t,e,n={}){let r=Array.from(t).filter(Number.isFinite),o=Array.from(e).filter(Number.isFinite),a=n.ratio??1;if(!(Number.isFinite(a)&&a>0))throw new RangeError("'ratio' must be a single positive number");let l=$(n.alternative),c=n.confLevel??.95;J(c);let s=r.length-1,f=o.length-1;if(s<1)throw new Error("not enough 'x' observations");if(f<1)throw new Error("not enough 'y' observations");let i=Y(r)/Y(o),u=i/a,m=Q(u,s,f,!0,!1),h=Q(u,s,f,!1,!1),d,g;if(l==="less")d=m,g=[0,i/qe(1-c,s,f,!0,!1)];else if(l==="greater")d=h,g=[i/qe(c,s,f,!0,!1),1/0];else{d=Math.min(1,2*Math.min(m,h));let p=(1-c)/2;g=[i/qe(1-p,s,f,!0,!1),i/qe(p,s,f,!0,!1)]}return{method:"F test to compare two variances",alternative:l,statistic:u,statisticName:"F",parameter:[s,f],parameterName:["num df","denom df"],pValue:d,confInt:g,confLevel:c,estimate:i,estimateNames:"ratio of variances",nullValue:a,nullValueName:"ratio of variances"}}function xr(t){let e=t.length;if(e<2)throw new RangeError("'x' must be a list with at least 2 elements");let n=[],r=[];for(let i of t){let u=Array.from(i).filter(Number.isFinite);if(u.length<2)throw new RangeError("there must be at least 2 observations in each group");n.push(u.length-1),r.push(Y(u))}let o=0,a=0,l=0,c=0;for(let i=0;i<e;i++)o+=n[i],a+=n[i]*r[i],l+=n[i]*Math.log(r[i]),c+=1/n[i];a/=o;let s=(o*Math.log(a)-l)/(1+(c-1/o)/(3*(e-1))),f=e-1;return{method:"Bartlett test of homogeneity of variances",statistic:s,statisticName:"Bartlett's K-squared",parameter:f,parameterName:"df",pValue:G(s,f/2,2,!1,!1)}}function vt(t,e,n="drop"){if(e===void 0){let l=t;if(l.length>0&&typeof l[0]=="number")throw new TypeError("'g' is required when 'x' is a single sample");let c=l.map(i=>Array.from(i).filter(u=>!Number.isNaN(u)));if(n==="error"&&c.some(i=>i.length===0))throw new RangeError("all groups must contain data");let s=[],f=[];return c.forEach((i,u)=>{i.length!==0&&(s.push(String(u+1)),f.push(i))}),{labels:s,groups:f}}let r=Array.from(t);if(r.length!==e.length)throw new RangeError("'x' and 'g' must have the same length");let o=new Map;for(let l=0;l<r.length;l++){let c=r[l],s=e[l];if(Number.isNaN(c)||typeof s=="number"&&Number.isNaN(s))continue;let f=o.get(s);f===void 0&&o.set(s,f=[]),f.push(c)}let a=Array.from(o.keys()).sort((l,c)=>typeof l=="number"&&typeof c=="number"?l-c:String(l)<String(c)?-1:String(l)>String(c)?1:0);return{labels:a.map(String),groups:a.map(l=>o.get(l))}}function me(t,e,n="drop"){return vt(t,e,n).groups}function yn(t){let e=[...t].sort((r,o)=>r-o),n=e.length;return n%2===1?e[(n-1)/2]:(e[n/2-1]+e[n/2])/2}function bt(t){if(t.length===0)throw new RangeError("'y' must have at least one row");let e=t[0].length;if(t.some(n=>n.length!==e))throw new RangeError("all rows of 'y' must have the same length");return t.filter(n=>n.every(r=>!Number.isNaN(r))).map(n=>Array.from(n))}function yt(t,e,n,r){return{method:t,statistic:n,statisticName:e,parameter:r,parameterName:"df",pValue:G(n,r/2,2,!1,!1)}}function Mn(t){let e=0;for(let n of fe(t))e+=n*n*n-n;return e}function Er(t,e){let n=me(t,e,"error"),r=n.length;if(r<2)throw new RangeError("all observations are in the same group");let o=n.flat(),a=o.length,l=H(o),c=0,s=0;for(let f of n){let i=0;for(let u=0;u<f.length;u++)i+=l[s+u];s+=f.length,c+=i*i/f.length}return c=(12*c/(a*(a+1))-3*(a+1))/(1-Mn(o)/(a*a*a-a)),yt("Kruskal-Wallis rank sum test","Kruskal-Wallis chi-squared",c,r-1)}function kr(t){let e=bt(t),n=e.length,r=t[0]?.length??0;if(n<2||r<2)throw new RangeError("'y' must have at least two complete rows and two columns");let o=new Array(r).fill(0),a=0;for(let s of e){let f=H(s);for(let i=0;i<r;i++)o[i]+=f[i];a+=Mn(s)}let l=0;for(let s of o)l+=(s-n*(r+1)/2)**2;let c=12*l/(n*r*(r+1)-a/(r-1));return yt("Friedman rank sum test","Friedman chi-squared",c,r-1)}function Rr(t){let e=bt(t),n=t.length,r=t[0]?.length??0;if(e.length<2||r<2)throw new RangeError("'y' must have at least two complete rows and two columns");let o=H(e.map(h=>Math.max(...h)-Math.min(...h))),a=new Array(r).fill(0),l=0;e.forEach((h,d)=>{let g=H(h);for(let p=0;p<r;p++){let b=o[d]*(g[p]-(r+1)/2);l+=b*b,a[p]+=b}});let c=0;for(let h of a)c+=h*h;c/=n;let s=r-1,f=(n-1)*(r-1),i,u,m=[s,f];if(l===c){i=NaN,m=[NaN,NaN];let h=0;for(let d=2;d<=r;d++)h+=Math.log(d);u=Math.exp((1-n)*h)}else i=(n-1)*c/(l-c),u=Q(i,s,f,!1,!1);return{method:"Quade test",statistic:i,statisticName:"Quade F",parameter:m,parameterName:["num df","denom df"],pValue:u}}function Ar(t,e){let n=me(t,e,"error"),r=n.length;if(r<2)throw new RangeError("all observations are in the same group");let o=n.flatMap(m=>{let h=yn(m);return m.map(d=>Math.abs(d-h))}),a=o.length,c=H(o).map(m=>P((1+m/(a+1))/2)),s=0;for(let m of c)s+=m;let f=s/a,i=0,u=0;for(let m of n){let h=0;for(let d=0;d<m.length;d++)h+=c[u+d];u+=m.length,i+=m.length*(h/m.length-f)**2}return i/=Y(c),yt("Fligner-Killeen test of homogeneity of variances","Fligner-Killeen:med chi-squared",i,r-1)}function qr(t,e,n={}){let r=Array.from(t).filter(Number.isFinite),o=Array.from(e).filter(Number.isFinite),a=$(n.alternative),l=r.length,c=o.length,s=l+c;if(s<3)throw new RangeError("not enough observations");let f=r.concat(o),i=Array.from({length:s},(N,y)=>y).sort((N,y)=>f[N]-f[y]),u=new Array(s),m=0;for(;m<s;){let N=m;for(;N+1<s&&f[i[N+1]]===f[i[m]];)N++;let y=0;for(let k=m;k<=N;k++)y+=(k+1-(s+1)/2)**2;y/=N-m+1;for(let k=m;k<=N;k++)u[i[k]]=y;m=N+1}let h=0;for(let N=0;N<l;N++)h+=u[N];let d=0;for(let N of u)d+=N;d/=s;let g=0;for(let N of u)g+=(N-d)**2;let p=l*d,b=l*c/(s*(s-1))*g,v=(h-p)/Math.sqrt(b),w=a==="less"?z(v):a==="greater"?z(v,{lowerTail:!1}):2*z(-Math.abs(v));return{method:"Mood two-sample test of scale",alternative:a,statistic:v,statisticName:"Z",pValue:w}}function he(t,e){let n=0;for(let r=t.length-1;r>=0;r--)n=n*e+t[r];return n}var Tr=[0,.221157,-.147981,-2.07119,4.434685,-2.706056],Ir=[0,.042981,-.293762,-1.752461,5.682633,-3.582633],Sr=[.544,-.39978,.025054,-6714e-7],Lr=[1.3822,-.77857,.062767,-.0020322],Fr=[-1.5861,-.31082,-.083751,.0038915],Vr=[-.4803,-.082676,.0030302],Cr=[-2.273,.459];function Or(t){if(!(t>=3)||t!==Math.floor(t))throw new RangeError("n must be an integer of at least 3");let e=new Float64Array(t);if(t===3)return e[0]=-Math.SQRT1_2,e[2]=Math.SQRT1_2,e;let n=Math.floor(t/2),r=new Float64Array(n),o=0;for(let u=0;u<n;u++)r[u]=-P((u+1-.375)/(t+.25)),o+=r[u]*r[u];o*=2;let a=Math.sqrt(o),l=1/Math.sqrt(t),c=r[0]/a+he(Tr,l),s=new Float64Array(n);s[0]=c;let f,i;if(t>5){let u=r[1]/a+he(Ir,l);s[1]=u,f=2,i=Math.sqrt((o-2*r[0]*r[0]-2*r[1]*r[1])/(1-2*c*c-2*u*u))}else f=1,i=Math.sqrt((o-2*r[0]*r[0])/(1-2*c*c));for(let u=f;u<n;u++)s[u]=r[u]/i;for(let u=0;u<n;u++)e[t-1-u]=s[u],e[u]=-s[u];return e}function xn(t){let e=t.length,n=Or(e),r=t[e-1]-t[0],o=0;for(let f of t)o+=f/r;o/=e;let a=0,l=0,c=0;for(let f=0;f<e;f++){let i=t[f]/r-o;a+=n[f]*n[f],l+=i*i,c+=n[f]*i}let s=Math.sqrt(a*l);return(s-c)*(s+c)/(a*l)}var Pr=1.90985931710274,zr=1.0471975511966;function En(t,e){if(Number.isNaN(t)||!(e>=3))return NaN;if(e===3){let l=Pr*(Math.asin(Math.sqrt(1-t))-zr);return Math.max(l,0)}let n=Math.log(t);if(e<=11){let l=he(Cr,e);if(n>=l)return 1e-99;let c=he(Sr,e),s=Math.exp(he(Lr,e));return z(-Math.log(l-n),{mean:c,sd:s,lowerTail:!1})}let r=Math.log(e),o=he(Fr,r),a=Math.exp(he(Vr,r));return z(n,{mean:o,sd:a,lowerTail:!1})}function $r(t,e,n={}){let r;e!==void 0&&!Array.isArray(e)?n=e:r=e;let o=me(t,r),a=n.varEqual??!1,l=o.length;if(l<2)throw new RangeError("not enough groups");let c=o.map(h=>h.length);if(c.some(h=>h<2))throw new RangeError("not enough observations");let s=o.map(te),f=o.map(Y),i=c.reduce((h,d)=>h+d,0),u,m;if(a){let h=te(o.flat()),d=0,g=0;for(let p=0;p<l;p++)d+=c[p]*(s[p]-h)**2,g+=(c[p]-1)*f[p];m=i-l,u=d/(l-1)/(g/m)}else{let h=c.map((v,w)=>v/f[w]),d=h.reduce((v,w)=>v+w,0),g=0,p=0;for(let v=0;v<l;v++)g+=(1-h[v]/d)**2/(c[v]-1),p+=h[v]*s[v];g/=l*l-1,p/=d;let b=0;for(let v=0;v<l;v++)b+=h[v]*(s[v]-p)**2;u=b/((l-1)*(1+2*(l-2)*g)),m=1/(3*g)}return{method:a?"One-way analysis of means":"One-way analysis of means (not assuming equal variances)",statistic:u,statisticName:"F",parameter:[l-1,m],parameterName:["num df","denom df"],pValue:Q(u,l-1,m,!1,!1)}}function Dr(t){let e=Array.from(t).filter(o=>!Number.isNaN(o)).sort((o,a)=>o-a),n=e.length;if(n<3||n>5e3)throw new RangeError("sample size must be between 3 and 5000");if(!Number.isFinite(e[0])||!Number.isFinite(e[n-1]))throw new RangeError("'x' must be finite");if(e[n-1]===e[0])throw new RangeError("all 'x' values are identical");let r=xn(e);return{method:"Shapiro-Wilk normality test",statistic:1-r,statisticName:"W",pValue:En(r,n)}}function Mt(t,e,n){let r=[0,0];for(let o=Math.max(0,e);o<Math.min(n,t.length);o++)r=D(r,[t[o],0]);return r[0]}function Wr([[t,e],[n,r]]){let o=t+n,a=e+r,l=t+e,c=Math.max(0,l-a),s=Math.min(l,o),f=new Float64Array(s-c+1);for(let i=c;i<=s;i++)f[i-c]=ge(i,o,a,l,!1);return{lo:c,d:f}}function _r(t,e){let n=new Float64Array(t.length+e.length-1);for(let r=0;r<t.length;r++){let o=t[r];if(o!==0)for(let a=0;a<e.length;a++)n[r+a]+=o*e[a]}return n}var Qe=class{lo;hi;logNull;constructor(e){let n=0,r=new Float64Array([1]);for(let o of e){let a=Wr(o);n+=a.lo,r=_r(r,a.d)}this.lo=n,this.hi=n+r.length-1,this.logNull=r.map(Math.log)}density(e){let n=this.logNull.length,r=new Float64Array(n);if(e===0||e===1/0)return r[e===0?0:n-1]=1,r;let o=Math.log(e),a=-1/0;for(let c=0;c<n;c++){let s=this.logNull[c]+(this.lo+c)*o;r[c]=s,s>a&&(a=s)}for(let c=0;c<n;c++)r[c]=Math.exp(r[c]-a);let l=Mt(r,0,n);for(let c=0;c<n;c++)r[c]=r[c]/l;return r}mean(e){if(e===0)return this.lo;if(e===1/0)return this.hi;let n=this.density(e),r=[0,0];for(let o=0;o<n.length;o++)r=D(r,[(this.lo+o)*n[o],0]);return r[0]}cdf(e,n,r){let o=this.density(n),a=e-this.lo;return r?Mt(o,a,o.length):Mt(o,0,a+1)}};function xt(t,e){return e?U(t,0,1):1/U(n=>t(1/n),Number.EPSILON,1)}function kn(t,e){if(e===t.lo)return 0;if(e===t.hi)return 1/0;let n=t.mean(1);return n===e?1:xt(r=>t.mean(r)-e,n>e)}function Et(t,e,n){if(e===t.hi)return 1/0;let r=t.cdf(e,1,!1);return r===n?1:xt(o=>n-t.cdf(e,o,!1),r<n)}function kt(t,e,n){if(e===t.lo)return 0;let r=t.cdf(e,1,!0);return r===n?1:xt(o=>t.cdf(e,o,!0)-n,r>n)}function jr(t,e={}){let n=t.length;if(n<1)throw new RangeError("'x' must have at least one stratum");let r=t[0].length,o=t[0][0]?.length??0;if(r<2||o<2||n<2)throw new RangeError("each dimension in table must be >= 2");for(let i of t){if(i.length!==r||i.some(u=>u.length!==o))throw new RangeError("all strata must have the same dimensions");if(i.some(u=>u.some(m=>!Number.isFinite(m)||m<0)))throw new RangeError("all entries of 'x' must be nonnegative and finite")}let a=t.map(i=>i.reduce((u,m)=>u+m.reduce((h,d)=>h+d,0),0));if(a.some(i=>i<2))throw new RangeError("sample size in each stratum must be > 1");let l=$(e.alternative),c=e.correct??!0,s=e.exact??!1,f=e.confLevel??.95;if(J(f),r===2&&o===2){let i=t.map(u=>[[u[0][0],u[0][1]],[u[1][0],u[1][1]]]);return s?Br(i,l,f):Hr(i,a,l,c,f)}return Gr(t,a,r,o)}function Hr(t,e,n,r,o){let a=0,l=0,c=0,s=0,f=0,i=0,u=0,m=0;t.forEach(([[N,y],[k,M]],x)=>{let A=e[x],E=N+y,I=k+M,q=N+k,R=y+M;a+=N,l+=E*q/A,c+=E*I*q*R/(A*A*(A-1));let F=(N+M)/A,L=(y+k)/A,S=N*M/A,T=y*k/A;s+=S,f+=T,i+=F*S,u+=F*T+L*S,m+=L*T});let h=a-l,d=r&&Math.abs(h)>=.5?.5:0,g=(Math.abs(h)-d)**2/c,p=n==="two.sided"?G(g,.5,2,!1,!1):z(Math.sign(h)*Math.sqrt(g),{lowerTail:n==="less"}),b=s/f,v=Math.sqrt(i/(2*s*s)+u/(2*s*f)+m/(2*f*f)),w;if(n==="less")w=[0,b*Math.exp(P(o)*v)];else if(n==="greater")w=[b*Math.exp(P(o,{lowerTail:!1})*v),1/0];else{let N=P((1+o)/2);w=[b*Math.exp(-N*v),b*Math.exp(N*v)]}return{method:`Mantel-Haenszel chi-squared test ${d!==0?"with":"without"} continuity correction`,alternative:n,statistic:g,statisticName:"Mantel-Haenszel X-squared",parameter:1,parameterName:"df",pValue:p,confInt:w,confLevel:o,estimate:b,estimateNames:"common odds ratio",nullValue:1,nullValueName:"common odds ratio"}}function Br(t,e,n){let r=new Qe(t),o=t.reduce((c,s)=>c+s[0][0],0),a;if(e==="two.sided"){let c=r.density(1),s=c[o-r.lo]*(1+1e-7),f=[0,0];for(let i of c)i<=s&&(f=D(f,[i,0]));a=Math.min(1,f[0])}else a=r.cdf(o,1,e==="greater");let l;if(e==="less")l=[0,Et(r,o,1-n)];else if(e==="greater")l=[kt(r,o,1-n),1/0];else{let c=(1-n)/2;l=[kt(r,o,c),Et(r,o,c)]}return{method:"Exact conditional test of independence in 2 x 2 x k tables",alternative:e,statistic:o,statisticName:"S",pValue:a,confInt:l,confLevel:n,estimate:kn(r,o),estimateNames:"common odds ratio",nullValue:1,nullValueName:"common odds ratio"}}function Gr(t,e,n,r){let o=(n-1)*(r-1),a=new Array(o).fill(0),l=Array.from({length:o},()=>new Array(o).fill(0));t.forEach((f,i)=>{let u=e[i],m=f.map(g=>g.reduce((p,b)=>p+b,0)),h=Array.from({length:r},(g,p)=>f.reduce((b,v)=>b+v[p],0)),d=1/(u*u*(u-1));for(let g=0;g<r-1;g++)for(let p=0;p<n-1;p++){let b=p+(n-1)*g;a[b]+=f[p][g]-m[p]*h[g]/u;for(let v=0;v<r-1;v++)for(let w=0;w<n-1;w++){let N=(p===w?u*m[p]:0)-m[p]*m[w],y=(g===v?u*h[g]:0)-h[g]*h[v];l[b][w+(n-1)*v]+=d*N*y}}});let c=an(l,a),s=0;for(let f=0;f<o;f++)s+=a[f]*c[f];return{method:"Cochran-Mantel-Haenszel test",statistic:s,statisticName:"Cochran-Mantel-Haenszel M^2",parameter:o,parameterName:"df",pValue:G(s,o/2,2,!1,!1)}}var Rn=new Map;function Ur(t,e){let n=`${t},${e}`,r=Rn.get(n);if(r!==void 0)return r;let o=t+e,a=[];for(let m=1;m<=o;m++)a.push(Math.min(m,o+1-m));let l=a.reduce((m,h)=>m+h,0),c=Array.from({length:t+1},()=>new Float64Array(l+1));c[0][0]=1;for(let m=0;m<o;m++){let h=o-m,d=a[m],g=Array.from({length:t+1},()=>new Float64Array(l+1));for(let p=0;p<=t;p++){let b=c[p],v=t-p;if(v>h)continue;let w=v/h;for(let N=0;N<=l;N++){let y=b[N];y!==0&&(v>0&&(g[p+1][N+d]+=y*w),v<h&&(g[p][N]+=y*(1-w)))}}c=g}let s=c[t],f=0;for(;f<s.length&&s[f]===0;)f++;let i=s.length-1;for(;i>f&&s[i]===0;)i--;let u={min:f,probs:s.slice(f,i+1)};return Rn.set(n,u),u}function Rt(t,e,n,r=!0){if(Number.isNaN(t)||!(e>=1)||!(n>=1)||e!==Math.floor(e)||n!==Math.floor(n))return NaN;let{min:o,probs:a}=Ur(e,n),l=Math.floor(t+1e-7)-o,c=0;if(r)for(let s=0;s<=Math.min(l,a.length-1);s++)c+=a[s];else for(let s=Math.max(l+1,0);s<a.length;s++)c+=a[s];return Math.min(c,1)}var An=new Map;function Kr(t,e){let n=`${t},${e}`,r=An.get(n);if(r!==void 0)return r;let o=t+e,a=0;for(let u=1;u<=o;u++)a+=Math.min(u,o+1-u);let l=Array.from({length:t+1},()=>new Float64Array(a+1));l[0][0]=1;for(let u=0;u<o;u++){let m=Math.min(u+1,o-u),h=Array.from({length:t+1},()=>new Float64Array(a+1));for(let d=0;d<=t;d++){if(t-d>o-u)continue;let g=l[d];for(let p=0;p<=a;p++){let b=g[p];b!==0&&(d<t&&(h[d+1][p+m]+=b),t-d<o-u&&(h[d][p]+=b))}}l=h}let c=l[t],s=0;for(;c[s]===0;)s++;let f=c.length-1;for(;c[f]===0;)f--;let i={min:s,counts:c.slice(s,f+1)};return An.set(n,i),i}function Ye(t,e,n){let{min:r,counts:o}=Kr(e,n);if(t<=0)return r;if(t>=1)return r+o.length-1;let a=nn(e+n,e),l=0;for(let c=0;c<o.length;c++)if(l+=o[c]/a,l>=t)return r+c;return r+o.length-1}function Xr(t,e,n={}){let r=Array.from(t).filter(w=>!Number.isNaN(w)),o=Array.from(e).filter(w=>!Number.isNaN(w)),a=r.length,l=o.length;if(a<1)throw new RangeError("not enough 'x' observations");if(l<1)throw new RangeError("not enough 'y' observations");let c=$(n.alternative),s=n.confInt??!1,f=n.confLevel??.95;s&&J(f);let i=a+l,u=H(r.concat(o)),m=u.map(w=>Math.min(w,i-w+1)),h=0;for(let w=0;w<a;w++)h+=m[w];let d=new Set(u).size<i,g=n.exact??(a<50&&l<50&&!d),p,b;if(g&&!d){let w=y=>Rt(y-1,a,l,!1),N=y=>Rt(y,a,l,!0);if(c==="two.sided"){let y=Math.floor((a+1)**2/4)+Math.floor(a*l/2)/2;p=Math.min(1,2*(h>y?w(h):N(h)))}else c==="less"?p=w(h):p=N(h);s&&(b=Yr(r,o,c,f))}else{let w=0;for(let x of m)w+=x*x;let N=i%2===0,y=N?a*(i+2)/4:a*(i+1)**2/(4*i),k=N?a*l*(16*w-i*(i+2)**2)/(16*i*(i-1)):a*l*(16*i*w-(i+1)**4)/(16*i*i*(i-1)),M=(h-y)/Math.sqrt(k);p=c==="two.sided"?2*Math.min(z(M),z(M,{lowerTail:!1})):c==="less"?z(M,{lowerTail:!1}):z(M),s&&(b=Zr(r,o,c,f))}let v={method:"Ansari-Bradley test",alternative:c,statistic:h,statisticName:"AB",pValue:p};return b!==void 0&&(v.confInt=b.confInt,v.confLevel=f,v.estimate=b.estimate,v.estimateNames="ratio of scales"),v.nullValue=1,v.nullValueName="ratio of scales",v}function qn(t,e,n){let r=t.length,o=r+e.length,a=Qr(t.map(s=>s/n).concat(e)),l=a.map(s=>Math.min(s,o-s+1)),c=0;for(let s=0;s<r;s++)c+=l[s];return{ab:c,a:l,ties:new Set(a).size<o}}function Qr(t){let e=t.filter(a=>!Number.isNaN(a));if(e.length===t.length)return H(t);let n=H(e),r=0,o=e.length;return t.map(a=>Number.isNaN(a)?++o:n[r++])}function At(t,e,n){return t==="two.sided"?n(e):t==="greater"?[n(2*e)[0],1/0]:[0,n(2*e)[1]]}function Yr(t,e,n,r){let o=t.length,a=e.length,l=[];for(let p of t)for(let b of e)p/b>=0&&l.push(p/b);l.sort((p,b)=>p-b);let c=l.length;if(c===0)return{confInt:At(n,1-r,()=>[NaN,NaN]),estimate:NaN};let s=l.map((p,b)=>qn(t,e,p+(b<c-1?(l[b+1]-p)/2:p*1.01)).ab),f=(p,b,v)=>{let w=1/0;for(let y of s)(b?y-p>0:y-p>=0)&&y-p<w&&(w=y-p);let N=v?-1/0:1/0;return s.forEach((y,k)=>{y-p===w&&(N=v?Math.max(N,l[k]):Math.min(N,l[k]))}),N},i=p=>{let b=Ye(p/2,o,a),v=Ye(1-p/2,o,a);if(!s.some(y=>y-b>=0)||!s.some(y=>y-v>0))return[NaN,NaN];let w=f(b,!1,!1),N=f(v,!0,!0);return w>N?[f(v,!1,!1),f(b,!0,!0)]:[w,N]},u=At(n,1-r,i),m=Ye(.5,o,a),h=-1/0,d=1/0;s.forEach((p,b)=>{p-m<=0?h=Math.max(h,l[b]):d=Math.min(d,l[b])});let g=h===-1/0||d===1/0?NaN:(d+h)/2;return{confInt:u,estimate:g}}function Zr(t,e,n,r){let o=t.length,a=e.length,l=o+a,c=l%2===0,s=(b,v)=>{let{ab:w,a:N,ties:y}=qn(t,e,b),k=c?w-o*(l+2)/4:w-o*(l+1)**2/(4*l),M;if(!y)M=Math.sqrt(c?o*a*(l+2)*(l-2)/(48*(l-1)):o*a*(l+1)*(3+l*l)/(48*l*l));else{let x=0;for(let A of N)x+=A*A;M=Math.sqrt(c?o*a*(16*x-l*(l+2)**2)/(16*l*(l-1)):o*a*(16*l*x-(l+1)**4)/(16*l*l*(l-1)))}return k/M-v},f=[],i=(b,v)=>{b.length===0||v.length===0||f.push(Math.min(...b)/Math.max(...v),Math.max(...b)/Math.min(...v))};if(i(t.filter(b=>b>0),e.filter(b=>b>0)),i(t.filter(b=>b<=0),e.filter(b=>b<0)),f.some(b=>!Number.isFinite(b)))return;let u=Math.min(...f),m=Math.max(...f),h=b=>U(v=>s(v,b),u,m,{tol:1e-4}),d=b=>{let v=P(b/2),w=P(b/2,{lowerTail:!1});if(s(u,v)>0||s(m,w)<0)return[NaN,NaN];let N=h(v),y=h(w);return N<=y?[N,y]:[y,N]},g=At(n,1-r,d),p=s(u,0)>0||s(m,0)<0?NaN:h(0);return{confInt:g,estimate:p}}function Jr(t,e,n={}){let r=Array.from(t).filter(x=>!Number.isNaN(x)),o=Array.from(e).filter(x=>!Number.isNaN(x)),a=r.length,l=o.length;if(a<1)throw new RangeError("not enough 'x' observations");if(l<1)throw new RangeError("not enough 'y' observations");let c=$(n.alternative),s=n.confLevel??.95;De(s);let f=H(r.concat(o)),i=f.slice(0,a),u=f.slice(a),m=x=>x.reduce((A,E)=>A+E,0)/x.length,h=m(i),d=m(u),g=(x,A,E)=>{let I=(x.length+1)/2,q=0;for(let R=0;R<x.length;R++)q+=(x[R]-A[R]-E+I)**2;return q/(x.length-1)},p=g(i,H(r),h),b=g(u,H(o),d),v=(d-(l+1)/2)/a,w=a*p+l*b,N=a*l*(d-h)/(a+l)/Math.sqrt(w),y=w**2/((a*p)**2/(a-1)+(l*b)**2/(l-1)),k;c==="greater"?k=B(N,y,!0,!1):c==="less"?k=B(N,y,!1,!1):k=2*B(-Math.abs(N),y,!0,!1);let M=ae((1-s)/2,y,!1,!1)*Math.sqrt(p/(a*l**2)+b/(l*a**2));return{method:"Brunner-Munzel Test",alternative:c,statistic:N,statisticName:"Brunner-Munzel Test Statistic",parameter:y,parameterName:"df",pValue:k,confInt:[v-M,v+M],confLevel:s,estimate:v,estimateNames:"P(X<Y)+.5*P(X=Y)"}}var eo=[1.2337005501361697,7831619385924639e-32];function to(t,e,n){let r=(i,u)=>{let m=new Float64Array(e*e);for(let h=0;h<e;h++)for(let d=0;d<e;d++){let g=i[h*e+d];if(g!==0)for(let p=0;p<e;p++)m[h*e+p]+=g*u[d*e+p]}return m},o=i=>{let u=0;for(let d of i)u=Math.max(u,Math.abs(d));if(u===0||!Number.isFinite(u))return 0;let m=Math.floor(Math.log2(u));if(Math.abs(m)<500)return 0;let h=2**-m;for(let d=0;d<i.length;d++)i[d]*=h;return m},a,l=0,c=t.slice(),s=0,f=n;for(;f>0;)f&1&&(a=a===void 0?c.slice():r(a,c),l+=s,l+=o(a)),f>>=1,f>0&&(c=r(c,c),s*=2,s+=o(c));return[a,l]}function Tn(t,e){if(Number.isNaN(e)||!(t>=1)||t!==Math.floor(t))return NaN;if(e<=1/(2*t))return 0;if(e>=1)return 1;if(t*e<1){let[i,u]=Ve(t,e),m=2*i-1+2*u,h=1,d=0;for(let g=1;g<=t;g++)h*=g/t*m,h<2**-500&&(h*=2**500,d-=500);for(;d<-1e3;)h*=2**-1e3,d+=1e3;return h*2**d}let n=Math.floor(t*e)+1,r=2*n-1,o=n-t*e,a=new Float64Array(r*r);for(let i=0;i<r;i++)for(let u=0;u<r;u++)a[i*r+u]=i-u+1>=0?1:0;for(let i=0;i<r;i++)a[i*r]-=Math.pow(o,i+1),a[(r-1)*r+i]-=Math.pow(o,r-i);2*o-1>0&&(a[(r-1)*r]+=Math.pow(2*o-1,r));for(let i=0;i<r;i++)for(let u=0;u<r;u++){let m=i-u+1;if(m>0){let h=1;for(let d=2;d<=m;d++)h*=d;a[i*r+u]/=h}}let[l,c]=to(a,r,t),s=l[(n-1)*r+n-1],f=c;for(let i=1;i<=t;i++)s=s*i/t,Math.abs(s)<2**-500&&(s*=2**500,f-=500);for(;f>1e3;)s*=2**1e3,f-=1e3;for(;f<-1e3;)s*=2**-1e3,f+=1e3;return s*2**f}function qt(t,e=!0){if(Number.isNaN(t))return NaN;if(t<=0)return e?0:1;if(t===1/0)return e?1:0;if(t<1){let o=Oe(eo,Ve(t,t)),a=o[0]+o[1],l=Math.exp(-o[0])*(1-o[1]),c=0;for(let f=2;f<100;f++){let i=Math.exp(-(2*f-1)*(2*f-1)*a);if(c+=i,i<=1e-17*(c+l))break}let s=Math.sqrt(2*Math.PI)/t*(l+c);return e?s:1-s}let n=0;for(let o=1;o<100;o++){let a=Math.exp(-2*o*o*t*t);if(n+=o%2===1?a:-a,a<=1e-17*Math.abs(n))break}let r=2*n;return e?1-r:r}function In(t,e){if(Number.isNaN(e)||!(t>=1)||t!==Math.floor(t))return NaN;if(e<=0)return 1;if(e>1)return 0;let[n,r]=Ve(t,e),o=Math.floor(t-n-r),a=0;for(let l=0;l<=o;l++){let c=D(nt(t-l,-n),[-r,0]);if(c[0]<=0)break;let s=D(nt(l,n),[r,0]),f=Oe(s,[t,0]),i=Oe(c,[t,0]);a+=Bt(l,t-l,f,i,!1)/(f[0]+f[1])}return Math.min(e*a,1)}function Sn(t,e,n,r={}){let o=r.alternative??"two.sided";if(Number.isNaN(t)||!(e>=1)||!(n>=1)||e!==Math.floor(e)||n!==Math.floor(n))return NaN;if(t<=0)return 1;if(t>1)return 0;let a=e+n,l;if(r.z!==void 0){if(r.z.length!==a)throw new RangeError("z must have length m + n");let m=[...r.z].sort((h,d)=>h-d);l=new Array(a+1).fill(!1);for(let h=1;h<a;h++)l[h]=m[h]!==m[h-1]}let c=t*e*n*(1-1e-10),s=(m,h)=>{let d=m*n-h*e;return(o==="two.sided"?Math.abs(d):o==="greater"?d:-d)>=c},f=new Float64Array(n+1),i=new Float64Array(n+1),u=0;for(let m=0;m<=e;m++){for(let h=0;h<=n;h++){if(m===0&&h===0){i[0]=1;continue}let d=m+h,g=(m>0?m/d*f[h]:0)+(h>0?h/d*i[h-1]:0);(l===void 0?d<a:l[d])&&s(m,h)?(g>0&&(u+=g*ge(m,e,n,d,!1)),i[h]=0):i[h]=g}[f,i]=[i,f],i.fill(0)}return Math.min(u,1)}function Ln(t,e){return t==="two.sided"?"two-sided":`the CDF of x lies ${t==="less"?"below":"above"} ${e?"the null hypothesis":"that of y"}`}function no(t,e,n={}){let r=Array.from(t).filter(v=>!Number.isNaN(v)).sort((v,w)=>v-w),o=r.length;if(o<1)throw new RangeError("not enough 'x' data");let a=$(n.alternative),l=a==="two.sided"?"D":a==="greater"?"D^+":"D^-";if(typeof e=="function"){let v=-1/0,w=-1/0;for(let x=0;x<o;x++){let A=e(r[x]);v=Math.max(v,(x+1)/o-A),w=Math.max(w,A-x/o)}let N=a==="two.sided"?Math.max(v,w):a==="greater"?v:w,y=new Set(r).size<o,k=n.exact??(o<100&&!y),M;return a==="two.sided"?M=k?1-Tn(o,N):qt(Math.sqrt(o)*N,!1):M=k?In(o,N):Math.exp(-2*o*N*N),{method:`${k?"Exact":"Asymptotic"} one-sample Kolmogorov-Smirnov test`,alternative:Ln(a,!0),exact:k,statistic:N,statisticName:l,pValue:Math.min(1,Math.max(0,M))}}let c=Array.from(e).filter(v=>!Number.isNaN(v)),s=c.length;if(s<1)throw new RangeError("not enough 'y' data");let f=r.map(v=>[v,0]).concat(c.map(v=>[v,1]));f.sort((v,w)=>v[0]-w[0]);let i=0,u=0,m=0,h=0;for(let v=0;v<f.length;v++){if(f[v][1]===0?i++:u++,v+1<f.length&&f[v+1][0]===f[v][0])continue;let w=i/o-u/s;m=Math.max(m,w),h=Math.max(h,-w)}let d=a==="two.sided"?Math.max(m,h):a==="greater"?m:h,g=new Set(f.map(v=>v[0])).size<f.length,p=n.exact??o*s<1e4,b;if(p)b=Sn(d,o,s,g?{alternative:a,z:f.map(v=>v[0])}:{alternative:a});else{let v=o*s/(o+s);b=a==="two.sided"?qt(Math.sqrt(v)*d,!1):Math.exp(-2*v*d*d)}return{method:`${p?"Exact":"Asymptotic"} two-sample Kolmogorov-Smirnov test`,alternative:Ln(a,!1),exact:p,statistic:d,statisticName:l,pValue:Math.min(1,Math.max(0,b))}}function Fn(t,e,n){let r=Array.from(t);if(r.length!==e.length)throw new RangeError("'x' and 'g' must have the same length");let o=new Map;for(let l=0;l<r.length;l++){let c=e[l];if(typeof c=="number"&&Number.isNaN(c)||n&&Number.isNaN(r[l]))continue;let s=o.get(c);s===void 0&&o.set(c,s=[]),s.push(r[l])}let a=Array.from(o.keys()).sort((l,c)=>typeof l=="number"&&typeof c=="number"?l-c:String(l)<String(c)?-1:String(l)>String(c)?1:0);return{levels:a,groups:a.map(l=>o.get(l))}}function Tt(t,e,n){let r=[],o=[];for(let c=0;c<t-1;c++)for(let s=c+1;s<t;s++)r.push(e(s,c)),o.push([s-1,c]);let a=gt(r,n),l=Array.from({length:t-1},()=>new Array(t-1).fill(NaN));return o.forEach(([c,s],f)=>l[c][s]=a[f]),l}function It(t,e,n,r){return{method:t,pValue:n,rowNames:e.slice(1).map(String),colNames:e.slice(0,-1).map(String),pAdjustMethod:r}}function ro(t,e,n={}){let r=n.paired??!1,o=n.poolSd??!r;if(r&&o)throw new RangeError("pooling of SD is incompatible with paired tests");let a=$(n.alternative),l=n.pAdjustMethod??"holm",{levels:c,groups:s}=Fn(t,e,!r),f=c.length;if(f<2)throw new RangeError("there must be at least two groups");let i,u;if(o){u="t tests with pooled SD";let m=s.map(b=>b.length),h=s.map(b=>b.length>0?te(b):NaN),d=0,g=0;s.forEach(b=>{b.length>1&&(d+=Y(b)*(b.length-1),g+=b.length-1)});let p=Math.sqrt(d/g);i=(b,v)=>{let w=(h[b]-h[v])/(p*Math.sqrt(1/m[b]+1/m[v]));return a==="less"?B(w,g,!0,!1):a==="greater"?B(w,g,!1,!1):2*B(-Math.abs(w),g,!0,!1)}}else u=r?"paired t tests":"t tests with non-pooled SD",i=(m,h)=>it(s[m],s[h],{paired:r,alternative:a}).pValue;return It(u,c,Tt(f,i,l),l)}function oo(t,e,n={}){let{pAdjustMethod:r,alternative:o,...a}=n,l=r??"holm",{levels:c,groups:s}=Fn(t,e,!(a.paired??!1)),f=c.length;if(f<2)throw new RangeError("there must be at least two groups");let i="",u=Tt(f,(m,h)=>{let d=ht(s[m],s[h],{...a,...o===void 0?{}:{alternative:o}});return i=d.method,d.pValue},l);return It(i,c,u,l)}function so(t,e,n={}){if(t.length!==e.length)throw new RangeError("'x' and 'n' must have the same length");let r=[],o=[];t.forEach((i,u)=>{Number.isNaN(i)||Number.isNaN(e[u])||(r.push(i),o.push(e[u]))});let a=r.length;if(a<2)throw new RangeError("too few groups");let l=n.pAdjustMethod??"holm",c=n.correct??!0,s=Tt(a,(i,u)=>Nt([r[i],r[u]],[o[i],o[u]],{correct:c}).pValue,l),f=Array.from({length:a},(i,u)=>u+1);return It("Pairwise comparison of proportions",f,s,l)}function Vn(t){let e=t.flat(),n=Te(e),r=[0,0],o=[0,0],a=[];for(let l of t){let c=Te(l);a.push(c[0]);let s=ee(c,n);r=D(r,Ce(Ce(s,s),[l.length,0]));for(let f of l){let i=ee([f,0],c);o=D(o,Ce(i,i))}}return{ssb:r[0],ssw:o[0],means:a}}function ao(t,e){let n=me(t,e),r=n.length;if(r<2)throw new RangeError("contrasts can be applied only to factors with 2 or more levels");let o=n.reduce((m,h)=>m+h.length,0),{ssb:a,ssw:l}=Vn(n),c=r-1,s=o-r,f=a/c,i=l/s,u=f/i;return{df:[c,s],sumSq:[a,l],meanSq:[f,i],fValue:u,pValue:s>0?Q(u,c,s,!1,!1):NaN}}function io(t,e,n={}){let r;e!==void 0&&!Array.isArray(e)?n=e:r=e;let{labels:o,groups:a}=vt(t,r),l=a.length;if(l<2)throw new RangeError("contrasts can be applied only to factors with 2 or more levels");let c=n.confLevel??.95,f=a.reduce((g,p)=>g+p.length,0)-l,{ssw:i,means:u}=Vn(a),m=i/f,h=Jt(c,l,f),d={names:[],i:[],j:[],diff:[],lwr:[],upr:[],pAdj:[]};for(let g=0;g<l-1;g++)for(let p=g+1;p<l;p++){let b=u[p]-u[g],v=Math.sqrt(m/2*(1/a[p].length+1/a[g].length));d.names.push(`${o[p]}-${o[g]}`),d.i.push(p+1),d.j.push(g+1),d.diff.push(b),d.lwr.push(b-h*v),d.upr.push(b+h*v),d.pAdj.push(Zt(Math.abs(b)/v,l,f,{lowerTail:!1}))}return d}function lo(t,e,n={}){let r;e!==void 0&&!ArrayBuffer.isView(e)&&!Array.isArray(e)?n=e:r=e;let{sigmaX:o,sigmaY:a}=n,l=n.mu??0;if(o===void 0&&r===void 0)throw new RangeError("sigmaX (the known standard deviation of x) is required");if(o===void 0||r!==void 0&&a===void 0)throw new RangeError("sigmaX and sigmaY are both required for two samples");if(Number.isNaN(l))throw new RangeError("mu must be a number");let c=$(n.alternative),s=n.confLevel??.95;if(!(s>=0&&s<=1))throw new RangeError("confLevel must be between 0 and 1");let f=Array.from(t).filter(w=>!Number.isNaN(w)),i=r===void 0?void 0:Array.from(r).filter(w=>!Number.isNaN(w));if(f.length<3)throw new RangeError("x needs at least 3 non-missing values");if(i!==void 0&&i.length<3)throw new RangeError("y needs at least 3 non-missing values");let u=Te(f)[0],m=i===void 0?NaN:Te(i)[0],h=i===void 0?o/Math.sqrt(f.length):Math.sqrt(o**2/f.length+a**2/i.length),d=i===void 0?u:u-m,g=(d-l)/h,p,b;if(c==="less")p=z(g),b=[-1/0,d+P(s)*h];else if(c==="greater")p=z(g,{lowerTail:!1}),b=[d-P(s)*h,1/0];else{p=2*z(-Math.abs(g));let w=P(1-(1-s)/2)*h;b=[d-w,d+w]}let v=i!==void 0;return{method:v?"Two-sample z-Test":"One-sample z-Test",alternative:c,statistic:g,statisticName:"z",pValue:p,confInt:b,confLevel:s,estimate:v?[u,m]:u,estimateNames:v?["mean of x","mean of y"]:"mean of x",nullValue:l,nullValueName:v?"difference in means":"mean"}}function co(t,e,n={}){let r=n.intercept??!0,o=t.length>0&&typeof t[0]!="number"?t.map(V=>Array.from(V)):Array.from(t,V=>[V]),a=Array.from(e);if(o.length!==a.length)throw new RangeError("variable lengths differ (found for 'x')");let l=n.weights===void 0?void 0:Array.from(n.weights);if(l!==void 0&&l.length!==a.length)throw new RangeError("variable lengths differ (found for '(weights)')");if(l?.some(V=>V<0))throw new RangeError("missing or negative weights not allowed");let c=a.map((V,O)=>!Number.isNaN(V)&&o[O].every(j=>!Number.isNaN(j))&&(l===void 0||!Number.isNaN(l[O]))),s=o.filter((V,O)=>c[O]).map(V=>r?[1,...V]:V),f=a.filter((V,O)=>c[O]),i=l?.filter((V,O)=>c[O]);if(f.length===0)throw new RangeError("0 (non-NA) cases");let u=f.map((V,O)=>i===void 0||i[O]!==0),m=s.filter((V,O)=>u[O]),h=f.filter((V,O)=>u[O]),d=i?.filter((V,O)=>u[O]),g=h.length;if(g===0)throw new RangeError("all weights are zero");let p=d?.map(Math.sqrt),b=p===void 0?m:m.map((V,O)=>V.map(j=>j*p[O])),v=p===void 0?h:h.map((V,O)=>V*p[O]),w=ve(b),N=w.rank,y=We(w,v),k=_e(w,v),M=p===void 0?k:k.map((V,O)=>V/p[O]),x=[],A=[],E=0;f.forEach((V,O)=>{if(u[O])x.push(M[E]),A.push(V-M[E]),E++;else{let j=s[O].reduce((Fe,jn,Wt)=>Number.isNaN(y[Wt])?Fe:Fe+jn*y[Wt],0);A.push(j),x.push(V-j)}});let I=A.filter((V,O)=>u[O]),q=g-N,R=d??new Array(g).fill(1),F=0;for(let V=0;V<g;V++)F+=R[V]*M[V]**2;let L=F/q,S=Math.sqrt(L),T=w.qr.slice(0,N).map(V=>V.slice(0,N)),C=N>0?je(T):[],_=w.pivot.slice(0,N).map((V,O)=>[V,O]).sort((V,O)=>V[0]-O[0]),X=_.map(([V])=>y[V]),oe=_.map(([,V])=>Math.sqrt(C[V][V]*L)),se=X.map((V,O)=>V/oe[O]),Ee=se.map(V=>2*B(-Math.abs(V),q,!0,!1)),ie={coefficients:y,residuals:x,fittedValues:A,rank:N,dfResidual:q,coefTable:{estimate:X,stdError:oe,tValue:se,pValue:Ee},sigma:S,rSquared:0,adjRSquared:0,intercept:r,qr:w},$t=r?1:0,Le=N-$t;if(Le===0)return ie;let ke=0;if(r){let V=R.reduce((j,Fe)=>j+Fe,0),O=0;for(let j=0;j<g;j++)O+=R[j]*I[j]/V;for(let j=0;j<g;j++)ke+=R[j]*(I[j]-O)**2}else for(let V=0;V<g;V++)ke+=R[V]*I[V]**2;ie.rSquared=ke/(ke+F),ie.adjRSquared=1-(1-ie.rSquared)*((g-$t)/q);let Dt=ke/Le/L;return ie.fStatistic={value:Dt,numdf:Le,dendf:q},ie.fPValue=Q(Dt,Le,q,!1,!1),ie}function fo(t,e={}){let n=e.level??.95,r=ae((1+n)/2,t.dfResidual,!0,!1),{estimate:o,stdError:a}=t.coefTable,l=t.coefficients.map(()=>NaN),c=t.coefficients.map(()=>NaN),s=0;return t.coefficients.forEach((f,i)=>{Number.isNaN(f)||(l[i]=o[s]-r*a[s],c[i]=o[s]+r*a[s],s++)}),{lower:l,upper:c}}function uo(t,e,n={}){let o=(e.length>0&&typeof e[0]!="number"?e.map(d=>Array.from(d)):Array.from(e,d=>[d])).map(d=>t.intercept?[1,...d]:d),a=t.rank,l=t.qr.pivot.slice(0,a),c=t.qr.qr.slice(0,a).map(d=>d.slice(0,a)),s=t.sigma**2,f=o.map(d=>d.reduce((g,p,b)=>Number.isNaN(t.coefficients[b])?g:g+p*t.coefficients[b],0)),i=o.map(d=>{let g=new Array(a).fill(0);for(let p=0;p<a;p++){let b=d[l[p]];for(let v=0;v<p;v++)b-=c[v][p]*g[v];g[p]=b/c[p][p]}return Math.sqrt(g.reduce((p,b)=>p+b*b,0)*s)}),u=n.interval??"none";if(u==="none")return{fit:f,seFit:i};let m=ae((1+(n.level??.95))/2,t.dfResidual,!0,!1),h=i.map(d=>m*Math.sqrt(d*d+(u==="prediction"?s:0)));return{fit:f,seFit:i,lwr:f.map((d,g)=>d-h[g]),upr:f.map((d,g)=>d+h[g])}}var K=2**-52,mo={gaussian:["identity","log","inverse"],binomial:["logit","probit","cauchit","log","cloglog"],quasibinomial:["logit","probit","cauchit","log","cloglog"],poisson:["log","identity","sqrt"],quasipoisson:["log","identity","sqrt"],Gamma:["inverse","identity","log"],"inverse.gaussian":["1/mu^2","inverse","identity","log"],quasi:["identity","logit","probit","cloglog","inverse","log","1/mu^2","sqrt"]},St=t=>Number.isFinite(t)&&t>0,be=()=>!0,Z=class{list=[];add(e){this.list.includes(e)||this.list.push(e)}},Ze;function Je(t,e){let n=Ze;Ze=t;try{return e()}finally{Ze=n}}function ho(t){return t<0&&Ze?.add("NaNs produced"),Math.sqrt(t)}function Lt(t){switch(t){case"identity":return{name:t,link:e=>e,linkinv:e=>e,muEta:()=>1,etaOk:be};case"log":return{name:t,link:Math.log,linkinv:e=>Math.max(Math.exp(e),K),muEta:e=>Math.max(Math.exp(e),K),etaOk:be};case"inverse":return{name:t,link:e=>1/e,linkinv:e=>1/e,muEta:e=>-1/(e*e),etaOk:e=>Number.isFinite(e)&&e!==0};case"sqrt":return{name:t,link:Math.sqrt,linkinv:e=>e*e,muEta:e=>2*e,etaOk:St};case"1/mu^2":return{name:t,link:e=>1/(e*e),linkinv:e=>1/ho(e),muEta:e=>-1/(2*e**1.5),etaOk:St};case"logit":return{name:t,link:e=>Math.log(e/(1-e)),linkinv:e=>{let n=e<-30?K:e>30?1/K:Math.exp(e);return n/(1+n)},muEta:e=>{if(Math.abs(e)>30)return K;let n=Math.exp(e);return n/((1+n)*(1+n))},etaOk:be};case"probit":{let e=-P(K);return{name:t,link:n=>P(n),linkinv:n=>z(Math.min(Math.max(n,-e),e)),muEta:n=>Math.max(Ht(n),K),etaOk:be}}case"cauchit":{let e=-st(K,0,1,!0,!1);return{name:t,link:n=>st(n,0,1,!0,!1),linkinv:n=>Xt(Math.min(Math.max(n,-e),e),0,1,!0,!1),muEta:n=>Math.max(Kt(n,0,1,!1),K),etaOk:be}}case"cloglog":return{name:t,link:e=>Math.log(-Math.log(1-e)),linkinv:e=>Math.min(Math.max(-Math.expm1(-Math.exp(e)),K),1-K),muEta:e=>{let n=Math.min(e,700);return Math.max(Math.exp(n)*Math.exp(-Math.exp(n)),K)},etaOk:be};default:throw new RangeError(`unknown link "${String(t)}"`)}}function po(t){if(!Number.isFinite(t))throw new RangeError("invalid power for the power link");if(t<=0)return Lt("log");if(t===1)return Lt("identity");let e=1/t;return{name:`mu^${Math.round(t*1e3)/1e3}`,link:n=>n**t,linkinv:n=>Math.max(n**e,K),muEta:n=>Math.max(e*n**(e-1),K),etaOk:St}}function go(t){switch(t){case"constant":return{variance:()=>1,muOk:()=>!0,dev:(e,n,r)=>r*(e-n)**2};case"mu(1-mu)":return{variance:e=>e*(1-e),muOk:e=>e>0&&e<1,dev:Cn};case"mu":return{variance:e=>e,muOk:e=>e>0,dev:(e,n,r)=>2*r*((e===0?0:e*Math.log(e/n))-(e-n))};case"mu^2":return{variance:e=>e*e,muOk:e=>e>0,dev:(e,n,r)=>Math.max(-2*r*(Math.log(e>0?e/n:1/n)-(e-n)/n),0)};case"mu^3":return{variance:e=>e*e*e,muOk:e=>e>0,dev:On};default:throw new RangeError(`'variance' "${String(t)}" is invalid: possible values are "mu(1-mu)", "mu", "mu^2", "mu^3" and "constant"`)}}function Cn(t,e,n){let r=t===0?0:t*Math.log(t/e),o=t===1?0:(1-t)*Math.log((1-t)/(1-e));return 2*n*(r+o)}function On(t,e,n){return n*(t-e)**2/(t*e*e)}function Se(t,e){let n=typeof t=="string"?{family:t}:t,r=n.family,o=mo[r];if(o===void 0)throw new RangeError(`unknown family "${String(r)}"`);let a=e??n.link??o[0],l;if(typeof a=="object"){if(r!=="quasi")throw new RangeError(`link "power" not available for ${r} family`);l=po(a.power)}else{if(!o.includes(a))throw new RangeError(`link "${a}" not available for ${r} family; available links are ${o.map(s=>`'${s}'`).join(", ")}`);l=Lt(a)}if(n.variance!==void 0&&r!=="quasi")throw new TypeError("'variance' is only used by the quasi family");let c={...l,family:r,varianceName:void 0,fixedDispersion:!1};switch(r){case"gaussian":return{...c,variance:()=>1,muOk:()=>!0,devContribution:(s,f,i)=>i*(s-f)**2};case"binomial":case"quasibinomial":return{...c,fixedDispersion:r==="binomial",variance:s=>s*(1-s),muOk:s=>Number.isFinite(s)&&s>0&&s<1,devContribution:Cn};case"poisson":case"quasipoisson":return{...c,fixedDispersion:r==="poisson",variance:s=>s,muOk:s=>Number.isFinite(s)&&s>0,devContribution:(s,f,i)=>s>0?2*i*(s*Math.log(s/f)-(s-f)):2*i*f};case"Gamma":return{...c,variance:s=>s*s,muOk:s=>Number.isFinite(s)&&s>0,devContribution:(s,f,i)=>-2*i*((s===0?0:Math.log(s/f))-(s-f)/f)};case"inverse.gaussian":return{...c,variance:s=>s*s*s,muOk:()=>!0,devContribution:On};case"quasi":{let s=n.variance??"constant",f=go(s);return{...c,varianceName:s,variance:f.variance,muOk:f.muOk,devContribution:f.dev}}}}function Ft(t,e,n,r,o){let a=t.family,l=a==="binomial"||a==="quasibinomial";if(e.length>0&&Array.isArray(e[0])){let i=e;if(i.every(g=>g.length===1))return Ft(t,i.map(g=>g[0]),n,r,o);if(!l)throw new TypeError("y must be a vector (or, for the binomial families, a two-column matrix)");if(i.some(g=>g.length!==2))throw new TypeError(`for the '${a}' family, y must be a vector of 0 and 1's
4
+ or a 2 column matrix where col 1 is no. successes and col 2 is no. failures`);a==="binomial"&&i.some(g=>Math.abs(g[0]-Math.round(g[0]))>.001||Math.abs(g[1]-Math.round(g[1]))>.001)&&o.add("non-integer counts in a binomial glm!");let u=i.map(g=>g[0]+g[1]),m=i.map((g,p)=>u[p]===0?0:g[0]/u[p]),h=n.map((g,p)=>g*u[p]),d=m.map((g,p)=>(u[p]*g+.5)/(u[p]+1));return{y:m,weights:h,mustart:d,size:u}}let s=e.slice(),f=n.slice();switch(a){case"binomial":case"quasibinomial":{for(let u=0;u<s.length;u++)f[u]===0&&(s[u]=0);if(s.some(u=>u<0||u>1))throw new RangeError("y values must be 0 <= y <= 1");let i=s.map((u,m)=>(f[m]*u+.5)/(f[m]+1));return a==="binomial"&&s.some((u,m)=>Math.abs(f[m]*u-Math.round(f[m]*u))>.001)&&o.add("non-integer #successes in a binomial glm!"),{y:s,weights:f,mustart:i,size:s.map(()=>1)}}case"poisson":case"quasipoisson":if(s.some(i=>i<0))throw new RangeError(`negative values not allowed for the '${a==="poisson"?"Poisson":"quasiPoisson"}' family`);return{y:s,weights:f,mustart:s.map(i=>i+.1),size:void 0};case"Gamma":if(s.some(i=>i<=0))throw new RangeError("non-positive values not allowed for the 'Gamma' family");return{y:s,weights:f,mustart:s.slice(),size:void 0};case"inverse.gaussian":if(s.some(i=>i<=0))throw new RangeError("positive values only are allowed for the 'inverse.gaussian' family");return{y:s,weights:f,mustart:s.slice(),size:void 0};case"gaussian":if(!r&&(t.name==="inverse"&&s.some(i=>i===0)||t.name==="log"&&s.some(i=>i<=0)))throw new Error("cannot find valid starting values: please specify some");return{y:s,weights:f,mustart:s.slice(),size:void 0};case"quasi":{let i=t.varianceName,u=i==="constant"?s.slice():i==="mu(1-mu)"?s.map(m=>Math.min(Math.max(m,.001),.999)):s.map(m=>m+(m===0?.1:0));return{y:s,weights:f,mustart:u,size:void 0}}}}function Pn(t,e,n,r,o,a,l){let c=e.length,s=0;switch(t.family){case"gaussian":{let f=0;for(let i of r)f+=Math.log(i);return c*(Math.log(2*Math.PI*a/c)+1)+2-f}case"binomial":{let f=o!==void 0&&o.some(i=>i>1)?o:r;for(let i=0;i<c;i++)f[i]>0&&(s+=r[i]/f[i]*pe(Re(f[i]*e[i]),Re(f[i]),n[i],!0));return-2*s}case"poisson":for(let f=0;f<c;f++)Ut(e[f])&&l.add(`non-integer x = ${e[f].toFixed(6)}`),s+=r[f]*Ae(e[f],n[f],!0);return-2*s;case"Gamma":{let f=0;for(let u of r)f+=u;let i=a/f;for(let u=0;u<c;u++)s+=r[u]*Gt(e[u],1/i,n[u]*i,!0);return-2*s+2}case"inverse.gaussian":{let f=0,i=0;for(let u=0;u<c;u++)f+=r[u],i+=r[u]*Math.log(e[u]);return f*(Math.log(2*Math.PI*a/f)+1)+3*i+2}default:return NaN}}var ye=2**-52;function wo(t){let e=t.map(n=>`"${n}"`);return e.length===1?e[0]:`c(${e.join(", ")})`}function et(t,e,n){return t.map((r,o)=>{let a=0;for(let l=0;l<r.length;l++)a+=r[l]*e[l];return a+n[o]})}function de(t,e,n,r){let o=0;for(let a=0;a<e.length;a++)o+=t.devContribution(e[a],n[a],r[a]);return o}function zn(t,e){let{x:n,p:r,y:o,w:a,offset:l,fam:c,epsilon:s,maxit:f}=t,i=o.length;return Je(e,()=>{let u=(q,R)=>q.every(F=>c.etaOk(F))&&R.every(F=>c.muOk(F));if(r===0){let q=l.slice();if(!q.every(S=>c.etaOk(S)))throw new Error("invalid linear predictor values in empty model");let R=q.map(S=>c.linkinv(S));if(!R.every(S=>c.muOk(S)))throw new Error("invalid fitted means in empty model");let F=q.map(S=>c.muEta(S)),L=R.map((S,T)=>Math.sqrt(a[T]*F[T]**2/c.variance(S))**2);return{coefficients:[],eta:q,mu:R,deviance:de(c,o,R,a),iter:0,converged:!0,boundary:!0,rank:0,qr:void 0,used:a.map(S=>S>0),workingWeights:L,workingResiduals:o.map((S,T)=>(S-R[T])/F[T])}}let m,h;if(t.start!==void 0){if(t.start.length!==r)throw new RangeError(`length of 'start' should equal ${r} and correspond to initial coefs for ${wo(t.columnNames)}`);h=t.start.slice(),m=et(n,h,l)}else t.etastart!==void 0?m=t.etastart.slice():m=t.mustart.map(q=>c.link(q));let d=m.map(q=>c.linkinv(q));if(!u(m,d))throw new Error("cannot find valid starting values: please specify some");let g=de(c,o,d,a),p=g,b=!1,v=!1,w=0,N=new Array(r).fill(0),y,k=a.map(()=>!1),M=[],x=Math.min(1e-7,s/1e3);for(w=1;w<=f;w++){let q=m.map(T=>c.muEta(T));for(let T=0;T<i;T++){if(!(a[T]>0))continue;let C=c.variance(d[T]);if(Number.isNaN(C))throw new Error("NAs in V(mu)");if(C===0)throw new Error("0s in V(mu)");if(Number.isNaN(q[T]))throw new Error("NAs in d(mu)/d(eta)")}k=a.map((T,C)=>T>0&&q[C]!==0);let R=[];for(let T=0;T<i;T++)k[T]&&R.push(T);if(R.length===0){e.add(`no observations informative at iteration ${w}`),b=!1;break}M=new Array(i).fill(0);let F=[],L=[];for(let T of R){let C=Math.sqrt(a[T]*q[T]**2/c.variance(d[T]));M[T]=C,F.push((m[T]-l[T]+(o[T]-d[T])/q[T])*C),L.push(n[T].map(W=>W*C))}y=ve(L,{tol:x});let S=We(y,F);if(S.some((T,C)=>y.pivot.indexOf(C)<y.rank&&!Number.isFinite(T))){e.add(`non-finite coefficients at iteration ${w}`),b=!1;break}if(N=S.map(T=>Number.isNaN(T)?0:T),v=!1,m=et(n,N,l),d=m.map(T=>c.linkinv(T)),p=de(c,o,d,a),!Number.isFinite(p)){if(h===void 0)throw new Error("no valid set of coefficients has been found: please supply starting values");e.add("step size truncated due to divergence");let T=0;for(;!Number.isFinite(p);){if(T>=f)throw new Error("inner loop 1; cannot correct step size");T++,N=N.map((C,W)=>(C+h[W])/2),m=et(n,N,l),d=m.map(C=>c.linkinv(C)),p=de(c,o,d,a)}v=!0}if(!u(m,d)){if(h===void 0)throw new Error("no valid set of coefficients has been found: please supply starting values");e.add("step size truncated: out of bounds");let T=0;for(;!u(m,d);){if(T>=f)throw new Error("inner loop 2; cannot correct step size");T++,N=N.map((C,W)=>(C+h[W])/2),m=et(n,N,l),d=m.map(C=>c.linkinv(C))}v=!0,p=de(c,o,d,a)}if(t.untilCoefficients){let T=Math.max(...N.map(Math.abs));if(h!==void 0&&N.every((C,W)=>Math.abs(C-h[W])<=8*ye*T)){b=!0;break}}else if(Math.abs(p-g)/(Math.abs(p)+.1)<s){b=!0;break}g=p,h=N.slice()}w>f&&(w=f);let A=r,E=N.slice();if(y!==void 0){A=y.rank;for(let q=y.rank;q<r;q++)E[y.pivot[q]]=NaN}let I=m.map(q=>c.muEta(q));return{coefficients:E,eta:m,mu:d,deviance:p,iter:w,converged:b,boundary:v,rank:A,qr:y,used:k,workingWeights:M.map(q=>q*q),workingResiduals:o.map((q,R)=>(q-d[R])/I[R])}})}function $n(t){return t.length>0&&typeof t[0]!="number"?t.map(e=>Array.from(e)):Array.from(t,e=>[e])}function Dn(t,e,n,r){r||(t.converged||n.add("glm.fit: algorithm did not converge"),t.boundary&&n.add("glm.fit: algorithm stopped at boundary value"),e.family==="binomial"&&t.mu.some(o=>o>1-10*ye||o<10*ye)&&n.add("glm.fit: fitted probabilities numerically 0 or 1 occurred"),e.family==="poisson"&&t.mu.some(o=>o<10*ye)&&n.add("glm.fit: fitted rates numerically 0 occurred"))}function Me(t,e,n,r={}){let o=Se(t.familySpec),a="start"in r?r.start:t.start,l=Ft(o,t.yGiven,t.priorGiven,a!==void 0||r.etastart!==void 0,n),c=r.extraOffset===void 0?t.offset:t.offset.map((i,u)=>i+r.extraOffset[u]),s=t.x.map(i=>e.map(u=>i[u])),f=zn({x:s,p:e.length,y:l.y,w:l.weights,offset:c,fam:o,epsilon:r.epsilon??t.epsilon,maxit:r.maxit??t.maxit,columnNames:e.map(i=>t.columnNames[i]),start:a,etastart:r.etastart,mustart:l.mustart,untilCoefficients:r.untilCoefficients},n);return Dn(f,o,n,e.length===0),{fit:f,fam:o,y:l.y,w:l.weights,size:l.size,offset:c}}function No(t,e,n={}){let r=n.intercept??!0,o=$n(t),l=e.length>0&&typeof e[0]!="number"?e.map(L=>Array.from(L)):Array.from(e),c=l.length;if(o.length!==c)throw new RangeError("variable lengths differ (found for 'x1')");let s=n.weights===void 0?void 0:Array.from(n.weights);if(s!==void 0&&s.length!==c)throw new RangeError("variable lengths differ (found for '(weights)')");let f=n.offset===void 0?void 0:Array.from(n.offset);if(f!==void 0&&f.length!==c)throw new RangeError("variable lengths differ (found for '(offset)')");let i=o.map((L,S)=>{let T=l[S];return!(Array.isArray(T)?T.some(W=>Number.isNaN(W)):Number.isNaN(T))&&L.every(W=>!Number.isNaN(W))&&!(s!==void 0&&Number.isNaN(s[S]))&&!(f!==void 0&&Number.isNaN(f[S]))}),u=o.filter((L,S)=>i[S]).map(L=>r?[1,...L]:L),m=l.filter((L,S)=>i[S]),h=m.length;if(h===0)throw new RangeError("0 (non-NA) cases");let d=s===void 0?new Array(h).fill(1):s.filter((L,S)=>i[S]);if(d.some(L=>L<0))throw new RangeError("negative weights not allowed");let g=f===void 0?new Array(h).fill(0):f.filter((L,S)=>i[S]),p=o.length>0?o[0].length:0,b=[...r?["(Intercept)"]:[],...Array.from({length:p},(L,S)=>`x${S+1}`)],v=b.length;if(u.some(L=>L.length!==v))throw new TypeError("all rows of x must have the same length");let w=typeof n.family=="object"?{...n.family}:{family:n.family??"gaussian"};n.link!==void 0&&(w.link=n.link);let N={x:u,columnNames:b,yGiven:m,priorGiven:d,offset:g,hasOffset:f!==void 0,intercept:r,familySpec:w,epsilon:n.epsilon??1e-8,maxit:n.maxit??25,start:n.start===void 0?void 0:Array.from(n.start)};if(!(N.epsilon>0))throw new RangeError("value of 'epsilon' must be > 0");if(!(N.maxit>0))throw new RangeError("maximum number of iterations must be > 0");let y=new Z,k=Array.from({length:v},(L,S)=>S),{fit:M,fam:x,y:A,w:E,size:I}=Me(N,k,y),q;if(r&&N.hasOffset){let L=new Z,S=zn({x:u.map(()=>[1]),p:1,y:A,w:E,offset:g,fam:x,epsilon:N.epsilon,maxit:N.maxit,columnNames:["(Intercept)"],mustart:M.mu},L);Dn(S,x,L,!1),L.list.forEach(T=>y.add(T)),q=S.deviance,S.converged||y.add("fitting to calculate the null deviance did not converge -- increase 'maxit'?")}else if(r){let L=0,S=0;for(let C=0;C<h;C++)L+=E[C],S+=E[C]*A[C];let T=S/L;q=de(x,A,A.map(()=>T),E)}else q=de(x,A,Je(y,()=>g.map(L=>x.linkinv(L))),E);let R=h-E.filter(L=>L===0).length,F=Pn(x,A,M.mu,E,I,M.deviance,y)+2*M.rank;return{coefficients:M.coefficients,fittedValues:M.mu,linearPredictors:M.eta,deviance:M.deviance,nullDeviance:q,aic:F,rank:M.rank,dfResidual:R-M.rank,dfNull:R-(r?1:0),iter:M.iter,converged:M.converged,boundary:M.boundary,y:A,priorWeights:E,weights:M.workingWeights,residuals:M.workingResiduals,family:x.family,link:x.name,warnings:y.list,qr:M.qr,model:N}}function tt(t){return Se(t.model.familySpec)}function xe(t,e){if(tt(t).fixedDispersion)return 1;if(t.dfResidual<=0)return NaN;let n=0;for(let r=0;r<t.weights.length;r++)t.weights[r]>0&&(n+=t.weights[r]*t.residuals[r]**2);return t.weights.some(r=>r===0)&&e?.add("observations with zero weight not used for calculating dispersion"),n/t.dfResidual}function vo(t){if(t.qr===void 0||t.rank===0)return[];let e=t.qr.qr.slice(0,t.rank).map(n=>n.slice(0,t.rank));return je(e)}function Vt(t,e={}){let n=new Z,r=tt(t),o=e.dispersion===void 0&&!r.fixedDispersion,a=e.dispersion??xe(t,n),l=vo(t),s=(t.qr===void 0?[]:t.qr.pivot.slice(0,t.rank)).map(h=>t.coefficients[h]),f=l.map((h,d)=>Math.sqrt(h[d]*a)),i=s.map((h,d)=>h/f[d]),u=!o,m=i.map(h=>u?2*z(-Math.abs(h)):t.dfResidual>0?2*B(-Math.abs(h),t.dfResidual,!0,!1):NaN);return o&&t.dfResidual===0&&(f.fill(NaN),i.fill(NaN)),{dispersion:a,estimate:s,stdError:f,statistic:i,pValue:m,statisticName:r.fixedDispersion?"z value":"t value",covUnscaled:l,covScaled:l.map(h=>h.map(d=>d*a)),dfResidual:t.dfResidual,warnings:n.list}}function Ct(t,e="deviance"){let n=tt(t),{y:r,fittedValues:o,priorWeights:a}=t;switch(e){case"response":return r.map((l,c)=>l-o[c]);case"working":return t.residuals.slice();case"pearson":return r.map((l,c)=>(l-o[c])*Math.sqrt(a[c])/Math.sqrt(n.variance(o[c])));case"deviance":return t.dfResidual<=0?r.map(()=>0):r.map((l,c)=>Math.sign(l-o[c])*Math.sqrt(Math.max(n.devContribution(l,o[c],a[c]),0)));default:throw new RangeError(`unknown type of residuals "${String(e)}"`)}}function Ot(t){let e=[],n=t.qr,r=[];if(n!==void 0&&t.rank>0){let l=n.qr.length,c=Array.from({length:l},(f,i)=>Array.from({length:t.rank},(u,m)=>i===m?1:0));r=sn(n,c).map(f=>f.reduce((i,u)=>i+u*u,0))}let o=0,a=t.weights.map(l=>l>0);return t.priorWeights.forEach((l,c)=>{let s=a[c]?r[o++]??0:0;l>0&&e.push(s>1-10*ye?1:s)}),e}function bo(t){let e=t.slice().sort((r,o)=>r-o),n=e.length>>1;return e.length%2===1?e[n]:(e[n-1]+e[n])/2}function yo(t,e={}){let n=Ot(t),r=e.dispersion??xe(t),o=Ct(t,"deviance").filter((l,c)=>t.priorWeights[c]>0),a=100*ye*bo(o.map(Math.abs));return o.map((l,c)=>{let s=(Math.abs(l)<a?0:l)/Math.sqrt(r*(1-n[c]));return Number.isFinite(s)?s:NaN})}function Mo(t,e={}){let n=Ot(t),r=e.dispersion??xe(t);return Ct(t,"pearson").filter((a,l)=>t.priorWeights[l]>0).map((a,l)=>{let c=(a/(1-n[l]))**2*(n[l]/(r*t.rank));return Number.isFinite(c)?c:NaN})}function xo(t,e={}){let n=tt(t),r,o;if(e.newdata===void 0)r=t.model.x,o=t.linearPredictors.slice();else{r=$n(e.newdata).map(u=>t.model.intercept?[1,...u]:u);let i=e.newoffset===void 0?r.map(()=>0):Array.from(e.newoffset);if(i.length!==r.length)throw new RangeError("newoffset must have one value per row of newdata");o=r.map((u,m)=>u.reduce((h,d,g)=>Number.isNaN(t.coefficients[g])?h:h+d*t.coefficients[g],0)+i[m])}let a=e.dispersion??xe(t),l=t.rank,c=t.qr===void 0?[]:t.qr.pivot.slice(0,l),s=t.qr?.qr,f=r.map(i=>{let u=new Array(l).fill(0),m=0;for(let h=0;h<l;h++){let d=i[c[h]];for(let g=0;g<h;g++)d-=s[g][h]*u[g];u[h]=d/s[h][h],m+=u[h]*u[h]}return Math.sqrt(m)*Math.sqrt(a)});return(e.type??"link")==="link"?{fit:o,seFit:f}:Je(new Z,()=>({fit:o.map(i=>n.linkinv(i)),seFit:f.map((i,u)=>i*Math.abs(n.muEta(o[u])))}))}var Wn={epsilon:1e-300,maxit:100,untilCoefficients:!0};function Pt(t,e,n,r,o=1e-11){let a=[];for(let g=0;g<e.length;g++)n[g]>0&&a.push(g);let l=0,c=0;for(let g of a)l+=n[g],c+=n[g]*e[g];let s=r?c/l:0,f=0;for(let g of a)f+=n[g]*(e[g]-s)**2;if((t.length>0?t[0].length:0)===0||a.length===0)return 0;let u=a.map(g=>Math.sqrt(n[g])),m=ve(a.map((g,p)=>t[g].map(b=>b*u[p])),{tol:o}),h=_e(m,a.map((g,p)=>e[g]*u[p])),d=0;for(let g of h)d+=g*g;return f-d}function Eo(t,e={}){let n=e.level??.95,r=e.test??"LRT";if(!(n>0&&n<1))throw new RangeError("'level' must be in (0, 1)");let o=t.coefficients.length,a=e.parm??Array.from({length:o},(k,M)=>M);for(let k of a)if(!Number.isInteger(k)||k<0||k>=o)throw new RangeError(`invalid coefficient index ${k}`);let l=t.model,c=t.coefficients.map((k,M)=>M).filter(k=>!Number.isNaN(t.coefficients[k])),s=new Z,f=Me(l,c,s,{...Wn,start:l.start===void 0?void 0:c.map(k=>l.start[k])}),i=new Array(o).fill(NaN);c.forEach((k,M)=>i[k]=f.fit.coefficients[M]);let u={...t,coefficients:i,weights:f.fit.workingWeights,residuals:f.fit.workingResiduals,qr:f.fit.qr,rank:f.fit.rank},m=Vt(u),h=m.dispersion,d=new Array(o).fill(NaN);(f.fit.qr===void 0?[]:f.fit.qr.pivot.slice(0,f.fit.rank)).forEach((k,M)=>d[c[k]]=m.stdError[M]);let p=l.x.map(k=>c.map(M=>k[M])),b=f.fit.eta,v=(k,M)=>{let x=c.filter(I=>I!==k),A=Me(l,x,new Z,{...Wn,start:void 0,etastart:b,extraOffset:l.x.map(I=>I[k]*M)}).fit,E=r==="LRT"?A.deviance-f.fit.deviance:Pt(p,A.workingResiduals,A.workingWeights,!1);return Math.sign(M-i[k])*Math.sqrt(Math.max(E/h,0))},w=[P((1-n)/2),P((1+n)/2)],N=a.map(()=>NaN),y=a.map(()=>NaN);return a.forEach((k,M)=>{if(!Number.isNaN(i[k]))for(let x of[0,1]){let A=x===0?-1:1,E=NaN,I=NaN;for(let C=0;C<=30;C++){let W=i[k]+A*2**C*d[k],_=v(k,W);if(Math.abs(_)>=Math.abs(w[x])){E=W,I=_;break}}if(Number.isNaN(E))continue;let q=C=>C===i[k]?-w[x]:v(k,C)-w[x],[R,F]=x===0?[E,i[k]]:[i[k],E],[L,S]=x===0?[I-w[x],-w[x]]:[-w[x],I-w[x]],T=U(q,R,F,{tol:1e-14*d[k],maxIter:500,fLower:L,fUpper:S});x===0?N[M]=T:y[M]=T}}),{lower:N,upper:y}}var ko=(t,e)=>G(t,e/2,2,!1,!1);function Ro(t,e,n){let{fit:r,w:o}=Me(t,e,n);return{dfRes:o.filter(l=>l>0).length-r.rank,dev:r.deviance,fit:r,x:t.x.map(l=>e.map(c=>l[c])),intercept:t.intercept}}var zt=(t,e)=>Pt(e.x,t.fit.workingResiduals,t.fit.workingWeights,e.intercept);function Ao(t,e={}){let n=Array.isArray(t)?t:[t];if(n.length===0)throw new RangeError("no fits to compare");let r=new Z,o=Array.isArray(t)&&n.length>1,a=n[0],l=Se(a.model.familySpec),c=l.fixedDispersion,s=e.test===void 0?e.dispersion!==void 0||c?"Chisq":"F":e.test,f=[],i,u,m=[],h;if(o){let M=n[0].model.x.length;if(n.some(x=>x.model.x.length!==M))throw new RangeError("models were not all fitted to the same size of dataset");if(n.forEach((x,A)=>f.push({name:String(A+1),dfRes:x.dfResidual,dev:x.deviance})),i=f.map((x,A)=>A===0?NaN:f[A-1].dfRes-x.dfRes),u=f.map((x,A)=>A===0?NaN:f[A-1].dev-x.dev),s==="Rao"){let x=n.map(A=>({dfRes:A.dfResidual,dev:A.deviance,fit:_n(A),x:A.model.x,intercept:A.model.intercept}));m=f.map((A,E)=>E===0?NaN:i[E]<0?-zt(x[E],x[E-1]):zt(x[E-1],x[E]))}h=n.reduce((x,A)=>A.dfResidual<x.dfResidual?A:x)}else{let M=a,x=M.model,A=x.x.length>0?x.x[0].length-(x.intercept?1:0):0,E=x.intercept?[0]:[],I=R=>[...E,...Array.from({length:R},(F,L)=>L+E.length)],q=[];for(let R=0;R<=A;R++)R===A?q.push({dfRes:M.dfResidual,dev:M.deviance,fit:_n(M),x:x.x,intercept:x.intercept}):R>0||s==="Rao"?q.push(Ro(x,I(R),r)):q.push(void 0);f.push({name:"NULL",dfRes:M.dfNull,dev:M.nullDeviance});for(let R=1;R<=A;R++)f.push({name:`x${R}`,dfRes:q[R].dfRes,dev:q[R].dev});i=f.map((R,F)=>F===0?NaN:f[F-1].dfRes-R.dfRes),u=f.map((R,F)=>F===0?NaN:Math.max(f[F-1].dev-R.dev,0)),s==="Rao"&&(m=f.map((R,F)=>F===0?NaN:zt(q[F-1],q[F]))),h=M}let d=new Z,g=e.dispersion??xe(h,d);d.list.forEach(M=>r.add(M));let p=c?1/0:h.dfResidual,b=o?["Resid. Df","Resid. Dev","Df","Deviance"]:["Df","Deviance","Resid. Df","Resid. Dev"],v=f.map((M,x)=>o?[M.dfRes,M.dev,i[x],u[x]]:[i[x],u[x],M.dfRes,M.dev]),w=[...b],N=M=>f.map((x,A)=>{if(A===0||i[A]===0)return NaN;let E=M[A]/g*Math.sign(i[A]);return E<0||Number.isNaN(E)?NaN:ko(E,Math.abs(i[A]))}),y=[];if(s==="Chisq"||s==="LRT")w.push("Pr(>Chi)"),y=[N(u)];else if(s==="Rao")w.push("Rao","Pr(>Chi)"),y=[m,N(m)];else if(s==="F"){if(c&&r.add(`using F test with a '${l.family}' family is inappropriate`),p!==0){let M=f.map((x,A)=>{let E=u[A]/i[A]/g;return A===0||i[A]===0||E<0?NaN:E});w.push("F","Pr(>F)"),y=[M,M.map((x,A)=>Number.isNaN(x)?NaN:Q(x,Math.abs(i[A]),p,!1,!1))]}}else if(s==="Cp"){let M=h.model.x.length;w.push("Cp"),y=[f.map(x=>x.dev+2*g*(M-x.dfRes))]}let k=v.map((M,x)=>[...M,...y.map(A=>A[x])]);return{colNames:w,rowNames:f.map(M=>M.name),table:k,warnings:r.list}}function _n(t){return{coefficients:t.coefficients,eta:t.linearPredictors,mu:t.fittedValues,deviance:t.deviance,iter:t.iter,converged:t.converged,boundary:t.boundary,rank:t.rank,qr:t.qr,used:t.weights.map(e=>e>0),workingWeights:t.weights,workingResiduals:t.residuals}}export{io as TukeyHSD,Xr as ansariTest,ao as aov,xr as bartlettTest,wt as binomTest,Jr as brunnerMunzelTest,Gn as chisqTest,fo as confint,Hn as corTest,Zn as fisherTest,Ar as flignerTest,kr as friedmanTest,No as glm,Ao as glmAnova,Eo as glmConfint,Mo as glmCooksDistance,Ot as glmHatvalues,xo as glmPredict,Ct as glmResiduals,yo as glmRstandard,Vt as glmSummary,Er as kruskalTest,no as ksTest,co as lm,jr as mantelhaenTest,br as mcnemarTest,qr as moodTest,$r as onewayTest,gt as pAdjust,so as pairwisePropTest,ro as pairwiseTTest,oo as pairwiseWilcoxTest,vr as poissonTest,uo as predict,Nt as propTest,Rr as quadeTest,Dr as shapiroTest,it as tTest,Mr as varTest,ht as wilcoxTest,lo as zTest};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@numero-uno-jpn/rstats",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "R-compatible statistical functions for the browser: distributions, random numbers that match set.seed(), hypothesis tests and linear algebra, tested against R.",
5
5
  "keywords": [
6
6
  "statistics",
@@ -1,2 +0,0 @@
1
- /*! rStats.js 0.8.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 N,b as M,c as x,d as f,f as h,g as a,h as b}from"./chunk-OHPHNE3O.js";var l=[.6931471805599453,23190468138462996e-33];function E(t){let r=t[0];if(!N())return[Math.exp(r),0];if(Number.isNaN(r))return[NaN,0];if(r>709.8)return[1/0,0];if(r<-708)return[Math.exp(r)*(1+t[1]),0];let e=Math.round(r/l[0]),n=h(t,b(l,e)),i=1024;n=[n[0]/i,n[1]/i];let u=n,o=n;for(let s=2;s<20&&(u=a(u,n),u=[u[0]/s,u[1]/s],o=f(o,u),!(Math.abs(u[0])<1e-36));s++);for(let s=0;s<10;s++)o=a(o,f(o,[2,0]));let p=f(o,[1,0]),c=Math.trunc(e/2),d=2**c,m=2**(e-c);return[p[0]*d*m,p[1]*d*m]}function L(t,r,e){let n=t-r;if(!Number.isFinite(n))return[n/e,0];let i=r===0?[t,0]:M(t,-r);if(e===1)return i;let u=i[0]/e;if(!Number.isFinite(u)||u===0)return[u,0];let o=h(i,g(e,u)),p=(o[0]+o[1])/e;return M(u,p)}function g(t,r){let e=t*r;return!Number.isFinite(e)||Math.abs(t)>1e300||Math.abs(r)>1e300?[e,0]:x(t,r)}function D(t){return t[0]>708?Math.exp(700-t[0])*(1-t[1])*Math.exp(-700):Math.exp(-t[0])*(1-t[1])}function S(t){return t>-Math.LN2?Math.log(-Math.expm1(t)):Math.log1p(-Math.exp(t))}function k(t){return t[0]>Math.LN2?Math.log1p(-D(t)):Math.log(-Math.expm1(-(t[0]+t[1])))}function q(t,r,e){let n=g(r,e);if(!Number.isFinite(n[0])||!Number.isFinite(t))return t+n[0];let i=f(n,[t,0]);return i[0]+i[1]}export{E as a,L as b,g as c,D as d,S as e,k as f,q as g};