@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 4.74 kB
JavaScript
// 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-number-array.js";import e from"./../assert/is-typed-array-like.js";import t from"./../assert/is-array.js";import n from"./../utils/define-read-only-property.js";import i from"./../assert/has-own-property.js";import a from"./base/dists/f/cdf.js";import o from"./../utils/copy.js";import s from"./../assert/is-plain-object.js";import l from"./../assert/is-number.js";import m from"./../assert/is-nan.js";import p from"./incr/stdev.js";import u from"./../assert/is-positive-integer.js";import f from"./../math/base/special/roundn.js";import g from"./../string/repeat.js";import h from"./../math/base/special/max.js";import d from"./../assert/is-boolean.js";var c=.05,v={alpha:c},j=i,w=s,y=l.isPrimitive,b=m;function S(r,e){if(!w(e))return new TypeError("invalid argument. Options must be an object. Value: `"+e+"`.");if(j(e,"alpha")){if(r.alpha=e.alpha,!y(r.alpha)||b(r.alpha))return new TypeError("invalid option. `alpha` option must be a number primitive. Option: `"+r.alpha+"`.");if(r.alpha<0||r.alpha>1)return new RangeError("invalid option. `alpha` must be a number in [0,1].")}return null}var E={numeric:!0};function V(r,e){return String(r).localeCompare(String(e),void 0,E)}function T(r){var e,t,n,i,a;for(e=(t=Array.prototype.slice.call(r)).length,t.sort(V),i=1,a=0;i<e;i++)n=t[i],t[a]!==n&&(t[a+=1]=n);return t.length=a+1,t}var A=p;function O(r,e,t){var n,i,a,o,s,l,m;for(i=t.length,n={},s=0;s<i;s++)for(a=A(),n[t[s]]={mean:0,sampleSize:0,SD:a},l=0;l<r.length;l++)e[l]===t[s]&&(n[t[s]].SD=a(r[l]));for(l=0;l<r.length;l++)n[e[l]].mean+=r[l],n[e[l]].sampleSize+=1;for(m=0;m<i;m++)o=n[t[m]].mean/n[t[m]].sampleSize,n[t[m]].mean=o;return n}function R(r){var e,t,n;for(t=0,e=r.length,n=0;n<e;n++)t+=(r[n]-t)/(n+1);return t}var F=u,z=s,N=i,q=f,x=g,M=h,P=d.isPrimitive;function D(r){return r<=0?"":x(" ",r)}function H(r){return function(e){var t,n,i,a,o,s,l,m,p,u,f,g,h,d;if(h=4,n=!0,arguments.length>0){if(!z(e))throw new TypeError("invalid argument. First argument must be an options object. Value: `"+e+"`.");if(N(e,"digits")){if(!F(e.digits))throw new TypeError("invalid option. `digits` option must be a positive integer. Option: `"+e.digits+"`.");h=e.digits}if(N(e,"decision")){if(!P(e.decision))throw new TypeError("invalid option. `decision` option must be a boolean primitive. Option: `"+e.decision+"`.");n=e.decision}}g=-h,d="",d+=r.method,d+="\n\n",d+="Null Hypothesis: All Means Equal",d+="\n",d+="Alternate Hypothesis: At Least one Mean not Equal",d+="\n\n",o=q(r.treatment.ss,g).toString(),f=q(r.error.ss,g).toString(),i=q(r.treatment.ms,g).toString(),p=q(r.error.ms,g).toString(),a=r.treatment.df.toString(),u=r.error.df.toString(),t=q(r.statistic,g).toString(),s=M(M(a.length,u.length),2),l=M(M(o.length,f.length),2),m=M(M(i.length,p.length),3),d+=" ",d+="df",d+=D(1+s),d+="SS",d+=D(2+l),d+="MS",d+=D(1+m),d+="F Score",d+=D(M(7,t.length)-7+2),d+="P Value",d+="\n",d+="Treatment",d+=D(5),d+=r.treatment.df,d+=D(3+s-a.length),d+=o,d+=D(4+l-o.length),d+=i,d+=D(3+m-i.length),d+=t,d+=D(M(7,t.length)-t.length+2),d+=q(r.pValue,g),d+="\n",d+="Errors",d+=" ",d+=r.error.df,d+=D(3+s-u.length),d+=f,d+=D(4+l-f.length),d+=p,n&&(d+="\n\n",r.rejected?(d+="Reject Null: ",d+=q(r.pValue,g),d+=" <= ",d+=r.alpha):(d+="Fail to Reject Null: ",d+=q(r.pValue,g),d+=" >= ",d+=r.alpha));return d}}var k=r.primitives,C=e,L=t,W=n,B=i,G=a,I=o,J=v,K=S,Q=T,U=O,X=R,Y=H;function Z(r,e,t){var n,i,a,o,s,l,m,p,u,f,g,h,d,c,v,j,w,y,b,S;if(!C(r)&&!k(r))throw new TypeError("invalid argument. First argument must be a numeric array. Value: `"+r+"`.");if(j=I(J),arguments.length>2&&(w=K(j,t)))throw w;if((c=r.length)<=1)throw new RangeError("invalid argument. First argument must have at least two elements. Value: `"+r+"`.");if(!L(e))throw new TypeError("invalid argument. Second argument must be an array. Value: `"+f+"`.");if((p=(f=Q(e)).length)<=1)throw new RangeError("invalid argument. Second argument must contain at least two unique elements. Value: `"+f+"`.");if(c!==e.length)throw new RangeError("invalid arguments. Arguments `x` and `factor` must be arrays of the same length.");for(o=0,a=0,g=U(r,e,f),m=X(r),S=0;S<c;S++)o+=b=(r[S]-m)*(r[S]-m);for(l in b=0,g)B(g,l)&&(b=(g[l].mean-m)*(g[l].mean-m),a+=g[l].sampleSize*b);return v=1-G(u=(n=a/(h=p-1))/(i=(s=o-a)/(d=c-p)),h,d),y={},W(l={},"df",h),W(l,"ss",a),W(l,"ms",n),W(y,"treatment",l),W(w={},"df",d),W(w,"ss",s),W(w,"ms",i),W(y,"error",w),W(y,"statistic",u),W(y,"pValue",v),W(y,"means",g),W(y,"method","One-Way ANOVA"),W(y,"alpha",j.alpha),W(y,"rejected",v<=j.alpha),W(y,"print",Y(y)),y}var $=Z;export default $;
//# sourceMappingURL=anova1.js.map