@numero-uno-jpn/rstats 0.7.0 → 0.8.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 (52) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.ja.md +17 -11
  3. package/README.md +17 -11
  4. package/THIRD_PARTY_NOTICES.md +30 -0
  5. package/dist/chunks/{chunk-ZYA4ISAT.js → chunk-32PRRONF.js} +1 -1
  6. package/dist/chunks/chunk-3I6EKGB6.js +2 -0
  7. package/dist/chunks/{chunk-BI5RSUZ2.js → chunk-EJRCDJ76.js} +2 -2
  8. package/dist/chunks/{chunk-JCZAB6C5.js → chunk-I3LAZE6C.js} +2 -2
  9. package/dist/chunks/chunk-JERGQKZM.js +2 -0
  10. package/dist/chunks/{chunk-UIOAWLAN.js → chunk-JVYV4633.js} +1 -1
  11. package/dist/chunks/chunk-LXMMKO26.js +2 -0
  12. package/dist/chunks/{chunk-YKN6OGJL.js → chunk-MJQLKEO5.js} +2 -2
  13. package/dist/chunks/{chunk-ZW52Z3GY.js → chunk-OHPHNE3O.js} +1 -1
  14. package/dist/chunks/{chunk-AFKYWGKN.js → chunk-RZ7SBJEG.js} +2 -2
  15. package/dist/chunks/{chunk-QNQJA6KZ.js → chunk-SPQC445Q.js} +2 -2
  16. package/dist/chunks/{chunk-SXSJXDD3.js → chunk-U633VFH3.js} +2 -2
  17. package/dist/chunks/{chunk-MVG5LUZU.js → chunk-VIPSPG3Y.js} +2 -2
  18. package/dist/chunks/{chunk-J3SNI7KY.js → chunk-XU4BGFZ6.js} +2 -2
  19. package/dist/chunks/{chunk-XYXHHF5L.js → chunk-YGWPU67I.js} +1 -1
  20. package/dist/descriptive.js +2 -2
  21. package/dist/distributions/beta.js +21 -5
  22. package/dist/distributions.js +2 -2
  23. package/dist/entries/distributions.d.ts +2 -1
  24. package/dist/entries/distributions.js +2 -1
  25. package/dist/entries/tests.d.ts +1 -0
  26. package/dist/entries/tests.js +1 -0
  27. package/dist/htest/brunnerMunzelTest.d.ts +28 -0
  28. package/dist/htest/brunnerMunzelTest.js +86 -0
  29. package/dist/linalg.js +2 -2
  30. package/dist/numerics.js +2 -2
  31. package/dist/random/lecuyer.d.ts +20 -0
  32. package/dist/random/lecuyer.js +71 -0
  33. package/dist/random/rng.d.ts +78 -11
  34. package/dist/random/rng.js +128 -26
  35. package/dist/random/sample.js +24 -7
  36. package/dist/random/streams.d.ts +34 -0
  37. package/dist/random/streams.js +75 -0
  38. package/dist/rstats.js +3 -3
  39. package/dist/special/igam.d.ts +1 -0
  40. package/dist/special/igam.js +1 -1
  41. package/dist/special/incbet.js +487 -6
  42. package/dist/special/incbetLargeA.d.ts +15 -0
  43. package/dist/special/incbetLargeA.js +200 -0
  44. package/dist/special/incbetTemme.d.ts +19 -0
  45. package/dist/special/incbetTemme.js +216 -0
  46. package/dist/special/loader.js +151 -118
  47. package/dist/special.js +2 -2
  48. package/dist/tests.js +3 -3
  49. package/package.json +1 -1
  50. package/dist/chunks/chunk-6R7YDHA2.js +0 -2
  51. package/dist/chunks/chunk-ANYGLFT4.js +0 -2
  52. package/dist/chunks/chunk-PTPPP4TI.js +0 -2
