UNPKG

@stdlib/esm

Version:

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

3 lines 3.49 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import i from"./../assert/is-array-like.js";import r from"./../assert/is-plain-object.js";import t from"./../utils/define-read-only-property.js";import e from"./../utils/keys.js";import a from"./base/dists/chisquare/cdf.js";import o from"./../utils/group.js";import n from"./../math/base/special/ln.js";import s from"./../assert/is-array.js";import p from"./../assert/is-number.js";import l from"./../assert/is-nan.js";import u from"./../assert/has-own-property.js";import m from"./../assert/is-positive-integer.js";import f from"./../assert/is-boolean.js";import h from"./../math/base/special/roundn.js";function g(i){var r,t,e,a,o,n;for(r=0,t=0,a=0,e=i.length,o=0;o<e;o++)a+=(r=(n=i[o])-t)*(n-(t+=r/(o+1)));return a/(o-1)}var d=s,v=p.isPrimitive,c=r,w=l,j=u;function y(i,r){return c(r)?j(r,"alpha")&&(i.alpha=r.alpha,!v(i.alpha)||w(i.alpha))?new TypeError("invalid option. `alpha` option must be a number primitive. Option: `"+i.alpha+"`."):j(r,"groups")&&(i.groups=r.groups,!d(i.groups))?new TypeError("invalid option. `groups` option must be an array. Option: `"+i.groups+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")}var b=m,E=r,T=f.isPrimitive,V=u,O=h;function k(i){var r,t,e;if(t=4,r=!0,arguments.length>0){if(!E(i))throw new TypeError("invalid argument. First argument must be an options object. Value: `"+i+"`.");if(V(i,"digits")){if(!b(i.digits))throw new TypeError("invalid option. `digits` option must be a positive integer. Option: `"+i.digits+"`.");t=i.digits}if(V(i,"decision")){if(!T(i.decision))throw new TypeError("invalid option. `decision` option must be a boolean primitive. Option: `"+i.decision+"`.");r=i.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: "+O(this.pValue,-t)+"\n",e+=" statistic: "+O(this.statistic,-t)+"\n",e+=" df: "+O(this.df,-t),e+="\n\n",r&&(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=i,A=r,F=t,P=e,R=a,x=o,B=n,D=g,M=y,N=k;function S(){var i,r,t,e,a,o,n,s,p,l,u,m,f,h,g,d,v,c,w,j;if(p=[],l={},A(arguments[(r=arguments.length)-1])&&(i=arguments[r-1],r-=1,h=M(l,i)))throw h;if(l.groups){if(a=x(arguments[0],l.groups),(r=(e=P(a)).length)<2)throw new Error("invalid number of groups. `groups` array must contain at least two unique elements. Value: `"+e+"`.");for(j=0;j<r;j++)p.push(a[e[j]])}else for(j=0;j<r;j++)p.push(arguments[j]);for(n=0,t=0,s=0,g=0,c=new Array(r),w=new Array(r),j=0;j<r;j++){if(f=p[j],!q(f))throw new TypeError("invalid input argument. Must provide array-like arguments. Value: `"+f+"`.");if(0===f.length)throw new Error("invalid input argument. Supplied arrays cannot be empty. Value: `"+f+"`.");c[j]=f.length-1,n+=c[j],t+=1/c[j],w[j]=D(f),s+=c[j]*w[j],g+=c[j]*B(w[j])}if(s/=n,(o=void 0===l.alpha?.05:l.alpha)<0||o>1)throw new RangeError("invalid argument. Option `alpha` must be a number in the range 0 to 1. Value: `"+o+"`.");return m=n*B(s)-g,u=1-R(m/=1+(t-1/n)/(3*(r-1)),v=r-1),F(d={},"rejected",u<=o),F(d,"alpha",o),F(d,"pValue",u),F(d,"statistic",m),F(d,"df",v),F(d,"method","Bartlett's test of equal variances"),F(d,"print",N),d}var z=S;export default z; //# sourceMappingURL=bartlett-test.js.map