@stdlib/stats-base-dists-signrank-pdf 0.2.2 → 0.3.0
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 +103 -6
- package/dist/index.js +6 -6
- package/dist/index.js.map +3 -3
- package/include/stdlib/stats/base/dists/signrank/pdf.h +40 -0
- package/lib/factory.js +4 -0
- package/lib/main.js +4 -0
- package/lib/native.js +66 -0
- package/manifest.json +78 -0
- package/package.json +9 -3
- package/src/addon.c +22 -0
- package/src/main.c +74 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -141,7 +141,7 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
141
141
|
x = randu() * 30.0;
|
|
142
142
|
n = ceil( randu() * 30.0 );
|
|
143
143
|
y = pdf( x, n );
|
|
144
|
-
console.log( 'x: %d, n: %d,
|
|
144
|
+
console.log( 'x: %d, n: %d, f(x;n): %d', x.toFixed( 4 ), n.toFixed( 4 ), y.toFixed( 4 ) );
|
|
145
145
|
}
|
|
146
146
|
```
|
|
147
147
|
|
|
@@ -149,6 +149,103 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
149
149
|
|
|
150
150
|
<!-- /.examples -->
|
|
151
151
|
|
|
152
|
+
<!-- C interface documentation. -->
|
|
153
|
+
|
|
154
|
+
* * *
|
|
155
|
+
|
|
156
|
+
<section class="c">
|
|
157
|
+
|
|
158
|
+
## C APIs
|
|
159
|
+
|
|
160
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
161
|
+
|
|
162
|
+
<section class="intro">
|
|
163
|
+
|
|
164
|
+
</section>
|
|
165
|
+
|
|
166
|
+
<!-- /.intro -->
|
|
167
|
+
|
|
168
|
+
<!-- C usage documentation. -->
|
|
169
|
+
|
|
170
|
+
<section class="usage">
|
|
171
|
+
|
|
172
|
+
### Usage
|
|
173
|
+
|
|
174
|
+
```c
|
|
175
|
+
#include "stdlib/stats/base/dists/signrank/pdf.h"
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### stdlib_base_dists_signrank_pdf( x, n )
|
|
179
|
+
|
|
180
|
+
Evaluates the probability density function (PDF) of the Wilcoxon signed rank test statistic with `n` observations.
|
|
181
|
+
|
|
182
|
+
```c
|
|
183
|
+
double out = stdlib_base_dists_signrank_pdf( 7.0, 9 );
|
|
184
|
+
// returns ~0.01
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The function accepts the following arguments:
|
|
188
|
+
|
|
189
|
+
- **x**: `[in] double` input value.
|
|
190
|
+
- **n**: `[in] int32_t` number of observations.
|
|
191
|
+
|
|
192
|
+
```c
|
|
193
|
+
double stdlib_base_dists_signrank_pdf( const double x, const int32_t n );
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
</section>
|
|
197
|
+
|
|
198
|
+
<!-- /.usage -->
|
|
199
|
+
|
|
200
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
201
|
+
|
|
202
|
+
<section class="notes">
|
|
203
|
+
|
|
204
|
+
</section>
|
|
205
|
+
|
|
206
|
+
<!-- /.notes -->
|
|
207
|
+
|
|
208
|
+
<!-- C API usage examples. -->
|
|
209
|
+
|
|
210
|
+
<section class="examples">
|
|
211
|
+
|
|
212
|
+
### Examples
|
|
213
|
+
|
|
214
|
+
```c
|
|
215
|
+
#include "stdlib/stats/base/dists/signrank/pdf.h"
|
|
216
|
+
#include "stdlib/math/base/special/ceil.h"
|
|
217
|
+
#include <stdlib.h>
|
|
218
|
+
#include <stdio.h>
|
|
219
|
+
#include <stdint.h>
|
|
220
|
+
|
|
221
|
+
static double random_uniform( const double min, const double max ) {
|
|
222
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
223
|
+
return min + ( v*(max-min) );
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
int main( void ) {
|
|
227
|
+
int32_t n;
|
|
228
|
+
double x;
|
|
229
|
+
double y;
|
|
230
|
+
int i;
|
|
231
|
+
|
|
232
|
+
for ( i = 0; i < 25; i++ ) {
|
|
233
|
+
x = random_uniform( 0, 30.0 );
|
|
234
|
+
n = (int32_t)stdlib_base_ceil( random_uniform( 1.0, 30.0 ) );
|
|
235
|
+
y = stdlib_base_dists_signrank_pdf( x, n );
|
|
236
|
+
printf( "x: %lf, n: %d, f(x;n): %lf\n", x, n, y );
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
</section>
|
|
242
|
+
|
|
243
|
+
<!-- /.examples -->
|
|
244
|
+
|
|
245
|
+
</section>
|
|
246
|
+
|
|
247
|
+
<!-- /.c -->
|
|
248
|
+
|
|
152
249
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
153
250
|
|
|
154
251
|
<section class="related">
|
|
@@ -183,7 +280,7 @@ See [LICENSE][stdlib-license].
|
|
|
183
280
|
|
|
184
281
|
## Copyright
|
|
185
282
|
|
|
186
|
-
Copyright © 2016-
|
|
283
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
187
284
|
|
|
188
285
|
</section>
|
|
189
286
|
|
|
@@ -196,8 +293,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
196
293
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-signrank-pdf.svg
|
|
197
294
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-signrank-pdf
|
|
198
295
|
|
|
199
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-signrank-pdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
200
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-signrank-pdf/actions/workflows/test.yml?query=branch:v0.
|
|
296
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-signrank-pdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
297
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-signrank-pdf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
201
298
|
|
|
202
299
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-signrank-pdf/main.svg
|
|
203
300
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-signrank-pdf?branch=main
|
|
@@ -209,8 +306,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
209
306
|
|
|
210
307
|
-->
|
|
211
308
|
|
|
212
|
-
[chat-image]: https://img.shields.io/
|
|
213
|
-
[chat-url]: https://
|
|
309
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
310
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
214
311
|
|
|
215
312
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
216
313
|
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var s=a(function(
|
|
1
|
+
"use strict";var a=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var s=a(function(G,v){
|
|
2
2
|
var m=require('@stdlib/utils-memoize/dist'),u;function p(r,e){var i;return e===0?r===0?1:0:(i=e*(e+1)/2,r<0||r>i?0:(r>i/2&&(r=i-r),u(r-e,e-1)+u(r,e-1)))}u=m(p);v.exports=u
|
|
3
|
-
});var f=a(function(
|
|
4
|
-
var N=require('@stdlib/math-base-assert-is-positive-integer/dist'),l=require('@stdlib/math-base-assert-is-finite/dist'),
|
|
5
|
-
});var o=a(function(
|
|
6
|
-
var
|
|
7
|
-
});var
|
|
3
|
+
});var f=a(function(H,n){
|
|
4
|
+
var N=require('@stdlib/math-base-assert-is-positive-integer/dist'),g=require('@stdlib/math-base-assert-is-integer/dist'),l=require('@stdlib/math-base-assert-is-finite/dist'),d=require('@stdlib/math-base-assert-is-nan/dist'),y=require('@stdlib/math-base-special-exp/dist'),I=require('@stdlib/math-base-special-ln/dist'),h=require('@stdlib/constants-float64-ln-two/dist'),w=s();function z(r,e){var i;return d(r)||!N(e)||!l(e)?NaN:!g(r)||(i=e*(e+1)/2,r<0||r>i)?0:y(I(w(r,e))-e*h)}n.exports=z
|
|
5
|
+
});var o=a(function(J,q){
|
|
6
|
+
var L=require('@stdlib/math-base-assert-is-positive-integer/dist'),P=require('@stdlib/utils-constant-function/dist'),F=require('@stdlib/math-base-assert-is-integer/dist'),O=require('@stdlib/math-base-assert-is-finite/dist'),R=require('@stdlib/math-base-assert-is-nan/dist'),b=require('@stdlib/math-base-special-exp/dist'),j=require('@stdlib/math-base-special-ln/dist'),k=require('@stdlib/constants-float64-ln-two/dist'),A=s();function B(r){var e;if(!L(r)||!O(r))return P(NaN);return e=r*(r+1)/2,i;function i(t){return R(t)?NaN:!F(t)||t<0||t>e?0:b(j(A(t,r))-r*k)}}q.exports=B
|
|
7
|
+
});var C=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=f(),D=o();C(c,"factory",D);module.exports=c;
|
|
8
8
|
/** @license Apache-2.0 */
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/weights.js", "../lib/main.js", "../lib/factory.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 memoize = require( '@stdlib/utils-memoize' );\n\n\n// VARIABLES //\n\nvar memoized;\n\n\n// FUNCTIONS //\n\n/**\n* Calculates the weight for the `(x,n)` pair and memoizes the result.\n*\n* @private\n* @param {number} x - input value\n* @param {NonNegativeInteger} n - number of observations\n* @returns {number} weight\n*/\nfunction weights( x, n ) {\n\tvar mlim;\n\n\tif ( n === 0 ) {\n\t\treturn ( x === 0 ) ? 1 : 0;\n\t}\n\tmlim = n * ( n + 1 ) / 2;\n\tif ( x < 0 || x > mlim ) {\n\t\treturn 0;\n\t}\n\tif ( x > mlim / 2 ) {\n\t\tx = mlim - x;\n\t}\n\treturn memoized( x - n, n - 1 ) + memoized( x, n - 1 );\n}\n\n\n// MAIN //\n\nmemoized = memoize( weights );\n\n\n// EXPORTS //\n\nmodule.exports = memoized;\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/math-base-assert-is-positive-integer' );\nvar isfinite = require( '@stdlib/math-base-assert-is-finite' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\nvar weights = require( './weights.js' );\n\n\n// MAIN //\n\n/**\n* Evaluates the probability density function (PDF) of the Wilcoxon signed rank test statistic with `n` observations.\n*\n* @param {number} x - input value\n* @param {PositiveInteger} n - number of observations\n* @returns {Probability} evaluated PDF\n*\n* @example\n* var y = pdf( 7.0, 9 );\n* // returns ~0.01\n*\n* @example\n* var y = pdf( 7.0, 6 );\n* // returns ~0.063\n*\n* @example\n* var y = pdf( -1.0, 40 );\n* // returns 0.0\n*\n* @example\n* var y = pdf( NaN, 10 );\n* // returns NaN\n*\n* @example\n* var y = pdf( 0.0, NaN );\n* // returns NaN\n*\n* @example\n* var y = pdf( 2.0, -1 );\n* // returns NaN\n*\n* @example\n* var y = pdf( 2.0, 1.8 );\n* // returns NaN\n*/\nfunction pdf( x, n ) {\n\tvar mlim;\n\tif (\n\t\tisnan( x ) ||\n\t\t!isPositiveInteger( n ) ||\n\t\t!isfinite( n )\n\t) {\n\t\treturn NaN;\n\t}\n\tmlim = ( n * ( n + 1 ) ) / 2;\n\tif ( x < 0.0 || x > mlim ) {\n\t\treturn 0.0;\n\t}\n\treturn exp( ln( weights( x, n ) ) - ( n * LN2 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = pdf;\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/math-base-assert-is-positive-integer' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar isfinite = require( '@stdlib/math-base-assert-is-finite' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\nvar weights = require( './weights.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the probability density function (PDF) for the distribution of the Wilcoxon signed rank test statistic with `n` observations.\n*\n* @param {PositiveInteger} n - number of observations\n* @returns {Function} PDF\n*\n* @example\n* var pdf = factory( 8 );\n* var y = pdf( 4.0 );\n* // returns ~0.008\n*\n* y = pdf( 17.0 );\n* // returns ~0.051\n*/\nfunction factory( n ) {\n\tvar mlim;\n\tif ( !isPositiveInteger( n ) || !isfinite( n ) ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tmlim = n * ( n + 1 ) / 2;\n\treturn pdf;\n\n\t/**\n\t* Evaluates the probability density function (PDF) for the distribution of the Wilcoxon signed rank test statistic.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {Probability} evaluated PDF\n\t*\n\t* @example\n\t* var y = pdf( 2 );\n\t* // returns <number>\n\t*/\n\tfunction pdf( x ) {\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x < 0.0 || x > mlim ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn exp( ln( weights( x, n ) ) - ( n * LN2 ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\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* Wilcoxon signed rank test statistic probability density function (PDF).\n*\n* @module @stdlib/stats-base-dists-signrank-pdf\n*\n* @example\n* var pdf = require( '@stdlib/stats-base-dists-signrank-pdf' );\n*\n* var y = pdf( 7.0, 9 );\n* // returns ~0.01\n*\n* var mypdf = pdf.factory( 8 );\n* y = mypdf( 4.0 );\n* // returns ~0.008\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,uBAAwB,EAK3CC,EAaJ,SAASC,EAASC,EAAGC,EAAI,CACxB,IAAIC,EAEJ,OAAKD,IAAM,EACDD,IAAM,EAAM,EAAI,GAE1BE,EAAOD,GAAMA,EAAI,GAAM,EAClBD,EAAI,GAAKA,EAAIE,EACV,GAEHF,EAAIE,EAAO,IACfF,EAAIE,EAAOF,GAELF,EAAUE,EAAIC,EAAGA,EAAI,CAAE,EAAIH,EAAUE,EAAGC,EAAI,CAAE,GACtD,CAKAH,EAAWD,EAASE,CAAQ,EAK5BH,EAAO,QAAUE,IChEjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,8CAA+C,EAC5EC,EAAW,QAAS,oCAAqC,EACzDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAM,QAAS,kCAAmC,EAClDC,EAAU,IAwCd,SAASC,EAAKC,EAAGC,EAAI,CACpB,IAAIC,EACJ,OACCR,EAAOM,CAAE,GACT,
|
|
6
|
-
"names": ["require_weights", "__commonJSMin", "exports", "module", "memoize", "memoized", "weights", "x", "n", "mlim", "require_main", "__commonJSMin", "exports", "module", "isPositiveInteger", "isfinite", "isnan", "exp", "ln", "LN2", "weights", "pdf", "x", "n", "mlim", "require_factory", "__commonJSMin", "exports", "module", "isPositiveInteger", "constantFunction", "isfinite", "isnan", "exp", "ln", "LN2", "weights", "factory", "n", "mlim", "pdf", "x", "setReadOnly", "main", "factory"]
|
|
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 memoize = require( '@stdlib/utils-memoize' );\n\n\n// VARIABLES //\n\nvar memoized;\n\n\n// FUNCTIONS //\n\n/**\n* Calculates the weight for the `(x,n)` pair and memoizes the result.\n*\n* @private\n* @param {number} x - input value\n* @param {NonNegativeInteger} n - number of observations\n* @returns {number} weight\n*/\nfunction weights( x, n ) {\n\tvar mlim;\n\n\tif ( n === 0 ) {\n\t\treturn ( x === 0 ) ? 1 : 0;\n\t}\n\tmlim = n * ( n + 1 ) / 2;\n\tif ( x < 0 || x > mlim ) {\n\t\treturn 0;\n\t}\n\tif ( x > mlim / 2 ) {\n\t\tx = mlim - x;\n\t}\n\treturn memoized( x - n, n - 1 ) + memoized( x, n - 1 );\n}\n\n\n// MAIN //\n\nmemoized = memoize( weights );\n\n\n// EXPORTS //\n\nmodule.exports = memoized;\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/math-base-assert-is-positive-integer' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar isfinite = require( '@stdlib/math-base-assert-is-finite' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\nvar weights = require( './weights.js' );\n\n\n// MAIN //\n\n/**\n* Evaluates the probability density function (PDF) of the Wilcoxon signed rank test statistic with `n` observations.\n*\n* @param {number} x - input value\n* @param {PositiveInteger} n - number of observations\n* @returns {Probability} evaluated PDF\n*\n* @example\n* var y = pdf( 7.0, 9 );\n* // returns ~0.01\n*\n* @example\n* var y = pdf( 7.0, 6 );\n* // returns ~0.063\n*\n* @example\n* var y = pdf( -1.0, 40 );\n* // returns 0.0\n*\n* @example\n* var y = pdf( NaN, 10 );\n* // returns NaN\n*\n* @example\n* var y = pdf( 0.0, NaN );\n* // returns NaN\n*\n* @example\n* var y = pdf( 2.0, -1 );\n* // returns NaN\n*\n* @example\n* var y = pdf( 2.0, 1.8 );\n* // returns NaN\n*/\nfunction pdf( x, n ) {\n\tvar mlim;\n\tif (\n\t\tisnan( x ) ||\n\t\t!isPositiveInteger( n ) ||\n\t\t!isfinite( n )\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( !isInteger( x ) ) {\n\t\treturn 0.0;\n\t}\n\tmlim = ( n * ( n + 1 ) ) / 2;\n\tif ( x < 0.0 || x > mlim ) {\n\t\treturn 0.0;\n\t}\n\treturn exp( ln( weights( x, n ) ) - ( n * LN2 ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = pdf;\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/math-base-assert-is-positive-integer' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar isfinite = require( '@stdlib/math-base-assert-is-finite' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\nvar weights = require( './weights.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the probability density function (PDF) for the distribution of the Wilcoxon signed rank test statistic with `n` observations.\n*\n* @param {PositiveInteger} n - number of observations\n* @returns {Function} PDF\n*\n* @example\n* var pdf = factory( 8 );\n* var y = pdf( 4.0 );\n* // returns ~0.008\n*\n* y = pdf( 17.0 );\n* // returns ~0.051\n*/\nfunction factory( n ) {\n\tvar mlim;\n\tif ( !isPositiveInteger( n ) || !isfinite( n ) ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tmlim = n * ( n + 1 ) / 2;\n\treturn pdf;\n\n\t/**\n\t* Evaluates the probability density function (PDF) for the distribution of the Wilcoxon signed rank test statistic.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {Probability} evaluated PDF\n\t*\n\t* @example\n\t* var y = pdf( 2 );\n\t* // returns <number>\n\t*/\n\tfunction pdf( x ) {\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( !isInteger( x ) ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\tif ( x < 0.0 || x > mlim ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn exp( ln( weights( x, n ) ) - ( n * LN2 ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\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* Wilcoxon signed rank test statistic probability density function (PDF).\n*\n* @module @stdlib/stats-base-dists-signrank-pdf\n*\n* @example\n* var pdf = require( '@stdlib/stats-base-dists-signrank-pdf' );\n*\n* var y = pdf( 7.0, 9 );\n* // returns ~0.01\n*\n* var mypdf = pdf.factory( 8 );\n* y = mypdf( 4.0 );\n* // returns ~0.008\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,uBAAwB,EAK3CC,EAaJ,SAASC,EAASC,EAAGC,EAAI,CACxB,IAAIC,EAEJ,OAAKD,IAAM,EACDD,IAAM,EAAM,EAAI,GAE1BE,EAAOD,GAAMA,EAAI,GAAM,EAClBD,EAAI,GAAKA,EAAIE,EACV,GAEHF,EAAIE,EAAO,IACfF,EAAIE,EAAOF,GAELF,EAAUE,EAAIC,EAAGA,EAAI,CAAE,EAAIH,EAAUE,EAAGC,EAAI,CAAE,GACtD,CAKAH,EAAWD,EAASE,CAAQ,EAK5BH,EAAO,QAAUE,IChEjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,8CAA+C,EAC5EC,EAAY,QAAS,qCAAsC,EAC3DC,EAAW,QAAS,oCAAqC,EACzDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAM,QAAS,kCAAmC,EAClDC,EAAU,IAwCd,SAASC,EAAKC,EAAGC,EAAI,CACpB,IAAIC,EACJ,OACCR,EAAOM,CAAE,GACT,CAACT,EAAmBU,CAAE,GACtB,CAACR,EAAUQ,CAAE,EAEN,IAEH,CAACT,EAAWQ,CAAE,IAGnBE,EAASD,GAAMA,EAAI,GAAQ,EACtBD,EAAI,GAAOA,EAAIE,GACZ,EAEDP,EAAKC,EAAIE,EAASE,EAAGC,CAAE,CAAE,EAAMA,EAAIJ,CAAM,CACjD,CAKAP,EAAO,QAAUS,IC3FjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,8CAA+C,EAC5EC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAY,QAAS,qCAAsC,EAC3DC,EAAW,QAAS,oCAAqC,EACzDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAM,QAAS,kCAAmC,EAClDC,EAAU,IAmBd,SAASC,EAASC,EAAI,CACrB,IAAIC,EACJ,GAAK,CAACX,EAAmBU,CAAE,GAAK,CAACP,EAAUO,CAAE,EAC5C,OAAOT,EAAkB,GAAI,EAE9B,OAAAU,EAAOD,GAAMA,EAAI,GAAM,EAChBE,EAaP,SAASA,EAAKC,EAAI,CACjB,OAAKT,EAAOS,CAAE,EACN,IAEH,CAACX,EAAWW,CAAE,GAGdA,EAAI,GAAOA,EAAIF,EACZ,EAEDN,EAAKC,EAAIE,EAASK,EAAGH,CAAE,CAAE,EAAMA,EAAIH,CAAM,CACjD,CACD,CAKAR,EAAO,QAAUU,IC/CjB,IAAIK,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
|
|
6
|
+
"names": ["require_weights", "__commonJSMin", "exports", "module", "memoize", "memoized", "weights", "x", "n", "mlim", "require_main", "__commonJSMin", "exports", "module", "isPositiveInteger", "isInteger", "isfinite", "isnan", "exp", "ln", "LN2", "weights", "pdf", "x", "n", "mlim", "require_factory", "__commonJSMin", "exports", "module", "isPositiveInteger", "constantFunction", "isInteger", "isfinite", "isnan", "exp", "ln", "LN2", "weights", "factory", "n", "mlim", "pdf", "x", "setReadOnly", "main", "factory"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#ifndef STDLIB_STATS_BASE_DISTS_SIGNRANK_PDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_SIGNRANK_PDF_H
|
|
21
|
+
|
|
22
|
+
#include <stdint.h>
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
26
|
+
*/
|
|
27
|
+
#ifdef __cplusplus
|
|
28
|
+
extern "C" {
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Evaluates the probability density function (PDF) of the Wilcoxon signed rank test statistic with `n` observations.
|
|
33
|
+
*/
|
|
34
|
+
double stdlib_base_dists_signrank_pdf( const double x, const int32_t n );
|
|
35
|
+
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
}
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#endif // !STDLIB_STATS_BASE_DISTS_SIGNRANK_PDF_H
|
package/lib/factory.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
var isPositiveInteger = require( '@stdlib/math-base-assert-is-positive-integer' );
|
|
24
24
|
var constantFunction = require( '@stdlib/utils-constant-function' );
|
|
25
|
+
var isInteger = require( '@stdlib/math-base-assert-is-integer' );
|
|
25
26
|
var isfinite = require( '@stdlib/math-base-assert-is-finite' );
|
|
26
27
|
var isnan = require( '@stdlib/math-base-assert-is-nan' );
|
|
27
28
|
var exp = require( '@stdlib/math-base-special-exp' );
|
|
@@ -69,6 +70,9 @@ function factory( n ) {
|
|
|
69
70
|
if ( isnan( x ) ) {
|
|
70
71
|
return NaN;
|
|
71
72
|
}
|
|
73
|
+
if ( !isInteger( x ) ) {
|
|
74
|
+
return 0.0;
|
|
75
|
+
}
|
|
72
76
|
if ( x < 0.0 || x > mlim ) {
|
|
73
77
|
return 0.0;
|
|
74
78
|
}
|
package/lib/main.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
23
|
var isPositiveInteger = require( '@stdlib/math-base-assert-is-positive-integer' );
|
|
24
|
+
var isInteger = require( '@stdlib/math-base-assert-is-integer' );
|
|
24
25
|
var isfinite = require( '@stdlib/math-base-assert-is-finite' );
|
|
25
26
|
var isnan = require( '@stdlib/math-base-assert-is-nan' );
|
|
26
27
|
var exp = require( '@stdlib/math-base-special-exp' );
|
|
@@ -75,6 +76,9 @@ function pdf( x, n ) {
|
|
|
75
76
|
) {
|
|
76
77
|
return NaN;
|
|
77
78
|
}
|
|
79
|
+
if ( !isInteger( x ) ) {
|
|
80
|
+
return 0.0;
|
|
81
|
+
}
|
|
78
82
|
mlim = ( n * ( n + 1 ) ) / 2;
|
|
79
83
|
if ( x < 0.0 || x > mlim ) {
|
|
80
84
|
return 0.0;
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var addon = require( './../src/addon.node' );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Evaluates the probability density function (PDF) of the Wilcoxon signed rank test statistic with `n` observations.
|
|
30
|
+
*
|
|
31
|
+
* @param {number} x - input value
|
|
32
|
+
* @param {PositiveInteger} n - number of observations
|
|
33
|
+
* @returns {Probability} evaluated PDF
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var y = pdf( 7.0, 9 );
|
|
37
|
+
* // returns ~0.01
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var y = pdf( 7.0, 6 );
|
|
41
|
+
* // returns ~0.063
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* var y = pdf( -1.0, 40 );
|
|
45
|
+
* // returns 0.0
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* var y = pdf( NaN, 10 );
|
|
49
|
+
* // returns NaN
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* var y = pdf( 0.0, NaN );
|
|
53
|
+
* // returns NaN
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* var y = pdf( 2.0, -1 );
|
|
57
|
+
* // returns NaN
|
|
58
|
+
*/
|
|
59
|
+
function pdf( x, n ) {
|
|
60
|
+
return addon( x, n );
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
// EXPORTS //
|
|
65
|
+
|
|
66
|
+
module.exports = pdf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": {
|
|
3
|
+
"task": "build",
|
|
4
|
+
"wasm": false
|
|
5
|
+
},
|
|
6
|
+
"fields": [
|
|
7
|
+
{
|
|
8
|
+
"field": "src",
|
|
9
|
+
"resolve": true,
|
|
10
|
+
"relative": true
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"field": "include",
|
|
14
|
+
"resolve": true,
|
|
15
|
+
"relative": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"field": "libraries",
|
|
19
|
+
"resolve": false,
|
|
20
|
+
"relative": false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"field": "libpath",
|
|
24
|
+
"resolve": true,
|
|
25
|
+
"relative": false
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"confs": [
|
|
29
|
+
{
|
|
30
|
+
"task": "build",
|
|
31
|
+
"wasm": false,
|
|
32
|
+
"src": ["./src/main.c"],
|
|
33
|
+
"include": ["./include"],
|
|
34
|
+
"libraries": [],
|
|
35
|
+
"libpath": [],
|
|
36
|
+
"dependencies": [
|
|
37
|
+
"@stdlib/math-base-assert-is-nan",
|
|
38
|
+
"@stdlib/math-base-special-exp",
|
|
39
|
+
"@stdlib/constants-float64-ln-two",
|
|
40
|
+
"@stdlib/math-base-napi-binary",
|
|
41
|
+
"@stdlib/math-base-special-ln",
|
|
42
|
+
"@stdlib/math-base-assert-is-integer"
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"task": "benchmark",
|
|
47
|
+
"wasm": false,
|
|
48
|
+
"src": ["./src/main.c"],
|
|
49
|
+
"include": ["./include"],
|
|
50
|
+
"libraries": [],
|
|
51
|
+
"libpath": [],
|
|
52
|
+
"dependencies": [
|
|
53
|
+
"@stdlib/math-base-special-ceil",
|
|
54
|
+
"@stdlib/math-base-assert-is-nan",
|
|
55
|
+
"@stdlib/math-base-special-exp",
|
|
56
|
+
"@stdlib/constants-float64-ln-two",
|
|
57
|
+
"@stdlib/math-base-special-ln",
|
|
58
|
+
"@stdlib/math-base-assert-is-integer"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"task": "examples",
|
|
63
|
+
"wasm": false,
|
|
64
|
+
"src": ["./src/main.c"],
|
|
65
|
+
"include": ["./include"],
|
|
66
|
+
"libraries": [],
|
|
67
|
+
"libpath": [],
|
|
68
|
+
"dependencies": [
|
|
69
|
+
"@stdlib/math-base-special-ceil",
|
|
70
|
+
"@stdlib/math-base-assert-is-nan",
|
|
71
|
+
"@stdlib/math-base-special-exp",
|
|
72
|
+
"@stdlib/constants-float64-ln-two",
|
|
73
|
+
"@stdlib/math-base-special-ln",
|
|
74
|
+
"@stdlib/math-base-assert-is-integer"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-signrank-pdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Wilcoxon signed rank test statistic probability density function (PDF).",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
16
|
"main": "./lib",
|
|
17
|
+
"gypfile": false,
|
|
17
18
|
"directories": {
|
|
18
19
|
"doc": "./docs",
|
|
20
|
+
"include": "./include",
|
|
19
21
|
"lib": "./lib",
|
|
22
|
+
"src": "./src",
|
|
20
23
|
"dist": "./dist"
|
|
21
24
|
},
|
|
22
25
|
"types": "./docs/types",
|
|
@@ -32,12 +35,15 @@
|
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@stdlib/constants-float64-ln-two": "^0.2.2",
|
|
34
37
|
"@stdlib/math-base-assert-is-finite": "^0.2.2",
|
|
38
|
+
"@stdlib/math-base-assert-is-integer": "^0.2.6",
|
|
35
39
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
36
|
-
"@stdlib/math-base-assert-is-positive-integer": "^0.3.
|
|
37
|
-
"@stdlib/math-base-
|
|
40
|
+
"@stdlib/math-base-assert-is-positive-integer": "^0.3.1",
|
|
41
|
+
"@stdlib/math-base-napi-binary": "^0.3.1",
|
|
42
|
+
"@stdlib/math-base-special-exp": "^0.2.4",
|
|
38
43
|
"@stdlib/math-base-special-ln": "^0.2.4",
|
|
39
44
|
"@stdlib/utils-constant-function": "^0.2.2",
|
|
40
45
|
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
46
|
+
"@stdlib/utils-library-manifest": "^0.2.3",
|
|
41
47
|
"@stdlib/utils-memoize": "^0.2.2"
|
|
42
48
|
},
|
|
43
49
|
"devDependencies": {},
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "stdlib/stats/base/dists/signrank/pdf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/binary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DI_D( stdlib_base_dists_signrank_pdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "stdlib/stats/base/dists/signrank/pdf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_integer.h"
|
|
21
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
22
|
+
#include "stdlib/math/base/special/exp.h"
|
|
23
|
+
#include "stdlib/constants/float64/ln_two.h"
|
|
24
|
+
#include "stdlib/math/base/special/ln.h"
|
|
25
|
+
#include <stdint.h>
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Calculates the weight for the (x,n) pair and memoizes the result.
|
|
29
|
+
*
|
|
30
|
+
* @param x input value
|
|
31
|
+
* @param n number of observations (must be a non-negative)
|
|
32
|
+
* @return weight value
|
|
33
|
+
*/
|
|
34
|
+
static double weights( double x, const int32_t n ) {
|
|
35
|
+
double mlim;
|
|
36
|
+
|
|
37
|
+
if ( n == 0 ) {
|
|
38
|
+
return ( x == 0 ) ? 1.0 : 0.0;
|
|
39
|
+
}
|
|
40
|
+
mlim = ( (double)n * ( (double)n + 1.0 ) ) / 2.0;
|
|
41
|
+
if ( x < 0 || x > mlim ) {
|
|
42
|
+
return 0.0;
|
|
43
|
+
}
|
|
44
|
+
if ( x > mlim / 2.0 ) {
|
|
45
|
+
x = mlim - x;
|
|
46
|
+
}
|
|
47
|
+
return weights( x-(double)n, n-1 ) + weights( x, n-1 );
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Evaluates the probability density function (PDF) of the Wilcoxon signed rank test statistic with `n` observations.
|
|
52
|
+
*
|
|
53
|
+
* @param x input value
|
|
54
|
+
* @param n number of observations (must be a non-negative)
|
|
55
|
+
* @return evaluated PDF
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* double y = stdlib_base_dists_signrank_pdf( 7.0, 9 );
|
|
59
|
+
* // returns ~0.01
|
|
60
|
+
*/
|
|
61
|
+
double stdlib_base_dists_signrank_pdf( const double x, const int32_t n ) {
|
|
62
|
+
double mlim;
|
|
63
|
+
if ( stdlib_base_is_nan( x ) || n <= 0 ) {
|
|
64
|
+
return 0.0/0.0;
|
|
65
|
+
}
|
|
66
|
+
if ( !stdlib_base_is_integer( x ) ) {
|
|
67
|
+
return 0.0;
|
|
68
|
+
}
|
|
69
|
+
mlim = ( (double)n * ( (double)n + 1.0 ) ) / 2.0;
|
|
70
|
+
if ( x < 0.0 || x > mlim ) {
|
|
71
|
+
return 0.0;
|
|
72
|
+
}
|
|
73
|
+
return stdlib_base_exp( stdlib_base_ln( weights( x, n ) ) - ( (double)n * STDLIB_CONSTANT_FLOAT64_LN2 ) );
|
|
74
|
+
}
|