@numero-uno-jpn/rstats 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.ja.md +42 -12
- package/README.md +40 -10
- package/dist/chunks/{chunk-FVPDVRJQ.js → chunk-3VMBBQLV.js} +2 -2
- package/dist/chunks/chunk-4OKAZJJG.js +3 -0
- package/dist/chunks/{chunk-GG4BJMJW.js → chunk-6BH65HGN.js} +1 -1
- package/dist/chunks/chunk-ATC4F4BX.js +2 -0
- package/dist/chunks/{chunk-6I6QKTFK.js → chunk-EDH53DXN.js} +2 -2
- package/dist/chunks/{chunk-ZRJQD7VS.js → chunk-EZ2KD5NA.js} +2 -2
- package/dist/chunks/{chunk-KK4GE65D.js → chunk-GSPOO2G3.js} +2 -2
- package/dist/chunks/{chunk-36GVER3O.js → chunk-K7AZ65H7.js} +2 -2
- package/dist/chunks/{chunk-2X7JYQBI.js → chunk-LEIH4U5X.js} +2 -2
- package/dist/chunks/{chunk-ETOEZTGL.js → chunk-OX3SBG5X.js} +1 -1
- package/dist/chunks/chunk-SGZQDJRR.js +2 -0
- package/dist/chunks/{chunk-PHHUHR7T.js → chunk-UH2N3ZQW.js} +1 -1
- package/dist/chunks/chunk-UV2MZYDQ.js +2 -0
- package/dist/chunks/{chunk-WQPFDDIY.js → chunk-VQHEOBTM.js} +2 -2
- package/dist/chunks/chunk-WJQZZYOI.js +2 -0
- package/dist/chunks/chunk-WKEFHOFR.js +2 -0
- package/dist/chunks/{chunk-X2AWQSVS.js → chunk-WXC25OPJ.js} +2 -2
- package/dist/chunks/{chunk-HITD7CX6.js → chunk-XJQKSR52.js} +1 -1
- package/dist/data/grouping.d.ts +6 -3
- package/dist/data/grouping.js +19 -22
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/mixed.d.ts +1 -0
- package/dist/entries/mixed.js +2 -0
- package/dist/htest/testFormula.js +6 -3
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +3 -0
- package/dist/models/aovStrata.d.ts +1 -1
- package/dist/models/aovStrata.js +5 -1
- package/dist/models/formula.d.ts +26 -1
- package/dist/models/formula.js +125 -9
- package/dist/models/lm.d.ts +2 -2
- package/dist/models/lmer.d.ts +162 -0
- package/dist/models/lmer.js +457 -0
- package/dist/models/mixedDeviance.d.ts +44 -0
- package/dist/models/mixedDeviance.js +872 -0
- package/dist/models/mixedStructure.d.ts +82 -0
- package/dist/models/mixedStructure.js +309 -0
- package/dist/models/modelFrame.d.ts +12 -1
- package/dist/models/modelFrame.js +36 -21
- package/dist/models/modelMatrix.d.ts +15 -4
- package/dist/models/modelMatrix.js +18 -4
- package/dist/numerics.js +2 -2
- package/dist/rstats.js +14 -14
- package/dist/special.js +2 -2
- package/dist/tests.js +12 -12
- package/llms.txt +11 -3
- package/package.json +5 -1
- package/dist/chunks/chunk-3WUXRSM6.js +0 -2
- package/dist/chunks/chunk-LAUYSGV4.js +0 -3
- package/dist/chunks/chunk-M6GDXKKS.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
2
|
-
import{a as h,b as c,c as b}from"./chunk-
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as h,b as c,c as b}from"./chunk-VQHEOBTM.js";import{D as L,E as C,k as v,l as j,n as M,o as x}from"./chunk-EDH53DXN.js";import{b as l,d as g,g as y,i as F,k as d}from"./chunk-OX3SBG5X.js";var I=30;function m(t){return t===Math.floor(t)}function D(t,r){if(m(t))return t;if(t>=0)return h(t)?t:c(t);let n=r-1-t;return h(n)?t:r-1-c(n)||-0}function S(t,r){let n=[1,0];for(let i=0;i<r;i++)n=F(y(n,l(t,-i)),[i+1,0]);return n}function p(t,r){return Math.min(t,r)>=1&&Math.max(t,r)<2**52?C(t,r):[L(t,r),0]}function A(t,r){if(t<0){let a=g(d(l(r,-t)),p(-t,r+1));return{log:[-a[0],-a[1]],sign:r%2===0?1:-1}}if(m(t)&&t<r)return;if(t>=r-1){let a=g(d(l(t,1)),p(t-r+1,r+1));return{log:[-a[0],-a[1]],sign:1}}let n=v(t),[i,e]=l(t,1),[o,f]=l(r,-t),s=e===0&&f===0?0:b(i+o),u=(e===0?0:e*(b(i)-s))+(f===0?0:f*(b(o)-s));return{log:g(p(i,o),[Math.log(Math.abs(n)/Math.PI)+u,0]),sign:(r%2===0?-1:1)*Math.sign(n)}}function O(t,r,n){if(Number.isNaN(t)||Number.isNaN(r))return NaN;let i=n?.rCompatible??!0;if(r=c(r),r<0)return 0;if(r===0)return 1;if(!Number.isFinite(r))return i&&t>=0&&t<1/0?0:NaN;if(!Number.isFinite(t))return i&&r>=I?NaN:t>0||r%2===0?1/0:-1/0;if(r<I){let f=i&&!m(t)&&!h(t);if(f&&t>=0&&c(t)<r)return 0;let s=S(t,r),u=s[0]+s[1];if(Number.isFinite(u))return m(t)||f?Math.round(u):u;let N=1;for(let a=0;a<r;a++)N=N*(t-a)/(a+1);return N}if(i&&(t=D(t,r),Object.is(t,-0)))return r%2===0?0:-0;let e=A(t,r);if(e===void 0)return 0;let o=e.sign*Math.exp(e.log[0])*(1+e.log[1]);return m(t)&&Number.isFinite(o)?Math.round(o):o}function P(t,r,n){if(Number.isNaN(t)||Number.isNaN(r))return NaN;let i=n?.rCompatible??!0;if(r=c(r),r<0)return-1/0;if(r===0)return 0;if(!Number.isFinite(r))return i&&t>=0&&t<1/0?-1/0:NaN;if(!Number.isFinite(t))return i&&r>=2?NaN:1/0;if(i&&r>=2&&(t=D(t,r)),r<I){let o=S(t,r),f=Math.abs(o[0]+o[1]);if(f>1e-300&&f<1e300){let u=d(o[0]<0?[-o[0],-o[1]]:o);return u[0]+u[1]}if(f===0)return-1/0;let s=-M(r+1);for(let u=0;u<r;u++)s+=Math.log(Math.abs(t-u));return s}let e=A(t,r);return e===void 0?-1/0:m(t)&&e.log[0]<36?Math.log(Math.round(Math.exp(e.log[0])*(1+e.log[1]))):e.log[0]+e.log[1]}function R(t){return j(t+1)}function _(t){return Math.abs(t)<=.2?x(t):M(t+1)}export{O as a,P as b,R as c,_ as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
2
|
var _=!0;function xt(){return _}function qt(t,s){if(!_)return[t+s,0];let n=t+s,o=n-t,u=t-(n-o)+(s-o);return[n,u]}function Mt(t,s){if(!_)return[t*s,0];let n=t*s,o=134217729*t,u=o-(o-t),T=t-u;o=134217729*s;let c=o-(o-s),e=s-c,l=u*c-n+u*e+T*c+T*e;return[n,l]}function Dt(t,s){if(!_)return[t[0]+s[0],0];let n=t[0]+s[0],o=n-t[0],u=t[0]-(n-o)+(s[0]-o),T=t[1]+s[1],c=T-t[1],e=t[1]-(T-c)+(s[1]-c),l=u+T,E=n+l,S=l-(E-n)+e,P=E+S,i=S-(P-E);return[P,i]}function mt(t){return[-t[0],-t[1]]}function gt(t,s){if(!_)return[t[0]-s[0],0];let n=-s[0],o=-s[1],u=t[0]+n,T=u-t[0],c=t[0]-(u-T)+(n-T),e=t[1]+o,l=e-t[1],E=t[1]-(e-l)+(o-l),L=c+e,S=u+L,i=L-(S-u)+E,m=S+i,j=i-(m-S);return[m,j]}function At(t,s){if(!_)return[t[0]*s[0],0];let n=t[0]*s[0],o=134217729*t[0],u=o-(o-t[0]),T=t[0]-u,c=134217729*s[0],e=c-(c-s[0]),l=s[0]-e,L=u*e-n+u*l+T*e+T*l+(t[0]*s[1]+t[1]*s[0]),S=n+L,P=L-(S-n);return[S,P]}function Nt(t,s){if(!_)return[t[0]*s,0];let n=t[0]*s,o=134217729*t[0],u=o-(o-t[0]),T=t[0]-u,c=134217729*s,e=c-(c-s),l=s-e,L=u*e-n+u*l+T*e+T*l+t[1]*s,S=n+L,P=L-(S-n);return[S,P]}function vt(t,s){if(!_)return[t[0]/s[0],0];let n=t[0]/s[0],o=s[0]*n,u=134217729*s[0],T=u-(u-s[0]),c=s[0]-T,e=134217729*n,l=e-(e-n),E=n-l,S=T*l-o+T*E+c*l+c*E+s[1]*n,P=o+S,i=S-(P-o),m=-P,j=-i,f=t[0]+m,Y=f-t[0],P1=t[0]-(f-Y)+(m-Y),N=t[1]+j,y=N-t[1],d1=t[1]-(N-y)+(j-y),Z=P1+N,d=f+Z,v=Z-(d-f)+d1,p=d+v,z=v-(p-d),h=p/s[0],B=s[0]*h,o1=134217729*s[0],G=o1-(o1-s[0]),F=s[0]-G,u1=134217729*h,O=u1-(u1-h),R=h-O,w=G*O-B+G*R+F*O+F*R+s[1]*h,H=B+w,T1=w-(H-B),J=-H,$=-T1,q=p+J,K=q-p,b1=p-(q-K)+(J-K),a=z+$,s1=a-z,r1=z-(a-s1)+($-s1),c1=b1+a,Q=q+c1,k=c1-(Q-q)+r1,t1=Q+k,F1=k-(t1-Q),U=t1/s[0],M=n+h,V=h-(M-n),D=M+U,W=D-M,q1=M-(D-W)+(U-W),C=V+0,g=C-V,e1=V-(C-g)+(0-g),x=q1+C,A=D+x,X=x-(A-D)+e1,n1=A+X,l1=X-(n1-A);return[n1,l1]}function Bt(t,s){if(!_)return[t[0]/s,0];let n=t[0]/s,o=s*n,u=134217729*s,T=u-(u-s),c=s-T,e=134217729*n,l=e-(e-n),E=n-l,S=T*l-o+T*E+c*l+c*E+0*n,P=o+S,i=S-(P-o),m=-P,j=-i,f=t[0]+m,Y=f-t[0],P1=t[0]-(f-Y)+(m-Y),N=t[1]+j,y=N-t[1],d1=t[1]-(N-y)+(j-y),Z=P1+N,d=f+Z,v=Z-(d-f)+d1,p=d+v,z=v-(p-d),h=p/s,B=s*h,o1=134217729*s,G=o1-(o1-s),F=s-G,u1=134217729*h,O=u1-(u1-h),R=h-O,w=G*O-B+G*R+F*O+F*R+0*h,H=B+w,T1=w-(H-B),J=-H,$=-T1,q=p+J,K=q-p,b1=p-(q-K)+(J-K),a=z+$,s1=a-z,r1=z-(a-s1)+($-s1),c1=b1+a,Q=q+c1,k=c1-(Q-q)+r1,t1=Q+k,F1=k-(t1-Q),U=t1/s,M=n+h,V=h-(M-n),D=M+U,W=D-M,q1=M-(D-W)+(U-W),C=V+0,g=C-V,e1=V-(C-g)+(0-g),x=q1+C,A=D+x,X=x-(A-D)+e1,n1=A+X,l1=X-(n1-A);return[n1,l1]}var f1=[.6931471805599453,23190468138462996e-33],g2=Math.SQRT2,r=[[1,0],[.3333333333333333,1850371707708594e-32],[.2,-11102230246251566e-33],[.14285714285714285,793016446160826e-32],[.1111111111111111,61679056923619804e-34],[.09090909090909091,-2523234146875356e-33]],tt=89,nt=[[-.3633938941874773,-2106844752226605e-32],[-.3522205935893521,-57233316949182485e-34],[-.34117075740276714,19366790062602867e-33],[-.33024168687057687,10828321637483858e-33],[-.3194307707663612,-1354256857264811e-33],[-.3087354816496133,16199186085148102e-33],[-.29815337231907635,1720695867445866e-32],[-.2876820724517809,-2607160616442564e-32],[-.27731928541623435,744528405583513e-32],[-.26706278524904525,732891532732017e-32],[-.2569104137850272,-2502843296152504e-32],[-.24686007793152578,-1361743371748368e-32],[-.2369097470783577,-19682402978398164e-34],[-.22705745063534608,-9551415762738488e-33],[-.2173012756899814,-16168452453763015e-34],[-.2076393647782445,-12053243216686129e-33],[-.1980699137620938,-3742843482461439e-33],[-.18859116980755003,7432164219196925e-33],[-.179201429457711,10785017454858423e-33],[-.16989903679539747,4868008764439071e-34],[-.16068238169047347,3650183553047837e-33],[-.15154989812720093,-51669593684615594e-34],[-.14250006260728304,9926388234225749e-33],[-.13353139262452263,3664457663660085e-33],[-.1246424452072766,5808912678940971e-33],[-.1158318155251217,-4338484369808096e-33],[-.1070981355563671,173705104015906e-32],[-.09844007281325252,4439009633675136e-33],[-.08985632912186105,6273760163689594e-34],[-.0813456394539524,-507707635593117e-32],[-.07290677080808779,6306860257532778e-33],[-.06453852113757118,6470486661692933e-33],[-.05623971832287608,32835149805605613e-34],[-.048009219186360606,-14390903347292205e-34],[-.039845908547199674,3129547680315208e-33],[-.0317486983145803,-30382263084680858e-34],[-.023716526617316044,15774243488668215e-34],[-.015748356968139168,-10021578630528974e-34],[-.007843177461025893,-2764708154124904e-34],[0,0],[.007782140442054949,-12819179123343845e-36],[.015504186535965254,-3278321022892429e-34],[.02316705928153438,-11769544932063305e-34],[.030771658666753687,10431732029005968e-34],[.0383188643021366,-2357996157351286e-33],[.0458095360312942,1902959866474257e-33],[.053244514518812285,-1665575816973663e-33],[.06062462181643484,26424025938726934e-34],[.06795066190850775,-12802141240611733e-34],[.07522342123758753,-5930604196293241e-33],[.08244366921107459,5700437773813987e-33],[.08961215868968714,-54268129336647135e-34],[.09672962645855111,-5597397486289965e-34],[.10379679368164356,547772415726659e-32],[.11081436634029011,1183748342825649e-33],[.11778303565638346,-11971685747593677e-34],[.12470347850095724,-46522609636496624e-34],[.13157635778871926,11123000879729588e-33],[.13840232285911913,4447777301357527e-33],[.1451820098444979,8242418783022475e-33],[.15191604202584197,64838631244022194e-34],[.15860503017663857,11257003872182592e-33],[.16524957289530717,-10094935622322628e-33],[.17185025692665923,-60224538210113705e-34],[.1784076574728183,-12432553788701131e-33],[.184922338494012,30236614153574064e-34],[.19139485299962947,-12129496905792884e-33],[.19782574332991987,12821194372980142e-33],[.2042155414286909,27338281018722773e-34],[.21056476910734964,-4249405314729895e-33],[.21687393830061436,4551026193234283e-33],[.22314355131420976,-9091270597324799e-33],[.22937410106484582,9927671823978025e-33],[.2355660713127669,-23943371495187355e-34],[.24171993688714516,8900990022166643e-33],[.24783616390458127,-12432209578702523e-33],[.25391520998096345,-8048097394424201e-33],[.25995752443692605,2069806938978935e-32],[.26596354849713794,53393802761314314e-34],[.27193371548364176,783319637697442e-33],[.2778684510034563,-916018294909263e-33],[.2837681731306446,-2032665581126656e-32],[.28963329258304266,20535953219858174e-33],[.2954642128938359,-216461086040599e-31],[.3012613305781618,-9048511144048564e-33],[.3070250352949119,-12319916200101964e-33],[.3127557100038969,-1451808353098951e-32],[.3184537311185346,27114779367326236e-33],[.324119468654212,-7958214381893813e-33],[.329753286372468,2122020616196946e-33],[.3353555419211378,1834564437059473e-32],[.3409265869705932,17467136443544747e-33],[.34646676734620857,1028583585496265e-32],[.3519764231571782,-12953893030191963e-33],[.3574558889218038,-25136910072413547e-33]];function Gt(t){if(!_)return[Math.log(t[0]),0];let s=t[0],n=t[1],o=0;s<22250738585072014e-324&&(s*=2**600,n*=2**600,o=-600);let u=Math.floor(Math.log2(s));o+=u;let T=2**-u,c=s*T,e=n*T;c>=g2?(c=c/2,e=e/2,o+=1):c<g2/2&&(c=c*2,e=e*2,o-=1);let l=Math.round(c*128),E=l/128,L=nt[l-tt],S=-E,P=-0,i=c+S,m=i-c,j=c-(i-m)+(S-m),f=e+P,Y=f-e,P1=e-(f-Y)+(P-Y),N=j+f,y=i+N,Z=N-(y-i)+P1,d=y+Z,I1=Z-(d-y),v=c+E,p=v-c,z=c-(v-p)+(E-p),h=e+0,B=h-e,o1=e-(h-B)+(0-B),G=z+h,F=v+G,O=G-(F-v)+o1,R=F+O,w1=O-(R-F),w=d/R,H=R*w,T1=134217729*R,J=T1-(T1-R),$=R-J,q=134217729*w,K=q-(q-w),b1=w-K,s1=J*K-H+J*b1+$*K+$*b1+w1*w,r1=H+s1,c1=s1-(r1-H),Q=-r1,x1=-c1,k=d+Q,t1=k-d,F1=d-(k-t1)+(Q-t1),U=I1+x1,M=U-I1,V=I1-(U-M)+(x1-M),D=F1+U,W=k+D,C=D-(W-k)+V,g=W+C,e1=C-(g-W),x=g/R,A=R*x,M1=134217729*R,X=M1-(M1-R),n1=R-X,l1=134217729*x,H1=l1-(l1-x),K0=x-H1,U0=X*H1-A+X*K0+n1*H1+n1*K0+w1*x,V0=A+U0,A2=U0-(V0-A),W0=-V0,X0=-A2,D1=g+W0,Y0=D1-g,N2=g-(D1-Y0)+(W0-Y0),J1=e1+X0,Z0=J1-e1,v2=e1-(J1-Z0)+(X0-Z0),$0=N2+J1,K1=D1+$0,a0=$0-(K1-D1)+v2,ss=K1+a0,et=a0-(ss-K1),ts=ss/R,m1=w+x,U1=x-(m1-w),g1=m1+ts,ns=g1-m1,B2=m1-(g1-ns)+(ts-ns),V1=U1+0,os=V1-U1,G2=U1-(V1-os)+(0-os),cs=B2+V1,W1=g1+cs,es=cs-(W1-g1)+G2,I=W1+es,X1=es-(I-W1),Y1=I*I,us=134217729*I,Z1=us-(us-I),Ts=I-Z1,bs=134217729*I,$1=bs-(bs-I),rs=I-$1,ls=Z1*$1-Y1+Z1*rs+Ts*$1+Ts*rs+(I*X1+X1*I),b=Y1+ls,p1=ls-(b-Y1),a1=r[5][0]*b,Ss=134217729*r[5][0],s0=Ss-(Ss-r[5][0]),hs=r[5][0]-s0,Ls=134217729*b,t0=Ls-(Ls-b),Rs=b-t0,Es=s0*t0-a1+s0*Rs+hs*t0+hs*Rs+(r[5][0]*p1+r[5][1]*b),A1=a1+Es,n0=Es-(A1-a1),N1=A1+r[4][0],Ps=N1-A1,O2=A1-(N1-Ps)+(r[4][0]-Ps),o0=n0+r[4][1],Is=o0-n0,Q2=n0-(o0-Is)+(r[4][1]-Is),ps=O2+o0,c0=N1+ps,is=ps-(c0-N1)+Q2,S1=c0+is,k2=is-(S1-c0),e0=S1*b,fs=134217729*S1,u0=fs-(fs-S1),ds=S1-u0,ws=134217729*b,T0=ws-(ws-b),xs=b-T0,qs=u0*T0-e0+u0*xs+ds*T0+ds*xs+(S1*p1+k2*b),v1=e0+qs,b0=qs-(v1-e0),B1=v1+r[3][0],Ms=B1-v1,C2=v1-(B1-Ms)+(r[3][0]-Ms),r0=b0+r[3][1],Ds=r0-b0,_2=b0-(r0-Ds)+(r[3][1]-Ds),ms=C2+r0,l0=B1+ms,gs=ms-(l0-B1)+_2,h1=l0+gs,j2=gs-(h1-l0),S0=h1*b,As=134217729*h1,h0=As-(As-h1),Ns=h1-h0,vs=134217729*b,L0=vs-(vs-b),Bs=b-L0,Gs=h0*L0-S0+h0*Bs+Ns*L0+Ns*Bs+(h1*p1+j2*b),G1=S0+Gs,R0=Gs-(G1-S0),O1=G1+r[2][0],Os=O1-G1,y2=G1-(O1-Os)+(r[2][0]-Os),E0=R0+r[2][1],Qs=E0-R0,z2=R0-(E0-Qs)+(r[2][1]-Qs),ks=y2+E0,P0=O1+ks,Cs=ks-(P0-O1)+z2,L1=P0+Cs,F2=Cs-(L1-P0),I0=L1*b,_s=134217729*L1,p0=_s-(_s-L1),js=L1-p0,ys=134217729*b,i0=ys-(ys-b),zs=b-i0,Fs=p0*i0-I0+p0*zs+js*i0+js*zs+(L1*p1+F2*b),Q1=I0+Fs,f0=Fs-(Q1-I0),k1=Q1+r[1][0],Hs=k1-Q1,H2=Q1-(k1-Hs)+(r[1][0]-Hs),d0=f0+r[1][1],Js=d0-f0,J2=f0-(d0-Js)+(r[1][1]-Js),Ks=H2+d0,w0=k1+Ks,Us=Ks-(w0-k1)+J2,R1=w0+Us,K2=Us-(R1-w0),x0=R1*b,Vs=134217729*R1,q0=Vs-(Vs-R1),Ws=R1-q0,Xs=134217729*b,M0=Xs-(Xs-b),Ys=b-M0,Zs=q0*M0-x0+q0*Ys+Ws*M0+Ws*Ys+(R1*p1+K2*b),C1=x0+Zs,D0=Zs-(C1-x0),_1=C1+r[0][0],$s=_1-C1,U2=C1-(_1-$s)+(r[0][0]-$s),m0=D0+r[0][1],as=m0-D0,V2=D0-(m0-as)+(r[0][1]-as),s2=U2+m0,g0=_1+s2,t2=s2-(g0-_1)+V2,E1=g0+t2,W2=t2-(E1-g0),A0=I*E1,n2=134217729*I,N0=n2-(n2-I),o2=I-N0,c2=134217729*E1,v0=c2-(c2-E1),e2=E1-v0,u2=N0*v0-A0+N0*e2+o2*v0+o2*e2+(I*W2+X1*E1),i1=A0+u2,X2=u2-(i1-A0),B0=i1*2,T2=134217729*i1,G0=T2-(T2-i1),b2=i1-G0,r2=134217729*2,O0=r2-(r2-2),l2=2-O0,S2=G0*O0-B0+G0*l2+b2*O0+b2*l2+X2*2,Q0=B0+S2,h2=S2-(Q0-B0),j1=L[0]+Q0,L2=j1-L[0],Y2=L[0]-(j1-L2)+(Q0-L2),k0=L[1]+h2,R2=k0-L[1],Z2=L[1]-(k0-R2)+(h2-R2),E2=Y2+k0,C0=j1+E2,P2=E2-(C0-j1)+Z2,y1=C0+P2,_0=P2-(y1-C0),j0=f1[0]*o,I2=134217729*f1[0],y0=I2-(I2-f1[0]),p2=f1[0]-y0,i2=134217729*o,z0=i2-(i2-o),f2=o-z0,d2=y0*z0-j0+y0*f2+p2*z0+p2*f2+f1[1]*o,F0=j0+d2,w2=d2-(F0-j0),z1=y1+F0,x2=z1-y1,$2=y1-(z1-x2)+(F0-x2),H0=_0+w2,q2=H0-_0,a2=_0-(H0-q2)+(w2-q2),M2=$2+H0,J0=z1+M2,D2=M2-(J0-z1)+a2,m2=J0+D2,st=D2-(m2-J0);return[m2,st]}export{xt as a,qt as b,Mt as c,Dt as d,mt as e,gt as f,At as g,Nt as h,vt as i,Bt as j,Gt as k};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{k as I,r as re}from"./chunk-EZ2KD5NA.js";import{a as ne,d as se,f as X,g as j,i as oe}from"./chunk-GSPOO2G3.js";import{g as T,h as G}from"./chunk-EDH53DXN.js";import{b as ee,c as te,d as A,f as q,g as C,i as W}from"./chunk-OX3SBG5X.js";import{b as Y,c as ae,i as ie}from"./chunk-4OKAZJJG.js";import{b as ce,c as V}from"./chunk-WKEFHOFR.js";function z(e){if(e.kind==="factor")return ce(e);let t=[...new Set(e.values)].sort((s,o)=>s-o),n=[...new Set(t.map(Y))],r=new Map(n.map((s,o)=>[s,o]));return{levels:n,codes:e.values.map(s=>r.get(Y(s)))}}function E(e,t){if(e.kind!=="numeric")throw new TypeError(`'${t}' must be a numeric column`);return e.values}function D(e,t){let n=ae(e),r=ie(n,Object.keys(t));return{terms:r,rhsVariables:r.variables.slice(r.response===0?1:0)}}function fe(e){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");return t<0?void 0:{lhs:e.slice(0,t).trim(),rhs:e.slice(t+1)}}var Ae=/^Pair\s*\(\s*([A-Za-z.][A-Za-z0-9._]*)\s*,\s*([A-Za-z.][A-Za-z0-9._]*)\s*\)$/,F="'formula' missing or incorrect",le=(e,t)=>t.length===0&&e.terms.length===0&&e.intercept;function Ve(e,t,n){let r=fe(e),s=r===void 0?null:Ae.exec(r.lhs);if(s!==null){let{terms:m,rhsVariables:h}=D(`~${r.rhs}`,t);if(!n||!le(m,h))throw new Error(F);let w=V(t,[s[1],s[2]]);return{kind:"paired",x:E(w.variables[0],s[1]),y:E(w.variables[1],s[2])}}let{terms:o,rhsVariables:c}=D(e,t);if(o.response<0)throw new Error(F);let i=o.variables[0];if(n&&le(o,c))return{kind:"one",x:E(V(t,[i]).variables[0],i)};if(c.length!==1||o.terms.length!==1)throw new Error(F);let a=V(t,[i,c[0]],{dropUnusedLevels:!0}),l=E(a.variables[0],i),u=z(a.variables[1]);if(u.levels.length!==2)throw new Error("grouping factor must have exactly 2 levels");return{kind:"two",x:l.filter((m,h)=>u.codes[h]===0),y:l.filter((m,h)=>u.codes[h]===1),levels:[u.levels[0],u.levels[1]]}}function je(e,t){let n=Ve(e,t,!1);if(n.kind!=="two")throw new Error(F);return n}function ze(e,t){let{terms:n,rhsVariables:r}=D(e,t);if(n.response<0)throw new Error(F);if(r.length!==1)throw new Error("'formula' should be of the form response ~ group");let s=n.variables[0],o=V(t,[s,r[0]],{dropUnusedLevels:!0});return{values:E(o.variables[0],s),group:z(o.variables[1])}}function Be(e,t){let n=t.levels.map(()=>[]);return e.forEach((r,s)=>n[t.codes[s]].push(r)),n}function Ue(e,t){let{terms:n,rhsVariables:r}=D(e,t);if(n.response<0||r.length===0)throw new Error(F);let s=n.variables[0],o=V(t,[s,...r],{dropUnusedLevels:!0}),c=o.variables.slice(1).map(z),i=o.rows.map((a,l)=>{let u=0,m=1;for(let h of c)u+=h.codes[l]*m,m*=h.levels.length;return u});return{values:E(o.variables[0],s),groups:i}}var ue="incorrect specification for 'formula'";function Ze(e,t){let n=fe(e),r=n?.rhs.split("|");if(n===void 0||n.lhs===""||r.length!==2)throw new Error(ue);let s=M=>{let{terms:d,rhsVariables:p}=D(M,t);if(p.length!==1||d.terms.length!==1)throw new Error(ue);return p[0]},{terms:o}=D(`${n.lhs} ~ 1`,t),c=o.variables[0],i=s(`~${r[0]}`),a=s(`~${r[1]}`),l=V(t,[c,i,a],{dropUnusedLevels:!0}),u=E(l.variables[0],c),m=z(l.variables[1]),h=z(l.variables[2]),w=h.levels.map(()=>m.levels.map(()=>NaN)),N=h.levels.map(()=>m.levels.map(()=>0));if(u.forEach((M,d)=>{let p=h.codes[d],b=m.codes[d];N[p][b]++,w[p][b]=M}),N.some(M=>M.some(d=>d!==1)))throw new Error("not an unreplicated complete block design");return w}function me(e,t){let{terms:n,rhsVariables:r}=D(e,t);if(n.response>=0)throw new Error("'formula' missing or invalid");if(r.length!==2)throw new Error("invalid formula");let s=V(t,r);return{x:E(s.variables[0],r[0]),y:E(s.variables[1],r[1])}}function pe(e){if(e===void 0)return"two.sided";let n=["two.sided","less","greater"].filter(r=>r.startsWith(e));if(e.length===0||n.length!==1)throw new RangeError(`invalid alternative "${e}" (expected "two.sided", "less" or "greater")`);return n[0]}function he(e){if(!(Number.isFinite(e)&&e>=0&&e<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function Ge(e){if(!(Number.isFinite(e)&&e>0&&e<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var Se=["pearson","kendall","spearman"];function Te(e){if(e===void 0)return"pearson";let t=Se.filter(n=>n.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function de(e){if(!(e[0]>0))return[Math.sqrt(e[0]),0];let t=Math.sqrt(e[0]),n=q(e,te(t,t));return ee(t,n[0]/(2*t))}function we(e){let t=ne(e);if(!Number.isFinite(t[0]))return;let n=e.map(o=>q([o,0],t)),r=0;for(let o of n)r=Math.max(r,Math.abs(o[0]));if(r===0)return n;let s=2**-Math.max(-1022,Math.floor(Math.log2(r)));return n.map(o=>[o[0]*s,o[1]*s])}function H(e,t){let n=e.length;if(n<2)return[NaN,0];let r=we(e),s=we(t);if(r===void 0||s===void 0)return[NaN,0];let o=[0,0],c=[0,0],i=[0,0];for(let l=0;l<n;l++)o=A(o,C(r[l],s[l])),c=A(c,C(r[l],r[l])),i=A(i,C(s[l],s[l]));if(c[0]===0||i[0]===0)return[NaN,0];let a=W(o,C(de(c),de(i)));return a[0]>=1?[1,0]:a[0]<=-1?[-1,0]:a}function ge(e,t){let n=C(q([1,0],e),A([1,0],e));return Math.sqrt(t)*e[0]/Math.sqrt(n[0])}function De(e){return Math.abs(e[0])<.5?Math.atanh(e[0]):.5*Math.log(A([1,0],e)[0]/q([1,0],e)[0])}function Ne(e,t,n){return n==="less"?I(e,t,!0,!1):n==="greater"?I(e,t,!1,!1):2*Math.min(I(e,t,!0,!1),I(e,t,!1,!1))}function Re(e,t){return t==="less"?T(e):t==="greater"?T(e,{lowerTail:!1}):2*Math.min(T(e),T(e,{lowerTail:!1}))}function K(e,t){let n=e.length,r=0;for(let u=0;u<n;u++){let m=e[u],h=t[u];for(let w=u+1;w<n;w++){let N=(e[w]>m?1:0)-(e[w]<m?1:0),M=(t[w]>h?1:0)-(t[w]<h?1:0);r+=N*M}}let s=j(e),o=j(t),c=n*(n-1)/2,i=s.reduce((u,m)=>u+m*(m-1)/2,0),a=o.reduce((u,m)=>u+m*(m-1)/2,0),l=n<2||i===c||a===c?NaN:i===0&&a===0?r/c:r/Math.sqrt((c-i)*(c-a));return{s:r,tau:l,ties:s.length>0||o.length>0,tx:s,ty:o}}function be(e,t){let n=e*(e-1)/2;if(t<0)return 0;if(t>=n)return 1;let r=new Float64Array(t+1);r[0]=1;for(let o=2;o<=e;o++){let c=new Float64Array(t+1),i=0;for(let l=0;l<=t;l++)i+=r[l],c[l]=i;let a=new Float64Array(t+1);for(let l=0;l<=t;l++)a[l]=(c[l]-(l>=o?c[l-o]:0))/o;r=a}let s=0;for(let o=t;o>=0;o--)s+=r[o];return Math.min(1,s)}var ve=new Map;function Le(e){let t=ve.get(e);if(t!==void 0)return t;let n=e*(e*e-1)/3,r=1<<e,s=new Array(r);s[0]=new Float64Array(n+1),s[0][0]=1;let o=i=>{let a=0;for(;i;i&=i-1)a++;return a};for(let i=0;i<r;i++){let a=s[i];if(a===void 0)continue;let l=o(i);for(let u=0;u<e;u++){if(i&1<<u)continue;let m=(u-l)**2,h=i|1<<u,w=s[h]??=new Float64Array(n+1);for(let N=0;N+m<=n;N++)a[N]&&(w[N+m]+=a[N])}i!==r-1&&(s[i]=void 0)}let c=s[r-1];return ve.set(e,c),c}var x=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function ye(e,t,n){let r=t;r%2!==0&&(r+=1);let s=1/e,o=(6*(r-1)*s/(e*e-1)-1)*Math.sqrt(1/s-1),c=o*o,a=o*s*(x[0]+s*(x[1]+x[2]*s)+c*(-x[3]+s*(x[4]+x[5]*s)-c*s*(x[6]+x[7]*s-c*(x[8]-x[9]*s+c*s*(x[10]-x[11]*c)))))/Math.exp(c/2),l=n?T(o)-a:a+T(o,{lowerTail:!1});return Math.min(1,Math.max(0,l))}function Me(e,t,n){let r=e*(e*e-1)/3;if(e<=9){let s=Le(e),o=1;for(let i=2;i<=e;i++)o*=i;let c=0;if(n)for(let i=Math.min(t,r);i>=0;i--)c+=s[i];else for(let i=r;i>=Math.max(t,0);i--)c+=s[i];return c/o}return n?t+1>r?1:t+1<=0?0:ye(e,t+1,!0):t<=0?1:t>r?0:ye(e,t,!1)}function _e(e,t,n={}){if(typeof e=="string"){let r=me(e,t);return _e(r.x,r.y,n)}return Ce(e,t,n)}function Ce(e,t,n){if(e.length!==t.length)throw new TypeError("x and y must have the same length");let r=pe(n.alternative),s=Te(n.method),o=n.continuity??!1,[c,i]=oe(Array.from(e),Array.from(t)),a=c.length;if(s==="pearson"){let f=n.confLevel??.95;if(he(f),a<3)throw new Error("not enough finite observations");let y=H(c,i),k=a-2,g=Number.isNaN(y[0])?NaN:ge(y,k),R={method:"Pearson's product-moment correlation",alternative:r,statistic:g,statisticName:"t",parameter:k,parameterName:"df",pValue:Ne(g,k,r),estimate:y[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation"};if(a>3){let B=De(y),L=1/Math.sqrt(a-3),_=S=>Math.tanh(B+S),$;if(r==="less")$=[-1,_(L*G(f))];else if(r==="greater")$=[_(-L*G(f)),1];else{let S=L*G((1+f)/2);$=[_(-S),_(S)]}R.confInt=$,R.confLevel=f}return R}if(a<2)throw new Error("not enough finite observations");if(s==="kendall"){let f=K(c,i),y={method:"Kendall's rank correlation tau",alternative:r,estimate:f.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau"};if(Number.isNaN(f.tau))return{...y,statistic:NaN,statisticName:"T",pValue:NaN};if((n.exact??a<50)&&!f.ties){let v=a*(a-1)/2,P=(f.s+v)/2,U=be(a,P),Z=be(a,v-P),Ee=r==="less"?U:r==="greater"?Z:Math.min(1,2*Math.min(U,Z));return{...y,statistic:P,statisticName:"T",pValue:Ee}}let g=(v,P)=>P.reduce((U,Z)=>U+v(Z),0),R=v=>v*(v-1),B=v=>v*(v-1)*(v-2),L=v=>v*(v-1)*(2*v+5),_=(a*(a-1)*(2*a+5)-g(L,f.tx)-g(L,f.ty))/18+g(B,f.tx)*g(B,f.ty)/(9*a*(a-1)*(a-2))+g(R,f.tx)*g(R,f.ty)/(2*a*(a-1)),S=(o?Math.sign(f.s)*(Math.abs(f.s)-1):f.s)/Math.sqrt(_);return{...y,statistic:S,statisticName:"z",pValue:Re(S,r)}}let l=X(c),u=X(i),m=H(l,u),h=a*a*a-a,w=h*(1-m[0])/6,N={method:"Spearman's rank correlation rho",alternative:r,statistic:w,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho"};if(Number.isNaN(m[0]))return{...N,pValue:NaN};let M=j(c).length>0||j(i).length>0;if((n.exact??a<=1290)&&!M&&a<=1290){let f=Math.round(w),y=Me(a,f,!0),k=Me(a,f,!1),g=r==="greater"?y:r==="less"?k:Math.min(1,2*Math.min(y,k));return{...N,pValue:g}}let p=m;if(o){let f=W([6,0],[h,0]);p=W(A(m,f),A([1,0],f)),Math.abs(p[0])>=1&&(p=[Math.sign(p[0]),0])}let b=ge(p,a-2);return{...N,pValue:Ne(b,a-2,r)}}function Fe(e,t){let n=e.length,r=new Array(n);if(t==="first"||t==="last"||t==="random"){let c=t==="random"?re(n):[],i=Array.from({length:n},(a,l)=>l);return i.sort((a,l)=>{let u=e[a]-e[l];return u!==0?u:t==="first"?a-l:t==="last"?l-a:c[a]-c[l]||a-l}),i.forEach((a,l)=>r[a]=l+1),r}let s=Array.from({length:n},(c,i)=>i).sort((c,i)=>e[c]-e[i]||c-i),o=0;for(;o<n;){let c=o;for(;c+1<n&&e[s[c+1]]===e[s[o]];)c++;let i=t==="average"?(o+c+2)/2:t==="min"?o+1:c+1;for(let a=o;a<=c;a++)r[s[a]]=i;o=c+1}return r}function J(e,t={}){let n=t.tiesMethod??"average";if(!["average","first","last","random","max","min"].includes(n))throw new RangeError(`invalid tiesMethod "${n}"`);let r=t.naLast??"last",s=Array.from(e),o=s.filter(m=>!Number.isNaN(m)),c=Fe(o,n),i=s.length-o.length,a=[],l=0,u=0;for(let m of s)Number.isNaN(m)?(u++,a.push(r==="keep"?NaN:r==="last"?o.length+u:u)):a.push(r==="first"?c[l++]+i:c[l++]);return a}var Oe=["pearson","kendall","spearman"],$e=["all.obs","complete.obs","pairwise.complete.obs","everything","na.or.complete"];function xe(e,t,n,r){if(e===void 0)return n;if(t.includes(e))return e;let s=t.filter(o=>o.startsWith(e));if(e.length===0||s.length!==1)throw new RangeError(`invalid '${r}' argument`);return s[0]}function O(e){return e.length>0&&Array.isArray(e[0])}function ke(e){if(!O(e))return[Array.from(e)];let t=e[0].length;return Array.from({length:t},(n,r)=>e.map(s=>s[r]))}function Q(e,t,n,r){let s=xe(n.method,Oe,"pearson","method"),o=xe(n.use,$e,"everything","use");if(t===void 0&&!O(e))throw new TypeError("supply both 'x' and 'y' or a matrix-like 'x'");let c=ke(e),i=t===void 0?c:ke(t),a=c[0]?.length??0;if(i.some(d=>d.length!==a))throw new RangeError("incompatible dimensions");let l=[...c,...i];if(o==="all.obs"&&l.some(d=>d.some(Number.isNaN)))throw new RangeError("missing observations in cov/cor");if(!r&&o==="pairwise.complete.obs"&&s!=="pearson")throw new RangeError("cannot handle 'pairwise.complete.obs'");let u;if((o==="complete.obs"||o==="na.or.complete")&&(u=Array.from({length:a},(d,p)=>l.every(b=>!Number.isNaN(b[p]))),!u.some(Boolean))){if(o==="complete.obs")throw new RangeError("no complete element pairs");return t===void 0||O(e)||O(t)?c.map(()=>i.map(()=>NaN)):NaN}let m=d=>{let p=u===void 0?d:d.filter((b,f)=>u[f]);return s==="spearman"&&o!=="pairwise.complete.obs"?J(p,{naLast:"keep"}):p},h=c.map(m),w=t===void 0?h:i.map(m),N=(d,p)=>{let b=d,f=p;if(o==="pairwise.complete.obs"){let y=d.map((k,g)=>!Number.isNaN(k)&&!Number.isNaN(p[g]));b=d.filter((k,g)=>y[g]),f=p.filter((k,g)=>y[g]),s==="spearman"&&(b=J(b),f=J(f))}else if(b.some(Number.isNaN)||f.some(Number.isNaN))return NaN;return s==="kendall"?r?K(b,f).tau:2*K(b,f).s:r?H(b,f)[0]:se(b,f)},M=h.map(d=>w.map(p=>N(d,p)));return r&&t===void 0&&o!=="pairwise.complete.obs"&&M.forEach((d,p)=>d[p]=1),t!==void 0&&!O(e)&&!O(t)?M[0][0]:M}function it(e,t,n={}){return t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!1):Q(e,t,n,!1)}function ct(e,t,n={}){return t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!0):Q(e,t,n,!0)}export{Ve as a,je as b,ze as c,Be as d,Ue as e,Ze as f,pe as g,he as h,Ge as i,H as j,_e as k,J as l,it as m,ct as n};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
2
|
function h(f,t,a){let n=Math.ceil(a);if(n===1)return[f];let i=(t-f)/(n-1),o=Array.from({length:n},(s,r)=>f+r*i);return n>0&&(o[n-1]=t),o}function g(f,t){let a=Array.from(f).map(o=>Math.trunc(o)),n=t??Math.max(1,...a.filter(o=>!Number.isNaN(o))),i=new Array(Math.max(0,n)).fill(0);for(let o of a)o>=1&&o<=n&&i[o-1]++;return i}function y(f,t={}){let a=t.useNA??"no",n=Array.from(f),i=new Map,o=0;for(let e of n)Number.isNaN(e)?o++:i.set(e===0?0:e,(i.get(e===0?0:e)??0)+1);let s=Array.from(i.keys()).sort((e,l)=>e-l),r=s.map(e=>i.get(e));return(a==="always"||a==="ifany"&&o>0)&&(s.push(NaN),r.push(o)),{values:s,counts:r}}function b(f){let t=new Set,a=[];for(let n of Array.from(f)){let i=n===0?0:n;t.has(i)||(t.add(i),a.push(n))}return a}function x(f,t,a={}){let n=a.right??!0,i=a.includeLowest??!1,o=Array.from(f),s;if(typeof t=="number"||t.length===1){let r=typeof t=="number"?t:t[0];if(!(r>=2))throw new RangeError("invalid number of intervals");let e=Math.trunc(r+1),l=o.filter(N=>!Number.isNaN(N)),u=Math.min(...l),c=Math.max(...l),m=c-u;m===0?(m=u!==0?Math.abs(u):1,s=h(u-m/1e3,c+m/1e3,e)):(s=h(u,c,e),s[0]=u-m/1e3,s[e-1]=c+m/1e3)}else s=[...t].sort((r,e)=>r-e);if(new Set(s).size<s.length)throw new RangeError("'breaks' are not unique");return d(o,s,n,i)}function d(f,t,a,n){let i=t.length;return f.map(o=>{if(Number.isNaN(o))return NaN;let s=0,r=i;for(;s<r;){let l=s+r>>1;(a?t[l]<o:t[l]<=o)?s=l+1:r=l}let e=s;return n&&(a&&o===t[0]&&(e=1),!a&&o===t[i-1]&&(e=i-1)),e>=1&&e<=i-1?e:NaN})}function A(f,t,a={}){let n=t.length;for(let r=1;r<n;r++)if(!(t[r]>=t[r-1]))throw new RangeError("'vec' must be sorted non-decreasingly and not contain NAs");if(t.some(Number.isNaN))throw new RangeError("'vec' must be sorted non-decreasingly and not contain NAs");let{rightmostClosed:i=!1,allInside:o=!1,leftOpen:s=!1}=a;return Array.from(f).map(r=>{if(Number.isNaN(r))return NaN;let e=0,l=n;for(;e<l;){let c=e+l>>1;(s?t[c]<r:t[c]<=r)?e=c+1:l=c}let u=e;return i&&n>0&&(!s&&u===n&&r===t[n-1]&&(u=n-1),s&&u===0&&r===t[0]&&(u=1)),o&&(u=Math.min(Math.max(u,1),n-1)),u})}export{h as a,g as b,y as c,b as d,x as e,A as f};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{c as T,i as A}from"./chunk-4OKAZJJG.js";import{c as N}from"./chunk-WKEFHOFR.js";function M(i,m){let t=i.length,a=i.map(()=>[]),r;switch(m){case"indicators":i.forEach((l,s)=>i.forEach((o,u)=>a[s].push(s===u?1:0))),r=[...i];break;case"contr.treatment":i.forEach((l,s)=>{for(let o=1;o<t;o++)a[s].push(s===o?1:0)}),r=i.slice(1);break;case"contr.sum":i.forEach((l,s)=>{for(let o=0;o<t-1;o++)a[s].push(s===o?1:s===t-1?-1:0)}),r=Array.from({length:t-1},(l,s)=>String(s+1));break;case"contr.helmert":i.forEach((l,s)=>{for(let o=1;o<t;o++)a[s].push(s<o?-1:s===o?o:0)}),r=Array.from({length:t-1},(l,s)=>String(s+1));break;default:throw new RangeError(`unknown contrast '${String(m)}'`)}return{m:a,names:r}}function R(i,m,t={},a=i.rhs){if(typeof m!="object"||m===null)throw new TypeError("data must be an object of columns");let r=A(i,Object.keys(m),a);t.intercept!==void 0&&(r.intercept=t.intercept);let l=[...r.variables,...(t.extraVariables??[]).filter(e=>!r.variables.includes(e))],s={};t.levels!==void 0&&(s.levels=t.levels),t.weights!==void 0&&(s.weights=t.weights),t.dropUnusedLevels!==void 0&&(s.dropUnusedLevels=t.dropUnusedLevels);let o=N(m,l,s),u=o.variables,E=o.rows.length,g=r.terms.map((e,c)=>c!==r.responseTerm),_=[],$=t.contrastVariables??r.variables;for(let e of Object.keys(t.contrasts??{}))if(!$.includes(e))_.push(`variable '${e}' is absent, its contrast will be ignored`);else if(u[r.variables.indexOf(e)]?.kind==="numeric")throw new TypeError("contrasts apply only to factors");let b=r.terms.map((e,c)=>e.map(n=>r.factors[n][c]));for(let e=0;e<r.terms.length;e++)if(g[e])for(let c of r.terms[e]){let n=u[c];if(n.kind==="factor"&&n.levels.length<2)throw new RangeError("contrasts can be applied only to factors with 2 or more levels")}if(!r.intercept)e:for(let e=0;e<r.terms.length;e++){if(!g[e])continue;let c=r.terms[e];for(let n=0;n<c.length;n++)if(u[c[n]].kind==="factor"){b[e][n]=2;break e}}let w=[],v=[],k=[];r.intercept&&(w.push(new Array(E).fill(1)),v.push("(Intercept)"),k.push(0));let j=(e,c)=>{let n=u[e],f=r.variables[e];if(n.kind==="numeric")return[{name:f,values:n.values}];let h=c===2?"indicators":t.allContrasts??t.contrasts?.[f]??"contr.treatment",{m:p,names:d}=M(n.levels,h);return d.map((y,x)=>({name:f+y,values:n.codes.map(F=>p[F][x])}))};r.terms.forEach((e,c)=>{if(!g[c])return;let n=j(e[0],b[c][0]);for(let f=1;f<e.length;f++){let h=[];for(let p of j(e[f],b[c][f]))for(let d of n)h.push({name:`${d.name}:${p.name}`,values:d.values.map((y,x)=>y*p.values[x])});n=h}for(let f of n)w.push(f.values),v.push(f.name),k.push(c+1)});let S=Array.from({length:E},(e,c)=>w.map(n=>n[c])),O=r.warnings.filter(e=>!e.startsWith("problem with term")),U=[...O,..._,...r.warnings.filter(e=>!O.includes(e))],L={terms:r,frame:o,x:S,colNames:v,assign:k,warnings:U};if(r.response>=0){let e=u[r.response];if(e.kind!=="numeric")throw new TypeError("the response must be numeric");L.y=e.values}return L}function C(i,m,t={}){let a=R(T(i),m,t);return{colNames:a.colNames,assign:a.assign,x:a.x,rows:a.frame.rows,termLabels:a.terms.termLabels,order:a.terms.order,intercept:a.terms.intercept,variables:a.terms.variables,factors:a.terms.terms.length>0?a.terms.factors:[],warnings:a.warnings}}export{R as a,C as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
2
|
-
import{a as m,i as M,j as E}from"./chunk-
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as m,i as M,j as E}from"./chunk-EDH53DXN.js";import{a as P,b as p,c as y,d as h,f as N,g as b,h as w}from"./chunk-OX3SBG5X.js";function X(t){return Math.abs(t-d(t))>1e-9*Math.max(1,Math.abs(t))}function d(t){if(!Number.isFinite(t))return t;let e=Math.round(t);return e-t===.5&&e%2!==0?e-1:e}var v=[.08333333333333333,-.021092796092796094,.007575757575757576,-.004166666666666667,.003968253968253968,-.008333333333333333,.08333333333333333],F=.9955816268920898,L=1569415565/1073741824,R=381566830/1073741824/1073741824,T=9016312093258695e-35,z=[-.002071332116774595,-.04525132144873906,-.28919126444774784,-.6503185377089651,-.3255503118680449,.25479851061131553],C=[-5578984132167551e-22,.0021284987017821146,.054151797245674226,.43593529692665967,1.4606242909763516,2.076711702373047,1];function Z(t){let e=t-L;e-=R,e-=T;let r=m(t-1,z)/m(t-1,C);return e*F+e*r}function j(t){let e=0;if(t<1e17){let r=1/(t*t);e=r*m(r,v)}return Math.log(t)-.5/t-e}function H(t){let e=0;if(Number.isNaN(t)||t===1/0)return t;if(t===-1/0)return NaN;if(t===0)return NaN;if(t<0){let r=t-Math.trunc(t);if(r===0)return NaN;e=-Math.PI/Math.tan(Math.PI*r),t=1-t}if(t<=10&&t===Math.floor(t)){let r=t;for(let n=1;n<r;n++)e+=1/n;return e-E}if(t<1)e-=1/t,t+=1;else if(t<10)for(;t>2;)t-=1,e+=1/t;return t>=1&&t<=2?e+Z(t):e+j(t)}var I=-.5040830082644554,G=7289763902976895e-32,O;function K(t){O??=Array.from({length:100},(o,i)=>U(i+2,I));let e=G,r=-1,n=t-I;for(let o=1;o<100;o++){r*=-n;let i=r*O[o-1];if(e+=i,Math.abs(i)<Number.EPSILON*Math.abs(e))break}return e}var k=[12,-720,30240,-1209600,47900160,-18924375803183792e-7,74724249600,-2950130727918164e-3,11646782814350067e-2,-4597978722407473,0x284e46fd8153bc0,-7166165256175667e3];function Q(t,e){let r=1,n=e,o=1,i=0;for(;e<=1e8&&(i<9||n<=9||n<t);)if(i+=1,n+=1,o=Math.exp(-t*Math.log1p(i/e)),r+=o,Math.abs(o/r)<M)return r;let u=n;r+=o*u/(t-1),r-=.5*o;let f=1,a=0;for(let c=0;c<12;c++){f*=t+a,o/=u;let s=f*o/k[c];if(r+=s,Math.abs(s/r)<M)break;a+=1,f*=t+a,o/=u,a+=1}return r}function U(t,e){let r=Math.pow(e,-t),n=e,o=0,i=0;for(;i<9||n<=9||n<t;)if(i+=1,n+=1,o=Math.pow(n,-t),r+=o,Math.abs(o/r)<M)return r;let u=n;r+=o*u/(t-1),r-=.5*o;let f=1,a=0;for(let c=0;c<12;c++){f*=t+a,o/=u;let s=f*o/k[c];if(r+=s,Math.abs(s/r)<M)break;a+=1,f*=t+a,o/=u,a+=1}return r}function S(t,e){if(e===1/0)return t%2===0?-0:0;let r=1;for(let o=1;o<=t;o++)r*=o/e;let n=r*(Q(t+1,e)/e);return t%2===0?-n:n}var g=[];function V(t){if(g[t]!==void 0)return g[t];let e=[0,1];for(let o=0;o<t;o++){let i=e.slice(1).map((f,a)=>f*(a+1)),u=new Array(i.length+2).fill(0);i.forEach((f,a)=>{u[a]=u[a]-f,u[a+2]=u[a+2]-f}),e=u}let r=(t+1)%2,n=[];for(let o=r;o<e.length;o+=2)n.push(e[o]);return g[t]=n,n}function Y(t,e){let r=V(t),n=e*e,o=r[r.length-1];for(let i=r.length-2;i>=0;i--)o=o*n+r[i];return(t+1)%2===1?o*e:o}function B(t){let e=t-Math.round(t);return Math.sin(Math.PI*(.5-Math.abs(e)))/Math.sin(Math.PI*e)}function A(t,e,r){if(Number.isNaN(e))return NaN;if(e===-1/0)return r&&t%2===1?1/0:NaN;if(e<=0&&e===Math.floor(e))return t%2===1?1/0:NaN;if(e>0)return S(t,e);let n=S(t,1-e);return(t%2===0?n:-n)-Math.pow(Math.PI,t+1)*Y(t,B(e))}function J(t){return Math.abs(t-I)<.3?K(t):H(t)}function et(t,e){return A(1,t,e?.rCompatible??!0)}function rt(t,e=0,r){let n=d(e);return Number.isNaN(n)||n<0||n>100?NaN:n===0?J(t):A(n,t,r?.rCompatible??!0)}var D=[.6931471805599453,23190468138462996e-33];function it(t){let e=t[0];if(!P())return[Math.exp(e),0];if(Number.isNaN(e))return[NaN,0];if(e>709.8)return[1/0,0];if(e<-708)return[Math.exp(e)*(1+t[1]),0];let r=Math.round(e/D[0]),n=N(t,w(D,r)),o=1024;n=[n[0]/o,n[1]/o];let i=n,u=n;for(let l=2;l<20&&(i=b(i,n),i=[i[0]/l,i[1]/l],u=h(u,i),!(Math.abs(i[0])<1e-36));l++);for(let l=0;l<10;l++)u=b(u,h(u,[2,0]));let f=h(u,[1,0]),a=Math.trunc(r/2),c=2**a,s=2**(r-a);return[f[0]*c*s,f[1]*c*s]}function ut(t,e,r){let n=t-e;if(!Number.isFinite(n))return[n/r,0];let o=e===0?[t,0]:p(t,-e);if(r===1)return o;let i=o[0]/r;if(!Number.isFinite(i)||i===0)return[i,0];let u=N(o,_(r,i)),f=(u[0]+u[1])/r;return p(i,f)}function _(t,e){let r=t*e;return!Number.isFinite(r)||Math.abs(t)>1e300||Math.abs(e)>1e300?[r,0]:y(t,e)}function W(t){return t[0]>708?Math.exp(700-t[0])*(1-t[1])*Math.exp(-700):Math.exp(-t[0])*(1-t[1])}function at(t){return t>-Math.LN2?Math.log(-Math.expm1(t)):Math.log1p(-Math.exp(t))}function ft(t){return t[0]>Math.LN2?Math.log1p(-W(t)):Math.log(-Math.expm1(-(t[0]+t[1])))}function ct(t,e,r){let n=_(e,r);if(!Number.isFinite(n[0])||!Number.isFinite(t))return t+n[0];let o=h(n,[t,0]);return o[0]+o[1]}export{X as a,d as b,J as c,et as d,rt as e,it as f,ut as g,_ as h,W as i,at as j,ft as k,ct as l};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
function M(c,r){return{nrow:c,ncol:r,data:new Float64Array(c*r)}}function E(c){return c.length>0&&typeof c[0]!="number"}function v(c){let r=c.length,o=r===0?0:c[0].length,t=M(r,o);for(let a=0;a<r;a++){let e=c[a];if(e.length!==o)throw new TypeError("all rows of the matrix must have the same length");for(let n=0;n<o;n++)t.data[a+n*r]=e[n]}return t}function A(c){if(E(c))return v(c);let r=c;return{nrow:r.length,ncol:1,data:Float64Array.from(r)}}function d(c){let r=[];for(let o=0;o<c.nrow;o++){let t=new Array(c.ncol);for(let a=0;a<c.ncol;a++)t[a]=c.data[o+a*c.nrow];r.push(t)}return r}function B(c){let r=M(c.ncol,c.nrow);for(let o=0;o<c.ncol;o++)for(let t=0;t<c.nrow;t++)r.data[o+t*c.ncol]=c.data[t+o*c.nrow];return r}function R(c,r="the matrix"){if(c.nrow!==c.ncol)throw new TypeError(`${r} must be square (got ${c.nrow} x ${c.ncol})`)}function Q(c,r={}){let o=v(c);if(r.lapack){let{tau:n,pivot:l}=S(o),u=Array.from({length:o.ncol},(h,f)=>n[f]??0);return{qr:d(o),rank:Math.min(o.nrow,o.ncol),qraux:u,pivot:l.map(h=>h-1),useLapack:!0}}for(let n of o.data)if(!Number.isFinite(n))throw new RangeError("the matrix contains NaN or infinite values");let{qraux:t,pivot:a,rank:e}=O(o,r.tol??1e-7);return{qr:d(o),rank:e,qraux:Array.from(t),pivot:a.map(n=>n-1),useLapack:!1}}function x(c,r,o){let t=0;for(let e=0;e<o;e++)t=Math.max(t,Math.abs(c[r+e]));if(t===0||!Number.isFinite(t))return t;let a=0;for(let e=0;e<o;e++){let n=c[r+e]/t;a+=n*n}return t*Math.sqrt(a)}function O(c,r){let o=c.nrow,t=c.ncol,a=c.data,e=new Float64Array(t),n=new Float64Array(t),l=new Float64Array(t),u=Array.from({length:t},(i,p)=>p+1);for(let i=0;i<t;i++)e[i]=x(a,i*o,o),n[i]=e[i],l[i]=e[i]===0?1:e[i];let h=new Float64Array(o),f=Math.min(o,t),s=t;for(let i=0;i<f;i++){for(;i<s&&e[i]<l[i]*r;){h.set(a.subarray(i*o,(i+1)*o));let[w,q,N,g]=[e[i],n[i],l[i],u[i]];a.copyWithin(i*o,(i+1)*o,t*o),a.set(h,(t-1)*o),e.copyWithin(i,i+1),n.copyWithin(i,i+1),l.copyWithin(i,i+1),u.copyWithin(i,i+1),e[t-1]=w,n[t-1]=q,l[t-1]=N,u[t-1]=g,s--}if(i===o-1)break;let p=i*o,m=x(a,p+i,o-i);if(m!==0){a[p+i]!==0&&(m=Math.sign(a[p+i])*Math.abs(m));for(let w=i;w<o;w++)a[p+w]/=m;a[p+i]=1+a[p+i];for(let w=i+1;w<t;w++){let q=w*o,N=0;for(let k=i;k<o;k++)N-=a[p+k]*a[q+k];N/=a[p+i];for(let k=i;k<o;k++)a[q+k]+=N*a[p+k];if(e[w]===0)continue;let g=1-(Math.abs(a[q+i])/e[w])**2;g=Math.max(g,0);let I=g;g=1+.05*g*(e[w]/n[w])**2,g!==1?e[w]*=Math.sqrt(I):(e[w]=x(a,q+i+1,o-i-1),n[w]=e[w])}e[i]=a[p+i],a[p+i]=-m}}return{qraux:e,pivot:u,rank:Math.min(s,o)}}function S(c){let r=c.nrow,o=c.ncol,t=c.data,a=Math.min(r,o),e=new Float64Array(a),n=Array.from({length:o},(f,s)=>s+1),l=new Float64Array(o),u=new Float64Array(o);for(let f=0;f<o;f++)l[f]=x(t,f*r,r),u[f]=l[f];let h=Math.sqrt(2**-53);for(let f=0;f<a;f++){let s=f;for(let p=f+1;p<o;p++)Math.abs(l[p])>Math.abs(l[s])&&(s=p);if(s!==f){for(let p=0;p<r;p++){let m=t[p+s*r];t[p+s*r]=t[p+f*r],t[p+f*r]=m}[n[s],n[f]]=[n[f],n[s]],l[s]=l[f],u[s]=u[f]}let i=f*r;if(e[f]=T(t,i+f,r-f),f<o-1){let p=t[i+f];t[i+f]=1,z(t,i+f,r-f,e[f],c,f,f+1,o-f-1),t[i+f]=p}for(let p=f+1;p<o;p++){if(l[p]===0)continue;let m=1-(Math.abs(t[f+p*r])/l[p])**2;m=Math.max(m,0),m*(l[p]/u[p])**2<=h?f<r-1?(l[p]=x(t,p*r+f+1,r-f-1),u[p]=l[p]):(l[p]=0,u[p]=0):l[p]*=Math.sqrt(m)}}return{tau:e,pivot:n}}function T(c,r,o){if(o<=1)return 0;let t=x(c,r+1,o-1);if(t===0)return 0;let a=c[r],e=-Math.sign(a||1)*Math.hypot(a,t),n=2**-1022/2**-53,l=0;if(Math.abs(e)<n){let f=1/n;do{l++;for(let s=1;s<o;s++)c[r+s]*=f;e*=f,a*=f}while(Math.abs(e)<n&&l<20);t=x(c,r+1,o-1),e=-Math.sign(a||1)*Math.hypot(a,t)}let u=(e-a)/e,h=1/(a-e);for(let f=1;f<o;f++)c[r+f]*=h;for(let f=0;f<l;f++)e*=n;return c[r]=e,u}function z(c,r,o,t,a,e,n,l){if(t===0)return;let u=a.nrow,h=a.data;for(let f=n;f<n+l;f++){let s=e+f*u,i=0;for(let p=0;p<o;p++)i+=h[s+p]*c[r+p];i*=t;for(let p=0;p<o;p++)h[s+p]-=c[r+p]*i}}function j(c){return{a:v(c.qr),qraux:c.qraux,rank:c.rank,pivot:c.pivot.map(r=>r+1),lapack:c.useLapack}}function $(c,r){let o=A(r);if(o.nrow!==c.a.nrow)throw new TypeError(`qr and y must have the same number of rows (${c.a.nrow} and ${o.nrow})`);return o}function b(c,r){return E(c)?d(r):Array.from(r.data)}function y(c,r,o,t=c.rank){let{a,qraux:e}=c,n=a.nrow;if(c.lapack){let h=Math.min(n,a.ncol),f=o?F(0,h):F(0,h).reverse();for(let s of f){let i=a.data[s+s*n];a.data[s+s*n]=1,z(a.data,s+s*n,n-s,e[s],r,s,0,r.ncol),a.data[s+s*n]=i}return}let l=Math.min(t,n-1),u=o?F(0,l):F(0,l).reverse();for(let h of u){if(e[h]===0)continue;let f=h*n,s=a.data[f+h];a.data[f+h]=e[h];for(let i=0;i<r.ncol;i++){let p=i*n,m=0;for(let w=h;w<n;w++)m-=a.data[f+w]*r.data[p+w];m/=a.data[f+h];for(let w=h;w<n;w++)r.data[p+w]+=m*a.data[f+w]}a.data[f+h]=s}}function F(c,r){return Array.from({length:Math.max(0,r-c)},(o,t)=>c+t)}function H(c,r){let o=j(c),t=$(o,r);return y(o,t,!0),b(r,t)}function J(c,r){let o=j(c),t=$(o,r);return y(o,t,!1),b(r,t)}function W(c,r){let o=j(c),t=$(o,r),a=o.a.ncol,e=o.a.nrow,n=o.lapack?Math.min(e,a):o.rank;y(o,t,!0);for(let u=0;u<t.ncol;u++){let h=u*e;for(let f=n-1;f>=0;f--){let s=o.a.data[f+f*e];if(s===0)throw new Error("exact singularity in qrCoef");t.data[h+f]/=s;let i=-t.data[h+f];for(let p=0;p<f;p++)t.data[h+p]+=i*o.a.data[p+f*e]}}let l=M(a,t.ncol);l.data.fill(NaN);for(let u=0;u<t.ncol;u++)for(let h=0;h<n;h++)l.data[o.pivot[h]-1+u*a]=t.data[h+u*e];return b(r,l)}function L(c,r,o,t){let a=j(c);if(a.lapack)throw new TypeError("not supported for a QR decomposition computed with lapack: true");let e=t??a.rank;if(!Number.isInteger(e)||e<0||e>a.rank)throw new RangeError(`invalid k (got ${e})`);let n=$(a,r),l=a.a.nrow;if(e===0)return b(r,n);if(l===1)return o||n.data.fill(0),b(r,n);y(a,n,!0,e);for(let u=0;u<n.ncol;u++)o?n.data.fill(0,u*l+e,(u+1)*l):n.data.fill(0,u*l,u*l+e);return y(a,n,!1,e),b(r,n)}function K(c,r){return L(c,r,!1)}function U(c,r,o={}){return L(c,r,!0,o.k)}function V(c,r={}){let o=j(c),t=o.a.nrow,a=r.complete?t:Math.min(t,o.a.ncol),e=r.dvec??new Array(a).fill(1);if(e.length!==a)throw new RangeError(`dvec must have length ${a}`);let n=M(t,a);for(let l=0;l<a;l++)n.data[l+l*t]=e[l];return y(o,n,!1),d(n)}function Y(c,r={}){let o=v(c.qr),t=r.complete?o.nrow:Math.min(o.nrow,o.ncol),a=M(t,o.ncol);for(let e=0;e<o.ncol;e++)for(let n=0;n<=Math.min(e,t-1);n++)a.data[n+e*t]=o.data[n+e*o.nrow];return d(a)}function Z(c,r={}){let o=j(c),t=o.a.nrow,a=o.a.ncol,e=r.complete??!1,n=r.ncol??(e?t:Math.min(t,a));if(!Number.isInteger(n)||n<0)throw new RangeError(`invalid ncol (got ${n})`);if(o.pivot.some((s,i)=>s!==i+1)&&n<a)throw new RangeError("ncol must be at least the number of columns because the decomposition is pivoted");let u=M(t,n);for(let s=0;s<n;s++)if(s<a)for(let i=0;i<=Math.min(s,t-1);i++)u.data[i+s*t]=o.a.data[i+s*t];else s<t&&(u.data[s+s*t]=1);y(o,u,!1);let h=Math.min(n,a),f=M(t,n);f.data.set(u.data);for(let s=0;s<h;s++){let i=o.pivot[s]-1;i<h&&f.data.set(u.data.subarray(s*t,(s+1)*t),i*t)}return d(f)}function tt(c,r,o={}){let t=Array.isArray(c)?Q(c,{tol:o.tol??1e-7}):c,a=t.qr.length,e=a===0?0:t.qr[0].length;if(t.rank!==Math.min(a,e))throw new Error("singular matrix in qrSolve");if(r===void 0&&a!==e)throw new TypeError("only square matrices can be inverted");let n=r??Array.from({length:a},(h,f)=>Array.from({length:a},(s,i)=>f===i?1:0)),l=W(t,n),u=h=>Number.isNaN(h)?0:h;return E(n)?l.map(h=>h.map(u)):l.map(u)}function nt(c,r={}){let o=v(c);if(R(o),o.nrow===0)throw new RangeError("the matrix has zero dimension");if(r.pivot){let{pivot:a,rank:e}=P(o,r.tol??-1);return _(o),{r:d(o),pivot:a.map(n=>n-1),rank:e}}let t=C(o);if(t>0)throw new Error(`the matrix is not positive definite: the leading minor of order ${t} is not positive`);return _(o),d(o)}function _(c){let r=c.nrow;for(let o=0;o<r;o++)for(let t=o+1;t<r;t++)c.data[t+o*r]=0}function C(c){let r=c.nrow,o=c.data;for(let t=0;t<r;t++){let a=t*r,e=o[t+a];for(let n=0;n<t;n++)e-=o[n+a]*o[n+a];if(e<=0)return o[t+a]=e,t+1;e=Math.sqrt(e),o[t+a]=e;for(let n=t+1;n<r;n++){let l=n*r,u=o[t+l];for(let h=0;h<t;h++)u-=o[h+a]*o[h+l];o[t+l]=u/e}}return 0}function P(c,r){let o=c.nrow,t=c.data,a=Array.from({length:o},(s,i)=>i+1),e=(s,i)=>s+i*o,n=(s,i)=>{let p=t[s];t[s]=t[i],t[i]=p},l=0;for(let s=1;s<o;s++)t[e(s,s)]>t[e(l,l)]&&(l=s);let u=t[e(l,l)];if(u<=0||Number.isNaN(u))return{pivot:a,rank:0};let h=r<0?o*Number.EPSILON*u:r,f=new Float64Array(2*o);for(let s=0;s<o;s++){for(let i=s;i<o;i++)s>0&&(f[i]+=t[e(s-1,i)]**2),f[o+i]=t[e(i,i)]-f[i];if(s>0){l=s;for(let i=s+1;i<o;i++)f[o+i]>f[o+l]&&(l=i);if(u=f[o+l],u<=h||Number.isNaN(u))return t[e(s,s)]=u,{pivot:a,rank:s}}if(s!==l){t[e(l,l)]=t[e(s,s)];for(let i=0;i<s;i++)n(e(i,s),e(i,l));for(let i=l+1;i<o;i++)n(e(s,i),e(l,i));for(let i=s+1;i<l;i++)n(e(s,i),e(i,l));[f[s],f[l]]=[f[l],f[s]],[a[s],a[l]]=[a[l],a[s]]}u=Math.sqrt(u),t[e(s,s)]=u;for(let i=s+1;i<o;i++){let p=t[e(s,i)];for(let m=0;m<s;m++)p-=t[e(m,s)]*t[e(m,i)];t[e(s,i)]=p/u}}return{pivot:a,rank:o}}function et(c,r={}){let o=A(c),t=r.size??o.ncol;if(!Number.isInteger(t)||t<1)throw new RangeError(`size must be a positive integer (got ${t})`);if(t>o.ncol)throw new RangeError(`size cannot exceed the number of columns (${o.ncol})`);if(t>o.nrow)throw new RangeError(`size cannot exceed the number of rows (${o.nrow})`);let a=M(t,t);for(let e=0;e<t;e++)for(let n=0;n<=e;n++)a.data[n+e*t]=o.data[n+e*o.nrow];X(a);for(let e=0;e<t;e++)for(let n=e+1;n<t;n++)a.data[n+e*t]=a.data[e+n*t];return d(a)}function X(c){let r=c.nrow,o=c.data;for(let t=0;t<r;t++)if(o[t+t*r]===0)throw new Error(`element (${t+1}, ${t+1}) is zero, so the inverse cannot be computed`);for(let t=0;t<r;t++){let a=t*r;o[t+a]=1/o[t+a];let e=-o[t+a];for(let n=0;n<t;n++){let l=o[n+a];if(l!==0){for(let u=0;u<n;u++)o[u+a]+=l*o[u+n*r];o[n+a]=l*o[n+n*r]}}for(let n=0;n<t;n++)o[n+a]*=e}for(let t=0;t<r;t++){let a=o[t+t*r];if(t<r-1){let e=0;for(let n=t;n<r;n++)e+=o[t+n*r]*o[t+n*r];o[t+t*r]=e;for(let n=0;n<t;n++)o[n+t*r]*=a;for(let n=t+1;n<r;n++){let l=o[t+n*r];if(l!==0)for(let u=0;u<t;u++)o[u+t*r]+=l*o[u+n*r]}}else for(let e=0;e<=t;e++)o[e+t*r]*=a}}export{M as a,E as b,v as c,A as d,d as e,B as f,R as g,Q as h,T as i,z as j,H as k,J as l,W as m,K as n,U as o,V as p,Y as q,Z as r,tt as s,nt as t,C as u,et as v,X as w};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
function g(o,u){let r=o[Symbol.iterator](),s=u[Symbol.iterator]();for(;;){let i=r.next(),t=s.next();if(i.done)return t.done?0:-1;if(t.done)return 1;let f=i.value.codePointAt(0)-t.value.codePointAt(0);if(f!==0)return f}}function h(o,u,r){if(u instanceof Float64Array&&r===void 0){let e=Array.from(u);return{v:{kind:"numeric",values:e},missing:e.map(a=>Number.isNaN(a))}}let s=Array.from(u),i=new Set(s.filter(e=>e!==null).map(e=>typeof e));if(i.size>1)throw new TypeError(`column '${o}' mixes ${[...i].join(" and ")} values`);let t=[...i][0]??"number";if(t!=="number"&&t!=="string"&&t!=="boolean")throw new TypeError(`column '${o}' has values of an unsupported type`);if(t==="number"&&r===void 0){let e=s.map(a=>a===null?NaN:a);return{v:{kind:"numeric",values:e},missing:e.map(a=>Number.isNaN(a))}}let f=e=>e===null||typeof e=="number"&&Number.isNaN(e)?null:typeof e=="boolean"?e?"TRUE":"FALSE":String(e),c=s.map(f),l;r!==void 0?l=Array.from(r,String):t==="boolean"?l=["FALSE","TRUE"]:l=[...new Set(c.filter(e=>e!==null))].sort(g);let m=new Map(l.map((e,a)=>[e,a])),d=c.map(e=>e===null?-1:m.get(e)??-1),n=r!==void 0?"given":t==="boolean"?"logical":"values";return{v:{kind:"factor",levels:l,codes:d},missing:d.map(e=>e<0),source:n}}function w(o,u){let r=o.map(()=>!1);for(let t of u)r[t]=!0;let s=new Map;return{levels:o.filter((t,f)=>(r[f]&&s.set(f,s.size),r[f])),codes:u.map(t=>s.get(t))}}function b(o){return w(o.levels,o.codes)}function y(o,u,r={}){if(typeof o!="object"||o===null)throw new TypeError("data must be an object of columns");let s=u.map(n=>{let e=Object.prototype.hasOwnProperty.call(o,n)?o[n]:void 0;if(e===void 0)throw new Error(`object '${n}' not found`);if(!Array.isArray(e)&&!(e instanceof Float64Array))throw new TypeError(`column '${n}' must be an array`);return e}),i;if(typeof r.weights=="string"){let n=Object.prototype.hasOwnProperty.call(o,r.weights)?o[r.weights]:void 0;if(n===void 0)throw new Error(`object '${r.weights}' not found`);i=n}else r.weights!==void 0&&(i=Array.from(r.weights));let t=s.length>0?s[0].length:i?.length??Object.values(o)[0]?.length??0;if(u.forEach((n,e)=>{if(s[e].length!==t)throw new RangeError(`variable lengths differ (found for '${n}')`)}),i!==void 0&&i.length!==t)throw new RangeError("variable lengths differ (found for '(weights)')");let f=u.map((n,e)=>h(n,s[e],r.levels?.[n])),c;i!==void 0&&(c=Array.from(i,n=>{if(n===null)return NaN;if(typeof n!="number")throw new TypeError("the weights must be numeric");return n}));let l=[];for(let n=0;n<t;n++)f.some(e=>e.missing[n])||c!==void 0&&Number.isNaN(c[n])||l.push(n);let m=f.map(({v:n,source:e})=>{if(n.kind==="numeric")return{kind:"numeric",values:l.map(p=>n.values[p])};let a=l.map(p=>n.codes[p]);return e==="values"||e==="given"&&r.dropUnusedLevels?{kind:"factor",...w(n.levels,a)}:{kind:"factor",levels:n.levels,codes:a}}),d={rows:l,variables:m};if(c!==void 0&&(d.weights=l.map(n=>c[n]),d.weights.some(n=>n<0)))throw new RangeError("missing or negative weights not allowed");return d}export{g as a,b,y as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
2
|
-
import{a as D}from"./chunk-M6GDXKKS.js";import{a as k,b,c as F}from"./chunk-KK4GE65D.js";import{d as X,g as I}from"./chunk-ETOEZTGL.js";function j(n){let o=Object.values(n),t=o[0]?.length??0;if(o.some(r=>r.length!==t))throw new RangeError("the columns of a data frame must have the same length");return t}var Y=n=>n==null||typeof n=="number"&&Number.isNaN(n),M=(n,o)=>n[o];function _(n,o){if(n.length>0&&n.every(t=>t instanceof Float64Array)){let t=new Float64Array(o.length);return o.forEach((r,e)=>t[e]=r===null?NaN:r[0][r[1]]),t}return o.map(t=>t===null?null:M(t[0],t[1]))}function ft(n,o){return n instanceof Float64Array?Float64Array.from(o,t=>n[t]):o.map(t=>M(n,t))}function O(n,o,t){if(Object.hasOwn(n,o))throw new Error(`duplicate column name '${o}'`);n[o]=t}function ut(n){if(Number.isNaN(n))return"NA";if(!Number.isFinite(n))return n>0?"Inf":"-Inf";if(n===0)return"0";let[o,t]=Number(n.toPrecision(15)).toExponential().split("e"),r=o.startsWith("-"),e=o.replace("-","").replace(".",""),s=Number(t),c=e.length,u=String(Math.abs(s)).padStart(2,"0"),f=c+(c>1?1:0)+2+u.length,a=s>=0?Math.max(s+1,c)+(c>s+1?1:0):2-s-1+c,l=r?"-":"";return a>f?`${l}${e[0]}${c>1?`.${e.slice(1)}`:""}e${s<0?"-":"+"}${u}`:s<0?`${l}0.${"0".repeat(-s-1)}${e}`:c<=s+1?`${l}${e}${"0".repeat(s+1-c)}`:`${l}${e.slice(0,s+1)}.${e.slice(s+1)}`}function K(n){return Y(n)?"NA":typeof n=="number"?ut(n):typeof n=="boolean"?n?"TRUE":"FALSE":n}var it=Symbol("NA"),U=n=>typeof n=="number"?0:typeof n=="string"?1:2;function at(n,o){let t=Y(n),r=Y(o);if(t||r)return t===r?0:t?1:-1;let e=n,s=o;return typeof e!=typeof s?U(e)-U(s):typeof e=="string"?D(e,s):Number(e)-Number(s)}function lt(n){let o=n.length,t=[...n],r=n.map((s,c)=>c),e=1;for(;e<=Math.trunc(o/9);)e=3*e+1;for(;e>0;e=Math.trunc(e/3))for(let s=e;s<o;s++){let c=t[s],u=r[s],f=s;for(;f>=e&&t[f-e]>c;)t[f]=t[f-e],r[f]=r[f-e],f-=e;t[f]=c,r[f]=u}return r}function B(n){let o=[],t=new Map;for(let r of lt(n)){let e=n[r];if(e===0)o.push(r);else{let s=t.get(e);s===void 0?t.set(e,[r]):s.push(r)}}return{alone:o,groups:t}}var T=n=>typeof n=="string"?[n]:[...n];function H(n,o){return o.map(t=>{if(!Object.hasOwn(n,t))throw new Error("'by' must specify a uniquely valid column");return n[t]})}function pt(n,o,t={}){let r=Object.keys(n),e=Object.keys(o),s=j(n),c=j(o),u=t.by===void 0?r.filter(i=>e.includes(i)):T(t.by),f=t.byX===void 0?u:T(t.byX),a=t.byY===void 0?u:T(t.byY),l=H(n,f),w=H(o,a);if(f.length!==a.length)throw new Error("'by.x' and 'by.y' specify different numbers of columns");let R=t.allX??t.all??!1,v=t.allY??t.all??!1,tt=t.sort??!0,[nt,et]=t.suffixes??[".x",".y"],L=r.filter(i=>!f.includes(i)),V=e.filter(i=>!a.includes(i)),rt=i=>V.includes(i)?i+nt:i,ot=i=>L.includes(i)||f.includes(i)?i+et:i,x=[];if(f.length===0)for(let i=0;i<c;i++)for(let m=0;m<s;m++)x.push([m,i]);else{let i=f.length===1?(p,y)=>{let E=M(p[0],y);return Y(E)?it:E}:(p,y)=>p.map(E=>K(M(E,y))).join("\r"),m=Array.from({length:s},(p,y)=>i(l,y)),h=Array.from({length:c},(p,y)=>i(w,y)),d=new Set(h),g=new Map,A=0;for(let p of m)d.has(p)&&(A++,g.has(p)||g.set(p,A));let z=B(m.map(p=>g.get(p)??0)),G=B(h.map(p=>g.get(p)??0));for(let[p,y]of z.groups){let E=G.groups.get(p)??[];for(let st of y)for(let ct of E)x.push([st,ct])}if(R)for(let p of z.alone)x.push([p,-1]);if(v)for(let p of G.alone)x.push([-1,p])}let S=x.map((i,m)=>m);if(tt&&f.length>0){let i=(m,h)=>{let[d,g]=x[m];return d>=0?M(l[h],d):M(w[h],g)};if(f.length>1&&!R&&!v){let m=x.map((h,d)=>f.map((g,A)=>K(i(d,A))).join("\r"));S.sort((h,d)=>D(m[h],m[d]))}else S.sort((m,h)=>{for(let d=0;d<f.length;d++){let g=at(i(m,d),i(h,d));if(g!==0)return g}return 0})}let q=S.map(i=>x[i]),$={};f.forEach((i,m)=>{let h=l[m],d=w[m];O($,i,_([h,d],q.map(([g,A])=>g>=0?[h,g]:[d,A])))});for(let i of L){let m=n[i];O($,rt(i),_([m],q.map(([h])=>h>=0?[m,h]:null)))}for(let i of V){let m=o[i];O($,ot(i),_([m],q.map(([,h])=>h>=0?[m,h]:null)))}return $}function dt(n,o,t={}){let r=Object.keys(n),e=j(n);if(typeof o!="function"&&o.length!==e)throw new RangeError(`'keep' has ${o.length} values for ${e} rows`);let s=a=>Object.fromEntries(r.map(l=>[l,M(n[l],a)])),c=[];for(let a=0;a<e;a++)(typeof o=="function"?o(s(a)):o[a])===!0&&c.push(a);let u=t.select??r,f={};for(let a of u){if(!Object.hasOwn(n,a))throw new Error("undefined columns selected");O(f,a,ft(n[a],c))}return f}function gt(n){if(n.length===0)return{};let o=Object.keys(n[0]);for(let r of n)if(j(r),Object.keys(r).length!==o.length||!o.every(s=>Object.hasOwn(r,s)))throw new Error("names do not match previous names");let t={};for(let r of o){let e=n.map(c=>c[r]),s=e.flatMap(c=>Array.from({length:c.length},(u,f)=>[c,f]));t[r]=_(e,s)}return t}function Nt(n){let o={},t=n.map(j),r=t.find(e=>e!==t[0]);if(r!==void 0)throw new RangeError(`arguments imply differing number of rows: ${t[0]}, ${r}`);for(let e of n)for(let[s,c]of Object.entries(e))O(o,s,c instanceof Float64Array?Float64Array.from(c):[...c]);return o}function yt(n,o={}){let t=o.columns;if(t===void 0){let e=new Set;for(let s of n)for(let c of Object.keys(s))e.add(c);t=[...e]}let r={};for(let e of t){let s=new Set,c=n.map((u,f)=>{let a=Object.hasOwn(u,e)?u[e]:void 0;if(a==null)return null;if(typeof a!="number"&&typeof a!="string"&&typeof a!="boolean")throw new TypeError(`row ${f}, column '${e}': values must be numbers, strings, booleans or null`);return s.add(typeof a),a});if(s.size>1)throw new TypeError(`column '${e}' mixes ${[...s].join(" and ")} values`);O(r,e,c)}return r}function bt(n){let o=Object.keys(n),t=j(n);return Array.from({length:t},(r,e)=>Object.fromEntries(o.map(s=>[s,M(n[s],e)])))}function N(n,o){let t=Array.from(n);return o?t.filter(r=>!Number.isNaN(r)):t.some(Number.isNaN)?void 0:t}function C(n){if(!n.every(Number.isFinite))return n.reduce((t,r)=>t+r,0);let o=[0,0];for(let t of n)o=X(o,[t,0]);return o[0]+o[1]}function vt(n,o={}){let t=N(n,o.naRm);return t===void 0?NaN:C(t)}function At(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;if(!t.every(Number.isFinite)||t.includes(0))return t.reduce((s,c)=>s*c,1);let r=[1,0],e=0;for(let s of t){r=I(r,[s,0]);let c=Math.floor(Math.log2(Math.abs(r[0])));if(c>500||c<-500){let u=2**-c;r=[r[0]*u,r[1]*u],e+=c}}return P(r,e)}function Et(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;let r=t.length;if(r===0)return NaN;let e=o.trim??0;if(Number.isNaN(e))throw new RangeError("'trim' must be numeric of length one");if(e>0&&r>0){if(e>=.5)return W(t);e=Math.max(e,0);let s=Math.floor(r*e),c=[...t].sort((u,f)=>u-f);return b(c.slice(s,r-s))}return b(t)}function Ot(n,o,t={}){let r=Array.from(n),e=Array.from(o);if(r.length!==e.length)throw new RangeError("'x' and 'w' must have the same length");if(t.naRm){let c=r.map(u=>!Number.isNaN(u));r=r.filter((u,f)=>c[f]),e=e.filter((u,f)=>c[f])}let s=[];for(let c=0;c<r.length;c++)e[c]!==0&&s.push(r[c]*e[c]);return C(s)/C(e)}function mt(n,o={}){let t=N(n,o.naRm);return t===void 0?NaN:F(t)}function jt(n,o={}){return Math.sqrt(mt(n,o))}function W(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;let r=t.length;if(r===0)return NaN;let e=[...t].sort((c,u)=>c-u),s=Math.floor(r/2);return r%2===1?e[s]:k([e[s-1],e[s]])[0]}function Rt(n,o={}){let t=N(n,o.naRm);if(t===void 0)return[NaN,NaN];let r=1/0,e=-1/0;for(let s of t)s<r&&(r=s),s>e&&(e=s);return[r,e]}function $t(n){let o=[],t=[0,0],r=0,e=!0;for(let s of Array.from(n))r+=s,e&&Number.isFinite(s)?(t=X(t,[s,0]),o.push(t[0]+t[1])):(e=!1,o.push(Number.isNaN(s)||Number.isNaN(r)?NaN:r));return o}function kt(n){let o=[],t=[1,0],r=0,e;for(let s of Array.from(n)){if(e===void 0&&(!Number.isFinite(s)||s===0)&&(e=P(t,r)),e!==void 0){e*=s,o.push(e);continue}t=I(t,[s,0]);let c=Math.floor(Math.log2(Math.abs(t[0])));(c>500||c<-500)&&(t=[t[0]*2**-c,t[1]*2**-c],r+=c),o.push(P(t,r))}return o}function P(n,o){let t=n[0]+n[1];for(;o>0&&Number.isFinite(t);){let r=Math.min(o,1e3);t*=2**r,o-=r}for(;o<0&&t!==0;){let r=Math.max(o,-1e3);t*=2**r,o-=r}return t}function J(n,o){let t=[],r=NaN,e=!1;for(let s of Array.from(n)){if(e||Number.isNaN(s)){e=!0,t.push(NaN);continue}(t.length===0||o(s,r))&&(r=s),t.push(r)}return t}function Ft(n){return J(n,(o,t)=>o>t)}function _t(n){return J(n,(o,t)=>o<t)}function Yt(n,o={}){let t=o.lag??1,r=o.differences??1;if(!(Number.isInteger(t)&&t>=1&&Number.isInteger(r)&&r>=1))throw new RangeError("'lag' and 'differences' must be integers >= 1");let e=Array.from(n);if(t*r>=e.length)return[];for(let s=0;s<r;s++){let c=[];for(let u=t;u<e.length;u++)c.push(e[u]-e[u-t]);e=c}return e}function Q(n){let o=k(n),t=0,r=0,e=0;for(let s of n){let c=s-o[0]-o[1],u=c*c;t+=u,r+=u*c,e+=u*u}return[t,r,e]}function Z(n){if(![1,2,3].includes(n))throw new RangeError("Invalid 'type' argument.")}function Dt(n,o={}){let t=o.type??3;Z(t);let r=N(n,!0),e=r.length,[s,c]=Q(r),u=Math.sqrt(e)*c/s**1.5;if(t===1)return u;if(t===2){if(e<3)throw new RangeError("Need at least 3 complete observations.");return u*Math.sqrt(e*(e-1))/(e-2)}return u*(1-1/e)**1.5}function Tt(n,o={}){let t=o.type??3;Z(t);let r=N(n,!0),e=r.length,[s,,c]=Q(r),u=e*c/(s*s);if(t===1)return u-3;if(t===2){if(e<4)throw new RangeError("Need at least 4 complete observations.");return((e+1)*(u-3)+6)*(e-1)/((e-2)*(e-3))}return u*(1-1/e)**2-3}function Ct(n,o={}){let t=N(n,o.naRm);return t===void 0?NaN:t.some(r=>r<0)?NaN:t.includes(0)?0:Math.exp(b(t.map(Math.log)))}function Pt(n){let o=N(n,!0),t=new Map;for(let s of o)t.set(s===0?0:s,(t.get(s===0?0:s)??0)+1);let r=0;for(let s of t.values())r=Math.max(r,s);return r<=1?{value:[NaN],frequency:NaN}:{value:[...t.entries()].filter(([,s])=>s===r).map(([s])=>s).sort((s,c)=>s-c),frequency:r}}function Wt(n,o={}){let t=N(n,!0),r=o.center??"mean",e=r==="mean"?b(t):r==="median"?W(t):r;return b(t.map(s=>Math.abs(s-e)))}function Lt(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;let r=t.length,e=Math.sqrt(F(t))/b(t);return o.unbiased&&(e*=1-1/(4*(r-1))+e*e/r+1/(2*(r-1)**2)),e}function Vt(n,o={}){let t=n.length>0&&Array.isArray(n[0])?n.map(f=>[...f]):Array.from(n,f=>[f]),r=t[0]?.length??0,e=f=>t.map(a=>a[f]),s={scaled:t},c=o.center??!0;if(c!==!1){let f=c===!0?Array.from({length:r},(a,l)=>b(e(l).filter(w=>!Number.isNaN(w)))):[...c];if(f.length!==r)throw new RangeError("length of 'center' must equal the number of columns of 'x'");for(let a of t)for(let l=0;l<r;l++)a[l]=a[l]-f[l];s.center=f}let u=o.scale??!0;if(u!==!1){let f=u===!0?Array.from({length:r},(a,l)=>{let w=e(l).filter(v=>!Number.isNaN(v)),R=0;for(let v of w)R+=v*v;return Math.sqrt(R/Math.max(1,w.length-1))}):[...u];if(f.length!==r)throw new RangeError("length of 'scale' must equal the number of columns of 'x'");for(let a of t)for(let l=0;l<r;l++)a[l]=a[l]/f[l];s.scale=f}return s}export{j as a,Y as b,ft as c,O as d,at as e,pt as f,dt as g,gt as h,Nt as i,yt as j,bt as k,N as l,vt as m,At as n,Et as o,Ot as p,mt as q,jt as r,W as s,Rt as t,$t as u,kt as v,Ft as w,_t as x,Yt as y,Dt as z,Tt as A,Ct as B,Pt as C,Wt as D,Lt as E,Vt as F};
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as k,b,c as F}from"./chunk-GSPOO2G3.js";import{d as X,g as I}from"./chunk-OX3SBG5X.js";import{a as D}from"./chunk-WKEFHOFR.js";function j(n){let o=Object.values(n),t=o[0]?.length??0;if(o.some(r=>r.length!==t))throw new RangeError("the columns of a data frame must have the same length");return t}var Y=n=>n==null||typeof n=="number"&&Number.isNaN(n),M=(n,o)=>n[o];function _(n,o){if(n.length>0&&n.every(t=>t instanceof Float64Array)){let t=new Float64Array(o.length);return o.forEach((r,e)=>t[e]=r===null?NaN:r[0][r[1]]),t}return o.map(t=>t===null?null:M(t[0],t[1]))}function ft(n,o){return n instanceof Float64Array?Float64Array.from(o,t=>n[t]):o.map(t=>M(n,t))}function O(n,o,t){if(Object.hasOwn(n,o))throw new Error(`duplicate column name '${o}'`);n[o]=t}function ut(n){if(Number.isNaN(n))return"NA";if(!Number.isFinite(n))return n>0?"Inf":"-Inf";if(n===0)return"0";let[o,t]=Number(n.toPrecision(15)).toExponential().split("e"),r=o.startsWith("-"),e=o.replace("-","").replace(".",""),s=Number(t),c=e.length,u=String(Math.abs(s)).padStart(2,"0"),f=c+(c>1?1:0)+2+u.length,a=s>=0?Math.max(s+1,c)+(c>s+1?1:0):2-s-1+c,l=r?"-":"";return a>f?`${l}${e[0]}${c>1?`.${e.slice(1)}`:""}e${s<0?"-":"+"}${u}`:s<0?`${l}0.${"0".repeat(-s-1)}${e}`:c<=s+1?`${l}${e}${"0".repeat(s+1-c)}`:`${l}${e.slice(0,s+1)}.${e.slice(s+1)}`}function K(n){return Y(n)?"NA":typeof n=="number"?ut(n):typeof n=="boolean"?n?"TRUE":"FALSE":n}var it=Symbol("NA"),U=n=>typeof n=="number"?0:typeof n=="string"?1:2;function at(n,o){let t=Y(n),r=Y(o);if(t||r)return t===r?0:t?1:-1;let e=n,s=o;return typeof e!=typeof s?U(e)-U(s):typeof e=="string"?D(e,s):Number(e)-Number(s)}function lt(n){let o=n.length,t=[...n],r=n.map((s,c)=>c),e=1;for(;e<=Math.trunc(o/9);)e=3*e+1;for(;e>0;e=Math.trunc(e/3))for(let s=e;s<o;s++){let c=t[s],u=r[s],f=s;for(;f>=e&&t[f-e]>c;)t[f]=t[f-e],r[f]=r[f-e],f-=e;t[f]=c,r[f]=u}return r}function B(n){let o=[],t=new Map;for(let r of lt(n)){let e=n[r];if(e===0)o.push(r);else{let s=t.get(e);s===void 0?t.set(e,[r]):s.push(r)}}return{alone:o,groups:t}}var T=n=>typeof n=="string"?[n]:[...n];function H(n,o){return o.map(t=>{if(!Object.hasOwn(n,t))throw new Error("'by' must specify a uniquely valid column");return n[t]})}function pt(n,o,t={}){let r=Object.keys(n),e=Object.keys(o),s=j(n),c=j(o),u=t.by===void 0?r.filter(i=>e.includes(i)):T(t.by),f=t.byX===void 0?u:T(t.byX),a=t.byY===void 0?u:T(t.byY),l=H(n,f),w=H(o,a);if(f.length!==a.length)throw new Error("'by.x' and 'by.y' specify different numbers of columns");let R=t.allX??t.all??!1,v=t.allY??t.all??!1,tt=t.sort??!0,[nt,et]=t.suffixes??[".x",".y"],L=r.filter(i=>!f.includes(i)),V=e.filter(i=>!a.includes(i)),rt=i=>V.includes(i)?i+nt:i,ot=i=>L.includes(i)||f.includes(i)?i+et:i,x=[];if(f.length===0)for(let i=0;i<c;i++)for(let m=0;m<s;m++)x.push([m,i]);else{let i=f.length===1?(p,y)=>{let E=M(p[0],y);return Y(E)?it:E}:(p,y)=>p.map(E=>K(M(E,y))).join("\r"),m=Array.from({length:s},(p,y)=>i(l,y)),h=Array.from({length:c},(p,y)=>i(w,y)),d=new Set(h),g=new Map,A=0;for(let p of m)d.has(p)&&(A++,g.has(p)||g.set(p,A));let z=B(m.map(p=>g.get(p)??0)),G=B(h.map(p=>g.get(p)??0));for(let[p,y]of z.groups){let E=G.groups.get(p)??[];for(let st of y)for(let ct of E)x.push([st,ct])}if(R)for(let p of z.alone)x.push([p,-1]);if(v)for(let p of G.alone)x.push([-1,p])}let S=x.map((i,m)=>m);if(tt&&f.length>0){let i=(m,h)=>{let[d,g]=x[m];return d>=0?M(l[h],d):M(w[h],g)};if(f.length>1&&!R&&!v){let m=x.map((h,d)=>f.map((g,A)=>K(i(d,A))).join("\r"));S.sort((h,d)=>D(m[h],m[d]))}else S.sort((m,h)=>{for(let d=0;d<f.length;d++){let g=at(i(m,d),i(h,d));if(g!==0)return g}return 0})}let q=S.map(i=>x[i]),$={};f.forEach((i,m)=>{let h=l[m],d=w[m];O($,i,_([h,d],q.map(([g,A])=>g>=0?[h,g]:[d,A])))});for(let i of L){let m=n[i];O($,rt(i),_([m],q.map(([h])=>h>=0?[m,h]:null)))}for(let i of V){let m=o[i];O($,ot(i),_([m],q.map(([,h])=>h>=0?[m,h]:null)))}return $}function dt(n,o,t={}){let r=Object.keys(n),e=j(n);if(typeof o!="function"&&o.length!==e)throw new RangeError(`'keep' has ${o.length} values for ${e} rows`);let s=a=>Object.fromEntries(r.map(l=>[l,M(n[l],a)])),c=[];for(let a=0;a<e;a++)(typeof o=="function"?o(s(a)):o[a])===!0&&c.push(a);let u=t.select??r,f={};for(let a of u){if(!Object.hasOwn(n,a))throw new Error("undefined columns selected");O(f,a,ft(n[a],c))}return f}function gt(n){if(n.length===0)return{};let o=Object.keys(n[0]);for(let r of n)if(j(r),Object.keys(r).length!==o.length||!o.every(s=>Object.hasOwn(r,s)))throw new Error("names do not match previous names");let t={};for(let r of o){let e=n.map(c=>c[r]),s=e.flatMap(c=>Array.from({length:c.length},(u,f)=>[c,f]));t[r]=_(e,s)}return t}function Nt(n){let o={},t=n.map(j),r=t.find(e=>e!==t[0]);if(r!==void 0)throw new RangeError(`arguments imply differing number of rows: ${t[0]}, ${r}`);for(let e of n)for(let[s,c]of Object.entries(e))O(o,s,c instanceof Float64Array?Float64Array.from(c):[...c]);return o}function yt(n,o={}){let t=o.columns;if(t===void 0){let e=new Set;for(let s of n)for(let c of Object.keys(s))e.add(c);t=[...e]}let r={};for(let e of t){let s=new Set,c=n.map((u,f)=>{let a=Object.hasOwn(u,e)?u[e]:void 0;if(a==null)return null;if(typeof a!="number"&&typeof a!="string"&&typeof a!="boolean")throw new TypeError(`row ${f}, column '${e}': values must be numbers, strings, booleans or null`);return s.add(typeof a),a});if(s.size>1)throw new TypeError(`column '${e}' mixes ${[...s].join(" and ")} values`);O(r,e,c)}return r}function bt(n){let o=Object.keys(n),t=j(n);return Array.from({length:t},(r,e)=>Object.fromEntries(o.map(s=>[s,M(n[s],e)])))}function N(n,o){let t=Array.from(n);return o?t.filter(r=>!Number.isNaN(r)):t.some(Number.isNaN)?void 0:t}function C(n){if(!n.every(Number.isFinite))return n.reduce((t,r)=>t+r,0);let o=[0,0];for(let t of n)o=X(o,[t,0]);return o[0]+o[1]}function vt(n,o={}){let t=N(n,o.naRm);return t===void 0?NaN:C(t)}function At(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;if(!t.every(Number.isFinite)||t.includes(0))return t.reduce((s,c)=>s*c,1);let r=[1,0],e=0;for(let s of t){r=I(r,[s,0]);let c=Math.floor(Math.log2(Math.abs(r[0])));if(c>500||c<-500){let u=2**-c;r=[r[0]*u,r[1]*u],e+=c}}return P(r,e)}function Et(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;let r=t.length;if(r===0)return NaN;let e=o.trim??0;if(Number.isNaN(e))throw new RangeError("'trim' must be numeric of length one");if(e>0&&r>0){if(e>=.5)return W(t);e=Math.max(e,0);let s=Math.floor(r*e),c=[...t].sort((u,f)=>u-f);return b(c.slice(s,r-s))}return b(t)}function Ot(n,o,t={}){let r=Array.from(n),e=Array.from(o);if(r.length!==e.length)throw new RangeError("'x' and 'w' must have the same length");if(t.naRm){let c=r.map(u=>!Number.isNaN(u));r=r.filter((u,f)=>c[f]),e=e.filter((u,f)=>c[f])}let s=[];for(let c=0;c<r.length;c++)e[c]!==0&&s.push(r[c]*e[c]);return C(s)/C(e)}function mt(n,o={}){let t=N(n,o.naRm);return t===void 0?NaN:F(t)}function jt(n,o={}){return Math.sqrt(mt(n,o))}function W(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;let r=t.length;if(r===0)return NaN;let e=[...t].sort((c,u)=>c-u),s=Math.floor(r/2);return r%2===1?e[s]:k([e[s-1],e[s]])[0]}function Rt(n,o={}){let t=N(n,o.naRm);if(t===void 0)return[NaN,NaN];let r=1/0,e=-1/0;for(let s of t)s<r&&(r=s),s>e&&(e=s);return[r,e]}function $t(n){let o=[],t=[0,0],r=0,e=!0;for(let s of Array.from(n))r+=s,e&&Number.isFinite(s)?(t=X(t,[s,0]),o.push(t[0]+t[1])):(e=!1,o.push(Number.isNaN(s)||Number.isNaN(r)?NaN:r));return o}function kt(n){let o=[],t=[1,0],r=0,e;for(let s of Array.from(n)){if(e===void 0&&(!Number.isFinite(s)||s===0)&&(e=P(t,r)),e!==void 0){e*=s,o.push(e);continue}t=I(t,[s,0]);let c=Math.floor(Math.log2(Math.abs(t[0])));(c>500||c<-500)&&(t=[t[0]*2**-c,t[1]*2**-c],r+=c),o.push(P(t,r))}return o}function P(n,o){let t=n[0]+n[1];for(;o>0&&Number.isFinite(t);){let r=Math.min(o,1e3);t*=2**r,o-=r}for(;o<0&&t!==0;){let r=Math.max(o,-1e3);t*=2**r,o-=r}return t}function J(n,o){let t=[],r=NaN,e=!1;for(let s of Array.from(n)){if(e||Number.isNaN(s)){e=!0,t.push(NaN);continue}(t.length===0||o(s,r))&&(r=s),t.push(r)}return t}function Ft(n){return J(n,(o,t)=>o>t)}function _t(n){return J(n,(o,t)=>o<t)}function Yt(n,o={}){let t=o.lag??1,r=o.differences??1;if(!(Number.isInteger(t)&&t>=1&&Number.isInteger(r)&&r>=1))throw new RangeError("'lag' and 'differences' must be integers >= 1");let e=Array.from(n);if(t*r>=e.length)return[];for(let s=0;s<r;s++){let c=[];for(let u=t;u<e.length;u++)c.push(e[u]-e[u-t]);e=c}return e}function Q(n){let o=k(n),t=0,r=0,e=0;for(let s of n){let c=s-o[0]-o[1],u=c*c;t+=u,r+=u*c,e+=u*u}return[t,r,e]}function Z(n){if(![1,2,3].includes(n))throw new RangeError("Invalid 'type' argument.")}function Dt(n,o={}){let t=o.type??3;Z(t);let r=N(n,!0),e=r.length,[s,c]=Q(r),u=Math.sqrt(e)*c/s**1.5;if(t===1)return u;if(t===2){if(e<3)throw new RangeError("Need at least 3 complete observations.");return u*Math.sqrt(e*(e-1))/(e-2)}return u*(1-1/e)**1.5}function Tt(n,o={}){let t=o.type??3;Z(t);let r=N(n,!0),e=r.length,[s,,c]=Q(r),u=e*c/(s*s);if(t===1)return u-3;if(t===2){if(e<4)throw new RangeError("Need at least 4 complete observations.");return((e+1)*(u-3)+6)*(e-1)/((e-2)*(e-3))}return u*(1-1/e)**2-3}function Ct(n,o={}){let t=N(n,o.naRm);return t===void 0?NaN:t.some(r=>r<0)?NaN:t.includes(0)?0:Math.exp(b(t.map(Math.log)))}function Pt(n){let o=N(n,!0),t=new Map;for(let s of o)t.set(s===0?0:s,(t.get(s===0?0:s)??0)+1);let r=0;for(let s of t.values())r=Math.max(r,s);return r<=1?{value:[NaN],frequency:NaN}:{value:[...t.entries()].filter(([,s])=>s===r).map(([s])=>s).sort((s,c)=>s-c),frequency:r}}function Wt(n,o={}){let t=N(n,!0),r=o.center??"mean",e=r==="mean"?b(t):r==="median"?W(t):r;return b(t.map(s=>Math.abs(s-e)))}function Lt(n,o={}){let t=N(n,o.naRm);if(t===void 0)return NaN;let r=t.length,e=Math.sqrt(F(t))/b(t);return o.unbiased&&(e*=1-1/(4*(r-1))+e*e/r+1/(2*(r-1)**2)),e}function Vt(n,o={}){let t=n.length>0&&Array.isArray(n[0])?n.map(f=>[...f]):Array.from(n,f=>[f]),r=t[0]?.length??0,e=f=>t.map(a=>a[f]),s={scaled:t},c=o.center??!0;if(c!==!1){let f=c===!0?Array.from({length:r},(a,l)=>b(e(l).filter(w=>!Number.isNaN(w)))):[...c];if(f.length!==r)throw new RangeError("length of 'center' must equal the number of columns of 'x'");for(let a of t)for(let l=0;l<r;l++)a[l]=a[l]-f[l];s.center=f}let u=o.scale??!0;if(u!==!1){let f=u===!0?Array.from({length:r},(a,l)=>{let w=e(l).filter(v=>!Number.isNaN(v)),R=0;for(let v of w)R+=v*v;return Math.sqrt(R/Math.max(1,w.length-1))}):[...u];if(f.length!==r)throw new RangeError("length of 'scale' must equal the number of columns of 'x'");for(let a of t)for(let l=0;l<r;l++)a[l]=a[l]/f[l];s.scale=f}return s}export{j as a,Y as b,ft as c,O as d,at as e,pt as f,dt as g,gt as h,Nt as i,yt as j,bt as k,N as l,vt as m,At as n,Et as o,Ot as p,mt as q,jt as r,W as s,Rt as t,$t as u,kt as v,Ft as w,_t as x,Yt as y,Dt as z,Tt as A,Ct as B,Pt as C,Wt as D,Lt as E,Vt as F};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
2
|
var E=23283064365386963e-26,M=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===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()*E;return t<=0?.5*M:1-t<=0?1-.5*M: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");this.mti=t[1];for(let e=0;e<624;e++)this.mt[e]=t[e+2]>>>0}};var b=2328306549295728e-25,R=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=R(e);for(let n=0;n<6;n++){do e=R(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)*b}};function p(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 y=[3.3871328727963665,133.14166789178438,1971.5909503065513,13731.69376550946,45921.95393154987,67265.7709270087,33430.57558358813,2509.0809287301227],_=[1,42.31333070160091,687.1870074920579,5394.196021424751,21213.794301586597,39307.89580009271,28729.085735721943,5226.495278852854],k=[1.4234371107496835,4.630337846156546,5.769497221460691,3.6478483247632045,1.2704582524523684,.2417807251774506,.022723844989269184,.0007745450142783414],I=[1,2.053191626637759,1.6763848301838038,.6897673349851,.14810397642748008,.015198666563616457,.0005475938084995345,10507500716444169e-25],K=[6.657904643501103,5.463784911164114,1.7848265399172913,.29656057182850487,.026532189526576124,.0012426609473880784,27115555687434876e-21,20103343992922881e-23],v=[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 g(r){let t=r-.5;if(Math.abs(t)<=.425){let o=.180625-t*t;return t*f(y,o)/f(_,o)}let e=t<0?r:1-r;e=Math.sqrt(-Math.log(e));let n;return e<=5?(e-=1.6,n=f(k,e)/f(I,e)):(e-=5,n=f(K,e)/f(v,e)),t<0?-n:n}var u=new c,i=u,l=!1,h=!1;function m(r){i.setSeed(r),h=!0}function A(){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]),m(r)}function W(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");m(t)}var L={default:!1,"Mersenne-Twister":!1,"L'Ecuyer-CMRG":!0},P={default:!1,Rejection:!1,Rounding:!0};function w(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 X(r={}){let t={kind:i===u?"Mersenne-Twister":"L'Ecuyer-CMRG",normalKind:"Inversion",sampleKind:l?"Rounding":"Rejection"},e=w(L,r.kind,"RNG kind"),n=w(P,r.sampleKind,"sample kind");if(e!==void 0){let o=Math.trunc(s()*4294967295);i=e?i===u?new a:i:u,m(o)}return n!==void 0&&(l=n),t}var x=()=>(i===u?3:7)+400+(l?0:1e4);function $(){return A(),i===u?u.getRandomSeed(x()):Int32Array.of(x(),...i.s)}function q(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(p(r)),i=n}else u.setRandomSeed(r),i=u;l=t<1e4,h=!0}function s(){return A(),i.nextDouble()}var F=()=>l;function T(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 N=33554432;function B(r){if(l)return Math.floor(r*(r>2147483647?(Math.floor(N*s())+s())/N:s()));if(r<=0)return 0;let t=Math.ceil(Math.log2(r)),e;do e=T(t);while(r<=e);return e}var S=134217728;function V(){let r=s();return r=Math.trunc(S*r)+s(),g(r/S)}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 z(){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]}export{p as a,W as b,X as c,$ as d,q as e,s as f,F as g,B as h,V as i,z as j};
|
package/dist/data/grouping.d.ts
CHANGED
|
@@ -81,9 +81,12 @@ export type AggregateValue = number | readonly number[] | Readonly<Record<string
|
|
|
81
81
|
* The function applied to the values of each group, as a data frame. Equivalent to R's `aggregate()`.
|
|
82
82
|
*
|
|
83
83
|
* Formula form, `aggregate(formula, data, fun)`: `"y ~ g"`, `"y ~ g + h"`, `"cbind(y, z) ~ g"` or `". ~ g"` (every
|
|
84
|
-
* column not on the right)
|
|
85
|
-
*
|
|
86
|
-
*
|
|
84
|
+
* column not on the right). The grouping variables are all the variables of the right-hand side in order of first
|
|
85
|
+
* appearance, whatever its operators (`"y ~ g:h"` and `"y ~ g * h"` group by g and h); `"y ~ ."` groups by every
|
|
86
|
+
* column not summarised, and `"y ~ 1"` gives one row without a grouping column. The rows with a missing value in any
|
|
87
|
+
* variable of the formula are dropped first. Data frame form, `aggregate(x, by, fun)`: the columns of `x` summarised
|
|
88
|
+
* by the label columns of `by` (its keys name them); only the rows with a missing label are dropped, so `fun` sees the
|
|
89
|
+
* missing values of `x`.
|
|
87
90
|
*
|
|
88
91
|
* The result has the grouping columns first (with the labels as in the data), then one column per summarised column,
|
|
89
92
|
* and one row per non-empty combination of the groups (the first factor varying fastest). When `fun` returns k > 1
|
package/dist/data/grouping.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// (the first factor varies fastest). A row whose label is missing (null, or NaN in a numeric column) belongs to no
|
|
7
7
|
// group. tapply keeps the empty cells (NaN or null), split keeps them unless `drop`, aggregate leaves them out.
|
|
8
8
|
import { formatR } from "../htest/core/simulate.js";
|
|
9
|
-
import { parseFormula } from "../models/formula.js";
|
|
9
|
+
import { expandRhs, formulaVariables, parseFormula } from "../models/formula.js";
|
|
10
10
|
import { compareCodePoints } from "../models/modelFrame.js";
|
|
11
11
|
const isMissing = (v) => v === null || (typeof v === "number" && Number.isNaN(v));
|
|
12
12
|
const levelOrder = (a, b) => typeof a === "number" ? a - b : typeof a === "string" ? compareCodePoints(a, b) : Number(a) - Number(b);
|
|
@@ -166,21 +166,12 @@ function labelColumn(data, name) {
|
|
|
166
166
|
throw new TypeError(`column '${name}' must be an array`);
|
|
167
167
|
return col;
|
|
168
168
|
}
|
|
169
|
-
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
summands(node.right, out);
|
|
176
|
-
}
|
|
177
|
-
else if (node.type === "paren")
|
|
178
|
-
summands(node.arg, out);
|
|
179
|
-
else
|
|
180
|
-
throw new SyntaxError("invalid formula: the right-hand side must be grouping variables joined by '+'");
|
|
181
|
-
return out;
|
|
182
|
-
}
|
|
183
|
-
/** The summarised and the grouping columns of `y ~ g`, `y ~ g + h`, `cbind(y, z) ~ g` or `. ~ g` */
|
|
169
|
+
/**
|
|
170
|
+
* The summarised and the grouping columns of a formula: the grouping columns are all the variables of the right-hand
|
|
171
|
+
* side in order of first appearance, whatever its operators (`y ~ g:h`, `y ~ g*h` and `y ~ g + h - g` all group by g
|
|
172
|
+
* and h; `y ~ 1` by nothing); `.` on the right stands for every column not summarised, on the left for every column
|
|
173
|
+
* not on the right.
|
|
174
|
+
*/
|
|
184
175
|
function aggregateFormula(formula, columns) {
|
|
185
176
|
if (typeof formula !== "string")
|
|
186
177
|
throw new TypeError("the formula must be a string");
|
|
@@ -188,22 +179,28 @@ function aggregateFormula(formula, columns) {
|
|
|
188
179
|
if (tilde < 0)
|
|
189
180
|
throw new SyntaxError("invalid formula: missing '~'");
|
|
190
181
|
const lhs = formula.slice(0, tilde).trim();
|
|
191
|
-
const
|
|
182
|
+
const { rhs } = parseFormula(`~ ${formula.slice(tilde + 1)}`);
|
|
192
183
|
const name = /^[A-Za-z.][A-Za-z0-9._]*$/;
|
|
193
184
|
let values;
|
|
194
|
-
if (lhs
|
|
195
|
-
values = columns.filter((c) => !groups.includes(c));
|
|
196
|
-
else {
|
|
185
|
+
if (lhs !== ".") {
|
|
197
186
|
const m = /^cbind\s*\((.*)\)$/s.exec(lhs);
|
|
198
187
|
values = m === null ? [lhs] : m[1].split(",").map((s) => s.trim());
|
|
199
188
|
if (values.some((v) => !name.test(v) || v === ".")) {
|
|
200
189
|
throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'");
|
|
201
190
|
}
|
|
202
191
|
}
|
|
203
|
-
|
|
192
|
+
else if (formulaVariables(rhs, []).length < formulaVariables(rhs, ["."]).length) {
|
|
193
|
+
throw new SyntaxError("invalid formula: '.' cannot be on both sides");
|
|
194
|
+
}
|
|
195
|
+
const dot = values === undefined ? [] : columns.filter((c) => !values.includes(c));
|
|
196
|
+
const groups = formulaVariables(rhs, dot);
|
|
197
|
+
// (the expansion's errors, such as a number that is not a term or an invalid power, as R's terms())
|
|
198
|
+
expandRhs(rhs, () => 0, dot);
|
|
199
|
+
return { values: values ?? columns.filter((c) => !groups.includes(c)), groups };
|
|
204
200
|
}
|
|
205
201
|
function aggregateRows(valueNames, valueCols, groupNames, groupCols, keep, fun) {
|
|
206
|
-
|
|
202
|
+
// (y ~ 1: no grouping column, one group of all the rows)
|
|
203
|
+
const n = groupCols[0]?.length ?? valueCols[0]?.length ?? 0;
|
|
207
204
|
valueNames.forEach((v, j) => {
|
|
208
205
|
if (valueCols[j].length !== n)
|
|
209
206
|
throw new RangeError(`variable lengths differ (found for '${v}')`);
|
package/dist/descriptive.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 0.
|
|
2
|
-
import{a as J,e as S,q as fe,r as ue,s as me}from"./chunks/chunk-LAUYSGV4.js";import"./chunks/chunk-ZRJQD7VS.js";import{A as ke,B as Re,C as Fe,D as je,E as Se,F as Te,a as q,b as T,c as z,d as k,e as G,f as he,g as pe,j as ge,k as ye,l as V,m as de,n as we,o as be,p as Ne,q as Ee,r as _,s as R,t as j,u as Ae,v as xe,w as Me,x as $e,y as ve,z as Oe}from"./chunks/chunk-X2AWQSVS.js";import{a as X}from"./chunks/chunk-M6GDXKKS.js";import{a as H,b as _e,c as Ce,d as Ie,e as Le,f as Pe}from"./chunks/chunk-PHHUHR7T.js";import"./chunks/chunk-HITD7CX6.js";import"./chunks/chunk-KK4GE65D.js";import"./chunks/chunk-6I6QKTFK.js";import"./chunks/chunk-ETOEZTGL.js";var B=4*Number.EPSILON,Ue={4:[0,1],5:[.5,.5],6:[0,0],8:[1/3,1/3],9:[3/8,3/8]};function qe(e,n,t){let r=e.length,o=a=>e[Math.min(Math.max(a,1),r)-1];if(t===7){let a=1+(r-1)*n,g=Math.floor(a),m=o(g),y=o(Math.ceil(a));if(a>g&&y!==m){let b=a-g;return(1-b)*m+b*y}return m}let i,l;if(t<=3){let a=t===3?r*n-.5:r*n;i=Math.floor(a*(1+B)),t===1?l=a>i?1:0:t===2?l=a>i?1:.5:l=a!==i||Math.abs(i%2)===1?1:0}else{let[a,g]=Ue[t],m=a+n*(r+1-a-g);i=Math.floor(m*(1+B)),l=m-i,Math.abs(l)<B&&(l=0)}let s=o(i),u=o(i+1);return l===1?u:l>0&&l<1&&s!==u?(1-l)*s+l*u:s}function C(e,n=[0,.25,.5,.75,1],t={}){let r=t.type??7;if(!(Number.isInteger(r)&&r>=1&&r<=9))throw new RangeError("'type' must be an integer in 1..9");let o=V(e,t.naRm);if(o===void 0)throw new RangeError("missing values and NaN's not allowed if 'na.rm' is FALSE");let i=o.sort((a,g)=>a-g),l=typeof n=="number"?[n]:Array.from(n),s=100*Number.EPSILON;if(l.some(a=>a<-s||a>1+s))throw new RangeError("'probs' outside [0,1]");let u=l.map(a=>Number.isNaN(a)||i.length===0?NaN:qe(i,Math.min(Math.max(a,0),1),r));return typeof n=="number"?u[0]:u}function W(e,n={}){let[t,r]=C(e,[.25,.75],n);return r-t}function ze(e){let n=Array.from(e).filter(i=>!Number.isNaN(i)).sort((i,l)=>i-l),t=n.length;if(t===0)return[NaN,NaN,NaN,NaN,NaN];let r=Math.floor((t+3)/2)/2;return[1,r,(t+1)/2,t+1-r,t].map(i=>.5*(n[Math.floor(i)-1]+n[Math.ceil(i)-1]))}function Ve(e,n={}){let t=V(e,n.naRm);if(t===void 0)return NaN;let r=n.center??R(t),o=n.constant??1.4826,i=n.low??!1,l=n.high??!1,s=t.map(a=>Math.abs(a-r)),u=s.length;if((i||l)&&u%2===0){if(i&&l)throw new RangeError("'low' and 'high' cannot be both TRUE");let a=u/2+(l?1:0),g=s.sort((m,y)=>m-y);return o*g[a-1]}return o*R(s)}var K=e=>e===null||typeof e=="number"&&Number.isNaN(e),Y=e=>Array.isArray(e)||ArrayBuffer.isView(e);function Be(e){if(Y(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 ee(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(Be),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=>!K(l[i])))}function We(e){if(Y(e))return Array.from(e).filter(r=>!K(r));let n=ee(e),t={};for(let[r,o]of Object.entries(e)){let i=Array.from(o).filter((l,s)=>n[s]);t[r]=o instanceof Float64Array?Float64Array.from(i):i}return t}function ne(e,n={}){let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5,o=n.minN??Math.floor(r/3),i=n.shrinkSml??.75,l=n.highUBias??1.5,s=n.u5Bias??.5+1.5*l,u=1/0,a=-1/0;for(let w of t)w<u&&(u=w),w>a&&(a=w);let g=a-u,m,y;if(g===0&&a===0)m=1,y=!0;else{m=Math.max(Math.abs(u),Math.abs(a));let M=(1+(s>=1.5*l+.5?1/(1+l):1.5/(1+s)))*Math.max(1,r)*Number.EPSILON;y=g<m*M*3}y?(m>10&&(m=9+m/10),m*=i,o>1&&(m/=o)):(m=r>1?g/r:g,g===1/0&&r>=2&&(m=a/r-u/r));let b=2**-20*Ze;m<b?m=b:m>Number.MAX_VALUE/1.25&&(m=Number.MAX_VALUE/1.25);let d=10**Math.floor(Math.log10(m)),x=[[2*d,l],[5*d,s],[10*d,l]],N=d;for(let[w,M]of x)if(w-m<M*(m-N))N=w;else break;let h=1e-10,f=Math.floor(u/N+h);for(;f*N>u+h*N;)f--;for(;!Number.isFinite(f*N);)f++;let c=Math.ceil(a/N-h);for(;c*N<a-h*N;)c++;for(;!Number.isFinite(c*N);)c--;let p=Math.trunc(.5+c-f);if(p<o){let w=o-p,M=Math.floor(w/2),O=w%2;u===0&&f===0&&a!==0?c+=w:a===0&&c===0&&u!==0?f-=w:f>=0?(c+=M,f-=M+O):(f-=M,c+=M+O),p=o}let E=f*N<u?f*N:u,A=c*N>a?c*N:a;if(p<=0)return[E];let $;if(Number.isFinite(A-E))$=H(E,A,p+1);else{let w=A/p-E/p;$=Array.from({length:p+1},(M,O)=>E+O*w),$[p]=A}let v=A/p-E/p;return $.map(w=>Math.abs(w)<1e-14*v?0:w)}var Ze=22250738585072014e-324;function De(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function Qe(e,n){let t=e.length,[r,o]=j(e),i=o-r;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let l=3.5*_(e)*t**-.3333333333333333;return l>0?Math.max(1,Math.ceil(i/l)):1}case"fd":case"freedman-diaconis":{let l=e.map(De),s=2*W(l);for(let u=1/8;s===0&&u>=1/512;u/=2){let[a,g]=C(l,[u,1-u]);s=(g-a)/(1-2*u)}return s===0&&(s=3.5*_(e)),s>0?Math.ceil(i/s*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function Je(e,n){let t=e.slice(1).map((r,o)=>r-e[o]);return e.length>5?R(t):e.length<=3?n:Math.min(...t.filter(r=>r>0))}function Xe(e,n={}){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)s=[...l].sort((h,f)=>h-f);else{i=!0;let h=typeof l=="string"?Qe(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[f,c]=j(t);s=ne([f,c],{n:h,minN:1});for(let p=1;p<s.length;p++)if(!(s[p]-s[p-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let u=s.length,[a,g]=r>0?j(t):[0,0],m=1e-7*Je(s,g-a),y=s.map((h,f)=>o?f===0&&i?h-m:h+m:f<u-1?h-m:i?h+m:h-m),b=new Array(Math.max(0,u-1)).fill(0),d=0;for(let h of t){let f=Ge(h,y,o,i);f>=0&&(b[f]++,d++)}if(d<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let x=b.map((h,f)=>h/(r*(s[f+1]-s[f]))),N=b.map((h,f)=>.5*(s[f+1]+s[f]));return{breaks:s,counts:b,density:x,mids:N}}function Ge(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,u=o;for(;s<u;){let a=s+u>>1;e<=n[a]?u=a:s=a+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=i+l+1>>1;n[s]<=e?i=s:l=s-1}return i}function He(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=o+i>>1;n[l]<=r?o=l+1:i=l}return o/t}}var I=e=>e===null||typeof e=="number"&&Number.isNaN(e),Ke=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?X(e,n):Number(e)-Number(n),Ye=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?S(e):e>0?"Inf":"-Inf";function en(e,n){let t=Array.from(n,s=>s===0?0:s),r=new Set(t.filter(s=>!I(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=>!I(s)))].sort(Ke),l=new Map(i.map((s,u)=>[s,u]));return{levels:i,codes:t.map(s=>I(s)?-1:l.get(s))}}var F=e=>Array.isArray(e)||e instanceof Float64Array;function se(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(F))return[...e];if(e.some(F))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function Z(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),i=new Array(t);for(let l=0;l<t;l++){let s=0,u=1;for(let a of r){let g=a.codes[l];if(g<0){s=-1;break}s+=g*u,u*=a.levels.length}i[l]=s}return{factors:r,size:o,cells:i}}function D(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function le(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 ae=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function nn(e,n,t){let r=Array.from(e),o=se(n),i=Z(o,ae(o.length,"index"),r.length),l=D(i).map(a=>a.length===0?null:{value:t(a.map(g=>r[g]))}),u=l.every(a=>a===null||typeof a.value=="number")?l.map(a=>a===null?NaN:a.value):l.map(a=>a===null?null:a.value);return{dim:i.factors.map(a=>a.levels.length),dimnames:i.factors.map(a=>[...a.levels]),values:u}}function tn(e,n){let t={};for(let[r,o]of Object.entries(e))t[r]=o instanceof Float64Array?Float64Array.from(n,i=>o[i]):n.map(i=>o[i]);return t}function rn(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!F(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 on(e,n,t={}){let r=t.sep??".",o=se(n),i=!F(e);if(i&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let l=i?rn(e):e.length,s=Z(o,ae(o.length,"f"),l),u=i?[]:Array.from(e),a=new Map;return D(s).forEach((g,m)=>{if(g.length===0&&(t.drop||s.factors.length===1))return;let y=le(s,m).map(Ye).join(r);a.set(y,i?tn(e,g):g.map(b=>u[b]))}),a}function te(e,n){if(n===void 0)throw new Error(`object '${e}' not found`);if(!F(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 re(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new Error(`object '${n}' not found`);if(!F(t))throw new TypeError(`column '${n}' must be an array`);return t}function L(e,n){if(e.type==="var")n.push(e.name);else if(e.type==="binary"&&e.op==="+")L(e.left,n),L(e.right,n);else if(e.type==="paren")L(e.arg,n);else throw new SyntaxError("invalid formula: the right-hand side must be grouping variables joined by '+'");return n}function sn(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(),o=L(J(`~ ${e.slice(t+1)}`).rhs,[]),i=/^[A-Za-z.][A-Za-z0-9._]*$/,l;if(r===".")l=n.filter(s=>!o.includes(s));else{let s=/^cbind\s*\((.*)\)$/s.exec(r);if(l=s===null?[r]:s[1].split(",").map(u=>u.trim()),l.some(u=>!i.test(u)||u==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}return{values:l,groups:o}}function oe(e,n,t,r,o,i){let l=r[0]?.length??0;e.forEach((m,y)=>{if(n[y].length!==l)throw new RangeError(`variable lengths differ (found for '${m}')`)});let s=Z(r,t,l),u=D(s).map((m,y)=>({cell:y,rows:m.filter(o)})).filter(m=>m.rows.length>0),a={},g=u.map(m=>le(s,m.cell));return t.forEach((m,y)=>{a[m]=g.map(b=>b[y])}),e.forEach((m,y)=>{let b=n[y],x=u.map(h=>i(h.rows.map(f=>b[f]))).map(h=>{if(typeof h=="number")return{names:void 0,values:[h]};if(Array.isArray(h))return{names:void 0,values:[...h]};let f=h;return{names:Object.keys(f),values:Object.values(f)}}),N=x[0]?.values.length??1;if(x.some(h=>h.values.length!==N))throw new RangeError("fun must return values of the same length for every group");if(N===1&&x[0]?.names===void 0){a[m]=x.map(h=>h.values[0]);return}for(let h=0;h<N;h++){let f=x[0].names?.[h]??String(h+1);a[`${m}.${f}`]=x.map(c=>c.values[h])}}),a}function ln(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:u,groups:a}=sn(e,Object.keys(s)),g=d=>Object.prototype.hasOwnProperty.call(s,d),m=u.map(d=>te(d,g(d)?s[d]:void 0)),y=a.map(d=>re(s,d));return oe(u,m,a,y,d=>m.every(x=>!Number.isNaN(x[d]))&&y.every(x=>!I(x[d])),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=>te(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=>re(n,s));return oe(r,o,i,l,()=>!0,t)}var P=e=>typeof e=="string"?[e]:[...e];function ce(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new Error(`Column \`${t}\` doesn't exist.`)}function an(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 cn(e,n){let t=null;for(let r of n){let o=an(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 fn(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new Error(`\`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,u)=>l===null?null:l[u+1]??null)})}function un(e,n,t,r){let o=new RegExp(n,"g"),i=[],l=[],s=e.map((a,g)=>{let m=[],y=0;for(let b of a.matchAll(o))b[0].length!==0&&(m.push(a.slice(y,b.index)),y=b.index+b[0].length);return m.push(a.slice(y)),m.length>t&&i.push(g+1),m.length<t&&l.push(g+1),Array.from({length:t},(b,d)=>m[d]??null)}),u=a=>`${a.length} rows [${a.join(", ")}]`;return i.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${u(i)}.`),l.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${u(l)}.`),s}function mn(e,n,t,r){let{namesSep:o,namesPattern:i}=t;if(n.length===1){if(o!==void 0)throw new Error("`names_sep` can't be used with a length 1 `names_to`.");if(i===void 0)return e.map(s=>[s]);let l=new RegExp(i);return e.map(s=>[l.exec(s)?.[1]??null])}if(o===void 0==(i===void 0))throw new Error("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?un(e,o,n.length,r):fn(e,i,n.length)}function hn(e,n){let t=q(e),r=Object.keys(e),o=typeof n.cols=="function"?r.filter(n.cols):[...new Set(n.cols)];if(ce(e,o),o.length===0)throw new Error("`cols` must select at least one column.");let i=P(n.namesTo??"name"),l=i.indexOf(".value");if(i.lastIndexOf(".value")!==l)throw new Error('`names_to` may contain ".value" only once');let s=[],u=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),a=o.map(f=>u===null?f:f.replace(u,"")),g=mn(a,i,n,s),m=[],y=[];if(l<0)m.push(...g),y.push({name:n.valuesTo??"value",sources:[...o]});else{let f=new Map,c=new Map;g.forEach((p,E)=>{let A=p.filter((O,U)=>U!==l),$=JSON.stringify(A),v=f.get($);if(v===void 0){v=m.length,f.set($,v),m.push(A);for(let O of y)O.sources.push(null)}let w=p[l]??"NA",M=c.get(w);if(M===void 0&&(M={name:w,sources:m.map(()=>null)},c.set(w,M),y.push(M)),M.sources[v]!==null)throw new Error(`the names give the value column '${w}' twice for one key`);M.sources[v]=o[E]})}let b=y.map(f=>cn(e,f.sources.filter(c=>c!==null))),d=[];if(n.colsVary==="slowest")for(let f=0;f<m.length;f++)for(let c=0;c<t;c++)d.push([c,f]);else for(let f=0;f<t;f++)for(let c=0;c<m.length;c++)d.push([f,c]);let x=(f,c,p)=>{let E=f.sources[p];return E==null?null:e[E][c]};n.valuesDropNa===!0&&(d=d.filter(([f,c])=>y.some(p=>!T(x(p,f,c)))));let N={},h=d.map(([f])=>f);for(let f of r)o.includes(f)||k(N,f,z(e[f],h));if(i.forEach((f,c)=>{if(c===l)return;let p=n.namesTransform?.[f],E=A=>{let $=m[A][c<l||l<0?c:c-1];return $===null||p===void 0?$:p($)};k(N,f,d.map(([,A])=>E(A)))}),y.forEach((f,c)=>{let p=b[c]==="double";if(p&&f.sources.every(E=>E!==null&&e[E]instanceof Float64Array))k(N,f.name,Float64Array.from(d,([E,A])=>x(f,E,A)));else{let E=d.map(([A,$])=>{let v=x(f,A,$);return p&&typeof v=="boolean"?Number(v):v});k(N,f.name,E)}}),n.onWarning!==void 0)for(let f of new Set(s))n.onWarning(f);return N}var pn=e=>T(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function ie(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(i,l)=>{let s=JSON.stringify(e.map(a=>pn(a[l]))),u=t.get(s);return u===void 0&&(u=r.length,t.set(s,u),r.push(l)),u}),firsts:r}}function gn(e){return T(e)?"NA":typeof e=="number"?Number.isFinite(e)?S(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function Q(e,n,t){if(e!==void 0)return n(e)?e:e[t]}function yn(e,n={}){let t=q(e),r=P(n.namesFrom??"name"),o=P(n.valuesFrom??"value"),i=n.idCols===void 0?Object.keys(e).filter(c=>!r.includes(c)&&!o.includes(c)):P(n.idCols);ce(e,[...i,...r,...o]);let l=n.namesPrefix??"",s=n.namesSep??"_",u=ie(i.map(c=>e[c]),t),a=ie(r.map(c=>e[c]),t),g=a.firsts.map((c,p)=>p);n.namesSort===!0&&g.sort((c,p)=>{for(let E of r){let A=G(e[E][a.firsts[c]],e[E][a.firsts[p]]);if(A!==0)return A}return 0});let m=a.firsts.map(c=>l+r.map(p=>gn(e[p][c])).join(s)),y=a.firsts.length,b=Array.from({length:u.firsts.length*y},()=>[]);for(let c=0;c<t;c++)b[u.codes[c]*y+a.codes[c]].push(c);let d=c=>typeof c=="function",x=c=>typeof c!="object"||c===null,N=(c,p)=>{let E=e[c],A=Q(n.valuesFn,d,c),$=Q(n.valuesFill,x,c)??null,v=u.firsts.map((w,M)=>{let O=b[M*y+p];return O.length===0?$:A!==void 0?A(O.map(U=>E[U])):E[O[0]]});return E instanceof Float64Array&&v.every(w=>w===null||typeof w=="number")?Float64Array.from(v,w=>w===null?NaN:w):v};for(let c of o)if(Q(n.valuesFn,d,c)===void 0&&b.some(p=>p.length>1))throw new Error(`values from '${c}' are not uniquely identified; use valuesFn to summarise them`);let h={};for(let c of i)k(h,c,z(e[c],u.firsts));let f=(c,p)=>o.length===1?m[p]:`${c}${s}${m[p]}`;if(n.namesVary==="slowest")for(let c of g)for(let p of o)k(h,f(p,c),N(p,c));else for(let c of o)for(let p of g)k(h,f(c,p),N(c,p));return h}export{W as IQR,ln as aggregate,ee as completeCases,me as cor,ue as cov,Me as cummax,$e as cummin,xe as cumprod,Ae as cumsum,Le as cut,Se as cv,ve as diff,He as ecdf,Pe as findInterval,ze as fivenum,ge as fromRows,Re as geometricMean,Xe as hist,ke as kurtosis,Ve as mad,be as mean,je as meanAD,R as median,he as merge,Fe as modes,We as naOmit,hn as pivotLonger,yn as pivotWider,ne as pretty,we as prod,C as quantile,j as range,fe as rank,Te as scale,_ as sd,Oe as skewness,on as split,pe as subset,de as sum,Ce as table,_e as tabulate,nn as tapply,ye as toRows,Ie as unique,Ee as variance,Ne as weightedMean};
|
|
1
|
+
/*! rStats.js 0.12.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{l as fe,m as me,n as he}from"./chunks/chunk-SGZQDJRR.js";import"./chunks/chunk-EZ2KD5NA.js";import{A as Re,B as Fe,C as je,D as Se,E as Te,F as _e,a as q,b as _,c as V,d as v,e as H,f as pe,g as ge,j as de,k as ye,l as z,m as we,n as be,o as Ne,p as Ee,q as Ae,r as I,s as R,t as j,u as xe,v as Me,w as $e,x as Oe,y as ke,z as ve}from"./chunks/chunk-WXC25OPJ.js";import{a as K,b as Ie,c as Ce,d as Le,e as Pe,f as Ue}from"./chunks/chunk-UH2N3ZQW.js";import"./chunks/chunk-XJQKSR52.js";import"./chunks/chunk-GSPOO2G3.js";import"./chunks/chunk-EDH53DXN.js";import"./chunks/chunk-OX3SBG5X.js";import{b as S,c as J,g as T,h as X}from"./chunks/chunk-4OKAZJJG.js";import{a as G}from"./chunks/chunk-WKEFHOFR.js";var B=4*Number.EPSILON,qe={4:[0,1],5:[.5,.5],6:[0,0],8:[1/3,1/3],9:[3/8,3/8]};function Ve(e,n,t){let r=e.length,o=a=>e[Math.min(Math.max(a,1),r)-1];if(t===7){let a=1+(r-1)*n,g=Math.floor(a),m=o(g),d=o(Math.ceil(a));if(a>g&&d!==m){let b=a-g;return(1-b)*m+b*d}return m}let i,l;if(t<=3){let a=t===3?r*n-.5:r*n;i=Math.floor(a*(1+B)),t===1?l=a>i?1:0:t===2?l=a>i?1:.5:l=a!==i||Math.abs(i%2)===1?1:0}else{let[a,g]=qe[t],m=a+n*(r+1-a-g);i=Math.floor(m*(1+B)),l=m-i,Math.abs(l)<B&&(l=0)}let s=o(i),f=o(i+1);return l===1?f:l>0&&l<1&&s!==f?(1-l)*s+l*f:s}function C(e,n=[0,.25,.5,.75,1],t={}){let r=t.type??7;if(!(Number.isInteger(r)&&r>=1&&r<=9))throw new RangeError("'type' must be an integer in 1..9");let o=z(e,t.naRm);if(o===void 0)throw new RangeError("missing values and NaN's not allowed if 'na.rm' is FALSE");let i=o.sort((a,g)=>a-g),l=typeof n=="number"?[n]:Array.from(n),s=100*Number.EPSILON;if(l.some(a=>a<-s||a>1+s))throw new RangeError("'probs' outside [0,1]");let f=l.map(a=>Number.isNaN(a)||i.length===0?NaN:Ve(i,Math.min(Math.max(a,0),1),r));return typeof n=="number"?f[0]:f}function W(e,n={}){let[t,r]=C(e,[.25,.75],n);return r-t}function ze(e){let n=Array.from(e).filter(i=>!Number.isNaN(i)).sort((i,l)=>i-l),t=n.length;if(t===0)return[NaN,NaN,NaN,NaN,NaN];let r=Math.floor((t+3)/2)/2;return[1,r,(t+1)/2,t+1-r,t].map(i=>.5*(n[Math.floor(i)-1]+n[Math.ceil(i)-1]))}function Be(e,n={}){let t=z(e,n.naRm);if(t===void 0)return NaN;let r=n.center??R(t),o=n.constant??1.4826,i=n.low??!1,l=n.high??!1,s=t.map(a=>Math.abs(a-r)),f=s.length;if((i||l)&&f%2===0){if(i&&l)throw new RangeError("'low' and 'high' cannot be both TRUE");let a=f/2+(l?1:0),g=s.sort((m,d)=>m-d);return o*g[a-1]}return o*R(s)}var Y=e=>e===null||typeof e=="number"&&Number.isNaN(e),ee=e=>Array.isArray(e)||ArrayBuffer.isView(e);function We(e){if(ee(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 ne(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(We),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=>!Y(l[i])))}function Ze(e){if(ee(e))return Array.from(e).filter(r=>!Y(r));let n=ne(e),t={};for(let[r,o]of Object.entries(e)){let i=Array.from(o).filter((l,s)=>n[s]);t[r]=o instanceof Float64Array?Float64Array.from(i):i}return t}function te(e,n={}){let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5,o=n.minN??Math.floor(r/3),i=n.shrinkSml??.75,l=n.highUBias??1.5,s=n.u5Bias??.5+1.5*l,f=1/0,a=-1/0;for(let w of t)w<f&&(f=w),w>a&&(a=w);let g=a-f,m,d;if(g===0&&a===0)m=1,d=!0;else{m=Math.max(Math.abs(f),Math.abs(a));let M=(1+(s>=1.5*l+.5?1/(1+l):1.5/(1+s)))*Math.max(1,r)*Number.EPSILON;d=g<m*M*3}d?(m>10&&(m=9+m/10),m*=i,o>1&&(m/=o)):(m=r>1?g/r:g,g===1/0&&r>=2&&(m=a/r-f/r));let b=2**-20*De;m<b?m=b:m>Number.MAX_VALUE/1.25&&(m=Number.MAX_VALUE/1.25);let y=10**Math.floor(Math.log10(m)),x=[[2*y,l],[5*y,s],[10*y,l]],N=y;for(let[w,M]of x)if(w-m<M*(m-N))N=w;else break;let h=1e-10,u=Math.floor(f/N+h);for(;u*N>f+h*N;)u--;for(;!Number.isFinite(u*N);)u++;let c=Math.ceil(a/N-h);for(;c*N<a-h*N;)c++;for(;!Number.isFinite(c*N);)c--;let p=Math.trunc(.5+c-u);if(p<o){let w=o-p,M=Math.floor(w/2),k=w%2;f===0&&u===0&&a!==0?c+=w:a===0&&c===0&&f!==0?u-=w:u>=0?(c+=M,u-=M+k):(u-=M,c+=M+k),p=o}let E=u*N<f?u*N:f,A=c*N>a?c*N:a;if(p<=0)return[E];let $;if(Number.isFinite(A-E))$=K(E,A,p+1);else{let w=A/p-E/p;$=Array.from({length:p+1},(M,k)=>E+k*w),$[p]=A}let O=A/p-E/p;return $.map(w=>Math.abs(w)<1e-14*O?0:w)}var De=22250738585072014e-324;function Qe(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function Je(e,n){let t=e.length,[r,o]=j(e),i=o-r;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let l=3.5*I(e)*t**-.3333333333333333;return l>0?Math.max(1,Math.ceil(i/l)):1}case"fd":case"freedman-diaconis":{let l=e.map(Qe),s=2*W(l);for(let f=1/8;s===0&&f>=1/512;f/=2){let[a,g]=C(l,[f,1-f]);s=(g-a)/(1-2*f)}return s===0&&(s=3.5*I(e)),s>0?Math.ceil(i/s*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function Xe(e,n){let t=e.slice(1).map((r,o)=>r-e[o]);return e.length>5?R(t):e.length<=3?n:Math.min(...t.filter(r=>r>0))}function Ge(e,n={}){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)s=[...l].sort((h,u)=>h-u);else{i=!0;let h=typeof l=="string"?Je(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[u,c]=j(t);s=te([u,c],{n:h,minN:1});for(let p=1;p<s.length;p++)if(!(s[p]-s[p-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let f=s.length,[a,g]=r>0?j(t):[0,0],m=1e-7*Xe(s,g-a),d=s.map((h,u)=>o?u===0&&i?h-m:h+m:u<f-1?h-m:i?h+m:h-m),b=new Array(Math.max(0,f-1)).fill(0),y=0;for(let h of t){let u=He(h,d,o,i);u>=0&&(b[u]++,y++)}if(y<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let x=b.map((h,u)=>h/(r*(s[u+1]-s[u]))),N=b.map((h,u)=>.5*(s[u+1]+s[u]));return{breaks:s,counts:b,density:x,mids:N}}function He(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 a=s+f>>1;e<=n[a]?f=a:s=a+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=i+l+1>>1;n[s]<=e?i=s:l=s-1}return i}function Ke(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=o+i>>1;n[l]<=r?o=l+1:i=l}return o/t}}var L=e=>e===null||typeof e=="number"&&Number.isNaN(e),Ye=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?G(e,n):Number(e)-Number(n),en=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?S(e):e>0?"Inf":"-Inf";function nn(e,n){let t=Array.from(n,s=>s===0?0:s),r=new Set(t.filter(s=>!L(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=>!L(s)))].sort(Ye),l=new Map(i.map((s,f)=>[s,f]));return{levels:i,codes:t.map(s=>L(s)?-1:l.get(s))}}var F=e=>Array.isArray(e)||e instanceof Float64Array;function le(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(F))return[...e];if(e.some(F))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function Z(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)=>nn(n[s],l)),o=r.reduce((l,s)=>l*s.levels.length,1),i=new Array(t);for(let l=0;l<t;l++){let s=0,f=1;for(let a of r){let g=a.codes[l];if(g<0){s=-1;break}s+=g*f,f*=a.levels.length}i[l]=s}return{factors:r,size:o,cells:i}}function D(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function ae(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 ie=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function tn(e,n,t){let r=Array.from(e),o=le(n),i=Z(o,ie(o.length,"index"),r.length),l=D(i).map(a=>a.length===0?null:{value:t(a.map(g=>r[g]))}),f=l.every(a=>a===null||typeof a.value=="number")?l.map(a=>a===null?NaN:a.value):l.map(a=>a===null?null:a.value);return{dim:i.factors.map(a=>a.levels.length),dimnames:i.factors.map(a=>[...a.levels]),values:f}}function rn(e,n){let t={};for(let[r,o]of Object.entries(e))t[r]=o instanceof Float64Array?Float64Array.from(n,i=>o[i]):n.map(i=>o[i]);return t}function on(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!F(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 sn(e,n,t={}){let r=t.sep??".",o=le(n),i=!F(e);if(i&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let l=i?on(e):e.length,s=Z(o,ie(o.length,"f"),l),f=i?[]:Array.from(e),a=new Map;return D(s).forEach((g,m)=>{if(g.length===0&&(t.drop||s.factors.length===1))return;let d=ae(s,m).map(en).join(r);a.set(d,i?rn(e,g):g.map(b=>f[b]))}),a}function re(e,n){if(n===void 0)throw new Error(`object '${e}' not found`);if(!F(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 oe(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new Error(`object '${n}' not found`);if(!F(t))throw new TypeError(`column '${n}' must be an array`);return t}function ln(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}=J(`~ ${e.slice(t+1)}`),i=/^[A-Za-z.][A-Za-z0-9._]*$/,l;if(r!=="."){let a=/^cbind\s*\((.*)\)$/s.exec(r);if(l=a===null?[r]:a[1].split(",").map(g=>g.trim()),l.some(g=>!i.test(g)||g==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}else if(T(o,[]).length<T(o,["."]).length)throw new SyntaxError("invalid formula: '.' cannot be on both sides");let s=l===void 0?[]:n.filter(a=>!l.includes(a)),f=T(o,s);return X(o,()=>0,s),{values:l??n.filter(a=>!f.includes(a)),groups:f}}function se(e,n,t,r,o,i){let l=r[0]?.length??n[0]?.length??0;e.forEach((m,d)=>{if(n[d].length!==l)throw new RangeError(`variable lengths differ (found for '${m}')`)});let s=Z(r,t,l),f=D(s).map((m,d)=>({cell:d,rows:m.filter(o)})).filter(m=>m.rows.length>0),a={},g=f.map(m=>ae(s,m.cell));return t.forEach((m,d)=>{a[m]=g.map(b=>b[d])}),e.forEach((m,d)=>{let b=n[d],x=f.map(h=>i(h.rows.map(u=>b[u]))).map(h=>{if(typeof h=="number")return{names:void 0,values:[h]};if(Array.isArray(h))return{names:void 0,values:[...h]};let u=h;return{names:Object.keys(u),values:Object.values(u)}}),N=x[0]?.values.length??1;if(x.some(h=>h.values.length!==N))throw new RangeError("fun must return values of the same length for every group");if(N===1&&x[0]?.names===void 0){a[m]=x.map(h=>h.values[0]);return}for(let h=0;h<N;h++){let u=x[0].names?.[h]??String(h+1);a[`${m}.${u}`]=x.map(c=>c.values[h])}}),a}function an(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:a}=ln(e,Object.keys(s)),g=y=>Object.prototype.hasOwnProperty.call(s,y),m=f.map(y=>re(y,g(y)?s[y]:void 0)),d=a.map(y=>oe(s,y));return se(f,m,a,d,y=>m.every(x=>!Number.isNaN(x[y]))&&d.every(x=>!L(x[y])),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=>re(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=>oe(n,s));return se(r,o,i,l,()=>!0,t)}var P=e=>typeof e=="string"?[e]:[...e];function ue(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new Error(`Column \`${t}\` doesn't exist.`)}function cn(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 un(e,n){let t=null;for(let r of n){let o=cn(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 fn(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new Error(`\`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 mn(e,n,t,r){let o=new RegExp(n,"g"),i=[],l=[],s=e.map((a,g)=>{let m=[],d=0;for(let b of a.matchAll(o))b[0].length!==0&&(m.push(a.slice(d,b.index)),d=b.index+b[0].length);return m.push(a.slice(d)),m.length>t&&i.push(g+1),m.length<t&&l.push(g+1),Array.from({length:t},(b,y)=>m[y]??null)}),f=a=>`${a.length} rows [${a.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 hn(e,n,t,r){let{namesSep:o,namesPattern:i}=t;if(n.length===1){if(o!==void 0)throw new Error("`names_sep` can't be used with a length 1 `names_to`.");if(i===void 0)return e.map(s=>[s]);let l=new RegExp(i);return e.map(s=>[l.exec(s)?.[1]??null])}if(o===void 0==(i===void 0))throw new Error("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?mn(e,o,n.length,r):fn(e,i,n.length)}function pn(e,n){let t=q(e),r=Object.keys(e),o=typeof n.cols=="function"?r.filter(n.cols):[...new Set(n.cols)];if(ue(e,o),o.length===0)throw new Error("`cols` must select at least one column.");let i=P(n.namesTo??"name"),l=i.indexOf(".value");if(i.lastIndexOf(".value")!==l)throw new Error('`names_to` may contain ".value" only once');let s=[],f=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),a=o.map(u=>f===null?u:u.replace(f,"")),g=hn(a,i,n,s),m=[],d=[];if(l<0)m.push(...g),d.push({name:n.valuesTo??"value",sources:[...o]});else{let u=new Map,c=new Map;g.forEach((p,E)=>{let A=p.filter((k,U)=>U!==l),$=JSON.stringify(A),O=u.get($);if(O===void 0){O=m.length,u.set($,O),m.push(A);for(let k of d)k.sources.push(null)}let w=p[l]??"NA",M=c.get(w);if(M===void 0&&(M={name:w,sources:m.map(()=>null)},c.set(w,M),d.push(M)),M.sources[O]!==null)throw new Error(`the names give the value column '${w}' twice for one key`);M.sources[O]=o[E]})}let b=d.map(u=>un(e,u.sources.filter(c=>c!==null))),y=[];if(n.colsVary==="slowest")for(let u=0;u<m.length;u++)for(let c=0;c<t;c++)y.push([c,u]);else for(let u=0;u<t;u++)for(let c=0;c<m.length;c++)y.push([u,c]);let x=(u,c,p)=>{let E=u.sources[p];return E==null?null:e[E][c]};n.valuesDropNa===!0&&(y=y.filter(([u,c])=>d.some(p=>!_(x(p,u,c)))));let N={},h=y.map(([u])=>u);for(let u of r)o.includes(u)||v(N,u,V(e[u],h));if(i.forEach((u,c)=>{if(c===l)return;let p=n.namesTransform?.[u],E=A=>{let $=m[A][c<l||l<0?c:c-1];return $===null||p===void 0?$:p($)};v(N,u,y.map(([,A])=>E(A)))}),d.forEach((u,c)=>{let p=b[c]==="double";if(p&&u.sources.every(E=>E!==null&&e[E]instanceof Float64Array))v(N,u.name,Float64Array.from(y,([E,A])=>x(u,E,A)));else{let E=y.map(([A,$])=>{let O=x(u,A,$);return p&&typeof O=="boolean"?Number(O):O});v(N,u.name,E)}}),n.onWarning!==void 0)for(let u of new Set(s))n.onWarning(u);return N}var gn=e=>_(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function ce(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(i,l)=>{let s=JSON.stringify(e.map(a=>gn(a[l]))),f=t.get(s);return f===void 0&&(f=r.length,t.set(s,f),r.push(l)),f}),firsts:r}}function dn(e){return _(e)?"NA":typeof e=="number"?Number.isFinite(e)?S(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function Q(e,n,t){if(e!==void 0)return n(e)?e:e[t]}function yn(e,n={}){let t=q(e),r=P(n.namesFrom??"name"),o=P(n.valuesFrom??"value"),i=n.idCols===void 0?Object.keys(e).filter(c=>!r.includes(c)&&!o.includes(c)):P(n.idCols);ue(e,[...i,...r,...o]);let l=n.namesPrefix??"",s=n.namesSep??"_",f=ce(i.map(c=>e[c]),t),a=ce(r.map(c=>e[c]),t),g=a.firsts.map((c,p)=>p);n.namesSort===!0&&g.sort((c,p)=>{for(let E of r){let A=H(e[E][a.firsts[c]],e[E][a.firsts[p]]);if(A!==0)return A}return 0});let m=a.firsts.map(c=>l+r.map(p=>dn(e[p][c])).join(s)),d=a.firsts.length,b=Array.from({length:f.firsts.length*d},()=>[]);for(let c=0;c<t;c++)b[f.codes[c]*d+a.codes[c]].push(c);let y=c=>typeof c=="function",x=c=>typeof c!="object"||c===null,N=(c,p)=>{let E=e[c],A=Q(n.valuesFn,y,c),$=Q(n.valuesFill,x,c)??null,O=f.firsts.map((w,M)=>{let k=b[M*d+p];return k.length===0?$:A!==void 0?A(k.map(U=>E[U])):E[k[0]]});return E instanceof Float64Array&&O.every(w=>w===null||typeof w=="number")?Float64Array.from(O,w=>w===null?NaN:w):O};for(let c of o)if(Q(n.valuesFn,y,c)===void 0&&b.some(p=>p.length>1))throw new Error(`values from '${c}' are not uniquely identified; use valuesFn to summarise them`);let h={};for(let c of i)v(h,c,V(e[c],f.firsts));let u=(c,p)=>o.length===1?m[p]:`${c}${s}${m[p]}`;if(n.namesVary==="slowest")for(let c of g)for(let p of o)v(h,u(p,c),N(p,c));else for(let c of o)for(let p of g)v(h,u(c,p),N(c,p));return h}export{W as IQR,an as aggregate,ne as completeCases,he as cor,me as cov,$e as cummax,Oe as cummin,Me as cumprod,xe as cumsum,Pe as cut,Te as cv,ke as diff,Ke as ecdf,Ue as findInterval,ze as fivenum,de as fromRows,Fe as geometricMean,Ge as hist,Re as kurtosis,Be as mad,Ne as mean,Se as meanAD,R as median,pe as merge,je as modes,Ze as naOmit,pn as pivotLonger,yn as pivotWider,te as pretty,be as prod,C as quantile,j as range,fe as rank,_e as scale,I as sd,ve as skewness,sn as split,ge as subset,we as sum,Ce as table,Ie as tabulate,tn as tapply,ye as toRows,Le as unique,Ae as variance,Ee as weightedMean};
|