@numero-uno-jpn/rstats 0.11.0 → 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 +57 -0
- package/README.ja.md +44 -13
- package/README.md +43 -11
- package/dist/chunks/{chunk-VJ4BDBMU.js → chunk-3VMBBQLV.js} +2 -2
- package/dist/chunks/chunk-4OKAZJJG.js +3 -0
- package/dist/chunks/{chunk-EZAFN5CD.js → chunk-6BH65HGN.js} +1 -1
- package/dist/chunks/chunk-ATC4F4BX.js +2 -0
- package/dist/chunks/{chunk-JWBO5WVN.js → chunk-EDH53DXN.js} +2 -2
- package/dist/chunks/{chunk-Y5CNQ266.js → chunk-EZ2KD5NA.js} +2 -2
- package/dist/chunks/{chunk-Y5PYRAYP.js → chunk-GSPOO2G3.js} +2 -2
- package/dist/chunks/{chunk-F5EDJFEO.js → chunk-K7AZ65H7.js} +2 -2
- package/dist/chunks/{chunk-YSWGDOWK.js → chunk-LEIH4U5X.js} +2 -2
- package/dist/chunks/{chunk-EZWBRCJL.js → chunk-OX3SBG5X.js} +1 -1
- package/dist/chunks/chunk-SGZQDJRR.js +2 -0
- package/dist/chunks/{chunk-C5XTWMGB.js → chunk-UH2N3ZQW.js} +1 -1
- package/dist/chunks/chunk-UV2MZYDQ.js +2 -0
- package/dist/chunks/{chunk-TOGXTCZO.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-CGBNKHNZ.js → chunk-WXC25OPJ.js} +2 -2
- package/dist/chunks/{chunk-5WDJPHYY.js → chunk-XJQKSR52.js} +1 -1
- package/dist/data/grouping.d.ts +39 -15
- package/dist/data/grouping.js +21 -22
- package/dist/descriptive/basic.d.ts +130 -17
- package/dist/descriptive/basic.js +115 -14
- package/dist/descriptive/cov.d.ts +22 -12
- package/dist/descriptive/dataFrames.d.ts +39 -11
- package/dist/descriptive/dataFrames.js +14 -6
- package/dist/descriptive/factanal.d.ts +26 -6
- package/dist/descriptive/factanal.js +7 -3
- package/dist/descriptive/hist.d.ts +27 -6
- package/dist/descriptive/hist.js +9 -3
- package/dist/descriptive/missing.d.ts +13 -6
- package/dist/descriptive/missing.js +4 -2
- package/dist/descriptive/moments.d.ts +91 -13
- package/dist/descriptive/moments.js +66 -9
- package/dist/descriptive/omega.d.ts +28 -6
- package/dist/descriptive/omega.js +16 -4
- package/dist/descriptive/pivot.d.ts +22 -6
- package/dist/descriptive/pivot.js +7 -3
- package/dist/descriptive/quantile.d.ts +33 -5
- package/dist/descriptive/quantile.js +20 -2
- package/dist/descriptive/rank.d.ts +12 -2
- package/dist/descriptive/rank.js +2 -0
- package/dist/descriptive/table.d.ts +55 -7
- package/dist/descriptive/table.js +38 -4
- package/dist/descriptive.js +2 -2
- package/dist/distributions/arcsine.d.ts +40 -5
- package/dist/distributions/arcsine.js +35 -4
- package/dist/distributions/beta.d.ts +12 -0
- package/dist/distributions/beta.js +12 -0
- package/dist/distributions/binomial.d.ts +18 -0
- package/dist/distributions/binomial.js +18 -0
- package/dist/distributions/bvnorm.d.ts +4 -1
- package/dist/distributions/bvnorm.js +4 -1
- package/dist/distributions/cauchy.d.ts +24 -0
- package/dist/distributions/cauchy.js +24 -0
- package/dist/distributions/chisq.d.ts +18 -0
- package/dist/distributions/chisq.js +18 -0
- package/dist/distributions/exponential.d.ts +29 -1
- package/dist/distributions/exponential.js +24 -0
- package/dist/distributions/f.d.ts +18 -0
- package/dist/distributions/f.js +18 -0
- package/dist/distributions/gamma.d.ts +20 -0
- package/dist/distributions/gamma.js +18 -0
- package/dist/distributions/geometric.d.ts +24 -0
- package/dist/distributions/geometric.js +24 -0
- package/dist/distributions/hypergeometric.d.ts +24 -0
- package/dist/distributions/hypergeometric.js +24 -0
- package/dist/distributions/invgamma.d.ts +32 -4
- package/dist/distributions/invgamma.js +27 -3
- package/dist/distributions/kumaraswamy.d.ts +31 -3
- package/dist/distributions/kumaraswamy.js +31 -3
- package/dist/distributions/laplace.d.ts +36 -4
- package/dist/distributions/laplace.js +31 -3
- package/dist/distributions/logistic.d.ts +29 -1
- package/dist/distributions/logistic.js +24 -0
- package/dist/distributions/lognormal.d.ts +29 -1
- package/dist/distributions/lognormal.js +24 -0
- package/dist/distributions/multinomial.d.ts +7 -1
- package/dist/distributions/multinomial.js +2 -0
- package/dist/distributions/negbinomial.d.ts +29 -1
- package/dist/distributions/negbinomial.js +24 -0
- package/dist/distributions/normal.d.ts +11 -1
- package/dist/distributions/normal.js +6 -0
- package/dist/distributions/pareto.d.ts +36 -4
- package/dist/distributions/pareto.js +31 -3
- package/dist/distributions/poisson.d.ts +18 -0
- package/dist/distributions/poisson.js +18 -0
- package/dist/distributions/signrank.d.ts +24 -0
- package/dist/distributions/signrank.js +24 -0
- package/dist/distributions/summary.d.ts +20 -2
- package/dist/distributions/summary.js +4 -0
- package/dist/distributions/t.d.ts +18 -0
- package/dist/distributions/t.js +18 -0
- package/dist/distributions/triangular.d.ts +36 -4
- package/dist/distributions/triangular.js +31 -3
- package/dist/distributions/tukey.d.ts +15 -1
- package/dist/distributions/tukey.js +10 -0
- package/dist/distributions/uniform.d.ts +29 -1
- package/dist/distributions/uniform.js +24 -0
- package/dist/distributions/weibull.d.ts +29 -1
- package/dist/distributions/weibull.js +24 -0
- package/dist/distributions/wilcox.d.ts +24 -0
- package/dist/distributions/wilcox.js +24 -0
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +1 -1
- package/dist/entries/mixed.d.ts +1 -0
- package/dist/entries/mixed.js +2 -0
- package/dist/entries/numerics.d.ts +1 -1
- package/dist/entries/tests.js +1 -1
- package/dist/htest/agreement.d.ts +61 -23
- package/dist/htest/agreement.js +19 -9
- package/dist/htest/ansariTest.d.ts +8 -2
- package/dist/htest/aov.d.ts +43 -10
- package/dist/htest/aov.js +17 -3
- package/dist/htest/binomTest.d.ts +12 -2
- package/dist/htest/binomTest.js +2 -0
- package/dist/htest/brunnerMunzelTest.d.ts +9 -3
- package/dist/htest/brunnerMunzelTest.js +4 -2
- package/dist/htest/chisqTest.d.ts +19 -3
- package/dist/htest/cor.d.ts +20 -4
- package/dist/htest/effectSize.d.ts +70 -12
- package/dist/htest/effectSize.js +40 -7
- package/dist/htest/fisherTest.d.ts +9 -1
- package/dist/htest/fisherTest.js +2 -0
- package/dist/htest/groups.d.ts +5 -1
- package/dist/htest/ksTest.d.ts +20 -3
- package/dist/htest/leveneTest.d.ts +15 -4
- package/dist/htest/leveneTest.js +5 -2
- package/dist/htest/mantelhaenTest.d.ts +25 -3
- package/dist/htest/mantelhaenTest.js +15 -1
- package/dist/htest/mcnemarTest.d.ts +14 -4
- package/dist/htest/mcnemarTest.js +4 -2
- package/dist/htest/multipleComparisons.d.ts +173 -29
- package/dist/htest/multipleComparisons.js +123 -19
- package/dist/htest/normalityTests.d.ts +56 -9
- package/dist/htest/normalityTests.js +40 -6
- package/dist/htest/onewayTest.d.ts +32 -3
- package/dist/htest/onewayTest.js +10 -0
- package/dist/htest/pAdjust.d.ts +9 -1
- package/dist/htest/pAdjust.js +2 -0
- package/dist/htest/pairwise.d.ts +50 -5
- package/dist/htest/pairwise.js +25 -0
- package/dist/htest/poissonTest.d.ts +12 -2
- package/dist/htest/poissonTest.js +2 -0
- package/dist/htest/polycor.d.ts +29 -10
- package/dist/htest/power.d.ts +60 -6
- package/dist/htest/power.js +6 -0
- package/dist/htest/propTest.d.ts +13 -2
- package/dist/htest/propTest.js +2 -0
- package/dist/htest/pwr.d.ts +286 -36
- package/dist/htest/pwr.js +116 -15
- package/dist/htest/rankTests.d.ts +80 -12
- package/dist/htest/rankTests.js +11 -2
- package/dist/htest/tTest.d.ts +13 -3
- package/dist/htest/testFormula.js +6 -3
- package/dist/htest/trendTests.d.ts +29 -8
- package/dist/htest/trendTests.js +8 -4
- package/dist/htest/types.d.ts +14 -2
- package/dist/htest/varTest.d.ts +25 -8
- package/dist/htest/wilcoxTest.d.ts +10 -2
- package/dist/internal/dpq.d.ts +4 -0
- package/dist/internal/noncentral.d.ts +2 -0
- package/dist/internal/vectorize.d.ts +4 -0
- package/dist/linalg/basic.d.ts +39 -5
- package/dist/linalg/basic.js +15 -0
- package/dist/linalg/chol.d.ts +26 -5
- package/dist/linalg/chol.js +7 -0
- package/dist/linalg/eigen.d.ts +16 -7
- package/dist/linalg/eigen.js +6 -5
- package/dist/linalg/expm.d.ts +15 -5
- package/dist/linalg/expm.js +5 -3
- package/dist/linalg/kappa.d.ts +21 -1
- package/dist/linalg/kappa.js +16 -0
- package/dist/linalg/lu.d.ts +30 -6
- package/dist/linalg/lu.js +15 -3
- package/dist/linalg/matrix.d.ts +4 -0
- package/dist/linalg/norm.d.ts +16 -1
- package/dist/linalg/norm.js +9 -0
- package/dist/linalg/ops.d.ts +156 -35
- package/dist/linalg/ops.js +96 -15
- package/dist/linalg/qr.d.ts +87 -12
- package/dist/linalg/qr.js +31 -0
- package/dist/linalg/schur.d.ts +8 -2
- package/dist/linalg/schur.js +3 -1
- package/dist/linalg/solve.d.ts +42 -6
- package/dist/linalg/solve.js +22 -0
- package/dist/linalg/svd.d.ts +12 -2
- package/dist/linalg/svd.js +2 -0
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +3 -0
- package/dist/models/anovaSequential.d.ts +26 -4
- package/dist/models/anovaSequential.js +3 -1
- package/dist/models/aovEz.d.ts +29 -6
- package/dist/models/aovEz.js +5 -2
- package/dist/models/aovStrata.d.ts +13 -3
- package/dist/models/aovStrata.js +5 -1
- package/dist/models/carAnova.d.ts +9 -3
- package/dist/models/carAnova.js +4 -2
- package/dist/models/coxph.d.ts +33 -7
- package/dist/models/coxph.js +8 -3
- package/dist/models/formula.d.ts +26 -1
- package/dist/models/formula.js +125 -9
- package/dist/models/glm.d.ts +128 -21
- package/dist/models/glm.js +71 -14
- package/dist/models/glmAnova.d.ts +30 -5
- package/dist/models/glmAnova.js +15 -2
- package/dist/models/glmConfint.d.ts +16 -2
- package/dist/models/glmConfint.js +9 -1
- package/dist/models/glmFamily.d.ts +27 -5
- package/dist/models/lm.d.ts +77 -19
- package/dist/models/lm.js +22 -4
- package/dist/models/lmer.d.ts +162 -0
- package/dist/models/lmer.js +457 -0
- package/dist/models/mauchly.d.ts +20 -5
- package/dist/models/mauchly.js +7 -3
- 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 +17 -2
- package/dist/models/modelFrame.js +36 -21
- package/dist/models/modelMatrix.d.ts +33 -8
- package/dist/models/modelMatrix.js +21 -5
- package/dist/models/survival.d.ts +41 -9
- package/dist/models/survival.js +10 -4
- package/dist/numerics/deriv.d.ts +21 -6
- package/dist/numerics/deriv.js +16 -5
- package/dist/numerics/integrate.d.ts +37 -7
- package/dist/numerics/integrate.js +8 -2
- package/dist/numerics/interp.d.ts +63 -12
- package/dist/numerics/interp.js +30 -6
- package/dist/numerics/ode.d.ts +15 -5
- package/dist/numerics/ode.js +5 -3
- package/dist/numerics.js +2 -2
- package/dist/optim/optim.d.ts +32 -8
- package/dist/optim/optim.js +8 -4
- package/dist/random/beta.d.ts +8 -0
- package/dist/random/beta.js +8 -0
- package/dist/random/binomial.d.ts +16 -0
- package/dist/random/binomial.js +16 -0
- package/dist/random/continuous.d.ts +51 -0
- package/dist/random/continuous.js +51 -0
- package/dist/random/extra.d.ts +66 -6
- package/dist/random/extra.js +66 -6
- package/dist/random/gamma.d.ts +33 -0
- package/dist/random/gamma.js +33 -0
- package/dist/random/hyper.d.ts +8 -0
- package/dist/random/hyper.js +8 -0
- package/dist/random/poisson.d.ts +25 -0
- package/dist/random/poisson.js +25 -0
- package/dist/random/r2dtable.d.ts +2 -0
- package/dist/random/r2dtable.js +2 -0
- package/dist/random/rank.d.ts +16 -0
- package/dist/random/rank.js +16 -0
- package/dist/random/rng.d.ts +49 -6
- package/dist/random/rng.js +29 -2
- package/dist/random/sample.d.ts +10 -2
- package/dist/random/sample.js +5 -1
- package/dist/random/streams.d.ts +13 -0
- package/dist/random/streams.js +13 -0
- package/dist/rstats.js +14 -14
- package/dist/special/besselIK.d.ts +11 -3
- package/dist/special/besselIK.js +6 -2
- package/dist/special/besselJY.d.ts +6 -2
- package/dist/special/besselJY.js +6 -2
- package/dist/special/beta.d.ts +16 -2
- package/dist/special/beta.js +16 -2
- package/dist/special/choose.d.ts +13 -5
- package/dist/special/choose.js +13 -5
- package/dist/special/erf.d.ts +8 -3
- package/dist/special/erf.js +8 -3
- package/dist/special/extra.d.ts +30 -10
- package/dist/special/extra.js +25 -9
- package/dist/special/gamma.d.ts +18 -2
- package/dist/special/gamma.js +18 -2
- package/dist/special/log1p.d.ts +16 -7
- package/dist/special/log1p.js +16 -7
- package/dist/special/psigamma.d.ts +9 -3
- package/dist/special/psigamma.js +9 -3
- package/dist/special/rCompatible.d.ts +5 -1
- package/dist/special.js +2 -2
- package/dist/tests.js +12 -12
- package/llms.txt +13 -3
- package/package.json +5 -1
- package/dist/chunks/chunk-7GQMKH3Z.js +0 -2
- package/dist/chunks/chunk-AHHS6AC4.js +0 -3
- package/dist/chunks/chunk-ALM3VHFP.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-ALM3VHFP.js";import{a as k,b,c as F}from"./chunk-Y5PYRAYP.js";import{d as X,g as I}from"./chunk-EZWBRCJL.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
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { type DataFrame } from "../models/modelFrame.js";
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A level of a grouping factor (a label that is not missing).
|
|
4
|
+
*
|
|
5
|
+
* @category Data frames
|
|
6
|
+
*/
|
|
5
7
|
export type GroupingLevel = number | string | boolean;
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The group labels of the rows: one per row.
|
|
10
|
+
*
|
|
11
|
+
* @category Data frames
|
|
12
|
+
*/
|
|
13
|
+
export type GroupingLabels = readonly (number | string | boolean | null)[] | Float64Array;
|
|
14
|
+
/**
|
|
15
|
+
* Result of {@link tapply}.
|
|
16
|
+
*
|
|
17
|
+
* @category Data frames
|
|
18
|
+
*/
|
|
11
19
|
export interface TapplyResult<R> {
|
|
12
20
|
/** The number of levels of each factor. */
|
|
13
21
|
dim: number[];
|
|
@@ -30,9 +38,15 @@ export interface TapplyResult<R> {
|
|
|
30
38
|
* ```ts
|
|
31
39
|
* tapply([1, 2, 3, 4], ["b", "a", "b", "a"], (v) => v.length); // { dim: [2], dimnames: [["a", "b"]], values: [2, 2] }
|
|
32
40
|
* ```
|
|
41
|
+
*
|
|
42
|
+
* @category Data frames
|
|
43
|
+
*/
|
|
44
|
+
export declare function tapply<T, R>(x: readonly T[] | Float64Array, index: GroupingLabels | readonly GroupingLabels[], fun: (values: T[]) => R): TapplyResult<R>;
|
|
45
|
+
/**
|
|
46
|
+
* Options for {@link split}.
|
|
47
|
+
*
|
|
48
|
+
* @category Data frames
|
|
33
49
|
*/
|
|
34
|
-
export declare function tapply<T, R>(x: Cells<T>, index: GroupingLabels | readonly GroupingLabels[], fun: (values: T[]) => R): TapplyResult<R>;
|
|
35
|
-
/** Options for {@link split}. */
|
|
36
50
|
export interface SplitOptions {
|
|
37
51
|
/** With several factors, leave out the combinations without a row. Default `false`. */
|
|
38
52
|
drop?: boolean;
|
|
@@ -51,19 +65,28 @@ export interface SplitOptions {
|
|
|
51
65
|
* ```ts
|
|
52
66
|
* split([1, 2, 3], ["b", "a", "b"]); // Map { "a" => [2], "b" => [1, 3] }
|
|
53
67
|
* ```
|
|
68
|
+
*
|
|
69
|
+
* @category Data frames
|
|
54
70
|
*/
|
|
55
71
|
export declare function split(x: DataFrame, f: GroupingLabels | readonly GroupingLabels[], options?: SplitOptions): Map<string, DataFrame>;
|
|
56
72
|
export declare function split(x: Float64Array, f: GroupingLabels | readonly GroupingLabels[], options?: SplitOptions): Map<string, number[]>;
|
|
57
73
|
export declare function split<T>(x: readonly T[], f: GroupingLabels | readonly GroupingLabels[], options?: SplitOptions): Map<string, T[]>;
|
|
58
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* What the function of {@link aggregate} returns for a group: a number, an array of numbers, or named numbers.
|
|
76
|
+
*
|
|
77
|
+
* @category Data frames
|
|
78
|
+
*/
|
|
59
79
|
export type AggregateValue = number | readonly number[] | Readonly<Record<string, number>>;
|
|
60
80
|
/**
|
|
61
81
|
* The function applied to the values of each group, as a data frame. Equivalent to R's `aggregate()`.
|
|
62
82
|
*
|
|
63
83
|
* Formula form, `aggregate(formula, data, fun)`: `"y ~ g"`, `"y ~ g + h"`, `"cbind(y, z) ~ g"` or `". ~ g"` (every
|
|
64
|
-
* column not on the right)
|
|
65
|
-
*
|
|
66
|
-
*
|
|
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`.
|
|
67
90
|
*
|
|
68
91
|
* The result has the grouping columns first (with the labels as in the data), then one column per summarised column,
|
|
69
92
|
* and one row per non-empty combination of the groups (the first factor varying fastest). When `fun` returns k > 1
|
|
@@ -73,7 +96,8 @@ export type AggregateValue = number | readonly number[] | Readonly<Record<string
|
|
|
73
96
|
* ```ts
|
|
74
97
|
* aggregate("y ~ g", { y: [1, 2, 3, 4], g: ["b", "a", "b", "a"] }, mean); // { g: ["a", "b"], y: [3, 2] }
|
|
75
98
|
* ```
|
|
99
|
+
*
|
|
100
|
+
* @category Data frames
|
|
76
101
|
*/
|
|
77
102
|
export declare function aggregate(formula: string, data: DataFrame, fun: (values: number[]) => AggregateValue): DataFrame;
|
|
78
103
|
export declare function aggregate(x: DataFrame, by: Readonly<Record<string, GroupingLabels>>, fun: (values: number[]) => AggregateValue): DataFrame;
|
|
79
|
-
export {};
|
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);
|
|
@@ -91,6 +91,8 @@ const factorNames = (count, what) => Array.from({ length: count }, (_, j) => (co
|
|
|
91
91
|
* ```ts
|
|
92
92
|
* tapply([1, 2, 3, 4], ["b", "a", "b", "a"], (v) => v.length); // { dim: [2], dimnames: [["a", "b"]], values: [2, 2] }
|
|
93
93
|
* ```
|
|
94
|
+
*
|
|
95
|
+
* @category Data frames
|
|
94
96
|
*/
|
|
95
97
|
export function tapply(x, index, fun) {
|
|
96
98
|
const xs = Array.from(x);
|
|
@@ -164,21 +166,12 @@ function labelColumn(data, name) {
|
|
|
164
166
|
throw new TypeError(`column '${name}' must be an array`);
|
|
165
167
|
return col;
|
|
166
168
|
}
|
|
167
|
-
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
summands(node.right, out);
|
|
174
|
-
}
|
|
175
|
-
else if (node.type === "paren")
|
|
176
|
-
summands(node.arg, out);
|
|
177
|
-
else
|
|
178
|
-
throw new SyntaxError("invalid formula: the right-hand side must be grouping variables joined by '+'");
|
|
179
|
-
return out;
|
|
180
|
-
}
|
|
181
|
-
/** 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
|
+
*/
|
|
182
175
|
function aggregateFormula(formula, columns) {
|
|
183
176
|
if (typeof formula !== "string")
|
|
184
177
|
throw new TypeError("the formula must be a string");
|
|
@@ -186,22 +179,28 @@ function aggregateFormula(formula, columns) {
|
|
|
186
179
|
if (tilde < 0)
|
|
187
180
|
throw new SyntaxError("invalid formula: missing '~'");
|
|
188
181
|
const lhs = formula.slice(0, tilde).trim();
|
|
189
|
-
const
|
|
182
|
+
const { rhs } = parseFormula(`~ ${formula.slice(tilde + 1)}`);
|
|
190
183
|
const name = /^[A-Za-z.][A-Za-z0-9._]*$/;
|
|
191
184
|
let values;
|
|
192
|
-
if (lhs
|
|
193
|
-
values = columns.filter((c) => !groups.includes(c));
|
|
194
|
-
else {
|
|
185
|
+
if (lhs !== ".") {
|
|
195
186
|
const m = /^cbind\s*\((.*)\)$/s.exec(lhs);
|
|
196
187
|
values = m === null ? [lhs] : m[1].split(",").map((s) => s.trim());
|
|
197
188
|
if (values.some((v) => !name.test(v) || v === ".")) {
|
|
198
189
|
throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'");
|
|
199
190
|
}
|
|
200
191
|
}
|
|
201
|
-
|
|
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 };
|
|
202
200
|
}
|
|
203
201
|
function aggregateRows(valueNames, valueCols, groupNames, groupCols, keep, fun) {
|
|
204
|
-
|
|
202
|
+
// (y ~ 1: no grouping column, one group of all the rows)
|
|
203
|
+
const n = groupCols[0]?.length ?? valueCols[0]?.length ?? 0;
|
|
205
204
|
valueNames.forEach((v, j) => {
|
|
206
205
|
if (valueCols[j].length !== n)
|
|
207
206
|
throw new RangeError(`variable lengths differ (found for '${v}')`);
|