@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 3.88 kB
JavaScript
// 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-array-like.js";import i from"./../assert/is-plain-object.js";import t from"./../utils/define-read-only-property.js";import e from"./../utils/count-by.js";import o from"./../utils/keys.js";import a from"./ranks.js";import s from"./../math/base/special/pow.js";import n from"./base/dists/chisquare/cdf.js";import p from"./../utils/identity-function.js";import l from"./../math/utils/incrspace.js";import u from"./../assert/is-array.js";import m from"./../assert/is-number.js";import f from"./../assert/is-nan.js";import h from"./../assert/has-own-property.js";import g from"./../assert/is-positive-integer.js";import d from"./../assert/is-boolean.js";import c from"./../math/base/special/roundn.js";var v=u,w=m.isPrimitive,j=i,b=f,y=h;function E(r,i){return j(i)?y(i,"alpha")&&(r.alpha=i.alpha,!w(r.alpha)||b(r.alpha))?new TypeError("invalid option. `alpha` option must be a number primitive. Option: `"+r.alpha+"`."):y(i,"groups")&&(r.groups=i.groups,!v(r.groups))?new TypeError("invalid option. `groups` option must be an array. Option: `"+r.groups+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+i+"`.")}var V=g,T=i,k=d.isPrimitive,O=h,F=c;function R(r){var i,t,e;if(t=4,i=!0,arguments.length>0){if(!T(r))throw new TypeError("invalid argument. First argument must be an options object. Value: `"+r+"`.");if(O(r,"digits")){if(!V(r.digits))throw new TypeError("invalid option. `digits` option must be a positive integer. Option: `"+r.digits+"`.");t=r.digits}if(O(r,"decision")){if(!k(r.decision))throw new TypeError("invalid option. `decision` option must be a boolean primitive. Option: `"+r.decision+"`.");i=r.decision}}return e="",e+=this.method,e+="\n\n",e+="Null hypothesis: the medians of all groups are the same",e+="\n\n",e+=" pValue: "+F(this.pValue,-t)+"\n",e+=" statistic: "+F(this.statistic,-t),e+=" df: "+this.df,e+="\n\n",i&&(e+="Test Decision: ",this.rejected?e+="Reject null in favor of alternative at "+100*this.alpha+"% significance level":e+="Fail to reject null in favor of alternative at "+100*this.alpha+"% significance level",e+="\n"),e}var q=r,M=i,P=t,x=e,D=o,K=a,N=s,S=n,W=p,z=l,A=E,B=R;function C(){var r,i,t,e,o,a,s,n,p,l,u,m,f,h,g,d,c,v,w,j,b,y,E,V;if(u={},M(arguments[(e=arguments.length)-1])&&(o=arguments[e-1],e-=1,d=A(u,o)))throw d;if(i={},b={},u.groups){if((E=arguments[0]).length!==u.groups.length)throw new RangeError("invalid arguments. First argument and `opts.groups` must be arrays of the same length.");for(b=x(u.groups,W),e=(a=D(b)).length,w=0;w<e;w++)i[c=a[w]]=0;if(e<2)throw new Error("invalid number of groups. `groups` array must contain at least two unique elements. Value: `"+a+"`.");r=u.groups}else{if(E=[],r=[],e<2)throw new Error("invalid number of input arguments. Must provide at least two array-like arguments. Value: `"+g+"`.");for(w=0;w<e;w++){if(!q(g=arguments[w]))throw new TypeError("invalid input argument. Must provide array-like arguments. Value: `"+g+"`.");if(0===g.length)throw new Error("invalid input argument. Supplied arrays cannot be empty. Value: `"+g+"`.");for(b[w]=g.length,i[w]=0,j=0;j<b[w];j++)r.push(w),E.push(g[j])}a=z(0,e,1)}if((s=void 0===u.alpha?.05:u.alpha)<0||s>1)throw new RangeError("invalid option. `alpha` must be a number in the range 0 to 1. Value: `"+s+"`.");for(y=E.length,p=K(E),h={},w=0;w<y;w++)i[r[w]]+=p[w],E[w]in h?h[E[w]]+=1:h[E[w]]=1;for(f=0,w=0;w<e;w++)c=a[w],f+=N(i[c],2)/b[c];for(f=12/(y*(y+1))*f-3*(y+1),t=0,l=D(h),w=0;w<l.length;w++)V=h[l[w]],t+=N(V,3)-V;return f/=1-t/(N(y,3)-y),m=1-S(f,n=e-1),P(v={},"rejected",m<=s),P(v,"alpha",s),P(v,"df",n),P(v,"pValue",m),P(v,"statistic",f),P(v,"method","Kruskal-Wallis Test"),P(v,"print",B),v}var G=C;export default G;
//# sourceMappingURL=kruskal-test.js.map