@stdlib/stats-wilcoxon 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +19 -42
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/lib/validate.js +6 -3
- package/package.json +23 -23
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -209,7 +209,7 @@ table = out.print();
|
|
|
209
209
|
*/
|
|
210
210
|
```
|
|
211
211
|
|
|
212
|
-
By default, all zero-differences are discarded before calculating the ranks. Set `zeroMethod` to `pratt` when you wish differences of zero to be used in the rank calculation but then drop them or to `zsplit` when differences of zero are shall be used in the ranking procedure and the ranks then split between positive and negative ones.
|
|
212
|
+
By default, all zero-differences are discarded before calculating the ranks. Set `zeroMethod` to `pratt` when you wish differences of zero to be used in the rank calculation but then drop them or to `zsplit` when differences of zero are shall be used in the ranking procedure and the ranks then split between positive and negative ones.
|
|
213
213
|
|
|
214
214
|
```javascript
|
|
215
215
|
var arr = [ 0, 2, 3, -1, -4, 0, 0, 8, 9 ];
|
|
@@ -243,21 +243,14 @@ out = wilcoxon( arr, {
|
|
|
243
243
|
By default, the test uses the exact distribution of the rank statistic to calculate the critical values for the test in case of no ties and no zero-differences. Since it is more computationally efficient, starting with fifty observations a normal approximation is employed. If you would like the test to use the correct distribution even for larger samples, set the `exact` option to `true`.
|
|
244
244
|
|
|
245
245
|
```javascript
|
|
246
|
-
var normal = require( '@stdlib/random-
|
|
247
|
-
var rnorm;
|
|
248
|
-
var arr;
|
|
249
|
-
var out;
|
|
250
|
-
var i;
|
|
246
|
+
var normal = require( '@stdlib/random-array-normal' );
|
|
251
247
|
|
|
252
|
-
rnorm = normal( 0.0, 4.0, {
|
|
248
|
+
var rnorm = normal.factory( 0.0, 4.0, {
|
|
253
249
|
'seed': 100
|
|
254
250
|
});
|
|
255
|
-
arr =
|
|
256
|
-
for ( i = 0; i < arr.length; i++ ) {
|
|
257
|
-
arr[ i ] = rnorm();
|
|
258
|
-
}
|
|
251
|
+
var arr = rnorm( 100 );
|
|
259
252
|
|
|
260
|
-
out = wilcoxon( arr, {
|
|
253
|
+
var out = wilcoxon( arr, {
|
|
261
254
|
'exact': false
|
|
262
255
|
});
|
|
263
256
|
/* e.g., returns
|
|
@@ -287,21 +280,14 @@ out = wilcoxon( arr, {
|
|
|
287
280
|
By default, when using the normal approximation, the test uses a continuity correction, which adjusts the Wilcoxon rank statistic by `0.5` towards the mean. To disable this correction, set `correction` to `false`.
|
|
288
281
|
|
|
289
282
|
```javascript
|
|
290
|
-
var normal = require( '@stdlib/random-
|
|
291
|
-
var rnorm;
|
|
292
|
-
var arr;
|
|
293
|
-
var out;
|
|
294
|
-
var i;
|
|
283
|
+
var normal = require( '@stdlib/random-array-normal' );
|
|
295
284
|
|
|
296
|
-
rnorm = normal( 0.0, 4.0, {
|
|
285
|
+
var rnorm = normal.factory( 0.0, 4.0, {
|
|
297
286
|
'seed': 100
|
|
298
287
|
});
|
|
299
|
-
arr =
|
|
300
|
-
for ( i = 0; i < arr.length; i++ ) {
|
|
301
|
-
arr[ i ] = rnorm();
|
|
302
|
-
}
|
|
288
|
+
var arr = rnorm( 100 );
|
|
303
289
|
|
|
304
|
-
out = wilcoxon( arr, {
|
|
290
|
+
var out = wilcoxon( arr, {
|
|
305
291
|
'correction': false
|
|
306
292
|
});
|
|
307
293
|
/* e.g., returns
|
|
@@ -339,26 +325,17 @@ out = wilcoxon( arr, {
|
|
|
339
325
|
<!-- eslint no-undef: "error" -->
|
|
340
326
|
|
|
341
327
|
```javascript
|
|
342
|
-
var uniform = require( '@stdlib/random-
|
|
328
|
+
var uniform = require( '@stdlib/random-array-discrete-uniform' );
|
|
343
329
|
var wilcoxon = require( '@stdlib/stats-wilcoxon' );
|
|
344
330
|
|
|
345
|
-
var
|
|
346
|
-
var runif;
|
|
347
|
-
var arr;
|
|
348
|
-
var out;
|
|
349
|
-
var i;
|
|
350
|
-
|
|
351
|
-
runif = uniform( -50.0, 50.0, {
|
|
331
|
+
var runif = uniform.factory( -50.0, 50.0, {
|
|
352
332
|
'seed': 37827
|
|
353
333
|
});
|
|
354
|
-
arr =
|
|
355
|
-
for ( i = 0; i < arr.length; i++ ) {
|
|
356
|
-
arr[ i ] = runif();
|
|
357
|
-
}
|
|
334
|
+
var arr = runif( 100 );
|
|
358
335
|
|
|
359
336
|
// Test whether distribution is symmetric around zero:
|
|
360
|
-
out = wilcoxon( arr );
|
|
361
|
-
table = out.print();
|
|
337
|
+
var out = wilcoxon( arr );
|
|
338
|
+
var table = out.print();
|
|
362
339
|
/* e.g., returns
|
|
363
340
|
One-Sample Wilcoxon signed rank test
|
|
364
341
|
|
|
@@ -432,7 +409,7 @@ See [LICENSE][stdlib-license].
|
|
|
432
409
|
|
|
433
410
|
## Copyright
|
|
434
411
|
|
|
435
|
-
Copyright © 2016-
|
|
412
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
436
413
|
|
|
437
414
|
</section>
|
|
438
415
|
|
|
@@ -445,8 +422,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
445
422
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-wilcoxon.svg
|
|
446
423
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-wilcoxon
|
|
447
424
|
|
|
448
|
-
[test-image]: https://github.com/stdlib-js/stats-wilcoxon/actions/workflows/test.yml/badge.svg?branch=v0.2.
|
|
449
|
-
[test-url]: https://github.com/stdlib-js/stats-wilcoxon/actions/workflows/test.yml?query=branch:v0.2.
|
|
425
|
+
[test-image]: https://github.com/stdlib-js/stats-wilcoxon/actions/workflows/test.yml/badge.svg?branch=v0.2.3
|
|
426
|
+
[test-url]: https://github.com/stdlib-js/stats-wilcoxon/actions/workflows/test.yml?query=branch:v0.2.3
|
|
450
427
|
|
|
451
428
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-wilcoxon/main.svg
|
|
452
429
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-wilcoxon?branch=main
|
|
@@ -458,8 +435,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
458
435
|
|
|
459
436
|
-->
|
|
460
437
|
|
|
461
|
-
[chat-image]: https://img.shields.io/
|
|
462
|
-
[chat-url]: https://
|
|
438
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
439
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
463
440
|
|
|
464
441
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
465
442
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var V=function(e,i){return function(){return i||e((i={exports:{}}).exports,i),i.exports}};var
|
|
1
|
+
"use strict";var V=function(e,i){return function(){return i||e((i={exports:{}}).exports,i),i.exports}};var Z=V(function(ze,W){"use strict";var C=require("@stdlib/array-base-assert-contains").factory,N=require("@stdlib/assert-is-boolean").isPrimitive,_=require("@stdlib/assert-is-number").isPrimitive,te=require("@stdlib/assert-is-plain-object"),B=require("@stdlib/assert-is-string").isPrimitive,j=require("@stdlib/assert-is-nan"),E=require("@stdlib/assert-has-own-property"),d=require("@stdlib/string-format"),I=["two-sided","less","greater"],U=["pratt","wilcox","zsplit"],ne=C(I),oe=C(U);function se(e,i){if(!te(i))return new TypeError(d("invalid argument. Options argument must be an object. Value: `%s`.",i));if(E(i,"alpha")){if(e.alpha=i.alpha,!_(e.alpha)||j(e.alpha))return new TypeError(d("invalid option. `%s` option must be a number. Option: `%s`.","alpha",e.alpha));if(e.alpha<0||e.alpha>1)return new RangeError(d("invalid option. `%s` option must be a number on the interval: [0, 1]. Option: `%f`.","alpha",e.alpha))}if(E(i,"alternative")){if(e.alternative=i.alternative,!B(e.alternative))return new TypeError(d("invalid option. `%s` option must be a string. Option: `%s`.","alternative",e.alternative));if(!ne(e.alternative))return new Error(d('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"alternative",I.join('", "'),e.alternative))}if(E(i,"correction")&&(e.correction=i.correction,!N(e.correction)||j(e.correction)))return new TypeError(d("invalid option. `%s` option must be a boolean. Option: `%s`.","correction",e.alpha));if(E(i,"exact")&&(e.exact=i.exact,!N(e.exact)||j(e.exact)))return new TypeError(d("invalid option. `%s` option must be a boolean. Option: `%s`.","exact",e.alpha));if(E(i,"mu")&&(e.mu=i.mu,!_(e.mu)||j(e.mu)))return new TypeError(d("invalid option. `%s` option must be a number. Option: `%s`.","mu",e.mu));if(E(i,"zeroMethod")){if(e.zeroMethod=i.zeroMethod,!B(e.zeroMethod))return new TypeError(d("invalid option. `%s` option must be a string. Option: `%s`.","zeroMethod",e.alternative));if(!oe(e.zeroMethod))return new Error(d('invalid option. `%s` option must be one of the following: "%s". Option: `%s`.',"zeroMethod",U.join('", "'),e.zeroMethod))}return null}W.exports=se});var G=V(function(Me,H){"use strict";function le(e,i){return e-i}function ue(e){var i,o,a,u;for(e=e.slice(),e.sort(le),i=e.length,a=1,u=0;a<i;a++)o=e[a],e[u]!==o&&(u+=1,e[u]=o);return e.length=u+1,e}H.exports=ue});var X=V(function(Ve,Q){"use strict";var ve=require("@stdlib/assert-is-positive-integer"),fe=require("@stdlib/assert-is-plain-object"),ce=require("@stdlib/assert-is-boolean").isPrimitive,J=require("@stdlib/assert-has-own-property"),K=require("@stdlib/math-base-special-roundn"),D=require("@stdlib/string-format");function he(e){var i,o,a;if(o=4,i=!0,arguments.length>0){if(!fe(e))throw new TypeError(D("invalid argument. First argument must be an object. Value: `%s`.",e));if(J(e,"digits")){if(!ve(e.digits))throw new TypeError(D("invalid option. `%s` option must be a positive integer. Option: `%s`.","digits",e.digits));o=e.digits}if(J(e,"decision")){if(!ce(e.decision))throw new TypeError(D("invalid option. `%s` option must be a boolean. Option: `%s`.","decision",e.decision));i=e.decision}}switch(a="",a+=this.method,a+="\n\n",a+="Alternative hypothesis: ",this.method==="Paired Wilcoxon signed rank test"?a+="Median of the difference `x - y` is ":a+="Median of `x` is ",this.alternative){case"less":a+="less than ";break;case"greater":a+="greater than ";break;default:a+="not equal to ";break}return a+=this.nullValue,a+="\n\n",a+=" pValue: "+K(this.pValue,-o)+"\n",a+=" statistic: "+K(this.statistic,-o)+"\n",a+="\n",i&&(a+="Test Decision: ",this.rejected?a+="Reject null in favor of alternative at "+this.alpha*100+"% significance level":a+="Fail to reject null in favor of alternative at "+this.alpha*100+"% significance level",a+="\n"),a}Q.exports=he});var ae=V(function(je,ie){"use strict";var Y=require("@stdlib/assert-is-number-array").primitives,$=require("@stdlib/assert-is-typed-array-like"),p=require("@stdlib/utils-define-read-only-property"),de=require("@stdlib/assert-is-plain-object"),me=require("@stdlib/stats-ranks"),ge=require("@stdlib/stats-base-dists-normal-cdf").factory,k=require("@stdlib/stats-base-dists-signrank-cdf"),pe=require("@stdlib/utils-tabulate"),we=require("@stdlib/math-base-special-signum"),be=require("@stdlib/math-base-special-sqrt"),ee=require("@stdlib/math-base-special-abs"),re=require("@stdlib/array-float64"),L=require("@stdlib/string-format"),qe=Z(),ye=G(),Ee=X(),S=ge(0,1);function xe(){var e,i,o,a,u,O,T,l,A,z,m,v,f,w,P,t,F,c,R,q,M,y,n,r,g,x,b,s,h;if(s=arguments[0],!$(s)&&!Y(s))throw new TypeError(L("invalid argument. First argument must be a numeric array. Value: `%s`.",s));if(t=s.length,arguments.length>1)if(de(arguments[1]))o=arguments[1];else{if(h=arguments[1],!$(h)&&!Y(h))throw new TypeError(L("invalid argument. `%s` argument must be a numeric array. Value: `%s`.","y",h));if(t!==h.length)throw new Error("invalid arguments. First and second arguments must have the same length.");arguments.length>2&&(o=arguments[2])}if(v={},o&&(P=qe(v,o),P))throw P;if(q=v.mu||0,v.correction===void 0?e=!0:e=v.correction,v.alpha===void 0?z=.05:z=v.alpha,t<2)throw new Error(L("invalid argument. First argument must contain at least two elements. Value: `%s`.",s));if(w=v.alternative||"two-sided",i=v.zeroMethod||"wilcox",i==="wilcox"){if(n=[],h)for(r=0;r<t;r++)b=s[r]-h[r]-q,b!==0&&n.push(b);else for(r=0;r<t;r++)s[r]!==0&&n.push(s[r]-q);l=s.length-n.length}else if(n=new re(t),l=0,h)for(r=0;r<t;r++)n[r]=s[r]-h[r]-q,n[r]===0&&(l+=1);else for(r=0;r<t;r++)n[r]=s[r]-q,n[r]===0&&(l+=1);if(l===t)throw new Error("`x` or `x - y` cannot be zero for all elements.");for(t=n.length,R=new re(t),r=0;r<t;r++)R[r]=ee(n[r]);for(g=me(R),T=0,A=0,r=0;r<t;r++)n[r]>0?T+=g[r]:n[r]===0&&(A+=g[r]);if(a=ye(g).length!==g.length,i==="zsplit"&&(T+=A/2),x=T,M=t*(t+1)*.25,y=t*(t+1)*(2*t+1),i==="pratt"){for(F=[],r=0;r<t;r++)n[r]!==0&&F.push(g[r]);g=F,M-=l*(l+1)*.25,y-=l*(l+1)*(2*l+1)}for(u=pe(g),O=0,r=0;r<u.length;r++)u[r][1]>1&&(b=u[r][1],O+=b*(b*b-1));if(O>0&&(y-=.5*O),y=be(y/24),t>50&&!v.exact||l>0||a){if(n=0,e)switch(w){case"two-sided":n=.5*we(x-M);break;case"less":n=-.5;break;default:n=.5;break}f=(x-M-n)/y,w==="two-sided"?m=2*(1-S(ee(f))):w==="greater"?m=1-S(f):m=S(f)}else f=x,w==="two-sided"?f>t*(t+1)/4?m=2*(1-k(f-1,t)):m=2*k(f,t):w==="greater"?m=1-k(f-1,t):m=k(f,t);return c={},p(c,"rejected",m<=z),p(c,"alpha",z),p(c,"pValue",m),p(c,"statistic",x),p(c,"nullValue",q),p(c,"alternative",w),p(c,"method",(h?"Paired":"One-Sample")+" Wilcoxon signed rank test"),p(c,"print",Ee),c}ie.exports=xe});var Oe=ae();module.exports=Oe;
|
|
2
2
|
/**
|
|
3
3
|
* @license Apache-2.0
|
|
4
4
|
*
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/validate.js", "../lib/unique.js", "../lib/print.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar contains = require( '@stdlib/assert-contains' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar ALTERNATIVE_VALUES = [ 'two-sided', 'less', 'greater' ];\nvar ZERO_METHOD_VALUES = [ 'pratt', 'wilcox', 'zsplit' ];\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for validated options\n* @param {Options} options - function options\n* @param {number} [options.alpha] - significance level\n* @param {string} [options.alternative] - alternative hypothesis (`two-sided`, `less` or `greater`)\n* @param {boolean} [options.exact] - whether to force using the exact distribution instead of a normal approximation when there are more than fifty data points\n* @param {boolean} [options.correction] - continuity correction adjusting the Wilcoxon rank statistic by 0.5 towards the mean\n* @param {string} [options.zeroMethod] - method governing how zero-differences are handled (`pratt`, `wilcox` or `zsplit`)\n* @param {number} [options.mu] - mean under H0\n* @returns {(null|Error)} null or an error\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'alpha' ) ) {\n\t\topts.alpha = options.alpha;\n\t\tif ( !isNumber( opts.alpha ) || isnan( opts.alpha ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a number. Option: `%s`.', 'alpha', opts.alpha ) );\n\t\t}\n\t\tif ( opts.alpha < 0.0 || opts.alpha > 1.0 ) {\n\t\t\treturn new RangeError( format( 'invalid option. `%s` option must be a number on the interval: [0, 1]. Option: `%f`.', 'alpha', opts.alpha ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'alternative' ) ) {\n\t\topts.alternative = options.alternative;\n\t\tif ( !isString( opts.alternative ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'alternative', opts.alternative ) );\n\t\t}\n\t\tif ( !contains( ALTERNATIVE_VALUES, opts.alternative ) ) {\n\t\t\treturn new Error( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'alternative', ALTERNATIVE_VALUES.join( '\", \"' ), opts.alternative ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'correction' ) ) {\n\t\topts.correction = options.correction;\n\t\tif ( !isBoolean( opts.correction ) || isnan( opts.correction ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'correction', opts.alpha ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'exact' ) ) {\n\t\topts.exact = options.exact;\n\t\tif (\n\t\t\t!isBoolean( opts.exact ) ||\n\t\t\tisnan( opts.exact )\n\t\t) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'exact', opts.alpha ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'mu' ) ) {\n\t\topts.mu = options.mu;\n\t\tif ( !isNumber( opts.mu ) || isnan( opts.mu ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a number. Option: `%s`.', 'mu', opts.mu ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'zeroMethod' ) ) {\n\t\topts.zeroMethod = options.zeroMethod;\n\t\tif ( !isString( opts.zeroMethod ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'zeroMethod', opts.alternative ) );\n\t\t}\n\t\tif ( !contains( ZERO_METHOD_VALUES, opts.zeroMethod ) ) {\n\t\t\treturn new Error( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'zeroMethod', ZERO_METHOD_VALUES.join( '\", \"' ), opts.zeroMethod ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "\n/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Comparator function to sort values in ascending order.\n*\n* @private\n* @param {number} a - first value\n* @param {number} b - second value\n* @returns {number} difference between `a` and `b`\n*/\nfunction ascending( a, b ) {\n\treturn a - b;\n}\n\n\n// MAIN //\n\n/**\n* Removes duplicate values from a numeric array.\n*\n* @private\n* @param {NumberArray} arr - array to be deduped\n* @returns {NumberArray} deduped array\n*/\nfunction unique( arr ) {\n\tvar len;\n\tvar val;\n\tvar i;\n\tvar j;\n\n\tarr = arr.slice();\n\tarr.sort( ascending );\n\tlen = arr.length;\n\n\t// Loop through the array, only incrementing a pointer when successive values are different. When a succeeding value is different, move the pointer and set the next value. In the trivial case where all array elements are unique, we incur a slight penalty in resetting the element value for each unique value. In other cases, we simply move a unique value to a new position in the array. The end result is a sorted array with unique values.\n\tfor ( i = 1, j = 0; i < len; i++ ) {\n\t\tval = arr[ i ];\n\t\tif ( arr[ j ] !== val ) {\n\t\t\tj += 1;\n\t\t\tarr[ j ] = val;\n\t\t}\n\t}\n\t// Truncate the array:\n\tarr.length = j + 1;\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = unique;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isPositiveInteger = require( '@stdlib/assert-is-positive-integer' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar roundn = require( '@stdlib/math-base-special-roundn' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Pretty-print output of test.\n*\n* @param {Object} [opts] - options object\n* @param {PositiveInteger} [opts.digits=4] - number of digits after the decimal point\n* @param {boolean} [opts.decision=true] - boolean indicating whether to print the test decision\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} formatted output\n*/\nfunction print( opts ) { // eslint-disable-line stdlib/no-redeclare\n\t/* eslint-disable no-invalid-this */\n\tvar decision;\n\tvar dgts;\n\tvar str;\n\n\tdgts = 4;\n\tdecision = true;\n\tif ( arguments.length > 0 ) {\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'digits' ) ) {\n\t\t\tif ( !isPositiveInteger( opts.digits ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'digits', opts.digits ) );\n\t\t\t}\n\t\t\tdgts = opts.digits;\n\t\t}\n\t\tif ( hasOwnProp( opts, 'decision' ) ) {\n\t\t\tif ( !isBoolean( opts.decision ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'decision', opts.decision ) );\n\t\t\t}\n\t\t\tdecision = opts.decision;\n\t\t}\n\t}\n\tstr = '';\n\tstr += this.method;\n\tstr += '\\n\\n';\n\tstr += 'Alternative hypothesis: ';\n\tif ( this.method === 'Paired Wilcoxon signed rank test' ) {\n\t\tstr += 'Median of the difference `x - y` is ';\n\t} else {\n\t\tstr += 'Median of `x` is ';\n\t}\n\tswitch ( this.alternative ) {\n\tcase 'less':\n\t\tstr += 'less than ';\n\t\tbreak;\n\tcase 'greater':\n\t\tstr += 'greater than ';\n\t\tbreak;\n\tcase 'two-sided':\n\tdefault:\n\t\tstr += 'not equal to ';\n\t\tbreak;\n\t}\n\tstr += this.nullValue;\n\tstr += '\\n\\n';\n\tstr += ' pValue: ' + roundn( this.pValue, -dgts ) + '\\n';\n\tstr += ' statistic: ' + roundn( this.statistic, -dgts ) + '\\n';\n\tstr += '\\n';\n\tif ( decision ) {\n\t\tstr += 'Test Decision: ';\n\t\tif ( this.rejected ) {\n\t\t\tstr += 'Reject null in favor of alternative at ' + (this.alpha*100) + '% significance level';\n\t\t} else {\n\t\t\tstr += 'Fail to reject null in favor of alternative at ' + (this.alpha*100) + '% significance level';\n\t\t}\n\t\tstr += '\\n';\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = print;\n", "/* eslint-disable max-statements, max-lines-per-function */\n\n/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumberArray = require( '@stdlib/assert-is-number-array' ).primitives;\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar setReadOnly = require( '@stdlib/utils-define-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar ranks = require( '@stdlib/stats-ranks' );\nvar normalCDF = require( '@stdlib/stats-base-dists-normal-cdf' ).factory;\nvar signrankCDF = require( '@stdlib/stats-base-dists-signrank-cdf' );\nvar tabulate = require( '@stdlib/utils-tabulate' );\nvar signum = require( '@stdlib/math-base-special-signum' );\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar Float64Array = require( '@stdlib/array-float64' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar unique = require( './unique.js' );\nvar print = require( './print.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// VARIABLES //\n\nvar pnorm = normalCDF( 0.0, 1.0 );\n\n\n// MAIN //\n\n/**\n* Computes a Wilcoxon signed rank test.\n*\n* @param {NumericArray} x - data array\n* @param {NumericArray} [y] - optional paired data array\n* @param {Options} [options] - function options\n* @param {number} [options.alpha=0.05] - significance level\n* @param {string} [options.alternative='two-sided'] - alternative hypothesis (`two-sided`, `less`, or `greater`)\n* @param {string} [options.zeroMethod='wilcox'] - method governing how zero-differences are handled (`pratt`, `wilcox`, or `zsplit`)\n* @param {boolean} [options.correction=true] - continuity correction adjusting the Wilcoxon rank statistic by 0.5 towards the mean\n* @param {boolean} [options.exact=false] - whether to force using the exact distribution instead of a normal approximation when there are more than fifty data points\n* @param {number} [options.mu=0] - location parameter under H0\n* @throws {TypeError} `x` must be a numeric array\n* @throws {TypeError} `y` must be a numeric array\n* @throws {TypeError} options must be an object\n* @throws {TypeError} `alpha` option has to be a number\n* @throws {RangeError} `alpha` option has to be a number in the interval `[0,1]`\n* @throws {TypeError} `alternative` option has to be a string\n* @throws {Error} `alternative` option must be `two-sided`, `less`, or `greater`\n* @throws {TypeError} `zeroMethod` option has to be a string\n* @throws {Error} `zeroMethod` option must be `pratt`, `wilcox`, or `zsplit`\n* @throws {TypeError} `correction` option has to be a boolean\n* @throws {TypeError} `exact` option has to be a boolean\n* @throws {TypeError} `mu` option has to be a number\n* @returns {Object} test result object\n*\n* @example\n* var x = [ 6, 8, 14, 16, 23, 24, 28, 29, 41, -48, 49, 56, 60, -67, 75 ];\n* var out = wilcoxon( x, {\n* 'mu': 2\n* });\n*\n* @example\n* var x = [ 6, 8, 14, 16, 23, 24, 28, 29, 41, -48, 49, 56, 60, -67, 75 ];\n* var out = wilcoxon( x, {\n* 'alternative': 'greater'\n* });\n*/\nfunction wilcoxon() {\n\tvar correction;\n\tvar zeroMethod;\n\tvar options;\n\tvar hasTies;\n\tvar counts;\n\tvar repsum;\n\tvar rplus;\n\tvar nzero;\n\tvar rzero;\n\tvar alpha;\n\tvar pval;\n\tvar opts;\n\tvar stat;\n\tvar alt;\n\tvar err;\n\tvar len;\n\tvar tmp;\n\tvar out;\n\tvar ad;\n\tvar mu;\n\tvar mn;\n\tvar se;\n\tvar d;\n\tvar i;\n\tvar r;\n\tvar T;\n\tvar v;\n\tvar x;\n\tvar y;\n\n\tx = arguments[ 0 ];\n\tif ( !isTypedArrayLike( x ) && !isNumberArray( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a numeric array. Value: `%s`.', x ) );\n\t}\n\tlen = x.length;\n\tif ( arguments.length > 1 ) {\n\t\tif ( isObject( arguments[ 1 ] ) ) {\n\t\t\toptions = arguments[ 1 ];\n\t\t} else {\n\t\t\ty = arguments[ 1 ];\n\t\t\tif ( !isTypedArrayLike( y ) && !isNumberArray( y ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. `%s` argument must be a numeric array. Value: `%s`.', 'y', y ) );\n\t\t\t}\n\t\t\tif ( len !== y.length ) {\n\t\t\t\tthrow new Error( 'invalid arguments. First and second arguments must have the same length.' );\n\t\t\t}\n\t\t\tif ( arguments.length > 2 ) {\n\t\t\t\toptions = arguments[ 2 ];\n\t\t\t}\n\t\t}\n\t}\n\topts = {};\n\tif ( options ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tmu = opts.mu || 0.0;\n\tif ( opts.correction === void 0 ) {\n\t\tcorrection = true;\n\t} else {\n\t\tcorrection = opts.correction;\n\t}\n\tif ( opts.alpha === void 0 ) {\n\t\talpha = 0.05;\n\t} else {\n\t\talpha = opts.alpha;\n\t}\n\tif ( len < 2 ) {\n\t\tthrow new Error( format( 'invalid argument. First argument must contain at least two elements. Value: `%s`.', x ) );\n\t}\n\talt = opts.alternative || 'two-sided';\n\tzeroMethod = opts.zeroMethod || 'wilcox';\n\n\tif ( zeroMethod === 'wilcox' ) {\n\t\t// Only keep all non-zero differences:\n\t\td = [];\n\t\tif ( y ) {\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tv = ( x[ i ] - y[ i ] ) - mu;\n\t\t\t\tif ( v !== 0 ) {\n\t\t\t\t\td.push( v );\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tif ( x[ i ] !== 0 ) {\n\t\t\t\t\td.push( x[ i ] - mu );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tnzero = x.length - d.length;\n\t} else {\n\t\td = new Float64Array( len );\n\t\tnzero = 0;\n\t\tif ( y ) {\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\td[ i ] = ( x[ i ] - y[ i ] ) - mu;\n\t\t\t\tif ( d[ i ] === 0 ) {\n\t\t\t\t\tnzero += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\td[ i ] = x[ i ] - mu;\n\t\t\t\tif ( d[ i ] === 0 ) {\n\t\t\t\t\tnzero += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif ( nzero === len ) {\n\t\tthrow new Error( '`x` or `x - y` cannot be zero for all elements.' );\n\t}\n\t// Update length after potentially discarding zero values:\n\tlen = d.length;\n\tad = new Float64Array( len );\n\tfor ( i = 0; i < len; i++ ) {\n\t\tad[ i ] = abs( d[ i ] );\n\t}\n\tr = ranks( ad );\n\trplus = 0;\n\trzero = 0;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tif ( d[ i ] > 0 ) {\n\t\t\trplus += r[ i ];\n\t\t}\n\t\telse if ( d[ i ] === 0 ) {\n\t\t\trzero += r[ i ];\n\t\t}\n\t}\n\thasTies = unique( r ).length !== r.length;\n\tif ( zeroMethod === 'zsplit' ) {\n\t\trplus += rzero / 2.0;\n\t}\n\tT = rplus;\n\tmn = len * ( len + 1.0 ) * 0.25;\n\tse = len * ( len + 1.0 ) * ( ( 2.0 * len ) + 1.0 );\n\n\tif ( zeroMethod === 'pratt' ) {\n\t\ttmp = [];\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( d[ i ] !== 0 ) {\n\t\t\t\ttmp.push( r[ i ] );\n\t\t\t}\n\t\t}\n\t\tr = tmp;\n\t\tmn -= nzero * ( nzero + 1.0 ) * 0.25;\n\t\tse -= nzero * ( nzero + 1.0 ) * ( ( 2.0 * nzero ) + 1.0 );\n\t}\n\tcounts = tabulate( r );\n\trepsum = 0;\n\tfor ( i = 0; i < counts.length; i++ ) {\n\t\tif ( counts[ i ][ 1 ] > 1 ) {\n\t\t\tv = counts[ i ][ 1 ];\n\t\t\trepsum += v * ( (v*v) - 1 );\n\t\t}\n\t}\n\tif ( repsum > 0 ) {\n\t\t// Correction for repeated values:\n\t\tse -= 0.5 * repsum;\n\t}\n\tse = sqrt( se / 24.0 );\n\n\tif (\n\t\t( len > 50 && !opts.exact ) ||\n\t\tnzero > 0 ||\n\t\thasTies\n\t) {\n\t\td = 0.0;\n\t\tif ( correction ) {\n\t\t\tswitch ( alt ) {\n\t\t\tcase 'two-sided':\n\t\t\t\td = 0.5 * signum( T - mn );\n\t\t\t\tbreak;\n\t\t\tcase 'less':\n\t\t\t\td = -0.5;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\td = 0.5;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t// Compute test statistic and p-value using normal approximation:\n\t\tstat = ( T - mn - d ) / se;\n\t\tif ( alt === 'two-sided' ) {\n\t\t\tpval = 2.0 * ( 1.0 - pnorm( abs( stat ) ) );\n\t\t} else if ( alt === 'greater' ) {\n\t\t\tpval = 1.0 - pnorm( stat );\n\t\t} else {\n\t\t\tpval = pnorm( stat );\n\t\t}\n\t} else {\n\t\t// Compute test statistic and p-value using exact critical values:\n\t\tstat = T;\n\t\tif ( alt === 'two-sided' ) {\n\t\t\tif ( stat > ( len * ( len+1 ) / 4 ) ) {\n\t\t\t\tpval = 2.0 * ( 1 - signrankCDF( stat - 1, len ) );\n\t\t\t} else {\n\t\t\t\tpval = 2.0 * signrankCDF( stat, len );\n\t\t\t}\n\t\t} else if ( alt === 'greater' ) {\n\t\t\tpval = 1.0 - signrankCDF( stat - 1, len );\n\t\t} else {\n\t\t\tpval = signrankCDF( stat, len );\n\t\t}\n\t}\n\tout = {};\n\tsetReadOnly( out, 'rejected', pval <= alpha );\n\tsetReadOnly( out, 'alpha', alpha );\n\tsetReadOnly( out, 'pValue', pval );\n\tsetReadOnly( out, 'statistic', T );\n\tsetReadOnly( out, 'nullValue', mu );\n\tsetReadOnly( out, 'alternative', alt );\n\tsetReadOnly( out, 'method', ( ( y ) ? 'Paired' : 'One-Sample' ) + ' Wilcoxon signed rank test' );\n\tsetReadOnly( out, 'print', print );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = wilcoxon;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute a Wilcoxon signed-rank test.\n*\n* @module @stdlib/stats-wilcoxon\n*\n* @example\n* var normal = require( '@stdlib/random-base-normal' ).factory;\n* var wilcoxon = require( '@stdlib/stats-wilcoxon' );\n*\n* var rnorm;\n* var out;\n* var i;\n* var x;\n* var y;\n*\n* rnorm = normal( 1.0, 2.0, {\n* 'seed': 786\n* });\n*\n* // One-sample Wilcoxon signed rank test:\n* x = new Array( 100 );\n* for ( i = 0; i < x.length; i++ ) {\n* x[ i ] = rnorm();\n* }\n* out = wilcoxon( x );\n*\n* // Paired Wilcoxon signed rank test:\n* x = new Array( 100 );\n* y = new Array( 100 );\n* for ( i = 0; i < x.length; i++ ) {\n* x[ i ] = rnorm();\n* y[ i ] = rnorm();\n* }\n* out = wilcoxon( x, y );\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,
|
|
6
|
-
"names": ["require_validate", "__commonJSMin", "exports", "module", "contains", "isBoolean", "isNumber", "isObject", "isString", "isnan", "hasOwnProp", "format", "ALTERNATIVE_VALUES", "ZERO_METHOD_VALUES", "validate", "opts", "options", "require_unique", "__commonJSMin", "exports", "module", "ascending", "a", "b", "unique", "arr", "len", "val", "i", "j", "require_print", "__commonJSMin", "exports", "module", "isPositiveInteger", "isObject", "isBoolean", "hasOwnProp", "roundn", "format", "print", "opts", "decision", "dgts", "str", "require_main", "__commonJSMin", "exports", "module", "isNumberArray", "isTypedArrayLike", "setReadOnly", "isObject", "ranks", "normalCDF", "signrankCDF", "tabulate", "signum", "sqrt", "abs", "Float64Array", "format", "validate", "unique", "print", "pnorm", "wilcoxon", "correction", "zeroMethod", "options", "hasTies", "counts", "repsum", "rplus", "nzero", "rzero", "alpha", "pval", "opts", "stat", "alt", "err", "len", "tmp", "out", "ad", "mu", "mn", "se", "d", "i", "r", "T", "v", "x", "y", "main"]
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar ALTERNATIVE_VALUES = [ 'two-sided', 'less', 'greater' ];\nvar ZERO_METHOD_VALUES = [ 'pratt', 'wilcox', 'zsplit' ];\n\nvar isAlternativeValue = contains( ALTERNATIVE_VALUES );\nvar isZeroMethod = contains( ZERO_METHOD_VALUES );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination for validated options\n* @param {Options} options - function options\n* @param {number} [options.alpha] - significance level\n* @param {string} [options.alternative] - alternative hypothesis (`two-sided`, `less` or `greater`)\n* @param {boolean} [options.exact] - whether to force using the exact distribution instead of a normal approximation when there are more than fifty data points\n* @param {boolean} [options.correction] - continuity correction adjusting the Wilcoxon rank statistic by 0.5 towards the mean\n* @param {string} [options.zeroMethod] - method governing how zero-differences are handled (`pratt`, `wilcox` or `zsplit`)\n* @param {number} [options.mu] - mean under H0\n* @returns {(null|Error)} null or an error\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'alpha' ) ) {\n\t\topts.alpha = options.alpha;\n\t\tif ( !isNumber( opts.alpha ) || isnan( opts.alpha ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a number. Option: `%s`.', 'alpha', opts.alpha ) );\n\t\t}\n\t\tif ( opts.alpha < 0.0 || opts.alpha > 1.0 ) {\n\t\t\treturn new RangeError( format( 'invalid option. `%s` option must be a number on the interval: [0, 1]. Option: `%f`.', 'alpha', opts.alpha ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'alternative' ) ) {\n\t\topts.alternative = options.alternative;\n\t\tif ( !isString( opts.alternative ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'alternative', opts.alternative ) );\n\t\t}\n\t\tif ( !isAlternativeValue( opts.alternative ) ) {\n\t\t\treturn new Error( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'alternative', ALTERNATIVE_VALUES.join( '\", \"' ), opts.alternative ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'correction' ) ) {\n\t\topts.correction = options.correction;\n\t\tif ( !isBoolean( opts.correction ) || isnan( opts.correction ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'correction', opts.alpha ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'exact' ) ) {\n\t\topts.exact = options.exact;\n\t\tif (\n\t\t\t!isBoolean( opts.exact ) ||\n\t\t\tisnan( opts.exact )\n\t\t) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'exact', opts.alpha ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'mu' ) ) {\n\t\topts.mu = options.mu;\n\t\tif ( !isNumber( opts.mu ) || isnan( opts.mu ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a number. Option: `%s`.', 'mu', opts.mu ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'zeroMethod' ) ) {\n\t\topts.zeroMethod = options.zeroMethod;\n\t\tif ( !isString( opts.zeroMethod ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'zeroMethod', opts.alternative ) );\n\t\t}\n\t\tif ( !isZeroMethod( opts.zeroMethod ) ) {\n\t\t\treturn new Error( format( 'invalid option. `%s` option must be one of the following: \"%s\". Option: `%s`.', 'zeroMethod', ZERO_METHOD_VALUES.join( '\", \"' ), opts.zeroMethod ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "\n/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Comparator function to sort values in ascending order.\n*\n* @private\n* @param {number} a - first value\n* @param {number} b - second value\n* @returns {number} difference between `a` and `b`\n*/\nfunction ascending( a, b ) {\n\treturn a - b;\n}\n\n\n// MAIN //\n\n/**\n* Removes duplicate values from a numeric array.\n*\n* @private\n* @param {NumberArray} arr - array to be deduped\n* @returns {NumberArray} deduped array\n*/\nfunction unique( arr ) {\n\tvar len;\n\tvar val;\n\tvar i;\n\tvar j;\n\n\tarr = arr.slice();\n\tarr.sort( ascending );\n\tlen = arr.length;\n\n\t// Loop through the array, only incrementing a pointer when successive values are different. When a succeeding value is different, move the pointer and set the next value. In the trivial case where all array elements are unique, we incur a slight penalty in resetting the element value for each unique value. In other cases, we simply move a unique value to a new position in the array. The end result is a sorted array with unique values.\n\tfor ( i = 1, j = 0; i < len; i++ ) {\n\t\tval = arr[ i ];\n\t\tif ( arr[ j ] !== val ) {\n\t\t\tj += 1;\n\t\t\tarr[ j ] = val;\n\t\t}\n\t}\n\t// Truncate the array:\n\tarr.length = j + 1;\n\treturn arr;\n}\n\n\n// EXPORTS //\n\nmodule.exports = unique;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isPositiveInteger = require( '@stdlib/assert-is-positive-integer' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar roundn = require( '@stdlib/math-base-special-roundn' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Pretty-print output of test.\n*\n* @param {Object} [opts] - options object\n* @param {PositiveInteger} [opts.digits=4] - number of digits after the decimal point\n* @param {boolean} [opts.decision=true] - boolean indicating whether to print the test decision\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} formatted output\n*/\nfunction print( opts ) { // eslint-disable-line stdlib/no-redeclare\n\t/* eslint-disable no-invalid-this */\n\tvar decision;\n\tvar dgts;\n\tvar str;\n\n\tdgts = 4;\n\tdecision = true;\n\tif ( arguments.length > 0 ) {\n\t\tif ( !isObject( opts ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', opts ) );\n\t\t}\n\t\tif ( hasOwnProp( opts, 'digits' ) ) {\n\t\t\tif ( !isPositiveInteger( opts.digits ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'digits', opts.digits ) );\n\t\t\t}\n\t\t\tdgts = opts.digits;\n\t\t}\n\t\tif ( hasOwnProp( opts, 'decision' ) ) {\n\t\t\tif ( !isBoolean( opts.decision ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'decision', opts.decision ) );\n\t\t\t}\n\t\t\tdecision = opts.decision;\n\t\t}\n\t}\n\tstr = '';\n\tstr += this.method;\n\tstr += '\\n\\n';\n\tstr += 'Alternative hypothesis: ';\n\tif ( this.method === 'Paired Wilcoxon signed rank test' ) {\n\t\tstr += 'Median of the difference `x - y` is ';\n\t} else {\n\t\tstr += 'Median of `x` is ';\n\t}\n\tswitch ( this.alternative ) {\n\tcase 'less':\n\t\tstr += 'less than ';\n\t\tbreak;\n\tcase 'greater':\n\t\tstr += 'greater than ';\n\t\tbreak;\n\tcase 'two-sided':\n\tdefault:\n\t\tstr += 'not equal to ';\n\t\tbreak;\n\t}\n\tstr += this.nullValue;\n\tstr += '\\n\\n';\n\tstr += ' pValue: ' + roundn( this.pValue, -dgts ) + '\\n';\n\tstr += ' statistic: ' + roundn( this.statistic, -dgts ) + '\\n';\n\tstr += '\\n';\n\tif ( decision ) {\n\t\tstr += 'Test Decision: ';\n\t\tif ( this.rejected ) {\n\t\t\tstr += 'Reject null in favor of alternative at ' + (this.alpha*100) + '% significance level';\n\t\t} else {\n\t\t\tstr += 'Fail to reject null in favor of alternative at ' + (this.alpha*100) + '% significance level';\n\t\t}\n\t\tstr += '\\n';\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = print;\n", "/* eslint-disable max-statements, max-lines-per-function */\n\n/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumberArray = require( '@stdlib/assert-is-number-array' ).primitives;\nvar isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' );\nvar setReadOnly = require( '@stdlib/utils-define-read-only-property' );\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar ranks = require( '@stdlib/stats-ranks' );\nvar normalCDF = require( '@stdlib/stats-base-dists-normal-cdf' ).factory;\nvar signrankCDF = require( '@stdlib/stats-base-dists-signrank-cdf' );\nvar tabulate = require( '@stdlib/utils-tabulate' );\nvar signum = require( '@stdlib/math-base-special-signum' );\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar Float64Array = require( '@stdlib/array-float64' );\nvar format = require( '@stdlib/string-format' );\nvar validate = require( './validate.js' );\nvar unique = require( './unique.js' );\nvar print = require( './print.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// VARIABLES //\n\nvar pnorm = normalCDF( 0.0, 1.0 );\n\n\n// MAIN //\n\n/**\n* Computes a Wilcoxon signed rank test.\n*\n* @param {NumericArray} x - data array\n* @param {NumericArray} [y] - optional paired data array\n* @param {Options} [options] - function options\n* @param {number} [options.alpha=0.05] - significance level\n* @param {string} [options.alternative='two-sided'] - alternative hypothesis (`two-sided`, `less`, or `greater`)\n* @param {string} [options.zeroMethod='wilcox'] - method governing how zero-differences are handled (`pratt`, `wilcox`, or `zsplit`)\n* @param {boolean} [options.correction=true] - continuity correction adjusting the Wilcoxon rank statistic by 0.5 towards the mean\n* @param {boolean} [options.exact=false] - whether to force using the exact distribution instead of a normal approximation when there are more than fifty data points\n* @param {number} [options.mu=0] - location parameter under H0\n* @throws {TypeError} `x` must be a numeric array\n* @throws {TypeError} `y` must be a numeric array\n* @throws {TypeError} options must be an object\n* @throws {TypeError} `alpha` option has to be a number\n* @throws {RangeError} `alpha` option has to be a number in the interval `[0,1]`\n* @throws {TypeError} `alternative` option has to be a string\n* @throws {Error} `alternative` option must be `two-sided`, `less`, or `greater`\n* @throws {TypeError} `zeroMethod` option has to be a string\n* @throws {Error} `zeroMethod` option must be `pratt`, `wilcox`, or `zsplit`\n* @throws {TypeError} `correction` option has to be a boolean\n* @throws {TypeError} `exact` option has to be a boolean\n* @throws {TypeError} `mu` option has to be a number\n* @returns {Object} test result object\n*\n* @example\n* var x = [ 6, 8, 14, 16, 23, 24, 28, 29, 41, -48, 49, 56, 60, -67, 75 ];\n* var out = wilcoxon( x, {\n* 'mu': 2\n* });\n*\n* @example\n* var x = [ 6, 8, 14, 16, 23, 24, 28, 29, 41, -48, 49, 56, 60, -67, 75 ];\n* var out = wilcoxon( x, {\n* 'alternative': 'greater'\n* });\n*/\nfunction wilcoxon() {\n\tvar correction;\n\tvar zeroMethod;\n\tvar options;\n\tvar hasTies;\n\tvar counts;\n\tvar repsum;\n\tvar rplus;\n\tvar nzero;\n\tvar rzero;\n\tvar alpha;\n\tvar pval;\n\tvar opts;\n\tvar stat;\n\tvar alt;\n\tvar err;\n\tvar len;\n\tvar tmp;\n\tvar out;\n\tvar ad;\n\tvar mu;\n\tvar mn;\n\tvar se;\n\tvar d;\n\tvar i;\n\tvar r;\n\tvar T;\n\tvar v;\n\tvar x;\n\tvar y;\n\n\tx = arguments[ 0 ];\n\tif ( !isTypedArrayLike( x ) && !isNumberArray( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a numeric array. Value: `%s`.', x ) );\n\t}\n\tlen = x.length;\n\tif ( arguments.length > 1 ) {\n\t\tif ( isObject( arguments[ 1 ] ) ) {\n\t\t\toptions = arguments[ 1 ];\n\t\t} else {\n\t\t\ty = arguments[ 1 ];\n\t\t\tif ( !isTypedArrayLike( y ) && !isNumberArray( y ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid argument. `%s` argument must be a numeric array. Value: `%s`.', 'y', y ) );\n\t\t\t}\n\t\t\tif ( len !== y.length ) {\n\t\t\t\tthrow new Error( 'invalid arguments. First and second arguments must have the same length.' );\n\t\t\t}\n\t\t\tif ( arguments.length > 2 ) {\n\t\t\t\toptions = arguments[ 2 ];\n\t\t\t}\n\t\t}\n\t}\n\topts = {};\n\tif ( options ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tmu = opts.mu || 0.0;\n\tif ( opts.correction === void 0 ) {\n\t\tcorrection = true;\n\t} else {\n\t\tcorrection = opts.correction;\n\t}\n\tif ( opts.alpha === void 0 ) {\n\t\talpha = 0.05;\n\t} else {\n\t\talpha = opts.alpha;\n\t}\n\tif ( len < 2 ) {\n\t\tthrow new Error( format( 'invalid argument. First argument must contain at least two elements. Value: `%s`.', x ) );\n\t}\n\talt = opts.alternative || 'two-sided';\n\tzeroMethod = opts.zeroMethod || 'wilcox';\n\n\tif ( zeroMethod === 'wilcox' ) {\n\t\t// Only keep all non-zero differences:\n\t\td = [];\n\t\tif ( y ) {\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tv = ( x[ i ] - y[ i ] ) - mu;\n\t\t\t\tif ( v !== 0 ) {\n\t\t\t\t\td.push( v );\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tif ( x[ i ] !== 0 ) {\n\t\t\t\t\td.push( x[ i ] - mu );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tnzero = x.length - d.length;\n\t} else {\n\t\td = new Float64Array( len );\n\t\tnzero = 0;\n\t\tif ( y ) {\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\td[ i ] = ( x[ i ] - y[ i ] ) - mu;\n\t\t\t\tif ( d[ i ] === 0 ) {\n\t\t\t\t\tnzero += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\td[ i ] = x[ i ] - mu;\n\t\t\t\tif ( d[ i ] === 0 ) {\n\t\t\t\t\tnzero += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif ( nzero === len ) {\n\t\tthrow new Error( '`x` or `x - y` cannot be zero for all elements.' );\n\t}\n\t// Update length after potentially discarding zero values:\n\tlen = d.length;\n\tad = new Float64Array( len );\n\tfor ( i = 0; i < len; i++ ) {\n\t\tad[ i ] = abs( d[ i ] );\n\t}\n\tr = ranks( ad );\n\trplus = 0;\n\trzero = 0;\n\tfor ( i = 0; i < len; i++ ) {\n\t\tif ( d[ i ] > 0 ) {\n\t\t\trplus += r[ i ];\n\t\t}\n\t\telse if ( d[ i ] === 0 ) {\n\t\t\trzero += r[ i ];\n\t\t}\n\t}\n\thasTies = unique( r ).length !== r.length;\n\tif ( zeroMethod === 'zsplit' ) {\n\t\trplus += rzero / 2.0;\n\t}\n\tT = rplus;\n\tmn = len * ( len + 1.0 ) * 0.25;\n\tse = len * ( len + 1.0 ) * ( ( 2.0 * len ) + 1.0 );\n\n\tif ( zeroMethod === 'pratt' ) {\n\t\ttmp = [];\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( d[ i ] !== 0 ) {\n\t\t\t\ttmp.push( r[ i ] );\n\t\t\t}\n\t\t}\n\t\tr = tmp;\n\t\tmn -= nzero * ( nzero + 1.0 ) * 0.25;\n\t\tse -= nzero * ( nzero + 1.0 ) * ( ( 2.0 * nzero ) + 1.0 );\n\t}\n\tcounts = tabulate( r );\n\trepsum = 0;\n\tfor ( i = 0; i < counts.length; i++ ) {\n\t\tif ( counts[ i ][ 1 ] > 1 ) {\n\t\t\tv = counts[ i ][ 1 ];\n\t\t\trepsum += v * ( (v*v) - 1 );\n\t\t}\n\t}\n\tif ( repsum > 0 ) {\n\t\t// Correction for repeated values:\n\t\tse -= 0.5 * repsum;\n\t}\n\tse = sqrt( se / 24.0 );\n\n\tif (\n\t\t( len > 50 && !opts.exact ) ||\n\t\tnzero > 0 ||\n\t\thasTies\n\t) {\n\t\td = 0.0;\n\t\tif ( correction ) {\n\t\t\tswitch ( alt ) {\n\t\t\tcase 'two-sided':\n\t\t\t\td = 0.5 * signum( T - mn );\n\t\t\t\tbreak;\n\t\t\tcase 'less':\n\t\t\t\td = -0.5;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\td = 0.5;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t// Compute test statistic and p-value using normal approximation:\n\t\tstat = ( T - mn - d ) / se;\n\t\tif ( alt === 'two-sided' ) {\n\t\t\tpval = 2.0 * ( 1.0 - pnorm( abs( stat ) ) );\n\t\t} else if ( alt === 'greater' ) {\n\t\t\tpval = 1.0 - pnorm( stat );\n\t\t} else {\n\t\t\tpval = pnorm( stat );\n\t\t}\n\t} else {\n\t\t// Compute test statistic and p-value using exact critical values:\n\t\tstat = T;\n\t\tif ( alt === 'two-sided' ) {\n\t\t\tif ( stat > ( len * ( len+1 ) / 4 ) ) {\n\t\t\t\tpval = 2.0 * ( 1 - signrankCDF( stat - 1, len ) );\n\t\t\t} else {\n\t\t\t\tpval = 2.0 * signrankCDF( stat, len );\n\t\t\t}\n\t\t} else if ( alt === 'greater' ) {\n\t\t\tpval = 1.0 - signrankCDF( stat - 1, len );\n\t\t} else {\n\t\t\tpval = signrankCDF( stat, len );\n\t\t}\n\t}\n\tout = {};\n\tsetReadOnly( out, 'rejected', pval <= alpha );\n\tsetReadOnly( out, 'alpha', alpha );\n\tsetReadOnly( out, 'pValue', pval );\n\tsetReadOnly( out, 'statistic', T );\n\tsetReadOnly( out, 'nullValue', mu );\n\tsetReadOnly( out, 'alternative', alt );\n\tsetReadOnly( out, 'method', ( ( y ) ? 'Paired' : 'One-Sample' ) + ' Wilcoxon signed rank test' );\n\tsetReadOnly( out, 'print', print );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = wilcoxon;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute a Wilcoxon signed-rank test.\n*\n* @module @stdlib/stats-wilcoxon\n*\n* @example\n* var normal = require( '@stdlib/random-base-normal' ).factory;\n* var wilcoxon = require( '@stdlib/stats-wilcoxon' );\n*\n* var rnorm;\n* var out;\n* var i;\n* var x;\n* var y;\n*\n* rnorm = normal( 1.0, 2.0, {\n* 'seed': 786\n* });\n*\n* // One-sample Wilcoxon signed rank test:\n* x = new Array( 100 );\n* for ( i = 0; i < x.length; i++ ) {\n* x[ i ] = rnorm();\n* }\n* out = wilcoxon( x );\n*\n* // Paired Wilcoxon signed rank test:\n* x = new Array( 100 );\n* y = new Array( 100 );\n* for ( i = 0; i < x.length; i++ ) {\n* x[ i ] = rnorm();\n* y[ i ] = rnorm();\n* }\n* out = wilcoxon( x, y );\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,GAAW,QAAS,gCAAiC,EACrDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAQ,QAAS,uBAAwB,EACzCC,EAAa,QAAS,iCAAkC,EACxDC,EAAS,QAAS,uBAAwB,EAK1CC,EAAqB,CAAE,YAAa,OAAQ,SAAU,EACtDC,EAAqB,CAAE,QAAS,SAAU,QAAS,EAEnDC,GAAqBV,EAAUQ,CAAmB,EAClDG,GAAeX,EAAUS,CAAmB,EAmBhD,SAASG,GAAUC,EAAMC,EAAU,CAClC,GAAK,CAACX,GAAUW,CAAQ,EACvB,OAAO,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE/G,GAAKR,EAAYQ,EAAS,OAAQ,EAAI,CAErC,GADAD,EAAK,MAAQC,EAAQ,MAChB,CAACZ,EAAUW,EAAK,KAAM,GAAKR,EAAOQ,EAAK,KAAM,EACjD,OAAO,IAAI,UAAWN,EAAQ,8DAA+D,QAASM,EAAK,KAAM,CAAE,EAEpH,GAAKA,EAAK,MAAQ,GAAOA,EAAK,MAAQ,EACrC,O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AK,cAAeJ,CAAI,EACrC7B,EAAaiC,EAAK,UAAcW,EAAM,SAAW,cAAiB,4BAA6B,EAC/F5C,EAAaiC,EAAK,QAASpB,EAAM,EAC1BoB,CACR,CAKApC,GAAO,QAAUkB,KC7PjB,IAAI8B,GAAO,KAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_validate", "__commonJSMin", "exports", "module", "contains", "isBoolean", "isNumber", "isObject", "isString", "isnan", "hasOwnProp", "format", "ALTERNATIVE_VALUES", "ZERO_METHOD_VALUES", "isAlternativeValue", "isZeroMethod", "validate", "opts", "options", "require_unique", "__commonJSMin", "exports", "module", "ascending", "a", "b", "unique", "arr", "len", "val", "i", "j", "require_print", "__commonJSMin", "exports", "module", "isPositiveInteger", "isObject", "isBoolean", "hasOwnProp", "roundn", "format", "print", "opts", "decision", "dgts", "str", "require_main", "__commonJSMin", "exports", "module", "isNumberArray", "isTypedArrayLike", "setReadOnly", "isObject", "ranks", "normalCDF", "signrankCDF", "tabulate", "signum", "sqrt", "abs", "Float64Array", "format", "validate", "unique", "print", "pnorm", "wilcoxon", "correction", "zeroMethod", "options", "hasTies", "counts", "repsum", "rplus", "nzero", "rzero", "alpha", "pval", "opts", "stat", "alt", "err", "len", "tmp", "out", "ad", "mu", "mn", "se", "d", "i", "r", "T", "v", "x", "y", "main"]
|
|
7
7
|
}
|
package/lib/validate.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var contains = require( '@stdlib/assert-contains' );
|
|
23
|
+
var contains = require( '@stdlib/array-base-assert-contains' ).factory;
|
|
24
24
|
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
|
|
25
25
|
var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;
|
|
26
26
|
var isObject = require( '@stdlib/assert-is-plain-object' );
|
|
@@ -35,6 +35,9 @@ var format = require( '@stdlib/string-format' );
|
|
|
35
35
|
var ALTERNATIVE_VALUES = [ 'two-sided', 'less', 'greater' ];
|
|
36
36
|
var ZERO_METHOD_VALUES = [ 'pratt', 'wilcox', 'zsplit' ];
|
|
37
37
|
|
|
38
|
+
var isAlternativeValue = contains( ALTERNATIVE_VALUES );
|
|
39
|
+
var isZeroMethod = contains( ZERO_METHOD_VALUES );
|
|
40
|
+
|
|
38
41
|
|
|
39
42
|
// MAIN //
|
|
40
43
|
|
|
@@ -70,7 +73,7 @@ function validate( opts, options ) {
|
|
|
70
73
|
if ( !isString( opts.alternative ) ) {
|
|
71
74
|
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'alternative', opts.alternative ) );
|
|
72
75
|
}
|
|
73
|
-
if ( !
|
|
76
|
+
if ( !isAlternativeValue( opts.alternative ) ) {
|
|
74
77
|
return new Error( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'alternative', ALTERNATIVE_VALUES.join( '", "' ), opts.alternative ) );
|
|
75
78
|
}
|
|
76
79
|
}
|
|
@@ -100,7 +103,7 @@ function validate( opts, options ) {
|
|
|
100
103
|
if ( !isString( opts.zeroMethod ) ) {
|
|
101
104
|
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'zeroMethod', opts.alternative ) );
|
|
102
105
|
}
|
|
103
|
-
if ( !
|
|
106
|
+
if ( !isZeroMethod( opts.zeroMethod ) ) {
|
|
104
107
|
return new Error( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'zeroMethod', ZERO_METHOD_VALUES.join( '", "' ), opts.zeroMethod ) );
|
|
105
108
|
}
|
|
106
109
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-wilcoxon",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Wilcoxon signed rank test.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -30,28 +30,28 @@
|
|
|
30
30
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@stdlib/array-
|
|
34
|
-
"@stdlib/
|
|
35
|
-
"@stdlib/assert-has-own-property": "^0.2.
|
|
36
|
-
"@stdlib/assert-is-boolean": "^0.2.
|
|
37
|
-
"@stdlib/assert-is-nan": "^0.2.
|
|
38
|
-
"@stdlib/assert-is-number": "^0.2.
|
|
39
|
-
"@stdlib/assert-is-number-array": "^0.2.
|
|
40
|
-
"@stdlib/assert-is-plain-object": "^0.2.
|
|
41
|
-
"@stdlib/assert-is-positive-integer": "^0.2.
|
|
42
|
-
"@stdlib/assert-is-string": "^0.2.
|
|
43
|
-
"@stdlib/assert-is-typed-array-like": "^0.2.
|
|
44
|
-
"@stdlib/math-base-special-abs": "^0.2.
|
|
45
|
-
"@stdlib/math-base-special-roundn": "^0.2.
|
|
46
|
-
"@stdlib/math-base-special-signum": "^0.2.
|
|
47
|
-
"@stdlib/math-base-special-sqrt": "^0.2.
|
|
48
|
-
"@stdlib/stats-base-dists-normal-cdf": "^0.
|
|
49
|
-
"@stdlib/stats-base-dists-signrank-cdf": "^0.2.
|
|
50
|
-
"@stdlib/stats-ranks": "^0.2.
|
|
51
|
-
"@stdlib/string-format": "^0.2.
|
|
52
|
-
"@stdlib/utils-define-read-only-property": "^0.2.
|
|
53
|
-
"@stdlib/utils-tabulate": "^0.2.
|
|
54
|
-
"@stdlib/error-tools-fmtprodmsg": "^0.2.
|
|
33
|
+
"@stdlib/array-base-assert-contains": "^0.2.2",
|
|
34
|
+
"@stdlib/array-float64": "^0.2.3",
|
|
35
|
+
"@stdlib/assert-has-own-property": "^0.2.3",
|
|
36
|
+
"@stdlib/assert-is-boolean": "^0.2.3",
|
|
37
|
+
"@stdlib/assert-is-nan": "^0.2.3",
|
|
38
|
+
"@stdlib/assert-is-number": "^0.2.3",
|
|
39
|
+
"@stdlib/assert-is-number-array": "^0.2.3",
|
|
40
|
+
"@stdlib/assert-is-plain-object": "^0.2.3",
|
|
41
|
+
"@stdlib/assert-is-positive-integer": "^0.2.3",
|
|
42
|
+
"@stdlib/assert-is-string": "^0.2.3",
|
|
43
|
+
"@stdlib/assert-is-typed-array-like": "^0.2.3",
|
|
44
|
+
"@stdlib/math-base-special-abs": "^0.2.3",
|
|
45
|
+
"@stdlib/math-base-special-roundn": "^0.2.3",
|
|
46
|
+
"@stdlib/math-base-special-signum": "^0.2.3",
|
|
47
|
+
"@stdlib/math-base-special-sqrt": "^0.2.3",
|
|
48
|
+
"@stdlib/stats-base-dists-normal-cdf": "^0.3.1",
|
|
49
|
+
"@stdlib/stats-base-dists-signrank-cdf": "^0.2.3",
|
|
50
|
+
"@stdlib/stats-ranks": "^0.2.3",
|
|
51
|
+
"@stdlib/string-format": "^0.2.3",
|
|
52
|
+
"@stdlib/utils-define-read-only-property": "^0.2.3",
|
|
53
|
+
"@stdlib/utils-tabulate": "^0.2.3",
|
|
54
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.2.3"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {},
|
|
57
57
|
"engines": {
|