UNPKG

@stdlib/esm

Version:

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

3 lines 4.14 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-number-array.js";import t from"./../assert/is-typed-array-like.js";import e from"./../utils/define-read-only-property.js";import r from"./base/dists/f/cdf.js";import a from"./base/dists/f/quantile.js";import n from"./base/variance.js";import s from"./../math/base/special/min.js";import o from"./../constants/math/float64-pinf.js";import l from"./../assert/is-number.js";import p from"./../assert/is-positive-number.js";import m from"./../assert/is-plain-object.js";import u from"./../assert/is-string.js";import f from"./../assert/is-nan.js";import v from"./../assert/has-own-property.js";import h from"./../assert/is-positive-integer.js";import d from"./../assert/is-boolean.js";import c from"./../math/base/special/roundn.js";var b=l.isPrimitive,g=p.isPrimitive,w=m,j=u.isPrimitive,y=f,E=v;function T(i,t){return w(t)?E(t,"alpha")&&(i.alpha=t.alpha,!b(i.alpha)||y(i.alpha))?new TypeError("invalid option. `alpha` option must be a number primitive. Option: `"+i.alpha+"`."):E(t,"alternative")&&(i.alternative=t.alternative,!j(i.alternative))?new TypeError("invalid option. `alternative` option must be a string primitive. Option: `"+i.alternative+"`."):E(t,"ratio")&&(i.ratio=t.ratio,!g(i.ratio)||y(i.ratio))?new TypeError("invalid option. `ratio` option must be a positive number. Option: `"+i.ratio+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+t+"`.")}var V=h,O=m,k=d.isPrimitive,x=v,F=c;function P(i){var t,e,r;if(e=4,t=!0,arguments.length>0){if(!O(i))throw new TypeError("invalid argument. First argument must be an options object. Value: `"+i+"`.");if(x(i,"digits")){if(!V(i.digits))throw new TypeError("invalid option. `digits` option must be a positive integer. Option: `"+i.digits+"`.");e=i.digits}if(x(i,"decision")){if(!k(i.decision))throw new TypeError("invalid option. `decision` option must be a boolean primitive. Option: `"+i.decision+"`.");t=i.decision}}switch(r="",r+=this.method,r+="\n\n",r+="Alternative hypothesis: ",r+="True ratio in variances is ",this.alternative){case"two-sided":default:r+="not equal to ";break;case"less":r+="less than ";break;case"greater":r+="greater than "}return r+=this.nullValue,r+="\n\n",r+=" pValue: "+F(this.pValue,-e)+"\n",r+=" statistic: "+F(this.statistic,-e)+"\n",r+=" variance of x: "+F(this.xvar,-e),r+=" (df of x: "+F(this.dfX,-e)+")\n",r+=" variance of y: "+F(this.yvar,-e),r+=" (df of y: "+F(this.dfY,-e)+")\n",r+=" "+100*(1-this.alpha)+"% confidence interval: ["+F(this.ci[0],-e)+","+F(this.ci[1],-e)+"]",r+="\n\n",t&&(r+="Test Decision: ",this.rejected?r+="Reject null in favor of alternative at "+100*this.alpha+"% significance level":r+="Fail to reject null in favor of alternative at "+100*this.alpha+"% significance level",r+="\n"),r}var q=i.primitives,R=t,X=e,Y=r,A=a,D=n,I=s,S=o,z=T,B=P;function C(i,t,e){var r,a,n,s,o,l,p,m,u,f,v,h,d,c,b;if(!R(i)&&!q(i))throw new TypeError("invalid argument. First argument `x` must be a numeric array. Value: `"+i+"`.");if(!R(t)&&!q(t))throw new TypeError("invalid argument. Second argument `y` must be a numeric array. Value: `"+t+"`.");if(l={},e&&(h=z(l,e)))throw h;if(n=l.ratio||1,(a=void 0===l.alpha?.05:l.alpha)<0||a>1)throw new RangeError("invalid argument. Option `alpha` must be a number in the range 0 to 1. Value: `"+a+"`.");switch(c=i.length-1,b=t.length-1,u=D(i.length,1,i,1),f=D(t.length,1,t,1),p=Y(m=(r=u/f)/n,c,b),v=l.alternative||"two-sided"){case"two-sided":p=2*I(p,1-p),o=[r/A(1-(s=a/2),c,b),r/A(s,c,b)];break;case"greater":p=1-p,o=[r/A(1-a,c,b),S];break;case"less":o=[0,r/A(a,c,b)];break;default:throw new Error("Invalid option. `alternative` must be either `two-sided`, `less` or `greater`. Value: `"+v+"`")}return X(d={},"rejected",p<=a),X(d,"alpha",a),X(d,"pValue",p),X(d,"statistic",m),X(d,"ci",o),X(d,"alternative",v),X(d,"xvar",u),X(d,"yvar",f),X(d,"dfX",c),X(d,"dfY",b),X(d,"method","F test for comparing two variances"),X(d,"nullValue",n),X(d,"print",B),d}var G=C;export default G; //# sourceMappingURL=vartest.js.map