@numero-uno-jpn/rstats 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/README.ja.md +8 -8
- package/README.md +8 -8
- package/THIRD_PARTY_NOTICES.md +3 -2
- package/dist/chunks/{chunk-WQWZ7FND.js → chunk-4KCSBTR5.js} +2 -2
- package/dist/chunks/{chunk-IEOD5GWC.js → chunk-4VRMAYPY.js} +2 -2
- package/dist/chunks/{chunk-BQSIBJVX.js → chunk-7IJCUSA5.js} +2 -2
- package/dist/chunks/{chunk-WIBKS73G.js → chunk-7KJ24LYK.js} +2 -2
- package/dist/chunks/{chunk-3W5NFFAA.js → chunk-DR4GQ7PW.js} +1 -1
- package/dist/chunks/{chunk-H7I32ZZE.js → chunk-DTJG2IL2.js} +2 -2
- package/dist/chunks/{chunk-BWKHYRM6.js → chunk-EJYCDE4Z.js} +1 -1
- package/dist/chunks/{chunk-YG5S5AVP.js → chunk-GGJA3JRO.js} +2 -2
- package/dist/chunks/{chunk-4OLDGML4.js → chunk-GJEKNJP7.js} +2 -2
- package/dist/chunks/{chunk-4F2IALD4.js → chunk-GRUQRNX7.js} +2 -2
- package/dist/chunks/chunk-GYGQUYEP.js +2 -0
- package/dist/chunks/{chunk-O2SQMGE3.js → chunk-HRA7PCQT.js} +2 -2
- package/dist/chunks/{chunk-63OPBEYO.js → chunk-HUWOSLKE.js} +1 -1
- package/dist/chunks/{chunk-6XJBCRBV.js → chunk-HZLSNJQM.js} +2 -2
- package/dist/chunks/{chunk-QZK3CCBA.js → chunk-JNWWLNE3.js} +2 -2
- package/dist/chunks/{chunk-NSWENS3S.js → chunk-N5BDSMXS.js} +1 -1
- package/dist/chunks/{chunk-WWVMVZUL.js → chunk-NDTJ23A6.js} +2 -2
- package/dist/chunks/{chunk-CKV4JWW2.js → chunk-OG7UORIX.js} +1 -1
- package/dist/chunks/{chunk-UKNDX4BA.js → chunk-QUTJEYDX.js} +2 -2
- package/dist/chunks/{chunk-LROMWFAK.js → chunk-U7BRXOUS.js} +2 -2
- package/dist/chunks/{chunk-QQX46TCI.js → chunk-UMLMY4XS.js} +2 -2
- package/dist/chunks/{chunk-UJ66VQIG.js → chunk-X4J6UJHN.js} +2 -2
- package/dist/chunks/{chunk-YHNMBYSW.js → chunk-Y4YWLSWU.js} +2 -2
- package/dist/chunks/{chunk-F7YGX7PN.js → chunk-YN5MLKDL.js} +2 -2
- package/dist/chunks/{chunk-DCAWMF4K.js → chunk-Z2HGLFZN.js} +2 -2
- package/dist/descriptive.js +2 -2
- package/dist/distributions/signrank.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/tests.d.ts +1 -1
- package/dist/htest/ansariTest.js +32 -34
- package/dist/htest/cor.d.ts +2 -2
- package/dist/htest/cor.js +2 -1
- package/dist/htest/core/scoreDistribution.d.ts +39 -0
- package/dist/htest/core/scoreDistribution.js +151 -0
- package/dist/htest/wilcoxTest.d.ts +23 -8
- package/dist/htest/wilcoxTest.js +521 -199
- package/dist/linalg/chol.d.ts +3 -3
- package/dist/linalg/chol.js +10 -2
- package/dist/linalg/qr.js +39 -15
- package/dist/linalg.js +2 -2
- package/dist/mixed.js +2 -2
- package/dist/models/anovaSequential.d.ts +16 -1
- package/dist/models/anovaSequential.js +40 -5
- package/dist/models/aovStrata.js +21 -4
- package/dist/models/glm.d.ts +15 -4
- package/dist/models/glm.js +13 -6
- package/dist/models/survival.d.ts +4 -1
- package/dist/models/survival.js +7 -1
- package/dist/numerics.js +2 -2
- package/dist/rstats.js +16 -16
- package/dist/special.js +2 -2
- package/dist/tests.js +13 -13
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/dist/chunks/chunk-KICBQGFN.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{l as M}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.1.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{l as M}from"./chunk-HUWOSLKE.js";var A=23283064365386963e-26,R=2328306437080797e-25,c=class{mt=new Uint32Array(624);mti=625;setSeed(t){let e=t>>>0;for(let n=0;n<50;n++)e=Math.imul(69069,e)+1>>>0;e=Math.imul(69069,e)+1>>>0;for(let n=0;n<624;n++)e=Math.imul(69069,e)+1>>>0,this.mt[n]=e;this.mti=624}sgenrand(t){for(let e=0;e<624;e++)this.mt[e]=t&4294901760,t=Math.imul(69069,t)+1>>>0,this.mt[e]=(this.mt[e]|(t&4294901760)>>>16)>>>0,t=Math.imul(69069,t)+1>>>0;this.mti=624}nextUint32(){let t=this.mt;if(this.mti>=624||this.mti===0){this.mti===625&&this.sgenrand(4357);let n=0,o;for(;n<227;n++)o=t[n]&2147483648|t[n+1]&2147483647,t[n]=t[n+397]^o>>>1^(o&1?2567483615:0);for(;n<623;n++)o=t[n]&2147483648|t[n+1]&2147483647,t[n]=t[n+-227]^o>>>1^(o&1?2567483615:0);o=t[623]&2147483648|t[0]&2147483647,t[623]=t[396]^o>>>1^(o&1?2567483615:0),this.mti=0}let e=t[this.mti++];return e^=e>>>11,e^=e<<7&2636928640,e^=e<<15&4022730752,e^=e>>>18,e>>>0}nextDouble(){let t=this.nextUint32()*A;return t<=0?.5*R:1-t<=0?1-.5*R:t}getRandomSeed(t){let e=new Int32Array(626);e[0]=t,e[1]=this.mti;for(let n=0;n<624;n++)e[n+2]=this.mt[n]|0;return e}setRandomSeed(t){if(t.length!==626)throw new RangeError("the random seed state must have 626 integers");let e=t[1];if(!Number.isInteger(e)||e<0||e>2**31-1)throw new RangeError("the position in the random seed state must be a non-negative 32-bit integer");for(let n=0;n<624;n++){let o=t[n+2];if(!Number.isInteger(o)||o<-(2**31)||o>=2**32)throw new RangeError("the random seed state must hold 32-bit integers")}this.mti=e;for(let n=0;n<624;n++)this.mt[n]=t[n+2]>>>0}};var k=2328306549295728e-25,g=r=>Math.imul(69069,r)+1>>>0,a=class{s=new Float64Array(6);setSeed(t){let e=t>>>0;for(let n=0;n<50;n++)e=g(e);for(let n=0;n<6;n++){do e=g(e);while(e>=4294944443);this.s[n]=e}}nextDouble(){let t=this.s,e=(1403580*t[1]-810728*t[0])%4294967087;e<0&&(e+=4294967087),t[0]=t[1],t[1]=t[2],t[2]=e;let n=(527612*t[5]-1370589*t[3])%4294944443;return n<0&&(n+=4294944443),t[3]=t[4],t[4]=t[5],t[5]=n,(e>n?e-n:e-n+4294967087)*k}};function p(r){if(r.length!==7)throw new RangeError("the random seed state of L'Ecuyer-CMRG must have 7 integers");let t=[];for(let e=1;e<=6;e++){let n=r[e];if(!Number.isInteger(n)||n<-2147483648||n>4294967295)throw new RangeError("the random seed state must hold 32-bit integers");t.push(n>>>0)}if(t[0]===0&&t[1]===0&&t[2]===0||t.slice(0,3).some(e=>e>=4294967087)||t.slice(3).some(e=>e>=4294944443))throw new RangeError("invalid L'Ecuyer-CMRG state: the first three seeds must be below 4294967087 and not all zero, the last three below 4294944443");return t}var I=[3.3871328727963665,133.14166789178438,1971.5909503065513,13731.69376550946,45921.95393154987,67265.7709270087,33430.57558358813,2509.0809287301227],y=[1,42.31333070160091,687.1870074920579,5394.196021424751,21213.794301586597,39307.89580009271,28729.085735721943,5226.495278852854],K=[1.4234371107496835,4.630337846156546,5.769497221460691,3.6478483247632045,1.2704582524523684,.2417807251774506,.022723844989269184,.0007745450142783414],_=[1,2.053191626637759,1.6763848301838038,.6897673349851,.14810397642748008,.015198666563616457,.0005475938084995345,10507500716444169e-25],v=[6.657904643501103,5.463784911164114,1.7848265399172913,.29656057182850487,.026532189526576124,.0012426609473880784,27115555687434876e-21,20103343992922881e-23],L=[1,.599832206555888,.1369298809227358,.014875361290850615,.0007868691311456133,18463183175100548e-21,1421511758316446e-22,20442631033899397e-31];function f(r,t){let e=r[7];for(let n=6;n>=0;n--)e=e*t+r[n];return e}function w(r){let t=r-.5;if(Math.abs(t)<=.425){let o=.180625-t*t;return t*f(I,o)/f(y,o)}let e=t<0?r:1-r;e=Math.sqrt(-Math.log(e));let n;return e<=5?(e-=1.6,n=f(K,e)/f(_,e)):(e-=5,n=f(v,e)/f(L,e)),t<0?-n:n}var G=["kind","sampleKind"],u=new c,i=u,l=!1,h=!1;function m(r){i.setSeed(r),h=!0}function E(){if(h)return;let r=(Date.now()^Math.floor(Math.random()*2**32))>>>0;typeof globalThis.crypto?.getRandomValues=="function"&&(r=globalThis.crypto.getRandomValues(new Uint32Array(1))[0]),m(r)}function q(r){if(!Number.isFinite(r))throw new RangeError("seed must be a finite number");let t=Math.trunc(r);if(Math.abs(t)>2147483647)throw new RangeError("seed must be a 32-bit integer");m(t)}var P={default:!1,"Mersenne-Twister":!1,"L'Ecuyer-CMRG":!0},T={default:!1,Rejection:!1,Rounding:!0};function N(r,t,e){if(t===void 0)return;let n=r[t];if(typeof n!="boolean")throw new RangeError(`unsupported ${e} "${t}"`);return n}function F(r={}){M(r,G,"RNGkind");let t={kind:i===u?"Mersenne-Twister":"L'Ecuyer-CMRG",normalKind:"Inversion",sampleKind:l?"Rounding":"Rejection"},e=N(P,r.kind,"RNG kind"),n=N(T,r.sampleKind,"sample kind");if(e!==void 0){let o=Math.trunc(s()*4294967295);i=e?i===u?new a:i:u,m(o)}return n!==void 0&&(l=n),t}var x=()=>(i===u?3:7)+400+(l?0:1e4);function B(){return E(),i===u?u.getRandomSeed(x()):Int32Array.of(x(),...i.s)}function V(r){let t=r[0],e=t%100;if(!Number.isInteger(t)||t<0||t>10407||e!==3&&e!==7||Math.floor(t/100)%100!==4)throw new RangeError(`unsupported RNG kind code ${String(t)} (supported: 10403, 403, 10407, 407)`);if(e===7){let n=new a;n.s.set(p(r)),i=n}else u.setRandomSeed(r),i=u;l=t<1e4,h=!0}function s(){return E(),i.nextDouble()}var z=()=>l;function U(r){let t=2**Math.max(r-16,0),e=0;for(let n=0;n<=r;n+=16){let o=Math.floor(s()*65536);e=65536*(e%t)+o}return e%2**r}var S=33554432;function Q(r){if(l)return Math.floor(r*(r>2147483647?(Math.floor(S*s())+s())/S:s()));if(r<=0)return 0;let t=Math.ceil(Math.log2(r)),e;do e=U(t);while(r<=e);return e}var b=134217728;function Y(){let r=s();return r=Math.trunc(b*r)+s(),w(r/b)}var d=(()=>{let r=[],t=1,e=0;for(let n=1;n<=16;n++)t*=Math.LN2/n,e+=t,r.push(e);return r})();function H(){let r=0,t=s();for(;t<=0||t>=1;)t=s();for(;t+=t,!(t>1);)r+=d[0];if(t-=1,t<=d[0])return r+t;let e=0,n=s(),o=n;do n=s(),o>n&&(o=n),e++;while(t>d[e]);return r+o*d[0]}export{p as a,q as b,F as c,B as d,V as e,s as f,z as g,Q as h,Y as i,H as j};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{b as A}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.1.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{b as A}from"./chunk-EJYCDE4Z.js";var y=t=>new SyntaxError(`invalid formula: ${t}`),L=/^(?:[\p{L}\p{Nl}.]|(?![0-9])\p{Nd})[\p{L}\p{Nl}\p{Nd}\p{M}._]*/u;function R(t,u,i=!1){let a=[],n=0;for(;n<t.length;){let e=t[n];if(/\s/.test(e)){n++;continue}if(/[0-9]/.test(e)||e==="."&&/[0-9]/.test(t[n+1]??"")){let c=/^(?:[0-9]+\.?[0-9]*|\.[0-9]+)(?:[eE][+-]?[0-9]+)?/.exec(t.slice(n));a.push({kind:"num",text:c[0]}),n+=c[0].length;continue}let r=L.exec(t.slice(n));if(r!==null){a.push({kind:"name",text:r[0]}),n+=r[0].length;continue}if(t.startsWith("%in%",n)){a.push({kind:"op",text:"%in%"}),n+=4;continue}if(u&&e==="|"){let c=t[n+1]==="|"?"||":"|";a.push({kind:"op",text:c}),n+=c.length;continue}if("~+-*/:^()".includes(e)||i&&e===","){a.push({kind:"op",text:e}),n++;continue}throw y(`unexpected '${e}'`)}return a.push({kind:"end"}),a}var T={"|":.5,"||":.5,"+":1,"-":1,"*":2,"/":2,"%in%":3,":":4,"^":6},C=5;function I(t,u=!1,i=!1,a=!1){if(typeof t!="string")throw new TypeError("the formula must be a string");let n=R(t,i,a),e=0,r=()=>n[e],c=()=>n[e++],f=(o,d)=>o.kind==="op"&&o.text===d;function m(){let o=c();if(o.kind==="name"){if(f(r(),"(")){if(o.text!=="Error"||!u)throw y(`function calls are not supported (${o.text})`);c();let d=g(0);if(!f(c(),")"))throw y("missing ')'");return{type:"Error",arg:d}}if(o.text===".")return{type:"dot"};if(/^\.[0-9]/.test(o.text))throw y(`unexpected '${o.text}'`);return{type:"var",name:o.text}}if(o.kind==="num")return{type:"num",value:Number(o.text),text:o.text};if(o.kind==="op"&&o.text==="("){let d=g(0);if(!f(c(),")"))throw y("missing ')'");return{type:"paren",arg:d}}if(o.kind==="op"&&(o.text==="-"||o.text==="+"))return{type:"unary",op:o.text,arg:g(C)};throw y(o.kind==="end"?"unexpected end of input":`unexpected '${o.kind==="op"?o.text:""}'`)}function g(o){let d=m();for(;;){let x=r();if(x.kind!=="op")break;let h=T[x.text];if(h===void 0||h<=o)break;c();let v=g(x.text==="^"?h-1:h);d=x.text==="|"||x.text==="||"?{type:"bar",double:x.text==="||",lhs:d,group:v}:{type:"binary",op:x.text,left:d,right:v}}return d}let b,l,s=n[0];if(a&&s.kind==="name"&&s.text==="cbind"&&f(n[1],"(")){let o=n[2],d=n[4],x=h=>h.kind==="name"&&h.text!=="."&&!/^\.[0-9]/.test(h.text);if(!(x(o)&&f(n[3],",")&&x(d)&&f(n[5],")")&&f(n[6],"~")))throw y("the response cbind() must have two column names: cbind(successes, failures)");l=[o.text,d.text],b=l[0],e=6}else if(!f(r(),"~")){let o=c();if(o.kind!=="name"||o.text==="."||!f(r(),"~"))throw y("the response must be a variable name followed by '~'");b=o.text}c();let p=g(0);if(r().kind!=="end")throw y("unexpected input after the formula");return l===void 0?{response:b,rhs:p}:{response:b,responseColumns:l,rhs:p}}function V(t){let u=[],i=e=>{if(e.type==="Error"){u.push(e.arg);return}if(e.type==="paren"){let r=i(e.arg);return r===void 0?void 0:{...e,arg:r}}if(e.type==="binary"&&e.op==="+"){let r=i(e.left),c=i(e.right);return r===void 0?c:c===void 0?r:{...e,left:r,right:c}}if(e.type==="binary"&&e.op==="-"){let r=i(e.left);return r===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:r}}return e},a=i(t),n=e=>{if(e.type==="Error")throw y("Error() must be a term of the right-hand side");e.type==="binary"?(n(e.left),n(e.right)):(e.type==="unary"||e.type==="paren")&&n(e.arg)};return a!==void 0&&n(a),u.forEach(n),{treatment:a,errors:u}}function Y(t){let u=[],i=e=>{switch(e.type){case"bar":u.push(e);return;case"paren":{let r=i(e.arg);return r===void 0?void 0:{...e,arg:r}}case"binary":if(e.op==="+"){let r=i(e.left),c=i(e.right);return r===void 0?c:c===void 0?r:{...e,left:r,right:c}}if(e.op==="-"){let r=i(e.left);return r===void 0?{type:"unary",op:"-",arg:e.right}:{...e,left:r}}return e;default:return e}},a=i(t),n=e=>{if(e.type==="bar")throw y("a random-effects term (lhs | group) must be a term of the right-hand side");e.type==="binary"?(n(e.left),n(e.right)):(e.type==="unary"||e.type==="paren"||e.type==="Error")&&n(e.arg)};a!==void 0&&n(a);for(let e of u)n(e.lhs),n(e.group);return{fixed:a,bars:u}}var M=new Set(["+","-","*","%in%"]);function w(t){switch(t.type){case"var":return t.name;case"dot":return".";case"num":return A(t.value);case"binary":{let u=w(t.left),i=w(t.right);return M.has(t.op)?`${u} ${t.op} ${i}`:`${u}${t.op}${i}`}case"unary":return`${t.op}${w(t.arg)}`;case"paren":return`(${w(t.arg)})`;case"Error":return`Error(${w(t.arg)})`;case"bar":return`${w(t.lhs)} ${t.double?"||":"|"} ${w(t.group)}`}}function k(t,u,i){if(t!==void 0)switch(t.type){case"var":i.includes(t.name)||i.push(t.name);return;case"dot":for(let a of u)i.includes(a)||i.push(a);return;case"num":return;case"binary":k(t.left,u,i),t.op!=="^"&&k(t.right,u,i);return;case"unary":case"paren":case"Error":k(t.arg,u,i);return;case"bar":k(t.lhs,u,i),k(t.group,u,i)}}function j(t,u){let i=[];return k(t,u,i),i}var N=t=>t.join(",");function E(t){let u=new Set;return t.filter(i=>{let a=N(i);return u.has(a)?!1:(u.add(a),!0)})}var $=(t,u)=>[...new Set([...t,...u])].sort((i,a)=>i-a);function B(t,u,i){let a=!0,n=(r,c)=>{switch(r.type){case"var":return[[u(r.name)]];case"dot":return i.map(f=>[u(f)]);case"num":if(r.value===1)a=!c;else if(r.value===0)a=c;else throw y(`a number (${r.text}) is not a term`);return[];case"paren":return n(r.arg,c);case"Error":throw y("Error() must be a term of the right-hand side");case"bar":throw y("a random-effects term (lhs | group) must be a term of the right-hand side");case"unary":return r.op==="+"?n(r.arg,c):(n(r.arg,!c),[]);case"binary":{if(r.op==="^"){let l=n(r.left,c),s=r.right;for(;s.type==="paren";)s=s.arg;let p=s.type==="num"?Math.trunc(s.value):NaN;if(!(p>=2&&p<=2147483647))throw new Error("invalid power in formula");let o=l;for(let d=1;d<p;d++){let x=[];for(let S of l)for(let O of o)x.push($(S,O));let h=E(x),v=h.length===o.length&&h.every((S,O)=>N(S)===N(o[O]));if(o=h,v)break}return o}if(r.op==="-"){let l=n(r.left,c),s=new Set(n(r.right,!c).map(N));return l.filter(p=>!s.has(N(p)))}let f=n(r.left,c),m=n(r.right,c);if(f.length===0&&r.op!=="+")return[];let g=()=>{let l=[];for(let s of f)for(let p of m)l.push($(s,p));return l},b=l=>l.reduce((s,p)=>$(s,p),[]);switch(r.op){case"+":return E([...f,...m]);case":":return E(g());case"*":return E([...f,...m,...g()]);case"/":{let l=b(f);return E([...f,...m.map(s=>$(s,l))])}case"%in%":{let l=b(m);return E(f.map(s=>$(s,l)))}}}}throw y("unsupported expression")};return{terms:t===void 0?[]:n(t,!1),intercept:a}}function z(t,u,i=t.rhs){let{response:a,responseColumns:n}=t,e=u.filter(s=>s!==a&&!(n?.includes(s)??!1)),r=a===void 0?[]:[a];n!==void 0&&n[1]!==a&&r.push(n[1]),k(t.rhs,e,r);let f=B(i,s=>r.indexOf(s),e),m=f.terms.map((s,p)=>[s,p]).sort((s,p)=>s[0].length-p[0].length||s[1]-p[1]).map(([s])=>s),g=[],b=a===void 0?-1:m.findIndex(s=>s.length===1&&s[0]===0);b>=0&&(g.push("the response appeared on the right-hand side and was dropped"),g.push(`problem with term ${b+1} in model.matrix: no columns are assigned`));let l=r.map(()=>m.map(()=>0));return m.forEach((s,p)=>{for(let o of s){let d=s.filter(h=>h!==o),x=d.length===0||m.slice(0,p).some(h=>d.every(v=>h.includes(v)));l[o][p]=x?1:2}}),{variables:r,response:a===void 0?-1:0,terms:m,termLabels:m.map(s=>s.map(p=>r[p]).join(":")),order:m.map(s=>s.length),intercept:f.intercept,factors:l,responseTerm:b,warnings:g}}export{I as a,V as b,Y as c,w as d,j as e,B as f,z as g};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{a as J}from"./chunk-4OLDGML4.js";import{a as H}from"./chunk-CKV4JWW2.js";import{I as D,P as $,g as sn,l as N,n as z,o as cn,r as fn,s as un,t as an,u as _,w as U,x as k,y as G,z as ln}from"./chunk-63OPBEYO.js";var Yn=["by","byX","byY","all","allX","allY","sort","suffixes"],kn=["select"],jn=["columns"];function T(e){let t=Object.values(e),n=t[0]?.length??0;if(t.some(r=>r.length!==n))throw new RangeError("the columns of a data frame must have the same length");return n}var F=e=>e==null||typeof e=="number"&&Number.isNaN(e),X=(e,t)=>e[t];function V(e,t){if(e.length>0&&e.every(n=>n instanceof Float64Array)){let n=new Float64Array(t.length);return t.forEach((r,o)=>n[o]=r===null?NaN:r[0][r[1]]),n}return t.map(n=>n===null?null:X(n[0],n[1]))}function gn(e,t){return e instanceof Float64Array?Float64Array.from(t,n=>e[n]):t.map(n=>X(e,n))}function v(e,t,n){if(Object.hasOwn(e,t))throw new RangeError(`duplicate column name '${t}'`);Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function Fn(e){if(Number.isNaN(e))return"NA";if(!Number.isFinite(e))return e>0?"Inf":"-Inf";if(e===0)return"0";let[t,n]=Number(e.toPrecision(15)).toExponential().split("e"),r=t.startsWith("-"),o=t.replace("-","").replace(".",""),s=Number(n),c=o.length,f=String(Math.abs(s)).padStart(2,"0"),i=c+(c>1?1:0)+2+f.length,u=s>=0?Math.max(s+1,c)+(c>s+1?1:0):2-s-1+c,d=r?"-":"";return u>i?`${d}${o[0]}${c>1?`.${o.slice(1)}`:""}e${s<0?"-":"+"}${f}`:s<0?`${d}0.${"0".repeat(-s-1)}${o}`:c<=s+1?`${d}${o}${"0".repeat(s+1-c)}`:`${d}${o.slice(0,s+1)}.${o.slice(s+1)}`}function B(e){return F(e)?"NA":typeof e=="number"?Fn(e):typeof e=="boolean"?e?"TRUE":"FALSE":e}var mn=Symbol("NA"),hn=e=>typeof e=="number"?0:typeof e=="string"?1:2;function $n(e,t){let n=F(e),r=F(t);if(n||r)return n===r?0:n?1:-1;let o=e,s=t;return typeof o!=typeof s?hn(o)-hn(s):typeof o=="string"?J(o,s):Number(o)-Number(s)}function vn(e){let t=e.length,n=[...e],r=e.map((s,c)=>c),o=1;for(;o<=Math.trunc(t/9);)o=3*o+1;for(;o>0;o=Math.trunc(o/3))for(let s=o;s<t;s++){let c=n[s],f=r[s],i=s;for(;i>=o&&n[i-o]>c;)n[i]=n[i-o],r[i]=r[i-o],i-=o;n[i]=c,r[i]=f}return r}function dn(e){let t=[],n=new Map;for(let r of vn(e)){let o=e[r];if(o===0)t.push(r);else{let s=n.get(o);s===void 0?n.set(o,[r]):s.push(r)}}return{alone:t,groups:n}}var Q=e=>typeof e=="string"?[e]:[...e];function pn(e,t){return t.map(n=>{if(!Object.hasOwn(e,n))throw new RangeError("'by' must specify a uniquely valid column");return e[n]})}function Zn(e,t,n={}){N(n,Yn,"merge");let r=Object.keys(e),o=Object.keys(t),s=T(e),c=T(t),f=n.by===void 0?r.filter(a=>o.includes(a)):Q(n.by),i=n.byX===void 0?f:Q(n.byX),u=n.byY===void 0?f:Q(n.byY),d=pn(e,i),y=pn(t,u);if(i.length!==u.length)throw new TypeError("'by.x' and 'by.y' specify different numbers of columns");let l=n.allX??n.all??!1,m=n.allY??n.all??!1,w=n.sort??!0,[h,b]=n.suffixes??[".x",".y"],M=r.filter(a=>!i.includes(a)),q=o.filter(a=>!u.includes(a)),An=a=>q.includes(a)?a+h:a,On=a=>M.includes(a)||i.includes(a)?a+b:a,O=[];if(i.length===0)for(let a=0;a<c;a++)for(let p=0;p<s;p++)O.push([p,a]);else{let a=d.map((g,S)=>{let j=new Set([...g,...y[S]].filter(x=>!F(x)).map(x=>typeof x));return j.has("string")?x=>typeof x=="string"?x:B(x):j.has("number")&&j.has("boolean")?x=>typeof x=="boolean"?Number(x):x:x=>x}),p=(g,S,j)=>{let x=X(g[S],j);return F(x)?mn:a[S](x)},E=i.length===1?(g,S)=>p(g,0,S):(g,S)=>JSON.stringify(g.map((j,x)=>{let W=p(g,x,S);return W===mn?null:B(W)})),A=Array.from({length:s},(g,S)=>E(d,S)),Y=Array.from({length:c},(g,S)=>E(y,S)),K=new Set(Y),I=new Map,tn=0;for(let g of A)K.has(g)&&(tn++,I.has(g)||I.set(g,tn));let rn=dn(A.map(g=>I.get(g)??0)),on=dn(Y.map(g=>I.get(g)??0));for(let[g,S]of rn.groups){let j=on.groups.get(g)??[];for(let x of S)for(let W of j)O.push([x,W])}if(l)for(let g of rn.alone)O.push([g,-1]);if(m)for(let g of on.alone)O.push([-1,g])}let L=O.some(([a])=>a<0),_n=O.some(([a])=>a>=0),nn=d.map((a,p)=>{let E=y[p],Y=V(_n||!L?L?[a,E]:[a]:[E],O.map(([K,I])=>K>=0?[a,K]:[E,I]));return L?yn(Y):Y}),C=O.map((a,p)=>p);if(w&&i.length>0){let a=(p,E)=>X(nn[E],p);if(i.length>1&&!l&&!m){let p=O.map((E,A)=>i.map((Y,K)=>B(a(A,K))).join("\r"));C.sort((E,A)=>J(p[E],p[A]))}else C.sort((p,E)=>{for(let A=0;A<i.length;A++){let Y=$n(a(p,A),a(E,A));if(Y!==0)return Y}return 0})}let en=C.map(a=>O[a]),P={};i.forEach((a,p)=>v(P,a,gn(nn[p],C)));for(let a of M){let p=e[a];v(P,An(a),V([p],en.map(([E])=>E>=0?[p,E]:null)))}for(let a of q){let p=t[a];v(P,On(a),V([p],en.map(([,E])=>E>=0?[p,E]:null)))}return P}function ne(e,t,n={}){N(n,kn,"subset");let r=Object.keys(e),o=T(e);if(typeof t!="function"&&t.length!==o)throw new RangeError(`'keep' has ${t.length} values for ${o} rows`);let s=u=>Object.fromEntries(r.map(d=>[d,X(e[d],u)])),c=[];for(let u=0;u<o;u++)(typeof t=="function"?t(s(u)):t[u])===!0&&c.push(u);let f=n.select??r,i={};for(let u of f){if(!Object.hasOwn(e,u))throw new RangeError("undefined columns selected");v(i,u,gn(e[u],c))}return i}function ee(e){if(e.length===0)return{};let t=Object.keys(e[0]);for(let r of e)if(T(r),Object.keys(r).length!==t.length||!t.every(s=>Object.hasOwn(r,s)))throw new TypeError("names do not match previous names");let n={};for(let r of t){let o=e.map(c=>c[r]),s=o.flatMap(c=>Array.from({length:c.length},(f,i)=>[c,i]));v(n,r,yn(V(o,s)))}return n}function yn(e){if(e instanceof Float64Array)return e;let t=new Set(e.filter(n=>!F(n)).map(n=>typeof n));return t.size<2?e:t.has("string")?e.map(n=>F(n)?null:typeof n=="string"?n:B(n)):e.map(n=>F(n)?null:typeof n=="boolean"?n?1:0:n)}function te(e){let t={},n=e.map(T),r=n.find(o=>o!==n[0]);if(r!==void 0)throw new RangeError(`arguments imply differing number of rows: ${n[0]}, ${r}`);for(let o of e)for(let[s,c]of Object.entries(o))v(t,s,c instanceof Float64Array?Float64Array.from(c):[...c]);return t}function re(e,t={}){N(t,jn,"fromRows");let n=t.columns;if(n===void 0){let o=new Set;for(let s of e)for(let c of Object.keys(s))o.add(c);n=[...o]}let r={};for(let o of n){let s=new Set,c=e.map((f,i)=>{let u=Object.hasOwn(f,o)?f[o]:void 0;if(u==null)return null;if(typeof u!="number"&&typeof u!="string"&&typeof u!="boolean")throw new TypeError(`row ${i}, column '${o}': values must be numbers, strings, booleans or null`);return s.add(typeof u),u});if(s.size>1)throw new TypeError(`column '${o}' mixes ${[...s].join(" and ")} values`);v(r,o,c)}return r}function oe(e){let t=Object.keys(e),n=T(e);return Array.from({length:n},(r,o)=>Object.fromEntries(t.map(s=>[s,X(e[s],o)])))}var Kn=["naRm"],In=["naRm"],Dn=["trim","naRm"],Tn=["naRm"],Xn=["naRm"],qn=["naRm"],Cn=["naRm"],Pn=["naRm"],Wn=["lag","differences"];function R(e,t){let n=Array.from(e);return t?n.filter(r=>!Number.isNaN(r)):n.some(Number.isNaN)?void 0:n}function ae(e,t={}){N(t,Kn,"sum");let n=R(e,t.naRm);return n===void 0?NaN:D(n)}function le(e,t={}){N(t,In,"prod");let n=R(e,t.naRm);if(n===void 0)return NaN;let r=bn();for(let o=0;o<n.length;o++){let s=n[o];if(!Number.isFinite(s)||s===0)return n.slice(o).reduce((c,f)=>c*f,wn(r));Nn(r,s)}return xn(r.p,r.e)}function bn(){return{p:[1,0],e:0}}function Nn(e,t){let n=Math.floor(Math.log2(Math.abs(t)));(n>500||n<-500)&&(t=_(t,-n),e.e+=n);let r=sn(e.p,[t,0]);if(n=Math.floor(Math.log2(Math.abs(r[0]))),n>500||n<-500){let o=2**-n;r=[r[0]*o,r[1]*o],e.e+=n}e.p=r}function wn(e){return e.p[0]<0?-1:1}function me(e,t={}){N(t,Dn,"mean");let n=R(e,t.naRm),r=t.trim??0;if(Number.isNaN(r)&&(n===void 0||n.length>0))throw new RangeError("'trim' must be numeric of length one");if(n===void 0)return NaN;let o=n.length;if(o===0)return NaN;if(r>0&&o>0){if(r>=.5)return Z(n);r=Math.max(r,0);let s=Math.floor(o*r),c=[...n].sort((f,i)=>f-i);return k(c.slice(s,o-s))}return k(n)}function he(e,t,n={}){N(n,Tn,"weightedMean");let r=Array.from(e),o=Array.from(t);if(r.length!==o.length)throw new RangeError("'x' and 'w' must have the same length");if(n.naRm){let h=r.map(b=>!Number.isNaN(b));r=r.filter((b,M)=>h[M]),o=o.filter((b,M)=>h[M])}let s=[],c=!1;for(let h=0;h<r.length;h++){if(o[h]===0)continue;let b=r[h]*o[h];r[h]!==0&&Math.abs(b)<2**-1022&&(c=!0),s.push(b)}let f=D(o),i=D(s)/f;if(Number.isFinite(i)&&Number.isFinite(f)&&!c||!r.every(Number.isFinite)||!o.every(Number.isFinite))return i;let u=Un(r,o);if(u!==void 0)return u;let d=r.filter((h,b)=>o[b]!==0),{groups:[y],k:l}=$([d]),{groups:[m]}=$([o]),w=[];for(let h=0,b=0;h<r.length;h++)o[h]!==0&&w.push(y[b++]*m[h]);return _(D(w)/D(m),l)}function Un(e,t){let n=[],r=[];for(let m=0;m<e.length;m++){if(t[m]===0)continue;let[w,h]=z(t[m]);if(r.push([w,h]),e[m]===0)continue;let[b,M]=z(e[m]);n.push([b*w,M+h])}let o=m=>{let w=0;for(let[,b]of m)w=Math.min(w,b);let h=0n;for(let[b,M]of m)h+=b<<BigInt(M-w);return[h,w]},[s,c]=o(n),[f,i]=o(r);if(f===0n)return;if(s===0n)return 0;f<0n&&(s=-s,f=-f);let u=s<0n,d=u?-s:s,y=Math.max(0,f.toString(2).length-d.toString(2).length+66),l=(d<<BigInt(y))/f;return l*f!==d<<BigInt(y)&&(l|=1n),cn(u?-l:l,c-i-y)}function de(e,t={}){N(t,Xn,"variance");let n=R(e,t.naRm);return n===void 0?NaN:G(n)}function pe(e,t={}){N(t,qn,"sd");let n=R(e,t.naRm);return n===void 0?NaN:ln(n)}function Z(e,t={}){N(t,Cn,"median");let n=R(e,t.naRm);if(n===void 0)return NaN;let r=n.length;if(r===0)return NaN;let o=[...n].sort((c,f)=>c-f),s=Math.floor(r/2);return r%2===1?o[s]:U([o[s-1],o[s]])[0]}function ge(e,t={}){N(t,Pn,"range");let n=R(e,t.naRm);if(n===void 0)return[NaN,NaN];let r=1/0,o=-1/0;for(let s of n)s<r&&(r=s),s>o&&(o=s);return[r,o]}function ye(e){let t=Array.from(e),n=[],r=fn(),o;for(let s of t){if(o===void 0&&!Number.isFinite(s)&&(o=0),o!==void 0){o+=s,n.push(o);continue}un(r,s,t.length),n.push(an(r))}return n}function be(e){let t=[],n=bn(),r;for(let o of Array.from(e)){if(r===void 0&&(!Number.isFinite(o)||o===0)&&(r=wn(n)),r!==void 0){r*=o,t.push(r);continue}Nn(n,o),t.push(xn(n.p,n.e))}return t}function xn(e,t){let n=e[0]+e[1];for(;t>0&&Number.isFinite(n);){let r=Math.min(t,1e3);n*=2**r,t-=r}for(;t<0&&n!==0;){let r=Math.max(t,-1e3);n*=2**r,t-=r}return n}function En(e,t){let n=[],r=NaN,o=!1;for(let s of Array.from(e)){if(o||Number.isNaN(s)){o=!0,n.push(NaN);continue}(n.length===0||t(s,r))&&(r=s),n.push(r)}return n}function Ne(e){return En(e,(t,n)=>t>n)}function we(e){return En(e,(t,n)=>t<n)}function xe(e,t={}){N(t,Wn,"diff");let n=t.lag??1,r=t.differences??1;if(!(Number.isInteger(n)&&n>=1&&Number.isInteger(r)&&r>=1))throw new RangeError("'lag' and 'differences' must be integers >= 1");let o=Array.from(e);if(n*r>=o.length)return[];for(let s=0;s<r;s++){let c=[];for(let f=n;f<o.length;f++)c.push(o[f]-o[f-n]);o=c}return o}var Gn=["type"],Vn=["type"],Bn=["naRm"],Ln=["center"],zn=["unbiased","naRm"],Hn=["center","scale"];function Sn(e){let t=$([e]).groups[0],n=U(t),r=t.map(u=>u-n[0]-n[1]),o=0;for(let u of r)o=Math.max(o,Math.abs(u));let s=o>0&&(o<2**-120||o>2**120)?2**-Math.floor(Math.log2(o)):1,c=0,f=0,i=0;for(let u of r){let d=u*s,y=d*d;c+=y,f+=y*d,i+=y*y}return[c,f,i]}function Rn(e){if(![1,2,3].includes(e))throw new RangeError("Invalid 'type' argument.")}function _e(e,t={}){N(t,Gn,"skewness");let n=t.type??3;Rn(n);let r=R(e,!0),o=r.length,[s,c]=Sn(r),f=Math.sqrt(o)*c/s**1.5;if(n===1)return f;if(n===2){if(o<3)throw new RangeError("Need at least 3 complete observations.");return f*Math.sqrt(o*(o-1))/(o-2)}return f*(1-1/o)**1.5}function Ye(e,t={}){N(t,Vn,"kurtosis");let n=t.type??3;Rn(n);let r=R(e,!0),o=r.length,[s,,c]=Sn(r),f=o*c/(s*s);if(n===1)return f-3;if(n===2){if(o<4)throw new RangeError("Need at least 4 complete observations.");return((o+1)*(f-3)+6)*(o-1)/((o-2)*(o-3))}return f*(1-1/o)**2-3}function ke(e,t={}){N(t,Bn,"geometricMean");let n=R(e,t.naRm);return n===void 0?NaN:n.some(r=>r<0)?NaN:n.includes(0)?0:Math.exp(k(n.map(Math.log)))}function je(e){let t=R(e,!0),n=new Map;for(let s of t)n.set(s===0?0:s,(n.get(s===0?0:s)??0)+1);let r=0;for(let s of n.values())r=Math.max(r,s);return r<=1?{value:[NaN],frequency:NaN}:{value:[...n.entries()].filter(([,s])=>s===r).map(([s])=>s).sort((s,c)=>s-c),frequency:r}}function Fe(e,t={}){N(t,Ln,"meanAD");let n=t.center??"mean",{groups:r,k:o}=$([R(e,!0),typeof n=="number"?[n]:[]]),s=r[0],c=n==="mean"?k(s):n==="median"?Z(s):r[1][0];return _(k(s.map(f=>Math.abs(f-c))),o)}function $e(e,t={}){N(t,zn,"cv");let n=R(e,t.naRm);if(n===void 0)return NaN;let r=n.length,o=$([n]).groups[0],s=Math.sqrt(G(o))/k(o);return t.unbiased&&(s*=1-1/(4*(r-1))+s*s/r+1/(2*(r-1)**2)),s}function Mn(e){let t=0;for(let r of e)t+=r*r;let n=H(e.map(Math.abs));if((t===1/0||t<2**-960)&&n>0&&n<1/0){t=0;for(let r of e)t+=(r/n)**2;return Math.sqrt(t/Math.max(1,e.length-1))*n}return Math.sqrt(t/Math.max(1,e.length-1))}function ve(e,t={}){N(t,Hn,"scale");let n=e.length>0&&Array.isArray(e[0])?e.map(l=>[...l]):Array.from(e,l=>[l]),r=n[0]?.length??0;if(n.some(l=>l.length!==r))throw new TypeError("all rows of the matrix must have the same length");let o=l=>n.map(m=>m[l]),s={scaled:n},c=n.map(l=>l.slice()),f=[],i=t.center??!0,u;if(i!==!1){if(u=i===!0?Array.from({length:r},(l,m)=>k(o(m).filter(w=>!Number.isNaN(w)))):[...i],u.length!==r)throw new RangeError("length of 'center' must equal the number of columns of 'x'");for(let l of n)for(let m=0;m<r;m++)l[m]=l[m]-u[m];s.center=u;for(let l=0;l<r;l++)Number.isFinite(u[l])&&n.some((m,w)=>!Number.isFinite(m[l])&&Number.isFinite(c[w][l]))&&f.push(l)}let d=t.scale??!0,y;if(d!==!1){if(y=d===!0?Array.from({length:r},(l,m)=>Mn(o(m).filter(w=>!Number.isNaN(w)))):[...d],y.length!==r)throw new RangeError("length of 'scale' must equal the number of columns of 'x'");for(let l of n)for(let m=0;m<r;m++)l[m]=l[m]/y[m];s.scale=y}for(let l of f){let m=Math.floor(Math.log2(H(c.map(M=>Math.abs(M[l])).filter(Number.isFinite)))),w=_(u[l],-m),h=c.map(M=>_(M[l],-m)-w),b=1;y!==void 0&&(d===!0?(b=Mn(h.filter(M=>!Number.isNaN(M))),y[l]=_(b,m)):b=_(y[l],-m)),n.forEach((M,q)=>M[l]=y===void 0?_(h[q],m):h[q]/b)}return s}export{T as a,F as b,gn as c,v as d,$n as e,Zn as f,ne as g,ee as h,te as i,re as j,oe as k,R as l,ae as m,le as n,me as o,he as p,de as q,pe as r,Z as s,ge as t,ye as u,be as v,Ne as w,we as x,xe as y,_e as z,Ye as A,ke as B,je as C,Fe as D,$e as E,ve as F};
|
|
1
|
+
/*! rStats.js 1.1.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as J}from"./chunk-GJEKNJP7.js";import{a as H}from"./chunk-OG7UORIX.js";import{I as D,P as $,g as sn,l as N,n as z,o as cn,r as fn,s as un,t as an,u as _,w as U,x as k,y as G,z as ln}from"./chunk-HUWOSLKE.js";var Yn=["by","byX","byY","all","allX","allY","sort","suffixes"],kn=["select"],jn=["columns"];function T(e){let t=Object.values(e),n=t[0]?.length??0;if(t.some(r=>r.length!==n))throw new RangeError("the columns of a data frame must have the same length");return n}var F=e=>e==null||typeof e=="number"&&Number.isNaN(e),X=(e,t)=>e[t];function V(e,t){if(e.length>0&&e.every(n=>n instanceof Float64Array)){let n=new Float64Array(t.length);return t.forEach((r,o)=>n[o]=r===null?NaN:r[0][r[1]]),n}return t.map(n=>n===null?null:X(n[0],n[1]))}function gn(e,t){return e instanceof Float64Array?Float64Array.from(t,n=>e[n]):t.map(n=>X(e,n))}function v(e,t,n){if(Object.hasOwn(e,t))throw new RangeError(`duplicate column name '${t}'`);Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function Fn(e){if(Number.isNaN(e))return"NA";if(!Number.isFinite(e))return e>0?"Inf":"-Inf";if(e===0)return"0";let[t,n]=Number(e.toPrecision(15)).toExponential().split("e"),r=t.startsWith("-"),o=t.replace("-","").replace(".",""),s=Number(n),c=o.length,f=String(Math.abs(s)).padStart(2,"0"),i=c+(c>1?1:0)+2+f.length,u=s>=0?Math.max(s+1,c)+(c>s+1?1:0):2-s-1+c,d=r?"-":"";return u>i?`${d}${o[0]}${c>1?`.${o.slice(1)}`:""}e${s<0?"-":"+"}${f}`:s<0?`${d}0.${"0".repeat(-s-1)}${o}`:c<=s+1?`${d}${o}${"0".repeat(s+1-c)}`:`${d}${o.slice(0,s+1)}.${o.slice(s+1)}`}function B(e){return F(e)?"NA":typeof e=="number"?Fn(e):typeof e=="boolean"?e?"TRUE":"FALSE":e}var mn=Symbol("NA"),hn=e=>typeof e=="number"?0:typeof e=="string"?1:2;function $n(e,t){let n=F(e),r=F(t);if(n||r)return n===r?0:n?1:-1;let o=e,s=t;return typeof o!=typeof s?hn(o)-hn(s):typeof o=="string"?J(o,s):Number(o)-Number(s)}function vn(e){let t=e.length,n=[...e],r=e.map((s,c)=>c),o=1;for(;o<=Math.trunc(t/9);)o=3*o+1;for(;o>0;o=Math.trunc(o/3))for(let s=o;s<t;s++){let c=n[s],f=r[s],i=s;for(;i>=o&&n[i-o]>c;)n[i]=n[i-o],r[i]=r[i-o],i-=o;n[i]=c,r[i]=f}return r}function dn(e){let t=[],n=new Map;for(let r of vn(e)){let o=e[r];if(o===0)t.push(r);else{let s=n.get(o);s===void 0?n.set(o,[r]):s.push(r)}}return{alone:t,groups:n}}var Q=e=>typeof e=="string"?[e]:[...e];function pn(e,t){return t.map(n=>{if(!Object.hasOwn(e,n))throw new RangeError("'by' must specify a uniquely valid column");return e[n]})}function Zn(e,t,n={}){N(n,Yn,"merge");let r=Object.keys(e),o=Object.keys(t),s=T(e),c=T(t),f=n.by===void 0?r.filter(a=>o.includes(a)):Q(n.by),i=n.byX===void 0?f:Q(n.byX),u=n.byY===void 0?f:Q(n.byY),d=pn(e,i),y=pn(t,u);if(i.length!==u.length)throw new TypeError("'by.x' and 'by.y' specify different numbers of columns");let l=n.allX??n.all??!1,m=n.allY??n.all??!1,w=n.sort??!0,[h,b]=n.suffixes??[".x",".y"],M=r.filter(a=>!i.includes(a)),q=o.filter(a=>!u.includes(a)),An=a=>q.includes(a)?a+h:a,On=a=>M.includes(a)||i.includes(a)?a+b:a,O=[];if(i.length===0)for(let a=0;a<c;a++)for(let p=0;p<s;p++)O.push([p,a]);else{let a=d.map((g,S)=>{let j=new Set([...g,...y[S]].filter(x=>!F(x)).map(x=>typeof x));return j.has("string")?x=>typeof x=="string"?x:B(x):j.has("number")&&j.has("boolean")?x=>typeof x=="boolean"?Number(x):x:x=>x}),p=(g,S,j)=>{let x=X(g[S],j);return F(x)?mn:a[S](x)},E=i.length===1?(g,S)=>p(g,0,S):(g,S)=>JSON.stringify(g.map((j,x)=>{let W=p(g,x,S);return W===mn?null:B(W)})),A=Array.from({length:s},(g,S)=>E(d,S)),Y=Array.from({length:c},(g,S)=>E(y,S)),K=new Set(Y),I=new Map,tn=0;for(let g of A)K.has(g)&&(tn++,I.has(g)||I.set(g,tn));let rn=dn(A.map(g=>I.get(g)??0)),on=dn(Y.map(g=>I.get(g)??0));for(let[g,S]of rn.groups){let j=on.groups.get(g)??[];for(let x of S)for(let W of j)O.push([x,W])}if(l)for(let g of rn.alone)O.push([g,-1]);if(m)for(let g of on.alone)O.push([-1,g])}let L=O.some(([a])=>a<0),_n=O.some(([a])=>a>=0),nn=d.map((a,p)=>{let E=y[p],Y=V(_n||!L?L?[a,E]:[a]:[E],O.map(([K,I])=>K>=0?[a,K]:[E,I]));return L?yn(Y):Y}),C=O.map((a,p)=>p);if(w&&i.length>0){let a=(p,E)=>X(nn[E],p);if(i.length>1&&!l&&!m){let p=O.map((E,A)=>i.map((Y,K)=>B(a(A,K))).join("\r"));C.sort((E,A)=>J(p[E],p[A]))}else C.sort((p,E)=>{for(let A=0;A<i.length;A++){let Y=$n(a(p,A),a(E,A));if(Y!==0)return Y}return 0})}let en=C.map(a=>O[a]),P={};i.forEach((a,p)=>v(P,a,gn(nn[p],C)));for(let a of M){let p=e[a];v(P,An(a),V([p],en.map(([E])=>E>=0?[p,E]:null)))}for(let a of q){let p=t[a];v(P,On(a),V([p],en.map(([,E])=>E>=0?[p,E]:null)))}return P}function ne(e,t,n={}){N(n,kn,"subset");let r=Object.keys(e),o=T(e);if(typeof t!="function"&&t.length!==o)throw new RangeError(`'keep' has ${t.length} values for ${o} rows`);let s=u=>Object.fromEntries(r.map(d=>[d,X(e[d],u)])),c=[];for(let u=0;u<o;u++)(typeof t=="function"?t(s(u)):t[u])===!0&&c.push(u);let f=n.select??r,i={};for(let u of f){if(!Object.hasOwn(e,u))throw new RangeError("undefined columns selected");v(i,u,gn(e[u],c))}return i}function ee(e){if(e.length===0)return{};let t=Object.keys(e[0]);for(let r of e)if(T(r),Object.keys(r).length!==t.length||!t.every(s=>Object.hasOwn(r,s)))throw new TypeError("names do not match previous names");let n={};for(let r of t){let o=e.map(c=>c[r]),s=o.flatMap(c=>Array.from({length:c.length},(f,i)=>[c,i]));v(n,r,yn(V(o,s)))}return n}function yn(e){if(e instanceof Float64Array)return e;let t=new Set(e.filter(n=>!F(n)).map(n=>typeof n));return t.size<2?e:t.has("string")?e.map(n=>F(n)?null:typeof n=="string"?n:B(n)):e.map(n=>F(n)?null:typeof n=="boolean"?n?1:0:n)}function te(e){let t={},n=e.map(T),r=n.find(o=>o!==n[0]);if(r!==void 0)throw new RangeError(`arguments imply differing number of rows: ${n[0]}, ${r}`);for(let o of e)for(let[s,c]of Object.entries(o))v(t,s,c instanceof Float64Array?Float64Array.from(c):[...c]);return t}function re(e,t={}){N(t,jn,"fromRows");let n=t.columns;if(n===void 0){let o=new Set;for(let s of e)for(let c of Object.keys(s))o.add(c);n=[...o]}let r={};for(let o of n){let s=new Set,c=e.map((f,i)=>{let u=Object.hasOwn(f,o)?f[o]:void 0;if(u==null)return null;if(typeof u!="number"&&typeof u!="string"&&typeof u!="boolean")throw new TypeError(`row ${i}, column '${o}': values must be numbers, strings, booleans or null`);return s.add(typeof u),u});if(s.size>1)throw new TypeError(`column '${o}' mixes ${[...s].join(" and ")} values`);v(r,o,c)}return r}function oe(e){let t=Object.keys(e),n=T(e);return Array.from({length:n},(r,o)=>Object.fromEntries(t.map(s=>[s,X(e[s],o)])))}var Kn=["naRm"],In=["naRm"],Dn=["trim","naRm"],Tn=["naRm"],Xn=["naRm"],qn=["naRm"],Cn=["naRm"],Pn=["naRm"],Wn=["lag","differences"];function R(e,t){let n=Array.from(e);return t?n.filter(r=>!Number.isNaN(r)):n.some(Number.isNaN)?void 0:n}function ae(e,t={}){N(t,Kn,"sum");let n=R(e,t.naRm);return n===void 0?NaN:D(n)}function le(e,t={}){N(t,In,"prod");let n=R(e,t.naRm);if(n===void 0)return NaN;let r=bn();for(let o=0;o<n.length;o++){let s=n[o];if(!Number.isFinite(s)||s===0)return n.slice(o).reduce((c,f)=>c*f,wn(r));Nn(r,s)}return xn(r.p,r.e)}function bn(){return{p:[1,0],e:0}}function Nn(e,t){let n=Math.floor(Math.log2(Math.abs(t)));(n>500||n<-500)&&(t=_(t,-n),e.e+=n);let r=sn(e.p,[t,0]);if(n=Math.floor(Math.log2(Math.abs(r[0]))),n>500||n<-500){let o=2**-n;r=[r[0]*o,r[1]*o],e.e+=n}e.p=r}function wn(e){return e.p[0]<0?-1:1}function me(e,t={}){N(t,Dn,"mean");let n=R(e,t.naRm),r=t.trim??0;if(Number.isNaN(r)&&(n===void 0||n.length>0))throw new RangeError("'trim' must be numeric of length one");if(n===void 0)return NaN;let o=n.length;if(o===0)return NaN;if(r>0&&o>0){if(r>=.5)return Z(n);r=Math.max(r,0);let s=Math.floor(o*r),c=[...n].sort((f,i)=>f-i);return k(c.slice(s,o-s))}return k(n)}function he(e,t,n={}){N(n,Tn,"weightedMean");let r=Array.from(e),o=Array.from(t);if(r.length!==o.length)throw new RangeError("'x' and 'w' must have the same length");if(n.naRm){let h=r.map(b=>!Number.isNaN(b));r=r.filter((b,M)=>h[M]),o=o.filter((b,M)=>h[M])}let s=[],c=!1;for(let h=0;h<r.length;h++){if(o[h]===0)continue;let b=r[h]*o[h];r[h]!==0&&Math.abs(b)<2**-1022&&(c=!0),s.push(b)}let f=D(o),i=D(s)/f;if(Number.isFinite(i)&&Number.isFinite(f)&&!c||!r.every(Number.isFinite)||!o.every(Number.isFinite))return i;let u=Un(r,o);if(u!==void 0)return u;let d=r.filter((h,b)=>o[b]!==0),{groups:[y],k:l}=$([d]),{groups:[m]}=$([o]),w=[];for(let h=0,b=0;h<r.length;h++)o[h]!==0&&w.push(y[b++]*m[h]);return _(D(w)/D(m),l)}function Un(e,t){let n=[],r=[];for(let m=0;m<e.length;m++){if(t[m]===0)continue;let[w,h]=z(t[m]);if(r.push([w,h]),e[m]===0)continue;let[b,M]=z(e[m]);n.push([b*w,M+h])}let o=m=>{let w=0;for(let[,b]of m)w=Math.min(w,b);let h=0n;for(let[b,M]of m)h+=b<<BigInt(M-w);return[h,w]},[s,c]=o(n),[f,i]=o(r);if(f===0n)return;if(s===0n)return 0;f<0n&&(s=-s,f=-f);let u=s<0n,d=u?-s:s,y=Math.max(0,f.toString(2).length-d.toString(2).length+66),l=(d<<BigInt(y))/f;return l*f!==d<<BigInt(y)&&(l|=1n),cn(u?-l:l,c-i-y)}function de(e,t={}){N(t,Xn,"variance");let n=R(e,t.naRm);return n===void 0?NaN:G(n)}function pe(e,t={}){N(t,qn,"sd");let n=R(e,t.naRm);return n===void 0?NaN:ln(n)}function Z(e,t={}){N(t,Cn,"median");let n=R(e,t.naRm);if(n===void 0)return NaN;let r=n.length;if(r===0)return NaN;let o=[...n].sort((c,f)=>c-f),s=Math.floor(r/2);return r%2===1?o[s]:U([o[s-1],o[s]])[0]}function ge(e,t={}){N(t,Pn,"range");let n=R(e,t.naRm);if(n===void 0)return[NaN,NaN];let r=1/0,o=-1/0;for(let s of n)s<r&&(r=s),s>o&&(o=s);return[r,o]}function ye(e){let t=Array.from(e),n=[],r=fn(),o;for(let s of t){if(o===void 0&&!Number.isFinite(s)&&(o=0),o!==void 0){o+=s,n.push(o);continue}un(r,s,t.length),n.push(an(r))}return n}function be(e){let t=[],n=bn(),r;for(let o of Array.from(e)){if(r===void 0&&(!Number.isFinite(o)||o===0)&&(r=wn(n)),r!==void 0){r*=o,t.push(r);continue}Nn(n,o),t.push(xn(n.p,n.e))}return t}function xn(e,t){let n=e[0]+e[1];for(;t>0&&Number.isFinite(n);){let r=Math.min(t,1e3);n*=2**r,t-=r}for(;t<0&&n!==0;){let r=Math.max(t,-1e3);n*=2**r,t-=r}return n}function En(e,t){let n=[],r=NaN,o=!1;for(let s of Array.from(e)){if(o||Number.isNaN(s)){o=!0,n.push(NaN);continue}(n.length===0||t(s,r))&&(r=s),n.push(r)}return n}function Ne(e){return En(e,(t,n)=>t>n)}function we(e){return En(e,(t,n)=>t<n)}function xe(e,t={}){N(t,Wn,"diff");let n=t.lag??1,r=t.differences??1;if(!(Number.isInteger(n)&&n>=1&&Number.isInteger(r)&&r>=1))throw new RangeError("'lag' and 'differences' must be integers >= 1");let o=Array.from(e);if(n*r>=o.length)return[];for(let s=0;s<r;s++){let c=[];for(let f=n;f<o.length;f++)c.push(o[f]-o[f-n]);o=c}return o}var Gn=["type"],Vn=["type"],Bn=["naRm"],Ln=["center"],zn=["unbiased","naRm"],Hn=["center","scale"];function Sn(e){let t=$([e]).groups[0],n=U(t),r=t.map(u=>u-n[0]-n[1]),o=0;for(let u of r)o=Math.max(o,Math.abs(u));let s=o>0&&(o<2**-120||o>2**120)?2**-Math.floor(Math.log2(o)):1,c=0,f=0,i=0;for(let u of r){let d=u*s,y=d*d;c+=y,f+=y*d,i+=y*y}return[c,f,i]}function Rn(e){if(![1,2,3].includes(e))throw new RangeError("Invalid 'type' argument.")}function _e(e,t={}){N(t,Gn,"skewness");let n=t.type??3;Rn(n);let r=R(e,!0),o=r.length,[s,c]=Sn(r),f=Math.sqrt(o)*c/s**1.5;if(n===1)return f;if(n===2){if(o<3)throw new RangeError("Need at least 3 complete observations.");return f*Math.sqrt(o*(o-1))/(o-2)}return f*(1-1/o)**1.5}function Ye(e,t={}){N(t,Vn,"kurtosis");let n=t.type??3;Rn(n);let r=R(e,!0),o=r.length,[s,,c]=Sn(r),f=o*c/(s*s);if(n===1)return f-3;if(n===2){if(o<4)throw new RangeError("Need at least 4 complete observations.");return((o+1)*(f-3)+6)*(o-1)/((o-2)*(o-3))}return f*(1-1/o)**2-3}function ke(e,t={}){N(t,Bn,"geometricMean");let n=R(e,t.naRm);return n===void 0?NaN:n.some(r=>r<0)?NaN:n.includes(0)?0:Math.exp(k(n.map(Math.log)))}function je(e){let t=R(e,!0),n=new Map;for(let s of t)n.set(s===0?0:s,(n.get(s===0?0:s)??0)+1);let r=0;for(let s of n.values())r=Math.max(r,s);return r<=1?{value:[NaN],frequency:NaN}:{value:[...n.entries()].filter(([,s])=>s===r).map(([s])=>s).sort((s,c)=>s-c),frequency:r}}function Fe(e,t={}){N(t,Ln,"meanAD");let n=t.center??"mean",{groups:r,k:o}=$([R(e,!0),typeof n=="number"?[n]:[]]),s=r[0],c=n==="mean"?k(s):n==="median"?Z(s):r[1][0];return _(k(s.map(f=>Math.abs(f-c))),o)}function $e(e,t={}){N(t,zn,"cv");let n=R(e,t.naRm);if(n===void 0)return NaN;let r=n.length,o=$([n]).groups[0],s=Math.sqrt(G(o))/k(o);return t.unbiased&&(s*=1-1/(4*(r-1))+s*s/r+1/(2*(r-1)**2)),s}function Mn(e){let t=0;for(let r of e)t+=r*r;let n=H(e.map(Math.abs));if((t===1/0||t<2**-960)&&n>0&&n<1/0){t=0;for(let r of e)t+=(r/n)**2;return Math.sqrt(t/Math.max(1,e.length-1))*n}return Math.sqrt(t/Math.max(1,e.length-1))}function ve(e,t={}){N(t,Hn,"scale");let n=e.length>0&&Array.isArray(e[0])?e.map(l=>[...l]):Array.from(e,l=>[l]),r=n[0]?.length??0;if(n.some(l=>l.length!==r))throw new TypeError("all rows of the matrix must have the same length");let o=l=>n.map(m=>m[l]),s={scaled:n},c=n.map(l=>l.slice()),f=[],i=t.center??!0,u;if(i!==!1){if(u=i===!0?Array.from({length:r},(l,m)=>k(o(m).filter(w=>!Number.isNaN(w)))):[...i],u.length!==r)throw new RangeError("length of 'center' must equal the number of columns of 'x'");for(let l of n)for(let m=0;m<r;m++)l[m]=l[m]-u[m];s.center=u;for(let l=0;l<r;l++)Number.isFinite(u[l])&&n.some((m,w)=>!Number.isFinite(m[l])&&Number.isFinite(c[w][l]))&&f.push(l)}let d=t.scale??!0,y;if(d!==!1){if(y=d===!0?Array.from({length:r},(l,m)=>Mn(o(m).filter(w=>!Number.isNaN(w)))):[...d],y.length!==r)throw new RangeError("length of 'scale' must equal the number of columns of 'x'");for(let l of n)for(let m=0;m<r;m++)l[m]=l[m]/y[m];s.scale=y}for(let l of f){let m=Math.floor(Math.log2(H(c.map(M=>Math.abs(M[l])).filter(Number.isFinite)))),w=_(u[l],-m),h=c.map(M=>_(M[l],-m)-w),b=1;y!==void 0&&(d===!0?(b=Mn(h.filter(M=>!Number.isNaN(M))),y[l]=_(b,m)):b=_(y[l],-m)),n.forEach((M,q)=>M[l]=y===void 0?_(h[q],m):h[q]/b)}return s}export{T as a,F as b,gn as c,v as d,$n as e,Zn as f,ne as g,ee as h,te as i,re as j,oe as k,R as l,ae as m,le as n,me as o,he as p,de as q,pe as r,Z as s,ge as t,ye as u,be as v,Ne as w,we as x,xe as y,_e as z,Ye as A,ke as B,je as C,Fe as D,$e as E,ve as F};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{a as h,t as s,u as b}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.1.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{a as h,t as s,u as b}from"./chunk-NDTJ23A6.js";import{l as M}from"./chunk-HUWOSLKE.js";function K(t){return Math.abs(t-m(t))>1e-9*Math.max(1,Math.abs(t))}function F(t){let e=m(t);return Math.abs(t-e)<=Math.min(1e-7,1e-9*Math.max(1,Math.abs(t)))?e:Math.floor(t)}function m(t){if(!Number.isFinite(t))return t;let e=Math.round(t);return e-t===.5&&e%2!==0?e-1:e}var A=["rCompatible"],E=["rCompatible"],O=[.08333333333333333,-.021092796092796094,.007575757575757576,-.004166666666666667,.003968253968253968,-.008333333333333333,.08333333333333333],S=.9955816268920898,d=1569415565/1073741824,w=381566830/1073741824/1073741824,_=9016312093258695e-35,k=[-.002071332116774595,-.04525132144873906,-.28919126444774784,-.6503185377089651,-.3255503118680449,.25479851061131553],v=[-5578984132167551e-22,.0021284987017821146,.054151797245674226,.43593529692665967,1.4606242909763516,2.076711702373047,1];function R(t){let e=t-d;e-=w,e-=_;let r=h(t-1,k)/h(t-1,v);return e*S+e*r}function T(t){let e=0;if(t<1e17){let r=1/(t*t);e=r*h(r,O)}return Math.log(t)-.5/t-e}function C(t){let e=0;if(Number.isNaN(t)||t===1/0)return t;if(t===-1/0)return NaN;if(t===0)return NaN;if(t<0){let r=t-Math.trunc(t);if(r===0)return NaN;e=-Math.PI/Math.tan(Math.PI*r),t=1-t}if(t<=10&&t===Math.floor(t)){let r=t;for(let o=1;o<r;o++)e+=1/o;return e-b}if(t<1)e-=1/t,t+=1;else if(t<10)for(;t>2;)t-=1,e+=1/t;return t>=1&&t<=2?e+R(t):e+T(t)}var N=-.5040830082644554,z=7289763902976895e-32,I;function G(t){I??=Array.from({length:100},(n,a)=>j(a+2,N));let e=z,r=-1,o=t-N;for(let n=1;n<100;n++){r*=-o;let a=r*I[n-1];if(e+=a,Math.abs(a)<Number.EPSILON*Math.abs(e))break}return e}var P=[12,-720,30240,-1209600,47900160,-18924375803183792e-7,74724249600,-2950130727918164e-3,11646782814350067e-2,-4597978722407473,0x284e46fd8153bc0,-7166165256175667e3];function Z(t,e){let r=1,o=e,n=1,a=0;for(;e<=1e8&&(a<9||o<=9||o<t);)if(a+=1,o+=1,n=Math.exp(-t*Math.log1p(a/e)),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let c=1,i=0;for(let u=0;u<12;u++){c*=t+i,n/=f;let l=c*n/P[u];if(r+=l,Math.abs(l/r)<s)break;i+=1,c*=t+i,n/=f,i+=1}return r}function j(t,e){let r=Math.pow(e,-t),o=e,n=0,a=0;for(;a<9||o<=9||o<t;)if(a+=1,o+=1,n=Math.pow(o,-t),r+=n,Math.abs(n/r)<s)return r;let f=o;r+=n*f/(t-1),r-=.5*n;let c=1,i=0;for(let u=0;u<12;u++){c*=t+i,n/=f;let l=c*n/P[u];if(r+=l,Math.abs(l/r)<s)break;i+=1,c*=t+i,n/=f,i+=1}return r}function g(t,e){if(e===1/0)return t%2===0?-0:0;let r=1;for(let n=1;n<=t;n++)r*=n/e;let o=r*(Z(t+1,e)/e);return t%2===0?-o:o}var p=[];function D(t){if(p[t]!==void 0)return p[t];let e=[0,1];for(let n=0;n<t;n++){let a=e.slice(1).map((c,i)=>c*(i+1)),f=new Array(a.length+2).fill(0);a.forEach((c,i)=>{f[i]=f[i]-c,f[i+2]=f[i+2]-c}),e=f}let r=(t+1)%2,o=[];for(let n=r;n<e.length;n+=2)o.push(e[n]);return p[t]=o,o}function H(t,e){let r=D(t),o=e*e,n=r[r.length-1];for(let a=r.length-2;a>=0;a--)n=n*o+r[a];return(t+1)%2===1?n*e:n}function L(t){let e=t-Math.round(t);return Math.sin(Math.PI*(.5-Math.abs(e)))/Math.sin(Math.PI*e)}function y(t,e,r){if(Number.isNaN(e))return NaN;if(e===-1/0)return r&&t%2===1?1/0:NaN;if(e<=0&&e===Math.floor(e))return t%2===1?1/0:NaN;if(e>0)return g(t,e);let o=g(t,1-e);return(t%2===0?o:-o)-Math.pow(Math.PI,t+1)*H(t,L(e))}function Y(t){return Math.abs(t-N)<.3?G(t):C(t)}function W(t,e){return M(e,A,"trigamma"),y(1,t,e?.rCompatible??!0)}function X(t,e=0,r){M(r,E,"psigamma");let o=m(e);return Number.isNaN(o)||o<0||o>100?NaN:o===0?Y(t):y(o,t,r?.rCompatible??!0)}export{K as a,F as b,m as c,Y as d,W as e,X as f};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{c as le}from"./chunk-DCAWMF4K.js";import{a as ne}from"./chunk-BQSIBJVX.js";import{a as ue,g as fe}from"./chunk-LROMWFAK.js";import{x as z}from"./chunk-YG5S5AVP.js";import{b as me,c as V}from"./chunk-4OLDGML4.js";import{c as R}from"./chunk-NSWENS3S.js";import{b as re}from"./chunk-BWKHYRM6.js";import{r as L,s as j}from"./chunk-WWVMVZUL.js";import{A as ie,B as ee,J as te,K as q,M as ce,b as oe,c as ae,d as S,f as W,g as F,i as G,l as M}from"./chunk-63OPBEYO.js";function B(e){if(e.kind==="factor")return me(e);let t=[...new Set(e.values)].sort((o,a)=>o-a),r=[...new Set(t.map(re))],n=new Map(r.map((o,a)=>[o,a]));return{levels:r,codes:e.values.map(o=>n.get(re(o)))}}function A(e,t){if(e.kind!=="numeric")throw new TypeError(`'${t}' must be a numeric column`);return e.values}function C(e,t){let r=ue(e),n=fe(r,Object.keys(t));return{terms:n,rhsVariables:n.variables.slice(n.response===0?1:0)}}function de(e){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");return t<0?void 0:{lhs:e.slice(0,t).trim(),rhs:e.slice(t+1)}}var Oe=/^Pair\s*\(\s*([A-Za-z.][A-Za-z0-9._]*)\s*,\s*([A-Za-z.][A-Za-z0-9._]*)\s*\)$/,$="'formula' missing or incorrect",pe=(e,t)=>t.length===0&&e.terms.length===0&&e.intercept;function De(e,t,r){let n=de(e),o=n===void 0?null:Oe.exec(n.lhs);if(o!==null){let{terms:m,rhsVariables:d}=C(`~${n.rhs}`,t);if(!r||!pe(m,d))throw new TypeError($);let w=V(t,[o[1],o[2]]);return{kind:"paired",x:A(w.variables[0],o[1]),y:A(w.variables[1],o[2])}}let{terms:a,rhsVariables:c}=C(e,t);if(a.response<0)throw new TypeError($);let i=a.variables[0];if(r&&pe(a,c))return{kind:"one",x:A(V(t,[i]).variables[0],i)};if(c.length!==1||a.terms.length!==1)throw new TypeError($);let s=V(t,[i,c[0]],{dropUnusedLevels:!0}),l=A(s.variables[0],i),u=B(s.variables[1]);if(u.levels.length!==2)throw new Error("grouping factor must have exactly 2 levels");return{kind:"two",x:l.filter((m,d)=>u.codes[d]===0),y:l.filter((m,d)=>u.codes[d]===1),levels:[u.levels[0],u.levels[1]]}}function Je(e,t){let r=De(e,t,!1);if(r.kind!=="two")throw new TypeError($);return r}function Qe(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0)throw new TypeError($);if(n.length!==1)throw new TypeError("'formula' should be of the form response ~ group");let o=r.variables[0],a=V(t,[o,n[0]],{dropUnusedLevels:!0});return{values:A(a.variables[0],o),group:B(a.variables[1])}}function et(e,t){let r=t.levels.map(()=>[]);return e.forEach((n,o)=>r[t.codes[o]].push(n)),r}function tt(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0||n.length===0)throw new TypeError($);let o=r.variables[0],a=V(t,[o,...n],{dropUnusedLevels:!0}),c=a.variables.slice(1).map(B),i=a.rows.map((s,l)=>{let u=0,m=1;for(let d of c)u+=d.codes[l]*m,m*=d.levels.length;return u});return{values:A(a.variables[0],o),groups:i}}var he="incorrect specification for 'formula'";function rt(e,t){let r=de(e),n=r?.rhs.split("|");if(r===void 0||r.lhs===""||n.length!==2)throw new TypeError(he);let o=y=>{let{terms:x,rhsVariables:p}=C(y,t);if(p.length!==1||x.terms.length!==1)throw new TypeError(he);return p[0]},{terms:a}=C(`${r.lhs} ~ 1`,t),c=a.variables[0],i=o(`~${n[0]}`),s=o(`~${n[1]}`),l=V(t,[c,i,s],{dropUnusedLevels:!0}),u=A(l.variables[0],c),m=B(l.variables[1]),d=B(l.variables[2]),w=d.levels.map(()=>m.levels.map(()=>NaN)),g=d.levels.map(()=>m.levels.map(()=>0));if(u.forEach((y,x)=>{let p=d.codes[x],N=m.codes[x];g[p][N]++,w[p][N]=y}),g.some(y=>y.some(x=>x!==1)))throw new Error("not an unreplicated complete block design");return w}function we(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response>=0)throw new TypeError("'formula' missing or invalid");if(n.length!==2)throw new TypeError("invalid formula");let o=V(t,n);return{x:A(o.variables[0],n[0]),y:A(o.variables[1],n[1])}}function ge(e){if(e===void 0)return"two.sided";let r=["two.sided","less","greater"].filter(n=>n.startsWith(e));if(e.length===0||r.length!==1)throw new RangeError(`invalid alternative "${e}" (expected "two.sided", "less" or "greater")`);return r[0]}function Ne(e){if(!(Number.isFinite(e)&&e>=0&&e<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function st(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7}function ot(e){if(!(Number.isFinite(e)&&e>0&&e<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var Fe=["alternative","exact","confLevel","continuity","method"],$e=["pearson","kendall","spearman"];function Pe(e){if(e===void 0)return"pearson";let t=$e.filter(r=>r.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function be(e){if(!(e[0]>0))return[Math.sqrt(e[0]),0];let t=Math.sqrt(e[0]),r=W(e,ae(t,t));return oe(t,r[0]/(2*t))}function H(e,t){let r=e.length;if(r<2)return[NaN,0];let n=ee(e)?.d,o=ee(t)?.d;if(n===void 0||o===void 0)return[NaN,0];let a=[0,0],c=[0,0],i=[0,0];for(let l=0;l<r;l++)a=S(a,F(n[l],o[l])),c=S(c,F(n[l],n[l])),i=S(i,F(o[l],o[l]));if(c[0]===0||i[0]===0)return[NaN,0];let s=G(a,F(be(c),be(i)));return s[0]>=1?[1,0]:s[0]<=-1?[-1,0]:s}function ve(e,t){let r=F(W([1,0],e),S([1,0],e));return Math.sqrt(t)*e[0]/Math.sqrt(r[0])}function Ke(e){return Math.abs(e[0])<.5?Math.atanh(e[0]):.5*Math.log(S([1,0],e)[0]/W([1,0],e)[0])}function ye(e,t,r){return r==="less"?z(e,t,!0,!1):r==="greater"?z(e,t,!1,!1):2*Math.min(z(e,t,!0,!1),z(e,t,!1,!1))}function Ie(e,t){return t==="less"?L(e):t==="greater"?L(e,{lowerTail:!1}):2*Math.min(L(e),L(e,{lowerTail:!1}))}function X(e,t){let r=e.length,n=0;for(let u=0;u<r;u++){let m=e[u],d=t[u];for(let w=u+1;w<r;w++){let g=(e[w]>m?1:0)-(e[w]<m?1:0),y=(t[w]>d?1:0)-(t[w]<d?1:0);n+=g*y}}let o=q(e),a=q(t),c=r*(r-1)/2,i=o.reduce((u,m)=>u+m*(m-1)/2,0),s=a.reduce((u,m)=>u+m*(m-1)/2,0),l=r<2||i===c||s===c?NaN:i===0&&s===0?n/c:n/Math.sqrt((c-i)*(c-s));return{s:n,tau:l,ties:o.length>0||a.length>0,tx:o,ty:a}}var Ee=1290;function ke(e,t){let r=e*(e-1)/2;if(t<0)return 0;if(t>=r)return 1;let n=new Float64Array(t+1);n[0]=1;for(let a=2;a<=e;a++){let c=new Float64Array(t+1),i=0;for(let l=0;l<=t;l++)i+=n[l],c[l]=i;let s=new Float64Array(t+1);for(let l=0;l<=t;l++)s[l]=(c[l]-(l>=a?c[l-a]:0))/a;n=s}let o=0;for(let a=t;a>=0;a--)o+=n[a];return Math.min(1,o)}var Te=new Map;function je(e){let t=Te.get(e);if(t!==void 0)return t;let r=e*(e*e-1)/3,n=1<<e,o=new Array(n);o[0]=new Float64Array(r+1),o[0][0]=1;let a=i=>{let s=0;for(;i;i&=i-1)s++;return s};for(let i=0;i<n;i++){let s=o[i];if(s===void 0)continue;let l=a(i);for(let u=0;u<e;u++){if(i&1<<u)continue;let m=(u-l)**2,d=i|1<<u,w=o[d]??=new Float64Array(r+1);for(let g=0;g+m<=r;g++)s[g]&&(w[g+m]+=s[g])}i!==n-1&&(o[i]=void 0)}let c=o[n-1];return Te.set(e,c),c}var T=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function xe(e,t,r){let n=t;n%2!==0&&(n+=1);let o=1/e,a=(6*(n-1)*o/(e*e-1)-1)*Math.sqrt(1/o-1),c=a*a,s=a*o*(T[0]+o*(T[1]+T[2]*o)+c*(-T[3]+o*(T[4]+T[5]*o)-c*o*(T[6]+T[7]*o-c*(T[8]-T[9]*o+c*o*(T[10]-T[11]*c)))))/Math.exp(c/2),l=r?L(a)-s:s+L(a,{lowerTail:!1});return Math.min(1,Math.max(0,l))}function Me(e,t,r){let n=e*(e*e-1)/3;if(e<=9){let o=je(e),a=1;for(let i=2;i<=e;i++)a*=i;let c=0;if(r)for(let i=Math.min(t,n);i>=0;i--)c+=o[i];else for(let i=n;i>=Math.max(t,0);i--)c+=o[i];return c/a}return r?t+1>n?1:t+1<=0?0:xe(e,t+1,!0):t<=0?1:t>n?0:xe(e,t,!1)}function qe(e,t,r={}){if(M(r,Fe,"corTest"),typeof e=="string"){let n=we(e,t);return qe(n.x,n.y,r)}return ze(e,t,r)}function ze(e,t,r){if(e.length!==t.length)throw new TypeError("x and y must have the same length");let n=ge(r.alternative),o=Pe(r.method),a=r.continuity??!1,[c,i]=ce(Array.from(e),Array.from(t)),s=c.length;if(o==="pearson"){let f=r.confLevel??.95;if(Ne(f),s<3)throw new Error("not enough finite observations");let h=H(c,i),E=s-2,v=Number.isNaN(h[0])?NaN:ve(h,E),k={method:"Pearson's product-moment correlation",alternative:n,statistic:v,statisticName:"t",parameter:E,parameterName:"df",pValue:ye(v,E,n),estimate:h[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation",warnings:Number.isNaN(h[0])&&(Se(c)||Se(i))?[se]:[]};if(s>3){let Z=Ke(h),O=1/Math.sqrt(s-3),D=_=>Math.tanh(Z+_),K;if(n==="less")K=[-1,D(O*j(f))];else if(n==="greater")K=[D(-O*j(f)),1];else{let _=(1-f)/2,b=O*(_<1e-8?j(_,{lowerTail:!1}):j((1+f)/2));K=[D(-b),D(b)]}k.confInt=K,k.confLevel=f}return R("corTest",k)}if(s<2)throw new Error("not enough finite observations");if(o==="kendall"){let f=X(c,i),h={method:"Kendall's rank correlation tau",alternative:n,estimate:f.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau",warnings:[]};if(Number.isNaN(f.tau))return R("corTest",{...h,statistic:NaN,statisticName:"T",pValue:NaN,warnings:[se]});let E=r.exact??s<50;if(E&&!f.ties){if(s>Ee)throw new RangeError(`the exact distribution of T for n = ${s} takes too long (at most ${Ee}): use exact: false`);let b=s*(s-1)/2,I=(f.s+b)/2,U=ke(s,I),Y=ke(s,b-I),Ce=n==="less"?U:n==="greater"?Y:Math.min(1,2*Math.min(U,Y));return R("corTest",{...h,statistic:I,statisticName:"T",pValue:Ce})}let v=(b,I)=>I.reduce((U,Y)=>U+b(Y),0),k=b=>b*(b-1),Z=b=>b*(b-1)*(b-2),O=b=>b*(b-1)*(2*b+5),D=(s*(s-1)*(2*s+5)-v(O,f.tx)-v(O,f.ty))/18+(s<3?0:v(Z,f.tx)*v(Z,f.ty)/(9*s*(s-1)*(s-2)))+v(k,f.tx)*v(k,f.ty)/(2*s*(s-1)),_=(a?Math.sign(f.s)*(Math.abs(f.s)-1):f.s)/Math.sqrt(D);return E&&(h.warnings=[Ae]),R("corTest",{...h,statistic:_,statisticName:"z",pValue:Ie(_,n)})}let l=te(c),u=te(i),m=H(l,u),d=s*s*s-s,w=d*(1-m[0])/6,g={method:"Spearman's rank correlation rho",alternative:n,statistic:w,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho",warnings:[]};if(Number.isNaN(m[0]))return R("corTest",{...g,pValue:NaN,warnings:[se]});let y=q(c).length>0||q(i).length>0;if(y&&(r.exact??!0)&&(g.warnings=[Ae]),(r.exact??s<=1290)&&!y&&s<=1290){let f=Math.round(w),h=Me(s,f,!0),E=Me(s,f,!1),v=n==="greater"?h:n==="less"?E:Math.min(1,2*Math.min(h,E));return R("corTest",{...g,pValue:v})}let p=m;if(a){let f=G([6,0],[d,0]);p=G(S(m,f),S([1,0],f)),Math.abs(p[0])>=1&&(p=[Math.sign(p[0]),0])}let N=ve(p,s-2);return s===2&&(g.warnings=[...g.warnings,Be]),R("corTest",{...g,pValue:ye(N,s-2,n)})}var se="the standard deviation is zero",Be="NaNs produced",Ae="Cannot compute exact p-value with ties";function Se(e){return Number.isFinite(e[0])&&e.every(t=>t===e[0])}var Ze=["tiesMethod","naLast"];function Ue(e,t){let r=e.length,n=new Array(r);if(t==="first"||t==="last"||t==="random"){let c=t==="random"?le(r):[],i=Array.from({length:r},(s,l)=>l);return i.sort((s,l)=>{let u=e[s]<e[l]?-1:e[s]>e[l]?1:0;return u!==0?u:t==="first"?s-l:t==="last"?l-s:c[s]-c[l]||s-l}),i.forEach((s,l)=>n[s]=l+1),n}let o=Array.from({length:r},(c,i)=>i).sort((c,i)=>e[c]-e[i]||c-i),a=0;for(;a<r;){let c=a;for(;c+1<r&&e[o[c+1]]===e[o[a]];)c++;let i=t==="average"?(a+c+2)/2:t==="min"?a+1:c+1;for(let s=a;s<=c;s++)n[o[s]]=i;a=c+1}return n}function J(e,t={}){M(t,Ze,"rank");let r=t.tiesMethod??"average";if(!["average","first","last","random","max","min"].includes(r))throw new RangeError(`invalid tiesMethod "${r}"`);let n=t.naLast??"last";if(n!=="last"&&n!=="first"&&n!=="keep")throw new RangeError(`invalid 'naLast': ${String(n)}`);let o=Array.from(e),a=o.filter(m=>!Number.isNaN(m)),c=Ue(a,r),i=o.length-a.length,s=[],l=0,u=0;for(let m of o)Number.isNaN(m)?(u++,s.push(n==="keep"?NaN:n==="last"?a.length+u:u)):s.push(n==="first"?c[l++]+i:c[l++]);return s}var Re=["method","use"],Ve=["method","use"],Ye=["pearson","kendall","spearman"],We=["all.obs","complete.obs","pairwise.complete.obs","everything","na.or.complete"];function _e(e,t,r,n){if(e===void 0)return r;if(t.includes(e))return e;let o=t.filter(a=>a.startsWith(e));if(e.length===0||o.length!==1)throw new RangeError(`invalid '${n}' argument`);return o[0]}function P(e){return e.length>0&&Array.isArray(e[0])}function Le(e){if(!P(e))return[Array.from(e)];let t=e[0].length;if(e.some(r=>!Array.isArray(r)||r.length!==t))throw new TypeError("all rows of the matrix must have the same length");return Array.from({length:t},(r,n)=>e.map(o=>o[n]))}function Q(e,t,r,n){let o=_e(r.method,Ye,"pearson","method"),a=_e(r.use,We,"everything","use");if(t===void 0&&!P(e))throw new TypeError("supply both 'x' and 'y' or a matrix-like 'x'");let c=Le(e),i=t===void 0?c:Le(t),s=c[0]?.length??0;if(i.some(p=>p.length!==s))throw new RangeError("incompatible dimensions");let l=[...c,...i];if(a==="all.obs"&&l.some(p=>p.some(Number.isNaN)))throw new RangeError("missing observations in cov/cor");if(!n&&a==="pairwise.complete.obs"&&o!=="pearson")throw new RangeError("cannot handle 'pairwise.complete.obs'");let u;if((a==="complete.obs"||a==="na.or.complete")&&(u=Array.from({length:s},(p,N)=>l.every(f=>!Number.isNaN(f[N]))),!u.some(Boolean))){if(a==="complete.obs")throw new RangeError("no complete element pairs");return t===void 0||P(e)||P(t)?c.map(()=>i.map(()=>NaN)):NaN}let m=p=>{let N=u===void 0?p:p.filter((f,h)=>u[h]);return o==="spearman"&&a!=="pairwise.complete.obs"?J(N,{naLast:"keep"}):N},d=c.map(m),w=t===void 0?d:i.map(m),g=(p,N)=>{let f=p,h=N;if(a==="pairwise.complete.obs"){let E=p.map((v,k)=>!Number.isNaN(v)&&!Number.isNaN(N[k]));f=p.filter((v,k)=>E[k]),h=N.filter((v,k)=>E[k]),o==="spearman"&&(f=J(f),h=J(h))}else if(f.some(Number.isNaN)||h.some(Number.isNaN))return NaN;return f.length<2?NaN:o==="kendall"?n?X(f,h).tau:2*X(f,h).s:n?H(f,h)[0]:ie(f,h)},y=d.map(p=>w.map(N=>g(p,N))),x=u===void 0?s:u.filter(Boolean).length;return n&&t===void 0&&a!=="pairwise.complete.obs"&&x>=2&&y.forEach((p,N)=>{Number.isNaN(p[N])||(p[N]=1)}),t!==void 0&&!P(e)&&!P(t)?y[0][0]:y}function Tt(e,t,r={}){return ne(t)&&M(t,Re,"cov"),M(r,Re,"cov"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!1):Q(e,t,r,!1)}function xt(e,t,r={}){return ne(t)&&M(t,Ve,"cor"),M(r,Ve,"cor"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!0):Q(e,t,r,!0)}export{De as a,Je as b,Qe as c,et as d,tt as e,rt as f,ge as g,Ne as h,st as i,ot as j,H as k,qe as l,J as m,Tt as n,xt as o};
|
|
1
|
+
/*! rStats.js 1.1.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{c as le}from"./chunk-Z2HGLFZN.js";import{a as ne}from"./chunk-7IJCUSA5.js";import{a as ue,g as fe}from"./chunk-U7BRXOUS.js";import{x as z}from"./chunk-GGJA3JRO.js";import{b as me,c as V}from"./chunk-GJEKNJP7.js";import{c as R}from"./chunk-N5BDSMXS.js";import{b as re}from"./chunk-EJYCDE4Z.js";import{r as L,s as j}from"./chunk-NDTJ23A6.js";import{A as ie,B as ee,J as te,K as q,M as ce,b as oe,c as ae,d as S,f as W,g as F,i as G,l as M}from"./chunk-HUWOSLKE.js";function B(e){if(e.kind==="factor")return me(e);let t=[...new Set(e.values)].sort((o,a)=>o-a),r=[...new Set(t.map(re))],n=new Map(r.map((o,a)=>[o,a]));return{levels:r,codes:e.values.map(o=>n.get(re(o)))}}function A(e,t){if(e.kind!=="numeric")throw new TypeError(`'${t}' must be a numeric column`);return e.values}function C(e,t){let r=ue(e),n=fe(r,Object.keys(t));return{terms:n,rhsVariables:n.variables.slice(n.response===0?1:0)}}function de(e){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");return t<0?void 0:{lhs:e.slice(0,t).trim(),rhs:e.slice(t+1)}}var Oe=/^Pair\s*\(\s*([A-Za-z.][A-Za-z0-9._]*)\s*,\s*([A-Za-z.][A-Za-z0-9._]*)\s*\)$/,$="'formula' missing or incorrect",pe=(e,t)=>t.length===0&&e.terms.length===0&&e.intercept;function De(e,t,r){let n=de(e),o=n===void 0?null:Oe.exec(n.lhs);if(o!==null){let{terms:m,rhsVariables:d}=C(`~${n.rhs}`,t);if(!r||!pe(m,d))throw new TypeError($);let w=V(t,[o[1],o[2]]);return{kind:"paired",x:A(w.variables[0],o[1]),y:A(w.variables[1],o[2])}}let{terms:a,rhsVariables:c}=C(e,t);if(a.response<0)throw new TypeError($);let i=a.variables[0];if(r&&pe(a,c))return{kind:"one",x:A(V(t,[i]).variables[0],i)};if(c.length!==1||a.terms.length!==1)throw new TypeError($);let s=V(t,[i,c[0]],{dropUnusedLevels:!0}),l=A(s.variables[0],i),u=B(s.variables[1]);if(u.levels.length!==2)throw new Error("grouping factor must have exactly 2 levels");return{kind:"two",x:l.filter((m,d)=>u.codes[d]===0),y:l.filter((m,d)=>u.codes[d]===1),levels:[u.levels[0],u.levels[1]]}}function Je(e,t){let r=De(e,t,!1);if(r.kind!=="two")throw new TypeError($);return r}function Qe(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0)throw new TypeError($);if(n.length!==1)throw new TypeError("'formula' should be of the form response ~ group");let o=r.variables[0],a=V(t,[o,n[0]],{dropUnusedLevels:!0});return{values:A(a.variables[0],o),group:B(a.variables[1])}}function et(e,t){let r=t.levels.map(()=>[]);return e.forEach((n,o)=>r[t.codes[o]].push(n)),r}function tt(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response<0||n.length===0)throw new TypeError($);let o=r.variables[0],a=V(t,[o,...n],{dropUnusedLevels:!0}),c=a.variables.slice(1).map(B),i=a.rows.map((s,l)=>{let u=0,m=1;for(let d of c)u+=d.codes[l]*m,m*=d.levels.length;return u});return{values:A(a.variables[0],o),groups:i}}var he="incorrect specification for 'formula'";function rt(e,t){let r=de(e),n=r?.rhs.split("|");if(r===void 0||r.lhs===""||n.length!==2)throw new TypeError(he);let o=y=>{let{terms:x,rhsVariables:p}=C(y,t);if(p.length!==1||x.terms.length!==1)throw new TypeError(he);return p[0]},{terms:a}=C(`${r.lhs} ~ 1`,t),c=a.variables[0],i=o(`~${n[0]}`),s=o(`~${n[1]}`),l=V(t,[c,i,s],{dropUnusedLevels:!0}),u=A(l.variables[0],c),m=B(l.variables[1]),d=B(l.variables[2]),w=d.levels.map(()=>m.levels.map(()=>NaN)),g=d.levels.map(()=>m.levels.map(()=>0));if(u.forEach((y,x)=>{let p=d.codes[x],N=m.codes[x];g[p][N]++,w[p][N]=y}),g.some(y=>y.some(x=>x!==1)))throw new Error("not an unreplicated complete block design");return w}function we(e,t){let{terms:r,rhsVariables:n}=C(e,t);if(r.response>=0)throw new TypeError("'formula' missing or invalid");if(n.length!==2)throw new TypeError("invalid formula");let o=V(t,n);return{x:A(o.variables[0],n[0]),y:A(o.variables[1],n[1])}}function ge(e){if(e===void 0)return"two.sided";let r=["two.sided","less","greater"].filter(n=>n.startsWith(e));if(e.length===0||r.length!==1)throw new RangeError(`invalid alternative "${e}" (expected "two.sided", "less" or "greater")`);return r[0]}function Ne(e){if(!(Number.isFinite(e)&&e>=0&&e<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function st(e){return Number.isFinite(e)&&e>=0&&Math.abs(e-Math.round(e))<=1e-7}function ot(e){if(!(Number.isFinite(e)&&e>0&&e<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var Fe=["alternative","exact","confLevel","continuity","method"],$e=["pearson","kendall","spearman"];function Pe(e){if(e===void 0)return"pearson";let t=$e.filter(r=>r.startsWith(e));if(e.length===0||t.length!==1)throw new RangeError(`invalid method "${e}"`);return t[0]}function be(e){if(!(e[0]>0))return[Math.sqrt(e[0]),0];let t=Math.sqrt(e[0]),r=W(e,ae(t,t));return oe(t,r[0]/(2*t))}function H(e,t){let r=e.length;if(r<2)return[NaN,0];let n=ee(e)?.d,o=ee(t)?.d;if(n===void 0||o===void 0)return[NaN,0];let a=[0,0],c=[0,0],i=[0,0];for(let l=0;l<r;l++)a=S(a,F(n[l],o[l])),c=S(c,F(n[l],n[l])),i=S(i,F(o[l],o[l]));if(c[0]===0||i[0]===0)return[NaN,0];let s=G(a,F(be(c),be(i)));return s[0]>=1?[1,0]:s[0]<=-1?[-1,0]:s}function ve(e,t){let r=F(W([1,0],e),S([1,0],e));return Math.sqrt(t)*e[0]/Math.sqrt(r[0])}function Ke(e){return Math.abs(e[0])<.5?Math.atanh(e[0]):.5*Math.log(S([1,0],e)[0]/W([1,0],e)[0])}function ye(e,t,r){return r==="less"?z(e,t,!0,!1):r==="greater"?z(e,t,!1,!1):2*Math.min(z(e,t,!0,!1),z(e,t,!1,!1))}function Ie(e,t){return t==="less"?L(e):t==="greater"?L(e,{lowerTail:!1}):2*Math.min(L(e),L(e,{lowerTail:!1}))}function X(e,t){let r=e.length,n=0;for(let u=0;u<r;u++){let m=e[u],d=t[u];for(let w=u+1;w<r;w++){let g=(e[w]>m?1:0)-(e[w]<m?1:0),y=(t[w]>d?1:0)-(t[w]<d?1:0);n+=g*y}}let o=q(e),a=q(t),c=r*(r-1)/2,i=o.reduce((u,m)=>u+m*(m-1)/2,0),s=a.reduce((u,m)=>u+m*(m-1)/2,0),l=r<2||i===c||s===c?NaN:i===0&&s===0?n/c:n/Math.sqrt((c-i)*(c-s));return{s:n,tau:l,ties:o.length>0||a.length>0,tx:o,ty:a}}var Ee=1290;function ke(e,t){let r=e*(e-1)/2;if(t<0)return 0;if(t>=r)return 1;let n=new Float64Array(t+1);n[0]=1;for(let a=2;a<=e;a++){let c=new Float64Array(t+1),i=0;for(let l=0;l<=t;l++)i+=n[l],c[l]=i;let s=new Float64Array(t+1);for(let l=0;l<=t;l++)s[l]=(c[l]-(l>=a?c[l-a]:0))/a;n=s}let o=0;for(let a=t;a>=0;a--)o+=n[a];return Math.min(1,o)}var Te=new Map;function je(e){let t=Te.get(e);if(t!==void 0)return t;let r=e*(e*e-1)/3,n=1<<e,o=new Array(n);o[0]=new Float64Array(r+1),o[0][0]=1;let a=i=>{let s=0;for(;i;i&=i-1)s++;return s};for(let i=0;i<n;i++){let s=o[i];if(s===void 0)continue;let l=a(i);for(let u=0;u<e;u++){if(i&1<<u)continue;let m=(u-l)**2,d=i|1<<u,w=o[d]??=new Float64Array(r+1);for(let g=0;g+m<=r;g++)s[g]&&(w[g+m]+=s[g])}i!==n-1&&(o[i]=void 0)}let c=o[n-1];return Te.set(e,c),c}var T=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function xe(e,t,r){let n=t;n%2!==0&&(n+=1);let o=1/e,a=(6*(n-1)*o/(e*e-1)-1)*Math.sqrt(1/o-1),c=a*a,s=a*o*(T[0]+o*(T[1]+T[2]*o)+c*(-T[3]+o*(T[4]+T[5]*o)-c*o*(T[6]+T[7]*o-c*(T[8]-T[9]*o+c*o*(T[10]-T[11]*c)))))/Math.exp(c/2),l=r?L(a)-s:s+L(a,{lowerTail:!1});return Math.min(1,Math.max(0,l))}function Me(e,t,r){let n=e*(e*e-1)/3;if(e<=9){let o=je(e),a=1;for(let i=2;i<=e;i++)a*=i;let c=0;if(r)for(let i=Math.min(t,n);i>=0;i--)c+=o[i];else for(let i=n;i>=Math.max(t,0);i--)c+=o[i];return c/a}return r?t+1>n?1:t+1<=0?0:xe(e,t+1,!0):t<=0?1:t>n?0:xe(e,t,!1)}function qe(e,t,r={}){if(M(r,Fe,"corTest"),typeof e=="string"){let n=we(e,t);return qe(n.x,n.y,r)}return ze(e,t,r)}function ze(e,t,r){if(e.length!==t.length)throw new TypeError("x and y must have the same length");let n=ge(r.alternative),o=Pe(r.method),a=r.continuity??!1,[c,i]=ce(Array.from(e),Array.from(t)),s=c.length;if(o==="pearson"){let f=r.confLevel??.95;if(Ne(f),s<3)throw new Error("not enough finite observations");let h=H(c,i),E=s-2,v=Number.isNaN(h[0])?NaN:ve(h,E),k={method:"Pearson's product-moment correlation",alternative:n,statistic:v,statisticName:"t",parameter:E,parameterName:"df",pValue:ye(v,E,n),estimate:h[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation",warnings:Number.isNaN(h[0])&&(Se(c)||Se(i))?[se]:[]};if(s>3){let Z=Ke(h),O=1/Math.sqrt(s-3),D=_=>Math.tanh(Z+_),K;if(n==="less")K=[-1,D(O*j(f))];else if(n==="greater")K=[D(-O*j(f)),1];else{let _=(1-f)/2,b=O*(_<1e-8?j(_,{lowerTail:!1}):j((1+f)/2));K=[D(-b),D(b)]}k.confInt=K,k.confLevel=f}return R("corTest",k)}if(s<2)throw new Error("not enough finite observations");if(o==="kendall"){let f=X(c,i),h={method:"Kendall's rank correlation tau",alternative:n,estimate:f.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau",warnings:[]};if(Number.isNaN(f.tau))return R("corTest",{...h,statistic:NaN,statisticName:"T",pValue:NaN,warnings:[se]});let E=r.exact??s<50;if(E&&!f.ties){if(s>Ee)throw new RangeError(`the exact distribution of T for n = ${s} takes too long (at most ${Ee}): use exact: false`);let b=s*(s-1)/2,I=(f.s+b)/2,U=ke(s,I),Y=ke(s,b-I),Ce=n==="less"?U:n==="greater"?Y:Math.min(1,2*Math.min(U,Y));return R("corTest",{...h,statistic:I,statisticName:"T",pValue:Ce})}let v=(b,I)=>I.reduce((U,Y)=>U+b(Y),0),k=b=>b*(b-1),Z=b=>b*(b-1)*(b-2),O=b=>b*(b-1)*(2*b+5),D=(s*(s-1)*(2*s+5)-v(O,f.tx)-v(O,f.ty))/18+(s<3?0:v(Z,f.tx)*v(Z,f.ty)/(9*s*(s-1)*(s-2)))+v(k,f.tx)*v(k,f.ty)/(2*s*(s-1)),_=(a?Math.sign(f.s)*(Math.abs(f.s)-1):f.s)/Math.sqrt(D);return E&&(h.warnings=[Ae]),R("corTest",{...h,statistic:_,statisticName:"z",pValue:Ie(_,n)})}let l=te(c),u=te(i),m=H(l,u),d=s*s*s-s,w=d*(1-m[0])/6,g={method:"Spearman's rank correlation rho",alternative:n,statistic:w,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho",warnings:[]};if(Number.isNaN(m[0]))return R("corTest",{...g,pValue:NaN,warnings:[se]});let y=q(c).length>0||q(i).length>0;if(y&&(r.exact??!0)&&(g.warnings=[Ae]),(r.exact??s<=1290)&&!y&&s<=1290){let f=Math.round(w),h=Me(s,f,!0),E=Me(s,f,!1),v=n==="greater"?h:n==="less"?E:Math.min(1,2*Math.min(h,E));return R("corTest",{...g,pValue:v})}let p=m;if(a){let f=G([6,0],[d,0]);p=G(S(m,f),S([1,0],f)),Math.abs(p[0])>=1&&(p=[Math.sign(p[0]),0])}let N=ve(p,s-2);return s===2&&(g.warnings=[...g.warnings,Be]),R("corTest",{...g,pValue:ye(N,s-2,n)})}var se="the standard deviation is zero",Be="NaNs produced",Ae="cannot compute exact p-value with ties";function Se(e){return Number.isFinite(e[0])&&e.every(t=>t===e[0])}var Ze=["tiesMethod","naLast"];function Ue(e,t){let r=e.length,n=new Array(r);if(t==="first"||t==="last"||t==="random"){let c=t==="random"?le(r):[],i=Array.from({length:r},(s,l)=>l);return i.sort((s,l)=>{let u=e[s]<e[l]?-1:e[s]>e[l]?1:0;return u!==0?u:t==="first"?s-l:t==="last"?l-s:c[s]-c[l]||s-l}),i.forEach((s,l)=>n[s]=l+1),n}let o=Array.from({length:r},(c,i)=>i).sort((c,i)=>e[c]-e[i]||c-i),a=0;for(;a<r;){let c=a;for(;c+1<r&&e[o[c+1]]===e[o[a]];)c++;let i=t==="average"?(a+c+2)/2:t==="min"?a+1:c+1;for(let s=a;s<=c;s++)n[o[s]]=i;a=c+1}return n}function J(e,t={}){M(t,Ze,"rank");let r=t.tiesMethod??"average";if(!["average","first","last","random","max","min"].includes(r))throw new RangeError(`invalid tiesMethod "${r}"`);let n=t.naLast??"last";if(n!=="last"&&n!=="first"&&n!=="keep")throw new RangeError(`invalid 'naLast': ${String(n)}`);let o=Array.from(e),a=o.filter(m=>!Number.isNaN(m)),c=Ue(a,r),i=o.length-a.length,s=[],l=0,u=0;for(let m of o)Number.isNaN(m)?(u++,s.push(n==="keep"?NaN:n==="last"?a.length+u:u)):s.push(n==="first"?c[l++]+i:c[l++]);return s}var Re=["method","use"],Ve=["method","use"],Ye=["pearson","kendall","spearman"],We=["all.obs","complete.obs","pairwise.complete.obs","everything","na.or.complete"];function _e(e,t,r,n){if(e===void 0)return r;if(t.includes(e))return e;let o=t.filter(a=>a.startsWith(e));if(e.length===0||o.length!==1)throw new RangeError(`invalid '${n}' argument`);return o[0]}function P(e){return e.length>0&&Array.isArray(e[0])}function Le(e){if(!P(e))return[Array.from(e)];let t=e[0].length;if(e.some(r=>!Array.isArray(r)||r.length!==t))throw new TypeError("all rows of the matrix must have the same length");return Array.from({length:t},(r,n)=>e.map(o=>o[n]))}function Q(e,t,r,n){let o=_e(r.method,Ye,"pearson","method"),a=_e(r.use,We,"everything","use");if(t===void 0&&!P(e))throw new TypeError("supply both 'x' and 'y' or a matrix-like 'x'");let c=Le(e),i=t===void 0?c:Le(t),s=c[0]?.length??0;if(i.some(p=>p.length!==s))throw new RangeError("incompatible dimensions");let l=[...c,...i];if(a==="all.obs"&&l.some(p=>p.some(Number.isNaN)))throw new RangeError("missing observations in cov/cor");if(!n&&a==="pairwise.complete.obs"&&o!=="pearson")throw new RangeError("cannot handle 'pairwise.complete.obs'");let u;if((a==="complete.obs"||a==="na.or.complete")&&(u=Array.from({length:s},(p,N)=>l.every(f=>!Number.isNaN(f[N]))),!u.some(Boolean))){if(a==="complete.obs")throw new RangeError("no complete element pairs");return t===void 0||P(e)||P(t)?c.map(()=>i.map(()=>NaN)):NaN}let m=p=>{let N=u===void 0?p:p.filter((f,h)=>u[h]);return o==="spearman"&&a!=="pairwise.complete.obs"?J(N,{naLast:"keep"}):N},d=c.map(m),w=t===void 0?d:i.map(m),g=(p,N)=>{let f=p,h=N;if(a==="pairwise.complete.obs"){let E=p.map((v,k)=>!Number.isNaN(v)&&!Number.isNaN(N[k]));f=p.filter((v,k)=>E[k]),h=N.filter((v,k)=>E[k]),o==="spearman"&&(f=J(f),h=J(h))}else if(f.some(Number.isNaN)||h.some(Number.isNaN))return NaN;return f.length<2?NaN:o==="kendall"?n?X(f,h).tau:2*X(f,h).s:n?H(f,h)[0]:ie(f,h)},y=d.map(p=>w.map(N=>g(p,N))),x=u===void 0?s:u.filter(Boolean).length;return n&&t===void 0&&a!=="pairwise.complete.obs"&&x>=2&&y.forEach((p,N)=>{Number.isNaN(p[N])||(p[N]=1)}),t!==void 0&&!P(e)&&!P(t)?y[0][0]:y}function Tt(e,t,r={}){return ne(t)&&M(t,Re,"cov"),M(r,Re,"cov"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!1):Q(e,t,r,!1)}function xt(e,t,r={}){return ne(t)&&M(t,Ve,"cor"),M(r,Ve,"cor"),t!==void 0&&!Array.isArray(t)&&!ArrayBuffer.isView(t)?Q(e,void 0,t,!0):Q(e,t,r,!0)}export{De as a,Je as b,Qe as c,et as d,tt as e,rt as f,ge as g,Ne as h,st as i,ot as j,H as k,qe as l,J as m,Tt as n,xt as o};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{B as R,a as S,c as y,e as I,f as O,h as U,j as A,q as K,u as j,v as E,y as P}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.1.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{B as R,a as S,c as y,e as I,f as O,h as U,j as A,q as K,u as j,v as E,y as P}from"./chunk-GYGQUYEP.js";import{a as q,c as z}from"./chunk-OG7UORIX.js";import{l as x,u as w}from"./chunk-HUWOSLKE.js";var _=["exact","norm","method","triangular","uplo"],$=["tol"];function Z(f,r={}){x(r,_,"kappa");let o=y(f),h=o;if(o.data.every(Number.isFinite)){let i=U(o.data),n=i===0?void 0:{...o,data:o.data.map(c=>w(c,-i))};n!==void 0&&n.data.every((c,u)=>c===0?o.data[u]===0:Math.abs(c)>=2**-1022)&&(h=n)}let l=h===o?f:I(h);if(r.exact){let i=r.norm===void 0?"2":G(r.norm);if(i==="2"){let c=j(f,{nu:0,nv:0}).d,u=z(c);return u===0?1/0:q(c)/u}let n;try{n=P(l)}catch(c){if(c instanceof Error&&c.message.startsWith("the system is exactly singular"))return 1/0;throw c}return E(l,{type:i})*E(n,{type:i})}let M=r.norm==="I"?"I":"O";if((r.method??"qr")==="direct"){if(r.triangular)return 1/C(h,(r.uplo??"U")==="U",M);let i=r.norm??"O",n=i.toUpperCase();if(n!=="1"&&n!=="O"&&n!=="I")throw new RangeError(`argument type[1]='${i}' must be one of '1','O', or 'I'`);return 1/R(f,{norm:n==="I"?"I":"O"})}let p=h.nrow<h.ncol?I(O(h)):l;return 1/C(y(K(A(p))),!0,M)}function C(f,r,o){return L(o==="I"?O(f):f,r)}function G(f){let r=f.toUpperCase();if(r==="1"||r==="O")return"O";if(r==="E")return"F";if(r==="I"||r==="F"||r==="M"||r==="2")return r;throw new RangeError(`invalid norm "${f}"`)}function L(f,r){let o=Math.min(f.nrow,f.ncol),h=f.nrow,l=(a,t)=>f.data[a+t*h],M=!r,p=0;for(let a=0;a<o;a++){let[t,m]=M?[a,o-a]:[0,a+1],e=0;for(let s=t;s<t+m;s++)e+=Math.abs(l(s,a));p=Math.max(p,e)}let i=1,n=new Float64Array(o),c=a=>{for(let t=0;t<o;t++)n[t]*=a};for(let a=0;a<o;a++){let t=M?o-1-a:a,m=l(t,t);if(n[t]!==0&&(i=n[t]>0?-Math.abs(i):Math.abs(i)),Math.abs(i-n[t])>Math.abs(m)){let k=Math.abs(m)/Math.abs(i-n[t]);c(k),i*=k}let e=i-n[t],s=-i-n[t],d=Math.abs(e),N=Math.abs(s);if(m!==0?(e/=m,s/=m):(e=1,s=1),a!==o-1){let[k,F]=M?[0,t-1]:[t+1,o-1];for(let b=k;b<=F;b++)N+=Math.abs(n[b]+s*l(t,b)),n[b]+=e*l(t,b),d+=Math.abs(n[b]);if(d<N){let b=s-e;e=s;for(let v=k;v<=F;v++)n[v]+=b*l(t,v)}}n[t]=e}c(1/Y(n));let u=1;for(let a=0;a<o;a++){let t=M?a:o-1-a,m=l(t,t);if(Math.abs(n[t])>Math.abs(m)){let e=Math.abs(m)/Math.abs(n[t]);c(e),u*=e}if(m!==0?n[t]/=m:n[t]=1,a<o-1){let e=-n[t];if(M)for(let s=t+1;s<o;s++)n[s]+=e*l(s,t);else for(let s=0;s<t;s++)n[s]+=e*l(s,t)}}let g=1/Y(n);return c(g),u*=g,p!==0?u/p:0}function Y(f){let r=0;for(let o of f)r+=Math.abs(o);return r}function T(f,r={}){x(r,$,"ginv");let o=r.tol??Math.sqrt(Number.EPSILON),h=y(f),{d:l,u:M,v:p,s:i}=j(f),n=h.nrow,c=h.ncol,u=S(c,n),g=Math.max(o*(l[0]??0),0),a=[];for(let t=0;t<l.length;t++){if(!(l[t]>g))continue;let m=1/l[t];if(!Number.isFinite(m)){a.push([t,1/w(l[t],600)]);continue}for(let e=0;e<n;e++){let s=M[e][t]*m;for(let d=0;d<c;d++)u.data[d+e*c]+=p[d][t]*s}}i!==0&&(u.data=u.data.map(t=>w(t,-i)));for(let[t,m]of a)for(let e=0;e<n;e++){let s=M[e][t]*m;for(let d=0;d<c;d++)u.data[d+e*c]+=w(p[d][t]*s,600-i)}return I(u)}export{Z as a,T as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{f as N,i as b,j as a}from"./chunk-
|
|
1
|
+
/*! rStats.js 1.1.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{f as N,i as b,j as a}from"./chunk-QUTJEYDX.js";import{f as l}from"./chunk-NDTJ23A6.js";import{d as f,h as m,k as c,l as u}from"./chunk-HUWOSLKE.js";function o(n,t){if(!Number.isFinite(n)||n<0)throw new RangeError("n must be a non-negative finite number");let e=Math.trunc(n),r=new Array(e);for(let i=0;i<e;i++)r[i]=t();return r}function h(n,t){let e=1;if(Number.isNaN(n))return n;if(t!==0){if(!Number.isFinite(n))return Math.pow(n,t);for(t<0&&(t=-t,n=1/n);t&1&&(e*=n),t>>=1,t;)n*=n}return e}var p=["min","max"],d=["mean","sd"],g=["rate"],R=["meanlog","sdlog"],E=["location","scale"],M=["location","scale"],x=["scale"];function y(n,t={}){u(t,p,"runif");let{min:e=0,max:r=1}=t;return o(n,()=>{if(!Number.isFinite(e)||!Number.isFinite(r)||r<e)return NaN;if(e===r)return e;let i=N();return Number.isFinite(r-e)?e+(r-e)*i:e*(1-i)+r*i})}function F(n,t){if(Number.isNaN(n)||!Number.isFinite(t)||t<0)return NaN;if(t===0||!Number.isFinite(n))return n;let e=b(),r=n+t*e;return Number.isFinite(r)?r:2*(n/2+t/2*e)}function L(n,t={}){u(t,d,"rnorm");let{mean:e=0,sd:r=1}=t;return o(n,()=>F(e,r))}function O(n,t={}){u(t,g,"rexp");let e=t.rate??1,r=1/e;return o(n,()=>r===1/0&&e>0?a()/e:!Number.isFinite(r)||r<=0?r===0?0:NaN:r*a())}function A(n,t={}){u(t,R,"rlnorm");let{meanlog:e=0,sdlog:r=1}=t;return o(n,()=>Number.isNaN(e)||!Number.isFinite(r)||r<0?NaN:Math.exp(F(e,r)))}function U(n,t={}){u(t,E,"rlogis");let{location:e=0,scale:r=1}=t;return o(n,()=>{if(Number.isNaN(e)||!Number.isFinite(r))return NaN;if(r<0)return N(),NaN;if(r===0||!Number.isFinite(e))return e;let i=N();return e+r*Math.log(i/(1-i))})}function k(n,t={}){u(t,M,"rcauchy");let{location:e=0,scale:r=1}=t;return o(n,()=>Number.isNaN(e)||!Number.isFinite(r)||r<0?NaN:r===0||!Number.isFinite(e)?e:e+r*Math.tan(Math.PI*N()))}function C(n,t,e={}){u(e,x,"rweibull");let{scale:r=1}=e;return o(n,()=>{if(!(t>0)||!(r>=0))return NaN;if(!Number.isFinite(t)||!Number.isFinite(r)||r===0)return r===0?0:NaN;let i=-Math.log(N()),s=Math.pow(i,1/t);return s!==1/0?r*s:l(f(c([r,0]),m(c([i,0]),1/t)))[0]})}export{o as a,h as b,y as c,F as d,L as e,O as f,A as g,U as h,k as i,C as j};
|
package/dist/descriptive.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! rStats.js 1.
|
|
2
|
-
import{m as ke,n as Fe,o as Te}from"./chunks/chunk-YHNMBYSW.js";import"./chunks/chunk-DCAWMF4K.js";import{A as De,B as Qe,C as Ze,D as Ge,E as Je,F as Xe,a as Z,b as W,c as G,d as F,e as fe,f as Se,g as _e,j as Ie,k as je,l as me,m as Ce,n as Le,o as Pe,p as Ve,q as Ue,r as z,s as j,t as C,u as qe,v as Ye,w as Ke,x as We,y as ze,z as Be}from"./chunks/chunk-QQX46TCI.js";import{a as he,b as He,c as en,d as nn,e as tn,f as rn}from"./chunks/chunk-QZK3CCBA.js";import"./chunks/chunk-UKNDX4BA.js";import"./chunks/chunk-BQSIBJVX.js";import{a as ae,e as K,f as ie}from"./chunks/chunk-LROMWFAK.js";import"./chunks/chunk-YG5S5AVP.js";import{a as ue}from"./chunks/chunk-4OLDGML4.js";import{b as le}from"./chunks/chunk-NSWENS3S.js";import{b as Y,d as ce}from"./chunks/chunk-BWKHYRM6.js";import{b as q,c as se}from"./chunks/chunk-CKV4JWW2.js";import"./chunks/chunk-WWVMVZUL.js";import{P as Q,l as S,u as V}from"./chunks/chunk-63OPBEYO.js";var on=["type","naRm"],sn=["type","naRm"],ln=["center","constant","low","high","naRm"],J=4*Number.EPSILON,an={4:[0,1],5:[.5,.5],6:[0,0],8:[1/3,1/3],9:[3/8,3/8]};function cn(e,n,t){let r=e.length,o=i=>e[Math.min(Math.max(i,1),r)-1];if(t===7){let i=1+(r-1)*n,m=Math.floor(i),c=o(m),p=o(Math.ceil(i));if(i>m&&p!==c){let h=i-m;return(1-h)*c+h*p}return c}let a,s;if(t<=3){let i=t===3?r*n-.5:r*n;a=Math.floor(i*(1+J)),t===1?s=i>a?1:0:t===2?s=i>a?1:.5:s=i!==a||Math.abs(a%2)===1?1:0}else{let[i,m]=an[t],c=i+n*(r+1-i-m);a=Math.floor(c*(1+J)),s=c-a,Math.abs(s)<J&&(s=0)}let l=o(a),f=o(a+1);return s===1?f:s>0&&s<1&&l!==f?(1-s)*l+s*f:l}function B(e,n=[0,.25,.5,.75,1],t={}){S(t,on,"quantile");let r=t.type??7;if(!(Number.isInteger(r)&&r>=1&&r<=9))throw new RangeError("'type' must be an integer in 1..9");let o=me(e,t.naRm);if(o===void 0)throw new RangeError("missing values and NaN's not allowed if 'na.rm' is FALSE");let a=o.sort((i,m)=>i-m),s=typeof n=="number"?[n]:Array.from(n),l=100*Number.EPSILON;if(s.some(i=>i<-l||i>1+l))throw new RangeError("'probs' outside [0,1]");let f=s.map(i=>Number.isNaN(i)||a.length===0?NaN:cn(a,Math.min(Math.max(i,0),1),r));return typeof n=="number"?f[0]:f}function X(e,n={}){S(n,sn,"IQR");let[t,r]=B(e,[.25,.75],n);return r-t}function un(e){let n=Array.from(e).filter(a=>!Number.isNaN(a)).sort((a,s)=>a-s),t=n.length;if(t===0)return[NaN,NaN,NaN,NaN,NaN];let r=Math.floor((t+3)/2)/2;return[1,r,(t+1)/2,t+1-r,t].map(a=>q(n[Math.floor(a)-1],n[Math.ceil(a)-1]))}function fn(e,n={}){S(n,ln,"mad");let t=Array.from(e),r=t.filter(c=>!Number.isNaN(c)),o=n.naRm?r:t,a=n.center??(o.length>r.length?NaN:j(r)),s=n.constant??1.4826,l=n.low??!1,f=n.high??!1,i=o.map(c=>Math.abs(c-a)),m=i.length;if((l||f)&&m%2===0){if(l&&f)throw new RangeError("'low' and 'high' cannot be both TRUE");let c=m/2+(f?1:0),p=i.filter(h=>!Number.isNaN(h)).sort((h,N)=>h-N);if(c===0||p.length<c)throw new RangeError(`'partial' index ${c} outside bounds`);return s*p[c-1]}return s*j(i)}var pe=e=>e===null||typeof e=="number"&&Number.isNaN(e),ge=e=>Array.isArray(e)||ArrayBuffer.isView(e);function mn(e){if(ge(e))return{columns:[e],rows:e.length};if(typeof e!="object"||e===null)throw new TypeError("the arguments must be arrays or data frames");let n=Object.values(e),t=n[0]?.length??0;if(n.some(r=>r.length!==t))throw new RangeError("not all arguments have the same length");return{columns:n,rows:t}}function de(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(mn),t=n[0].rows;if(n.some(o=>o.rows!==t))throw new RangeError("not all arguments have the same length");let r=n.flatMap(o=>o.columns);return Array.from({length:t},(o,a)=>r.every(s=>!pe(s[a])))}function hn(e){if(ge(e))return Array.from(e).filter(r=>!pe(r));let n=de(e),t={};for(let[r,o]of Object.entries(e)){let a=Array.from(o).filter((s,l)=>n[l]);F(t,r,o instanceof Float64Array?Float64Array.from(a):a)}return t}var pn=["breaks","right","includeLowest"],gn=["n","minN","shrinkSml","highUBias","u5Bias"];function we(e,n={}){S(n,gn,"pretty");let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5;if(Number.isNaN(r)||Math.abs(r)>=2**31||Math.trunc(r)<0)throw new RangeError("invalid 'n' argument");let o=Math.trunc(r),a=n.minN??Math.floor(r/3);if(Number.isNaN(a)||Math.trunc(a)<0||Math.trunc(a)>o)throw new RangeError("invalid 'min.n' argument");let s=Math.trunc(a),l=n.shrinkSml??.75;if(!Number.isFinite(l)||l<=0)throw new RangeError("invalid 'shrink.sml' argument");let f=n.highUBias??1.5;if(!Number.isFinite(f)||f<0)throw new RangeError("invalid 'high.u.bias' argument");let i=n.u5Bias??.5+1.5*f;if(!Number.isFinite(i)||i<0)throw new RangeError("invalid 'u5.bias' argument");let m=1/0,c=-1/0;for(let R of t)R<m&&(m=R),R>c&&(c=R);let p=c-m,h,N;if(p===0&&c===0)h=1,N=!0;else{h=Math.max(Math.abs(m),Math.abs(c));let $=(1+(i>=1.5*f+.5?1/(1+f):1.5/(1+i)))*Math.max(1,o)*Number.EPSILON;N=p<h*$*3}N?(h>10&&(h=9+h/10),h*=l,s>1&&(h/=s)):(h=o>1?p/o:p,p===1/0&&o>=2&&(h=c/o-m/o));let E=2**-20*dn;h<E?h=E:h>Number.MAX_VALUE/1.25&&(h=Number.MAX_VALUE/1.25);let M=10**Math.floor(Math.log10(h)),g=[[2*M,f],[5*M,i],[10*M,f]],y=M;for(let[R,$]of g)if(R-h<$*(h-y))y=R;else break;let d=1e-10,w=Math.floor(m/y+d);for(;w*y>m+d*y;)w--;for(;!Number.isFinite(w*y);)w++;let x=Math.ceil(c/y-d);for(;x*y<c-d*y;)x++;for(;!Number.isFinite(x*y);)x--;let u=Math.trunc(.5+x-w);if(u<s){let R=s-u,$=Math.floor(R/2),k=R%2;m===0&&w===0&&c!==0?x+=R:c===0&&x===0&&m!==0?w-=R:w>=0?(x+=$,w-=$+k):(w-=$,x+=$+k),u=s}let b=w*y<m?w*y:m,v=x*y>c?x*y:c;if(u<=0)return[b];let O=he(b,v,u+1),A=v/u-b/u;return O.map(R=>Math.abs(R)<1e-14*A?0:R)}var dn=22250738585072014e-324;function wn(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function yn(e,n){let t=e.length;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let r=l=>[C(l),3.5*z(l)*t**-.3333333333333333],[[o,a],s]=r(e);return Number.isFinite(a-o)&&Number.isFinite(s)||([[o,a],s]=r(Q([e]).groups[0])),s>0?Math.max(1,Math.ceil((a-o)/s)):1}case"fd":case"freedman-diaconis":{let r=(f,i)=>{let m=2*X(i);for(let c=.125;m===0&&c>=.001953125;c/=2){let[p,h]=B(i,[c,1-c]);m=(h-p)/(1-2*c)}return m===0&&(m=3.5*z(f)),[C(f),m]},o=e.map(wn),[[a,s],l]=r(e,o);if(!(Number.isFinite(s-a)&&Number.isFinite(l))){let{k:f}=Q([e]);[[a,s],l]=r(e.map(i=>V(i,-f)),o.map(i=>V(i,-f)))}return l>0?Math.ceil((s-a)/l*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function bn(e,n,t){let r=e.slice(1).map((o,a)=>o-e[a]);return e.length>5?1e-7*j(r):e.length<=3?t-n===1/0?2*(1e-7*(t/2-n/2)):1e-7*(t-n):1e-7*se(r.filter(o=>o>0))}function Nn(e,n={}){S(n,pn,"hist");let t=Array.from(e).filter(Number.isFinite),r=t.length,o=n.right??!0,a=n.includeLowest??!0,s=n.breaks??"Sturges",l;if(typeof s!="string"&&typeof s!="number"&&s.length>1){if(!s.every(Number.isFinite))throw new RangeError("'breaks' are not finite");if(l=[...s].sort((g,y)=>g-y),l.some((g,y)=>y>0&&!(g>l[y-1])))throw new RangeError("'breaks' are not strictly increasing")}else{a=!0;let g=typeof s=="string"?yn(t,s):typeof s=="number"?s:s[0];if(!Number.isFinite(g)||g<1)throw new RangeError("invalid number of 'breaks'");g=Math.min(g,1e6);let[y,d]=C(t);l=we([y,d],{n:g,minN:1});for(let w=1;w<l.length;w++)if(!(l[w]-l[w-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let f=l.length,[i,m]=r>0?C(t):[0,0],c=bn(l,i,m),p=l.map((g,y)=>o?y===0&&a?g-c:g+c:y<f-1?g-c:a?g+c:g-c),h=new Array(Math.max(0,f-1)).fill(0),N=0;for(let g of t){let y=xn(g,p,o,a);y>=0&&(h[y]++,N++)}if(N<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let E=h.map((g,y)=>En(g,r,l[y],l[y+1])),M=h.map((g,y)=>q(l[y+1],l[y]));return{breaks:l,counts:h,density:E,mids:M}}function En(e,n,t,r){let o=r-t;if(!(n*o===1/0&&Number.isFinite(t)&&Number.isFinite(r)))return e/(n*o);let a=o===1/0?1:0,s=a===1?r/2-t/2:o,l=Math.floor(Math.log2(s));return V(e,-(l+a))/(n*V(s,-l))}function xn(e,n,t,r){let o=n.length-1;if(o<1)return-1;if(t){if(e===n[0]&&r)return 0;if(!(e>n[0]&&e<=n[o]))return-1;let l=1,f=o;for(;l<f;){let i=Math.floor((l+f)/2);e<=n[i]?f=i:l=i+1}return l-1}if(e===n[o]&&r)return o-1;if(!(e>=n[0]&&e<n[o]))return-1;let a=0,s=o-1;for(;a<s;){let l=Math.floor((a+s+1)/2);n[l]<=e?a=l:s=l-1}return a}function Rn(e){let n=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,o)=>r-o),t=n.length;if(t<1)throw new RangeError("'x' must have 1 or more non-missing values");return r=>{if(Number.isNaN(r))return NaN;let o=0,a=t;for(;o<a;){let s=Math.floor((o+a)/2);n[s]<=r?o=s+1:a=s}return o/t}}var vn=["drop","sep"],D=e=>e===null||typeof e=="number"&&Number.isNaN(e),$n=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?ue(e,n):Number(e)-Number(n),An=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?Y(e):e>0?"Inf":"-Inf";function Mn(e,n){let t=ce(n),r=new Set(t.filter(l=>!D(l)).map(l=>typeof l));if(r.size>1)throw new TypeError(`${e} mixes ${[...r].join(" and ")} labels`);let o=[...r][0];if(o!==void 0&&o!=="number"&&o!=="string"&&o!=="boolean")throw new TypeError(`${e} has labels of an unsupported type`);let a=[...new Set(t.filter(l=>!D(l)))].sort($n),s=new Map(a.map((l,f)=>[l,f]));return{levels:a,codes:t.map(l=>D(l)?-1:s.get(l))}}var L=e=>Array.isArray(e)||e instanceof Float64Array;function Ee(e){if(e instanceof Float64Array)return[e];if(!Array.isArray(e))throw new TypeError("the group labels must be an array or an array of arrays");if(e.length>0&&e.every(L))return[...e];if(e.some(L))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function H(e,n,t){e.forEach((s,l)=>{if(s.length!==t)throw new RangeError(`${n[l]} must have one label per row (${t}), not ${s.length}`)});let r=e.map((s,l)=>Mn(n[l],s)),o=r.reduce((s,l)=>s*l.levels.length,1);if(o>=2**31)throw new RangeError("total number of levels >= 2^31");let a=new Array(t);for(let s=0;s<t;s++){let l=0,f=1;for(let i of r){let m=i.codes[s];if(m<0){l=-1;break}l+=m*f,f*=i.levels.length}a[s]=l}return{factors:r,size:o,cells:a}}function ee(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function On(e,n){return e.factors.map(t=>{let r=t.levels.length,o=t.levels[n%r];return n=Math.floor(n/r),o})}var xe=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function kn(e,n,t){let r=Array.from(e),o=Ee(n),a=H(o,xe(o.length,"index"),r.length),s=ee(a).map(i=>i.length===0?null:{value:t(i.map(m=>r[m]))}),f=s.every(i=>i===null||typeof i.value=="number")?s.map(i=>i===null?NaN:i.value):s.map(i=>i===null?null:i.value);return{dim:a.factors.map(i=>i.levels.length),dimnames:a.factors.map(i=>[...i.levels]),values:f}}function Fn(e,n){let t={};for(let[r,o]of Object.entries(e))F(t,r,o instanceof Float64Array?Float64Array.from(n,a=>o[a]):n.map(a=>o[a]));return t}function Tn(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!L(o))throw new TypeError(`column '${r}' must be an array`);if(o.length!==t)throw new RangeError(`the columns of the data frame have different lengths (found for '${r}')`)}return t}function Sn(e,n,t={}){S(t,vn,"split");let r=t.sep??".",o=Ee(n),a=!L(e);if(a&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let s=a?Tn(e):e.length,l=H(o,xe(o.length,"f"),s),f=a?[]:Array.from(e),i=new Map;return ee(l).forEach((m,c)=>{if(m.length===0&&(t.drop||l.factors.length===1))return;let p=On(l,c).map(An).join(r);if(i.has(p))throw new RangeError(`the group names joined with '${r}' are not unique ('${p}'); use another sep`);i.set(p,a?Fn(e,m):m.map(h=>f[h]))}),i}function ye(e,n){if(n===void 0)throw new RangeError(`object '${e}' not found`);if(!L(n))throw new TypeError(`column '${e}' must be an array`);return Array.from(n,t=>{if(t===null)return NaN;if(typeof t!="number")throw new TypeError(`column '${e}' to summarise must be numeric`);return t})}function be(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new RangeError(`object '${n}' not found`);if(!L(t))throw new TypeError(`column '${n}' must be an array`);return t}function _n(e,n){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");if(t<0)throw new SyntaxError("invalid formula: missing '~'");let r=e.slice(0,t).trim(),{rhs:o}=ae(`~ ${e.slice(t+1)}`),a=/^[A-Za-z.][A-Za-z0-9._]*$/,s;if(r!=="."){let i=/^cbind\s*\((.*)\)$/s.exec(r);if(s=i===null?[r]:i[1].split(",").map(m=>m.trim()),s.some(m=>!a.test(m)||m==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}else if(K(o,[]).length<K(o,["."]).length)throw new SyntaxError("invalid formula: '.' cannot be on both sides");let l=s===void 0?[]:n.filter(i=>!s.includes(i)),f=K(o,l);return ie(o,()=>0,l),{values:s??n.filter(i=>!f.includes(i)),groups:f}}function Ne(e,n,t,r,o,a){let s=r[0]?.length??n[0]?.length??0;e.forEach((c,p)=>{if(n[p].length!==s)throw new RangeError(`variable lengths differ (found for '${c}')`)});let l=H(r,t,s),f=ee(l).map((c,p)=>({cell:p,rows:c.filter(o)})).filter(c=>c.rows.length>0),i={};t.forEach((c,p)=>{let h=r[p];F(i,c,f.map(N=>{let E=h[N.rows[0]];return E===0?0:E}))});let m=(c,p)=>{if(Object.hasOwn(i,c))throw new RangeError(`duplicate column name '${c}' in the result`);F(i,c,p)};return e.forEach((c,p)=>{let h=n[p],E=f.map(g=>a(g.rows.map(y=>h[y]))).map(g=>{if(typeof g=="number")return{names:void 0,values:[g]};if(Array.isArray(g))return{names:void 0,values:[...g]};let y=g;return{names:Object.keys(y),values:Object.values(y)}}),M=E[0]?.values.length??1;if(E.some(g=>g.values.length!==M))throw new RangeError("fun must return values of the same length for every group");if(M===1&&E[0]?.names===void 0){m(c,E.map(g=>g.values[0]));return}for(let g=0;g<M;g++){let y=E[0].names?.[g]??String(g+1);m(`${c}.${y}`,E.map(d=>d.values[g]))}}),i}function In(e,n,t){if(typeof n!="object"||n===null)throw new TypeError("the data must be an object of columns");if(typeof e=="string"){let l=n,{values:f,groups:i}=_n(e,Object.keys(l)),m=N=>Object.prototype.hasOwnProperty.call(l,N),c=f.map(N=>ye(N,m(N)?l[N]:void 0)),p=i.map(N=>be(l,N));return Ne(f,c,i,p,N=>c.every(E=>!Number.isNaN(E[N]))&&p.every(E=>!D(E[N])),t)}if(typeof e!="object"||e===null)throw new TypeError("x must be a data frame");let r=Object.keys(e),o=r.map(l=>ye(l,e[l])),a=Object.keys(n);if(a.length===0)throw new RangeError("'by' must name at least one grouping column");let s=a.map(l=>be(n,l));return Ne(r,o,a,s,()=>!0,t)}var jn=new Set(["cols","namesTo","namesPrefix","namesSep","namesPattern","namesTransform","valuesTo","valuesDropNa","colsVary","onWarning"]),Cn=new Set(["namesFrom","valuesFrom","idCols","namesPrefix","namesSep","namesSort","namesVary","valuesFill","valuesFn"]),te=e=>typeof e=="string"?[e]:[...e];function Ae(e,n){if(n==null)return"fastest";if(n==="fastest"||n==="slowest")return n;throw typeof n!="string"?new TypeError(`\`${e}\` must be a string or character vector.`):new RangeError(`\`${e}\` must be one of "fastest" or "slowest", not "${n}".`)}function re(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new RangeError(`Column \`${t}\` doesn't exist.`)}function Me(e,n){if(n instanceof Float64Array)return"double";let t=null;for(let r of n){if(r===null)continue;let o=typeof r=="number"?"double":typeof r=="string"?"character":"logical";if(t!==null&&o!==t)throw new TypeError(`column '${e}' mixes ${t} and ${o} values`);t=o}return t}function Ln(e,n){let t=null;for(let r of n){let o=Me(r,e[r]);if(o!==null){if(t===null)t={type:o,column:r};else if(t.type!==o){if(t.type==="character"||o==="character")throw new TypeError(`Can't combine \`${t.column}\` <${t.type}> and \`${r}\` <${o}>.`);o==="double"&&(t={type:o,column:r})}}}return t?.type??null}function Re(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new TypeError(`\`regex\` should define ${t} groups; ${r} found.`);let o=new RegExp(n);return e.map(a=>{let s=o.exec(a);return Array.from({length:t},(l,f)=>s===null?null:s[f+1]??null)})}function Pn(e,n){let t=e.charCodeAt(n);if(t>=55296&&t<=56319&&n+1<e.length){let r=e.charCodeAt(n+1);if(r>=56320&&r<=57343)return 2}return 1}function Vn(e,n,t,r){let o=new RegExp(n,"g"),a=[],s=[],l=e.map((i,m)=>{let c=[],p=0,h=0;for(;;){o.lastIndex=p;let N=o.exec(i);if(N===null||(c.push(i.slice(h,N.index)),h=N.index+N[0].length,p=N[0].length===0?N.index+Pn(i,N.index):h,p>=i.length))break}return c.push(i.slice(h)),c.length>t&&a.push(m+1),c.length<t&&s.push(m+1),Array.from({length:t},(N,E)=>c[E]??null)}),f=i=>`${i.length} rows [${i.join(", ")}]`;return a.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${f(a)}.`),s.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${f(s)}.`),l}function ve(e,n){return e!==void 0&&Object.hasOwn(e,n)?e[n]:void 0}function Un(e,n,t,r){let{namesSep:o,namesPattern:a}=t;if(n.length===0)return e.map(()=>[]);if(n.length===1){if(o!==void 0)throw new TypeError("`names_sep` can't be used with a length 1 `names_to`.");return a===void 0?e.map(s=>[s]):Re(e,a,1)}if(o===void 0==(a===void 0))throw new TypeError("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?Vn(e,o,n.length,r):Re(e,a,n.length)}function qn(e,n){S(n,jn,"pivotLonger");let t=Ae("cols_vary",n.colsVary),r=Z(e),o=Object.keys(e),a=typeof n.cols=="function"?o.filter(n.cols):[...new Set(n.cols)];if(re(e,a),a.length===0)throw new RangeError("`cols` must select at least one column.");let s=te(n.namesTo??"name"),l=s.indexOf(".value");if(s.lastIndexOf(".value")!==l)throw new RangeError('`names_to` may contain ".value" only once');let f=[],i=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),m=a.map(d=>i===null?d:d.replace(i,"")),c=Un(m,s,n,f),p=[],h=[];if(l<0)p.push(...c),h.push({name:n.valuesTo??"value",sources:[...a]});else{let d=new Map,w=new Map,x=ve(n.namesTransform,".value");c.forEach((u,b)=>{let v=u.filter((_,I)=>I!==l),O=JSON.stringify(v),A=d.get(O);if(A===void 0){A=p.length,d.set(O,A),p.push(v);for(let _ of h)_.sources.push(null)}let R=u[l]??null,$=R===null||x===void 0?R:x(R);if($!==null&&typeof $!="string")throw new TypeError(`the transform of \`.value\` must give strings, not ${typeof $}`);let k=$??"NA",T=w.get(k);if(T===void 0&&(T={name:k,sources:p.map(()=>null)},w.set(k,T),h.push(T)),T.sources[A]!==null)throw new RangeError(`the names give the value column '${k}' twice for one key`);T.sources[A]=a[b]})}let N=h.map(d=>Ln(e,d.sources.filter(w=>w!==null))),E=[];if(t==="slowest")for(let d=0;d<p.length;d++)for(let w=0;w<r;w++)E.push([w,d]);else for(let d=0;d<r;d++)for(let w=0;w<p.length;w++)E.push([d,w]);let M=(d,w,x)=>{let u=d.sources[x];return u==null?null:e[u][w]};n.valuesDropNa===!0&&(E=E.filter(([d,w])=>h.some(x=>!W(M(x,d,w)))));let g={},y=E.map(([d])=>d);for(let d of o)a.includes(d)||F(g,d,G(e[d],y));if(s.forEach((d,w)=>{if(w===l)return;let x=ve(n.namesTransform,d),u=b=>{let v=p[b][w<l||l<0?w:w-1];return v===null||x===void 0?v:x(v)};F(g,d,E.map(([,b])=>u(b)))}),h.forEach((d,w)=>{let x=N[w]==="double";if(x&&d.sources.every(u=>u!==null&&e[u]instanceof Float64Array))F(g,d.name,Float64Array.from(E,([u,b])=>M(d,u,b)));else{let u=E.map(([b,v])=>{let O=M(d,b,v);return x&&typeof O=="boolean"?Number(O):O});F(g,d.name,u)}}),n.onWarning!==void 0)for(let d of new Set(f))n.onWarning(d);else le("pivotLonger",f);return g}var oe=e=>typeof e=="number"?"double":typeof e=="string"?"character":"logical";function Yn(e,n){if(e===null||n===null)return e;let t=oe(e);if(t===n)return e;if(n==="double"&&t==="logical")return Number(e);if(n==="logical"&&t==="double"){let r=e;if(Number.isNaN(r))return null;if(r===0||r===1)return r===1;throw new TypeError("Can't convert from `fill` <double> to <logical> due to loss of precision.")}throw new TypeError(`Can't convert \`fill\` <${t}> to <${n}>.`)}var Kn=e=>W(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function $e(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(a,s)=>{let l=JSON.stringify(e.map(i=>Kn(i[s]))),f=t.get(l);return f===void 0&&(f=r.length,t.set(l,f),r.push(s)),f}),firsts:r}}function Wn(e){return W(e)?"NA":typeof e=="number"?Number.isFinite(e)?Y(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function ne(e,n,t){if(e!==void 0)return n(e)?e:Object.hasOwn(e,t)?e[t]:void 0}function zn(e,n={}){S(n,Cn,"pivotWider");let t=Ae("names_vary",n.namesVary),r=Z(e),o=(u,b)=>{let v=[...new Set(te(u))];if(re(e,v),v.length===0)throw new RangeError(`\`${b}\` must select at least one column.`);return v},a=o(n.namesFrom??"name","names_from"),s=o(n.valuesFrom??"value","values_from"),l=n.idCols===void 0?Object.keys(e).filter(u=>!a.includes(u)&&!s.includes(u)):[...new Set(te(n.idCols))];re(e,l);for(let u of l){let b=a.includes(u)?"names_from":s.includes(u)?"values_from":null;if(b!==null)throw new RangeError(`\`id_cols\` can't select a column already selected by \`${b}\`. Column \`${u}\` has already been selected.`)}let f=n.namesPrefix??"",i=n.namesSep??"_",m=$e(l.map(u=>e[u]),r),c=$e(a.map(u=>e[u]),r),p=c.firsts.map((u,b)=>b);n.namesSort===!0&&p.sort((u,b)=>{for(let v of a){let O=fe(e[v][c.firsts[u]],e[v][c.firsts[b]]);if(O!==0)return O}return 0});let h=c.firsts.map(u=>f+a.map(b=>Wn(e[b][u])).join(i)),N=c.firsts.length,E=Array.from({length:m.firsts.length*N},()=>[]);for(let u=0;u<r;u++)E[m.codes[u]*N+c.codes[u]].push(u);let M=u=>typeof u=="function",g=u=>typeof u!="object"||u===null;for(let u of s)if(ne(n.valuesFn,M,u)===void 0&&E.some(b=>b.length>1))throw new RangeError(`values from '${u}' are not uniquely identified; use valuesFn to summarise them`);let y=new Map;for(let u of s){let b=e[u],v=ne(n.valuesFn,M,u),O=new Array(E.length).fill(null),A=null;if(v===void 0)A=Me(u,b),E.forEach(($,k)=>{$.length>0&&(O[k]=b[$[0]])});else{let $=new Uint8Array(E.length),k=0,T=0;for(let _=0;_<r;_++){let I=m.codes[_]*N+c.codes[_];if($[I]===1)continue;$[I]=1,T++;let U=v(E[I].map(Oe=>b[Oe]));if(O[I]=U,U==null)continue;let P=oe(U);if(A===null||A==="logical"&&P==="double")A=P,k=T;else if(P!==A&&(A==="character"||P==="character"))throw new TypeError(`Can't combine \`x[[${k}]]\` <${A}> and \`x[[${T}]]\` <${P}>.`)}}let R=Yn(ne(n.valuesFill,g,u)??null,A);y.set(u,{cells:O,type:A??(R===null?null:oe(R)),fill:R})}let d=(u,b)=>{let v=e[u],{cells:O,type:A,fill:R}=y.get(u),$=m.firsts.map((k,T)=>{let _=T*N+b,I=E[_].length===0?R:O[_];return A==="double"&&typeof I=="boolean"?Number(I):I});return v instanceof Float64Array&&(A==="double"||A===null)?Float64Array.from($,k=>k===null?NaN:k):$},w={};for(let u of l)F(w,u,G(e[u],m.firsts));let x=(u,b)=>s.length===1?h[b]:`${u}${i}${h[b]}`;if(t==="slowest")for(let u of p)for(let b of s)F(w,x(b,u),d(b,u));else for(let u of s)for(let b of p)F(w,x(u,b),d(u,b));return w}export{X as IQR,In as aggregate,de as completeCases,Te as cor,Fe as cov,Ke as cummax,We as cummin,Ye as cumprod,qe as cumsum,tn as cut,Je as cv,ze as diff,Rn as ecdf,rn as findInterval,un as fivenum,Ie as fromRows,Qe as geometricMean,Nn as hist,De as kurtosis,fn as mad,Pe as mean,Ge as meanAD,j as median,Se as merge,Ze as modes,hn as naOmit,qn as pivotLonger,zn as pivotWider,we as pretty,Le as prod,B as quantile,C as range,ke as rank,Xe as scale,z as sd,Be as skewness,Sn as split,_e as subset,Ce as sum,en as table,He as tabulate,kn as tapply,je as toRows,nn as unique,Ue as variance,Ve as weightedMean};
|
|
1
|
+
/*! rStats.js 1.1.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
+
import{m as ke,n as Fe,o as Te}from"./chunks/chunk-Y4YWLSWU.js";import"./chunks/chunk-Z2HGLFZN.js";import{A as De,B as Qe,C as Ze,D as Ge,E as Je,F as Xe,a as Z,b as W,c as G,d as F,e as fe,f as Se,g as _e,j as Ie,k as je,l as me,m as Ce,n as Le,o as Pe,p as Ve,q as Ue,r as z,s as j,t as C,u as qe,v as Ye,w as Ke,x as We,y as ze,z as Be}from"./chunks/chunk-UMLMY4XS.js";import{a as he,b as He,c as en,d as nn,e as tn,f as rn}from"./chunks/chunk-JNWWLNE3.js";import"./chunks/chunk-QUTJEYDX.js";import"./chunks/chunk-7IJCUSA5.js";import{a as ae,e as K,f as ie}from"./chunks/chunk-U7BRXOUS.js";import"./chunks/chunk-GGJA3JRO.js";import{a as ue}from"./chunks/chunk-GJEKNJP7.js";import{b as le}from"./chunks/chunk-N5BDSMXS.js";import{b as Y,d as ce}from"./chunks/chunk-EJYCDE4Z.js";import{b as q,c as se}from"./chunks/chunk-OG7UORIX.js";import"./chunks/chunk-NDTJ23A6.js";import{P as Q,l as S,u as V}from"./chunks/chunk-HUWOSLKE.js";var on=["type","naRm"],sn=["type","naRm"],ln=["center","constant","low","high","naRm"],J=4*Number.EPSILON,an={4:[0,1],5:[.5,.5],6:[0,0],8:[1/3,1/3],9:[3/8,3/8]};function cn(e,n,t){let r=e.length,o=i=>e[Math.min(Math.max(i,1),r)-1];if(t===7){let i=1+(r-1)*n,m=Math.floor(i),c=o(m),p=o(Math.ceil(i));if(i>m&&p!==c){let h=i-m;return(1-h)*c+h*p}return c}let a,s;if(t<=3){let i=t===3?r*n-.5:r*n;a=Math.floor(i*(1+J)),t===1?s=i>a?1:0:t===2?s=i>a?1:.5:s=i!==a||Math.abs(a%2)===1?1:0}else{let[i,m]=an[t],c=i+n*(r+1-i-m);a=Math.floor(c*(1+J)),s=c-a,Math.abs(s)<J&&(s=0)}let l=o(a),f=o(a+1);return s===1?f:s>0&&s<1&&l!==f?(1-s)*l+s*f:l}function B(e,n=[0,.25,.5,.75,1],t={}){S(t,on,"quantile");let r=t.type??7;if(!(Number.isInteger(r)&&r>=1&&r<=9))throw new RangeError("'type' must be an integer in 1..9");let o=me(e,t.naRm);if(o===void 0)throw new RangeError("missing values and NaN's not allowed if 'na.rm' is FALSE");let a=o.sort((i,m)=>i-m),s=typeof n=="number"?[n]:Array.from(n),l=100*Number.EPSILON;if(s.some(i=>i<-l||i>1+l))throw new RangeError("'probs' outside [0,1]");let f=s.map(i=>Number.isNaN(i)||a.length===0?NaN:cn(a,Math.min(Math.max(i,0),1),r));return typeof n=="number"?f[0]:f}function X(e,n={}){S(n,sn,"IQR");let[t,r]=B(e,[.25,.75],n);return r-t}function un(e){let n=Array.from(e).filter(a=>!Number.isNaN(a)).sort((a,s)=>a-s),t=n.length;if(t===0)return[NaN,NaN,NaN,NaN,NaN];let r=Math.floor((t+3)/2)/2;return[1,r,(t+1)/2,t+1-r,t].map(a=>q(n[Math.floor(a)-1],n[Math.ceil(a)-1]))}function fn(e,n={}){S(n,ln,"mad");let t=Array.from(e),r=t.filter(c=>!Number.isNaN(c)),o=n.naRm?r:t,a=n.center??(o.length>r.length?NaN:j(r)),s=n.constant??1.4826,l=n.low??!1,f=n.high??!1,i=o.map(c=>Math.abs(c-a)),m=i.length;if((l||f)&&m%2===0){if(l&&f)throw new RangeError("'low' and 'high' cannot be both TRUE");let c=m/2+(f?1:0),p=i.filter(h=>!Number.isNaN(h)).sort((h,N)=>h-N);if(c===0||p.length<c)throw new RangeError(`'partial' index ${c} outside bounds`);return s*p[c-1]}return s*j(i)}var pe=e=>e===null||typeof e=="number"&&Number.isNaN(e),ge=e=>Array.isArray(e)||ArrayBuffer.isView(e);function mn(e){if(ge(e))return{columns:[e],rows:e.length};if(typeof e!="object"||e===null)throw new TypeError("the arguments must be arrays or data frames");let n=Object.values(e),t=n[0]?.length??0;if(n.some(r=>r.length!==t))throw new RangeError("not all arguments have the same length");return{columns:n,rows:t}}function de(...e){if(e.length===0)throw new RangeError("no input has determined the number of cases");let n=e.map(mn),t=n[0].rows;if(n.some(o=>o.rows!==t))throw new RangeError("not all arguments have the same length");let r=n.flatMap(o=>o.columns);return Array.from({length:t},(o,a)=>r.every(s=>!pe(s[a])))}function hn(e){if(ge(e))return Array.from(e).filter(r=>!pe(r));let n=de(e),t={};for(let[r,o]of Object.entries(e)){let a=Array.from(o).filter((s,l)=>n[l]);F(t,r,o instanceof Float64Array?Float64Array.from(a):a)}return t}var pn=["breaks","right","includeLowest"],gn=["n","minN","shrinkSml","highUBias","u5Bias"];function we(e,n={}){S(n,gn,"pretty");let t=Array.from(e).filter(Number.isFinite);if(t.length===0)return[];let r=n.n??5;if(Number.isNaN(r)||Math.abs(r)>=2**31||Math.trunc(r)<0)throw new RangeError("invalid 'n' argument");let o=Math.trunc(r),a=n.minN??Math.floor(r/3);if(Number.isNaN(a)||Math.trunc(a)<0||Math.trunc(a)>o)throw new RangeError("invalid 'min.n' argument");let s=Math.trunc(a),l=n.shrinkSml??.75;if(!Number.isFinite(l)||l<=0)throw new RangeError("invalid 'shrink.sml' argument");let f=n.highUBias??1.5;if(!Number.isFinite(f)||f<0)throw new RangeError("invalid 'high.u.bias' argument");let i=n.u5Bias??.5+1.5*f;if(!Number.isFinite(i)||i<0)throw new RangeError("invalid 'u5.bias' argument");let m=1/0,c=-1/0;for(let R of t)R<m&&(m=R),R>c&&(c=R);let p=c-m,h,N;if(p===0&&c===0)h=1,N=!0;else{h=Math.max(Math.abs(m),Math.abs(c));let $=(1+(i>=1.5*f+.5?1/(1+f):1.5/(1+i)))*Math.max(1,o)*Number.EPSILON;N=p<h*$*3}N?(h>10&&(h=9+h/10),h*=l,s>1&&(h/=s)):(h=o>1?p/o:p,p===1/0&&o>=2&&(h=c/o-m/o));let E=2**-20*dn;h<E?h=E:h>Number.MAX_VALUE/1.25&&(h=Number.MAX_VALUE/1.25);let M=10**Math.floor(Math.log10(h)),g=[[2*M,f],[5*M,i],[10*M,f]],y=M;for(let[R,$]of g)if(R-h<$*(h-y))y=R;else break;let d=1e-10,w=Math.floor(m/y+d);for(;w*y>m+d*y;)w--;for(;!Number.isFinite(w*y);)w++;let x=Math.ceil(c/y-d);for(;x*y<c-d*y;)x++;for(;!Number.isFinite(x*y);)x--;let u=Math.trunc(.5+x-w);if(u<s){let R=s-u,$=Math.floor(R/2),k=R%2;m===0&&w===0&&c!==0?x+=R:c===0&&x===0&&m!==0?w-=R:w>=0?(x+=$,w-=$+k):(w-=$,x+=$+k),u=s}let b=w*y<m?w*y:m,v=x*y>c?x*y:c;if(u<=0)return[b];let O=he(b,v,u+1),A=v/u-b/u;return O.map(R=>Math.abs(R)<1e-14*A?0:R)}var dn=22250738585072014e-324;function wn(e){return e===0||!Number.isFinite(e)?e:Number(e.toPrecision(5))}function yn(e,n){let t=e.length;switch(n.toLowerCase()){case"sturges":return Math.ceil(Math.log2(t)+1);case"scott":{let r=l=>[C(l),3.5*z(l)*t**-.3333333333333333],[[o,a],s]=r(e);return Number.isFinite(a-o)&&Number.isFinite(s)||([[o,a],s]=r(Q([e]).groups[0])),s>0?Math.max(1,Math.ceil((a-o)/s)):1}case"fd":case"freedman-diaconis":{let r=(f,i)=>{let m=2*X(i);for(let c=.125;m===0&&c>=.001953125;c/=2){let[p,h]=B(i,[c,1-c]);m=(h-p)/(1-2*c)}return m===0&&(m=3.5*z(f)),[C(f),m]},o=e.map(wn),[[a,s],l]=r(e,o);if(!(Number.isFinite(s-a)&&Number.isFinite(l))){let{k:f}=Q([e]);[[a,s],l]=r(e.map(i=>V(i,-f)),o.map(i=>V(i,-f)))}return l>0?Math.ceil((s-a)/l*t**(1/3)):1}default:throw new RangeError("unknown 'breaks' algorithm")}}function bn(e,n,t){let r=e.slice(1).map((o,a)=>o-e[a]);return e.length>5?1e-7*j(r):e.length<=3?t-n===1/0?2*(1e-7*(t/2-n/2)):1e-7*(t-n):1e-7*se(r.filter(o=>o>0))}function Nn(e,n={}){S(n,pn,"hist");let t=Array.from(e).filter(Number.isFinite),r=t.length,o=n.right??!0,a=n.includeLowest??!0,s=n.breaks??"Sturges",l;if(typeof s!="string"&&typeof s!="number"&&s.length>1){if(!s.every(Number.isFinite))throw new RangeError("'breaks' are not finite");if(l=[...s].sort((g,y)=>g-y),l.some((g,y)=>y>0&&!(g>l[y-1])))throw new RangeError("'breaks' are not strictly increasing")}else{a=!0;let g=typeof s=="string"?yn(t,s):typeof s=="number"?s:s[0];if(!Number.isFinite(g)||g<1)throw new RangeError("invalid number of 'breaks'");g=Math.min(g,1e6);let[y,d]=C(t);l=we([y,d],{n:g,minN:1});for(let w=1;w<l.length;w++)if(!(l[w]-l[w-1]>0))throw new RangeError("'breaks' are not strictly increasing")}let f=l.length,[i,m]=r>0?C(t):[0,0],c=bn(l,i,m),p=l.map((g,y)=>o?y===0&&a?g-c:g+c:y<f-1?g-c:a?g+c:g-c),h=new Array(Math.max(0,f-1)).fill(0),N=0;for(let g of t){let y=xn(g,p,o,a);y>=0&&(h[y]++,N++)}if(N<r)throw new RangeError("some 'x' not counted; maybe 'breaks' do not span range of 'x'");let E=h.map((g,y)=>En(g,r,l[y],l[y+1])),M=h.map((g,y)=>q(l[y+1],l[y]));return{breaks:l,counts:h,density:E,mids:M}}function En(e,n,t,r){let o=r-t;if(!(n*o===1/0&&Number.isFinite(t)&&Number.isFinite(r)))return e/(n*o);let a=o===1/0?1:0,s=a===1?r/2-t/2:o,l=Math.floor(Math.log2(s));return V(e,-(l+a))/(n*V(s,-l))}function xn(e,n,t,r){let o=n.length-1;if(o<1)return-1;if(t){if(e===n[0]&&r)return 0;if(!(e>n[0]&&e<=n[o]))return-1;let l=1,f=o;for(;l<f;){let i=Math.floor((l+f)/2);e<=n[i]?f=i:l=i+1}return l-1}if(e===n[o]&&r)return o-1;if(!(e>=n[0]&&e<n[o]))return-1;let a=0,s=o-1;for(;a<s;){let l=Math.floor((a+s+1)/2);n[l]<=e?a=l:s=l-1}return a}function Rn(e){let n=Array.from(e).filter(r=>!Number.isNaN(r)).sort((r,o)=>r-o),t=n.length;if(t<1)throw new RangeError("'x' must have 1 or more non-missing values");return r=>{if(Number.isNaN(r))return NaN;let o=0,a=t;for(;o<a;){let s=Math.floor((o+a)/2);n[s]<=r?o=s+1:a=s}return o/t}}var vn=["drop","sep"],D=e=>e===null||typeof e=="number"&&Number.isNaN(e),$n=(e,n)=>typeof e=="number"?e-n:typeof e=="string"?ue(e,n):Number(e)-Number(n),An=e=>typeof e=="boolean"?e?"TRUE":"FALSE":typeof e=="string"?e:Number.isFinite(e)?Y(e):e>0?"Inf":"-Inf";function Mn(e,n){let t=ce(n),r=new Set(t.filter(l=>!D(l)).map(l=>typeof l));if(r.size>1)throw new TypeError(`${e} mixes ${[...r].join(" and ")} labels`);let o=[...r][0];if(o!==void 0&&o!=="number"&&o!=="string"&&o!=="boolean")throw new TypeError(`${e} has labels of an unsupported type`);let a=[...new Set(t.filter(l=>!D(l)))].sort($n),s=new Map(a.map((l,f)=>[l,f]));return{levels:a,codes:t.map(l=>D(l)?-1:s.get(l))}}var L=e=>Array.isArray(e)||e instanceof Float64Array;function Ee(e){if(e instanceof Float64Array)return[e];if(!Array.isArray(e))throw new TypeError("the group labels must be an array or an array of arrays");if(e.length>0&&e.every(L))return[...e];if(e.some(L))throw new TypeError("the group labels must be an array or an array of arrays");return[e]}function H(e,n,t){e.forEach((s,l)=>{if(s.length!==t)throw new RangeError(`${n[l]} must have one label per row (${t}), not ${s.length}`)});let r=e.map((s,l)=>Mn(n[l],s)),o=r.reduce((s,l)=>s*l.levels.length,1);if(o>=2**31)throw new RangeError("total number of levels >= 2^31");let a=new Array(t);for(let s=0;s<t;s++){let l=0,f=1;for(let i of r){let m=i.codes[s];if(m<0){l=-1;break}l+=m*f,f*=i.levels.length}a[s]=l}return{factors:r,size:o,cells:a}}function ee(e){let n=Array.from({length:e.size},()=>[]);return e.cells.forEach((t,r)=>{t>=0&&n[t].push(r)}),n}function On(e,n){return e.factors.map(t=>{let r=t.levels.length,o=t.levels[n%r];return n=Math.floor(n/r),o})}var xe=(e,n)=>Array.from({length:e},(t,r)=>e===1?n:`${n}[${r}]`);function kn(e,n,t){let r=Array.from(e),o=Ee(n),a=H(o,xe(o.length,"index"),r.length),s=ee(a).map(i=>i.length===0?null:{value:t(i.map(m=>r[m]))}),f=s.every(i=>i===null||typeof i.value=="number")?s.map(i=>i===null?NaN:i.value):s.map(i=>i===null?null:i.value);return{dim:a.factors.map(i=>i.levels.length),dimnames:a.factors.map(i=>[...i.levels]),values:f}}function Fn(e,n){let t={};for(let[r,o]of Object.entries(e))F(t,r,o instanceof Float64Array?Float64Array.from(n,a=>o[a]):n.map(a=>o[a]));return t}function Tn(e){let t=Object.values(e)[0]?.length??0;for(let[r,o]of Object.entries(e)){if(!L(o))throw new TypeError(`column '${r}' must be an array`);if(o.length!==t)throw new RangeError(`the columns of the data frame have different lengths (found for '${r}')`)}return t}function Sn(e,n,t={}){S(t,vn,"split");let r=t.sep??".",o=Ee(n),a=!L(e);if(a&&(typeof e!="object"||e===null))throw new TypeError("x must be an array or a data frame");let s=a?Tn(e):e.length,l=H(o,xe(o.length,"f"),s),f=a?[]:Array.from(e),i=new Map;return ee(l).forEach((m,c)=>{if(m.length===0&&(t.drop||l.factors.length===1))return;let p=On(l,c).map(An).join(r);if(i.has(p))throw new RangeError(`the group names joined with '${r}' are not unique ('${p}'); use another sep`);i.set(p,a?Fn(e,m):m.map(h=>f[h]))}),i}function ye(e,n){if(n===void 0)throw new RangeError(`object '${e}' not found`);if(!L(n))throw new TypeError(`column '${e}' must be an array`);return Array.from(n,t=>{if(t===null)return NaN;if(typeof t!="number")throw new TypeError(`column '${e}' to summarise must be numeric`);return t})}function be(e,n){let t=Object.prototype.hasOwnProperty.call(e,n)?e[n]:void 0;if(t===void 0)throw new RangeError(`object '${n}' not found`);if(!L(t))throw new TypeError(`column '${n}' must be an array`);return t}function _n(e,n){if(typeof e!="string")throw new TypeError("the formula must be a string");let t=e.indexOf("~");if(t<0)throw new SyntaxError("invalid formula: missing '~'");let r=e.slice(0,t).trim(),{rhs:o}=ae(`~ ${e.slice(t+1)}`),a=/^[A-Za-z.][A-Za-z0-9._]*$/,s;if(r!=="."){let i=/^cbind\s*\((.*)\)$/s.exec(r);if(s=i===null?[r]:i[1].split(",").map(m=>m.trim()),s.some(m=>!a.test(m)||m==="."))throw new SyntaxError("invalid formula: the left-hand side must be a variable, cbind(...) of variables or '.'")}else if(K(o,[]).length<K(o,["."]).length)throw new SyntaxError("invalid formula: '.' cannot be on both sides");let l=s===void 0?[]:n.filter(i=>!s.includes(i)),f=K(o,l);return ie(o,()=>0,l),{values:s??n.filter(i=>!f.includes(i)),groups:f}}function Ne(e,n,t,r,o,a){let s=r[0]?.length??n[0]?.length??0;e.forEach((c,p)=>{if(n[p].length!==s)throw new RangeError(`variable lengths differ (found for '${c}')`)});let l=H(r,t,s),f=ee(l).map((c,p)=>({cell:p,rows:c.filter(o)})).filter(c=>c.rows.length>0),i={};t.forEach((c,p)=>{let h=r[p];F(i,c,f.map(N=>{let E=h[N.rows[0]];return E===0?0:E}))});let m=(c,p)=>{if(Object.hasOwn(i,c))throw new RangeError(`duplicate column name '${c}' in the result`);F(i,c,p)};return e.forEach((c,p)=>{let h=n[p],E=f.map(g=>a(g.rows.map(y=>h[y]))).map(g=>{if(typeof g=="number")return{names:void 0,values:[g]};if(Array.isArray(g))return{names:void 0,values:[...g]};let y=g;return{names:Object.keys(y),values:Object.values(y)}}),M=E[0]?.values.length??1;if(E.some(g=>g.values.length!==M))throw new RangeError("fun must return values of the same length for every group");if(M===1&&E[0]?.names===void 0){m(c,E.map(g=>g.values[0]));return}for(let g=0;g<M;g++){let y=E[0].names?.[g]??String(g+1);m(`${c}.${y}`,E.map(d=>d.values[g]))}}),i}function In(e,n,t){if(typeof n!="object"||n===null)throw new TypeError("the data must be an object of columns");if(typeof e=="string"){let l=n,{values:f,groups:i}=_n(e,Object.keys(l)),m=N=>Object.prototype.hasOwnProperty.call(l,N),c=f.map(N=>ye(N,m(N)?l[N]:void 0)),p=i.map(N=>be(l,N));return Ne(f,c,i,p,N=>c.every(E=>!Number.isNaN(E[N]))&&p.every(E=>!D(E[N])),t)}if(typeof e!="object"||e===null)throw new TypeError("x must be a data frame");let r=Object.keys(e),o=r.map(l=>ye(l,e[l])),a=Object.keys(n);if(a.length===0)throw new RangeError("'by' must name at least one grouping column");let s=a.map(l=>be(n,l));return Ne(r,o,a,s,()=>!0,t)}var jn=new Set(["cols","namesTo","namesPrefix","namesSep","namesPattern","namesTransform","valuesTo","valuesDropNa","colsVary","onWarning"]),Cn=new Set(["namesFrom","valuesFrom","idCols","namesPrefix","namesSep","namesSort","namesVary","valuesFill","valuesFn"]),te=e=>typeof e=="string"?[e]:[...e];function Ae(e,n){if(n==null)return"fastest";if(n==="fastest"||n==="slowest")return n;throw typeof n!="string"?new TypeError(`\`${e}\` must be a string or character vector.`):new RangeError(`\`${e}\` must be one of "fastest" or "slowest", not "${n}".`)}function re(e,n){for(let t of n)if(!Object.hasOwn(e,t))throw new RangeError(`Column \`${t}\` doesn't exist.`)}function Me(e,n){if(n instanceof Float64Array)return"double";let t=null;for(let r of n){if(r===null)continue;let o=typeof r=="number"?"double":typeof r=="string"?"character":"logical";if(t!==null&&o!==t)throw new TypeError(`column '${e}' mixes ${t} and ${o} values`);t=o}return t}function Ln(e,n){let t=null;for(let r of n){let o=Me(r,e[r]);if(o!==null){if(t===null)t={type:o,column:r};else if(t.type!==o){if(t.type==="character"||o==="character")throw new TypeError(`Can't combine \`${t.column}\` <${t.type}> and \`${r}\` <${o}>.`);o==="double"&&(t={type:o,column:r})}}}return t?.type??null}function Re(e,n,t){let r=new RegExp(`${n}|`).exec("").length-1;if(r!==t)throw new TypeError(`\`regex\` should define ${t} groups; ${r} found.`);let o=new RegExp(n);return e.map(a=>{let s=o.exec(a);return Array.from({length:t},(l,f)=>s===null?null:s[f+1]??null)})}function Pn(e,n){let t=e.charCodeAt(n);if(t>=55296&&t<=56319&&n+1<e.length){let r=e.charCodeAt(n+1);if(r>=56320&&r<=57343)return 2}return 1}function Vn(e,n,t,r){let o=new RegExp(n,"g"),a=[],s=[],l=e.map((i,m)=>{let c=[],p=0,h=0;for(;;){o.lastIndex=p;let N=o.exec(i);if(N===null||(c.push(i.slice(h,N.index)),h=N.index+N[0].length,p=N[0].length===0?N.index+Pn(i,N.index):h,p>=i.length))break}return c.push(i.slice(h)),c.length>t&&a.push(m+1),c.length<t&&s.push(m+1),Array.from({length:t},(N,E)=>c[E]??null)}),f=i=>`${i.length} rows [${i.join(", ")}]`;return a.length>0&&r.push(`Expected ${t} pieces. Additional pieces discarded in ${f(a)}.`),s.length>0&&r.push(`Expected ${t} pieces. Missing pieces filled with \`NA\` in ${f(s)}.`),l}function ve(e,n){return e!==void 0&&Object.hasOwn(e,n)?e[n]:void 0}function Un(e,n,t,r){let{namesSep:o,namesPattern:a}=t;if(n.length===0)return e.map(()=>[]);if(n.length===1){if(o!==void 0)throw new TypeError("`names_sep` can't be used with a length 1 `names_to`.");return a===void 0?e.map(s=>[s]):Re(e,a,1)}if(o===void 0==(a===void 0))throw new TypeError("If you supply multiple names in `names_to` you must also supply one of `names_sep` or `names_pattern`.");return o!==void 0?Vn(e,o,n.length,r):Re(e,a,n.length)}function qn(e,n){S(n,jn,"pivotLonger");let t=Ae("cols_vary",n.colsVary),r=Z(e),o=Object.keys(e),a=typeof n.cols=="function"?o.filter(n.cols):[...new Set(n.cols)];if(re(e,a),a.length===0)throw new RangeError("`cols` must select at least one column.");let s=te(n.namesTo??"name"),l=s.indexOf(".value");if(s.lastIndexOf(".value")!==l)throw new RangeError('`names_to` may contain ".value" only once');let f=[],i=n.namesPrefix===void 0?null:new RegExp(`^(?:${n.namesPrefix})`),m=a.map(d=>i===null?d:d.replace(i,"")),c=Un(m,s,n,f),p=[],h=[];if(l<0)p.push(...c),h.push({name:n.valuesTo??"value",sources:[...a]});else{let d=new Map,w=new Map,x=ve(n.namesTransform,".value");c.forEach((u,b)=>{let v=u.filter((_,I)=>I!==l),O=JSON.stringify(v),A=d.get(O);if(A===void 0){A=p.length,d.set(O,A),p.push(v);for(let _ of h)_.sources.push(null)}let R=u[l]??null,$=R===null||x===void 0?R:x(R);if($!==null&&typeof $!="string")throw new TypeError(`the transform of \`.value\` must give strings, not ${typeof $}`);let k=$??"NA",T=w.get(k);if(T===void 0&&(T={name:k,sources:p.map(()=>null)},w.set(k,T),h.push(T)),T.sources[A]!==null)throw new RangeError(`the names give the value column '${k}' twice for one key`);T.sources[A]=a[b]})}let N=h.map(d=>Ln(e,d.sources.filter(w=>w!==null))),E=[];if(t==="slowest")for(let d=0;d<p.length;d++)for(let w=0;w<r;w++)E.push([w,d]);else for(let d=0;d<r;d++)for(let w=0;w<p.length;w++)E.push([d,w]);let M=(d,w,x)=>{let u=d.sources[x];return u==null?null:e[u][w]};n.valuesDropNa===!0&&(E=E.filter(([d,w])=>h.some(x=>!W(M(x,d,w)))));let g={},y=E.map(([d])=>d);for(let d of o)a.includes(d)||F(g,d,G(e[d],y));if(s.forEach((d,w)=>{if(w===l)return;let x=ve(n.namesTransform,d),u=b=>{let v=p[b][w<l||l<0?w:w-1];return v===null||x===void 0?v:x(v)};F(g,d,E.map(([,b])=>u(b)))}),h.forEach((d,w)=>{let x=N[w]==="double";if(x&&d.sources.every(u=>u!==null&&e[u]instanceof Float64Array))F(g,d.name,Float64Array.from(E,([u,b])=>M(d,u,b)));else{let u=E.map(([b,v])=>{let O=M(d,b,v);return x&&typeof O=="boolean"?Number(O):O});F(g,d.name,u)}}),n.onWarning!==void 0)for(let d of new Set(f))n.onWarning(d);else le("pivotLonger",f);return g}var oe=e=>typeof e=="number"?"double":typeof e=="string"?"character":"logical";function Yn(e,n){if(e===null||n===null)return e;let t=oe(e);if(t===n)return e;if(n==="double"&&t==="logical")return Number(e);if(n==="logical"&&t==="double"){let r=e;if(Number.isNaN(r))return null;if(r===0||r===1)return r===1;throw new TypeError("Can't convert from `fill` <double> to <logical> due to loss of precision.")}throw new TypeError(`Can't convert \`fill\` <${t}> to <${n}>.`)}var Kn=e=>W(e)?"NA":typeof e=="number"?`n${e}`:typeof e=="string"?`s${e}`:`b${String(e)}`;function $e(e,n){let t=new Map,r=[];return{codes:Array.from({length:n},(a,s)=>{let l=JSON.stringify(e.map(i=>Kn(i[s]))),f=t.get(l);return f===void 0&&(f=r.length,t.set(l,f),r.push(s)),f}),firsts:r}}function Wn(e){return W(e)?"NA":typeof e=="number"?Number.isFinite(e)?Y(e):e>0?"Inf":"-Inf":typeof e=="boolean"?e?"TRUE":"FALSE":e}function ne(e,n,t){if(e!==void 0)return n(e)?e:Object.hasOwn(e,t)?e[t]:void 0}function zn(e,n={}){S(n,Cn,"pivotWider");let t=Ae("names_vary",n.namesVary),r=Z(e),o=(u,b)=>{let v=[...new Set(te(u))];if(re(e,v),v.length===0)throw new RangeError(`\`${b}\` must select at least one column.`);return v},a=o(n.namesFrom??"name","names_from"),s=o(n.valuesFrom??"value","values_from"),l=n.idCols===void 0?Object.keys(e).filter(u=>!a.includes(u)&&!s.includes(u)):[...new Set(te(n.idCols))];re(e,l);for(let u of l){let b=a.includes(u)?"names_from":s.includes(u)?"values_from":null;if(b!==null)throw new RangeError(`\`id_cols\` can't select a column already selected by \`${b}\`. Column \`${u}\` has already been selected.`)}let f=n.namesPrefix??"",i=n.namesSep??"_",m=$e(l.map(u=>e[u]),r),c=$e(a.map(u=>e[u]),r),p=c.firsts.map((u,b)=>b);n.namesSort===!0&&p.sort((u,b)=>{for(let v of a){let O=fe(e[v][c.firsts[u]],e[v][c.firsts[b]]);if(O!==0)return O}return 0});let h=c.firsts.map(u=>f+a.map(b=>Wn(e[b][u])).join(i)),N=c.firsts.length,E=Array.from({length:m.firsts.length*N},()=>[]);for(let u=0;u<r;u++)E[m.codes[u]*N+c.codes[u]].push(u);let M=u=>typeof u=="function",g=u=>typeof u!="object"||u===null;for(let u of s)if(ne(n.valuesFn,M,u)===void 0&&E.some(b=>b.length>1))throw new RangeError(`values from '${u}' are not uniquely identified; use valuesFn to summarise them`);let y=new Map;for(let u of s){let b=e[u],v=ne(n.valuesFn,M,u),O=new Array(E.length).fill(null),A=null;if(v===void 0)A=Me(u,b),E.forEach(($,k)=>{$.length>0&&(O[k]=b[$[0]])});else{let $=new Uint8Array(E.length),k=0,T=0;for(let _=0;_<r;_++){let I=m.codes[_]*N+c.codes[_];if($[I]===1)continue;$[I]=1,T++;let U=v(E[I].map(Oe=>b[Oe]));if(O[I]=U,U==null)continue;let P=oe(U);if(A===null||A==="logical"&&P==="double")A=P,k=T;else if(P!==A&&(A==="character"||P==="character"))throw new TypeError(`Can't combine \`x[[${k}]]\` <${A}> and \`x[[${T}]]\` <${P}>.`)}}let R=Yn(ne(n.valuesFill,g,u)??null,A);y.set(u,{cells:O,type:A??(R===null?null:oe(R)),fill:R})}let d=(u,b)=>{let v=e[u],{cells:O,type:A,fill:R}=y.get(u),$=m.firsts.map((k,T)=>{let _=T*N+b,I=E[_].length===0?R:O[_];return A==="double"&&typeof I=="boolean"?Number(I):I});return v instanceof Float64Array&&(A==="double"||A===null)?Float64Array.from($,k=>k===null?NaN:k):$},w={};for(let u of l)F(w,u,G(e[u],m.firsts));let x=(u,b)=>s.length===1?h[b]:`${u}${i}${h[b]}`;if(t==="slowest")for(let u of p)for(let b of s)F(w,x(b,u),d(b,u));else for(let u of s)for(let b of p)F(w,x(u,b),d(u,b));return w}export{X as IQR,In as aggregate,de as completeCases,Te as cor,Fe as cov,Ke as cummax,We as cummin,Ye as cumprod,qe as cumsum,tn as cut,Je as cv,ze as diff,Rn as ecdf,rn as findInterval,un as fivenum,Ie as fromRows,Qe as geometricMean,Nn as hist,De as kurtosis,fn as mad,Pe as mean,Ge as meanAD,j as median,Se as merge,Ze as modes,hn as naOmit,qn as pivotLonger,zn as pivotWider,we as pretty,Le as prod,B as quantile,C as range,ke as rank,Xe as scale,z as sd,Be as skewness,Sn as split,_e as subset,Ce as sum,en as table,He as tabulate,kn as tapply,je as toRows,nn as unique,Ue as variance,Ve as weightedMean};
|
|
@@ -201,8 +201,8 @@ export function psignrank1(q, n, lowerTail, logP) {
|
|
|
201
201
|
n = signrankN(n);
|
|
202
202
|
if (Number.isNaN(n))
|
|
203
203
|
return NaN;
|
|
204
|
-
//
|
|
205
|
-
//
|
|
204
|
+
// The largest count not above q, as the other discrete distribution functions (#145, #146). R 4.6 takes
|
|
205
|
+
// floor(q + 1e-7) as here, apart from q within 1e-7 below an integer (R 4.5 rounded q + 1e-7 to the nearest integer)
|
|
206
206
|
const x = countAtMost(q);
|
|
207
207
|
const total = (n * (n + 1)) / 2;
|
|
208
208
|
if (x < 0)
|