Skip to content

Commit 18e1770

Browse files
vivekmaurya001Planeshifterstdlib-bot
authored
feat: add stats/base/dists/bradford/skewness
PR-URL: #6401 Ref: #168 Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Co-authored-by: stdlib-bot <noreply@stdlib.io> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent da78bfd commit 18e1770

File tree

12 files changed

+703
-0
lines changed

12 files changed

+703
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Skewness
22+
23+
> [Bradford][bradford-distribution] distribution [skewness][skewness].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
The [skewness][skewness] for a [Bradford][bradford-distribution] random variable with shape parameter.`c` is
30+
31+
<!-- <equation class="equation" label="eq:bradford_skewness" align="center" raw="\operatorname{skew}\left( c \right) = \frac{\sqrt{2}\,\Bigl(12c^2 - 9c\,\log(1+c)(c+2) +2\,(\log(1+c))^2\,(c(c+3)+3)\Bigr)}{\sqrt{c\,\Bigl(c\,(\log(1+c)-2)+2\log(1+c)\Bigr)}\Bigl(3c\,(\log(1+c)-2)+6\log(1+c)\Bigr)}" alt="Skewness for a bradford distribution."> -->
32+
33+
```math
34+
\mathop{\mathrm{skew}}\left( c \right) = \frac{\sqrt{2}\,\Bigl(12c^2 - 9c\,\log(1+c)(c+2) + 2\,(\log(1+c))^2\,(c(c+3)+3)\Bigr)}{\sqrt{c\,\Bigl(c\,(\log(1+c)-2)+2\log(1+c)\Bigr)}\Bigl(3c\,(\log(1+c)-2)+6\log(1+c)\Bigr)}
35+
```
36+
37+
<!-- </equation> -->
38+
39+
where `c` is the shape parameter.
40+
41+
</section>
42+
43+
<!-- /.intro -->
44+
45+
<!-- Package usage documentation. -->
46+
47+
<section class="usage">
48+
49+
## Usage
50+
51+
```javascript
52+
var skewness = require( '@stdlib/stats/base/dists/bradford/skewness' );
53+
```
54+
55+
#### skewness( c )
56+
57+
Returns the [skewness][skewness] of a [Bradford][bradford-distribution] distribution with shape parameter `c`.
58+
59+
```javascript
60+
var v = skewness( 9.0 );
61+
// returns ~0.772
62+
63+
v = skewness( 0.5 );
64+
// returns ~0.140
65+
```
66+
67+
If provided `c <= 0`, the function returns `NaN`.
68+
69+
```javascript
70+
var v = skewness( -1.0 );
71+
// returns NaN
72+
```
73+
74+
</section>
75+
76+
<!-- /.usage -->
77+
78+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
79+
80+
<section class="notes">
81+
82+
</section>
83+
84+
<!-- /.notes -->
85+
86+
<!-- Package usage examples. -->
87+
88+
<section class="examples">
89+
90+
## Examples
91+
92+
<!-- eslint no-undef: "error" -->
93+
94+
```javascript
95+
var uniform = require( '@stdlib/random/array/uniform' );
96+
var logEachMap = require( '@stdlib/console/log-each-map' );
97+
var skewness = require( '@stdlib/stats/base/dists/bradford/skewness' );
98+
99+
var opts = {
100+
'dtype': 'float64'
101+
};
102+
var c = uniform( 10, 0.1, 10.0, opts );
103+
104+
logEachMap( 'c: %0.4f, Skew(X;c): %0.4f', c, skewness );
105+
```
106+
107+
</section>
108+
109+
<!-- /.examples -->
110+
111+
<!-- 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. -->
112+
113+
<section class="references">
114+
115+
</section>
116+
117+
<!-- /.references -->
118+
119+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
120+
121+
<section class="related">
122+
123+
</section>
124+
125+
<!-- /.related -->
126+
127+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
128+
129+
<section class="links">
130+
131+
[bradford-distribution]: https://en.wikipedia.org/wiki/Bradford%27s_law
132+
133+
[skewness]: https://en.wikipedia.org/wiki/Skewness
134+
135+
</section>
136+
137+
<!-- /.links -->
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 bench = require( '@stdlib/bench' );
24+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var EPS = require( '@stdlib/constants/float64/eps' );
27+
var pkg = require( './../package.json' ).name;
28+
var skewness = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var len;
35+
var c;
36+
var y;
37+
var i;
38+
39+
len = 100;
40+
c = uniform( 100, EPS, 20.0 );
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
y = skewness( c[ i % len ] );
45+
if ( isnan( y ) ) {
46+
b.fail( 'should not return NaN' );
47+
}
48+
}
49+
b.toc();
50+
if ( isnan( y ) ) {
51+
b.fail( 'should not return NaN' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
{{alias}}( c )
3+
Returns the skewness of a Bradford distribution.
4+
5+
If provided `NaN` as any argument, the function returns `NaN`.
6+
7+
If provided `c <= 0`, the function returns `NaN`.
8+
9+
Parameters
10+
----------
11+
c: number
12+
Shape Parameter.
13+
14+
Returns
15+
-------
16+
out: number
17+
Skewness.
18+
19+
Examples
20+
--------
21+
> var v = {{alias}}( 11.0 )
22+
~0.829
23+
> v = {{alias}}( 1.5 )
24+
~0.316
25+
26+
See Also
27+
--------
28+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Returns the skewness of a Bradford distribution.
23+
*
24+
* ## Notes
25+
*
26+
* - If provided `c <= 0`, the function returns `NaN`.
27+
*
28+
* @param c - shape parameter
29+
* @returns skewness
30+
*
31+
* @example
32+
* var v = skewness( 9.0 );
33+
* // returns ~0.772
34+
*
35+
* @example
36+
* var v = skewness( 1.0 );
37+
* // returns ~0.239
38+
*
39+
* @example
40+
* var v = skewness( -0.2 );
41+
* // returns NaN
42+
*
43+
* @example
44+
* var v = skewness( NaN );
45+
* // returns NaN
46+
*/
47+
declare function skewness( c: number ): number;
48+
49+
50+
// EXPORTS //
51+
52+
export = skewness;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
import skewness = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
skewness( 9.0 ); // $ExpectType number
27+
}
28+
29+
// The compiler throws an error if the function is provided a value other than a number...
30+
{
31+
skewness( true ); // $ExpectError
32+
skewness( false ); // $ExpectError
33+
skewness( null ); // $ExpectError
34+
skewness( undefined ); // $ExpectError
35+
skewness( '5' ); // $ExpectError
36+
skewness( [] ); // $ExpectError
37+
skewness( {} ); // $ExpectError
38+
skewness( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided insufficient arguments...
42+
{
43+
skewness(); // $ExpectError
44+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
var uniform = require( '@stdlib/random/array/uniform' );
22+
var logEachMap = require( '@stdlib/console/log-each-map' );
23+
var skewness = require( './../lib' );
24+
25+
var opts = {
26+
'dtype': 'float64'
27+
};
28+
var c = uniform( 10, 0.1, 10.0, opts );
29+
30+
logEachMap( 'c: %0.4f, Skew(X;c): %0.4f', c, skewness );
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
/**
22+
* Bradford distribution skewness.
23+
*
24+
* @module @stdlib/stats/base/dists/bradford/skewness
25+
*
26+
* @example
27+
* var skewness = require( '@stdlib/stats/base/dists/bradford/skewness' );
28+
*
29+
* var v = skewness( 11.0 );
30+
* // returns ~0.829
31+
*
32+
* v = skewness( 1.5 );
33+
* // returns ~0.316
34+
*/
35+
36+
// MODULES //
37+
38+
var main = require( './main.js' );
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = main;

0 commit comments

Comments
 (0)