UNPKG

@stdlib/esm

Version:

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

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