@numero-uno-jpn/rstats 0.10.0 → 0.11.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 +24 -0
- package/README.ja.md +11 -8
- package/README.md +10 -7
- package/dist/chunks/{chunk-7HPVUVZB.js → chunk-5WDJPHYY.js} +1 -1
- package/dist/chunks/{chunk-EWC6I75B.js → chunk-7GQMKH3Z.js} +1 -1
- package/dist/chunks/chunk-AHHS6AC4.js +3 -0
- package/dist/chunks/chunk-ALM3VHFP.js +2 -0
- package/dist/chunks/{chunk-QFULZNHL.js → chunk-C5XTWMGB.js} +1 -1
- package/dist/chunks/chunk-CGBNKHNZ.js +2 -0
- package/dist/chunks/{chunk-QULPY6YM.js → chunk-EZAFN5CD.js} +1 -1
- package/dist/chunks/{chunk-2XKG3DX4.js → chunk-EZWBRCJL.js} +1 -1
- package/dist/chunks/{chunk-O6PT7IVU.js → chunk-F5EDJFEO.js} +2 -2
- package/dist/chunks/{chunk-4NM37MGA.js → chunk-JWBO5WVN.js} +2 -2
- package/dist/chunks/{chunk-ENL43FNO.js → chunk-TOGXTCZO.js} +2 -2
- package/dist/chunks/{chunk-IT354SHV.js → chunk-VJ4BDBMU.js} +2 -2
- package/dist/chunks/{chunk-ZRIM4R4A.js → chunk-Y5CNQ266.js} +2 -2
- package/dist/chunks/{chunk-LIMZKONM.js → chunk-Y5PYRAYP.js} +2 -2
- package/dist/chunks/{chunk-QJJWGNJP.js → chunk-YSWGDOWK.js} +2 -2
- package/dist/data/grouping.d.ts +79 -0
- package/dist/data/grouping.js +262 -0
- package/dist/descriptive/dataFrames.d.ts +110 -0
- package/dist/descriptive/dataFrames.js +392 -0
- package/dist/descriptive/missing.d.ts +35 -0
- package/dist/descriptive/missing.js +50 -0
- package/dist/descriptive/pivot.d.ts +89 -0
- package/dist/descriptive/pivot.js +343 -0
- package/dist/descriptive.js +2 -2
- package/dist/distributions.js +2 -2
- package/dist/entries/descriptive.d.ts +4 -0
- package/dist/entries/descriptive.js +4 -0
- package/dist/htest/ansariTest.d.ts +12 -0
- package/dist/htest/ansariTest.js +5 -17
- package/dist/htest/cor.d.ts +12 -0
- package/dist/htest/cor.js +9 -27
- package/dist/htest/ksTest.d.ts +13 -0
- package/dist/htest/ksTest.js +5 -8
- package/dist/htest/onewayTest.d.ts +14 -0
- package/dist/htest/onewayTest.js +5 -7
- package/dist/htest/rankTests.d.ts +57 -0
- package/dist/htest/rankTests.js +19 -31
- package/dist/htest/tTest.d.ts +20 -0
- package/dist/htest/tTest.js +19 -24
- package/dist/htest/testFormula.d.ts +57 -0
- package/dist/htest/testFormula.js +171 -0
- package/dist/htest/varTest.d.ts +23 -0
- package/dist/htest/varTest.js +11 -21
- package/dist/htest/wilcoxTest.d.ts +14 -0
- package/dist/htest/wilcoxTest.js +9 -24
- package/dist/linalg/ops.d.ts +13 -2
- package/dist/linalg/ops.js +20 -5
- package/dist/linalg.js +2 -2
- package/dist/numerics.js +2 -2
- package/dist/rstats.js +14 -14
- package/dist/special.js +2 -2
- package/dist/tests.js +12 -13
- package/llms.txt +12 -0
- package/package.json +1 -1
- package/dist/chunks/chunk-AECGWZHD.js +0 -2
- package/dist/chunks/chunk-XWTZ4RTR.js +0 -2
package/llms.txt
CHANGED
|
@@ -62,6 +62,17 @@ CDN without a bundler, see the README section "Using it in the browser".
|
|
|
62
62
|
"breslow", weights = w)` → `coxph(time, status, x, { ties: "breslow", weights: w })`, with `strata` as labels.
|
|
63
63
|
psych's `omega(m, nfactors = 3)` → `omega(x, { nfactors: 3 })` (`omega(null, { covmat: R })` for a correlation
|
|
64
64
|
matrix).
|
|
65
|
+
- Data frames are objects of columns (`null` or `NaN` for NA); `fromRows(rows)` converts an array of row objects
|
|
66
|
+
(`[{ age: 30, score: 5 }, ...]`) and `toRows(d)` converts back. Tests take formulas like R's:
|
|
67
|
+
`t.test(y ~ g, data = d)` → `tTest("y ~ g", d)`, `friedman.test(y ~ w | b, d)` → `friedmanTest("y ~ w | b", d)`,
|
|
68
|
+
`cor.test(~ x + y, d)` → `corTest("~ x + y", d)`. `na.omit(d)` → `naOmit(d)`, `complete.cases(d)` →
|
|
69
|
+
`completeCases(d)`, `subset(d, age >= 20, select = c(y, g))` → `subset(d, (r) => r.age >= 20, { select: ["y",
|
|
70
|
+
"g"] })`, `tapply(x, g, mean)` → `tapply(x, g, mean)` (`{ dim, dimnames, values }`), `split(x, g)` → a `Map`,
|
|
71
|
+
`aggregate(y ~ g + sex, d, mean)` → `aggregate("y ~ g + sex", d, mean)`, `merge(a, b, by = "id", all.x = TRUE)`
|
|
72
|
+
→ `merge(a, b, { by: "id", allX: true })`, `rbind(d1, d2)` → `rbind(d1, d2)`. tidyr's `pivot_longer(d, cols =
|
|
73
|
+
c(t1, t2), names_to = "time", values_to = "score")` → `pivotLonger(d, { cols: ["t1", "t2"], namesTo: "time",
|
|
74
|
+
valuesTo: "score" })`, `pivot_wider(d, names_from = time, values_from = score)` → `pivotWider(d, { namesFrom:
|
|
75
|
+
"time", valuesFrom: "score" })`.
|
|
65
76
|
- Random numbers: after `setSeed(42)`, `rnorm`, `runif`, `sample` and the other `r*` functions
|
|
66
77
|
give the same numbers as R after `set.seed(42)`. `RNGkind` supports Mersenne-Twister (R's
|
|
67
78
|
default) and L'Ecuyer-CMRG.
|
|
@@ -92,6 +103,7 @@ glmSummary(fit).pValue; // ≈ [5.357e-8, 3.579e-9]
|
|
|
92
103
|
- [README](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/README.md): install, examples, the full list of functions by area
|
|
93
104
|
- [Differences from R](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/docs/differences-from-r.md): every known difference from R, function by function
|
|
94
105
|
- [Accuracy](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/docs/accuracy.md): how results are checked against R and high-precision references
|
|
106
|
+
- [Guide for JavaScript developers](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/docs/guide-for-js-developers.md): data frames, missing values, factors, formulas and a worked analysis
|
|
95
107
|
- [Migrating from jStat](https://raw.githubusercontent.com/numero-uno-jpn/rStats.js/main/docs/migrating-from-jstat.md): the replacement for every jStat function
|
|
96
108
|
|
|
97
109
|
## Optional
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@numero-uno-jpn/rstats",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "R-compatible statistical functions for the browser: distributions, random numbers that match set.seed(), hypothesis tests and linear algebra, tested against R.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"statistics",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.10.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 d,b as m,c as p}from"./chunk-LIMZKONM.js";import{d as g,g as x}from"./chunk-2XKG3DX4.js";function c(s,r){let e=Array.from(s);return r?e.filter(t=>!Number.isNaN(t)):e.some(Number.isNaN)?void 0:e}function b(s){if(!s.every(Number.isFinite))return s.reduce((e,t)=>e+t,0);let r=[0,0];for(let e of s)r=g(r,[e,0]);return r[0]+r[1]}function D(s,r={}){let e=c(s,r.naRm);return e===void 0?NaN:b(e)}function F(s,r={}){let e=c(s,r.naRm);if(e===void 0)return NaN;if(!e.every(Number.isFinite)||e.includes(0))return e.reduce((o,u)=>o*u,1);let t=[1,0],n=0;for(let o of e){t=x(t,[o,0]);let u=Math.floor(Math.log2(Math.abs(t[0])));if(u>500||u<-500){let f=2**-u;t=[t[0]*f,t[1]*f],n+=u}}return v(t,n)}function I(s,r={}){let e=c(s,r.naRm);if(e===void 0)return NaN;let t=e.length;if(t===0)return NaN;let n=r.trim??0;if(Number.isNaN(n))throw new RangeError("'trim' must be numeric of length one");if(n>0&&t>0){if(n>=.5)return M(e);n=Math.max(n,0);let o=Math.floor(t*n),u=[...e].sort((f,a)=>f-a);return m(u.slice(o,t-o))}return m(e)}function O(s,r,e={}){let t=Array.from(s),n=Array.from(r);if(t.length!==n.length)throw new RangeError("'x' and 'w' must have the same length");if(e.naRm){let u=t.map(f=>!Number.isNaN(f));t=t.filter((f,a)=>u[a]),n=n.filter((f,a)=>u[a])}let o=[];for(let u=0;u<t.length;u++)n[u]!==0&&o.push(t[u]*n[u]);return b(o)/b(n)}function q(s,r={}){let e=c(s,r.naRm);return e===void 0?NaN:p(e)}function _(s,r={}){return Math.sqrt(q(s,r))}function M(s,r={}){let e=c(s,r.naRm);if(e===void 0)return NaN;let t=e.length;if(t===0)return NaN;let n=[...e].sort((u,f)=>u-f),o=Math.floor(t/2);return t%2===1?n[o]:d([n[o-1],n[o]])[0]}function j(s,r={}){let e=c(s,r.naRm);if(e===void 0)return[NaN,NaN];let t=1/0,n=-1/0;for(let o of e)o<t&&(t=o),o>n&&(n=o);return[t,n]}function S(s){let r=[],e=[0,0],t=0,n=!0;for(let o of Array.from(s))t+=o,n&&Number.isFinite(o)?(e=g(e,[o,0]),r.push(e[0]+e[1])):(n=!1,r.push(Number.isNaN(o)||Number.isNaN(t)?NaN:t));return r}function T(s){let r=[],e=[1,0],t=0,n;for(let o of Array.from(s)){if(n===void 0&&(!Number.isFinite(o)||o===0)&&(n=v(e,t)),n!==void 0){n*=o,r.push(n);continue}e=x(e,[o,0]);let u=Math.floor(Math.log2(Math.abs(e[0])));(u>500||u<-500)&&(e=[e[0]*2**-u,e[1]*2**-u],t+=u),r.push(v(e,t))}return r}function v(s,r){let e=s[0]+s[1];for(;r>0&&Number.isFinite(e);){let t=Math.min(r,1e3);e*=2**t,r-=t}for(;r<0&&e!==0;){let t=Math.max(r,-1e3);e*=2**t,r-=t}return e}function y(s,r){let e=[],t=NaN,n=!1;for(let o of Array.from(s)){if(n||Number.isNaN(o)){n=!0,e.push(NaN);continue}(e.length===0||r(o,t))&&(t=o),e.push(t)}return e}function z(s){return y(s,(r,e)=>r>e)}function B(s){return y(s,(r,e)=>r<e)}function C(s,r={}){let e=r.lag??1,t=r.differences??1;if(!(Number.isInteger(e)&&e>=1&&Number.isInteger(t)&&t>=1))throw new RangeError("'lag' and 'differences' must be integers >= 1");let n=Array.from(s);if(e*t>=n.length)return[];for(let o=0;o<t;o++){let u=[];for(let f=e;f<n.length;f++)u.push(n[f]-n[f-e]);n=u}return n}function R(s){let r=d(s),e=0,t=0,n=0;for(let o of s){let u=o-r[0]-r[1],f=u*u;e+=f,t+=f*u,n+=f*f}return[e,t,n]}function A(s){if(![1,2,3].includes(s))throw new RangeError("Invalid 'type' argument.")}function L(s,r={}){let e=r.type??3;A(e);let t=c(s,!0),n=t.length,[o,u]=R(t),f=Math.sqrt(n)*u/o**1.5;if(e===1)return f;if(e===2){if(n<3)throw new RangeError("Need at least 3 complete observations.");return f*Math.sqrt(n*(n-1))/(n-2)}return f*(1-1/n)**1.5}function P(s,r={}){let e=r.type??3;A(e);let t=c(s,!0),n=t.length,[o,,u]=R(t),f=n*u/(o*o);if(e===1)return f-3;if(e===2){if(n<4)throw new RangeError("Need at least 4 complete observations.");return((n+1)*(f-3)+6)*(n-1)/((n-2)*(n-3))}return f*(1-1/n)**2-3}function Q(s,r={}){let e=c(s,r.naRm);return e===void 0?NaN:e.some(t=>t<0)?NaN:e.includes(0)?0:Math.exp(m(e.map(Math.log)))}function U(s){let r=c(s,!0),e=new Map;for(let o of r)e.set(o===0?0:o,(e.get(o===0?0:o)??0)+1);let t=0;for(let o of e.values())t=Math.max(t,o);return t<=1?{value:[NaN],frequency:NaN}:{value:[...e.entries()].filter(([,o])=>o===t).map(([o])=>o).sort((o,u)=>o-u),frequency:t}}function V(s,r={}){let e=c(s,!0),t=r.center??"mean",n=t==="mean"?m(e):t==="median"?M(e):t;return m(e.map(o=>Math.abs(o-n)))}function W(s,r={}){let e=c(s,r.naRm);if(e===void 0)return NaN;let t=e.length,n=Math.sqrt(p(e))/m(e);return r.unbiased&&(n*=1-1/(4*(t-1))+n*n/t+1/(2*(t-1)**2)),n}function X(s,r={}){let e=s.length>0&&Array.isArray(s[0])?s.map(a=>[...a]):Array.from(s,a=>[a]),t=e[0]?.length??0,n=a=>e.map(l=>l[a]),o={scaled:e},u=r.center??!0;if(u!==!1){let a=u===!0?Array.from({length:t},(l,i)=>m(n(i).filter(N=>!Number.isNaN(N)))):[...u];if(a.length!==t)throw new RangeError("length of 'center' must equal the number of columns of 'x'");for(let l of e)for(let i=0;i<t;i++)l[i]=l[i]-a[i];o.center=a}let f=r.scale??!0;if(f!==!1){let a=f===!0?Array.from({length:t},(l,i)=>{let N=n(i).filter(h=>!Number.isNaN(h)),w=0;for(let h of N)w+=h*h;return Math.sqrt(w/Math.max(1,N.length-1))}):[...f];if(a.length!==t)throw new RangeError("length of 'scale' must equal the number of columns of 'x'");for(let l of e)for(let i=0;i<t;i++)l[i]=l[i]/a[i];o.scale=a}return o}export{c as a,D as b,F as c,I as d,O as e,q as f,_ as g,M as h,j as i,S as j,T as k,z as l,B as m,C as n,L as o,P as p,Q as q,U as r,V as s,W as t,X as u};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! rStats.js 0.10.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
|
|
2
|
-
import{k as _,r as J}from"./chunk-ZRIM4R4A.js";import{a as Q,d as X,f as U,g as q,i as Y}from"./chunk-LIMZKONM.js";import{g as V,h as W}from"./chunk-4NM37MGA.js";import{b as Z,c as G,d as x,f as P,g as R,i as O}from"./chunk-2XKG3DX4.js";function tt(t){if(t===void 0)return"two.sided";let o=["two.sided","less","greater"].filter(r=>r.startsWith(t));if(t.length===0||o.length!==1)throw new RangeError(`invalid alternative "${t}" (expected "two.sided", "less" or "greater")`);return o[0]}function et(t){if(!(Number.isFinite(t)&&t>=0&&t<=1))throw new RangeError("confLevel must be a number between 0 and 1")}function yt(t){if(!(Number.isFinite(t)&&t>0&&t<1))throw new RangeError("'conf.level' must be a single number between 0 and 1")}var ht=["pearson","kendall","spearman"];function dt(t){if(t===void 0)return"pearson";let e=ht.filter(o=>o.startsWith(t));if(t.length===0||e.length!==1)throw new RangeError(`invalid method "${t}"`);return e[0]}function nt(t){if(!(t[0]>0))return[Math.sqrt(t[0]),0];let e=Math.sqrt(t[0]),o=P(t,G(e,e));return Z(e,o[0]/(2*e))}function rt(t){let e=Q(t);if(!Number.isFinite(e[0]))return;let o=t.map(s=>P([s,0],e)),r=0;for(let s of o)r=Math.max(r,Math.abs(s[0]));if(r===0)return o;let c=2**-Math.max(-1022,Math.floor(Math.log2(r)));return o.map(s=>[s[0]*c,s[1]*c])}function H(t,e){let o=t.length;if(o<2)return[NaN,0];let r=rt(t),c=rt(e);if(r===void 0||c===void 0)return[NaN,0];let s=[0,0],i=[0,0],a=[0,0];for(let u=0;u<o;u++)s=x(s,R(r[u],c[u])),i=x(i,R(r[u],r[u])),a=x(a,R(c[u],c[u]));if(i[0]===0||a[0]===0)return[NaN,0];let n=O(s,R(nt(i),nt(a)));return n[0]>=1?[1,0]:n[0]<=-1?[-1,0]:n}function ot(t,e){let o=R(P([1,0],t),x([1,0],t));return Math.sqrt(e)*t[0]/Math.sqrt(o[0])}function pt(t){return Math.abs(t[0])<.5?Math.atanh(t[0]):.5*Math.log(x([1,0],t)[0]/P([1,0],t)[0])}function st(t,e,o){return o==="less"?_(t,e,!0,!1):o==="greater"?_(t,e,!1,!1):2*Math.min(_(t,e,!0,!1),_(t,e,!1,!1))}function Nt(t,e){return e==="less"?V(t):e==="greater"?V(t,{lowerTail:!1}):2*Math.min(V(t),V(t,{lowerTail:!1}))}function z(t,e){let o=t.length,r=0;for(let f=0;f<o;f++){let m=t[f],v=e[f];for(let w=f+1;w<o;w++){let M=(t[w]>m?1:0)-(t[w]<m?1:0),A=(e[w]>v?1:0)-(e[w]<v?1:0);r+=M*A}}let c=q(t),s=q(e),i=o*(o-1)/2,a=c.reduce((f,m)=>f+m*(m-1)/2,0),n=s.reduce((f,m)=>f+m*(m-1)/2,0),u=o<2||a===i||n===i?NaN:a===0&&n===0?r/i:r/Math.sqrt((i-a)*(i-n));return{s:r,tau:u,ties:c.length>0||s.length>0,tx:c,ty:s}}function at(t,e){let o=t*(t-1)/2;if(e<0)return 0;if(e>=o)return 1;let r=new Float64Array(e+1);r[0]=1;for(let s=2;s<=t;s++){let i=new Float64Array(e+1),a=0;for(let u=0;u<=e;u++)a+=r[u],i[u]=a;let n=new Float64Array(e+1);for(let u=0;u<=e;u++)n[u]=(i[u]-(u>=s?i[u-s]:0))/s;r=n}let c=0;for(let s=e;s>=0;s--)c+=r[s];return Math.min(1,c)}var it=new Map;function gt(t){let e=it.get(t);if(e!==void 0)return e;let o=t*(t*t-1)/3,r=1<<t,c=new Array(r);c[0]=new Float64Array(o+1),c[0][0]=1;let s=a=>{let n=0;for(;a;a&=a-1)n++;return n};for(let a=0;a<r;a++){let n=c[a];if(n===void 0)continue;let u=s(a);for(let f=0;f<t;f++){if(a&1<<f)continue;let m=(f-u)**2,v=a|1<<f,w=c[v]??=new Float64Array(o+1);for(let M=0;M+m<=o;M++)n[M]&&(w[M+m]+=n[M])}a!==r-1&&(c[a]=void 0)}let i=c[r-1];return it.set(t,i),i}var y=[.2274,.2531,.1745,.0758,.1033,.3932,.0879,.0151,.0072,.0831,.0131,46e-5];function ct(t,e,o){let r=e;r%2!==0&&(r+=1);let c=1/t,s=(6*(r-1)*c/(t*t-1)-1)*Math.sqrt(1/c-1),i=s*s,n=s*c*(y[0]+c*(y[1]+y[2]*c)+i*(-y[3]+c*(y[4]+y[5]*c)-i*c*(y[6]+y[7]*c-i*(y[8]-y[9]*c+i*c*(y[10]-y[11]*i)))))/Math.exp(i/2),u=o?V(s)-n:n+V(s,{lowerTail:!1});return Math.min(1,Math.max(0,u))}function ut(t,e,o){let r=t*(t*t-1)/3;if(t<=9){let c=gt(t),s=1;for(let a=2;a<=t;a++)s*=a;let i=0;if(o)for(let a=Math.min(e,r);a>=0;a--)i+=c[a];else for(let a=r;a>=Math.max(e,0);a--)i+=c[a];return i/s}return o?e+1>r?1:e+1<=0?0:ct(t,e+1,!0):e<=0?1:e>r?0:ct(t,e,!1)}function St(t,e,o={}){if(t.length!==e.length)throw new TypeError("x and y must have the same length");let r=tt(o.alternative),c=dt(o.method),s=o.continuity??!1,[i,a]=Y(Array.from(t),Array.from(e)),n=i.length;if(c==="pearson"){let l=o.confLevel??.95;if(et(l),n<3)throw new Error("not enough finite observations");let g=H(i,a),k=n-2,d=Number.isNaN(g[0])?NaN:ot(g,k),S={method:"Pearson's product-moment correlation",alternative:r,statistic:d,statisticName:"t",parameter:k,parameterName:"df",pValue:st(d,k,r),estimate:g[0],estimateNames:"cor",nullValue:0,nullValueName:"correlation"};if(n>3){let j=pt(g),T=1/Math.sqrt(n-3),D=E=>Math.tanh(j+E),L;if(r==="less")L=[-1,D(T*W(l))];else if(r==="greater")L=[D(-T*W(l)),1];else{let E=T*W((1+l)/2);L=[D(-E),D(E)]}S.confInt=L,S.confLevel=l}return S}if(n<2)throw new Error("not enough finite observations");if(c==="kendall"){let l=z(i,a),g={method:"Kendall's rank correlation tau",alternative:r,estimate:l.tau,estimateNames:"tau",nullValue:0,nullValueName:"tau"};if(Number.isNaN(l.tau))return{...g,statistic:NaN,statisticName:"T",pValue:NaN};if((o.exact??n<50)&&!l.ties){let N=n*(n-1)/2,C=(l.s+N)/2,$=at(n,C),B=at(n,N-C),mt=r==="less"?$:r==="greater"?B:Math.min(1,2*Math.min($,B));return{...g,statistic:C,statisticName:"T",pValue:mt}}let d=(N,C)=>C.reduce(($,B)=>$+N(B),0),S=N=>N*(N-1),j=N=>N*(N-1)*(N-2),T=N=>N*(N-1)*(2*N+5),D=(n*(n-1)*(2*n+5)-d(T,l.tx)-d(T,l.ty))/18+d(j,l.tx)*d(j,l.ty)/(9*n*(n-1)*(n-2))+d(S,l.tx)*d(S,l.ty)/(2*n*(n-1)),E=(s?Math.sign(l.s)*(Math.abs(l.s)-1):l.s)/Math.sqrt(D);return{...g,statistic:E,statisticName:"z",pValue:Nt(E,r)}}let u=U(i),f=U(a),m=H(u,f),v=n*n*n-n,w=v*(1-m[0])/6,M={method:"Spearman's rank correlation rho",alternative:r,statistic:w,statisticName:"S",estimate:m[0],estimateNames:"rho",nullValue:0,nullValueName:"rho"};if(Number.isNaN(m[0]))return{...M,pValue:NaN};let A=q(i).length>0||q(a).length>0;if((o.exact??n<=1290)&&!A&&n<=1290){let l=Math.round(w),g=ut(n,l,!0),k=ut(n,l,!1),d=r==="greater"?g:r==="less"?k:Math.min(1,2*Math.min(g,k));return{...M,pValue:d}}let h=m;if(s){let l=O([6,0],[v,0]);h=O(x(m,l),x([1,0],l)),Math.abs(h[0])>=1&&(h=[Math.sign(h[0]),0])}let b=ot(h,n-2);return{...M,pValue:st(b,n-2,r)}}function wt(t,e){let o=t.length,r=new Array(o);if(e==="first"||e==="last"||e==="random"){let i=e==="random"?J(o):[],a=Array.from({length:o},(n,u)=>u);return a.sort((n,u)=>{let f=t[n]-t[u];return f!==0?f:e==="first"?n-u:e==="last"?u-n:i[n]-i[u]||n-u}),a.forEach((n,u)=>r[n]=u+1),r}let c=Array.from({length:o},(i,a)=>a).sort((i,a)=>t[i]-t[a]||i-a),s=0;for(;s<o;){let i=s;for(;i+1<o&&t[c[i+1]]===t[c[s]];)i++;let a=e==="average"?(s+i+2)/2:e==="min"?s+1:i+1;for(let n=s;n<=i;n++)r[c[n]]=a;s=i+1}return r}function I(t,e={}){let o=e.tiesMethod??"average";if(!["average","first","last","random","max","min"].includes(o))throw new RangeError(`invalid tiesMethod "${o}"`);let r=e.naLast??"last",c=Array.from(t),s=c.filter(m=>!Number.isNaN(m)),i=wt(s,o),a=c.length-s.length,n=[],u=0,f=0;for(let m of c)Number.isNaN(m)?(f++,n.push(r==="keep"?NaN:r==="last"?s.length+f:f)):n.push(r==="first"?i[u++]+a:i[u++]);return n}var Mt=["pearson","kendall","spearman"],bt=["all.obs","complete.obs","pairwise.complete.obs","everything","na.or.complete"];function lt(t,e,o,r){if(t===void 0)return o;if(e.includes(t))return t;let c=e.filter(s=>s.startsWith(t));if(t.length===0||c.length!==1)throw new RangeError(`invalid '${r}' argument`);return c[0]}function F(t){return t.length>0&&Array.isArray(t[0])}function ft(t){if(!F(t))return[Array.from(t)];let e=t[0].length;return Array.from({length:e},(o,r)=>t.map(c=>c[r]))}function K(t,e,o,r){let c=lt(o.method,Mt,"pearson","method"),s=lt(o.use,bt,"everything","use");if(e===void 0&&!F(t))throw new TypeError("supply both 'x' and 'y' or a matrix-like 'x'");let i=ft(t),a=e===void 0?i:ft(e),n=i[0]?.length??0;if(a.some(p=>p.length!==n))throw new RangeError("incompatible dimensions");let u=[...i,...a];if(s==="all.obs"&&u.some(p=>p.some(Number.isNaN)))throw new RangeError("missing observations in cov/cor");if(!r&&s==="pairwise.complete.obs"&&c!=="pearson")throw new RangeError("cannot handle 'pairwise.complete.obs'");let f;if((s==="complete.obs"||s==="na.or.complete")&&(f=Array.from({length:n},(p,h)=>u.every(b=>!Number.isNaN(b[h]))),!f.some(Boolean))){if(s==="complete.obs")throw new RangeError("no complete element pairs");return e===void 0||F(t)||F(e)?i.map(()=>a.map(()=>NaN)):NaN}let m=p=>{let h=f===void 0?p:p.filter((b,l)=>f[l]);return c==="spearman"&&s!=="pairwise.complete.obs"?I(h,{naLast:"keep"}):h},v=i.map(m),w=e===void 0?v:a.map(m),M=(p,h)=>{let b=p,l=h;if(s==="pairwise.complete.obs"){let g=p.map((k,d)=>!Number.isNaN(k)&&!Number.isNaN(h[d]));b=p.filter((k,d)=>g[d]),l=h.filter((k,d)=>g[d]),c==="spearman"&&(b=I(b),l=I(l))}else if(b.some(Number.isNaN)||l.some(Number.isNaN))return NaN;return c==="kendall"?r?z(b,l).tau:2*z(b,l).s:r?H(b,l)[0]:X(b,l)},A=v.map(p=>w.map(h=>M(p,h)));return r&&e===void 0&&s!=="pairwise.complete.obs"&&A.forEach((p,h)=>p[h]=1),e!==void 0&&!F(t)&&!F(e)?A[0][0]:A}function Pt(t,e,o={}){return e!==void 0&&!Array.isArray(e)&&!ArrayBuffer.isView(e)?K(t,void 0,e,!1):K(t,e,o,!1)}function _t(t,e,o={}){return e!==void 0&&!Array.isArray(e)&&!ArrayBuffer.isView(e)?K(t,void 0,e,!0):K(t,e,o,!0)}export{tt as a,et as b,yt as c,H as d,St as e,I as f,Pt as g,_t as h};
|