UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 2.84 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import r from"./../assert/is-probability-array.js";import e from"./../assert/is-integer.js";import n from"./../assert/is-string.js";import t from"./../math/base/special/min.js";import o from"./../math/base/special/max.js";import a from"./../array/float64.js";import i from"./../constants/math/float64-pinf.js";import f from"./../array/int32.js";import s from"./base/cumax.js";import m from"./base/cumin.js";function u(r,e){var n,t;for(t=0;t<r.length;t++)n=r[t],r[t]=e*n>1?1:e*n;return r}var l=f;function h(r,e){return r<e?-1:r>e?1:0}function c(r,e){return r<e?1:r>e?-1:0}function g(r,e){var n,t,o;for(n=e?c:h,t=new l(r.length),o=0;o<r.length;o++)t[o]=o;return t.sort((function(e,t){return n(r[e],r[t])}))}var p=t,v=o,w=a,b=i,y=g,j=Array.prototype.slice;function d(r,e){var n,t,o,a,i,f,s,m,u,l,h,c;if((t=e-(i=r.length))>0)for(r=j.call(r);t>0;)r.push(1),t-=1;for(n=y(r),m=0;m<e;m++)c=e*r[m]/(m+1);for(h=new w(e),o=new w(e),m=e-1;m>1;m--){for(s=b,l=e-m+1;l<=e;l++)(c=m*r[n[l]]/(2+l-e+m-1))<s&&(s=c);for(u=0;u<e-m+1;u++)h[u]=p(m*r[n[u]],s);for(l=e-m+1;l<=e;l++)h[l]=h[e-m];for(u=0;u<o.length;u++)o[u]=v(h[u],o[u])}for(f=new Array(i),m=0;m<i;m++)a=n[m],c=v(o[m],r[a]),f[a]=c;return f}var A=t,E=s,V=a,x=g;function T(r,e){var n,t,o,a,i;for(o=r.length,n=x(r),t=new V(o),i=0;i<o;i++)t[i]=(e-i)*r[n[i]];for(t=E(o,t,1,t,1),a=new Array(o),i=0;i<o;i++)a[n[i]]=A(t[i],1);return a}var P=t,S=m,F=a,R=g;function W(r,e){var n,t,o,a,i;for(o=r.length,n=R(r,!0),t=new F(o),i=0;i<o;i++)t[i]=e/(o-i)*r[n[i]];for(t=S(o,t,1,t,1),a=new Array(o),i=0;i<o;i++)a[n[i]]=P(t[i],1);return a}var k=t,q=m,z=a,B=g;function C(r,e){var n,t,o,a,i,f;for(o=r.length,n=B(r,!0),f=0,i=0;i<e;i++)f+=1/(1+i);for(t=new z(o),i=0;i<o;i++)t[i]=f*e/(o-i)*r[n[i]];for(t=q(o,t,1,t,1),a=new Array(o),i=0;i<o;i++)a[n[i]]=k(t[i],1);return a}var D=r,G=e.isPrimitive,H=n.isPrimitive,I=u,J=d,K=T,L=W,M=C,N=["bh","bonferroni","by","holm","hommel"];function O(r,e,n){if(!D(r))throw new TypeError("invalid argument. First argument must be an array of probabilities. Value: `"+r+"`.");if(!H(e))throw new TypeError("invalid argument. Second argument must be a string primitive. Value: `"+e+"`.");if(arguments.length>2){if(!G(n))throw new TypeError("invalid argument. `comparisons` must be an integer. Value: `"+n+"`.");if(n<r.length)throw new RangeError("invalid argument. When specified, `comparisons` arguments must have at least a length of "+r.length+". Value: `"+n+"`.")}switch(n=n||r.length,e){case"bonferroni":return I(r,n);case"by":return M(r,n);case"bh":return L(r,n);case"holm":return K(r,n);case"hommel":return J(r,n);default:throw new Error("invalid argument. Second argument must be one of "+N.join(", ")+" Value: `"+e+"`.")}}var Q=O;export default Q; //# sourceMappingURL=padjust.js.map