@numero-uno-jpn/rstats 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.ja.md +9 -9
  3. package/README.md +9 -9
  4. package/dist/chunks/chunk-6R7YDHA2.js +2 -0
  5. package/dist/chunks/chunk-AFKYWGKN.js +2 -0
  6. package/dist/chunks/{chunk-QNAIK4PY.js → chunk-ANYGLFT4.js} +2 -2
  7. package/dist/chunks/chunk-BI5RSUZ2.js +2 -0
  8. package/dist/chunks/chunk-J3SNI7KY.js +2 -0
  9. package/dist/chunks/{chunk-Y4IZV7XK.js → chunk-JCZAB6C5.js} +2 -2
  10. package/dist/chunks/{chunk-7NK4SA6B.js → chunk-MVG5LUZU.js} +2 -2
  11. package/dist/chunks/chunk-PTPPP4TI.js +2 -0
  12. package/dist/chunks/{chunk-TPC6MTYC.js → chunk-QNQJA6KZ.js} +2 -2
  13. package/dist/chunks/{chunk-AJYQNFXK.js → chunk-SXSJXDD3.js} +2 -2
  14. package/dist/chunks/{chunk-ZWJ42QN6.js → chunk-UIOAWLAN.js} +1 -1
  15. package/dist/chunks/{chunk-NOCEAM44.js → chunk-XYXHHF5L.js} +1 -1
  16. package/dist/chunks/{chunk-2JCIB5H2.js → chunk-YKN6OGJL.js} +2 -2
  17. package/dist/chunks/{chunk-UGUQYWRQ.js → chunk-ZW52Z3GY.js} +1 -1
  18. package/dist/chunks/{chunk-DRNMIEYH.js → chunk-ZYA4ISAT.js} +1 -1
  19. package/dist/descriptive.js +2 -2
  20. package/dist/distributions.js +2 -2
  21. package/dist/entries/distributions.d.ts +1 -0
  22. package/dist/entries/distributions.js +1 -0
  23. package/dist/entries/special.d.ts +1 -0
  24. package/dist/entries/special.js +1 -0
  25. package/dist/entries/tests.d.ts +1 -1
  26. package/dist/entries/tests.js +1 -1
  27. package/dist/htest/ansariTest.d.ts +18 -1
  28. package/dist/htest/ansariTest.js +181 -8
  29. package/dist/htest/chisqTest.d.ts +34 -2
  30. package/dist/htest/chisqTest.js +140 -37
  31. package/dist/htest/core/ansari.d.ts +7 -0
  32. package/dist/htest/core/ansari.js +65 -0
  33. package/dist/htest/core/simulate.d.ts +2 -0
  34. package/dist/htest/core/simulate.js +16 -0
  35. package/dist/htest/fisherTest.d.ts +12 -1
  36. package/dist/htest/fisherTest.js +53 -7
  37. package/dist/linalg.js +2 -2
  38. package/dist/numerics.js +2 -2
  39. package/dist/random/r2dtable.d.ts +26 -0
  40. package/dist/random/r2dtable.js +153 -0
  41. package/dist/rstats.js +3 -2
  42. package/dist/special/log1p.d.ts +53 -0
  43. package/dist/special/log1p.js +93 -0
  44. package/dist/special.js +2 -2
  45. package/dist/tests.js +3 -2
  46. package/package.json +1 -1
  47. package/dist/chunks/chunk-7JVSDGQQ.js +0 -2
  48. package/dist/chunks/chunk-NAYDS7CL.js +0 -2
  49. package/dist/chunks/chunk-XM2TVD63.js +0 -2
