@stdlib/stats-base-dists-binomial-skewness 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 +112 -16
- package/dist/index.js.map +1 -1
- package/include/stdlib/stats/base/dists/binomial/skewness.h +40 -0
- package/lib/index.js +2 -2
- package/lib/native.js +59 -0
- package/manifest.json +81 -0
- package/package.json +8 -3
- package/src/addon.c +22 -0
- package/src/main.c +45 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -139,20 +139,112 @@ v = skewness( 20, 1.5 );
|
|
|
139
139
|
<!-- eslint no-undef: "error" -->
|
|
140
140
|
|
|
141
141
|
```javascript
|
|
142
|
-
var
|
|
143
|
-
var
|
|
142
|
+
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
|
|
143
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
144
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
144
145
|
var skewness = require( '@stdlib/stats-base-dists-binomial-skewness' );
|
|
145
146
|
|
|
146
|
-
var
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
var
|
|
147
|
+
var opts = {
|
|
148
|
+
'dtype': 'float64'
|
|
149
|
+
};
|
|
150
|
+
var n = discreteUniform( 10, 0, 100, opts );
|
|
151
|
+
var p = uniform( 10, 0.0, 1.0, opts );
|
|
150
152
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
logEachMap( 'n: %0.4f, p: %0.4f, skew(X;n,p): %0.4f', n, p, skewness );
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
</section>
|
|
157
|
+
|
|
158
|
+
<!-- /.examples -->
|
|
159
|
+
|
|
160
|
+
<!-- C interface documentation. -->
|
|
161
|
+
|
|
162
|
+
* * *
|
|
163
|
+
|
|
164
|
+
<section class="c">
|
|
165
|
+
|
|
166
|
+
## C APIs
|
|
167
|
+
|
|
168
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
169
|
+
|
|
170
|
+
<section class="intro">
|
|
171
|
+
|
|
172
|
+
</section>
|
|
173
|
+
|
|
174
|
+
<!-- /.intro -->
|
|
175
|
+
|
|
176
|
+
<!-- C usage documentation. -->
|
|
177
|
+
|
|
178
|
+
<section class="usage">
|
|
179
|
+
|
|
180
|
+
### Usage
|
|
181
|
+
|
|
182
|
+
```c
|
|
183
|
+
#include "stdlib/stats/base/dists/binomial/skewness.h"
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### stdlib_base_dists_binomial_skewness( n, p )
|
|
187
|
+
|
|
188
|
+
Returns the [skewness][skewness] of a [binomial][binomial-distribution] distribution with number of trials `n` and success probability `p`.
|
|
189
|
+
|
|
190
|
+
```c
|
|
191
|
+
double out = stdlib_base_dists_binomial_skewness( 100, 0.1 );
|
|
192
|
+
// returns ~0.267
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The function accepts the following arguments:
|
|
196
|
+
|
|
197
|
+
- **n**: `[in] int32_t` number of trials.
|
|
198
|
+
- **p**: `[in] double` success probability.
|
|
199
|
+
|
|
200
|
+
```c
|
|
201
|
+
double stdlib_base_dists_binomial_skewness( const int32_t n, const double p );
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
</section>
|
|
205
|
+
|
|
206
|
+
<!-- /.usage -->
|
|
207
|
+
|
|
208
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
209
|
+
|
|
210
|
+
<section class="notes">
|
|
211
|
+
|
|
212
|
+
</section>
|
|
213
|
+
|
|
214
|
+
<!-- /.notes -->
|
|
215
|
+
|
|
216
|
+
<!-- C API usage examples. -->
|
|
217
|
+
|
|
218
|
+
<section class="examples">
|
|
219
|
+
|
|
220
|
+
### Examples
|
|
221
|
+
|
|
222
|
+
```c
|
|
223
|
+
#include "stdlib/stats/base/dists/binomial/skewness.h"
|
|
224
|
+
#include "stdlib/math/base/special/ceil.h"
|
|
225
|
+
#include <stdlib.h>
|
|
226
|
+
#include <stdint.h>
|
|
227
|
+
#include <stdio.h>
|
|
228
|
+
|
|
229
|
+
static double random_uniform( const double min, const double max ) {
|
|
230
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
231
|
+
return min + ( v * (max - min) );
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
int main( void ) {
|
|
235
|
+
int32_t n;
|
|
236
|
+
double p;
|
|
237
|
+
double y;
|
|
238
|
+
int i;
|
|
239
|
+
|
|
240
|
+
for ( i = 0; i < 25; i++ ) {
|
|
241
|
+
n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
|
|
242
|
+
p = random_uniform( 0.0, 1.0 );
|
|
243
|
+
y = stdlib_base_dists_binomial_skewness( n, p );
|
|
244
|
+
printf( "n: %d, p: %lf, skew(X;n,p): %lf\n", n, p, y );
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return 0;
|
|
156
248
|
}
|
|
157
249
|
```
|
|
158
250
|
|
|
@@ -160,6 +252,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
160
252
|
|
|
161
253
|
<!-- /.examples -->
|
|
162
254
|
|
|
255
|
+
</section>
|
|
256
|
+
|
|
257
|
+
<!-- /.c -->
|
|
258
|
+
|
|
163
259
|
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
164
260
|
|
|
165
261
|
<section class="references">
|
|
@@ -202,7 +298,7 @@ See [LICENSE][stdlib-license].
|
|
|
202
298
|
|
|
203
299
|
## Copyright
|
|
204
300
|
|
|
205
|
-
Copyright © 2016-
|
|
301
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
206
302
|
|
|
207
303
|
</section>
|
|
208
304
|
|
|
@@ -215,8 +311,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
215
311
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-binomial-skewness.svg
|
|
216
312
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-binomial-skewness
|
|
217
313
|
|
|
218
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-binomial-skewness/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
219
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-binomial-skewness/actions/workflows/test.yml?query=branch:v0.
|
|
314
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-binomial-skewness/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
315
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-binomial-skewness/actions/workflows/test.yml?query=branch:v0.3.0
|
|
220
316
|
|
|
221
317
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-binomial-skewness/main.svg
|
|
222
318
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-binomial-skewness?branch=main
|
|
@@ -228,8 +324,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
228
324
|
|
|
229
325
|
-->
|
|
230
326
|
|
|
231
|
-
[chat-image]: https://img.shields.io/
|
|
232
|
-
[chat-url]: https://
|
|
327
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
328
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
233
329
|
|
|
234
330
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
235
331
|
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNonNegativeInteger = require( '@stdlib/math-base-assert-is-nonnegative-integer' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\n\n\n// MAIN //\n\n/**\n* Returns the skewness of a binomial distribution.\n*\n* @param {NonNegativeInteger} n - number of trials\n* @param {Probability} p - success probability\n* @returns {number} skewness\n*\n* @example\n* var v = skewness( 100, 0.1 );\n* // returns ~0.267\n*\n* @example\n* var v = skewness( 20, 0.5 );\n* // returns 0.0\n*\n* @example\n* var v = skewness( 10.3, 0.5 );\n* // returns NaN\n*\n* @example\n* var v = skewness( 20, 1.1 );\n* // returns NaN\n*\n* @example\n* var v = skewness( 20, NaN );\n* // returns NaN\n*/\nfunction skewness( n, p ) {\n\tif (\n\t\tisnan( n ) ||\n\t\tisnan( p ) ||\n\t\tp < 0.0 ||\n\t\tp > 1.0 ||\n\t\t!isNonNegativeInteger( n ) ||\n\t\tn === PINF\n\t) {\n\t\treturn NaN;\n\t}\n\treturn ( 1.0 - ( 2.0*p ) ) / sqrt( n * p * ( 1.0-p ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = skewness;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Binomial distribution skewness.\n*\n* @module @stdlib/stats-base-dists-binomial-skewness\n*\n* @example\n* var skewness = require( '@stdlib/stats-base-dists-binomial-skewness' );\n*\n* var v = skewness( 100, 0.1 );\n* // returns
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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 isNonNegativeInteger = require( '@stdlib/math-base-assert-is-nonnegative-integer' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\n\n\n// MAIN //\n\n/**\n* Returns the skewness of a binomial distribution.\n*\n* @param {NonNegativeInteger} n - number of trials\n* @param {Probability} p - success probability\n* @returns {number} skewness\n*\n* @example\n* var v = skewness( 100, 0.1 );\n* // returns ~0.267\n*\n* @example\n* var v = skewness( 20, 0.5 );\n* // returns 0.0\n*\n* @example\n* var v = skewness( 10.3, 0.5 );\n* // returns NaN\n*\n* @example\n* var v = skewness( 20, 1.1 );\n* // returns NaN\n*\n* @example\n* var v = skewness( 20, NaN );\n* // returns NaN\n*/\nfunction skewness( n, p ) {\n\tif (\n\t\tisnan( n ) ||\n\t\tisnan( p ) ||\n\t\tp < 0.0 ||\n\t\tp > 1.0 ||\n\t\t!isNonNegativeInteger( n ) ||\n\t\tn === PINF\n\t) {\n\t\treturn NaN;\n\t}\n\treturn ( 1.0 - ( 2.0*p ) ) / sqrt( n * p * ( 1.0-p ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = skewness;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 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* Binomial distribution skewness.\n*\n* @module @stdlib/stats-base-dists-binomial-skewness\n*\n* @example\n* var skewness = require( '@stdlib/stats-base-dists-binomial-skewness' );\n*\n* var v = skewness( 100, 0.1 );\n* // returns ~0.267\n*\n* v = skewness( 20, 0.5 );\n* // returns 0\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
5
|
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,iDAAkD,EAClFC,EAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,EAAO,QAAS,gCAAiC,EAgCrD,SAASC,EAAUC,EAAGC,EAAI,CACzB,OACCL,EAAOI,CAAE,GACTJ,EAAOK,CAAE,GACTA,EAAI,GACJA,EAAI,GACJ,CAACN,EAAsBK,CAAE,GACzBA,IAAMF,EAEC,KAEC,EAAQ,EAAIG,GAAQJ,EAAMG,EAAIC,GAAM,EAAIA,EAAI,CACtD,CAKAP,EAAO,QAAUK,ICrCjB,IAAIG,EAAO,IAKX,OAAO,QAAUA",
|
|
6
6
|
"names": ["require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isnan", "sqrt", "PINF", "skewness", "n", "p", "main"]
|
|
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_BINOMIAL_SKEWNESS_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_BINOMIAL_SKEWNESS_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
|
+
* Returns the skewness of a binomial distribution with number of trials `n` and success probability `p`.
|
|
33
|
+
*/
|
|
34
|
+
double stdlib_base_dists_binomial_skewness( const int32_t n, const double p );
|
|
35
|
+
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
}
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#endif // !STDLIB_STATS_BASE_DISTS_BINOMIAL_SKEWNESS_H
|
package/lib/index.js
CHANGED
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
* var skewness = require( '@stdlib/stats-base-dists-binomial-skewness' );
|
|
28
28
|
*
|
|
29
29
|
* var v = skewness( 100, 0.1 );
|
|
30
|
-
* // returns
|
|
30
|
+
* // returns ~0.267
|
|
31
31
|
*
|
|
32
32
|
* v = skewness( 20, 0.5 );
|
|
33
|
-
* // returns
|
|
33
|
+
* // returns 0
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
// MODULES //
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
* Returns the skewness of a binomial distribution with number of trials `n` and success probability `p`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {NonNegativeInteger} n - number of trials
|
|
33
|
+
* @param {Probability} p - success probability
|
|
34
|
+
* @returns {number} skewness
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var v = skewness( 100, 0.1 );
|
|
38
|
+
* // returns ~0.267
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var v = skewness( 20, 0.5 );
|
|
42
|
+
* // returns 0.0
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var v = skewness( 20, 1.1 );
|
|
46
|
+
* // returns NaN
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var v = skewness( 20, NaN );
|
|
50
|
+
* // returns NaN
|
|
51
|
+
*/
|
|
52
|
+
function skewness( n, p ) {
|
|
53
|
+
return addon( n, p );
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// EXPORTS //
|
|
58
|
+
|
|
59
|
+
module.exports = skewness;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
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": [
|
|
33
|
+
"./src/main.c"
|
|
34
|
+
],
|
|
35
|
+
"include": [
|
|
36
|
+
"./include"
|
|
37
|
+
],
|
|
38
|
+
"libraries": [],
|
|
39
|
+
"libpath": [],
|
|
40
|
+
"dependencies": [
|
|
41
|
+
"@stdlib/math-base-napi-binary",
|
|
42
|
+
"@stdlib/math-base-assert-is-nan",
|
|
43
|
+
"@stdlib/math-base-special-sqrt"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"task": "benchmark",
|
|
48
|
+
"wasm": false,
|
|
49
|
+
"src": [
|
|
50
|
+
"./src/main.c"
|
|
51
|
+
],
|
|
52
|
+
"include": [
|
|
53
|
+
"./include"
|
|
54
|
+
],
|
|
55
|
+
"libraries": [],
|
|
56
|
+
"libpath": [],
|
|
57
|
+
"dependencies": [
|
|
58
|
+
"@stdlib/math-base-assert-is-nan",
|
|
59
|
+
"@stdlib/math-base-special-sqrt",
|
|
60
|
+
"@stdlib/math-base-special-ceil"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"task": "examples",
|
|
65
|
+
"wasm": false,
|
|
66
|
+
"src": [
|
|
67
|
+
"./src/main.c"
|
|
68
|
+
],
|
|
69
|
+
"include": [
|
|
70
|
+
"./include"
|
|
71
|
+
],
|
|
72
|
+
"libraries": [],
|
|
73
|
+
"libpath": [],
|
|
74
|
+
"dependencies": [
|
|
75
|
+
"@stdlib/math-base-assert-is-nan",
|
|
76
|
+
"@stdlib/math-base-special-sqrt",
|
|
77
|
+
"@stdlib/math-base-special-ceil"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-binomial-skewness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Binomial distribution skewness.",
|
|
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,8 +35,10 @@
|
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@stdlib/constants-float64-pinf": "^0.2.2",
|
|
34
37
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
35
|
-
"@stdlib/math-base-assert-is-nonnegative-integer": "^0.2.
|
|
36
|
-
"@stdlib/math-base-
|
|
38
|
+
"@stdlib/math-base-assert-is-nonnegative-integer": "^0.2.2",
|
|
39
|
+
"@stdlib/math-base-napi-binary": "^0.3.1",
|
|
40
|
+
"@stdlib/math-base-special-sqrt": "^0.2.2",
|
|
41
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
37
42
|
},
|
|
38
43
|
"devDependencies": {},
|
|
39
44
|
"engines": {
|
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/binomial/skewness.h"
|
|
20
|
+
#include "stdlib/math/base/napi/binary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_ID_D( stdlib_base_dists_binomial_skewness );
|
package/src/main.c
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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/binomial/skewness.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/sqrt.h"
|
|
22
|
+
#include <stdint.h>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns the skewness of a binomial distribution.
|
|
26
|
+
*
|
|
27
|
+
* @param n number of trials
|
|
28
|
+
* @param p success probability
|
|
29
|
+
* @return skewness
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* double y = stdlib_base_dists_binomial_skewness( 100, 0.1 );
|
|
33
|
+
* // returns ~0.267
|
|
34
|
+
*/
|
|
35
|
+
double stdlib_base_dists_binomial_skewness( const int32_t n, const double p ) {
|
|
36
|
+
if (
|
|
37
|
+
stdlib_base_is_nan( p ) ||
|
|
38
|
+
n < 0 ||
|
|
39
|
+
p < 0.0 ||
|
|
40
|
+
p > 1.0
|
|
41
|
+
) {
|
|
42
|
+
return 0.0 / 0.0;
|
|
43
|
+
}
|
|
44
|
+
return ( 1.0 - ( 2.0*p ) ) / stdlib_base_sqrt( n * p * (1.0 - p) );
|
|
45
|
+
}
|