@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 4.49 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import e from"./../assert/is-number-array.js";import i from"./../assert/is-typed-array-like.js";import t from"./../assert/is-positive-number.js";import r from"./../utils/define-read-only-property.js";import a from"./base/dists/normal/quantile.js";import n from"./base/dists/normal/cdf.js";import s from"./../math/base/special/sqrt.js";import o from"./../math/base/special/abs.js";import m from"./base/mean.js";import l from"./../constants/math/float64-ninf.js";import p from"./../constants/math/float64-pinf.js";import f from"./../assert/is-probability.js";import u from"./../assert/is-number.js";import d from"./../assert/is-plain-object.js";import h from"./../assert/is-string.js";import c from"./../assert/is-nan.js";import v from"./../assert/has-own-property.js";import b from"./../assert/is-positive-integer.js";import g from"./../assert/is-boolean.js";import w from"./../math/base/special/roundn.js";var j=f.isPrimitive,y=u.isPrimitive,T=d,E=h.isPrimitive,V=c,O=v;function k(e,i){if(!T(i))return new TypeError("invalid argument. Options argument must be an object. Value: `"+i+"`.");if(O(i,"alpha")){if(e.alpha=i.alpha,!y(e.alpha)||V(e.alpha))return new TypeError("invalid option. `alpha` option must be a number primitive. Option: `"+e.alpha+"`.");if(!j(e.alpha))return new RangeError("invalid option. `alpha` option must be a number in the range 0 to 1. Option: `"+e.alpha+"`.")}return O(i,"alternative")&&(e.alternative=i.alternative,!E(e.alternative))?new TypeError("invalid option. `alternative` option must be a string primitive. Option: `"+e.alternative+"`."):O(i,"difference")&&(e.difference=i.difference,!y(e.difference)||V(e.difference))?new TypeError("invalid option. `difference` option must be a number primitive. Option: `"+e.difference+"`."):null}var P=b,x=d,q=g.isPrimitive,F=v,R=w;function z(e){var i,t,r;if(t=4,i=!0,arguments.length>0){if(!x(e))throw new TypeError("invalid argument. First argument must be an options object. Value: `"+e+"`.");if(F(e,"digits")){if(!P(e.digits))throw new TypeError("invalid option. `digits` option must be a positive integer. Option: `"+e.digits+"`.");t=e.digits}if(F(e,"decision")){if(!q(e.decision))throw new TypeError("invalid option. `decision` option must be a boolean primitive. Option: `"+e.decision+"`.");i=e.decision}}switch(r="",r+=this.method,r+="\n\n",r+="Alternative hypothesis: ",r+="True difference in means is ",this.alternative){case"less":r+="less than ";break;case"greater":r+="greater than ";break;case"two-sided":default:r+="not equal to "}return r+=this.nullValue,r+="\n\n",r+=" pValue: "+R(this.pValue,-t)+"\n",r+=" statistic: "+R(this.statistic,-t)+"\n",r+=" "+100*(1-this.alpha)+"% confidence interval: ["+R(this.ci[0],-t)+","+R(this.ci[1],-t)+"]",r+="\n\n",i&&(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 A=e.primitives,D=i,I=t.isPrimitive,S=r,B=a.factory,C=n.factory,G=s,H=o,J=m,K=l,L=p,M=k,N=z,Q=B(0,1),U=C(0,1);function W(e,i,t,r,a){var n,s,o,m,l,p,f,u,d,h,c,v,b,g;if(!D(e)&&!A(e))throw new TypeError("invalid argument. First argument `x` must be a numeric array. Value: `"+e+"`.");if(!D(i)&&!A(i))throw new TypeError("invalid argument. Second argument `y` must be a numeric array. Value: `"+i+"`.");if(!I(t))throw new TypeError("invalid argument. Third argument `sigmax` must be a positive number. Value: `"+t+"`.");if(!I(r))throw new TypeError("invalid argument. Third argument `sigmay` must be a positive number. Value: `"+r+"`.");if(f={},a&&(c=M(f,a)))throw c;switch(p=f.difference||0,s=void 0===f.alpha?.05:f.alpha,b=e.length,g=i.length,n=G(t*t/b+r*r/g),d=((o=J(b,e,1))-(m=J(g,i,1))-p)/n,h=f.alternative||"two-sided"){case"two-sided":u=2*U(-H(d)),(l=[d-Q(1-s/2),d+Q(1-s/2)])[0]=p+l[0]*n,l[1]=p+l[1]*n;break;case"greater":u=1-U(d),(l=[d-Q(1-s),L])[0]=p+l[0]*n;break;case"less":u=U(d),(l=[K,d+Q(1-s)])[1]=p+l[1]*n;break;default:throw new Error("Invalid option. `alternative` must be either `two-sided`, `less` or `greater`. Value: `"+h+"`")}return S(v={},"rejected",u<=s),S(v,"alpha",s),S(v,"pValue",u),S(v,"statistic",d),S(v,"ci",l),S(v,"alternative",h),S(v,"method","Two-sample z-test"),S(v,"nullValue",p),S(v,"xmean",o),S(v,"ymean",m),S(v,"print",N),v}var X=W;export default X;
//# sourceMappingURL=ztest2.js.map