UNPKG

@stdlib/esm

Version:

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

3 lines 4.1 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-array-like.js";import i from"./../assert/is-plain-object.js";import t from"./../utils/define-read-only-property.js";import e from"./../utils/keys.js";import o from"./base/dists/normal/quantile.js";import a from"./base/dists/chisquare/cdf.js";import n from"./../utils/group.js";import s from"./ranks.js";import p from"./../math/base/special/abs.js";import l from"./../math/base/special/pow.js";import u from"./../utils/index-of.js";import m from"./../math/base/special/floor.js";import f from"./../assert/is-array.js";import h from"./../assert/is-number.js";import g from"./../assert/is-nan.js";import c from"./../assert/has-own-property.js";import d from"./../assert/is-positive-integer.js";import v from"./../assert/is-boolean.js";import j from"./../math/base/special/roundn.js";var b=m;function w(r,i){return r-i}function y(r){var i,t,e,o=r.length;if(!o)return null;for(t=[],e=0;e<o;e++)t.push(r[e]);return t.sort(w),i=b(o/2),o%2?t[i]:(t[i-1]+t[i])/2}var E=f,T=h.isPrimitive,V=i,O=g,k=c;function q(r,i){return V(i)?k(i,"alpha")&&(r.alpha=i.alpha,!T(r.alpha)||O(r.alpha))?new TypeError("invalid option. `alpha` option must be a number primitive. Option: `"+r.alpha+"`."):k(i,"groups")&&(r.groups=i.groups,!E(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 A=d,F=i,x=v.isPrimitive,P=c,R=j;function D(r){var i,t,e;if(t=4,i=!0,arguments.length>0){if(!F(r))throw new TypeError("invalid argument. First argument must be an options object. Value: `"+r+"`.");if(P(r,"digits")){if(!A(r.digits))throw new TypeError("invalid option. `digits` option must be a positive integer. Option: `"+r.digits+"`.");t=r.digits}if(P(r,"decision")){if(!x(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 variances in all groups are the same.",e+="\n\n",e+=" pValue: "+R(this.pValue,-t)+"\n",e+=" statistic: "+R(this.statistic,-t)+"\n",e+=" df: "+R(this.df,-t),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 K=r,M=i,N=t,S=e,z=o,B=a,C=n,G=s,H=p,I=l,J=u,L=y,Q=q,U=D;function W(r,i){var t,e=new Array(i);for(t=0;t<i;t++)e[t]=r;return e}function X(){var r,i,t,e,o,a,n,s,p,l,u,m,f,h,g,c,d,v,j,b,w,y,E,T,V,O;if(l=[],m={},M(arguments[(t=arguments.length)-1])&&(i=arguments[t-1],t-=1,d=Q(m,i)))throw d;if(m.groups){if(o=m.groups,n=C(arguments[0],o),(t=(e=S(n)).length)<2)throw new Error("invalid number of groups. `groups` array must contain at least two unique elements. Value: `"+e+"`.");for(V=0;V<t;V++)l.push(n[e[V]])}else for(o=[],V=0;V<t;V++)l.push(arguments[V]),o=o.concat(W(V,arguments[V].length));if((s=void 0===m.alpha?.05:m.alpha)<0||s>1)throw new RangeError("invalid argument. Option `alpha` must be a number in the range 0 to 1. Value: `"+s+"`.");for(T=[],V=0;V<t;V++){if(!K(l[V]))throw new TypeError("invalid input argument. Must provide array-like arguments. Value: `"+l[V]+"`.");if(0===l[V].length)throw new Error("invalid input argument. Supplied arrays cannot be empty. Value: `"+l[V]+"`.");for(v=L(l[V]),O=0;O<l[V].length;O++)l[V][O]-=v;T=T.concat(l[V])}for(E=T.length,g=new Array(E),V=0;V<E;V++)g[V]=H(T[V]);for(a=G(g),y=new Array(E),u=0,w=0,h=W(0,t),V=0;V<E;V++)y[V]=z((1+a[V]/(E+1))/2,0,1),h[e?J(e,o[V]):o[V]]+=y[V],u+=(p=y[V]-u)/(V+1),w+=p*(y[V]-u);for(r=w/(E-1),c=0,V=0;V<t;V++)c+=I(h[V],2)/l[V].length;return c=(c-E*I(u,2))/r,f=1-B(c,b=t-1),N(j={},"rejected",f<=s),N(j,"alpha",s),N(j,"pValue",f),N(j,"statistic",c),N(j,"df",b),N(j,"method","Fligner-Killeen test of homogeneity of variances"),N(j,"print",U),j}var Y=X;export default Y; //# sourceMappingURL=fligner-test.js.map