@numero-uno-jpn/rstats 1.7.0 → 1.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.
- package/CHANGELOG.md +18 -0
- package/README.ja.md +3 -3
- package/README.md +3 -3
- package/dist/chunks/{chunk-76FLTZVF.js → chunk-2X6PE6JF.js} +2 -2
- package/dist/chunks/{chunk-YKNRDPIB.js → chunk-2ZQ2TSZS.js} +1 -1
- package/dist/chunks/{chunk-PCTRVBEJ.js → chunk-3DO726WZ.js} +2 -2
- package/dist/chunks/{chunk-THSV22QF.js → chunk-45HUI3M4.js} +2 -2
- package/dist/chunks/{chunk-QWDK3ZC2.js → chunk-52RWDNO6.js} +2 -2
- package/dist/chunks/{chunk-VQOU7U7R.js → chunk-53OM63EU.js} +2 -2
- package/dist/chunks/{chunk-MOJ2KIQE.js → chunk-73IRLCTF.js} +2 -2
- package/dist/chunks/{chunk-J7ZVV4DN.js → chunk-7ODUCEGX.js} +2 -2
- package/dist/chunks/chunk-ANZUXEMH.js +3 -0
- package/dist/chunks/chunk-BHQGMZTI.js +2 -0
- package/dist/chunks/{chunk-RIP2RKAW.js → chunk-D3LKPD4H.js} +2 -2
- package/dist/chunks/{chunk-FQRNZEH2.js → chunk-DG2RTNIR.js} +2 -2
- package/dist/chunks/{chunk-SDT3YHAG.js → chunk-GRTQ7FYQ.js} +2 -2
- package/dist/chunks/{chunk-R5BMFVIH.js → chunk-HXYH5ZMB.js} +2 -2
- package/dist/chunks/chunk-HYJ4MIZE.js +2 -0
- package/dist/chunks/{chunk-CUT3IHMY.js → chunk-IJST2ZGT.js} +1 -1
- package/dist/chunks/{chunk-B7XZMIQO.js → chunk-JIAFWEED.js} +2 -2
- package/dist/chunks/{chunk-TY3IFCLI.js → chunk-JXJDCQYE.js} +2 -2
- package/dist/chunks/{chunk-CZUOG2U5.js → chunk-LZB43TUL.js} +2 -2
- package/dist/chunks/{chunk-RX6MZO2Y.js → chunk-MLNWWGGE.js} +2 -2
- package/dist/chunks/{chunk-HSJ4OT3H.js → chunk-QQHF5T2A.js} +1 -1
- package/dist/chunks/{chunk-PLQQ4VFN.js → chunk-RWZ6ICYN.js} +2 -2
- package/dist/chunks/{chunk-JXEXOD7K.js → chunk-TQM6KGKT.js} +2 -2
- package/dist/chunks/{chunk-CB7STL5Z.js → chunk-TUL6UFLQ.js} +2 -2
- package/dist/chunks/{chunk-HORF36FD.js → chunk-TYMC2D5I.js} +2 -2
- package/dist/chunks/{chunk-BJMPSDJ7.js → chunk-V7ECXPWY.js} +2 -2
- package/dist/chunks/{chunk-AIEPW6DX.js → chunk-VB6PVRSN.js} +2 -2
- package/dist/chunks/{chunk-YVJ4LDDE.js → chunk-Y4KNH43T.js} +2 -2
- package/dist/chunks/{chunk-VALULDEX.js → chunk-YD4U3QZ3.js} +1 -1
- package/dist/chunks/{chunk-V2Y2W7LE.js → chunk-YT62DNDS.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/regression.d.ts +4 -0
- package/dist/entries/regression.js +6 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/gee.d.ts +280 -0
- package/dist/models/gee.js +704 -0
- package/dist/models/glmnet.d.ts +259 -0
- package/dist/models/glmnet.js +1112 -0
- package/dist/models/modelMatrix.d.ts +2 -0
- package/dist/models/rq.d.ts +203 -0
- package/dist/models/rq.js +1089 -0
- package/dist/numerics.js +2 -2
- package/dist/regression.js +3 -3
- package/dist/rstats.js +1 -1
- package/dist/special.js +2 -2
- package/dist/tests.js +15 -15
- package/llms.txt +3 -0
- package/package.json +1 -1
- package/dist/chunks/chunk-56AMJQ27.js +0 -2
- package/dist/chunks/chunk-B6KJ4RWG.js +0 -2
- package/dist/chunks/chunk-KSH43GX4.js +0 -2
- package/dist/chunks/chunk-LMRCFKVK.js +0 -2
- package/dist/chunks/chunk-R7F7ELS7.js +0 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{l as R}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.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{l as R}from"./chunk-2ZQ2TSZS.js";var _=23283064365386963e-26,w=2328306437080797e-25,c=class{mt=new Uint32Array(624);mti=625;setSeed(t){let e=t>>>0;for(let n=0;n<50;n++)e=Math.imul(69069,e)+1>>>0;e=Math.imul(69069,e)+1>>>0;for(let n=0;n<624;n++)e=Math.imul(69069,e)+1>>>0,this.mt[n]=e;this.mti=624}sgenrand(t){for(let e=0;e<624;e++)this.mt[e]=t&4294901760,t=Math.imul(69069,t)+1>>>0,this.mt[e]=(this.mt[e]|(t&4294901760)>>>16)>>>0,t=Math.imul(69069,t)+1>>>0;this.mti=624}nextUint32(){let t=this.mt;if(this.mti>=624||this.mti===0){this.mti===625&&this.sgenrand(4357);let n=0,o;for(;n<227;n++)o=t[n]&2147483648|t[n+1]&2147483647,t[n]=t[n+397]^o>>>1^(o&1?2567483615:0);for(;n<623;n++)o=t[n]&2147483648|t[n+1]&2147483647,t[n]=t[n+-227]^o>>>1^(o&1?2567483615:0);o=t[623]&2147483648|t[0]&2147483647,t[623]=t[396]^o>>>1^(o&1?2567483615:0),this.mti=0}let e=t[this.mti++];return e^=e>>>11,e^=e<<7&2636928640,e^=e<<15&4022730752,e^=e>>>18,e>>>0}nextDouble(){let t=this.nextUint32()*_;return t<=0?.5*w:1-t<=0?1-.5*w:t}getRandomSeed(t){let e=new Int32Array(626);e[0]=t,e[1]=this.mti;for(let n=0;n<624;n++)e[n+2]=this.mt[n]|0;return e}setRandomSeed(t){if(t.length!==626)throw new RangeError("the random seed state must have 626 integers");let e=t[1];if(!Number.isInteger(e)||e<0||e>2**31-1)throw new RangeError("the position in the random seed state must be a non-negative 32-bit integer");for(let n=0;n<624;n++){let o=t[n+2];if(!Number.isInteger(o)||o<-(2**31)||o>=2**32)throw new RangeError("the random seed state must hold 32-bit integers")}this.mti=e;for(let n=0;n<624;n++)this.mt[n]=t[n+2]>>>0}};var v=2328306549295728e-25,x=r=>Math.imul(69069,r)+1>>>0,a=class{s=new Float64Array(6);setSeed(t){let e=t>>>0;for(let n=0;n<50;n++)e=x(e);for(let n=0;n<6;n++){do e=x(e);while(e>=4294944443);this.s[n]=e}}nextDouble(){let t=this.s,e=(1403580*t[1]-810728*t[0])%4294967087;e<0&&(e+=4294967087),t[0]=t[1],t[1]=t[2],t[2]=e;let n=(527612*t[5]-1370589*t[3])%4294944443;return n<0&&(n+=4294944443),t[3]=t[4],t[4]=t[5],t[5]=n,(e>n?e-n:e-n+4294967087)*v}};function N(r){if(r.length!==7)throw new RangeError("the random seed state of L'Ecuyer-CMRG must have 7 integers");let t=[];for(let e=1;e<=6;e++){let n=r[e];if(!Number.isInteger(n)||n<-2147483648||n>4294967295)throw new RangeError("the random seed state must hold 32-bit integers");t.push(n>>>0)}if(t[0]===0&&t[1]===0&&t[2]===0||t.slice(0,3).some(e=>e>=4294967087)||t.slice(3).some(e=>e>=4294944443))throw new RangeError("invalid L'Ecuyer-CMRG state: the first three seeds must be below 4294967087 and not all zero, the last three below 4294944443");return t}var L=[3.3871328727963665,133.14166789178438,1971.5909503065513,13731.69376550946,45921.95393154987,67265.7709270087,33430.57558358813,2509.0809287301227],T=[1,42.31333070160091,687.1870074920579,5394.196021424751,21213.794301586597,39307.89580009271,28729.085735721943,5226.495278852854],G=[1.4234371107496835,4.630337846156546,5.769497221460691,3.6478483247632045,1.2704582524523684,.2417807251774506,.022723844989269184,.0007745450142783414],D=[1,2.053191626637759,1.6763848301838038,.6897673349851,.14810397642748008,.015198666563616457,.0005475938084995345,10507500716444169e-25],P=[6.657904643501103,5.463784911164114,1.7848265399172913,.29656057182850487,.026532189526576124,.0012426609473880784,27115555687434876e-21,20103343992922881e-23],U=[1,.599832206555888,.1369298809227358,.014875361290850615,.0007868691311456133,18463183175100548e-21,1421511758316446e-22,20442631033899397e-31];function f(r,t){let e=r[7];for(let n=6;n>=0;n--)e=e*t+r[n];return e}function b(r){let t=r-.5;if(Math.abs(t)<=.425){let o=.180625-t*t;return t*f(L,o)/f(T,o)}let e=t<0?r:1-r;e=Math.sqrt(-Math.log(e));let n;return e<=5?(e-=1.6,n=f(G,e)/f(D,e)):(e-=5,n=f(P,e)/f(U,e)),t<0?-n:n}var j=["kind","sampleKind"],u=new c,i=u,l=!1,h=!1;function p(r){i.setSeed(r),h=!0}function Q(){return h}function M(){if(h)return;let r=(Date.now()^Math.floor(Math.random()*2**32))>>>0;typeof globalThis.crypto?.getRandomValues=="function"&&(r=globalThis.crypto.getRandomValues(new Uint32Array(1))[0]),p(r)}function J(r){if(!Number.isFinite(r))throw new RangeError("seed must be a finite number");let t=Math.trunc(r);if(Math.abs(t)>2147483647)throw new RangeError("seed must be a 32-bit integer");p(t)}var O={default:!1,"Mersenne-Twister":!1,"L'Ecuyer-CMRG":!0},W={default:!1,Rejection:!1,Rounding:!0};function S(r,t,e){if(t===void 0)return;let n=r[t];if(typeof n!="boolean")throw new RangeError(`unsupported ${e} "${t}"`);return n}function Z(r={}){R(r,j,"RNGkind");let t={kind:i===u?"Mersenne-Twister":"L'Ecuyer-CMRG",normalKind:"Inversion",sampleKind:l?"Rounding":"Rejection"},e=S(O,r.kind,"RNG kind"),n=S(W,r.sampleKind,"sample kind");if((e!==void 0||n!==void 0)&&M(),e!==void 0){let o=Math.trunc(s()*4294967295);i=e?i===u?new a:i:u,p(o)}return n!==void 0&&(l=n),t}var y=()=>(i===u?3:7)+400+(l?0:1e4);function tt(){return M(),i===u?u.getRandomSeed(y()):Int32Array.of(y(),...i.s)}function et(r){let t=r[0],e=t%100;if(!Number.isInteger(t)||t<0||t>10407||e!==3&&e!==7||Math.floor(t/100)%100!==4)throw new RangeError(`unsupported RNG kind code ${String(t)} (supported: 10403, 403, 10407, 407)`);if(e===7){let n=new a;n.s.set(N(r)),i=n}else u.setRandomSeed(r),i=u;l=t<1e4,h=!0}function s(){return M(),i.nextDouble()}var nt=()=>l;function C(r){let t=2**Math.max(r-16,0),e=0;for(let n=0;n<=r;n+=16){let o=Math.floor(s()*65536);e=65536*(e%t)+o}return e%2**r}var E=33554432;function rt(r){if(l)return Math.floor(r*(r>2147483647?(Math.floor(E*s())+s())/E:s()));if(r<=0)return 0;let t=Math.ceil(Math.log2(r)),e;do e=C(t);while(r<=e);return e}var A=134217728;function ot(){let r=s();return r=Math.trunc(A*r)+s(),b(r/A)}var d=(()=>{let r=[],t=1,e=0;for(let n=1;n<=16;n++)t*=Math.LN2/n,e+=t,r.push(e);return r})();function it(){let r=0,t=s();for(;t<=0||t>=1;)t=s();for(;t+=t,!(t>1);)r+=d[0];if(t-=1,t<=d[0])return r+t;let e=0,n=s(),o=n;do n=s(),o>n&&(o=n),e++;while(t>d[e]);return r+o*d[0]}var I="@numero-uno-jpn/rstats.warningHandler";function K(){return globalThis[Symbol.for(I)]??null}function ut(r){if(r!==null&&typeof r!="function")throw new TypeError("handler must be a function or null");let t=K();return globalThis[Symbol.for(I)]=r,t}var g=0;function H(r,t){if(g>0||t.length===0)return;let e=K();if(e!==null)for(let n of new Set(t))e(n,r)}function ft(r,t,...e){let n=new Set(e.flatMap(o=>X(o)));return H(r,(t.warnings??[]).filter(o=>!n.has(o))),t}function X(r){let t=typeof r=="object"&&r!==null?r.warnings:void 0;return Array.isArray(t)?t.filter(e=>typeof e=="string"):[]}function lt(r){g++;try{return r()}finally{g--}}var k=class{list=[];add(t){this.list.includes(t)||this.list.push(t)}},m;function at(r,t){let e=m;m=r;try{return t()}finally{m=e}}function ct(r){m?.add(r)}export{N as a,Q as b,J as c,Z as d,tt as e,et as f,s as g,nt as h,rt as i,ot as j,it as k,ut as l,H as m,ft as n,lt as o,k as p,at as q,ct as r};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{
|
|
1
|
+
/*! rStats.js 1.8.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as M,b as st,d as at}from"./chunk-7ODUCEGX.js";import{E as ot}from"./chunk-HYJ4MIZE.js";import{g as it}from"./chunk-HXYH5ZMB.js";import{g as x,j as v,k as w}from"./chunk-TQM6KGKT.js";import{a as ft}from"./chunk-YD4U3QZ3.js";import{f as et}from"./chunk-73IRLCTF.js";import{d as rt,j as nt,k as Z,l as k}from"./chunk-2ZQ2TSZS.js";var _t=["rate","scale"],Qt=["ncp"],Ot=["ncp"],St=["ncp"],Tt=5.656854,dt=.36787944117144233,Kt=.04166669,Yt=.02083148,Lt=.00801191,Xt=.00144121,Bt=-7388e-8,Ct=24511e-8,Gt=2424e-7,Pt=.3333333,jt=-.250003,Dt=.2000062,Ht=-.1662921,Ut=.1423657,Vt=-.1367177,Jt=.1233795,ut=0,ct=0,g=0,E=0,mt=0,$=0,O=0,S=0,C=0;function lt(t){let r=t/(g+g);return Math.abs(r)<=.25?$+.5*t*t*((((((Jt*r+Vt)*r+Ut)*r+Ht)*r+Dt)*r+jt)*r+Pt)*r:$-g*t+.25*t*t+(E+E)*Math.log(1+r)}function q(t,r){if(Number.isNaN(t)||Number.isNaN(r))return NaN;if(t<0||r<0)return NaN;if(t===0||r===0)return 0;if(!Number.isFinite(t)||!Number.isFinite(r))return 1/0;if(t<1){let o=1+dt*t,s,m;for(;;)if(m=o*x(),m>=1){if(s=-Math.log((o-m)/t),w()>=(1-t)*Math.log(s))break}else if(s=Math.exp(Math.log(m)/t),w()>=s)break;return s<2**-1022&&r>1?et(rt(Z([r,0]),nt(Z([m,0]),t)))[0]:r*s}t!==ut&&(ut=t,E=t-.5,g=Math.sqrt(E),mt=Tt-g*12);let n=v(),e=g+.5*n,i=e*e;if(n>=0)return r*i;let f=x();if(mt*f<=n*n*n)return r*i;if(t!==ct){ct=t;let o=1/t;$=((((((Gt*o+Ct)*o+Bt)*o+Xt)*o+Lt)*o+Yt)*o+Kt)*o,t<=3.686?(O=.463+g+.178*E,S=1.235,C=.195/g-.079+.16*g):t<=13.022?(O=1.654+.0076*E,S=1.68/g+.275,C=.062/g+.024):(O=1.77,S=.75,C=.1515/g)}if(e>0){let o=lt(n);if(Math.log(1-f)<=o)return r*i}for(;;){let o=w();if(f=x(),f=f+f-1,n=f<0?O-S*o:O+S*o,n>=-.71874483771719){let s=lt(n);if(s>0){let m=Math.expm1(s);if(C*Math.abs(f)<=m*Math.exp(o-.5*n*n))break}}}return e=g+.5*n,r*e*e}function Ar(t,r,n={}){k(n,_t,"rgamma");let e=it(n);return M(t,()=>q(r,e))}function T(t){return!Number.isFinite(t)||t<0?NaN:q(t/2,2)}function Wt(t,r){if(Number.isNaN(t)||!Number.isFinite(r)||t<0||r<0)return NaN;if(r===0)return t===0?0:q(t/2,2);let n=I(r/2);return n>0&&(n=T(2*n)),t>0&&(n+=q(t/2,2)),n}function G(t,r,n={}){k(n,Qt,"rchisq");let{ncp:e}=n;return e===void 0?M(t,()=>T(r)):M(t,()=>Wt(r,e))}function Fr(t,r,n={}){k(n,Ot,"rt");let{ncp:e}=n;if(e===void 0)return M(t,()=>Number.isNaN(r)||r<=0?NaN:Number.isFinite(r)?v()/Math.sqrt(T(r)/r):v());if(Number.isNaN(e))return M(t,()=>NaN);let i=M(t,()=>at(e,1));if(r===1/0)return i;let f=G(t,r);return i.map((o,s)=>o/Math.sqrt(f[s]/r))}function yr(t,r,n,e={}){k(e,St,"rf");let{ncp:i}=e;if(i===void 0)return M(t,()=>{if(Number.isNaN(r)||Number.isNaN(n)||r<=0||n<=0)return NaN;let s=Number.isFinite(r)?T(r)/r:1,m=Number.isFinite(n)?T(n)/n:1;return s/m});let f=r===1/0?G(t,r,{ncp:i}).map(s=>Number.isNaN(s)?NaN:1):G(t,r,{ncp:i}).map(s=>s/r),o=n===1/0?M(t,()=>1):G(t,n).map(s=>s/n);return r>0&&n>0?f.map((s,m)=>s/o[m]):f.map(()=>NaN)}var Zt=["prob","mu"],$t=-.5,zt=.3333333,tr=-.2500068,rr=.2000118,nr=-.1661269,er=.1421878,ir=-.1384794,or=.125006,fr=1/7,sr=1/12,ar=1/24,Nt=.3989422804014327,ur=[1,1,2,6,24,120,720,5040,40320,362880],A=0,ht=0,pt=new Float64Array(36),P=0,Mt=0,z=0,j=0,bt=0,d=0,xt=0,gt=0,At=0,_=0,K=0,Ft=0,yt=0,kt=0,wt=0,Y=0;function I(t){if(!Number.isFinite(t)||t<0)return NaN;if(t<=0)return 0;let r=t>=10,n=!1;if(!(r&&t===P))if(r)n=!0,P=t,d=Math.sqrt(t),xt=6*t*t,At=Math.floor(t-1.1484);else for(t!==P&&(P=t,ht=Math.max(1,Math.trunc(t)),A=0,j=bt=z=Math.exp(-t));;){let h=x();if(h<=bt)return 0;if(A>0){let l=h>.458?Math.min(A,ht):1;for(let p=l;p<=A;p++)if(h<=pt[p])return p;if(A===35)continue}A++;for(let l=A;l<=35;l++)if(z*=t/l,j+=z,pt[l]=j,h<=j)return A=l,l;A=35}let e=-1,i=0,f=0,o=0,s=t+d*v();if(s>=0&&(e=Math.floor(s),e>=At||(i=e,f=t-i,o=x(),xt*o>=f*f*f)))return e;(n||t!==Mt)&&(Mt=t,gt=Nt/d,_=ar/t,K=.3*_*_,Y=fr*_*K,wt=K-15*Y,kt=_-6*K+45*Y,yt=1-_+3*K-15*Y,Ft=.1069/t);let m=0,u=0,a=0,N=0,c=()=>{if(e<10)m=-t,u=Math.pow(t,e)/ur[e];else{let p=sr/i;p=p*(1-4.8*p*p);let b=f/i;Math.abs(b)<=.25?m=i*b*b*(((((((or*b+ir)*b+er)*b+nr)*b+rr)*b+tr)*b+zt)*b+$t)-p:m=i*Math.log(1+b)-f-p,u=Nt/Math.sqrt(i)}let h=(.5-f)/d,l=h*h;a=-.5*l,N=gt*(((Y*l+wt)*l+kt)*l+yt)};if(s>=0&&(c(),N-o*N<=u*Math.exp(m-a)))return e;for(;;){let h=w();o=2*x()-1;let l=1.8+(o>=0?h:-h);if(l>-.6744&&(e=Math.floor(t+d*l),i=e,f=t-i,c(),Ft*Math.abs(o)<=u*Math.exp(m+h)-N*Math.exp(a+h)))break}return e}function Er(t,r){return M(t,()=>I(r))}function Ir(t,r){return M(t,()=>{if(!Number.isFinite(r)||r<=0||r>1)return NaN;let n=(1-r)/r,e=w(),i=Number.isFinite(n)?e*n:e*(1-r)/r;return i===1/0?1/0:I(i)})}function qt(t,r,n){let e=r/n;if(Number.isFinite(e))return I(q(t,e));let i=q(t,1)*r/n;return i===1/0?1/0:I(i)}function _r(t,r,n){k(n,Zt,"rnbinom");let{prob:e,mu:i}=n;if(e===void 0==(i===void 0))throw new TypeError("specify exactly one of prob and mu");let f=Number.isFinite(r)?r:Number.MAX_VALUE/2;if(i!==void 0)return M(t,()=>!Number.isFinite(i)||Number.isNaN(r)||r<=0||i<0?NaN:i===0?0:qt(f,i,f));let o=e;return M(t,()=>{if(!Number.isFinite(o)||Number.isNaN(r)||r<=0||o<=0||o>1)return NaN;if(o===1)return 0;let s=qt(f,1-o,o);return r===1/0?1/0:s})}var cr=2147483647,R=0,L=0,Q=0,y=0,D=0,H=0,Rt=0,vt=0,X=0,U=0,V=0,B=0,J=0,tt=-1,Et=-1,F=0;function W(t){let r=t*t;return(13860-(462-(132-(99-140/r)/r)/r)/r)/t/166320}function mr(t,r,n,e,i){let f=i+1,o=e+1,s=t+1-e,m=t-i+1;return(e+.5)*Math.log(o/f)+(t-e+.5)*Math.log(s/m)+(i-e)*Math.log(m*r/(f*n))+W(o)+W(s)-W(f)-W(m)}function It(t,r){if(!Number.isFinite(t))return NaN;let n=Math.round(t);if(n!==t)return NaN;if(!Number.isFinite(r)||n<0||r<0||r>1)return NaN;if(n===0||r===0)return 0;if(r===1)return n;if(n>=cr)return ot(x(),n,r,{lowerTail:!1});let e=n,i=Math.min(r,1-r),f=1-i,o=e*i,s=i/f,m=s*(e+1),u;if(r!==tt||e!==Et)if(tt=r,Et=e,o<30)vt=f===1&&i>0?Math.exp(e*Math.log1p(-i)):st(f,e),u=!0;else{u=!1,L=o+i,F=Math.trunc(L),Q=o*f,y=Math.trunc(2.195*Math.sqrt(Q)-4.6*f)+.5,B=F+.5,X=B-y,J=B+y,R=.134+20.5/(15.3+F);let N=(L-X)/(L-X*i);U=N*(1+.5*N),N=(J-L)/(J*f),V=N*(1+.5*N),D=y*(1+R+R),H=D+R/U,Rt=H+R/V}else u=o<30;let a;if(u)t:for(;;){a=0;let N=vt,c=x();for(;;){if(c<N)break t;if(a>110)break;c-=N,a++,N*=m/a-s}}else for(;;){let N=x()*Rt,c=x();if(N<=y){a=Math.trunc(B-y*c+N);break}if(N<=D){let l=X+(N-y)/R;if(c=c*R+1-Math.abs(B-l)/y,c>1||c<=0)continue;a=Math.trunc(l)}else if(N>H){if(a=Math.trunc(J-Math.log(c)/V),a>e)continue;c=c*(N-H)*V}else{if(a=Math.trunc(X+Math.log(c)/U),a<0)continue;c=c*(N-D)*U}let h=Math.abs(a-F);if(h<=20||h>=Q/2-1){let l=1;if(F<a)for(let p=F+1;p<=a;p++)l*=m/p-s;else if(F>a)for(let p=a+1;p<=F;p++)l/=m/p-s;if(c<=l)break}else{let l=h/Q*((h*(h/3+.625)+.1666666666666)/Q+.5),p=-h*h/(2*Q),b=Math.log(c);if(b<p-l||b<=p+l&&b<=mr(e,i,f,F,a))break}}return tt>.5&&(a=e-a),a}function Kr(t,r,n){return M(t,()=>It(r,n))}function Yr(t,r,n){if(!Number.isFinite(r)||r<=-1||r>=2147483648)throw new RangeError("size must be non-negative, truncated to an integer up to 2147483647");let e=Math.max(0,Math.trunc(r)),i=0;for(let u of n){if(!Number.isFinite(u)||u<0)throw new RangeError("prob must contain non-negative finite numbers");i+=u}if(i===0)throw new RangeError("prob must contain at least one positive value");let f;if(i===1/0){let u=ft(n);i=0;for(let a of n)i+=a/u;f=n.map(a=>a/u/i)}else f=n.map(u=>u/i);let o=f.length,s=new Array(o+1).fill(0);for(let u=o-1;u>=0;u--)s[u]=s[u+1]+f[u];let m=()=>{let u=new Array(o).fill(0),a=e,N=1;for(let c=0;c<o-1;c++){if(f[c]){let h=f[c]/N;h>=1&&s[c+1]>0&&(h=f[c]/s[c]),u[c]=h<1?It(a,h):a,a-=u[c]}if(a<=0)return u;N-=f[c]}return u[o-1]=a,u};if(!Number.isFinite(t)||t<=-1)throw new RangeError("n must be a non-negative finite number");return Array.from({length:Math.trunc(t)},m)}export{I as a,Er as b,Ir as c,_r as d,q as e,Ar as f,G as g,Fr as h,yr as i,It as j,Kr as k,Yr as l};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{l as N,s as R}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.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{l as N,s as R}from"./chunk-2X6PE6JF.js";import{a as w}from"./chunk-YD4U3QZ3.js";import{P as b,l as g,u as d,w as S,x,y as A}from"./chunk-2ZQ2TSZS.js";var K=["type"],Y=["type"],D=["naRm"],I=["center"],O=["unbiased","naRm"],T=["center","scale"];function _(a){let n=b([a]).groups[0],e=S(n),t=n.map(l=>l-e[0]-e[1]),s=0;for(let l of t)s=Math.max(s,Math.abs(l));let r=s>0&&(s<2**-120||s>2**120)?2**-Math.floor(Math.log2(s)):1,u=0,f=0,M=0;for(let l of t){let m=l*r,i=m*m;u+=i,f+=i*m,M+=i*i}return[u,f,M]}function k(a){if(![1,2,3].includes(a))throw new RangeError("Invalid 'type' argument.")}function L(a,n={}){g(n,K,"skewness");let e=n.type??3;k(e);let t=N(a,!0),s=t.length,[r,u]=_(t),f=Math.sqrt(s)*u/r**1.5;if(e===1)return f;if(e===2){if(s<3)throw new RangeError("Need at least 3 complete observations.");return f*Math.sqrt(s*(s-1))/(s-2)}return f*(1-1/s)**1.5}function V(a,n={}){g(n,Y,"kurtosis");let e=n.type??3;k(e);let t=N(a,!0),s=t.length,[r,,u]=_(t),f=s*u/(r*r);if(e===1)return f-3;if(e===2){if(s<4)throw new RangeError("Need at least 4 complete observations.");return((s+1)*(f-3)+6)*(s-1)/((s-2)*(s-3))}return f*(1-1/s)**2-3}function W(a,n={}){g(n,D,"geometricMean");let e=N(a,n.naRm);return e===void 0?NaN:e.some(t=>t<0)?NaN:e.includes(0)?0:Math.exp(x(e.map(Math.log)))}function z(a){let n=N(a,!0),e=new Map;for(let r of n)e.set(r===0?0:r,(e.get(r===0?0:r)??0)+1);let t=0;for(let r of e.values())t=Math.max(t,r);return t<=1?{value:[NaN],frequency:NaN}:{value:[...e.entries()].filter(([,r])=>r===t).map(([r])=>r).sort((r,u)=>r-u),frequency:t}}function B(a,n={}){g(n,I,"meanAD");let e=n.center??"mean",{groups:t,k:s}=b([N(a,!0),typeof e=="number"?[e]:[]]),r=t[0],u=e==="mean"?x(r):e==="median"?R(r):t[1][0];return d(x(r.map(f=>Math.abs(f-u))),s)}function H(a,n={}){g(n,O,"cv");let e=N(a,n.naRm);if(e===void 0)return NaN;let t=e.length,s=b([e]).groups[0],r=Math.sqrt(A(s))/x(s);return n.unbiased&&(r*=1-1/(4*(t-1))+r*r/t+1/(2*(t-1)**2)),r}function q(a){let n=0;for(let t of a)n+=t*t;let e=w(a.map(Math.abs));if((n===1/0||n<2**-960)&&e>0&&e<1/0){n=0;for(let t of a)n+=(t/e)**2;return Math.sqrt(n/Math.max(1,a.length-1))*e}return Math.sqrt(n/Math.max(1,a.length-1))}function J(a,n={}){g(n,T,"scale");let e=a.length>0&&Array.isArray(a[0])?a.map(o=>[...o]):Array.from(a,o=>[o]),t=e[0]?.length??0;if(e.some(o=>o.length!==t))throw new TypeError("all rows of the matrix must have the same length");let s=o=>e.map(c=>c[o]),r={scaled:e},u=e.map(o=>o.slice()),f=[],M=n.center??!0,l;if(M!==!1){if(l=M===!0?Array.from({length:t},(o,c)=>x(s(c).filter(h=>!Number.isNaN(h)))):[...M],l.length!==t)throw new RangeError("length of 'center' must equal the number of columns of 'x'");for(let o of e)for(let c=0;c<t;c++)o[c]=o[c]-l[c];r.center=l;for(let o=0;o<t;o++)Number.isFinite(l[o])&&e.some((c,h)=>!Number.isFinite(c[o])&&Number.isFinite(u[h][o]))&&f.push(o)}let m=n.scale??!0,i;if(m!==!1){if(i=m===!0?Array.from({length:t},(o,c)=>q(s(c).filter(h=>!Number.isNaN(h)))):[...m],i.length!==t)throw new RangeError("length of 'scale' must equal the number of columns of 'x'");for(let o of e)for(let c=0;c<t;c++)o[c]=o[c]/i[c];r.scale=i}for(let o of f){let c=Math.floor(Math.log2(w(u.map(p=>Math.abs(p[o])).filter(Number.isFinite)))),h=d(l[o],-c),y=u.map(p=>d(p[o],-c)-h),E=1;i!==void 0&&(m===!0?(E=q(y.filter(p=>!Number.isNaN(p))),i[o]=d(E,c)):E=d(i[o],-c)),e.forEach((p,v)=>p[o]=i===void 0?d(y[v],c):y[v]/E)}return r}export{L as a,V as b,W as c,z as d,B as e,H as f,J as g};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{a as f,b as h,c as q}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.8.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as f,b as h,c as q}from"./chunk-HYJ4MIZE.js";import{h as m,i as p,l as u}from"./chunk-HXYH5ZMB.js";import{e as a}from"./chunk-73IRLCTF.js";import{l as s}from"./chunk-2ZQ2TSZS.js";var g=["log","ncp"],N=["lowerTail","logP","ncp"],S=["lowerTail","logP","ncp"];function T(c,n,r={}){s(r,g,"dchisq");let{log:o=!1,ncp:e}=r;if(e!==void 0)return a(c,i=>f(i,n,e,o));let t=n<0?NaN:n/2;return a(c,i=>m(i,t,2,o))}function C(c,n,r={}){s(r,N,"pchisq");let{lowerTail:o=!0,logP:e=!1,ncp:t}=r;if(t!==void 0)return a(c,l=>h(l,n,t,o,e));let i=n<0?NaN:n/2;return a(c,l=>p(l,i,2,o,e))}function E(c,n,r={}){s(r,S,"qchisq");let{lowerTail:o=!0,logP:e=!1,ncp:t}=r;if(t!==void 0)return a(c,l=>q(l,n,t,o,e));let i=n<0?NaN:n/2;return a(c,l=>u(l,i,2,o,e))}export{T as a,C as b,E as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{l as x,u as q}from"./chunk-YKNRDPIB.js";function v(s,r){return{nrow:s,ncol:r,data:new Float64Array(s*r)}}function R(s){return s.length>0&&typeof s[0]!="number"}function k(s){let r=s.length,t=r===0?0:s[0].length,o=v(r,t);for(let e=0;e<r;e++){let a=s[e];if(a.length!==t)throw new TypeError("all rows of the matrix must have the same length");for(let i=0;i<t;i++)o.data[e+i*r]=a[i]}return o}function F(s){if(R(s))return k(s);let r=s;return{nrow:r.length,ncol:1,data:Float64Array.from(r)}}function M(s){let r=[];for(let t=0;t<s.nrow;t++){let o=new Array(s.ncol);for(let e=0;e<s.ncol;e++)o[e]=s.data[t+e*s.nrow];r.push(o)}return r}function rt(s){let r=v(s.ncol,s.nrow);for(let t=0;t<s.ncol;t++)for(let o=0;o<s.nrow;o++)r.data[t+o*s.ncol]=s.data[o+t*s.nrow];return r}function Q(s,r="the matrix"){if(s.nrow!==s.ncol)throw new TypeError(`${r} must be square (got ${s.nrow} x ${s.ncol})`)}function S(s){let r=0;for(let t=0;t<s.length;t++)r=Math.max(r,Math.abs(s[t]));return r===0||r>=2**-256&&r<=2**256?0:Math.floor(Math.log2(r))}function L(s,r=256){let t=S(s);return t>0?Math.max(0,t-r):t}var Y=["tol","lapack"],C=["complete","dvec"],W=["complete"],X=["complete","ncol"],H=["k"],V=["tol"];function D(s,r={}){x(r,Y,"qr");let t=k(s);if(r.lapack){let m=t.data.slice(),{tau:l,pivot:c}=O(t);if(m.every(Number.isFinite)&&!(t.data.every(Number.isFinite)&&l.every(Number.isFinite))){let u=L(m);if(u!==0){let w=t.nrow;for(let p=0;p<m.length;p++)t.data[p]=q(m[p],-u);({tau:l,pivot:c}=O(t));for(let p=0;p<t.ncol;p++)for(let d=0;d<=Math.min(p,w-1);d++)t.data[d+p*w]=q(t.data[d+p*w],u)}}let n=Array.from(l);return{qr:M(t),rank:Math.min(t.nrow,t.ncol),qraux:n,pivot:c.map(u=>u-1),useLapack:!0}}for(let m of t.data)if(!Number.isFinite(m))throw new RangeError("the matrix contains NaN or infinite values");let o=r.tol??1e-7;if(!(o>=0&&o<1/0))throw new RangeError("'tol' must be a non-negative finite number");let e=t.data.slice(),{qraux:a,pivot:i,rank:f,transformed:h}=z(t,o);if(!(t.data.every(Number.isFinite)&&a.every(Number.isFinite))){let m=t.nrow,l=Array.from({length:t.ncol},(c,n)=>S(e.subarray(n*m,(n+1)*m)));if(l.some(c=>c!==0)){for(let c=0;c<t.ncol;c++)for(let n=0;n<m;n++)t.data[n+c*m]=q(e[n+c*m],-l[c]);({qraux:a,pivot:i,rank:f,transformed:h}=z(t,o));for(let c=0;c<t.ncol;c++){let n=l[i[c]-1];if(n!==0){for(let u=0;u<=Math.min(c,m-1);u++)t.data[u+c*m]=q(t.data[u+c*m],n);h[c]||(a[c]=q(a[c],n))}}}}return{qr:M(t),rank:f,qraux:Array.from(a),pivot:i.map(m=>m-1),useLapack:!1}}function b(s,r,t){let o=0;for(let a=0;a<t;a++)o=Math.max(o,Math.abs(s[r+a]));if(o===0||!Number.isFinite(o))return o;let e=0;for(let a=0;a<t;a++){let i=s[r+a]/o;e+=i*i}return o*Math.sqrt(e)}function z(s,r){let t=s.nrow,o=s.ncol,e=s.data,a=new Float64Array(o),i=new Float64Array(o),f=new Uint8Array(o),h=Array.from({length:o},(n,u)=>u+1);for(let n=0;n<o;n++)a[n]=b(e,n*t,t),i[n]=a[n]===0?1:a[n];let m=new Float64Array(t),l=Math.min(t,o),c=o;for(let n=0;n<l;n++){for(;n<c&&a[n]<i[n]*r;){m.set(e.subarray(n*t,(n+1)*t));let[p,d,N]=[a[n],i[n],h[n]];e.copyWithin(n*t,(n+1)*t,o*t),e.set(m,(o-1)*t),a.copyWithin(n,n+1),i.copyWithin(n,n+1),h.copyWithin(n,n+1),a[o-1]=p,i[o-1]=d,h[o-1]=N,c--}if(n===t-1)break;let u=n*t,w=b(e,u+n,t-n);if(w!==0){e[u+n]!==0&&(w=Math.sign(e[u+n])*Math.abs(w));for(let p=n;p<t;p++)e[u+p]/=w;e[u+n]=1+e[u+n];for(let p=n+1;p<o;p++){let d=p*t,N=0;for(let g=n;g<t;g++)N-=e[u+g]*e[d+g];N/=e[u+n];for(let g=n;g<t;g++)e[d+g]+=N*e[u+g];if(a[p]===0)continue;let $=Math.max(1-(Math.abs(e[d+n])/a[p])**2,0);$<1e-6?a[p]=b(e,d+n+1,t-n-1):a[p]*=Math.sqrt($)}a[n]=e[u+n],f[n]=1,e[u+n]=-w}}return{qraux:a,pivot:h,rank:Math.min(c,t),transformed:f}}function O(s){let r=s.nrow,t=s.ncol,o=s.data,e=Math.min(r,t),a=new Float64Array(e),i=Array.from({length:t},(l,c)=>c+1),f=new Float64Array(t),h=new Float64Array(t);for(let l=0;l<t;l++)f[l]=b(o,l*r,r),h[l]=f[l];let m=Math.sqrt(2**-53);for(let l=0;l<e;l++){let c=l;for(let u=l+1;u<t;u++)Math.abs(f[u])>Math.abs(f[c])&&(c=u);if(c!==l){for(let u=0;u<r;u++){let w=o[u+c*r];o[u+c*r]=o[u+l*r],o[u+l*r]=w}[i[c],i[l]]=[i[l],i[c]],f[c]=f[l],h[c]=h[l]}let n=l*r;a[l]=P(o,n+l,r-l),l<t-1&&I(o,n+l,r-l,a[l],s,l,l+1,t-l-1);for(let u=l+1;u<t;u++){if(f[u]===0)continue;let w=1-(Math.abs(o[l+u*r])/f[u])**2;w=Math.max(w,0),w*(f[u]/h[u])**2<=m?l<r-1?(f[u]=b(o,u*r+l+1,r-l-1),h[u]=f[u]):(f[u]=0,h[u]=0):f[u]*=Math.sqrt(w)}}return{tau:a,pivot:i}}function P(s,r,t){if(t<=1)return 0;let o=b(s,r+1,t-1);if(o===0)return 0;let e=s[r],a=-Math.sign(e||1)*Math.hypot(e,o),i=2**-1022/2**-53,f=0;if(Math.abs(a)<i){let l=1/i;do{f++;for(let c=1;c<t;c++)s[r+c]*=l;a*=l,e*=l}while(Math.abs(a)<i&&f<20);o=b(s,r+1,t-1),a=-Math.sign(e||1)*Math.hypot(e,o)}let h=(a-e)/a,m=1/(e-a);for(let l=1;l<t;l++)s[r+l]*=m;for(let l=0;l<f;l++)a*=i;return s[r]=a,h}function ct(s,r,t,o,e,a,i,f){if(o===0)return;let h=e.nrow,m=e.data;for(let l=i;l<i+f;l++){let c=a+l*h,n=0;for(let u=0;u<t;u++)n+=m[c+u]*s[r+u];n*=o;for(let u=0;u<t;u++)m[c+u]-=s[r+u]*n}}function I(s,r,t,o,e,a,i,f){if(o===0)return;let h=t;for(;h>1&&s[r+h-1]===0;)h--;let m=e.nrow,l=e.data;for(let c=i;c<i+f;c++){let n=a+c*m;if(h===1){l[n]*=1-o;continue}let u=0;for(let p=1;p<h;p++)u+=l[n+p]*s[r+p];u+=l[n];let w=-o*u;l[n]+=w;for(let p=1;p<h;p++)l[n+p]+=s[r+p]*w}}function E(s){return{a:k(s.qr),qraux:s.qraux,rank:s.rank,pivot:s.pivot.map(r=>r+1),lapack:s.useLapack}}function A(s,r){let t=F(r);if(t.nrow!==s.a.nrow)throw new TypeError(`qr and y must have the same number of rows (${s.a.nrow} and ${t.nrow})`);return t}function j(s,r){return R(s)?M(r):Array.from(r.data)}function y(s,r,t,o=s.rank){let{a:e,qraux:a}=s,i=e.nrow;if(s.lapack){let m=Math.min(i,e.ncol),l=t?_(0,m):_(0,m).reverse();for(let c of l)I(e.data,c+c*i,i-c,a[c],r,c,0,r.ncol);return}let f=Math.min(o,i-1),h=t?_(0,f):_(0,f).reverse();for(let m of h){if(a[m]===0)continue;let l=m*i,c=e.data[l+m];e.data[l+m]=a[m];for(let n=0;n<r.ncol;n++){let u=n*i,w=0;for(let p=m;p<i;p++)w-=e.data[l+p]*r.data[u+p];w/=e.data[l+m];for(let p=m;p<i;p++)r.data[u+p]+=w*e.data[l+p]}e.data[l+m]=c}}function _(s,r){return Array.from({length:Math.max(0,r-s)},(t,o)=>s+o)}function st(s,r){let t=E(s),o=A(t,r);return y(t,o,!0),j(r,o)}function lt(s,r){let t=E(s),o=A(t,r);return y(t,o,!1),j(r,o)}function U(s,r){let t=E(s),o=A(t,r),e=t.a.ncol,a=t.a.nrow,i=t.lapack?Math.min(a,e):t.rank;y(t,o,!0);for(let h=0;h<o.ncol;h++){let m=h*a;for(let l=i-1;l>=0;l--){let c=t.a.data[l+l*a];if(c===0)throw new Error("exact singularity in qrCoef");o.data[m+l]/=c;let n=-o.data[m+l];for(let u=0;u<l;u++)o.data[m+u]+=n*t.a.data[u+l*a]}}let f=v(e,o.ncol);f.data.fill(NaN);for(let h=0;h<o.ncol;h++)for(let m=0;m<i;m++)f.data[t.pivot[m]-1+h*e]=o.data[m+h*a];return j(r,f)}function K(s,r,t,o){let e=E(s);if(e.lapack)throw new TypeError("not supported for a QR decomposition computed with lapack: true");let a=o??e.rank;if(!Number.isInteger(a)||a<0||a>e.rank)throw new RangeError(`invalid k (got ${a})`);let i=A(e,r),f=e.a.nrow;if(a===0)return j(r,i);if(f===1)return t||i.data.fill(0),j(r,i);y(e,i,!0,a);for(let h=0;h<i.ncol;h++)t?i.data.fill(0,h*f+a,(h+1)*f):i.data.fill(0,h*f,h*f+a);return y(e,i,!1,a),j(r,i)}function ft(s,r){return K(s,r,!1)}function ut(s,r,t={}){return x(t,H,"qrFitted"),K(s,r,!0,t.k)}function ht(s,r={}){x(r,C,"qrQ");let t=E(s),o=t.a.nrow,e=r.complete?o:Math.min(o,t.a.ncol),a=r.dvec??new Array(e).fill(1);if(a.length!==e)throw new RangeError(`dvec must have length ${e}`);let i=v(o,e);for(let f=0;f<e;f++)i.data[f+f*o]=a[f];return y(t,i,!1),M(i)}function mt(s,r={}){x(r,W,"qrR");let t=k(s.qr),o=r.complete?t.nrow:Math.min(t.nrow,t.ncol),e=v(o,t.ncol);for(let a=0;a<t.ncol;a++)for(let i=0;i<=Math.min(a,o-1);i++)e.data[i+a*o]=t.data[i+a*t.nrow];return M(e)}function pt(s,r={}){x(r,X,"qrX");let t=E(s),o=t.a.nrow,e=t.a.ncol,a=r.complete??!1,i=r.ncol??(a?o:Math.min(o,e));if(!Number.isInteger(i)||i<0)throw new RangeError(`invalid ncol (got ${i})`);if(i>Math.max(o,e))throw new RangeError(`ncol must be at most max(nrow, ncol of x) = ${Math.max(o,e)} (got ${i})`);if(t.pivot.some((c,n)=>c!==n+1)&&i<e)throw new RangeError("ncol must be at least the number of columns because the decomposition is pivoted");let h=v(o,i);for(let c=0;c<i;c++)if(c<e)for(let n=0;n<=Math.min(c,o-1);n++)h.data[n+c*o]=t.a.data[n+c*o];else c<o&&(h.data[c+c*o]=1);y(t,h,!1);let m=Math.min(i,e),l=v(o,i);l.data.set(h.data);for(let c=0;c<m;c++){let n=t.pivot[c]-1;n<m&&l.data.set(h.data.subarray(c*o,(c+1)*o),n*o)}return M(l)}function wt(s,r,t={}){x(t,V,"qrSolve");let o=Array.isArray(s)?D(s,{tol:t.tol??1e-7}):s,e=o.qr.length,a=e===0?0:o.qr[0].length;if(o.rank!==Math.min(e,a))throw new Error("singular matrix in qrSolve");if(o.useLapack){let l=t.tol??1e-7,c=Math.abs(o.qr[0]?.[0]??0);for(let n=0;n<Math.min(e,a);n++)if(!(Math.abs(o.qr[n][n])>l*c))throw new Error("singular matrix in qrSolve")}if(r===void 0&&e!==a)throw new TypeError("only square matrices can be inverted");let i=r??Array.from({length:e},(l,c)=>Array.from({length:e},(n,u)=>c===u?1:0)),f=U(o,i),h=new Set(o.pivot.slice(Math.min(e,a)));if(R(i)){let l=f;for(let c of h)l[c].fill(0);return l}let m=f;for(let l of h)m[l]=0;return m}var B=["pivot","tol"],G=["size"];function vt(s,r={}){x(r,B,"chol");let t=k(s);if(Q(t),t.nrow===0)throw new RangeError("the matrix has zero dimension");if(r.pivot){let e=r.tol??-1;if(Number.isNaN(e))throw new RangeError("'tol' must not be NaN");let{pivot:a,rank:i}=tt(t,e);return T(t),J(t,i),{r:M(t),pivot:a.map(f=>f-1),rank:i}}let o=Z(t);if(o>0)throw new Error(`the matrix is not positive definite: the leading minor of order ${o} is not positive`);return T(t),M(t)}function T(s){let r=s.nrow;for(let t=0;t<r;t++)for(let o=t+1;o<r;o++)s.data[o+t*r]=0}function J(s,r){let t=s.nrow;for(let o=r;o<t;o++)for(let e=r;e<t;e++)s.data[e+o*t]=0}function Z(s){let r=s.nrow,t=s.data;for(let o=0;o<r;o++){let e=o*r,a=t[o+e];for(let i=0;i<o;i++)a-=t[i+e]*t[i+e];if(a<=0)return t[o+e]=a,o+1;a=Math.sqrt(a),t[o+e]=a;for(let i=o+1;i<r;i++){let f=i*r,h=t[o+f];for(let m=0;m<o;m++)h-=t[m+e]*t[m+f];t[o+f]=h/a}}return 0}function tt(s,r){let t=s.nrow,o=s.data,e=Array.from({length:t},(c,n)=>n+1),a=(c,n)=>c+n*t,i=(c,n)=>{let u=o[c];o[c]=o[n],o[n]=u},f=0;for(let c=1;c<t;c++)o[a(c,c)]>o[a(f,f)]&&(f=c);let h=o[a(f,f)];if(h<=0||Number.isNaN(h))return{pivot:e,rank:0};let m=r<0?t*Number.EPSILON*h:r,l=new Float64Array(2*t);for(let c=0;c<t;c++){for(let n=c;n<t;n++)c>0&&(l[n]+=o[a(c-1,n)]**2),l[t+n]=o[a(n,n)]-l[n];if(c>0){f=c;for(let n=c+1;n<t;n++)l[t+n]>l[t+f]&&(f=n);if(h=l[t+f],h<=m||Number.isNaN(h))return o[a(c,c)]=h,{pivot:e,rank:c}}if(c!==f){o[a(f,f)]=o[a(c,c)];for(let n=0;n<c;n++)i(a(n,c),a(n,f));for(let n=f+1;n<t;n++)i(a(c,n),a(f,n));for(let n=c+1;n<f;n++)i(a(c,n),a(n,f));[l[c],l[f]]=[l[f],l[c]],[e[c],e[f]]=[e[f],e[c]]}h=Math.sqrt(h),o[a(c,c)]=h;for(let n=c+1;n<t;n++){let u=o[a(c,n)];for(let w=0;w<c;w++)u-=o[a(w,c)]*o[a(w,n)];o[a(c,n)]=u/h}}return{pivot:e,rank:t}}function gt(s,r={}){x(r,G,"chol2inv");let t=F(s),o=r.size??t.ncol;if(!Number.isInteger(o)||o<1)throw new RangeError(`size must be a positive integer (got ${o})`);if(o>t.ncol)throw new RangeError(`size cannot exceed the number of columns (${t.ncol})`);if(o>t.nrow)throw new RangeError(`size cannot exceed the number of rows (${t.nrow})`);let e=v(o,o);for(let a=0;a<o;a++)for(let i=0;i<=a;i++)e.data[i+a*o]=t.data[i+a*t.nrow];ot(e);for(let a=0;a<o;a++)for(let i=a+1;i<o;i++)e.data[i+a*o]=e.data[a+i*o];return M(e)}function ot(s){let r=s.nrow,t=s.data;for(let o=0;o<r;o++)if(t[o+o*r]===0)throw new Error(`element (${o+1}, ${o+1}) is zero, so the inverse cannot be computed`);for(let o=0;o<r;o++){let e=o*r;t[o+e]=1/t[o+e];let a=-t[o+e];for(let i=0;i<o;i++){let f=t[i+e];if(f!==0){for(let h=0;h<i;h++)t[h+e]+=f*t[h+i*r];t[i+e]=f*t[i+i*r]}}for(let i=0;i<o;i++)t[i+e]*=a}for(let o=0;o<r;o++){let e=t[o+o*r];if(o<r-1){let a=0;for(let i=o;i<r;i++)a+=t[o+i*r]*t[o+i*r];t[o+o*r]=a;for(let i=0;i<o;i++)t[i+o*r]*=e;for(let i=o+1;i<r;i++){let f=t[o+i*r];if(f!==0)for(let h=0;h<o;h++)t[h+o*r]+=f*t[h+i*r]}}else for(let a=0;a<=o;a++)t[a+o*r]*=e}}export{v as a,R as b,k as c,F as d,M as e,rt as f,Q as g,S as h,L as i,D as j,P as k,ct as l,st as m,lt as n,U as o,ft as p,ut as q,ht as r,mt as s,pt as t,wt as u,vt as v,Z as w,gt as x,ot as y};
|
|
1
|
+
/*! rStats.js 1.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{l as x,u as q}from"./chunk-2ZQ2TSZS.js";function v(s,r){return{nrow:s,ncol:r,data:new Float64Array(s*r)}}function R(s){return s.length>0&&typeof s[0]!="number"}function k(s){let r=s.length,t=r===0?0:s[0].length,o=v(r,t);for(let e=0;e<r;e++){let a=s[e];if(a.length!==t)throw new TypeError("all rows of the matrix must have the same length");for(let i=0;i<t;i++)o.data[e+i*r]=a[i]}return o}function F(s){if(R(s))return k(s);let r=s;return{nrow:r.length,ncol:1,data:Float64Array.from(r)}}function M(s){let r=[];for(let t=0;t<s.nrow;t++){let o=new Array(s.ncol);for(let e=0;e<s.ncol;e++)o[e]=s.data[t+e*s.nrow];r.push(o)}return r}function rt(s){let r=v(s.ncol,s.nrow);for(let t=0;t<s.ncol;t++)for(let o=0;o<s.nrow;o++)r.data[t+o*s.ncol]=s.data[o+t*s.nrow];return r}function Q(s,r="the matrix"){if(s.nrow!==s.ncol)throw new TypeError(`${r} must be square (got ${s.nrow} x ${s.ncol})`)}function S(s){let r=0;for(let t=0;t<s.length;t++)r=Math.max(r,Math.abs(s[t]));return r===0||r>=2**-256&&r<=2**256?0:Math.floor(Math.log2(r))}function L(s,r=256){let t=S(s);return t>0?Math.max(0,t-r):t}var Y=["tol","lapack"],C=["complete","dvec"],W=["complete"],X=["complete","ncol"],H=["k"],V=["tol"];function D(s,r={}){x(r,Y,"qr");let t=k(s);if(r.lapack){let m=t.data.slice(),{tau:l,pivot:c}=O(t);if(m.every(Number.isFinite)&&!(t.data.every(Number.isFinite)&&l.every(Number.isFinite))){let u=L(m);if(u!==0){let w=t.nrow;for(let p=0;p<m.length;p++)t.data[p]=q(m[p],-u);({tau:l,pivot:c}=O(t));for(let p=0;p<t.ncol;p++)for(let d=0;d<=Math.min(p,w-1);d++)t.data[d+p*w]=q(t.data[d+p*w],u)}}let n=Array.from(l);return{qr:M(t),rank:Math.min(t.nrow,t.ncol),qraux:n,pivot:c.map(u=>u-1),useLapack:!0}}for(let m of t.data)if(!Number.isFinite(m))throw new RangeError("the matrix contains NaN or infinite values");let o=r.tol??1e-7;if(!(o>=0&&o<1/0))throw new RangeError("'tol' must be a non-negative finite number");let e=t.data.slice(),{qraux:a,pivot:i,rank:f,transformed:h}=z(t,o);if(!(t.data.every(Number.isFinite)&&a.every(Number.isFinite))){let m=t.nrow,l=Array.from({length:t.ncol},(c,n)=>S(e.subarray(n*m,(n+1)*m)));if(l.some(c=>c!==0)){for(let c=0;c<t.ncol;c++)for(let n=0;n<m;n++)t.data[n+c*m]=q(e[n+c*m],-l[c]);({qraux:a,pivot:i,rank:f,transformed:h}=z(t,o));for(let c=0;c<t.ncol;c++){let n=l[i[c]-1];if(n!==0){for(let u=0;u<=Math.min(c,m-1);u++)t.data[u+c*m]=q(t.data[u+c*m],n);h[c]||(a[c]=q(a[c],n))}}}}return{qr:M(t),rank:f,qraux:Array.from(a),pivot:i.map(m=>m-1),useLapack:!1}}function b(s,r,t){let o=0;for(let a=0;a<t;a++)o=Math.max(o,Math.abs(s[r+a]));if(o===0||!Number.isFinite(o))return o;let e=0;for(let a=0;a<t;a++){let i=s[r+a]/o;e+=i*i}return o*Math.sqrt(e)}function z(s,r){let t=s.nrow,o=s.ncol,e=s.data,a=new Float64Array(o),i=new Float64Array(o),f=new Uint8Array(o),h=Array.from({length:o},(n,u)=>u+1);for(let n=0;n<o;n++)a[n]=b(e,n*t,t),i[n]=a[n]===0?1:a[n];let m=new Float64Array(t),l=Math.min(t,o),c=o;for(let n=0;n<l;n++){for(;n<c&&a[n]<i[n]*r;){m.set(e.subarray(n*t,(n+1)*t));let[p,d,N]=[a[n],i[n],h[n]];e.copyWithin(n*t,(n+1)*t,o*t),e.set(m,(o-1)*t),a.copyWithin(n,n+1),i.copyWithin(n,n+1),h.copyWithin(n,n+1),a[o-1]=p,i[o-1]=d,h[o-1]=N,c--}if(n===t-1)break;let u=n*t,w=b(e,u+n,t-n);if(w!==0){e[u+n]!==0&&(w=Math.sign(e[u+n])*Math.abs(w));for(let p=n;p<t;p++)e[u+p]/=w;e[u+n]=1+e[u+n];for(let p=n+1;p<o;p++){let d=p*t,N=0;for(let g=n;g<t;g++)N-=e[u+g]*e[d+g];N/=e[u+n];for(let g=n;g<t;g++)e[d+g]+=N*e[u+g];if(a[p]===0)continue;let $=Math.max(1-(Math.abs(e[d+n])/a[p])**2,0);$<1e-6?a[p]=b(e,d+n+1,t-n-1):a[p]*=Math.sqrt($)}a[n]=e[u+n],f[n]=1,e[u+n]=-w}}return{qraux:a,pivot:h,rank:Math.min(c,t),transformed:f}}function O(s){let r=s.nrow,t=s.ncol,o=s.data,e=Math.min(r,t),a=new Float64Array(e),i=Array.from({length:t},(l,c)=>c+1),f=new Float64Array(t),h=new Float64Array(t);for(let l=0;l<t;l++)f[l]=b(o,l*r,r),h[l]=f[l];let m=Math.sqrt(2**-53);for(let l=0;l<e;l++){let c=l;for(let u=l+1;u<t;u++)Math.abs(f[u])>Math.abs(f[c])&&(c=u);if(c!==l){for(let u=0;u<r;u++){let w=o[u+c*r];o[u+c*r]=o[u+l*r],o[u+l*r]=w}[i[c],i[l]]=[i[l],i[c]],f[c]=f[l],h[c]=h[l]}let n=l*r;a[l]=P(o,n+l,r-l),l<t-1&&I(o,n+l,r-l,a[l],s,l,l+1,t-l-1);for(let u=l+1;u<t;u++){if(f[u]===0)continue;let w=1-(Math.abs(o[l+u*r])/f[u])**2;w=Math.max(w,0),w*(f[u]/h[u])**2<=m?l<r-1?(f[u]=b(o,u*r+l+1,r-l-1),h[u]=f[u]):(f[u]=0,h[u]=0):f[u]*=Math.sqrt(w)}}return{tau:a,pivot:i}}function P(s,r,t){if(t<=1)return 0;let o=b(s,r+1,t-1);if(o===0)return 0;let e=s[r],a=-Math.sign(e||1)*Math.hypot(e,o),i=2**-1022/2**-53,f=0;if(Math.abs(a)<i){let l=1/i;do{f++;for(let c=1;c<t;c++)s[r+c]*=l;a*=l,e*=l}while(Math.abs(a)<i&&f<20);o=b(s,r+1,t-1),a=-Math.sign(e||1)*Math.hypot(e,o)}let h=(a-e)/a,m=1/(e-a);for(let l=1;l<t;l++)s[r+l]*=m;for(let l=0;l<f;l++)a*=i;return s[r]=a,h}function ct(s,r,t,o,e,a,i,f){if(o===0)return;let h=e.nrow,m=e.data;for(let l=i;l<i+f;l++){let c=a+l*h,n=0;for(let u=0;u<t;u++)n+=m[c+u]*s[r+u];n*=o;for(let u=0;u<t;u++)m[c+u]-=s[r+u]*n}}function I(s,r,t,o,e,a,i,f){if(o===0)return;let h=t;for(;h>1&&s[r+h-1]===0;)h--;let m=e.nrow,l=e.data;for(let c=i;c<i+f;c++){let n=a+c*m;if(h===1){l[n]*=1-o;continue}let u=0;for(let p=1;p<h;p++)u+=l[n+p]*s[r+p];u+=l[n];let w=-o*u;l[n]+=w;for(let p=1;p<h;p++)l[n+p]+=s[r+p]*w}}function E(s){return{a:k(s.qr),qraux:s.qraux,rank:s.rank,pivot:s.pivot.map(r=>r+1),lapack:s.useLapack}}function A(s,r){let t=F(r);if(t.nrow!==s.a.nrow)throw new TypeError(`qr and y must have the same number of rows (${s.a.nrow} and ${t.nrow})`);return t}function j(s,r){return R(s)?M(r):Array.from(r.data)}function y(s,r,t,o=s.rank){let{a:e,qraux:a}=s,i=e.nrow;if(s.lapack){let m=Math.min(i,e.ncol),l=t?_(0,m):_(0,m).reverse();for(let c of l)I(e.data,c+c*i,i-c,a[c],r,c,0,r.ncol);return}let f=Math.min(o,i-1),h=t?_(0,f):_(0,f).reverse();for(let m of h){if(a[m]===0)continue;let l=m*i,c=e.data[l+m];e.data[l+m]=a[m];for(let n=0;n<r.ncol;n++){let u=n*i,w=0;for(let p=m;p<i;p++)w-=e.data[l+p]*r.data[u+p];w/=e.data[l+m];for(let p=m;p<i;p++)r.data[u+p]+=w*e.data[l+p]}e.data[l+m]=c}}function _(s,r){return Array.from({length:Math.max(0,r-s)},(t,o)=>s+o)}function st(s,r){let t=E(s),o=A(t,r);return y(t,o,!0),j(r,o)}function lt(s,r){let t=E(s),o=A(t,r);return y(t,o,!1),j(r,o)}function U(s,r){let t=E(s),o=A(t,r),e=t.a.ncol,a=t.a.nrow,i=t.lapack?Math.min(a,e):t.rank;y(t,o,!0);for(let h=0;h<o.ncol;h++){let m=h*a;for(let l=i-1;l>=0;l--){let c=t.a.data[l+l*a];if(c===0)throw new Error("exact singularity in qrCoef");o.data[m+l]/=c;let n=-o.data[m+l];for(let u=0;u<l;u++)o.data[m+u]+=n*t.a.data[u+l*a]}}let f=v(e,o.ncol);f.data.fill(NaN);for(let h=0;h<o.ncol;h++)for(let m=0;m<i;m++)f.data[t.pivot[m]-1+h*e]=o.data[m+h*a];return j(r,f)}function K(s,r,t,o){let e=E(s);if(e.lapack)throw new TypeError("not supported for a QR decomposition computed with lapack: true");let a=o??e.rank;if(!Number.isInteger(a)||a<0||a>e.rank)throw new RangeError(`invalid k (got ${a})`);let i=A(e,r),f=e.a.nrow;if(a===0)return j(r,i);if(f===1)return t||i.data.fill(0),j(r,i);y(e,i,!0,a);for(let h=0;h<i.ncol;h++)t?i.data.fill(0,h*f+a,(h+1)*f):i.data.fill(0,h*f,h*f+a);return y(e,i,!1,a),j(r,i)}function ft(s,r){return K(s,r,!1)}function ut(s,r,t={}){return x(t,H,"qrFitted"),K(s,r,!0,t.k)}function ht(s,r={}){x(r,C,"qrQ");let t=E(s),o=t.a.nrow,e=r.complete?o:Math.min(o,t.a.ncol),a=r.dvec??new Array(e).fill(1);if(a.length!==e)throw new RangeError(`dvec must have length ${e}`);let i=v(o,e);for(let f=0;f<e;f++)i.data[f+f*o]=a[f];return y(t,i,!1),M(i)}function mt(s,r={}){x(r,W,"qrR");let t=k(s.qr),o=r.complete?t.nrow:Math.min(t.nrow,t.ncol),e=v(o,t.ncol);for(let a=0;a<t.ncol;a++)for(let i=0;i<=Math.min(a,o-1);i++)e.data[i+a*o]=t.data[i+a*t.nrow];return M(e)}function pt(s,r={}){x(r,X,"qrX");let t=E(s),o=t.a.nrow,e=t.a.ncol,a=r.complete??!1,i=r.ncol??(a?o:Math.min(o,e));if(!Number.isInteger(i)||i<0)throw new RangeError(`invalid ncol (got ${i})`);if(i>Math.max(o,e))throw new RangeError(`ncol must be at most max(nrow, ncol of x) = ${Math.max(o,e)} (got ${i})`);if(t.pivot.some((c,n)=>c!==n+1)&&i<e)throw new RangeError("ncol must be at least the number of columns because the decomposition is pivoted");let h=v(o,i);for(let c=0;c<i;c++)if(c<e)for(let n=0;n<=Math.min(c,o-1);n++)h.data[n+c*o]=t.a.data[n+c*o];else c<o&&(h.data[c+c*o]=1);y(t,h,!1);let m=Math.min(i,e),l=v(o,i);l.data.set(h.data);for(let c=0;c<m;c++){let n=t.pivot[c]-1;n<m&&l.data.set(h.data.subarray(c*o,(c+1)*o),n*o)}return M(l)}function wt(s,r,t={}){x(t,V,"qrSolve");let o=Array.isArray(s)?D(s,{tol:t.tol??1e-7}):s,e=o.qr.length,a=e===0?0:o.qr[0].length;if(o.rank!==Math.min(e,a))throw new Error("singular matrix in qrSolve");if(o.useLapack){let l=t.tol??1e-7,c=Math.abs(o.qr[0]?.[0]??0);for(let n=0;n<Math.min(e,a);n++)if(!(Math.abs(o.qr[n][n])>l*c))throw new Error("singular matrix in qrSolve")}if(r===void 0&&e!==a)throw new TypeError("only square matrices can be inverted");let i=r??Array.from({length:e},(l,c)=>Array.from({length:e},(n,u)=>c===u?1:0)),f=U(o,i),h=new Set(o.pivot.slice(Math.min(e,a)));if(R(i)){let l=f;for(let c of h)l[c].fill(0);return l}let m=f;for(let l of h)m[l]=0;return m}var B=["pivot","tol"],G=["size"];function vt(s,r={}){x(r,B,"chol");let t=k(s);if(Q(t),t.nrow===0)throw new RangeError("the matrix has zero dimension");if(r.pivot){let e=r.tol??-1;if(Number.isNaN(e))throw new RangeError("'tol' must not be NaN");let{pivot:a,rank:i}=tt(t,e);return T(t),J(t,i),{r:M(t),pivot:a.map(f=>f-1),rank:i}}let o=Z(t);if(o>0)throw new Error(`the matrix is not positive definite: the leading minor of order ${o} is not positive`);return T(t),M(t)}function T(s){let r=s.nrow;for(let t=0;t<r;t++)for(let o=t+1;o<r;o++)s.data[o+t*r]=0}function J(s,r){let t=s.nrow;for(let o=r;o<t;o++)for(let e=r;e<t;e++)s.data[e+o*t]=0}function Z(s){let r=s.nrow,t=s.data;for(let o=0;o<r;o++){let e=o*r,a=t[o+e];for(let i=0;i<o;i++)a-=t[i+e]*t[i+e];if(a<=0)return t[o+e]=a,o+1;a=Math.sqrt(a),t[o+e]=a;for(let i=o+1;i<r;i++){let f=i*r,h=t[o+f];for(let m=0;m<o;m++)h-=t[m+e]*t[m+f];t[o+f]=h/a}}return 0}function tt(s,r){let t=s.nrow,o=s.data,e=Array.from({length:t},(c,n)=>n+1),a=(c,n)=>c+n*t,i=(c,n)=>{let u=o[c];o[c]=o[n],o[n]=u},f=0;for(let c=1;c<t;c++)o[a(c,c)]>o[a(f,f)]&&(f=c);let h=o[a(f,f)];if(h<=0||Number.isNaN(h))return{pivot:e,rank:0};let m=r<0?t*Number.EPSILON*h:r,l=new Float64Array(2*t);for(let c=0;c<t;c++){for(let n=c;n<t;n++)c>0&&(l[n]+=o[a(c-1,n)]**2),l[t+n]=o[a(n,n)]-l[n];if(c>0){f=c;for(let n=c+1;n<t;n++)l[t+n]>l[t+f]&&(f=n);if(h=l[t+f],h<=m||Number.isNaN(h))return o[a(c,c)]=h,{pivot:e,rank:c}}if(c!==f){o[a(f,f)]=o[a(c,c)];for(let n=0;n<c;n++)i(a(n,c),a(n,f));for(let n=f+1;n<t;n++)i(a(c,n),a(f,n));for(let n=c+1;n<f;n++)i(a(c,n),a(n,f));[l[c],l[f]]=[l[f],l[c]],[e[c],e[f]]=[e[f],e[c]]}h=Math.sqrt(h),o[a(c,c)]=h;for(let n=c+1;n<t;n++){let u=o[a(c,n)];for(let w=0;w<c;w++)u-=o[a(w,c)]*o[a(w,n)];o[a(c,n)]=u/h}}return{pivot:e,rank:t}}function gt(s,r={}){x(r,G,"chol2inv");let t=F(s),o=r.size??t.ncol;if(!Number.isInteger(o)||o<1)throw new RangeError(`size must be a positive integer (got ${o})`);if(o>t.ncol)throw new RangeError(`size cannot exceed the number of columns (${t.ncol})`);if(o>t.nrow)throw new RangeError(`size cannot exceed the number of rows (${t.nrow})`);let e=v(o,o);for(let a=0;a<o;a++)for(let i=0;i<=a;i++)e.data[i+a*o]=t.data[i+a*t.nrow];ot(e);for(let a=0;a<o;a++)for(let i=a+1;i<o;i++)e.data[i+a*o]=e.data[a+i*o];return M(e)}function ot(s){let r=s.nrow,t=s.data;for(let o=0;o<r;o++)if(t[o+o*r]===0)throw new Error(`element (${o+1}, ${o+1}) is zero, so the inverse cannot be computed`);for(let o=0;o<r;o++){let e=o*r;t[o+e]=1/t[o+e];let a=-t[o+e];for(let i=0;i<o;i++){let f=t[i+e];if(f!==0){for(let h=0;h<i;h++)t[h+e]+=f*t[h+i*r];t[i+e]=f*t[i+i*r]}}for(let i=0;i<o;i++)t[i+e]*=a}for(let o=0;o<r;o++){let e=t[o+o*r];if(o<r-1){let a=0;for(let i=o;i<r;i++)a+=t[o+i*r]*t[o+i*r];t[o+o*r]=a;for(let i=0;i<o;i++)t[i+o*r]*=e;for(let i=o+1;i<r;i++){let f=t[o+i*r];if(f!==0)for(let h=0;h<o;h++)t[h+o*r]+=f*t[h+i*r]}}else for(let a=0;a<=o;a++)t[a+o*r]*=e}}export{v as a,R as b,k as c,F as d,M as e,rt as f,Q as g,S as h,L as i,D as j,P as k,ct as l,st as m,lt as n,U as o,ft as p,ut as q,ht as r,mt as s,pt as t,wt as u,vt as v,Z as w,gt as x,ot as y};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{c as G,m as ne,n as re,o as oe}from"./chunk-LMRCFKVK.js";import{a as ie}from"./chunk-VALULDEX.js";import{a as S,b as T,c as L,d as P,e as Jt}from"./chunk-R5BMFVIH.js";import{g as W,h as ae,i as J}from"./chunk-JXEXOD7K.js";import{a as C,b as j,c as v}from"./chunk-RIP2RKAW.js";import{A as kt,B as te,E as ee,e as I,r as R,s as B}from"./chunk-MOJ2KIQE.js";import{b as Ut,c as Nt,d as ot,e as Vt,f as Zt,g as z,i as it,k as zt,l as y}from"./chunk-YKNRDPIB.js";var ln=["log"],fn=["lowerTail","logP"],hn=["lowerTail","logP"];function bt(t,e,n,r){if(t===0&&e===0)return{e:[0,0],logDenom:0};if(t===0||e===0){let o=t+e,[i,a]=t===0?[r,n]:[n,r];return{e:a[0]<.1?ot(te(o,z([o,0],i)),z([o,0],a)):Vt(z([o,0],zt(i))),logDenom:0}}return ee(t,e,n,r)}function le(t,e,n,r){let o=e+n,i=it([r,0],[o,0]),a=it([o-r,0],[o,0]),s=bt(t,e-t,i,a),c=bt(r-t,n-r+t,i,a),u=bt(r,o-r,i,a);return{e:Zt(ot(s.e,c.e),u.e),logDenom:s.logDenom+c.logDenom-u.logDenom}}function fe(t,e){let[n,r]=t.e,o=e*Math.exp(-.5*t.logDenom);return n<700?Math.exp(-n)*(1-r)*o:Math.exp(700-n)*(1-r)*o*Math.exp(-700)}function he(t){return-t.e[0]-t.e[1]-.5*t.logDenom}function wt(t,e){return Ut(t,e)[1]===0}function at(t,e,n){return[Math.max(0,n-e),Math.min(n,t)]}function Mn(t,e,n,r,o){if([t,e,n,r].some(Number.isNaN))return NaN;if(![e,n,r].every(Number.isFinite)||C(e)||C(n)||C(r))return NaN;if(e=v(e),n=v(n),r=v(r),e<0||n<0||r<0||r>e+n)return NaN;if(Et(e,n,r))return ne(t,r,xt(e,n),o);if(C(t))return L(o);t=v(t);let[i,a]=at(e,n,r);if(t<i||t>a)return L(o);if(r===0)return o?0:1;if(!wt(e,n))return NaN;if(r===e+n)return o?0:1;let s=le(t,e,n,r);return o?he(s):fe(s,1)}function se(t,e,n,r){return it(Nt(t,e),Nt(n,r))}function pn(t,e,n,r,o,i,a){let s=[1,0],c=[1,0],u=t;for(;!(o?u<=i:u>=a);){let l=o?se(u,n-r+u,e-u+1,r-u+1):se(e-u,r-u,u+1,n-r+u+1);s=z(s,l),c=ot(c,s),u+=o?-1:1;let h=l[0];if(h<1&&s[0]*h/(1-h)<c[0]*2**-60)break}return c[0]+c[1]}function Me(t,e,n,r,o,i){let[a,s]=at(e,n,r),c=e+n,u=t*c<r*e,l=ce(t,e,n,r,u,a,s);if(l.value>.5){let h=ce(t,e,n,r,!u,a,s);h.value<l.value&&(l=h,u=!u)}return u===o?i?l.value>1e-300?Math.log(l.value):he(l.form)+Math.log(l.sum):l.value:i?Math.log1p(-l.value):1-l.value}function ce(t,e,n,r,o,i,a){let s=o?t:t+1,c=le(s,e,n,r),u=pn(s,e,n,r,o,i,a);return{form:c,sum:u,value:fe(c,u)}}function xt(t,e){return t>=e?1/(1+e/t):e/t===1/0?0:t/e/(1+t/e)}function Et(t,e,n){return n>0&&n<t*2**-60+e*2**-60}function pe(t,e,n){if([t,e,n].every(Number.isFinite)&&(t=v(t),e=v(e),n=v(n),!(t<0||e<0||n<0||n>t+e)))return[t,e,n]}function mn(t,e,n,r,o,i){if([t,e,n,r].some(Number.isNaN))return NaN;let a=pe(e,n,r);if(a===void 0)return NaN;if([e,n,r]=a,Et(e,n,r))return re(t,r,xt(e,n),o,i);let s=j(t),[c,u]=at(e,n,r);if(s<c)return S(o,i);if(s>=u)return T(o,i);if(u>ge||!wt(e,n))return NaN;let l=gn(s,e,n,r,c,u);if(l>dn)throw new RangeError(`phyper: m = ${e}, n = ${n}, k = ${r} needs about ${Math.round(l)} terms at q = ${t} (at most 2^26)`);return Me(s,e,n,r,o,i)}function me(t,e,n,r){return n*t/r*(e/r)*(r-n)/Math.max(r-1,1)}function ue(t,e,n,r,o,i){let a=e?n-t:t-n,s=Math.sqrt(a*a+83*r);return Math.min(a>=0?83*r/(s+a):s-a,e?t-o:i-t)}function gn(t,e,n,r,o,i){let a=e+n,s=r*e/a,c=me(e,n,r,a),u=t*a<r*e,l=u?t:t+1,h=ue(l,u,s,c,o,i);return Math.abs(l-s)>=1?h:h+ue(u?t+1:t,!u,s,c,o,i)}var dn=2**26,Nn=2**21,ge=2**53;function bn(t,e,n,r,o,i,a=!0){if([t,e,n,r].some(Number.isNaN))return NaN;let s=pe(e,n,r);if(s===void 0)return NaN;if([e,n,r]=s,Et(e,n,r))return oe(t,r,xt(e,n),o,i);let[c,u]=at(e,n,r),l=P(t,c,u,o,i);if(l!==void 0)return l;if(c===u)return c;if(u>ge||!wt(e,n))return NaN;let h=e+n,f=r*e/h,p=Math.sqrt(me(e,n,r,h));if(a&&p>Nn)throw new RangeError(`qhyper: m = ${e}, n = ${n}, k = ${r} has a standard deviation of about ${p.toPrecision(3)} (at most 2^21)`);let M=B(t,{lowerTail:o,logP:i}),N=f+p*M;return G({p:t,lowerTail:o,logP:i,cdf:(g,E,d)=>g<c?S(E,d):g>=u?T(E,d):Me(g,e,n,r,E,d),y0:Number.isFinite(N)?N:f,lo:c,hi:u})}function Wr(t,e,n,r,o={}){y(o,ln,"dhyper");let i=o.log??!1;return I(t,a=>Mn(a,e,n,r,i))}function $r(t,e,n,r,o={}){y(o,fn,"phyper");let{lowerTail:i=!0,logP:a=!1}=o;return I(t,s=>mn(s,e,n,r,i,a))}function Or(t,e,n,r,o={}){y(o,hn,"qhyper");let{lowerTail:i=!0,logP:a=!1}=o;return I(t,s=>bn(s,e,n,r,i,a))}var wn=["log"],xn=["lowerTail","logP"],En=["lowerTail","logP"],yn=2**900,de=-900,$=new Map,In=2**21,st=0,vn=2**25;function be(t,e){if(e+1>vn)throw new RangeError(`signrank: n = ${t} needs too large a table (${e+1} entries)`);let n=new Float64Array(e+1);n[0]=1;let r=0,o=-1/0,i=Math.min(t,e);for(let u=1;u<=i;u++){for(let l=e;l>=u;l--)n[l]+=n[l-u];if(n[Math.min(e,Math.floor(u*(u+1)/4))]>yn){let l=2**de;for(let h=0;h<=e;h++)n[h]*=l;r-=de,o=Math.max(o,r-1015+i-u)}}let a=new Float64Array(e+1),s=0,c=0;for(let u=0;u<=e;u++){let l=n[u]-c,h=s+l;c=h-s-l,s=h,a[u]=s}return{n:t,len:e+1,count:n,cum:a,scale:r,minTrusted:2**(o-r)}}function Ne(t,e,n=!1){let r=n?-t:t,o=$.get(r);if(o!==void 0&&o.len>e)return $.delete(r),$.set(r,o),o;let i=Math.floor(t*(t+1)/4),a=Math.min(i,Math.max(e,o===void 0?0:2*o.len));return we(r,be(t,a),o)}function we(t,e,n){n!==void 0&&($.delete(t),st-=n.len),$.set(t,e),st+=e.len;for(let[r,o]of $){if(st<=In||r===t)break;$.delete(r),st-=o.len}return e}function yt(t,e,n){let r=(a,s)=>e===a.len-1||s>=(n?(e+1)*a.minTrusted:a.minTrusted),o=Ne(t,e),i=(n?o.cum:o.count)[e];return r(o,i)?[i,o]:(o=Ne(t,e,!0),i=(n?o.cum:o.count)[e],r(o,i)?[i,o]:(o=we(-t,be(t,e),$.get(-t)),[(n?o.cum:o.count)[e],o]))}function It(t,e,n){let r=e.scale-e.n,o=Math.trunc(r/2),i=t*2**o*2**(r-o);if(!n)return i;if(i>=1e-300)return Math.log(i);let a=Math.floor(Math.log2(t)),s=Math.trunc(a/2),c=t*2**-s*2**-(a-s);return c>=2?(c/=2,a++):c<1&&(c*=2,a--),Math.log(c)+(a+r)*Math.LN2}function vt(t){return Number.isFinite(t)?(t=v(t),t<=0||t>=2**27?NaN:t):NaN}function An(t,e,n){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;if(C(t))return L(n);t=v(t);let r=e*(e+1)/2;if(t<0||t>r)return L(n);let o=Math.min(t,r-t),[i,a]=yt(e,o,!1);return It(i,a,n)}function xe(t,e,n,r){let o=e*(e+1)/2,i=t,a=o-t-1,s=n?i:a,c=n?a:i;if(s<=c){let[f,p]=yt(e,s,!0);return It(f,p,r)}let[u,l]=yt(e,c,!0),h=It(u,l,!1);return r?Math.log1p(-h):1-h}function _n(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;let o=j(t),i=e*(e+1)/2;return o<0?S(n,r):o>=i?T(n,r):xe(o,e,n,r)}function Rn(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;let o=e*(e+1)/2,i=P(t,0,o,n,r);if(i!==void 0)return i;let a=o/2,s=Math.sqrt(e*(e+1)*(2*e+1)/24),c=a+s*B(t,{lowerTail:n,logP:r});return G({p:t,lowerTail:n,logP:r,cdf:(u,l,h)=>u<0?S(l,h):u>=o?T(l,h):xe(u,e,l,h),y0:Number.isFinite(c)?c:a,lo:0,hi:o})}function jr(t,e,n={}){y(n,wn,"dsignrank");let r=n.log??!1;return I(t,o=>An(o,e,r))}function Gr(t,e,n={}){y(n,xn,"psignrank");let{lowerTail:r=!0,logP:o=!1}=n;return I(t,i=>_n(i,e,r,o))}function Qr(t,e,n={}){y(n,En,"qsignrank");let{lowerTail:r=!0,logP:o=!1}=n;return I(t,i=>Rn(i,e,r,o))}var Sn=["log"],Tn=["lowerTail","logP"],Fn=["lowerTail","logP"],Ee=960,ye=2**996,Ln=2**25,_e=2**29,Cn=2**760,Ie=200,Pn=2**-969,ct=134217729,O=new Map,Wn=2**21,ut=0;function Re(t,e,n){if(n+1>Ln)throw new RangeError(`wilcox: m = ${t}, n = ${e} needs too large a table (${n+1} entries)`);if(t*(n+1)>_e)throw new RangeError(`wilcox: m = ${t}, n = ${e} needs ${t*(n+1)} steps for a table of ${n+1} entries (at most 2^29)`);let r=new Float64Array(n+1),o=new Float64Array(n+1);r[0]=2**Ee;let i=Ee,a=NaN,s=n+1;for(let f=1;f<=t;f++){let p=Math.min(s-1,f*e),M=e+f,N=ct*f,g=N-(N-f),E=f-g;N=ct*M;let d=N-(N-M),m=M-d;for(let b=0;b<=p;b++){let x=r[b];if(x===0)continue;if(!(Math.abs(x)<=ye)){s=b,p=b-1;break}let F=x*f;N=ct*x;let _=N-(N-x),H=x-_,cn=_*g-F+_*E+H*g+H*E+o[b]*f,X=F/M,jt=X*M;N=ct*X;let gt=N-(N-X),Gt=X-gt,un=gt*d-jt+gt*m+Gt*d+Gt*m,Qt=(F-jt-un+cn)/M,dt=X+Qt;o[b]=Qt-(dt-X),r[b]=dt,Math.abs(dt)<Pn&&Number.isNaN(a)&&(a=i)}let w=e+f;for(let b=p;b>=w;b--)ve(r,o,b,b-w,-1);for(let b=f;b<=p;b++)ve(r,o,b,b-f,1);let A=Math.min(p,Math.floor(f*e/2));for(;A>=0&&r[A]>0&&r[A]<Cn;){let b=2**Ie;for(let x=0;x<=p;x++)r[x]*=b,o[x]*=b;i+=Ie}}let c=new Float64Array(n+1),u=0,l=0;for(let f=0;f<s;f++){let p=r[f];if(!(Math.abs(p)<=ye)){s=f;break}let M=u+p,N=M-u,g=u-(M-N)+(p-N);g+=l+o[f],u=M+g,l=g-(u-M),c[f]=u}let h=Number.isNaN(a)?0:2**Math.min(1023,-909+Math.ceil(Math.log2(t*(n+1)))+i-a);return{m:t,n:e,len:n+1,prob:r,cum:c,scale:i,minTrusted:h,valid:s}}function ve(t,e,n,r,o){let i=t[n],a=o*t[r],s=i+a,c=s-i,u=i-(s-c)+(a-c);u+=e[n]+o*e[r];let l=s+u;e[n]=u-(l-s),t[n]=l}function Ae(t,e,n,r=!1){let o=`${t},${e}${r?",low":""}`,i=O.get(o);if(i!==void 0&&i.len>n)return O.delete(o),O.set(o,i),i;let a=Math.floor(t*e/2),s=i===void 0?0:Math.min(2*i.len,Math.floor(_e/t)-1),c=Math.min(a,Math.max(n,s));return Se(o,Re(t,e,c),i)}function Se(t,e,n){n!==void 0&&(O.delete(t),ut-=n.len),O.set(t,e),ut+=e.len;for(let[r,o]of O){if(ut<=Wn||r===t)break;O.delete(r),ut-=o.len}return e}function At(t,e,n,r){t>e&&([t,e]=[e,t]);let o=u=>{if(n>=u.valid)throw new RangeError(`wilcox: the exact distribution for m = ${t}, n = ${e} cannot be computed accurately at ${n} (from ${u.valid} on, near the center of large samples)`);return(r?u.cum:u.prob)[n]},i=(u,l)=>n===u.len-1||l>=(r?(n+1)*u.minTrusted:u.minTrusted),a=Ae(t,e,n),s=o(a);if(i(a,s))return[s,a];if(a=Ae(t,e,n,!0),s=o(a),i(a,s))return[s,a];let c=`${t},${e},low`;return a=Se(c,Re(t,e,n),O.get(c)),[o(a),a]}var $n=.6931471803691238,On=19082149292705877e-26;function _t(t,e,n){let r=-e.scale,o=Math.trunc(r/2),i=t*2**o*2**(r-o);if(!n)return i;if(i>=1e-300)return Math.log(i);let a=Math.floor(Math.log2(t)),s=Math.trunc(a/2),c=t*2**-s*2**-(a-s);return c>=2?(c/=2,a++):c<1&&(c*=2,a--),(a+r)*$n+(Math.log(c)+(a+r)*On)}function Rt(t,e){if(!(!Number.isFinite(t)||!Number.isFinite(e))&&(t=v(t),e=v(e),!(t<=0||e<=0||t*e>2**53)))return t*e===2**53&&BigInt(t)*BigInt(e)!==2n**53n?void 0:[t,e]}function qn(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let o=Rt(e,n);if(o===void 0)return NaN;if([e,n]=o,C(t))return L(r);t=v(t);let i=e*n;if(t<0||t>i)return L(r);let a=Math.min(t,i-t),[s,c]=At(e,n,a,!1);return _t(s,c,r)}function Te(t,e,n,r,o){let i=e*n,a=r?t:i-t-1,s=r?i-t-1:t;if(a<=s){let[h,f]=At(e,n,a,!0);return _t(h,f,o)}let[c,u]=At(e,n,s,!0),l=_t(c,u,!1);return o?Math.log1p(-l):1-l}function Dn(t,e,n,r,o){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let i=Rt(e,n);if(i===void 0)return NaN;[e,n]=i;let a=j(t);return a<0?S(r,o):a>=e*n?T(r,o):Te(a,e,n,r,o)}function Yn(t,e,n,r,o){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let i=Rt(e,n);if(i===void 0)return NaN;[e,n]=i;let a=e*n,s=P(t,0,a,r,o);if(s!==void 0)return s;let c=a/2,u=Math.sqrt(a*(e+n+1)/12),l=c+u*B(t,{lowerTail:r,logP:o});return G({p:t,lowerTail:r,logP:o,cdf:(h,f,p)=>h<0?S(f,p):h>=a?T(f,p):Te(h,e,n,f,p),y0:Number.isFinite(l)?l:c,lo:0,hi:a})}function eo(t,e,n,r={}){y(r,Sn,"dwilcox");let o=r.log??!1;return I(t,i=>qn(i,e,n,o))}function no(t,e,n,r={}){y(r,Tn,"pwilcox");let{lowerTail:o=!0,logP:i=!1}=r;return I(t,a=>Dn(a,e,n,o,i))}function ro(t,e,n,r={}){y(r,Fn,"qwilcox");let{lowerTail:o=!0,logP:i=!1}=r;return I(t,a=>Yn(a,e,n,o,i))}var Kn=["nranges","lowerTail","logP"],Hn=["nranges","lowerTail","logP"],D=128,et=Number.EPSILON,Xn=256,Ot=Float64Array.from({length:2*D+1},(t,e)=>Math.cos(Math.PI*e/D));function Bn(t){let e=new Float64Array(t+1);for(let n=0;n<=t;n++){let r=0;for(let o=0;o<=t;o+=2)r+=(o===0||o===t?.5:1)*Ot[o*n%(2*t)*(D/t)]*2/(1-o*o);e[n]=(n===0||n===t?.5:1)*2*r/t}return e}var jn=new Map([16,32,64,128].map(t=>[t,Bn(t)]));function Gn(t,e){let n=jn.get(e),r=D/e,o=0,i=0;for(let s=0;s<=e;s++)o+=n[s]*t[s],i+=Math.abs(n[s]*t[s]);let a=0;for(let s=e-7;s<=e;s++){let c=.5*(t[0]+(s%2===0?t[e]:-t[e]));for(let u=1;u<e;u++)c+=t[u]*Ot[s*u%(2*e)*r];c*=2/e,s===e&&(c*=.5),a=Math.max(a,Math.abs(c))}return{integral:o,tail:a,scale:i}}var tt=class{f;a;b;noise;c;h;values=new Float64Array(D+1);have=new Uint8Array(D+1);N=0;integral=0;error=1/0;constructor(e,n,r,o){this.f=e,this.a=n,this.b=r,this.noise=o,this.c=.5*(n+r),this.h=.5*(r-n)}advance(e){let n=D/e,r=new Float64Array(e+1);for(let i=0;i<=e;i++){let a=i*n;this.have[a]||(this.values[a]=this.f(this.c+this.h*Ot[a]),this.have[a]=1),r[i]=this.values[a]}let o=Gn(r,e);this.N=e,this.integral=o.integral*this.h,this.error=Math.max(o.tail*4/e,this.noise*o.scale)*Math.abs(this.h)}};function ht(t,e,n,r=4*et){let o=[];for(let a=0;a+1<e.length;a++){let s=new tt(t,e[a],e[a+1],r);s.advance(16),o.push(s)}for(let a=0;a<40;a++){let s=0;for(let f of o)s+=f.integral;let c=n*Math.abs(s)/o.length,u=!0,l=o.length,h=[];for(let f of o){if(f.error<=c||f.error<=r*Math.abs(f.integral)){h.push(f);continue}if(u=!1,f.N<D)f.advance(2*f.N),h.push(f);else if(l>=Xn)h.push(f);else{l++;let p=new tt(t,f.a,f.c,r),M=new tt(t,f.c,f.b,r);p.advance(16),M.advance(16),h.push(p,M)}}if(o=h,u)break}let i=0;for(let a of o)i+=a.integral;return i}function Ce(t,e,n){let r=Math.max(1,Math.ceil((e-t)/n));return Array.from({length:r+1},(o,i)=>i===r?e:t+(e-t)*i/r)}var Pe=2e-15,We=1e-16,Qn={lowerTail:!1},Un={logP:!0},Vn={lowerTail:!1,logP:!0},rt=.9189385332046728,Mt=t=>R(t),U=t=>R(t,Qn),qt=t=>R(t,Un),Dt=t=>R(t,Vn),Zn=.3989422804014327;function V(t){let e=Math.round(t*16)/16,n=t-e;return Zn*Math.exp(-.5*e*e)*Math.exp(-.5*n*(t+e))}var Ft=[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],$e=[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626];function zn(t,e){let n=t-.5*e,r=.5*e,o=0;for(let i=0;i<4;i++)o+=$e[i]*(V(n-r*Ft[i])+V(n+r*Ft[i]));return o*r}function Jn(t,e){let n=t-.5*e,r=.5*e,o=0;for(let i=0;i<4;i++){let a=r*Ft[i];o+=$e[i]*(Math.exp(n*a-a*a/2)+Math.exp(-n*a-a*a/2))}return-rt-n*n/2+Math.log(o*r)}var Yt=(t,e)=>e*Math.max(1,Math.abs(t),Math.abs(t-e))<.5;function Z(t,e){let n=t-e,r=n-t,o=t-(n-r)+(-e-r);return{ah:n,al:o}}function nt(t,e){return Mt(t)+V(t)*e}function kn(t,e){return U(t)-V(t)*e}function Oe(t,e){if(Yt(t,e))return zn(t,e);let{ah:n,al:r}=Z(t,e);return n>=0?kn(n,r)-U(t):t<=0?Mt(t)-nt(n,r):1-nt(n,r)-U(t)}function tr(t,e,n){if(t>0&&t-e<0&&!Yt(t,e)){let{ah:o,al:i}=Z(t,e);return Math.exp(n*Math.log1p(-(nt(o,i)+U(t))))}let r=Oe(t,e);return r>0?r**n:0}function er(t,e){return t>0?Math.exp(e*Math.log1p(-U(t))):Mt(t)**e}function qe(t,e){let{ah:n,al:r}=Z(t,e),o=qt(n);return o+r*Math.exp(-rt-n*n/2-o)}function nr(t,e){let{ah:n,al:r}=Z(t,e),o=Dt(n);return o-r*Math.exp(-rt-n*n/2-o)}function De(t,e){if(Yt(t,e))return Jn(t,e);if(t-e>=0){let i=nr(t,e);return i+Math.log(-Math.expm1(Dt(t)-i))}if(t<=0){let i=qt(t);return i+Math.log(-Math.expm1(qe(t,e)-i))}let{ah:r,al:o}=Z(t,e);return Math.log1p(-nt(r,o)-U(t))}var Ye=2,St=1e-18;function Ke(t,e,n){let r=Ce(e,n,Ye),o=r.map(t),i=0;for(let f=1;f<o.length;f++)o[f]>o[i]&&(i=f);let a=o[i];if(!(a>0))return 0;let s=Math.max(i-1,0),c=Math.min(i+1,o.length-1);for(;s>0&&o[s]>a*St;)s--;for(;c<o.length-1&&o[c]>a*St;)c++;let u=a*St,l=r[s],h=r[c];if(o[s]<=u){let f=r[s+1];for(let p=0;p<2;p++){let M=.5*(l+f);t(M)<=u?l=M:f=M}}if(o[c]<=u){let f=r[c-1];for(let p=0;p<2;p++){let M=.5*(h+f);t(M)<=u?h=M:f=M}}return ht(t,[l,h],We)}function He(t,e,n){let r=Ce(e,n,Ye),o=r.map(t),i=0;for(let m=1;m<o.length;m++)o[m]>o[i]&&(i=m);if(!(o[i]>-1/0))return-1/0;let a=r[Math.max(i-1,0)],s=r[Math.min(i+1,r.length-1)],c=(Math.sqrt(5)-1)/2,u=s-c*(s-a),l=a+c*(s-a),h=t(u),f=t(l);for(let m=0;m<80&&s-a>1e-12*Math.max(1,Math.abs(a));m++)h<f?(a=u,u=l,h=f,l=a+c*(s-a),f=t(l)):(s=l,l=u,f=h,u=s-c*(s-a),h=t(u));let p=h>f?u:l,M=Math.max(h,f);o[i]>M&&(p=r[i],M=o[i]);let N=m=>{let w=m<0?e:n,A=Math.max(1e-6,.001*(r[1]-r[0])),b=p;for(;;){let x=p+m*A;if(m<0?x<=w:x>=w)return w;if(t(x)<M-46){let F=x;for(let _=0;_<6;_++){let H=.5*(b+F);t(H)<M-46?F=H:b=H}return F}b=x,A*=2}},g=N(-1),E=N(1),d=[...new Set([g,p,E])].sort((m,w)=>m-w);return M+Math.log(ht(m=>Math.exp(t(m)-M),d,We,4*et*Math.max(1,Math.abs(M))))}var Kt=-10,Ht=10;function rr(t,e){return t<=0?0:e*Ke(n=>V(n)*tr(n,t,e-1),Kt,Ht)}function Xe(t,e){if(t<=0)return 1;let n=i=>{let a=Mt(i);if(a===0)return 0;let{ah:s,al:c}=Z(i,t),u=nt(s,c),l=u<.5*a?-Math.expm1((e-1)*Math.log1p(-u/a)):-Math.expm1((e-1)*Math.log(Oe(i,t)/a));return V(i)*er(i,e-1)*l};if(t>60)return 0;let[r,o]=Be(t);return e*Ke(n,r,o)}function Be(t){return t>40?[t/2-15,t/2+15]:[Kt,t+Ht]}function or(t,e){if(t>100)return-Math.exp(je(t,e));let n=r=>-rt-r*r/2+(e-1)*De(r,t);return Math.log(e)+He(n,Kt,Ht)}function je(t,e){if(t>100){let i=e*(e-1);return(Number.isFinite(i)?Math.log(i):Math.log(e)+Math.log(e-1))+Dt(t/Math.SQRT2)}let n=i=>{let a=qt(i),s=qe(i,t)-a,c;return s<-40?c=Math.log(e-1)+s:s<-Math.LN2?c=Math.log(-Math.expm1((e-1)*Math.log1p(-Math.exp(s)))):c=Math.log(-Math.expm1((e-1)*(De(i,t)-a))),-rt-i*i/2+(e-1)*a+c},[r,o]=Be(t);return Math.log(e)+He(n,r,o)}function ir(t,e){let n=-1/0;for(let r of e)n=Math.max(n,t(r));for(let r=0;r+1<e.length;r++)n=Math.max(n,t(.5*(e[r]+e[r+1])));if(n===-1/0)return-1/0;if(et*Math.abs(n)>1)return n;for(let r=0;r<4;r++){let o=n,i=ht(a=>{let s=t(a);return s>o&&(o=s),Math.exp(s-n)},e,Pe,8*et*Math.max(1,Math.abs(n)));if(Number.isFinite(i)&&o-n<300)return n+Math.log(i);n=o}return NaN}var q=32,ar=1e-15,Q=Math.log(.01),pt=Math.log(20),Ge=Math.log(40),Qe=Float64Array.from({length:2*q+1},(t,e)=>Math.cos(Math.PI*e/q));function sr(t,e){let n=new Float64Array(e+1);for(let r=0;r<=e;r++){let o=.5*(t[0]+(r%2===0?t[e]:-t[e]));for(let i=1;i<e;i++)o+=t[i]*Qe[r*i%(2*e)];o*=2/e,(r===0||r===e)&&(o*=.5),n[r]=o}return n}function Tt(t,e,n){let r=[],o=[[e,n,0]];for(;o.length>0;){let[i,a,s]=o.pop(),c=.5*(i+a),u=.5*(a-i),l=new Float64Array(q+1),h=1/0;for(let M=0;M<=q;M++)l[M]=t(c+u*Qe[M]),h=Math.min(h,Math.max(1,Math.abs(l[M])));let f=sr(l,q),p=0;for(let M=q-3;M<=q;M++)p=Math.max(p,Math.abs(f[M]));p<=ar*h||s>=14||!l.every(Number.isFinite)?r.push({a:i,b:a,coef:f}):o.push([c,a,s+1],[i,c,s+1])}return r.sort((i,a)=>i.a-a.a)}function Lt(t,e){let n=0,r=t.length-1;for(;n<r;){let l=n+r+1>>1;t[l].a<=e?n=l:r=l-1}let{a:o,b:i,coef:a}=t[n],s=(2*e-o-i)/(i-o),c=0,u=0;for(let l=q;l>=1;l--){let h=2*s*c-u+a[l];u=c,c=h}return s*c-u+a[0]}var k=new Map,cr=64,Ue=Math.log(1e-10);function Ve(t){let e=k.get(t);if(e!==void 0)return e;let n=o=>{let i=rr(o,t);return i>1e-290?Math.log(i):or(o,t)},r=o=>{let i=Math.exp(o);return Xe(i,t)*Ze(i)};return e={logW:Tt(o=>n(Math.exp(o)),Q,pt),scaledWc:Tt(r,Q,Ge),smallW:Tt(o=>n(Math.exp(o))-(t-1)*o,Ue,Q)},k.size>=cr&&k.delete(k.keys().next().value),k.set(t,e),e}function Ze(t){let e=t*t,n=134217729*t,r=n-(n-t),o=t-r,i=r*r-e+2*r*o+o*o;return Math.exp(e/4)*(1+i/4)}function ze(t,e){let n=Math.log(t);if(n>=pt)return 0;let r=Ve(e);return n>=Q?Lt(r.logW,n):Lt(r.smallW,Math.max(n,Ue))+(e-1)*n}function Ct(t,e){return Math.log(t)>=pt?1:Math.exp(ze(t,e))}function Pt(t,e){let n=Math.log(t);return n>=Q&&n<=Ge?Lt(Ve(e).scaledWc,n)/Ze(t):n<Q?1-Ct(t,e):Xe(t,e)}function lt(t,e,n,r){if(!r){let i=Math.min(Ct(t,e),1);return n===1?i:i**n}let o=Math.min(Pt(t,e),1);return o<=.5?n===1?o:-Math.expm1(n*Math.log1p(-o)):1-Math.min(Ct(t,e),1)**n}function Wt(t,e,n,r){if(!r)return n*(Math.log(t)<pt?ze(t,e):Math.log1p(-Math.min(Pt(t,e),1)));let o=Math.min(Pt(t,e),1),i=o>1e-290?Math.log(o):je(t,e);return n===1?i:i<-700?Math.log(n)+i:Math.log(-Math.expm1(n*Math.log1p(-Math.exp(i))))}function $t(t,e,n,r,o){if(n===1/0||ke(t,e,n,r))return lt(t,e,r,o);let i=n/2,a=Je(i);return ht(c=>{let u=Math.exp(a(c));return u===0?0:u*lt(t*Math.exp(.5*c),e,r,o)},tn(t,e,n,r,o),Pe)}function Je(t){let e=.5*Math.log(t/(2*Math.PI))-kt(t);return n=>{let r;if(Math.abs(n)<.5){let o=n*n/2;r=o;for(let i=3;i<60&&(o*=n/i,r+=o,!(Math.abs(o)<1e-17*r));i++);}else r=Math.expm1(n)-n;return e-t*r}}function ke(t,e,n,r){let o=Math.max((e-1)*r,t*t,1);return o*o<1e-17*n}function ur(t,e,n,r,o){if(n===1/0||ke(t,e,n,r))return Wt(t,e,r,o);let i=Je(n/2),a=Math.log(t);return ir(c=>i(c)+Wt(Math.exp(a+.5*c),e,r,o),tn(t,e,n,r,o,!0))}function tn(t,e,n,r,o,i=!1){let a=n/2,s=a,c;if(o){let m=2*Math.log(t)-Math.log(4*a);c=-(m>30?m:Math.log1p(Math.exp(m)))}else s=a+(e-1)*r/2,c=Math.log1p((e-1)*r/(2*a));let u=(m,w)=>[m-9/Math.sqrt(w)-41/w,m+9/Math.sqrt(w)+Math.log1p(41/w)],[l,h]=u(0,a),[f,p]=u(c,s),M=i?Math.min(l,f):Math.max(Math.min(l,f),-740-Math.log(a)),N=Math.max(h,p),g=1/Math.sqrt(a),E=1/Math.sqrt(s),d=[M,Math.min(-4*g,c-4*E),Math.max(4*g,c+4*E),N];return[...new Set(d.map(m=>Math.min(Math.max(m,M),N)))].sort((m,w)=>m-w)}function en(t,e,n){return t>=2&&e>=2&&n>=1&&Number.isFinite(t)&&Number.isFinite(n)&&!Number.isNaN(e)}function ft(t,e,n,r,o,i){if(t<Fe){let s=ft(Fe,e,n,r,!0,!0)+(e-1)*r*Math.log(t*10715086071862673e285);return o?i?s:Math.exp(s):i?-Math.exp(s):-Math.expm1(s)}let a;return K!==void 0&&K.q===t&&K.k===e&&K.df===n&&K.r===r?a=K.tail:(a=lr(t,e,n,r,!o),K={q:t,k:e,df:n,r,tail:a}),a.upper===!o?i?a.log:a.value:i?Math.log1p(-a.value):1-a.value}var K,Fe=2**-1e3;function lr(t,e,n,r,o){let i=o;n!==1/0&<(t,e,r,i)>.5&&(i=!i);let a=$t(t,e,n,r,i);if(a>.5){let s=$t(t,e,n,r,!i);s<a&&(a=s,i=!i)}if(a<1e-290){let s=ur(t,e,n,r,i);return{upper:i,value:Math.exp(s),log:s}}return{upper:i,value:a,log:Math.log(a)}}function fr(t,e,n,r,o,i){return[t,e,n,r].some(Number.isNaN)?NaN:en(e,n,r)?t<=0?S(o,i):t===1/0?T(o,i):ft(t,e,n,r,o,i):NaN}function hr(t,e,n,r,o,i){if([t,e,n,r].some(Number.isNaN))return NaN;if(!en(e,n,r))return NaN;let a=P(t,0,1/0,o,i);if(a!==void 0)return a;let{lower:s,logTarget:c,linearTarget:u}=Jt(t,o,i),l=f=>p=>{let M=Math.exp(p);if(u!==void 0&&u>1e-290){let g=f===1/0?$t(M,e,f,r,!s):ft(M,e,f,r,s,!1);if(g>0)return Math.log(g/u)}return(f===1/0?Mr(M,e,r,s):ft(M,e,f,r,s,!0))-c},h=Le(l(1/0),Math.log(3),s);return Math.exp(n===1/0?h:Le(l(n),h,s))}function Mr(t,e,n,r){let o=lt(t,e,n,!r);return o>1e-290?Math.log(o):Wt(t,e,n,!r)}function Le(t,e,n){let r=e,o=t(r);if(o===0)return r;let i=o>0===n?-1:1,a=.05,s=r+i*a,c=t(s),u=NaN;for(let l=0;l<200&&Math.sign(c)===Math.sign(o)&&c!==0;l++){if(Math.abs(u-s)<.001)return s;for(r=s,o=c,a*=2,s=(r+i*a-u)*i>=0?.5*(r+u):r+i*a,c=t(s);!Number.isFinite(c);){if(u=s,Math.abs(u-r)<.001)return r;s=.5*(r+u),c=t(s)}}return c===0?s:!Number.isFinite(c)||Math.sign(c)===Math.sign(o)?Number.isFinite(c)?s:r:pr(t,r,s,o,c)}function pr(t,e,n,r,o){let i=e,a=r,s=n-e,c=s;for(let u=0;u<100;u++){Math.sign(o)===Math.sign(a)&&(i=e,a=r,s=n-e,c=s),Math.abs(a)<Math.abs(o)&&(e=n,n=i,i=e,r=o,o=a,a=r);let l=2*et*Math.abs(n)+1e-300,h=.5*(i-n);if(Math.abs(h)<=l||o===0)return n;if(Math.abs(c)>=l&&Math.abs(r)>Math.abs(o)){let f=o/r,p,M;if(e===i)p=2*h*f,M=1-f;else{let N=r/a,g=o/a;p=f*(2*h*N*(N-g)-(n-e)*(g-1)),M=(N-1)*(g-1)*(f-1)}p>0?M=-M:p=-p,2*p<Math.min(3*h*M-Math.abs(l*M),Math.abs(c*M))?(c=s,s=p/M):(s=h,c=h)}else s=h,c=h;e=n,r=o,n+=Math.abs(s)>l?s:h>0?l:-l,o=t(n)}return n}function lo(t,e,n,r={}){y(r,Kn,"ptukey");let{nranges:o=1,lowerTail:i=!0,logP:a=!1}=r;return I(t,s=>fr(s,e,n,o,i,a))}function fo(t,e,n,r={}){y(r,Hn,"qtukey");let{nranges:o=1,lowerTail:i=!0,logP:a=!1}=r;return I(t,s=>hr(s,e,n,o,i,a))}function Xt(t){let e=[],n=[];for(let r=1;r<=t/2;r++){let o=Math.cos(Math.PI*(r-.25)/(t+.5)),i=0;for(let a=0;a<100;a++){let s=1,c=o;for(let l=2;l<=t;l++)[s,c]=[c,((2*l-1)*o*c-(l-1)*s)/l];i=t*(o*c-s)/(o*o-1);let u=c/i;if(o-=u,Math.abs(u)<=1e-17)break}e.push(o),n.push(2/((1-o*o)*i*i))}return{x:e,w:n}}var mr=[Xt(6),Xt(12),Xt(20)],Bt=2*Math.PI,Y=t=>R(t,{lowerTail:!1});function gr(t,e,n){if(n===1)return Y(Math.max(t,e));if(n===-1)return t>=-e?0:t>=0?Y(t)-Y(-e):R(-e)-R(t);let{x:r,w:o}=mr[Math.abs(n)<.3?0:Math.abs(n)<.75?1:2],i=t*e;if(Math.abs(n)<.925){let g=(t*t+e*e)/2,E=Math.asin(n),d=0;for(let m=0;m<r.length;m++)for(let w of[1-r[m],1+r[m]]){let A=Math.sin(E*w/2);d+=o[m]*Math.exp((A*i-g)/(1-A*A))}return d*E/(2*Bt)+Y(t)*Y(e)}let a=n<0?-e:e,s=n<0?-i:i,c=(1-n)*(1+n),u=Math.sqrt(c),l=(t-a)**2,h=(4-s)/8,f=(12-s)/16,p=u*Math.exp(-(l/c+s)/2)*(1-h*(l-c)*(1-f*l/5)/3+h*f*c*c/5);if(s>-160){let g=Math.sqrt(l);p-=Math.exp(-s/2)*Math.sqrt(Bt)*R(-g/u)*g*(1-h*l*(1-f*l/5)/3)}let M=u/2;for(let g=0;g<r.length;g++)for(let E of[1-r[g],1+r[g]]){let d=(M*E)**2,m=Math.sqrt(1-d);p+=M*o[g]*(Math.exp(-l/(2*d)-s/(1+m))/m-Math.exp(-(l/d+s)/2)*(1+h*d*(1+f*d)))}let N=-p/Bt;return n>0?N+Y(Math.max(t,a)):-N+(a>t?R(a)-R(t):0)}function mt(t,e,n){return t===1/0||e===1/0?0:t===-1/0?e===-1/0?1:Y(e):e===-1/0?Y(t):gr(t,e,n)}function po(t,e,n){if(t.length!==2||e.length!==2)throw new TypeError("'lower' and 'upper' must have length 2");if(!(n>=-1&&n<=1))throw new RangeError("'rho' must be in [-1, 1]");let[r,o]=t,[i,a]=e;if([r,o,i,a].some(Number.isNaN))return NaN;if([r,o,i,a]=[r,o,i,a].map(c=>c>40?1/0:c<-40?-1/0:c),!(r<i&&o<a))return 0;r+i+o+a<0&&([r,o,i,a]=[-i,-a,-r,-o]);let s=mt(r,o,n)-mt(r,a,n)-mt(i,o,n)+mt(i,a,n);return Math.max(0,s)}var dr=["size","replace","prob"],Nr=["size","replace","prob"];function wo(t,e={}){return y(e,Nr,"sampleInt"),nn(t,e).map(n=>n-1)}function nn(t,e){if(!Number.isFinite(t)||t<0||t>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");t=Math.trunc(t);let{replace:n=!1,prob:r}=e,o=e.size!==void 0,i=o?e.size:t;if(!Number.isFinite(i)||i<=-1)throw new RangeError("size must be a non-negative number");let a=Math.trunc(i);if(t===0&&a>0)throw new RangeError("cannot take a sample from an empty population");if(r!==void 0){if(a>=2**31)throw new RangeError("size must be less than 2^31 with prob");if(t>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(r.length!==t)throw new TypeError("prob must have length n");let l=on(r,a,n);if(n){let h=rn(l),f=new Array(a);for(let p=0;p<a;p++)f[p]=h();return f}if(a>t)throw new RangeError("cannot take a sample larger than the population when replace is false");return xr(l,a)}if(!n&&a>t)throw new RangeError("cannot take a sample larger than the population when replace is false");if(!n&&t>1e7&&o&&a<=t/2){let l=new Set,h=[];for(;h.length<a;){let f=J(t);l.has(f)||(l.add(f),h.push(f+1))}return h}let s=new Array(a);if(n||a<2){for(let l=0;l<a;l++)s[l]=J(t)+1;return s}if(t>=2**31)throw new RangeError("n must be less than 2^31 to sample without replacement with size above n / 2");let c=new Int32Array(t);for(let l=0;l<t;l++)c[l]=l;let u=t;for(let l=0;l<a;l++){let h=J(u);s[l]=c[h]+1,c[h]=c[--u]}return s}function xo(t,e){if(!Number.isFinite(t)||t<0||t>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");if(t=Math.trunc(t),t>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(e.length!==t)throw new TypeError("prob must have length n");let n=rn(on(e,0,!0));return()=>n()-1}function rn(t){let e=t.length,n=0;for(let r=0;r<e;r++)e*t[r]>.1&&n++;return n>200?Er(t):wr(t)}function Eo(t,e={}){return y(e,dr,"sample"),nn(t.length,e).map(n=>t[n-1])}function on(t,e,n){let r=0,o=0;for(let i of t){if(!Number.isFinite(i))throw new RangeError("prob contains NaN or infinite values");if(i<0)throw new RangeError("prob contains negative values");i>0&&(o++,r+=i)}if(o===0||!n&&e>o)throw new RangeError("too few positive probabilities");if(r===1/0){let i=ie(t);r=0;for(let a of t)r+=a/i;return Float64Array.from(t,a=>a/i/r)}return Float64Array.from(t,i=>i/r)}function br(t,e){let n=t.length;if(n<=1)return;let r=c=>t[c-1],o=(n>>1)+1,i=n,a,s;for(;;){if(o>1)o=o-1,a=r(o),s=e[o-1];else if(a=r(i),s=e[i-1],t[i-1]=r(1),e[i-1]=e[0],--i===1){t[0]=a,e[0]=s;return}let c=o,u=o<<1;for(;u<=i;)u<i&&r(u)>r(u+1)&&++u,a>r(u)?(t[c-1]=r(u),e[c-1]=e[u-1],c=u,u+=u):u=i+1;t[c-1]=a,e[c-1]=s}}function an(t){let e=new Int32Array(t.length);for(let n=0;n<t.length;n++)e[n]=n+1;return br(t,e),e}function wr(t){let e=Float64Array.from(t),n=e.length,r=an(e);for(let o=1;o<n;o++)e[o]+=e[o-1];return()=>{let o=W(),i=0;for(;i<n-1&&!(o<=e[i]);i++);return r[i]}}function xr(t,e){let n=Float64Array.from(t),r=n.length,o=an(n),i=new Array(e),a=1;for(let s=0,c=r-1;s<e;s++,c--){let u=a*W(),l=0,h=0;for(;h<c&&(l+=n[h],!(u<=l));h++);i[s]=o[h],a-=n[h];for(let f=h;f<c;f++)n[f]=n[f+1],o[f]=o[f+1]}return i}function Er(t){let e=t.length,n=new Float64Array(e),r=new Int32Array(e),o=new Int32Array(e),i=-1,a=e;for(let c=0;c<e;c++)n[c]=t[c]*e,n[c]<1?o[++i]=c:o[--a]=c;if(i>=0&&a<e)for(let c=0;c<e-1;c++){let u=o[c],l=o[a];if(r[u]=l,n[l]+=n[u]-1,n[l]<1&&a++,a>=e)break}let s=ae();return()=>{let c,u;return s?(u=W()*e,c=Math.trunc(u)):(c=J(e),u=c+W()),u<n[c]+c?c+1:r[c]+1}}var yr=2**24;function Ir(t){let e=new Float64Array(t+1);for(let n=2;n<=t;n++)e[n]=e[n-1]+Math.log(n);return e}function vr(t,e,n,r){let o=t.length,i=e.length,a=Array.from(e),s=0;for(let u of t)s+=u;for(let u=0;u<o-1;u++){let l=t[u],h=s;s-=l;let f=0;for(;f<i-1;f++){let p=a[f],M=h;h-=p;let N=M-l,g=N-p;if(M===0){for(let m=f;m<i-1;m++)r[u+m*o]=0;l=0;break}let E=W(),d;t:for(;;){d=Math.floor(l*(p/M)+.5);let m=Math.exp(n[l]+n[N]+n[h]+n[p]-n[M]-n[d]-n[p-d]-n[l-d]-n[g+d]);if(m>=E)break;if(m===0)throw new Error(`r2dtable: probability underflow at cell [${u}, ${f}]`);let w=m,A=m,b=d,x=!1,F=!1;for(;!(x&&F);){if(!x){let _=(p-d)*(l-d);if(_===0)x=!0;else if(d++,m=m*_/(d*(g+d)),w+=m,w>=E)break t}do{let _=b*(g+b);if(_===0){F=!0;break}if(b--,A=A*_/((p-b)*(l-b)),w+=A,w>=E){d=b;break t}}while(x)}E=w*W()}r[u+f*o]=d,l-=d,a[f]=a[f]-d}r[u+(i-1)*o]=l}let c=e[i-1];for(let u=0;u<o-1;u++)c-=r[u+(i-1)*o];for(let u=0;u<i-1;u++)r[o-1+u*o]=a[u];r[o-1+(i-1)*o]=c}function sn(t,e){let n=Array.from(t,r=>Math.trunc(r));if(n.length<=1||n.some(r=>!(r>=0)||r>2147483647))throw new RangeError(`invalid argument '${e}'`);return n}function vo(t,e,n){if(!(Number.isFinite(t)&&t>-1&&t<2**31))throw new RangeError("invalid argument 'n'");let r=Math.trunc(t),o=sn(e,"r"),i=sn(n,"c"),a=o.reduce((l,h)=>l+h,0);if(a!==i.reduce((l,h)=>l+h,0))throw new RangeError("arguments 'r' and 'c' must have the same sums");if(a>2147483647)throw new RangeError("the sum of 'r' must be at most 2147483647");if(r===0)return[];if(a>yr)throw new RangeError("the sum of 'r' must be at most 16777216 (2^24) to generate tables");let s=Ir(a),c=new Int32Array(o.length*i.length),u=[];for(let l=0;l<r;l++)vr(o,i,s,c),u.push(o.map((h,f)=>i.map((p,M)=>c[f+M*o.length])));return u}export{Mn as a,xt as b,mn as c,bn as d,Wr as e,$r as f,Or as g,_n as h,Rn as i,jr as j,Gr as k,Qr as l,qn as m,Dn as n,Yn as o,eo as p,no as q,ro as r,lo as s,fo as t,po as u,wo as v,xo as w,Eo as x,yr as y,Ir as z,vr as A,vo as B};
|
|
1
|
+
/*! rStats.js 1.8.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{A as re,B as oe,f as G,z as ne}from"./chunk-HYJ4MIZE.js";import{a as S,b as T,c as L,d as P,e as Jt}from"./chunk-HXYH5ZMB.js";import{g as W,h as ae,i as J}from"./chunk-TQM6KGKT.js";import{a as ie}from"./chunk-YD4U3QZ3.js";import{a as C,b as j,c as v}from"./chunk-D3LKPD4H.js";import{A as kt,B as te,E as ee,e as I,r as R,s as B}from"./chunk-73IRLCTF.js";import{b as Ut,c as Nt,d as ot,e as Vt,f as Zt,g as z,i as it,k as zt,l as y}from"./chunk-2ZQ2TSZS.js";var ln=["log"],fn=["lowerTail","logP"],hn=["lowerTail","logP"];function bt(t,e,n,r){if(t===0&&e===0)return{e:[0,0],logDenom:0};if(t===0||e===0){let o=t+e,[i,a]=t===0?[r,n]:[n,r];return{e:a[0]<.1?ot(te(o,z([o,0],i)),z([o,0],a)):Vt(z([o,0],zt(i))),logDenom:0}}return ee(t,e,n,r)}function le(t,e,n,r){let o=e+n,i=it([r,0],[o,0]),a=it([o-r,0],[o,0]),s=bt(t,e-t,i,a),c=bt(r-t,n-r+t,i,a),u=bt(r,o-r,i,a);return{e:Zt(ot(s.e,c.e),u.e),logDenom:s.logDenom+c.logDenom-u.logDenom}}function fe(t,e){let[n,r]=t.e,o=e*Math.exp(-.5*t.logDenom);return n<700?Math.exp(-n)*(1-r)*o:Math.exp(700-n)*(1-r)*o*Math.exp(-700)}function he(t){return-t.e[0]-t.e[1]-.5*t.logDenom}function wt(t,e){return Ut(t,e)[1]===0}function at(t,e,n){return[Math.max(0,n-e),Math.min(n,t)]}function Mn(t,e,n,r,o){if([t,e,n,r].some(Number.isNaN))return NaN;if(![e,n,r].every(Number.isFinite)||C(e)||C(n)||C(r))return NaN;if(e=v(e),n=v(n),r=v(r),e<0||n<0||r<0||r>e+n)return NaN;if(Et(e,n,r))return ne(t,r,xt(e,n),o);if(C(t))return L(o);t=v(t);let[i,a]=at(e,n,r);if(t<i||t>a)return L(o);if(r===0)return o?0:1;if(!wt(e,n))return NaN;if(r===e+n)return o?0:1;let s=le(t,e,n,r);return o?he(s):fe(s,1)}function se(t,e,n,r){return it(Nt(t,e),Nt(n,r))}function pn(t,e,n,r,o,i,a){let s=[1,0],c=[1,0],u=t;for(;!(o?u<=i:u>=a);){let l=o?se(u,n-r+u,e-u+1,r-u+1):se(e-u,r-u,u+1,n-r+u+1);s=z(s,l),c=ot(c,s),u+=o?-1:1;let h=l[0];if(h<1&&s[0]*h/(1-h)<c[0]*2**-60)break}return c[0]+c[1]}function Me(t,e,n,r,o,i){let[a,s]=at(e,n,r),c=e+n,u=t*c<r*e,l=ce(t,e,n,r,u,a,s);if(l.value>.5){let h=ce(t,e,n,r,!u,a,s);h.value<l.value&&(l=h,u=!u)}return u===o?i?l.value>1e-300?Math.log(l.value):he(l.form)+Math.log(l.sum):l.value:i?Math.log1p(-l.value):1-l.value}function ce(t,e,n,r,o,i,a){let s=o?t:t+1,c=le(s,e,n,r),u=pn(s,e,n,r,o,i,a);return{form:c,sum:u,value:fe(c,u)}}function xt(t,e){return t>=e?1/(1+e/t):e/t===1/0?0:t/e/(1+t/e)}function Et(t,e,n){return n>0&&n<t*2**-60+e*2**-60}function pe(t,e,n){if([t,e,n].every(Number.isFinite)&&(t=v(t),e=v(e),n=v(n),!(t<0||e<0||n<0||n>t+e)))return[t,e,n]}function mn(t,e,n,r,o,i){if([t,e,n,r].some(Number.isNaN))return NaN;let a=pe(e,n,r);if(a===void 0)return NaN;if([e,n,r]=a,Et(e,n,r))return re(t,r,xt(e,n),o,i);let s=j(t),[c,u]=at(e,n,r);if(s<c)return S(o,i);if(s>=u)return T(o,i);if(u>ge||!wt(e,n))return NaN;let l=gn(s,e,n,r,c,u);if(l>dn)throw new RangeError(`phyper: m = ${e}, n = ${n}, k = ${r} needs about ${Math.round(l)} terms at q = ${t} (at most 2^26)`);return Me(s,e,n,r,o,i)}function me(t,e,n,r){return n*t/r*(e/r)*(r-n)/Math.max(r-1,1)}function ue(t,e,n,r,o,i){let a=e?n-t:t-n,s=Math.sqrt(a*a+83*r);return Math.min(a>=0?83*r/(s+a):s-a,e?t-o:i-t)}function gn(t,e,n,r,o,i){let a=e+n,s=r*e/a,c=me(e,n,r,a),u=t*a<r*e,l=u?t:t+1,h=ue(l,u,s,c,o,i);return Math.abs(l-s)>=1?h:h+ue(u?t+1:t,!u,s,c,o,i)}var dn=2**26,Nn=2**21,ge=2**53;function bn(t,e,n,r,o,i,a=!0){if([t,e,n,r].some(Number.isNaN))return NaN;let s=pe(e,n,r);if(s===void 0)return NaN;if([e,n,r]=s,Et(e,n,r))return oe(t,r,xt(e,n),o,i);let[c,u]=at(e,n,r),l=P(t,c,u,o,i);if(l!==void 0)return l;if(c===u)return c;if(u>ge||!wt(e,n))return NaN;let h=e+n,f=r*e/h,p=Math.sqrt(me(e,n,r,h));if(a&&p>Nn)throw new RangeError(`qhyper: m = ${e}, n = ${n}, k = ${r} has a standard deviation of about ${p.toPrecision(3)} (at most 2^21)`);let M=B(t,{lowerTail:o,logP:i}),N=f+p*M;return G({p:t,lowerTail:o,logP:i,cdf:(g,E,d)=>g<c?S(E,d):g>=u?T(E,d):Me(g,e,n,r,E,d),y0:Number.isFinite(N)?N:f,lo:c,hi:u})}function Wr(t,e,n,r,o={}){y(o,ln,"dhyper");let i=o.log??!1;return I(t,a=>Mn(a,e,n,r,i))}function $r(t,e,n,r,o={}){y(o,fn,"phyper");let{lowerTail:i=!0,logP:a=!1}=o;return I(t,s=>mn(s,e,n,r,i,a))}function Or(t,e,n,r,o={}){y(o,hn,"qhyper");let{lowerTail:i=!0,logP:a=!1}=o;return I(t,s=>bn(s,e,n,r,i,a))}var wn=["log"],xn=["lowerTail","logP"],En=["lowerTail","logP"],yn=2**900,de=-900,$=new Map,In=2**21,st=0,vn=2**25;function be(t,e){if(e+1>vn)throw new RangeError(`signrank: n = ${t} needs too large a table (${e+1} entries)`);let n=new Float64Array(e+1);n[0]=1;let r=0,o=-1/0,i=Math.min(t,e);for(let u=1;u<=i;u++){for(let l=e;l>=u;l--)n[l]+=n[l-u];if(n[Math.min(e,Math.floor(u*(u+1)/4))]>yn){let l=2**de;for(let h=0;h<=e;h++)n[h]*=l;r-=de,o=Math.max(o,r-1015+i-u)}}let a=new Float64Array(e+1),s=0,c=0;for(let u=0;u<=e;u++){let l=n[u]-c,h=s+l;c=h-s-l,s=h,a[u]=s}return{n:t,len:e+1,count:n,cum:a,scale:r,minTrusted:2**(o-r)}}function Ne(t,e,n=!1){let r=n?-t:t,o=$.get(r);if(o!==void 0&&o.len>e)return $.delete(r),$.set(r,o),o;let i=Math.floor(t*(t+1)/4),a=Math.min(i,Math.max(e,o===void 0?0:2*o.len));return we(r,be(t,a),o)}function we(t,e,n){n!==void 0&&($.delete(t),st-=n.len),$.set(t,e),st+=e.len;for(let[r,o]of $){if(st<=In||r===t)break;$.delete(r),st-=o.len}return e}function yt(t,e,n){let r=(a,s)=>e===a.len-1||s>=(n?(e+1)*a.minTrusted:a.minTrusted),o=Ne(t,e),i=(n?o.cum:o.count)[e];return r(o,i)?[i,o]:(o=Ne(t,e,!0),i=(n?o.cum:o.count)[e],r(o,i)?[i,o]:(o=we(-t,be(t,e),$.get(-t)),[(n?o.cum:o.count)[e],o]))}function It(t,e,n){let r=e.scale-e.n,o=Math.trunc(r/2),i=t*2**o*2**(r-o);if(!n)return i;if(i>=1e-300)return Math.log(i);let a=Math.floor(Math.log2(t)),s=Math.trunc(a/2),c=t*2**-s*2**-(a-s);return c>=2?(c/=2,a++):c<1&&(c*=2,a--),Math.log(c)+(a+r)*Math.LN2}function vt(t){return Number.isFinite(t)?(t=v(t),t<=0||t>=2**27?NaN:t):NaN}function An(t,e,n){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;if(C(t))return L(n);t=v(t);let r=e*(e+1)/2;if(t<0||t>r)return L(n);let o=Math.min(t,r-t),[i,a]=yt(e,o,!1);return It(i,a,n)}function xe(t,e,n,r){let o=e*(e+1)/2,i=t,a=o-t-1,s=n?i:a,c=n?a:i;if(s<=c){let[f,p]=yt(e,s,!0);return It(f,p,r)}let[u,l]=yt(e,c,!0),h=It(u,l,!1);return r?Math.log1p(-h):1-h}function _n(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;let o=j(t),i=e*(e+1)/2;return o<0?S(n,r):o>=i?T(n,r):xe(o,e,n,r)}function Rn(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e))return NaN;if(e=vt(e),Number.isNaN(e))return NaN;let o=e*(e+1)/2,i=P(t,0,o,n,r);if(i!==void 0)return i;let a=o/2,s=Math.sqrt(e*(e+1)*(2*e+1)/24),c=a+s*B(t,{lowerTail:n,logP:r});return G({p:t,lowerTail:n,logP:r,cdf:(u,l,h)=>u<0?S(l,h):u>=o?T(l,h):xe(u,e,l,h),y0:Number.isFinite(c)?c:a,lo:0,hi:o})}function jr(t,e,n={}){y(n,wn,"dsignrank");let r=n.log??!1;return I(t,o=>An(o,e,r))}function Gr(t,e,n={}){y(n,xn,"psignrank");let{lowerTail:r=!0,logP:o=!1}=n;return I(t,i=>_n(i,e,r,o))}function Qr(t,e,n={}){y(n,En,"qsignrank");let{lowerTail:r=!0,logP:o=!1}=n;return I(t,i=>Rn(i,e,r,o))}var Sn=["log"],Tn=["lowerTail","logP"],Fn=["lowerTail","logP"],Ee=960,ye=2**996,Ln=2**25,_e=2**29,Cn=2**760,Ie=200,Pn=2**-969,ct=134217729,O=new Map,Wn=2**21,ut=0;function Re(t,e,n){if(n+1>Ln)throw new RangeError(`wilcox: m = ${t}, n = ${e} needs too large a table (${n+1} entries)`);if(t*(n+1)>_e)throw new RangeError(`wilcox: m = ${t}, n = ${e} needs ${t*(n+1)} steps for a table of ${n+1} entries (at most 2^29)`);let r=new Float64Array(n+1),o=new Float64Array(n+1);r[0]=2**Ee;let i=Ee,a=NaN,s=n+1;for(let f=1;f<=t;f++){let p=Math.min(s-1,f*e),M=e+f,N=ct*f,g=N-(N-f),E=f-g;N=ct*M;let d=N-(N-M),m=M-d;for(let b=0;b<=p;b++){let x=r[b];if(x===0)continue;if(!(Math.abs(x)<=ye)){s=b,p=b-1;break}let F=x*f;N=ct*x;let _=N-(N-x),H=x-_,cn=_*g-F+_*E+H*g+H*E+o[b]*f,X=F/M,jt=X*M;N=ct*X;let gt=N-(N-X),Gt=X-gt,un=gt*d-jt+gt*m+Gt*d+Gt*m,Qt=(F-jt-un+cn)/M,dt=X+Qt;o[b]=Qt-(dt-X),r[b]=dt,Math.abs(dt)<Pn&&Number.isNaN(a)&&(a=i)}let w=e+f;for(let b=p;b>=w;b--)ve(r,o,b,b-w,-1);for(let b=f;b<=p;b++)ve(r,o,b,b-f,1);let A=Math.min(p,Math.floor(f*e/2));for(;A>=0&&r[A]>0&&r[A]<Cn;){let b=2**Ie;for(let x=0;x<=p;x++)r[x]*=b,o[x]*=b;i+=Ie}}let c=new Float64Array(n+1),u=0,l=0;for(let f=0;f<s;f++){let p=r[f];if(!(Math.abs(p)<=ye)){s=f;break}let M=u+p,N=M-u,g=u-(M-N)+(p-N);g+=l+o[f],u=M+g,l=g-(u-M),c[f]=u}let h=Number.isNaN(a)?0:2**Math.min(1023,-909+Math.ceil(Math.log2(t*(n+1)))+i-a);return{m:t,n:e,len:n+1,prob:r,cum:c,scale:i,minTrusted:h,valid:s}}function ve(t,e,n,r,o){let i=t[n],a=o*t[r],s=i+a,c=s-i,u=i-(s-c)+(a-c);u+=e[n]+o*e[r];let l=s+u;e[n]=u-(l-s),t[n]=l}function Ae(t,e,n,r=!1){let o=`${t},${e}${r?",low":""}`,i=O.get(o);if(i!==void 0&&i.len>n)return O.delete(o),O.set(o,i),i;let a=Math.floor(t*e/2),s=i===void 0?0:Math.min(2*i.len,Math.floor(_e/t)-1),c=Math.min(a,Math.max(n,s));return Se(o,Re(t,e,c),i)}function Se(t,e,n){n!==void 0&&(O.delete(t),ut-=n.len),O.set(t,e),ut+=e.len;for(let[r,o]of O){if(ut<=Wn||r===t)break;O.delete(r),ut-=o.len}return e}function At(t,e,n,r){t>e&&([t,e]=[e,t]);let o=u=>{if(n>=u.valid)throw new RangeError(`wilcox: the exact distribution for m = ${t}, n = ${e} cannot be computed accurately at ${n} (from ${u.valid} on, near the center of large samples)`);return(r?u.cum:u.prob)[n]},i=(u,l)=>n===u.len-1||l>=(r?(n+1)*u.minTrusted:u.minTrusted),a=Ae(t,e,n),s=o(a);if(i(a,s))return[s,a];if(a=Ae(t,e,n,!0),s=o(a),i(a,s))return[s,a];let c=`${t},${e},low`;return a=Se(c,Re(t,e,n),O.get(c)),[o(a),a]}var $n=.6931471803691238,On=19082149292705877e-26;function _t(t,e,n){let r=-e.scale,o=Math.trunc(r/2),i=t*2**o*2**(r-o);if(!n)return i;if(i>=1e-300)return Math.log(i);let a=Math.floor(Math.log2(t)),s=Math.trunc(a/2),c=t*2**-s*2**-(a-s);return c>=2?(c/=2,a++):c<1&&(c*=2,a--),(a+r)*$n+(Math.log(c)+(a+r)*On)}function Rt(t,e){if(!(!Number.isFinite(t)||!Number.isFinite(e))&&(t=v(t),e=v(e),!(t<=0||e<=0||t*e>2**53)))return t*e===2**53&&BigInt(t)*BigInt(e)!==2n**53n?void 0:[t,e]}function qn(t,e,n,r){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let o=Rt(e,n);if(o===void 0)return NaN;if([e,n]=o,C(t))return L(r);t=v(t);let i=e*n;if(t<0||t>i)return L(r);let a=Math.min(t,i-t),[s,c]=At(e,n,a,!1);return _t(s,c,r)}function Te(t,e,n,r,o){let i=e*n,a=r?t:i-t-1,s=r?i-t-1:t;if(a<=s){let[h,f]=At(e,n,a,!0);return _t(h,f,o)}let[c,u]=At(e,n,s,!0),l=_t(c,u,!1);return o?Math.log1p(-l):1-l}function Dn(t,e,n,r,o){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let i=Rt(e,n);if(i===void 0)return NaN;[e,n]=i;let a=j(t);return a<0?S(r,o):a>=e*n?T(r,o):Te(a,e,n,r,o)}function Yn(t,e,n,r,o){if(Number.isNaN(t)||Number.isNaN(e)||Number.isNaN(n))return NaN;let i=Rt(e,n);if(i===void 0)return NaN;[e,n]=i;let a=e*n,s=P(t,0,a,r,o);if(s!==void 0)return s;let c=a/2,u=Math.sqrt(a*(e+n+1)/12),l=c+u*B(t,{lowerTail:r,logP:o});return G({p:t,lowerTail:r,logP:o,cdf:(h,f,p)=>h<0?S(f,p):h>=a?T(f,p):Te(h,e,n,f,p),y0:Number.isFinite(l)?l:c,lo:0,hi:a})}function eo(t,e,n,r={}){y(r,Sn,"dwilcox");let o=r.log??!1;return I(t,i=>qn(i,e,n,o))}function no(t,e,n,r={}){y(r,Tn,"pwilcox");let{lowerTail:o=!0,logP:i=!1}=r;return I(t,a=>Dn(a,e,n,o,i))}function ro(t,e,n,r={}){y(r,Fn,"qwilcox");let{lowerTail:o=!0,logP:i=!1}=r;return I(t,a=>Yn(a,e,n,o,i))}var Kn=["nranges","lowerTail","logP"],Hn=["nranges","lowerTail","logP"],D=128,et=Number.EPSILON,Xn=256,Ot=Float64Array.from({length:2*D+1},(t,e)=>Math.cos(Math.PI*e/D));function Bn(t){let e=new Float64Array(t+1);for(let n=0;n<=t;n++){let r=0;for(let o=0;o<=t;o+=2)r+=(o===0||o===t?.5:1)*Ot[o*n%(2*t)*(D/t)]*2/(1-o*o);e[n]=(n===0||n===t?.5:1)*2*r/t}return e}var jn=new Map([16,32,64,128].map(t=>[t,Bn(t)]));function Gn(t,e){let n=jn.get(e),r=D/e,o=0,i=0;for(let s=0;s<=e;s++)o+=n[s]*t[s],i+=Math.abs(n[s]*t[s]);let a=0;for(let s=e-7;s<=e;s++){let c=.5*(t[0]+(s%2===0?t[e]:-t[e]));for(let u=1;u<e;u++)c+=t[u]*Ot[s*u%(2*e)*r];c*=2/e,s===e&&(c*=.5),a=Math.max(a,Math.abs(c))}return{integral:o,tail:a,scale:i}}var tt=class{f;a;b;noise;c;h;values=new Float64Array(D+1);have=new Uint8Array(D+1);N=0;integral=0;error=1/0;constructor(e,n,r,o){this.f=e,this.a=n,this.b=r,this.noise=o,this.c=.5*(n+r),this.h=.5*(r-n)}advance(e){let n=D/e,r=new Float64Array(e+1);for(let i=0;i<=e;i++){let a=i*n;this.have[a]||(this.values[a]=this.f(this.c+this.h*Ot[a]),this.have[a]=1),r[i]=this.values[a]}let o=Gn(r,e);this.N=e,this.integral=o.integral*this.h,this.error=Math.max(o.tail*4/e,this.noise*o.scale)*Math.abs(this.h)}};function ht(t,e,n,r=4*et){let o=[];for(let a=0;a+1<e.length;a++){let s=new tt(t,e[a],e[a+1],r);s.advance(16),o.push(s)}for(let a=0;a<40;a++){let s=0;for(let f of o)s+=f.integral;let c=n*Math.abs(s)/o.length,u=!0,l=o.length,h=[];for(let f of o){if(f.error<=c||f.error<=r*Math.abs(f.integral)){h.push(f);continue}if(u=!1,f.N<D)f.advance(2*f.N),h.push(f);else if(l>=Xn)h.push(f);else{l++;let p=new tt(t,f.a,f.c,r),M=new tt(t,f.c,f.b,r);p.advance(16),M.advance(16),h.push(p,M)}}if(o=h,u)break}let i=0;for(let a of o)i+=a.integral;return i}function Ce(t,e,n){let r=Math.max(1,Math.ceil((e-t)/n));return Array.from({length:r+1},(o,i)=>i===r?e:t+(e-t)*i/r)}var Pe=2e-15,We=1e-16,Qn={lowerTail:!1},Un={logP:!0},Vn={lowerTail:!1,logP:!0},rt=.9189385332046728,Mt=t=>R(t),U=t=>R(t,Qn),qt=t=>R(t,Un),Dt=t=>R(t,Vn),Zn=.3989422804014327;function V(t){let e=Math.round(t*16)/16,n=t-e;return Zn*Math.exp(-.5*e*e)*Math.exp(-.5*n*(t+e))}var Ft=[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],$e=[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626];function zn(t,e){let n=t-.5*e,r=.5*e,o=0;for(let i=0;i<4;i++)o+=$e[i]*(V(n-r*Ft[i])+V(n+r*Ft[i]));return o*r}function Jn(t,e){let n=t-.5*e,r=.5*e,o=0;for(let i=0;i<4;i++){let a=r*Ft[i];o+=$e[i]*(Math.exp(n*a-a*a/2)+Math.exp(-n*a-a*a/2))}return-rt-n*n/2+Math.log(o*r)}var Yt=(t,e)=>e*Math.max(1,Math.abs(t),Math.abs(t-e))<.5;function Z(t,e){let n=t-e,r=n-t,o=t-(n-r)+(-e-r);return{ah:n,al:o}}function nt(t,e){return Mt(t)+V(t)*e}function kn(t,e){return U(t)-V(t)*e}function Oe(t,e){if(Yt(t,e))return zn(t,e);let{ah:n,al:r}=Z(t,e);return n>=0?kn(n,r)-U(t):t<=0?Mt(t)-nt(n,r):1-nt(n,r)-U(t)}function tr(t,e,n){if(t>0&&t-e<0&&!Yt(t,e)){let{ah:o,al:i}=Z(t,e);return Math.exp(n*Math.log1p(-(nt(o,i)+U(t))))}let r=Oe(t,e);return r>0?r**n:0}function er(t,e){return t>0?Math.exp(e*Math.log1p(-U(t))):Mt(t)**e}function qe(t,e){let{ah:n,al:r}=Z(t,e),o=qt(n);return o+r*Math.exp(-rt-n*n/2-o)}function nr(t,e){let{ah:n,al:r}=Z(t,e),o=Dt(n);return o-r*Math.exp(-rt-n*n/2-o)}function De(t,e){if(Yt(t,e))return Jn(t,e);if(t-e>=0){let i=nr(t,e);return i+Math.log(-Math.expm1(Dt(t)-i))}if(t<=0){let i=qt(t);return i+Math.log(-Math.expm1(qe(t,e)-i))}let{ah:r,al:o}=Z(t,e);return Math.log1p(-nt(r,o)-U(t))}var Ye=2,St=1e-18;function Ke(t,e,n){let r=Ce(e,n,Ye),o=r.map(t),i=0;for(let f=1;f<o.length;f++)o[f]>o[i]&&(i=f);let a=o[i];if(!(a>0))return 0;let s=Math.max(i-1,0),c=Math.min(i+1,o.length-1);for(;s>0&&o[s]>a*St;)s--;for(;c<o.length-1&&o[c]>a*St;)c++;let u=a*St,l=r[s],h=r[c];if(o[s]<=u){let f=r[s+1];for(let p=0;p<2;p++){let M=.5*(l+f);t(M)<=u?l=M:f=M}}if(o[c]<=u){let f=r[c-1];for(let p=0;p<2;p++){let M=.5*(h+f);t(M)<=u?h=M:f=M}}return ht(t,[l,h],We)}function He(t,e,n){let r=Ce(e,n,Ye),o=r.map(t),i=0;for(let m=1;m<o.length;m++)o[m]>o[i]&&(i=m);if(!(o[i]>-1/0))return-1/0;let a=r[Math.max(i-1,0)],s=r[Math.min(i+1,r.length-1)],c=(Math.sqrt(5)-1)/2,u=s-c*(s-a),l=a+c*(s-a),h=t(u),f=t(l);for(let m=0;m<80&&s-a>1e-12*Math.max(1,Math.abs(a));m++)h<f?(a=u,u=l,h=f,l=a+c*(s-a),f=t(l)):(s=l,l=u,f=h,u=s-c*(s-a),h=t(u));let p=h>f?u:l,M=Math.max(h,f);o[i]>M&&(p=r[i],M=o[i]);let N=m=>{let w=m<0?e:n,A=Math.max(1e-6,.001*(r[1]-r[0])),b=p;for(;;){let x=p+m*A;if(m<0?x<=w:x>=w)return w;if(t(x)<M-46){let F=x;for(let _=0;_<6;_++){let H=.5*(b+F);t(H)<M-46?F=H:b=H}return F}b=x,A*=2}},g=N(-1),E=N(1),d=[...new Set([g,p,E])].sort((m,w)=>m-w);return M+Math.log(ht(m=>Math.exp(t(m)-M),d,We,4*et*Math.max(1,Math.abs(M))))}var Kt=-10,Ht=10;function rr(t,e){return t<=0?0:e*Ke(n=>V(n)*tr(n,t,e-1),Kt,Ht)}function Xe(t,e){if(t<=0)return 1;let n=i=>{let a=Mt(i);if(a===0)return 0;let{ah:s,al:c}=Z(i,t),u=nt(s,c),l=u<.5*a?-Math.expm1((e-1)*Math.log1p(-u/a)):-Math.expm1((e-1)*Math.log(Oe(i,t)/a));return V(i)*er(i,e-1)*l};if(t>60)return 0;let[r,o]=Be(t);return e*Ke(n,r,o)}function Be(t){return t>40?[t/2-15,t/2+15]:[Kt,t+Ht]}function or(t,e){if(t>100)return-Math.exp(je(t,e));let n=r=>-rt-r*r/2+(e-1)*De(r,t);return Math.log(e)+He(n,Kt,Ht)}function je(t,e){if(t>100){let i=e*(e-1);return(Number.isFinite(i)?Math.log(i):Math.log(e)+Math.log(e-1))+Dt(t/Math.SQRT2)}let n=i=>{let a=qt(i),s=qe(i,t)-a,c;return s<-40?c=Math.log(e-1)+s:s<-Math.LN2?c=Math.log(-Math.expm1((e-1)*Math.log1p(-Math.exp(s)))):c=Math.log(-Math.expm1((e-1)*(De(i,t)-a))),-rt-i*i/2+(e-1)*a+c},[r,o]=Be(t);return Math.log(e)+He(n,r,o)}function ir(t,e){let n=-1/0;for(let r of e)n=Math.max(n,t(r));for(let r=0;r+1<e.length;r++)n=Math.max(n,t(.5*(e[r]+e[r+1])));if(n===-1/0)return-1/0;if(et*Math.abs(n)>1)return n;for(let r=0;r<4;r++){let o=n,i=ht(a=>{let s=t(a);return s>o&&(o=s),Math.exp(s-n)},e,Pe,8*et*Math.max(1,Math.abs(n)));if(Number.isFinite(i)&&o-n<300)return n+Math.log(i);n=o}return NaN}var q=32,ar=1e-15,Q=Math.log(.01),pt=Math.log(20),Ge=Math.log(40),Qe=Float64Array.from({length:2*q+1},(t,e)=>Math.cos(Math.PI*e/q));function sr(t,e){let n=new Float64Array(e+1);for(let r=0;r<=e;r++){let o=.5*(t[0]+(r%2===0?t[e]:-t[e]));for(let i=1;i<e;i++)o+=t[i]*Qe[r*i%(2*e)];o*=2/e,(r===0||r===e)&&(o*=.5),n[r]=o}return n}function Tt(t,e,n){let r=[],o=[[e,n,0]];for(;o.length>0;){let[i,a,s]=o.pop(),c=.5*(i+a),u=.5*(a-i),l=new Float64Array(q+1),h=1/0;for(let M=0;M<=q;M++)l[M]=t(c+u*Qe[M]),h=Math.min(h,Math.max(1,Math.abs(l[M])));let f=sr(l,q),p=0;for(let M=q-3;M<=q;M++)p=Math.max(p,Math.abs(f[M]));p<=ar*h||s>=14||!l.every(Number.isFinite)?r.push({a:i,b:a,coef:f}):o.push([c,a,s+1],[i,c,s+1])}return r.sort((i,a)=>i.a-a.a)}function Lt(t,e){let n=0,r=t.length-1;for(;n<r;){let l=n+r+1>>1;t[l].a<=e?n=l:r=l-1}let{a:o,b:i,coef:a}=t[n],s=(2*e-o-i)/(i-o),c=0,u=0;for(let l=q;l>=1;l--){let h=2*s*c-u+a[l];u=c,c=h}return s*c-u+a[0]}var k=new Map,cr=64,Ue=Math.log(1e-10);function Ve(t){let e=k.get(t);if(e!==void 0)return e;let n=o=>{let i=rr(o,t);return i>1e-290?Math.log(i):or(o,t)},r=o=>{let i=Math.exp(o);return Xe(i,t)*Ze(i)};return e={logW:Tt(o=>n(Math.exp(o)),Q,pt),scaledWc:Tt(r,Q,Ge),smallW:Tt(o=>n(Math.exp(o))-(t-1)*o,Ue,Q)},k.size>=cr&&k.delete(k.keys().next().value),k.set(t,e),e}function Ze(t){let e=t*t,n=134217729*t,r=n-(n-t),o=t-r,i=r*r-e+2*r*o+o*o;return Math.exp(e/4)*(1+i/4)}function ze(t,e){let n=Math.log(t);if(n>=pt)return 0;let r=Ve(e);return n>=Q?Lt(r.logW,n):Lt(r.smallW,Math.max(n,Ue))+(e-1)*n}function Ct(t,e){return Math.log(t)>=pt?1:Math.exp(ze(t,e))}function Pt(t,e){let n=Math.log(t);return n>=Q&&n<=Ge?Lt(Ve(e).scaledWc,n)/Ze(t):n<Q?1-Ct(t,e):Xe(t,e)}function lt(t,e,n,r){if(!r){let i=Math.min(Ct(t,e),1);return n===1?i:i**n}let o=Math.min(Pt(t,e),1);return o<=.5?n===1?o:-Math.expm1(n*Math.log1p(-o)):1-Math.min(Ct(t,e),1)**n}function Wt(t,e,n,r){if(!r)return n*(Math.log(t)<pt?ze(t,e):Math.log1p(-Math.min(Pt(t,e),1)));let o=Math.min(Pt(t,e),1),i=o>1e-290?Math.log(o):je(t,e);return n===1?i:i<-700?Math.log(n)+i:Math.log(-Math.expm1(n*Math.log1p(-Math.exp(i))))}function $t(t,e,n,r,o){if(n===1/0||ke(t,e,n,r))return lt(t,e,r,o);let i=n/2,a=Je(i);return ht(c=>{let u=Math.exp(a(c));return u===0?0:u*lt(t*Math.exp(.5*c),e,r,o)},tn(t,e,n,r,o),Pe)}function Je(t){let e=.5*Math.log(t/(2*Math.PI))-kt(t);return n=>{let r;if(Math.abs(n)<.5){let o=n*n/2;r=o;for(let i=3;i<60&&(o*=n/i,r+=o,!(Math.abs(o)<1e-17*r));i++);}else r=Math.expm1(n)-n;return e-t*r}}function ke(t,e,n,r){let o=Math.max((e-1)*r,t*t,1);return o*o<1e-17*n}function ur(t,e,n,r,o){if(n===1/0||ke(t,e,n,r))return Wt(t,e,r,o);let i=Je(n/2),a=Math.log(t);return ir(c=>i(c)+Wt(Math.exp(a+.5*c),e,r,o),tn(t,e,n,r,o,!0))}function tn(t,e,n,r,o,i=!1){let a=n/2,s=a,c;if(o){let m=2*Math.log(t)-Math.log(4*a);c=-(m>30?m:Math.log1p(Math.exp(m)))}else s=a+(e-1)*r/2,c=Math.log1p((e-1)*r/(2*a));let u=(m,w)=>[m-9/Math.sqrt(w)-41/w,m+9/Math.sqrt(w)+Math.log1p(41/w)],[l,h]=u(0,a),[f,p]=u(c,s),M=i?Math.min(l,f):Math.max(Math.min(l,f),-740-Math.log(a)),N=Math.max(h,p),g=1/Math.sqrt(a),E=1/Math.sqrt(s),d=[M,Math.min(-4*g,c-4*E),Math.max(4*g,c+4*E),N];return[...new Set(d.map(m=>Math.min(Math.max(m,M),N)))].sort((m,w)=>m-w)}function en(t,e,n){return t>=2&&e>=2&&n>=1&&Number.isFinite(t)&&Number.isFinite(n)&&!Number.isNaN(e)}function ft(t,e,n,r,o,i){if(t<Fe){let s=ft(Fe,e,n,r,!0,!0)+(e-1)*r*Math.log(t*10715086071862673e285);return o?i?s:Math.exp(s):i?-Math.exp(s):-Math.expm1(s)}let a;return K!==void 0&&K.q===t&&K.k===e&&K.df===n&&K.r===r?a=K.tail:(a=lr(t,e,n,r,!o),K={q:t,k:e,df:n,r,tail:a}),a.upper===!o?i?a.log:a.value:i?Math.log1p(-a.value):1-a.value}var K,Fe=2**-1e3;function lr(t,e,n,r,o){let i=o;n!==1/0&<(t,e,r,i)>.5&&(i=!i);let a=$t(t,e,n,r,i);if(a>.5){let s=$t(t,e,n,r,!i);s<a&&(a=s,i=!i)}if(a<1e-290){let s=ur(t,e,n,r,i);return{upper:i,value:Math.exp(s),log:s}}return{upper:i,value:a,log:Math.log(a)}}function fr(t,e,n,r,o,i){return[t,e,n,r].some(Number.isNaN)?NaN:en(e,n,r)?t<=0?S(o,i):t===1/0?T(o,i):ft(t,e,n,r,o,i):NaN}function hr(t,e,n,r,o,i){if([t,e,n,r].some(Number.isNaN))return NaN;if(!en(e,n,r))return NaN;let a=P(t,0,1/0,o,i);if(a!==void 0)return a;let{lower:s,logTarget:c,linearTarget:u}=Jt(t,o,i),l=f=>p=>{let M=Math.exp(p);if(u!==void 0&&u>1e-290){let g=f===1/0?$t(M,e,f,r,!s):ft(M,e,f,r,s,!1);if(g>0)return Math.log(g/u)}return(f===1/0?Mr(M,e,r,s):ft(M,e,f,r,s,!0))-c},h=Le(l(1/0),Math.log(3),s);return Math.exp(n===1/0?h:Le(l(n),h,s))}function Mr(t,e,n,r){let o=lt(t,e,n,!r);return o>1e-290?Math.log(o):Wt(t,e,n,!r)}function Le(t,e,n){let r=e,o=t(r);if(o===0)return r;let i=o>0===n?-1:1,a=.05,s=r+i*a,c=t(s),u=NaN;for(let l=0;l<200&&Math.sign(c)===Math.sign(o)&&c!==0;l++){if(Math.abs(u-s)<.001)return s;for(r=s,o=c,a*=2,s=(r+i*a-u)*i>=0?.5*(r+u):r+i*a,c=t(s);!Number.isFinite(c);){if(u=s,Math.abs(u-r)<.001)return r;s=.5*(r+u),c=t(s)}}return c===0?s:!Number.isFinite(c)||Math.sign(c)===Math.sign(o)?Number.isFinite(c)?s:r:pr(t,r,s,o,c)}function pr(t,e,n,r,o){let i=e,a=r,s=n-e,c=s;for(let u=0;u<100;u++){Math.sign(o)===Math.sign(a)&&(i=e,a=r,s=n-e,c=s),Math.abs(a)<Math.abs(o)&&(e=n,n=i,i=e,r=o,o=a,a=r);let l=2*et*Math.abs(n)+1e-300,h=.5*(i-n);if(Math.abs(h)<=l||o===0)return n;if(Math.abs(c)>=l&&Math.abs(r)>Math.abs(o)){let f=o/r,p,M;if(e===i)p=2*h*f,M=1-f;else{let N=r/a,g=o/a;p=f*(2*h*N*(N-g)-(n-e)*(g-1)),M=(N-1)*(g-1)*(f-1)}p>0?M=-M:p=-p,2*p<Math.min(3*h*M-Math.abs(l*M),Math.abs(c*M))?(c=s,s=p/M):(s=h,c=h)}else s=h,c=h;e=n,r=o,n+=Math.abs(s)>l?s:h>0?l:-l,o=t(n)}return n}function lo(t,e,n,r={}){y(r,Kn,"ptukey");let{nranges:o=1,lowerTail:i=!0,logP:a=!1}=r;return I(t,s=>fr(s,e,n,o,i,a))}function fo(t,e,n,r={}){y(r,Hn,"qtukey");let{nranges:o=1,lowerTail:i=!0,logP:a=!1}=r;return I(t,s=>hr(s,e,n,o,i,a))}function Xt(t){let e=[],n=[];for(let r=1;r<=t/2;r++){let o=Math.cos(Math.PI*(r-.25)/(t+.5)),i=0;for(let a=0;a<100;a++){let s=1,c=o;for(let l=2;l<=t;l++)[s,c]=[c,((2*l-1)*o*c-(l-1)*s)/l];i=t*(o*c-s)/(o*o-1);let u=c/i;if(o-=u,Math.abs(u)<=1e-17)break}e.push(o),n.push(2/((1-o*o)*i*i))}return{x:e,w:n}}var mr=[Xt(6),Xt(12),Xt(20)],Bt=2*Math.PI,Y=t=>R(t,{lowerTail:!1});function gr(t,e,n){if(n===1)return Y(Math.max(t,e));if(n===-1)return t>=-e?0:t>=0?Y(t)-Y(-e):R(-e)-R(t);let{x:r,w:o}=mr[Math.abs(n)<.3?0:Math.abs(n)<.75?1:2],i=t*e;if(Math.abs(n)<.925){let g=(t*t+e*e)/2,E=Math.asin(n),d=0;for(let m=0;m<r.length;m++)for(let w of[1-r[m],1+r[m]]){let A=Math.sin(E*w/2);d+=o[m]*Math.exp((A*i-g)/(1-A*A))}return d*E/(2*Bt)+Y(t)*Y(e)}let a=n<0?-e:e,s=n<0?-i:i,c=(1-n)*(1+n),u=Math.sqrt(c),l=(t-a)**2,h=(4-s)/8,f=(12-s)/16,p=u*Math.exp(-(l/c+s)/2)*(1-h*(l-c)*(1-f*l/5)/3+h*f*c*c/5);if(s>-160){let g=Math.sqrt(l);p-=Math.exp(-s/2)*Math.sqrt(Bt)*R(-g/u)*g*(1-h*l*(1-f*l/5)/3)}let M=u/2;for(let g=0;g<r.length;g++)for(let E of[1-r[g],1+r[g]]){let d=(M*E)**2,m=Math.sqrt(1-d);p+=M*o[g]*(Math.exp(-l/(2*d)-s/(1+m))/m-Math.exp(-(l/d+s)/2)*(1+h*d*(1+f*d)))}let N=-p/Bt;return n>0?N+Y(Math.max(t,a)):-N+(a>t?R(a)-R(t):0)}function mt(t,e,n){return t===1/0||e===1/0?0:t===-1/0?e===-1/0?1:Y(e):e===-1/0?Y(t):gr(t,e,n)}function po(t,e,n){if(t.length!==2||e.length!==2)throw new TypeError("'lower' and 'upper' must have length 2");if(!(n>=-1&&n<=1))throw new RangeError("'rho' must be in [-1, 1]");let[r,o]=t,[i,a]=e;if([r,o,i,a].some(Number.isNaN))return NaN;if([r,o,i,a]=[r,o,i,a].map(c=>c>40?1/0:c<-40?-1/0:c),!(r<i&&o<a))return 0;r+i+o+a<0&&([r,o,i,a]=[-i,-a,-r,-o]);let s=mt(r,o,n)-mt(r,a,n)-mt(i,o,n)+mt(i,a,n);return Math.max(0,s)}var dr=["size","replace","prob"],Nr=["size","replace","prob"];function wo(t,e={}){return y(e,Nr,"sampleInt"),nn(t,e).map(n=>n-1)}function nn(t,e){if(!Number.isFinite(t)||t<0||t>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");t=Math.trunc(t);let{replace:n=!1,prob:r}=e,o=e.size!==void 0,i=o?e.size:t;if(!Number.isFinite(i)||i<=-1)throw new RangeError("size must be a non-negative number");let a=Math.trunc(i);if(t===0&&a>0)throw new RangeError("cannot take a sample from an empty population");if(r!==void 0){if(a>=2**31)throw new RangeError("size must be less than 2^31 with prob");if(t>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(r.length!==t)throw new TypeError("prob must have length n");let l=on(r,a,n);if(n){let h=rn(l),f=new Array(a);for(let p=0;p<a;p++)f[p]=h();return f}if(a>t)throw new RangeError("cannot take a sample larger than the population when replace is false");return xr(l,a)}if(!n&&a>t)throw new RangeError("cannot take a sample larger than the population when replace is false");if(!n&&t>1e7&&o&&a<=t/2){let l=new Set,h=[];for(;h.length<a;){let f=J(t);l.has(f)||(l.add(f),h.push(f+1))}return h}let s=new Array(a);if(n||a<2){for(let l=0;l<a;l++)s[l]=J(t)+1;return s}if(t>=2**31)throw new RangeError("n must be less than 2^31 to sample without replacement with size above n / 2");let c=new Int32Array(t);for(let l=0;l<t;l++)c[l]=l;let u=t;for(let l=0;l<a;l++){let h=J(u);s[l]=c[h]+1,c[h]=c[--u]}return s}function xo(t,e){if(!Number.isFinite(t)||t<0||t>45e14)throw new RangeError("n must be a non-negative number up to 4.5e15");if(t=Math.trunc(t),t>=2**31)throw new RangeError("n must be less than 2^31 with prob");if(e.length!==t)throw new TypeError("prob must have length n");let n=rn(on(e,0,!0));return()=>n()-1}function rn(t){let e=t.length,n=0;for(let r=0;r<e;r++)e*t[r]>.1&&n++;return n>200?Er(t):wr(t)}function Eo(t,e={}){return y(e,dr,"sample"),nn(t.length,e).map(n=>t[n-1])}function on(t,e,n){let r=0,o=0;for(let i of t){if(!Number.isFinite(i))throw new RangeError("prob contains NaN or infinite values");if(i<0)throw new RangeError("prob contains negative values");i>0&&(o++,r+=i)}if(o===0||!n&&e>o)throw new RangeError("too few positive probabilities");if(r===1/0){let i=ie(t);r=0;for(let a of t)r+=a/i;return Float64Array.from(t,a=>a/i/r)}return Float64Array.from(t,i=>i/r)}function br(t,e){let n=t.length;if(n<=1)return;let r=c=>t[c-1],o=(n>>1)+1,i=n,a,s;for(;;){if(o>1)o=o-1,a=r(o),s=e[o-1];else if(a=r(i),s=e[i-1],t[i-1]=r(1),e[i-1]=e[0],--i===1){t[0]=a,e[0]=s;return}let c=o,u=o<<1;for(;u<=i;)u<i&&r(u)>r(u+1)&&++u,a>r(u)?(t[c-1]=r(u),e[c-1]=e[u-1],c=u,u+=u):u=i+1;t[c-1]=a,e[c-1]=s}}function an(t){let e=new Int32Array(t.length);for(let n=0;n<t.length;n++)e[n]=n+1;return br(t,e),e}function wr(t){let e=Float64Array.from(t),n=e.length,r=an(e);for(let o=1;o<n;o++)e[o]+=e[o-1];return()=>{let o=W(),i=0;for(;i<n-1&&!(o<=e[i]);i++);return r[i]}}function xr(t,e){let n=Float64Array.from(t),r=n.length,o=an(n),i=new Array(e),a=1;for(let s=0,c=r-1;s<e;s++,c--){let u=a*W(),l=0,h=0;for(;h<c&&(l+=n[h],!(u<=l));h++);i[s]=o[h],a-=n[h];for(let f=h;f<c;f++)n[f]=n[f+1],o[f]=o[f+1]}return i}function Er(t){let e=t.length,n=new Float64Array(e),r=new Int32Array(e),o=new Int32Array(e),i=-1,a=e;for(let c=0;c<e;c++)n[c]=t[c]*e,n[c]<1?o[++i]=c:o[--a]=c;if(i>=0&&a<e)for(let c=0;c<e-1;c++){let u=o[c],l=o[a];if(r[u]=l,n[l]+=n[u]-1,n[l]<1&&a++,a>=e)break}let s=ae();return()=>{let c,u;return s?(u=W()*e,c=Math.trunc(u)):(c=J(e),u=c+W()),u<n[c]+c?c+1:r[c]+1}}var yr=2**24;function Ir(t){let e=new Float64Array(t+1);for(let n=2;n<=t;n++)e[n]=e[n-1]+Math.log(n);return e}function vr(t,e,n,r){let o=t.length,i=e.length,a=Array.from(e),s=0;for(let u of t)s+=u;for(let u=0;u<o-1;u++){let l=t[u],h=s;s-=l;let f=0;for(;f<i-1;f++){let p=a[f],M=h;h-=p;let N=M-l,g=N-p;if(M===0){for(let m=f;m<i-1;m++)r[u+m*o]=0;l=0;break}let E=W(),d;t:for(;;){d=Math.floor(l*(p/M)+.5);let m=Math.exp(n[l]+n[N]+n[h]+n[p]-n[M]-n[d]-n[p-d]-n[l-d]-n[g+d]);if(m>=E)break;if(m===0)throw new Error(`r2dtable: probability underflow at cell [${u}, ${f}]`);let w=m,A=m,b=d,x=!1,F=!1;for(;!(x&&F);){if(!x){let _=(p-d)*(l-d);if(_===0)x=!0;else if(d++,m=m*_/(d*(g+d)),w+=m,w>=E)break t}do{let _=b*(g+b);if(_===0){F=!0;break}if(b--,A=A*_/((p-b)*(l-b)),w+=A,w>=E){d=b;break t}}while(x)}E=w*W()}r[u+f*o]=d,l-=d,a[f]=a[f]-d}r[u+(i-1)*o]=l}let c=e[i-1];for(let u=0;u<o-1;u++)c-=r[u+(i-1)*o];for(let u=0;u<i-1;u++)r[o-1+u*o]=a[u];r[o-1+(i-1)*o]=c}function sn(t,e){let n=Array.from(t,r=>Math.trunc(r));if(n.length<=1||n.some(r=>!(r>=0)||r>2147483647))throw new RangeError(`invalid argument '${e}'`);return n}function vo(t,e,n){if(!(Number.isFinite(t)&&t>-1&&t<2**31))throw new RangeError("invalid argument 'n'");let r=Math.trunc(t),o=sn(e,"r"),i=sn(n,"c"),a=o.reduce((l,h)=>l+h,0);if(a!==i.reduce((l,h)=>l+h,0))throw new RangeError("arguments 'r' and 'c' must have the same sums");if(a>2147483647)throw new RangeError("the sum of 'r' must be at most 2147483647");if(r===0)return[];if(a>yr)throw new RangeError("the sum of 'r' must be at most 16777216 (2^24) to generate tables");let s=Ir(a),c=new Int32Array(o.length*i.length),u=[];for(let l=0;l<r;l++)vr(o,i,s,c),u.push(o.map((h,f)=>i.map((p,M)=>c[f+M*o.length])));return u}export{Mn as a,xt as b,mn as c,bn as d,Wr as e,$r as f,Or as g,_n as h,Rn as i,jr as j,Gr as k,Qr as l,qn as m,Dn as n,Yn as o,eo as p,no as q,ro as r,lo as s,fo as t,po as u,wo as v,xo as w,Eo as x,yr as y,Ir as z,vr as A,vo as B};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
1
|
+
/*! rStats.js 1.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
2
|
function e(n){let t=-1/0;for(let i=0;i<n.length;i++)t=Math.max(t,n[i]);return t}function r(n,t){let i=.5*(n+t);return Number.isFinite(i)||!Number.isFinite(n)||!Number.isFinite(t)?i:.5*n+.5*t}function m(n){let t=1/0;for(let i=0;i<n.length;i++)t=Math.min(t,n[i]);return t}export{e as a,r as b,m as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{b as A}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.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{b as A}from"./chunk-IJST2ZGT.js";var y=t=>new SyntaxError(`invalid formula: ${t}`),L=/^(?:[\p{L}\p{Nl}.]|(?![0-9])\p{Nd})[\p{L}\p{Nl}\p{Nd}\p{M}._]*/u;function R(t,u,i=!1){let a=[],n=0;for(;n<t.length;){let e=t[n];if(/\s/.test(e)){n++;continue}if(/[0-9]/.test(e)||e==="."&&/[0-9]/.test(t[n+1]??"")){let c=/^(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:[eE][+-]?[0-9]+)?/.exec(t.slice(n));a.push({kind:"num",text:c[0]}),n+=c[0].length;continue}let r=L.exec(t.slice(n));if(r!==null){a.push({kind:"name",text:r[0]}),n+=r[0].length;continue}if(t.startsWith("%in%",n)){a.push({kind:"op",text:"%in%"}),n+=4;continue}if(u&&e==="|"){let c=t[n+1]==="|"?"||":"|";a.push({kind:"op",text:c}),n+=c.length;continue}if("~+-*/:^()".includes(e)||i&&e===","){a.push({kind:"op",text:e}),n++;continue}throw y(`unexpected '${e}'`)}return a.push({kind:"end"}),a}var T={"|":.5,"||":.5,"+":1,"-":1,"*":2,"/":2,"%in%":3,":":4,"^":6},C=5;function I(t,u=!1,i=!1,a=!1){if(typeof t!="string")throw new TypeError("the formula must be a string");let n=R(t,i,a),e=0,r=()=>n[e],c=()=>n[e++],f=(o,d)=>o.kind==="op"&&o.text===d;function m(){let o=c();if(o.kind==="name"){if(f(r(),"(")){if(o.text!=="Error"||!u)throw y(`function calls are not supported (${o.text})`);c();let d=g(0);if(!f(c(),")"))throw y("missing ')'");return{type:"Error",arg:d}}if(o.text===".")return{type:"dot"};if(/^\.[0-9]/.test(o.text))throw y(`unexpected '${o.text}'`);return{type:"var",name:o.text}}if(o.kind==="num")return{type:"num",value:Number(o.text),text:o.text};if(o.kind==="op"&&o.text==="("){let d=g(0);if(!f(c(),")"))throw y("missing ')'");return{type:"paren",arg:d}}if(o.kind==="op"&&(o.text==="-"||o.text==="+"))return{type:"unary",op:o.text,arg:g(C)};throw y(o.kind==="end"?"unexpected end of input":`unexpected '${o.kind==="op"?o.text:""}'`)}function g(o){let d=m();for(;;){let x=r();if(x.kind!=="op")break;let h=T[x.text];if(h===void 0||h<=o)break;c();let v=g(x.text==="^"?h-1:h);d=x.text==="|"||x.text==="||"?{type:"bar",double:x.text==="||",lhs:d,group:v}:{type:"binary",op:x.text,left:d,right:v}}return d}let b,l,s=n[0];if(a&&s.kind==="name"&&s.text==="cbind"&&f(n[1],"(")){let o=n[2],d=n[4],x=h=>h.kind==="name"&&h.text!=="."&&!/^\.[0-9]/.test(h.text);if(!(x(o)&&f(n[3],",")&&x(d)&&f(n[5],")")&&f(n[6],"~")))throw y("the response cbind() must have two column names: cbind(successes, failures)");l=[o.text,d.text],b=l[0],e=6}else if(!f(r(),"~")){let o=c();if(o.kind!=="name"||o.text==="."||!f(r(),"~"))throw y("the response must be a variable name followed by '~'");b=o.text}c();let p=g(0);if(r().kind!=="end")throw y("unexpected input after the formula");return l===void 0?{response:b,rhs:p}:{response:b,responseColumns:l,rhs:p}}function V(t){let u=[],i=e=>{if(e.type==="Error"){u.push(e.arg);return}if(e.type==="paren"){let r=i(e.arg);return r===void 0?void 0:{...e,arg:r}}if(e.type==="binary"&&e.op==="+"){let r=i(e.left),c=i(e.right);return r===void 0?c:c===void 0?r:{...e,left:r,right:c}}if(e.type==="binary"&&e.op==="-"){let r=i(e.left);return r===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:r}}return e},a=i(t),n=e=>{if(e.type==="Error")throw y("Error() must be a term of the right-hand side");e.type==="binary"?(n(e.left),n(e.right)):(e.type==="unary"||e.type==="paren")&&n(e.arg)};return a!==void 0&&n(a),u.forEach(n),{treatment:a,errors:u}}function Y(t){let u=[],i=e=>{switch(e.type){case"bar":u.push(e);return;case"paren":{let r=i(e.arg);return r===void 0?void 0:{...e,arg:r}}case"binary":if(e.op==="+"){let r=i(e.left),c=i(e.right);return r===void 0?c:c===void 0?r:{...e,left:r,right:c}}if(e.op==="-"){let r=i(e.left);return r===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:r}}return e;default:return e}},a=i(t),n=e=>{if(e.type==="bar")throw y("a random-effects term (lhs | group) must be a term of the right-hand side");e.type==="binary"?(n(e.left),n(e.right)):(e.type==="unary"||e.type==="paren"||e.type==="Error")&&n(e.arg)};a!==void 0&&n(a);for(let e of u)n(e.lhs),n(e.group);return{fixed:a,bars:u}}var M=new Set(["+","-","*","%in%"]);function w(t){switch(t.type){case"var":return t.name;case"dot":return".";case"num":return A(t.value);case"binary":{let u=w(t.left),i=w(t.right);return M.has(t.op)?`${u} ${t.op} ${i}`:`${u}${t.op}${i}`}case"unary":return`${t.op}${w(t.arg)}`;case"paren":return`(${w(t.arg)})`;case"Error":return`Error(${w(t.arg)})`;case"bar":return`${w(t.lhs)} ${t.double?"||":"|"} ${w(t.group)}`}}function k(t,u,i){if(t!==void 0)switch(t.type){case"var":i.includes(t.name)||i.push(t.name);return;case"dot":for(let a of u)i.includes(a)||i.push(a);return;case"num":return;case"binary":k(t.left,u,i),t.op!=="^"&&k(t.right,u,i);return;case"unary":case"paren":case"Error":k(t.arg,u,i);return;case"bar":k(t.lhs,u,i),k(t.group,u,i)}}function j(t,u){let i=[];return k(t,u,i),i}var N=t=>t.join(",");function E(t){let u=new Set;return t.filter(i=>{let a=N(i);return u.has(a)?!1:(u.add(a),!0)})}var $=(t,u)=>[...new Set([...t,...u])].sort((i,a)=>i-a);function B(t,u,i){let a=!0,n=(r,c)=>{switch(r.type){case"var":return[[u(r.name)]];case"dot":return i.map(f=>[u(f)]);case"num":if(r.value===1)a=!c;else if(r.value===0)a=c;else throw y(`a number (${r.text}) is not a term`);return[];case"paren":return n(r.arg,c);case"Error":throw y("Error() must be a term of the right-hand side");case"bar":throw y("a random-effects term (lhs | group) must be a term of the right-hand side");case"unary":return r.op==="+"?n(r.arg,c):(n(r.arg,!c),[]);case"binary":{if(r.op==="^"){let l=n(r.left,c),s=r.right;for(;s.type==="paren";)s=s.arg;let p=s.type==="num"?Math.trunc(s.value):NaN;if(!(p>=2&&p<=2147483647))throw new Error("invalid power in formula");let o=l;for(let d=1;d<p;d++){let x=[];for(let S of l)for(let O of o)x.push($(S,O));let h=E(x),v=h.length===o.length&&h.every((S,O)=>N(S)===N(o[O]));if(o=h,v)break}return o}if(r.op==="-"){let l=n(r.left,c),s=new Set(n(r.right,!c).map(N));return l.filter(p=>!s.has(N(p)))}let f=n(r.left,c),m=n(r.right,c);if(f.length===0&&r.op!=="+")return[];let g=()=>{let l=[];for(let s of f)for(let p of m)l.push($(s,p));return l},b=l=>l.reduce((s,p)=>$(s,p),[]);switch(r.op){case"+":return E([...f,...m]);case":":return E(g());case"*":return E([...f,...m,...g()]);case"/":{let l=b(f);return E([...f,...m.map(s=>$(s,l))])}case"%in%":{let l=b(m);return E(f.map(s=>$(s,l)))}}}}throw y("unsupported expression")};return{terms:t===void 0?[]:n(t,!1),intercept:a}}function z(t,u,i=t.rhs){let{response:a,responseColumns:n}=t,e=u.filter(s=>s!==a&&!(n?.includes(s)??!1)),r=a===void 0?[]:[a];n!==void 0&&n[1]!==a&&r.push(n[1]),k(t.rhs,e,r);let f=B(i,s=>r.indexOf(s),e),m=f.terms.map((s,p)=>[s,p]).sort((s,p)=>s[0].length-p[0].length||s[1]-p[1]).map(([s])=>s),g=[],b=a===void 0?-1:m.findIndex(s=>s.length===1&&s[0]===0);b>=0&&(g.push("the response appeared on the right-hand side and was dropped"),g.push(`problem with term ${b+1} in model.matrix: no columns are assigned`));let l=r.map(()=>m.map(()=>0));return m.forEach((s,p)=>{for(let o of s){let d=s.filter(h=>h!==o),x=d.length===0||m.slice(0,p).some(h=>d.every(v=>h.includes(v)));l[o][p]=x?1:2}}),{variables:r,response:a===void 0?-1:0,terms:m,termLabels:m.map(s=>s.map(p=>r[p]).join(":")),order:m.map(s=>s.length),intercept:f.intercept,factors:l,responseTerm:b,warnings:g}}export{I as a,V as b,Y as c,w as d,j as e,B as f,z as g};
|
package/dist/descriptive.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{m as Te,n as Se,o as _e,p as J,q as Q,r as Be,s as De}from"./chunks/chunk-PLQQ4VFN.js";import{a as Ye,b as Ke,c as Ge,d as Je,e as Qe,f as Xe,g as Ze}from"./chunks/chunk-HORF36FD.js";import{a as Y,b as W,c as K,d as M,e as ce,f as ke,g as Oe,j as Fe,k as Me,m as je,n as Ce,o as Ie,p as Le,q as Pe,r as z,s as G,t as C,u as Ve,v as Ue,w as qe,x as We,y as ze}from"./chunks/chunk-76FLTZVF.js";import{a as fe,b as He,c as en,d as nn,e as tn,f as rn}from"./chunks/chunk-QWDK3ZC2.js";import"./chunks/chunk-THSV22QF.js";import"./chunks/chunk-J7ZVV4DN.js";import{b as re,c as oe}from"./chunks/chunk-VALULDEX.js";import{a as le,e as q,f as ie}from"./chunks/chunk-V2Y2W7LE.js";import"./chunks/chunk-R5BMFVIH.js";import{a as ue}from"./chunks/chunk-TY3IFCLI.js";import{m as se}from"./chunks/chunk-JXEXOD7K.js";import{b as U,d as ae}from"./chunks/chunk-CUT3IHMY.js";import"./chunks/chunk-MOJ2KIQE.js";import{P as D,l as j,u as P}from"./chunks/chunk-YKNRDPIB.js";var me=e=>e===null||typeof e=="number"&&Number.isNaN(e),he=e=>Array.isArray(e)||ArrayBuffer.isView(e);function on(e){if(he(e))return{columns:[e],rows:e.length};if(typeof e!="object"||e===null)throw new TypeError("the arguments must be arrays or data frames");let n=Object.values(e),t=n[0]?.length??0;if(n.some(r=>r.length!==t))throw new RangeError("not all arguments have the same length");return{columns:n,rows:t}}function pe(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(on),t=n[0].rows;if(n.some(o=>o.rows!==t))throw new RangeError("not all arguments have the same length");let r=n.flatMap(o=>o.columns);return Array.from({length:t},(o,i)=>r.every(l=>!me(l[i])))}function sn(e){if(he(e))return Array.from(e).filter(r=>!me(r));let n=pe(e),t={};for(let[r,o]of Object.entries(e)){let i=Array.from(o).filter((l,s)=>n[s]);M(t,r,o instanceof Float64Array?Float64Array.from(i):i)}return t}var ln=["breaks","right","includeLowest"],an=["n","minN","shrinkSml","highUBias","u5Bias"];function ge(e,n={}){j(n,an,"pretty");let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5;if(Number.isNaN(r)||Math.abs(r)>=2**31||Math.trunc(r)<0)throw new RangeError("invalid 'n' argument");let o=Math.trunc(r),i=n.minN??Math.floor(r/3);if(Number.isNaN(i)||Math.trunc(i)<0||Math.trunc(i)>o)throw new RangeError("invalid 'min.n' argument");let l=Math.trunc(i),s=n.shrinkSml??.75;if(!Number.isFinite(s)||s<=0)throw new RangeError("invalid 'shrink.sml' argument");let f=n.highUBias??1.5;if(!Number.isFinite(f)||f<0)throw new RangeError("invalid 'high.u.bias' argument");let u=n.u5Bias??.5+1.5*f;if(!Number.isFinite(u)||u<0)throw new RangeError("invalid 'u5.bias' argument");let m=1/0,c=-1/0;for(let v of t)v<m&&(m=v),v>c&&(c=v);let y=c-m,g,N;if(y===0&&c===0)g=1,N=!0;else{g=Math.max(Math.abs(m),Math.abs(c));let A=(1+(u>=1.5*f+.5?1/(1+f):1.5/(1+u)))*Math.max(1,o)*Number.EPSILON;N=y<g*A*3}N?(g>10&&(g=9+g/10),g*=s,l>1&&(g/=l)):(g=o>1?y/o:y,y===1/0&&o>=2&&(g=c/o-m/o));let E=2**-20*un;g<E?g=E:g>Number.MAX_VALUE/1.25&&(g=Number.MAX_VALUE/1.25);let k=10**Math.floor(Math.log10(g)),h=[[2*k,f],[5*k,u],[10*k,f]],w=k;for(let[v,A]of h)if(v-g<A*(g-w))w=v;else break;let p=1e-10,d=Math.floor(m/w+p);for(;d*w>m+p*w;)d--;for(;!Number.isFinite(d*w);)d++;let $=Math.ceil(c/w-p);for(;$*w<c-p*w;)$++;for(;!Number.isFinite($*w);)$--;let a=Math.trunc(.5+$-d);if(a<l){let v=l-a,A=Math.floor(v/2),F=v%2;m===0&&d===0&&c!==0?$+=v:c===0&&$===0&&m!==0?d-=v:d>=0?($+=A,d-=A+F):(d-=A,$+=A+F),a=l}let b=d*w<m?d*w:m,x=$*w>c?$*w:c;if(a<=0)return[b];let O=fe(b,x,a+1),R=x/a-b/a;return O.map(v=>Math.abs(v)<1e-14*R?0:v)}var un=22250738585072014e-324;function cn(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function fn(e,n){let t=e.length;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let r=s=>[C(s),3.5*z(s)*t**-.3333333333333333],[[o,i],l]=r(e);return Number.isFinite(i-o)&&Number.isFinite(l)||([[o,i],l]=r(D([e]).groups[0])),l>0?Math.max(1,Math.ceil((i-o)/l)):1}case"fd":case"freedman-diaconis":{let r=(f,u)=>{let m=2*Q(u);for(let c=.125;m===0&&c>=.001953125;c/=2){let[y,g]=J(u,[c,1-c]);m=(g-y)/(1-2*c)}return m===0&&(m=3.5*z(f)),[C(f),m]},o=e.map(cn),[[i,l],s]=r(e,o);if(!(Number.isFinite(l-i)&&Number.isFinite(s))){let{k:f}=D([e]);[[i,l],s]=r(e.map(u=>P(u,-f)),o.map(u=>P(u,-f)))}return s>0?Math.ceil((l-i)/s*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function mn(e,n,t){let r=e.slice(1).map((o,i)=>o-e[i]);return e.length>5?1e-7*G(r):e.length<=3?t-n===1/0?2*(1e-7*(t/2-n/2)):1e-7*(t-n):1e-7*oe(r.filter(o=>o>0))}function hn(e,n={}){j(n,ln,"hist");let t=Array.from(e).filter(Number.isFinite),r=t.length,o=n.right??!0,i=n.includeLowest??!0,l=n.breaks??"Sturges",s;if(typeof l!="string"&&typeof l!="number"&&l.length>1){if(!l.every(Number.isFinite))throw new RangeError("'breaks' are not finite");if(s=[...l].sort((h,w)=>h-w),s.some((h,w)=>w>0&&!(h>s[w-1])))throw new RangeError("'breaks' are not strictly increasing")}else{i=!0;let h=typeof l=="string"?fn(t,l):typeof l=="number"?l:l[0];if(!Number.isFinite(h)||h<1)throw new RangeError("invalid number of 'breaks'");h=Math.min(h,1e6);let[w,p]=C(t);s=ge([w,p],{n:h,minN:1});for(let d=1;d<s.length;d++)if(!(s[d]-s[d-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let f=s.length,[u,m]=r>0?C(t):[0,0],c=mn(s,u,m),y=s.map((h,w)=>o?w===0&&i?h-c:h+c:w<f-1?h-c:i?h+c:h-c),g=new Array(Math.max(0,f-1)).fill(0),N=0;for(let h of t){let w=gn(h,y,o,i);w>=0&&(g[w]++,N++)}if(N<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let E=g.map((h,w)=>pn(h,r,s[w],s[w+1])),k=g.map((h,w)=>re(s[w+1],s[w]));return{breaks:s,counts:g,density:E,mids:k}}function pn(e,n,t,r){let o=r-t;if(!(n*o===1/0&&Number.isFinite(t)&&Number.isFinite(r)))return e/(n*o);let i=o===1/0?1:0,l=i===1?r/2-t/2:o,s=Math.floor(Math.log2(l));return P(e,-(s+i))/(n*P(l,-s))}function gn(e,n,t,r){let o=n.length-1;if(o<1)return-1;if(t){if(e===n[0]&&r)return 0;if(!(e>n[0]&&e<=n[o]))return-1;let s=1,f=o;for(;s<f;){let u=Math.floor((s+f)/2);e<=n[u]?f=u:s=u+1}return s-1}if(e===n[o]&&r)return o-1;if(!(e>=n[0]&&e<n[o]))return-1;let i=0,l=o-1;for(;i<l;){let s=Math.floor((i+l+1)/2);n[s]<=e?i=s:l=s-1}return i}function dn(e){let n=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,o)=>r-o),t=n.length;if(t<1)throw new RangeError("'x' must have 1 or more non-missing values");return r=>{if(Number.isNaN(r))return NaN;let o=0,i=t;for(;o<i;){let l=Math.floor((o+i)/2);n[l]<=r?o=l+1:i=l}return o/t}}var wn=["drop","sep"],B=e=>e===null||typeof e=="number"&&Number.isNaN(e),yn=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?ue(e,n):Number(e)-Number(n),bn=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?U(e):e>0?"Inf":"-Inf";function En(e,n){let t=ae(n),r=new Set(t.filter(s=>!B(s)).map(s=>typeof s));if(r.size>1)throw new TypeError(`${e} mixes ${[...r].join(" and ")} labels`);let o=[...r][0];if(o!==void 0&&o!=="number"&&o!=="string"&&o!=="boolean")throw new TypeError(`${e} has labels of an unsupported type`);let i=[...new Set(t.filter(s=>!B(s)))].sort(yn),l=new Map(i.map((s,f)=>[s,f]));return{levels:i,codes:t.map(s=>B(s)?-1:l.get(s))}}var I=e=>Array.isArray(e)||e instanceof Float64Array;function be(e){if(e instanceof Float64Array)return[e];if(!Array.isArray(e))throw new TypeError("the group labels must be an array or an array of arrays");if(e.length>0&&e.every(I))return[...e];if(e.some(I))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function X(e,n,t){e.forEach((l,s)=>{if(l.length!==t)throw new RangeError(`${n[s]} must have one label per row (${t}), not ${l.length}`)});let r=e.map((l,s)=>En(n[s],l)),o=r.reduce((l,s)=>l*s.levels.length,1);if(o>=2**31)throw new RangeError("total number of levels >= 2^31");let i=new Array(t);for(let l=0;l<t;l++){let s=0,f=1;for(let u of r){let m=u.codes[l];if(m<0){s=-1;break}s+=m*f,f*=u.levels.length}i[l]=s}return{factors:r,size:o,cells:i}}function Z(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function Nn(e,n){return e.factors.map(t=>{let r=t.levels.length,o=t.levels[n%r];return n=Math.floor(n/r),o})}var Ee=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function $n(e,n,t){let r=Array.from(e),o=be(n),i=X(o,Ee(o.length,"index"),r.length),l=Z(i).map(u=>u.length===0?null:{value:t(u.map(m=>r[m]))}),f=l.every(u=>u===null||typeof u.value=="number")?l.map(u=>u===null?NaN:u.value):l.map(u=>u===null?null:u.value);return{dim:i.factors.map(u=>u.levels.length),dimnames:i.factors.map(u=>[...u.levels]),values:f}}function vn(e,n){let t={};for(let[r,o]of Object.entries(e))M(t,r,o instanceof Float64Array?Float64Array.from(n,i=>o[i]):n.map(i=>o[i]));return t}function xn(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!I(o))throw new TypeError(`column '${r}' must be an array`);if(o.length!==t)throw new RangeError(`the columns of the data frame have different lengths (found for '${r}')`)}return t}function An(e,n,t={}){j(t,wn,"split");let r=t.sep??".",o=be(n),i=!I(e);if(i&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let l=i?xn(e):e.length,s=X(o,Ee(o.length,"f"),l),f=i?[]:Array.from(e),u=new Map;return Z(s).forEach((m,c)=>{if(m.length===0&&(t.drop||s.factors.length===1))return;let y=Nn(s,c).map(bn).join(r);if(u.has(y))throw new RangeError(`the group names joined with '${r}' are not unique ('${y}'); use another sep`);u.set(y,i?vn(e,m):m.map(g=>f[g]))}),u}function de(e,n){if(n===void 0)throw new RangeError(`object '${e}' not found`);if(!I(n))throw new TypeError(`column '${e}' must be an array`);return Array.from(n,t=>{if(t===null)return NaN;if(typeof t!="number")throw new TypeError(`column '${e}' to summarise must be numeric`);return t})}function we(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new RangeError(`object '${n}' not found`);if(!I(t))throw new TypeError(`column '${n}' must be an array`);return t}function Rn(e,n){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");if(t<0)throw new SyntaxError("invalid formula: missing '~'");let r=e.slice(0,t).trim(),{rhs:o}=le(`~ ${e.slice(t+1)}`),i=/^[A-Za-z.][A-Za-z0-9._]*$/,l;if(r!=="."){let u=/^cbind\s*\((.*)\)$/s.exec(r);if(l=u===null?[r]:u[1].split(",").map(m=>m.trim()),l.some(m=>!i.test(m)||m==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}else if(q(o,[]).length<q(o,["."]).length)throw new SyntaxError("invalid formula: '.' cannot be on both sides");let s=l===void 0?[]:n.filter(u=>!l.includes(u)),f=q(o,s);return ie(o,()=>0,s),{values:l??n.filter(u=>!f.includes(u)),groups:f}}function ye(e,n,t,r,o,i){let l=r[0]?.length??n[0]?.length??0;e.forEach((c,y)=>{if(n[y].length!==l)throw new RangeError(`variable lengths differ (found for '${c}')`)});let s=X(r,t,l),f=Z(s).map((c,y)=>({cell:y,rows:c.filter(o)})).filter(c=>c.rows.length>0),u={};t.forEach((c,y)=>{let g=r[y];M(u,c,f.map(N=>{let E=g[N.rows[0]];return E===0?0:E}))});let m=(c,y)=>{if(Object.hasOwn(u,c))throw new RangeError(`duplicate column name '${c}' in the result`);M(u,c,y)};return e.forEach((c,y)=>{let g=n[y],E=f.map(h=>i(h.rows.map(w=>g[w]))).map(h=>{if(typeof h=="number")return{names:void 0,values:[h]};if(Array.isArray(h))return{names:void 0,values:[...h]};let w=h;return{names:Object.keys(w),values:Object.values(w)}}),k=E[0]?.values.length??1;if(E.some(h=>h.values.length!==k))throw new RangeError("fun must return values of the same length for every group");if(k===1&&E[0]?.names===void 0){m(c,E.map(h=>h.values[0]));return}for(let h=0;h<k;h++){let w=E[0].names?.[h]??String(h+1);m(`${c}.${w}`,E.map(p=>p.values[h]))}}),u}function kn(e,n,t){if(typeof n!="object"||n===null)throw new TypeError("the data must be an object of columns");if(typeof e=="string"){let s=n,{values:f,groups:u}=Rn(e,Object.keys(s)),m=N=>Object.prototype.hasOwnProperty.call(s,N),c=f.map(N=>de(N,m(N)?s[N]:void 0)),y=u.map(N=>we(s,N));return ye(f,c,u,y,N=>c.every(E=>!Number.isNaN(E[N]))&&y.every(E=>!B(E[N])),t)}if(typeof e!="object"||e===null)throw new TypeError("x must be a data frame");let r=Object.keys(e),o=r.map(s=>de(s,e[s])),i=Object.keys(n);if(i.length===0)throw new RangeError("'by' must name at least one grouping column");let l=i.map(s=>we(n,s));return ye(r,o,i,l,()=>!0,t)}var On=new Set(["cols","namesTo","namesPrefix","namesSep","namesPattern","namesTransform","valuesTo","valuesDropNa","colsVary","onWarning"]),Fn=new Set(["namesFrom","valuesFrom","idCols","namesPrefix","namesSep","namesSort","namesVary","valuesFill","valuesFn"]),ee=e=>typeof e=="string"?[e]:[...e];function xe(e,n){if(n==null)return"fastest";if(n==="fastest"||n==="slowest")return n;throw typeof n!="string"?new TypeError(`\`${e}\` must be a string or character vector.`):new RangeError(`\`${e}\` must be one of "fastest" or "slowest", not "${n}".`)}function ne(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new RangeError(`Column \`${t}\` doesn't exist.`)}function Ae(e,n){if(n instanceof Float64Array)return"double";let t=null;for(let r of n){if(r===null)continue;let o=typeof r=="number"?"double":typeof r=="string"?"character":"logical";if(t!==null&&o!==t)throw new TypeError(`column '${e}' mixes ${t} and ${o} values`);t=o}return t}function Mn(e,n){let t=null;for(let r of n){let o=Ae(r,e[r]);if(o!==null){if(t===null)t={type:o,column:r};else if(t.type!==o){if(t.type==="character"||o==="character")throw new TypeError(`Can't combine \`${t.column}\` <${t.type}> and \`${r}\` <${o}>.`);o==="double"&&(t={type:o,column:r})}}}return t?.type??null}function Ne(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new TypeError(`\`regex\` should define ${t} groups; ${r} found.`);let o=new RegExp(n);return e.map(i=>{let l=o.exec(i);return Array.from({length:t},(s,f)=>l===null?null:l[f+1]??null)})}function Tn(e,n){let t=e.charCodeAt(n);if(t>=55296&&t<=56319&&n+1<e.length){let r=e.charCodeAt(n+1);if(r>=56320&&r<=57343)return 2}return 1}function Sn(e,n,t,r){let o=new RegExp(n,"g"),i=[],l=[],s=e.map((u,m)=>{let c=[],y=0,g=0;for(;;){o.lastIndex=y;let N=o.exec(u);if(N===null||(c.push(u.slice(g,N.index)),g=N.index+N[0].length,y=N[0].length===0?N.index+Tn(u,N.index):g,y>=u.length))break}return c.push(u.slice(g)),c.length>t&&i.push(m+1),c.length<t&&l.push(m+1),Array.from({length:t},(N,E)=>c[E]??null)}),f=u=>`${u.length} rows [${u.join(", ")}]`;return i.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${f(i)}.`),l.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${f(l)}.`),s}function $e(e,n){return e!==void 0&&Object.hasOwn(e,n)?e[n]:void 0}function _n(e,n,t,r){let{namesSep:o,namesPattern:i}=t;if(n.length===0)return e.map(()=>[]);if(n.length===1){if(o!==void 0)throw new TypeError("`names_sep` can't be used with a length 1 `names_to`.");return i===void 0?e.map(l=>[l]):Ne(e,i,1)}if(o===void 0==(i===void 0))throw new TypeError("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?Sn(e,o,n.length,r):Ne(e,i,n.length)}function jn(e,n){j(n,On,"pivotLonger");let t=xe("cols_vary",n.colsVary),r=Y(e),o=Object.keys(e),i=typeof n.cols=="function"?o.filter(n.cols):[...new Set(n.cols)];if(ne(e,i),i.length===0)throw new RangeError("`cols` must select at least one column.");let l=ee(n.namesTo??"name"),s=l.indexOf(".value");if(l.lastIndexOf(".value")!==s)throw new RangeError('`names_to` may contain ".value" only once');let f=[],u=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),m=i.map(p=>u===null?p:p.replace(u,"")),c=_n(m,l,n,f),y=[],g=[];if(s<0)y.push(...c),g.push({name:n.valuesTo??"value",sources:[...i]});else{let p=new Map,d=new Map,$=$e(n.namesTransform,".value");c.forEach((a,b)=>{let x=a.filter((S,_)=>_!==s),O=JSON.stringify(x),R=p.get(O);if(R===void 0){R=y.length,p.set(O,R),y.push(x);for(let S of g)S.sources.push(null)}let v=a[s]??null,A=v===null||$===void 0?v:$(v);if(A!==null&&typeof A!="string")throw new TypeError(`the transform of \`.value\` must give strings, not ${typeof A}`);let F=A??"NA",T=d.get(F);if(T===void 0&&(T={name:F,sources:y.map(()=>null)},d.set(F,T),g.push(T)),T.sources[R]!==null)throw new RangeError(`the names give the value column '${F}' twice for one key`);T.sources[R]=i[b]})}let N=g.map(p=>Mn(e,p.sources.filter(d=>d!==null))),E=[];if(t==="slowest")for(let p=0;p<y.length;p++)for(let d=0;d<r;d++)E.push([d,p]);else for(let p=0;p<r;p++)for(let d=0;d<y.length;d++)E.push([p,d]);let k=(p,d,$)=>{let a=p.sources[$];return a==null?null:e[a][d]};n.valuesDropNa===!0&&(E=E.filter(([p,d])=>g.some($=>!W(k($,p,d)))));let h={},w=E.map(([p])=>p);for(let p of o)i.includes(p)||M(h,p,K(e[p],w));if(l.forEach((p,d)=>{if(d===s)return;let $=$e(n.namesTransform,p),a=b=>{let x=y[b][d<s||s<0?d:d-1];return x===null||$===void 0?x:$(x)};M(h,p,E.map(([,b])=>a(b)))}),g.forEach((p,d)=>{let $=N[d]==="double";if($&&p.sources.every(a=>a!==null&&e[a]instanceof Float64Array))M(h,p.name,Float64Array.from(E,([a,b])=>k(p,a,b)));else{let a=E.map(([b,x])=>{let O=k(p,b,x);return $&&typeof O=="boolean"?Number(O):O});M(h,p.name,a)}}),n.onWarning!==void 0)for(let p of new Set(f))n.onWarning(p);else se("pivotLonger",f);return h}var te=e=>typeof e=="number"?"double":typeof e=="string"?"character":"logical";function Cn(e,n){if(e===null||n===null)return e;let t=te(e);if(t===n)return e;if(n==="double"&&t==="logical")return Number(e);if(n==="logical"&&t==="double"){let r=e;if(Number.isNaN(r))return null;if(r===0||r===1)return r===1;throw new TypeError("Can't convert from `fill` <double> to <logical> due to loss of precision.")}throw new TypeError(`Can't convert \`fill\` <${t}> to <${n}>.`)}var In=e=>W(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function ve(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(i,l)=>{let s=JSON.stringify(e.map(u=>In(u[l]))),f=t.get(s);return f===void 0&&(f=r.length,t.set(s,f),r.push(l)),f}),firsts:r}}function Ln(e){return W(e)?"NA":typeof e=="number"?Number.isFinite(e)?U(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function H(e,n,t){if(e!==void 0)return n(e)?e:Object.hasOwn(e,t)?e[t]:void 0}function Pn(e,n={}){j(n,Fn,"pivotWider");let t=xe("names_vary",n.namesVary),r=Y(e),o=(a,b)=>{let x=[...new Set(ee(a))];if(ne(e,x),x.length===0)throw new RangeError(`\`${b}\` must select at least one column.`);return x},i=o(n.namesFrom??"name","names_from"),l=o(n.valuesFrom??"value","values_from"),s=n.idCols===void 0?Object.keys(e).filter(a=>!i.includes(a)&&!l.includes(a)):[...new Set(ee(n.idCols))];ne(e,s);for(let a of s){let b=i.includes(a)?"names_from":l.includes(a)?"values_from":null;if(b!==null)throw new RangeError(`\`id_cols\` can't select a column already selected by \`${b}\`. Column \`${a}\` has already been selected.`)}let f=n.namesPrefix??"",u=n.namesSep??"_",m=ve(s.map(a=>e[a]),r),c=ve(i.map(a=>e[a]),r),y=c.firsts.map((a,b)=>b);n.namesSort===!0&&y.sort((a,b)=>{for(let x of i){let O=ce(e[x][c.firsts[a]],e[x][c.firsts[b]]);if(O!==0)return O}return 0});let g=c.firsts.map(a=>f+i.map(b=>Ln(e[b][a])).join(u)),N=c.firsts.length,E=Array.from({length:m.firsts.length*N},()=>[]);for(let a=0;a<r;a++)E[m.codes[a]*N+c.codes[a]].push(a);let k=a=>typeof a=="function",h=a=>typeof a!="object"||a===null;for(let a of l)if(H(n.valuesFn,k,a)===void 0&&E.some(b=>b.length>1))throw new RangeError(`values from '${a}' are not uniquely identified; use valuesFn to summarise them`);let w=new Map;for(let a of l){let b=e[a],x=H(n.valuesFn,k,a),O=new Array(E.length).fill(null),R=null;if(x===void 0)R=Ae(a,b),E.forEach((A,F)=>{A.length>0&&(O[F]=b[A[0]])});else{let A=new Uint8Array(E.length),F=0,T=0;for(let S=0;S<r;S++){let _=m.codes[S]*N+c.codes[S];if(A[_]===1)continue;A[_]=1,T++;let V=x(E[_].map(Re=>b[Re]));if(O[_]=V,V==null)continue;let L=te(V);if(R===null||R==="logical"&&L==="double")R=L,F=T;else if(L!==R&&(R==="character"||L==="character"))throw new TypeError(`Can't combine \`x[[${F}]]\` <${R}> and \`x[[${T}]]\` <${L}>.`)}}let v=Cn(H(n.valuesFill,h,a)??null,R);w.set(a,{cells:O,type:R??(v===null?null:te(v)),fill:v})}let p=(a,b)=>{let x=e[a],{cells:O,type:R,fill:v}=w.get(a),A=m.firsts.map((F,T)=>{let S=T*N+b,_=E[S].length===0?v:O[S];return R==="double"&&typeof _=="boolean"?Number(_):_});return x instanceof Float64Array&&(R==="double"||R===null)?Float64Array.from(A,F=>F===null?NaN:F):A},d={};for(let a of s)M(d,a,K(e[a],m.firsts));let $=(a,b)=>l.length===1?g[b]:`${a}${u}${g[b]}`;if(t==="slowest")for(let a of y)for(let b of l)M(d,$(b,a),p(b,a));else for(let a of l)for(let b of y)M(d,$(a,b),p(a,b));return d}export{Q as IQR,kn as aggregate,pe as completeCases,_e as cor,Se as cov,qe as cummax,We as cummin,Ue as cumprod,Ve as cumsum,tn as cut,Xe as cv,ze as diff,dn as ecdf,rn as findInterval,Be as fivenum,Fe as fromRows,Ge as geometricMean,hn as hist,Ke as kurtosis,De as mad,Ie as mean,Qe as meanAD,G as median,ke as merge,Je as modes,sn as naOmit,jn as pivotLonger,Pn as pivotWider,ge as pretty,Ce as prod,J as quantile,C as range,Te as rank,Ze as scale,z as sd,Ye as skewness,An as split,Oe as subset,je as sum,en as table,He as tabulate,$n as tapply,Me as toRows,nn as unique,Pe as variance,Le as weightedMean};
|
|
1
|
+
/*! rStats.js 1.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{m as Te,n as Se,o as _e,p as J,q as Q,r as Be,s as De}from"./chunks/chunk-RWZ6ICYN.js";import{a as Ye,b as Ke,c as Ge,d as Je,e as Qe,f as Xe,g as Ze}from"./chunks/chunk-TYMC2D5I.js";import{a as Y,b as W,c as K,d as M,e as ce,f as ke,g as Oe,j as Fe,k as Me,m as je,n as Ce,o as Ie,p as Le,q as Pe,r as z,s as G,t as C,u as Ve,v as Ue,w as qe,x as We,y as ze}from"./chunks/chunk-2X6PE6JF.js";import{a as fe,b as He,c as en,d as nn,e as tn,f as rn}from"./chunks/chunk-52RWDNO6.js";import"./chunks/chunk-7ODUCEGX.js";import"./chunks/chunk-45HUI3M4.js";import{a as le,e as q,f as ie}from"./chunks/chunk-YT62DNDS.js";import"./chunks/chunk-HXYH5ZMB.js";import{a as ue}from"./chunks/chunk-JXJDCQYE.js";import{m as se}from"./chunks/chunk-TQM6KGKT.js";import{b as U,d as ae}from"./chunks/chunk-IJST2ZGT.js";import{b as re,c as oe}from"./chunks/chunk-YD4U3QZ3.js";import"./chunks/chunk-73IRLCTF.js";import{P as D,l as j,u as P}from"./chunks/chunk-2ZQ2TSZS.js";var me=e=>e===null||typeof e=="number"&&Number.isNaN(e),he=e=>Array.isArray(e)||ArrayBuffer.isView(e);function on(e){if(he(e))return{columns:[e],rows:e.length};if(typeof e!="object"||e===null)throw new TypeError("the arguments must be arrays or data frames");let n=Object.values(e),t=n[0]?.length??0;if(n.some(r=>r.length!==t))throw new RangeError("not all arguments have the same length");return{columns:n,rows:t}}function pe(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(on),t=n[0].rows;if(n.some(o=>o.rows!==t))throw new RangeError("not all arguments have the same length");let r=n.flatMap(o=>o.columns);return Array.from({length:t},(o,i)=>r.every(l=>!me(l[i])))}function sn(e){if(he(e))return Array.from(e).filter(r=>!me(r));let n=pe(e),t={};for(let[r,o]of Object.entries(e)){let i=Array.from(o).filter((l,s)=>n[s]);M(t,r,o instanceof Float64Array?Float64Array.from(i):i)}return t}var ln=["breaks","right","includeLowest"],an=["n","minN","shrinkSml","highUBias","u5Bias"];function ge(e,n={}){j(n,an,"pretty");let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5;if(Number.isNaN(r)||Math.abs(r)>=2**31||Math.trunc(r)<0)throw new RangeError("invalid 'n' argument");let o=Math.trunc(r),i=n.minN??Math.floor(r/3);if(Number.isNaN(i)||Math.trunc(i)<0||Math.trunc(i)>o)throw new RangeError("invalid 'min.n' argument");let l=Math.trunc(i),s=n.shrinkSml??.75;if(!Number.isFinite(s)||s<=0)throw new RangeError("invalid 'shrink.sml' argument");let f=n.highUBias??1.5;if(!Number.isFinite(f)||f<0)throw new RangeError("invalid 'high.u.bias' argument");let u=n.u5Bias??.5+1.5*f;if(!Number.isFinite(u)||u<0)throw new RangeError("invalid 'u5.bias' argument");let m=1/0,c=-1/0;for(let v of t)v<m&&(m=v),v>c&&(c=v);let y=c-m,g,N;if(y===0&&c===0)g=1,N=!0;else{g=Math.max(Math.abs(m),Math.abs(c));let A=(1+(u>=1.5*f+.5?1/(1+f):1.5/(1+u)))*Math.max(1,o)*Number.EPSILON;N=y<g*A*3}N?(g>10&&(g=9+g/10),g*=s,l>1&&(g/=l)):(g=o>1?y/o:y,y===1/0&&o>=2&&(g=c/o-m/o));let E=2**-20*un;g<E?g=E:g>Number.MAX_VALUE/1.25&&(g=Number.MAX_VALUE/1.25);let k=10**Math.floor(Math.log10(g)),h=[[2*k,f],[5*k,u],[10*k,f]],w=k;for(let[v,A]of h)if(v-g<A*(g-w))w=v;else break;let p=1e-10,d=Math.floor(m/w+p);for(;d*w>m+p*w;)d--;for(;!Number.isFinite(d*w);)d++;let $=Math.ceil(c/w-p);for(;$*w<c-p*w;)$++;for(;!Number.isFinite($*w);)$--;let a=Math.trunc(.5+$-d);if(a<l){let v=l-a,A=Math.floor(v/2),F=v%2;m===0&&d===0&&c!==0?$+=v:c===0&&$===0&&m!==0?d-=v:d>=0?($+=A,d-=A+F):(d-=A,$+=A+F),a=l}let b=d*w<m?d*w:m,x=$*w>c?$*w:c;if(a<=0)return[b];let O=fe(b,x,a+1),R=x/a-b/a;return O.map(v=>Math.abs(v)<1e-14*R?0:v)}var un=22250738585072014e-324;function cn(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function fn(e,n){let t=e.length;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let r=s=>[C(s),3.5*z(s)*t**-.3333333333333333],[[o,i],l]=r(e);return Number.isFinite(i-o)&&Number.isFinite(l)||([[o,i],l]=r(D([e]).groups[0])),l>0?Math.max(1,Math.ceil((i-o)/l)):1}case"fd":case"freedman-diaconis":{let r=(f,u)=>{let m=2*Q(u);for(let c=.125;m===0&&c>=.001953125;c/=2){let[y,g]=J(u,[c,1-c]);m=(g-y)/(1-2*c)}return m===0&&(m=3.5*z(f)),[C(f),m]},o=e.map(cn),[[i,l],s]=r(e,o);if(!(Number.isFinite(l-i)&&Number.isFinite(s))){let{k:f}=D([e]);[[i,l],s]=r(e.map(u=>P(u,-f)),o.map(u=>P(u,-f)))}return s>0?Math.ceil((l-i)/s*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function mn(e,n,t){let r=e.slice(1).map((o,i)=>o-e[i]);return e.length>5?1e-7*G(r):e.length<=3?t-n===1/0?2*(1e-7*(t/2-n/2)):1e-7*(t-n):1e-7*oe(r.filter(o=>o>0))}function hn(e,n={}){j(n,ln,"hist");let t=Array.from(e).filter(Number.isFinite),r=t.length,o=n.right??!0,i=n.includeLowest??!0,l=n.breaks??"Sturges",s;if(typeof l!="string"&&typeof l!="number"&&l.length>1){if(!l.every(Number.isFinite))throw new RangeError("'breaks' are not finite");if(s=[...l].sort((h,w)=>h-w),s.some((h,w)=>w>0&&!(h>s[w-1])))throw new RangeError("'breaks' are not strictly increasing")}else{i=!0;let h=typeof l=="string"?fn(t,l):typeof l=="number"?l:l[0];if(!Number.isFinite(h)||h<1)throw new RangeError("invalid number of 'breaks'");h=Math.min(h,1e6);let[w,p]=C(t);s=ge([w,p],{n:h,minN:1});for(let d=1;d<s.length;d++)if(!(s[d]-s[d-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let f=s.length,[u,m]=r>0?C(t):[0,0],c=mn(s,u,m),y=s.map((h,w)=>o?w===0&&i?h-c:h+c:w<f-1?h-c:i?h+c:h-c),g=new Array(Math.max(0,f-1)).fill(0),N=0;for(let h of t){let w=gn(h,y,o,i);w>=0&&(g[w]++,N++)}if(N<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let E=g.map((h,w)=>pn(h,r,s[w],s[w+1])),k=g.map((h,w)=>re(s[w+1],s[w]));return{breaks:s,counts:g,density:E,mids:k}}function pn(e,n,t,r){let o=r-t;if(!(n*o===1/0&&Number.isFinite(t)&&Number.isFinite(r)))return e/(n*o);let i=o===1/0?1:0,l=i===1?r/2-t/2:o,s=Math.floor(Math.log2(l));return P(e,-(s+i))/(n*P(l,-s))}function gn(e,n,t,r){let o=n.length-1;if(o<1)return-1;if(t){if(e===n[0]&&r)return 0;if(!(e>n[0]&&e<=n[o]))return-1;let s=1,f=o;for(;s<f;){let u=Math.floor((s+f)/2);e<=n[u]?f=u:s=u+1}return s-1}if(e===n[o]&&r)return o-1;if(!(e>=n[0]&&e<n[o]))return-1;let i=0,l=o-1;for(;i<l;){let s=Math.floor((i+l+1)/2);n[s]<=e?i=s:l=s-1}return i}function dn(e){let n=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,o)=>r-o),t=n.length;if(t<1)throw new RangeError("'x' must have 1 or more non-missing values");return r=>{if(Number.isNaN(r))return NaN;let o=0,i=t;for(;o<i;){let l=Math.floor((o+i)/2);n[l]<=r?o=l+1:i=l}return o/t}}var wn=["drop","sep"],B=e=>e===null||typeof e=="number"&&Number.isNaN(e),yn=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?ue(e,n):Number(e)-Number(n),bn=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?U(e):e>0?"Inf":"-Inf";function En(e,n){let t=ae(n),r=new Set(t.filter(s=>!B(s)).map(s=>typeof s));if(r.size>1)throw new TypeError(`${e} mixes ${[...r].join(" and ")} labels`);let o=[...r][0];if(o!==void 0&&o!=="number"&&o!=="string"&&o!=="boolean")throw new TypeError(`${e} has labels of an unsupported type`);let i=[...new Set(t.filter(s=>!B(s)))].sort(yn),l=new Map(i.map((s,f)=>[s,f]));return{levels:i,codes:t.map(s=>B(s)?-1:l.get(s))}}var I=e=>Array.isArray(e)||e instanceof Float64Array;function be(e){if(e instanceof Float64Array)return[e];if(!Array.isArray(e))throw new TypeError("the group labels must be an array or an array of arrays");if(e.length>0&&e.every(I))return[...e];if(e.some(I))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function X(e,n,t){e.forEach((l,s)=>{if(l.length!==t)throw new RangeError(`${n[s]} must have one label per row (${t}), not ${l.length}`)});let r=e.map((l,s)=>En(n[s],l)),o=r.reduce((l,s)=>l*s.levels.length,1);if(o>=2**31)throw new RangeError("total number of levels >= 2^31");let i=new Array(t);for(let l=0;l<t;l++){let s=0,f=1;for(let u of r){let m=u.codes[l];if(m<0){s=-1;break}s+=m*f,f*=u.levels.length}i[l]=s}return{factors:r,size:o,cells:i}}function Z(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function Nn(e,n){return e.factors.map(t=>{let r=t.levels.length,o=t.levels[n%r];return n=Math.floor(n/r),o})}var Ee=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function $n(e,n,t){let r=Array.from(e),o=be(n),i=X(o,Ee(o.length,"index"),r.length),l=Z(i).map(u=>u.length===0?null:{value:t(u.map(m=>r[m]))}),f=l.every(u=>u===null||typeof u.value=="number")?l.map(u=>u===null?NaN:u.value):l.map(u=>u===null?null:u.value);return{dim:i.factors.map(u=>u.levels.length),dimnames:i.factors.map(u=>[...u.levels]),values:f}}function vn(e,n){let t={};for(let[r,o]of Object.entries(e))M(t,r,o instanceof Float64Array?Float64Array.from(n,i=>o[i]):n.map(i=>o[i]));return t}function xn(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!I(o))throw new TypeError(`column '${r}' must be an array`);if(o.length!==t)throw new RangeError(`the columns of the data frame have different lengths (found for '${r}')`)}return t}function An(e,n,t={}){j(t,wn,"split");let r=t.sep??".",o=be(n),i=!I(e);if(i&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let l=i?xn(e):e.length,s=X(o,Ee(o.length,"f"),l),f=i?[]:Array.from(e),u=new Map;return Z(s).forEach((m,c)=>{if(m.length===0&&(t.drop||s.factors.length===1))return;let y=Nn(s,c).map(bn).join(r);if(u.has(y))throw new RangeError(`the group names joined with '${r}' are not unique ('${y}'); use another sep`);u.set(y,i?vn(e,m):m.map(g=>f[g]))}),u}function de(e,n){if(n===void 0)throw new RangeError(`object '${e}' not found`);if(!I(n))throw new TypeError(`column '${e}' must be an array`);return Array.from(n,t=>{if(t===null)return NaN;if(typeof t!="number")throw new TypeError(`column '${e}' to summarise must be numeric`);return t})}function we(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new RangeError(`object '${n}' not found`);if(!I(t))throw new TypeError(`column '${n}' must be an array`);return t}function Rn(e,n){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");if(t<0)throw new SyntaxError("invalid formula: missing '~'");let r=e.slice(0,t).trim(),{rhs:o}=le(`~ ${e.slice(t+1)}`),i=/^[A-Za-z.][A-Za-z0-9._]*$/,l;if(r!=="."){let u=/^cbind\s*\((.*)\)$/s.exec(r);if(l=u===null?[r]:u[1].split(",").map(m=>m.trim()),l.some(m=>!i.test(m)||m==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}else if(q(o,[]).length<q(o,["."]).length)throw new SyntaxError("invalid formula: '.' cannot be on both sides");let s=l===void 0?[]:n.filter(u=>!l.includes(u)),f=q(o,s);return ie(o,()=>0,s),{values:l??n.filter(u=>!f.includes(u)),groups:f}}function ye(e,n,t,r,o,i){let l=r[0]?.length??n[0]?.length??0;e.forEach((c,y)=>{if(n[y].length!==l)throw new RangeError(`variable lengths differ (found for '${c}')`)});let s=X(r,t,l),f=Z(s).map((c,y)=>({cell:y,rows:c.filter(o)})).filter(c=>c.rows.length>0),u={};t.forEach((c,y)=>{let g=r[y];M(u,c,f.map(N=>{let E=g[N.rows[0]];return E===0?0:E}))});let m=(c,y)=>{if(Object.hasOwn(u,c))throw new RangeError(`duplicate column name '${c}' in the result`);M(u,c,y)};return e.forEach((c,y)=>{let g=n[y],E=f.map(h=>i(h.rows.map(w=>g[w]))).map(h=>{if(typeof h=="number")return{names:void 0,values:[h]};if(Array.isArray(h))return{names:void 0,values:[...h]};let w=h;return{names:Object.keys(w),values:Object.values(w)}}),k=E[0]?.values.length??1;if(E.some(h=>h.values.length!==k))throw new RangeError("fun must return values of the same length for every group");if(k===1&&E[0]?.names===void 0){m(c,E.map(h=>h.values[0]));return}for(let h=0;h<k;h++){let w=E[0].names?.[h]??String(h+1);m(`${c}.${w}`,E.map(p=>p.values[h]))}}),u}function kn(e,n,t){if(typeof n!="object"||n===null)throw new TypeError("the data must be an object of columns");if(typeof e=="string"){let s=n,{values:f,groups:u}=Rn(e,Object.keys(s)),m=N=>Object.prototype.hasOwnProperty.call(s,N),c=f.map(N=>de(N,m(N)?s[N]:void 0)),y=u.map(N=>we(s,N));return ye(f,c,u,y,N=>c.every(E=>!Number.isNaN(E[N]))&&y.every(E=>!B(E[N])),t)}if(typeof e!="object"||e===null)throw new TypeError("x must be a data frame");let r=Object.keys(e),o=r.map(s=>de(s,e[s])),i=Object.keys(n);if(i.length===0)throw new RangeError("'by' must name at least one grouping column");let l=i.map(s=>we(n,s));return ye(r,o,i,l,()=>!0,t)}var On=new Set(["cols","namesTo","namesPrefix","namesSep","namesPattern","namesTransform","valuesTo","valuesDropNa","colsVary","onWarning"]),Fn=new Set(["namesFrom","valuesFrom","idCols","namesPrefix","namesSep","namesSort","namesVary","valuesFill","valuesFn"]),ee=e=>typeof e=="string"?[e]:[...e];function xe(e,n){if(n==null)return"fastest";if(n==="fastest"||n==="slowest")return n;throw typeof n!="string"?new TypeError(`\`${e}\` must be a string or character vector.`):new RangeError(`\`${e}\` must be one of "fastest" or "slowest", not "${n}".`)}function ne(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new RangeError(`Column \`${t}\` doesn't exist.`)}function Ae(e,n){if(n instanceof Float64Array)return"double";let t=null;for(let r of n){if(r===null)continue;let o=typeof r=="number"?"double":typeof r=="string"?"character":"logical";if(t!==null&&o!==t)throw new TypeError(`column '${e}' mixes ${t} and ${o} values`);t=o}return t}function Mn(e,n){let t=null;for(let r of n){let o=Ae(r,e[r]);if(o!==null){if(t===null)t={type:o,column:r};else if(t.type!==o){if(t.type==="character"||o==="character")throw new TypeError(`Can't combine \`${t.column}\` <${t.type}> and \`${r}\` <${o}>.`);o==="double"&&(t={type:o,column:r})}}}return t?.type??null}function Ne(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new TypeError(`\`regex\` should define ${t} groups; ${r} found.`);let o=new RegExp(n);return e.map(i=>{let l=o.exec(i);return Array.from({length:t},(s,f)=>l===null?null:l[f+1]??null)})}function Tn(e,n){let t=e.charCodeAt(n);if(t>=55296&&t<=56319&&n+1<e.length){let r=e.charCodeAt(n+1);if(r>=56320&&r<=57343)return 2}return 1}function Sn(e,n,t,r){let o=new RegExp(n,"g"),i=[],l=[],s=e.map((u,m)=>{let c=[],y=0,g=0;for(;;){o.lastIndex=y;let N=o.exec(u);if(N===null||(c.push(u.slice(g,N.index)),g=N.index+N[0].length,y=N[0].length===0?N.index+Tn(u,N.index):g,y>=u.length))break}return c.push(u.slice(g)),c.length>t&&i.push(m+1),c.length<t&&l.push(m+1),Array.from({length:t},(N,E)=>c[E]??null)}),f=u=>`${u.length} rows [${u.join(", ")}]`;return i.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${f(i)}.`),l.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${f(l)}.`),s}function $e(e,n){return e!==void 0&&Object.hasOwn(e,n)?e[n]:void 0}function _n(e,n,t,r){let{namesSep:o,namesPattern:i}=t;if(n.length===0)return e.map(()=>[]);if(n.length===1){if(o!==void 0)throw new TypeError("`names_sep` can't be used with a length 1 `names_to`.");return i===void 0?e.map(l=>[l]):Ne(e,i,1)}if(o===void 0==(i===void 0))throw new TypeError("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?Sn(e,o,n.length,r):Ne(e,i,n.length)}function jn(e,n){j(n,On,"pivotLonger");let t=xe("cols_vary",n.colsVary),r=Y(e),o=Object.keys(e),i=typeof n.cols=="function"?o.filter(n.cols):[...new Set(n.cols)];if(ne(e,i),i.length===0)throw new RangeError("`cols` must select at least one column.");let l=ee(n.namesTo??"name"),s=l.indexOf(".value");if(l.lastIndexOf(".value")!==s)throw new RangeError('`names_to` may contain ".value" only once');let f=[],u=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),m=i.map(p=>u===null?p:p.replace(u,"")),c=_n(m,l,n,f),y=[],g=[];if(s<0)y.push(...c),g.push({name:n.valuesTo??"value",sources:[...i]});else{let p=new Map,d=new Map,$=$e(n.namesTransform,".value");c.forEach((a,b)=>{let x=a.filter((S,_)=>_!==s),O=JSON.stringify(x),R=p.get(O);if(R===void 0){R=y.length,p.set(O,R),y.push(x);for(let S of g)S.sources.push(null)}let v=a[s]??null,A=v===null||$===void 0?v:$(v);if(A!==null&&typeof A!="string")throw new TypeError(`the transform of \`.value\` must give strings, not ${typeof A}`);let F=A??"NA",T=d.get(F);if(T===void 0&&(T={name:F,sources:y.map(()=>null)},d.set(F,T),g.push(T)),T.sources[R]!==null)throw new RangeError(`the names give the value column '${F}' twice for one key`);T.sources[R]=i[b]})}let N=g.map(p=>Mn(e,p.sources.filter(d=>d!==null))),E=[];if(t==="slowest")for(let p=0;p<y.length;p++)for(let d=0;d<r;d++)E.push([d,p]);else for(let p=0;p<r;p++)for(let d=0;d<y.length;d++)E.push([p,d]);let k=(p,d,$)=>{let a=p.sources[$];return a==null?null:e[a][d]};n.valuesDropNa===!0&&(E=E.filter(([p,d])=>g.some($=>!W(k($,p,d)))));let h={},w=E.map(([p])=>p);for(let p of o)i.includes(p)||M(h,p,K(e[p],w));if(l.forEach((p,d)=>{if(d===s)return;let $=$e(n.namesTransform,p),a=b=>{let x=y[b][d<s||s<0?d:d-1];return x===null||$===void 0?x:$(x)};M(h,p,E.map(([,b])=>a(b)))}),g.forEach((p,d)=>{let $=N[d]==="double";if($&&p.sources.every(a=>a!==null&&e[a]instanceof Float64Array))M(h,p.name,Float64Array.from(E,([a,b])=>k(p,a,b)));else{let a=E.map(([b,x])=>{let O=k(p,b,x);return $&&typeof O=="boolean"?Number(O):O});M(h,p.name,a)}}),n.onWarning!==void 0)for(let p of new Set(f))n.onWarning(p);else se("pivotLonger",f);return h}var te=e=>typeof e=="number"?"double":typeof e=="string"?"character":"logical";function Cn(e,n){if(e===null||n===null)return e;let t=te(e);if(t===n)return e;if(n==="double"&&t==="logical")return Number(e);if(n==="logical"&&t==="double"){let r=e;if(Number.isNaN(r))return null;if(r===0||r===1)return r===1;throw new TypeError("Can't convert from `fill` <double> to <logical> due to loss of precision.")}throw new TypeError(`Can't convert \`fill\` <${t}> to <${n}>.`)}var In=e=>W(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function ve(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(i,l)=>{let s=JSON.stringify(e.map(u=>In(u[l]))),f=t.get(s);return f===void 0&&(f=r.length,t.set(s,f),r.push(l)),f}),firsts:r}}function Ln(e){return W(e)?"NA":typeof e=="number"?Number.isFinite(e)?U(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function H(e,n,t){if(e!==void 0)return n(e)?e:Object.hasOwn(e,t)?e[t]:void 0}function Pn(e,n={}){j(n,Fn,"pivotWider");let t=xe("names_vary",n.namesVary),r=Y(e),o=(a,b)=>{let x=[...new Set(ee(a))];if(ne(e,x),x.length===0)throw new RangeError(`\`${b}\` must select at least one column.`);return x},i=o(n.namesFrom??"name","names_from"),l=o(n.valuesFrom??"value","values_from"),s=n.idCols===void 0?Object.keys(e).filter(a=>!i.includes(a)&&!l.includes(a)):[...new Set(ee(n.idCols))];ne(e,s);for(let a of s){let b=i.includes(a)?"names_from":l.includes(a)?"values_from":null;if(b!==null)throw new RangeError(`\`id_cols\` can't select a column already selected by \`${b}\`. Column \`${a}\` has already been selected.`)}let f=n.namesPrefix??"",u=n.namesSep??"_",m=ve(s.map(a=>e[a]),r),c=ve(i.map(a=>e[a]),r),y=c.firsts.map((a,b)=>b);n.namesSort===!0&&y.sort((a,b)=>{for(let x of i){let O=ce(e[x][c.firsts[a]],e[x][c.firsts[b]]);if(O!==0)return O}return 0});let g=c.firsts.map(a=>f+i.map(b=>Ln(e[b][a])).join(u)),N=c.firsts.length,E=Array.from({length:m.firsts.length*N},()=>[]);for(let a=0;a<r;a++)E[m.codes[a]*N+c.codes[a]].push(a);let k=a=>typeof a=="function",h=a=>typeof a!="object"||a===null;for(let a of l)if(H(n.valuesFn,k,a)===void 0&&E.some(b=>b.length>1))throw new RangeError(`values from '${a}' are not uniquely identified; use valuesFn to summarise them`);let w=new Map;for(let a of l){let b=e[a],x=H(n.valuesFn,k,a),O=new Array(E.length).fill(null),R=null;if(x===void 0)R=Ae(a,b),E.forEach((A,F)=>{A.length>0&&(O[F]=b[A[0]])});else{let A=new Uint8Array(E.length),F=0,T=0;for(let S=0;S<r;S++){let _=m.codes[S]*N+c.codes[S];if(A[_]===1)continue;A[_]=1,T++;let V=x(E[_].map(Re=>b[Re]));if(O[_]=V,V==null)continue;let L=te(V);if(R===null||R==="logical"&&L==="double")R=L,F=T;else if(L!==R&&(R==="character"||L==="character"))throw new TypeError(`Can't combine \`x[[${F}]]\` <${R}> and \`x[[${T}]]\` <${L}>.`)}}let v=Cn(H(n.valuesFill,h,a)??null,R);w.set(a,{cells:O,type:R??(v===null?null:te(v)),fill:v})}let p=(a,b)=>{let x=e[a],{cells:O,type:R,fill:v}=w.get(a),A=m.firsts.map((F,T)=>{let S=T*N+b,_=E[S].length===0?v:O[S];return R==="double"&&typeof _=="boolean"?Number(_):_});return x instanceof Float64Array&&(R==="double"||R===null)?Float64Array.from(A,F=>F===null?NaN:F):A},d={};for(let a of s)M(d,a,K(e[a],m.firsts));let $=(a,b)=>l.length===1?g[b]:`${a}${u}${g[b]}`;if(t==="slowest")for(let a of y)for(let b of l)M(d,$(b,a),p(b,a));else for(let a of l)for(let b of y)M(d,$(a,b),p(a,b));return d}export{Q as IQR,kn as aggregate,pe as completeCases,_e as cor,Se as cov,qe as cummax,We as cummin,Ue as cumprod,Ve as cumsum,tn as cut,Xe as cv,ze as diff,dn as ecdf,rn as findInterval,Be as fivenum,Fe as fromRows,Ge as geometricMean,hn as hist,Ke as kurtosis,De as mad,Ie as mean,Qe as meanAD,G as median,ke as merge,Je as modes,sn as naOmit,jn as pivotLonger,Pn as pivotWider,ge as pretty,Ce as prod,J as quantile,C as range,Te as rank,Ze as scale,z as sd,Ye as skewness,An as split,Oe as subset,je as sum,en as table,He as tabulate,$n as tapply,Me as toRows,nn as unique,Pe as variance,Le as weightedMean};
|