Skip to content

Commit dfb9dde

Browse files
feat: add stats/base/dists/bradford/skewness
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: passed - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent ef90f52 commit dfb9dde

File tree

12 files changed

+682
-0
lines changed

12 files changed

+682
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 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 degrees of freedom `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 skewness = require( '@stdlib/stats/base/dists/bradford/skewness' );
96+
var uniform = require( '@stdlib/random/array/uniform' );
97+
98+
var c = uniform( 10, 0.1, 10.0 );
99+
100+
var v;
101+
var i;
102+
for ( i = 0; i < 10; i++ ) {
103+
v = skewness( c[ i ] );
104+
console.log( 'c: %d, Skew(X;c): %d', c[ i ].toFixed( 4 ), v.toFixed( 4 ) );
105+
}
106+
```
107+
108+
</section>
109+
110+
<!-- /.examples -->
111+
112+
<!-- 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. -->
113+
114+
<section class="references">
115+
116+
</section>
117+
118+
<!-- /.references -->
119+
120+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
121+
122+
<section class="related">
123+
124+
</section>
125+
126+
<!-- /.related -->
127+
128+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
129+
130+
<section class="links">
131+
132+
[bradford-distribution]: https://en.wikipedia.org/wiki/Bradford%27s_law
133+
134+
[skewness]: https://en.wikipedia.org/wiki/Skewness
135+
136+
</section>
137+
138+
<!-- /.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) 2018 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) 2019 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) 2019 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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 skewness = require( './../lib' );
23+
24+
var c = uniform( 10, 0.1, 10.0 );
25+
26+
var v;
27+
var i;
28+
for ( i = 0; i < 10; i++ ) {
29+
v = skewness( c[ i ] );
30+
console.log( 'c: %d, Skew(X;c): %d', c[ i ].toFixed( 4 ), v.toFixed( 4 ) );
31+
}
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) 2018 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)