UNPKG

@stdlib/esm

Version:

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

3 lines 4.72 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 t from"./../assert/is-typed-array-like.js";import r from"./../utils/define-read-only-property.js";import i from"./base/dists/normal/quantile.js";import a from"./base/dists/normal/cdf.js";import o from"./../math/base/special/atanh.js";import s from"./../math/base/special/tanh.js";import n from"./base/dists/t/cdf.js";import l from"./../math/base/special/sqrt.js";import m from"./../math/base/special/min.js";import p from"./../assert/is-positive-integer.js";import h from"./../assert/is-plain-object.js";import c from"./../assert/is-boolean.js";import f from"./../assert/has-own-property.js";import u from"./../math/base/special/roundn.js";import d from"./../math/base/special/max.js";import v from"./base/variance.js";import b from"./base/mean.js";import g from"./../assert/is-number.js";import w from"./../assert/is-nan.js";import j from"./../utils/index-of.js";var y=p,E=h,T=c.isPrimitive,k=f,V=u;function x(e){var t,r,i;if(r=4,t=!0,arguments.length>0){if(!E(e))throw new TypeError("invalid argument. First argument must be an options object. Value: `"+e+"`.");if(k(e,"digits")){if(!y(e.digits))throw new TypeError("invalid option. `digits` option must be a positive integer. Option: `"+e.digits+"`.");r=e.digits}if(k(e,"decision")){if(!T(e.decision))throw new TypeError("invalid option. `decision` option must be a boolean primitive. Option: `"+e.decision+"`.");t=e.decision}}switch(i="",i+=this.method,i+="\n\n",i+="Alternative hypothesis: ",i+="True correlation coefficient is ",this.alternative){case"less":i+="less than ";break;case"greater":i+="greater than ";break;case"two-sided":default:i+="not equal to "}return i+=this.nullValue,i+="\n\n",i+=" pValue: "+V(this.pValue,-r)+"\n",i+=" statistic: "+V(this.statistic,-r)+"\n",i+=" "+100*(1-this.alpha)+"% confidence interval: ["+V(this.ci[0],-r)+","+V(this.ci[1],-r)+"]",i+="\n\n",t&&(i+="Test Decision: ",this.rejected?i+="Reject null in favor of alternative at "+100*this.alpha+"% significance level":i+="Fail to reject null in favor of alternative at "+100*this.alpha+"% significance level",i+="\n"),i}var O=d,F=m,P=l,q=v,A=b;function z(e,t){var r,i,a,o,s,n,l;for(l=e.length,o=A(l,e,1),s=A(l,t,1),a=0,n=0;n<l;n++)a+=e[n]*t[n];return i=a-l*o*s,r=(l-1)*P(q(l,1,e,1))*P(q(l,1,t,1)),O(F(i/r,1),-1)}var D=g.isPrimitive,R=h,S=w,B=j,C=f,G=["two-sided","less","greater"];function H(e,t){return R(t)?C(t,"alpha")&&(e.alpha=t.alpha,!D(e.alpha)||S(e.alpha)||e.alpha<0||e.alpha>1)?new TypeError("invalid option. `alpha` option must be a number in `[0,1]`. Option: `"+e.alpha+"`."):C(t,"alternative")&&(e.alternative=t.alternative,-1===B(G,e.alternative))?new TypeError('invalid option. `alternative` option must be one of the following: "'+G.join('", "')+'". Option: `'+e.alternative+"`."):C(t,"rho")&&(e.rho=t.rho,!D(e.rho)||S(e.rho)||e.rho<-1||e.rho>1)?new TypeError("invalid option. `rho` option must be a number in [-1,1]. Option: `"+e.rho+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+t+"`.")}var I=e.primitives,J=t,K=r,L=i.factory,M=a.factory,N=o,Q=s,U=n,W=l,X=m,Y=x,Z=z,$=H,_=L(0,1),ee=M(0,1);function te(e,t,r){var i,a,o,s,n,l,m,p,h,c,f,u,d,v,b,g;if(!J(e)&&!I(e))throw new TypeError("invalid argument. First argument `x` must be a numeric array. Value: `"+e+"`.");if(!J(t)&&!I(t))throw new TypeError("invalid argument. Second argument `y` must be a numeric array. Value: `"+t+"`.");if((v=e.length)!==t.length)throw new Error("invalid arguments. Arguments `x` and `y` must be arrays of the same length");if(s={},r&&(p=$(s,r)))throw p;if(a=void 0===s.alpha?.05:s.alpha,v<4)throw new Error("not enough observations. `x` and `y` must contain at least four observations.");if(c=void 0===s.rho?0:s.rho,m=void 0===s.alternative?"two-sided":s.alternative,b=Z(e,t),g=N(b),d=1/W(v-3),0===c)switch(i="t-test for Pearson correlation coefficient",l=W(u=v-2)*b/W(1-b*b),m){case"greater":n=1-U(l,u);break;case"less":n=U(l,u);break;case"two-sided":default:n=2*X(U(l,u),1-U(l,u))}else switch(i="Fisher's z transform test for Pearson correlation coefficient",l=(g-N(c))*W(v-3),m){case"greater":n=ee(-l);break;case"less":n=1-ee(-l);break;case"two-sided":default:n=2*X(ee(-l),1-ee(-l))}switch(m){case"greater":o=[Q(g-d*_(1-a)),1];break;case"less":o=[-1,Q(g+d*_(1-a))];break;case"two-sided":default:f=d*_(1-a/2),o=[Q(g-f),Q(g+f)]}return K(h={},"rejected",n<=a),K(h,"alpha",a),K(h,"pValue",n),K(h,"statistic",l),K(h,"ci",o),K(h,"alternative",m),K(h,"method",i),K(h,"nullValue",c),K(h,"pcorr",b),K(h,"print",Y),h}var re=te;export default re; //# sourceMappingURL=pcorrtest.js.map