@@ -0,0 +1,53 @@
1
+ /**
2
+ * log(1 + x) - x, accurate for small |x| (where log1p(x) - x would cancel). As `log1pmx` in R's C API (Rmath.h).
3
+ *
4
+ * @param x A number >= -1.
5
+ * @returns log(1 + x) - x; `-Infinity` at x = -1 and x = Infinity, `NaN` for x < -1.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * log1pmx(1e-5); // -4.9999666669166655e-11
10
+ * ```
11
+ */
12
+ export declare function log1pmx(x: number): number;
13
+ /**
14
+ * lgamma(1 + x) = log|Gamma(1 + x)|, accurate near x = 0 and x = 1, where it is near 0. As `lgamma1p` in R's C
15
+ * API (Rmath.h).
16
+ *
17
+ * @param x A number.
18
+ * @returns log|Gamma(1 + x)|; `Infinity` at the poles (x a negative integer) and at x = Infinity, `NaN` for
19
+ * x = -Infinity.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * lgamma1p(1e-10); // -5.7721566481928616e-11 (lgamma(1 + 1e-10) keeps only about 6 digits)
24
+ * ```
25
+ */
26
+ export declare function lgamma1p(x: number): number;
27
+ /**
28
+ * log(1 - exp(-x)) for x >= 0, accurate for both small and large x. As `log1mexp` in R's C API (Rmath.h) and the DPQ
29
+ * package; note the sign of the argument.
30
+ *
31
+ * @param x A number >= 0.
32
+ * @returns log(1 - exp(-x)); `-Infinity` at x = 0, 0 at x = Infinity, `NaN` for x < 0.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * log1mexp(1e-10); // -23.025850929990458
37
+ * ```
38
+ */
39
+ export declare function log1mexp(x: number): number;
40
+ /**
41
+ * log(1 + exp(x)), without overflow for large x and accurate for very negative x. As `log1pexp` in R's C API
42
+ * (Rmath.h) and the DPQ package.
43
+ *
44
+ * @param x A number.
45
+ * @returns log(1 + exp(x)); 0 at x = -Infinity, `Infinity` at x = Infinity.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * log1pexp(800); // 800
50
+ * log1pexp(-40); // 4.248354255291589e-18
51
+ * ```
52
+ */
53
+ export declare function log1pexp(x: number): number;
@@ -0,0 +1,93 @@
1
+ // log1p-type functions of R's C API (Rmath.h: log1pmx, lgamma1p, log1mexp, log1pexp), which R does not export to R
2
+ // code; the definitions are those of Rmath and the DPQ package. The kernels are the ones rStats.js uses internally
3
+ // (log1pmx: xsf's series, src/special/log1pmx.ts; lgamma1p: src/special/gamma.ts; log(1 - exp(x)):
4
+ // src/internal/ddexp.ts); this file adds the special values and domains. log1pexp follows the switching points of
5
+ // Maechler (2012), "Accurately computing log(1 - exp(-|a|))", the Rmpfr package vignette.
6
+ import { log1mExp } from "../internal/ddexp.js";
7
+ import { lgamma1p as lgamma1pKernel } from "./gamma.js";
8
+ import { log1pmx as log1pmxKernel } from "./log1pmx.js";
9
+ /**
10
+ * log(1 + x) - x, accurate for small |x| (where log1p(x) - x would cancel). As `log1pmx` in R's C API (Rmath.h).
11
+ *
12
+ * @param x A number >= -1.
13
+ * @returns log(1 + x) - x; `-Infinity` at x = -1 and x = Infinity, `NaN` for x < -1.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * log1pmx(1e-5); // -4.9999666669166655e-11
18
+ * ```
19
+ */
20
+ export function log1pmx(x) {
21
+ if (Number.isNaN(x) || x < -1)
22
+ return NaN;
23
+ if (x === -1 || x === Infinity)
24
+ return -Infinity;
25
+ return log1pmxKernel(x);
26
+ }
27
+ /**
28
+ * lgamma(1 + x) = log|Gamma(1 + x)|, accurate near x = 0 and x = 1, where it is near 0. As `lgamma1p` in R's C
29
+ * API (Rmath.h).
30
+ *
31
+ * @param x A number.
32
+ * @returns log|Gamma(1 + x)|; `Infinity` at the poles (x a negative integer) and at x = Infinity, `NaN` for
33
+ * x = -Infinity.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * lgamma1p(1e-10); // -5.7721566481928616e-11 (lgamma(1 + 1e-10) keeps only about 6 digits)
38
+ * ```
39
+ */
40
+ export function lgamma1p(x) {
41
+ if (Number.isNaN(x) || x === -Infinity)
42
+ return NaN;
43
+ if (x === Infinity)
44
+ return Infinity;
45
+ if (x <= -1 && x === Math.floor(x))
46
+ return Infinity;
47
+ return lgamma1pKernel(x);
48
+ }
49
+ /**
50
+ * log(1 - exp(-x)) for x >= 0, accurate for both small and large x. As `log1mexp` in R's C API (Rmath.h) and the DPQ
51
+ * package; note the sign of the argument.
52
+ *
53
+ * @param x A number >= 0.
54
+ * @returns log(1 - exp(-x)); `-Infinity` at x = 0, 0 at x = Infinity, `NaN` for x < 0.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * log1mexp(1e-10); // -23.025850929990458
59
+ * ```
60
+ */
61
+ export function log1mexp(x) {
62
+ if (Number.isNaN(x) || x < 0)
63
+ return NaN;
64
+ if (x === 0)
65
+ return -Infinity;
66
+ if (x === Infinity)
67
+ return 0;
68
+ return log1mExp(-x);
69
+ }
70
+ /**
71
+ * log(1 + exp(x)), without overflow for large x and accurate for very negative x. As `log1pexp` in R's C API
72
+ * (Rmath.h) and the DPQ package.
73
+ *
74
+ * @param x A number.
75
+ * @returns log(1 + exp(x)); 0 at x = -Infinity, `Infinity` at x = Infinity.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * log1pexp(800); // 800
80
+ * log1pexp(-40); // 4.248354255291589e-18
81
+ * ```
82
+ */
83
+ export function log1pexp(x) {
84
+ if (Number.isNaN(x))
85
+ return NaN;
86
+ if (x <= -37)
87
+ return Math.exp(x); // log1p(e) = e to double precision
88
+ if (x <= 18)
89
+ return Math.log1p(Math.exp(x));
90
+ if (x <= 33.3)
91
+ return x + Math.exp(-x);
92
+ return x;
93
+ }
package/dist/special.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! rStats.js 0.6.1 | 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 z,b as U,c as T,d as Et,e as Rt}from"./chunks/chunk-2JCIB5H2.js";import{A as Tt,B as nt,C as gt,b as x,c as Ct,h as Mt,k as g,l as F,m as Z,n as L,o as Q,p as $,q as bt,u as tt,v as pt,w as Nt,y as et}from"./chunks/chunk-QNAIK4PY.js";import{b as j,d as q,f as R,g as E,h as ht,i as O,k as D}from"./chunks/chunk-UGUQYWRQ.js";var it=30;function V(t){return t===Math.floor(t)}function dt(t,e){if(V(t))return t;if(t>=0)return z(t)?t:U(t);let n=e-1-t;return z(n)?t:e-1-U(n)||-0}function It(t,e){let n=[1,0];for(let r=0;r<e;r++)n=O(E(n,j(t,-r)),[r+1,0]);return n}function rt(t,e){return Math.min(t,e)>=1&&Math.max(t,e)<2**52?gt(t,e):[nt(t,e),0]}function yt(t,e){if(t<0){let f=q(D(j(e,-t)),rt(-t,e+1));return{log:[-f[0],-f[1]],sign:e%2===0?1:-1}}if(V(t)&&t<e)return;if(t>=e-1){let f=q(D(j(t,1)),rt(t-e+1,e+1));return{log:[-f[0],-f[1]],sign:1}}let n=g(t),[r,i]=j(t,1),[o,s]=j(e,-t),a=i===0&&s===0?0:T(r+o),c=(i===0?0:i*(T(r)-a))+(s===0?0:s*(T(o)-a));return{log:q(rt(r,o),[Math.log(Math.abs(n)/Math.PI)+c,0]),sign:(e%2===0?-1:1)*Math.sign(n)}}function Jt(t,e,n){if(Number.isNaN(t)||Number.isNaN(e))return NaN;let r=n?.rCompatible??!0;if(e=U(e),e<0)return 0;if(e===0)return 1;if(!Number.isFinite(e))return r&&t>=0&&t<1/0?0:NaN;if(!Number.isFinite(t))return r&&e>=it?NaN:t>0||e%2===0?1/0:-1/0;if(e<it){let s=r&&!V(t)&&!z(t);if(s&&t>=0&&U(t)<e)return 0;let a=It(t,e),c=a[0]+a[1];if(Number.isFinite(c))return V(t)||s?Math.round(c):c;let l=1;for(let f=0;f<e;f++)l=l*(t-f)/(f+1);return l}if(r&&(t=dt(t,e),Object.is(t,-0)))return e%2===0?0:-0;let i=yt(t,e);if(i===void 0)return 0;let o=i.sign*Math.exp(i.log[0])*(1+i.log[1]);return V(t)&&Number.isFinite(o)?Math.round(o):o}function Yt(t,e,n){if(Number.isNaN(t)||Number.isNaN(e))return NaN;let r=n?.rCompatible??!0;if(e=U(e),e<0)return-1/0;if(e===0)return 0;if(!Number.isFinite(e))return r&&t>=0&&t<1/0?-1/0:NaN;if(!Number.isFinite(t))return r&&e>=2?NaN:1/0;if(r&&e>=2&&(t=dt(t,e)),e<it){let o=It(t,e),s=Math.abs(o[0]+o[1]);if(s>1e-300&&s<1e300){let c=D(o[0]<0?[-o[0],-o[1]]:o);return c[0]+c[1]}if(s===0)return-1/0;let a=-L(e+1);for(let c=0;c<e;c++)a+=Math.log(Math.abs(t-c));return a}let i=yt(t,e);return i===void 0?-1/0:V(t)&&i.log[0]<36?Math.log(Math.round(Math.exp(i.log[0])*(1+i.log[1]))):i.log[0]+i.log[1]}function Kt(t){return F(t+1)}function Bt(t){return Math.abs(t)<=.2?Q(t):L(t+1)}var Pt=22250738585072014e-324;function k(t,e,n){if(t<10)return Math.pow(e/2,t)/F(t+1)*n;let r=e/2,i=tt(t,r,!1);if(i>=Pt&&r<700){let s=i*Math.exp(r)*n;if(Math.abs(s)>=Pt)return s}let o=tt(t,r,!0)+r+Math.log(Math.abs(n));return Math.sign(n)*Math.exp(o)}var _=Number.EPSILON,v=1e6;function qt(t){return Math.expm1(Q(t))}function Ot(t,e){let n=qt(t),r=qt(-t),i=Math.log(e/2),o=Math.exp(t*i),s=-i*t,a=Math.abs(t)<_?1:g(t)/(t*Math.PI),c=Math.abs(s)<_?1:Math.sinh(s)/s,l=Math.abs(t)<_?-.5772156649015329:.5/t*(n-r)*a,f=(2+n+r)*a/2,u=(n+1)/(2*o),m=(1+r)*o/2,M=(Math.cosh(s)*l+c*-i*f)/a,b=u,h=1,w=h*M,S=h*b;for(let I=1;I<v&&(M=(I*M+u+m)/(I*I-t*t),u/=I-t,m/=I+t,b=u-I*M,h*=e*e/(4*I),w+=h*M,S+=h*b,!(Math.abs(h*M)<Math.abs(w)*_));I++);return[w,2*S/e]}function Qt(t,e){let n=Math.sqrt(Number.MIN_VALUE*4503599627370496),r=n,i=n,o=0;for(let s=1;s<v;s++){let a=2*(t+s)/e;r=a+1/r,o=a+o,r===0&&(r=n),o===0&&(o=n),o=1/o;let c=r*o;if(i*=c,Math.abs(c-1)<=2*_)break}return i}function Ut(t,e){let n=t*t-.25,r=2*(e+1),i=1/r,o=i,s=i,a=0,c=1,l=-n,f=l,u=1+f*s;for(let b=2;b<v;b++){n-=2*(b-1),r+=2,i=1/(r+n*i),s*=r*i-1,o+=s;let h=(a-(r-2)*c)/n;if(a=c,c=h,l*=-n/b,f+=l*h,u+=f*s,h<_&&(l*=h,a/=h,c/=h),Math.abs(f*s)<Math.abs(u)*_)break}let m=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/u;return[M,M*m]}function G(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function St(t,e){let n=Math.round(t),r=t-n,i,o;if(r===-.5)i=o=Math.sqrt(Math.PI/(2*e));else if(e<=2){let[a,c]=Ot(r,e),l=Math.exp(e);i=a*l,o=c*l}else[i,o]=Ut(r,e);let s=0;for(let a=1;a<=n;a++){let c=2*(r+a)/e,l=Math.log2(Math.abs(o))+Math.log2(c);if(l>900&&Number.isFinite(l)){let u=Math.ceil(l-800);i=G(i,-u),o=G(o,-u),s+=u}let f=c*o+i;i=o,o=f}return{k:i,k1:o,exp2:s}}function Vt(t,e){let n=e*e/4,r=1,i=0;for(let o=1;o<v&&(i+=r,r*=n/o,r/=o+t,!(Math.abs(r)<=_*Math.abs(i)));o++);return k(t,e,i+r)}function Xt(t,e,n){if(t===0||!Number.isFinite(t))return t;let r=t,i=e,o=n>0?700:-700,s=Math.exp(o);for(;Math.abs(n)>700;){n-=o,r*=s;let a=Math.floor(Math.log2(Math.abs(r)));r=G(r,-a),i+=a}return G(r*Math.exp(n),i)}function ot(t,e,n){let r=t.ex+n;return r===0?G(t.m,t.e2):Xt(t.m,t.e2,r*e)}function Zt(t,e){if(t===.5)return{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(t>0&&e/t<.25)return{m:Vt(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<_*10&&e>100){let a=4*t*t,c=8*e,l=a-1,f=c,u=1-l/f;return l*=a-9,f*=c*2,u+=l/f,l*=a-25,f*=c*3,u-=l/f,{m:u/Math.sqrt(2*e*Math.PI),e2:0,ex:1}}let{k:r,k1:i,exp2:o}=St(t,e),s=Qt(t,e);return{m:1/(e*(r*s+i)),e2:-o,ex:1}}function jt(t,e){let n=4*t*t,r=8*e,i=(n-1)/r,o=i*(n-9)/(2*r),s=o*(n-25)/(3*r),a=s*(n-49)/(4*r),c=1+i+o+s;if(Math.abs(a)<_*Math.abs(c))return{m:c*Math.sqrt(Math.PI)/Math.sqrt(2*e),e2:0,ex:-1};let{k:l,exp2:f}=St(t,e);return{m:l,e2:f,ex:-1}}function Gt(t,e,n={}){let r=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let i=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?g(i)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return r?0:1/0;let s=r?-1:0,a=ot(Zt(i,t),t,s);if(!o)return a;let c=jt(i,t);return a+ot({...c,m:2/Math.PI*g(i)*c.m},t,s)}function Ht(t,e,n={}){let r=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let i=Math.abs(e);return t===0?1/0:t===1/0?0:ot(jt(i,t),t,r?1:0)}var y=Number.EPSILON;function J(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function Ft(t,e,n,r,i){let o=r,s=i,a=0;for(let c=1;c<=n;c++){let l=2*(t+c)/e,f=Math.log2(Math.abs(s))+Math.log2(l);if(f>900&&Number.isFinite(f)){let m=Math.ceil(f-800);o=J(o,-m),s=J(s,-m),a+=m}let u=l*s-o;o=s,s=u}return{y:o,y1:s,e2:a}}var Y=1e6,d=Math.sqrt(22250738585072014e-324),Wt=Number.MAX_VALUE;function Dt(t){return Math.expm1(Q(t))}function X(t){return g(.5-Math.abs(t%2))}function Lt(t,e){let n=-(e/2)*(e/2),r=1,i=0;for(let o=1;o<Y&&(i+=r,r*=n/(o*(o+t)),!(Math.abs(r)<=y*Math.abs(i)));o++);return k(t,e,i+r)}function $t(t,e){let n=Math.log(e/2),r=0,i=t>=170||709.78/t<Math.abs(n),o;if(i){let m=L(t);if(n=t*n,o=m-Math.log(Math.PI)-n,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,r=M}o=-Math.exp(o)}else{let m=F(t);n=Math.pow(e/2,t),Wt*n<m&&(m*=2**-1e3,r=1e3),o=-m/(Math.PI*n)}let s=-(e/2)*(e/2),a=1,c=0;for(let m=1;m<Y&&(c+=a,a*=s/(m*(m-t)),!(Math.abs(a)<=y*Math.abs(c)));m++);let l=(c+a)*o,f;if(!i)f=F(-t)*X(t)*n/Math.PI;else{let m=Z(-t);f=Math.exp(m.value+n)*m.sign/Math.PI}a=1;let u=0;for(let m=1;m<Y&&(u+=a,a*=s/(m*(m+t)),!(Math.abs(a)<=y*Math.abs(u)));m++);return u+=a,l-=J(f*u,-r),{m:l,e2:r}}function zt(t,e){let n=1,r=0,i=1,o=8*e,s=1,a=4*t*t,c=1,l=!0;do{c*=(a-s*s)/(i*o),r+=c,i+=1,s+=2;let f=(s*s-a)/(i*o);l=Math.abs(f)<.5,c*=f,n+=c,i+=1,s+=2}while(Math.abs(c)>2*y*n&&l);return l?{p:n,q:r}:void 0}function kt(t,e){let n=Dt(t),r=Dt(-t),i=g(t),o=g(t/2),s=Math.pow(e/2,t),a=Math.log(e/2),c=-a*t,l=Math.abs(c)<y?1:Math.sinh(c)/c,f=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,u=t===0?-.5772156649015329:(n-r)/((1+n)*(1+r)*2*t),m=(2+n+r)/((1+n)*(1+r)*2),M=Math.abs(t)<y?1/Math.PI:t/i,b=(u*Math.cosh(c)-m*a*l)*2*M,h=M/(s*(1+r)),w=M*s/(1+n),S=b+f*w,I=h,A=1,K=A*S,H=A*I,W=t*t,p=-e*e/4;for(let N=1;N<Y&&(b=(N*b+h+w)/(N*N-W),h/=N-t,w/=N+t,S=b+f*w,I=h-N*S,A*=p/N,K+=A*S,H+=A*I,!(Math.abs(A*S)<Math.abs(K)*y));N++);return[-K,-2*H/e]}function vt(t,e){let n=[d,0],r=[d,0],i=[0,0],o=1,s=[e,0];for(let a=1;a<Y*100;a++){let c=j(t,a),l=O([2*c[0],2*c[1]],s);n=R(l,O([1,0],n)),i=R(l,i),n[0]===0&&(n=[d,0]),i[0]===0&&(i=[d,0]),i=O([1,0],i);let f=E(n,i);if(r=E(r,f),i[0]<0&&(o=-o),Math.abs(f[0]-1+f[1])<y*y)break}return{fv:-(r[0]+r[1]),sign:o}}function wt(t,e){if(e>30)return vt(t,e);let n=d,r=d,i=0,o=1;for(let s=1;s<Y*100;s++){let a=2*(t+s)/e;n=a-1/n,i=a-i,n===0&&(n=d),i===0&&(i=d),i=1/i;let c=n*i;if(r*=c,i<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-r,sign:o}}function _t(t,e){let n=-.5/e,r=1,i=n,o=r,s=t*t,a=(.25-s)/e,c=2*e,l=2,f=i*i+1;o=l+a*i/f,i=c+a/f;let u=c,m=l;Math.abs(i)+Math.abs(o)<d&&(i=d),Math.abs(u)+Math.abs(m)<d&&(u=d),f=u*u+m*m,u=u/f,m=-m/f;let M=i*u-o*m,b=o*u+i*m;f=n,n=f*M-r*b,r=f*b+r*M;for(let h=2;h<Y&&(a=h-.5,a*=a,a-=s,l+=2,f=i*i+o*o,i=c+a*i/f,o=l-a*o/f,u=c+a*u,m=l+a*m,Math.abs(i)+Math.abs(o)<d&&(i=d),Math.abs(u)+Math.abs(m)<d&&(u=d),f=u*u+m*m,u=u/f,m=-m/f,M=i*u-o*m,b=o*u+i*m,f=n,n=f*M-r*b,r=f*b+r*M,!(Math.abs(M-1)+Math.abs(b)<2*y));h++);return{p:n,q:r}}function xt(t,e){let n=1,r=4*t*t,i=2*e;return i*=i,n+=(r-1)/(2*i),n+=3*(r-1)*(r-9)/(i*i*8),n+=15*(r-1)*(r-9)*(r-25)/(i*i*i*8*6),Math.sqrt(n*2/(Math.PI*e))}function te(t,e){let n=4*t*t,r=4*e,i=r*r,o=0;return o+=(n-1)/(2*r),r*=i,o+=(n-1)*(n-25)/(6*r),r*=i,o+=(n-1)*(n*n-114*n+1073)/(5*r),r*=i,o+=(n-1)*(5*n*n*n-1535*n*n+54703*n-375733)/(14*r),o}function ee(t,e){let n=xt(t,e),r=te(t,e),i=Math.cos(e),o=Math.sin(e),s=X(t/2+.25),a=g(t/2+.25),c=Math.sin(r),l=Math.cos(r),f=(c*(i*s+o*a)+l*(o*s-i*a))*n;return{j:(l*(i*s+o*a)-c*(o*s-i*a))*n,y:f}}function st(t,e,n){let r=Math.round(t),i=t-r,o=2/(e*Math.PI);if(!n&&(e<5||t>e*e/4))return{j:Lt(t,e),y:{m:NaN,e2:0}};if(e<1&&i!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:Lt(t,e),y:$t(t,e)};if(Math.max(t,1)<e*.011048543456039806){let p=ee(t,e);return{j:p.j,y:{m:p.y,e2:0}}}if(e>8){let p=zt(t,e);if(p!==void 0){let N=(t/2+.25)%2,P=Math.sin(e),C=Math.cos(e),B=g(N),ct=X(N),lt=P*ct-B*C,ut=C*ct+P*B,mt=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:mt*(p.p*ut-p.q*lt),y:{m:mt*(p.p*lt+p.q*ut),e2:0}}}}if(e<=2){let[p,N]=kt(i,e),P=Ft(i,e,r,p,N),{fv:C}=wt(t,e);return{j:J(o/(P.y*C-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let{fv:s,sign:a}=wt(t,e);if(e>=t&&t>2){let{p,q:N}=_t(t,e),P=t/e-s,C=(p-P)/N;C===0&&(C=t*y/e);let B=a*Math.sqrt(o/(N+C*(p-P)));return{j:B,y:{m:C*B,e2:0}}}let c=d,l=s*a*c,f=a*c,u=0;for(let p=r;p>0;p--){let N=2*(i+p)/e;Math.abs(f)>2**900&&(l*=2**-900,f*=2**-900,u+=900);let P=N*f-l;P===0&&(P=l*y/2),l=f,f=P}let m=J(a*c/f,-u),M=l/f,{p:b,q:h}=_t(i,e),w=i/e-M,S=(b-w)/h;S===0&&(S=i*y/e);let I=Math.sign(f)*Math.sqrt(o/(h+S*(b-w))),A=I*m,K=S*I,H=K*(i/e-b-h/S);if(!n)return{j:A,y:{m:NaN,e2:0}};let W=Ft(i,e,r,K,H);return{j:A,y:{m:W.y,e2:W.e2}}}function ne(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),r=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:r?g(n)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!r){let o=st(n,t,!1).j;return e<0&&n%2===1?-o:o}let i=st(n,t,!0);return X(n)*i.j-J(g(n)*i.y.m,i.y.e2)}function re(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),r=e<0;if(t===0){if(!r)return-1/0;let a=X(n);return a===0?0:a>0?-1/0:1/0}if(t===1/0)return 0;let i=st(n,t,!0);if(!r)return J(i.y.m,i.y.e2);let o=X(n),s=g(n);return(s!==0?s*i.j:0)+(o===0?0:J(o*i.y.m,i.y.e2))}function ie(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let n=L(e),r=F(e),i=l=>{let f=et(e,t,l,!1),u=r*f;if(Number.isFinite(r)&&f>At&&Number.isFinite(u)&&u>At)return[u,Math.log(u)];let m=n+et(e,t,l,!0);return m<710&&m>-746&&t>0&&(l?t<e:t>e)?oe(t,e,l):[Math.exp(m),m]},[o,s]=i(!0),[a,c]=i(!1);return{lower:o,upper:a,logLower:s,logUpper:c}}var At=22250738585072014e-324;function oe(t,e,n){let r=q(ht(D([t,0]),e),[-t,0]);n?r=q(r,D([pt(e,t)/e,0])):r=q(r,D([Nt(e,t),0]));let i=r[0]+r[1];return[r[0]>-708?Math.exp(r[0])*(1+r[1]):Math.exp(i),i]}function at(t){return Number.isNaN(t)||t<0||t>2?NaN:-Mt(t/2)*Math.SQRT1_2}function se(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,n=Math.abs(t);if(n>=.5)return e*at(1-n);if(n<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let r=at(1-n);for(let i=0;i<3;i++){let o=(x(r)-n)/(1.1283791670955126*Math.exp(-r*r));if(r-=o,Math.abs(o)<=1e-17*r)break}return e*r}function ae(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let n=e===Math.floor(e);return t===Math.floor(t)&&n&&e>t?0:!Number.isFinite(t)||!Number.isFinite(e)?he(t,e):n&&e<=1e3?fe(t,e):ce(t,e)}function fe(t,e){let n=[1,0];for(let r=0;r<e;r++){let i=j(t,-r),o=n[0]*i[0];if(!Number.isFinite(o)){let s=Math.sign(o);for(let a=r+1;a<e;a++)t-a<0&&(s=-s);return s*(1/0)}n=Math.abs(n[0])>1e290||Math.abs(i[0])>1e290?[(n[0]+n[1])*(i[0]+i[1]),0]:E(n,i)}return n[0]+n[1]}function ce(t,e){let[n,r]=j(t,-e);if(n+1<=0)return le(t,n,r);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let i;if(n>=15){if(e*Math.log(n+1)>720)return 1/0;let o=j(t,-n),s=R(E(o,D([t,0])),bt(n,[t,0]));s=q(s,[$(t)-$(n),0]),i=Math.sqrt(t/n)*Math.exp(s[0])*(1+s[1])}else if(t<30)i=F(t+1)/F(n+1);else{if(L(t+1)-L(n+1)>720)return 1/0;let o=R(ft(t+1),D([F(n+1),0]));i=Math.exp(o[0])*(1+o[1])}return r!==0&&Number.isFinite(i)&&i!==0&&(i*=Math.exp(-r*T(n+1))),i}function le(t,e,n){let r=q(j(e,1),[n,0]),i=g(r[0])+g(r[0]+.5)*Math.PI*r[1];if(i===0)return 0;let o=Math.sign(i),s=q(R(D([Math.abs(i),0]),me),[-n*T(-e),0]);if(L(t+1)+L(-e)+s[0]>720)return o*(1/0);let a=q(q(ft(t+1),ft(-e)),s);return o*Math.exp(a[0])*(1+a[1])}var ue=[.9189385332046728,-38782941580672414e-33],me=[1.1447298858494002,10265951162707826e-33];function ft(t){if(t<15)return D([F(t),0]);let e=R(E(j(t,-.5),D([t,0])),[t,0]);return q(q(e,ue),[$(t),0])}function he(t,e){let n=Z(t+1),r=Z(t-e+1);return n.sign*r.sign*Math.exp(n.value-r.value)}export{Gt as besselI,ne as besselJ,Ht as besselK,re as besselY,Tt as beta,Jt as choose,T as digamma,x as erf,Ct as erfc,at as erfcinv,se as erfinv,Kt as factorial,F as gamma,ie as gammainc,nt as lbeta,Yt as lchoose,Bt as lfactorial,L as lgamma,ae as perm,Rt as psigamma,Et as trigamma};
1
+ /*! rStats.js 0.7.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{e as ht}from"./chunks/chunk-BI5RSUZ2.js";import{a as wt,b as Lt,c as _t,d as Et}from"./chunks/chunk-J3SNI7KY.js";import{c as G,d as St,e as jt}from"./chunks/chunk-YKN6OGJL.js";import{B as Dt,C as Ft,b as $,c as qt,h as ft,k as d,l as q,m as U,n as _,o as C,p as Z,q as ct,u as z,v as lt,w as mt,x as ut,z as v}from"./chunks/chunk-ANYGLFT4.js";import{b as E,d as j,f as T,g as J,h as at,i as O,k as L}from"./chunks/chunk-ZW52Z3GY.js";var Mt=22250738585072014e-324;function W(t,e,n){if(t<10)return Math.pow(e/2,t)/q(t+1)*n;let s=e/2,r=z(t,s,!1);if(r>=Mt&&s<700){let a=r*Math.exp(s)*n;if(Math.abs(a)>=Mt)return a}let o=z(t,s,!0)+s+Math.log(Math.abs(n));return Math.sign(n)*Math.exp(o)}var D=Number.EPSILON,H=1e6;function pt(t){return Math.expm1(C(t))}function Tt(t,e){let n=pt(t),s=pt(-t),r=Math.log(e/2),o=Math.exp(t*r),a=-r*t,i=Math.abs(t)<D?1:d(t)/(t*Math.PI),c=Math.abs(a)<D?1:Math.sinh(a)/a,l=Math.abs(t)<D?-.5772156649015329:.5/t*(n-s)*i,f=(2+n+s)*i/2,m=(n+1)/(2*o),u=(1+s)*o/2,M=(Math.cosh(a)*l+c*-r*f)/i,p=m,h=1,S=h*M,k=h*p;for(let I=1;I<H&&(M=(I*M+m+u)/(I*I-t*t),m/=I-t,u/=I+t,p=m-I*M,h*=e*e/(4*I),S+=h*M,k+=h*p,!(Math.abs(h*M)<Math.abs(S)*D));I++);return[S,2*k/e]}function At(t,e){let n=Math.sqrt(Number.MIN_VALUE*4503599627370496),s=n,r=n,o=0;for(let a=1;a<H;a++){let i=2*(t+a)/e;s=i+1/s,o=i+o,s===0&&(s=n),o===0&&(o=n),o=1/o;let c=s*o;if(r*=c,Math.abs(c-1)<=2*D)break}return r}function Jt(t,e){let n=t*t-.25,s=2*(e+1),r=1/s,o=r,a=r,i=0,c=1,l=-n,f=l,m=1+f*a;for(let p=2;p<H;p++){n-=2*(p-1),s+=2,r=1/(s+n*r),a*=s*r-1,o+=a;let h=(i-(s-2)*c)/n;if(i=c,c=h,l*=-n/p,f+=l*h,m+=f*a,h<D&&(l*=h,i/=h,c/=h),Math.abs(f*a)<Math.abs(m)*D)break}let u=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/m;return[M,M*u]}function V(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function bt(t,e){let n=Math.round(t),s=t-n,r,o;if(s===-.5)r=o=Math.sqrt(Math.PI/(2*e));else if(e<=2){let[i,c]=Tt(s,e),l=Math.exp(e);r=i*l,o=c*l}else[r,o]=Jt(s,e);let a=0;for(let i=1;i<=n;i++){let c=2*(s+i)/e,l=Math.log2(Math.abs(o))+Math.log2(c);if(l>900&&Number.isFinite(l)){let m=Math.ceil(l-800);r=V(r,-m),o=V(o,-m),a+=m}let f=c*o+r;r=o,o=f}return{k:r,k1:o,exp2:a}}function Kt(t,e){let n=e*e/4,s=1,r=0;for(let o=1;o<H&&(r+=s,s*=n/o,s/=o+t,!(Math.abs(s)<=D*Math.abs(r)));o++);return W(t,e,r+s)}function Rt(t,e,n){if(t===0||!Number.isFinite(t))return t;let s=t,r=e,o=n>0?700:-700,a=Math.exp(o);for(;Math.abs(n)>700;){n-=o,s*=a;let i=Math.floor(Math.log2(Math.abs(s)));s=V(s,-i),r+=i}return V(s*Math.exp(n),r)}function x(t,e,n){let s=t.ex+n;return s===0?V(t.m,t.e2):Rt(t.m,t.e2,s*e)}function Yt(t,e){if(t===.5)return{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(t>0&&e/t<.25)return{m:Kt(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<D*10&&e>100){let i=4*t*t,c=8*e,l=i-1,f=c,m=1-l/f;return l*=i-9,f*=c*2,m+=l/f,l*=i-25,f*=c*3,m-=l/f,{m:m/Math.sqrt(2*e*Math.PI),e2:0,ex:1}}let{k:s,k1:r,exp2:o}=bt(t,e),a=At(t,e);return{m:1/(e*(s*a+r)),e2:-o,ex:1}}function Nt(t,e){let n=4*t*t,s=8*e,r=(n-1)/s,o=r*(n-9)/(2*s),a=o*(n-25)/(3*s),i=a*(n-49)/(4*s),c=1+r+o+a;if(Math.abs(i)<D*Math.abs(c))return{m:c*Math.sqrt(Math.PI)/Math.sqrt(2*e),e2:0,ex:-1};let{k:l,exp2:f}=bt(t,e);return{m:l,e2:f,ex:-1}}function Ct(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?d(r)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return s?0:1/0;let a=s?-1:0,i=x(Yt(r,t),t,a);if(!o)return i;let c=Nt(r,t);return i+x({...c,m:2/Math.PI*d(r)*c.m},t,a)}function Qt(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e);return t===0?1/0:t===1/0?0:x(Nt(r,t),t,s?1:0)}var y=Number.EPSILON;function A(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function gt(t,e,n,s,r){let o=s,a=r,i=0;for(let c=1;c<=n;c++){let l=2*(t+c)/e,f=Math.log2(Math.abs(a))+Math.log2(l);if(f>900&&Number.isFinite(f)){let u=Math.ceil(f-800);o=A(o,-u),a=A(a,-u),i+=u}let m=l*a-o;o=a,a=m}return{y:o,y1:a,e2:i}}var K=1e6,g=Math.sqrt(22250738585072014e-324),Ut=Number.MAX_VALUE;function It(t){return Math.expm1(C(t))}function Q(t){return d(.5-Math.abs(t%2))}function dt(t,e){let n=-(e/2)*(e/2),s=1,r=0;for(let o=1;o<K&&(r+=s,s*=n/(o*(o+t)),!(Math.abs(s)<=y*Math.abs(r)));o++);return W(t,e,r+s)}function Vt(t,e){let n=Math.log(e/2),s=0,r=t>=170||709.78/t<Math.abs(n),o;if(r){let u=_(t);if(n=t*n,o=u-Math.log(Math.PI)-n,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,s=M}o=-Math.exp(o)}else{let u=q(t);n=Math.pow(e/2,t),Ut*n<u&&(u*=2**-1e3,s=1e3),o=-u/(Math.PI*n)}let a=-(e/2)*(e/2),i=1,c=0;for(let u=1;u<K&&(c+=i,i*=a/(u*(u-t)),!(Math.abs(i)<=y*Math.abs(c)));u++);let l=(c+i)*o,f;if(!r)f=q(-t)*Q(t)*n/Math.PI;else{let u=U(-t);f=Math.exp(u.value+n)*u.sign/Math.PI}i=1;let m=0;for(let u=1;u<K&&(m+=i,i*=a/(u*(u+t)),!(Math.abs(i)<=y*Math.abs(m)));u++);return m+=i,l-=A(f*m,-s),{m:l,e2:s}}function Xt(t,e){let n=1,s=0,r=1,o=8*e,a=1,i=4*t*t,c=1,l=!0;do{c*=(i-a*a)/(r*o),s+=c,r+=1,a+=2;let f=(a*a-i)/(r*o);l=Math.abs(f)<.5,c*=f,n+=c,r+=1,a+=2}while(Math.abs(c)>2*y*n&&l);return l?{p:n,q:s}:void 0}function Bt(t,e){let n=It(t),s=It(-t),r=d(t),o=d(t/2),a=Math.pow(e/2,t),i=Math.log(e/2),c=-i*t,l=Math.abs(c)<y?1:Math.sinh(c)/c,f=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,m=t===0?-.5772156649015329:(n-s)/((1+n)*(1+s)*2*t),u=(2+n+s)/((1+n)*(1+s)*2),M=Math.abs(t)<y?1/Math.PI:t/r,p=(m*Math.cosh(c)-u*i*l)*2*M,h=M/(a*(1+s)),S=M*a/(1+n),k=p+f*S,I=h,F=1,R=F*k,X=F*I,B=t*t,b=-e*e/4;for(let N=1;N<K&&(p=(N*p+h+S)/(N*N-B),h/=N-t,S/=N+t,k=p+f*S,I=h-N*k,F*=b/N,R+=F*k,X+=F*I,!(Math.abs(F*k)<Math.abs(R)*y));N++);return[-R,-2*X/e]}function Ot(t,e){let n=[g,0],s=[g,0],r=[0,0],o=1,a=[e,0];for(let i=1;i<K*100;i++){let c=E(t,i),l=O([2*c[0],2*c[1]],a);n=T(l,O([1,0],n)),r=T(l,r),n[0]===0&&(n=[g,0]),r[0]===0&&(r=[g,0]),r=O([1,0],r);let f=J(n,r);if(s=J(s,f),r[0]<0&&(o=-o),Math.abs(f[0]-1+f[1])<y*y)break}return{fv:-(s[0]+s[1]),sign:o}}function yt(t,e){if(e>30)return Ot(t,e);let n=g,s=g,r=0,o=1;for(let a=1;a<K*100;a++){let i=2*(t+a)/e;n=i-1/n,r=i-r,n===0&&(n=g),r===0&&(r=g),r=1/r;let c=n*r;if(s*=c,r<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-s,sign:o}}function Pt(t,e){let n=-.5/e,s=1,r=n,o=s,a=t*t,i=(.25-a)/e,c=2*e,l=2,f=r*r+1;o=l+i*r/f,r=c+i/f;let m=c,u=l;Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f;let M=r*m-o*u,p=o*m+r*u;f=n,n=f*M-s*p,s=f*p+s*M;for(let h=2;h<K&&(i=h-.5,i*=i,i-=a,l+=2,f=r*r+o*o,r=c+i*r/f,o=l-i*o/f,m=c+i*m,u=l+i*u,Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f,M=r*m-o*u,p=o*m+r*u,f=n,n=f*M-s*p,s=f*p+s*M,!(Math.abs(M-1)+Math.abs(p)<2*y));h++);return{p:n,q:s}}function Zt(t,e){let n=1,s=4*t*t,r=2*e;return r*=r,n+=(s-1)/(2*r),n+=3*(s-1)*(s-9)/(r*r*8),n+=15*(s-1)*(s-9)*(s-25)/(r*r*r*8*6),Math.sqrt(n*2/(Math.PI*e))}function Gt(t,e){let n=4*t*t,s=4*e,r=s*s,o=0;return o+=(n-1)/(2*s),s*=r,o+=(n-1)*(n-25)/(6*s),s*=r,o+=(n-1)*(n*n-114*n+1073)/(5*s),s*=r,o+=(n-1)*(5*n*n*n-1535*n*n+54703*n-375733)/(14*s),o}function Wt(t,e){let n=Zt(t,e),s=Gt(t,e),r=Math.cos(e),o=Math.sin(e),a=Q(t/2+.25),i=d(t/2+.25),c=Math.sin(s),l=Math.cos(s),f=(c*(r*a+o*i)+l*(o*a-r*i))*n;return{j:(l*(r*a+o*i)-c*(o*a-r*i))*n,y:f}}function tt(t,e,n){let s=Math.round(t),r=t-s,o=2/(e*Math.PI);if(!n&&(e<5||t>e*e/4))return{j:dt(t,e),y:{m:NaN,e2:0}};if(e<1&&r!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:dt(t,e),y:Vt(t,e)};if(Math.max(t,1)<e*.011048543456039806){let b=Wt(t,e);return{j:b.j,y:{m:b.y,e2:0}}}if(e>8){let b=Xt(t,e);if(b!==void 0){let N=(t/2+.25)%2,P=Math.sin(e),w=Math.cos(e),Y=d(N),rt=Q(N),st=P*rt-Y*w,ot=w*rt+P*Y,it=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:it*(b.p*ot-b.q*st),y:{m:it*(b.p*st+b.q*ot),e2:0}}}}if(e<=2){let[b,N]=Bt(r,e),P=gt(r,e,s,b,N),{fv:w}=yt(t,e);return{j:A(o/(P.y*w-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let{fv:a,sign:i}=yt(t,e);if(e>=t&&t>2){let{p:b,q:N}=Pt(t,e),P=t/e-a,w=(b-P)/N;w===0&&(w=t*y/e);let Y=i*Math.sqrt(o/(N+w*(b-P)));return{j:Y,y:{m:w*Y,e2:0}}}let c=g,l=a*i*c,f=i*c,m=0;for(let b=s;b>0;b--){let N=2*(r+b)/e;Math.abs(f)>2**900&&(l*=2**-900,f*=2**-900,m+=900);let P=N*f-l;P===0&&(P=l*y/2),l=f,f=P}let u=A(i*c/f,-m),M=l/f,{p,q:h}=Pt(r,e),S=r/e-M,k=(p-S)/h;k===0&&(k=r*y/e);let I=Math.sign(f)*Math.sqrt(o/(h+k*(p-S))),F=I*u,R=k*I,X=R*(r/e-p-h/k);if(!n)return{j:F,y:{m:NaN,e2:0}};let B=gt(r,e,s,R,X);return{j:F,y:{m:B.y,e2:B.e2}}}function Ht(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:s?d(n)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!s){let o=tt(n,t,!1).j;return e<0&&n%2===1?-o:o}let r=tt(n,t,!0);return Q(n)*r.j-A(d(n)*r.y.m,r.y.e2)}function $t(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0;if(t===0){if(!s)return-1/0;let i=Q(n);return i===0?0:i>0?-1/0:1/0}if(t===1/0)return 0;let r=tt(n,t,!0);if(!s)return A(r.y.m,r.y.e2);let o=Q(n),a=d(n);return(a!==0?a*r.j:0)+(o===0?0:A(o*r.y.m,r.y.e2))}function zt(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let n=_(e),s=q(e),r=l=>{let f=v(e,t,l,!1),m=s*f;if(Number.isFinite(s)&&f>kt&&Number.isFinite(m)&&m>kt)return[m,Math.log(m)];let u=n+v(e,t,l,!0);return u<710&&u>-746&&t>0&&(l?t<e:t>e)?vt(t,e,l):[Math.exp(u),u]},[o,a]=r(!0),[i,c]=r(!1);return{lower:o,upper:i,logLower:a,logUpper:c}}var kt=22250738585072014e-324;function vt(t,e,n){let s=j(at(L([t,0]),e),[-t,0]);n?s=j(s,L([mt(e,t)/e,0])):s=j(s,L([ut(e,t),0]));let r=s[0]+s[1];return[s[0]>-708?Math.exp(s[0])*(1+s[1]):Math.exp(r),r]}function et(t){return Number.isNaN(t)||t<0||t>2?NaN:-ft(t/2)*Math.SQRT1_2}function xt(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,n=Math.abs(t);if(n>=.5)return e*et(1-n);if(n<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let s=et(1-n);for(let r=0;r<3;r++){let o=($(s)-n)/(1.1283791670955126*Math.exp(-s*s));if(s-=o,Math.abs(o)<=1e-17*s)break}return e*s}function te(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let n=e===Math.floor(e);return t===Math.floor(t)&&n&&e>t?0:!Number.isFinite(t)||!Number.isFinite(e)?ie(t,e):n&&e<=1e3?ee(t,e):ne(t,e)}function ee(t,e){let n=[1,0];for(let s=0;s<e;s++){let r=E(t,-s),o=n[0]*r[0];if(!Number.isFinite(o)){let a=Math.sign(o);for(let i=s+1;i<e;i++)t-i<0&&(a=-a);return a*(1/0)}n=Math.abs(n[0])>1e290||Math.abs(r[0])>1e290?[(n[0]+n[1])*(r[0]+r[1]),0]:J(n,r)}return n[0]+n[1]}function ne(t,e){let[n,s]=E(t,-e);if(n+1<=0)return re(t,n,s);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let r;if(n>=15){if(e*Math.log(n+1)>720)return 1/0;let o=E(t,-n),a=T(J(o,L([t,0])),ct(n,[t,0]));a=j(a,[Z(t)-Z(n),0]),r=Math.sqrt(t/n)*Math.exp(a[0])*(1+a[1])}else if(t<30)r=q(t+1)/q(n+1);else{if(_(t+1)-_(n+1)>720)return 1/0;let o=T(nt(t+1),L([q(n+1),0]));r=Math.exp(o[0])*(1+o[1])}return s!==0&&Number.isFinite(r)&&r!==0&&(r*=Math.exp(-s*G(n+1))),r}function re(t,e,n){let s=j(E(e,1),[n,0]),r=d(s[0])+d(s[0]+.5)*Math.PI*s[1];if(r===0)return 0;let o=Math.sign(r),a=j(T(L([Math.abs(r),0]),oe),[-n*G(-e),0]);if(_(t+1)+_(-e)+a[0]>720)return o*(1/0);let i=j(j(nt(t+1),nt(-e)),a);return o*Math.exp(i[0])*(1+i[1])}var se=[.9189385332046728,-38782941580672414e-33],oe=[1.1447298858494002,10265951162707826e-33];function nt(t){if(t<15)return L([q(t),0]);let e=T(J(E(t,-.5),L([t,0])),[t,0]);return j(j(e,se),[Z(t),0])}function ie(t,e){let n=U(t+1),s=U(t-e+1);return n.sign*s.sign*Math.exp(n.value-s.value)}function ae(t){return Number.isNaN(t)||t<-1?NaN:t===-1||t===1/0?-1/0:lt(t)}function fe(t){return Number.isNaN(t)||t===-1/0?NaN:t===1/0||t<=-1&&t===Math.floor(t)?1/0:C(t)}function ce(t){return Number.isNaN(t)||t<0?NaN:t===0?-1/0:t===1/0?0:ht(-t)}function le(t){return Number.isNaN(t)?NaN:t<=-37?Math.exp(t):t<=18?Math.log1p(Math.exp(t)):t<=33.3?t+Math.exp(-t):t}export{Ct as besselI,Ht as besselJ,Qt as besselK,$t as besselY,Dt as beta,wt as choose,G as digamma,$ as erf,qt as erfc,et as erfcinv,xt as erfinv,_t as factorial,q as gamma,zt as gammainc,Ft as lbeta,Lt as lchoose,Et as lfactorial,_ as lgamma,fe as lgamma1p,ce as log1mexp,le as log1pexp,ae as log1pmx,te as perm,jt as psigamma,St as trigamma};
package/dist/tests.js CHANGED
@@ -1,2 +1,3 @@
1
- /*! rStats.js 0.6.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
- import{B as Et,C as at,G as ut,H as Ot,M as ht,N as pe,R as pt,S as de,W as ge,X as we,c as D,d as Ft,l as Ct,m as st,r as X,s as wt,x as jt}from"./chunks/chunk-7JVSDGQQ.js";import{h as ye,k as ve,l as xe,t as Ee,y as Ae}from"./chunks/chunk-ZWJ42QN6.js";import{a as L,b as be,c as G,f as Xe}from"./chunks/chunk-AJYQNFXK.js";import{k as Q,l as it}from"./chunks/chunk-XM2TVD63.js";import{c as Me}from"./chunks/chunk-TPC6MTYC.js";import"./chunks/chunk-DRNMIEYH.js";import{a as Nt,b as Y,c as K,e as Ne,f as U,g as lt,h as ft,i as At}from"./chunks/chunk-7NK4SA6B.js";import{b as he}from"./chunks/chunk-2JCIB5H2.js";import{g as C,h as j,s as ue}from"./chunks/chunk-QNAIK4PY.js";import{b as Lt,c as yt,d as F,e as ce,f as B,g as vt,i as xt,k as me}from"./chunks/chunk-UGUQYWRQ.js";function Pt(e,t,r={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?r=t:n=t;let o=L(r.alternative),i=r.mu??0,f=r.paired??!1,s=r.varEqual??!1,a=r.confLevel??.95;if(Number.isNaN(i))throw new RangeError("mu must be a number");if(be(a),f&&n===void 0)throw new TypeError("y is required when paired is true");let c=Array.from(e),l=n===void 0?void 0:Array.from(n);if(f){let[A,q]=At(c,l);c=A.map((k,y)=>k-q[y]),l=void 0}else c=ft(c),l!==void 0&&(l=ft(l));let m,u,h,p,d,g,b,N=c.length;if(N<2)throw new Error("not enough 'x' observations");let w=Y(c),M=K(c);if(l===void 0){if(u=N-1,h=Math.sqrt(M/N),h<10*Number.EPSILON*Math.abs(w))throw new Error("data are essentially constant");m=(w-i)/h,g=f?"Paired t-test":"One Sample t-test",p=w,d=f?"mean difference":"mean of x",b=f?"mean difference":"mean"}else{let A=l.length;if(A<1||!s&&A<2)throw new Error("not enough 'y' observations");if(s&&N+A<3)throw new Error("not enough observations");let q=Y(l),k=K(l);if(g=`${s?"":"Welch"} Two Sample t-test`,p=[w,q],d=["mean of x","mean of y"],b="difference in means",s){u=N+A-2;let y=0;N>1&&(y+=(N-1)*M),A>1&&(y+=(A-1)*k),y/=u,h=Math.sqrt(y*(1/N+1/A))}else{let y=M/N,T=k/A;h=Math.sqrt(y+T),u=(h*h)**2/(y*y/(N-1)+T*T/(A-1))}if(h<10*Number.EPSILON*Math.max(Math.abs(w),Math.abs(q)))throw new Error("data are essentially constant");m=(w-q-i)/h}let v,E;if(o==="less")v=Q(m,u,!0,!1),E=[-1/0,m+it(a,u,!0,!1)];else if(o==="greater")v=Q(m,u,!1,!1),E=[m-it(a,u,!0,!1),1/0];else{v=2*Q(-Math.abs(m),u,!0,!1);let A=1-a,q=it(1-A/2,u,!0,!1);E=[m-q,m+q]}return E=[i+E[0]*h,i+E[1]*h],{method:g,alternative:o,statistic:m,statisticName:"t",parameter:u,parameterName:"df",pValue:v,confInt:E,confLevel:a,estimate:p,estimateNames:d,nullValue:i,nullValueName:b,stdErr:h}}function rt(e){let t=[0,0],r=0;for(let n of e)t=F(t,[n,0]),r+=n;return Number.isFinite(r)?t[0]:r}function Qe(e,t={}){let r=t.correct??!0;if(e.length>0&&typeof e[0]!="number"){let o=e.map(f=>Array.from(f)),i=o[0].length;if(o.some(f=>f.length!==i))throw new TypeError("all rows of the matrix must have the same length");return o.length===1?zt(o[0],t):i===1?zt(o.map(f=>f[0]),t):Ye(o,r)}return zt(Array.from(e),t)}function Re(e,t){return Number.isNaN(e)?NaN:D(e,t/2,2,!1,!1)}function Te(e){if(!e.some(t=>t<5)&&e.some(Number.isNaN))throw new RangeError("missing value where TRUE/FALSE needed (the expected counts contain NaN)")}function zt(e,t){let r=e.length;if(e.some(c=>Number.isNaN(c)||c<0))throw new RangeError("all entries of 'x' must be non-negative and finite");if(r<2)throw new TypeError("'x' must have at least 2 elements");let n=rt(e);if(!(n>0))throw new RangeError("at least one entry of 'x' must be positive");let o=t.p===void 0?e.map(()=>1/r):Array.from(t.p);if(o.length!==r)throw new TypeError("'x' and 'p' must have the same number of elements");if(o.some(Number.isNaN))throw new RangeError("p contains missing values");if(o.some(c=>c<0))throw new RangeError("probabilities must be non-negative");if(t.rescaleP??!1){let c=rt(o);o=o.map(l=>l/c)}else if(Math.abs(rt(o)-1)>Math.sqrt(Number.EPSILON))throw new RangeError("probabilities must sum to 1");let i=o.map(c=>n*c);Te(i);let f=o.map((c,l)=>i[l]*(1-c)),s=rt(e.map((c,l)=>(c-i[l])**2/i[l])),a=r-1;return{method:"Chi-squared test for given probabilities",statistic:s,statisticName:"X-squared",parameter:a,parameterName:"df",pValue:Re(s,a),observed:e,expected:i,residuals:e.map((c,l)=>(c-i[l])/Math.sqrt(i[l])),stdres:e.map((c,l)=>(c-i[l])/Math.sqrt(f[l]))}}function Ye(e,t){let r=e.length,n=e[0].length,o=e.flat();if(o.some(d=>!(d>=0&&d<1/0)))throw new RangeError("all entries of 'x' must be non-negative and finite");let i=rt(o);if(!(i>0))throw new RangeError("at least one entry of 'x' must be positive");let f=e.map(d=>rt(d)),s=e[0].map((d,g)=>rt(e.map(b=>b[g]))),a=f.map(d=>s.map(g=>d*g/i));Te(a.flat());let c=e.map((d,g)=>d.map((b,N)=>b-a[g][N])),l="Pearson's Chi-squared test",m,u=t&&r===2&&n===2?Math.min(.5,...c.flat().map(Math.abs)):0;u>0?(l+=" with Yates' continuity correction",m=rt(c.flatMap((d,g)=>d.map((b,N)=>(Math.abs(b)-u)**2/a[g][N])))):m=rt(c.flatMap((d,g)=>d.map((b,N)=>b*b/a[g][N])));let h=(r-1)*(n-1),p=a.map((d,g)=>d.map((b,N)=>b*(1-f[g]/i)*(1-s[N]/i)));return{method:l,statistic:m,statisticName:"X-squared",parameter:h,parameterName:"df",pValue:Re(m,h),observed:e,expected:a,residuals:c.map((d,g)=>d.map((b,N)=>b/Math.sqrt(a[g][N]))),stdres:c.map((d,g)=>d.map((b,N)=>b/Math.sqrt(p[g][N])))}}var Ge=Math.pow(Number.EPSILON,.25);function Z(e,t,r,n={}){let o={tol:n.tol??Ge,maxiter:n.maxIter??1e3};return n.fLower!==void 0&&(o.fLower=n.fLower),n.fUpper!==void 0&&(o.fUpper=n.fUpper),Me(e,t,r,o).root}function Ze(e,t={}){let r=e.length,n=r===0?0:e[0].length;if(e.some(s=>s.length!==n))throw new TypeError("all rows of the matrix must have the same length");if(r<2||n<2)throw new TypeError("'x' must have at least 2 rows and columns");let o=e.map(s=>Array.from(s));if(o.flat().some(s=>Number.isNaN(s)||s<0))throw new RangeError("all entries of 'x' must be non-negative and finite");if(o.flat().some(s=>s===1/0))throw new RangeError("'x' has entries too large to be integer");let i=o.map(s=>s.map(he)),f="Fisher's Exact Test for Count Data";return r===2&&n===2?en(i,t,f):{method:f,alternative:t.alternative??"two.sided",pValue:nn(i)}}var Je=1+1e-7,tn=16;function _t(e,t,r){let n=[0,0];for(let o=Math.max(0,t);o<=Math.min(r,e.length-1);o++)e[o]!==0&&(n=F(n,[e[o],0]));return n[0]}var Ht=class{m;n;k;lo;hi;logCentral;constructor(t,r,n){this.m=t,this.n=r,this.k=n,this.lo=Math.max(0,n-r),this.hi=Math.min(n,t),this.logCentral=new Float64Array(this.hi-this.lo+1);let o=0,i=1;for(let f=this.lo;f<=this.hi;f++){let s=f-this.lo;s%tn===0||!(i>0&&i<1/0)?(o=ut(f,t,r,n,!0),i=1,this.logCentral[s]=o):this.logCentral[s]=o+Math.log(i),i*=(t-f)*(n-f)/((f+1)*(r-n+f+1))}}density(t){let r=this.logCentral.length,n=Math.log(t),o=new Float64Array(r),i=-1/0;for(let s=0;s<r;s++){let a=this.logCentral[s]+(this.lo+s)*n;o[s]=a,a>i&&(i=a)}for(let s=0;s<r;s++){let a=o[s]-i;o[s]=a<-746?0:Math.exp(a)}let f=_t(o,0,r-1);for(let s=0;s<r;s++)o[s]!==0&&(o[s]=o[s]/f);return o}mean(t){if(t===0)return this.lo;if(t===1/0)return this.hi;let r=this.density(t),n=[0,0];for(let o=0;o<r.length;o++)r[o]!==0&&(n=F(n,[(this.lo+o)*r[o],0]));return n[0]}tail(t,r,n){if(r===1)return n?Ot(t-1,this.m,this.n,this.k,!1,!1):Ot(t,this.m,this.n,this.k,!0,!1);if(r===0||r===1/0){let f=r===0?this.lo:this.hi;return(n?t<=f:t>=f)?1:0}let o=this.density(r),i=t-this.lo;return n?_t(o,i,o.length-1):_t(o,0,i)}};function Wt(e,t){return t?Z(e,0,1):1/Z(r=>e(1/r),Number.EPSILON,1)}function en(e,t,r){let n=L(t.alternative),o=t.or??1;if(!(o>=0))throw new RangeError("'or' must be a single number between 0 and Inf");let i=t.confLevel??.95;if(!(i>0&&i<1))throw new RangeError("confLevel must be a single number between 0 and 1");let[[f,s],[a,c]]=e,l=f,m=new Ht(f+a,s+c,f+s),{lo:u,hi:h}=m,p;if(n==="less")p=m.tail(l,o,!1);else if(n==="greater")p=m.tail(l,o,!0);else if(o===0)p=l===u?1:0;else if(o===1/0)p=l===h?1:0;else{let M=m.density(o),v=M[l-u]*Je,E=[0,0];for(let A of M)A<=v&&(E=F(E,[A,0]));p=E[0]}let d;if(l===u)d=0;else if(l===h)d=1/0;else{let M=m.mean(1);d=M===l?1:Wt(v=>m.mean(v)-l,M>l)}let g={method:r,alternative:n,pValue:p,estimate:d,estimateNames:"odds ratio",nullValue:o,nullValueName:"odds ratio"};if(!(t.confInt??!0))return g;let b=M=>{if(l===h)return 1/0;let v=m.tail(l,1,!1);return v===M?1:Wt(E=>m.tail(l,E,!1)-M,v<M)},N=M=>{if(l===u)return 0;let v=m.tail(l,1,!0);return v===M?1:Wt(E=>m.tail(l,E,!0)-M,v>M)},w;if(n==="less")w=[0,b(1-i)];else if(n==="greater")w=[N(1-i),1/0];else{let M=(1-i)/2;w=[N(M),b(M)]}return{...g,confInt:w,confLevel:i}}var Rt=[[0,0]];function J(e){for(let t=Rt.length;t<=e;t++)Rt.push(F(Rt[t-1],me([t,0])));return Rt[e]}function Tt(e,t,r,n){let o=e+r,i=o-e,f=e-(o-i)+(r-i)+t+n,s=o+f;return[s,f-(s-o)]}var $t=class{scale=-1/0;hi=0;lo=0;add(t,r,n){if(t>this.scale){let a=Number.isFinite(this.scale)?Math.exp(this.scale-t):0;this.hi*=a,this.lo*=a,this.scale=t}let o=n*Math.exp(t-this.scale)*(1+r),i=this.hi+o,f=i-this.hi,s=this.hi-(i-f)+(o-f)+this.lo;this.hi=i+s,this.lo=s-(this.hi-i)}value(){return this.scale===-1/0?0:this.hi*Math.exp(this.scale)}};function nn(e){let t=e.filter(w=>w.some(M=>M>0));if(t.length===0)throw new RangeError("all entries of the table are zero");let r=t[0].map((w,M)=>t.some(v=>v[M]>0));if(t=t.map(w=>w.filter((M,v)=>r[v])),t.length<2||t[0].length<2)return 1;t.length>t[0].length&&(t=t[0].map((w,M)=>t.map(v=>v[M])));let n=t.length,o=t.map(w=>w.reduce((M,v)=>M+v,0)),i=t[0].map((w,M)=>t.reduce((v,E)=>v+E[M],0)).sort((w,M)=>M-w),f=i.length,s=o.reduce((w,M)=>w+M,0),a=ce(J(s));for(let w of o)a=F(a,J(w));for(let w of i)a=F(a,J(w));let c=[0,0];for(let w of t.flat())c=B(c,J(w));let l=F(c,[Math.log1p(1e-7),0]),m=1e-9*(1+Math.abs(l[0])),[u,h]=l,p=Array.from({length:f},()=>new Map),d=(w,M)=>{let v=M.join(","),E=p[w].get(v);if(E!==void 0)return E;let A=F(a,J(M.reduce((x,V)=>x+V,0)));for(let x of M)A=B(A,J(x));for(let x=w;x<f;x++)A=B(A,J(i[x]));let q={R:M,KZ:A,max:0,min:0,edges:[],pastHi:[],pastLo:[],count:[],index:new Map};if(p[w].set(v,q),w===f-1){let x=[0,0];for(let V of M)x=B(x,J(V));return q.max=q.min=x[0],q.edges.push({to:q,hi:x[0],lo:x[1],mult:1}),q}let k=new Map,y=new Array(n+1).fill(0);for(let x=n-1;x>=0;x--)y[x]=y[x+1]+M[x];let T=new Array(n).fill(0),S=(x,V,O)=>{if(x===n-1){T[x]=V;let z=B(O,J(V)),tt=M.map((nt,dt)=>nt-T[dt]).sort((nt,dt)=>nt-dt),W=d(w+1,tt),$=`${tt.join(",")}|${z[0]}`,et=k.get($);et===void 0?k.set($,{to:W,hi:z[0],lo:z[1],mult:1}):et.mult++;return}let P=Math.max(0,V-y[x+1]),H=Math.min(M[x],V);for(let z=P;z<=H;z++)T[x]=z,S(x+1,V-z,B(O,J(z)))};if(S(0,i[w],[0,0]),q.edges=[...k.values()],q.max=Math.max(...q.edges.map(x=>x.hi+x.to.max)),q.min=Math.min(...q.edges.map(x=>x.hi+x.to.min)),w===f-2){let x=q.edges.map(W=>{let $=W.to.edges[0];return{v:F([W.hi,W.lo],[$.hi,$.lo]),mult:W.mult}});x.sort((W,$)=>W.v[0]-$.v[0]||W.v[1]-$.v[1]);let V=x.length,O=x[V-1].v[0],P=new Float64Array(V),H=new Float64Array(V),z=new Float64Array(V),tt=[0,0];x.forEach(({v:W,mult:$},et)=>{P[et]=W[0],H[et]=W[1];let nt=B(W,[O,0]);tt=F(tt,[$*Math.exp(nt[0])*(1+nt[1]),0]),z[et]=tt[0]}),q.dist={hi:P,lo:H,cum:z,vmax:O,kv:F(a,[O,0])}}return q},g=d(0,[...o].sort((w,M)=>w-M)),b=new $t,N=(w,M,v,E)=>{if(M+w.max<=u-m){let[S,x]=Tt(w.KZ[0],w.KZ[1],M,v);return b.add(S,x,E),!0}if(M+w.min>u+m)return!0;let A=w.dist;if(A===void 0)return!1;let[q,k]=Tt(u,h,-M,-v),y=0,T=A.hi.length;for(;y<T;){let S=y+T>>>1,x=A.hi[S];x<q||x===q&&A.lo[S]<=k?y=S+1:T=S}if(y>0){let[S,x]=Tt(A.kv[0],A.kv[1],M,v);b.add(S,x,E*A.cum[y-1])}return!0};N(g,0,0,1)||(g.pastHi.push(0),g.pastLo.push(0),g.count.push(1));for(let w=0;w<f-2;w++)for(let M of p[w].values()){let{pastHi:v,pastLo:E,count:A}=M;if(A.length!==0){for(let{to:q,hi:k,lo:y,mult:T}of M.edges)for(let S=0;S<A.length;S++){let[x,V]=Tt(v[S],E[S],k,y),O=A[S]*T;if(N(q,x,V,O))continue;let P=q.index.get(x);P===void 0?(q.index.set(x,q.count.length),q.pastHi.push(x),q.pastLo.push(V),q.count.push(O)):q.count[P]+=O}M.pastHi=M.pastLo=M.count=[],M.index.clear()}}return Math.min(1,b.value())}function Dt(e,t,r={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?r=t:n=t;let o=L(r.alternative),i=r.mu??0,f=r.paired??!1,s=r.exact??null,a=r.correct??!0,c=r.confInt??!1,l=r.confLevel??.95,m=r.tolRoot??1e-4;if(!Number.isFinite(i))throw new RangeError("mu must be a single finite number");if(c&&!(l>0&&l<1))throw new RangeError("confLevel must be a number strictly between 0 and 1");if(f&&n===void 0)throw new TypeError("y is required when paired is true");let u,h;if(f){let[d,g]=At(Array.from(e),Array.from(n));u=ft(d.map((b,N)=>b-g[N]))}else u=ft(Array.from(e)),n!==void 0&&(h=ft(Array.from(n)));if(u.length<1)throw new Error("not enough (non-missing) 'x' observations");if(h!==void 0&&h.length<1)throw new Error("not enough (non-missing) 'y' observations");let p={alternative:o,mu:i,correct:a,confInt:c,confLevel:l,tolRoot:m};return h===void 0?on(u,s,f,p):ln(u,h,s,p)}function qt(e,t,r){return r?t==="two.sided"?Math.sign(e)*.5:t==="greater"?.5:-.5:0}function ke(e,t){return t==="less"?C(e):t==="greater"?C(e,{lowerTail:!1}):2*Math.min(C(e),C(e,{lowerTail:!1}))}function rn(e){if(!(e>0)||!Number.isFinite(e))return e;let r=1-Math.floor(Math.log10(e)),n=r>=0?e*10**r:e/10**-r,o=Math.round(n);return o-n===.5&&o%2!==0&&(o-=1),r>=0?o/10**r:o*10**-r}function Kt(e){let t=e.length;if(t===0)return NaN;let r=Math.floor(t/2);return t%2===1?e[r]:Y([e[r-1],e[r]])}var Ut=(e,t)=>e-t;function Se(e){let t=e.length,r=U(e.map(Math.abs)),n=0;for(let f=0;f<t;f++)e[f]>0&&(n+=r[f]);let o=0;for(let f of lt(r))o+=f*f*f-f;let i=Math.sqrt(t*(t+1)*(2*t+1)/24-o/48);return[n,n-t*(t+1)/4,i]}function on(e,t,r,n){let{alternative:o,mu:i,correct:f}=n,s=e.map(E=>E-i),a=s.some(E=>E===0);a&&(s=s.filter(E=>E!==0));let c=s.length,l=t??c<50,m=U(s.map(Math.abs)),u=lt(m).length>0,[h,p,d]=Se(s),g,b,N=l&&!u&&!a;if(N){b="Wilcoxon signed rank exact test";let E=c*(c+1)/2;if(o==="less")g=ht(h,c,!0,!1);else if(o==="greater")g=ht(h-1,c,!1,!1);else{let A=h>E/2?ht(h-1,c,!1,!1):ht(h,c,!0,!1);g=Math.min(1,2*A)}}else b=`Wilcoxon signed rank test${f?" with continuity correction":""}`,g=ke((p-qt(p,o,f))/d,o);let w={method:b,alternative:o,statistic:h,statisticName:"V",pValue:g,nullValue:i,nullValueName:r?"location shift":"location"};if(!n.confInt)return w;let M=s.map(E=>E+i),v=N?sn(M,n):an(M,n);return{...w,...v}}function kt(e,t,r){return e==="less"?[-1/0,r]:e==="greater"?[t,1/0]:[t,r]}function qe(e,t,r){let n={confInt:kt(e,NaN,NaN),confLevel:0,estimate:t};return r!==void 0&&(n.estimateNames=r),n}function Ie(e,t,r){let n=e(t==="two.sided"?r/2:r);return n===0?1:n}function Ve(e){if(!(e>0))throw new RangeError("tolRoot must be positive")}function sn(e,t){let{alternative:r,confLevel:n}=t,o=e.length,i=[];for(let m=0;m<o;m++)for(let u=m;u<o;u++)i.push((e[m]+e[u])/2);i.sort(Ut);let f=i.length,s=1-n,a=Ie(m=>pe(m,o,!0,!1),r,s),c=ht(a-1,o,!0,!1),l=r==="two.sided"?2*c:c;return{confInt:kt(r,i[a-1],i[f-a]),confLevel:l-s>s/2?1-rn(l):n,estimate:Kt(i),estimateNames:"(pseudo)median"}}function an(e,t){let{alternative:r,correct:n,confLevel:o,tolRoot:i}=t,f=e.length;if(f===0)return qe(r,NaN);let s=Math.min(...e),a=Math.max(...e);if(!Number.isFinite(s)||!Number.isFinite(a)||f===1||s===a)return qe(r,(s+a)/2,"midrange");let c=(w,M)=>{let[,v,E]=Se(e.map(A=>A-w).filter(A=>A!==0));return(v-qt(v,r,M))/E},l=c(s,n),m=c(a,n),u=w=>-j(w),h=w=>r==="greater"?!(l<u(w)):r==="less"?!(m>j(w/2)):!(l<u(w/2))&&!(m>j(w/2)),p=1-o,d=!1;for(;!h(p)&&p<1;)p*=2,d=!0;Ve(i);let g=w=>Z(M=>c(M,n)-w,s,a,{tol:i,fLower:l-w,fUpper:m-w}),b;if(p>=1){let w=Kt([...e].sort(Ut));b=kt(r,w,w)}else r==="greater"?b=[g(u(p)),1/0]:r==="less"?b=[-1/0,g(j(p))]:b=[g(u(p/2)),g(j(p/2))];let N=Z(w=>c(w,!1),s,a,{tol:i,fLower:c(s,!1),fUpper:c(a,!1)});return{confInt:b,confLevel:d?1-Math.min(1,p):o,estimate:N,estimateNames:"(pseudo)median"}}function Le(e,t){let r=e.length,n=t.length,o=U([...e,...t]),i=0;for(let l=0;l<r;l++)i+=o[l];let f=i-r*(r+1)/2,s=0;for(let l of lt(o))s+=l*l*l-l;let a=r+n,c=Math.sqrt(r*n/12*(a+1-s/(a*(a-1))));return[f,f-r*n/2,c]}function ln(e,t,r,n){let{alternative:o,mu:i,correct:f}=n,s=e.length,a=t.length,c=e.map(M=>M-i),l=r??(s<50&&a<50),m=lt([...c,...t]).length>0,[u,h,p]=Le(c,t),d,g,b=l&&!m;if(b)if(g="Wilcoxon rank sum exact test",o==="less")d=pt(u,s,a,!0,!1);else if(o==="greater")d=pt(u-1,s,a,!1,!1);else{let M=u>s*a/2?pt(u-1,s,a,!1,!1):pt(u,s,a,!0,!1);d=Math.min(1,2*M)}else g=`Wilcoxon rank sum test${f?" with continuity correction":""}`,d=ke((h-qt(h,o,f))/p,o);let N={method:g,alternative:o,statistic:u,statisticName:"W",pValue:d,nullValue:i,nullValueName:"location shift"};if(!n.confInt)return N;let w=b?fn(e,t,n):cn(e,t,n);return{...N,...w}}function fn(e,t,r){let{alternative:n,confLevel:o}=r,i=e.length,f=t.length,s=[];for(let h of e)for(let p of t)s.push(h-p);s.sort(Ut);let a=s.length,c=1-o,l=Ie(h=>de(h,i,f,!0,!1),n,c),m=pt(l-1,i,f,!0,!1),u=n==="two.sided"?2*m:m;return{confInt:kt(n,s[l-1],s[a-l]),confLevel:u-c>c/2?1-u:o,estimate:Kt(s),estimateNames:"difference in location"}}function cn(e,t,r){let{alternative:n,correct:o,confLevel:i,tolRoot:f}=r,s=Math.min(...e)-Math.max(...t),a=Math.max(...e)-Math.min(...t);if(!Number.isFinite(s)||!Number.isFinite(a))throw new Error("cannot compute the confidence interval because the differences are not finite");let c=(h,p)=>{let[,d,g]=Le(e.map(b=>b-h),t);return(d-qt(d,n,p))/g},l=(h,p)=>{let d=c(s,p)-h,g=c(a,p)-h;if(Number.isNaN(d)||Number.isNaN(g))throw new Error("cannot compute the confidence interval because all observations are tied");return d<=0?s:g>=0?a:(Ve(f),Z(b=>c(b,p)-h,s,a,{tol:f,fLower:d,fUpper:g}))},m=1-i,u;return n==="greater"?u=[l(-j(m),o),1/0]:n==="less"?u=[-1/0,l(j(m),o)]:u=[l(-j(m/2),o),l(j(m/2),o)],{confInt:u,confLevel:i,estimate:l(0,!1),estimateNames:"difference in location"}}var Fe=["holm","hochberg","hommel","bonferroni","BH","BY","fdr","none"];function mn(e){if(Fe.includes(e))return e;let t=Fe.filter(r=>r.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function Bt(e,t={}){let r=typeof t=="string"?{method:t}:t,n=mn(r.method??"holm"),o=Array.from(e),i=[];for(let m=0;m<o.length;m++)Number.isNaN(o[m])||i.push(m);let f=i.length,s=r.n??f;if(!(s>=f))throw new RangeError("n must be at least the number of non-NaN p-values");if(s<=1)return o;let a=i.map(m=>o[m]),c=un(a,n,s),l=o.slice();return i.forEach((m,u)=>l[m]=c[u]),l}function St(e,t){let r=e.map((n,o)=>o);return r.sort((n,o)=>(t?e[o]-e[n]:e[n]-e[o])||n-o),r}function un(e,t,r){let n=e.length,o=new Array(n);switch(t){case"none":return e.slice();case"bonferroni":return e.map(i=>Math.min(1,r*i));case"holm":{let i=St(e,!1),f=-1/0;return i.forEach((s,a)=>{f=Math.max(f,(r-a)*e[s]),o[s]=Math.min(1,f)}),o}case"hochberg":{let i=St(e,!0),f=1/0;return i.forEach((s,a)=>{let c=n-a;f=Math.min(f,(r-c+1)*e[s]),o[s]=Math.min(1,f)}),o}case"BH":case"fdr":case"BY":{let i=t==="BY"?Ne(Array.from({length:Math.floor(r)},(a,c)=>1/(c+1))):1,f=St(e,!0),s=1/0;return f.forEach((a,c)=>{let l=n-c;s=Math.min(s,i*r/l*e[a]),o[a]=Math.min(1,s)}),o}case"hommel":return hn(e,r)}}function hn(e,t){if(!Number.isInteger(t))throw new RangeError("n must be an integer for the hommel method");let r=e.length,n=[...e,...new Array(t-r).fill(1)],o=St(n,!1),i=o.map(a=>n[a]),f=i.slice();for(let a=t;a>=2;a--){let c=1/0;for(let l=1;l<=a;l++)c=Math.min(c,a*i[t-a+l-1]/l);for(let l=t-a;l<t;l++)f[l]=Math.max(f[l],c);for(let l=0;l<t-a;l++)f[l]=Math.max(f[l],Math.min(a*i[l],c))}let s=new Array(r);return o.forEach((a,c)=>{a<r&&(s[a]=f[c])}),s}var pn=1+1e-7;function It(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7*Math.max(1,Math.abs(e))}function dn(e,t,r){if(r===0)return e===0?1:0;if(r===1)return e===t?1:0;let n=t*r;if(e===n)return 1;let o=Et(e,t,r,!1)*pn,i=0;if(e<n){for(let a=Math.ceil(n);a<=t;a++)Et(a,t,r,!1)<=o&&i++;let s=i===0?0:at(t-i,t,r,!1,!1);return Math.min(1,at(e,t,r,!0,!1)+s)}for(let s=0;s<=Math.floor(n);s++)Et(s,t,r,!1)<=o&&i++;let f=i===0?0:at(i-1,t,r,!0,!1);return Math.min(1,at(e-1,t,r,!1,!1)+f)}function Xt(e,t,r={}){let n,o;if(typeof e!="number"){if(e.length!==2)throw new RangeError("incorrect length of 'x'");if(t!==void 0&&typeof t!="number"&&(r=t),!It(e[0])||!It(e[1]))throw new RangeError("'x' must be nonnegative and integer");n=Math.round(e[0]),o=Math.round(e[0])+Math.round(e[1])}else{if(typeof t!="number")throw new TypeError("'n' is required when 'x' is a single number");if(!It(e))throw new RangeError("'x' must be nonnegative and integer");if(n=Math.round(e),!(It(t)&&Math.round(t)>=n&&t>0))throw new RangeError("'n' must be a positive integer >= 'x'");o=Math.round(t)}let i=r.p??.5;if(!(i>=0&&i<=1))throw new RangeError("'p' must be a single number between 0 and 1");let f=L(r.alternative),s=r.confLevel??.95;G(s);let a;f==="less"?a=at(n,o,i,!0,!1):f==="greater"?a=at(n-1,o,i,!1,!1):a=dn(n,o,i);let c=u=>n===0?0:jt(u,n,o-n+1,!0,!1),l=u=>n===o?1:jt(1-u,n+1,o-n,!0,!1),m;if(f==="less")m=[0,l(1-s)];else if(f==="greater")m=[c(1-s),1];else{let u=(1-s)/2;m=[c(u),l(u)]}return{method:"Exact binomial test",alternative:f,statistic:n,statisticName:"number of successes",parameter:o,parameterName:"number of trials",pValue:a,confInt:m,confLevel:s,estimate:n/o,estimateNames:"probability of success",nullValue:i,nullValueName:"probability of success"}}var gn=1+1e-7;function wn(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7*Math.max(1,Math.abs(e))}function Nn(e,t){if(t===0)return e===0?1:0;if(e===t)return 1;let r=Ct(e,t,!1)*gn,n=s=>Ct(s,t,!1)<=r,o=Math.floor(t);if(e<t){let s=Math.max(e+1,o),a=s;if(!n(s)){let c=s,l=1;for(a=s+1;!n(a);)c=a,l*=2,a=s+l;for(;a-c>1;){let m=c+Math.floor((a-c)/2);n(m)?a=m:c=m}}return Math.min(1,st(e,t,!0,!1)+st(a-1,t,!1,!1))}let i=Math.min(e-1,o),f;if(!n(0))f=-1;else if(n(i))f=i;else{f=0;let s=i;for(;s-f>1;){let a=f+Math.floor((s-f)/2);n(a)?f=a:s=a}}return Math.min(1,st(f,t,!0,!1)+st(e-1,t,!1,!1))}function bn(e,t={}){let r=typeof e=="number"?[e]:Array.from(e);if(r.length<1||r.length>2)throw new RangeError("incorrect length of 'x'");if(!r.every(wn))throw new RangeError("'x' must be finite, nonnegative, and integer");let n=r.map(Math.round),o=n.length,i=t.T??1,f=typeof i=="number"?new Array(o).fill(i):Array.from(i);if(f.length!==o)throw new RangeError("'x' and 'T' have incompatible length");if(!f.every(b=>Number.isFinite(b)&&b>=0))throw new RangeError("'T' must be nonnegative");let s=t.r??1;if(!(Number.isFinite(s)&&s>=0))throw new RangeError("'r' must be a single positive number");let a=L(t.alternative),c=t.confLevel??.95;if(G(c),o===2){let[b,N]=n,[w,M]=f,v=b+N,E=s*w/(s*w+M),A=Xt([b,N],{p:E,alternative:a,confLevel:c}),q=k=>k/(1-k)*(M/w);return{method:"Comparison of Poisson rates",alternative:a,statistic:b,statisticName:"count1",parameter:v*s*w/(w+s*M),parameterName:"expected count1",pValue:A.pValue,confInt:[q(A.confInt[0]),q(A.confInt[1])],confLevel:c,estimate:b/w/(N/M),estimateNames:"rate ratio",nullValue:s,nullValueName:"rate ratio"}}let l=n[0],m=f[0],u=s*m,h;a==="less"?h=st(l,u,!0,!1):a==="greater"?h=st(l-1,u,!1,!1):h=Nn(l,u);let p=b=>l===0?0:Ft(b,l,1,!0,!1),d=b=>Ft(1-b,l+1,1,!0,!1),g;if(a==="less")g=[0,d(1-c)];else if(a==="greater")g=[p(1-c),1/0];else{let b=(1-c)/2;g=[p(b),d(b)]}return{method:"Exact Poisson test",alternative:a,statistic:l,statisticName:"number of events",parameter:m,parameterName:"time base",pValue:h,confInt:[g[0]/m,g[1]/m],confLevel:c,estimate:l/m,estimateNames:"event rate",nullValue:s,nullValueName:"event rate"}}function Qt(e,t,r={}){let n,o,i=r;if(typeof e!="number"&&e.length>0&&Array.isArray(e[0])){let y=e;if(y.some(T=>T.length!==2))throw new RangeError("'x' must have 2 columns");n=y.map(T=>T[0]),o=y.map(T=>T[0]+T[1]),t!==void 0&&typeof t=="object"&&!Array.isArray(t)&&(i=t)}else{if(t===void 0||typeof t=="object"&&!Array.isArray(t))throw new RangeError("'n' must be given");n=typeof e=="number"?[e]:Array.from(e),o=typeof t=="number"?[t]:Array.from(t)}if(n.length!==o.length)throw new RangeError("'x' and 'n' must have the same length");let f=n.length,s=[];for(let y=0;y<f;y++)!Number.isNaN(n[y])&&!Number.isNaN(o[y])&&s.push(y);let a=s.length;if(a<1)throw new RangeError("not enough data");if(n=s.map(y=>n[y]),o=s.map(y=>o[y]),o.some(y=>!(y>0)))throw new RangeError("elements of 'n' must be positive");if(n.some(y=>!(y>=0)))throw new RangeError("elements of 'x' must be nonnegative");if(n.some((y,T)=>y>o[T]))throw new RangeError("elements of 'x' must not be greater than those of 'n'");let c;if(i.p!==void 0){let y=typeof i.p=="number"?[i.p]:Array.from(i.p);if(y.length!==f)throw new RangeError("'p' must have the same length as 'x' and 'n'");if(c=s.map(T=>y[T]),c.some(T=>!(T>0&&T<1)))throw new RangeError("elements of 'p' must be in (0,1)")}let l=c!==void 0;a===1&&c===void 0&&(c=[.5]);let m=i.confLevel??.95;G(m);let u=L(i.alternative);(a>2||a===2&&l)&&(u="two.sided");let h=n.map((y,T)=>y/o[T]),p=a===2?h[0]-h[1]:0,d=a===2?1/o[0]+1/o[1]:0,g=(i.correct??!0)&&a<=2?.5:0,b=!1;if(g>0&&a===1){let y=Math.abs(n[0]-o[0]*c[0]);y<=g&&([g,b]=[y,!0])}else if(g>0&&a===2&&!l){let y=Math.abs(p)/d;y<=g&&([g,b]=[y,!0])}let N=n.reduce((y,T)=>y+T,0)/o.reduce((y,T)=>y+T,0),w=0;if(!b)for(let y=0;y<a;y++){let T=c?.[y]??N,S=o[y]*T,x=o[y]*(1-T);w+=(Math.abs(n[y]-S)-g)**2/S,w+=(Math.abs(o[y]-n[y]-x)-g)**2/x}let M=c!==void 0?a:a-1,v;if(u==="two.sided")v=D(w,M/2,2,!1,!1);else{let y=Math.sign(a===1?h[0]-c[0]:p);v=C(y*Math.sqrt(w),{lowerTail:u==="less"})}let E;if(a===1||a===2&&!l){let y=j(u==="two.sided"?(1+m)/2:m);if(a===1){let T=o[0],S=y*y,x=(z,tt)=>(z+S/(2*T)+tt*y*Math.sqrt(z*(1-z)/T+S/(4*T*T)))/(1+S/T),V=h[0]+g/T,O=h[0]-g/T,P=Math.min(1,Math.max(0,V>=1?1:x(V,1))),H=Math.min(1,Math.max(0,O<=0?0:x(O,-1)));E=u==="two.sided"?[H,P]:u==="greater"?[H,1]:[0,P]}else{let T=Math.sqrt(h.reduce((O,P,H)=>O+P*(1-P)/o[H],0)),S=y*T+g*d,x=Math.max(-1,p-S),V=Math.min(1,p+S);E=u==="two.sided"?[x,V]:u==="greater"?[x,1]:[-1,V]}}let A=a===1?"p":s.map(y=>`prop ${y+1}`),k={method:`${a===1?"1-sample proportions test":`${a}-sample test for ${l?"given proportions":"equality of proportions"}`} ${g!==0?"with":"without"} continuity correction`,alternative:u,statistic:w,statisticName:"X-squared",parameter:M,parameterName:"df",pValue:v,estimate:a===1?h[0]:h,estimateNames:A};return c!==void 0&&(k.nullValue=a===1?c[0]:c,k.nullValueName=A),E!==void 0&&(k.confInt=E,k.confLevel=m),k}function Mn(e,t,r={}){let n;if(e.length>0&&Array.isArray(e[0])){t!==void 0&&!Array.isArray(t)&&(r=t),n=e.map(l=>Array.from(l));let c=n.length;if(c<2||n.some(l=>l.length!==c))throw new RangeError("'x' must be square with at least two rows and columns");if(n.some(l=>l.some(m=>!Number.isFinite(m)||m<0)))throw new RangeError("all entries of 'x' must be nonnegative and finite")}else{if(!Array.isArray(t))throw new TypeError("'y' is required when 'x' is not a table");n=yn(e,t)}let o=r.correct??!0,i=n.length,f,s=o&&i===2&&n[0][1]!==n[1][0];if(s){let c=n[0][1],l=n[1][0];f=(Math.abs(c-l)-1)**2/(c+l)}else{f=0;for(let c=0;c<i;c++)for(let l=c+1;l<i;l++){let m=n[c][l],u=n[l][c];f+=(m-u)**2/(m+u)}}let a=i*(i-1)/2;return{method:s?"McNemar's Chi-squared test with continuity correction":"McNemar's Chi-squared test",statistic:f,statisticName:"McNemar's chi-squared",parameter:a,parameterName:"df",pValue:D(f,a/2,2,!1,!1)}}function yn(e,t){if(e.length!==t.length)throw new RangeError("'x' and 'y' must have the same length");let r=[];for(let c=0;c<e.length;c++){let l=e[c],m=t[c];typeof l=="number"&&Number.isNaN(l)||typeof m=="number"&&Number.isNaN(m)||r.push([l,m])}let n=c=>Array.from(new Set(c)).sort((l,m)=>typeof l=="number"&&typeof m=="number"?l-m:String(l)<String(m)?-1:String(l)>String(m)?1:0),o=n(r.map(c=>c[0])),i=n(r.map(c=>c[1]));if(o.length<2||o.length!==i.length)throw new RangeError("'x' and 'y' must have the same number of levels (minimum 2)");let f=new Map(o.map((c,l)=>[c,l])),s=new Map(i.map((c,l)=>[c,l])),a=o.map(()=>new Array(o.length).fill(0));for(let[c,l]of r)a[f.get(c)][s.get(l)]++;return a}function vn(e,t,r={}){let n=Array.from(e).filter(Number.isFinite),o=Array.from(t).filter(Number.isFinite),i=r.ratio??1;if(!(Number.isFinite(i)&&i>0))throw new RangeError("'ratio' must be a single positive number");let f=L(r.alternative),s=r.confLevel??.95;G(s);let a=n.length-1,c=o.length-1;if(a<1)throw new Error("not enough 'x' observations");if(c<1)throw new Error("not enough 'y' observations");let l=K(n)/K(o),m=l/i,u=X(m,a,c,!0,!1),h=X(m,a,c,!1,!1),p,d;if(f==="less")p=u,d=[0,l/wt(1-s,a,c,!0,!1)];else if(f==="greater")p=h,d=[l/wt(s,a,c,!0,!1),1/0];else{p=Math.min(1,2*Math.min(u,h));let g=(1-s)/2;d=[l/wt(1-g,a,c,!0,!1),l/wt(g,a,c,!0,!1)]}return{method:"F test to compare two variances",alternative:f,statistic:m,statisticName:"F",parameter:[a,c],parameterName:["num df","denom df"],pValue:p,confInt:d,confLevel:s,estimate:l,estimateNames:"ratio of variances",nullValue:i,nullValueName:"ratio of variances"}}function xn(e){let t=e.length;if(t<2)throw new RangeError("'x' must be a list with at least 2 elements");let r=[],n=[];for(let l of e){let m=Array.from(l).filter(Number.isFinite);if(m.length<2)throw new RangeError("there must be at least 2 observations in each group");r.push(m.length-1),n.push(K(m))}let o=0,i=0,f=0,s=0;for(let l=0;l<t;l++)o+=r[l],i+=r[l]*n[l],f+=r[l]*Math.log(n[l]),s+=1/r[l];i/=o;let a=(o*Math.log(i)-f)/(1+(s-1/o)/(3*(t-1))),c=t-1;return{method:"Bartlett test of homogeneity of variances",statistic:a,statisticName:"Bartlett's K-squared",parameter:c,parameterName:"df",pValue:D(a,c/2,2,!1,!1)}}function Yt(e,t,r="drop"){if(t===void 0){let f=e;if(f.length>0&&typeof f[0]=="number")throw new TypeError("'g' is required when 'x' is a single sample");let s=f.map(l=>Array.from(l).filter(m=>!Number.isNaN(m)));if(r==="error"&&s.some(l=>l.length===0))throw new RangeError("all groups must contain data");let a=[],c=[];return s.forEach((l,m)=>{l.length!==0&&(a.push(String(m+1)),c.push(l))}),{labels:a,groups:c}}let n=Array.from(e);if(n.length!==t.length)throw new RangeError("'x' and 'g' must have the same length");let o=new Map;for(let f=0;f<n.length;f++){let s=n[f],a=t[f];if(Number.isNaN(s)||typeof a=="number"&&Number.isNaN(a))continue;let c=o.get(a);c===void 0&&o.set(a,c=[]),c.push(s)}let i=Array.from(o.keys()).sort((f,s)=>typeof f=="number"&&typeof s=="number"?f-s:String(f)<String(s)?-1:String(f)>String(s)?1:0);return{labels:i.map(String),groups:i.map(f=>o.get(f))}}function ct(e,t,r="drop"){return Yt(e,t,r).groups}function Ce(e){let t=[...e].sort((n,o)=>n-o),r=t.length;return r%2===1?t[(r-1)/2]:(t[r/2-1]+t[r/2])/2}function Gt(e){if(e.length===0)throw new RangeError("'y' must have at least one row");let t=e[0].length;if(e.some(r=>r.length!==t))throw new RangeError("all rows of 'y' must have the same length");return e.filter(r=>r.every(n=>!Number.isNaN(n))).map(r=>Array.from(r))}function Zt(e,t,r,n){return{method:e,statistic:r,statisticName:t,parameter:n,parameterName:"df",pValue:D(r,n/2,2,!1,!1)}}function je(e){let t=0;for(let r of lt(e))t+=r*r*r-r;return t}function En(e,t){let r=ct(e,t,"error"),n=r.length;if(n<2)throw new RangeError("all observations are in the same group");let o=r.flat(),i=o.length,f=U(o),s=0,a=0;for(let c of r){let l=0;for(let m=0;m<c.length;m++)l+=f[a+m];a+=c.length,s+=l*l/c.length}return s=(12*s/(i*(i+1))-3*(i+1))/(1-je(o)/(i*i*i-i)),Zt("Kruskal-Wallis rank sum test","Kruskal-Wallis chi-squared",s,n-1)}function An(e){let t=Gt(e),r=t.length,n=e[0]?.length??0;if(r<2||n<2)throw new RangeError("'y' must have at least two complete rows and two columns");let o=new Array(n).fill(0),i=0;for(let a of t){let c=U(a);for(let l=0;l<n;l++)o[l]+=c[l];i+=je(a)}let f=0;for(let a of o)f+=(a-r*(n+1)/2)**2;let s=12*f/(r*n*(n+1)-i/(n-1));return Zt("Friedman rank sum test","Friedman chi-squared",s,n-1)}function Rn(e){let t=Gt(e),r=e.length,n=e[0]?.length??0;if(t.length<2||n<2)throw new RangeError("'y' must have at least two complete rows and two columns");let o=U(t.map(h=>Math.max(...h)-Math.min(...h))),i=new Array(n).fill(0),f=0;t.forEach((h,p)=>{let d=U(h);for(let g=0;g<n;g++){let b=o[p]*(d[g]-(n+1)/2);f+=b*b,i[g]+=b}});let s=0;for(let h of i)s+=h*h;s/=r;let a=n-1,c=(r-1)*(n-1),l,m,u=[a,c];if(f===s){l=NaN,u=[NaN,NaN];let h=0;for(let p=2;p<=n;p++)h+=Math.log(p);m=Math.exp((1-r)*h)}else l=(r-1)*s/(f-s),m=X(l,a,c,!1,!1);return{method:"Quade test",statistic:l,statisticName:"Quade F",parameter:u,parameterName:["num df","denom df"],pValue:m}}function Tn(e,t){let r=ct(e,t,"error"),n=r.length;if(n<2)throw new RangeError("all observations are in the same group");let o=r.flatMap(u=>{let h=Ce(u);return u.map(p=>Math.abs(p-h))}),i=o.length,s=U(o).map(u=>j((1+u/(i+1))/2)),a=0;for(let u of s)a+=u;let c=a/i,l=0,m=0;for(let u of r){let h=0;for(let p=0;p<u.length;p++)h+=s[m+p];m+=u.length,l+=u.length*(h/u.length-c)**2}return l/=K(s),Zt("Fligner-Killeen test of homogeneity of variances","Fligner-Killeen:med chi-squared",l,n-1)}function qn(e,t,r={}){let n=Array.from(e).filter(Number.isFinite),o=Array.from(t).filter(Number.isFinite),i=L(r.alternative),f=n.length,s=o.length,a=f+s;if(a<3)throw new RangeError("not enough observations");let c=n.concat(o),l=Array.from({length:a},(M,v)=>v).sort((M,v)=>c[M]-c[v]),m=new Array(a),u=0;for(;u<a;){let M=u;for(;M+1<a&&c[l[M+1]]===c[l[u]];)M++;let v=0;for(let E=u;E<=M;E++)v+=(E+1-(a+1)/2)**2;v/=M-u+1;for(let E=u;E<=M;E++)m[l[E]]=v;u=M+1}let h=0;for(let M=0;M<f;M++)h+=m[M];let p=0;for(let M of m)p+=M;p/=a;let d=0;for(let M of m)d+=(M-p)**2;let g=f*p,b=f*s/(a*(a-1))*d,N=(h-g)/Math.sqrt(b),w=i==="less"?C(N):i==="greater"?C(N,{lowerTail:!1}):2*C(-Math.abs(N));return{method:"Mood two-sample test of scale",alternative:i,statistic:N,statisticName:"Z",pValue:w}}function mt(e,t){let r=0;for(let n=e.length-1;n>=0;n--)r=r*t+e[n];return r}var kn=[0,.221157,-.147981,-2.07119,4.434685,-2.706056],Sn=[0,.042981,-.293762,-1.752461,5.682633,-3.582633],In=[.544,-.39978,.025054,-6714e-7],Vn=[1.3822,-.77857,.062767,-.0020322],Ln=[-1.5861,-.31082,-.083751,.0038915],Fn=[-.4803,-.082676,.0030302],Cn=[-2.273,.459];function jn(e){if(!(e>=3)||e!==Math.floor(e))throw new RangeError("n must be an integer of at least 3");let t=new Float64Array(e);if(e===3)return t[0]=-Math.SQRT1_2,t[2]=Math.SQRT1_2,t;let r=Math.floor(e/2),n=new Float64Array(r),o=0;for(let m=0;m<r;m++)n[m]=-j((m+1-.375)/(e+.25)),o+=n[m]*n[m];o*=2;let i=Math.sqrt(o),f=1/Math.sqrt(e),s=n[0]/i+mt(kn,f),a=new Float64Array(r);a[0]=s;let c,l;if(e>5){let m=n[1]/i+mt(Sn,f);a[1]=m,c=2,l=Math.sqrt((o-2*n[0]*n[0]-2*n[1]*n[1])/(1-2*s*s-2*m*m))}else c=1,l=Math.sqrt((o-2*n[0]*n[0])/(1-2*s*s));for(let m=c;m<r;m++)a[m]=n[m]/l;for(let m=0;m<r;m++)t[e-1-m]=a[m],t[m]=-a[m];return t}function Oe(e){let t=e.length,r=jn(t),n=e[t-1]-e[0],o=0;for(let c of e)o+=c/n;o/=t;let i=0,f=0,s=0;for(let c=0;c<t;c++){let l=e[c]/n-o;i+=r[c]*r[c],f+=l*l,s+=r[c]*l}let a=Math.sqrt(i*f);return(a-s)*(a+s)/(i*f)}var On=1.90985931710274,Pn=1.0471975511966;function Pe(e,t){if(Number.isNaN(e)||!(t>=3))return NaN;if(t===3){let f=On*(Math.asin(Math.sqrt(1-e))-Pn);return Math.max(f,0)}let r=Math.log(e);if(t<=11){let f=mt(Cn,t);if(r>=f)return 1e-99;let s=mt(In,t),a=Math.exp(mt(Vn,t));return C(-Math.log(f-r),{mean:s,sd:a,lowerTail:!1})}let n=Math.log(t),o=mt(Ln,n),i=Math.exp(mt(Fn,n));return C(r,{mean:o,sd:i,lowerTail:!1})}function zn(e,t,r={}){let n;t!==void 0&&!Array.isArray(t)?r=t:n=t;let o=ct(e,n),i=r.varEqual??!1,f=o.length;if(f<2)throw new RangeError("not enough groups");let s=o.map(h=>h.length);if(s.some(h=>h<2))throw new RangeError("not enough observations");let a=o.map(Y),c=o.map(K),l=s.reduce((h,p)=>h+p,0),m,u;if(i){let h=Y(o.flat()),p=0,d=0;for(let g=0;g<f;g++)p+=s[g]*(a[g]-h)**2,d+=(s[g]-1)*c[g];u=l-f,m=p/(f-1)/(d/u)}else{let h=s.map((N,w)=>N/c[w]),p=h.reduce((N,w)=>N+w,0),d=0,g=0;for(let N=0;N<f;N++)d+=(1-h[N]/p)**2/(s[N]-1),g+=h[N]*a[N];d/=f*f-1,g/=p;let b=0;for(let N=0;N<f;N++)b+=h[N]*(a[N]-g)**2;m=b/((f-1)*(1+2*(f-2)*d)),u=1/(3*d)}return{method:i?"One-way analysis of means":"One-way analysis of means (not assuming equal variances)",statistic:m,statisticName:"F",parameter:[f-1,u],parameterName:["num df","denom df"],pValue:X(m,f-1,u,!1,!1)}}function _n(e){let t=Array.from(e).filter(o=>!Number.isNaN(o)).sort((o,i)=>o-i),r=t.length;if(r<3||r>5e3)throw new RangeError("sample size must be between 3 and 5000");if(!Number.isFinite(t[0])||!Number.isFinite(t[r-1]))throw new RangeError("'x' must be finite");if(t[r-1]===t[0])throw new RangeError("all 'x' values are identical");let n=Oe(t);return{method:"Shapiro-Wilk normality test",statistic:1-n,statisticName:"W",pValue:Pe(n,r)}}function Jt(e,t,r){let n=[0,0];for(let o=Math.max(0,t);o<Math.min(r,e.length);o++)n=F(n,[e[o],0]);return n[0]}function Wn([[e,t],[r,n]]){let o=e+r,i=t+n,f=e+t,s=Math.max(0,f-i),a=Math.min(f,o),c=new Float64Array(a-s+1);for(let l=s;l<=a;l++)c[l-s]=ut(l,o,i,f,!1);return{lo:s,d:c}}function Hn(e,t){let r=new Float64Array(e.length+t.length-1);for(let n=0;n<e.length;n++){let o=e[n];if(o!==0)for(let i=0;i<t.length;i++)r[n+i]+=o*t[i]}return r}var Vt=class{lo;hi;logNull;constructor(t){let r=0,n=new Float64Array([1]);for(let o of t){let i=Wn(o);r+=i.lo,n=Hn(n,i.d)}this.lo=r,this.hi=r+n.length-1,this.logNull=n.map(Math.log)}density(t){let r=this.logNull.length,n=new Float64Array(r);if(t===0||t===1/0)return n[t===0?0:r-1]=1,n;let o=Math.log(t),i=-1/0;for(let s=0;s<r;s++){let a=this.logNull[s]+(this.lo+s)*o;n[s]=a,a>i&&(i=a)}for(let s=0;s<r;s++)n[s]=Math.exp(n[s]-i);let f=Jt(n,0,r);for(let s=0;s<r;s++)n[s]=n[s]/f;return n}mean(t){if(t===0)return this.lo;if(t===1/0)return this.hi;let r=this.density(t),n=[0,0];for(let o=0;o<r.length;o++)n=F(n,[(this.lo+o)*r[o],0]);return n[0]}cdf(t,r,n){let o=this.density(r),i=t-this.lo;return n?Jt(o,i,o.length):Jt(o,0,i+1)}};function te(e,t){return t?Z(e,0,1):1/Z(r=>e(1/r),Number.EPSILON,1)}function ze(e,t){if(t===e.lo)return 0;if(t===e.hi)return 1/0;let r=e.mean(1);return r===t?1:te(n=>e.mean(n)-t,r>t)}function ee(e,t,r){if(t===e.hi)return 1/0;let n=e.cdf(t,1,!1);return n===r?1:te(o=>r-e.cdf(t,o,!1),n<r)}function ne(e,t,r){if(t===e.lo)return 0;let n=e.cdf(t,1,!0);return n===r?1:te(o=>e.cdf(t,o,!0)-r,n>r)}function $n(e,t={}){let r=e.length;if(r<1)throw new RangeError("'x' must have at least one stratum");let n=e[0].length,o=e[0][0]?.length??0;if(n<2||o<2||r<2)throw new RangeError("each dimension in table must be >= 2");for(let l of e){if(l.length!==n||l.some(m=>m.length!==o))throw new RangeError("all strata must have the same dimensions");if(l.some(m=>m.some(u=>!Number.isFinite(u)||u<0)))throw new RangeError("all entries of 'x' must be nonnegative and finite")}let i=e.map(l=>l.reduce((m,u)=>m+u.reduce((h,p)=>h+p,0),0));if(i.some(l=>l<2))throw new RangeError("sample size in each stratum must be > 1");let f=L(t.alternative),s=t.correct??!0,a=t.exact??!1,c=t.confLevel??.95;if(G(c),n===2&&o===2){let l=e.map(m=>[[m[0][0],m[0][1]],[m[1][0],m[1][1]]]);return a?Kn(l,f,c):Dn(l,i,f,s,c)}return Un(e,i,n,o)}function Dn(e,t,r,n,o){let i=0,f=0,s=0,a=0,c=0,l=0,m=0,u=0;e.forEach(([[M,v],[E,A]],q)=>{let k=t[q],y=M+v,T=E+A,S=M+E,x=v+A;i+=M,f+=y*S/k,s+=y*T*S*x/(k*k*(k-1));let V=(M+A)/k,O=(v+E)/k,P=M*A/k,H=v*E/k;a+=P,c+=H,l+=V*P,m+=V*H+O*P,u+=O*H});let h=i-f,p=n&&Math.abs(h)>=.5?.5:0,d=(Math.abs(h)-p)**2/s,g=r==="two.sided"?D(d,.5,2,!1,!1):C(Math.sign(h)*Math.sqrt(d),{lowerTail:r==="less"}),b=a/c,N=Math.sqrt(l/(2*a*a)+m/(2*a*c)+u/(2*c*c)),w;if(r==="less")w=[0,b*Math.exp(j(o)*N)];else if(r==="greater")w=[b*Math.exp(j(o,{lowerTail:!1})*N),1/0];else{let M=j((1+o)/2);w=[b*Math.exp(-M*N),b*Math.exp(M*N)]}return{method:`Mantel-Haenszel chi-squared test ${p!==0?"with":"without"} continuity correction`,alternative:r,statistic:d,statisticName:"Mantel-Haenszel X-squared",parameter:1,parameterName:"df",pValue:g,confInt:w,confLevel:o,estimate:b,estimateNames:"common odds ratio",nullValue:1,nullValueName:"common odds ratio"}}function Kn(e,t,r){let n=new Vt(e),o=e.reduce((s,a)=>s+a[0][0],0),i;if(t==="two.sided"){let s=n.density(1),a=s[o-n.lo]*(1+1e-7),c=[0,0];for(let l of s)l<=a&&(c=F(c,[l,0]));i=Math.min(1,c[0])}else i=n.cdf(o,1,t==="greater");let f;if(t==="less")f=[0,ee(n,o,1-r)];else if(t==="greater")f=[ne(n,o,1-r),1/0];else{let s=(1-r)/2;f=[ne(n,o,s),ee(n,o,s)]}return{method:"Exact conditional test of independence in 2 x 2 x k tables",alternative:t,statistic:o,statisticName:"S",pValue:i,confInt:f,confLevel:r,estimate:ze(n,o),estimateNames:"common odds ratio",nullValue:1,nullValueName:"common odds ratio"}}function Un(e,t,r,n){let o=(r-1)*(n-1),i=new Array(o).fill(0),f=Array.from({length:o},()=>new Array(o).fill(0));e.forEach((c,l)=>{let m=t[l],u=c.map(d=>d.reduce((g,b)=>g+b,0)),h=Array.from({length:n},(d,g)=>c.reduce((b,N)=>b+N[g],0)),p=1/(m*m*(m-1));for(let d=0;d<n-1;d++)for(let g=0;g<r-1;g++){let b=g+(r-1)*d;i[b]+=c[g][d]-u[g]*h[d]/m;for(let N=0;N<n-1;N++)for(let w=0;w<r-1;w++){let M=(g===w?m*u[g]:0)-u[g]*u[w],v=(d===N?m*h[d]:0)-h[d]*h[N];f[b][w+(r-1)*N]+=p*M*v}}});let s=Ee(f,i),a=0;for(let c=0;c<o;c++)a+=i[c]*s[c];return{method:"Cochran-Mantel-Haenszel test",statistic:a,statisticName:"Cochran-Mantel-Haenszel M^2",parameter:o,parameterName:"df",pValue:D(a,o/2,2,!1,!1)}}var _e=new Map;function Bn(e,t){let r=`${e},${t}`,n=_e.get(r);if(n!==void 0)return n;let o=e+t,i=[];for(let u=1;u<=o;u++)i.push(Math.min(u,o+1-u));let f=i.reduce((u,h)=>u+h,0),s=Array.from({length:e+1},()=>new Float64Array(f+1));s[0][0]=1;for(let u=0;u<o;u++){let h=o-u,p=i[u],d=Array.from({length:e+1},()=>new Float64Array(f+1));for(let g=0;g<=e;g++){let b=s[g],N=e-g;if(N>h)continue;let w=N/h;for(let M=0;M<=f;M++){let v=b[M];v!==0&&(N>0&&(d[g+1][M+p]+=v*w),N<h&&(d[g][M]+=v*(1-w)))}}s=d}let a=s[e],c=0;for(;c<a.length&&a[c]===0;)c++;let l=a.length-1;for(;l>c&&a[l]===0;)l--;let m={min:c,probs:a.slice(c,l+1)};return _e.set(r,m),m}function re(e,t,r,n=!0){if(Number.isNaN(e)||!(t>=1)||!(r>=1)||t!==Math.floor(t)||r!==Math.floor(r))return NaN;let{min:o,probs:i}=Bn(t,r),f=Math.floor(e+1e-7)-o,s=0;if(n)for(let a=0;a<=Math.min(f,i.length-1);a++)s+=i[a];else for(let a=Math.max(f+1,0);a<i.length;a++)s+=i[a];return Math.min(s,1)}function Xn(e,t,r={}){let n=Array.from(e).filter(d=>!Number.isNaN(d)),o=Array.from(t).filter(d=>!Number.isNaN(d)),i=n.length,f=o.length;if(i<1)throw new RangeError("not enough 'x' observations");if(f<1)throw new RangeError("not enough 'y' observations");let s=L(r.alternative),a=i+f,c=U(n.concat(o)),l=c.map(d=>Math.min(d,a-d+1)),m=0;for(let d=0;d<i;d++)m+=l[d];let u=new Set(c).size<a,h=r.exact??(i<50&&f<50&&!u),p;if(h&&!u){let d=b=>re(b-1,i,f,!1),g=b=>re(b,i,f,!0);if(s==="two.sided"){let b=Math.floor((i+1)**2/4)+Math.floor(i*f/2)/2;p=Math.min(1,2*(m>b?d(m):g(m)))}else s==="less"?p=d(m):p=g(m)}else{let d=0;for(let M of l)d+=M*M;let g=a%2===0,b=g?i*(a+2)/4:i*(a+1)**2/(4*a),N=g?i*f*(16*d-a*(a+2)**2)/(16*a*(a-1)):i*f*(16*a*d-(a+1)**4)/(16*a*a*(a-1)),w=(m-b)/Math.sqrt(N);p=s==="two.sided"?2*Math.min(C(w),C(w,{lowerTail:!1})):s==="less"?C(w,{lowerTail:!1}):C(w)}return{method:"Ansari-Bradley test",alternative:s,statistic:m,statisticName:"AB",pValue:p,nullValue:1,nullValueName:"ratio of scales"}}var Qn=[1.2337005501361697,7831619385924639e-32];function Yn(e,t,r){let n=(l,m)=>{let u=new Float64Array(t*t);for(let h=0;h<t;h++)for(let p=0;p<t;p++){let d=l[h*t+p];if(d!==0)for(let g=0;g<t;g++)u[h*t+g]+=d*m[p*t+g]}return u},o=l=>{let m=0;for(let p of l)m=Math.max(m,Math.abs(p));if(m===0||!Number.isFinite(m))return 0;let u=Math.floor(Math.log2(m));if(Math.abs(u)<500)return 0;let h=2**-u;for(let p=0;p<l.length;p++)l[p]*=h;return u},i,f=0,s=e.slice(),a=0,c=r;for(;c>0;)c&1&&(i=i===void 0?s.slice():n(i,s),f+=a,f+=o(i)),c>>=1,c>0&&(s=n(s,s),a*=2,a+=o(s));return[i,f]}function We(e,t){if(Number.isNaN(t)||!(e>=1)||e!==Math.floor(e))return NaN;if(t<=1/(2*e))return 0;if(t>=1)return 1;if(e*t<1){let[l,m]=yt(e,t),u=2*l-1+2*m,h=1,p=0;for(let d=1;d<=e;d++)h*=d/e*u,h<2**-500&&(h*=2**500,p-=500);for(;p<-1e3;)h*=2**-1e3,p+=1e3;return h*2**p}let r=Math.floor(e*t)+1,n=2*r-1,o=r-e*t,i=new Float64Array(n*n);for(let l=0;l<n;l++)for(let m=0;m<n;m++)i[l*n+m]=l-m+1>=0?1:0;for(let l=0;l<n;l++)i[l*n]-=Math.pow(o,l+1),i[(n-1)*n+l]-=Math.pow(o,n-l);2*o-1>0&&(i[(n-1)*n]+=Math.pow(2*o-1,n));for(let l=0;l<n;l++)for(let m=0;m<n;m++){let u=l-m+1;if(u>0){let h=1;for(let p=2;p<=u;p++)h*=p;i[l*n+m]/=h}}let[f,s]=Yn(i,n,e),a=f[(r-1)*n+r-1],c=s;for(let l=1;l<=e;l++)a=a*l/e,Math.abs(a)<2**-500&&(a*=2**500,c-=500);for(;c>1e3;)a*=2**1e3,c-=1e3;for(;c<-1e3;)a*=2**-1e3,c+=1e3;return a*2**c}function oe(e,t=!0){if(Number.isNaN(e))return NaN;if(e<=0)return t?0:1;if(e===1/0)return t?1:0;if(e<1){let o=xt(Qn,yt(e,e)),i=o[0]+o[1],f=Math.exp(-o[0])*(1-o[1]),s=0;for(let c=2;c<100;c++){let l=Math.exp(-(2*c-1)*(2*c-1)*i);if(s+=l,l<=1e-17*(s+f))break}let a=Math.sqrt(2*Math.PI)/e*(f+s);return t?a:1-a}let r=0;for(let o=1;o<100;o++){let i=Math.exp(-2*o*o*e*e);if(r+=o%2===1?i:-i,i<=1e-17*Math.abs(r))break}let n=2*r;return t?1-n:n}function He(e,t){if(Number.isNaN(t)||!(e>=1)||e!==Math.floor(e))return NaN;if(t<=0)return 1;if(t>1)return 0;let[r,n]=yt(e,t),o=Math.floor(e-r-n),i=0;for(let f=0;f<=o;f++){let s=F(Lt(e-f,-r),[-n,0]);if(s[0]<=0)break;let a=F(Lt(f,r),[n,0]),c=xt(a,[e,0]),l=xt(s,[e,0]);i+=ue(f,e-f,c,l,!1)/(c[0]+c[1])}return Math.min(t*i,1)}function $e(e,t,r,n={}){let o=n.alternative??"two.sided";if(Number.isNaN(e)||!(t>=1)||!(r>=1)||t!==Math.floor(t)||r!==Math.floor(r))return NaN;if(e<=0)return 1;if(e>1)return 0;let i=t+r,f;if(n.z!==void 0){if(n.z.length!==i)throw new RangeError("z must have length m + n");let u=[...n.z].sort((h,p)=>h-p);f=new Array(i+1).fill(!1);for(let h=1;h<i;h++)f[h]=u[h]!==u[h-1]}let s=e*t*r*(1-1e-10),a=(u,h)=>{let p=u*r-h*t;return(o==="two.sided"?Math.abs(p):o==="greater"?p:-p)>=s},c=new Float64Array(r+1),l=new Float64Array(r+1),m=0;for(let u=0;u<=t;u++){for(let h=0;h<=r;h++){if(u===0&&h===0){l[0]=1;continue}let p=u+h,d=(u>0?u/p*c[h]:0)+(h>0?h/p*l[h-1]:0);(f===void 0?p<i:f[p])&&a(u,h)?(d>0&&(m+=d*ut(u,t,r,p,!1)),l[h]=0):l[h]=d}[c,l]=[l,c],l.fill(0)}return Math.min(m,1)}function De(e,t){return e==="two.sided"?"two-sided":`the CDF of x lies ${e==="less"?"below":"above"} ${t?"the null hypothesis":"that of y"}`}function Gn(e,t,r={}){let n=Array.from(e).filter(N=>!Number.isNaN(N)).sort((N,w)=>N-w),o=n.length;if(o<1)throw new RangeError("not enough 'x' data");let i=L(r.alternative),f=i==="two.sided"?"D":i==="greater"?"D^+":"D^-";if(typeof t=="function"){let N=-1/0,w=-1/0;for(let q=0;q<o;q++){let k=t(n[q]);N=Math.max(N,(q+1)/o-k),w=Math.max(w,k-q/o)}let M=i==="two.sided"?Math.max(N,w):i==="greater"?N:w,v=new Set(n).size<o,E=r.exact??(o<100&&!v),A;return i==="two.sided"?A=E?1-We(o,M):oe(Math.sqrt(o)*M,!1):A=E?He(o,M):Math.exp(-2*o*M*M),{method:`${E?"Exact":"Asymptotic"} one-sample Kolmogorov-Smirnov test`,alternative:De(i,!0),exact:E,statistic:M,statisticName:f,pValue:Math.min(1,Math.max(0,A))}}let s=Array.from(t).filter(N=>!Number.isNaN(N)),a=s.length;if(a<1)throw new RangeError("not enough 'y' data");let c=n.map(N=>[N,0]).concat(s.map(N=>[N,1]));c.sort((N,w)=>N[0]-w[0]);let l=0,m=0,u=0,h=0;for(let N=0;N<c.length;N++){if(c[N][1]===0?l++:m++,N+1<c.length&&c[N+1][0]===c[N][0])continue;let w=l/o-m/a;u=Math.max(u,w),h=Math.max(h,-w)}let p=i==="two.sided"?Math.max(u,h):i==="greater"?u:h,d=new Set(c.map(N=>N[0])).size<c.length,g=r.exact??o*a<1e4,b;if(g)b=$e(p,o,a,d?{alternative:i,z:c.map(N=>N[0])}:{alternative:i});else{let N=o*a/(o+a);b=i==="two.sided"?oe(Math.sqrt(N)*p,!1):Math.exp(-2*N*p*p)}return{method:`${g?"Exact":"Asymptotic"} two-sample Kolmogorov-Smirnov test`,alternative:De(i,!1),exact:g,statistic:p,statisticName:f,pValue:Math.min(1,Math.max(0,b))}}function Ke(e,t,r){let n=Array.from(e);if(n.length!==t.length)throw new RangeError("'x' and 'g' must have the same length");let o=new Map;for(let f=0;f<n.length;f++){let s=t[f];if(typeof s=="number"&&Number.isNaN(s)||r&&Number.isNaN(n[f]))continue;let a=o.get(s);a===void 0&&o.set(s,a=[]),a.push(n[f])}let i=Array.from(o.keys()).sort((f,s)=>typeof f=="number"&&typeof s=="number"?f-s:String(f)<String(s)?-1:String(f)>String(s)?1:0);return{levels:i,groups:i.map(f=>o.get(f))}}function se(e,t,r){let n=[],o=[];for(let s=0;s<e-1;s++)for(let a=s+1;a<e;a++)n.push(t(a,s)),o.push([a-1,s]);let i=Bt(n,r),f=Array.from({length:e-1},()=>new Array(e-1).fill(NaN));return o.forEach(([s,a],c)=>f[s][a]=i[c]),f}function ae(e,t,r,n){return{method:e,pValue:r,rowNames:t.slice(1).map(String),colNames:t.slice(0,-1).map(String),pAdjustMethod:n}}function Zn(e,t,r={}){let n=r.paired??!1,o=r.poolSd??!n;if(n&&o)throw new RangeError("pooling of SD is incompatible with paired tests");let i=L(r.alternative),f=r.pAdjustMethod??"holm",{levels:s,groups:a}=Ke(e,t,!n),c=s.length;if(c<2)throw new RangeError("there must be at least two groups");let l,m;if(o){m="t tests with pooled SD";let u=a.map(b=>b.length),h=a.map(b=>b.length>0?Y(b):NaN),p=0,d=0;a.forEach(b=>{b.length>1&&(p+=K(b)*(b.length-1),d+=b.length-1)});let g=Math.sqrt(p/d);l=(b,N)=>{let w=(h[b]-h[N])/(g*Math.sqrt(1/u[b]+1/u[N]));return i==="less"?Q(w,d,!0,!1):i==="greater"?Q(w,d,!1,!1):2*Q(-Math.abs(w),d,!0,!1)}}else m=n?"paired t tests":"t tests with non-pooled SD",l=(u,h)=>Pt(a[u],a[h],{paired:n,alternative:i}).pValue;return ae(m,s,se(c,l,f),f)}function Jn(e,t,r={}){let{pAdjustMethod:n,alternative:o,...i}=r,f=n??"holm",{levels:s,groups:a}=Ke(e,t,!(i.paired??!1)),c=s.length;if(c<2)throw new RangeError("there must be at least two groups");let l="",m=se(c,(u,h)=>{let p=Dt(a[u],a[h],{...i,...o===void 0?{}:{alternative:o}});return l=p.method,p.pValue},f);return ae(l,s,m,f)}function tr(e,t,r={}){if(e.length!==t.length)throw new RangeError("'x' and 'n' must have the same length");let n=[],o=[];e.forEach((l,m)=>{Number.isNaN(l)||Number.isNaN(t[m])||(n.push(l),o.push(t[m]))});let i=n.length;if(i<2)throw new RangeError("too few groups");let f=r.pAdjustMethod??"holm",s=r.correct??!0,a=se(i,(l,m)=>Qt([n[l],n[m]],[o[l],o[m]],{correct:s}).pValue,f),c=Array.from({length:i},(l,m)=>m+1);return ae("Pairwise comparison of proportions",c,a,f)}function Ue(e){let t=e.flat(),r=Nt(t),n=[0,0],o=[0,0],i=[];for(let f of e){let s=Nt(f);i.push(s[0]);let a=B(s,r);n=F(n,vt(vt(a,a),[f.length,0]));for(let c of f){let l=B([c,0],s);o=F(o,vt(l,l))}}return{ssb:n[0],ssw:o[0],means:i}}function er(e,t){let r=ct(e,t),n=r.length;if(n<2)throw new RangeError("contrasts can be applied only to factors with 2 or more levels");let o=r.reduce((u,h)=>u+h.length,0),{ssb:i,ssw:f}=Ue(r),s=n-1,a=o-n,c=i/s,l=f/a,m=c/l;return{df:[s,a],sumSq:[i,f],meanSq:[c,l],fValue:m,pValue:a>0?X(m,s,a,!1,!1):NaN}}function nr(e,t,r={}){let n;t!==void 0&&!Array.isArray(t)?r=t:n=t;let{labels:o,groups:i}=Yt(e,n),f=i.length;if(f<2)throw new RangeError("contrasts can be applied only to factors with 2 or more levels");let s=r.confLevel??.95,c=i.reduce((d,g)=>d+g.length,0)-f,{ssw:l,means:m}=Ue(i),u=l/c,h=we(s,f,c),p={names:[],i:[],j:[],diff:[],lwr:[],upr:[],pAdj:[]};for(let d=0;d<f-1;d++)for(let g=d+1;g<f;g++){let b=m[g]-m[d],N=Math.sqrt(u/2*(1/i[g].length+1/i[d].length));p.names.push(`${o[g]}-${o[d]}`),p.i.push(g+1),p.j.push(d+1),p.diff.push(b),p.lwr.push(b-h*N),p.upr.push(b+h*N),p.pAdj.push(ge(Math.abs(b)/N,f,c,{lowerTail:!1}))}return p}function rr(e,t,r={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?r=t:n=t;let{sigmaX:o,sigmaY:i}=r,f=r.mu??0;if(o===void 0&&n===void 0)throw new RangeError("sigmaX (the known standard deviation of x) is required");if(o===void 0||n!==void 0&&i===void 0)throw new RangeError("sigmaX and sigmaY are both required for two samples");if(Number.isNaN(f))throw new RangeError("mu must be a number");let s=L(r.alternative),a=r.confLevel??.95;if(!(a>=0&&a<=1))throw new RangeError("confLevel must be between 0 and 1");let c=Array.from(e).filter(w=>!Number.isNaN(w)),l=n===void 0?void 0:Array.from(n).filter(w=>!Number.isNaN(w));if(c.length<3)throw new RangeError("x needs at least 3 non-missing values");if(l!==void 0&&l.length<3)throw new RangeError("y needs at least 3 non-missing values");let m=Nt(c)[0],u=l===void 0?NaN:Nt(l)[0],h=l===void 0?o/Math.sqrt(c.length):Math.sqrt(o**2/c.length+i**2/l.length),p=l===void 0?m:m-u,d=(p-f)/h,g,b;if(s==="less")g=C(d),b=[-1/0,p+j(a)*h];else if(s==="greater")g=C(d,{lowerTail:!1}),b=[p-j(a)*h,1/0];else{g=2*C(-Math.abs(d));let w=j(1-(1-a)/2)*h;b=[p-w,p+w]}let N=l!==void 0;return{method:N?"Two-sample z-Test":"One-sample z-Test",alternative:s,statistic:d,statisticName:"z",pValue:g,confInt:b,confLevel:a,estimate:N?[m,u]:m,estimateNames:N?["mean of x","mean of y"]:"mean of x",nullValue:f,nullValueName:N?"difference in means":"mean"}}function or(e,t,r={}){let n=r.intercept??!0,o=e.length>0&&typeof e[0]!="number"?e.map(R=>Array.from(R)):Array.from(e,R=>[R]),i=Array.from(t);if(o.length!==i.length)throw new RangeError("variable lengths differ (found for 'x')");let f=r.weights===void 0?void 0:Array.from(r.weights);if(f!==void 0&&f.length!==i.length)throw new RangeError("variable lengths differ (found for '(weights)')");if(f?.some(R=>R<0))throw new RangeError("missing or negative weights not allowed");let s=i.map((R,I)=>!Number.isNaN(R)&&o[I].every(_=>!Number.isNaN(_))&&(f===void 0||!Number.isNaN(f[I]))),a=o.filter((R,I)=>s[I]).map(R=>n?[1,...R]:R),c=i.filter((R,I)=>s[I]),l=f?.filter((R,I)=>s[I]);if(c.length===0)throw new RangeError("0 (non-NA) cases");let m=c.map((R,I)=>l===void 0||l[I]!==0),u=a.filter((R,I)=>m[I]),h=c.filter((R,I)=>m[I]),p=l?.filter((R,I)=>m[I]),d=h.length;if(d===0)throw new RangeError("all weights are zero");let g=p?.map(Math.sqrt),b=g===void 0?u:u.map((R,I)=>R.map(_=>_*g[I])),N=g===void 0?h:h.map((R,I)=>R*g[I]),w=ye(b),M=w.rank,v=ve(w,N),E=xe(w,N),A=g===void 0?E:E.map((R,I)=>R/g[I]),q=[],k=[],y=0;c.forEach((R,I)=>{if(m[I])q.push(A[y]),k.push(R-A[y]),y++;else{let _=a[I].reduce((Mt,Be,fe)=>Number.isNaN(v[fe])?Mt:Mt+Be*v[fe],0);k.push(_),q.push(R-_)}});let T=k.filter((R,I)=>m[I]),S=d-M,x=p??new Array(d).fill(1),V=0;for(let R=0;R<d;R++)V+=x[R]*A[R]**2;let O=V/S,P=Math.sqrt(O),H=w.qr.slice(0,M).map(R=>R.slice(0,M)),z=M>0?Ae(H):[],W=w.pivot.slice(0,M).map((R,I)=>[R,I]).sort((R,I)=>R[0]-I[0]),$=W.map(([R])=>v[R]),et=W.map(([,R])=>Math.sqrt(z[R][R]*O)),nt=$.map((R,I)=>R/et[I]),dt=nt.map(R=>2*Q(-Math.abs(R),S,!0,!1)),ot={coefficients:v,residuals:q,fittedValues:k,rank:M,dfResidual:S,coefTable:{estimate:$,stdError:et,tValue:nt,pValue:dt},sigma:P,rSquared:0,adjRSquared:0,intercept:n,qr:w},ie=n?1:0,bt=M-ie;if(bt===0)return ot;let gt=0;if(n){let R=x.reduce((_,Mt)=>_+Mt,0),I=0;for(let _=0;_<d;_++)I+=x[_]*T[_]/R;for(let _=0;_<d;_++)gt+=x[_]*(T[_]-I)**2}else for(let R=0;R<d;R++)gt+=x[R]*T[R]**2;ot.rSquared=gt/(gt+V),ot.adjRSquared=1-(1-ot.rSquared)*((d-ie)/S);let le=gt/bt/O;return ot.fStatistic={value:le,numdf:bt,dendf:S},ot.fPValue=X(le,bt,S,!1,!1),ot}function sr(e,t={}){let r=t.level??.95,n=it((1+r)/2,e.dfResidual,!0,!1),{estimate:o,stdError:i}=e.coefTable,f=e.coefficients.map(()=>NaN),s=e.coefficients.map(()=>NaN),a=0;return e.coefficients.forEach((c,l)=>{Number.isNaN(c)||(f[l]=o[a]-n*i[a],s[l]=o[a]+n*i[a],a++)}),{lower:f,upper:s}}function ar(e,t,r={}){let o=(t.length>0&&typeof t[0]!="number"?t.map(p=>Array.from(p)):Array.from(t,p=>[p])).map(p=>e.intercept?[1,...p]:p),i=e.rank,f=e.qr.pivot.slice(0,i),s=e.qr.qr.slice(0,i).map(p=>p.slice(0,i)),a=e.sigma**2,c=o.map(p=>p.reduce((d,g,b)=>Number.isNaN(e.coefficients[b])?d:d+g*e.coefficients[b],0)),l=o.map(p=>{let d=new Array(i).fill(0);for(let g=0;g<i;g++){let b=p[f[g]];for(let N=0;N<g;N++)b-=s[N][g]*d[N];d[g]=b/s[g][g]}return Math.sqrt(d.reduce((g,b)=>g+b*b,0)*a)}),m=r.interval??"none";if(m==="none")return{fit:c,seFit:l};let u=it((1+(r.level??.95))/2,e.dfResidual,!0,!1),h=l.map(p=>u*Math.sqrt(p*p+(m==="prediction"?a:0)));return{fit:c,seFit:l,lwr:c.map((p,d)=>p-h[d]),upr:c.map((p,d)=>p+h[d])}}export{nr as TukeyHSD,Xn as ansariTest,er as aov,xn as bartlettTest,Xt as binomTest,Qe as chisqTest,sr as confint,Xe as corTest,Ze as fisherTest,Tn as flignerTest,An as friedmanTest,En as kruskalTest,Gn as ksTest,or as lm,$n as mantelhaenTest,Mn as mcnemarTest,qn as moodTest,zn as onewayTest,Bt as pAdjust,tr as pairwisePropTest,Zn as pairwiseTTest,Jn as pairwiseWilcoxTest,bn as poissonTest,ar as predict,Qt as propTest,Rn as quadeTest,_n as shapiroTest,Pt as tTest,vn as varTest,Dt as wilcoxTest,rr as zTest};
1
+ /*! rStats.js 0.7.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{$ as qt,B as At,C as at,G as ut,H as $t,M as ht,N as be,R as pt,S as Me,W as ye,X as ve,Y as xe,_ as Rt,c as D,d as Ot,l as zt,m as st,r as G,s as wt,x as _t}from"./chunks/chunk-6R7YDHA2.js";import{h as ke,k as Ie,l as Se,t as Le,y as Ve}from"./chunks/chunk-UIOAWLAN.js";import{a as C,b as Ae,c as U,f as cn}from"./chunks/chunk-SXSJXDD3.js";import{k as Y,l as it}from"./chunks/chunk-PTPPP4TI.js";import{c as Te}from"./chunks/chunk-QNQJA6KZ.js";import"./chunks/chunk-ZYA4ISAT.js";import{a as Nt,b as Z,c as K,e as Ee,f as W,g as lt,h as ct,i as Tt}from"./chunks/chunk-MVG5LUZU.js";import{a as Re,d as qe}from"./chunks/chunk-J3SNI7KY.js";import{b as Ne}from"./chunks/chunk-YKN6OGJL.js";import{g as P,h as V,s as we}from"./chunks/chunk-ANYGLFT4.js";import{b as jt,c as vt,d as F,e as de,f as Q,g as xt,i as Et,k as ge}from"./chunks/chunk-ZW52Z3GY.js";function Ht(e,t,o={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?o=t:n=t;let r=C(o.alternative),s=o.mu??0,i=o.paired??!1,l=o.varEqual??!1,a=o.confLevel??.95;if(Number.isNaN(s))throw new RangeError("mu must be a number");if(Ae(a),i&&n===void 0)throw new TypeError("y is required when paired is true");let f=Array.from(e),c=n===void 0?void 0:Array.from(n);if(i){let[E,R]=Tt(f,c);f=E.map((k,v)=>k-R[v]),c=void 0}else f=ct(f),c!==void 0&&(c=ct(c));let m,u,h,p,M,d,b,w=f.length;if(w<2)throw new Error("not enough 'x' observations");let g=Z(f),N=K(f);if(c===void 0){if(u=w-1,h=Math.sqrt(N/w),h<10*Number.EPSILON*Math.abs(g))throw new Error("data are essentially constant");m=(g-s)/h,d=i?"Paired t-test":"One Sample t-test",p=g,M=i?"mean difference":"mean of x",b=i?"mean difference":"mean"}else{let E=c.length;if(E<1||!l&&E<2)throw new Error("not enough 'y' observations");if(l&&w+E<3)throw new Error("not enough observations");let R=Z(c),k=K(c);if(d=`${l?"":"Welch"} Two Sample t-test`,p=[g,R],M=["mean of x","mean of y"],b="difference in means",l){u=w+E-2;let v=0;w>1&&(v+=(w-1)*N),E>1&&(v+=(E-1)*k),v/=u,h=Math.sqrt(v*(1/w+1/E))}else{let v=N/w,T=k/E;h=Math.sqrt(v+T),u=(h*h)**2/(v*v/(w-1)+T*T/(E-1))}if(h<10*Number.EPSILON*Math.max(Math.abs(g),Math.abs(R)))throw new Error("data are essentially constant");m=(g-R-s)/h}let y,x;if(r==="less")y=Y(m,u,!0,!1),x=[-1/0,m+it(a,u,!0,!1)];else if(r==="greater")y=Y(m,u,!1,!1),x=[m-it(a,u,!0,!1),1/0];else{y=2*Y(-Math.abs(m),u,!0,!1);let E=1-a,R=it(1-E/2,u,!0,!1);x=[m-R,m+R]}return x=[s+x[0]*h,s+x[1]*h],{method:d,alternative:r,statistic:m,statisticName:"t",parameter:u,parameterName:"df",pValue:y,confInt:x,confLevel:a,estimate:p,estimateNames:M,nullValue:s,nullValueName:b,stdErr:h}}function bt(e){return` with simulated p-value
3
+ (based on ${fn(e)} replicates)`}function fn(e){if(!Number.isFinite(e)||e===0)return String(e);let t=e.toExponential(14).replace(/\.?0+e/,"e"),[o,n]=t.split("e"),r=Number(n),s=`${o}e${r<0?"-":"+"}${String(Math.abs(r)).padStart(2,"0")}`,i=String(Number(e.toPrecision(15)));return i.length<=s.length?i:s}function J(e){let t=[0,0],o=0;for(let n of e)t=F(t,[n,0]),o+=n;return Number.isFinite(o)?t[0]:o}function mn(e,t,o){return Array.isArray(t)?un(e,t,o??{}):hn(e,t??{})}var Fe=(e,t)=>e<t?-1:e>t?1:0;function un(e,t,o){if(e.length!==t.length)throw new RangeError("'x' and 'y' must have the same length");let n=u=>u==null;for(let u of[...e,...t])if(!n(u)&&typeof u!="string")throw new TypeError("factor values must be strings (or null for missing values)");let r=[],s=[];e.forEach((u,h)=>{let p=t[h];!n(u)&&!n(p)&&(r.push(u),s.push(p))});let i=[...new Set(r)].sort(Fe),l=[...new Set(s)].sort(Fe);if(i.length<2||l.length<2)throw new RangeError("'x' and 'y' must have at least 2 levels");let a=new Map(i.map((u,h)=>[u,h])),f=new Map(l.map((u,h)=>[u,h])),c=i.map(()=>l.map(()=>0));return r.forEach((u,h)=>c[a.get(u)][f.get(s[h])]++),{...ze(c,o),rowLevels:i,colLevels:l}}function hn(e,t){if(e.length>0&&typeof e[0]!="number"){let n=e.map(s=>Array.from(s)),r=n[0].length;if(n.some(s=>s.length!==r))throw new TypeError("all rows of the matrix must have the same length");return n.length===1?Wt(n[0],t):r===1?Wt(n.map(s=>s[0]),t):ze(n,t)}return Wt(Array.from(e),t)}function Ce(e){let t=e.B??2e3;if(!(t>=0&&t<2**31))throw new RangeError("'B' must be a non-negative number");return t}function Pe(e,t,o){let n=(1-64*Number.EPSILON)*t,r=0;for(let s=0;s<e.length;s++)e[s]>=n&&r++;return(1+r)/(o+1)}function je(e,t){return Number.isNaN(e)?NaN:D(e,t/2,2,!1,!1)}function Oe(e){if(!e.some(t=>t<5)&&e.some(Number.isNaN))throw new RangeError("missing value where TRUE/FALSE needed (the expected counts contain NaN)")}function Wt(e,t){let o=e.length;if(e.some(m=>Number.isNaN(m)||m<0))throw new RangeError("all entries of 'x' must be non-negative and finite");if(o<2)throw new TypeError("'x' must have at least 2 elements");let n=J(e);if(!(n>0))throw new RangeError("at least one entry of 'x' must be positive");let r=t.p===void 0?e.map(()=>1/o):Array.from(t.p);if(r.length!==o)throw new TypeError("'x' and 'p' must have the same number of elements");if(r.some(Number.isNaN))throw new RangeError("p contains missing values");if(r.some(m=>m<0))throw new RangeError("probabilities must be non-negative");if(t.rescaleP??!1){let m=J(r);r=r.map(u=>u/m)}else if(Math.abs(J(r)-1)>Math.sqrt(Number.EPSILON))throw new RangeError("probabilities must sum to 1");let s=r.map(m=>n*m);Oe(s);let i=r.map((m,u)=>s[u]*(1-m)),l=J(e.map((m,u)=>(m-s[u])**2/s[u])),a="Chi-squared test for given probabilities",f=o-1,c;if(t.simulatePValue??!1){let m=Ce(t);a+=bt(m),f=NaN,c=Pe(pn(n,r,s,m),l,m)}else c=je(l,f);return{method:a,statistic:l,statisticName:"X-squared",parameter:f,parameterName:"df",pValue:c,observed:e,expected:s,residuals:e.map((m,u)=>(m-s[u])/Math.sqrt(s[u])),stdres:e.map((m,u)=>(m-s[u])/Math.sqrt(i[u]))}}function pn(e,t,o,n){let r=t.length,s=xe(r,{size:Math.trunc(n*e),replace:!0,prob:t}),i=Math.trunc(e);if(s.length===0)return new Float64Array(0);if(i===0)throw new RangeError("invalid 'nrow' value (too large or NA)");let l=Math.ceil(s.length/i),a=new Float64Array(l),f=new Float64Array(r);for(let c=0;c<l;c++){f.fill(0);for(let u=0;u<i;u++)f[s[(c*i+u)%s.length]]++;let m=0;for(let u=0;u<r;u++)m+=(f[u]-o[u])**2/o[u];a[c]=m}return a}function dn(e,t,o,n){let r=e.length,s=t.length,i=e.reduce((c,m)=>c+m,0),l=Rt(i),a=new Int32Array(r*s),f=new Float64Array(Math.trunc(n));for(let c=0;c<f.length;c++){qt(e,t,l,a);let m=0;for(let u=0;u<s;u++)for(let h=0;h<r;h++){let p=o[h][u];m+=(a[h+u*r]-p)**2/p}f[c]=m}return f}function ze(e,t){let o=t.correct??!0,n=e.length,r=e[0].length,s=e.flat();if(s.some(w=>!(w>=0&&w<1/0)))throw new RangeError("all entries of 'x' must be non-negative and finite");let i=J(s);if(!(i>0))throw new RangeError("at least one entry of 'x' must be positive");let l=e.map(w=>J(w)),a=e[0].map((w,g)=>J(e.map(N=>N[g]))),f=l.map(w=>a.map(g=>w*g/i));Oe(f.flat());let c=e.map((w,g)=>w.map((N,y)=>N-f[g][y])),m="Pearson's Chi-squared test",u,h=(n-1)*(r-1),p,M=(t.simulatePValue??!1)&&l.every(w=>w>0)&&a.every(w=>w>0),d=!M&&o&&n===2&&r===2?Math.min(.5,...c.flat().map(Math.abs)):0;if(M){let w=Ce(t);m+=bt(w),u=J(c.flatMap((N,y)=>N.map((x,E)=>x*x/f[y][E]))),h=NaN;let g=dn(l.map(N=>Math.trunc(N)),a.map(N=>Math.trunc(N)),f,w);p=Pe(g,u,w)}else d>0?(m+=" with Yates' continuity correction",u=J(c.flatMap((w,g)=>w.map((N,y)=>(Math.abs(N)-d)**2/f[g][y])))):u=J(c.flatMap((w,g)=>w.map((N,y)=>N*N/f[g][y])));let b=f.map((w,g)=>w.map((N,y)=>N*(1-l[g]/i)*(1-a[y]/i)));return{method:m,statistic:u,statisticName:"X-squared",parameter:h,parameterName:"df",pValue:p??je(u,h),observed:e,expected:f,residuals:c.map((w,g)=>w.map((N,y)=>N/Math.sqrt(f[g][y]))),stdres:c.map((w,g)=>w.map((N,y)=>N/Math.sqrt(b[g][y])))}}var gn=Math.pow(Number.EPSILON,.25);function X(e,t,o,n={}){let r={tol:n.tol??gn,maxiter:n.maxIter??1e3};return n.fLower!==void 0&&(r.fLower=n.fLower),n.fUpper!==void 0&&(r.fUpper=n.fUpper),Te(e,t,o,r).root}function wn(e,t={}){let o=e.length,n=o===0?0:e[0].length;if(e.some(a=>a.length!==n))throw new TypeError("all rows of the matrix must have the same length");if(o<2||n<2)throw new TypeError("'x' must have at least 2 rows and columns");let r=e.map(a=>Array.from(a));if(r.flat().some(a=>Number.isNaN(a)||a<0))throw new RangeError("all entries of 'x' must be non-negative and finite");if(r.flat().some(a=>a===1/0))throw new RangeError("'x' has entries too large to be integer");let s=r.map(a=>a.map(Ne)),i="Fisher's Exact Test for Count Data";if(o===2&&n===2)return yn(s,t,i);let l=t.alternative??"two.sided";if(t.simulatePValue??!1){let a=t.B??2e3;if(!(a>=0&&a<2**31))throw new RangeError("'B' must be a non-negative number");return{method:i+bt(a),alternative:l,pValue:Nn(s,a)}}return{method:i,alternative:l,pValue:vn(s)}}function Nn(e,t){let o=e.filter(M=>M.some(d=>d>0)),n=e[0].map((M,d)=>d).filter(M=>e.some(d=>d[M]>0));if(o.length<=1)throw new RangeError("need 2 or more non-zero row marginals");if(n.length<=1)throw new RangeError("need 2 or more non-zero column marginals");let r=o.map(M=>n.map(d=>M[d])),s=r.map(M=>M.reduce((d,b)=>d+b,0)),i=r[0].map((M,d)=>r.reduce((b,w)=>b+w[d],0)),l=s.length,a=i.length,f=[0,0];for(let M of r.flat())f=F(f,[-qe(M),0]);let c=f[0]/(1+64*Number.EPSILON),m=Rt(s.reduce((M,d)=>M+d,0)),u=new Int32Array(l*a),h=0,p=Math.trunc(t);for(let M=0;M<p;M++){qt(s,i,m,u);let d=0;for(let b=0;b<u.length;b++)d-=m[u[b]];d<=c&&h++}return Math.max(0,Math.min(1,(1+h)/(t+1)))}var bn=1+1e-7,Mn=16;function Bt(e,t,o){let n=[0,0];for(let r=Math.max(0,t);r<=Math.min(o,e.length-1);r++)e[r]!==0&&(n=F(n,[e[r],0]));return n[0]}var Kt=class{m;n;k;lo;hi;logCentral;constructor(t,o,n){this.m=t,this.n=o,this.k=n,this.lo=Math.max(0,n-o),this.hi=Math.min(n,t),this.logCentral=new Float64Array(this.hi-this.lo+1);let r=0,s=1;for(let i=this.lo;i<=this.hi;i++){let l=i-this.lo;l%Mn===0||!(s>0&&s<1/0)?(r=ut(i,t,o,n,!0),s=1,this.logCentral[l]=r):this.logCentral[l]=r+Math.log(s),s*=(t-i)*(n-i)/((i+1)*(o-n+i+1))}}density(t){let o=this.logCentral.length,n=Math.log(t),r=new Float64Array(o),s=-1/0;for(let l=0;l<o;l++){let a=this.logCentral[l]+(this.lo+l)*n;r[l]=a,a>s&&(s=a)}for(let l=0;l<o;l++){let a=r[l]-s;r[l]=a<-746?0:Math.exp(a)}let i=Bt(r,0,o-1);for(let l=0;l<o;l++)r[l]!==0&&(r[l]=r[l]/i);return r}mean(t){if(t===0)return this.lo;if(t===1/0)return this.hi;let o=this.density(t),n=[0,0];for(let r=0;r<o.length;r++)o[r]!==0&&(n=F(n,[(this.lo+r)*o[r],0]));return n[0]}tail(t,o,n){if(o===1)return n?$t(t-1,this.m,this.n,this.k,!1,!1):$t(t,this.m,this.n,this.k,!0,!1);if(o===0||o===1/0){let i=o===0?this.lo:this.hi;return(n?t<=i:t>=i)?1:0}let r=this.density(o),s=t-this.lo;return n?Bt(r,s,r.length-1):Bt(r,0,s)}};function Dt(e,t){return t?X(e,0,1):1/X(o=>e(1/o),Number.EPSILON,1)}function yn(e,t,o){let n=C(t.alternative),r=t.or??1;if(!(r>=0))throw new RangeError("'or' must be a single number between 0 and Inf");let s=t.confLevel??.95;if(!(s>0&&s<1))throw new RangeError("confLevel must be a single number between 0 and 1");let[[i,l],[a,f]]=e,c=i,m=new Kt(i+a,l+f,i+l),{lo:u,hi:h}=m,p;if(n==="less")p=m.tail(c,r,!1);else if(n==="greater")p=m.tail(c,r,!0);else if(r===0)p=c===u?1:0;else if(r===1/0)p=c===h?1:0;else{let N=m.density(r),y=N[c-u]*bn,x=[0,0];for(let E of N)E<=y&&(x=F(x,[E,0]));p=x[0]}let M;if(c===u)M=0;else if(c===h)M=1/0;else{let N=m.mean(1);M=N===c?1:Dt(y=>m.mean(y)-c,N>c)}let d={method:o,alternative:n,pValue:p,estimate:M,estimateNames:"odds ratio",nullValue:r,nullValueName:"odds ratio"};if(!(t.confInt??!0))return d;let b=N=>{if(c===h)return 1/0;let y=m.tail(c,1,!1);return y===N?1:Dt(x=>m.tail(c,x,!1)-N,y<N)},w=N=>{if(c===u)return 0;let y=m.tail(c,1,!0);return y===N?1:Dt(x=>m.tail(c,x,!0)-N,y>N)},g;if(n==="less")g=[0,b(1-s)];else if(n==="greater")g=[w(1-s),1/0];else{let N=(1-s)/2;g=[w(N),b(N)]}return{...d,confInt:g,confLevel:s}}var kt=[[0,0]];function tt(e){for(let t=kt.length;t<=e;t++)kt.push(F(kt[t-1],ge([t,0])));return kt[e]}function It(e,t,o,n){let r=e+o,s=r-e,i=e-(r-s)+(o-s)+t+n,l=r+i;return[l,i-(l-r)]}var Ut=class{scale=-1/0;hi=0;lo=0;add(t,o,n){if(t>this.scale){let a=Number.isFinite(this.scale)?Math.exp(this.scale-t):0;this.hi*=a,this.lo*=a,this.scale=t}let r=n*Math.exp(t-this.scale)*(1+o),s=this.hi+r,i=s-this.hi,l=this.hi-(s-i)+(r-i)+this.lo;this.hi=s+l,this.lo=l-(this.hi-s)}value(){return this.scale===-1/0?0:this.hi*Math.exp(this.scale)}};function vn(e){let t=e.filter(g=>g.some(N=>N>0));if(t.length===0)throw new RangeError("all entries of the table are zero");let o=t[0].map((g,N)=>t.some(y=>y[N]>0));if(t=t.map(g=>g.filter((N,y)=>o[y])),t.length<2||t[0].length<2)return 1;t.length>t[0].length&&(t=t[0].map((g,N)=>t.map(y=>y[N])));let n=t.length,r=t.map(g=>g.reduce((N,y)=>N+y,0)),s=t[0].map((g,N)=>t.reduce((y,x)=>y+x[N],0)).sort((g,N)=>N-g),i=s.length,l=r.reduce((g,N)=>g+N,0),a=de(tt(l));for(let g of r)a=F(a,tt(g));for(let g of s)a=F(a,tt(g));let f=[0,0];for(let g of t.flat())f=Q(f,tt(g));let c=F(f,[Math.log1p(1e-7),0]),m=1e-9*(1+Math.abs(c[0])),[u,h]=c,p=Array.from({length:i},()=>new Map),M=(g,N)=>{let y=N.join(","),x=p[g].get(y);if(x!==void 0)return x;let E=F(a,tt(N.reduce((A,L)=>A+L,0)));for(let A of N)E=Q(E,tt(A));for(let A=g;A<i;A++)E=Q(E,tt(s[A]));let R={R:N,KZ:E,max:0,min:0,edges:[],pastHi:[],pastLo:[],count:[],index:new Map};if(p[g].set(y,R),g===i-1){let A=[0,0];for(let L of N)A=Q(A,tt(L));return R.max=R.min=A[0],R.edges.push({to:R,hi:A[0],lo:A[1],mult:1}),R}let k=new Map,v=new Array(n+1).fill(0);for(let A=n-1;A>=0;A--)v[A]=v[A+1]+N[A];let T=new Array(n).fill(0),I=(A,L,j)=>{if(A===n-1){T[A]=L;let z=Q(j,tt(L)),et=N.map((rt,dt)=>rt-T[dt]).sort((rt,dt)=>rt-dt),$=M(g+1,et),B=`${et.join(",")}|${z[0]}`,nt=k.get(B);nt===void 0?k.set(B,{to:$,hi:z[0],lo:z[1],mult:1}):nt.mult++;return}let O=Math.max(0,L-v[A+1]),H=Math.min(N[A],L);for(let z=O;z<=H;z++)T[A]=z,I(A+1,L-z,Q(j,tt(z)))};if(I(0,s[g],[0,0]),R.edges=[...k.values()],R.max=Math.max(...R.edges.map(A=>A.hi+A.to.max)),R.min=Math.min(...R.edges.map(A=>A.hi+A.to.min)),g===i-2){let A=R.edges.map($=>{let B=$.to.edges[0];return{v:F([$.hi,$.lo],[B.hi,B.lo]),mult:$.mult}});A.sort(($,B)=>$.v[0]-B.v[0]||$.v[1]-B.v[1]);let L=A.length,j=A[L-1].v[0],O=new Float64Array(L),H=new Float64Array(L),z=new Float64Array(L),et=[0,0];A.forEach(({v:$,mult:B},nt)=>{O[nt]=$[0],H[nt]=$[1];let rt=Q($,[j,0]);et=F(et,[B*Math.exp(rt[0])*(1+rt[1]),0]),z[nt]=et[0]}),R.dist={hi:O,lo:H,cum:z,vmax:j,kv:F(a,[j,0])}}return R},d=M(0,[...r].sort((g,N)=>g-N)),b=new Ut,w=(g,N,y,x)=>{if(N+g.max<=u-m){let[I,A]=It(g.KZ[0],g.KZ[1],N,y);return b.add(I,A,x),!0}if(N+g.min>u+m)return!0;let E=g.dist;if(E===void 0)return!1;let[R,k]=It(u,h,-N,-y),v=0,T=E.hi.length;for(;v<T;){let I=v+T>>>1,A=E.hi[I];A<R||A===R&&E.lo[I]<=k?v=I+1:T=I}if(v>0){let[I,A]=It(E.kv[0],E.kv[1],N,y);b.add(I,A,x*E.cum[v-1])}return!0};w(d,0,0,1)||(d.pastHi.push(0),d.pastLo.push(0),d.count.push(1));for(let g=0;g<i-2;g++)for(let N of p[g].values()){let{pastHi:y,pastLo:x,count:E}=N;if(E.length!==0){for(let{to:R,hi:k,lo:v,mult:T}of N.edges)for(let I=0;I<E.length;I++){let[A,L]=It(y[I],x[I],k,v),j=E[I]*T;if(w(R,A,L,j))continue;let O=R.index.get(A);O===void 0?(R.index.set(A,R.count.length),R.pastHi.push(A),R.pastLo.push(L),R.count.push(j)):R.count[O]+=j}N.pastHi=N.pastLo=N.count=[],N.index.clear()}}return Math.min(1,b.value())}function Xt(e,t,o={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?o=t:n=t;let r=C(o.alternative),s=o.mu??0,i=o.paired??!1,l=o.exact??null,a=o.correct??!0,f=o.confInt??!1,c=o.confLevel??.95,m=o.tolRoot??1e-4;if(!Number.isFinite(s))throw new RangeError("mu must be a single finite number");if(f&&!(c>0&&c<1))throw new RangeError("confLevel must be a number strictly between 0 and 1");if(i&&n===void 0)throw new TypeError("y is required when paired is true");let u,h;if(i){let[M,d]=Tt(Array.from(e),Array.from(n));u=ct(M.map((b,w)=>b-d[w]))}else u=ct(Array.from(e)),n!==void 0&&(h=ct(Array.from(n)));if(u.length<1)throw new Error("not enough (non-missing) 'x' observations");if(h!==void 0&&h.length<1)throw new Error("not enough (non-missing) 'y' observations");let p={alternative:r,mu:s,correct:a,confInt:f,confLevel:c,tolRoot:m};return h===void 0?En(u,l,i,p):qn(u,h,l,p)}function St(e,t,o){return o?t==="two.sided"?Math.sign(e)*.5:t==="greater"?.5:-.5:0}function $e(e,t){return t==="less"?P(e):t==="greater"?P(e,{lowerTail:!1}):2*Math.min(P(e),P(e,{lowerTail:!1}))}function xn(e){if(!(e>0)||!Number.isFinite(e))return e;let o=1-Math.floor(Math.log10(e)),n=o>=0?e*10**o:e/10**-o,r=Math.round(n);return r-n===.5&&r%2!==0&&(r-=1),o>=0?r/10**o:r*10**-o}function Qt(e){let t=e.length;if(t===0)return NaN;let o=Math.floor(t/2);return t%2===1?e[o]:Z([e[o-1],e[o]])}var Gt=(e,t)=>e-t;function He(e){let t=e.length,o=W(e.map(Math.abs)),n=0;for(let i=0;i<t;i++)e[i]>0&&(n+=o[i]);let r=0;for(let i of lt(o))r+=i*i*i-i;let s=Math.sqrt(t*(t+1)*(2*t+1)/24-r/48);return[n,n-t*(t+1)/4,s]}function En(e,t,o,n){let{alternative:r,mu:s,correct:i}=n,l=e.map(x=>x-s),a=l.some(x=>x===0);a&&(l=l.filter(x=>x!==0));let f=l.length,c=t??f<50,m=W(l.map(Math.abs)),u=lt(m).length>0,[h,p,M]=He(l),d,b,w=c&&!u&&!a;if(w){b="Wilcoxon signed rank exact test";let x=f*(f+1)/2;if(r==="less")d=ht(h,f,!0,!1);else if(r==="greater")d=ht(h-1,f,!1,!1);else{let E=h>x/2?ht(h-1,f,!1,!1):ht(h,f,!0,!1);d=Math.min(1,2*E)}}else b=`Wilcoxon signed rank test${i?" with continuity correction":""}`,d=$e((p-St(p,r,i))/M,r);let g={method:b,alternative:r,statistic:h,statisticName:"V",pValue:d,nullValue:s,nullValueName:o?"location shift":"location"};if(!n.confInt)return g;let N=l.map(x=>x+s),y=w?An(N,n):Rn(N,n);return{...g,...y}}function Lt(e,t,o){return e==="less"?[-1/0,o]:e==="greater"?[t,1/0]:[t,o]}function _e(e,t,o){let n={confInt:Lt(e,NaN,NaN),confLevel:0,estimate:t};return o!==void 0&&(n.estimateNames=o),n}function We(e,t,o){let n=e(t==="two.sided"?o/2:o);return n===0?1:n}function Be(e){if(!(e>0))throw new RangeError("tolRoot must be positive")}function An(e,t){let{alternative:o,confLevel:n}=t,r=e.length,s=[];for(let m=0;m<r;m++)for(let u=m;u<r;u++)s.push((e[m]+e[u])/2);s.sort(Gt);let i=s.length,l=1-n,a=We(m=>be(m,r,!0,!1),o,l),f=ht(a-1,r,!0,!1),c=o==="two.sided"?2*f:f;return{confInt:Lt(o,s[a-1],s[i-a]),confLevel:c-l>l/2?1-xn(c):n,estimate:Qt(s),estimateNames:"(pseudo)median"}}function Rn(e,t){let{alternative:o,correct:n,confLevel:r,tolRoot:s}=t,i=e.length;if(i===0)return _e(o,NaN);let l=Math.min(...e),a=Math.max(...e);if(!Number.isFinite(l)||!Number.isFinite(a)||i===1||l===a)return _e(o,(l+a)/2,"midrange");let f=(g,N)=>{let[,y,x]=He(e.map(E=>E-g).filter(E=>E!==0));return(y-St(y,o,N))/x},c=f(l,n),m=f(a,n),u=g=>-V(g),h=g=>o==="greater"?!(c<u(g)):o==="less"?!(m>V(g/2)):!(c<u(g/2))&&!(m>V(g/2)),p=1-r,M=!1;for(;!h(p)&&p<1;)p*=2,M=!0;Be(s);let d=g=>X(N=>f(N,n)-g,l,a,{tol:s,fLower:c-g,fUpper:m-g}),b;if(p>=1){let g=Qt([...e].sort(Gt));b=Lt(o,g,g)}else o==="greater"?b=[d(u(p)),1/0]:o==="less"?b=[-1/0,d(V(p))]:b=[d(u(p/2)),d(V(p/2))];let w=X(g=>f(g,!1),l,a,{tol:s,fLower:f(l,!1),fUpper:f(a,!1)});return{confInt:b,confLevel:M?1-Math.min(1,p):r,estimate:w,estimateNames:"(pseudo)median"}}function De(e,t){let o=e.length,n=t.length,r=W([...e,...t]),s=0;for(let c=0;c<o;c++)s+=r[c];let i=s-o*(o+1)/2,l=0;for(let c of lt(r))l+=c*c*c-c;let a=o+n,f=Math.sqrt(o*n/12*(a+1-l/(a*(a-1))));return[i,i-o*n/2,f]}function qn(e,t,o,n){let{alternative:r,mu:s,correct:i}=n,l=e.length,a=t.length,f=e.map(N=>N-s),c=o??(l<50&&a<50),m=lt([...f,...t]).length>0,[u,h,p]=De(f,t),M,d,b=c&&!m;if(b)if(d="Wilcoxon rank sum exact test",r==="less")M=pt(u,l,a,!0,!1);else if(r==="greater")M=pt(u-1,l,a,!1,!1);else{let N=u>l*a/2?pt(u-1,l,a,!1,!1):pt(u,l,a,!0,!1);M=Math.min(1,2*N)}else d=`Wilcoxon rank sum test${i?" with continuity correction":""}`,M=$e((h-St(h,r,i))/p,r);let w={method:d,alternative:r,statistic:u,statisticName:"W",pValue:M,nullValue:s,nullValueName:"location shift"};if(!n.confInt)return w;let g=b?Tn(e,t,n):kn(e,t,n);return{...w,...g}}function Tn(e,t,o){let{alternative:n,confLevel:r}=o,s=e.length,i=t.length,l=[];for(let h of e)for(let p of t)l.push(h-p);l.sort(Gt);let a=l.length,f=1-r,c=We(h=>Me(h,s,i,!0,!1),n,f),m=pt(c-1,s,i,!0,!1),u=n==="two.sided"?2*m:m;return{confInt:Lt(n,l[c-1],l[a-c]),confLevel:u-f>f/2?1-u:r,estimate:Qt(l),estimateNames:"difference in location"}}function kn(e,t,o){let{alternative:n,correct:r,confLevel:s,tolRoot:i}=o,l=Math.min(...e)-Math.max(...t),a=Math.max(...e)-Math.min(...t);if(!Number.isFinite(l)||!Number.isFinite(a))throw new Error("cannot compute the confidence interval because the differences are not finite");let f=(h,p)=>{let[,M,d]=De(e.map(b=>b-h),t);return(M-St(M,n,p))/d},c=(h,p)=>{let M=f(l,p)-h,d=f(a,p)-h;if(Number.isNaN(M)||Number.isNaN(d))throw new Error("cannot compute the confidence interval because all observations are tied");return M<=0?l:d>=0?a:(Be(i),X(b=>f(b,p)-h,l,a,{tol:i,fLower:M,fUpper:d}))},m=1-s,u;return n==="greater"?u=[c(-V(m),r),1/0]:n==="less"?u=[-1/0,c(V(m),r)]:u=[c(-V(m/2),r),c(V(m/2),r)],{confInt:u,confLevel:s,estimate:c(0,!1),estimateNames:"difference in location"}}var Ke=["holm","hochberg","hommel","bonferroni","BH","BY","fdr","none"];function In(e){if(Ke.includes(e))return e;let t=Ke.filter(o=>o.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function Yt(e,t={}){let o=typeof t=="string"?{method:t}:t,n=In(o.method??"holm"),r=Array.from(e),s=[];for(let m=0;m<r.length;m++)Number.isNaN(r[m])||s.push(m);let i=s.length,l=o.n??i;if(!(l>=i))throw new RangeError("n must be at least the number of non-NaN p-values");if(l<=1)return r;let a=s.map(m=>r[m]),f=Sn(a,n,l),c=r.slice();return s.forEach((m,u)=>c[m]=f[u]),c}function Vt(e,t){let o=e.map((n,r)=>r);return o.sort((n,r)=>(t?e[r]-e[n]:e[n]-e[r])||n-r),o}function Sn(e,t,o){let n=e.length,r=new Array(n);switch(t){case"none":return e.slice();case"bonferroni":return e.map(s=>Math.min(1,o*s));case"holm":{let s=Vt(e,!1),i=-1/0;return s.forEach((l,a)=>{i=Math.max(i,(o-a)*e[l]),r[l]=Math.min(1,i)}),r}case"hochberg":{let s=Vt(e,!0),i=1/0;return s.forEach((l,a)=>{let f=n-a;i=Math.min(i,(o-f+1)*e[l]),r[l]=Math.min(1,i)}),r}case"BH":case"fdr":case"BY":{let s=t==="BY"?Ee(Array.from({length:Math.floor(o)},(a,f)=>1/(f+1))):1,i=Vt(e,!0),l=1/0;return i.forEach((a,f)=>{let c=n-f;l=Math.min(l,s*o/c*e[a]),r[a]=Math.min(1,l)}),r}case"hommel":return Ln(e,o)}}function Ln(e,t){if(!Number.isInteger(t))throw new RangeError("n must be an integer for the hommel method");let o=e.length,n=[...e,...new Array(t-o).fill(1)],r=Vt(n,!1),s=r.map(a=>n[a]),i=s.slice();for(let a=t;a>=2;a--){let f=1/0;for(let c=1;c<=a;c++)f=Math.min(f,a*s[t-a+c-1]/c);for(let c=t-a;c<t;c++)i[c]=Math.max(i[c],f);for(let c=0;c<t-a;c++)i[c]=Math.max(i[c],Math.min(a*s[c],f))}let l=new Array(o);return r.forEach((a,f)=>{a<o&&(l[a]=i[f])}),l}var Vn=1+1e-7;function Ft(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7*Math.max(1,Math.abs(e))}function Fn(e,t,o){if(o===0)return e===0?1:0;if(o===1)return e===t?1:0;let n=t*o;if(e===n)return 1;let r=At(e,t,o,!1)*Vn,s=0;if(e<n){for(let a=Math.ceil(n);a<=t;a++)At(a,t,o,!1)<=r&&s++;let l=s===0?0:at(t-s,t,o,!1,!1);return Math.min(1,at(e,t,o,!0,!1)+l)}for(let l=0;l<=Math.floor(n);l++)At(l,t,o,!1)<=r&&s++;let i=s===0?0:at(s-1,t,o,!0,!1);return Math.min(1,at(e-1,t,o,!1,!1)+i)}function Zt(e,t,o={}){let n,r;if(typeof e!="number"){if(e.length!==2)throw new RangeError("incorrect length of 'x'");if(t!==void 0&&typeof t!="number"&&(o=t),!Ft(e[0])||!Ft(e[1]))throw new RangeError("'x' must be nonnegative and integer");n=Math.round(e[0]),r=Math.round(e[0])+Math.round(e[1])}else{if(typeof t!="number")throw new TypeError("'n' is required when 'x' is a single number");if(!Ft(e))throw new RangeError("'x' must be nonnegative and integer");if(n=Math.round(e),!(Ft(t)&&Math.round(t)>=n&&t>0))throw new RangeError("'n' must be a positive integer >= 'x'");r=Math.round(t)}let s=o.p??.5;if(!(s>=0&&s<=1))throw new RangeError("'p' must be a single number between 0 and 1");let i=C(o.alternative),l=o.confLevel??.95;U(l);let a;i==="less"?a=at(n,r,s,!0,!1):i==="greater"?a=at(n-1,r,s,!1,!1):a=Fn(n,r,s);let f=u=>n===0?0:_t(u,n,r-n+1,!0,!1),c=u=>n===r?1:_t(1-u,n+1,r-n,!0,!1),m;if(i==="less")m=[0,c(1-l)];else if(i==="greater")m=[f(1-l),1];else{let u=(1-l)/2;m=[f(u),c(u)]}return{method:"Exact binomial test",alternative:i,statistic:n,statisticName:"number of successes",parameter:r,parameterName:"number of trials",pValue:a,confInt:m,confLevel:l,estimate:n/r,estimateNames:"probability of success",nullValue:s,nullValueName:"probability of success"}}var Cn=1+1e-7;function Pn(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7*Math.max(1,Math.abs(e))}function jn(e,t){if(t===0)return e===0?1:0;if(e===t)return 1;let o=zt(e,t,!1)*Cn,n=l=>zt(l,t,!1)<=o,r=Math.floor(t);if(e<t){let l=Math.max(e+1,r),a=l;if(!n(l)){let f=l,c=1;for(a=l+1;!n(a);)f=a,c*=2,a=l+c;for(;a-f>1;){let m=f+Math.floor((a-f)/2);n(m)?a=m:f=m}}return Math.min(1,st(e,t,!0,!1)+st(a-1,t,!1,!1))}let s=Math.min(e-1,r),i;if(!n(0))i=-1;else if(n(s))i=s;else{i=0;let l=s;for(;l-i>1;){let a=i+Math.floor((l-i)/2);n(a)?i=a:l=a}}return Math.min(1,st(i,t,!0,!1)+st(e-1,t,!1,!1))}function On(e,t={}){let o=typeof e=="number"?[e]:Array.from(e);if(o.length<1||o.length>2)throw new RangeError("incorrect length of 'x'");if(!o.every(Pn))throw new RangeError("'x' must be finite, nonnegative, and integer");let n=o.map(Math.round),r=n.length,s=t.T??1,i=typeof s=="number"?new Array(r).fill(s):Array.from(s);if(i.length!==r)throw new RangeError("'x' and 'T' have incompatible length");if(!i.every(b=>Number.isFinite(b)&&b>=0))throw new RangeError("'T' must be nonnegative");let l=t.r??1;if(!(Number.isFinite(l)&&l>=0))throw new RangeError("'r' must be a single positive number");let a=C(t.alternative),f=t.confLevel??.95;if(U(f),r===2){let[b,w]=n,[g,N]=i,y=b+w,x=l*g/(l*g+N),E=Zt([b,w],{p:x,alternative:a,confLevel:f}),R=k=>k/(1-k)*(N/g);return{method:"Comparison of Poisson rates",alternative:a,statistic:b,statisticName:"count1",parameter:y*l*g/(g+l*N),parameterName:"expected count1",pValue:E.pValue,confInt:[R(E.confInt[0]),R(E.confInt[1])],confLevel:f,estimate:b/g/(w/N),estimateNames:"rate ratio",nullValue:l,nullValueName:"rate ratio"}}let c=n[0],m=i[0],u=l*m,h;a==="less"?h=st(c,u,!0,!1):a==="greater"?h=st(c-1,u,!1,!1):h=jn(c,u);let p=b=>c===0?0:Ot(b,c,1,!0,!1),M=b=>Ot(1-b,c+1,1,!0,!1),d;if(a==="less")d=[0,M(1-f)];else if(a==="greater")d=[p(1-f),1/0];else{let b=(1-f)/2;d=[p(b),M(b)]}return{method:"Exact Poisson test",alternative:a,statistic:c,statisticName:"number of events",parameter:m,parameterName:"time base",pValue:h,confInt:[d[0]/m,d[1]/m],confLevel:f,estimate:c/m,estimateNames:"event rate",nullValue:l,nullValueName:"event rate"}}function Jt(e,t,o={}){let n,r,s=o;if(typeof e!="number"&&e.length>0&&Array.isArray(e[0])){let v=e;if(v.some(T=>T.length!==2))throw new RangeError("'x' must have 2 columns");n=v.map(T=>T[0]),r=v.map(T=>T[0]+T[1]),t!==void 0&&typeof t=="object"&&!Array.isArray(t)&&(s=t)}else{if(t===void 0||typeof t=="object"&&!Array.isArray(t))throw new RangeError("'n' must be given");n=typeof e=="number"?[e]:Array.from(e),r=typeof t=="number"?[t]:Array.from(t)}if(n.length!==r.length)throw new RangeError("'x' and 'n' must have the same length");let i=n.length,l=[];for(let v=0;v<i;v++)!Number.isNaN(n[v])&&!Number.isNaN(r[v])&&l.push(v);let a=l.length;if(a<1)throw new RangeError("not enough data");if(n=l.map(v=>n[v]),r=l.map(v=>r[v]),r.some(v=>!(v>0)))throw new RangeError("elements of 'n' must be positive");if(n.some(v=>!(v>=0)))throw new RangeError("elements of 'x' must be nonnegative");if(n.some((v,T)=>v>r[T]))throw new RangeError("elements of 'x' must not be greater than those of 'n'");let f;if(s.p!==void 0){let v=typeof s.p=="number"?[s.p]:Array.from(s.p);if(v.length!==i)throw new RangeError("'p' must have the same length as 'x' and 'n'");if(f=l.map(T=>v[T]),f.some(T=>!(T>0&&T<1)))throw new RangeError("elements of 'p' must be in (0,1)")}let c=f!==void 0;a===1&&f===void 0&&(f=[.5]);let m=s.confLevel??.95;U(m);let u=C(s.alternative);(a>2||a===2&&c)&&(u="two.sided");let h=n.map((v,T)=>v/r[T]),p=a===2?h[0]-h[1]:0,M=a===2?1/r[0]+1/r[1]:0,d=(s.correct??!0)&&a<=2?.5:0,b=!1;if(d>0&&a===1){let v=Math.abs(n[0]-r[0]*f[0]);v<=d&&([d,b]=[v,!0])}else if(d>0&&a===2&&!c){let v=Math.abs(p)/M;v<=d&&([d,b]=[v,!0])}let w=n.reduce((v,T)=>v+T,0)/r.reduce((v,T)=>v+T,0),g=0;if(!b)for(let v=0;v<a;v++){let T=f?.[v]??w,I=r[v]*T,A=r[v]*(1-T);g+=(Math.abs(n[v]-I)-d)**2/I,g+=(Math.abs(r[v]-n[v]-A)-d)**2/A}let N=f!==void 0?a:a-1,y;if(u==="two.sided")y=D(g,N/2,2,!1,!1);else{let v=Math.sign(a===1?h[0]-f[0]:p);y=P(v*Math.sqrt(g),{lowerTail:u==="less"})}let x;if(a===1||a===2&&!c){let v=V(u==="two.sided"?(1+m)/2:m);if(a===1){let T=r[0],I=v*v,A=(z,et)=>(z+I/(2*T)+et*v*Math.sqrt(z*(1-z)/T+I/(4*T*T)))/(1+I/T),L=h[0]+d/T,j=h[0]-d/T,O=Math.min(1,Math.max(0,L>=1?1:A(L,1))),H=Math.min(1,Math.max(0,j<=0?0:A(j,-1)));x=u==="two.sided"?[H,O]:u==="greater"?[H,1]:[0,O]}else{let T=Math.sqrt(h.reduce((j,O,H)=>j+O*(1-O)/r[H],0)),I=v*T+d*M,A=Math.max(-1,p-I),L=Math.min(1,p+I);x=u==="two.sided"?[A,L]:u==="greater"?[A,1]:[-1,L]}}let E=a===1?"p":l.map(v=>`prop ${v+1}`),k={method:`${a===1?"1-sample proportions test":`${a}-sample test for ${c?"given proportions":"equality of proportions"}`} ${d!==0?"with":"without"} continuity correction`,alternative:u,statistic:g,statisticName:"X-squared",parameter:N,parameterName:"df",pValue:y,estimate:a===1?h[0]:h,estimateNames:E};return f!==void 0&&(k.nullValue=a===1?f[0]:f,k.nullValueName=E),x!==void 0&&(k.confInt=x,k.confLevel=m),k}function zn(e,t,o={}){let n;if(e.length>0&&Array.isArray(e[0])){t!==void 0&&!Array.isArray(t)&&(o=t),n=e.map(c=>Array.from(c));let f=n.length;if(f<2||n.some(c=>c.length!==f))throw new RangeError("'x' must be square with at least two rows and columns");if(n.some(c=>c.some(m=>!Number.isFinite(m)||m<0)))throw new RangeError("all entries of 'x' must be nonnegative and finite")}else{if(!Array.isArray(t))throw new TypeError("'y' is required when 'x' is not a table");n=_n(e,t)}let r=o.correct??!0,s=n.length,i,l=r&&s===2&&n[0][1]!==n[1][0];if(l){let f=n[0][1],c=n[1][0];i=(Math.abs(f-c)-1)**2/(f+c)}else{i=0;for(let f=0;f<s;f++)for(let c=f+1;c<s;c++){let m=n[f][c],u=n[c][f];i+=(m-u)**2/(m+u)}}let a=s*(s-1)/2;return{method:l?"McNemar's Chi-squared test with continuity correction":"McNemar's Chi-squared test",statistic:i,statisticName:"McNemar's chi-squared",parameter:a,parameterName:"df",pValue:D(i,a/2,2,!1,!1)}}function _n(e,t){if(e.length!==t.length)throw new RangeError("'x' and 'y' must have the same length");let o=[];for(let f=0;f<e.length;f++){let c=e[f],m=t[f];typeof c=="number"&&Number.isNaN(c)||typeof m=="number"&&Number.isNaN(m)||o.push([c,m])}let n=f=>Array.from(new Set(f)).sort((c,m)=>typeof c=="number"&&typeof m=="number"?c-m:String(c)<String(m)?-1:String(c)>String(m)?1:0),r=n(o.map(f=>f[0])),s=n(o.map(f=>f[1]));if(r.length<2||r.length!==s.length)throw new RangeError("'x' and 'y' must have the same number of levels (minimum 2)");let i=new Map(r.map((f,c)=>[f,c])),l=new Map(s.map((f,c)=>[f,c])),a=r.map(()=>new Array(r.length).fill(0));for(let[f,c]of o)a[i.get(f)][l.get(c)]++;return a}function $n(e,t,o={}){let n=Array.from(e).filter(Number.isFinite),r=Array.from(t).filter(Number.isFinite),s=o.ratio??1;if(!(Number.isFinite(s)&&s>0))throw new RangeError("'ratio' must be a single positive number");let i=C(o.alternative),l=o.confLevel??.95;U(l);let a=n.length-1,f=r.length-1;if(a<1)throw new Error("not enough 'x' observations");if(f<1)throw new Error("not enough 'y' observations");let c=K(n)/K(r),m=c/s,u=G(m,a,f,!0,!1),h=G(m,a,f,!1,!1),p,M;if(i==="less")p=u,M=[0,c/wt(1-l,a,f,!0,!1)];else if(i==="greater")p=h,M=[c/wt(l,a,f,!0,!1),1/0];else{p=Math.min(1,2*Math.min(u,h));let d=(1-l)/2;M=[c/wt(1-d,a,f,!0,!1),c/wt(d,a,f,!0,!1)]}return{method:"F test to compare two variances",alternative:i,statistic:m,statisticName:"F",parameter:[a,f],parameterName:["num df","denom df"],pValue:p,confInt:M,confLevel:l,estimate:c,estimateNames:"ratio of variances",nullValue:s,nullValueName:"ratio of variances"}}function Hn(e){let t=e.length;if(t<2)throw new RangeError("'x' must be a list with at least 2 elements");let o=[],n=[];for(let c of e){let m=Array.from(c).filter(Number.isFinite);if(m.length<2)throw new RangeError("there must be at least 2 observations in each group");o.push(m.length-1),n.push(K(m))}let r=0,s=0,i=0,l=0;for(let c=0;c<t;c++)r+=o[c],s+=o[c]*n[c],i+=o[c]*Math.log(n[c]),l+=1/o[c];s/=r;let a=(r*Math.log(s)-i)/(1+(l-1/r)/(3*(t-1))),f=t-1;return{method:"Bartlett test of homogeneity of variances",statistic:a,statisticName:"Bartlett's K-squared",parameter:f,parameterName:"df",pValue:D(a,f/2,2,!1,!1)}}function te(e,t,o="drop"){if(t===void 0){let i=e;if(i.length>0&&typeof i[0]=="number")throw new TypeError("'g' is required when 'x' is a single sample");let l=i.map(c=>Array.from(c).filter(m=>!Number.isNaN(m)));if(o==="error"&&l.some(c=>c.length===0))throw new RangeError("all groups must contain data");let a=[],f=[];return l.forEach((c,m)=>{c.length!==0&&(a.push(String(m+1)),f.push(c))}),{labels:a,groups:f}}let n=Array.from(e);if(n.length!==t.length)throw new RangeError("'x' and 'g' must have the same length");let r=new Map;for(let i=0;i<n.length;i++){let l=n[i],a=t[i];if(Number.isNaN(l)||typeof a=="number"&&Number.isNaN(a))continue;let f=r.get(a);f===void 0&&r.set(a,f=[]),f.push(l)}let s=Array.from(r.keys()).sort((i,l)=>typeof i=="number"&&typeof l=="number"?i-l:String(i)<String(l)?-1:String(i)>String(l)?1:0);return{labels:s.map(String),groups:s.map(i=>r.get(i))}}function ft(e,t,o="drop"){return te(e,t,o).groups}function Ue(e){let t=[...e].sort((n,r)=>n-r),o=t.length;return o%2===1?t[(o-1)/2]:(t[o/2-1]+t[o/2])/2}function ee(e){if(e.length===0)throw new RangeError("'y' must have at least one row");let t=e[0].length;if(e.some(o=>o.length!==t))throw new RangeError("all rows of 'y' must have the same length");return e.filter(o=>o.every(n=>!Number.isNaN(n))).map(o=>Array.from(o))}function ne(e,t,o,n){return{method:e,statistic:o,statisticName:t,parameter:n,parameterName:"df",pValue:D(o,n/2,2,!1,!1)}}function Xe(e){let t=0;for(let o of lt(e))t+=o*o*o-o;return t}function Wn(e,t){let o=ft(e,t,"error"),n=o.length;if(n<2)throw new RangeError("all observations are in the same group");let r=o.flat(),s=r.length,i=W(r),l=0,a=0;for(let f of o){let c=0;for(let m=0;m<f.length;m++)c+=i[a+m];a+=f.length,l+=c*c/f.length}return l=(12*l/(s*(s+1))-3*(s+1))/(1-Xe(r)/(s*s*s-s)),ne("Kruskal-Wallis rank sum test","Kruskal-Wallis chi-squared",l,n-1)}function Bn(e){let t=ee(e),o=t.length,n=e[0]?.length??0;if(o<2||n<2)throw new RangeError("'y' must have at least two complete rows and two columns");let r=new Array(n).fill(0),s=0;for(let a of t){let f=W(a);for(let c=0;c<n;c++)r[c]+=f[c];s+=Xe(a)}let i=0;for(let a of r)i+=(a-o*(n+1)/2)**2;let l=12*i/(o*n*(n+1)-s/(n-1));return ne("Friedman rank sum test","Friedman chi-squared",l,n-1)}function Dn(e){let t=ee(e),o=e.length,n=e[0]?.length??0;if(t.length<2||n<2)throw new RangeError("'y' must have at least two complete rows and two columns");let r=W(t.map(h=>Math.max(...h)-Math.min(...h))),s=new Array(n).fill(0),i=0;t.forEach((h,p)=>{let M=W(h);for(let d=0;d<n;d++){let b=r[p]*(M[d]-(n+1)/2);i+=b*b,s[d]+=b}});let l=0;for(let h of s)l+=h*h;l/=o;let a=n-1,f=(o-1)*(n-1),c,m,u=[a,f];if(i===l){c=NaN,u=[NaN,NaN];let h=0;for(let p=2;p<=n;p++)h+=Math.log(p);m=Math.exp((1-o)*h)}else c=(o-1)*l/(i-l),m=G(c,a,f,!1,!1);return{method:"Quade test",statistic:c,statisticName:"Quade F",parameter:u,parameterName:["num df","denom df"],pValue:m}}function Kn(e,t){let o=ft(e,t,"error"),n=o.length;if(n<2)throw new RangeError("all observations are in the same group");let r=o.flatMap(u=>{let h=Ue(u);return u.map(p=>Math.abs(p-h))}),s=r.length,l=W(r).map(u=>V((1+u/(s+1))/2)),a=0;for(let u of l)a+=u;let f=a/s,c=0,m=0;for(let u of o){let h=0;for(let p=0;p<u.length;p++)h+=l[m+p];m+=u.length,c+=u.length*(h/u.length-f)**2}return c/=K(l),ne("Fligner-Killeen test of homogeneity of variances","Fligner-Killeen:med chi-squared",c,n-1)}function Un(e,t,o={}){let n=Array.from(e).filter(Number.isFinite),r=Array.from(t).filter(Number.isFinite),s=C(o.alternative),i=n.length,l=r.length,a=i+l;if(a<3)throw new RangeError("not enough observations");let f=n.concat(r),c=Array.from({length:a},(N,y)=>y).sort((N,y)=>f[N]-f[y]),m=new Array(a),u=0;for(;u<a;){let N=u;for(;N+1<a&&f[c[N+1]]===f[c[u]];)N++;let y=0;for(let x=u;x<=N;x++)y+=(x+1-(a+1)/2)**2;y/=N-u+1;for(let x=u;x<=N;x++)m[c[x]]=y;u=N+1}let h=0;for(let N=0;N<i;N++)h+=m[N];let p=0;for(let N of m)p+=N;p/=a;let M=0;for(let N of m)M+=(N-p)**2;let d=i*p,b=i*l/(a*(a-1))*M,w=(h-d)/Math.sqrt(b),g=s==="less"?P(w):s==="greater"?P(w,{lowerTail:!1}):2*P(-Math.abs(w));return{method:"Mood two-sample test of scale",alternative:s,statistic:w,statisticName:"Z",pValue:g}}function mt(e,t){let o=0;for(let n=e.length-1;n>=0;n--)o=o*t+e[n];return o}var Xn=[0,.221157,-.147981,-2.07119,4.434685,-2.706056],Qn=[0,.042981,-.293762,-1.752461,5.682633,-3.582633],Gn=[.544,-.39978,.025054,-6714e-7],Yn=[1.3822,-.77857,.062767,-.0020322],Zn=[-1.5861,-.31082,-.083751,.0038915],Jn=[-.4803,-.082676,.0030302],tr=[-2.273,.459];function er(e){if(!(e>=3)||e!==Math.floor(e))throw new RangeError("n must be an integer of at least 3");let t=new Float64Array(e);if(e===3)return t[0]=-Math.SQRT1_2,t[2]=Math.SQRT1_2,t;let o=Math.floor(e/2),n=new Float64Array(o),r=0;for(let m=0;m<o;m++)n[m]=-V((m+1-.375)/(e+.25)),r+=n[m]*n[m];r*=2;let s=Math.sqrt(r),i=1/Math.sqrt(e),l=n[0]/s+mt(Xn,i),a=new Float64Array(o);a[0]=l;let f,c;if(e>5){let m=n[1]/s+mt(Qn,i);a[1]=m,f=2,c=Math.sqrt((r-2*n[0]*n[0]-2*n[1]*n[1])/(1-2*l*l-2*m*m))}else f=1,c=Math.sqrt((r-2*n[0]*n[0])/(1-2*l*l));for(let m=f;m<o;m++)a[m]=n[m]/c;for(let m=0;m<o;m++)t[e-1-m]=a[m],t[m]=-a[m];return t}function Qe(e){let t=e.length,o=er(t),n=e[t-1]-e[0],r=0;for(let f of e)r+=f/n;r/=t;let s=0,i=0,l=0;for(let f=0;f<t;f++){let c=e[f]/n-r;s+=o[f]*o[f],i+=c*c,l+=o[f]*c}let a=Math.sqrt(s*i);return(a-l)*(a+l)/(s*i)}var nr=1.90985931710274,rr=1.0471975511966;function Ge(e,t){if(Number.isNaN(e)||!(t>=3))return NaN;if(t===3){let i=nr*(Math.asin(Math.sqrt(1-e))-rr);return Math.max(i,0)}let o=Math.log(e);if(t<=11){let i=mt(tr,t);if(o>=i)return 1e-99;let l=mt(Gn,t),a=Math.exp(mt(Yn,t));return P(-Math.log(i-o),{mean:l,sd:a,lowerTail:!1})}let n=Math.log(t),r=mt(Zn,n),s=Math.exp(mt(Jn,n));return P(o,{mean:r,sd:s,lowerTail:!1})}function or(e,t,o={}){let n;t!==void 0&&!Array.isArray(t)?o=t:n=t;let r=ft(e,n),s=o.varEqual??!1,i=r.length;if(i<2)throw new RangeError("not enough groups");let l=r.map(h=>h.length);if(l.some(h=>h<2))throw new RangeError("not enough observations");let a=r.map(Z),f=r.map(K),c=l.reduce((h,p)=>h+p,0),m,u;if(s){let h=Z(r.flat()),p=0,M=0;for(let d=0;d<i;d++)p+=l[d]*(a[d]-h)**2,M+=(l[d]-1)*f[d];u=c-i,m=p/(i-1)/(M/u)}else{let h=l.map((w,g)=>w/f[g]),p=h.reduce((w,g)=>w+g,0),M=0,d=0;for(let w=0;w<i;w++)M+=(1-h[w]/p)**2/(l[w]-1),d+=h[w]*a[w];M/=i*i-1,d/=p;let b=0;for(let w=0;w<i;w++)b+=h[w]*(a[w]-d)**2;m=b/((i-1)*(1+2*(i-2)*M)),u=1/(3*M)}return{method:s?"One-way analysis of means":"One-way analysis of means (not assuming equal variances)",statistic:m,statisticName:"F",parameter:[i-1,u],parameterName:["num df","denom df"],pValue:G(m,i-1,u,!1,!1)}}function sr(e){let t=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,s)=>r-s),o=t.length;if(o<3||o>5e3)throw new RangeError("sample size must be between 3 and 5000");if(!Number.isFinite(t[0])||!Number.isFinite(t[o-1]))throw new RangeError("'x' must be finite");if(t[o-1]===t[0])throw new RangeError("all 'x' values are identical");let n=Qe(t);return{method:"Shapiro-Wilk normality test",statistic:1-n,statisticName:"W",pValue:Ge(n,o)}}function re(e,t,o){let n=[0,0];for(let r=Math.max(0,t);r<Math.min(o,e.length);r++)n=F(n,[e[r],0]);return n[0]}function ar([[e,t],[o,n]]){let r=e+o,s=t+n,i=e+t,l=Math.max(0,i-s),a=Math.min(i,r),f=new Float64Array(a-l+1);for(let c=l;c<=a;c++)f[c-l]=ut(c,r,s,i,!1);return{lo:l,d:f}}function ir(e,t){let o=new Float64Array(e.length+t.length-1);for(let n=0;n<e.length;n++){let r=e[n];if(r!==0)for(let s=0;s<t.length;s++)o[n+s]+=r*t[s]}return o}var Ct=class{lo;hi;logNull;constructor(t){let o=0,n=new Float64Array([1]);for(let r of t){let s=ar(r);o+=s.lo,n=ir(n,s.d)}this.lo=o,this.hi=o+n.length-1,this.logNull=n.map(Math.log)}density(t){let o=this.logNull.length,n=new Float64Array(o);if(t===0||t===1/0)return n[t===0?0:o-1]=1,n;let r=Math.log(t),s=-1/0;for(let l=0;l<o;l++){let a=this.logNull[l]+(this.lo+l)*r;n[l]=a,a>s&&(s=a)}for(let l=0;l<o;l++)n[l]=Math.exp(n[l]-s);let i=re(n,0,o);for(let l=0;l<o;l++)n[l]=n[l]/i;return n}mean(t){if(t===0)return this.lo;if(t===1/0)return this.hi;let o=this.density(t),n=[0,0];for(let r=0;r<o.length;r++)n=F(n,[(this.lo+r)*o[r],0]);return n[0]}cdf(t,o,n){let r=this.density(o),s=t-this.lo;return n?re(r,s,r.length):re(r,0,s+1)}};function oe(e,t){return t?X(e,0,1):1/X(o=>e(1/o),Number.EPSILON,1)}function Ye(e,t){if(t===e.lo)return 0;if(t===e.hi)return 1/0;let o=e.mean(1);return o===t?1:oe(n=>e.mean(n)-t,o>t)}function se(e,t,o){if(t===e.hi)return 1/0;let n=e.cdf(t,1,!1);return n===o?1:oe(r=>o-e.cdf(t,r,!1),n<o)}function ae(e,t,o){if(t===e.lo)return 0;let n=e.cdf(t,1,!0);return n===o?1:oe(r=>e.cdf(t,r,!0)-o,n>o)}function lr(e,t={}){let o=e.length;if(o<1)throw new RangeError("'x' must have at least one stratum");let n=e[0].length,r=e[0][0]?.length??0;if(n<2||r<2||o<2)throw new RangeError("each dimension in table must be >= 2");for(let c of e){if(c.length!==n||c.some(m=>m.length!==r))throw new RangeError("all strata must have the same dimensions");if(c.some(m=>m.some(u=>!Number.isFinite(u)||u<0)))throw new RangeError("all entries of 'x' must be nonnegative and finite")}let s=e.map(c=>c.reduce((m,u)=>m+u.reduce((h,p)=>h+p,0),0));if(s.some(c=>c<2))throw new RangeError("sample size in each stratum must be > 1");let i=C(t.alternative),l=t.correct??!0,a=t.exact??!1,f=t.confLevel??.95;if(U(f),n===2&&r===2){let c=e.map(m=>[[m[0][0],m[0][1]],[m[1][0],m[1][1]]]);return a?fr(c,i,f):cr(c,s,i,l,f)}return mr(e,s,n,r)}function cr(e,t,o,n,r){let s=0,i=0,l=0,a=0,f=0,c=0,m=0,u=0;e.forEach(([[N,y],[x,E]],R)=>{let k=t[R],v=N+y,T=x+E,I=N+x,A=y+E;s+=N,i+=v*I/k,l+=v*T*I*A/(k*k*(k-1));let L=(N+E)/k,j=(y+x)/k,O=N*E/k,H=y*x/k;a+=O,f+=H,c+=L*O,m+=L*H+j*O,u+=j*H});let h=s-i,p=n&&Math.abs(h)>=.5?.5:0,M=(Math.abs(h)-p)**2/l,d=o==="two.sided"?D(M,.5,2,!1,!1):P(Math.sign(h)*Math.sqrt(M),{lowerTail:o==="less"}),b=a/f,w=Math.sqrt(c/(2*a*a)+m/(2*a*f)+u/(2*f*f)),g;if(o==="less")g=[0,b*Math.exp(V(r)*w)];else if(o==="greater")g=[b*Math.exp(V(r,{lowerTail:!1})*w),1/0];else{let N=V((1+r)/2);g=[b*Math.exp(-N*w),b*Math.exp(N*w)]}return{method:`Mantel-Haenszel chi-squared test ${p!==0?"with":"without"} continuity correction`,alternative:o,statistic:M,statisticName:"Mantel-Haenszel X-squared",parameter:1,parameterName:"df",pValue:d,confInt:g,confLevel:r,estimate:b,estimateNames:"common odds ratio",nullValue:1,nullValueName:"common odds ratio"}}function fr(e,t,o){let n=new Ct(e),r=e.reduce((l,a)=>l+a[0][0],0),s;if(t==="two.sided"){let l=n.density(1),a=l[r-n.lo]*(1+1e-7),f=[0,0];for(let c of l)c<=a&&(f=F(f,[c,0]));s=Math.min(1,f[0])}else s=n.cdf(r,1,t==="greater");let i;if(t==="less")i=[0,se(n,r,1-o)];else if(t==="greater")i=[ae(n,r,1-o),1/0];else{let l=(1-o)/2;i=[ae(n,r,l),se(n,r,l)]}return{method:"Exact conditional test of independence in 2 x 2 x k tables",alternative:t,statistic:r,statisticName:"S",pValue:s,confInt:i,confLevel:o,estimate:Ye(n,r),estimateNames:"common odds ratio",nullValue:1,nullValueName:"common odds ratio"}}function mr(e,t,o,n){let r=(o-1)*(n-1),s=new Array(r).fill(0),i=Array.from({length:r},()=>new Array(r).fill(0));e.forEach((f,c)=>{let m=t[c],u=f.map(M=>M.reduce((d,b)=>d+b,0)),h=Array.from({length:n},(M,d)=>f.reduce((b,w)=>b+w[d],0)),p=1/(m*m*(m-1));for(let M=0;M<n-1;M++)for(let d=0;d<o-1;d++){let b=d+(o-1)*M;s[b]+=f[d][M]-u[d]*h[M]/m;for(let w=0;w<n-1;w++)for(let g=0;g<o-1;g++){let N=(d===g?m*u[d]:0)-u[d]*u[g],y=(M===w?m*h[M]:0)-h[M]*h[w];i[b][g+(o-1)*w]+=p*N*y}}});let l=Le(i,s),a=0;for(let f=0;f<r;f++)a+=s[f]*l[f];return{method:"Cochran-Mantel-Haenszel test",statistic:a,statisticName:"Cochran-Mantel-Haenszel M^2",parameter:r,parameterName:"df",pValue:D(a,r/2,2,!1,!1)}}var Ze=new Map;function ur(e,t){let o=`${e},${t}`,n=Ze.get(o);if(n!==void 0)return n;let r=e+t,s=[];for(let u=1;u<=r;u++)s.push(Math.min(u,r+1-u));let i=s.reduce((u,h)=>u+h,0),l=Array.from({length:e+1},()=>new Float64Array(i+1));l[0][0]=1;for(let u=0;u<r;u++){let h=r-u,p=s[u],M=Array.from({length:e+1},()=>new Float64Array(i+1));for(let d=0;d<=e;d++){let b=l[d],w=e-d;if(w>h)continue;let g=w/h;for(let N=0;N<=i;N++){let y=b[N];y!==0&&(w>0&&(M[d+1][N+p]+=y*g),w<h&&(M[d][N]+=y*(1-g)))}}l=M}let a=l[e],f=0;for(;f<a.length&&a[f]===0;)f++;let c=a.length-1;for(;c>f&&a[c]===0;)c--;let m={min:f,probs:a.slice(f,c+1)};return Ze.set(o,m),m}function ie(e,t,o,n=!0){if(Number.isNaN(e)||!(t>=1)||!(o>=1)||t!==Math.floor(t)||o!==Math.floor(o))return NaN;let{min:r,probs:s}=ur(t,o),i=Math.floor(e+1e-7)-r,l=0;if(n)for(let a=0;a<=Math.min(i,s.length-1);a++)l+=s[a];else for(let a=Math.max(i+1,0);a<s.length;a++)l+=s[a];return Math.min(l,1)}var Je=new Map;function hr(e,t){let o=`${e},${t}`,n=Je.get(o);if(n!==void 0)return n;let r=e+t,s=0;for(let m=1;m<=r;m++)s+=Math.min(m,r+1-m);let i=Array.from({length:e+1},()=>new Float64Array(s+1));i[0][0]=1;for(let m=0;m<r;m++){let u=Math.min(m+1,r-m),h=Array.from({length:e+1},()=>new Float64Array(s+1));for(let p=0;p<=e;p++){if(e-p>r-m)continue;let M=i[p];for(let d=0;d<=s;d++){let b=M[d];b!==0&&(p<e&&(h[p+1][d+u]+=b),e-p<r-m&&(h[p][d]+=b))}}i=h}let l=i[e],a=0;for(;l[a]===0;)a++;let f=l.length-1;for(;l[f]===0;)f--;let c={min:a,counts:l.slice(a,f+1)};return Je.set(o,c),c}function Pt(e,t,o){let{min:n,counts:r}=hr(t,o);if(e<=0)return n;if(e>=1)return n+r.length-1;let s=Re(t+o,t),i=0;for(let l=0;l<r.length;l++)if(i+=r[l]/s,i>=e)return n+l;return n+r.length-1}function pr(e,t,o={}){let n=Array.from(e).filter(g=>!Number.isNaN(g)),r=Array.from(t).filter(g=>!Number.isNaN(g)),s=n.length,i=r.length;if(s<1)throw new RangeError("not enough 'x' observations");if(i<1)throw new RangeError("not enough 'y' observations");let l=C(o.alternative),a=o.confInt??!1,f=o.confLevel??.95;a&&U(f);let c=s+i,m=W(n.concat(r)),u=m.map(g=>Math.min(g,c-g+1)),h=0;for(let g=0;g<s;g++)h+=u[g];let p=new Set(m).size<c,M=o.exact??(s<50&&i<50&&!p),d,b;if(M&&!p){let g=y=>ie(y-1,s,i,!1),N=y=>ie(y,s,i,!0);if(l==="two.sided"){let y=Math.floor((s+1)**2/4)+Math.floor(s*i/2)/2;d=Math.min(1,2*(h>y?g(h):N(h)))}else l==="less"?d=g(h):d=N(h);a&&(b=gr(n,r,l,f))}else{let g=0;for(let R of u)g+=R*R;let N=c%2===0,y=N?s*(c+2)/4:s*(c+1)**2/(4*c),x=N?s*i*(16*g-c*(c+2)**2)/(16*c*(c-1)):s*i*(16*c*g-(c+1)**4)/(16*c*c*(c-1)),E=(h-y)/Math.sqrt(x);d=l==="two.sided"?2*Math.min(P(E),P(E,{lowerTail:!1})):l==="less"?P(E,{lowerTail:!1}):P(E),a&&(b=wr(n,r,l,f))}let w={method:"Ansari-Bradley test",alternative:l,statistic:h,statisticName:"AB",pValue:d};return b!==void 0&&(w.confInt=b.confInt,w.confLevel=f,w.estimate=b.estimate,w.estimateNames="ratio of scales"),w.nullValue=1,w.nullValueName="ratio of scales",w}function tn(e,t,o){let n=e.length,r=n+t.length,s=dr(e.map(a=>a/o).concat(t)),i=s.map(a=>Math.min(a,r-a+1)),l=0;for(let a=0;a<n;a++)l+=i[a];return{ab:l,a:i,ties:new Set(s).size<r}}function dr(e){let t=e.filter(s=>!Number.isNaN(s));if(t.length===e.length)return W(e);let o=W(t),n=0,r=t.length;return e.map(s=>Number.isNaN(s)?++r:o[n++])}function le(e,t,o){return e==="two.sided"?o(t):e==="greater"?[o(2*t)[0],1/0]:[0,o(2*t)[1]]}function gr(e,t,o,n){let r=e.length,s=t.length,i=[];for(let d of e)for(let b of t)d/b>=0&&i.push(d/b);i.sort((d,b)=>d-b);let l=i.length;if(l===0)return{confInt:le(o,1-n,()=>[NaN,NaN]),estimate:NaN};let a=i.map((d,b)=>tn(e,t,d+(b<l-1?(i[b+1]-d)/2:d*1.01)).ab),f=(d,b,w)=>{let g=1/0;for(let y of a)(b?y-d>0:y-d>=0)&&y-d<g&&(g=y-d);let N=w?-1/0:1/0;return a.forEach((y,x)=>{y-d===g&&(N=w?Math.max(N,i[x]):Math.min(N,i[x]))}),N},c=d=>{let b=Pt(d/2,r,s),w=Pt(1-d/2,r,s);if(!a.some(y=>y-b>=0)||!a.some(y=>y-w>0))return[NaN,NaN];let g=f(b,!1,!1),N=f(w,!0,!0);return g>N?[f(w,!1,!1),f(b,!0,!0)]:[g,N]},m=le(o,1-n,c),u=Pt(.5,r,s),h=-1/0,p=1/0;a.forEach((d,b)=>{d-u<=0?h=Math.max(h,i[b]):p=Math.min(p,i[b])});let M=h===-1/0||p===1/0?NaN:(p+h)/2;return{confInt:m,estimate:M}}function wr(e,t,o,n){let r=e.length,s=t.length,i=r+s,l=i%2===0,a=(b,w)=>{let{ab:g,a:N,ties:y}=tn(e,t,b),x=l?g-r*(i+2)/4:g-r*(i+1)**2/(4*i),E;if(!y)E=Math.sqrt(l?r*s*(i+2)*(i-2)/(48*(i-1)):r*s*(i+1)*(3+i*i)/(48*i*i));else{let R=0;for(let k of N)R+=k*k;E=Math.sqrt(l?r*s*(16*R-i*(i+2)**2)/(16*i*(i-1)):r*s*(16*i*R-(i+1)**4)/(16*i*i*(i-1)))}return x/E-w},f=[],c=(b,w)=>{b.length===0||w.length===0||f.push(Math.min(...b)/Math.max(...w),Math.max(...b)/Math.min(...w))};if(c(e.filter(b=>b>0),t.filter(b=>b>0)),c(e.filter(b=>b<=0),t.filter(b=>b<0)),f.some(b=>!Number.isFinite(b)))return;let m=Math.min(...f),u=Math.max(...f),h=b=>X(w=>a(w,b),m,u,{tol:1e-4}),p=b=>{let w=V(b/2),g=V(b/2,{lowerTail:!1});if(a(m,w)>0||a(u,g)<0)return[NaN,NaN];let N=h(w),y=h(g);return N<=y?[N,y]:[y,N]},M=le(o,1-n,p),d=a(m,0)>0||a(u,0)<0?NaN:h(0);return{confInt:M,estimate:d}}var Nr=[1.2337005501361697,7831619385924639e-32];function br(e,t,o){let n=(c,m)=>{let u=new Float64Array(t*t);for(let h=0;h<t;h++)for(let p=0;p<t;p++){let M=c[h*t+p];if(M!==0)for(let d=0;d<t;d++)u[h*t+d]+=M*m[p*t+d]}return u},r=c=>{let m=0;for(let p of c)m=Math.max(m,Math.abs(p));if(m===0||!Number.isFinite(m))return 0;let u=Math.floor(Math.log2(m));if(Math.abs(u)<500)return 0;let h=2**-u;for(let p=0;p<c.length;p++)c[p]*=h;return u},s,i=0,l=e.slice(),a=0,f=o;for(;f>0;)f&1&&(s=s===void 0?l.slice():n(s,l),i+=a,i+=r(s)),f>>=1,f>0&&(l=n(l,l),a*=2,a+=r(l));return[s,i]}function en(e,t){if(Number.isNaN(t)||!(e>=1)||e!==Math.floor(e))return NaN;if(t<=1/(2*e))return 0;if(t>=1)return 1;if(e*t<1){let[c,m]=vt(e,t),u=2*c-1+2*m,h=1,p=0;for(let M=1;M<=e;M++)h*=M/e*u,h<2**-500&&(h*=2**500,p-=500);for(;p<-1e3;)h*=2**-1e3,p+=1e3;return h*2**p}let o=Math.floor(e*t)+1,n=2*o-1,r=o-e*t,s=new Float64Array(n*n);for(let c=0;c<n;c++)for(let m=0;m<n;m++)s[c*n+m]=c-m+1>=0?1:0;for(let c=0;c<n;c++)s[c*n]-=Math.pow(r,c+1),s[(n-1)*n+c]-=Math.pow(r,n-c);2*r-1>0&&(s[(n-1)*n]+=Math.pow(2*r-1,n));for(let c=0;c<n;c++)for(let m=0;m<n;m++){let u=c-m+1;if(u>0){let h=1;for(let p=2;p<=u;p++)h*=p;s[c*n+m]/=h}}let[i,l]=br(s,n,e),a=i[(o-1)*n+o-1],f=l;for(let c=1;c<=e;c++)a=a*c/e,Math.abs(a)<2**-500&&(a*=2**500,f-=500);for(;f>1e3;)a*=2**1e3,f-=1e3;for(;f<-1e3;)a*=2**-1e3,f+=1e3;return a*2**f}function ce(e,t=!0){if(Number.isNaN(e))return NaN;if(e<=0)return t?0:1;if(e===1/0)return t?1:0;if(e<1){let r=Et(Nr,vt(e,e)),s=r[0]+r[1],i=Math.exp(-r[0])*(1-r[1]),l=0;for(let f=2;f<100;f++){let c=Math.exp(-(2*f-1)*(2*f-1)*s);if(l+=c,c<=1e-17*(l+i))break}let a=Math.sqrt(2*Math.PI)/e*(i+l);return t?a:1-a}let o=0;for(let r=1;r<100;r++){let s=Math.exp(-2*r*r*e*e);if(o+=r%2===1?s:-s,s<=1e-17*Math.abs(o))break}let n=2*o;return t?1-n:n}function nn(e,t){if(Number.isNaN(t)||!(e>=1)||e!==Math.floor(e))return NaN;if(t<=0)return 1;if(t>1)return 0;let[o,n]=vt(e,t),r=Math.floor(e-o-n),s=0;for(let i=0;i<=r;i++){let l=F(jt(e-i,-o),[-n,0]);if(l[0]<=0)break;let a=F(jt(i,o),[n,0]),f=Et(a,[e,0]),c=Et(l,[e,0]);s+=we(i,e-i,f,c,!1)/(f[0]+f[1])}return Math.min(t*s,1)}function rn(e,t,o,n={}){let r=n.alternative??"two.sided";if(Number.isNaN(e)||!(t>=1)||!(o>=1)||t!==Math.floor(t)||o!==Math.floor(o))return NaN;if(e<=0)return 1;if(e>1)return 0;let s=t+o,i;if(n.z!==void 0){if(n.z.length!==s)throw new RangeError("z must have length m + n");let u=[...n.z].sort((h,p)=>h-p);i=new Array(s+1).fill(!1);for(let h=1;h<s;h++)i[h]=u[h]!==u[h-1]}let l=e*t*o*(1-1e-10),a=(u,h)=>{let p=u*o-h*t;return(r==="two.sided"?Math.abs(p):r==="greater"?p:-p)>=l},f=new Float64Array(o+1),c=new Float64Array(o+1),m=0;for(let u=0;u<=t;u++){for(let h=0;h<=o;h++){if(u===0&&h===0){c[0]=1;continue}let p=u+h,M=(u>0?u/p*f[h]:0)+(h>0?h/p*c[h-1]:0);(i===void 0?p<s:i[p])&&a(u,h)?(M>0&&(m+=M*ut(u,t,o,p,!1)),c[h]=0):c[h]=M}[f,c]=[c,f],c.fill(0)}return Math.min(m,1)}function on(e,t){return e==="two.sided"?"two-sided":`the CDF of x lies ${e==="less"?"below":"above"} ${t?"the null hypothesis":"that of y"}`}function Mr(e,t,o={}){let n=Array.from(e).filter(w=>!Number.isNaN(w)).sort((w,g)=>w-g),r=n.length;if(r<1)throw new RangeError("not enough 'x' data");let s=C(o.alternative),i=s==="two.sided"?"D":s==="greater"?"D^+":"D^-";if(typeof t=="function"){let w=-1/0,g=-1/0;for(let R=0;R<r;R++){let k=t(n[R]);w=Math.max(w,(R+1)/r-k),g=Math.max(g,k-R/r)}let N=s==="two.sided"?Math.max(w,g):s==="greater"?w:g,y=new Set(n).size<r,x=o.exact??(r<100&&!y),E;return s==="two.sided"?E=x?1-en(r,N):ce(Math.sqrt(r)*N,!1):E=x?nn(r,N):Math.exp(-2*r*N*N),{method:`${x?"Exact":"Asymptotic"} one-sample Kolmogorov-Smirnov test`,alternative:on(s,!0),exact:x,statistic:N,statisticName:i,pValue:Math.min(1,Math.max(0,E))}}let l=Array.from(t).filter(w=>!Number.isNaN(w)),a=l.length;if(a<1)throw new RangeError("not enough 'y' data");let f=n.map(w=>[w,0]).concat(l.map(w=>[w,1]));f.sort((w,g)=>w[0]-g[0]);let c=0,m=0,u=0,h=0;for(let w=0;w<f.length;w++){if(f[w][1]===0?c++:m++,w+1<f.length&&f[w+1][0]===f[w][0])continue;let g=c/r-m/a;u=Math.max(u,g),h=Math.max(h,-g)}let p=s==="two.sided"?Math.max(u,h):s==="greater"?u:h,M=new Set(f.map(w=>w[0])).size<f.length,d=o.exact??r*a<1e4,b;if(d)b=rn(p,r,a,M?{alternative:s,z:f.map(w=>w[0])}:{alternative:s});else{let w=r*a/(r+a);b=s==="two.sided"?ce(Math.sqrt(w)*p,!1):Math.exp(-2*w*p*p)}return{method:`${d?"Exact":"Asymptotic"} two-sample Kolmogorov-Smirnov test`,alternative:on(s,!1),exact:d,statistic:p,statisticName:i,pValue:Math.min(1,Math.max(0,b))}}function sn(e,t,o){let n=Array.from(e);if(n.length!==t.length)throw new RangeError("'x' and 'g' must have the same length");let r=new Map;for(let i=0;i<n.length;i++){let l=t[i];if(typeof l=="number"&&Number.isNaN(l)||o&&Number.isNaN(n[i]))continue;let a=r.get(l);a===void 0&&r.set(l,a=[]),a.push(n[i])}let s=Array.from(r.keys()).sort((i,l)=>typeof i=="number"&&typeof l=="number"?i-l:String(i)<String(l)?-1:String(i)>String(l)?1:0);return{levels:s,groups:s.map(i=>r.get(i))}}function fe(e,t,o){let n=[],r=[];for(let l=0;l<e-1;l++)for(let a=l+1;a<e;a++)n.push(t(a,l)),r.push([a-1,l]);let s=Yt(n,o),i=Array.from({length:e-1},()=>new Array(e-1).fill(NaN));return r.forEach(([l,a],f)=>i[l][a]=s[f]),i}function me(e,t,o,n){return{method:e,pValue:o,rowNames:t.slice(1).map(String),colNames:t.slice(0,-1).map(String),pAdjustMethod:n}}function yr(e,t,o={}){let n=o.paired??!1,r=o.poolSd??!n;if(n&&r)throw new RangeError("pooling of SD is incompatible with paired tests");let s=C(o.alternative),i=o.pAdjustMethod??"holm",{levels:l,groups:a}=sn(e,t,!n),f=l.length;if(f<2)throw new RangeError("there must be at least two groups");let c,m;if(r){m="t tests with pooled SD";let u=a.map(b=>b.length),h=a.map(b=>b.length>0?Z(b):NaN),p=0,M=0;a.forEach(b=>{b.length>1&&(p+=K(b)*(b.length-1),M+=b.length-1)});let d=Math.sqrt(p/M);c=(b,w)=>{let g=(h[b]-h[w])/(d*Math.sqrt(1/u[b]+1/u[w]));return s==="less"?Y(g,M,!0,!1):s==="greater"?Y(g,M,!1,!1):2*Y(-Math.abs(g),M,!0,!1)}}else m=n?"paired t tests":"t tests with non-pooled SD",c=(u,h)=>Ht(a[u],a[h],{paired:n,alternative:s}).pValue;return me(m,l,fe(f,c,i),i)}function vr(e,t,o={}){let{pAdjustMethod:n,alternative:r,...s}=o,i=n??"holm",{levels:l,groups:a}=sn(e,t,!(s.paired??!1)),f=l.length;if(f<2)throw new RangeError("there must be at least two groups");let c="",m=fe(f,(u,h)=>{let p=Xt(a[u],a[h],{...s,...r===void 0?{}:{alternative:r}});return c=p.method,p.pValue},i);return me(c,l,m,i)}function xr(e,t,o={}){if(e.length!==t.length)throw new RangeError("'x' and 'n' must have the same length");let n=[],r=[];e.forEach((c,m)=>{Number.isNaN(c)||Number.isNaN(t[m])||(n.push(c),r.push(t[m]))});let s=n.length;if(s<2)throw new RangeError("too few groups");let i=o.pAdjustMethod??"holm",l=o.correct??!0,a=fe(s,(c,m)=>Jt([n[c],n[m]],[r[c],r[m]],{correct:l}).pValue,i),f=Array.from({length:s},(c,m)=>m+1);return me("Pairwise comparison of proportions",f,a,i)}function an(e){let t=e.flat(),o=Nt(t),n=[0,0],r=[0,0],s=[];for(let i of e){let l=Nt(i);s.push(l[0]);let a=Q(l,o);n=F(n,xt(xt(a,a),[i.length,0]));for(let f of i){let c=Q([f,0],l);r=F(r,xt(c,c))}}return{ssb:n[0],ssw:r[0],means:s}}function Er(e,t){let o=ft(e,t),n=o.length;if(n<2)throw new RangeError("contrasts can be applied only to factors with 2 or more levels");let r=o.reduce((u,h)=>u+h.length,0),{ssb:s,ssw:i}=an(o),l=n-1,a=r-n,f=s/l,c=i/a,m=f/c;return{df:[l,a],sumSq:[s,i],meanSq:[f,c],fValue:m,pValue:a>0?G(m,l,a,!1,!1):NaN}}function Ar(e,t,o={}){let n;t!==void 0&&!Array.isArray(t)?o=t:n=t;let{labels:r,groups:s}=te(e,n),i=s.length;if(i<2)throw new RangeError("contrasts can be applied only to factors with 2 or more levels");let l=o.confLevel??.95,f=s.reduce((M,d)=>M+d.length,0)-i,{ssw:c,means:m}=an(s),u=c/f,h=ve(l,i,f),p={names:[],i:[],j:[],diff:[],lwr:[],upr:[],pAdj:[]};for(let M=0;M<i-1;M++)for(let d=M+1;d<i;d++){let b=m[d]-m[M],w=Math.sqrt(u/2*(1/s[d].length+1/s[M].length));p.names.push(`${r[d]}-${r[M]}`),p.i.push(d+1),p.j.push(M+1),p.diff.push(b),p.lwr.push(b-h*w),p.upr.push(b+h*w),p.pAdj.push(ye(Math.abs(b)/w,i,f,{lowerTail:!1}))}return p}function Rr(e,t,o={}){let n;t!==void 0&&!ArrayBuffer.isView(t)&&!Array.isArray(t)?o=t:n=t;let{sigmaX:r,sigmaY:s}=o,i=o.mu??0;if(r===void 0&&n===void 0)throw new RangeError("sigmaX (the known standard deviation of x) is required");if(r===void 0||n!==void 0&&s===void 0)throw new RangeError("sigmaX and sigmaY are both required for two samples");if(Number.isNaN(i))throw new RangeError("mu must be a number");let l=C(o.alternative),a=o.confLevel??.95;if(!(a>=0&&a<=1))throw new RangeError("confLevel must be between 0 and 1");let f=Array.from(e).filter(g=>!Number.isNaN(g)),c=n===void 0?void 0:Array.from(n).filter(g=>!Number.isNaN(g));if(f.length<3)throw new RangeError("x needs at least 3 non-missing values");if(c!==void 0&&c.length<3)throw new RangeError("y needs at least 3 non-missing values");let m=Nt(f)[0],u=c===void 0?NaN:Nt(c)[0],h=c===void 0?r/Math.sqrt(f.length):Math.sqrt(r**2/f.length+s**2/c.length),p=c===void 0?m:m-u,M=(p-i)/h,d,b;if(l==="less")d=P(M),b=[-1/0,p+V(a)*h];else if(l==="greater")d=P(M,{lowerTail:!1}),b=[p-V(a)*h,1/0];else{d=2*P(-Math.abs(M));let g=V(1-(1-a)/2)*h;b=[p-g,p+g]}let w=c!==void 0;return{method:w?"Two-sample z-Test":"One-sample z-Test",alternative:l,statistic:M,statisticName:"z",pValue:d,confInt:b,confLevel:a,estimate:w?[m,u]:m,estimateNames:w?["mean of x","mean of y"]:"mean of x",nullValue:i,nullValueName:w?"difference in means":"mean"}}function qr(e,t,o={}){let n=o.intercept??!0,r=e.length>0&&typeof e[0]!="number"?e.map(q=>Array.from(q)):Array.from(e,q=>[q]),s=Array.from(t);if(r.length!==s.length)throw new RangeError("variable lengths differ (found for 'x')");let i=o.weights===void 0?void 0:Array.from(o.weights);if(i!==void 0&&i.length!==s.length)throw new RangeError("variable lengths differ (found for '(weights)')");if(i?.some(q=>q<0))throw new RangeError("missing or negative weights not allowed");let l=s.map((q,S)=>!Number.isNaN(q)&&r[S].every(_=>!Number.isNaN(_))&&(i===void 0||!Number.isNaN(i[S]))),a=r.filter((q,S)=>l[S]).map(q=>n?[1,...q]:q),f=s.filter((q,S)=>l[S]),c=i?.filter((q,S)=>l[S]);if(f.length===0)throw new RangeError("0 (non-NA) cases");let m=f.map((q,S)=>c===void 0||c[S]!==0),u=a.filter((q,S)=>m[S]),h=f.filter((q,S)=>m[S]),p=c?.filter((q,S)=>m[S]),M=h.length;if(M===0)throw new RangeError("all weights are zero");let d=p?.map(Math.sqrt),b=d===void 0?u:u.map((q,S)=>q.map(_=>_*d[S])),w=d===void 0?h:h.map((q,S)=>q*d[S]),g=ke(b),N=g.rank,y=Ie(g,w),x=Se(g,w),E=d===void 0?x:x.map((q,S)=>q/d[S]),R=[],k=[],v=0;f.forEach((q,S)=>{if(m[S])R.push(E[v]),k.push(q-E[v]),v++;else{let _=a[S].reduce((yt,ln,pe)=>Number.isNaN(y[pe])?yt:yt+ln*y[pe],0);k.push(_),R.push(q-_)}});let T=k.filter((q,S)=>m[S]),I=M-N,A=p??new Array(M).fill(1),L=0;for(let q=0;q<M;q++)L+=A[q]*E[q]**2;let j=L/I,O=Math.sqrt(j),H=g.qr.slice(0,N).map(q=>q.slice(0,N)),z=N>0?Ve(H):[],$=g.pivot.slice(0,N).map((q,S)=>[q,S]).sort((q,S)=>q[0]-S[0]),B=$.map(([q])=>y[q]),nt=$.map(([,q])=>Math.sqrt(z[q][q]*j)),rt=B.map((q,S)=>q/nt[S]),dt=rt.map(q=>2*Y(-Math.abs(q),I,!0,!1)),ot={coefficients:y,residuals:R,fittedValues:k,rank:N,dfResidual:I,coefTable:{estimate:B,stdError:nt,tValue:rt,pValue:dt},sigma:O,rSquared:0,adjRSquared:0,intercept:n,qr:g},ue=n?1:0,Mt=N-ue;if(Mt===0)return ot;let gt=0;if(n){let q=A.reduce((_,yt)=>_+yt,0),S=0;for(let _=0;_<M;_++)S+=A[_]*T[_]/q;for(let _=0;_<M;_++)gt+=A[_]*(T[_]-S)**2}else for(let q=0;q<M;q++)gt+=A[q]*T[q]**2;ot.rSquared=gt/(gt+L),ot.adjRSquared=1-(1-ot.rSquared)*((M-ue)/I);let he=gt/Mt/j;return ot.fStatistic={value:he,numdf:Mt,dendf:I},ot.fPValue=G(he,Mt,I,!1,!1),ot}function Tr(e,t={}){let o=t.level??.95,n=it((1+o)/2,e.dfResidual,!0,!1),{estimate:r,stdError:s}=e.coefTable,i=e.coefficients.map(()=>NaN),l=e.coefficients.map(()=>NaN),a=0;return e.coefficients.forEach((f,c)=>{Number.isNaN(f)||(i[c]=r[a]-n*s[a],l[c]=r[a]+n*s[a],a++)}),{lower:i,upper:l}}function kr(e,t,o={}){let r=(t.length>0&&typeof t[0]!="number"?t.map(p=>Array.from(p)):Array.from(t,p=>[p])).map(p=>e.intercept?[1,...p]:p),s=e.rank,i=e.qr.pivot.slice(0,s),l=e.qr.qr.slice(0,s).map(p=>p.slice(0,s)),a=e.sigma**2,f=r.map(p=>p.reduce((M,d,b)=>Number.isNaN(e.coefficients[b])?M:M+d*e.coefficients[b],0)),c=r.map(p=>{let M=new Array(s).fill(0);for(let d=0;d<s;d++){let b=p[i[d]];for(let w=0;w<d;w++)b-=l[w][d]*M[w];M[d]=b/l[d][d]}return Math.sqrt(M.reduce((d,b)=>d+b*b,0)*a)}),m=o.interval??"none";if(m==="none")return{fit:f,seFit:c};let u=it((1+(o.level??.95))/2,e.dfResidual,!0,!1),h=c.map(p=>u*Math.sqrt(p*p+(m==="prediction"?a:0)));return{fit:f,seFit:c,lwr:f.map((p,M)=>p-h[M]),upr:f.map((p,M)=>p+h[M])}}export{Ar as TukeyHSD,pr as ansariTest,Er as aov,Hn as bartlettTest,Zt as binomTest,mn as chisqTest,Tr as confint,cn as corTest,wn as fisherTest,Kn as flignerTest,Bn as friedmanTest,Wn as kruskalTest,Mr as ksTest,qr as lm,lr as mantelhaenTest,zn as mcnemarTest,Un as moodTest,or as onewayTest,Yt as pAdjust,xr as pairwisePropTest,yr as pairwiseTTest,vr as pairwiseWilcoxTest,On as poissonTest,kr as predict,Jt as propTest,Dn as quadeTest,sr as shapiroTest,Ht as tTest,$n as varTest,Xt as wilcoxTest,Rr as zTest};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@numero-uno-jpn/rstats",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "R-compatible statistical functions for the browser: distributions, random numbers that match set.seed(), hypothesis tests and linear algebra, tested against R.",
5
5
  "keywords": [
6
6
  "statistics",