package/dist/tests.js CHANGED
@@ -1,3 +1,3 @@
1
- /*! rStats.js 0.7.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 at,G as ut,H as $t,M as ht,N as be,R as pt,S as Me,W as ye,X as ve,Y as xe,_ as Rt,c as D,d as Ot,l as zt,m as st,r as G,s as wt,x as _t}from"./chunks/chunk-6R7YDHA2.js";import{h as ke,k as Ie,l as Se,t as Le,y as Ve}from"./chunks/chunk-UIOAWLAN.js";import{a as C,b as Ae,c as U,f as cn}from"./chunks/chunk-SXSJXDD3.js";import{k as Y,l as it}from"./chunks/chunk-PTPPP4TI.js";import{c as Te}from"./chunks/chunk-QNQJA6KZ.js";import"./chunks/chunk-ZYA4ISAT.js";import{a as Nt,b as Z,c as K,e as Ee,f as W,g as lt,h as ct,i as Tt}from"./chunks/chunk-MVG5LUZU.js";import{a as Re,d as qe}from"./chunks/chunk-J3SNI7KY.js";import{b as Ne}from"./chunks/chunk-YKN6OGJL.js";import{g as P,h as V,s as we}from"./chunks/chunk-ANYGLFT4.js";import{b as jt,c as vt,d as F,e as de,f as Q,g as xt,i as Et,k as ge}from"./chunks/chunk-ZW52Z3GY.js";function Ht(e,t,o={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?o=t:n=t;let r=C(o.alternative),s=o.mu??0,i=o.paired??!1,l=o.varEqual??!1,a=o.confLevel??.95;if(Number.isNaN(s))throw new RangeError("mu must be a number");if(Ae(a),i&&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(i){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=K(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=i?"Paired t-test":"One Sample t-test",p=g,M=i?"mean difference":"mean of x",b=i?"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=K(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,T=k/E;h=Math.sqrt(v+T),u=(h*h)**2/(v*v/(w-1)+T*T/(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=Y(m,u,!0,!1),x=[-1/0,m+it(a,u,!0,!1)];else if(r==="greater")y=Y(m,u,!1,!1),x=[m-it(a,u,!0,!1),1/0];else{y=2*Y(-Math.abs(m),u,!0,!1);let E=1-a,R=it(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:a,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")}`,i=String(Number(e.toPrecision(15)));return i.length<=s.length?i:s}function J(e){let t=[0,0],o=0;for(let n of e)t=F(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 i=[...new Set(r)].sort(Fe),l=[...new Set(s)].sort(Fe);if(i.length<2||l.length<2)throw new RangeError("'x' and 'y' must have at least 2 levels");let a=new Map(i.map((u,h)=>[u,h])),f=new Map(l.map((u,h)=>[u,h])),c=i.map(()=>l.map(()=>0));return r.forEach((u,h)=>c[a.get(u)][f.get(s[h])]++),{...ze(c,o),rowLevels:i,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):ze(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:D(e,t/2,2,!1,!1)}function Oe(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);Oe(s);let i=r.map((m,u)=>s[u]*(1-m)),l=J(e.map((m,u)=>(m-s[u])**2/s[u])),a="Chi-squared test for given probabilities",f=o-1,c;if(t.simulatePValue??!1){let m=Ce(t);a+=bt(m),f=NaN,c=Pe(pn(n,r,s,m),l,m)}else c=je(l,f);return{method:a,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(i[u]))}}function pn(e,t,o,n){let r=t.length,s=xe(r,{size:Math.trunc(n*e),replace:!0,prob:t}),i=Math.trunc(e);if(s.length===0)return new Float64Array(0);if(i===0)throw new RangeError("invalid 'nrow' value (too large or NA)");let l=Math.ceil(s.length/i),a=new Float64Array(l),f=new Float64Array(r);for(let c=0;c<l;c++){f.fill(0);for(let u=0;u<i;u++)f[s[(c*i+u)%s.length]]++;let m=0;for(let u=0;u<r;u++)m+=(f[u]-o[u])**2/o[u];a[c]=m}return a}function dn(e,t,o,n){let r=e.length,s=t.length,i=e.reduce((c,m)=>c+m,0),l=Rt(i),a=new Int32Array(r*s),f=new Float64Array(Math.trunc(n));for(let c=0;c<f.length;c++){qt(e,t,l,a);let m=0;for(let u=0;u<s;u++)for(let h=0;h<r;h++){let p=o[h][u];m+=(a[h+u*r]-p)**2/p}f[c]=m}return f}function ze(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 i=J(s);if(!(i>0))throw new RangeError("at least one entry of 'x' must be positive");let l=e.map(w=>J(w)),a=e[0].map((w,g)=>J(e.map(N=>N[g]))),f=l.map(w=>a.map(g=>w*g/i));Oe(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)&&a.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)),a.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]/i)*(1-a[y]/i)));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 X(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(a=>a.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(a=>Array.from(a));if(r.flat().some(a=>Number.isNaN(a)||a<0))throw new RangeError("all entries of 'x' must be non-negative and finite");if(r.flat().some(a=>a===1/0))throw new RangeError("'x' has entries too large to be integer");let s=r.map(a=>a.map(Ne)),i="Fisher's Exact Test for Count Data";if(o===2&&n===2)return yn(s,t,i);let l=t.alternative??"two.sided";if(t.simulatePValue??!1){let a=t.B??2e3;if(!(a>=0&&a<2**31))throw new RangeError("'B' must be a non-negative number");return{method:i+bt(a),alternative:l,pValue:Nn(s,a)}}return{method:i,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)),i=r[0].map((M,d)=>r.reduce((b,w)=>b+w[d],0)),l=s.length,a=i.length,f=[0,0];for(let M of r.flat())f=F(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*a),h=0,p=Math.trunc(t);for(let M=0;M<p;M++){qt(s,i,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 Bt(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=F(n,[e[r],0]));return n[0]}var Kt=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 i=this.lo;i<=this.hi;i++){let l=i-this.lo;l%Mn===0||!(s>0&&s<1/0)?(r=ut(i,t,o,n,!0),s=1,this.logCentral[l]=r):this.logCentral[l]=r+Math.log(s),s*=(t-i)*(n-i)/((i+1)*(o-n+i+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 a=this.logCentral[l]+(this.lo+l)*n;r[l]=a,a>s&&(s=a)}for(let l=0;l<o;l++){let a=r[l]-s;r[l]=a<-746?0:Math.exp(a)}let i=Bt(r,0,o-1);for(let l=0;l<o;l++)r[l]!==0&&(r[l]=r[l]/i);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=F(n,[(this.lo+r)*o[r],0]));return n[0]}tail(t,o,n){if(o===1)return n?$t(t-1,this.m,this.n,this.k,!1,!1):$t(t,this.m,this.n,this.k,!0,!1);if(o===0||o===1/0){let i=o===0?this.lo:this.hi;return(n?t<=i:t>=i)?1:0}let r=this.density(o),s=t-this.lo;return n?Bt(r,s,r.length-1):Bt(r,0,s)}};function Dt(e,t){return t?X(e,0,1):1/X(o=>e(1/o),Number.EPSILON,1)}function yn(e,t,o){let n=C(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[[i,l],[a,f]]=e,c=i,m=new Kt(i+a,l+f,i+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=F(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:Dt(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:Dt(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:Dt(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 kt=[[0,0]];function tt(e){for(let t=kt.length;t<=e;t++)kt.push(F(kt[t-1],ge([t,0])));return kt[e]}function It(e,t,o,n){let r=e+o,s=r-e,i=e-(r-s)+(o-s)+t+n,l=r+i;return[l,i-(l-r)]}var Ut=class{scale=-1/0;hi=0;lo=0;add(t,o,n){if(t>this.scale){let a=Number.isFinite(this.scale)?Math.exp(this.scale-t):0;this.hi*=a,this.lo*=a,this.scale=t}let r=n*Math.exp(t-this.scale)*(1+o),s=this.hi+r,i=s-this.hi,l=this.hi-(s-i)+(r-i)+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),i=s.length,l=r.reduce((g,N)=>g+N,0),a=de(tt(l));for(let g of r)a=F(a,tt(g));for(let g of s)a=F(a,tt(g));let f=[0,0];for(let g of t.flat())f=Q(f,tt(g));let c=F(f,[Math.log1p(1e-7),0]),m=1e-9*(1+Math.abs(c[0])),[u,h]=c,p=Array.from({length:i},()=>new Map),M=(g,N)=>{let y=N.join(","),x=p[g].get(y);if(x!==void 0)return x;let E=F(a,tt(N.reduce((A,L)=>A+L,0)));for(let A of N)E=Q(E,tt(A));for(let A=g;A<i;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===i-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 T=new Array(n).fill(0),I=(A,L,j)=>{if(A===n-1){T[A]=L;let z=Q(j,tt(L)),et=N.map((rt,dt)=>rt-T[dt]).sort((rt,dt)=>rt-dt),$=M(g+1,et),B=`${et.join(",")}|${z[0]}`,nt=k.get(B);nt===void 0?k.set(B,{to:$,hi:z[0],lo:z[1],mult:1}):nt.mult++;return}let O=Math.max(0,L-v[A+1]),H=Math.min(N[A],L);for(let z=O;z<=H;z++)T[A]=z,I(A+1,L-z,Q(j,tt(z)))};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===i-2){let A=R.edges.map($=>{let B=$.to.edges[0];return{v:F([$.hi,$.lo],[B.hi,B.lo]),mult:$.mult}});A.sort(($,B)=>$.v[0]-B.v[0]||$.v[1]-B.v[1]);let L=A.length,j=A[L-1].v[0],O=new Float64Array(L),H=new Float64Array(L),z=new Float64Array(L),et=[0,0];A.forEach(({v:$,mult:B},nt)=>{O[nt]=$[0],H[nt]=$[1];let rt=Q($,[j,0]);et=F(et,[B*Math.exp(rt[0])*(1+rt[1]),0]),z[nt]=et[0]}),R.dist={hi:O,lo:H,cum:z,vmax:j,kv:F(a,[j,0])}}return R},d=M(0,[...r].sort((g,N)=>g-N)),b=new Ut,w=(g,N,y,x)=>{if(N+g.max<=u-m){let[I,A]=It(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]=It(u,h,-N,-y),v=0,T=E.hi.length;for(;v<T;){let I=v+T>>>1,A=E.hi[I];A<R||A===R&&E.lo[I]<=k?v=I+1:T=I}if(v>0){let[I,A]=It(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<i-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:T}of N.edges)for(let I=0;I<E.length;I++){let[A,L]=It(y[I],x[I],k,v),j=E[I]*T;if(w(R,A,L,j))continue;let O=R.index.get(A);O===void 0?(R.index.set(A,R.count.length),R.pastHi.push(A),R.pastLo.push(L),R.count.push(j)):R.count[O]+=j}N.pastHi=N.pastLo=N.count=[],N.index.clear()}}return Math.min(1,b.value())}function Xt(e,t,o={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?o=t:n=t;let r=C(o.alternative),s=o.mu??0,i=o.paired??!1,l=o.exact??null,a=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(i&&n===void 0)throw new TypeError("y is required when paired is true");let u,h;if(i){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:a,confInt:f,confLevel:c,tolRoot:m};return h===void 0?En(u,l,i,p):qn(u,h,l,p)}function St(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 He(e){let t=e.length,o=W(e.map(Math.abs)),n=0;for(let i=0;i<t;i++)e[i]>0&&(n+=o[i]);let r=0;for(let i of lt(o))r+=i*i*i-i;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:i}=n,l=e.map(x=>x-s),a=l.some(x=>x===0);a&&(l=l.filter(x=>x!==0));let f=l.length,c=t??f<50,m=W(l.map(Math.abs)),u=lt(m).length>0,[h,p,M]=He(l),d,b,w=c&&!u&&!a;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${i?" with continuity correction":""}`,d=$e((p-St(p,r,i))/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 Lt(e,t,o){return e==="less"?[-1/0,o]:e==="greater"?[t,1/0]:[t,o]}function _e(e,t,o){let n={confInt:Lt(e,NaN,NaN),confLevel:0,estimate:t};return o!==void 0&&(n.estimateNames=o),n}function We(e,t,o){let n=e(t==="two.sided"?o/2:o);return n===0?1:n}function Be(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 i=s.length,l=1-n,a=We(m=>be(m,r,!0,!1),o,l),f=ht(a-1,r,!0,!1),c=o==="two.sided"?2*f:f;return{confInt:Lt(o,s[a-1],s[i-a]),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,i=e.length;if(i===0)return _e(o,NaN);let l=Math.min(...e),a=Math.max(...e);if(!Number.isFinite(l)||!Number.isFinite(a)||i===1||l===a)return _e(o,(l+a)/2,"midrange");let f=(g,N)=>{let[,y,x]=He(e.map(E=>E-g).filter(E=>E!==0));return(y-St(y,o,N))/x},c=f(l,n),m=f(a,n),u=g=>-V(g),h=g=>o==="greater"?!(c<u(g)):o==="less"?!(m>V(g/2)):!(c<u(g/2))&&!(m>V(g/2)),p=1-r,M=!1;for(;!h(p)&&p<1;)p*=2,M=!0;Be(s);let d=g=>X(N=>f(N,n)-g,l,a,{tol:s,fLower:c-g,fUpper:m-g}),b;if(p>=1){let g=Qt([...e].sort(Gt));b=Lt(o,g,g)}else o==="greater"?b=[d(u(p)),1/0]:o==="less"?b=[-1/0,d(V(p))]:b=[d(u(p/2)),d(V(p/2))];let w=X(g=>f(g,!1),l,a,{tol:s,fLower:f(l,!1),fUpper:f(a,!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=W([...e,...t]),s=0;for(let c=0;c<o;c++)s+=r[c];let i=s-o*(o+1)/2,l=0;for(let c of lt(r))l+=c*c*c-c;let a=o+n,f=Math.sqrt(o*n/12*(a+1-l/(a*(a-1))));return[i,i-o*n/2,f]}function qn(e,t,o,n){let{alternative:r,mu:s,correct:i}=n,l=e.length,a=t.length,f=e.map(N=>N-s),c=o??(l<50&&a<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,a,!0,!1);else if(r==="greater")M=pt(u-1,l,a,!1,!1);else{let N=u>l*a/2?pt(u-1,l,a,!1,!1):pt(u,l,a,!0,!1);M=Math.min(1,2*N)}else d=`Wilcoxon rank sum test${i?" with continuity correction":""}`,M=$e((h-St(h,r,i))/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,i=t.length,l=[];for(let h of e)for(let p of t)l.push(h-p);l.sort(Gt);let a=l.length,f=1-r,c=We(h=>Me(h,s,i,!0,!1),n,f),m=pt(c-1,s,i,!0,!1),u=n==="two.sided"?2*m:m;return{confInt:Lt(n,l[c-1],l[a-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:i}=o,l=Math.min(...e)-Math.max(...t),a=Math.max(...e)-Math.min(...t);if(!Number.isFinite(l)||!Number.isFinite(a))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-St(M,n,p))/d},c=(h,p)=>{let M=f(l,p)-h,d=f(a,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?a:(Be(i),X(b=>f(b,p)-h,l,a,{tol:i,fLower:M,fUpper:d}))},m=1-s,u;return n==="greater"?u=[c(-V(m),r),1/0]:n==="less"?u=[-1/0,c(V(m),r)]:u=[c(-V(m/2),r),c(V(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 Yt(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 i=s.length,l=o.n??i;if(!(l>=i))throw new RangeError("n must be at least the number of non-NaN p-values");if(l<=1)return r;let a=s.map(m=>r[m]),f=Sn(a,n,l),c=r.slice();return s.forEach((m,u)=>c[m]=f[u]),c}function Vt(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=Vt(e,!1),i=-1/0;return s.forEach((l,a)=>{i=Math.max(i,(o-a)*e[l]),r[l]=Math.min(1,i)}),r}case"hochberg":{let s=Vt(e,!0),i=1/0;return s.forEach((l,a)=>{let f=n-a;i=Math.min(i,(o-f+1)*e[l]),r[l]=Math.min(1,i)}),r}case"BH":case"fdr":case"BY":{let s=t==="BY"?Ee(Array.from({length:Math.floor(o)},(a,f)=>1/(f+1))):1,i=Vt(e,!0),l=1/0;return i.forEach((a,f)=>{let c=n-f;l=Math.min(l,s*o/c*e[a]),r[a]=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=Vt(n,!1),s=r.map(a=>n[a]),i=s.slice();for(let a=t;a>=2;a--){let f=1/0;for(let c=1;c<=a;c++)f=Math.min(f,a*s[t-a+c-1]/c);for(let c=t-a;c<t;c++)i[c]=Math.max(i[c],f);for(let c=0;c<t-a;c++)i[c]=Math.max(i[c],Math.min(a*s[c],f))}let l=new Array(o);return r.forEach((a,f)=>{a<o&&(l[a]=i[f])}),l}var Vn=1+1e-7;function Ft(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 a=Math.ceil(n);a<=t;a++)At(a,t,o,!1)<=r&&s++;let l=s===0?0:at(t-s,t,o,!1,!1);return Math.min(1,at(e,t,o,!0,!1)+l)}for(let l=0;l<=Math.floor(n);l++)At(l,t,o,!1)<=r&&s++;let i=s===0?0:at(s-1,t,o,!0,!1);return Math.min(1,at(e-1,t,o,!1,!1)+i)}function Zt(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),!Ft(e[0])||!Ft(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(!Ft(e))throw new RangeError("'x' must be nonnegative and integer");if(n=Math.round(e),!(Ft(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 i=C(o.alternative),l=o.confLevel??.95;U(l);let a;i==="less"?a=at(n,r,s,!0,!1):i==="greater"?a=at(n-1,r,s,!1,!1):a=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(i==="less")m=[0,c(1-l)];else if(i==="greater")m=[f(1-l),1];else{let u=(1-l)/2;m=[f(u),c(u)]}return{method:"Exact binomial test",alternative:i,statistic:n,statisticName:"number of successes",parameter:r,parameterName:"number of trials",pValue:a,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=zt(e,t,!1)*Cn,n=l=>zt(l,t,!1)<=o,r=Math.floor(t);if(e<t){let l=Math.max(e+1,r),a=l;if(!n(l)){let f=l,c=1;for(a=l+1;!n(a);)f=a,c*=2,a=l+c;for(;a-f>1;){let m=f+Math.floor((a-f)/2);n(m)?a=m:f=m}}return Math.min(1,st(e,t,!0,!1)+st(a-1,t,!1,!1))}let s=Math.min(e-1,r),i;if(!n(0))i=-1;else if(n(s))i=s;else{i=0;let l=s;for(;l-i>1;){let a=i+Math.floor((l-i)/2);n(a)?i=a:l=a}}return Math.min(1,st(i,t,!0,!1)+st(e-1,t,!1,!1))}function On(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,i=typeof s=="number"?new Array(r).fill(s):Array.from(s);if(i.length!==r)throw new RangeError("'x' and 'T' have incompatible length");if(!i.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 a=C(t.alternative),f=t.confLevel??.95;if(U(f),r===2){let[b,w]=n,[g,N]=i,y=b+w,x=l*g/(l*g+N),E=Zt([b,w],{p:x,alternative:a,confLevel:f}),R=k=>k/(1-k)*(N/g);return{method:"Comparison of Poisson rates",alternative:a,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=i[0],u=l*m,h;a==="less"?h=st(c,u,!0,!1):a==="greater"?h=st(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(a==="less")d=[0,M(1-f)];else if(a==="greater")d=[p(1-f),1/0];else{let b=(1-f)/2;d=[p(b),M(b)]}return{method:"Exact Poisson test",alternative:a,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 Jt(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(T=>T.length!==2))throw new RangeError("'x' must have 2 columns");n=v.map(T=>T[0]),r=v.map(T=>T[0]+T[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 i=n.length,l=[];for(let v=0;v<i;v++)!Number.isNaN(n[v])&&!Number.isNaN(r[v])&&l.push(v);let a=l.length;if(a<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,T)=>v>r[T]))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!==i)throw new RangeError("'p' must have the same length as 'x' and 'n'");if(f=l.map(T=>v[T]),f.some(T=>!(T>0&&T<1)))throw new RangeError("elements of 'p' must be in (0,1)")}let c=f!==void 0;a===1&&f===void 0&&(f=[.5]);let m=s.confLevel??.95;U(m);let u=C(s.alternative);(a>2||a===2&&c)&&(u="two.sided");let h=n.map((v,T)=>v/r[T]),p=a===2?h[0]-h[1]:0,M=a===2?1/r[0]+1/r[1]:0,d=(s.correct??!0)&&a<=2?.5:0,b=!1;if(d>0&&a===1){let v=Math.abs(n[0]-r[0]*f[0]);v<=d&&([d,b]=[v,!0])}else if(d>0&&a===2&&!c){let v=Math.abs(p)/M;v<=d&&([d,b]=[v,!0])}let w=n.reduce((v,T)=>v+T,0)/r.reduce((v,T)=>v+T,0),g=0;if(!b)for(let v=0;v<a;v++){let T=f?.[v]??w,I=r[v]*T,A=r[v]*(1-T);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?a:a-1,y;if(u==="two.sided")y=D(g,N/2,2,!1,!1);else{let v=Math.sign(a===1?h[0]-f[0]:p);y=P(v*Math.sqrt(g),{lowerTail:u==="less"})}let x;if(a===1||a===2&&!c){let v=V(u==="two.sided"?(1+m)/2:m);if(a===1){let T=r[0],I=v*v,A=(z,et)=>(z+I/(2*T)+et*v*Math.sqrt(z*(1-z)/T+I/(4*T*T)))/(1+I/T),L=h[0]+d/T,j=h[0]-d/T,O=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,O]:u==="greater"?[H,1]:[0,O]}else{let T=Math.sqrt(h.reduce((j,O,H)=>j+O*(1-O)/r[H],0)),I=v*T+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=a===1?"p":l.map(v=>`prop ${v+1}`),k={method:`${a===1?"1-sample proportions test":`${a}-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:a===1?h[0]:h,estimateNames:E};return f!==void 0&&(k.nullValue=a===1?f[0]:f,k.nullValueName=E),x!==void 0&&(k.confInt=x,k.confLevel=m),k}function zn(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,i,l=r&&s===2&&n[0][1]!==n[1][0];if(l){let f=n[0][1],c=n[1][0];i=(Math.abs(f-c)-1)**2/(f+c)}else{i=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];i+=(m-u)**2/(m+u)}}let a=s*(s-1)/2;return{method:l?"McNemar's Chi-squared test with continuity correction":"McNemar's Chi-squared test",statistic:i,statisticName:"McNemar's chi-squared",parameter:a,parameterName:"df",pValue:D(i,a/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 i=new Map(r.map((f,c)=>[f,c])),l=new Map(s.map((f,c)=>[f,c])),a=r.map(()=>new Array(r.length).fill(0));for(let[f,c]of o)a[i.get(f)][l.get(c)]++;return a}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 i=C(o.alternative),l=o.confLevel??.95;U(l);let a=n.length-1,f=r.length-1;if(a<1)throw new Error("not enough 'x' observations");if(f<1)throw new Error("not enough 'y' observations");let c=K(n)/K(r),m=c/s,u=G(m,a,f,!0,!1),h=G(m,a,f,!1,!1),p,M;if(i==="less")p=u,M=[0,c/wt(1-l,a,f,!0,!1)];else if(i==="greater")p=h,M=[c/wt(l,a,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,a,f,!0,!1),c/wt(d,a,f,!0,!1)]}return{method:"F test to compare two variances",alternative:i,statistic:m,statisticName:"F",parameter:[a,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 Hn(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(K(m))}let r=0,s=0,i=0,l=0;for(let c=0;c<t;c++)r+=o[c],s+=o[c]*n[c],i+=o[c]*Math.log(n[c]),l+=1/o[c];s/=r;let a=(r*Math.log(s)-i)/(1+(l-1/r)/(3*(t-1))),f=t-1;return{method:"Bartlett test of homogeneity of variances",statistic:a,statisticName:"Bartlett's K-squared",parameter:f,parameterName:"df",pValue:D(a,f/2,2,!1,!1)}}function te(e,t,o="drop"){if(t===void 0){let i=e;if(i.length>0&&typeof i[0]=="number")throw new TypeError("'g' is required when 'x' is a single sample");let l=i.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 a=[],f=[];return l.forEach((c,m)=>{c.length!==0&&(a.push(String(m+1)),f.push(c))}),{labels:a,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 i=0;i<n.length;i++){let l=n[i],a=t[i];if(Number.isNaN(l)||typeof a=="number"&&Number.isNaN(a))continue;let f=r.get(a);f===void 0&&r.set(a,f=[]),f.push(l)}let s=Array.from(r.keys()).sort((i,l)=>typeof i=="number"&&typeof l=="number"?i-l:String(i)<String(l)?-1:String(i)>String(l)?1:0);return{labels:s.map(String),groups:s.map(i=>r.get(i))}}function ft(e,t,o="drop"){return te(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 ee(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 ne(e,t,o,n){return{method:e,statistic:o,statisticName:t,parameter:n,parameterName:"df",pValue:D(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 Wn(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,i=W(r),l=0,a=0;for(let f of o){let c=0;for(let m=0;m<f.length;m++)c+=i[a+m];a+=f.length,l+=c*c/f.length}return l=(12*l/(s*(s+1))-3*(s+1))/(1-Xe(r)/(s*s*s-s)),ne("Kruskal-Wallis rank sum test","Kruskal-Wallis chi-squared",l,n-1)}function Bn(e){let t=ee(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 a of t){let f=W(a);for(let c=0;c<n;c++)r[c]+=f[c];s+=Xe(a)}let i=0;for(let a of r)i+=(a-o*(n+1)/2)**2;let l=12*i/(o*n*(n+1)-s/(n-1));return ne("Friedman rank sum test","Friedman chi-squared",l,n-1)}function Dn(e){let t=ee(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=W(t.map(h=>Math.max(...h)-Math.min(...h))),s=new Array(n).fill(0),i=0;t.forEach((h,p)=>{let M=W(h);for(let d=0;d<n;d++){let b=r[p]*(M[d]-(n+1)/2);i+=b*b,s[d]+=b}});let l=0;for(let h of s)l+=h*h;l/=o;let a=n-1,f=(o-1)*(n-1),c,m,u=[a,f];if(i===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/(i-l),m=G(c,a,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=W(r).map(u=>V((1+u/(s+1))/2)),a=0;for(let u of l)a+=u;let f=a/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/=K(l),ne("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=C(o.alternative),i=n.length,l=r.length,a=i+l;if(a<3)throw new RangeError("not enough observations");let f=n.concat(r),c=Array.from({length:a},(N,y)=>y).sort((N,y)=>f[N]-f[y]),m=new Array(a),u=0;for(;u<a;){let N=u;for(;N+1<a&&f[c[N+1]]===f[c[u]];)N++;let y=0;for(let x=u;x<=N;x++)y+=(x+1-(a+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<i;N++)h+=m[N];let p=0;for(let N of m)p+=N;p/=a;let M=0;for(let N of m)M+=(N-p)**2;let d=i*p,b=i*l/(a*(a-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],Qn=[0,.042981,-.293762,-1.752461,5.682633,-3.582633],Gn=[.544,-.39978,.025054,-6714e-7],Yn=[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]=-V((m+1-.375)/(e+.25)),r+=n[m]*n[m];r*=2;let s=Math.sqrt(r),i=1/Math.sqrt(e),l=n[0]/s+mt(Xn,i),a=new Float64Array(o);a[0]=l;let f,c;if(e>5){let m=n[1]/s+mt(Qn,i);a[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++)a[m]=n[m]/c;for(let m=0;m<o;m++)t[e-1-m]=a[m],t[m]=-a[m];return t}function Qe(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,i=0,l=0;for(let f=0;f<t;f++){let c=e[f]/n-r;s+=o[f]*o[f],i+=c*c,l+=o[f]*c}let a=Math.sqrt(s*i);return(a-l)*(a+l)/(s*i)}var nr=1.90985931710274,rr=1.0471975511966;function Ge(e,t){if(Number.isNaN(e)||!(t>=3))return NaN;if(t===3){let i=nr*(Math.asin(Math.sqrt(1-e))-rr);return Math.max(i,0)}let o=Math.log(e);if(t<=11){let i=mt(tr,t);if(o>=i)return 1e-99;let l=mt(Gn,t),a=Math.exp(mt(Yn,t));return P(-Math.log(i-o),{mean:l,sd:a,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,i=r.length;if(i<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 a=r.map(Z),f=r.map(K),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<i;d++)p+=l[d]*(a[d]-h)**2,M+=(l[d]-1)*f[d];u=c-i,m=p/(i-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<i;w++)M+=(1-h[w]/p)**2/(l[w]-1),d+=h[w]*a[w];M/=i*i-1,d/=p;let b=0;for(let w=0;w<i;w++)b+=h[w]*(a[w]-d)**2;m=b/((i-1)*(1+2*(i-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:[i-1,u],parameterName:["num df","denom df"],pValue:G(m,i-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=Qe(t);return{method:"Shapiro-Wilk normality test",statistic:1-n,statisticName:"W",pValue:Ge(n,o)}}function re(e,t,o){let n=[0,0];for(let r=Math.max(0,t);r<Math.min(o,e.length);r++)n=F(n,[e[r],0]);return n[0]}function ar([[e,t],[o,n]]){let r=e+o,s=t+n,i=e+t,l=Math.max(0,i-s),a=Math.min(i,r),f=new Float64Array(a-l+1);for(let c=l;c<=a;c++)f[c-l]=ut(c,r,s,i,!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 Ct=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 a=this.logNull[l]+(this.lo+l)*r;n[l]=a,a>s&&(s=a)}for(let l=0;l<o;l++)n[l]=Math.exp(n[l]-s);let i=re(n,0,o);for(let l=0;l<o;l++)n[l]=n[l]/i;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=F(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?re(r,s,r.length):re(r,0,s+1)}};function oe(e,t){return t?X(e,0,1):1/X(o=>e(1/o),Number.EPSILON,1)}function Ye(e,t){if(t===e.lo)return 0;if(t===e.hi)return 1/0;let o=e.mean(1);return o===t?1:oe(n=>e.mean(n)-t,o>t)}function se(e,t,o){if(t===e.hi)return 1/0;let n=e.cdf(t,1,!1);return n===o?1:oe(r=>o-e.cdf(t,r,!1),n<o)}function ae(e,t,o){if(t===e.lo)return 0;let n=e.cdf(t,1,!0);return n===o?1:oe(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 i=C(t.alternative),l=t.correct??!0,a=t.exact??!1,f=t.confLevel??.95;if(U(f),n===2&&r===2){let c=e.map(m=>[[m[0][0],m[0][1]],[m[1][0],m[1][1]]]);return a?fr(c,i,f):cr(c,s,i,l,f)}return mr(e,s,n,r)}function cr(e,t,o,n,r){let s=0,i=0,l=0,a=0,f=0,c=0,m=0,u=0;e.forEach(([[N,y],[x,E]],R)=>{let k=t[R],v=N+y,T=x+E,I=N+x,A=y+E;s+=N,i+=v*I/k,l+=v*T*I*A/(k*k*(k-1));let L=(N+E)/k,j=(y+x)/k,O=N*E/k,H=y*x/k;a+=O,f+=H,c+=L*O,m+=L*H+j*O,u+=j*H});let h=s-i,p=n&&Math.abs(h)>=.5?.5:0,M=(Math.abs(h)-p)**2/l,d=o==="two.sided"?D(M,.5,2,!1,!1):P(Math.sign(h)*Math.sqrt(M),{lowerTail:o==="less"}),b=a/f,w=Math.sqrt(c/(2*a*a)+m/(2*a*f)+u/(2*f*f)),g;if(o==="less")g=[0,b*Math.exp(V(r)*w)];else if(o==="greater")g=[b*Math.exp(V(r,{lowerTail:!1})*w),1/0];else{let N=V((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 Ct(e),r=e.reduce((l,a)=>l+a[0][0],0),s;if(t==="two.sided"){let l=n.density(1),a=l[r-n.lo]*(1+1e-7),f=[0,0];for(let c of l)c<=a&&(f=F(f,[c,0]));s=Math.min(1,f[0])}else s=n.cdf(r,1,t==="greater");let i;if(t==="less")i=[0,se(n,r,1-o)];else if(t==="greater")i=[ae(n,r,1-o),1/0];else{let l=(1-o)/2;i=[ae(n,r,l),se(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:i,confLevel:o,estimate:Ye(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),i=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];i[b][g+(o-1)*w]+=p*N*y}}});let l=Le(i,s),a=0;for(let f=0;f<r;f++)a+=s[f]*l[f];return{method:"Cochran-Mantel-Haenszel test",statistic:a,statisticName:"Cochran-Mantel-Haenszel M^2",parameter:r,parameterName:"df",pValue:D(a,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 i=s.reduce((u,h)=>u+h,0),l=Array.from({length:e+1},()=>new Float64Array(i+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(i+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<=i;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 a=l[e],f=0;for(;f<a.length&&a[f]===0;)f++;let c=a.length-1;for(;c>f&&a[c]===0;)c--;let m={min:f,probs:a.slice(f,c+1)};return Ze.set(o,m),m}function ie(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),i=Math.floor(e+1e-7)-r,l=0;if(n)for(let a=0;a<=Math.min(i,s.length-1);a++)l+=s[a];else for(let a=Math.max(i+1,0);a<s.length;a++)l+=s[a];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 i=Array.from({length:e+1},()=>new Float64Array(s+1));i[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=i[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))}}i=h}let l=i[e],a=0;for(;l[a]===0;)a++;let f=l.length-1;for(;l[f]===0;)f--;let c={min:a,counts:l.slice(a,f+1)};return Je.set(o,c),c}function Pt(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),i=0;for(let l=0;l<r.length;l++)if(i+=r[l]/s,i>=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,i=r.length;if(s<1)throw new RangeError("not enough 'x' observations");if(i<1)throw new RangeError("not enough 'y' observations");let l=C(o.alternative),a=o.confInt??!1,f=o.confLevel??.95;a&&U(f);let c=s+i,m=W(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&&i<50&&!p),d,b;if(M&&!p){let g=y=>ie(y-1,s,i,!1),N=y=>ie(y,s,i,!0);if(l==="two.sided"){let y=Math.floor((s+1)**2/4)+Math.floor(s*i/2)/2;d=Math.min(1,2*(h>y?g(h):N(h)))}else l==="less"?d=g(h):d=N(h);a&&(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*i*(16*g-c*(c+2)**2)/(16*c*(c-1)):s*i*(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),a&&(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(a=>a/o).concat(t)),i=s.map(a=>Math.min(a,r-a+1)),l=0;for(let a=0;a<n;a++)l+=i[a];return{ab:l,a:i,ties:new Set(s).size<r}}function dr(e){let t=e.filter(s=>!Number.isNaN(s));if(t.length===e.length)return W(e);let o=W(t),n=0,r=t.length;return e.map(s=>Number.isNaN(s)?++r:o[n++])}function le(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,i=[];for(let d of e)for(let b of t)d/b>=0&&i.push(d/b);i.sort((d,b)=>d-b);let l=i.length;if(l===0)return{confInt:le(o,1-n,()=>[NaN,NaN]),estimate:NaN};let a=i.map((d,b)=>tn(e,t,d+(b<l-1?(i[b+1]-d)/2:d*1.01)).ab),f=(d,b,w)=>{let g=1/0;for(let y of a)(b?y-d>0:y-d>=0)&&y-d<g&&(g=y-d);let N=w?-1/0:1/0;return a.forEach((y,x)=>{y-d===g&&(N=w?Math.max(N,i[x]):Math.min(N,i[x]))}),N},c=d=>{let b=Pt(d/2,r,s),w=Pt(1-d/2,r,s);if(!a.some(y=>y-b>=0)||!a.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=le(o,1-n,c),u=Pt(.5,r,s),h=-1/0,p=1/0;a.forEach((d,b)=>{d-u<=0?h=Math.max(h,i[b]):p=Math.min(p,i[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,i=r+s,l=i%2===0,a=(b,w)=>{let{ab:g,a:N,ties:y}=tn(e,t,b),x=l?g-r*(i+2)/4:g-r*(i+1)**2/(4*i),E;if(!y)E=Math.sqrt(l?r*s*(i+2)*(i-2)/(48*(i-1)):r*s*(i+1)*(3+i*i)/(48*i*i));else{let R=0;for(let k of N)R+=k*k;E=Math.sqrt(l?r*s*(16*R-i*(i+2)**2)/(16*i*(i-1)):r*s*(16*i*R-(i+1)**4)/(16*i*i*(i-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=>X(w=>a(w,b),m,u,{tol:1e-4}),p=b=>{let w=V(b/2),g=V(b/2,{lowerTail:!1});if(a(m,w)>0||a(u,g)<0)return[NaN,NaN];let N=h(w),y=h(g);return N<=y?[N,y]:[y,N]},M=le(o,1-n,p),d=a(m,0)>0||a(u,0)<0?NaN:h(0);return{confInt:M,estimate:d}}var Nr=[1.2337005501361697,7831619385924639e-32];function br(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,i=0,l=e.slice(),a=0,f=o;for(;f>0;)f&1&&(s=s===void 0?l.slice():n(s,l),i+=a,i+=r(s)),f>>=1,f>0&&(l=n(l,l),a*=2,a+=r(l));return[s,i]}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[i,l]=br(s,n,e),a=i[(o-1)*n+o-1],f=l;for(let c=1;c<=e;c++)a=a*c/e,Math.abs(a)<2**-500&&(a*=2**500,f-=500);for(;f>1e3;)a*=2**1e3,f-=1e3;for(;f<-1e3;)a*=2**-1e3,f+=1e3;return a*2**f}function ce(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(Nr,vt(e,e)),s=r[0]+r[1],i=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+i))break}let a=Math.sqrt(2*Math.PI)/e*(i+l);return t?a:1-a}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 i=0;i<=r;i++){let l=F(jt(e-i,-o),[-n,0]);if(l[0]<=0)break;let a=F(jt(i,o),[n,0]),f=Et(a,[e,0]),c=Et(l,[e,0]);s+=we(i,e-i,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,i;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);i=new Array(s+1).fill(!1);for(let h=1;h<s;h++)i[h]=u[h]!==u[h-1]}let l=e*t*o*(1-1e-10),a=(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);(i===void 0?p<s:i[p])&&a(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 Mr(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=C(o.alternative),i=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):ce(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:i,pValue:Math.min(1,Math.max(0,E))}}let l=Array.from(t).filter(w=>!Number.isNaN(w)),a=l.length;if(a<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/a;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*a<1e4,b;if(d)b=rn(p,r,a,M?{alternative:s,z:f.map(w=>w[0])}:{alternative:s});else{let w=r*a/(r+a);b=s==="two.sided"?ce(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:i,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 i=0;i<n.length;i++){let l=t[i];if(typeof l=="number"&&Number.isNaN(l)||o&&Number.isNaN(n[i]))continue;let a=r.get(l);a===void 0&&r.set(l,a=[]),a.push(n[i])}let s=Array.from(r.keys()).sort((i,l)=>typeof i=="number"&&typeof l=="number"?i-l:String(i)<String(l)?-1:String(i)>String(l)?1:0);return{levels:s,groups:s.map(i=>r.get(i))}}function fe(e,t,o){let n=[],r=[];for(let l=0;l<e-1;l++)for(let a=l+1;a<e;a++)n.push(t(a,l)),r.push([a-1,l]);let s=Yt(n,o),i=Array.from({length:e-1},()=>new Array(e-1).fill(NaN));return r.forEach(([l,a],f)=>i[l][a]=s[f]),i}function me(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 yr(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=C(o.alternative),i=o.pAdjustMethod??"holm",{levels:l,groups:a}=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=a.map(b=>b.length),h=a.map(b=>b.length>0?Z(b):NaN),p=0,M=0;a.forEach(b=>{b.length>1&&(p+=K(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"?Y(g,M,!0,!1):s==="greater"?Y(g,M,!1,!1):2*Y(-Math.abs(g),M,!0,!1)}}else m=n?"paired t tests":"t tests with non-pooled SD",c=(u,h)=>Ht(a[u],a[h],{paired:n,alternative:s}).pValue;return me(m,l,fe(f,c,i),i)}function vr(e,t,o={}){let{pAdjustMethod:n,alternative:r,...s}=o,i=n??"holm",{levels:l,groups:a}=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=fe(f,(u,h)=>{let p=Xt(a[u],a[h],{...s,...r===void 0?{}:{alternative:r}});return c=p.method,p.pValue},i);return me(c,l,m,i)}function xr(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 i=o.pAdjustMethod??"holm",l=o.correct??!0,a=fe(s,(c,m)=>Jt([n[c],n[m]],[r[c],r[m]],{correct:l}).pValue,i),f=Array.from({length:s},(c,m)=>m+1);return me("Pairwise comparison of proportions",f,a,i)}function an(e){let t=e.flat(),o=Nt(t),n=[0,0],r=[0,0],s=[];for(let i of e){let l=Nt(i);s.push(l[0]);let a=Q(l,o);n=F(n,xt(xt(a,a),[i.length,0]));for(let f of i){let c=Q([f,0],l);r=F(r,xt(c,c))}}return{ssb:n[0],ssw:r[0],means:s}}function Er(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:i}=an(o),l=n-1,a=r-n,f=s/l,c=i/a,m=f/c;return{df:[l,a],sumSq:[s,i],meanSq:[f,c],fValue:m,pValue:a>0?G(m,l,a,!1,!1):NaN}}function Ar(e,t,o={}){let n;t!==void 0&&!Array.isArray(t)?o=t:n=t;let{labels:r,groups:s}=te(e,n),i=s.length;if(i<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)-i,{ssw:c,means:m}=an(s),u=c/f,h=ve(l,i,f),p={names:[],i:[],j:[],diff:[],lwr:[],upr:[],pAdj:[]};for(let M=0;M<i-1;M++)for(let d=M+1;d<i;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(ye(Math.abs(b)/w,i,f,{lowerTail:!1}))}return p}function Rr(e,t,o={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?o=t:n=t;let{sigmaX:r,sigmaY:s}=o,i=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(i))throw new RangeError("mu must be a number");let l=C(o.alternative),a=o.confLevel??.95;if(!(a>=0&&a<=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-i)/h,d,b;if(l==="less")d=P(M),b=[-1/0,p+V(a)*h];else if(l==="greater")d=P(M,{lowerTail:!1}),b=[p-V(a)*h,1/0];else{d=2*P(-Math.abs(M));let g=V(1-(1-a)/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:a,estimate:w?[m,u]:m,estimateNames:w?["mean of x","mean of y"]:"mean of x",nullValue:i,nullValueName:w?"difference in means":"mean"}}function qr(e,t,o={}){let n=o.intercept??!0,r=e.length>0&&typeof e[0]!="number"?e.map(q=>Array.from(q)):Array.from(e,q=>[q]),s=Array.from(t);if(r.length!==s.length)throw new RangeError("variable lengths differ (found for 'x')");let i=o.weights===void 0?void 0:Array.from(o.weights);if(i!==void 0&&i.length!==s.length)throw new RangeError("variable lengths differ (found for '(weights)')");if(i?.some(q=>q<0))throw new RangeError("missing or negative weights not allowed");let l=s.map((q,S)=>!Number.isNaN(q)&&r[S].every(_=>!Number.isNaN(_))&&(i===void 0||!Number.isNaN(i[S]))),a=r.filter((q,S)=>l[S]).map(q=>n?[1,...q]:q),f=s.filter((q,S)=>l[S]),c=i?.filter((q,S)=>l[S]);if(f.length===0)throw new RangeError("0 (non-NA) cases");let m=f.map((q,S)=>c===void 0||c[S]!==0),u=a.filter((q,S)=>m[S]),h=f.filter((q,S)=>m[S]),p=c?.filter((q,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((q,S)=>q.map(_=>_*d[S])),w=d===void 0?h:h.map((q,S)=>q*d[S]),g=ke(b),N=g.rank,y=Ie(g,w),x=Se(g,w),E=d===void 0?x:x.map((q,S)=>q/d[S]),R=[],k=[],v=0;f.forEach((q,S)=>{if(m[S])R.push(E[v]),k.push(q-E[v]),v++;else{let _=a[S].reduce((yt,ln,pe)=>Number.isNaN(y[pe])?yt:yt+ln*y[pe],0);k.push(_),R.push(q-_)}});let T=k.filter((q,S)=>m[S]),I=M-N,A=p??new Array(M).fill(1),L=0;for(let q=0;q<M;q++)L+=A[q]*E[q]**2;let j=L/I,O=Math.sqrt(j),H=g.qr.slice(0,N).map(q=>q.slice(0,N)),z=N>0?Ve(H):[],$=g.pivot.slice(0,N).map((q,S)=>[q,S]).sort((q,S)=>q[0]-S[0]),B=$.map(([q])=>y[q]),nt=$.map(([,q])=>Math.sqrt(z[q][q]*j)),rt=B.map((q,S)=>q/nt[S]),dt=rt.map(q=>2*Y(-Math.abs(q),I,!0,!1)),ot={coefficients:y,residuals:R,fittedValues:k,rank:N,dfResidual:I,coefTable:{estimate:B,stdError:nt,tValue:rt,pValue:dt},sigma:O,rSquared:0,adjRSquared:0,intercept:n,qr:g},ue=n?1:0,Mt=N-ue;if(Mt===0)return ot;let gt=0;if(n){let q=A.reduce((_,yt)=>_+yt,0),S=0;for(let _=0;_<M;_++)S+=A[_]*T[_]/q;for(let _=0;_<M;_++)gt+=A[_]*(T[_]-S)**2}else for(let q=0;q<M;q++)gt+=A[q]*T[q]**2;ot.rSquared=gt/(gt+L),ot.adjRSquared=1-(1-ot.rSquared)*((M-ue)/I);let he=gt/Mt/j;return ot.fStatistic={value:he,numdf:Mt,dendf:I},ot.fPValue=G(he,Mt,I,!1,!1),ot}function Tr(e,t={}){let o=t.level??.95,n=it((1+o)/2,e.dfResidual,!0,!1),{estimate:r,stdError:s}=e.coefTable,i=e.coefficients.map(()=>NaN),l=e.coefficients.map(()=>NaN),a=0;return e.coefficients.forEach((f,c)=>{Number.isNaN(f)||(i[c]=r[a]-n*s[a],l[c]=r[a]+n*s[a],a++)}),{lower:i,upper:l}}function kr(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,i=e.qr.pivot.slice(0,s),l=e.qr.qr.slice(0,s).map(p=>p.slice(0,s)),a=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[i[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)*a)}),m=o.interval??"none";if(m==="none")return{fit:f,seFit:c};let u=it((1+(o.level??.95))/2,e.dfResidual,!0,!1),h=c.map(p=>u*Math.sqrt(p*p+(m==="prediction"?a:0)));return{fit:f,seFit:c,lwr:f.map((p,M)=>p-h[M]),upr:f.map((p,M)=>p+h[M])}}export{Ar as TukeyHSD,pr as ansariTest,Er as aov,Hn as bartlettTest,Zt as binomTest,mn as chisqTest,Tr as confint,cn as corTest,wn as fisherTest,Kn as flignerTest,Bn as friedmanTest,Wn as kruskalTest,Mr as ksTest,qr as lm,lr as mantelhaenTest,zn as mcnemarTest,Un as moodTest,or as onewayTest,Yt as pAdjust,xr as pairwisePropTest,yr as pairwiseTTest,vr as pairwiseWilcoxTest,On as poissonTest,kr as predict,Jt as propTest,Dn as quadeTest,sr as shapiroTest,Ht as tTest,$n as varTest,Xt as wilcoxTest,Rr as zTest};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@numero-uno-jpn/rstats",
3
- "version": "0.7.0",
3
+ "version": "0.8.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.7.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 v,b as I,c as F,d as L,e as S,f as O,g as Q,h as Bt,i as Yn,j as qt,s as nt,t as bt}from"./chunk-PTPPP4TI.js";import{a as j,b as R,c as gt}from"./chunk-YKN6OGJL.js";import{C as P,D as Zn,a as kt,e as b,g as pt,h as C,j as nn,l as Xn,n as Y,o as wt,p as Ct,q as St,s as T,t as at,u as w,y as $n,z as U}from"./chunk-ANYGLFT4.js";import{b as D,c as $,d as x,e as tt,f as Vn,g as W,h as tn,i as _,j as dt,k as G}from"./chunk-ZW52Z3GY.js";function ge(n,t){let r=[.213623493715853,4.28342155967104,11.6616720288968,3.31125922108741],e=[.03611708101884203,1.27364489782223,6.40691597760039,6.61053765625462,1],i=n<.5?Math.sqrt(-2*Math.log(n)):Math.sqrt(-2*Math.log(t)),o=i-kt(i,r)/kt(i,e);return n<.5?-o:o}function be(n,t,r,e){let i=1;if(r>=1){let o=t/(n+1);i+=o;for(let u=2;u<=r&&(o*=t/(n+u),i+=o,!(o<e));++u);}return i}function Tn(n,t){let r=(n-1)*Math.log(t),e=r*r,i=e*r,o=e*e,u=n*n,s=u*n,f=(n-1)*(1+r),a=(n-1)*(-(e/2)+(n-2)*r+(3*n-5)/2),c=(n-1)*(i/3-(3*n-5)*e/2+(u-6*n+7)*r+(11*u-46*n+47)/6),l=(n-1)*(-(o/4)+(11*n-17)*i/6+(-3*u+13*n-13)*e+(2*s-25*u+72*n-61)*r/2+(25*s-195*u+477*n-379)/12),N=t*t,h=N*t,m=N*N;return t+r+f/t+a/N+c/h+l/m}function rn(n,t,r){if(n===1)return r>.9?-Math.log1p(-t):-Math.log(r);if(n<1){let M=Xn(n),p=r*M;if(p>.6||p>=.45&&n>=.3){let d=p*r>1e-8&&r>1e-5?Math.pow(t*M*n,1/n):Math.exp(-r/n-nn);return d/(1-d/(n+1))}if(n<.3&&p>=.35){let d=Math.exp(-nn-p),y=d*Math.exp(d);return d*Math.exp(y)}if(p>.15||n>=.3){let d=-Math.log(p),y=d-(1-n)*Math.log(d);return d-(1-n)*Math.log(y)-Math.log(1+(1-n)/(1+y))}if(p>.1){let d=-Math.log(p),y=d-(1-n)*Math.log(d);return d-(1-n)*Math.log(y)-Math.log((y*y+2*(3-n)*y+(2-n)*(3-n))/(y*y+(5-n)*y+2))}return Tn(n,-Math.log(p))}let e=ge(t,r),i=e*e,o=i*e,u=i*i,s=u*e,f=Math.sqrt(n),a=n+e*f+(i-1)/3;if(a+=(o-7*e)/(36*f),a-=(3*u+7*i-16)/(810*n),a+=(9*s+256*o-433*e)/(38880*n*f),n>=500&&Math.abs(1-a/n)<1e-6)return a;if(t>.5){if(a<3*n)return a;let M=Math.max(2,n*(n-1)),p=Math.log(r)+Y(n);if(p<-M*2.3)return Tn(n,-p);let d=-p+(n-1)*Math.log(a)-Math.log(1+(1-n)/(1+a));return-p+(n-1)*Math.log(d)-Math.log(1+(1-n)/(1+d))}let c=a,l=n+1,N=n+2;if(a<.15*l){let M=Math.log(t)+Y(l);c=Math.exp((M+a)/n),e=Math.log1p(c/l*(1+c/N)),c=Math.exp((M+c-e)/n),e=Math.log1p(c/l*(1+c/N)),c=Math.exp((M+c-e)/n),e=Math.log1p(c/l*(1+c/N*(1+c/(n+3)))),c=Math.exp((M+c-e)/n)}if(c<=.01*l||c>.7*l)return c;let h=Math.log(be(n,c,100,1e-4)),m=Math.log(t)+Y(l);return c=Math.exp((m+c-h)/n),c*(1-(n*Math.log(c)-c-m+h)/(n-c))}function en(n){let{rate:t,scale:r}=n;if(t!==void 0&&r!==void 0){if(Math.abs(t*r-1)>=1e-15)throw new RangeError("rate and scale can both be given only when scale = 1 / rate");return r}return r!==void 0?r:t!==void 0?1/t:1}function ye(n,t){if(t<1){let r=w(t,n,!0),e=t/n;return r+(Number.isFinite(e)?Math.log(e):Math.log(t)-Math.log(n))}return w(t-1,n,!0)}function ct(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<=0)return NaN;if(n<0)return F(e);if(t===0)return n===0?1/0:F(e);if(n===0)return t<1?1/0:t>1?F(e):e?-Math.log(r):1/r;if(t<1){let o=w(t,n/r,e);if(e){let u=t/n;return o+(Number.isFinite(u)?Math.log(u):Math.log(t)-Math.log(n))}return o*t/n}let i=w(t-1,n/r,e);return e?i-Math.log(r):i/r}function Wt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<=0)return NaN;let o=n/r;return Number.isNaN(o)?o:t===0?o<=0?v(e,i):I(e,i):o<=0?v(e,i):U(t,o,e,i)}function Ie(n,t,r,e){let{lower:i,logTarget:o,linearTarget:u}=S(n,r,e),s=U(t,Number.MIN_VALUE,i,!0);if(i?s>=o:s<=o)return 0;let f;if(t>1&&o<=-700){let a=C(o,{lowerTail:i,logP:!0}),c=1-1/(9*t)+a/Math.sqrt(9*t);f=c>0?t*c*c*c:t*.001}else if(o>-700){let a=Math.exp(o),c=-Math.expm1(o);f=i?rn(t,a,c):rn(t,c,a)}else if(i)f=Math.exp((o+wt(t))/t);else{f=-o;for(let a=0;a<3;a++)f=-o-Y(t)+(t-1)*Math.log(f)}return O({logTarget:o,...u!==void 0&&{linearTarget:u},lower:i,cdf:(a,c)=>U(t,a,c,!1),cdfLog:(a,c)=>U(t,a,c,!0),cdfBoth:(a,c)=>$n(t,a,c),pdfLog:a=>ye(a,t),dlogPdf:a=>(t-1)/a-1,x0:f,lo:0,hi:1/0,positive:!0})}function rt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=L(n,0,1/0,e,i);return o!==void 0?o:t<0||r<=0?NaN:t===0?0:Ie(n,t,e,i)*r}function eo(n,t,r={}){let e=en(r),i=r.log??!1;return b(n,o=>ct(o,t,e,i))}function io(n,t,r={}){let e=en(r),{lowerTail:i=!0,logP:o=!1}=r;return b(n,u=>Wt(u,t,e,i,o))}function oo(n,t,r={}){let e=en(r),{lowerTail:i=!0,logP:o=!1}=r;return b(n,u=>rt(u,t,e,i,o))}var yt=8*Number.EPSILON,Pn=2*Number.EPSILON,ve=1e-290;function K(n){let{p:t,lowerTail:r,logP:e,cdf:i,lo:o,hi:u}=n,s;if(e||t<ve){let l;e?l=r?t*(1+Pn):t*(1-Pn):l=Math.log(t)+Math.log1p(r?-yt:yt),s=r?N=>i(N,!0,!0)>=l:N=>i(N,!1,!0)<=l}else{let l;if(r?l=t*(1-yt):l=1-t>4*yt?t*(1+yt):t,l>.5){let N=1-l;s=r?h=>i(h,!1,!1)<=N:h=>i(h,!0,!1)>=N}else s=r?N=>i(N,!0,!1)>=l:N=>i(N,!1,!1)<=l}let f=Math.round(n.y0);if(Number.isFinite(f)||(f=o),f=Math.min(Math.max(f,o),u),s(f)){let l=1,N=f-l;for(;N>=o&&s(N);)f=N,l*=2,N=f-l;if(N<o){if(f===o)return o;N=o-1}return Jn(N,f,s)}let a=1,c=f+a;for(;c<=u&&!s(c);)f=c,a*=2,c=f+a;return c>u&&(c=u),Jn(f,c,s)}function Jn(n,t,r){for(;t-n>1;){let e=Math.floor(n+(t-n)/2);if(e===n||e===t)break;r(e)?t=e:n=e}return t}var Ot=j;function Fe(n,t,r){return Number.isNaN(n)||Number.isNaN(t)?NaN:t<0?NaN:Ot(n)?F(r):n<0||!Number.isFinite(n)?F(r):w(Math.round(n),t,r)}function xe(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t<0)return NaN;if(n<0)return v(r,e);if(t===0)return I(r,e);if(!Number.isFinite(n))return I(r,e);let i=Math.floor(n+1e-7);return U(i+1,t,!r,e)}function Le(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(!Number.isFinite(t)||t<0)return NaN;let i=L(n,0,1/0,r,e);if(i!==void 0)return t===0&&!Number.isNaN(i)?0:i;if(t===0)return 0;let o=Math.sqrt(t),u=C(n,{lowerTail:r,logP:e}),s=t+o*(u+(u*u-1)/(6*o));return K({p:n,lowerTail:r,logP:e,cdf:(f,a,c)=>U(f+1,t,!a,c),y0:Number.isFinite(s)?s:t,lo:0,hi:1/0})}function Mo(n,t,r={}){let e=r.log??!1;return b(n,i=>Fe(i,t,e))}function po(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return b(n,o=>xe(o,t,e,i))}function go(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return b(n,o=>Le(o,t,e,i))}var Ee=1e-17,_e=Math.log(Ee),zn=2e7,un=500,on=2**un,It=2**-un,Ae=2**250,De=2**-250,sn=un*Math.LN2,Lt={h:0,l:0,k:0};function Z(n,t,r,e=!1){if(n===0)return Lt;if(!Number.isFinite(n))return{h:n,l:0,k:r};for(;Math.abs(n)>Ae;)n*=It,t*=It,r++;for(;Math.abs(n)<De;)n*=on,t*=on,r--;return e?{h:n,l:t,k:r,approx:e}:{h:n,l:t,k:r}}var Re=[346.5735902799727,-22599635089223323e-30];function Ht(n,t){if(n>1e-305||Number.isNaN(n))return Z(n,0,0);let r=t(),[e,i]=typeof r=="number"?[r,0]:r;if(e===-1/0)return Lt;if(Number.isNaN(e))return{h:NaN,l:0,k:0};let o=Math.round(e/sn),u=x([e,i],W(Re,[-o,0])),s=Math.exp(u[0]);return typeof r=="number"?Z(s,0,o,!0):Z(s,s*u[1],o)}function fn(n,t){if(n===0)return[-t,0];let r=22250738585072014e-324;if(n<=t*r||t<n*r||!Number.isFinite(n))return x(W(G([t,0]),[n,0]),[-t-wt(n),0]);let e=x(St(n,[t,0]),[Ct(n),0]);return x([-e[0],-e[1]],[-.5*(we+Math.log(n)),0])}var we=1.8378770664093456;function J(n,t){return n.approx===!0&&Ft(n)>-700?t():n}function et(n,t){return vt(n,Z(t[0],t[1],0))}function Ce(n,t){if(n.h===0)return Lt;let r=Z(t[0],t[1],0),e=_([n.h,n.l],[r.h,r.l]);return Z(e[0],e[1],n.k-r.k,n.approx)}function kn(n,t,r){let e=et(n,t.ratio(r));return t.ratioK?{...e,k:e.k+t.ratioK}:e}function tr(n,t,r){let e=Ce(n,t.ratio(r));return t.ratioK?{...e,k:e.k-t.ratioK}:e}function vt(n,t){if(n.h===0||t.h===0)return Lt;let r=W([n.h,n.l],[t.h,t.l]);return Z(r[0],r[1],n.k+t.k,n.approx===!0||t.approx===!0)}function Ut(n,t,r,e){for(let i=r;i<e&&n!==0;i++)n*=It,t*=It;return[n,t]}function nr(n,t){if(n.h===0)return t;if(t.h===0)return n;let r=Math.max(n.k,t.k),e=x(Ut(n.h,n.l,n.k,r),Ut(t.h,t.l,t.k,r));return Z(e[0],e[1],r)}function Ft(n){return n.h===0?-1/0:Math.log(n.h)+n.l/n.h+n.k*sn}var xt=class{s=0;c=0;k=0;add(t){if(t.h===0)return;if(this.s===0&&this.c===0){this.s=t.h,this.c=t.l,this.k=t.k;return}t.k>this.k&&([this.s,this.c]=Ut(this.s,this.c,this.k,t.k),this.k=t.k);let[r,e]=Ut(t.h,t.l,t.k,this.k);this.addNum(r),this.addNum(e)}addNum(t){let r=this.s+t;Math.abs(this.s)>=Math.abs(t)?this.c+=this.s-r+t:this.c+=t-r+this.s,this.s=r}get log(){let t=this.s+this.c;return Number.isNaN(t)?NaN:t>0?Math.log(t)+this.k*sn:-1/0}get linear(){let t=this.s+this.c;for(let r=0;r<this.k;r++)t*=on;for(let r=0;r>this.k&&t!==0;r--)t*=It;return t}value(t){return t?this.log:this.linear}divideBy(t){let r=Z(t,0,0);this.s/=r.h,this.c/=r.h,this.k-=r.k}};function Se(n){let t=Math.floor(n),r=1;for(;;){if(r*=n/(t+1),r/(1-n/(t+2))<3e-21)return t;t++}}function Be(n){let t=Math.floor(n),r=1;for(;t>0;){if(r*=t/n,r/(1-(t-1)/n)<3e-21)return t;t--}return 0}function jt(n,t,r){if(r===-1/0||!(n<t))return!1;let e=n-t;return n+e-Math.log(-Math.expm1(e))<=_e+r}function it(n,t){return Ht(w(n,t,!1),()=>fn(n,t))}function H(n,t){return Ht(n.inc(t,!1),()=>n.incLogDD?n.incLogDD(t):n.inc(t,!0))}function lt(n,t,r,e){return(r?sr(n,t):fr(n,t)).value(e)}function rr(n,t,r){let e=r?sr(n,t):fr(n,t);return{lin:e.linear,log:e.log}}function er(n,t,r,e){return w(r,t,!0)+n.cdf(r,e,!0)}function ir(n,t,r){for(;r-t>2;){let i=Math.floor(t+(r-t)/3),o=Math.ceil(r-(r-t)/3);n(i)<n(o)?t=i:r=o}let e=t;for(let i=t+1;i<=r;i++)n(i)>n(e)&&(e=i);return e}var qe=60;function or(n,t,r,e){let i=n(t)-qe;for(let o=1;;o*=2){let u=t+r*o;if(r>0?u>=e:u<=e)return e;if(n(u)<i)return u}}var ur=3e3;function sr(n,t){let r=Se(n);if(r>ur){let f=a=>er(t,n,a,!0);r=or(f,ir(f,0,r),1,r)}let e=Ht(t.cdf(r,!0,!1),()=>t.cdf(r,!0,!0)),i=it(r,n),o=r>0?H(t,r-1):Lt,u=new xt,s=-1/0;for(let f=r;f>=0;f--){let a=vt(i,e),c=Ft(a);if(u.add(a),jt(c,s,u.log)||(s=c,f===0))break;e=nr(e,o),i=J(et(i,dt([f,0],n)),()=>it(f-1,n)),f>=2&&(o=o.h===0?H(t,f-2):J(tr(o,t,f-1),()=>H(t,f-2)))}return u}function fr(n,t){let r=Be(n),e=!1;for(;;){let i=Ht(t.cdf(r,!1,!1),()=>t.cdf(r,!1,!0)),o=it(r,n),u=H(t,r),s=new xt,f=-1/0,a=-1;for(let c=r;c<r+zn;c++){let l=vt(o,i),N=Ft(l);if(s.add(l),jt(N,f,s.log)||N===-1/0&&c>n+50&&c>r+50)break;if(!e&&c-r>=ur&&N>=f){let h=d=>er(t,n,d,!1),m=h(c),M=c+1;for(let d=1;h(M)>=m;d*=2)M=c+d;let p=or(h,ir(h,c,M),-1,c);if(e=!0,p>c){a=p;break}}f=N,i=nr(i,u),o=J(et(o,dt([n,0],c+1)),()=>it(c+1,n)),u=u.h===0?H(t,c+1):J(kn(u,t,c+1),()=>H(t,c+1))}if(a<0)return s;r=a}}function Gt(n,t,r,e,i,o){let u=Number.isFinite(e)?Math.max(0,Math.round(e)):0,s=new xt,f=it(u,n),a=H(t,u),c=f,l=a,N=-1/0;for(let h=u;h<u+zn;h++){let m=et(vt(c,l),[r(h),0]),M=Ft(m);if(s.add(m),jt(M,N,s.log)||M===-1/0&&h>n+50&&h>u+50)break;N=M,c=J(et(c,dt([n,0],h+1)),()=>it(h+1,n)),l=l.h===0?H(t,h+1):J(kn(l,t,h+1),()=>H(t,h+1))}c=f,l=a,N=-1/0;for(let h=u-1;h>=0;h--){c=J(et(c,dt([h+1,0],n)),()=>it(h,n)),l=l.h===0?H(t,h):J(tr(l,t,h+1),()=>H(t,h));let m=et(vt(c,l),[r(h),0]),M=Ft(m);if(s.add(m),jt(M,N,s.log))break;N=M}return s.divideBy(i),s.value(o)}function We(n){return n<=.5?[[n,0],D(1,-n)]:[D(1,-(1-n)),[1-n,0]]}function hr(n,t,r,e){let[i,o]=We(n),{e:u,logDenom:s}=at(t,r,i,o),f=x(tt(x(G(i),G(o))),[Math.log(t*r/(t+r))-.5*s,0]),a=x(tt(u),f);return e?a[0]+a[1]:Math.exp(a[0])*(1+a[1])}function Oe(n,t,r,e){return hr(n,r,e,!0)}function an(n,t,r,e){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<0||r<0?NaN:n<0||n>1?F(e):t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)?t===0&&r===0?n===0||n===1?1/0:F(e):t===0||r/t===1/0?n===0?1/0:F(e):r===0||t/r===1/0?n===1?1/0:F(e):n===.5?1/0:F(e):n===0?t>1?F(e):t<1?1/0:e?Math.log(r):r:n===1?r>1?F(e):r<1?1/0:e?Math.log(t):t:hr(n,t,r,e)}function cn(n,t,r,e,i){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<0||r<0?NaN:n>=1?I(e,i):t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)?t===0&&r===0?i?-Math.LN2:.5:t===0||r/t===1/0?I(e,i):r===0||t/r===1/0?v(e,i):n<.5?v(e,i):I(e,i):n<=0?v(e,i):Q(t,r,n,1-n,e,i)}function ln(n,t,r,e){if(!(n>1&&t>1))return;let i=C(e,{logP:!0}),o=r?-i:i,u=1/(2*n-1),s=1/(2*t-1),f=2/(u+s),a=(o*o-3)/6;if(!(f+a>0))return;let c=o*Math.sqrt(f+a)/f-(s-u)*(a+5/6-2/(3*f)),l=n/(n+t*Math.exp(2*c));return l>0&&l<1?l:void 0}function ar(n,t,r,e,i){let o=Q(n,t,Number.MIN_VALUE,1,r,!0);if(r?o>=e:o<=e)return 0;let u=.25,s=1/0;if(r){let f=(e+Math.log(n)+P(n,t))/n;s=Math.exp(Math.max(f,-745)),u=Math.min(s,.25)}if(!(s<.001)){let f=ln(n,t,r,e);f!==void 0&&f<.5&&(u=f)}return O({logTarget:e,...i!==void 0&&{linearTarget:i},lower:r,cdf:(f,a)=>Q(n,t,f,1-f,a,!1),cdfLog:(f,a)=>Q(n,t,f,1-f,a,!0),cdfBoth:(f,a)=>qt(n,t,f,1-f,a),pdfLog:f=>Oe(f,1-f,n,t),dlogPdf:f=>(n-1)/f-(t-1)/(1-f),x0:u,lo:0,hi:.5,positive:!0})}function Qt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<0)return NaN;let o=L(n,0,1,e,i);if(o!==void 0)return o;if(t===0||r===0||!Number.isFinite(t)||!Number.isFinite(r)){if(t===0&&r===0){let l=i?n:Math.log(n),N=e?l:Math.log1p(-Math.exp(l));return N<-Math.LN2?0:N>-Math.LN2?1:.5}return t===0||r/t===1/0?0:r===0||t/r===1/0?1:.5}let{lower:u,logTarget:s,linearTarget:f}=S(n,e,i),a=Q(t,r,.5,.5,u,!0);return(u?s<=a:s>=a)?ar(t,r,u,s,f):1-ar(r,t,!u,s,f)}function So(n,t,r,e={}){let{log:i=!1,ncp:o}=e;return o!==void 0?b(n,u=>cr(u,t,r,o,i)):b(n,u=>an(u,t,r,i))}function Bo(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?b(n,s=>lr(s,t,r,u,i,o)):b(n,s=>cn(s,t,r,i,o))}function qo(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?b(n,s=>Nr(s,t,r,u,i,o)):b(n,s=>Qt(s,t,r,i,o))}function Mr(n,t){let r=t<1e-250,e=r?t*2**500:t;return{ratioK:r?-1:0,cdf:(i,o,u)=>U(n+i,t,o,u),inc:(i,o)=>{let[u,s]=mr(n,i,t);return o?w(u,t,!0)+s:w(u,t,!1)*(1+s)},ratio:i=>_([e,0],D(n,i)),incLogDD:i=>{let[o,u]=mr(n,i,t);return x(fn(o,t),[u,0])}}}function mr(n,t,r){let[e,i]=D(n,t);return[e,i===0?0:i*(Math.log(r)-gt(e+1))]}function dr(n,t){return n>=0&&t>=0&&Number.isFinite(n)&&Number.isFinite(t)}function pr(n,t,r,e){let i=r/2;if(i*(n/2)>1e18){let s=Ue(n,t,r);return e?{lin:-Math.expm1(s),log:Math.log1p(-Math.exp(s))}:{lin:Math.exp(s),log:s}}let o=Mr(t/2,Math.max(n/2,Number.MIN_VALUE)),u=rr(i,o,e);if(u.lin>.5){let s;return{lin:u.lin,get log(){return s??=Math.log1p(-lt(i,o,!e,!1)),s}}}return u}function Ue(n,t,r){let e=.5-Math.sqrt(r/n)/2-(t-3)/(4*n);return br(n,t,r,!0)-Math.log(e)}function Nn(n,t,r,e,i){let o=pr(n,t,r,e);return i?o.log:o.lin}function je(n,t){let r=NaN,e=!0,i={lin:NaN,log:NaN};return(o,u)=>((o!==r||u!==e)&&(i=pr(o,n,t,u),r=o,e=u),i)}function gr(n,t,r,e){let i=t/2,o=n/2,u=r/2,s=(-(i-1)+Math.sqrt((i-1)*(i-1)+4*u*o))/2;return u*o>1e18?br(n,t,r,e):Gt(u,Mr(i,o),f=>i+f,s,n,e)}function br(n,t,r,e){let i=t/2-1,o=Math.sqrt(r*n),u=4*i*i,s=1,f=1;for(let l=1;l<30&&(s*=-(u-(2*l-1)*(2*l-1))/(8*l*o),f+=s,!(Math.abs(s)<1e-17*Math.abs(f)));l++);let a=Math.sqrt(n)-Math.sqrt(r),c=-Math.LN2-a*a/2+i/2*Math.log(n/r)-.5*Math.log(2*Math.PI*o)+Math.log(f);return e?c:Math.exp(c)}function yr(n,t,r,e){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:dr(t,r)?r===0?ct(n,t/2,2,e):n<0||n===1/0?e?-1/0:0:n===0?t<2?1/0:t===2?e?-r/2-Math.LN2:Math.exp(-r/2)/2:e?-1/0:0:gr(n,t,r,e):NaN}function Ir(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!dr(t,r))return NaN;if(n<0)return v(e,i);if(n===0){if(t>0)return v(e,i);let o=-r/2;return e?i?o:Math.exp(o):i?o<-Math.LN2?Math.log1p(-Math.exp(o)):Math.log(-Math.expm1(o)):-Math.expm1(o)}return r===0?n===1/0?I(e,i):U(t/2,Math.max(n/2,Number.MIN_VALUE),e,i):n===1/0?I(e,i):Nn(n,t,r,e,i)}function vr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!(t>=0&&r>=0&&Number.isFinite(t)))return NaN;let o=L(n,0,1/0,e,i);if(o!==void 0)return o;if(!Number.isFinite(r))return i&&Math.exp(n)===1?e?1/0:0:NaN;if(r===0)return rt(n,t/2,2,e,i);let{lower:u,logTarget:s,linearTarget:f}=S(n,e,i),a=je(t,r),c=Nn(Number.MIN_VALUE,t,r,u,!0);if(u?c>=s:c<=s)return 0;let l=(t+2*r)/(t+r),N=(t+r)*(t+r)/(t+2*r),h=l*rt(s,N/2,2,u,!0);(!(h>0)||!Number.isFinite(h))&&(h=t+r);let m=Math.max(h,t+r,1);for(let M=0;M<2e3;M++){let p=Nn(m,t,r,u,!0);if(u?p>=s:p<=s)break;m*=2}return O({logTarget:s,...f!==void 0&&{linearTarget:f},lower:u,cdf:(M,p)=>a(M,p).lin,cdfLog:(M,p)=>a(M,p).log,pdfLog:M=>gr(M,t,r,!0),x0:Math.min(h,m),lo:0,hi:m,positive:!0})}function xr(n,t,r,e){let i=D(n,t),o=r[0]<1e-250,u=o?[r[0]*2**500,r[1]*2**500]:r;return{ratioK:o?-1:0,cdf:(s,f,a)=>Bt(n+s,t,r,e,f,a),inc:(s,f)=>{let[a,c]=Fr(n,t,s,r),l=t/(a+t);return f?T(a,t,r,e,!0)+Math.log(l)+c:T(a,t,r,e,!1)*l*(1+c)},ratio:s=>_(W(u,x(i,[s-1,0])),D(n,s)),incLogDD:s=>{let[f,a]=Fr(n,t,s,r);if(!(r[0]>1e-305&&e[0]>1e-305)){let N=He(f,t,r,e);return typeof N=="number"?N+a:x(N,[a,0])}let{e:c,logDenom:l}=at(f,t,r,e);return x([-c[0],-c[1]],[-.5*l+Math.log(t/(f+t))+a,0])}}}function Fr(n,t,r,e){let[i,o]=D(n,r);return o===0?[i,0]:[i,o*(Math.log(e[0])+e[1]/e[0]+gt(i+t)-gt(i+1))]}function He(n,t,r,e){if(!(r[0]>0&&e[0]>0))return-1/0;let i=x(tn(G(r),n),tn(G(e),t));return x(x(i,tt(Zn(n,t))),[-Math.log(n),0])}function mn(n){return n<=.5?[[n,0],D(1,-n)]:[D(1,-(1-n)),[1-n,0]]}function Mn(n,t,r,e,i,o,u){let s=xr(n,t,e,i),f=r/2,a=lt(f,s,o,!1);return u?a>.5?Math.log1p(-lt(f,s,!o,!1)):a>=1e-280?Math.log(a):lt(f,s,o,!0):a}function Lr(n,t,r,e,i,o,u){let s=r/2,f=e[0],a=s*f,c=n-1-a,l=(-c+Math.sqrt(Math.max(0,c*c+4*a*(n+t-1))))/2;return Gt(s,xr(n,t,e,i),N=>n+N,l,o,u)}function dn(n,t,r){return n>0&&t>0&&Number.isFinite(n)&&Number.isFinite(t)&&r>=0&&Number.isFinite(r)}function Er(n,t,r,e,i){let[o,u]=mn(n),s=W(o,u);return Lr(t,r,e,o,u,s[0]+s[1],i)}function cr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!dn(t,r,e))return NaN;if(e===0)return an(n,t,r,i);if(n<0||n>1)return i?-1/0:0;let o=e/2;return n===0?t>1?i?-1/0:0:t<1?1/0:i?Math.log(r)-o:r*Math.exp(-o):n===1?r>1?i?-1/0:0:r<1?1/0:i?Math.log(t+o):t+o:Er(n,t,r,e,i)}function lr(n,t,r,e,i,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(n<=0)return v(i,o);if(n>=1)return I(i,o);if(!dn(t,r,e))return NaN;if(e===0)return cn(n,t,r,i,o);let[u,s]=mn(n);return Mn(t,r,e,u,s,i,o)}function Nr(n,t,r,e,i,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!(t>0&&r>0&&e>=0))return NaN;let u=L(n,0,1,i,o);if(u!==void 0)return u;if(!dn(t,r,e))return NaN;if(e===0)return Qt(n,t,r,i,o);let{lower:s,logTarget:f,linearTarget:a}=S(n,i,o),c=(m,M,p)=>{let[d,y]=mn(m);return Mn(t,r,e,d,y,M,p)},l=c(Number.MIN_VALUE,s,!0);if(s?l>=f:l<=f)return 0;let N=c(1-Number.EPSILON/2,s,!0);if(s?N<f:N>f)return 1;let h=Qt(f,t+e/2,r,s,!0);return h>0&&h<1||(h=.5),O({logTarget:f,...a!==void 0&&{linearTarget:a},lower:s,cdf:(m,M)=>c(m,M,!1),cdfLog:(m,M)=>c(m,M,!0),pdfLog:m=>Er(m,t,r,e,!0),x0:h,lo:0,hi:1,positive:!0})}function _r(n,t,r){let e=$(t,n);if(Number.isFinite(e[0])&&Number.isFinite(e[1])&&Math.abs(e[0])<1e290){let o=x(e,[r,0]);return[_(e,o),_([r,0],o)]}let i=r/t/n;return[D(1,-i),[i,0]]}function Ar(n,t,r,e,i){if(t/r*n<1e-306){let s=t/2,f=-e/2+s*(Math.log(t/r)+Math.log(n))-P(s,r/2)-Math.log(n);return i?f:Math.exp(f)}let[o,u]=_r(n,t,r);return Lr(t/2,r/2,e,o,u,n,i)}function Dr(n,t,r,e,i,o){let u=t/2,s=-e/2+u*(Math.log(t/r)+Math.log(n))-Math.log(u)-P(u,r/2);return i?o?s:Math.exp(s):o?-Math.exp(s):-Math.expm1(s)}function Et(n,t,r,e,i,o){if(t/r*n<1e-306)return Dr(n,t,r,e,i,o);let[u,s]=_r(n,t,r);return Mn(t/2,r/2,e,u,s,i,o)}function Rr(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!(t>0&&r>0&&e>=0))return NaN;if(n<0)return i?-1/0:0;if(!Number.isFinite(e))return NaN;if(t===1/0)return r===1/0?n===1?1/0:i?-1/0:0:n===0?NaN:Kt(n,t,r,i);if(r===1/0){let o=yr(n*t,t,e,i);return i?o+Math.log(t):o*t}return n===1/0?NaN:n===0?t<2?1/0:t>2?i?-1/0:0:i?-e/2:Math.exp(-e/2):e===0?Kt(n,t,r,i):Ar(n,t,r,e,i)}function wr(n,t,r,e,i,o){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e)?NaN:!(t>0&&r>0&&e>=0)||!Number.isFinite(e)?NaN:t===1/0&&r===1/0?NaN:n<=0?v(i,o):n===1/0?I(i,o):t===1/0?NaN:r===1/0?Ir(n*t,t,e,i,o):t/r*n<1e-306?Dr(n,t,r,e,i,o):e===0?hn(n,t,r,i,o):Et(n,t,r,e,i,o)}function Cr(n,t,r,e,i,o){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)||Number.isNaN(e))return NaN;if(!(t>0&&r>0&&e>=0)||!Number.isFinite(e))return NaN;let u=L(n,0,1/0,i,o);return u!==void 0?u:t===1/0?NaN:r===1/0?vr(n,t,e,i,o)/t:e===0?Vt(n,t,r,i,o):Ge(n,t,r,e,i,o)}function Ge(n,t,r,e,i,o){let{lower:u,logTarget:s,linearTarget:f}=S(n,i,o),a=Et(Number.MIN_VALUE,t,r,e,u,!0);if(u?a>=s:a<=s)return 0;let c=Et(Number.MAX_VALUE,t,r,e,u,!0);if(u?c<s:c>s)return 1/0;let l=(t+e)*(t+e)/(t+2*e),N=(t+e)/t*Vt(s,l,r,u,!0);return(!(N>0)||!Number.isFinite(N))&&(N=1),O({logTarget:s,...f!==void 0&&{linearTarget:f},lower:u,cdf:(h,m)=>Et(h,t,r,e,m,!1),cdfLog:(h,m)=>Et(h,t,r,e,m,!0),pdfLog:h=>Ar(h,t,r,e,!0),x0:N,lo:0,hi:1/0,positive:!0})}function Sr(n,t,r,e){let i=$(t,n),o,u;if(Number.isFinite(i[0])&&Number.isFinite(i[1])&&Math.abs(i[0])<1e290){let l=x(i,[r,0]);o=_(i,l),u=_([r,0],l)}else u=[r/t/n,0],o=[1,-u[0]];let s=o[0],f=u[0];if(t>=2){let l=t*f/2,N=T((t-2)/2,r/2,o,u,e);return e?Math.log(l)+N:l*N}let a=t/(r+t*n)*t*r/(2*(t+r)*s),c=T(t/2,r/2,o,u,e);return e?Math.log(a)+c:a*c}function Kt(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<=0||r<=0)return NaN;if(n<0)return F(e);if(n===0)return t>2?F(e):t===2?e?0:1:1/0;if(!Number.isFinite(t)&&!Number.isFinite(r))return n===1?1/0:F(e);if(!Number.isFinite(r))return ct(n,t/2,2/t,e);if(!Number.isFinite(t)){let i=ct(1/n,r/2,2/r,e);return e?i-2*Math.log(n):i/(n*n)}return Number.isFinite(n)?Sr(n,t,r,e):t<2?NaN:F(e)}function pn(n,t,r,e,i){let o=$(t,n);if(Number.isFinite(o[0])&&Number.isFinite(o[1])&&Math.abs(o[0])<1e290){let s=x(o,[r,0]);return Bt(t/2,r/2,_(o,s),_([r,0],s),e,i)}let u=r/t/n;return Q(t/2,r/2,1-u,u,e,i)}function Qe(n,t,r,e){let i=ln(n/2,t/2,r,e);if(i===void 0)return 1;let o=t*i/(n*(1-i));return o>0&&Number.isFinite(o)?o:1}function Ke(n,t,r,e){let i=$(t,n);if(Number.isFinite(i[0])&&Number.isFinite(i[1])&&Math.abs(i[0])<1e290){let u=x(i,[r,0]);return Yn(t/2,r/2,_(i,u),_([r,0],u),e)}let o=r/t/n;return qt(t/2,r/2,1-o,o,e)}function hn(n,t,r,e,i){return Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r)?NaN:t<=0||r<=0?NaN:n<=0?v(e,i):n===1/0?I(e,i):!Number.isFinite(t)&&!Number.isFinite(r)?n===1?i?-Math.LN2:.5:n<1?v(e,i):I(e,i):Number.isFinite(r)?Number.isFinite(t)?pn(n,t,r,e,i):Wt(r/n,r/2,2,!e,i):Wt(n*t,t/2,2,e,i)}function Vt(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<=0||r<=0)return NaN;let o=L(n,0,1/0,e,i);if(o!==void 0)return o;if(!Number.isFinite(t)&&!Number.isFinite(r))return 1;if(!Number.isFinite(r))return rt(n,t/2,2,e,i)/t;if(!Number.isFinite(t))return r/rt(n,r/2,2,!e,i);let{lower:u,logTarget:s,linearTarget:f}=S(n,e,i);return u&&(s+Math.log(t/2)+P(t/2,r/2))/(t/2)+Math.log(r/t)<-746?0:!u&&-(s+Math.log(r/2)+P(t/2,r/2))/(r/2)+Math.log(r/t)>709.78?1/0:O({logTarget:s,...f!==void 0&&{linearTarget:f},lower:u,cdf:(a,c)=>pn(a,t,r,c,!1),cdfLog:(a,c)=>pn(a,t,r,c,!0),cdfBoth:(a,c)=>Ke(a,t,r,c),pdfLog:a=>Sr(a,t,r,!0),dlogPdf:a=>(t/2-1)/a-(t+r)/2*(t/(r+t*a)),x0:Qe(t,r,u,s),lo:0,hi:1/0,positive:!0})}function mu(n,t,r,e={}){let{log:i=!1,ncp:o}=e;return o!==void 0?b(n,u=>Rr(u,t,r,o,i)):b(n,u=>Kt(u,t,r,i))}function Mu(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?b(n,s=>wr(s,t,r,u,i,o)):b(n,s=>hn(s,t,r,i,o))}function du(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1,ncp:u}=e;return u!==void 0?b(n,s=>Cr(s,t,r,u,i,o)):b(n,s=>Vt(s,t,r,i,o))}function gn(n,t){return Ot(n)||n<0||!Number.isFinite(n)||t<0||t>1}function Ve(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(gn(t,r))return NaN;if(Ot(n)||n<0||!Number.isFinite(n))return F(e);let i=Math.round(n),o=Math.round(t);if(i>o)return F(e);let u=r<=.5?[r,0]:D(1,-(1-r)),s=r<=.5?D(1,-r):[1-r,0];return T(i,o-i,u,s,e)}function Br(n,t,r,e,i){return Q(n+1,t-n,r,1-r,!e,i)}function Xe(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(gn(t,r))return NaN;let o=Math.round(t);if(n<0)return v(e,i);let u=Math.floor(n+1e-7);return o<=u?I(e,i):r===0?I(e,i):r===1?v(e,i):Br(u,o,r,e,i)}function $e(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;if(!Number.isFinite(t)||!Number.isFinite(r)||r<0||r>1||t<0)return NaN;let o=L(n,0,Ze(t),e,i);if(o!==void 0)return o;if(gn(t,r))return NaN;let u=Math.round(t);if(r===0||u===0)return 0;if(r===1)return u;let s=1-r,f=u*r,a=Math.sqrt(u*r*s),c=(s-r)/a,l=C(n,{lowerTail:e,logP:i}),N=f+a*(l+c*(l*l-1)/6);return K({p:n,lowerTail:e,logP:i,cdf:(h,m,M)=>h>=u?I(m,M):Br(h,u,r,m,M),y0:Number.isFinite(N)?N:f,lo:0,hi:u})}function Eu(n,t,r,e={}){let i=e.log??!1;return b(n,o=>Ve(o,t,r,i))}function _u(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return b(n,u=>Xe(u,t,r,i,o))}function Au(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return b(n,u=>$e(u,t,r,i,o))}function Ze(n){let t=Math.round(n);return Math.abs(n%1)===.5&&t%2!==0?t-1:t}function bn(n,t,r,e){if(n===0&&t===0)return{e:[0,0],logDenom:0};if(n===0||t===0){let i=n+t,[o,u]=n===0?[e,r]:[r,e];return{e:u[0]<.1?x(St(i,W([i,0],o)),W([i,0],u)):tt(W([i,0],G(o))),logDenom:0}}return at(n,t,r,e)}function Or(n,t,r,e){let i=t+r,o=_([e,0],[i,0]),u=_([i-e,0],[i,0]),s=bn(n,t-n,o,u),f=bn(e-n,r-e+n,o,u),a=bn(e,i-e,o,u);return{e:Vn(x(s.e,f.e),a.e),logDenom:s.logDenom+f.logDenom-a.logDenom}}function Ur(n,t){let[r,e]=n.e,i=t*Math.exp(-.5*n.logDenom);return r<700?Math.exp(-r)*(1-e)*i:Math.exp(700-r)*(1-e)*i*Math.exp(-700)}function jr(n){return-n.e[0]-n.e[1]-.5*n.logDenom}function Xt(n,t,r){return[Math.max(0,r-t),Math.min(r,n)]}function Ye(n,t,r,e,i){if([n,t,r,e].some(Number.isNaN))return NaN;if(![t,r,e].every(Number.isFinite)||j(t)||j(r)||j(e))return NaN;if(t=R(t),r=R(r),e=R(e),t<0||r<0||e<0||e>t+r)return NaN;if(j(n))return F(i);n=R(n);let[o,u]=Xt(t,r,e);if(n<o||n>u)return F(i);if(e===0||e===t+r)return i?0:1;let s=Or(n,t,r,e);return i?jr(s):Ur(s,1)}function qr(n,t,r,e){return _($(n,t),$(r,e))}function Te(n,t,r,e,i,o,u){let s=[1,0],f=[1,0],a=n;for(;!(i?a<=o:a>=u);){let c=i?qr(a,r-e+a,t-a+1,e-a+1):qr(t-a,e-a,a+1,r-e+a+1);s=W(s,c),f=x(f,s),a+=i?-1:1;let l=c[0];if(l<1&&s[0]*l/(1-l)<f[0]*2**-60)break}return f[0]+f[1]}function Hr(n,t,r,e,i,o){let[u,s]=Xt(t,r,e),f=t+r,a=n*f<e*t,c=Wr(n,t,r,e,a,u,s);if(c.value>.5){let l=Wr(n,t,r,e,!a,u,s);l.value<c.value&&(c=l,a=!a)}return a===i?o?c.value>1e-300?Math.log(c.value):jr(c.form)+Math.log(c.sum):c.value:o?Math.log1p(-c.value):1-c.value}function Wr(n,t,r,e,i,o,u){let s=i?n:n+1,f=Or(s,t,r,e),a=Te(s,t,r,e,i,o,u);return{form:f,sum:a,value:Ur(f,a)}}function Gr(n,t,r){if([n,t,r].every(Number.isFinite)&&(n=R(n),t=R(t),r=R(r),!(n<0||t<0||r<0||r>n+t)))return[n,t,r]}function Pe(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;let u=Gr(t,r,e);if(u===void 0)return NaN;[t,r,e]=u;let s=Math.floor(n+1e-7),[f,a]=Xt(t,r,e);return s<f?v(i,o):s>=a?I(i,o):Hr(s,t,r,e,i,o)}function Je(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;let u=Gr(t,r,e);if(u===void 0)return NaN;[t,r,e]=u;let[s,f]=Xt(t,r,e),a=L(n,s,f,i,o);if(a!==void 0)return a;if(s===f)return s;let c=t+r,l=e*t/c,N=Math.sqrt(e*t/c*(r/c)*(c-e)/Math.max(c-1,1)),h=C(n,{lowerTail:i,logP:o}),m=l+N*h;return K({p:n,lowerTail:i,logP:o,cdf:(M,p,d)=>M<s?v(p,d):M>=f?I(p,d):Hr(M,t,r,e,p,d),y0:Number.isFinite(m)?m:l,lo:s,hi:f})}function Ou(n,t,r,e,i={}){let o=i.log??!1;return b(n,u=>Ye(u,t,r,e,o))}function Uu(n,t,r,e,i={}){let{lowerTail:o=!0,logP:u=!1}=i;return b(n,s=>Pe(s,t,r,e,o,u))}function ju(n,t,r,e,i={}){let{lowerTail:o=!0,logP:u=!1}=i;return b(n,s=>Je(s,t,r,e,o,u))}var ze=2**900,Qr=-900,ot=new Map,ke=2**21,$t=0,ti=2**25;function ni(n,t){if(t+1>ti)throw new RangeError(`signrank: n = ${n} needs too large a table (${t+1} entries)`);let r=new Float64Array(t+1);r[0]=1;let e=0,i=Math.min(n,t);for(let f=1;f<=i;f++){for(let a=t;a>=f;a--)r[a]+=r[a-f];if(r[Math.min(t,Math.floor(f*(f+1)/4))]>ze){let a=2**Qr;for(let c=0;c<=t;c++)r[c]*=a;e-=Qr}}let o=new Float64Array(t+1),u=0,s=0;for(let f=0;f<=t;f++){let a=r[f]-s,c=u+a;s=c-u-a,u=c,o[f]=u}return{n,len:t+1,count:r,cum:o,scale:e}}function yn(n,t){let r=ot.get(n);if(r!==void 0&&r.len>t)return ot.delete(n),ot.set(n,r),r;let e=Math.floor(n*(n+1)/4),i=Math.min(e,Math.max(t,r===void 0?0:2*r.len)),o=ni(n,i);r!==void 0&&(ot.delete(n),$t-=r.len),ot.set(n,o),$t+=o.len;for(let[u,s]of ot){if($t<=ke||u===n)break;ot.delete(u),$t-=s.len}return o}function In(n,t,r){let e=t.scale-t.n,i=Math.trunc(e/2),o=n*2**i*2**(e-i);return r?o>=1e-300?Math.log(o):Math.log(n)+e*Math.LN2:o}function vn(n){return Number.isFinite(n)?(n=R(n),n<=0?NaN:n):NaN}function ri(n,t,r){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=vn(t),Number.isNaN(t))return NaN;if(j(n))return F(r);n=R(n);let e=t*(t+1)/2;if(n<0||n>e)return F(r);let i=Math.min(n,e-n),o=yn(t,i);return In(o.count[i],o,r)}function Kr(n,t,r,e){let i=t*(t+1)/2,o=n,u=i-n-1,s=r?o:u,f=r?u:o;if(s<=f){let l=yn(t,s);return In(l.cum[s],l,e)}let a=yn(t,f),c=In(a.cum[f],a,!1);return e?Math.log1p(-c):1-c}function ei(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=vn(t),Number.isNaN(t))return NaN;let i=R(n+1e-7),o=t*(t+1)/2;return i<0?v(r,e):i>=o?I(r,e):Kr(i,t,r,e)}function ii(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t))return NaN;if(t=vn(t),Number.isNaN(t))return NaN;let i=t*(t+1)/2,o=L(n,0,i,r,e);if(o!==void 0)return o;let u=i/2,s=Math.sqrt(t*(t+1)*(2*t+1)/24),f=u+s*C(n,{lowerTail:r,logP:e});return K({p:n,lowerTail:r,logP:e,cdf:(a,c,l)=>a<0?v(c,l):a>=i?I(c,l):Kr(a,t,c,l),y0:Number.isFinite(f)?f:u,lo:0,hi:i})}function $u(n,t,r={}){let e=r.log??!1;return b(n,i=>ri(i,t,e))}function Zu(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return b(n,o=>ei(o,t,e,i))}function Yu(n,t,r={}){let{lowerTail:e=!0,logP:i=!1}=r;return b(n,o=>ii(o,t,e,i))}var Tt=960,oi=2**25,Zt=134217729,ut=new Map,ui=2**21,Yt=0;function si(n,t,r){if(r+1>oi)throw new RangeError(`wilcox: m = ${n}, n = ${t} needs too large a table (${r+1} entries)`);let e=new Float64Array(r+1),i=new Float64Array(r+1);e[0]=2**Tt;for(let f=1;f<=n;f++){let a=Math.min(r,f*t),c=t+f,l=Zt*f,N=l-(l-f),h=f-N;l=Zt*c;let m=l-(l-c),M=c-m;for(let d=0;d<=a;d++){let y=e[d];if(y===0)continue;let g=y*f;l=Zt*y;let E=l-(l-y),V=y-E,B=E*N-g+E*h+V*N+V*h+i[d]*f,A=g/c,X=A*c;l=Zt*A;let q=l-(l-A),ft=A-q,pe=q*m-X+q*M+ft*m+ft*M,Qn=(g-X-pe+B)/c,Kn=A+Qn;i[d]=Qn-(Kn-A),e[d]=Kn}let p=t+f;for(let d=a;d>=p;d--)Vr(e,i,d,d-p,-1);for(let d=f;d<=a;d++)Vr(e,i,d,d-f,1)}let o=new Float64Array(r+1),u=0,s=0;for(let f=0;f<=r;f++){let a=e[f],c=u+a,l=c-u,N=u-(c-l)+(a-l);N+=s+i[f],u=c+N,s=N-(u-c),o[f]=u}return{m:n,n:t,len:r+1,prob:e,cum:o}}function Vr(n,t,r,e,i){let o=n[r],u=i*n[e],s=o+u,f=s-o,a=o-(s-f)+(u-f);a+=t[r]+i*t[e];let c=s+a;t[r]=a-(c-s),n[r]=c}function Fn(n,t,r){n>t&&([n,t]=[t,n]);let e=`${n},${t}`,i=ut.get(e);if(i!==void 0&&i.len>r)return ut.delete(e),ut.set(e,i),i;let o=Math.floor(n*t/2),u=Math.min(o,Math.max(r,i===void 0?0:2*i.len)),s=si(n,t,u);i!==void 0&&(ut.delete(e),Yt-=i.len),ut.set(e,s),Yt+=s.len;for(let[f,a]of ut){if(Yt<=ui||f===e)break;ut.delete(f),Yt-=a.len}return s}function xn(n,t){let r=n*2**-(Tt/2)*2**-(Tt/2);return t?r>=1e-300?Math.log(r):Math.log(n)-Tt*Math.LN2:r}function Ln(n,t){if(!(!Number.isFinite(n)||!Number.isFinite(t)))return n=R(n),t=R(t),n<=0||t<=0?void 0:[n,t]}function fi(n,t,r,e){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let i=Ln(t,r);if(i===void 0)return NaN;if([t,r]=i,j(n))return F(e);n=R(n);let o=t*r;if(n<0||n>o)return F(e);let u=Math.min(n,o-n);return xn(Fn(t,r,u).prob[u],e)}function Xr(n,t,r,e,i){let o=t*r,u=e?n:o-n-1,s=e?o-n-1:n;if(u<=s)return xn(Fn(t,r,u).cum[u],i);let f=xn(Fn(t,r,s).cum[s],!1);return i?Math.log1p(-f):1-f}function ai(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=Ln(t,r);if(o===void 0)return NaN;[t,r]=o;let u=Math.floor(n+1e-7);return u<0?v(e,i):u>=t*r?I(e,i):Xr(u,t,r,e,i)}function ci(n,t,r,e,i){if(Number.isNaN(n)||Number.isNaN(t)||Number.isNaN(r))return NaN;let o=Ln(t,r);if(o===void 0)return NaN;[t,r]=o;let u=t*r,s=L(n,0,u,e,i);if(s!==void 0)return s;let f=u/2,a=Math.sqrt(u*(t+r+1)/12),c=f+a*C(n,{lowerTail:e,logP:i});return K({p:n,lowerTail:e,logP:i,cdf:(l,N,h)=>l<0?v(N,h):l>=u?I(N,h):Xr(l,t,r,N,h),y0:Number.isFinite(c)?c:f,lo:0,hi:u})}function ns(n,t,r,e={}){let i=e.log??!1;return b(n,o=>fi(o,t,r,i))}function rs(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return b(n,u=>ai(u,t,r,i,o))}function es(n,t,r,e={}){let{lowerTail:i=!0,logP:o=!1}=e;return b(n,u=>ci(u,t,r,i,o))}var k=128,Bn=Number.EPSILON,qn=Float64Array.from({length:2*k+1},(n,t)=>Math.cos(Math.PI*t/k));function li(n){let t=new Float64Array(n+1);for(let r=0;r<=n;r++){let e=0;for(let i=0;i<=n;i+=2)e+=(i===0||i===n?.5:1)*qn[i*r%(2*n)*(k/n)]*2/(1-i*i);t[r]=(r===0||r===n?.5:1)*2*e/n}return t}var Ni=new Map([16,32,64,128].map(n=>[n,li(n)]));function hi(n,t){let r=Ni.get(t),e=k/t,i=0,o=0;for(let s=0;s<=t;s++)i+=r[s]*n[s],o+=Math.abs(r[s]*n[s]);let u=0;for(let s=t-7;s<=t;s++){let f=.5*(n[0]+(s%2===0?n[t]:-n[t]));for(let a=1;a<t;a++)f+=n[a]*qn[s*a%(2*t)*e];f*=2/t,s===t&&(f*=.5),u=Math.max(u,Math.abs(f))}return{integral:i,tail:u,scale:o}}var At=class{f;a;b;c;h;values=new Float64Array(k+1);have=new Uint8Array(k+1);N=0;integral=0;error=1/0;constructor(t,r,e){this.f=t,this.a=r,this.b=e,this.c=.5*(r+e),this.h=.5*(e-r)}advance(t){let r=k/t,e=new Float64Array(t+1);for(let o=0;o<=t;o++){let u=o*r;this.have[u]||(this.values[u]=this.f(this.c+this.h*qn[u]),this.have[u]=1),e[o]=this.values[u]}let i=hi(e,t);this.N=t,this.integral=i.integral*this.h,this.error=Math.max(i.tail*4/t,4*Bn*i.scale)*Math.abs(this.h)}};function Jt(n,t,r){let e=[];for(let o=0;o+1<t.length;o++){let u=new At(n,t[o],t[o+1]);u.advance(16),e.push(u)}for(let o=0;o<40;o++){let u=0;for(let c of e)u+=c.integral;let s=r*Math.abs(u)/e.length,f=!0,a=[];for(let c of e){if(c.error<=s||c.error<=4*Bn*Math.abs(c.integral)){a.push(c);continue}if(f=!1,c.N<k)c.advance(2*c.N),a.push(c);else{let l=new At(n,c.a,c.c),N=new At(n,c.c,c.b);l.advance(16),N.advance(16),a.push(l,N)}}if(e=a,f)break}let i=0;for(let o of e)i+=o.integral;return i}function Zr(n,t,r){let e=Math.max(1,Math.ceil((t-n)/r));return Array.from({length:e+1},(i,o)=>o===e?t:n+(t-n)*o/e)}var Yr=2e-15,Tr=1e-16,mi={lowerTail:!1},Mi={logP:!0},di={lowerTail:!1,logP:!0},Rt=.9189385332046728,zt=n=>pt(n),ht=n=>pt(n,mi),Wn=n=>pt(n,Mi),On=n=>pt(n,di),pi=.3989422804014327;function mt(n){let t=Math.round(n*16)/16,r=n-t;return pi*Math.exp(-.5*t*t)*Math.exp(-.5*r*(n+t))}var An=[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],Pr=[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626];function gi(n,t){let r=n-.5*t,e=.5*t,i=0;for(let o=0;o<4;o++)i+=Pr[o]*(mt(r-e*An[o])+mt(r+e*An[o]));return i*e}function bi(n,t){let r=n-.5*t,e=.5*t,i=0;for(let o=0;o<4;o++){let u=e*An[o];i+=Pr[o]*(Math.exp(r*u-u*u/2)+Math.exp(-r*u-u*u/2))}return-Rt-r*r/2+Math.log(i*e)}var Un=(n,t)=>t*Math.max(1,Math.abs(n),Math.abs(n-t))<.5;function Mt(n,t){let r=n-t,e=r-n,i=n-(r-e)+(-t-e);return{ah:r,al:i}}function Dt(n,t){return zt(n)+mt(n)*t}function yi(n,t){return ht(n)-mt(n)*t}function Jr(n,t){if(Un(n,t))return gi(n,t);let{ah:r,al:e}=Mt(n,t);return r>=0?yi(r,e)-ht(n):n<=0?zt(n)-Dt(r,e):1-Dt(r,e)-ht(n)}function Ii(n,t,r){if(n>0&&n-t<0&&!Un(n,t)){let{ah:i,al:o}=Mt(n,t);return Math.exp(r*Math.log1p(-(Dt(i,o)+ht(n))))}let e=Jr(n,t);return e>0?e**r:0}function vi(n,t){return n>0?Math.exp(t*Math.log1p(-ht(n))):zt(n)**t}function zr(n,t){let{ah:r,al:e}=Mt(n,t),i=Wn(r);return i+e*Math.exp(-Rt-r*r/2-i)}function Fi(n,t){let{ah:r,al:e}=Mt(n,t),i=On(r);return i-e*Math.exp(-Rt-r*r/2-i)}function kr(n,t){if(Un(n,t))return bi(n,t);if(n-t>=0){let o=Fi(n,t);return o+Math.log(-Math.expm1(On(n)-o))}if(n<=0){let o=Wn(n);return o+Math.log(-Math.expm1(zr(n,t)-o))}let{ah:e,al:i}=Mt(n,t);return Math.log1p(-Dt(e,i)-ht(n))}var te=2,En=1e-18;function ne(n,t,r){let e=Zr(t,r,te),i=e.map(n),o=0;for(let N=1;N<i.length;N++)i[N]>i[o]&&(o=N);let u=i[o];if(!(u>0))return 0;let s=Math.max(o-1,0),f=Math.min(o+1,i.length-1);for(;s>0&&i[s]>u*En;)s--;for(;f<i.length-1&&i[f]>u*En;)f++;let a=u*En,c=e[s],l=e[f];if(i[s]<=a){let N=e[s+1];for(let h=0;h<2;h++){let m=.5*(c+N);n(m)<=a?c=m:N=m}}if(i[f]<=a){let N=e[f-1];for(let h=0;h<2;h++){let m=.5*(l+N);n(m)<=a?l=m:N=m}}return Jt(n,[c,l],Tr)}function re(n,t,r){let e=Zr(t,r,te),i=e.map(n),o=0;for(let g=1;g<i.length;g++)i[g]>i[o]&&(o=g);if(!(i[o]>-1/0))return-1/0;let u=e[Math.max(o-1,0)],s=e[Math.min(o+1,e.length-1)],f=(Math.sqrt(5)-1)/2,a=s-f*(s-u),c=u+f*(s-u),l=n(a),N=n(c);for(let g=0;g<80&&s-u>1e-12*Math.max(1,Math.abs(u));g++)l<N?(u=a,a=c,l=N,c=u+f*(s-u),N=n(c)):(s=c,c=a,N=l,a=s-f*(s-u),l=n(a));let h=l>N?a:c,m=Math.max(l,N);i[o]>m&&(h=e[o],m=i[o]);let M=g=>{let E=g<0?t:r,V=Math.max(1e-6,.001*(e[1]-e[0])),B=h;for(;;){let A=h+g*V;if(g<0?A<=E:A>=E)return E;if(n(A)<m-46){let X=A;for(let q=0;q<6;q++){let ft=.5*(B+X);n(ft)<m-46?X=ft:B=ft}return X}B=A,V*=2}},p=M(-1),d=M(1),y=[...new Set([p,h,d])].sort((g,E)=>g-E);return m+Math.log(Jt(g=>Math.exp(n(g)-m),y,Tr))}var jn=-10,Hn=10;function xi(n,t){return n<=0?0:t*ne(r=>mt(r)*Ii(r,n,t-1),jn,Hn)}function ee(n,t){if(n<=0)return 1;let r=o=>{let u=zt(o);if(u===0)return 0;let{ah:s,al:f}=Mt(o,n),a=Dt(s,f),c=a<.5*u?-Math.expm1((t-1)*Math.log1p(-a/u)):-Math.expm1((t-1)*Math.log(Jr(o,n)/u));return mt(o)*vi(o,t-1)*c};if(n>60)return 0;let[e,i]=ie(n);return t*ne(r,e,i)}function ie(n){return n>40?[n/2-15,n/2+15]:[jn,n+Hn]}function oe(n,t){if(n>100)return-Math.exp(ue(n,t));let r=e=>-Rt-e*e/2+(t-1)*kr(e,n);return Math.log(t)+re(r,jn,Hn)}function ue(n,t){if(n>100)return Math.log(t*(t-1))+On(n/Math.SQRT2);let r=o=>{let u=Wn(o),s=zr(o,n)-u,f;return s<-40?f=Math.log(t-1)+s:s<-Math.LN2?f=Math.log(-Math.expm1((t-1)*Math.log1p(-Math.exp(s)))):f=Math.log(-Math.expm1((t-1)*(kr(o,n)-u))),-Rt-o*o/2+(t-1)*u+f},[e,i]=ie(n);return Math.log(t)+re(r,e,i)}function Li(n,t){let r=-1/0;for(let e of t)r=Math.max(r,n(e));for(let e=0;e+1<t.length;e++)r=Math.max(r,n(.5*(t[e]+t[e+1])));if(r===-1/0)return-1/0;for(let e=0;e<4;e++){let i=r,o=Jt(u=>{let s=n(u);return s>i&&(i=s),Math.exp(s-r)},t,Yr);if(Number.isFinite(o)&&i-r<300)return r+Math.log(o);r=i}return NaN}var z=32,Ei=1e-15,Nt=Math.log(.01),Gn=Math.log(20),se=Math.log(40),fe=Float64Array.from({length:2*z+1},(n,t)=>Math.cos(Math.PI*t/z));function _i(n,t){let r=new Float64Array(t+1);for(let e=0;e<=t;e++){let i=.5*(n[0]+(e%2===0?n[t]:-n[t]));for(let o=1;o<t;o++)i+=n[o]*fe[e*o%(2*t)];i*=2/t,(e===0||e===t)&&(i*=.5),r[e]=i}return r}function _n(n,t,r){let e=[],i=[[t,r,0]];for(;i.length>0;){let[o,u,s]=i.pop(),f=.5*(o+u),a=.5*(u-o),c=new Float64Array(z+1),l=1/0;for(let m=0;m<=z;m++)c[m]=n(f+a*fe[m]),l=Math.min(l,Math.max(1,Math.abs(c[m])));let N=_i(c,z),h=0;for(let m=z-3;m<=z;m++)h=Math.max(h,Math.abs(N[m]));h<=Ei*l||s>=14||!c.every(Number.isFinite)?e.push({a:o,b:u,coef:N}):i.push([f,u,s+1],[o,f,s+1])}return e.sort((o,u)=>o.a-u.a)}function Dn(n,t){let r=0,e=n.length-1;for(;r<e;){let c=r+e+1>>1;n[c].a<=t?r=c:e=c-1}let{a:i,b:o,coef:u}=n[r],s=(2*t-i-o)/(o-i),f=0,a=0;for(let c=z;c>=1;c--){let l=2*s*f-a+u[c];a=f,f=l}return s*f-a+u[0]}var _t=new Map,Ai=64,ae=Math.log(1e-10);function ce(n){let t=_t.get(n);if(t!==void 0)return t;let r=i=>{let o=xi(i,n);return o>1e-290?Math.log(o):oe(i,n)},e=i=>{let o=Math.exp(i);return ee(o,n)*le(o)};return t={logW:_n(i=>r(Math.exp(i)),Nt,Gn),scaledWc:_n(e,Nt,se),smallW:_n(i=>r(Math.exp(i))-(n-1)*i,ae,Nt)},_t.size>=Ai&&_t.delete(_t.keys().next().value),_t.set(n,t),t}function le(n){let t=n*n,r=134217729*n,e=r-(r-n),i=n-e,o=e*e-t+2*e*i+i*i;return Math.exp(t/4)*(1+o/4)}function Di(n,t){let r=Math.log(n);if(r>=Gn)return 0;let e=ce(t);return r>=Nt?Dn(e.logW,r):Dn(e.smallW,Math.max(r,ae))+(t-1)*r}function Rn(n,t){return Math.log(n)>=Gn?1:Math.exp(Di(n,t))}function Ri(n,t){let r=Math.log(n);return r>=Nt&&r<=se?Dn(ce(t).scaledWc,r)/le(n):r<Nt?1-Rn(n,t):ee(n,t)}function Pt(n,t,r,e){if(!e){let o=Math.min(Rn(n,t),1);return r===1?o:o**r}let i=Math.min(Ri(n,t),1);return i<=.5?r===1?i:-Math.expm1(r*Math.log1p(-i)):1-Math.min(Rn(n,t),1)**r}function wn(n,t,r,e){if(!e)return r*oe(n,t);let i=ue(n,t);return r===1?i:Math.log(-Math.expm1(r*Math.log1p(-Math.exp(i))))}function Cn(n,t,r,e,i){if(r===1/0)return Pt(n,t,e,i);let o=r/2,u=Math.log(o),s=wi(o);return Jt(a=>{let{d:c,s:l}=s(a);return c===0?0:c*Pt(n*l,t,e,i)},Ne(n,t,r,e,i).map(a=>a-u),Yr)}function wi(n){let t=Ct(n),r=Math.sqrt(n/(2*Math.PI));return e=>{let i;if(Math.abs(e)<.5){let o=e*e/2;i=o;for(let u=3;u<60&&(o*=e/u,i+=o,!(Math.abs(o)<1e-17*i));u++);}else i=Math.expm1(e)-e;return{d:r*Math.exp(-t-n*i),s:Math.exp(.5*e)}}}function Ci(n,t,r,e,i){if(r===1/0)return wn(n,t,e,i);let o=r/2,u=Math.log(o),s=Y(o+1);return Li(a=>{let c=Math.exp(a),l=c>1e-300?w(o,c,!0):o*a-c-s;return u+l+wn(Math.exp(Math.log(n)+.5*(a-u)),t,e,i)},Ne(n,t,r,e,i,!0))}function Ne(n,t,r,e,i,o=!1){let u=r/2,s=u,f=Math.log(u);if(i){let g=2*Math.log(n)-Math.log(4*u);f-=g>30?g:Math.log1p(Math.exp(g))}else s=u+(t-1)*e/2,f=Math.log(s);let a=(g,E)=>[g-9/Math.sqrt(E)-41/E,g+9/Math.sqrt(E)+Math.log1p(41/E)],[c,l]=a(Math.log(u),u),[N,h]=a(f,s),m=o?Math.min(c,N):Math.max(Math.min(c,N),-740),M=Math.max(l,h),p=1/Math.sqrt(u),d=1/Math.sqrt(s),y=[m,Math.min(Math.log(u)-4*p,f-4*d),Math.max(Math.log(u)+4*p,f+4*d),M];return[...new Set(y.map(g=>Math.min(Math.max(g,m),M)))].sort((g,E)=>g-E)}function he(n,t,r){return n>=2&&t>=2&&r>=1&&Number.isFinite(n)&&Number.isFinite(r)&&!Number.isNaN(t)}function Sn(n,t,r,e,i,o){let u;return st!==void 0&&st.q===n&&st.k===t&&st.df===r&&st.r===e?u=st.tail:(u=Si(n,t,r,e,!i),st={q:n,k:t,df:r,r:e,tail:u}),u.upper===!i?o?u.log:u.value:o?Math.log1p(-u.value):1-u.value}var st;function Si(n,t,r,e,i){let o=i;r!==1/0&&Pt(n,t,e,o)>.5&&(o=!o);let u=Cn(n,t,r,e,o);if(u>.5){let s=Cn(n,t,r,e,!o);s<u&&(u=s,o=!o)}if(u<1e-290){let s=Ci(n,t,r,e,o);return{upper:o,value:Math.exp(s),log:s}}return{upper:o,value:u,log:Math.log(u)}}function Bi(n,t,r,e,i,o){return[n,t,r,e].some(Number.isNaN)?NaN:he(t,r,e)?n<=0?v(i,o):n===1/0?I(i,o):Sn(n,t,r,e,i,o):NaN}function qi(n,t,r,e,i,o){if([n,t,r,e].some(Number.isNaN))return NaN;if(!he(t,r,e))return NaN;let u=L(n,0,1/0,i,o);if(u!==void 0)return u;let{lower:s,logTarget:f,linearTarget:a}=S(n,i,o),c=N=>h=>{let m=Math.exp(h);if(a!==void 0&&a>1e-290){let p=N===1/0?Cn(m,t,N,e,!s):Sn(m,t,N,e,s,!1);if(p>0)return Math.log(p/a)}return(N===1/0?Wi(m,t,e,s):Sn(m,t,N,e,s,!0))-f},l=$r(c(1/0),Math.log(3),s);return Math.exp(r===1/0?l:$r(c(r),l,s))}function Wi(n,t,r,e){let i=Pt(n,t,r,!e);return i>1e-290?Math.log(i):wn(n,t,r,!e)}function $r(n,t,r){let e=t,i=n(e);if(i===0)return e;let o=i>0===r?-1:1,u=.05,s=e+o*u,f=n(s);for(let a=0;a<200&&Math.sign(f)===Math.sign(i)&&f!==0;a++)e=s,i=f,u*=2,s=e+o*u,f=n(s);return f===0?s:!Number.isFinite(f)||Math.sign(f)===Math.sign(i)?Number.isFinite(f)?s:e:Oi(n,e,s,i,f)}function Oi(n,t,r,e,i){let o=t,u=e,s=r-t,f=s;for(let a=0;a<100;a++){Math.sign(i)===Math.sign(u)&&(o=t,u=e,s=r-t,f=s),Math.abs(u)<Math.abs(i)&&(t=r,r=o,o=t,e=i,i=u,u=e);let c=2*Bn*Math.abs(r)+1e-300,l=.5*(o-r);if(Math.abs(l)<=c||i===0)return r;if(Math.abs(f)>=c&&Math.abs(e)>Math.abs(i)){let N=i/e,h,m;if(t===o)h=2*l*N,m=1-N;else{let M=e/u,p=i/u;h=N*(2*l*M*(M-p)-(r-t)*(p-1)),m=(M-1)*(p-1)*(N-1)}h>0?m=-m:h=-h,2*h<Math.min(3*l*m-Math.abs(c*m),Math.abs(f*m))?(f=s,s=h/m):(s=l,f=l)}else s=l,f=l;t=r,e=i,r+=Math.abs(s)>c?s:l>0?c:-c,i=n(r)}return r}function cs(n,t,r,e={}){let{nranges:i=1,lowerTail:o=!0,logP:u=!1}=e;return b(n,s=>Bi(s,t,r,i,o,u))}function ls(n,t,r,e={}){let{nranges:i=1,lowerTail:o=!0,logP:u=!1}=e;return b(n,s=>qi(s,t,r,i,o,u))}function ms(n,t={}){return me(n,t).map(r=>r-1)}function me(n,t){if(!Number.isFinite(n)||n<0||n>=2**31)throw new RangeError("n must be a non-negative number less than 2^31");n=Math.trunc(n);let{replace:r=!1,prob:e}=t,i=t.size!==void 0,o=i?t.size:n;if(!Number.isFinite(o)||o<0)throw new RangeError("size must be a non-negative number");let u=Math.trunc(o);if(e!==void 0){if(e.length!==n)throw new TypeError("prob must have length n");let c=Ui(e,u,r);if(r){let l=0;for(let N=0;N<n;N++)n*c[N]>.1&&l++;return l>200?Qi(c,u):Hi(c,u)}if(u>n)throw new RangeError("cannot take a sample larger than the population when replace is false");return Gi(c,u)}if(!r&&u>n)throw new RangeError("cannot take a sample larger than the population when replace is false");if(!r&&n>1e7&&i&&u<=n/2){let c=new Set,l=[];for(;l.length<u;){let N=bt(n);c.has(N)||(c.add(N),l.push(N+1))}return l}let s=new Array(u);if(r||u<2){for(let c=0;c<u;c++)s[c]=bt(n)+1;return s}let f=new Int32Array(n);for(let c=0;c<n;c++)f[c]=c;let a=n;for(let c=0;c<u;c++){let l=bt(a);s[c]=f[l]+1,f[l]=f[--a]}return s}function Ms(n,t={}){return me(n.length,t).map(r=>n[r-1])}function Ui(n,t,r){let e=0,i=0;for(let o of n){if(!Number.isFinite(o))throw new RangeError("prob contains NaN or infinite values");if(o<0)throw new RangeError("prob contains negative values");o>0&&(i++,e+=o)}if(i===0||!r&&t>i)throw new RangeError("too few positive probabilities");return Float64Array.from(n,o=>o/e)}function ji(n,t){let r=n.length;if(r<=1)return;let e=f=>n[f-1],i=(r>>1)+1,o=r,u,s;for(;;){if(i>1)i=i-1,u=e(i),s=t[i-1];else if(u=e(o),s=t[o-1],n[o-1]=e(1),t[o-1]=t[0],--o===1){n[0]=u,t[0]=s;return}let f=i,a=i<<1;for(;a<=o;)a<o&&e(a)>e(a+1)&&++a,u>e(a)?(n[f-1]=e(a),t[f-1]=t[a-1],f=a,a+=a):a=o+1;n[f-1]=u,t[f-1]=s}}function Me(n){let t=new Int32Array(n.length);for(let r=0;r<n.length;r++)t[r]=r+1;return ji(n,t),t}function Hi(n,t){let r=Float64Array.from(n),e=r.length,i=Me(r);for(let u=1;u<e;u++)r[u]+=r[u-1];let o=new Array(t);for(let u=0;u<t;u++){let s=nt(),f=0;for(;f<e-1&&!(s<=r[f]);f++);o[u]=i[f]}return o}function Gi(n,t){let r=Float64Array.from(n),e=r.length,i=Me(r),o=new Array(t),u=1;for(let s=0,f=e-1;s<t;s++,f--){let a=u*nt(),c=0,l=0;for(;l<f&&(c+=r[l],!(a<=c));l++);o[s]=i[l],u-=r[l];for(let N=l;N<f;N++)r[N]=r[N+1],i[N]=i[N+1]}return o}function Qi(n,t){let r=n.length,e=new Float64Array(r),i=new Int32Array(r),o=new Int32Array(r),u=-1,s=r;for(let a=0;a<r;a++)e[a]=n[a]*r,e[a]<1?o[++u]=a:o[--s]=a;if(u>=0&&s<r)for(let a=0;a<r-1;a++){let c=o[a],l=o[s];if(i[c]=l,e[l]+=e[c]-1,e[l]<1&&s++,s>=r)break}let f=new Array(t);for(let a=0;a<t;a++){let c=bt(r);f[a]=nt()<e[c]?c+1:i[c]+1}return f}function Ki(n){let t=new Float64Array(n+1);for(let r=2;r<=n;r++)t[r]=t[r-1]+Math.log(r);return t}function Vi(n,t,r,e){let i=n.length,o=t.length,u=Array.from(t),s=0;for(let a of n)s+=a;for(let a=0;a<i-1;a++){let c=n[a],l=s;s-=c;let N=0;for(;N<o-1;N++){let h=u[N],m=l;l-=h;let M=m-c,p=M-h;if(m===0){for(let g=N;g<o-1;g++)e[a+g*i]=0;c=0;break}let d=nt(),y;t:for(;;){y=Math.floor(c*(h/m)+.5);let g=Math.exp(r[c]+r[M]+r[l]+r[h]-r[m]-r[y]-r[h-y]-r[c-y]-r[p+y]);if(g>=d)break;if(g===0)throw new Error(`r2dtable: probability underflow at cell [${a}, ${N}]`);let E=g,V=g,B=y,A=!1,X=!1;for(;!(A&&X);){if(!A){let q=(h-y)*(c-y);if(q===0)A=!0;else if(y++,g=g*q/(y*(p+y)),E+=g,E>=d)break t}do{let q=B*(p+B);if(q===0){X=!0;break}if(B--,V=V*q/((h-B)*(c-B)),E+=V,E>=d){y=B;break t}}while(A)}d=E*nt()}e[a+N*i]=y,c-=y,u[N]=u[N]-y}e[a+(o-1)*i]=c}let f=t[o-1];for(let a=0;a<i-1;a++)f-=e[a+(o-1)*i];for(let a=0;a<o-1;a++)e[i-1+a*i]=u[a];e[i-1+(o-1)*i]=f}function de(n,t){let r=Array.from(n,e=>Math.trunc(e));if(r.length<=1||r.some(e=>!(e>=0)||e>2147483647))throw new RangeError(`invalid argument '${t}'`);return r}function gs(n,t,r){let e=Math.trunc(n);if(!(e>=0))throw new RangeError("invalid argument 'n'");let i=de(t,"r"),o=de(r,"c"),u=i.reduce((c,l)=>c+l,0);if(u!==o.reduce((c,l)=>c+l,0))throw new RangeError("arguments 'r' and 'c' must have the same sums");let s=Ki(u),f=new Int32Array(i.length*o.length),a=[];for(let c=0;c<e;c++)Vi(i,o,s,f),a.push(i.map((l,N)=>o.map((h,m)=>f[N+m*i.length])));return a}export{en as a,ct as b,Wt as c,rt as d,eo as e,io as f,oo as g,yr as h,Ir as i,vr as j,K as k,Fe as l,xe as m,Le as n,Mo as o,po as p,go as q,hn as r,Vt as s,mu as t,Mu as u,du as v,cn as w,Qt as x,So as y,Bo as z,qo as A,Ve as B,Xe as C,Eu as D,_u as E,Au as F,Ye as G,Pe as H,Je as I,Ou as J,Uu as K,ju as L,ei as M,ii as N,$u as O,Zu as P,Yu as Q,ai as R,ci as S,ns as T,rs as U,es as V,cs as W,ls as X,ms as Y,Ms as Z,Ki as _,Vi as $,gs as aa};
@@ -1,2 +0,0 @@
1
- /*! rStats.js 0.7.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 N3,b as w,c as p3,d as h,e as g3,f as H,g as I,h as d,i as b3,j as I3,k as g}from"./chunk-ZW52Z3GY.js";function v(e,t){let n=t[0];for(let o=1;o<t.length;o++)n=n*e+t[o];return n}function q(e,t){let n=e+t[0];for(let o=1;o<t.length;o++)n=n*e+t[o];return n}var y5=[2461969814735305e-25,.5641895648310689,7.463210564422699,48.63719709856814,196.5208329560771,526.4451949954773,934.5285271719576,1027.5518868951572,557.5353353693994],_5=[13.228195115474499,86.70721408859897,354.9377788878199,975.7085017432055,1823.9091668790973,2246.3376081871097,1656.6630919416134,557.5353408177277],P5=[.5641895835477551,1.275366707599781,5.019050422511805,6.160210979930536,7.4097426995044895,2.9788666537210022],F5=[2.2605286322011726,9.396035249380015,12.048953980809666,17.08144507475659,9.608968090632859,3.369076451000815],R5=[9.604973739870516,90.02601972038427,2232.005345946843,7003.325141128051,55592.30130103949],L5=[33.56171416475031,521.3579497801527,4594.323829709801,22629.000061389095,49267.39426086359],E5=709.782712893384,w5=.5641895835477563;function r1(e){if(Number.isNaN(e))return NaN;if(e<0)return-r1(-e);if(e>1)return 1-I1(e);let t=e*e;return e*v(t,R5)/q(t,L5)}function I1(e){if(Number.isNaN(e))return NaN;let t=Math.abs(e);if(t<1)return 1-r1(e);if(e<0)return 2-I1(t);let[n,o]=p3(t,t);if(n>E5+40)return 0;let r=d3(t)*(1-o);return n<700?Math.exp(-n)*r:Math.exp(700-n)*r*Math.exp(-700)}function d1(e){return Number.isNaN(e)?NaN:e<1?Math.exp(e*e)*(1-r1(e)):e>1e8?w5/e:d3(e)}function d3(e){return e<8?v(e,y5)/q(e,_5):v(e,P5)/q(e,F5)}var q5=[-59.96335010141079,98.00107541859997,-56.67628574690703,13.931260938727968,-1.2391658386738125],G5=[1.9544885833814176,4.676279128988815,86.36024213908905,-225.46268785411937,200.26021238006066,-82.03722561683334,15.90562251262117,-1.1833162112133],T5=[4.0554489230596245,31.525109459989388,57.16281922464213,44.08050738932008,14.684956192885803,2.1866330685079025,-.1402560791713545,-.03504246268278482,-.0008574567851546854],D5=[15.779988325646675,45.39076351288792,41.3172038254672,15.04253856929075,2.504649462083094,-.14218292285478779,-.03808064076915783,-.0009332594808954574],k5=[3.2377489177694603,6.915228890689842,3.9388102529247444,1.3330346081580755,.20148538954917908,.012371663481782003,.00030158155350823543,26580697468673755e-22,6239745391849833e-24],C5=[6.02427039364742,3.6798356385616087,1.3770209948908132,.21623699359449663,.013420400608854318,.00032801446468212774,28924786474538068e-22,6790194080099813e-24],A3=.1353352832366127,O5=2.5066282746310007;function S3(e){let t=e-Math.log(e)/e,n=1/e,o=e<8?n*v(n,T5)/q(n,D5):n*v(n,k5)/q(n,C5);return t-o}function A1(e){if(e===0)return-1/0;if(e===1)return 1/0;if(!(e>=0&&e<=1))return NaN;let t=e,n=!0;if(t>1-A3&&(t=1-t,n=!1),t>A3){t=t-.5;let r=t*t;return(t+t*(r*v(r,q5)/q(r,G5)))*O5}let o=S3(Math.sqrt(-2*Math.log(t)));return n?-o:o}function v3(e){if(e<-Number.MAX_VALUE)return-1/0;if(e<-2){let t=e>=-Number.MAX_VALUE*.5?Math.sqrt(-2*e):Math.SQRT2*Math.sqrt(-e);return-S3(t)}return e>-.14541345786885906?-A1(-Math.expm1(e)):A1(Math.exp(e))}function S1(e,t){return typeof e=="number"?t(e):e instanceof Float64Array?e.map(t):e.map(n=>t(n))}var v1=Math.SQRT1_2;function y3(e,t){let n=Math.floor(e*16)/16,o=e-n,r=n*n/2,s=t*Math.exp(-o*(e+n)/2);return r<=700?s*Math.exp(-r):s*Math.exp(700-r)*Math.exp(-700)}function S0(e){let t=-e;return t<Math.SQRT2?.5-.5*r1(t*v1):y3(t,.5*d1(t*v1))}function _3(e,t){if(!t)return e<=0?S0(e):1-S0(-e);if(e>-1)return Math.log1p(-S0(-e));let n=-e;return Math.log(.5*d1(n*v1))-n*n/2}function Q5(e,t,n,o,r){if(Number.isNaN(e)||Number.isNaN(t)||Number.isNaN(n))return NaN;if(!Number.isFinite(e)&&t===e)return NaN;let s=o?r?-1/0:0:r?0:1,i=o?r?0:1:r?-1/0:0;if(n<0)return NaN;if(n===0)return e<t?s:i;let c=(e-t)/n;return Number.isFinite(c)?_3(o?c:-c,r):e<t?s:i}function z5(e,t,n,o,r){if(Number.isNaN(e)||Number.isNaN(t)||Number.isNaN(n))return NaN;let s=o?-1/0:1/0;if(r){if(e>0)return NaN;if(e===0)return-s;if(e===-1/0)return s}else{if(e<0||e>1)return NaN;if(e===0)return s;if(e===1)return-s}if(n<0)return NaN;if(n===0)return t;let i=r?B5(e):A1(e);return t+n*(o?i:-i)}var X5=.7978845608028654;function B5(e){let t=v3(e);if(!(e<-2048)||!Number.isFinite(t))return t;let n=X5/d1(-t*v1),o=(_3(t,!0)-e)/n;return Number.isFinite(o)?t-o:t}var H5=.9189385332046728,V5=.3989422804014327;function Y5(e,t,n,o){if(Number.isNaN(e)||Number.isNaN(t)||Number.isNaN(n))return NaN;if(n<0)return NaN;if(!Number.isFinite(n))return o?-1/0:0;if(!Number.isFinite(e)&&t===e)return NaN;if(n===0)return e===t?1/0:o?-1/0:0;let r=(e-t)/n;return Number.isFinite(r)?o?-(H5+.5*r*r+Math.log(n)):y3(Math.abs(r),V5/n):o?-1/0:0}function Y6(e,t={}){let{mean:n=0,sd:o=1,log:r=!1}=t;return S1(e,s=>Y5(s,n,o,r))}function U6(e,t={}){let{mean:n=0,sd:o=1,lowerTail:r=!0,logP:s=!1}=t;return S1(e,i=>Q5(i,n,o,r,s))}function j6(e,t={}){let{mean:n=0,sd:o=1,lowerTail:r=!0,logP:s=!1}=t;return S1(e,i=>z5(i,n,o,r,s))}var G=11102230246251565e-32;var D=171.6243769563027,s1=.9189385332046728,P3=1.1447298858494002;var v0=.5772156649015329;var U5=[.00016011952247675185,.0011913514700658638,.010421379756176158,.04763678004571372,.20744822764843598,.4942148268014971,1],j5=[-23158187332412014e-21,.0005396055804933034,-.004456419138517973,.011813978522206043,.035823639860549865,-.23459179571824335,.0714304917030273,1];function E3(e){let t=1;e<0&&(e=-e,t=-1);let n=e%2;return n<.5?t*Math.sin(Math.PI*n):n>1.5?t*Math.sin(Math.PI*(n-2)):-t*Math.sin(Math.PI*(n-1))}function F3(e){if(e>=D)return 1/0;let t=e-1,n=h(d(g([t,0]),t),[-t+t6(t),0]);return Math.sqrt(2*Math.PI*t)*Math.exp(n[0])*(1+n[1])}function k(e){if(!Number.isFinite(e))return e>0?e:NaN;if(e===0)return NaN;let t=Math.abs(e);if(t>33){if(e<0){let o=Math.floor(t);if(o===t)return NaN;let r=o%2===0?-1:1,s=t-o;return s>.5&&(o+=1,s=t-o),s=t*E3(s),s===0?r*(1/0):r*Math.PI/(Math.abs(s)*F3(t))}return F3(e)}let n=1;for(;e>=3;)e-=1,n*=e;for(;e<0;){if(e>-1e-9)return R3(e,n);n/=e,e+=1}for(;e<2;){if(e<1e-9)return R3(e,n);n/=e,e+=1}return e===2?n:(e-=2,n*v(e,U5)/v(e,j5))}function R3(e,t){return e===0?NaN:t/((1+v0*e)*e)}var K5=[.0008116141674705085,-.0005950619042843014,.0007936503404577169,-.002777777777300997,.08333333333333319],Z5=[-1378.2515256912086,-38801.631513463784,-331612.9927388712,-1162370974927623e-9,-1.7217370082083966e6,-853555.6642457654],J5=[-351.81570143652345,-17064.210665188115,-220528.59055385445,-1.1393344436798252e6,-2.5325230717758294e6,-2.0188914143353277e6],W5=2556348e299;function $5(e){let t=(e-.5)*Math.log(e)-e+s1;if(e>1e8)return t;let n=1/(e*e);return t+((.0007936507936507937*n-.002777777777777778)*n+.08333333333333333)/e}function T(e){if(!Number.isFinite(e))return{value:e===-1/0?1/0:e,sign:1};if(e<-34){let o=-e,r=T(o).value,s=Math.floor(o);if(s===o)return{value:1/0,sign:1};let i=s%2===0?-1:1,c=o-s;return c>.5&&(s+=1,c=s-o),c=o*E3(c),c===0?{value:1/0,sign:1}:{value:P3-Math.log(c)-r,sign:i}}if(e<13){let o=1,r=0,s=e;for(;s>=3;)r-=1,s=e+r,o*=s;for(;s<2;){if(s===0)return{value:1/0,sign:1};o/=s,r+=1,s=e+r}let i=1;if(o<0&&(i=-1,o=-o),s===2)return{value:Math.log(o),sign:i};r-=2;let c=e+r;return{value:Math.log(o)+c*v(c,Z5)/q(c,J5),sign:i}}if(e>W5)return{value:1/0,sign:1};if(e>=1e3)return{value:$5(e),sign:1};let t=(e-.5)*Math.log(e)-e+s1,n=1/(e*e);return{value:t+v(n,K5)/e,sign:1}}function K(e){return Math.abs(e-1)<=.2?V(e-1):Math.abs(e-2)<=.2?V(e-2)+Math.log1p(e-2):T(e).value}var x5=[1.6449340668482264,1.2020569031595942,1.0823232337111381,1.03692775514337,1.0173430619844492,1.008349277381923,1.0040773561979444,1.0020083928260821,1.000994575127818,1.0004941886041194,1.000246086553308,1.0001227133475785,1.0000612481350588,1.000030588236307,1.0000152822594086,1.0000076371976379,1.000003817293265,1.0000019082127165,1.0000009539620338,1.0000004769329869,1.0000002384505027,1.000000119219926,1.000000059608189,1.0000000298035034,1.0000000149015549,1.0000000074507118,1.000000003725334,1.0000000018626598,1.0000000009313275,1.0000000004656628,1.000000000232831,1.0000000001164155,1.0000000000582077,1.0000000000291038,1.000000000014552,1.000000000007276,1.000000000003638,1.000000000001819,1.0000000000009095,1.0000000000004547];function L3(e){if(e===0)return 0;let t=-v0*e,n=-e;for(let o=2;o<42;o++){n*=-e;let r=x5[o-2]*n/o;if(t+=r,Math.abs(r)<G*Math.abs(t))break}return t}function V(e){return Math.abs(e)<=.2?L3(e):Math.abs(e-1)<=.2?Math.log(e)+L3(e-1):K(e+1)}var e6=[1/12,-1/360,1/1260,-1/1680,1/1188,-691/360360,1/156];function t6(e){let t=1/(e*e),n=0,o=1/e;for(let r of e6)n+=r*o,o*=t;return n}var w3=[1/12,-1/360,1/1260,-1/1680,1/1188,-691/360360,1/156];function q3(e,t){let n=y0(e,t);return n[0]+n[1]}function y0(e,t){if(e===0)return[0,0];let n=0,o=t;for(;o<=15;)n-=Math.log1p(e/o),o+=1;let r=Math.log1p(e/o),s=e*Math.log(o+e),i=Math.abs(s)>2&&Number.isFinite(s)&&e<1e300?d(g(w(o,e)),e):[s,0],c=(o-.5)*r-e,u=1/o,l=1/(o*o);for(let f=0;f<w3.length;f++){let a=2*f+1;c+=w3[f]*u*Math.expm1(-a*r),u*=l}return h(i,[n+c,0])}var G3=22250738585072014e-324,F0=1.8378770664093456,n6=[.15342640972002736,.08106146679532726,.05481412105191765,.0413406959554093,.03316287351993629,.02767792568499834,.023746163656297496,.020790672103765093,.018488450532673187,.016644691189821193,.015134973221917378,.013876128823070748,.012810465242920227,.01189670994589177,.011104559758206917,.010411265261972096,.009799416126158804,.009255462182712733,.008768700134139386,.00833056343336287,.00793411456431402,.007573675487951841,.007244554301320383,.00694284010720953,.006665247032707682,.006408994188004207,.006171712263039458,.0059513701127588475,.0057462165130101155,.005554733551962801],y1=1/12,_1=1/360,_0=1/1260,T3=1/1680,o6=1/1188,r6=691/360360,s6=1/156;function D3(e){let t=1/(e*e);return e>500?(y1-_1*t)/e:e>80?(y1-(_1-_0*t)*t)/e:e>35?(y1-(_1-(_0-T3*t)*t)*t)/e:(y1-(_1-(_0-(T3-(o6-(r6-s6*t)*t)*t)*t)*t)*t)/e}function A(e){if(e>15)return D3(e);let t=2*e;if(t===Math.floor(t)&&t>=1)return n6[t-1];if(e<1)return V(e)-(e+.5)*Math.log(e)+e-s1;let n=0,o=e;for(;o<=15;)n+=(o+.5)*Math.log1p(1/o)-1,o+=1;return n+D3(o)}function C(e,t){if(!N3())return i6(e,t);let n=-t[0],o=-t[1],r=e+n,s=r-e,i=e-(r-s)+(n-s),c=0+o,u=c-0,l=0-(c-u)+(o-u),f=i+c,a=r+f,b=f-(a-r)+l,S=a+b,y=b-(S-a),p=S,P=y;if(Math.abs(p)<.1*(e+t[0])){let R=e+t[0],Z=R-e,J=e-(R-Z)+(t[0]-Z),Y=0+t[1],O=Y-0,c1=0-(Y-O)+(t[1]-O),W=J+Y,w1=R+W,w0=W-(w1-R)+c1,_=w1+w0,q0=w0-(_-w1),Q=p/_,q1=_*Q,G0=134217729*_,G1=G0-(G0-_),T0=_-G1,D0=134217729*Q,T1=D0-(D0-Q),k0=Q-T1,C0=G1*T1-q1+G1*k0+T0*T1+T0*k0+q0*Q,O0=q1+C0,e5=C0-(O0-q1),Q0=-O0,z0=-e5,u1=p+Q0,X0=u1-p,t5=p-(u1-X0)+(Q0-X0),D1=P+z0,B0=D1-P,n5=P-(D1-B0)+(z0-B0),H0=t5+D1,k1=u1+H0,V0=H0-(k1-u1)+n5,$=k1+V0,C1=V0-($-k1),z=$/_,O1=_*z,Y0=134217729*_,Q1=Y0-(Y0-_),U0=_-Q1,j0=134217729*z,z1=j0-(j0-z),K0=z-z1,Z0=Q1*z1-O1+Q1*K0+U0*z1+U0*K0+q0*z,J0=O1+Z0,o5=Z0-(J0-O1),W0=-J0,$0=-o5,f1=$+W0,x0=f1-$,r5=$-(f1-x0)+(W0-x0),X1=C1+$0,e2=X1-C1,s5=C1-(X1-e2)+($0-e2),t2=r5+X1,B1=f1+t2,n2=t2-(B1-f1)+s5,o2=B1+n2,S6=n2-(o2-B1),r2=o2/_,a1=Q+z,H1=z-(a1-Q),l1=a1+r2,s2=l1-a1,i5=a1-(l1-s2)+(r2-s2),V1=H1+0,i2=V1-H1,c5=H1-(V1-i2)+(0-i2),c2=i5+V1,Y1=l1+c2,u2=c2-(Y1-l1)+c5,f2=Y1+u2,u5=u2-(f2-Y1),M=f2,h1=u5,U1=p*M,a2=134217729*p,j1=a2-(a2-p),l2=p-j1,h2=134217729*M,K1=h2-(h2-M),M2=M-K1,m2=j1*K1-U1+j1*M2+l2*K1+l2*M2+(p*h1+P*M),N2=U1+m2,f5=m2-(N2-U1),U=N2,j=f5,x=2*e,Z1=M*x,p2=134217729*M,J1=p2-(p2-M),g2=M-J1,b2=134217729*x,W1=b2-(b2-x),I2=x-W1,d2=J1*W1-Z1+J1*I2+g2*W1+g2*I2+h1*x,A2=Z1+d2,a5=d2-(A2-Z1),E=A2,e1=a5,$1=M*M,S2=134217729*M,x1=S2-(S2-M),v2=M-x1,y2=134217729*M,e0=y2-(y2-M),_2=M-e0,P2=x1*e0-$1+x1*_2+v2*e0+v2*_2+(M*h1+h1*M),F2=$1+P2,l5=P2-(F2-$1),t1=F2,h5=l5;for(let t0=1;t0<1e3;t0++){let n0=E*t1,R2=134217729*E,o0=R2-(R2-E),L2=E-o0,E2=134217729*t1,r0=E2-(E2-t1),w2=t1-r0,q2=o0*r0-n0+o0*w2+L2*r0+L2*w2+(E*h5+e1*t1),G2=n0+q2,M5=q2-(G2-n0);E=G2,e1=M5;let L=2*t0+1,X=E/L,s0=L*X,T2=134217729*L,i0=T2-(T2-L),D2=L-i0,k2=134217729*X,c0=k2-(k2-X),C2=X-c0,O2=i0*c0-s0+i0*C2+D2*c0+D2*C2+0*X,Q2=s0+O2,m5=O2-(Q2-s0),z2=-Q2,X2=-m5,M1=E+z2,B2=M1-E,N5=E-(M1-B2)+(z2-B2),u0=e1+X2,H2=u0-e1,p5=e1-(u0-H2)+(X2-H2),V2=N5+u0,f0=M1+V2,Y2=V2-(f0-M1)+p5,n1=f0+Y2,a0=Y2-(n1-f0),B=n1/L,l0=L*B,U2=134217729*L,h0=U2-(U2-L),j2=L-h0,K2=134217729*B,M0=K2-(K2-B),Z2=B-M0,J2=h0*M0-l0+h0*Z2+j2*M0+j2*Z2+0*B,W2=l0+J2,g5=J2-(W2-l0),$2=-W2,x2=-g5,m1=n1+$2,e3=m1-n1,b5=n1-(m1-e3)+($2-e3),m0=a0+x2,t3=m0-a0,I5=a0-(m0-t3)+(x2-t3),n3=b5+m0,N0=m1+n3,o3=n3-(N0-m1)+I5,r3=N0+o3,q6=o3-(r3-N0),s3=r3/L,N1=X+B,p0=B-(N1-X),p1=N1+s3,i3=p1-N1,d5=N1-(p1-i3)+(s3-i3),g0=p0+0,c3=g0-p0,A5=p0-(g0-c3)+(0-c3),u3=d5+g0,b0=p1+u3,f3=u3-(b0-p1)+A5,g1=b0+f3,a3=f3-(g1-b0),b1=U+g1,l3=b1-U,S5=U-(b1-l3)+(g1-l3),I0=j+a3,h3=I0-j,v5=j-(I0-h3)+(a3-h3),M3=S5+I0,d0=b1+M3,m3=M3-(d0-b1)+v5,o1=d0+m3,A0=m3-(o1-d0);if(Math.abs(g1)<=1e-33*Math.abs(o1)||o1===U&&A0===j)return[o1,A0];U=o1,j=A0}return[U,j]}let F=H(g([e,0]),g(t));return h(d(F,e),[-p,-P])}function i6(e,t){let n=H([e,0],t);if(Math.abs(n[0])<.1*(e+t[0])){let r=b3(n,h([e,0],t)),s=I(n,r),i=d(r,2*e),c=I(r,r);for(let u=1;u<1e3;u++){i=I(i,c);let l=I3(i,2*u+1),f=h(s,l);if(Math.abs(l[0])<=1e-33*Math.abs(f[0])||f[0]===s[0]&&f[1]===s[1])return f;s=f}return s}let o=H(g([e,0]),g(t));return h(d(o,e),g3(n))}function i4(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t===0)return NaN;if(e===0)return t;let n=C(e,[t,0]);return n[0]+n[1]}function P0(e,t,n,o){if(t)return-e[0]-e[1]-.5*n();if(e[0]<700)return Math.exp(-e[0])*(1-e[1])/Math.sqrt(o());let r=o();return!Number.isFinite(r)||r===0?Math.exp(-e[0]-e[1]-.5*n()):Math.exp(700-e[0])*(1-e[1])/Math.sqrt(r)*Math.exp(-700)}function c4(e,t,n,o,r){let s=r?-1/0:0,i=r?0:1,c=w(e,t),u=c[0];if(n[0]===0)return e===0?i:s;if(o[0]===0)return t===0?i:s;if(e===0){if(u===0)return i;if(n[0]<.1){let N=h(C(u,I(c,o)),I(c,n));return r?-N[0]-N[1]:Math.exp(-N[0])*(1-N[1])}let f=g(o),a=I(c,f);return r?a[0]+a[1]:Math.exp(a[0])*(1+a[1])}if(t===0){if(o[0]<.1){let a=h(C(u,I(c,n)),I(c,o));return r?-a[0]-a[1]:Math.exp(-a[0])*(1-a[1])}let f=I(c,g(n));return r?f[0]+f[1]:Math.exp(f[0])*(1+f[1])}if(e<0||t<0)return s;let l=h(C(e,I(c,n)),C(t,I(c,o)));return l=h(l,w(A(e)+A(t),-A(u))),P0(l,r,()=>F0+Math.log(e)+Math.log(t)-Math.log(u),()=>2*Math.PI*e*(t/u))}function u4(e,t,n,o){let r=w(e,t),s=r[0],i=h(C(e,I(r,n)),C(t,I(r,o)));return i=h(i,w(A(e)+A(t),-A(s))),{e:i,logDenom:F0+Math.log(e)+Math.log(t)-Math.log(s)}}function i1(e,t,n){let o=k3(e,t,n,!n);return n?o[0]:o[1]}function R0(e,t){return k3(e,t,!0,!0)}function k3(e,t,n,o){if(t===0)return e===0?[0,1]:[-1/0,0];if(!Number.isFinite(t)||e<0)return[-1/0,0];if(e<=t*G3)return[-t,o?Math.exp(-t):NaN];if(t<e*G3){if(!Number.isFinite(e))return[-1/0,0];let c=-t+e*Math.log(t)-V(e);return[c,o?Math.exp(c):NaN]}let r=h(C(e,[t,0]),[A(e),0]),s=()=>F0+Math.log(e),i=()=>2*Math.PI*e;return[n?P0(r,!0,s,i):NaN,o?P0(r,!1,s,i):NaN]}var P1=1e6;function Q3(e,t){let{value:n,sign:o}=T(t),r=n;return r-=t*Math.log(e),r+=t*(1-t)/(2*e),r+=t*(1-t)*(1-2*t)/(12*e*e),r+=-t*t*(1-t)*(1-t)/(12*e*e*e),{value:r,sign:o}}function c6(e,t){if(Number.isNaN(e)||Number.isNaN(t))return NaN;if(e===1/0&&t>0||t===1/0&&e>0)return 0;if(e>0&&t>0&&Math.max(e,t)>15){let i=Math.min(e,t),c=Math.max(e,t);if(i<1){let l=y0(i,c);return k(i)*Math.exp(-l[0])*(1-l[1])}let u=c>=X3?B3(c,i):H3(e,t);return Math.exp(u[0])*(1+u[1])}let n=1;if(e<=0&&e===Math.floor(e))return C3(e,t);if(t<=0&&t===Math.floor(t))return C3(t,e);if(Math.abs(e)<Math.abs(t)&&([e,t]=[t,e]),Math.abs(e)>P1*Math.abs(t)&&e>P1){let i=Q3(e,t);return i.sign*Math.exp(i.value)}let o=e+t;if(Math.abs(o)>D||Math.abs(e)>D||Math.abs(t)>D){let i=T(o);n*=i.sign;let c=T(t);n*=c.sign;let u=T(e);n*=u.sign;let l=u.value+(c.value-i.value);return n*Math.exp(l)}o=1/k(o);let r=k(e),s=k(t);return Number.isFinite(o)?Math.abs(Math.abs(r*o)-1)>Math.abs(Math.abs(s*o)-1)?s*o*r:r*o*s:n*(1/0)}function C3(e,t){return t===Math.floor(t)&&1-e-t>0?(t%2===0?1:-1)*c6(1-e-t,t):1/0}function u6(e,t){if(Number.isNaN(e)||Number.isNaN(t))return NaN;if(e===1/0&&t>0||t===1/0&&e>0)return-1/0;if(e>0&&t>0&&Number.isFinite(e)&&Number.isFinite(t)&&Math.max(e,t)>15){let i=Math.min(e,t),c=Math.max(e,t);if(i<1)return K(i)-q3(i,c);let u=c>=X3?B3(c,i):H3(e,t);return u[0]+u[1]}if(e<=0&&e===Math.floor(e))return O3(e,t);if(t<=0&&t===Math.floor(t))return O3(t,e);if(Math.abs(e)<Math.abs(t)&&([e,t]=[t,e]),Math.abs(e)>P1*Math.abs(t)&&e>P1)return Q3(e,t).value;let n=e+t;if(Math.abs(n)>D||Math.abs(e)>D||Math.abs(t)>D)return T(e).value+(T(t).value-T(n).value);n=1/k(n);let o=k(e),r=k(t);if(!Number.isFinite(n))return 1/0;let s=Math.abs(Math.abs(o*n)-1)>Math.abs(Math.abs(r*n)-1)?r*n*o:o*n*r;return Math.log(Math.abs(s))}function O3(e,t){return t===Math.floor(t)&&1-e-t>0?u6(1-e-t,t):1/0}var z3=[.9189385332046728,-38782941580672414e-33],X3=2**52;function B3(e,t){let n=d(H(g([t,0]),g([e,0])),t),o=-.5*Math.log(t)-(e+t-.5)*Math.log1p(t/e)+(A(e)+A(t)-A(e+t));return h(h(n,z3),[o,0])}function H3(e,t){let n=w(e,t),o=d(g([e,0]),e-.5),r=d(g([t,0]),t-.5),s=f6(g(n),h(n,[-.5,0])),i=H(h(o,r),s);return i=h(i,z3),h(i,w(A(e)+A(t),-A(n[0])))}function f6(e,t){return h(d(e,t[0]),d(e,t[1]))}function L0(e){if(Math.abs(e)<.5){let t=e,n=0;for(let o=2;o<500;o++){t*=-e;let r=t/o;if(n+=r,Math.abs(r)<G*Math.abs(n))break}return n}return Math.log1p(e)-e}var V3=[[-.3333333333333333,.08333333333333333,-.014814814814814815,.0011574074074074073,.0003527336860670194,-.0001787551440329218,3919263178522438e-20,-21854485106799924e-22,-185406221071516e-20,8296711340953087e-22,-17665952736826078e-23,6707853543401498e-24,10261809784240309e-24,-4382036018453353e-24,914769958223679e-24,-2551419399494625e-26,-5830772132550426e-26,24361948020667415e-27,-50276692801141755e-28,11004392031956135e-29,33717632624009856e-29,-1392388722418162e-28,28534893807047445e-30,-5139111834242572e-31,-19752288294349442e-31],[-.001851851851851852,-.003472222222222222,.0026455026455026454,-.0009902263374485596,.00020576131687242798,-4018775720164609e-22,-18098550334489977e-21,764916091608111e-20,-16120900894563446e-22,4647127802807434e-24,1378633446915721e-22,-5752545603517705e-23,11951628599778148e-24,-17543241719747647e-27,-10091543710600413e-25,4162792991842583e-25,-856390702649298e-25,6067215101604758e-29,71624989648114856e-28,-2933186643771437e-27,5996696365683689e-28,-21671786527323313e-32,-4978339972369262e-29,20291628823713425e-30,-413125571381061e-29],[.004133597883597883,-.0026813271604938273,.0007716049382716049,20093878600823047e-22,-.00010736653226365161,52923448829120125e-21,-12760635188618728e-21,3423578734096138e-23,13721957309062932e-22,-6298992138380055e-22,14280614206064242e-23,-20477098421990866e-26,-1409252991086752e-23,6228974084922022e-24,-13670488396617112e-25,9428356159014678e-28,12872252400089318e-26,-55645956134363323e-27,1197593554636698e-26,-41689782251838634e-31,-10940640427884595e-28,4662239946390136e-28,-9905105763906907e-29,18931876768373515e-33,8859221872591127e-30],[.0006494341563786008,.00022947209362139917,-.0004691894943952557,.00026772063206283885,-7561801671883977e-20,-2396505113867297e-22,11082654115347302e-21,-56749528269915965e-22,14230900732435883e-22,-27861080291528143e-27,-16958404091930278e-23,8099464905388083e-23,-19111168485973655e-24,23928620439808118e-28,20620131815488797e-25,-9460496661855133e-25,21541049775774907e-26,-1388823336813903e-29,-21894761681963938e-27,9790998951171684e-27,-2178219188018096e-27,6208819573407901e-32,2126978363279737e-28,-9344688791517433e-29,2045367122678285e-29],[-.0008618882909167117,.0007840392217200666,-.0002990724803031902,-14638452578843418e-22,6641498215465122e-20,-3968365047179435e-20,11375726970678419e-21,2507497226237533e-25,-16954149536558305e-22,8907507532205309e-22,-2292934834000805e-22,2956794137544049e-26,28865829742708783e-24,-14189739437803219e-24,34463580499464896e-25,-23024517174528067e-29,-39409233028046403e-26,186023389685045e-24,-4356323005056618e-26,1278600101629623e-30,467927502665792e-26,-2149246470613483e-27,4908815614809652e-28,-633859148489156e-32,-5045332069080094e-29],[-.00033679855336635813,-6972813758365858e-20,.0002772753244959392,-.00019932570516188847,6797780477937208e-20,1419062920643967e-22,-13594048189768693e-21,8018470256334202e-21,-2291481176508095e-21,-3252473551298454e-25,34652846491085265e-23,-18447187191171344e-23,48240967037894184e-24,-17989466721743514e-30,-6306194500013523e-24,3162417628774568e-24,-7840924253697429e-25,5192679165254041e-30,9358944242306784e-26,-4513426216163278e-26,10799129993116828e-27,-3661886712685252e-32,-1210902069055155e-27,5680743584990564e-28,-13249659916340829e-29],[.0005313079364639922,-.0005921664373536939,.0002708782096718045,7902353232660328e-22,-8153969367561969e-20,561168275310625e-19,-18329116582843375e-21,-30796134506033047e-25,3465155368803609e-21,-20291327396058603e-22,5788792863149004e-22,2338630673826657e-28,-8828600746330484e-23,47435958880408125e-24,-12545415020710382e-24,8649648858010293e-29,16846058979264062e-25,-8575492823577594e-25,21598224929232125e-26,-7613230520476153e-31,-26639822008536144e-27,13065700536611057e-27,-31799163902367977e-28,4710976121367431e-33,36902800842763465e-29],[.00034436760689237765,5171790908260592e-20,-.00033493161081142234,.0002812695154763237,-.00010976582244684731,-12741009095484485e-23,27744451511563645e-21,-18263488805711332e-21,57876949497350525e-22,493875893393627e-24,-10595367014026043e-22,6166714376110408e-22,-17562973359060463e-23,-1297447328701544e-27,2695423606288966e-23,-14578352908731272e-24,3887645959386175e-24,-3881002251019412e-32,-5327994173877286e-25,27437977643314844e-26,-6995796092070568e-26,2589986387486848e-32,8856689099669639e-27,-4403168815871311e-27,10865561947091654e-28],[-.0006526239185953094,.0008394987206720873,-.000438297098541721,-6969091458420552e-22,.00016644846642067547,-.00012783517679769218,4629953263691304e-20,4557909867922708e-24,-10595271125805195e-21,6783342904865167e-21,-21075476666258803e-22,-17213731432817144e-27,3773587741611098e-22,-21867506700122867e-23,6220228804018927e-23,6597703826733e-28,-9590386497425686e-24,5213214492280807e-24,-13991589583935709e-25,5382058999060575e-31,19484714275467745e-26,-10127287556389682e-26,26077347197254926e-27,-5090418699993299e-33,-33721464474854593e-28],[-.0005967612901927463,-7204895416020011e-20,.0006782308837667328,-.0006401475260262758,.00027750107634328704,1819700838046515e-22,-8479507117068503e-20,6105192082501531e-20,-21073920183404862e-21,-8858589014125599e-25,45284535953805374e-22,-28427815022504407e-22,8708234177864641e-22,36886101871706966e-28,-1534469519070206e-22,8862466778790695e-23,-25184812301826817e-24,-10225912098215092e-30,3896947075815478e-24,-21267304792235634e-25,5737013552805138e-25,-1887749850169741e-34,-8093153869465787e-26,423827232834492e-25,-11002224534207727e-27],[.0013324454494800656,-.0019144384985654776,.0011089369134596636,99324041226423e-20,-.0005087450129309319,.00042735056665392886,-.000168588537679108,-81301893922785e-22,45284402370562144e-21,-3127053674781734e-20,1044986828530338e-20,48435226265680926e-27,-2148256587345626e-21,1329369701097492e-21,-4029569309210103e-22,-1756787766632329e-28,7014504316366825e-23,-4040787734999483e-23,11474026743371962e-24,39642746853563326e-34,-17804938269892715e-25,9748026254873165e-25,-26405338676507616e-26,5794875163403742e-33,3764774955354384e-26],[.001579727660730835,.00016251626278391583,-.0020633421035543276,.00213896861856891,-.0010108559391263003,-399127055299192e-21,.0003623502508476469,-.00028143901463712157,.00010449513336495887,212114184918303e-23,-25779417251947842e-21,17281818956040464e-21,-5641377387290428e-21,-11024320105776174e-27,11223224418895176e-22,-6869339637952674e-22,20653236975414888e-23,46714772409838506e-30,-35609886164949055e-24,20470855345905963e-24,-5809173863328336e-24,-1332821287582869e-31,9035460439133513e-25,-4959878251733084e-25,13481607129399748e-26],[-.004072512119514016,.00640336283380807,-.004041016108167662,-2183732802866233e-21,.002174044180125464,-.001970044051841889,.0008359546974796246,19445447567109655e-24,-.000257793871204217,.00019009987368139304,-6769649993743896e-20,-14440629666426571e-26,15712512518742267e-21,-10304008744776892e-21,3304517767401387e-21,7982976024232571e-28,-64097794149313e-20,38894624761300054e-23,-1161834764494887e-22,-2816808630596451e-30,19878012911297094e-24,-11407719956357511e-24,32355857064185554e-25,4175946829345594e-35,-5042311271810582e-25],[-.0059475779383993,-.0005401647678926045,.00879104135507679,-.009857631558785612,.005013469503102154,12807521786221875e-22,-.0020626019342754685,.0017109128573523059,-.000676953127141338,-6901154567656214e-24,.00018855128143995903,-.0001339521566349197,4626318303352804e-20,4003423061332135e-26,-10255652921494033e-21,6612086372797651e-21,-20913022027253007e-22,-20951775649603836e-29,3975602904199325e-22,-2395621197881589e-22,7118288338214586e-23,8925574873053455e-31,-12101547235064675e-24,6935061824833439e-24,-196614644538561e-23],[.01740202778752271,-.029527880945699123,.020045875571402798,70289515966903405e-22,-.012375421071343148,.011976293444235253,-.0054156038466518525,-6329089339641862e-23,.0018855118129005065,-.001473473274825001,.0005551581009770838,5240683441255066e-25,-.00014357913535784837,991812932249433e-19,-3346083474947831e-20,-3575583729109899e-27,71560851960630075e-22,-4551680262815553e-21,14236576649271474e-22,18803149082089665e-30,-2662340389892921e-22,15950642189595716e-23,-471875146738411e-22,-6510787295875518e-32,7979509102674624e-24],[.03024912416090589,.0024817436002649977,-.049939134373457025,.05991564300930787,-.03248320760162339,-5721296865210344e-21,.015085251778569354,-.013261324005088445,.0055515262632426145,3026318225703001e-23,-.0017229548406756724,.0012893570099929638,-.00046845138348319875,-1830259937893045e-25,.00011449739014822654,-7737856522124447e-20,25625836246985202e-21,10766165333192815e-28,-5324680928242262e-21,3349634863064464e-21,-10381253128684019e-22,-5608909920621128e-30,19150821930676592e-23,-11418365800203487e-23,33654425209171787e-24],[-.09905102088015905,.17954011706123485,-.12989606383463778,-31478872752284355e-21,.09051063527684813,-.0928288244111844,.04441211283987781,27779236316835886e-23,-.017229543805449696,.014182925050891573,-.005621416163374734,-239598509186381e-23,.0016029634366079909,-.0011606784674435774,.00041001337768153875,1836580075409066e-26,-958442565636559e-19,6364306233776471e-20,-2076250624489065e-20,-11806020912804483e-29,4213180823912065e-21,-2626224133701247e-21,8077062049493066e-22,6012591212363273e-31,-1472973737401884e-22],[-.19994542198219728,-.015056113040026424,.36470239469348487,-.4643519231173355,.26640934719197895,3403826602714719e-20,-.13784338709329624,.1276467178337056,-.056213828755200985,-1753150885483011e-22,.019235592956768112,-.015088821281095314,.005740185445135012,10622382710310225e-25,-.0015335082692563998,.0010819320643228215,-.0003737251019394566,-6617090972903199e-27,8426361738090962e-20,-5515070682748348e-20,1776953644834807e-20,3882792321020553e-29,-353513697488768e-20,2186583213004527e-21,-668128494476256e-21],[.7243860850402943,-1.3918010932653375,1.0654143352413967,.0001876173868950258,-.827055011761527,.8935243334782842,-.44971003995291337,-16107401567546651e-22,.1923559016527109,-.1659770216004261,.06888222268181433,13910091724608687e-24,-.02146911561508663,.016228980898865892,-.005979601617258426,-11287469112826745e-26,.0015167451119784856,-.00104786342935539,.0003553907288912642,8170432211180152e-28,-777730134424524e-19,5029141389700772e-20,-16035083867000518e-21,12469354315487606e-30,31369106244517616e-22],[1.6668949727276812,.1165462765994632,-3.3288393225018904,4.469232548286404,-2.6977693045875806,-.0002600667859891061,1.5389017615694538,-1.4937962361134611,.6888196463323315,13077482004552384e-22,-.2576296332559629,.21097676102125448,-.08371440835921988,-7792042888135476e-24,.0242679230648336,-.017813678334552312,.006397033038890006,4943080709048052e-26,-.0015554602758465635,.0010561196919903215,-.000352771844604729,9300233464502246e-29,7528585502655717e-20,-4818651556915635e-20,15227271505597605e-21],[-6.618829886137293,13.397985455142589,-10.789350606845145,-.0014352254537875018,9.23336945961898,-10.456552819547769,5.510552602903347,12024439690716742e-21,-2.5762961164755818,2.320744274538718,-1.0045728797216285,-10207833290021913e-23,.3397509217116947,-.2672051745075747,.10235252851562705,8432973048487163e-25,-.027998284958442594,.020066274144976814,-.007055436891508624,19402238183698188e-28,.0016562888105449611,-.0011082898580743682,.0003654545161310169,-5129003202697179e-26,-7634010369686903e-20],[-17.112706061976095,-1.1208044642899115,37.131966511885445,-52.29827102534896,33.058589696624615,.002479129897620022,-20.61089403411526,20.88672775145582,-10.045703956517752,-12238783449063012e-21,4.077013427422114,-3.473667358470195,1.4329352617312006,7135991441187971e-23,-.4479725715911561,.3411266608064446,-.12699786326594922,-2895367726908153e-25,.03312577627825986,-.023274087021036102,.008039999350364889,-1177805216235265e-24,-.001832162489107167,.0012108282933588664,-.0003947994124682252],[73.89033153567425,-156.80141270402274,132.2177542759164,.013692876877324546,-123.66496885920151,146.2068939106273,-80.36558772486535,-.00011259851148881298,40.77013219617994,-38.21034001327303,17.19522294277362,9351970795516835e-22,-6.271615990774704,5.116899907185264,-2.0319658112299095,-4950721558276154e-24,.596263972943326,-.44220765337238094,.16079998700166273,-24733786203223403e-24,-.040307574759979765,.02784905074709787,-.009475185899205422,6419922235909132e-21,.002125018077469946],[212.1683709838252,13.107863022633868,-496.9828593287175,731.215952669692,-482.1382172089085,-.028817248692894887,326.167203029471,-343.8934028008712,171.95193870816232,.00014038077378096157,-75.2594195897599,66.51969984520935,-28.447519748152462,-7613702615875392e-22,9.540223710530437,-7.517530111331138,2.894399756887196,-466121949995382e-21,-.8061514959879409,.5848300657063102,-.20845408972964957,.00014765818959305816,.05100043386375302,-.03306625214188366,.015109265210467774],[-989.5964309832236,2192.555536090523,-1928.3586782723355,-.15925738122215252,1956.9985945919857,-2407.2514765081555,1375.6149959336497,.0012920735237496668,-752.5941715948055,731.7166874220871,-341.37023466220063,-9985739026060805e-21,133.56313181291574,-112.76295161252794,46.31039609820446,-7923738713361476e-21,-14.510726927018647,11.111771248100563,-4.169081794527089,.0031008219800117806,1.1220095449981469,-.7605237992614992,.36262236505085255,.2216867741940747,.48683443692930506]];var E1=1e7,K3=20,R1=200,Z3=.3,J3=4.5,l6=4503599627370496,F1=2220446049250313e-31;function U3(e,t,n){let o=W3(e,t);return n?i1(e,t,!0)+Math.log(o):i1(e,t,!1)*o}function j3(e,t){let n=W3(e,t),o=R0(e,t);return[o[0]+Math.log(n),o[1]*n]}function W3(e,t){if(e>1e3&&t>.97*e)return M6(e,t);let n=e,o=1,r=1;for(let s=0;s<E1&&(n+=1,o*=t/n,r+=o,!(o<=G*r));s++);return r}var h6=2**-64;function M6(e,t){let n=1,o=0,r=1,s=0;for(let i=1;i<E1;i++){let c=e+i,u=c-e,l=e-(c-u)+(i-u),f=t/c,a=134217729*f,N=a-(a-f),b=f-N;a=134217729*c;let S=a-(a-c),y=c-S,p=f*c,P=N*S-p+N*y+b*S+b*y,F=(t-p-P-f*l)/c;a=134217729*n;let R=a-(a-n),Z=n-R,J=n*f,Y=R*N-J+R*b+Z*N+Z*b+(n*F+o*f);n=J+Y,o=Y-(n-J);let O=r+n,c1=O-r,W=r-(O-c1)+(n-c1)+(s+o);if(r=O+W,s=W-(r-O),n*f<=h6*r*(1-f))break}return r+s}function m6(e,t,n){let o=$3(e,t);return n?Math.log(e)+i1(e,t,!0)+Math.log(o):e*i1(e,t,!1)*o}function N6(e,t){let n=$3(e,t),o=R0(e,t);return[Math.log(e)+o[0]+Math.log(n),e*o[1]*n]}function $3(e,t){let n=1-e,o=t+n+1,r=0,s=1,i=t,c=t+1,u=o*t,l=c/u;for(let f=0;f<E1;f++){r+=1,n+=1,o+=2;let a=n*r,N=c*o-s*a,b=u*o-i*a,S;if(b!==0){let y=N/b;S=Math.abs((l-y)/y),l=y}else S=1;if(s=c,c=N,i=u,u=b,Math.abs(N)>l6&&(s*=F1,c*=F1,i*=F1,u*=F1),S<=G)break}return l}function x3(e,t){let n=1,o=0;for(let c=1;c<E1;c++){n*=-t/c;let u=n/(e+c);if(o+=u,Math.abs(u)<=G*Math.abs(o))break}let r=Math.log(t),s=e*r-V(e);return-Math.expm1(s)-e*Math.exp(s)*o}function L1(e,t,n){let o=n?-1:1,r=t/e,s=(t-e)/e,i;r>1?i=Math.sqrt(-2*L0(s)):r<1?i=-Math.sqrt(-2*L0(s)):i=0;let c=.5*I1(o*i*Math.sqrt(e/2)),u=new Array(25).fill(0);u[0]=1;let l=0,f=0,a=1,N=1/0;for(let b=0;b<25;b++){let S=V3[b],y=S[0];for(let F=1;F<25;F++){F>l&&(u[F]=i*u[F-1],l+=1);let R=S[F]*u[F];if(y+=R,Math.abs(R)<G*Math.abs(y))break}let p=y*a,P=Math.abs(p);if(P>N||(f+=p,P<G*Math.abs(f)))break;N=P,a/=e}return c+=o*Math.exp(-.5*e*i*i)*f/Math.sqrt(2*Math.PI*e),c}function E0(e,t,n){if(t>1.1)return t<e?{lower:!0,value:U3(e,t,n)}:{lower:!1,value:m6(e,t,n)};if(t<=.5?-.4/Math.log(t)<e:t*1.1<e)return{lower:!0,value:U3(e,t,n)};let r=x3(e,t);return{lower:!1,value:n?Math.log(r):r}}function p6(e,t){if(t>1.1){let[r,s]=t<e?j3(e,t):N6(e,t);return{lower:t<e,log:r,lin:s}}if(t<=.5?-.4/Math.log(t)<e:t*1.1<e){let[r,s]=j3(e,t);return{lower:!0,log:r,lin:s}}let o=x3(e,t);return{lower:!1,log:Math.log(o),lin:o}}function _4(e,t,n){if(Number.isNaN(e)||Number.isNaN(t))return[NaN,NaN];if(t<0||e<0)return[NaN,NaN];if(e===0)return t>0?n?[0,1]:[-1/0,0]:[NaN,NaN];if(t===0)return n?[-1/0,0]:[0,1];if(e===1/0)return t===1/0?[NaN,NaN]:n?[-1/0,0]:[0,1];if(t===1/0)return n?[0,1]:[-1/0,0];if(t>1e15*Math.max(e,1)){let s=(e-1)*Math.log(t)-t-K(e)+Math.log1p((e-1)/t);return n?[Math.log1p(-Math.exp(s)),-Math.expm1(s)]:[s,Math.exp(s)]}let o=Math.abs(t-e)/e;if(e>K3&&e<R1&&o<Z3||e>R1&&o<J3/Math.sqrt(e)){let s=L1(e,t,n);return[s>.5?Math.log1p(-L1(e,t,!n)):Math.log(s),s]}let r=p6(e,t);return r.lower===n?[r.log,r.lin]:[r.lin>0?Math.log1p(-r.lin):-Math.exp(r.log),1-r.lin]}function P4(e,t,n,o){if(Number.isNaN(e)||Number.isNaN(t))return NaN;if(t<0||e<0)return NaN;let r=o?-1/0:0,s=o?0:1;if(e===0)return t>0?n?s:r:NaN;if(t===0)return n?r:s;if(e===1/0)return t===1/0?NaN:n?r:s;if(t===1/0)return n?s:r;if(t>1e15*Math.max(e,1)){let u=(e-1)*Math.log(t)-t-K(e)+Math.log1p((e-1)/t);return n?o?Math.log1p(-Math.exp(u)):-Math.expm1(u):o?u:Math.exp(u)}let i=Math.abs(t-e)/e;if(e>K3&&e<R1&&i<Z3||e>R1&&i<J3/Math.sqrt(e)){let u=L1(e,t,n);return o?u>.5?Math.log1p(-L1(e,t,!n)):Math.log(u):u}if(o){let u=E0(e,t,!0);if(u.lower===n)return u.value;let l=E0(e,t,!1).value;return l>0?Math.log1p(-l):-Math.exp(u.value)}let c=E0(e,t,!1);return c.lower===n?c.value:1-c.value}export{v as a,r1 as b,I1 as c,d1 as d,S1 as e,Y6 as f,U6 as g,j6 as h,G as i,v0 as j,E3 as k,k as l,T as m,K as n,V as o,A as p,C as q,i4 as r,c4 as s,u4 as t,i1 as u,L0 as v,W3 as w,$3 as x,_4 as y,P4 as z,q3 as A,c6 as B,u6 as C,H3 as D};